当前位置: 首页>>代码示例>>Python>>正文


Python urllib.splituser方法代码示例

本文整理汇总了Python中urllib.splituser方法的典型用法代码示例。如果您正苦于以下问题:Python urllib.splituser方法的具体用法?Python urllib.splituser怎么用?Python urllib.splituser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib的用法示例。


在下文中一共展示了urllib.splituser方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_host_info

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splituser [as 别名]
def get_host_info(self, host):

        x509 = {}
        if isinstance(host, TupleType):
            host, x509 = host

        import urllib
        auth, host = urllib.splituser(host)

        if auth:
            import base64
            auth = base64.encodestring(urllib.unquote(auth))
            auth = string.join(string.split(auth), "") # get rid of whitespace
            extra_headers = [
                ("Authorization", "Basic " + auth)
                ]
        else:
            extra_headers = None

        return host, extra_headers, x509

    ##
    # Connect to server.
    #
    # @param host Target host.
    # @return A connection handle. 
开发者ID:glmcdona,项目名称:meddle,代码行数:28,代码来源:xmlrpclib.py

示例2: test_splituser

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splituser [as 别名]
def test_splituser(self):
        splituser = urllib.splituser
        self.assertEqual(splituser('User:Pass@www.python.org:080'),
                         ('User:Pass', 'www.python.org:080'))
        self.assertEqual(splituser('@www.python.org:080'),
                         ('', 'www.python.org:080'))
        self.assertEqual(splituser('www.python.org:080'),
                         (None, 'www.python.org:080'))
        self.assertEqual(splituser('User:Pass@'),
                         ('User:Pass', ''))
        self.assertEqual(splituser('User@example.com:Pass@www.python.org:080'),
                         ('User@example.com:Pass', 'www.python.org:080')) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_urllib.py

示例3: savefilename

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splituser [as 别名]
def savefilename(self, url):
        type, rest = urllib.splittype(url)
        host, path = urllib.splithost(rest)
        path = path.lstrip("/")
        user, host = urllib.splituser(host)
        host, port = urllib.splitnport(host)
        host = host.lower()
        if not path or path[-1] == "/":
            path = path + "index.html"
        if os.sep != "/":
            path = os.sep.join(path.split("/"))
        path = os.path.join(host, path)
        return path 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:15,代码来源:websucker.py

示例4: url_permutations

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splituser [as 别名]
def url_permutations(url):
        """Try all permutations of hostname and path which can be applied

        to blacklisted URLs
        """
        def url_host_permutations(host):
            if re.match(r'\d+\.\d+\.\d+\.\d+', host):
                yield host
                return
            parts = host.split('.')
            l = min(len(parts), 5)
            if l > 4:
                yield host
            for i in range(l - 1):
                yield '.'.join(parts[i - l:])

        def url_path_permutations(path):
            yield path
            query = None
            if '?' in path:
                path, query = path.split('?', 1)
            if query is not None:
                yield path
            path_parts = path.split('/')[0:-1]
            curr_path = ''
            for i in range(min(4, len(path_parts))):
                curr_path = curr_path + path_parts[i] + '/'
                yield curr_path

        protocol, address_str = urllib.splittype(url)
        host, path = urllib.splithost(address_str)
        user, host = urllib.splituser(host)
        host, port = urllib.splitport(host)
        host = host.strip('/')
        seen_permutations = set()
        for h in url_host_permutations(host):
            for p in url_path_permutations(path):
                u = '{}{}'.format(h, p)
                if u not in seen_permutations:
                    yield u
                    seen_permutations.add(u) 
开发者ID:afilipovich,项目名称:gglsbl,代码行数:43,代码来源:protocol.py

