Ejemplo n.º 1
0
    def __init__(self, uri, cookiejar=None, use_datetime=0):
        Transport.__init__(self, use_datetime=use_datetime)

        self.opener = build_opener()

        # Parse auth (user:passwd) from the uri
        urltype, rest = splittype(uri)
        host, rest = splithost(rest)
        auth, host = splituser(host)
        self.uri = urltype + '://' + host + rest

        # Handle HTTP Basic authentication
        if auth is not None:
            user, passwd = splitpasswd(auth)
            passwdmgr = HTTPPasswordMgrWithDefaultRealm()
            passwdmgr.add_password(realm=None,
                                   uri=self.uri,
                                   user=user,
                                   passwd=passwd)
            authhandler = HTTPBasicAuthHandler(passwdmgr)
            self.opener.add_handler(authhandler)

        # Handle HTTP Cookies
        if cookiejar is not None:
            self.opener.add_handler(HTTPCookieProcessor(cookiejar))
Ejemplo n.º 2
0
    def __init__(self, username, password, verbose=0, use_datetime=False,
                 https_handler=None):
        Transport.__init__(self, use_datetime=False)
        self._username = username
        self._password = password
        self._use_datetime = use_datetime
        self.verbose = verbose
        self._username = username
        self._password = password

        self._handlers = []

        if self._username and self._password:
            self._passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
            self._auth_handler = urllib2.HTTPDigestAuthHandler(self._passmgr)
        else:
            self._auth_handler = None
            self._passmgr = None

        if https_handler:
            self._handlers.append(https_handler)
            self._scheme = 'https'
        else:
            self._scheme = 'http'

        if self._auth_handler:
            self._handlers.append(self._auth_handler)
Ejemplo n.º 3
0
    def __init__(self,
                 username,
                 password,
                 verbose=0,
                 use_datetime=False,
                 https_handler=None):
        Transport.__init__(self, use_datetime=False)
        self._username = username
        self._password = password
        self._use_datetime = use_datetime
        self.verbose = verbose
        self._username = username
        self._password = password

        self._handlers = []

        if self._username and self._password:
            self._passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
            self._auth_handler = urllib2.HTTPDigestAuthHandler(self._passmgr)
        else:
            self._auth_handler = None
            self._passmgr = None

        if https_handler:
            self._handlers.append(https_handler)
            self._scheme = 'https'
        else:
            self._scheme = 'http'

        if self._auth_handler:
            self._handlers.append(self._auth_handler)
Ejemplo n.º 4
0
    def __init__(self, socket):
        Transport.__init__(self)

        def connect(self):
            self.sock = socket

        connection = httplib.HTTPConnection
        connection.connect = connect
Ejemplo n.º 5
0
    def __init__(self, socket):
        Transport.__init__(self)

        def connect(self):
            self.sock = socket

        connection = httplib.HTTPConnection
        connection.connect = connect
Ejemplo n.º 6
0
 def __init__(self, endpoint, cookie_jar=None):
     Transport.__init__(self, use_datetime=True)
     self.scheme, self.host = urlparse(endpoint)[:2]
     assert self.scheme in ('http', 'https'), (
         "Unsupported URL scheme: %s" % self.scheme)
     if cookie_jar is None:
         cookie_jar = RequestsCookieJar()
     self.cookie_jar = cookie_jar
     self.timeout = config.checkwatches.default_socket_timeout
Ejemplo n.º 7
0
    def __init__(self, language=None, user_agent=None):
        self.language = language or Settings.LANGUAGE
        self.token = None
        self.user_agent = user_agent or os.getenv('OS_USER_AGENT') or Settings.USER_AGENT

        transport = Transport()
        transport.user_agent = self.user_agent

        self.xmlrpc = ServerProxy(Settings.OPENSUBTITLES_SERVER,
                                  allow_none=True, transport=transport)
Ejemplo n.º 8
0
 def __init__(self, endpoint, cookie_jar=None):
     Transport.__init__(self, use_datetime=True)
     self.scheme, self.host = urlparse(endpoint)[:2]
     assert self.scheme in ('http', 'https'), (
         "Unsupported URL scheme: %s" % self.scheme)
     self.cookie_processor = HTTPCookieProcessor(cookie_jar)
     self.redirect_handler = XMLRPCRedirectHandler()
     self.opener = build_opener(
         self.cookie_processor, self.redirect_handler)
     self.timeout = config.checkwatches.default_socket_timeout
