Esempio n. 1
0
File: utils.py Progetto: EdDev/vdsm
def picklecopy(obj):
    """
    Returns a deep copy of argument,
    like copy.deepcopy() does, but faster.

    To be faster, this function leverages the pickle
    module. The following types are safely handled:

    * None, True, and False
    * integers, long integers, floating point numbers,
      complex numbers
    * normal and Unicode strings
    * tuples, lists, sets, and dictionaries containing
      only picklable objects
    * functions defined at the top level of a module
    * built-in functions defined at the top level of a module
    * classes that are defined at the top level of a module
    * instances of such classes whose __dict__ or the
      result of calling __getstate__() is picklable.

    Attempts to pickle unpicklable objects will raise the
    PicklingError exception;
    For full documentation, see:
    https://docs.python.org/2/library/pickle.html
    """
    return pickle.loads(pickle.dumps(obj, pickle.HIGHEST_PROTOCOL))
Esempio n. 2
0
def picklecopy(obj):
    """
    Returns a deep copy of argument,
    like copy.deepcopy() does, but faster.

    To be faster, this function leverages the pickle
    module. The following types are safely handled:

    * None, True, and False
    * integers, long integers, floating point numbers,
      complex numbers
    * normal and Unicode strings
    * tuples, lists, sets, and dictionaries containing
      only picklable objects
    * functions defined at the top level of a module
    * built-in functions defined at the top level of a module
    * classes that are defined at the top level of a module
    * instances of such classes whose __dict__ or the
      result of calling __getstate__() is picklable.

    Attempts to pickle unpicklable objects will raise the
    PicklingError exception;
    For full documentation, see:
    https://docs.python.org/2/library/pickle.html
    """
    return pickle.loads(pickle.dumps(obj, pickle.HIGHEST_PROTOCOL))
Esempio n. 3
0
File: vdsmapi.py Progetto: nirs/vdsm
    def __init__(self, schema_types, strict_mode):
        """
        Constructs schema object based on an iterable of schema type
        enumerations and a mode which determines request/response
        validation behavior. Usually it is based on api_strict_mode
        property from config.py
        """
        self._strict_mode = strict_mode
        self._methods = {}
        self._types = {}
        try:
            for schema_type in schema_types:
                with io.open(schema_type.path(), 'rb') as f:
                    loaded_schema = pickle.loads(f.read())

                types = loaded_schema.pop('types')
                self._types.update(types)
                self._methods.update(loaded_schema)
        except EnvironmentError:
            raise SchemaNotFound("Unable to find API schema file")
Esempio n. 4
0
    def __init__(self, schema_types, strict_mode):
        """
        Constructs schema object based on an iterable of schema type
        enumerations and a mode which determines request/response
        validation behavior. Usually it is based on api_strict_mode
        property from config.py
        """
        self._strict_mode = strict_mode
        self._methods = {}
        self._types = {}
        try:
            for schema_type in schema_types:
                with io.open(schema_type.path(), 'rb') as f:
                    loaded_schema = pickle.loads(f.read())

                types = loaded_schema.pop('types')
                self._types.update(types)
                self._methods.update(loaded_schema)
        except EnvironmentError:
            raise SchemaNotFound("Unable to find API schema file")
Esempio n. 5
0
 def test_pickle_copy(self):
     p1 = ProtectedPassword("12345678")
     p2 = pickle.loads(pickle.dumps(p1))
     self.assertEqual(p1, p2)
Esempio n. 6
0
 def test_pickle_copy(self):
     p1 = ProtectedPassword("12345678")
     p2 = pickle.loads(pickle.dumps(p1))
     self.assertEqual(p1, p2)