当前位置: 首页>>代码示例>>Python>>正文


Python py3compat.u方法代码示例

本文整理汇总了Python中paramiko.py3compat.u方法的典型用法代码示例。如果您正苦于以下问题:Python py3compat.u方法的具体用法?Python py3compat.u怎么用?Python py3compat.u使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在paramiko.py3compat的用法示例。


在下文中一共展示了py3compat.u方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: hash_host

# 需要导入模块: from paramiko import py3compat [as 别名]
# 或者: from paramiko.py3compat import u [as 别名]
def hash_host(hostname, salt=None):
        """
        Return a "hashed" form of the hostname, as used by OpenSSH when storing
        hashed hostnames in the known_hosts file.

        :param str hostname: the hostname to hash
        :param str salt: optional salt to use when hashing (must be 20 bytes long)
        :return: the hashed hostname as a `str`
        """
        if salt is None:
            salt = os.urandom(sha1().digest_size)
        else:
            if salt.startswith('|1|'):
                salt = salt.split('|')[2]
            salt = decodebytes(b(salt))
        assert len(salt) == sha1().digest_size
        hmac = HMAC(salt, b(hostname), sha1).digest()
        hostkey = '|1|%s|%s' % (u(encodebytes(salt)), u(encodebytes(hmac)))
        return hostkey.replace('\n', '') 
开发者ID:iopsgroup,项目名称:imoocc,代码行数:21,代码来源:hostkeys.py

示例2: test_5_rename

# 需要导入模块: from paramiko import py3compat [as 别名]
# 或者: from paramiko.py3compat import u [as 别名]
def test_5_rename(self):
        """
        verify that renaming a file works.
        """
        try:
            with sftp.open(FOLDER + '/first.txt', 'w') as f:
                f.write('content!\n')
            sftp.rename(FOLDER + '/first.txt', FOLDER + '/second.txt')
            try:
                sftp.open(FOLDER + '/first.txt', 'r')
                self.assertTrue(False, 'no exception on reading nonexistent file')
            except IOError:
                pass
            with sftp.open(FOLDER + '/second.txt', 'r') as f:
                f.seek(-6, f.SEEK_END)
                self.assertEqual(u(f.read(4)), 'tent')
        finally:
            try:
                sftp.remove(FOLDER + '/first.txt')
            except:
                pass
            try:
                sftp.remove(FOLDER + '/second.txt')
            except:
                pass 
开发者ID:hpe-storage,项目名称:python-hpedockerplugin,代码行数:27,代码来源:test_sftp.py

示例3: test_D_flush_seek

# 需要导入模块: from paramiko import py3compat [as 别名]
# 或者: from paramiko.py3compat import u [as 别名]
def test_D_flush_seek(self):
        """
        verify that buffered writes are automatically flushed on seek.
        """
        try:
            with sftp.open(FOLDER + '/happy.txt', 'w', 1) as f:
                f.write('full line.\n')
                f.write('partial')
                f.seek(9, f.SEEK_SET)
                f.write('?\n')

            with sftp.open(FOLDER + '/happy.txt', 'r') as f:
                self.assertEqual(f.readline(), u('full line?\n'))
                self.assertEqual(f.read(7), b'partial')
        finally:
            try:
                sftp.remove(FOLDER + '/happy.txt')
            except:
                pass 
开发者ID:hpe-storage,项目名称:python-hpedockerplugin,代码行数:21,代码来源:test_sftp.py

示例4: check_auth_publickey

# 需要导入模块: from paramiko import py3compat [as 别名]
# 或者: from paramiko.py3compat import u [as 别名]
def check_auth_publickey(self, username, key):
        self.plog("check_auth_publickey: username='%s', key fingerprint='%s'" % (
            username, u(hexlify(key.get_fingerprint()))
        ))
        return paramiko.AUTH_FAILED 
开发者ID:gynvael,项目名称:stream,代码行数:7,代码来源:demo_server.py

示例5: check_auth_publickey

