From 879c6b195d6b352ee009dab8da3ebab40fba95d5 Mon Sep 17 00:00:00 2001 From: Erik Nyquist Date: Sat, 5 Nov 2022 15:31:32 -0700 Subject: [PATCH] Update docs build --- docs/_modules/versionedobj/serializer.html | 60 +++++---- docs/index.html | 147 +++++++++++++-------- docs/searchindex.js | 2 +- docs/versionedobj.html | 34 ++--- 4 files changed, 145 insertions(+), 98 deletions(-) diff --git a/docs/_modules/versionedobj/serializer.html b/docs/_modules/versionedobj/serializer.html index 4b39405..1fbed9f 100644 --- a/docs/_modules/versionedobj/serializer.html +++ b/docs/_modules/versionedobj/serializer.html @@ -111,10 +111,10 @@

Source code for versionedobj.serializer

     """
     Class for serializing/deserializing any VersionedObject types
     """
-
[docs] def __init__(self): - pass
+
[docs] def __init__(self, obj=None): + self.obj = obj
-
[docs] def to_dict(self, obj, only=[], ignore=[]): +
[docs] def to_dict(self, obj=None, only=[], ignore=[]): """ Convert object to a dict, suitable for passing to the json library @@ -125,14 +125,15 @@

Source code for versionedobj.serializer

         :return: object data as a dict
         :rtype: dict
         """
-        return _obj_to_dict(obj, only, ignore)
+ return _obj_to_dict(obj if obj is not None else self.obj, only, ignore)
-
[docs] def validate_dict(self, obj, attrs, only=[], ignore=[]): +
[docs] def validate_dict(self, attrs, obj=None, only=[], ignore=[]): """ Validate a versioned object in dict form. - :param obj: VersionedObject instance you want to validate the dict against :param dict attrs: dict to validate + :param obj: VersionedObject instance you want to validate the dict against. If unset,\ + object passed to __init__ will be used instead :param list only: Whitelist of attribute names to validate (cannot be used with 'ignore') :param list ignore: Blacklist of attribute names to exclude from validation (cannot be used with 'only') @@ -145,6 +146,8 @@

Source code for versionedobj.serializer

         if only and ignore:
             raise InvalidFilterError("Cannot use both 'only' and 'ignore'")
 
+        obj = obj if obj is not None else self.obj
+
         # Create a map of all object attribute names, to track which attributes have
         # also been seen in the dict
         obj_attrs_loaded = {}
@@ -179,12 +182,13 @@ 

Source code for versionedobj.serializer

         if missing:
             raise InputValidationError(f"Attributes missing from dict: {','.join(missing)}")
-
[docs] def from_dict(self, obj, attrs, validate=True, only=[], ignore=[]): +
[docs] def from_dict(self, attrs, obj=None, validate=True, only=[], ignore=[]): """ Populate instance attributes of a VersionedObjbect instance, with object data from a dict. - :param obj: VersionedObject instance to populate :param dict attrs: dict containing object data + :param obj: VersionedObject instance to populate. If unset,\ + object passed to __init__ will be used instead :param bool validate: If false, pre-validation will be skipped for the input data.\ This may be useful if you want to load a partial object that is missing some fields,\ and don't want to mess with filtering. @@ -201,13 +205,15 @@

Source code for versionedobj.serializer

         if only and ignore:
             raise InvalidFilterError("Cannot use both 'only' and 'ignore'")
 
+        obj = obj if obj is not None else self.obj
+
         version = obj.__dict__.get('version', None)
         migration_result, attrs = obj._vobj__migrate(version, attrs)
         if (migration_result is not None) and (not migration_result.success):
             return migration_result
 
         if validate:
-            self.validate_dict(obj, attrs, only, ignore)
+            self.validate_dict(attrs, obj, only, ignore)
 
         # Delete version field from dict, if it exists
         if 'version' in attrs:
@@ -222,12 +228,13 @@ 

Source code for versionedobj.serializer

 
         return migration_result
-
[docs] def to_json(self, obj, indent=None, only=[], ignore=[]): +
[docs] def to_json(self, obj=None, indent=None, only=[], ignore=[]): """ Generate a JSON string containing all data from a VersionedObject instance - :param obj: VersionedObject instance :param int indent: Indentation level to use, in columns. If None, everything will be on one line. + :param obj: VersionedObject instance to serialize. If unset, object passed to __init__\ + will be used instead :param list only: Whitelist of field names to serialize (cannot be used with blacklist) :param list ignore: Blacklist of field names to ignore (cannot be used with whitelist) @@ -236,12 +243,13 @@

Source code for versionedobj.serializer

         """
         return json.dumps(self.to_dict(obj, only, ignore), indent=indent)
