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


Python urllib.splitport方法代码示例

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


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

示例1: request

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitport [as 别名]
def request(self, method, url, body=None, headers={}):
        # Request is called before connect, so can interpret url and get
        # real host/port to be used to make CONNECT request to proxy
        proto, rest = urllib.splittype(url)

        if proto is None:
            raise ValueError, "unknown URL type: %s" % url

        # Get host
        host, rest = urllib.splithost(rest)

        # Try to get port
        host, port = urllib.splitport(host)

        # If port is not defined try to get from proto
        if port is None:
            try:
                port = self._ports[proto]
            except KeyError:
                raise ValueError, "unknown protocol for: %s" % url

        self._real_host = host
        self._real_port = int(port)

        httplib.HTTPConnection.request(self, method, url, body, headers) 
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:27,代码来源:proxy.py

示例2: ftp_open

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitport [as 别名]
def ftp_open(self, req):
        host = req.get_host()
        if not host:
            raise IOError, ('ftp error', 'no host given')
        host, port = splitport(host)
        if port is None:
            port = ftplib.FTP_PORT
        else:
            port = int(port)

        # username/password handling
        user, host = splituser(host)
        if user:
            user, passwd = splitpasswd(user)
        else:
            passwd = None
        host = unquote(host)
        user = unquote(user or '')
        passwd = unquote(passwd or '')
        
        try:
            host = socket.gethostbyname(host)
        except socket.error, msg:
            raise urllib2.URLError(msg) 
开发者ID:yandex,项目名称:root-2015-tasks,代码行数:26,代码来源:byterange.py

示例3: _get_proxy_info

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitport [as 别名]
def _get_proxy_info(self, scheme, authority):
        """Return a ProxyInfo instance (or None) based on the scheme
        and authority.
        """
        hostname, port = urllib.splitport(authority)
        proxy_info = self.proxy_info
        if callable(proxy_info):
            proxy_info = proxy_info(scheme)

        if hasattr(proxy_info, "applies_to") and not proxy_info.applies_to(hostname):
            proxy_info = None
        return proxy_info 
开发者ID:remg427,项目名称:misp42splunk,代码行数:14,代码来源:__init__.py

示例4: _get_proxy_info

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitport [as 别名]
def _get_proxy_info(self, scheme, authority):
        """Return a ProxyInfo instance (or None) based on the scheme
        and authority.
        """
        hostname, port = urllib.splitport(authority)
        proxy_info = self.proxy_info
        if callable(proxy_info):
            proxy_info = proxy_info(scheme)

        if (hasattr(proxy_info, 'applies_to')
            and not proxy_info.applies_to(hostname)):
            proxy_info = None
        return proxy_info 
开发者ID:mortcanty,项目名称:earthengine,代码行数:15,代码来源:__init__.py

示例5: _spliturl

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitport [as 别名]
def _spliturl(url):
    scheme, opaque = urllib.splittype(url)
    netloc, path = urllib.splithost(opaque)
    host, port = urllib.splitport(netloc)
    # Strip brackets if its an IPv6 address
    if host.startswith('[') and host.endswith(']'): host = host[1:-1]
    if port is None: port = DEFAULT_PORT
    return scheme, host, port, path

# Given an HTTP request handler, this wrapper objects provides a related
# family of convenience methods built using that handler. 
开发者ID:DanielSchwartz1,项目名称:SplunkForPCAP,代码行数:13,代码来源:binding.py

示例6: test_splitport

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitport [as 别名]
def test_splitport(self):
        splitport = urllib.splitport
        self.assertEqual(splitport('parrot:88'), ('parrot', '88'))
        self.assertEqual(splitport('parrot'), ('parrot', None))
        self.assertEqual(splitport('parrot:'), ('parrot', None))
        self.assertEqual(splitport('127.0.0.1'), ('127.0.0.1', None))
        self.assertEqual(splitport('parrot:cheese'), ('parrot:cheese', None))
        self.assertEqual(splitport('[::1]:88'), ('[::1]', '88'))
        self.assertEqual(splitport('[::1]'), ('[::1]', None))
        self.assertEqual(splitport(':88'), ('', '88')) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_urllib.py