Ejemplo n.º 9
0
 def __init__(self, endpoint, cookie_jar=None):
     Transport.__init__(self, use_datetime=True)
     self.scheme, self.host = urlparse(endpoint)[:2]
     assert self.scheme in ('http',
                            'https'), ("Unsupported URL scheme: %s" %
                                       self.scheme)
     self.cookie_processor = HTTPCookieProcessor(cookie_jar)
     self.redirect_handler = XMLRPCRedirectHandler()
     self.opener = build_opener(self.cookie_processor,
                                self.redirect_handler)
     self.timeout = config.checkwatches.default_socket_timeout
Ejemplo n.º 10
0
    def __init__(self, language="en", user_agent="TemporaryUserAgent"):
        self._token = None
        self.language = language
        self.user_agent = user_agent

        transport = Transport()
        transport.user_agent = self.user_agent

        self._server = ServerProxy(self.API_XMLRPC,
                                   allow_none=True,
                                   transport=transport)
Ejemplo n.º 11
0
    def __init__(self, ca_certs=None, keyfile=None, certfile=None, cert_reqs=None,
                 ssl_version=None, timeout=None, strict=None):

        self.ca_certs = ca_certs
        self.keyfile = keyfile
        self.certfile = certfile
        self.cert_reqs = cert_reqs
        self.ssl_version = ssl_version
        self.timeout = timeout
        self.strict = strict

        Transport.__init__(self)
Ejemplo n.º 12
0
    def __init__(self, ca_certs=None, keyfile=None, certfile=None, cert_reqs=None,
                 ssl_version=None, timeout=None, strict=None):

        self.ca_certs = ca_certs
        self.keyfile = keyfile
        self.certfile = certfile
        self.cert_reqs = cert_reqs
        self.ssl_version = ssl_version
        self.timeout = timeout
        self.strict = strict

        Transport.__init__(self)
Ejemplo n.º 13
0
 def make_connection(self, host):
   try:
     if self._scheme == 'http':
       return Transport.make_connection(self, host)
     return SafeTransport.make_connection(self, host)
   except socket.error, e:
     raise ProtocolError(host, -1, "Could not connect to server", None)
Ejemplo n.º 14
0
    def get_host_info(self, host):
        host, extra_headers, x509 = Transport.get_host_info(self,host)
        if extra_headers == None:
                extra_headers = []

        extra_headers.append( ( 'Connection', 'keep-alive' ))

        return host, extra_headers, x509
Ejemplo n.º 15
0
    def __init__(self,
                 user_agent=DEFAULT_USER_AGENT,
                 username=None,
                 password=None):

        self.user_agent = user_agent
        self.username = username
        self.password = password

        transport = Transport()
        transport.user_agent = self.user_agent

        self.xmlrpc = ServerProxy(API_URL,
                                  allow_none=True,
                                  transport=transport)

        self._token = None
Ejemplo n.º 16
0
    def get_host_info(self, host):
        host, extra_headers, x509 = Transport.get_host_info(self, host)
        if extra_headers == None:
            extra_headers = []

        extra_headers.append(('Connection', 'keep-alive'))

        return host, extra_headers, x509
Ejemplo n.º 17
0
    def __init__(self, key_file, cert_file):
        Transport.__init__(self)
        self.key_file = key_file
        self.cert_file = cert_file

        # in pyth version 2.7 upwards, the xmlrpclib.Transport library seems
        # to re-use connections or for some other reason likes to store the
        # connection in self._connection.  This version is designed to work
        # with both without clobbering either.  This is potentially brittle
        # code, so we check the python version so we can revise things if
        # neccessary

        if sys.version_info[0] == 2 and sys.version_info[1] not in (6,7):
            sys.stderr.write("SaferTransport implementation has not been " + \
                    "checked in this version.  Please check to make sure " + \
                    "it still works\n")

        self._connection = (None, None)
Ejemplo n.º 18
0
    def __init__(self, realm, url, username=None, password=None, **kwds):
        """
        Initialization.

        EXAMPLES::

            sage: from trac_interface import REALM, TRAC_SERVER_URI, DigestTransport
            sage: type(DigestTransport(REALM, TRAC_SERVER_URI+"/xmlrpc"))
            trac_interface.DigestTransport

        """
        Transport.__init__(self, **kwds)

        authhandler = urllib2.HTTPDigestAuthHandler()
        if username and password:
            authhandler.add_password(realm, url, username, password)

        self.opener = urllib2.build_opener(authhandler)
