#NEWLINE# def encode_component( uri_component , encoding ) : #NEWLINE# #INDENT# if ( uri_component is None ) : #NEWLINE# #INDENT# return uri_component #NEWLINE# #UNINDENT# uri_bytes = to_bytes ( uri_component , encoding ) #NEWLINE# encoded_uri = bytearray ( ) #NEWLINE# for i in range ( 0 , len ( uri_bytes ) ) : #NEWLINE# #INDENT# byte = uri_bytes [ i : ( i + 1 ) ] #NEWLINE# byte_ord = ord ( byte ) #NEWLINE# if ( ( byte_ord < 128 ) and ( byte . decode ( ) in NON_PCT_ENCODED ) ) : #NEWLINE# #INDENT# encoded_uri . extend ( byte ) #NEWLINE# continue #NEWLINE# #UNINDENT# encoded_uri . extend ( '%{0:02x}' . format ( byte_ord ) . encode ( ) ) #NEWLINE# #UNINDENT# return encoded_uri . decode ( encoding )