Пример #1
0
    def connect(self, uri, **kwargs):
        """Connect to the remote host"""

        options = merge_dicts(parse_uri(uri), kwargs)

        self.hostname = options.pop('hostname', None) or self.hostname

        protocol = options.pop('protocol', None) or self.protocol
        transport = None
        if '+' in protocol:
            protocol, transport = self.protocol.split('+', 1)

        options['transport'] = options.get('transport') or transport
        self.protocol = protocol

        self.creds = options.pop('creds', None) or DEFAULT_CREDS
        port = options.get('port')

        if port:
            options['port'] = port

        options['timeout'] = options.get('timeout') or DEFAULT_TIMEOUT

        self.options = options

        self.conn = _load_protocol_adapter(protocol)()
        self.conn.connect(self.hostname, self.creds, **self.options)
Пример #2
0
    def clone(self, uri=None, **kwargs):
        cloned = self.__class__()

        if not uri:
            uri = self.hostname

        kwargs = merge_dicts(self.options, parse_uri(uri), kwargs)
        cloned.connect(uri, **kwargs)
        if self.authorized:
            cloned.authorize(*self.authorized)

        return cloned