-
[docs] def from_json(self, obj, jsonstr, validate=True, only=[], ignore=[]): +
[docs] def from_json(self, jsonstr, obj=None, validate=True, only=[], ignore=[]): """ Populate instance attributes of a VersionedObject instance with object data from a JSON string. - :param obj: VersionedObject instance to populate :param str jsonstr: JSON string to load + :param obj: VersionedObject instance to populate. If unset, object passed to __init__\ + will be used instead :param bool validate: If false, pre-validation will be skipped for the input data.\ This may be useful if you want to load a partial object that is missing some fields,\ and don't want to mess with filtering. @@ -261,14 +269,15 @@

Source code for versionedobj.serializer

         except JSONDecodeError:
             raise LoadObjectError("JSON decode failure")
 
-        return self.from_dict(obj, d, validate, only, ignore)
+ return self.from_dict(d, obj, validate, only, ignore)
-
[docs] def to_file(self, obj, filename, indent=None, only=[], ignore=[]): +
[docs] def to_file(self, filename, obj=None, indent=None, only=[], ignore=[]): """ Save VersionedObject instance data to a JSON file - :param obj: VersionedObject instance :param str filename: Name of file to write + :param obj: VersionedObject instance to serialize. If unset, object passed to __init__\ + will be used instead. :param int indent: Indentation level to use, in columns. If None, everything will be on one line. :param list only: Whitelist of field names to serialize (cannot be used with blacklist) :param list ignore: Blacklist of field names to ignore (cannot be used with whitelist) @@ -276,12 +285,13 @@

Source code for versionedobj.serializer

         with open(filename, 'w') as fh:
             fh.write(self.to_json(obj, indent, only, ignore))
-
[docs] def from_file(self, obj, filename, validate=True, only=[], ignore=[]): +
[docs] def from_file(self, filename, obj=None, validate=True, only=[], ignore=[]): """ Populate instance attributes of a VersionedObject instance with object data from a JSON file. - :param obj: VersionedObject instance to populate :param str filename: Name of file to load + :param obj: VersionedObject instance to populate. If unset, object passed to __init__ will\ + be used instead :param bool validate: If false, pre-validation will be skipped for the input data.\ This may be useful if you want to load a partial object that is missing some fields,\ and don't want to mess with filtering. @@ -297,15 +307,17 @@

Source code for versionedobj.serializer

         :rtype: MigrationResult
         """
         with open(filename, 'r') as fh:
-            return self.from_json(obj, fh.read(), validate, only, ignore)
+ return self.from_json(fh.read(), obj, validate, only, ignore)
-
[docs] def reset_to_defaults(self, obj): +
[docs] def reset_to_defaults(self, obj=None): """ Resets instance attribute values of a VersionedObject instance back to the default values defined in the matching class attributes. - :param obj: VersionedObject instance to reset + :param obj: VersionedObject instance to reset. If unset, object passed to __init__\ + will be used instead """ + obj = obj if obj is not None else self.obj obj._vobj__populate_instance()
@@ -324,16 +336,16 @@

Source code for versionedobj.serializer

             raise ValueError("First argument must be a VersionedObject instance or class object")
 
         self.filename = filename
-        self.serializer = Serializer()
+ self.serializer = Serializer(self.obj)
def __enter__(self): if os.path.isfile(self.filename): - self.serializer.from_file(self.obj, self.filename) + self.serializer.from_file(self.filename) return self.obj def __exit__(self, exc_type, exc_value, exc_traceback): - self.serializer.to_file(self.obj, self.filename)
+ self.serializer.to_file(self.filename)
diff --git a/docs/index.html b/docs/index.html index 8036bb6..ada3337 100644 --- a/docs/index.html +++ b/docs/index.html @@ -102,32 +102,33 @@

