예제 #1
0
def maybe_dill_dumps(o):
  """Pickle using cPickle or the Dill pickler as a fallback."""
  # We need to use the dill pickler for objects of certain custom classes,
  # including, for example, ones that contain lambdas.
  try:
    return pickle.dumps(o, pickle.HIGHEST_PROTOCOL)
  except Exception:  # pylint: disable=broad-except
    return dill.dumps(o)
예제 #2
0
def maybe_dill_dumps(o):
    """Pickle using cPickle or the Dill pickler as a fallback."""
    # We need to use the dill pickler for objects of certain custom classes,
    # including, for example, ones that contain lambdas.
    try:
        return pickle.dumps(o, pickle.HIGHEST_PROTOCOL)
    except Exception:  # pylint: disable=broad-except
        return dill.dumps(o)
예제 #3
0
  def test_generated_class_pickle(self):
    schema = schema_pb2.Schema(
        id="some-uuid",
        fields=[
            schema_pb2.Field(
                name='name',
                type=schema_pb2.FieldType(atomic_type=schema_pb2.STRING),
            )
        ])
    user_type = named_tuple_from_schema(schema)
    instance = user_type(name="test")

    self.assertEqual(instance, pickle.loads(pickle.dumps(instance)))
예제 #4
0
파일: coders.py 프로젝트: zoltan-kski/beam
 def encode(self, value):
     return base64.b64encode(pickle.dumps(value, pickle.HIGHEST_PROTOCOL))
예제 #5
0
 def encode(self, value):
   return base64.b64encode(pickle.dumps(value, pickle.HIGHEST_PROTOCOL))