示例#1
0
 def __init__(self, uri, transport=None, encoding=None, verbose=0,
                    use_datetime=0):
     import urllib
     protocol, uri = urllib.splittype(uri)
     if transport is None:
         if protocol == 'http':
             self.__transport = Transport(use_datetime)
         elif protocol == 'https':
             self.__transport = SafeTransport(use_datetime)
         else:
             raise IOError("unsupported XML-RPC protocol")
     else:
         self.__transport = transport
     self.__host, self.__handler = urllib.splithost(uri)
     self.__handler = self.__handler or '/RPC2'
     self.__encoding = encoding or 'utf-8'
     if self.__encoding == 'utf-8':
         xmlheader = "<?xml version='1.0'?>\n"
     else:
         xmlheader_template = "<?xml version='1.0' encoding='%s'?>\n"
         xmlheader = xmlheader_template % str(self.__encoding)
     if FastMarshaller:
         self.__marshaller = FastMarshaller(self.__encoding)
     else:
         self.__marshaller = Marshaller(self.__encoding, allow_none=True)
     method_call_template = \
         '%s<methodCall>\n<methodName>%%s</methodName>\n%%s</methodCall>'
     method_response_template = \
         '%s<methodResponse>\n%%s</methodResponse>'
     self.__method_call_template = method_call_template % (xmlheader)
     self.__method_response_template = method_response_template % (xmlheader)
示例#2
0
    def __init__(self, **kwds):
        """
        Initialization.

        EXAMPLES::

            sage: type(sage.dev.trac_interface.DigestTransport())
            <class 'sage.dev.trac_interface.DigestTransport'>
            sage: type(sage.dev.trac_interface.DigestTransport(realm='realm',
            ....:         url='url', username='******', password='******'))
            <class 'sage.dev.trac_interface.DigestTransport'>
        """
        def get_pop(this, k, d=None):
            try:
                return this.pop(k)
            except KeyError:
                return d

        auth = tuple(get_pop(kwds, x) for x in
                ('realm', 'url', 'username', 'password'))

        SafeTransport.__init__(self, **kwds)

        authhandler = urllib2.HTTPDigestAuthHandler()
        if all(x is not None for x in auth):
            authhandler.add_password(*auth)

        self.opener = urllib2.build_opener(authhandler)
示例#3
0
 def __init__(self, timeout=None, scheme='http'):
   SafeTransport.__init__(self)
   transport_class = Transport if scheme == 'http' else SafeTransport
   def make_connection(*args, **kw):
     connection = transport_class.make_connection(self, *args, **kw)
     if timeout is not None:
       connection.timeout = timeout
     return connection
   self.make_connection = make_connection
示例#4
0
 def __init__(self, timeout=None, scheme='http'):
   SafeTransport.__init__(self)
   transport_class = Transport if scheme == 'http' else SafeTransport
   def make_connection(*args, **kw):
     connection = transport_class.make_connection(self, *args, **kw)
     if timeout is not None:
       # BBB: On Python < 2.7, HTTP connection is wrapped
       getattr(connection, '_conn', connection).timeout = timeout
     return connection
   self.make_connection = make_connection
示例#5
0
    def __init__(self, timeout=None, scheme='http'):
        SafeTransport.__init__(self)
        transport_class = Transport if scheme == 'http' else SafeTransport

        def make_connection(*args, **kw):
            connection = transport_class.make_connection(self, *args, **kw)
            if timeout is not None:
                # BBB: On Python < 2.7, HTTP connection is wrapped
                getattr(connection, '_conn', connection).timeout = timeout
            return connection

        self.make_connection = make_connection
示例#6
0
    def __init__(self):
        """
        Initialization.

        EXAMPLES::

            sage: from sage.dev.digest_transport import DigestTransport
            sage: type(DigestTransport())
            <class 'sage.dev.digest_transport.DigestTransport'>
        """
        SafeTransport.__init__(self)
        self._opener = None
示例#7
0
    def __init__(self):
        """
        Initialization.

        EXAMPLES::

            sage: from sage.dev.digest_transport import DigestTransport
            sage: type(DigestTransport())
            <class 'sage.dev.digest_transport.DigestTransport'>
        """
        SafeTransport.__init__(self)
        self._opener = None
示例#8
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)
示例#9
0
 def send_content(self, connection, request_body):
   try:
     return SafeTransport.send_content(self, connection, request_body)
   except socket.error, e:
     # BBB: On Python < 2.7, HTTP connection is wrapped
     raise ProtocolError(getattr(connection, '_conn', connection).host, -1,
                         "Could not connect to server", None)
示例#10
0
 def send_content(self, connection, request_body):
     try:
         return SafeTransport.send_content(self, connection, request_body)
     except socket.error, e:
         # BBB: On Python < 2.7, HTTP connection is wrapped
         raise ProtocolError(
             getattr(connection, '_conn', connection).host, -1,
             "Could not connect to server", None)