Object serialization & versioning fra
  • Serializing and de-serializing

  • -
  • Filtering serialization/deserialization output

    +
  • Using one Serializer instance with multiple object types

  • +
  • Filtering serialization/deserialization output

  • -
  • Context manager for loading & editing saved object data

  • -
  • Migrations: making use of the version number

    +
  • Context manager for loading & editing saved object data

  • +
  • Migrations: making use of the version number

  • -
  • Migrations: migrating an unversioned object

  • -
  • Validating input data without deserializing

  • -
  • Resetting object instance to default values

  • -
  • Testing object instance equality

  • -
  • Object instance hashing

  • -
  • Testing whether object instances contain specific values

  • -
  • Performance/stress test visualization

  • -
  • Contributions

  • +
  • Migrations: migrating an unversioned object

  • +
  • Validating input data without deserializing

  • +
  • Resetting object instance to default values

  • +
  • Testing object instance equality

  • +
  • Object instance hashing

  • +
  • Testing whether object instances contain specific values

  • +
  • Performance/stress test visualization

  • +
  • Contributions

  • -
  • Indices and tables

  • +
  • Indices and tables

  • You can also save/load object data as a JSON string:

    # Save object instance to JSON string
    -obj_as_json = serializer.to_json(obj, indent=4)
    +obj_as_json = serializer.to_json(indent=4)
     
     # Load object instance from JSON string
    -serializer.from_json(obj, obj_as_json)
    +serializer.from_json(obj_as_json)
     

    Or, as a dict:

    # Save object instance to dict
    -obj_as_dict = serializer.to_dict(obj)
    +obj_as_dict = serializer.to_dict()
     
     # Load object instance from dict
    -serializer.from_dict(obj, obj_as_dict)
    +serializer.from_dict(obj_as_dict)
     
    +
    +

    Using one Serializer instance with multiple object types

    +

    For convenience, you can pass an object instance when you create a versionedobj.Serializer, +and this object will be used for all future serialization/deserialization operations, +so that you don’t have to pass in the object instance every time (as shown in previous +examples).

    +

    However, this is not required, and you can optionally provide an object instance +for all serialization/deserialization methods, if you want to (for example) use +a single versionedobj.Serializer instance for multiple object types:

    +
    from versionedobj import VersionedObject, Serializer
    +
    +class ObjectA(VersionedObject):
    +    name = "john"
    +    age = 44
    +
    +class ObjectB(VersionedObject):
    +    last_login_time = 12345678
    +    enabled = False
    +
    +# Create an instance of each object
    +a = ObjectA()
    +b = ObjectB()
    +serializer = Serializer()
    +
    +# Serialize both objects using the same serializer
    +a_jsonstr = serializer.to_json(a)
    +b_jsonstr = serializer.to_json(b)
    +
    +# De-serialize both objects using the same serializer
    +serializer.from_json(a_jsonstr, a)
    +serializer.from_json(b_jsonstr, b)
    +
    +
    +
    -

    Filtering serialization/deserialization output

    +

    Filtering serialization/deserialization output

    -

    Whitelisting by field name

    +

    Whitelisting by field name

    When serializing, if you only want to output certain fields, you can use the ‘only’ parameter to specify which fields should be output (effectively a whitelist by field name):

    -
    serializer.to_file(obj 'user_config.json', only=['version', 'username', 'display_config.resolution'])
    +
    serializer.to_file('user_config.json', only=['version', 'username', 'display_config.resolution'])
     
     # Output looks like this:
     #
    @@ -288,18 +323,18 @@ 

    Whitelisting by field name
    serializer.from_file(obj, 'user_config.json', only=['display_config.display_mode'])
    +
    serializer.from_file('user_config.json', only=['display_config.display_mode'])
     
     # Only the 'display_config.display_mode' field is loaded from the file
     
    -

    Blacklisting by field name

    +

    Blacklisting by field name

    When serializing, if you don’t want to output certain fields, you can use the ‘ignore’ parameter to specify which fields should be excluded from output (effectively a blacklist by field name):

    -
    serializer.to_file(obj, 'user_config.json', ignore=['friend_list', 'display_config.volume'])
    +
    serializer.to_file('user_config.json', ignore=['friend_list', 'display_config.volume'])
     
     # Output looks like this:
     #
    @@ -314,7 +349,7 @@ 

    Blacklisting by field name
    -

    Migrations: making use of the version number

    +

    Migrations: making use of the version number

    A VersionedObject object can have a version attribute, which can be any object, although it is typically a string (e.g. "v1.2.3"). This version attribute can be used to support migrations for older objects, in the event that you need to change the format of your object.

    -

    Example scenario, part 1: you have created a beautiful versioned object

    +

    Example scenario, part 1: you have created a beautiful versioned object

    Let’s take the same config file definition from the previous example:

    from versionedobj import VersionedObject
     
    @@ -382,7 +417,7 @@ 

    Example scenario, part 1: you have creat on their computers.

    -

    Example scenario, part 2: you update your software, modifying the versioned object

    +

    Example scenario, part 2: you update your software, modifying the versioned object

    Now, imagine you are making a new release of your software, and some new features require you to make the following changes to your versioned object:

    -

    Uh-oh, you have a problem…

    +

    Uh-oh, you have a problem…

    Right now, if you send this updated UserConfig class to your existing users, it will fail to load their existing JSON files with version v1.0.0, since those files will contain the DisplayConfig.resolution field that we deleted in v1.0.1, and @@ -416,7 +451,7 @@

    Uh-oh, you have a problem…DisplayConfig.volumes. This situation is what migrations are for.

    -

    Solution– migrations!

    +

    Solution– migrations!

    The solution is to:

    1. Change the version number to something new, e.g. v1.0.0 becomes v1.0.1

    2. @@ -459,7 +494,7 @@

      Solution– migrations! -

      Migrations: migrating an unversioned object

      +

      Migrations: migrating an unversioned object

      You may run into a situation where you release an unversioned object, but then later you need to make changes, and migrate an unversioned object to a versioned object.

      This can be handled simply by passing “None” to the “add_migration()” method, for the @@ -479,7 +514,7 @@

      Migrations: migrating an unversioned obj

    -

    Testing object instance equality

    +

    Testing object instance equality

    You can test whether two VersionedObject instances are equal in both structure and values, the same way in which you would check equality of any other two objects:

    from versionedobj import VersionedObject
    @@ -559,7 +594,7 @@ 

    Testing object instance equality

    -

    Object instance hashing

    +

    Object instance hashing

    Objects can be uniquely hashed based on their instance attribute values, using the builtin hash() function. This means, for example, that you can use object instances as dict keys:

    from versionedobj import VersionedObject
    @@ -581,7 +616,7 @@ 

    Object instance hashing -

    Testing whether object instances contain specific values

    +

    Testing whether object instances contain specific values

    You can check whether an object instance contains a particular attribute value using the in keyword:

    from versionedobj import VersionedObject
    @@ -606,7 +641,7 @@ 

    Testing whether object instances contain

    -

    Performance/stress test visualization

    +

    Performance/stress test visualization

    The following image is generated by the tests/performance_tests/big_class_performance_test.py script, which creates and serializes/deserializes multiple versioned objects of an incrementally increasing size, and simultaneously having an increasing depth of contained nested objects.

    @@ -621,7 +656,7 @@

    Performance/stress test visualization

    -

    Contributions

    +

    Contributions

    Contributions are welcome, please open a pull request at https://github.com/eriknyquist/versionedobj and ensure that:

    1. All existing unit tests pass (run tests via python setup.py test)

    2. @@ -637,7 +672,7 @@

      Contributions

    -

    Indices and tables

    +

    Indices and tables

    • Index

    • Module Index

    • diff --git a/docs/searchindex.js b/docs/searchindex.js index 4ad75d9..1af23f4 100644 --- a/docs/searchindex.js +++ b/docs/searchindex.js @@ -1 +1 @@ -Search.setIndex({docnames:["index","modules","versionedobj"],envversion:{"sphinx.domains.c":2,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":5,"sphinx.domains.index":1,"sphinx.domains.javascript":2,"sphinx.domains.math":2,"sphinx.domains.python":3,"sphinx.domains.rst":2,"sphinx.domains.std":2,"sphinx.ext.viewcode":1,sphinx:56},filenames:["index.rst","modules.rst","versionedobj.rst"],objects:{"":[[2,0,0,"-","versionedobj"]],"versionedobj.exceptions":[[2,1,1,"","InputValidationError"],[2,1,1,"","InvalidFilterError"],[2,1,1,"","InvalidVersionAttributeError"],[2,1,1,"","LoadObjectError"]],"versionedobj.object":[[2,2,1,"","CustomValue"],[2,2,1,"","MigrationResult"],[2,2,1,"","VersionedObject"],[2,4,1,"","add_migration"],[2,4,1,"","migration"]],"versionedobj.object.CustomValue":[[2,3,1,"","from_dict"],[2,3,1,"","to_dict"]],"versionedobj.object.MigrationResult":[[2,3,1,"","__init__"]],"versionedobj.object.VersionedObject":[[2,3,1,"","__init__"]],"versionedobj.serializer":[[2,2,1,"","FileLoader"],[2,2,1,"","Serializer"]],"versionedobj.serializer.FileLoader":[[2,3,1,"","__init__"]],"versionedobj.serializer.Serializer":[[2,3,1,"","__init__"],[2,3,1,"","from_dict"],[2,3,1,"","from_file"],[2,3,1,"","from_json"],[2,3,1,"","reset_to_defaults"],[2,3,1,"","to_dict"],[2,3,1,"","to_file"],[2,3,1,"","to_json"],[2,3,1,"","validate_dict"]],versionedobj:[[2,0,0,"-","exceptions"],[2,0,0,"-","object"],[2,0,0,"-","serializer"]]},objnames:{"0":["py","module","Python module"],"1":["py","exception","Python exception"],"2":["py","class","Python class"],"3":["py","method","Python method"],"4":["py","function","Python function"]},objtypes:{"0":"py:module","1":"py:exception","2":"py:class","3":"py:method","4":"py:function"},terms:{"0":0,"10":0,"19":0,"1920x1080":0,"21":0,"3":0,"31":0,"32":0,"4":0,"66":0,"98":0,"abstract":2,"case":0,"class":[0,2],"default":2,"float":0,"function":[0,2],"import":0,"int":2,"new":0,"return":[0,2],"true":[0,2],A:0,As:0,For:0,If:[0,2],In:0,It:0,Or:0,That:0,The:0,__init__:2,about:0,abov:0,across:0,actual:[0,2],ad:[0,2],add:[0,2],add_migr:[0,2],addit:0,after:[0,2],ag:0,against:2,all:[0,2],allow:[0,2],alreadi:0,also:0,altern:2,although:0,amd64:0,an:2,ani:[0,2],anoth:[0,2],anytim:0,api:0,approach:0,ar:[0,2],assign:0,attempt:2,attr:[0,2],attr_nam:0,attribut:2,automat:0,b:0,back:[0,2],base:[0,2],becaus:[0,2],becom:0,been:0,befor:2,behav:0,between:0,big_class_performance_test:0,blacklist:2,bool:2,both:[0,2],build:0,builtin:0,buster:0,call:[0,2],callabl:2,can:[0,2],cannot:2,carrot:0,celeri:0,certain:0,chang:[0,2],check:0,cl:2,code:0,code_coverag:0,column:2,com:0,complex:0,comput:0,condit:0,config:0,consid:0,contact:0,contain:2,content:1,context:2,convert:2,copi:0,core:0,cours:0,cover:0,coverag:0,cumin:0,current:[0,2],custom:2,customvalu:2,d:0,data:2,debian:0,decor:[0,2],def:0,defin:[0,2],del:0,delet:0,depth:0,describ:2,deseri:2,dev_requir:0,develop:0,dict:[0,2],differ:0,display_config:0,display_mod:0,displayconfig:0,document:0,doe:0,don:[0,2],done:0,dot:0,downsid:0,dump:2,e:0,each:0,easili:0,effect:0,either:0,eknyquist:0,ensur:0,entir:0,entri:[0,2],equival:2,erik:0,eriknyquist:0,error:2,event:0,everi:0,everyth:2,except:[0,1],exclud:[0,2],execut:0,exist:[0,2],exit:[0,2],f:0,fail:[0,2],fals:[0,2],featur:0,field:2,file:[0,2],fileload:[0,2],filenam:2,filter:2,follow:0,forget:0,form:2,format:0,found:2,friend_list:0,from:[0,2],from_dict:[0,2],from_fil:[0,2],from_json:[0,2],from_vers:[0,2],full:0,fullscreen:0,g:0,garlic:0,gener:[0,2],ginger:0,github:0,gmail:0,gnu:0,gone:0,graph:0,ha:[0,2],had:2,handl:[0,2],help:0,here:2,http:0,i7:0,i:0,ignor:[0,2],imag:0,imagin:0,increas:0,increment:0,indent:[0,2],index:0,individu:0,ingredient_12:0,ingredient_1:0,ingredient_2:0,ingredient_3:0,inherit:0,initi:2,initial_valu:2,input:2,inputvalidationerror:[0,2],instanc:2,instance_or_class:2,intel:0,invalidfiltererror:2,invalidversionattributeerror:2,iter:0,jane:0,john:0,json:[0,2],jsonstr:2,just:0,kei:[0,2],keyword:0,later:0,let:0,level:[0,2],librari:2,like:0,line:2,linux:0,list:[0,2],load:2,loadobjecterror:2,look:0,mai:[0,2],manag:2,manual:0,map:2,match:[0,2],mean:0,measur:0,mechan:0,mention:0,mess:2,method:[0,2],migrat:2,migrate_100_to_101:0,migrate_none_to_100:0,migration_func:2,migrationresult:2,miss:[0,2],modifi:2,modul:[0,1],multipl:0,must:0,name:2,need:0,nest:[0,2],never:0,none:[0,2],notat:0,now:0,number:2,o:0,obj:[0,2],obj_as_dict:0,obj_as_json:0,objbect:2,object:1,old_vers:2,older:[0,2],one:2,onion:0,onli:[0,2],open:0,order:0,other:0,otherwis:2,our:0,out:0,over:0,overhead:0,p1:0,p2:0,p:0,packag:[0,1],page:0,paramet:[0,2],pars:2,parser:[0,2],partial:2,particular:0,pass:[0,2],peform:2,peopl:0,perform:2,performance_test:0,person:0,pip:0,pleas:0,point:0,popul:[0,2],pre:2,previou:0,previous:2,print:0,provid:[0,2],pull:0,py:0,question:0,r:0,rais:[0,2],rcp1:0,rcp2:0,rcp:0,re:0,recip:0,regist:[0,2],regular:0,rel:0,releas:0,remov:0,replac:0,repres:0,request:0,requir:[0,2],reset:2,reset_to_default:[0,2],resolut:0,right:0,run:0,s:0,salli:0,sam:0,same:[0,2],save:2,script:0,search:0,see:0,send:0,serial:1,serv:0,set:[0,2],setup:0,should:[0,2],similarli:0,simpli:0,simultan:0,sinc:0,singl:2,sit:0,situat:0,size:0,skip:2,smith:0,so:0,some:[0,2],someth:[0,2],sourc:2,specifi:0,standard:2,str:2,string:[0,2],structur:0,sub:2,submodul:1,success:2,suitabl:2,support:[0,2],system:0,t:[0,2],take:0,taken:0,target:2,target_vers:2,thei:0,thi:[0,2],those:0,time:[0,2],to_dict:[0,2],to_fil:[0,2],to_json:[0,2],to_vers:2,tomato:0,top:0,track:0,transform:0,treat:0,two:0,txt:0,type:2,typic:0,udpat:0,uniqu:0,unit:0,upsid:0,us:2,user1:0,user2:0,user3:0,user:0,user_config:0,userconfig:0,usernam:0,v1:0,valid:2,validate_dict:[0,2],valu:2,variabl:2,ve:0,veri:0,version:2,version_reach:2,versionedobjbect:[0,2],versionedobject:[0,2],via:0,volum:0,wa:[0,2],wai:[0,2],want:[0,2],we:0,welcom:0,well:0,were:2,what:0,when:0,whenev:2,where:0,which:0,whitelist:2,why:0,window:0,world:0,worri:0,worth:0,would:0,write:[0,2],you:2},titles:["versionedobj","versionedobj","versionedobj package"],titleterms:{"1":0,"2":0,"3x":0,"default":0,access:0,an:0,attribut:0,beauti:0,blacklist:0,contain:0,content:[0,2],context:0,contribut:0,creat:0,data:0,de:0,definit:0,deseri:0,edit:0,equal:0,exampl:0,except:2,field:0,filter:0,framework:0,get:0,hash:0,have:0,indic:0,input:0,instal:0,instanc:0,load:0,make:0,manag:0,migrat:0,modifi:0,modul:2,name:0,number:0,object:[0,2],oh:0,output:0,packag:2,part:0,perform:0,problem:0,python:0,reset:0,save:0,scenario:0,serial:[0,2],softwar:0,solut:0,specif:0,start:0,stress:0,submodul:2,tabl:0,test:0,uh:0,unvers:0,updat:0,us:0,valid:0,valu:0,version:0,versionedobj:[0,1,2],visual:0,whether:0,whitelist:0,without:0,you:0,your:0}}) \ No newline at end of file +Search.setIndex({docnames:["index","modules","versionedobj"],envversion:{"sphinx.domains.c":2,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":5,"sphinx.domains.index":1,"sphinx.domains.javascript":2,"sphinx.domains.math":2,"sphinx.domains.python":3,"sphinx.domains.rst":2,"sphinx.domains.std":2,"sphinx.ext.viewcode":1,sphinx:56},filenames:["index.rst","modules.rst","versionedobj.rst"],objects:{"":[[2,0,0,"-","versionedobj"]],"versionedobj.exceptions":[[2,1,1,"","InputValidationError"],[2,1,1,"","InvalidFilterError"],[2,1,1,"","InvalidVersionAttributeError"],[2,1,1,"","LoadObjectError"]],"versionedobj.object":[[2,2,1,"","CustomValue"],[2,2,1,"","MigrationResult"],[2,2,1,"","VersionedObject"],[2,4,1,"","add_migration"],[2,4,1,"","migration"]],"versionedobj.object.CustomValue":[[2,3,1,"","from_dict"],[2,3,1,"","to_dict"]],"versionedobj.object.MigrationResult":[[2,3,1,"","__init__"]],"versionedobj.object.VersionedObject":[[2,3,1,"","__init__"]],"versionedobj.serializer":[[2,2,1,"","FileLoader"],[2,2,1,"","Serializer"]],"versionedobj.serializer.FileLoader":[[2,3,1,"","__init__"]],"versionedobj.serializer.Serializer":[[2,3,1,"","__init__"],[2,3,1,"","from_dict"],[2,3,1,"","from_file"],[2,3,1,"","from_json"],[2,3,1,"","reset_to_defaults"],[2,3,1,"","to_dict"],[2,3,1,"","to_file"],[2,3,1,"","to_json"],[2,3,1,"","validate_dict"]],versionedobj:[[2,0,0,"-","exceptions"],[2,0,0,"-","object"],[2,0,0,"-","serializer"]]},objnames:{"0":["py","module","Python module"],"1":["py","exception","Python exception"],"2":["py","class","Python class"],"3":["py","method","Python method"],"4":["py","function","Python function"]},objtypes:{"0":"py:module","1":"py:exception","2":"py:class","3":"py:method","4":"py:function"},terms:{"0":0,"10":0,"12345678":0,"19":0,"1920x1080":0,"21":0,"3":0,"31":0,"32":0,"4":0,"44":0,"66":0,"98":0,"abstract":2,"case":0,"class":[0,2],"default":2,"float":0,"function":[0,2],"import":0,"int":2,"new":0,"return":[0,2],"true":[0,2],A:0,As:0,For:0,If:[0,2],In:0,It:0,Or:0,That:0,The:0,__init__:2,a_jsonstr:0,about:0,abov:0,across:0,actual:[0,2],ad:[0,2],add:[0,2],add_migr:[0,2],addit:0,after:[0,2],ag:0,against:2,all:[0,2],allow:[0,2],alreadi:0,also:0,altern:2,although:0,amd64:0,an:2,ani:[0,2],anoth:[0,2],anytim:0,api:0,approach:0,ar:[0,2],assign:0,attempt:2,attr:[0,2],attr_nam:0,attribut:2,automat:0,b:0,b_jsonstr:0,back:[0,2],base:[0,2],becaus:[0,2],becom:0,been:0,befor:2,behav:0,between:0,big_class_performance_test:0,blacklist:2,bool:2,both:[0,2],build:0,builtin:0,buster:0,call:[0,2],callabl:2,can:[0,2],cannot:2,carrot:0,celeri:0,certain:0,chang:[0,2],check:0,cl:2,code:0,code_coverag:0,column:2,com:0,complex:0,comput:0,condit:0,config:0,consid:0,contact:0,contain:2,content:1,context:2,conveni:0,convert:2,copi:0,core:0,cours:0,cover:0,coverag:0,cumin:0,current:[0,2],custom:2,customvalu:2,d:0,data:2,debian:0,decor:[0,2],def:0,defin:[0,2],del:0,delet:0,depth:0,describ:2,deseri:2,dev_requir:0,develop:0,dict:[0,2],differ:0,display_config:0,display_mod:0,displayconfig:0,document:0,doe:0,don:[0,2],done:0,dot:0,downsid:0,dump:2,e:0,each:0,easili:0,effect:0,either:0,eknyquist:0,enabl:0,ensur:0,entir:0,entri:[0,2],equival:2,erik:0,eriknyquist:0,error:2,event:0,everi:0,everyth:2,except:[0,1],exclud:[0,2],execut:0,exist:[0,2],exit:[0,2],f:0,fail:[0,2],fals:[0,2],featur:0,field:2,file:[0,2],fileload:[0,2],filenam:2,filter:2,follow:0,forget:0,form:2,format:0,found:2,friend_list:0,from:[0,2],from_dict:[0,2],from_fil:[0,2],from_json:[0,2],from_vers:[0,2],full:0,fullscreen:0,futur:0,g:0,garlic:0,gener:[0,2],ginger:0,github:0,gmail:0,gnu:0,gone:0,graph:0,ha:[0,2],had:2,handl:[0,2],help:0,here:2,howev:0,http:0,i7:0,i:0,ignor:[0,2],imag:0,imagin:0,increas:0,increment:0,indent:[0,2],index:0,individu:0,ingredient_12:0,ingredient_1:0,ingredient_2:0,ingredient_3:0,inherit:0,initi:2,initial_valu:2,input:2,inputvalidationerror:[0,2],instanc:2,instance_or_class:2,instead:2,intel:0,invalidfiltererror:2,invalidversionattributeerror:2,iter:0,jane:0,john:0,json:[0,2],jsonstr:2,just:0,kei:[0,2],keyword:0,last_login_tim:0,later:0,let:0,level:[0,2],librari:2,like:0,line:2,linux:0,list:[0,2],load:2,loadobjecterror:2,look:0,mai:[0,2],manag:2,manual:0,map:2,match:[0,2],mean:0,measur:0,mechan:0,mention:0,mess:2,method:[0,2],migrat:2,migrate_100_to_101:0,migrate_none_to_100:0,migration_func:2,migrationresult:2,miss:[0,2],modifi:2,modul:[0,1],must:0,name:2,need:0,nest:[0,2],never:0,none:[0,2],notat:0,now:0,number:2,o:0,obj:[0,2],obj_as_dict:0,obj_as_json:0,objbect:2,object:1,objecta:0,objectb:0,old_vers:2,older:[0,2],one:2,onion:0,onli:[0,2],open:0,oper:0,option:0,order:0,other:0,otherwis:2,our:0,out:0,over:0,overhead:0,p1:0,p2:0,p:0,packag:[0,1],page:0,paramet:[0,2],pars:2,parser:[0,2],partial:2,particular:0,pass:[0,2],peform:2,peopl:0,perform:2,performance_test:0,person:0,pip:0,pleas:0,point:0,popul:[0,2],pre:2,previou:0,previous:2,print:0,provid:[0,2],pull:0,py:0,question:0,r:0,rais:[0,2],rcp1:0,rcp2:0,rcp:0,re:0,recip:0,regist:[0,2],regular:0,rel:0,releas:0,remov:0,replac:0,repres:0,request:0,requir:[0,2],reset:2,reset_to_default:[0,2],resolut:0,right:0,run:0,s:0,salli:0,sam:0,same:[0,2],save:2,script:0,search:0,see:0,send:0,serial:1,serv:0,set:[0,2],setup:0,should:[0,2],shown:0,similarli:0,simpli:0,simultan:0,sinc:0,singl:[0,2],sit:0,situat:0,size:0,skip:2,smith:0,so:0,some:[0,2],someth:[0,2],sourc:2,specifi:0,standard:2,str:2,string:[0,2],structur:0,sub:2,submodul:1,success:2,suitabl:2,support:[0,2],system:0,t:[0,2],take:0,taken:0,target:2,target_vers:2,thei:0,thi:[0,2],those:0,time:[0,2],to_dict:[0,2],to_fil:[0,2],to_json:[0,2],to_vers:2,tomato:0,top:0,track:0,transform:0,treat:0,two:0,txt:0,type:2,typic:0,udpat:0,uniqu:0,unit:0,unset:2,upsid:0,us:2,user1:0,user2:0,user3:0,user:0,user_config:0,userconfig:0,usernam:0,v1:0,valid:2,validate_dict:[0,2],valu:2,variabl:2,ve:0,veri:0,version:2,version_reach:2,versionedobjbect:[0,2],versionedobject:[0,2],via:0,volum:0,wa:[0,2],wai:[0,2],want:[0,2],we:0,welcom:0,well:0,were:2,what:0,when:0,whenev:2,where:0,which:0,whitelist:2,why:0,window:0,world:0,worri:0,worth:0,would:0,write:[0,2],you:2},titles:["versionedobj","versionedobj","versionedobj package"],titleterms:{"1":0,"2":0,"3x":0,"default":0,access:0,an:0,attribut:0,beauti:0,blacklist:0,contain:0,content:[0,2],context:0,contribut:0,creat:0,data:0,de:0,definit:0,deseri:0,edit:0,equal:0,exampl:0,except:2,field:0,filter:0,framework:0,get:0,hash:0,have:0,indic:0,input:0,instal:0,instanc:0,load:0,make:0,manag:0,migrat:0,modifi:0,modul:2,multipl:0,name:0,number:0,object:[0,2],oh:0,one:0,output:0,packag:2,part:0,perform:0,problem:0,python:0,reset:0,save:0,scenario:0,serial:[0,2],softwar:0,solut:0,specif:0,start:0,stress:0,submodul:2,tabl:0,test:0,type:0,uh:0,unvers:0,updat:0,us:0,valid:0,valu:0,version:0,versionedobj:[0,1,2],visual:0,whether:0,whitelist:0,without:0,you:0,your:0}}) \ No newline at end of file diff --git a/docs/versionedobj.html b/docs/versionedobj.html index 75e698b..7bd94b8 100644 --- a/docs/versionedobj.html +++ b/docs/versionedobj.html @@ -246,23 +246,23 @@

      Submodules
      -class versionedobj.serializer.Serializer[source]
      +class versionedobj.serializer.Serializer(obj=None)[source]

      Bases: object

      Class for serializing/deserializing any VersionedObject types

      -__init__()[source]
      +__init__(obj=None)[source]
      -from_dict(obj, attrs, validate=True, only=[], ignore=[])[source]
      +from_dict(attrs, obj=None, validate=True, only=[], ignore=[])[source]

      Populate instance attributes of a VersionedObjbect instance, with object data from a dict.

      Parameters
        -
      • obj – VersionedObject instance to populate

      • attrs (dict) – dict containing object data

      • +
      • obj – VersionedObject instance to populate. If unset, object passed to __init__ will be used instead

      • validate (bool) – If false, pre-validation will be skipped for the input data. This may be useful if you want to load a partial object that is missing some fields, and don’t want to mess with filtering.

      • only (list) – Whitelist of field names to load (cannot be used with blacklist)

      • ignore (list) – Blacklist of field names to ignore (cannot be used with whitelist)

      • @@ -285,13 +285,13 @@

        Submodules
        -from_file(obj, filename, validate=True, only=[], ignore=[])[source]
        +from_file(filename, obj=None, validate=True, only=[], ignore=[])[source]

        Populate instance attributes of a VersionedObject instance with object data from a JSON file.

        Parameters
          -
        • obj – VersionedObject instance to populate

        • filename (str) – Name of file to load

        • +
        • obj – VersionedObject instance to populate. If unset, object passed to __init__ will be used instead

        • validate (bool) – If false, pre-validation will be skipped for the input data. This may be useful if you want to load a partial object that is missing some fields, and don’t want to mess with filtering.

        • only (list) – Whitelist of field names to load (cannot be used with blacklist)

        • ignore (list) – Blacklist of field names to ignore (cannot be used with whitelist)

        • @@ -315,13 +315,13 @@

          Submodules
          -from_json(obj, jsonstr, validate=True, only=[], ignore=[])[source]
          +from_json(jsonstr, obj=None, validate=True, only=[], ignore=[])[source]

          Populate instance attributes of a VersionedObject instance with object data from a JSON string.

          Parameters
            -
          • obj – VersionedObject instance to populate

          • jsonstr (str) – JSON string to load

          • +
          • obj – VersionedObject instance to populate. If unset, object passed to __init__ will be used instead

          • validate (bool) – If false, pre-validation will be skipped for the input data. This may be useful if you want to load a partial object that is missing some fields, and don’t want to mess with filtering.

          • only (list) – Whitelist of field names to load (cannot be used with blacklist)

          • ignore (list) – Blacklist of field names to ignore (cannot be used with whitelist)

          • @@ -345,19 +345,19 @@

            Submodules
            -reset_to_defaults(obj)[source]
            +reset_to_defaults(obj=None)[source]

            Resets instance attribute values of a VersionedObject instance back to the default values defined in the matching class attributes.

            Parameters
            -

            obj – VersionedObject instance to reset

            +

            obj – VersionedObject instance to reset. If unset, object passed to __init__ will be used instead

          -to_dict(obj, only=[], ignore=[])[source]
          +to_dict(obj=None, only=[], ignore=[])[source]

          Convert object to a dict, suitable for passing to the json library

          Parameters
          @@ -378,13 +378,13 @@

          Submodules
          -to_file(obj, filename, indent=None, only=[], ignore=[])[source]
          +to_file(filename, obj=None, indent=None, only=[], ignore=[])[source]

          Save VersionedObject instance data to a JSON file

          Parameters
            -
          • obj – VersionedObject instance

          • filename (str) – Name of file to write

          • +
          • obj – VersionedObject instance to serialize. If unset, object passed to __init__ will be used instead.

          • indent (int) – Indentation level to use, in columns. If None, everything will be on one line.

          • only (list) – Whitelist of field names to serialize (cannot be used with blacklist)

          • ignore (list) – Blacklist of field names to ignore (cannot be used with whitelist)

          • @@ -395,13 +395,13 @@

            Submodules
            -to_json(obj, indent=None, only=[], ignore=[])[source]
            +to_json(obj=None, indent=None, only=[], ignore=[])[source]

            Generate a JSON string containing all data from a VersionedObject instance

            Parameters
              -
            • obj – VersionedObject instance

            • indent (int) – Indentation level to use, in columns. If None, everything will be on one line.

            • +
            • obj – VersionedObject instance to serialize. If unset, object passed to __init__ will be used instead

            • only (list) – Whitelist of field names to serialize (cannot be used with blacklist)

            • ignore (list) – Blacklist of field names to ignore (cannot be used with whitelist)

            @@ -417,13 +417,13 @@

            Submodules
            -validate_dict(obj, attrs, only=[], ignore=[])[source]
            +validate_dict(attrs, obj=None, only=[], ignore=[])[source]

            Validate a versioned object in dict form.

            Parameters
              -
            • obj – VersionedObject instance you want to validate the dict against

            • attrs (dict) – dict to validate

            • +
            • obj – VersionedObject instance you want to validate the dict against. If unset, object passed to __init__ will be used instead

            • only (list) – Whitelist of attribute names to validate (cannot be used with ‘ignore’)

            • ignore (list) – Blacklist of attribute names to exclude from validation (cannot be used with ‘only’)