json_to_csv._private
index

Copyright (c) 2017 Timothy Savannah All Rights Reserved
 
Licensed under terms of LGPLv3.
 
Private items used in the implementation of public JsonToCsv class

 
Modules
       
copy
sys
traceback

 
Classes
       
builtins.Exception(builtins.BaseException)
WalkNullException
builtins.object
Level
Level_ListMap
Level_Map
Rule

 
class Level(builtins.object)
    Level - Base class of any level-walk operations.
 
Does not itself hold implement of walk method.
 
For the subclasses, calling obj.walk(level) will perform the walk from level -> newLevel, and return newLevel if found.
 
  If newLevel could not be reached, WalkNullException will be raised with a message (.msg) defined to be the reason why (for debug purposes)
 
Private
 
  Methods defined here:
__init__(self, levelKey)
__init__ - Create a Level object.
 
@param levelKey <str> - The key at which we will descend into to get to the next level
__repr__ = __str__(self)
__str__(self)
Return str(self).
walk(self, curLevel)
walk - Walk from the current level (#curLevel) and return the level reached.
 
@param curLevel <dict> - The starting level
 
@return <dict> - The landing level
 
@raises WalkNullException - If the walk could not be completed

Data descriptors defined here:
levelKey

Data and other attributes defined here:
levelType = 'undefined'

 
class Level_ListMap(Level)
     Level_ListMap - A Level that searches a list of maps for a specific key : value
 
 Like:
 
"MyKey" : [{
      "name" : "Something",
      "value" : "x"
    },
    {
      "name" : "Blah",
      "value" : "y"
    }
]
 
 If we wanted to descend into the one with name equal to "Something", we would have:
 
    ListMap("MyKey", "name", "Something")
 
 or in the format language, 
 
    /"MyKey"["name"="Something"
 
 @see Level
 
 Private
 
 
Method resolution order:
Level_ListMap
Level
builtins.object

Methods defined here:
__init__(self, levelKey, matchKey, matchValue)
__init__ - Create a Level_ListMap object
 
@param levelKey <str> - The key with which to find this list-of-maps
 
@param matchKey <str> - The key we will check against in each map
 
@param matchValue<str> - The value we are looking for in #matchKey to select that map
walk(self, curLevel)
walk - Walk from the current level (#curLevel) to the next level and return that next level
 
@param curLevel <dict> - The current level
 
@return <dict> - The level reached
 
@throws WalkNullException if:
 
   1. #curLevel does not contain a key matching #levelKey
   2. The result of #curLevel[#levelKey] is not a list or contains items other than maps
   3. No match found

Data descriptors defined here:
levelKey
matchKey
matchValue

Data and other attributes defined here:
levelType = 'list_map'

Methods inherited from Level:
__repr__ = __str__(self)
Return str(self).
__str__(self)
Return str(self).

 
class Level_Map(Level)
    Level_Map - A type of Level access which simply accesses a key on a map.
 
@see Level
 
Private
 
 
Method resolution order:
Level_Map
Level
builtins.object

Methods defined here:
__init__(self, levelKey)
__init__ - Create a Level_Map object
 
@param levelKey <str> - The string on which to access
walk(self, curLevel)
walk - Walk from the current level accessing a key, and return that as the next level
 
@see Level.walk
 
@param curLevel <dict> - Current level
 
@return <dict> - The landing level
 
@raises WalkNullException - If the key does not exist, or does not point to a map

Data descriptors defined here:
levelKey

Data and other attributes defined here:
levelType = 'map'

Methods inherited from Level:
__repr__ = __str__(self)
Return str(self).
__str__(self)
Return str(self).

 
class Rule(builtins.object)
    Rule - Private object used to walk the tree.
 
  Methods defined here:
__call__(self, obj)
__call__ - Called when this object is called. i.e. x = Rule(...)   x(myObj) <--- called here
 
 
@param obj <dict> - The upper-most object
 
@return <str / type(self.nullValue) > - Will transverse the levels and print the key associated with
 
   this rule. @see Rule.__init__ for more info. If it could not complete the walk or did not find the 
 
   final key, or the final key has a value of 'null', will return self.nullValue (as passed in __init__, default empty string).
__init__(self, levels, keyName, nullValue='', debug=False)
__init__ - Construct a Rule object.
 
This object should be called and passed an object to transverse and return the key found.
 
@param levels - list< Level > List of objects of a subclass to "Level"
 
    Level types and Data:
 
        * 'map' - A map access. 
 
        * 'list_map' - Access a list of maps, searching for a key=value pair.
    .
@param keyName - The key to print after transversing levels
 
@param nullValue - The value to return to represent null
 
@param debug <bool> Default False - If True, will print some info to stderr.

Static methods defined here:
descendLevels(obj, levels, debug=False, doneLevels=None)
descendLevels - Takes an object and descends a series of levels, returning the final object reached.
 
   "Walk" from #obj down #levels and return the resulting object.
 
@param obj <dict> - The starting object
 
@param levels <list<tuple>> - Levels to transverse. @see Rule.__init__ for more info
 
@param debug <bool> Default False - If True, will print some info to stderr
 
@param doneLevels <None/list> Default None, if you provide a list, it will contain all the levels transversed before stopping.
 
    If you get a return of 'None' (can't transverse all levels), this will show you where it stopped.
 
@return <dict/None> - If could transverse successfully, will return the object reached.
 
    If it could not, will return None. @see doneLevels

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class WalkNullException(builtins.Exception)
    WalkNullException - Raised when a Level cannot walk down (reality doesn't match expected format).
 
contains 'msg' attribute which contains the message
 
Private
 
 
Method resolution order:
WalkNullException
builtins.Exception
builtins.BaseException
builtins.object

Methods defined here:
__init__(self, msg='')
Initialize self.  See help(type(self)) for accurate signature.

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Methods inherited from builtins.Exception:
__new__(*args, **kwargs) from builtins.type
Create and return a new object.  See help(type) for accurate signature.

Methods inherited from builtins.BaseException:
__delattr__(self, name, /)
Implement delattr(self, name).
__getattribute__(self, name, /)
Return getattr(self, name).
__reduce__(...)
helper for pickle
__repr__(self, /)
Return repr(self).
__setattr__(self, name, value, /)
Implement setattr(self, name, value).
__setstate__(...)
__str__(self, /)
Return str(self).
with_traceback(...)
Exception.with_traceback(tb) --
set self.__traceback__ to tb and return self.

Data descriptors inherited from builtins.BaseException:
__cause__
exception cause
__context__
exception context
__dict__
__suppress_context__
__traceback__
args

 
Data
        __all__ = ('Rule', 'Level', 'Level_Map', 'Level_ListMap', 'WalkNullException')