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


Python url.parse函数代码示例

本文整理汇总了Python中url.parse函数的典型用法代码示例。如果您正苦于以下问题:Python parse函数的具体用法?Python parse怎么用?Python parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test

 def test(rules, example, pld, tld):
     try:
         url.set_psl(rules)
         assert_equal(url.parse(example).pld, pld)
         assert_equal(url.parse(example).tld, tld)
     finally:
         url.set_psl(pkgutil.get_data('url', 'psl/2016-08-16.psl'))
开发者ID:seomoz,项目名称:url-py,代码行数:7,代码来源:test.py

示例2: __init__

 def __init__(self, target, **params):
     if isinstance(target, basestring):
         self._host = url.parse(target)
     elif isinstance(target, (tuple, list)):
         self._host = url.parse('http://%s:%s/' % target)
     else:
         raise TypeError('Host must be a string or tuple')
     self._params = params
开发者ID:dlecocq,项目名称:nsq-py,代码行数:8,代码来源:__init__.py

示例3: test_str_repr

    def test_str_repr(self):
        '''Make sure str and repr produce reasonable results'''
        examples = [
            ('http://foo.com/', 'http://foo.com/'),
            ('http://FOO.com/', 'http://foo.com/')
        ]

        for toparse, strng in examples:
            self.assertEqual(str(url.parse(toparse)), strng)
            self.assertEqual(repr(url.parse(toparse)),
                '<url.URL object "%s" >' % strng)
开发者ID:wil,项目名称:url-py,代码行数:11,代码来源:test.py

示例4: test_empty_hostname

 def test_empty_hostname(self):
     '''Allow empty hostnames'''
     examples = [
         'http:///path',
         'http://[email protected]/path',
         'http://:80/path',
     ]
     for example in examples:
         # Equal to itself
         self.assertEqual(url.parse(example), example)
         # String representation equal to the provided example
         self.assertEqual(url.parse(example).utf8(), example)
开发者ID:mherdeg,项目名称:url-py,代码行数:12,代码来源:test.py

示例5: test

 def test(uni, puny, upuny, epuny):
     assert_equal(url.parse(uni).escape().punycode().utf8(), epuny)
     # Also make sure punycode is idempotent
     assert_equal(
         url.parse(uni).escape().punycode().punycode().utf8(), epuny)
     # Make sure that we can reverse the procedure correctly
     assert_equal(
         url.parse(uni).escape().punycode().unpunycode().unescape(),
         uni)
     # And we get what we'd expect going the opposite direction
     assert_equal(
         url.parse(puny).unescape().unpunycode().unicode(), uni)
开发者ID:masayuko,项目名称:url-py,代码行数:12,代码来源:test.py

示例6: _response_to_features

def _response_to_features(response):
    features = set()
    tree = etree.HTML(response.text)

    for item in tree.iter(tag=etree.Element):
        features.add("tag-%s" % item.tag)

        if "class" in item.attrib and item.attrib["class"].strip():
            classes = whitespace.split(item.attrib["class"])
            for _c in classes:
                c = _c.strip()
                if c:
                    features.add("class-%s" % c)

        if "id" in item.attrib:
            features.add("id-%s" % item.attrib["id"])

    # path parts
    u = moz_url.parse(response.url)
    path = u._path.split("/")[1:]
    for idx, part in enumerate(path):
        features.add("path-%s-%s" % (idx, path))

    if u._query:
        for k, vl in urlparse.parse_qs(u._query).iteritems():
            features.add("qse-%s" % k)
            for v in vl:
                features.add("qsv-%s-%s" % (k, v))

    return features
开发者ID:apendleton,项目名称:mlscrape,代码行数:30,代码来源:page.py

示例7: test_abspath

    def test_abspath(self):
        '''Make sure absolute path checking works correctly'''
        examples = [
            ('howdy'           , 'howdy'        ),
            ('hello//how//are' , 'hello/how/are'),
            ('hello/../how/are', 'how/are'      ),
            ('hello//..//how/' , 'how/'         ),
            ('a/b/../../c'     , 'c'            ),
            ('../../../c'      , 'c'            ),
            ('./hello'         , 'hello'        ),
            ('./././hello'     , 'hello'        ),
            ('a/b/c/'          , 'a/b/c/'       ),
            ('a/b/c/..'        , 'a/b/'         ),
            ('a/b/.'           , 'a/b/'         ),
            ('a/b/./././'      , 'a/b/'         ),
            ('a/b/../'         , 'a/'           ),
            ('.'               , ''             ),
            ('../../..'        , ''             ),
            ('////foo'         , 'foo'          )
        ]

        base = 'http://testing.com/'
        for bad, good in examples:
            bad = base + bad
            good = base + good
            self.assertEqual(url.parse(bad).abspath().utf8(), good)
