def to_asciihex(b):
  """
  Convert raw binary data to a sequence of ASCII-encoded hex bytes,
  suitable for import via COPY .. CSV into a PostgreSQL bytea field.
  """
  return '\\x'+''.join('%.2x' % ord(x) for x in b)