diff options
author | Olle Lundberg <geek@nerd.sh> | 2014-08-15 21:53:33 +0200 |
---|---|---|
committer | Olle Lundberg <geek@nerd.sh> | 2014-08-21 23:08:27 +0200 |
commit | 84299d318bbea57a58d933ec79a053177f946500 (patch) | |
tree | 8c7459a62d76963830bb98f0e6def1286afd9fc9 | |
parent | 991d56bad32c1ea4eda6c86771a4a4b7bef00475 (diff) |
Add a decorator for checking channel openness.
This decorator will be used in future commits.
-rw-r--r-- | paramiko/channel.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/paramiko/channel.py b/paramiko/channel.py index 583809d5..2215636b 100644 --- a/paramiko/channel.py +++ b/paramiko/channel.py @@ -25,6 +25,7 @@ import os import socket import time import threading +from functools import wraps from paramiko import util from paramiko.common import cMSG_CHANNEL_REQUEST, cMSG_CHANNEL_WINDOW_ADJUST, \ @@ -42,6 +43,15 @@ from paramiko import pipe # lower bound on the max packet size we'll accept from the remote host MIN_PACKET_SIZE = 1024 +def requires_open_channel(func): + """This decorator make sures that the channel is open else raises an + exception""" + @wraps(func) + def _check(self, *args, **kwds): + if self.closed or self.eof_received or self.eof_sent or not self.active: + raise SSHException('Channel is not open') + return func(self, *args, **kwds) + return _check class Channel (object): """ |