示例#11
0
    def __init__(self, timeout, url, *args, **kwargs):
        SafeTransport.__init__(self, *args, **kwargs)
        self.timeout = timeout
        self.host = None
        self.proxy = None
        self.scheme = url.split('://', 1)[0]
        self.https = url.startswith('https')
        self.proxy = os.environ.get('SZ_HTTP_PROXY')

        if self.https:
            self.context = default_ssl_context

        if self.proxy:
            logger.debug("Using proxy %s for: %s", self.proxy, url)
            self.https = self.proxy.startswith('https')

            if self.timeout:
                self.timeout = self.timeout * 3
示例#12
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
示例#13
0
class XMLProxy(object):

    def __init__(self, uri, transport=None, encoding=None, verbose=0,
                       use_datetime=0):
        import urllib
        protocol, uri = urllib.splittype(uri)
        if transport is None:
            if protocol == 'http':
                self.__transport = Transport(use_datetime)
            elif protocol == 'https':
                self.__transport = SafeTransport(use_datetime)
            else:
                raise IOError("unsupported XML-RPC protocol")
        else:
            self.__transport = transport
        self.__host, self.__handler = urllib.splithost(uri)
        self.__handler = self.__handler or '/RPC2'
        self.__encoding = encoding or 'utf-8'
        if self.__encoding == 'utf-8':
            xmlheader = "<?xml version='1.0'?>\n"
        else:
            xmlheader_template = "<?xml version='1.0' encoding='%s'?>\n"
            xmlheader = xmlheader_template % str(self.__encoding)
        if FastMarshaller:
            self.__marshaller = FastMarshaller(self.__encoding)
        else:
            self.__marshaller = Marshaller(self.__encoding, allow_none=True)
        method_call_template = \
            '%s<methodCall>\n<methodName>%%s</methodName>\n%%s</methodCall>'
        method_response_template = \
            '%s<methodResponse>\n%%s</methodResponse>'
        self.__method_call_template = method_call_template % (xmlheader)
        self.__method_response_template = method_response_template % (xmlheader)

    def __request(self, methodname, params):
        req = self.__marshaller.dumps(params)
        if methodname:
            if not isinstance(methodname, StringType):
                methodname = methodname.encode(self.__encoding)
            req = self.__method_call_template % (methodname, req)
        resp = self.__transport.request(self.__host, self.__handler, req)
        if len(resp) == 1:
            resp = resp[0]
        return resp

    def __getattr__(self, name):
        # magic method dispatcher
        return _Method(self.__request, name)

    def __repr__(self):
        return ("<XMLServerProxy for %s%s>" % (self.__host, self.__handler))

    __str__ = __repr__
示例#14
0
 def __init__(self, timeout, *args, **kwargs):
     SafeTransport.__init__(self, *args, **kwargs)
     self.timeout = timeout
     self.context = default_ssl_context
示例#15
0
 def __init__(self):
     TransportMixIn.__init__(self)
     XMLSafeTransport.__init__(self)
示例#16
0
 def request(self, host, handler, request_body, verbose=0):
     """Make the request but using the with_timeout decorator."""
     return SafeTransport.request(
         self, host, handler, request_body, verbose)
示例#17
0
 def send_content(self, connection, request_body):
   try:
     return SafeTransport.send_content(self, connection, request_body)
   except socket.error, e:
     raise ProtocolError(connection.host, -1,
                         "Could not connect to server", None)
示例#18
0
 def make_connection(self, host):
     """Create the connection for the transport and save it."""
     self.conn = SafeTransport.make_connection(self, host)
     return self.conn
 def __init__(self, context=None):
     TransportMixIn.__init__(self)
     XMLSafeTransport.__init__(self, context)
示例#20
0
 def __init__(self, timeout=None, scheme="http"):
     self._timeout = timeout
     self._scheme = scheme
     SafeTransport.__init__(self)
示例#21
0
 def make_connection(self,host):
     host_with_cert = (host, {
         'key_file'  :  self.__key_file,
         'cert_file' :  self.__cert_file
         })
     return SafeTransport.make_connection(self,host_with_cert)
示例#22
0
    def make_connection(self, host):
        c = SafeTransport.make_connection(self, host)
        c.timeout = self.timeout

        return c
示例#23
0
 def __init__(self, timeout=None):
     # Old style class call to super required.
     SafeTransport.__init__(self)
     self.timeout = timeout
示例#24
0
 def __init__(self, timeout=None):
     # Old style class call to super required.
     SafeTransport.__init__(self)
     self.timeout = timeout
示例#25
0
 def request(self, host, handler, request_body, verbose=0):
     """Make the request but using the with_timeout decorator."""
     return SafeTransport.request(self, host, handler, request_body,
                                  verbose)
示例#26
0
 def make_connection(self, host):
     """Create the connection for the transport and save it."""
     self.conn = SafeTransport.make_connection(self, host)
     return self.conn