def run(self, context):
        o, a = context.get_parsed_arguments()
        if o.repository and (o.username or o.password or o.repository_url):
            raise bento.errors.UsageException(
                "Cannot specify repository and username/password/url at the same time"
            )
        if not (o.repository or
                (o.username or o.password or o.repository_url)):
            # FIXME: why does distutils use DEFAULT_REPOSITORY (i.e. an url)
            # here ?
            config = _read_pypirc(DEFAULT_REPOSITORY)
        elif o.repository:
            config = _read_pypirc(o.repository)
        else:
            config = PyPIConfig(o.username, o.password, o.repository_url)

        auth = HTTPPasswordMgr()
        host = urlparse(config.repository)[1]
        auth.add_password(config.realm, host, config.username, config.password)

        post_data = build_post_data(context.pkg, "submit")
        code, msg = post_to_server(post_data, config, auth)
        if code != 200:
            raise bento.errors.BentoError(
                "Error while submitting package metadata to server: %r" % msg)
Пример #2
0
    def test_register_server(self):
        package = PackageDescription(name="foo")
        repository = 'http://testpypi.python.org/pypi'
        realm = DEFAULT_REALM
        config = PyPIConfig(username="******", password="******", repository=repository, realm=realm)

        auth = HTTPPasswordMgr()
        host = urlparse(config.repository)[0]
        auth.add_password(config.realm, host, config.username, config.password)

        post_data = build_post_data(package, "submit")
        code, msg = post_to_server(post_data, config, auth)
        self.assertEqual(code, 200)
        self.assertEqual(msg, "OK")
Пример #3
0
    def test_register_server(self):
        package = PackageDescription(name="foo")
        repository = "http://testpypi.python.org/pypi"
        realm = DEFAULT_REALM
        config = PyPIConfig(username="******", password="******", repository=repository, realm=realm)

        auth = HTTPPasswordMgr()
        host = urlparse(config.repository)[0]
        auth.add_password(config.realm, host, config.username, config.password)

        post_data = build_post_data(package, "submit")
        code, msg = post_to_server(post_data, config, auth)
        self.assertEqual(code, 200)
        self.assertEqual(msg, "OK")
Пример #4
0
    def __init__(self, password_mgr=None, debuglevel=0):
        """Initialize an instance of a AbstractAuthHandler.

Verify operation with all default arguments.
>>> abstrct = AbstractAuthHandler()

Verify "normal" operation.
>>> abstrct = AbstractAuthHandler(urllib2.HTTPPasswordMgrWithDefaultRealm())
"""
        super(AuthHandler, self).__init__(logging.getLogger('urllib_auth'))

        if password_mgr is None:
            password_mgr = HTTPPasswordMgr()

        self.parent = None
        self.passwd = password_mgr
        self.add_password = self.passwd.add_password

        self._debuglevel = debuglevel

        self._basic = AbstractBasicAuthHandler(password_mgr=self.passwd)
        self._digest = AbstractDigestAuthHandler(passwd=self.passwd)

        self.auth_header_request = None
        self.auth_header_response = None
        self.auth_is_proxy = None
        self.auth_code = None
Пример #5
0
    def __init__(self, password_mgr=None):
        """
        Initialize a new FTPBasicAuthHandler.
        """

        if password_mgr is None:
            password_mgr = HTTPPasswordMgr()
        self.passwd = password_mgr
        self.add_password = self.passwd.add_password
        return super().__init__()
Пример #6
0
    def run(self, context):
        o, a = context.get_parsed_arguments()
        if o.repository and (o.username or o.password or o.repository_url):
            raise bento.errors.UsageException("Cannot specify repository and username/password/url at the same time")
        if not (o.repository or (o.username or o.password or o.repository_url)):
            # FIXME: why does distutils use DEFAULT_REPOSITORY (i.e. an url)
            # here ?
            config = _read_pypirc(DEFAULT_REPOSITORY)
        elif o.repository:
            config = _read_pypirc(o.repository)
        else:
            config = PyPIConfig(o.username, o.password, o.repository_url)

        auth = HTTPPasswordMgr()
        host = urlparse(config.repository)[1]
        auth.add_password(config.realm, host, config.username, config.password)

        post_data = build_post_data(context.pkg, "submit")
        code, msg = post_to_server(post_data, config, auth)
        if code != 200:
            raise bento.errors.BentoError("Error while submitting package metadata to server: %r" % msg)
Пример #7
0
 def find_key_cert(self, authuri):
     return HTTPPasswordMgr.find_user_password(self, None, authuri)
Пример #8
0
 def is_suburi(self, base, test):
     if base is None:
         # default to the proxy's host/port
         hostport, path = test
         base = (hostport, "/")
     return HTTPPasswordMgr.is_suburi(self, base, test)
Пример #9
0
 def reduce_uri(self, uri, default_port=True):
     if uri is None:
         return None
     return HTTPPasswordMgr.reduce_uri(self, uri, default_port)
Пример #10
0
 def __init__(self, password_mgr=None):
     if password_mgr is None:
         password_mgr = HTTPPasswordMgr()
     self.passwd = password_mgr
     self.add_password = self.passwd.add_password
Пример #11
0
 def find_key_cert(self, authuri):
     return HTTPPasswordMgr.find_user_password(self, None, authuri)
Пример #12
0
 def is_suburi(self, base, test):
     if base is None:
         # default to the proxy's host/port
         hostport, path = test
         base = (hostport, "/")
     return HTTPPasswordMgr.is_suburi(self, base, test)
Пример #13
0
 def reduce_uri(self, uri, default_port=True):
     if uri is None:
         return None
     return HTTPPasswordMgr.reduce_uri(self, uri, default_port)