コード例 #1
0
 def pop(self):
     """
     Pop the frame at the top of the stack.
     @return: The popped frame, else None.
     @rtype: L{Frame}
     """
     if len(self.stack):
         popped = self.stack.pop()
         log.debug('pop: (%s)\n%s', Repr(popped), Repr(self.stack))
         return popped
     else:
         log.debug('stack empty, not-popped')
     return None
コード例 #2
0
 def push(self, x):
     """
     Push an I{object} onto the stack.
     @param x: An object to push.
     @type x: L{Frame}
     @return: The pushed frame.
     @rtype: L{Frame}
     """
     if isinstance(x, Frame):
         frame = x
     else:
         frame = Frame(x)
     self.stack.append(frame)
     log.debug('push: (%s)\n%s', Repr(frame), Repr(self.stack))
     return frame
コード例 #3
0
 def sort(self):
     """
     Sort the list based on dependancies.
     @return: The sorted items.
     @rtype: list
     """
     self.sorted = list()
     self.pushed = set()
     for item in self.unsorted:
         popped = []
         self.push(item)
         while len(self.stack):
             try:
                 top = self.top()
                 ref = next(top[1])
                 refd = self.index.get(ref)
                 if refd is None:
                     log.debug('"%s" not found, skipped', Repr(ref))
                     continue
                 self.push(refd)
             except StopIteration:
                 popped.append(self.pop())
                 continue
         for p in popped:
             self.sorted.append(p)
     self.unsorted = self.sorted
     return self.sorted
コード例 #4
0
 def getchild(self, name, parent):
     """ get a child by name """
     log.debug('searching parent (%s) for (%s)', Repr(parent), name)
     if name.startswith('@'):
         return parent.get_attribute(name[1:])
     else:
         return parent.get_child(name)
コード例 #5
0
ファイル: sxbase.py プロジェクト: levacorp/LevaCorp
 def str(self, indent=0, history=None):
     """
     Get a string representation of this object.
     @param indent: The indent.
     @type indent: int
     @return: A string.
     @rtype: str
     """
     if history is None:
         history = []
     if self in history:
         return '%s ...' % Repr(self)
     history.append(self)
     tab = '%*s' % (indent * 3, '')
     result = []
     result.append('%s<%s' % (tab, self.id))
     for n in self.description():
         if not hasattr(self, n):
             continue
         v = getattr(self, n)
         if v is None:
             continue
         result.append(' %s="%s"' % (n, v))
     if len(self):
         result.append('>')
         for c in self.rawchildren:
             result.append('\n')
             result.append(c.str(indent + 1, history[:]))
             if c.isattr():
                 result.append('@')
         result.append('\n%s' % tab)
         result.append('</%s>' % self.__class__.__name__)
     else:
         result.append(' />')
     return ''.join(result)
コード例 #6
0
 def dereference(self):
     """
     Instruct all children to perform dereferencing.
     """
     all = []
     indexes = {}
     for child in self.children:
         child.content(all)
     deplist = DepList()
     for x in all:
         x.qualify()
         midx, deps = x.dependencies()
         item = (x, tuple(deps))
         deplist.add(item)
         indexes[x] = midx
     for x, deps in deplist.sort():
         midx = indexes.get(x)
         if midx is None:
             continue
         d = deps[midx]
         log.debug('(%s) merging %s <== %s', self.tns[1], Repr(x), Repr(d))
         x.merge(d)
コード例 #7
0
 def branch(self, root, parts):
     """
     Traverse the path until the leaf is reached.
     @param parts: A list of path parts.
     @type parts: [str,..]
     @param root: The root.
     @type root: L{xsd.sxbase.SchemaObject}
     @return: The end of the branch.
     @rtype: L{xsd.sxbase.SchemaObject}
     """
     result = root
     for part in parts[1:-1]:
         name = splitPrefix(part)[1]
         log.debug('searching parent (%s) for (%s)', Repr(result), name)
         result, ancestry = result.get_child(name)
         if result is None:
             log.error('(%s) not-found', name)
             raise PathResolver.BadPath(name)
         else:
             result = result.resolve(nobuiltin=True)
             log.debug('found (%s) as (%s)', name, Repr(result))
     return result
コード例 #8
0
 def result(self, result):
     """
     Query result post processing.
     @param result: A query result.
     @type result: L{sxbase.SchemaObject}
     """
     if result is None:
         log.debug('%s, not-found', self.ref)
         return
     if self.resolved:
         result = result.resolve()
     log.debug('%s, found as: %s', self.ref, Repr(result))
     self.history.append(result)
     return result
コード例 #9
0
 def filter(self, result):
     """
     Filter the specified result based on query criteria.
     @param result: A potential result.
     @type result: L{sxbase.SchemaObject}
     @return: True if result should be excluded.
     @rtype: boolean
     """
     if result is None:
         return True
     reject = result in self.history
     if reject:
         log.debug('result %s, rejected by\n%s', Repr(result), self)
     return reject
コード例 #10
0
 def root(self, parts):
     """
     Find the path root.
     @param parts: A list of path parts.
     @type parts: [str,..]
     @return: The root.
     @rtype: L{xsd.sxbase.SchemaObject}
     """
     result = None
     name = parts[0]
     log.debug('searching schema for (%s)', name)
     qref = self.qualify(parts[0])
     query = BlindQuery(qref)
     result = query.execute(self.schema)
     if result is None:
         log.error('(%s) not-found', name)
         raise PathResolver.BadPath(name)
     else:
         log.debug('found (%s) as (%s)', name, Repr(result))
     return result
コード例 #11
0
 def find(self, name, resolved=True):
     """
     Get the definition object for the schema object by name.
     @param name: The name of a schema object.
     @type name: str
     @param resolved: A flag indicating that the fully resolved type
         should be returned.
     @type resolved: boolean
     @return: The found schema I{type}
     @rtype: L{xsd.sxbase.SchemaObject}
     """
     log.debug('searching schema for (%s)', name)
     qref = qualify(name, self.schema.root, self.schema.tns)
     query = BlindQuery(qref)
     result = query.execute(self.schema)
     if result is None:
         log.error('(%s) not-found', name)
         return None
     log.debug('found (%s) as (%s)', name, Repr(result))
     if resolved:
         result = result.resolve()
     return result
コード例 #12
0
 def __str__(self):
     return '%s\n%s\n%s' % (Repr(self.type), Repr(
         self.resolved), [Repr(t) for t in self.ancestry])