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


Python encoding.recode_uri函数代码示例

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


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

示例1: test_dots_fixup

def test_dots_fixup():
    # Real-world example:
    # http://www.yelp.com/biz/orange-county-church-of-christ-irvine
    strange_url = 'http://.ocregion.com'
    normalized_url = E.recode_uri(strange_url)
    assert normalized_url == 'http://ocregion.com'

    # Extreme example
    strange_url = 'http://[email protected]:8080/'
    normalized_url = E.recode_uri(strange_url)
    assert normalized_url == 'http://[email protected]:8080/'
开发者ID:Yelp,项目名称:yelp_uri,代码行数:11,代码来源:encoding_test.py

示例2: test_letters_recoding

def test_letters_recoding():
    """Tests that alphanumeric escapes get unquoted in recode_uri."""
    url = (
        u'http://💩.la/%74%68%69%73%5f%69%73%5f%61%5f%70%61%74%68'
        u'?a=b%3f%63&%64%3D%65=f#%73%70%61%63%65%73 %61%72%65 %64%61%6e%67%65%72%6f%75%73'
    )
    assert E.recode_uri(url) == \
        'http://xn--ls8h.la/this_is_a_path?a=b%3fc&d%3De=f#spaces%20are%20dangerous'
开发者ID:Yelp,项目名称:yelp_uri,代码行数:8,代码来源:encoding_test.py

示例3: test_url_with_params

def test_url_with_params():
    url = (
        'http://ad.doubleclick.net/clk;217976351;41128009;f?'
        'http%3A//www.24hourfitness.com/FindClubDetail.do?'
        'clubid=189&edit=null&semiPromoCode=null&cm_mmc='
        'Yelp-_-ClubPage-_-BusinessListing-_-Link'
    )
    assert E.recode_uri(url) == url
开发者ID:Yelp,项目名称:yelp_uri,代码行数:8,代码来源:encoding_test.py

示例4: test_worst_case_unicode

def test_worst_case_unicode():
    # Test both unicode and utf8-bytes
    for umlaut in (u'ü', 'ü'):
        strange_url = worst_case(umlaut)
        normalized_url = E.recode_uri(strange_url)

        # I think this makes things more readable
        processed = normalized_url.replace('%C3%BC', '%')
        assert processed == 'http://%:%@www.xn--tda.com/%;%;%/%;%;%?%=%&%=%#!%/%'
开发者ID:Yelp,项目名称:yelp_uri,代码行数:9,代码来源:encoding_test.py

示例5: test_bad_bytes

def test_bad_bytes():
    # This is unlikely to happen except due to gross programming error,
    # but I want to show what *would* happen.
    for bad_stuff in (u'\xFF', b'\xFF', u'%FF', b'%FF'):
        strange_url = worst_case(bad_stuff)
        normalized_url = E.recode_uri(strange_url)

        # I think this makes things more readable
        processed = normalized_url.replace('%C3%BF', '%')
        assert processed == 'http://%:%@www.xn--wda.com/%;%;%/%;%;%?%=%&%=%#!%/%'
开发者ID:Yelp,项目名称:yelp_uri,代码行数:10,代码来源:encoding_test.py

示例6: test_recode_encoded

def test_recode_encoded(charname, chars, pathchars, expected_url, encoding):
    url_template = u"http://m{chars}nchen.com/m{chars}chen/{pathchars}"
    unicode_url = url_template.format(chars=chars, pathchars=pathchars)

    try:
        encoded_url = unicode_url.encode(encoding)
    except UnicodeEncodeError:
        pytest.skip("Some of these things just won't go.")

    assert E.recode_uri(encoded_url) == expected_url

    quoted_url = url_template.format(
        chars=quote(chars.encode(encoding)),
        pathchars=quote(pathchars.encode(encoding)),
    )
    if charname == 'ascii':
        # ASCII is a special case when it comes to quoting: their quoted-ness should go untouched.
        assert E.recode_uri(quoted_url) == quoted_url
    else:
        assert E.recode_uri(quoted_url) == expected_url
开发者ID:Yelp,项目名称:yelp_uri,代码行数:20,代码来源:encoding_test.py

