コード例 #1
0
    def __init__(self,
                 probe,
                 uri,
                 transport=None,
                 encoding=None,
                 verbose=0,
                 allow_none=0,
                 use_datetime=0):
        xmlrpclib.ServerProxy.__init__(self, uri, transport, encoding, verbose,
                                       allow_none, use_datetime)
        self._probe = probe
        # establish a "logical" server connection

        # get the url
        import urllib
        type, uri = urllib.splittype(uri)
        if type not in ("http", "https"):
            raise IOError("unsupported XML-RPC protocol")
        self.__host, self.__handler = urllib.splithost(uri)
        if not self.__handler:
            self.__handler = "/RPC2"

        if transport is None:
            if type == "https":
                transport = xmlrpclib.SafeTransport(use_datetime=use_datetime)
            else:
                transport = xmlrpclib.Transport(use_datetime=use_datetime)
        self.__transport = transport

        self.__encoding = encoding
        self.__verbose = verbose
        self.__allow_none = allow_none
コード例 #2
0
    def setup_connection(self):
        # on *NIX, the proxy can show up either upper or lowercase.
        # Prefer lower case, and prefer HTTPS over HTTP if the
        # NEOS.scheme is https.
        proxy = os.environ.get('http_proxy', os.environ.get('HTTP_PROXY', ''))
        if NEOS.scheme == 'https':
            proxy = os.environ.get('https_proxy',
                                   os.environ.get('HTTPS_PROXY', proxy))
        if proxy:
            self.transport = ProxiedTransport()
            self.transport.set_proxy(proxy)
        elif NEOS.scheme == 'https':
            self.transport = xmlrpclib.SafeTransport()
        else:
            self.transport = xmlrpclib.Transport()

        self.neos = xmlrpclib.ServerProxy("%s://%s:%s" %
                                          (NEOS.scheme, NEOS.host, NEOS.port),
                                          transport=self.transport)

        logger.info("Connecting to the NEOS server ... ")
        try:
            result = self.neos.ping()
            logger.info("OK.")
        except (socket.error, xmlrpclib.ProtocolError,
                six.moves.http_client.BadStatusLine):
            e = sys.exc_info()[1]
            self.neos = None
            logger.info("Fail.")
            logger.warning("NEOS is temporarily unavailable.\n")
コード例 #3
0
def find_current_version(package, cur_version, index_urls=None):

    if index_urls is None:
        index_urls = ['http://pypi.python.org/pypi']

    for index_url in index_urls:
        pypi = xmlrpclib.ServerProxy(index_url, xmlrpclib.Transport())
        pypi_hits = pypi.package_releases(package)
        if len(pypi_hits) > 0:
            if semver.Version(pypi_hits[0]) > cur_version:
                return semver.Version(pypi_hits[0])

    return False
コード例 #4
0
    def __init__(self, options):
        Server.__init__(self, options)
        self.factory = options.factory
        self.server_url = options.server.rstrip('/')
        self.xmlrpc_url = self.server_url + '/xmlrpc/'
        self.password = options.password

        socket.setdefaulttimeout(180.0)
        if options.proxy:
            transport = ProxyTransport(options.proxy)
        else:
            transport = xmlrpclib.Transport()
        transport.user_agent = self.get_user_agent()
        self.server = xmlrpclib.Server(self.xmlrpc_url, transport)
        challenge = self.server.nonces.challenge(self.factory)
        encrypted = self.encrypt_password(challenge)
        self.server.nonces.verify(self.factory, encrypted)
コード例 #5
0
ファイル: snippet.py プロジェクト: someburner/GistsHub
def find_current_version(package, index_urls=None):
    """
    Using the XMLRPC method available for PyPI, get the most recent version
    of <package> from each of the index_urls and figure out which one (if any)
    is higher
    
    Returns a tuple of the index with the higher version and the version it has
    """
    if index_urls is None:
        index_urls = ['http://pypi.python.org/pypi',]
    cur_version = '0'
    cur_index = ''
    for index_url in index_urls:
        pypi = xmlrpclib.ServerProxy(index_url, xmlrpclib.Transport())
        pypi_hits = pypi.package_releases(package)
        if len(pypi_hits) > 0:
            if compare_versions(pypi_hits[0], cur_version) == 1:
                cur_version = pypi_hits[0]
                cur_index = index_url
    
    return cur_index, cur_version
