LoginSignup
2
1

More than 5 years have passed since last update.

paramikoのコンテキストマネージャのクラス一覧

Posted at

paramikoを書いてて、毎回close()するのめんどくさいので、コンテキストマネージャかどうか調べてみました。

コンテキストマネージャとは

withが使えるオブジェクトのこと

__enter__()__exit__()を持つオブジェクト

paramikoのコンテキストマネージャのクラス

paramiko.util.ClosingContextManagerというクラスが定義されており、このクラスを継承していれば、コンテキストマネージャになる

paramiko.util.ClosingContextManager

class ClosingContextManager(object):
    def __enter__(self):
        return self

    def __exit__(self, type, value, traceback):
        self.close()

以下のクラスがコンテキストマネージャになっている

  • paramiko.channel.Channel
  • paramiko.client.SSHClient
  • paramiko.file.BufferedFile
  • paramiko.proxy.ProxyCommand
  • paramiko.sftp_client.SFTPClient
  • paramiko.sftp_handle.SFTPHandle
  • paramiko.transport.Transport

参考文献

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1