Пример #1
0
def connectDeviceHive(device_hive_url, factory):
    """
    Connects a DeviceHive client.
    
    @type device_hive_url: C{str}
    @param device_hive_url: 
    
    @type factory: C{object}
    @param factory: a factory object which implements C{IProtoFactory} interface.
    """
    url, host, port = parse_url(device_hive_url)
    factory.url = url
    factory.host = host
    factory.port = port
    return reactor.connectTCP(host, port, factory)
Пример #2
0
def connectDeviceHive(device_hive_url, factory):
    """
    Connects a DeviceHive client.
    
    @type device_hive_url: C{str}
    @param device_hive_url: 
    
    @type factory: C{object}
    @param factory: a factory object which implements C{IProtoFactory} interface.
    """
    url, host, port = parse_url(device_hive_url)
    factory.url  = url
    factory.host = host
    factory.port = port
    return reactor.connectTCP(host, port, factory)
Пример #3
0
 def api_received(self, wsurl, server_time):
     log.msg('The call to "/info" api has finished successfully.')
     try :
         self.server_time = parse_date(server_time)
     except ValueError :
         log.msg('Failed to parse a date-time string "{0}" returned from "/info" api call.'.format(server_time))
         self.server_time = datetime.utcnow()
     if wsurl is not None :
         wsurl = wsurl.strip().replace('ws://', 'http://', 1).replace('wss://', 'https://', 1)
         if wsurl.startswith('http://') or wsurl.startswith('https://') :
             self.ws_url, self.ws_host, self.ws_port = parse_url(wsurl)
             self.handler.on_apimeta(wsurl, self.server_time)
             self.connect_ws()
             return
     self.handler.on_apimeta(wsurl, self.server_time)
     self.connect_poll()
 def api_received(self, wsurl, server_time):
     log.msg('The call to "/info" api has finished successfully.')
     try:
         self.server_time = parse_date(server_time)
     except ValueError:
         log.msg(
             'Failed to parse a date-time string "{0}" returned from "/info" api call.'
             .format(server_time))
         self.server_time = datetime.utcnow()
     if wsurl is not None:
         wsurl = wsurl.strip().replace('ws://', 'http://',
                                       1).replace('wss://', 'https://', 1)
         if wsurl.startswith('http://') or wsurl.startswith('https://'):
             self.ws_url, self.ws_host, self.ws_port = parse_url(wsurl)
             self.handler.on_apimeta(wsurl, self.server_time)
             self.connect_ws()
             return
     self.handler.on_apimeta(wsurl, self.server_time)
     self.connect_poll()
Пример #5
0
def connectDeviceHive(device_hive_url, factory):
    """
    Connects a DeviceHive client.
    
    @type device_hive_url: C{str}
    @param device_hive_url: 
    
    @type factory: C{object}
    @param factory: a factory object which implements C{IProtoFactory} interface.
    """
    url, host, port = parse_url(device_hive_url)
    factory.url = url
    factory.host = host
    factory.port = port
    if url.startswith('http://'):
        log.msg('Establishing NON-SECURE connection with {0}.'.format(url))
        reactor.connectTCP(host, port, factory)
    else:
        ccf = ssl.ClientContextFactory()
        ccf.method = SSL.SSLv23_METHOD
        log.msg('Establishing SECURE connection with {0}.'.format(url))
        reactor.connectSSL(host, port, factory, ccf)
Пример #6
0
def connectDeviceHive(device_hive_url, factory):
    """
    Connects a DeviceHive client.
    
    @type device_hive_url: C{str}
    @param device_hive_url: 
    
    @type factory: C{object}
    @param factory: a factory object which implements C{IProtoFactory} interface.
    """
    url, host, port = parse_url(device_hive_url)
    factory.url = url
    factory.host = host
    factory.port = port
    if url.startswith('http://'):
        log.msg('Establishing NON-SECURE connection with {0}.'.format(url))
        reactor.connectTCP(host, port, factory)
    else:
        ccf = ssl.ClientContextFactory()
        ccf.method = SSL.SSLv23_METHOD
        log.msg('Establishing SECURE connection with {0}.'.format(url))
        reactor.connectSSL(host, port, factory, ccf)
Пример #7
0
 def test_normal_parse_url(self):
     url, host, port = utils.parse_url('http://example.com/api/')
     self.assertEquals('http://example.com/api/', url)
     self.assertEquals('example.com', host)
     self.assertEquals(80, port)
Пример #8
0
 def test_redef_ssl_port_parse_url(self):
     url, host, port = utils.parse_url('https://example.com:9191/api/')
     self.assertEquals('https://example.com:9191/api/', url)
     self.assertEquals('example.com', host)
     self.assertEquals(9191, port)
Пример #9
0
 def test_default_ssl_port_parse_url(self):
     url, host, port = utils.parse_url('https://example.com/api')
     self.assertEquals('https://example.com/api/', url)
     self.assertEquals('example.com', host)
     self.assertEquals(443, port)
Пример #10
0
 def test_def_port_parse_url(self):
     url, host, port = utils.parse_url('http://example.com:8181/api')
     self.assertEquals('http://example.com:8181/api/', url)
     self.assertEquals('example.com', host)
     self.assertEquals(8181, port)
Пример #11
0
 def test_normal_parse_url(self):
     url, host, port = utils.parse_url('http://example.com/api/')
     self.assertEquals('http://example.com/api/', url)
     self.assertEquals('example.com', host)
     self.assertEquals(80, port)
Пример #12
0
 def test_redef_ssl_port_parse_url(self):
     url, host, port = utils.parse_url('https://example.com:9191/api/')
     self.assertEquals('https://example.com:9191/api/', url)
     self.assertEquals('example.com', host)
     self.assertEquals(9191, port)
Пример #13
0
 def test_default_ssl_port_parse_url(self):
     url, host, port = utils.parse_url('https://example.com/api')
     self.assertEquals('https://example.com/api/', url)
     self.assertEquals('example.com', host)
     self.assertEquals(443, port)
Пример #14
0
 def test_def_port_parse_url(self):
     url, host, port = utils.parse_url('http://example.com:8181/api')
     self.assertEquals('http://example.com:8181/api/', url)
     self.assertEquals('example.com', host)
     self.assertEquals(8181, port)