<commit_before># vim: set ts=2 et:
from .fields import Field

__all__ = ['DateTimeField', 'EncodedStringField']


class DateTimeField(Field):
  def to_wire(self, date):
    if date is not None:
      date = date.isoformat()
    return date

  def from_wire(self, data):
    import dateutil.parser
    if data is None:
      return None
    return dateutil.parser.parse(data)


class EncodedStringField(Field):
  __slots__ = ('encoding', )

  def __init__(self, encoding='utf-8', **kwargs):
    super(EncodedStringField, self).__init__(**kwargs)
    self.encoding = encoding

  def to_wire(self, string):
    if string is not None:
      string = string.encode(self.encoding)
    return string

  def from_wire(self, data):
    if data is None:
      return none
    return data.decode(self.encoding)<commit_msg>Fix none -> None<commit_after># vim: set ts=2 et:
from .fields import Field

__all__ = ['DateTimeField', 'EncodedStringField']


class DateTimeField(Field):
  def to_wire(self, date):
    if date is not None:
      date = date.isoformat()
    return date

  def from_wire(self, data):
    import dateutil.parser
    if data is None:
      return None
    return dateutil.parser.parse(data)


class EncodedStringField(Field):
  __slots__ = ('encoding', )

  def __init__(self, encoding='utf-8', **kwargs):
    super(EncodedStringField, self).__init__(**kwargs)
    self.encoding = encoding

  def to_wire(self, string):
    if string is not None:
      string = string.encode(self.encoding)
    return string

  def from_wire(self, data):
    if data is None:
      return None
    return data.decode(self.encoding)
{'fraction_non_alphanumeric': 0.10830769230769231, 'fraction_numerical': 0.0024615384615384616, 'mean_word_length': 3.4547945205479453, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4918703', 'n_tokens_mistral': 518, 'n_tokens_neox': 504, 'n_words': 149}