示例7: test_splitport

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitport [as 别名]
def test_splitport(self):
        splitport = urllib.splitport
        self.assertEqual(splitport('parrot:88'), ('parrot', '88'))
        self.assertEqual(splitport('parrot'), ('parrot', None))
        self.assertEqual(splitport('parrot:'), ('parrot', None))
        self.assertEqual(splitport('127.0.0.1'), ('127.0.0.1', None))
        self.assertEqual(splitport('parrot:cheese'), ('parrot:cheese', None)) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:9,代码来源:test_urllib.py

示例8: url_permutations

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitport [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

示例9: SplitUrl

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitport [as 别名]
def SplitUrl(url):
  Url = collections.namedtuple('Url', ('method host port path'))
  method, rest = urllib.splittype(url)
  hostport, path = urllib.splithost(rest)
  host, port = urllib.splitport(hostport)
  return Url(method, host, int(port or 0), path) 
开发者ID:omererdem,项目名称:honeything,代码行数:8,代码来源:http.py

示例10: _tomcatFsStartFunc

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitport [as 别名]
def _tomcatFsStartFunc(self, event):
        if (str(self._tomcatMainURL.getText()).strip()) != '':
            import urllib
            url = str(self._tomcatMainURL.getText().strip())
            if url.startswith('http://') or url.startswith('https://'):
                if not url.endswith('/'):
                    url += '/'
                proto, rest = urllib.splittype(url)
                host, rest = urllib.splithost(rest) 
                host2, port = urllib.splitport(host)
                host = host.split(':')[0]
                if port is None: 
                    port = 80
                                    
                usersFile = str(self._tomcatMainUname.getText())
                pwdsFile = str(self._tomcatMainPwd.getText())
                if usersFile != '' and pwdsFile != '':
                    bruter = Bruter(host, port, usersFile, pwdsFile)
                    print bruter.doLogin()
                    
                else:
                    print 'Please load dict files'
            else:
                print 'Check URL'
                    
                
                
# ########################################################## 
开发者ID:WallbreakerTeam,项目名称:TomcatBrute,代码行数:30,代码来源:TomcatBrute.py

示例11: uri_encode_idna

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitport [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

示例12: uri_decode_idna

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitport [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

示例13: normalize_uri

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitport [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

示例14: open_local_file

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitport [as 别名]
def open_local_file(self, req):
        import mimetypes
        import mimetools
        host = req.get_host()
        file = req.get_selector()
        localfile = urllib.url2pathname(file)
        stats = os.stat(localfile)
        size = stats[stat.ST_SIZE]
        modified = rfc822.formatdate(stats[stat.ST_MTIME])
        mtype = mimetypes.guess_type(file)[0]
        if host:
            host, port = urllib.splitport(host)
            if port or socket.gethostbyname(host) not in self.get_names():
                raise urllib2.URLError('file not on local host')
        fo = open(localfile,'rb')
        brange = req.headers.get('Range',None)
        brange = range_header_to_tuple(brange)
        assert brange != ()
        if brange:
            (fb,lb) = brange
            if lb == '': lb = size
            if fb < 0 or fb > size or lb > size:
                raise RangeError(9, 'Requested Range Not Satisfiable')
            size = (lb - fb)
            fo = RangeableFileObject(fo, (fb,lb))
        headers = mimetools.Message(StringIO(
            'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' %
            (mtype or 'text/plain', size, modified)))
        return urllib.addinfourl(fo, headers, 'file:'+file)


# FTP Range Support 
# Unfortunately, a large amount of base FTP code had to be copied
# from urllib and urllib2 in order to insert the FTP REST command.
# Code modifications for range support have been commented as 
# follows:
# -- range support modifications start/end here 
开发者ID:yandex,项目名称:root-2015-tasks,代码行数:39,代码来源:byterange.py


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