コード例 #1
0
 def __init__(self):
     if IS_PY3:
         super(ProxiedTransport, self).__init__()
     else:
         Transport.__init__(self)
     self.realhost = None
     self.proxy = None
コード例 #2
0
 def __init__(self):
     if IS_PY3:
         super(ProxiedTransport, self).__init__()
     else:  
         Transport.__init__(self)
     self.realhost = None
     self.proxy = None
コード例 #3
0
ファイル: transport.py プロジェクト: crobinso/python-bugzilla
    def __init__(self, url, cookiejar=None,
                 sslverify=True, sslcafile=None, debug=0):
        if hasattr(Transport, "__init__"):
            Transport.__init__(self, use_datetime=False)

        self.verbose = debug
        self._cookiejar = cookiejar

        # transport constructor needs full url too, as xmlrpc does not pass
        # scheme to request
        self.scheme = urlparse(url)[0]
        if self.scheme not in ["http", "https"]:
            raise Exception("Invalid URL scheme: %s (%s)" % (self.scheme, url))

        self.use_https = self.scheme == 'https'

        self.request_defaults = {
            'cert': sslcafile if self.use_https else None,
            'cookies': cookiejar,
            'verify': sslverify,
            'headers': {
                'Content-Type': 'text/xml',
                'User-Agent': self.user_agent,
            }
        }

        # Using an explicit Session, rather than requests.get, will use
        # HTTP KeepAlive if the server supports it.
        self.session = requests.Session()
コード例 #4
0
    def __init__(self, url, cookiejar=None,
                 sslverify=True, sslcafile=None, debug=True, cert=None):
        if hasattr(Transport, "__init__"):
            Transport.__init__(self, use_datetime=False)

        self.verbose = debug
        self._cookiejar = cookiejar

        # transport constructor needs full url too, as xmlrpc does not pass
        # scheme to request
        self.scheme = urlparse(url)[0]
        if self.scheme not in ["http", "https"]:
            raise Exception("Invalid URL scheme: %s (%s)" % (self.scheme, url))

        self.use_https = self.scheme == 'https'

        self.request_defaults = {
            'cert': sslcafile if self.use_https else None,
            'cookies': cookiejar,
            'verify': sslverify,
            'headers': {
                'Content-Type': 'text/xml',
                'User-Agent': self.user_agent,
            }
        }

        # Using an explicit Session, rather than requests.get, will use
        # HTTP KeepAlive if the server supports it.
        self.session = requests.Session()
        if cert:
            self.session.cert = cert
コード例 #5
0
    def __init__(self, secure=False, username=None, password=None):
        Transport.__init__(self)

        self.secure = secure

        self.username = username
        self.password = password
コード例 #6
0
ファイル: jsonrpc.py プロジェクト: westbuke/trex-core
 def __init__(self, config, path=None):
     """
     :param config: The jsonrpclib configuration
     :param path: Path to the Unix socket (overrides the host name later)
     """
     TransportMixIn.__init__(self, config)
     XMLTransport.__init__(self)
     # Keep track of the given path, if any
     self.__unix_path = os.path.abspath(path) if path else None
コード例 #7
0
ファイル: jsonrpc.py プロジェクト: pymedusa/SickRage
 def __init__(self, config, path=None):
     """
     :param config: The jsonrpclib configuration
     :param path: Path to the Unix socket (overrides the host name later)
     """
     TransportMixIn.__init__(self, config)
     XMLTransport.__init__(self)
     # Keep track of the given path, if any
     self.__unix_path = os.path.abspath(path) if path else None
コード例 #8
0
    def __init__(self, bugzillasession):
        if hasattr(Transport, "__init__"):
            Transport.__init__(self, use_datetime=False)

        self.__bugzillasession = bugzillasession
        self.__bugzillasession.set_xmlrpc_defaults()
        self.__seen_valid_xml = False

        # Override Transport.user_agent
        self.user_agent = self.__bugzillasession.get_user_agent()
