MCPcopy Create free account
hub / github.com/aws/aws-cli / percent_encode

Function percent_encode

awscli/botocore/utils.py:757–775  ·  view source on GitHub ↗

Urlencodes a string. Whereas percent_encode_sequence handles taking a dict/sequence and producing a percent encoded string, this function deals only with taking a string (not a dict/sequence) and percent encoding it. If given the binary type, will simply URL encode it. If given the

(input_str, safe=SAFE_CHARS)

Source from the content-addressed store, hash-verified

755
756
757def percent_encode(input_str, safe=SAFE_CHARS):
758 """Urlencodes a string.
759
760 Whereas percent_encode_sequence handles taking a dict/sequence and
761 producing a percent encoded string, this function deals only with
762 taking a string (not a dict/sequence) and percent encoding it.
763
764 If given the binary type, will simply URL encode it. If given the
765 text type, will produce the binary type by UTF-8 encoding the
766 text. If given something else, will convert it to the text type
767 first.
768 """
769 # If its not a binary or text string, make it a text string.
770 if not isinstance(input_str, (bytes, str)):
771 input_str = str(input_str)
772 # If it's not bytes, make it bytes by UTF-8 encoding it.
773 if not isinstance(input_str, bytes):
774 input_str = input_str.encode('utf-8')
775 return quote(input_str, safe=safe)
776
777
778def _epoch_seconds_to_datetime(value, tzinfo):

Callers 8

uri_encodeMethod · 0.90
_render_uri_templateMethod · 0.90
_quote_source_headerFunction · 0.90
percent_encode_sequenceFunction · 0.85

Calls 1

encodeMethod · 0.45

Tested by 3