Ejemplo n.º 19
0
class xmlrpc_connection(object):
    def __init__(self, host=None, port=8182):
        if host is None:
            host = gethostname()
        self.host = "%s:%s" % (host, port)
        self.transport = Transport()

    def remote(self, method, params=()):
        """ Invoke the server with the given method name and parameters.
            The return value is always a tuple. """
        return self.transport.request(self.host, "/RPC2", dumps(params, method))
Ejemplo n.º 20
0
    def __init__(self, language=None, user_agent=None):
        """
        Initialize the OpenSubtitles client

        :param language: language for login
        :param user_agent: User Agent to include with requests.
            Can be specified here, via the OS_USER_AGENT environment variable,
            or via Settings.USER_AGENT (default)

            For more information: http://trac.opensubtitles.org/projects/opensubtitles/wiki/DevReadFirst#Howtorequestanewuseragent
        """
        self.language = language or Settings.LANGUAGE
        self.token = None
        self.user_agent = user_agent or os.getenv('OS_USER_AGENT') or Settings.USER_AGENT

        transport = Transport()
        transport.user_agent = self.user_agent

        self.xmlrpc = ServerProxy(Settings.OPENSUBTITLES_SERVER,
                                  allow_none=True, transport=transport)
Ejemplo n.º 21
0
    def getparser(self):
        parser, unmarshaller = Transport.getparser(self)
        dispatch = unmarshaller.dispatch.copy()
        unmarshaller.dispatch = dispatch
        # Now we can add custom types
        dispatch["ex:nil"] = dispatch["nil"]
        dispatch["ex:i2"]  = dispatch["int"]
        dispatch["ex:i4"]  = dispatch["int"]
        dispatch["ex:i8"]  = dispatch["int"]
 
        return parser, unmarshaller                                                                                                                                                                                                                                                                                                                              
    def getparser(self):
        parser, unmarshaller = Transport.getparser(self)
        dispatch = unmarshaller.dispatch.copy()
        unmarshaller.dispatch = dispatch
        # Now we can add custom types
        dispatch["ex:nil"] = dispatch["nil"]
        dispatch["ex:i2"] = dispatch["int"]
        dispatch["ex:i4"] = dispatch["int"]
        dispatch["ex:i8"] = dispatch["int"]

        return parser, unmarshaller
Ejemplo n.º 23
0
    def make_connection(self, host):
        self.host = host
        if self.proxy:
            host = self.proxy.split('://', 1)[-1]
        if self.https:
            c = SafeTransport.make_connection(self, host)
        else:
            c = Transport.make_connection(self, host)

        c.timeout = self.timeout

        return c
Ejemplo n.º 24
0
class xmlrpc_connection(object):
    def __init__(self, host=None, port=8182):
        if host is None:
            host = gethostname()
        self.host = "%s:%s" % (host, port)
        self.transport = Transport()

    def remote(self, method, params=()):
        """ Invoke the server with the given method name and parameters.
            The return value is always a tuple. """
        return self.transport.request(self.host, '/RPC2',
                                      dumps(params, method))
Ejemplo n.º 25
0
	def __init__(self, uri, cookiejar=None, use_datetime=0):
		Transport.__init__(self, use_datetime=use_datetime)

		self.opener = build_opener()

		# Parse auth (user:passwd) from the uri
		urltype, rest = splittype(uri)
		host, rest = splithost(rest)
		auth, host = splituser(host)
		self.uri = urltype + '://' + host + rest

		# Handle HTTP Basic authentication
		if auth is not None:
			user, passwd = splitpasswd(auth)
			passwdmgr = HTTPPasswordMgrWithDefaultRealm()
			passwdmgr.add_password(realm=None, uri=self.uri, user=user, passwd=passwd)
			authhandler = HTTPBasicAuthHandler(passwdmgr)
			self.opener.add_handler(authhandler)

		# Handle HTTP Cookies
		if cookiejar is not None:
			self.opener.add_handler(HTTPCookieProcessor(cookiejar))
