Пример #1
0
 def __init__(self, http_session, is_secure, url, engineIO_session=None):
     super(WebsocketTransport, self).__init__(http_session, is_secure, url,
                                              engineIO_session)
     params = dict(http_session.params, **{
         'EIO': ENGINEIO_PROTOCOL,
         'transport': 'websocket'
     })
     request = http_session.prepare_request(requests.Request('GET', url))
     kw = {'header': ['%s: %s' % x for x in request.headers.items()]}
     if engineIO_session:
         params['sid'] = engineIO_session.id
         kw['timeout'] = self._timeout = engineIO_session.ping_timeout
     ws_url = '%s://%s/?%s' % ('wss' if is_secure else 'ws', url,
                               format_query(params))
     http_scheme = 'https' if is_secure else 'http'
     if http_scheme in http_session.proxies:  # Use the correct proxy
         proxy_url_pack = parse_url(http_session.proxies[http_scheme])
         kw['http_proxy_host'] = proxy_url_pack.hostname
         kw['http_proxy_port'] = proxy_url_pack.port
         if proxy_url_pack.username:
             kw['http_proxy_auth'] = (proxy_url_pack.username,
                                      proxy_url_pack.password)
     if http_session.verify:
         if http_session.cert:  # Specify certificate path on disk
             if isinstance(http_session.cert, six.string_types):
                 kw['ca_certs'] = http_session.cert
             else:
                 kw['ca_certs'] = http_session.cert[0]
     else:  # Do not verify the SSL certificate
         kw['sslopt'] = {'cert_reqs': ssl.CERT_NONE}
     try:
         self._connection = create_connection(ws_url, **kw)
     except Exception as e:
         raise ConnectionError(e)
 def __init__(self, http_session, is_secure, url, engineIO_session=None):
     super(WebsocketTransport, self).__init__(
         http_session, is_secure, url, engineIO_session)
     params = dict(http_session.params, **{
         'EIO': ENGINEIO_PROTOCOL, 'transport': 'websocket'})
     request = http_session.prepare_request(requests.Request('GET', url))
     kw = {'header': ['%s: %s' % x for x in request.headers.items()]}
     if engineIO_session:
         params['sid'] = engineIO_session.id
         kw['timeout'] = self._timeout = engineIO_session.ping_timeout
     ws_url = '%s://%s/?%s' % (
         'wss' if is_secure else 'ws', url, format_query(params))
     http_scheme = 'https' if is_secure else 'http'
     if http_scheme in http_session.proxies:  # Use the correct proxy
         proxy_url_pack = parse_url(http_session.proxies[http_scheme])
         kw['http_proxy_host'] = proxy_url_pack.hostname
         kw['http_proxy_port'] = proxy_url_pack.port
         if proxy_url_pack.username:
             kw['http_proxy_auth'] = (
                 proxy_url_pack.username, proxy_url_pack.password)
     if http_session.verify:
         if http_session.cert:  # Specify certificate path on disk
             if isinstance(http_session.cert, six.string_types):
                 kw['ca_certs'] = http_session.cert
             else:
                 kw['ca_certs'] = http_session.cert[0]
     else:  # Do not verify the SSL certificate
         kw['sslopt'] = {'cert_reqs': ssl.CERT_NONE}
     try:
         self._connection = create_connection(ws_url, **kw)
     except Exception as e:
         raise ConnectionError(e)
Пример #3
0
def parse_host(host, port, resource):
    if not host.startswith('http'):
        host = 'http://' + host
    url_pack = parse_url(host)
    is_secure = url_pack.scheme == 'https'
    port = port or url_pack.port or (443 if is_secure else 80)
    url = '%s:%s%s/%s' % (url_pack.hostname, port, url_pack.path, resource)
    return is_secure, url
Пример #4
0
def parse_host(host, port, resource):
    if not host.startswith('http'):
        host = 'http://' + host
    url_pack = parse_url(host)
    is_secure = url_pack.scheme == 'https'
    port = port or url_pack.port or (443 if is_secure else 80)
    url = '%s:%s%s/%s' % (url_pack.hostname, port, url_pack.path, resource)
    return is_secure, url
Пример #5
0
def serve(data_folder, tool_name, result_arguments=None):
    initialize_data_types()
    response, client = _prepare_response(data_folder, tool_name,
                                         result_arguments)
    result_url = json.loads(response.data.decode('utf-8'))['result_url']
    with client.get(parse_url(result_url).path) as response:
        soup = BeautifulSoup(response.data, 'html.parser')
    return soup, client
Пример #6
0
    def __init__(self, server_url, queue_token):
        self.server_url = server_url
        self.queue_token = queue_token

        self.parent_folder = join(HOME_FOLDER, '.crosscompute',
                                  parse_url(server_url).hostname, 'results')
        self.pull_url = join(server_url, 'results', 'pull')
        self.push_url = join(server_url, 'results', 'push')
Пример #7
0
def serve(data_folder, tool_name, result_arguments=None):
    response, client = _prepare_response(
        data_folder, tool_name, result_arguments)
    assert response.status_code == 303, response.data
    result_url = parse_url(dict(response.headers)['Location']).path
    with client.get(result_url) as response:
        soup = BeautifulSoup(response.data, 'html.parser')
    return soup, client
Пример #8
0
    def __init__(self, server_url, queue_token):
        self.server_url = server_url
        self.queue_token = queue_token

        self.parent_folder = join(HOME_FOLDER, '.crosscompute', parse_url(
            server_url).hostname, 'results')
        self.pull_url = join(server_url, 'results', 'pull')
        self.push_url = join(server_url, 'results', 'push')
Пример #9
0
def serve(data_folder, tool_name, result_arguments=None):
    initialize_data_types()
    response, client = _prepare_response(
        data_folder, tool_name, result_arguments)
    result_url = json.loads(response.data.decode('utf-8'))['result_url']
    with client.get(parse_url(result_url).path) as response:
        soup = BeautifulSoup(response.data, 'html.parser')
    return soup, client
Пример #10
0
 def _set_control_link_url(self, custom_address=None):
     """Set the address to use for the Control Connection
     in such cases where Lightstreamer is behind a Load Balancer.
     """
     if custom_address is None:
         self._control_url = self._base_url
     else:
         parsed_custom_address = parse_url("//" + custom_address)
         self._control_url = parsed_custom_address._replace(
             scheme=self._base_url[0])
Пример #11
0
 def __init__(self, base_url, adapter_set="", user="", password=""):
     self._base_url = parse_url(base_url)
     self._adapter_set = adapter_set
     self._user = user
     self._password = password
     self._session = {}
     self._subscriptions = {}
     self._current_subscription_key = 0
     self._stream_connection = None
     self._stream_connection_thread = None
     self._bind_counter = 0
Пример #12
0
def parse_host(host, port, resource):
    if not host.startswith('http'):
        host = 'http://' + host
    url_pack = parse_url(host)
    is_secure = url_pack.scheme == 'https'
    port = port or url_pack.port or (443 if is_secure else 80)
    if ':' in url_pack.hostname: #Parse ipv6 per Duvallj in https://github.com/invisibleroads/socketIO-client/issues/172.
        url = '[%s]:%s%s/%s' % (url_pack.hostname, port, url_pack.path, resource)
    else:
        url = '%s:%s%s/%s' % (url_pack.hostname, port, url_pack.path, resource)
    
    return is_secure, url