开发者ID:wil,项目名称:url-py,代码行数:26,代码来源:test.py

示例8: test_deuserinfo

 def test_deuserinfo(self):
     '''Correctly removes userinfo'''
     examples = [
         ('http://user:[email protected]/', 'http://foo.com/'),
         ('http://[email protected]/', 'http://foo.com/')
     ]
     for bad, good in examples:
         self.assertEqual(url.parse(bad).deuserinfo().utf8(), good)
开发者ID:mherdeg,项目名称:url-py,代码行数:8,代码来源:test.py

示例9: save

def save(url_, path="", wait=60):
    if hasattr(url_, "url"):
        url_ = url_.url
    if len(path) < 5 or "." not in path[-5:-3]:
        file = url.parse(str(url_)).filename
        path = os.path.join(path, file)
    open(path, "w").write(download(url_, wait))
    return path
开发者ID:imclab,项目名称:plotdevice-libs,代码行数:8,代码来源:__init__.py

示例10: test_tld

 def test_tld(self):
     '''Test the pay-level domain functionality'''
     examples = [
         ('http://foo.com/bar'    , 'com'),
         ('http://bar.foo.com/bar', 'com'),
         ('/foo'                  , '')
     ]
     for query, result in examples:
         self.assertEqual(url.parse(query).tld(), result)
开发者ID:mherdeg,项目名称:url-py,代码行数:9,代码来源:test.py

示例11: test_escape

    def test_escape(self):
        '''Make sure we escape paths correctly'''
        examples = [
            ('hello%20and%20how%20are%20you', 'hello%20and%20how%20are%20you'),
            ('danny\'s pub'                 , 'danny%27s%20pub'              ),
            ('danny%27s pub?foo=bar&yo'     , 'danny%27s%20pub?foo=bar&yo'   ),
            # Thanks to @myronmarston for these test cases
            ('foo?bar none=foo bar'         , 'foo?bar%20none=foo%20bar'     ),
            ('foo;a=1;b=2?a=1&b=2'          , 'foo;a=1;b=2?a=1&b=2'          ),
            ('foo?bar=["hello","howdy"]'    ,
                'foo?bar=%5B%22hello%22,%22howdy%22%5D'),
        ]

        base = 'http://testing.com/'
        for bad, good in examples:
            bad = base + bad
            good = base + good
            self.assertEqual(url.parse(bad).escape().utf8(), good)
            # Escaping should also be idempotent
            self.assertEqual(url.parse(bad).escape().escape().utf8(), good)
开发者ID:wil,项目名称:url-py,代码行数:20,代码来源:test.py

示例12: test_userinfo

 def test_userinfo(self):
     '''Allow a userinfo section'''
     examples = [
         ('http://user:[email protected]',   'http://user:[email protected]'),
         ('http://[email protected]', 'http://[email protected]')
     ]
     suffix = '/page.html'
     for bad, good in examples:
         bad = bad + suffix
         good = good + suffix
         self.assertEqual(url.parse(bad).utf8(), good)
开发者ID:mherdeg,项目名称:url-py,代码行数:11,代码来源:test.py

示例13: test_absolute

    def test_absolute(self):
        '''Can it recognize if it's a relative or absolute url?'''
        examples = [
            ('http://foo.com/bar', True ),
            ('foo/'              , False),
            ('http://foo.com'    , True ),
            ('/foo/bar/../'      , False)
        ]

        for query, result in examples:
            self.assertEqual(url.parse(query).absolute(), result)
开发者ID:wil,项目名称:url-py,代码行数:11,代码来源:test.py

示例14: test_sanitize

    def test_sanitize(self):
        '''Make sure the sanitize method does all that it should'''
        examples = [
            ('../foo/bar none', 'foo/bar%20none')
        ]

        base = 'http://testing.com/'
        for bad, good in examples:
            bad = base + bad
            good = base + good
            self.assertEqual(url.parse(bad).sanitize().utf8(), good)
开发者ID:wil,项目名称:url-py,代码行数:11,代码来源:test.py

示例15: test_lower

 def test_lower(self):
     '''Can lowercase the domain name correctly'''
     examples = [
         ('www.TESTING.coM'    , 'www.testing.com/'   ),
         ('WWW.testing.com'    , 'www.testing.com/'   ),
         ('WWW.testing.com/FOO', 'www.testing.com/FOO')
     ]
     for bad, good in examples:
         bad = 'http://' + bad
         good = 'http://' + good
         self.assertEqual(url.parse(bad).utf8(), good)
开发者ID:wil,项目名称:url-py,代码行数:11,代码来源:test.py


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