def __init__(self,hostName, portNumber): HTTPConnection.__init__(self, hostName, portNumber) self._hostName = hostName self._portNumber = portNumber self._commandList = []
def __init__(self, host, port = http_port_scheme.get("https"), strict = None, timeout = socket._GLOBAL_DEFAULT_TIMEOUT, source_address = None, socket_options = [(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)], key_file = None, cert_file = None, cert_reqs = 'CERT_NONE', ca_certs = None, context = None, *args, **kwargs): self.host = host self.port = port self.key_file = key_file self.cert_file = cert_file self.source_address = source_address self.socket_options = socket_options self.timeout = timeout ssl_req_scheme = { 'CERT_NONE': ssl.CERT_NONE, 'CERT_OPTIONAL': ssl.CERT_OPTIONAL, 'CERT_REQUIRED': ssl.CERT_REQUIRED } self.cert_reqs = ssl_req_scheme.get(cert_reqs) or ssl.CERT_NONE self.ca_certs = ca_certs HTTPConnection.__init__(self, self.host, self.port, self.strict, self.timeout, self.source_address) self.connect()
def __init__(self, host, port=None, key_file=None, cert_file=None, strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, source_address=None): HTTPConnection.__init__(self, host, port, strict, timeout, source_address) self.key_file = key_file self.cert_file = cert_file
def __init__(self, *args, **kwargs): '''I overrode the init and copied a lot of the code from the parent class because HTTPConnection when this happens has been replaced by VCRHTTPConnection, but doing it here lets us use the original one.''' HTTPConnection.__init__(self, *args, **kwargs) self.key_file = kwargs.pop('key_file', None) self.cert_file = kwargs.pop('cert_file', None)
def __init__(self, host, port=None, strict=None, **ssl): try: self.ssl_ctx = ssl['ssl_context'] assert isinstance(self.ssl_ctx, SSL.Context), self.ssl_ctx except KeyError: self.ssl_ctx = SSL.Context(SSL.SSLv23_METHOD) HTTPConnection.__init__(self, host, port, strict)
def __init__(self, *args, **kwargs): '''I overrode the init and copied a lot of the code from the parent class because HTTPConnection when this happens has been replaced by VCRHTTPConnection, but doing it here lets us use the original one.''' # Delete the keyword arguments that HTTPSConnection would not recognize safe_keys = set(('host', 'port', 'key_file', 'cert_file', 'strict', 'timeout', 'source_address')) unknown_keys = set(kwargs.keys()) - safe_keys safe_kwargs = kwargs.copy() for kw in unknown_keys: del safe_kwargs[kw] self.proxy_info = kwargs.pop('proxy_info', None) if not 'ca_certs' in kwargs or kwargs['ca_certs'] is None: try: import httplib2 self.ca_certs = httplib2.CA_CERTS except ImportError: self.ca_certs = None else: self.ca_certs = kwargs['ca_certs'] self.disable_ssl_certificate_validation = kwargs.pop( 'disable_ssl_certificate_validation', None) HTTPConnection.__init__(self, *args, **safe_kwargs) self.key_file = kwargs.pop('key_file', None) self.cert_file = kwargs.pop('cert_file', None)
def __init__(self, *args, **kwargs): # httplib.HTTPConnection has been replaced by ReplayHTTPConnection, # so doing it this way rather than calling through # HTTPSConnection.__init__ allows us to use the original one. self.key_file = kwargs.pop('key_file', None) self.cert_file = kwargs.pop('cert_file', None) HTTPConnection.__init__(self, *args, **kwargs) ReplayConnectionHelper.__init__(self)
def __init__(self, *args, **kwargs): # I overrode the init and copied a lot of the code from the parent # class because when this happens, HTTPConnection has been replaced # by ReplayHTTPConnection, but doing it here lets us use the original # one. HTTPConnection.__init__(self, *args, **kwargs) ReplayConnectionHelper.__init__(self) self.key_file = kwargs.pop('key_file', None) self.cert_file = kwargs.pop('cert_file', None)
def __init__(self, scheme, host, port=None, strict=None): self.scheme = scheme if scheme == 'https': self.default_port = 443 HTTPConnection.__init__(self, host, port, strict) self.key_file = None self.cert_file = None # Python 2.5 support: if not hasattr(self, 'timeout'): self.timeout = None
def __init__(self, host, port=None, strict=None, timeout=None): """Initialize the object. Args: host: the connection host. port: optional port. strict: strict connection. timeout: socket connection timeout value. """ _HC.__init__(self, host, port, strict) self._timeout = timeout or TimeoutHTTPConnection._timeout if self._timeout: self._timeout = float(self._timeout)
def __init__(self, proxy, host, port=None, username=None, password=None): # The connection goes through the proxy HTTPConnection.__init__(self, proxy) # save the proxy connection settings self.__proxy, self.__proxy_port = self.host, self.port # self.host and self.port will point to the real host self._set_hostport(host, port) # save the host and port self._host, self._port = self.host, self.port # Authenticated proxies support self.__username = username self.__password = password
def __init__(self, *args, **kwargs): '''I overrode the init because I need to clean kwargs before calling HTTPConnection.__init__.''' # Delete the keyword arguments that HTTPSConnection would not recognize safe_keys = set(('host', 'port', 'strict', 'timeout', 'source_address')) unknown_keys = set(kwargs.keys()) - safe_keys safe_kwargs = kwargs.copy() for kw in unknown_keys: del safe_kwargs[kw] self.proxy_info = kwargs.pop('proxy_info', None) HTTPConnection.__init__(self, *args, **safe_kwargs)
def __init__(self, host, port=None, strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, ssl_context=None): HTTPConnection.__init__(self, host, port, strict, timeout) if not hasattr(self, 'ssl_context'): self.ssl_context = None if ssl_context is not None: if not isinstance(ssl_context, SSL.Context): raise TypeError('Expecting OpenSSL.SSL.Context type for "' 'ssl_context" keyword; got %r instead' % ssl_context) self.ssl_context = ssl_context
def __init__(self, host, port=None, key_file=None, cert_file=None, strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, source_address=None, context=None): # Directly taken from httplib. HTTPConnection.__init__(self, host, port, strict, timeout, source_address) self.key_file = key_file self.cert_file = cert_file if context is None: context = ssl._create_default_https_context() if key_file or cert_file: context.load_cert_chain(cert_file, key_file) self._context = context
def __init__(self, host, port=None, ssl_configuration=None, strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, source_address=None): """ :Parameters: - `host`: str, the host address. - `port`: int, the port number. - `ssl_configuration`: documents.SSLConfiguration, where you specify certs files. - `strict`: bool, the strict. - `timeout`: int, the connection timeout in milliseconds. - `source_address`: str, the source address. """ HTTPConnection.__init__(self, host, port, strict, timeout, source_address) self._ssl_configuration = ssl_configuration
def __init__(self, host, port=None, strict=None, **kwargs): self.proxy_host = None self.proxy_port = None if os.environ.has_key('http_proxy'): o = urlparse(os.environ['http_proxy']) try: self.proxy_host, self.proxy_port = o[1].split(':') except: pass HTTPConnection.__init__(self, host=host, port=port, strict=strict, **kwargs)
def __init__( self, host, port=None, key_file=None, cert_file=None, strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, # pylint:disable-msg=W0212 source_address=None, ssl_ctx=None): HTTPConnection.__init__(self, host, port, strict, timeout, source_address) self.key_file = key_file self.cert_file = cert_file if ssl_ctx is None: ssl_ctx = SSL.Context(SSL.SSLv23_METHOD) if self.key_file is not None: ssl_ctx.use_privatekey_file(self.key_file) if self.cert_file is not None: ssl_ctx.use_certificate_file(self.cert_file) ssl_ctx.use_certificate_chain_file(self.cert_file) self.ssl_ctx = ssl_ctx HTTPConnection.__init__(self, host, port, strict)
def __init__(self, host, port, ssl, strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT): """ Create a new HTTPSConnection. @type host: str @param host: Host name of the server to connect to. @type port: int @param port: Port number to connect to. @type ssl: ctSSL.SSL @param ssl: SSL object for the HTTPS connection. @type timeout: int @param timeout: Socket timeout value. """ HTTPConnection.__init__(self, host, port, strict, timeout) self._ssl = ssl
def __init__(self, sock, host, port=None, strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT): ''' Constructor. It delegates construction to the base class HTTPConnection and initializes the new member variables with the default values from the Python documentation @param sock: connected sock to use @type sock: socket @param host: host to connect to @type host: str @param port: port to connect to. use None for the default HTTP port @type port: int|None @param strict: n/a @type strict: Unknown @param timeout: default time for network operations @type timeout: float ''' HTTPConnection.__init__(self, host, port, strict, timeout) self.sock = sock
def __init__(self, host, port=None, **ssl): keys = ssl.keys() try: keys.remove('key_file') except ValueError: pass try: keys.remove('cert_file') except ValueError: pass try: keys.remove('ssl_context') except ValueError: pass if keys: raise ValueError() try: self.ssl_ctx = ssl['ssl_context'] assert isinstance(self.ssl_ctx, SSL.Context) except KeyError: self.ssl_ctx = SSL.Context('sslv23') HTTPConnection.__init__(self, host, port)
def __init__(self, host, port=None, ssl=None, ssl_ctx=None, strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT): """ Create a new HTTPSConnection. @type host: str @param host: Host name of the server to connect to. @type port: int @param port: Port number to connect to. 443 by default. @type ssl: ctSSL.SSL @param ssl: SSL object for the HTTPS connection. If not specified, a default SSL object will be created for the connection and SSL certificates will NOT be verified when connecting to the server. @type ssl_ctx: ctSSL.SSL_CTX @param ssl_ctx: SSL_CTX object for the HTTPS connection. If not specified, a default SSL_CTX object will be created for the connection and SSL certificates will NOT be verified when connecting to the server. @type timeout: int @param timeout: Socket timeout value. """ HTTPConnection.__init__(self, host, port, strict, timeout) self.ssl_ctx = ssl_ctx self.ssl = ssl if self.ssl_ctx is None: self.ssl_ctx = SSL_CTX.SSL_CTX() # Can't verify certs by default self.ssl_ctx.set_verify(constants.SSL_VERIFY_NONE) if self.ssl is None: self.ssl = SSL.SSL(self.ssl_ctx)
def __init__(self, proxytype, proxyaddr, proxyport = None, rdns = True, username = None, password = None, *args, **kwargs): self.proxyargs = (proxytype, proxyaddr, proxyport, rdns, username, password) HTTPConnection.__init__(self, *args, **kwargs)
def __init__(self, module32, host='127.0.0.1', port=None, timeout=10.0, quiet=True, append_sys_path=None, append_environ_path=None, **kwargs): """Base class for communicating with a 32-bit library from 64-bit Python. Starts a 32-bit server, :class:`~.server32.Server32`, to host a Python module that is a wrapper around a 32-bit library. The *client64* module runs within a 64-bit Python interpreter and it sends a request to the server which calls the 32-bit library to execute the request. The server then provides a response back to the client. Parameters ---------- module32 : :class:`str` The name of the Python module that is to be imported by the 32-bit server. host : :class:`str`, optional The IP address of the 32-bit server. Default is ``'127.0.0.1'``. port : :class:`int`, optional The port to open on the 32-bit server. Default is :obj:`None`, which means to automatically find a port that is available. timeout : :class:`float`, optional The maximum number of seconds to wait to establish a connection to the 32-bit server. Default is 10 seconds. quiet : :class:`bool`, optional Whether to hide :obj:`sys.stdout` messages from the 32-bit server. Default is :obj:`True`. append_sys_path : :class:`str` or :class:`list` of :class:`str`, optional Append path(s) to the 32-bit server's :obj:`sys.path` variable. The value of :obj:`sys.path` from the 64-bit process is automatically included, i.e., ``sys.path(32bit) = sys.path(64bit) + append_sys_path`` Default is :obj:`None`. append_environ_path : :class:`str` or :class:`list` of :class:`str`, optional Append path(s) to the 32-bit server's :obj:`os.environ['PATH'] <os.environ>` variable. This can be useful if the library that is being loaded requires additional libraries that must be available on ``PATH``. Default is :obj:`None`. **kwargs Keyword arguments that will be passed to the :class:`~.server32.Server32` subclass. The data type of each value is not preserved. It will be a string at the constructor of the :class:`~.server32.Server32` subclass. Note ---- If `module32` is not located in the current working directory then you must either specify the full path to `module32` **or** you can specify the folder where `module32` is located by passing a value to the `append_sys_path` parameter. Using the `append_sys_path` option also allows for any other modules that `module32` may depend on to also be included in :obj:`sys.path` so that those modules can be imported when `module32` is imported. Raises ------ IOError If the frozen executable cannot be found. TypeError If the data type of `append_sys_path` or `append_environ_path` is invalid. :exc:`~msl.loadlib.utils.ConnectionTimeoutError` If the connection to the 32-bit server cannot be established. """ self._is_active = False if port is None: port = utils.get_available_port() # the temporary file to use to save the pickle'd data self._pickle_temp_file = os.path.join(tempfile.gettempdir(), str(uuid.uuid4())) # select the highest-level pickle protocol to use based on the version of python major, minor = sys.version_info.major, sys.version_info.minor if (major <= 1) or (major == 2 and minor < 3): self._pickle_protocol = 1 elif major == 2: self._pickle_protocol = 2 elif (major == 3) and (minor < 4): self._pickle_protocol = 3 else: self._pickle_protocol = pickle.HIGHEST_PROTOCOL # make sure that the server32 executable exists server_exe = os.path.join(os.path.dirname(__file__), SERVER_FILENAME) if not os.path.isfile(server_exe): raise IOError('Cannot find ' + server_exe) cmd = [ server_exe, '--module', module32, '--host', host, '--port', str(port) ] # include paths to the 32-bit server's sys.path _append_sys_path = sys.path if append_sys_path is not None: if isinstance(append_sys_path, str): _append_sys_path.append(append_sys_path.strip()) elif isinstance(append_sys_path, (list, tuple)): _append_sys_path.extend(append_sys_path) else: raise TypeError('append_sys_path must be a str, list or tuple') cmd.extend(['--append-sys-path', ';'.join(_append_sys_path).strip()]) # include paths to the 32-bit server's os.environ['PATH'] if append_environ_path is not None: if isinstance(append_environ_path, str): env_str = append_environ_path.strip() elif isinstance(append_environ_path, (list, tuple)): env_str = ';'.join(append_environ_path).strip() else: raise TypeError( 'append_environ_path must be a str, list or tuple') if env_str: cmd.extend(['--append-environ-path', env_str]) # include any keyword arguments if kwargs: kw_str = ';'.join('{}={}'.format(key, value) for key, value in kwargs.items()) cmd.extend(['--kwargs', kw_str]) if quiet: cmd.append('--quiet') # start the server, cannot use subprocess.call() because it blocks subprocess.Popen(cmd, stderr=sys.stderr, stdout=sys.stderr) utils.wait_for_server(host, port, timeout) # start the connection HTTPConnection.__init__(self, host, port) self._is_active = True self._lib32_path = self.request32('LIB32_PATH')
def __init__(self, *args, **kwargs): HTTPConnection.__init__(self, *args, **kwargs) ReplayConnectionHelper.__init__(self)
def __init__(self, host, port=None, strict=None, connection_timeout=60): HTTPConnection.__init__(self, host, port, strict) self.request_length = 0 self.connection_timeout = connection_timeout
def __init__(self, host, port, timeout): HTTPConnection.__init__(self, host, port) self.timeout = timeout
def __init__(self, host, port=None, strict=None): HTTPConnection.__init__(self, host, port, strict) self.request_length = 0
def __init__(self, path): HTTPConnection.__init__(self, 'localhost') self.path = path
def __init__(self, *args, **kwargs): HTTPConnection.__init__(self, *args, **kwargs) # see VCRConnectionMixin._restore_socket for the motivation here del self.sock
def __init__(self, path): HTTPConnection.__init__(self, 'localhost', 0) self.unix_socket = path
def __init__(self, host, port=None, timeout=20): HTTPConnection.__init__(self, host, port) self.timeout = timeout
def __init__(self, *args, **kwargs): self.ss_client = kwargs.pop('ss_client') HTTPConnection.__init__(self, *args, **kwargs)
def __init__(self, host, **kw): self.user, self.host = host.split('@') HTTPConnection.__init__(self, self.host, **kw)
def __init__(self, *args, **kwargs): HTTPConnection.__init__(self, *args, **kwargs) self.__getTransaction()
def __init__(self, rfile=sys.stdin, wfile=sys.stdout): self.rfile = rfile self.wfile = wfile BaseHTTPConnection.__init__(self, "stdio")
def __init__(self, *args, **kwargs): HTTPConnection.__init__(self, *args, **kwargs) self.headers = {}
def __init__(self, *args, **kwargs): HTTPConnection.__init__(self, *args, **kwargs) self._canceled = False self.deadline = 0
def __init__(self, rfile, wfile): HTTPConnection.__init__(self, 'localhost') self.rfile = rfile self.wfile = wfile
def __init__(self, module32, host='127.0.0.1', port=None, timeout=10.0, quiet=True, append_path=None): self._is_active = False if port is None: # then find a port that is not being used while True: port = random.randint(1024, 65535) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(0.01) if s.connect_ex((host, port)) != 0: s.close() break s.close() # the temporary file to use to save the pickle'd data self._pickle_temp_file = os.path.join(tempfile.gettempdir(), str(uuid.uuid4())) # select the highest-level pickle protocol to use based on the version of python major, minor = sys.version_info.major, sys.version_info.minor if (major <= 1) or (major == 2 and minor < 3): self._pickle_protocol = 1 elif major == 2: self._pickle_protocol = 2 elif (major == 3) and (minor < 4): self._pickle_protocol = 3 else: self._pickle_protocol = pickle.HIGHEST_PROTOCOL # make sure that the server32 executable exists found_server = False for name in os.listdir(os.path.dirname(__file__)): if SERVER_FILENAME in name: found_server = True break if not found_server: msg = 'Cannot find {}\n'.format( os.path.join(os.path.dirname(__file__), SERVER_FILENAME)) msg += 'To create a 32-bit Python server run:\n' msg += '>>> from msl.loadlib import freeze_server32\n' msg += '>>> freeze_server32.main()' raise IOError(msg) cmd = [ os.path.join(os.path.dirname(__file__), SERVER_FILENAME), '--module', module32, '--host', host, '--port', str(port) ] # include folders to the 32-bit server's sys.path _append_path = site.getsitepackages() if append_path is not None: if isinstance(append_path, str): _append_path.append(append_path) else: _append_path.extend(append_path) cmd.extend(['--append-path', '[' + ','.join(_append_path) + ']']) if quiet: cmd.append('--quiet') # start the server, cannot use subprocess.call() because it blocks subprocess.Popen(cmd, stderr=sys.stderr, stdout=sys.stderr) # wait for the server to be running -- essentially this is the subprocess.wait() method t = 0.0 socket_timeout = 0.02 while t < timeout: s = socket.socket(socket.AF_INET) s.settimeout(socket_timeout) if s.connect_ex((host, port)) == 0: s.close() break s.close() t += socket_timeout if t >= timeout: msg = 'Timeout after {:.1f} seconds. Cannot connect to {}:{}'.format( t, host, port) raise HTTPException(msg) # start the connection HTTPConnection.__init__(self, host, port) self._is_active = True
def __init__(self, host, *fakedata): HTTPConnection.__init__(self, host) self.fakedata = list(fakedata)
def __init__(self, host, port=None, strict=None, timeout=None): HTTPConnection.__init__(self, host, port, strict) self._timeout = timeout
def __init__(self, *args, **kwargs): HTTPConnection.__init__(self, *args, **kwargs)
def __init__(self, host, port=None, strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT): self.host = host #'128.0.0.100' self.port = 9191 HTTPConnection.__init__(self,host, port, strict, timeout);
def __init__(self, host, port=None, strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT): self.host = '128.0.0.100' self.port = 9191 HTTPConnection.__init__(self,host, port, strict, timeout);
def __init__(self, path): HTTPConnection.__init__(self, '127.0.0.1') self.path = path
def __init__(self, *args, **kwargs): HTTPConnection.__init__(self, *args, **kwargs) self.response_class = MyResponse
def __init__(self, host, time_out): HTTPConnection.__init__(self, host, timeout=time_out)
def __init__(self, *args, **kwargs): self.tls = kwargs.pop('tls', None) HTTPConnection.__init__(self, *args, **kwargs)
def __init__(self, path, *args, **kwargs): HTTPConnection.__init__(self, *args, **kwargs) self.path = path