コード例 #9
0
    def __init__(self,
                 user_agent,
                 server='http://api.opensubtitles.org/xml-rpc',
                 language='eng'):
        self.server = server
        self.language = language

        trans = Transport()
        trans.user_agent = user_agent

        self._rpc = ServerProxy(self.server, allow_none=True, transport=trans)
        login_response = self._rpc.LogIn('', '', language, user_agent)

        assert_status(login_response)

        self._token = login_response.get('token')
コード例 #10
0
 def parse_response(self, response):
     """parse and store cookie"""
     try:
         for header in response.msg.get_all("Set-Cookie"):
             cookie = header.split(";", 1)[0]
             cookieKey, cookieValue = cookie.split("=", 1)
             self._cookies[cookieKey] = cookieValue
     finally:
         return Transport.parse_response(self, response)
コード例 #11
0
ファイル: dokuwiki.py プロジェクト: fmenabe/python-dokuwiki
 def parse_response(self, response):
     """parse and store cookie"""
     try:
         for header in response.msg.get_all("Set-Cookie"):
             cookie = header.split(";", 1)[0]
             cookieKey, cookieValue = cookie.split("=", 1)
             self._cookies[cookieKey] = cookieValue
     finally:
         return Transport.parse_response(self, response)
コード例 #12
0
 def __init__(self):
     # noinspection SpellCheckingInspection
     opensubtitles_ua = b'VkxzdWIgMC4xMC4y'
     self.ua = base64.b64decode(opensubtitles_ua).decode()
     self.opensubtitles_api_url = 'http://api.opensubtitles.org/xml-rpc'
     self.opensubtitles_lang = 'en'
     self.token = None
     self.xmlrpc_transport = Transport()
     self.xmlrpc_transport.user_agent = self.ua
     self.xmlrpc = ServerProxy(self.opensubtitles_api_url,
                               allow_none=True,
                               transport=self.xmlrpc_transport)
コード例 #13
0
ファイル: dokuwiki.py プロジェクト: fmenabe/python-dokuwiki
 def parse_response(self, response):
     """parse and store cookie"""
     try:
         for header in response.getheader("set-cookie").split(", "):
             # filter 'expire' information
             if not header.startswith("D"):
                 continue
             cookie = header.split(";", 1)[0]
             cookieKey, cookieValue = cookie.split("=", 1)
             self._cookies[cookieKey] = cookieValue
     finally:
         return Transport.parse_response(self, response)
コード例 #14
0
def login():
    transport = Transport()
    transport.user_agent = constants.USER_AGENT_OPENSUBS
    xmlrpc = ServerProxy(constants.OPENSUBTITLES_URL,
                         allow_none=True,
                         transport=transport)
    try:
        data = xmlrpc.LogIn(constants.USERNAME, constants.PASSWORD,
                            constants.LANGUAGE, constants.USER_AGENT_OPENSUBS)
    except:
        logging.warning(
            "Error occured while establishing connection to opensubtitles...")
        return None, None
    if '200' == data.get('status').split()[0]:
        logging.info("Got token from opensubtitles")
        return data.get('token'), xmlrpc
    else:
        logging.warning(
            "Error occured while getting opensubtitles token. Returned status as "
            + data.get('status').split()[0])
        return None
コード例 #15
0
 def parse_response(self, response):
     """parse and store cookie"""
     try:
         for header in response.getheader("set-cookie").split(", "):
             # filter 'expire' information
             if not header.startswith("D"):
                 continue
             cookie = header.split(";", 1)[0]
             cookieKey, cookieValue = cookie.split("=", 1)
             self._cookies[cookieKey] = cookieValue
     finally:
         return Transport.parse_response(self, response)
