Changeset 2631:81a30d7983ae in livinglogic.python.xist

Show
Ignore:
Timestamp:
01/31/07 11:56:26 (13 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Change the default for the prefixes argument: Now all namespaces known to
the current pool are mapped to the empty prefix.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/ll/xist/parsers.py

    r2629 r2631  
    557557 
    558558class LaxElement(xsc.Element): 
     559    register = None 
    559560    Attrs = LaxAttrs 
    560561 
     
    566567    """ 
    567568 
    568     def __init__(self, saxparser=SGMLOPParser, prefixes={}, tidy=False, loc=True, validate=True, encoding=None, pool=None): 
     569    def __init__(self, saxparser=SGMLOPParser, prefixes=None, tidy=False, loc=True, validate=True, encoding=None, pool=None): 
    569570        """ 
    570571        <par>Create a new <class>Parser</class> instance.</par> 
     
    607608 
    608609        # the currently active prefix mapping (will be replaced once xmlns attributes are encountered) 
    609         self.prefixes = {} 
    610         for (prefix, xmlns) in prefixes.iteritems(): 
    611             if isinstance(xmlns, (list, tuple)): 
    612                 self.prefixes[prefix] = map(xsc.nsname, xmlns) 
    613             else: 
    614                 self.prefixes[prefix] = xsc.nsname(xmlns) 
     610        if prefixes is None: 
     611            # make all currently known namespaces available without prefix 
     612            # (if there are elements with colliding namespace, which one will be used is random (based on dict iteration order) 
     613            self.prefixes = {None: list(set(xsc.nsname(c.xmlns) for c in xsc.getpoolstack()[-1].element_values()))} 
     614        else: 
     615            self.prefixes = {} 
     616            for (prefix, xmlns) in prefixes.iteritems(): 
     617                if isinstance(xmlns, (list, tuple)): 
     618                    self.prefixes[prefix] = map(xsc.nsname, xmlns) 
     619                else: 
     620                    self.prefixes[prefix] = xsc.nsname(xmlns) 
    615621 
    616622        self._locator = None