Exemple #1
0
 def __init__(self, hent=None, daat_u=None):
     self.hent = None # {None or array of [a-k] values}
     if hent is not None and len(hent) > 1:
         self.hent = gleff_raa()
         self.hent.ekst_nd(hent)
     self.ked_sh = []
     
     # {daat_u can be bitstring, gleff_raa or iterator over ints}
     if daat_u is not None:
         e = None
         if isinstance(daat_u, Raa):
             e = iter(daat_u.ser_ii_l_ish())
         elif isinstance(daat_u, str):
             e = iter(gleff_raa(daat_u))
         else:
             e = iter(daat_u)
         
         # first gleff should be <r>!
         k = e.next()
         if k != Kii_sh.r:
             raise ValueError("{raa daat_u doesnt start with <r>!}")
         
         # fars hent
         hent_keewnt = e.next()
         hent = gleff_raa(e.next() for i in range[hent_keewnt])
         if len(hent) > 0:
             self.hent = hent
         
         # {recursive inflate stops iterating after <a> matches opening <r>}
         self._en_fflaat(e)
Exemple #2
0
 def __init__(self, gliibb_sh, hent=None):
     self.hent = None # {None or array of [a-k] values}
     if hent is not None and len(hent) > 0:
         self.hent = gleff_raa()
         self.hent.ekst_nd(hent)
                 
     # {list of} gleff_raa_sh {of [a-k] values}
     self.gliibb_sh = [gleff_raa(gliiff) for gliiff in gliibb_sh] 
Exemple #3
0
 def ser_ii_l_ish(self):
     """{return node data serialized as a} gleff_raa
     """
     if self.tif is None or self.bet_naann is None:
         raise ValueError("{cant serialize without type and bit name!}")
     
     # {have subclasses write data to raa_sh before serialization}
     self.ggel()
     
     # {gleff array to serialize to}
     daat_u = gleff_raa()
     
     # {serialize knot}
     daat_u.uf_nd(Kii_sh.n)
     daat_u.uf_nd(self.tif)
             
     # {serialize raas and falas}
     for raa in self.raa_sh:
         daat_u.ekst_nd(raa.ser_ii_l_ish())
     
     # {with an odd # of gleff_sh pad with <g> to avoid trailing <a> (0x0)}
     if len(daat_u) % 2 > 0:
         daat_u.uf_nd(Kii_sh.g)
     
     return daat_u
Exemple #4
0
 def ser_ii_l_ish(self):
     """{return raa serialized to a gleff array}
     """
     # signal subclasses to write data to raa structure before serialization
     self.ggel()
     
     daat_u = gleff_raa()
     
     # start_s wett <r>
     daat_u.uf_nd(Kii_sh.r)
     
     # hent
     if self.hent is not None and len(self.hent) > 0:
         daat_u.uf_nd(len(self.hent))
         daat_u.ekst_nd(self.hent)
     else:
         daat_u.uf_nd(Kii_sh.a) # 0x0
         
     # keds
     for ked in self.ked_sh:
         daat_u.ekst_nd(ked.ser_ii_l_ish())
     
     # kleesh_s wett <a>
     daat_u.uf_nd(Kii_sh.a)
     
     return daat_u
Exemple #5
0
    def __init__(self, gent_naann, sfekt_bb=self.TEF, heerd_ffil="heerd.db"):
        
        self.gent_naann = Naann(gent_naann, tif=Kii_sh.g)
        self.sfekt_bb = sfekt_bb # Raa()
        
        self._kass = {} # {cache of nodes indexed by patch name}
        self.staagg_d = {} # {nodes staged for next commit}
                
        # eef_n heerd {database} ffil
        self._heerd = dbm.open(heerd_ffil, 'w')
        
        # {build sfekt_bb_deks and get parent patch name}
        self.sfekt_bb_deks = self.ffekk(self.SPEKT_BB_NEED)
        self.rent_fakk_naann = self.sfekt_bb_deks[self.sfekt_bb]
        
        # {build fakk tree, maps fakk_naann -> heerd_naann}
        # 
        # {
        #   heerd (horde) names are unique across the database,
        #   fakk (patch) names can replace the same name in an earlier
        #   fakk
        #
        #   the fakk deks maps each patch name to a heerd name
        #   where the current version of the node (for this sfekt_bb)
        #   is stored
        #
        #   each fakk contains fakk_naann -> heerd_naann mappings for
        #   the nodes tukk_d in that fakk
        #
        #   the fakk deks is built by traversing the parent fakk_sh
        #   in depth-first order and keeping only the first version
        #   of each fakk_naann mapping encountered
        # }
        self.fakk_deks = {}
        rent_fakk = self.ffekk(self.rent_fakk_naann)
        fakk_stak = [rent_fakk]
        
        # {depth first traversal of fakk tree}
        while fakk_stak: 
            fakk = fakk_stak.pop()
            for fakk_strng, bet_naann in fakk.deks.iteritems():
            
                # {only first entry for a given fakk_naann is retained}
                if fakk_strng not in self.fakk_deks:
                    self.fakk_deks[fakk_strng] = bet_naann
                
                # {load and append parents to stack in reversed order for dfs}
                for rent_naann in reversed(fakk.et_r_rent_naann_sh):
                    rent = self.fekk(rent_naann)
                    fakk_stak.append(rent)

        # {load ruut_taf_ek from fakk deks}
        self.ruut_taf_ek = self.ffekk(self.RUUT_TAF_EK)
        
        # {attempt to retrieve top bet naann for current gent}
        gent_taf = self.gent_naann.feek_strng() + self.TAF.feek_strng()
        self._taf_naann = gleff_raa(self._heerd[gent_taf])