示例5: __init__

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splituser [as 别名]
def __init__(self, url, config = Config):
        proto, uri = urllib.splittype(url)

        # apply some defaults
        if uri[0:2] != '//':
            if proto != None:
                uri = proto + ':' + uri

            uri = '//' + uri
            proto = 'http'

        host, path = urllib.splithost(uri)

        try:
            int(host)
            host = 'localhost:' + host
        except:
            pass

        if not path:
            path = '/'

        if proto not in ('http', 'https', 'httpg'):
            raise IOError, "unsupported SOAP protocol"
        if proto == 'httpg' and not config.GSIclient:
            raise AttributeError, \
                  "GSI client not supported by this Python installation"
        if proto == 'https' and not config.SSLclient:
            raise AttributeError, \
                "SSL client not supported by this Python installation"

        self.user,host = urllib.splituser(host)
        self.proto = proto
        self.host = host
        self.path = path 
开发者ID:donSchoe,项目名称:p2pool-n,代码行数:37,代码来源:Client.py

示例6: uri_encode_idna

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splituser [as 别名]
def uri_encode_idna(uri):
    '''
    Do IDNA encoding for hostnames, if possible
    '''
    scheme, netloc, path, query, fragment  = urlparse.urlsplit(uri)
    if scheme.lower() in urlparse.uses_netloc and netloc is not None:
        user_password, host_port = urllib.splituser(netloc)
        if host_port is not None:
            host, port = urllib.splitport(host_port)
            if host is not None and host[:1] + host[-1:] != '[]':
                # NOTE: this works around a bug in the urlparse cache w.r.t. unicode strings
                host = ''.join([ chr(ord(ch)) for ch in host ])
                try:
                    host = urllib.quote(unicodedata.normalize('NFKC', urllib.unquote(host).decode('utf-8')).encode('utf-8'))
                except:
                    pass
                try:
                    host = urllib.quote(encode_idna(urllib.unquote(host)))
                except:
                    pass
                host_port = host + (port is not None and (':' + port) or '')
                netloc = (user_password is not None and (user_password + '@') or '') + host_port
        pass
    uri = urlparse.urlunsplit((scheme, netloc, path, query, fragment))
    # NOTE: this works around a bug in the urlparse cache w.r.t. unicode strings
    uri = ''.join([ chr(ord(ch)) for ch in uri ])
    return uri 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:29,代码来源:user.py

示例7: uri_decode_idna

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splituser [as 别名]
def uri_decode_idna(uri):
    '''
    Do IDNA decoding for hostnames, if possible
    '''
    scheme, netloc, path, query, fragment  = urlparse.urlsplit(uri)
    if scheme.lower() in urlparse.uses_netloc and netloc is not None:
        user_password, host_port = urllib.splituser(netloc)
        if host_port is not None:
            host, port = urllib.splitport(host_port)
            if host is not None and host[:1] + host[-1:] != '[]':
                # NOTE: this works around a bug in the urlparse cache w.r.t. unicode strings
                host = ''.join([ chr(ord(ch)) for ch in host ])
                try:
                    host = urllib.quote(decode_idna(urllib.unquote(host)))
                except:
                    pass
                try:
                    host = urllib.quote(unicodedata.normalize('NFKC', urllib.unquote(host).decode('utf-8')).encode('utf-8'))
                except:
                    pass
                host_port = host + (port is not None and (':' + port) or '')
                netloc = (user_password is not None and (user_password + '@') or '') + host_port
        pass
    uri = urlparse.urlunsplit((scheme, netloc, path, query, fragment))
    # NOTE: this works around a bug in the urlparse cache w.r.t. unicode strings
    uri = ''.join([ chr(ord(ch)) for ch in uri ])
    return uri 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:29,代码来源:user.py

示例8: normalize_uri

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splituser [as 别名]
def normalize_uri(uri):
    '''
    normalize a URI; also converts IRIs to URIs
    '''
    uri = ''.join([ (ord(x) in xrange(33, 127)) and x or urllib.quote(x, safe='') for x in u''.join(uri.decode('UTF-8').split()).encode('UTF-8') ])
    try:
        scheme, netloc, path, query, fragment = urlparse.urlsplit(uri)
        uri = urlparse.urlunsplit((scheme, netloc, path, query, fragment))
        if scheme in urlparse.uses_netloc:
            if netloc is not None:
                user, hostport = urllib.splituser(netloc)
                if hostport is not None:
                    host, port = urllib.splitport(hostport)
                    if host is not None:
                        if host[:1] != '[':
                            # hostname segments get downcased and IDNA-encoded
                            ohost = []
                            for part in host.split('.'):
                                part = urllib.unquote(part)
                                try:
                                    part = part.decode('UTF-8').lower().encode('UTF-8')
                                    try:
                                        part = part.decode('UTF-8').encode('idna')
                                        pass
                                    except KeyboardInterrupt, k:
                                        raise
                                    except:
                                        pass
                                    pass
                                except KeyboardInterrupt, k:
                                    raise
                                except: 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:34,代码来源:metadata.py