コード例 #16
0
ファイル: pkcs11-adapter.py プロジェクト: mcrute/dev_urandom
    def __init__(self, use_datetime=0, pin='', key_name="01:01"):
        Transport.__init__(self, use_datetime=use_datetime)

        self.get_engine()
        cls = PKCS11Transport

        import getpass
        pin = getpass.getpass()

        self.cert = cls._pkcs11.load_certificate(key_name)
        self.key = cls._pkcs11.load_private_key(key_name, pin=pin)

        # Use False to prevent setting the crypto list which causes an NPE
        self.context = SSL.Context('tlsv1', False)

        # Manually load the key and cert into the context because the helper
        # doesn't read from the smart card or handle DER-encoded certs
        m2.ssl_ctx_use_pkey_privkey(self.context.ctx, self.key._ptr())
        m2.ssl_ctx_use_x509(self.context.ctx, self.cert._ptr())

        self.context.load_verify_locations("ca.pem", "")
        self.context.set_verify(SSL.verify_peer, 10)
        self.context.set_info_callback()
コード例 #17
0
ファイル: xmlrpc.py プロジェクト: kiwitcms/tcms-api
    def get_host_info(self, host):
        host, extra_headers, x509 = Transport.get_host_info(self, host)

        # Set the remote host principal
        hostinfo = host.split(':')
        service = "HTTP@" + hostinfo[0]

        service_name = gssapi.Name(service, gssapi.NameType.hostbased_service)
        context = gssapi.SecurityContext(usage="initiate", name=service_name)
        token = context.step()
        token = b64encode(token).decode()
        extra_headers = [("Authorization", f"Negotiate {token}")]

        return host, extra_headers, x509
コード例 #18
0
    def get_host_info(self, host):
        host, extra_headers, x509 = Transport.get_host_info(self, host)

        # Set the remote host principal
        hostinfo = host.split(':')
        service = "HTTP@" + hostinfo[0]

        _result, context = kerberos.authGSSClientInit(service)
        kerberos.authGSSClientStep(context, "")

        extra_headers = [
            ("Authorization",
             "negotiate %s" % kerberos.authGSSClientResponse(context))
        ]

        return host, extra_headers, x509
コード例 #19
0
ファイル: http.py プロジェクト: kseppi/mrs-mapreduce
 def request(self, host, *args, **kwds):
     # Note that if the server's backlog gets filled, then it refuses
     # connections.
     for i in range(RETRIES):
         try:
             return Transport.request(self, host, *args, **kwds)
         except socket.timeout:
             logger.error("RPC to %s failed: timed out." % host)
             time.sleep(RETRY_DELAY)
             continue
         except socket.error as e:
             if e.errno == errno.ECONNREFUSED:
                 logger.error("RPC to %s failed: connection refused." %
                              host)
                 continue
             else:
                 logger.error("RPC to %s failed: %s" % (host, str(e)))
                 break
     raise ConnectionFailed(host)
コード例 #20
0
 def request(self, host, *args, **kwds):
     # Note that if the server's backlog gets filled, then it refuses
     # connections.
     for i in range(RETRIES):
         try:
             return Transport.request(self, host, *args, **kwds)
         except socket.timeout:
             logger.error("RPC to %s failed: timed out." % host)
             time.sleep(RETRY_DELAY)
             continue
         except socket.error as e:
             if e.errno == errno.ECONNREFUSED:
                 logger.error("RPC to %s failed: connection refused."
                         % host)
                 continue
             else:
                 logger.error("RPC to %s failed: %s" %
                         (host, str(e)))
                 break
     raise ConnectionFailed(host)
コード例 #21
0
 def __init__(self, timeout):
     Transport.__init__(self)
     self.timeout = timeout
コード例 #22
0
 def make_connection(self, host):
     prev = socket.getdefaulttimeout()
     socket.setdefaulttimeout(self.timeout)
     value = Transport.make_connection(self, host)
     socket.setdefaulttimeout(prev)
     return value
コード例 #23
0
ファイル: xmlrpc.py プロジェクト: yaleyang/couping
 def __init__(self, timeout: typing.Union[int, float]=socket._GLOBAL_DEFAULT_TIMEOUT, *args, **kwargs) -> None:
     Transport.__init__(self, *args, **kwargs)
     self._timeout = timeout