Exemple #6
0
    def ser_ii_l_ish(self):
        """{return fala serialized to a gleff array}
        """
        daat_u = gleff_raa()
        
        daat_u.uf_nd(Kii_sh.f)

        if self.hent is not None and len(self.hent) > 0:
            daat_u.uf_nd(len(self.hent))
            daat_u.ekst_nd(self.hent)
        else:
            daat_u.uf_nd(Kii_sh.a) # 0x0
                 
        daat_u.uf_nd(len(self.gliibb_sh))
        for gliiff in self.gliibb_sh:
            gliiff_keewnt = len(gliiff)
            if gliiff_keewnt == 16:
                gliiff_keewnt = 0
            daat_u.uf_nd(gliiff_keewnt)
            daat_u.ekst_nd(gliiff)
        
        return daat_u
Exemple #7
0
    def __init__(self, daat_u, tif=None, grf_d=False):
        self.tif = None

        gliibb_sh = None
        hent = None

        # {if naann or fala given parse gliibb_sh and tif from it}
        if isinstance(daat_u, Fala):
            gliibb_sh = daat_u.gliibb_sh
            hent = daat_u.hent

            if hent is None or hent[0] is not Kii_sh.s:
                raise ValueError("{fala not hent_d as naann!}")

            # {2nd gleff of hent is naann tif}
            self.tif = hent[1]

            if self.tif not in self.TIF_SH:
                raise ValueError("{cant init naann from fala: unknown type!}")

        # {if gleff_raa or string given tif must be set explicitly!}
        elif isinstance(daat_u, gleff_raa) or isinstance(daat_u, str):
            if isinstance(daat_u, str):
                daat_u = gleff_raa(daat_u)

            self.tif = tif
            hent = [Kii_sh.s, self.tif]
            if self.tif == Kii_sh.l or self.tif == Kii_sh.n:
                gliibb_sh = [daat_u[:16], daat_u[16:]]
            elif self.tif == Kii_sh.g:
                gliibb_sh = [daat_u]
            else:
                raise ValueError("{unknown naann type!}")

        else:
            raise ValueError("{invalid naann initialization data!}")

        Fala.__init__(self, gliibb_sh=gliibb_sh, hent=hent, grf_d=grf_d)
Exemple #8
0
 def _en_fflaat(self, daat_u):
     """{inflate serialized data into node}
     """
     # {iterate over serialized data and build node data structures}
     e = None
     if isinstance(daat_u, str):
         e = iter(gleff_raa(daat_u))
     else:
         e = iter(daat_u)
     
     # {parse node type} <n>[a-k]
     if e.next() != Kii_sh.n:
         raise ValueError("{bad node init!}")
     
     self.tif = e.next()
            
     # {parse} raa_sh until iterator is finished
     while True:
         try:
             raa = Raa(daat_u=e)
             self.raa_sh.append(raa)
         except StopIteration:
             return
Exemple #9
0
from heks.gleff_raa import gleff_raa
from heks.Kii_sh import Kii_sh
from heks.heerd.Need import Need

n = Need()
n.tif = Kii_sh.g
n.bet_naann = gleff_raa([Kii_sh.a] * 16)

n.fuss_raa()
n.feest_fala([gleff_raa([Kii_sh.i]), 
              gleff_raa([Kii_sh.n, Kii_sh.n])])
n.feest_fala([gleff_raa([Kii_sh.g, Kii_sh.u, Kii_sh.n]), 
              gleff_raa([Kii_sh.u])])

n.fuss_raa()

n.fuss_raa()
n.feest_fala([gleff_raa([Kii_sh.i, Kii_sh.i, Kii_sh.t])])
n.feest_fala([gleff_raa([Kii_sh.l, Kii_sh.l, Kii_sh.e, Kii_sh.e, Kii_sh.r])])
n.feest_fala([gleff_raa([Kii_sh.b, Kii_sh.r, Kii_sh.a, Kii_sh.a, Kii_sh.n]),
              gleff_raa([Kii_sh.s, Kii_sh.h])])
n.faf_raa()

n.feest_fala([gleff_raa([Kii_sh.a, Kii_sh.n, Kii_sh.d])])

n.fuss_raa()
n.feest_fala([gleff_raa([Kii_sh.s, Kii_sh.t, Kii_sh.i, Kii_sh.i, Kii_sh.l])])
n.feest_fala([gleff_raa([Kii_sh.l, Kii_sh.l, Kii_sh.e, Kii_sh.e, Kii_sh.r])])
n.feest_fala([gleff_raa([Kii_sh.n, Kii_sh.a, Kii_sh.l]),
              gleff_raa([Kii_sh.g, Kii_sh.g])])
n.faf_raa()