示例9: stripUserPassFromUrl

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splituser [as 别名]
def stripUserPassFromUrl(url):
    arr = list(urlparse.urlparse(url))
    hostUserPass = arr[1]
    userPass, host = urllib.splituser(hostUserPass)
    arr[1] = host
    return urlparse.urlunparse(arr) 
开发者ID:sassoftware,项目名称:conary,代码行数:8,代码来源:util.py

示例10: urlSplit

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splituser [as 别名]
def urlSplit(url, defaultPort = None):
    """A function to split a URL in the format
    <scheme>://<user>:<pass>@<host>:<port>/<path>;<params>#<fragment>
    into a tuple
    (<scheme>, <user>, <pass>, <host>, <port>, <path>, <params>, <fragment>)
    Any missing pieces (user/pass) will be set to None.
    If the port is missing, it will be set to defaultPort; otherwise, the port
    should be a numeric value.
    """
    scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
    userpass, hostport = urllib.splituser(netloc)
    if scheme == 'lookaside':
        # Always a local path, sometimes the first part will have a colon in it
        # but it isn't a port, e.g. "lp:lightdm".
        host, port = hostport, None
    else:
        host, port = networking.splitHostPort(hostport)
    if port is None:
        port = defaultPort

    if userpass:
        user, passwd = urllib.splitpasswd(userpass)
        if sys.version_info[:2] == (2, 7):
            # splituser is considered internal and changed
            # behavior in 2.7.  New behavior is right because
            # it allows : in password, but we must deal with
            # the old 2.6 behavior and not double-unquote
            user = urllib.unquote(user)
            if passwd:
                passwd = urllib.unquote(passwd)
        if passwd:
            passwd = ProtectedString(passwd)
    else:
        user, passwd = None, None
    return scheme, user, passwd, host, port, path, \
        query or None, fragment or None 
开发者ID:sassoftware,项目名称:conary,代码行数:38,代码来源:util.py

示例11: _GuessBase

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splituser [as 别名]
def _GuessBase(self, required):
    """Returns the SVN base URL.

    Args:
      required: If true, exits if the url can't be guessed, otherwise None is
        returned.
    """
    info = RunShell(["svn", "info"])
    for line in info.splitlines():
      words = line.split()
      if len(words) == 2 and words[0] == "URL:":
        url = words[1]
        scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
        username, netloc = urllib.splituser(netloc)
        if username:
          logging.info("Removed username from base URL")
        if netloc.endswith("svn.python.org"):
          if netloc == "svn.python.org":
            if path.startswith("/projects/"):
              path = path[9:]
          elif netloc != "pythondev@svn.python.org":
            ErrorExit("Unrecognized Python URL: %s" % url)
          base = "http://svn.python.org/view/*checkout*%s/" % path
          logging.info("Guessed Python base = %s", base)
        elif netloc.endswith("svn.collab.net"):
          if path.startswith("/repos/"):
            path = path[6:]
          base = "http://svn.collab.net/viewvc/*checkout*%s/" % path
          logging.info("Guessed CollabNet base = %s", base)
        elif netloc.endswith(".googlecode.com"):
          path = path + "/"
          base = urlparse.urlunparse(("http", netloc, path, params,
                                      query, fragment))
          logging.info("Guessed Google Code base = %s", base)
        else:
          path = path + "/"
          base = urlparse.urlunparse((scheme, netloc, path, params,
                                      query, fragment))
          logging.info("Guessed base = %s", base)
        return base
    if required:
      ErrorExit("Can't find URL in output from svn info")
    return None 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:45,代码来源:upload.py


注:本文中的urllib.splituser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。