コード例 #24
0
 def send_headers(self, connection, headers):
     if self._cookies:
         cookies = map(lambda x: x[0] + '=' + x[1], self._cookies.items())
         connection.putheader("Cookie", "; ".join(cookies))
     Transport.send_headers(self, connection, headers)
コード例 #25
0
 def send_request(self, connection, handler, request_body):
     Transport.send_request(self, connection, handler, request_body)
     # set cookie below handler
     if self._cookies:
         cookies = map(lambda x: x[0] + '=' + x[1], self._cookies.items())
         connection.putheader("Cookie", "; ".join(cookies))
コード例 #26
0
ファイル: dokuwiki.py プロジェクト: fmenabe/python-dokuwiki
 def send_headers(self, connection, headers):
     if self._cookies:
         cookies = map(lambda x: x[0] + '=' + x[1], self._cookies.items())
         connection.putheader("Cookie", "; ".join(cookies))
     Transport.send_headers(self, connection, headers)
コード例 #27
0
 def __init__(self):
     Transport.__init__(self)
     self._cookies = dict()
コード例 #28
0
ファイル: utils.py プロジェクト: yaronsamuel/morsite
 def __init__(self, *args, **kwargs):
     Transport.__init__(self, *args, **kwargs)
     self.client = Client()
コード例 #29
0
ファイル: jsonrpc.py プロジェクト: youngmou/Elymus
 def __init__(self, config):
     TransportMixIn.__init__(self, config)
     XMLTransport.__init__(self)
コード例 #30
0
from nestegg import NesteggException
from requests import get, head

from xmlrpc.client import ServerProxy, Transport

pypi_client = ServerProxy("https://pypi.python.org/pypi", Transport())


def get_real_pkg_name(pkg_name):
    r = head('https://pypi.python.org/simple/{0}/'.format(pkg_name))
    if r.status_code == 200:
        return pkg_name
    if 300 <= r.status_code <= 399:
        location = r.headers["location"]
        if location.startswith("/simple/"):
            return location.split("/")[-1]
        else:
            raise NesteggException(
                "Unexpected redirect from pypi: {}".format(location))
    raise NesteggException(
        "Unable to get real package name for {} from pypi".format(pkg_name))


def get_package_details(pkg_name):
    real_pkg_name = get_real_pkg_name(pkg_name)
    releases = pypi_client.package_releases(real_pkg_name, True)
    print(releases)
    for release in releases:
        urls = pypi_client.release_urls(real_pkg_name, release)
        print(release, urls)
コード例 #31
0
ファイル: dokuwiki.py プロジェクト: fmenabe/python-dokuwiki
 def send_request(self, connection, handler, request_body):
     Transport.send_request(self, connection, handler, request_body)
     # set cookie below handler
     if self._cookies:
         cookies = map(lambda x: x[0] + '=' + x[1], self._cookies.items())
         connection.putheader("Cookie", "; ".join(cookies))
コード例 #32
0
ファイル: dokuwiki.py プロジェクト: fmenabe/python-dokuwiki
 def __init__(self):
     Transport.__init__(self)
     self._cookies = dict()
コード例 #33
0
ファイル: scgitransport.py プロジェクト: tobbez/libtc
 def __init__(self, *args, **kwargs):
     self.socket_path = kwargs.pop("socket_path", "")
     Transport.__init__(self, *args, **kwargs)
コード例 #34
0
ファイル: myUtils.py プロジェクト: joshuaweiss2020/AlexP2P
 def __init__(self, ProxyServer):
     Transport.__init__(self)
     self.ProxyServer = ProxyServer
コード例 #35
0
 def make_connection(self, host):
     conn = Transport.make_connection(self, host)
     conn.timeout = self._timeout
     return conn
コード例 #36
0
ファイル: http.py プロジェクト: kseppi/mrs-mapreduce
 def __init__(self, timeout):
     Transport.__init__(self)
     self.timeout = timeout
