예제 #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)