Skip to content

Instantly share code, notes, and snippets.

@cassiel
Created February 19, 2012 17:21

Revisions

  1. cassiel revised this gist Feb 19, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,6 @@ def __unpack(self, x):
    if isinstance(x, Map):
    return Manifest(x)
    elif isinstance(x, List):
    return map(lambda i: self.__unpack(i), x)
    return map(self.__unpack, x)
    else:
    return x
  2. cassiel revised this gist Feb 19, 2012. 1 changed file with 10 additions and 13 deletions.
    23 changes: 10 additions & 13 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,20 @@
    from java.util import Map
    from java.util import Map, List

    class Manifest:
    def __init__(self, h=None, **kw):
    self.keys = []
    self.all = []

    for k in kw:
    self.associate(k, kw[k])
    setattr(self, k, kw[k])

    if h is not None:
    for k in h.iterator():
    n = k.getKey().getName()
    v = k.getValue()
    if isinstance(v, Map):
    self.associate(n, Manifest(v))
    else:
    self.associate(n, v)
    setattr(self, n, self.__unpack(v))

    def associate(self, key, val):
    setattr(self, key, val)
    self.keys.append(key)
    self.all.append(val)
    def __unpack(self, x):
    if isinstance(x, Map):
    return Manifest(x)
    elif isinstance(x, List):
    return map(lambda i: self.__unpack(i), x)
    else:
    return x
  3. cassiel created this gist Feb 19, 2012.
    23 changes: 23 additions & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    from java.util import Map

    class Manifest:
    def __init__(self, h=None, **kw):
    self.keys = []
    self.all = []

    for k in kw:
    self.associate(k, kw[k])

    if h is not None:
    for k in h.iterator():
    n = k.getKey().getName()
    v = k.getValue()
    if isinstance(v, Map):
    self.associate(n, Manifest(v))
    else:
    self.associate(n, v)

    def associate(self, key, val):
    setattr(self, key, val)
    self.keys.append(key)
    self.all.append(val)