コード例 #37
0
 def __init__(self,
              timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
              *args,
              **kwargs):
     Transport.__init__(self, *args, **kwargs)
     self._timeout = timeout
コード例 #38
0
ファイル: jsonrpc.py プロジェクト: prs247au/jsonrpclib
 def __init__(self):
     TransportMixIn.__init__(self)
     XMLTransport.__init__(self)
コード例 #39
0
ファイル: lp_registration.py プロジェクト: hroncok/breezy
 def __init__(self, scheme):
     Transport.__init__(self)
     self._scheme = scheme
     self.verbose = 0
     self._possible_bzr_transports = []
コード例 #40
0
import os
import sys
import json
import requests
from zipfile import ZipFile
import logging
from xmlrpc.client import ServerProxy, Transport
logger = logging.getLogger()

OPENSUBTITLES_SERVER = 'http://api.opensubtitles.org/xml-rpc'
LANGUAGE = 'en'
USER_AGENT = "TemporaryUserAgent"
CHUNK_SIZE = 128

t = Transport()
t.user_agent = USER_AGENT
xmlrpc = ServerProxy(OPENSUBTITLES_SERVER,transport=t,allow_none=True)



def login(uname,pwd):
    try:
        token = xmlrpc.LogIn(uname,pwd,LANGUAGE,USER_AGENT)
        if '200 OK' in token['status']:
            return token['token']
        else:
            return None
    except Exception as e:
        print('Login Error : {error} '.format(error = str(e)))

コード例 #41
0
ファイル: jsonrpc.py プロジェクト: westbuke/trex-core
 def __init__(self, config):
     TransportMixIn.__init__(self, config)
     XMLTransport.__init__(self)
コード例 #42
0
 def __init__(self, service, uri, use_datetime=1):
     self.service = service
     self.uri = uri
     Transport.__init__(self, use_datetime=use_datetime)
コード例 #43
0
ファイル: http.py プロジェクト: kseppi/mrs-mapreduce
 def make_connection(self, host):
     prev = socket.getdefaulttimeout()
     socket.setdefaulttimeout(self.timeout)
     value = Transport.make_connection(self, host)
     socket.setdefaulttimeout(prev)
     return value
コード例 #44
0
 def __init__(self, timeout=None, *args, **kwargs):
     Transport.__init__(self, *args, **kwargs)
     self.timeout = timeout
コード例 #45
0
ファイル: xmlrpc.py プロジェクト: kbm1422/husky
 def __init__(self, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, *args, **kwargs):
     Transport.__init__(self, *args, **kwargs)
     self._timeout = timeout
コード例 #46
0
ファイル: xmlrpc.py プロジェクト: kbm1422/husky
 def make_connection(self, host):
     conn = Transport.make_connection(self, host)
     conn.timeout = self._timeout
     return conn
コード例 #47
0
ファイル: utils.py プロジェクト: emencia/django-blog-xinnia
 def __init__(self, *args, **kwargs):
     Transport.__init__(self, *args, **kwargs)
     self.client = Client()
コード例 #48
0
    "414": SubAuthError,
    "415": SubAuthError,
    "416": SubUploadError,
    "429": SubServerError,
    "503": SubServerError,
    "506": SubServerError,
    "520": SubServerError,
}

_API_PROTOCOL_ERR_MAP = {
    503: "503 Service Unavailable",
    506: "506 Server under maintenance",
    520: "520 Unknown internal error",
}

_client = ServerProxy(API_BASE, allow_none=True, transport=Transport())


# TODO: give a way to let lib user to set `TIMEOUT`?
def request(endpoint, token, *params):
    """
    Function to allow for robust and reusable calls to the XMLRPC API. `endpoint`
    is the `Endpoint` that you want to use from the opensubtitles API. `token` is the
    auth token that is used for any user-authenticated calls. `*params` are any
    additional parameters to pass to the API.
    Note: Retrying with exponential backoff and exposing appropriate errors are all
    handled automatically.
    """
    TIMEOUT = 15
    DELAY_FACTOR = 2
    current_delay = 1.5