Пример #1
0
    def connect(self):
        factory = WebSocketClientFactory(self.endpoint)
        factory.protocol = self.protocol
        factory.client = self
        factory.kwargs = self.kwargs
        factory.headers["X-Host-ID"] = self.host_id
        factory.headers["X-Client-Type"] = self.type
        if self.persistent:
            factory.headers["X-Persistence-Policy"] = "Persistent"
        else:
            factory.headers["X-Persistence-Policy"] = "DeleteOnDisconnect"

        if self.username:
            authorization = base64.b64encode(
                b"%s:%s" % (self.username, self.password)).decode("ascii")
            factory.headers["Authorization"] = 'Basic %s' % authorization

        if self.filter:
            factory.headers["X-Gremlin-Filter"] = self.filter

        self.loop = asyncio.get_event_loop()
        u = urlparse(self.endpoint)

        coro = self.loop.create_connection(factory, u.hostname, u.port)
        self.loop.run_until_complete(coro)

        try:
            self.loop.run_forever()
        except KeyboardInterrupt:
            self.loop.close()
        finally:
            pass
Пример #2
0
    def connect(self):
        factory = WebSocketClientFactory(self.endpoint)
        factory.protocol = self.protocol
        factory.client = self
        factory.kwargs = self.kwargs
        factory.headers["X-Host-ID"] = self.host_id
        factory.headers["X-Client-Type"] = self.type
        factory.headers["X-Client-Protocol"] = "json"
        if self.persistent:
            factory.headers["X-Persistence-Policy"] = "Persistent"
        else:
            factory.headers["X-Persistence-Policy"] = "DeleteOnDisconnect"

        if self.username:
            if self.auth.login():
                cookie = "authtoken={}".format(self.auth.token)
                if self.cookies:
                    self.cookies.append(cookie)
                else:
                    self.cookies = [
                        cookie,
                    ]

        if self.filter:
            factory.headers["X-Gremlin-Filter"] = self.filter

        if self.cookies:
            factory.headers["Cookie"] = ";".join(self.cookies)

        coro = self.loop.create_connection(factory,
                                           self.url.hostname,
                                           self.url.port,
                                           ssl=self.ssl_context)
        (transport, protocol) = self.loop.run_until_complete(coro)
        LOG.debug("transport, protocol: %r, %r", transport, protocol)
Пример #3
0
    def connect(self):
        factory = WebSocketClientFactory(self.endpoint)
        factory.protocol = self.protocol
        factory.client = self
        factory.kwargs = self.kwargs
        factory.headers["X-Host-ID"] = self.host_id
        factory.headers["X-Client-Type"] = self.type
        if self.persistent:
            factory.headers["X-Persistence-Policy"] = "Persistent"
        else:
            factory.headers["X-Persistence-Policy"] = "DeleteOnDisconnect"

        if self.username:
            authorization = base64.b64encode(
                b"%s:%s" % (self.username, self.password)).decode("ascii")
            factory.headers["Authorization"] = 'Basic %s' % authorization

        if self.filter:
            factory.headers["X-Gremlin-Filter"] = self.filter

        if self.cookies:
            factory.headers['Cookie'] = ';'.join(self.cookies)

        self.loop = asyncio.get_event_loop()
        u = urlparse(self.endpoint)

        coro = self.loop.create_connection(factory, u.hostname, u.port)
        (transport, protocol) = self.loop.run_until_complete(coro)
        LOG.debug('transport, protocol: %r, %r', transport, protocol)
Пример #4
0
    def connect(self):
        factory = WebSocketClientFactory(self.endpoint)
        factory.protocol = self.protocol
        factory.client = self
        factory.kwargs = self.kwargs
        factory.headers["X-Host-ID"] = self.host_id
        factory.headers["X-Client-Type"] = self.type
        factory.headers["X-Client-Protocol"] = "json"
        if self.persistent:
            factory.headers["X-Persistence-Policy"] = "Persistent"
        else:
            factory.headers["X-Persistence-Policy"] = "DeleteOnDisconnect"

        if self.username:
            if self.auth.login():
                cookie = 'authtok={}'.format(self.auth.authtok)
                if self.cookies:
                    self.cookies.append(cookie)
                else:
                    self.cookies = [
                        cookie,
                    ]

        if self.filter:
            factory.headers["X-Gremlin-Filter"] = self.filter

        if self.cookies:
            factory.headers['Cookie'] = ';'.join(self.cookies)

        context = None
        if self.url.scheme == "wss":
            if self.insecure:
                context = ssl._create_unverified_context()
            else:
                context = ssl._create_default_context()

        coro = self.loop.create_connection(factory,
                                           self.url.hostname,
                                           self.url.port,
                                           ssl=context)
        (transport, protocol) = self.loop.run_until_complete(coro)
        LOG.debug('transport, protocol: %r, %r', transport, protocol)
Пример #5
0
    def connect(self):
        factory = WebSocketClientFactory(self.endpoint)
        factory.protocol = self.protocol
        factory.client = self
        factory.kwargs = self.kwargs
        factory.headers["X-Host-ID"] = self.host_id
        factory.headers["X-Client-Type"] = self.type
        factory.headers["X-Client-Protocol"] = "json"
        if self.persistent:
            factory.headers["X-Persistence-Policy"] = "Persistent"
        else:
            factory.headers["X-Persistence-Policy"] = "DeleteOnDisconnect"

        if self.username:
            if self.auth.login():
                cookie = 'authtok={}'.format(self.auth.authtok)
                if self.cookies:
                    self.cookies.append(cookie)
                else:
                    self.cookies = [cookie, ]

        if self.filter:
            factory.headers["X-Gremlin-Filter"] = self.filter

        if self.cookies:
            factory.headers['Cookie'] = ';'.join(self.cookies)

        context = None
        if self.url.scheme == "wss":
            if self.insecure:
                context = ssl._create_unverified_context()
            else:
                context = ssl._create_default_context()

        coro = self.loop.create_connection(factory,
                                           self.url.hostname, self.url.port,
                                           ssl=context)
        (transport, protocol) = self.loop.run_until_complete(coro)
        LOG.debug('transport, protocol: %r, %r', transport, protocol)