# 需要导入模块: from paramiko import py3compat [as 别名]
# 或者: from paramiko.py3compat import u [as 别名]
def check_auth_publickey(self, username, key):
        print('Auth attempt with username: {!r} & key: {!r}'.format(username, u(hexlify(key.get_fingerprint())))) # noqa
        if (username in ['robey', 'keyonly']) and (key == self.good_pub_key):
            return paramiko.AUTH_SUCCESSFUL
        if username == 'pkey2fa' and key == self.good_pub_key:
            self.key_verified = True
            return paramiko.AUTH_PARTIALLY_SUCCESSFUL
        return paramiko.AUTH_FAILED 
开发者ID:huashengdun,项目名称:webssh,代码行数:10,代码来源:sshserver.py

示例6: interactive_shell

# 需要导入模块: from paramiko import py3compat [as 别名]
# 或者: from paramiko.py3compat import u [as 别名]
def interactive_shell(chan, callback=None):
    oldtty = termios.tcgetattr(sys.stdin)
    try:
        tty.setraw(sys.stdin.fileno())
        tty.setcbreak(sys.stdin.fileno())
        chan.settimeout(0.0)

        while True:
            r, w, e = select.select([chan, sys.stdin], [], [])
            if chan in r:
                try:
                    x = u(chan.recv(1024))
                    if len(x) == 0:
                        sys.stdout.write("\r\n[+] Terminating SSH connection\r\n")
                        sys.stdout.flush()
                        if callback != None:
                            callback()
                        break
                    sys.stdout.write(x)
                    sys.stdout.flush()
                except socket.timeout:
                    pass
            if sys.stdin in r:
                x = sys.stdin.read(1)
                if len(x) == 0:
                    break
                chan.send(x)

    finally:
        termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty) 
开发者ID:ivRodriguezCA,项目名称:decrypt-ios-apps-script,代码行数:32,代码来源:helpers.py

示例7: keygen

# 需要导入模块: from paramiko import py3compat [as 别名]
# 或者: from paramiko.py3compat import u [as 别名]
def keygen(self,
               filename: str,
               type: str = 'rsa',
               bits: int = 4096,
               comment: Optional[str] = None,
               passphrase: Optional[str] = None) -> SSHKeygenResponse:
        """
        Generate an SSH keypair.

        :param filename: Output file name for the private key (the public key will be stored in <filename>.pub).
        :param type: Encryption algorithm, either "rsa" or "dsa" (default: "rsa").
        :param bits: Key length in bits (default: 4096).
        :param comment: Key comment (default: None).
        :param passphrase: Key passphrase (default: None).
        :return: :class:`platypush.message.response.ssh.SSHKeygenResponse`.
        """
        assert type != 'dsa' or bits <= 1024, 'DSA keys support a maximum of 1024 bits'
        assert type in self.key_dispatch_table, 'No such type: {}. Available types: {}'.format(
            type, self.key_dispatch_table.keys())

        if filename:
            filename = os.path.abspath(os.path.expanduser(filename))

        prv = self.key_dispatch_table[type].generate(bits=bits)
        prv.write_private_key_file(filename=filename, password=passphrase)
        pub = self.key_dispatch_table[type](filename=filename, password=passphrase)
        pub_file = '{filename}.pub'.format(filename=filename)
        with open(pub_file, 'w') as f:
            f.write('{name} {key}'.format(name=pub.get_name(), key=pub.get_base64()))
            if comment:
                f.write(' ' + comment)

        hash = u(hexlify(pub.get_fingerprint()))
        return SSHKeygenResponse(fingerprint=hash, key_file=filename, pub_key_file=pub_file) 
开发者ID:BlackLight,项目名称:platypush,代码行数:36,代码来源:__init__.py

示例8: set_host_key

# 需要导入模块: from paramiko import py3compat [as 别名]
# 或者: from paramiko.py3compat import u [as 别名]
def set_host_key(self, host_key):
        self.host_key = host_key
        LOG.info('ServerHostKey: %s'%u(hexlify(host_key.get_fingerprint()))) 
开发者ID:tintinweb,项目名称:pub,代码行数:5,代码来源:poc.py

示例9: get_base64

# 需要导入模块: from paramiko import py3compat [as 别名]
# 或者: from paramiko.py3compat import u [as 别名]
def get_base64(self):
        """
        Return a base64 string containing the public part of this key.  Nothing
        secret is revealed.  This format is compatible with that used to store
        public key files or recognized host keys.

        :return: a base64 `string <str>` containing the public part of the key.
        """
        return u(encodebytes(self.asbytes())).replace('\n', '') 
