Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@pytest.fixture(params=[_PyQuoter, _Quoter], ids=["py_quoter", "c_quoter"])
def quoter(request):
return request.param
def test_quote_fastpath_pct():
s1 = "abc%A0"
s2 = _Quoter()(s1)
assert s1 is s2
def test_quote_fastpath_safe():
s1 = "/path/to"
s2 = _Quoter(safe="/")(s1)
assert s1 is s2
# segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
# ; non-zero-length segment without any colon ":"
# pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
# query = *( pchar / "/" / "?" )
# fragment = *( pchar / "/" / "?" )
# URI-reference = URI / relative-ref
# relative-ref = relative-part [ "?" query ] [ "#" fragment ]
# relative-part = "//" authority path-abempty
# / path-absolute
# / path-noscheme
# / path-empty
# absolute-URI = scheme ":" hier-part [ "?" query ]
__slots__ = ("_cache", "_val")
_QUOTER = _Quoter()
_PATH_QUOTER = _Quoter(safe="@:", protected="/+")
_QUERY_QUOTER = _Quoter(safe="?/:@", protected="=+&;", qs=True)
_QUERY_PART_QUOTER = _Quoter(safe="?/:@", qs=True)
_FRAGMENT_QUOTER = _Quoter(safe="?/:@")
_UNQUOTER = _Unquoter()
_PATH_UNQUOTER = _Unquoter(unsafe="+")
_QS_UNQUOTER = _Unquoter(qs=True)
def __new__(cls, val="", *, encoded=False, strict=None):
if strict is not None: # pragma: no cover
warnings.warn("strict parameter is ignored")
if type(val) is cls:
return val
if type(val) is str:
val = urlsplit(val)
elif type(val) is SplitResult:
# segment-nz = 1*pchar
# segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
# ; non-zero-length segment without any colon ":"
# pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
# query = *( pchar / "/" / "?" )
# fragment = *( pchar / "/" / "?" )
# URI-reference = URI / relative-ref
# relative-ref = relative-part [ "?" query ] [ "#" fragment ]
# relative-part = "//" authority path-abempty
# / path-absolute
# / path-noscheme
# / path-empty
# absolute-URI = scheme ":" hier-part [ "?" query ]
__slots__ = ("_cache", "_val")
_QUOTER = _Quoter()
_PATH_QUOTER = _Quoter(safe="@:", protected="/+")
_QUERY_QUOTER = _Quoter(safe="?/:@", protected="=+&;", qs=True)
_QUERY_PART_QUOTER = _Quoter(safe="?/:@", qs=True)
_FRAGMENT_QUOTER = _Quoter(safe="?/:@")
_UNQUOTER = _Unquoter()
_PATH_UNQUOTER = _Unquoter(unsafe="+")
_QS_UNQUOTER = _Unquoter(qs=True)
def __new__(cls, val="", *, encoded=False, strict=None):
if strict is not None: # pragma: no cover
warnings.warn("strict parameter is ignored")
if type(val) is cls:
return val
if type(val) is str:
val = urlsplit(val)
# ; non-zero-length segment without any colon ":"
# pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
# query = *( pchar / "/" / "?" )
# fragment = *( pchar / "/" / "?" )
# URI-reference = URI / relative-ref
# relative-ref = relative-part [ "?" query ] [ "#" fragment ]
# relative-part = "//" authority path-abempty
# / path-absolute
# / path-noscheme
# / path-empty
# absolute-URI = scheme ":" hier-part [ "?" query ]
__slots__ = ("_cache", "_val")
_QUOTER = _Quoter()
_PATH_QUOTER = _Quoter(safe="@:", protected="/+")
_QUERY_QUOTER = _Quoter(safe="?/:@", protected="=+&;", qs=True)
_QUERY_PART_QUOTER = _Quoter(safe="?/:@", qs=True)
_FRAGMENT_QUOTER = _Quoter(safe="?/:@")
_UNQUOTER = _Unquoter()
_PATH_UNQUOTER = _Unquoter(unsafe="+")
_QS_UNQUOTER = _Unquoter(qs=True)
def __new__(cls, val="", *, encoded=False, strict=None):
if strict is not None: # pragma: no cover
warnings.warn("strict parameter is ignored")
if type(val) is cls:
return val
if type(val) is str:
val = urlsplit(val)
elif type(val) is SplitResult:
if not encoded:
# pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
# query = *( pchar / "/" / "?" )
# fragment = *( pchar / "/" / "?" )
# URI-reference = URI / relative-ref
# relative-ref = relative-part [ "?" query ] [ "#" fragment ]
# relative-part = "//" authority path-abempty
# / path-absolute
# / path-noscheme
# / path-empty
# absolute-URI = scheme ":" hier-part [ "?" query ]
__slots__ = ("_cache", "_val")
_QUOTER = _Quoter()
_PATH_QUOTER = _Quoter(safe="@:", protected="/+")
_QUERY_QUOTER = _Quoter(safe="?/:@", protected="=+&;", qs=True)
_QUERY_PART_QUOTER = _Quoter(safe="?/:@", qs=True)
_FRAGMENT_QUOTER = _Quoter(safe="?/:@")
_UNQUOTER = _Unquoter()
_PATH_UNQUOTER = _Unquoter(unsafe="+")
_QS_UNQUOTER = _Unquoter(qs=True)
def __new__(cls, val="", *, encoded=False, strict=None):
if strict is not None: # pragma: no cover
warnings.warn("strict parameter is ignored")
if type(val) is cls:
return val
if type(val) is str:
val = urlsplit(val)
elif type(val) is SplitResult:
if not encoded:
raise ValueError("Cannot apply decoding to SplitResult")
def __init__(self, *, unsafe: str = "", qs: bool = False) -> None:
self._unsafe = unsafe
self._qs = qs
self._quoter = _Quoter()
self._qs_quoter = _Quoter(qs=True)