コード例 #6
0
 def test_transport(self):
     t = xmlrpclib.Transport()
     p = xmlrpclib.ServerProxy(self.url, transport=t)
     self.assertEqual(p('transport'), t)
コード例 #7
0
ファイル: download.py プロジェクト: jialei/Join-the-Event
from pip.backwardcompat import md5, copytree
from pip.exceptions import InstallationError
from pip.util import (splitext, rmtree,
                      format_size, display_path, backup_dir, ask,
                      unpack_file, create_download_cache_folder, cache_download)
from pip.vcs import vcs
from pip.log import logger


__all__ = ['xmlrpclib_transport', 'get_file_content', 'urlopen',
           'is_url', 'url_to_path', 'path_to_url', 'path_to_url2',
           'geturl', 'is_archive_file', 'unpack_vcs_link',
           'unpack_file_url', 'is_vcs_url', 'is_file_url', 'unpack_http_url']


xmlrpclib_transport = xmlrpclib.Transport()


def get_file_content(url, comes_from=None):
    """Gets the content of a file; it may be a filename, file: URL, or
    http: URL.  Returns (location, content)"""
    match = _scheme_re.search(url)
    if match:
        scheme = match.group(1).lower()
        if (scheme == 'file' and comes_from
            and comes_from.startswith('http')):
            raise InstallationError(
                'Requirements file %s references URL %s, which is local'
                % (comes_from, url))
        if scheme == 'file':
            path = url.split(':', 1)[1]
コード例 #8
0
        self.cache = None

    def Resources(self):
        aggregate = {
            'hrn': 'topdomain.nitos',
            'addr': '192.168.254.188',
            'port': 8080
        }
        server = SfaServerProxy('192.168.254.188:8080')
        server.ListResources(None, None)


import xmlrpclib
from httplib import HTTPS, HTTPSConnection
need_HTTPSConnection = hasattr(
    xmlrpclib.Transport().make_connection('localhost'), 'getresponse')


class SfaServerProxy:
    def __init__(self,
                 url,
                 keyfile=None,
                 certfile=None,
                 verbose=False,
                 timeout=None):
        self.url = url
        self.keyfile = keyfile
        self.certfile = certfile
        self.verbose = verbose
        self.timeout = timeout
        # an instance of xmlrpclib.ServerProxy