Ejemplo n.º 26
0
    def get_host_info(self, host):
        (host, extra_headers, x509) = Transport.get_host_info(self, host)

        try:
            lang = locale.setlocale(locale.LC_ALL, '').split('.')[0].lower()
        except locale.Error:
            # fallback to default locale
            lang = 'en_us'

        if not isinstance(extra_headers, list):
            extra_headers = []

        extra_headers.append(('Accept-Language', lang.replace('_', '-')))
        extra_headers.append(('Referer', 'https://%s/ipa/xml' % str(host)))

        return (host, extra_headers, x509)
 def make_connection(self, host):
     self.realhost = host
     proxies = urllib.getproxies()
     proxyurl = None
     if 'http' in proxies:
         proxyurl = proxies['http']
     elif 'all' in proxies:
         proxyurl = proxies['all']
     if proxyurl:
         urltype, proxyhost = urllib.splittype(proxyurl)
         host, selector = urllib.splithost(proxyhost)
         h = httplib.HTTP(host)
         self.proxy_is_used = True
         return h
     else:
         self.proxy_is_used = False
         return Transport.make_connection(self, host)
Ejemplo n.º 28
0
 def make_connection(self, host):
     self.realhost = host
     proxies = urllib.getproxies()
     proxyurl = None
     if 'http' in proxies:
         proxyurl = proxies['http']
     elif 'all' in proxies:
         proxyurl = proxies['all']
     if proxyurl:
         urltype, proxyhost = urllib.splittype(proxyurl)
         host, selector = urllib.splithost(proxyhost)
         h = httplib.HTTP(host)
         self.proxy_is_used = True
         return h
     else:
         self.proxy_is_used = False
         return Transport.make_connection(self, host)
Ejemplo n.º 29
0
class xmlrpc_connection:
    """The xmlrpc_connection class tests the xmlrpc_server.  You must 
    download and install the medusa and xmlrpclib libraries to run 
    this code:  http://www.nightmare.com  http://www.pythonware.com"""
    def __init__(self, host=None, port=2640):
        if host is None:
            host = gethostname()
        self.host = "%s:%s" % (host, port)
        self.transport = Transport()

    def remote(self, method, params=()):
        """remote invokes the server with the method name and an 
        optional set of parameters.  The return value is always a
        tuple."""

        response = self.transport.request(self.host, '/RPC2',
                                          dumps(params, method))
        return response
Ejemplo n.º 30
0
    def get_host_info(self, host):
        (host, extra_headers, x509) = Transport.get_host_info(self, host)

        try:
            lang = locale.setlocale(locale.LC_ALL, '').split('.')[0].lower()
        except locale.Error:
            # fallback to default locale
            lang = 'en_us'

        if not isinstance(extra_headers, list):
            extra_headers = []

        extra_headers.append(
            ('Accept-Language', lang.replace('_', '-'))
        )
        extra_headers.append(
            ('Referer', 'https://%s/ipa/xml' % str(host))
        )

        return (host, extra_headers, x509)
Ejemplo n.º 31
0
class xmlrpc_connection:
    """The xmlrpc_connection class tests the xmlrpc_server.  You must 
    download and install the medusa and xmlrpclib libraries to run 
    this code:  http://www.nightmare.com  http://www.pythonware.com"""

    def __init__(self, host=None, port=8182):
        if host is None:
            host = gethostname()
        self.host = "%s:%s" % (host, port)
        self.transport = Transport()

    def remote(self, method, params=()):
        """remote invokes the server with the method name and an 
        optional set of parameters.  The return value is always a
        tuple."""

        response = self.transport.request(self.host, 
                                          '/RPC2',
                                          dumps(params, method))
        return response
Ejemplo n.º 32
0
 def __init__(self, timeout, *args, **kwargs):
     Transport.__init__(self, *args, **kwargs)
     self.timeout = timeout
Ejemplo n.º 33
0
 def make_connection(self, host):    
     conn = Transport.make_connection(self, host)
     conn.timeout = self._timeout
     return conn
Ejemplo n.º 34
0
 def __init__(self):
     TransportMixIn.__init__(self)
     XMLTransport.__init__(self)
Ejemplo n.º 35
0
 def make_connection(self, host):
     """Create the connection for the transport and save it."""
     self.conn = Transport.make_connection(self, host)
     return self.conn
Ejemplo n.º 36
0
    def __init__(self, realm, url, username, password, **kwds):
        Transport.__init__(self, **kwds)

        authhandler = urllib2.HTTPDigestAuthHandler()
        authhandler.add_password(realm, url, username, password)
        self.opener = urllib2.build_opener(authhandler)
