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)
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")
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")
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
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__()
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)
def find_key_cert(self, authuri): return HTTPPasswordMgr.find_user_password(self, None, authuri)
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)
def reduce_uri(self, uri, default_port=True): if uri is None: return None return HTTPPasswordMgr.reduce_uri(self, uri, default_port)
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