def _validate_encode_value(value, do_pickle):
 flags = 0
 stored_value = value
 if isinstance(value, str):
  pass
 elif isinstance(value, unicode):
  stored_value = value.encode('utf-8')
  flags |= TYPE_UNICODE
 elif isinstance(value, bool):
  stored_value = str(int(value))
  flags |= TYPE_BOOL
 elif isinstance(value, int):
  stored_value = str(value)
  flags |= TYPE_INT
 elif isinstance(value, long):
  stored_value = str(value)
  flags |= TYPE_LONG
 else:
  stored_value = do_pickle(value)
  flags |= TYPE_PICKLED
 if (len(stored_value) > MAX_VALUE_SIZE):
  raise ValueError(('Values may not be more than %d bytes in length; received %d bytes' % (MAX_VALUE_SIZE, len(stored_value))))
 return (stored_value, flags)

def _validate_encode_value ( value , do_pickle ) : flags = 0 stored_value = value if isinstance ( value , str ) : pass elif isinstance ( value , unicode ) : stored_value = value . encode ( 'utf-8' ) flags |= TYPE_UNICODE elif isinstance ( value , bool ) : stored_value = str ( int ( value ) ) flags |= TYPE_BOOL elif isinstance ( value , int ) : stored_value = str ( value ) flags |= TYPE_INT elif isinstance ( value , long ) : stored_value = str ( value ) flags |= TYPE_LONG else : stored_value = do_pickle ( value ) flags |= TYPE_PICKLED if ( len ( stored_value ) > MAX_VALUE_SIZE ) : raise ValueError ( ( 'Values may not be more than %d bytes in length; received %d bytes' % ( MAX_VALUE_SIZE , len ( stored_value ) ) ) ) return ( stored_value , flags )
utility function to validate and encode server keys and values .