示例7: test_worst_case_ascii

def test_worst_case_ascii():
    for ascii_char in '<> ':
        strange_url = worst_case(ascii_char)
        normalized_url = E.recode_uri(strange_url)

        escaped_char = '%%%2X' % ord(ascii_char)
        assert escaped_char in normalized_url

        # I think this makes things more readable
        processed = normalized_url.replace(ascii_char, '{ascii_char}')
        processed = processed.replace(escaped_char, '%')
        assert processed == 'http://%:%@www.{ascii_char}.com/%;%;%/%;%;%?%=%&%=%#!%/%'
开发者ID:Yelp,项目名称:yelp_uri,代码行数:12,代码来源:encoding_test.py

示例8: test_recode_unicode

def test_recode_unicode(charname, chars, pathchars, expected_url):
    del charname  # passed, but unused
    url_template = u"http://m{chars}nchen.com/m{chars}chen/{pathchars}"
    unicode_url = url_template.format(chars=chars, pathchars=pathchars)
    assert E.recode_uri(unicode_url) == expected_url
开发者ID:Yelp,项目名称:yelp_uri,代码行数:5,代码来源:encoding_test.py

示例9: test_path_only_url

def test_path_only_url():
    strange_url = '/➨ ?➨ #➨ '
    expected = '/%E2%9E%A8%20?%E2%9E%A8%20#%E2%9E%A8%20'
    processed = E.recode_uri(strange_url)
    assert processed == expected
开发者ID:Yelp,项目名称:yelp_uri,代码行数:5,代码来源:encoding_test.py

示例10: test_url_with_hashbang

def test_url_with_hashbang():
    # For a discussion of url hashbangs, see: http://www.jenitennison.com/blog/node/154
    url = 'https://twitter.com/#!/YelpCincy/statuses/179565284020060161'
    assert E.recode_uri(url) == url
开发者ID:Yelp,项目名称:yelp_uri,代码行数:4,代码来源:encoding_test.py

示例11: test_url_reserved_chars

def test_url_reserved_chars():
    url = 'http://www.yelp.com?chars=%s' % quote(':/?&=')
    assert E.recode_uri(url) == url
开发者ID:Yelp,项目名称:yelp_uri,代码行数:3,代码来源:encoding_test.py

示例12: test_utf8_url

def test_utf8_url():
    """Tests that a url with mixed quoting in multiple parameters has uniform quoting after requoting"""
    url = u'http://yelp.com/münchen/m%C3%BCnchen?münchen=m%C3%BCnchen&htmlchars=<">'.encode('utf-8')
    assert E.recode_uri(url) == \
        'http://yelp.com/m%C3%BCnchen/m%C3%BCnchen?m%C3%BCnchen=m%C3%BCnchen&htmlchars=%3C%22%3E'
开发者ID:Yelp,项目名称:yelp_uri,代码行数:5,代码来源:encoding_test.py

示例13: test_mixed_quoting_param

def test_mixed_quoting_param():
    """Tests that a url with mixed quoting in the parameters has uniform quoting after requoting"""
    url = u'http://www.yelp.com?m%C3%BCnchen=münchen'
    assert E.recode_uri(url) == 'http://www.yelp.com?m%C3%BCnchen=m%C3%BCnchen'
开发者ID:Yelp,项目名称:yelp_uri,代码行数:4,代码来源:encoding_test.py

示例14: test_unicode_url_gets_quoted

def test_unicode_url_gets_quoted():
    url = u'http://www.yelp.com/münchen'
    assert E.recode_uri(url) == 'http://www.yelp.com/m%C3%BCnchen'
开发者ID:Yelp,项目名称:yelp_uri,代码行数:3,代码来源:encoding_test.py

示例15: test_param_xss

def test_param_xss():
    assert E.recode_uri('/foo;<script>;baz/barney;%2F%3B%25;wilma') == '/foo;%3Cscript%3E;baz/barney;%2F%3B%25;wilma'
开发者ID:Yelp,项目名称:yelp_uri,代码行数:2,代码来源:encoding_test.py


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