开发者ID:iopsgroup,项目名称:imoocc,代码行数:11,代码来源:pkey.py

示例10: get_text

# 需要导入模块: from paramiko import py3compat [as 别名]
# 或者: from paramiko.py3compat import u [as 别名]
def get_text(self):
        """
        Fetch a Unicode string from the stream.
        """
        return u(self.get_string()) 
开发者ID:iopsgroup,项目名称:imoocc,代码行数:7,代码来源:message.py

示例11: readline

# 需要导入模块: from paramiko import py3compat [as 别名]
# 或者: from paramiko.py3compat import u [as 别名]
def readline(self, timeout):
        """
        Read a line from the socket.  We assume no data is pending after the
        line, so it's okay to attempt large reads.
        """
        buf = self.__remainder
        while not linefeed_byte in buf:
            buf += self._read_timeout(timeout)
        n = buf.index(linefeed_byte)
        self.__remainder = buf[n + 1:]
        buf = buf[:n]
        if (len(buf) > 0) and (buf[-1] == cr_byte_value):
            buf = buf[:-1]
        return u(buf) 
开发者ID:iopsgroup,项目名称:imoocc,代码行数:16,代码来源:packet.py

示例12: getcwd

# 需要导入模块: from paramiko import py3compat [as 别名]
# 或者: from paramiko.py3compat import u [as 别名]
def getcwd(self):
        """
        Return the "current working directory" for this SFTP session, as
        emulated by Paramiko.  If no directory has been set with `chdir`,
        this method will return ``None``.

        .. versionadded:: 1.4
        """
        # TODO: make class initialize with self._cwd set to self.normalize('.')
        return self._cwd and u(self._cwd) 
开发者ID:iopsgroup,项目名称:imoocc,代码行数:12,代码来源:sftp_client.py

示例13: check_auth_publickey

# 需要导入模块: from paramiko import py3compat [as 别名]
# 或者: from paramiko.py3compat import u [as 别名]
def check_auth_publickey(self, username, key):
        print('Auth attempt with username: {!r} & key: {!r}'.format(username, u(hexlify(key.get_fingerprint())))) # noqa
        if (username in ['robey', 'keyonly']) and (key == self.good_pub_key):
            return paramiko.AUTH_SUCCESSFUL
        return paramiko.AUTH_FAILED 
开发者ID:guohongze,项目名称:adminset,代码行数:7,代码来源:sshserver.py

示例14: ssh_shell

# 需要导入模块: from paramiko import py3compat [as 别名]
# 或者: from paramiko.py3compat import u [as 别名]
def ssh_shell(command):
    from paramiko.py3compat import u
    oldtty = termios.tcgetattr(sys.stdin)
    try:
        tty.setraw(sys.stdin.fileno())
        tty.setcbreak(sys.stdin.fileno())
        command.settimeout(0.0)
        while True:
            r, w, e = select.select([command, sys.stdin], [], [])
            if command in r:
                try:
                    x = u(command.recv(1024))
                    if len(x) == 0:
                        sys.stdout.write('\r\n{0}[x]{1} shell closed'.format(warna.merah, warna.tutup))
                        break
                    sys.stdout.write(x)
                    sys.stdout.flush()

                except socket.timeout:
                    pass

            if sys.stdin in r:
                x = sys.stdin.read(1)
                if len(x) == 0:
                    break
                command.send(x)

    finally:
        termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty) 
开发者ID:kuburan,项目名称:txtool,代码行数:31,代码来源:fungsi.py

示例15: check_auth_publickey

# 需要导入模块: from paramiko import py3compat [as 别名]
# 或者: from paramiko.py3compat import u [as 别名]
def check_auth_publickey(self, username, key):
        print('Auth attempt with key: ' + u(hexlify(key.get_fingerprint())))
        if (username == 'robey') and (key == self.good_pub_key):
            return paramiko.AUTH_SUCCESSFUL
        return paramiko.AUTH_FAILED 
开发者ID:hpe-storage,项目名称:python-hpedockerplugin,代码行数:7,代码来源:demo_server.py


注:本文中的paramiko.py3compat.u方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。