當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。