def quote_from_bytes(bs, safe='/'):
 if (not isinstance(bs, (bytes, bytearray))):
  raise TypeError('quote_from_bytes() expected bytes')
 if (not bs):
  return ''
 if isinstance(safe, str):
  safe = safe.encode('ascii', 'ignore')
 else:
  safe = bytes([c for c in safe if (c < 128)])
 if (not bs.rstrip((_ALWAYS_SAFE_BYTES + safe))):
  return bs.decode()
 try:
  quoter = _safe_quoters[safe]
 except KeyError:
  _safe_quoters[safe] = quoter = Quoter(safe).__getitem__
 return ''.join([quoter(char) for char in bs])

def quote_from_bytes ( bs , safe = '/' ) : if ( not isinstance ( bs , ( bytes , bytearray ) ) ) : raise TypeError ( 'quote_from_bytes() expected bytes' ) if ( not bs ) : return '' if isinstance ( safe , str ) : safe = safe . encode ( 'ascii' , 'ignore' ) else : safe = bytes ( [ c for c in safe if ( c < 128 ) ] ) if ( not bs . rstrip ( ( _ALWAYS_SAFE_BYTES + safe ) ) ) : return bs . decode ( ) try : quoter = _safe_quoters [ safe ] except KeyError : _safe_quoters [ safe ] = quoter = Quoter ( safe ) . __getitem__ return '' . join ( [ quoter ( char ) for char in bs ] )
like quote() .