old_contents: #!/usr/bin/env python
  """
  common tools for parsers
  """
  
  import sys
  import simplejson
  
  def netstring(x):
      """
          >>> netstring('banana')
          '6:banana,'
      """
      return str(len(x)) + ':' + x + ','
  
  def jsonify(d):
      return simplejson.dumps(d, indent=2, sort_keys=True)
  
  def export(generator):
      for item in generator:
          sys.stdout.write(netstring(jsonify(item)))
  
  if __name__ == "__main__":
      import doctest
      doctest.testmod()
  
new_contents: #!/usr/bin/env python
  """
  common tools for parsers
  """
  
  import sys
  import simplejson
  
  def netstring(x):
      """
          >>> netstring('banana')
          '6:banana,'
      """
      return str(len(x)) + ':' + x + ','
  
  def jsonify(d):
      return simplejson.dumps(d, indent=2, sort_keys=True)
  
  def export(generator):
      for item in generator:
          sys.stdout.write(netstring(jsonify(item)))
  
  def unexport(fh):
      n = '0'
      while n:
          n = int(n + ''.join(c for c in iter(lambda: fh.read(1), ':')))
          yield simplejson.loads(fh.read(n))
          assert fh.read(1) == ','
          n = fh.read(1)
  
  if __name__ == "__main__":
      import doctest
      doctest.testmod()
  
subject: add unexport function for njs format