Ejemplo n.º 37
0
 def __init__(self, http_client):
     Transport.__init__(self)
     self.httpClient = http_client
     self.protocol = http_client.getProperty('protocol')
     self.recordLog = False
Ejemplo n.º 38
0
 def __init__(self, *args, **kwargs):
     Transport.__init__(self)
     self.protocol = kwargs.get('protocol', None)
Ejemplo n.º 39
0
 def __init__(self, *args, **kwargs):
     Transport.__init__(self, *args, **kwargs)
     self.client = Client()
Ejemplo n.º 40
0
 def send_request(self, connection, handler, request_body):
     set_custom_timeout(connection, request_body)
     Transport.send_request(self, connection, handler, request_body)
 def send_request(self, connection, handler, request_body):
     if self.proxy_is_used:
         connection.putrequest("POST", 'http://%s%s' % (self.realhost, handler))
     else:
         Transport.send_request(self, connection, handler, request_body)
 def send_host(self, connection, host):
     if self.proxy_is_used:
         connection.putheader('Host', self.realhost)
     else:
         Transport.send_host(self, connection, host)
Ejemplo n.º 43
0
 def __init__(self, protocol):
     Transport.__init__(self)
     self.protocol = protocol
Ejemplo n.º 44
0
 def send_request(self, connection, handler, request_body):
     handler = '%s://%s%s' % (self.scheme, self.host, handler)
     Transport.send_request(self, connection, handler, request_body)
Ejemplo n.º 45
0
 def __init__(self, protocol):
     Transport.__init__(self)
     self.protocol = protocol
Ejemplo n.º 46
0
    def make_connection(self, host):
        c = Transport.make_connection(self, host)
        c.timeout = self.timeout

        return c
Ejemplo n.º 47
0
    def __init__(self, *l, **kw):
        self.timeout = kw.get('timeout', 10)
        if 'timeout' in kw.keys():
            del kw['timeout']

        Transport.__init__(self, *l, **kw)
Ejemplo n.º 48
0
 def __init__(self, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, *args, **kwargs):
     Transport.__init__(self, *args, **kwargs)
     self._timeout = timeout
Ejemplo n.º 49
0
 def __init__(self, *args, **kwargs):
     Transport.__init__(self, *args, **kwargs)
     self.client = Client()
Ejemplo n.º 50
0
    def __init__(self, *l, **kw):
        self.timeout = kw.get('timeout', 10)
        if 'timeout' in kw.keys():
            del kw['timeout']

        Transport.__init__(self, *l, **kw)
Ejemplo n.º 51
0
 def __init__(self):
     Transport.__init__(self, use_datetime=0)
Ejemplo n.º 52
0
 def getparser(self):
     if self.protocol == 'json':
         parser = DummyParser()
         return parser, parser
     else:
         return Transport.getparser(self)
Ejemplo n.º 53
0
 def send_user_agent(self, connection):
     if self.session:          
         connection.putheader("Cookie", self.session)
     print self.session
     return Transport.send_user_agent(self, connection)
Ejemplo n.º 54
0
 def request(self, host, handler, request_body, verbose=0):
     """Make the request but using the with_timeout decorator."""
     return Transport.request(self, host, handler, request_body, verbose)
Ejemplo n.º 55
0
Archivo: rpc.py Proyecto: stlaz/freeipa
 def __init__(self, *args, **kwargs):
     Transport.__init__(self)
     self.protocol = kwargs.get('protocol', None)
Ejemplo n.º 56
0
 def __init__(self, host=None, port=8182):
     if host is None:
         host = gethostname()
     self.host = "%s:%s" % (host, port)
     self.transport = Transport()
Ejemplo n.º 57
0
 def make_connection(self, host):
     """Create the connection for the transport and save it."""
     self.conn = Transport.make_connection(self, host)
     return self.conn
Ejemplo n.º 58
0
 def getparser(self):
     if self.protocol == 'json':
         parser = DummyParser()
         return parser, parser
     else:
         return Transport.getparser(self)
Ejemplo n.º 59
0
 def request(self, host, handler, request_body, verbose=0):
     """Make the request but using the with_timeout decorator."""
     return Transport.request(
         self, host, handler, request_body, verbose)