MCPcopy Index your code
hub / github.com/python/cpython / _Quoter

Class _Quoter

Lib/urllib/parse.py:999–1018  ·  view source on GitHub ↗

A mapping from bytes numbers (in range(0,256)) to strings. String values are percent-encoded byte values, unless the key < 128, and in either of the specified safe set, or the always safe set.

Source from the content-addressed store, hash-verified

997
998
999class _Quoter(dict):
1000 """A mapping from bytes numbers (in range(0,256)) to strings.
1001
1002 String values are percent-encoded byte values, unless the key < 128, and
1003 in either of the specified safe set, or the always safe set.
1004 """
1005 # Keeps a cache internally, via __missing__, for efficiency (lookups
1006 # of cached keys don't call Python code at all).
1007 def __init__(self, safe):
1008 """safe: bytes object."""
1009 self.safe = _ALWAYS_SAFE.union(safe)
1010
1011 def __repr__(self):
1012 return f"<Quoter {dict(self)!r}>"
1013
1014 def __missing__(self, b):
1015 # Handle a cache miss. Store quoted string in cache and return.
1016 res = chr(b) if b in self.safe else '%{:02X}'.format(b)
1017 self[b] = res
1018 return res
1019
1020def quote(string, safe='/', encoding=None, errors=None):
1021 """quote('abc def') -> 'abc%20def'

Callers 1

_byte_quoter_factoryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…