コード例 #9
0
class XMLRPCTransport(xmlrpclib.Transport, ClientHelper):
    """Handles an HTTPS transaction to an XML-RPC server."""

    # Pre python 2.7, the make_connection returns a HTTP class
    transport = xmlrpclib.Transport()
    conn_class_is_http = not hasattr(transport, '_connection')
    del (transport)

    def __init__(self,
                 use_datetime=0,
                 username=None,
                 password=None,
                 certChain=None,
                 privateKey=None,
                 checker=None,
                 settings=None,
                 ignoreAbruptClose=False):
        """
        Create a new XMLRPCTransport.

        An instance of this class can be passed to
        :py:class:`xmlrpclib.ServerProxy`
        to use TLS with XML-RPC calls::

            from tlslite import XMLRPCTransport
            from xmlrpclib import ServerProxy

            transport = XMLRPCTransport(user="******", password="******")
            server = ServerProxy("https://localhost", transport)

        For client authentication, use one of these argument
        combinations:

         - username, password (SRP)
         - certChain, privateKey (certificate)

        For server authentication, you can either rely on the
        implicit mutual authentication performed by SRP or
        you can do certificate-based server
        authentication with one of these argument combinations:

         - x509Fingerprint

        Certificate-based server authentication is compatible with
        SRP or certificate-based client authentication.

        The constructor does not perform the TLS handshake itself, but
        simply stores these arguments for later.  The handshake is
        performed only when this class needs to connect with the
        server.  Thus you should be prepared to handle TLS-specific
        exceptions when calling methods of :py:class:`xmlrpclib.ServerProxy`.
        See the
        client handshake functions in
        :py:class:`~tlslite.tlsconnection.TLSConnection` for details on which
        exceptions might be raised.

        :type username: str
        :param username: SRP username.  Requires the
            'password' argument.

        :type password: str
        :param password: SRP password for mutual authentication.
            Requires the 'username' argument.

        :type certChain: ~tlslite.x509certchain.X509CertChain
        :param certChain: Certificate chain for client authentication.
            Requires the 'privateKey' argument.  Excludes the SRP arguments.

        :type privateKey: ~tlslite.utils.rsakey.RSAKey
        :param privateKey: Private key for client authentication.
            Requires the 'certChain' argument.  Excludes the SRP arguments.

        :type checker: ~tlslite.checker.Checker
        :param checker: Callable object called after handshaking to
            evaluate the connection and raise an Exception if necessary.

        :type settings: ~tlslite.handshakesettings.HandshakeSettings
        :param settings: Various settings which can be used to control
            the ciphersuites, certificate types, and SSL/TLS versions
            offered by the client.

        :type ignoreAbruptClose: bool
        :param ignoreAbruptClose: ignore the TLSAbruptCloseError on
            unexpected hangup.
        """
        # self._connection is new in python 2.7, since we're using it here,
        # we'll add this ourselves too, just in case we're pre-2.7
        self._connection = (None, None)
        xmlrpclib.Transport.__init__(self, use_datetime)
        self.ignoreAbruptClose = ignoreAbruptClose
        ClientHelper.__init__(self, username, password, certChain, privateKey,
                              checker, settings)

    def make_connection(self, host):
        """Make a connection to `host`. Reuse keepalive connections."""
        # return an existing connection if possible.  This allows
        # HTTP/1.1 keep-alive.
        if self._connection and host == self._connection[0]:
            http = self._connection[1]
        else:
            # create a HTTPS connection object from a host descriptor
            chost, extra_headers, x509 = self.get_host_info(host)

            http = HTTPTLSConnection(chost,
                                     None,
                                     username=self.username,
                                     password=self.password,
                                     certChain=self.certChain,
                                     privateKey=self.privateKey,
                                     checker=self.checker,
                                     settings=self.settings,
                                     ignoreAbruptClose=self.ignoreAbruptClose)
            # store the host argument along with the connection object
            self._connection = host, http
        if not self.conn_class_is_http:
            return http
        http2 = httplib.HTTP()
        http2._setup(http)
        return http2
コード例 #10
0
 def __init__(self):
     self.transport = xmlrpclib.Transport()
     self.rpc = xmlrpclib.ServerProxy('http://python.org/pypi',
                                      transport=self.transport)
コード例 #11
0
 def _src(self):
     return xmlrpclib.ServerProxy(self.url, xmlrpclib.Transport())
コード例 #12
0
        self.cache = None

    def Resources(self):
        aggregate = {
            "hrn": "topdomain.nitos",
            "addr": "192.168.254.188",
            "port": 8080
        }
        server = SfaServerProxy("192.168.254.188:8080")
        server.ListResources(None, None)


import xmlrpclib
from httplib import HTTPS, HTTPSConnection
need_HTTPSConnection = hasattr(
    xmlrpclib.Transport().make_connection("localhost"), "getresponse")


class SfaServerProxy:
    def __init__(self,
                 url,
                 keyfile=None,
                 certfile=None,
                 verbose=False,
                 timeout=None):
        self.url = url
        self.keyfile = keyfile
        self.certfile = certfile
        self.verbose = verbose
        self.timeout = timeout
        # an instance of xmlrpclib.ServerProxy