def serialize(self, value): """See base class.""" if isinstance(value, list): return self.list_sep.join( _helpers.str_or_unicode(x.name) for x in value) else: return _helpers.str_or_unicode(value.name)
def _get_parsed_value_as_string(self, value): """Returns parsed flag value as string.""" if value is None: return None if self.serializer: return repr(self.serializer.serialize(value)) if self.boolean: if value: return repr('true') else: return repr('false') return repr(_helpers.str_or_unicode(value))
def serialize(self, value): """Serializes a list as a CSV string or unicode.""" if six.PY2: # In Python2 csv.writer doesn't accept unicode, so we convert to UTF-8. output = io.BytesIO() csv.writer(output).writerow([unicode(x).encode('utf-8') for x in value]) serialized_value = output.getvalue().decode('utf-8').strip() else: # In Python3 csv.writer expects a text stream. output = io.StringIO() csv.writer(output).writerow([str(x) for x in value]) serialized_value = output.getvalue().strip() # We need the returned value to be pure ascii or Unicodes so that # when the xml help is generated they are usefully encodable. return _helpers.str_or_unicode(serialized_value)
def serialize(self, value): """Serializes a list as a CSV string or unicode.""" if six.PY2: # In Python2 csv.writer doesn't accept unicode, so we convert to UTF-8. output = io.BytesIO() csv.writer(output).writerow( [unicode(x).encode('utf-8') for x in value]) serialized_value = output.getvalue().decode('utf-8').strip() else: # In Python3 csv.writer expects a text stream. output = io.StringIO() csv.writer(output).writerow([str(x) for x in value]) serialized_value = output.getvalue().strip() # We need the returned value to be pure ascii or Unicodes so that # when the xml help is generated they are usefully encodable. return _helpers.str_or_unicode(serialized_value)
def serialize(self, value): """Returns a serialized string of the Enum class value.""" as_string = _helpers.str_or_unicode(value.name) return as_string.lower() if self._lowercase else as_string
def serialize(self, value): """See base class.""" return self.list_sep.join([_helpers.str_or_unicode(x) for x in value])
def serialize(self, value): """Returns a serialized string of the value.""" return _helpers.str_or_unicode(value)