Changeset 2270:337ee934750e in livinglogic.python.xist

Show
Ignore:
Timestamp:
02/07/05 17:21:05 (15 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Move content of errors.py into xsc.py. This fixes import problems.

Files:
1 removed
8 modified

Legend:

Unmodified
Added
Removed
  • NEWS.xml

    r2263 r2270  
    55of <class>ll.xist.presenters.TreePresenter</class> have been lowercased and 
    66presenters are properly reset after they've done their job.</item> 
     7<item>All error and warning classes from <module>ll.xist.errors</module> 
     8have been merged into <module>ll.xist.xsc</module> (This avoids 
     9import problems).</item> 
    710</ulist> 
    811</section> 
  • _xist/ns/doc.py

    r2256 r2270  
    2020import types, inspect, warnings, __builtin__ 
    2121 
    22 from ll.xist import xsc, parsers, sims, errors, xfind 
     22from ll.xist import xsc, parsers, sims, xfind 
    2323from ll.xist.ns import html, text, docbook, fo, specials, xml 
    2424 
     
    750750        context = converter[self] 
    751751        if not context.lists: 
    752             raise errors.NodeOutsideContextError(self, self.__ns__.list) 
     752            raise xsc.NodeOutsideContextError(self, self.__ns__.list) 
    753753        if context.lists[-1][0] == "dlist": 
    754754            e = converter.target.dd(self.content) 
  • _xist/ns/htmlspecials.py

    r2235 r2270  
    1919import sys, types, time as time_, string, warnings 
    2020 
    21 from ll.xist import xsc, parsers, errors, sims 
     21from ll.xist import xsc, parsers, sims 
    2222from ll.xist.ns import ihtml, html, meta, specials 
    2323 
     
    7777                            for c in content: 
    7878                                if c not in u"0369cf": 
    79                                     warnings.warn(errors.IllegalAttrValueWarning(self)) 
     79                                    warnings.warn(xsc.IllegalAttrValueWarning(self)) 
    8080                        else: 
    81                             warnings.warn(errors.IllegalAttrValueWarning(self)) 
     81                            warnings.warn(xsc.IllegalAttrValueWarning(self)) 
    8282 
    8383        class alt(html.img.Attrs.alt): 
  • _xist/parsers.py

    r2264 r2270  
    2929from ll import url 
    3030 
    31 import xsc, errors, utils, cssparsers 
     31import xsc, utils, cssparsers 
    3232from ns import html 
    3333 
     
    242242            name = texts[0] 
    243243            if len(texts)==1: 
    244                 raise errors.MalformedCharRefWarning(name) 
     244                raise xsc.MalformedCharRefWarning(name) 
    245245            if name.startswith(u"#"): 
    246246                try: 
     
    250250                        node.append(ct(unichr(int(name[1:])))) 
    251251                except ValueError: 
    252                     raise errors.MalformedCharRefWarning(name) 
     252                    raise xsc.MalformedCharRefWarning(name) 
    253253            else: 
    254254                try: 
     
    278278            try: 
    279279                self.getContentHandler().skippedEntity(name) 
    280             except errors.IllegalEntityError: 
     280            except xsc.IllegalEntityError: 
    281281                try: 
    282282                    entity = html.entity(name, xml=True) 
    283                 except errors.IllegalEntityError: 
     283                except xsc.IllegalEntityError: 
    284284                    self.getContentHandler().characters(u"&%s;" % name) 
    285285                else: 
     
    311311            if len(texts)==1: # no ; found, so it's no entity => append it literally 
    312312                name = u"&" + name 
    313                 warnings.warn(errors.MalformedCharRefWarning(name)) 
     313                warnings.warn(xsc.MalformedCharRefWarning(name)) 
    314314                node.append(ct(name)) 
    315315                break 
     
    323323                    except (ValueError, OverflowError): # illegal format => append it literally 
    324324                        name = u"&%s;" % name 
    325                         warnings.warn(errors.MalformedCharRefWarning(name)) 
     325                        warnings.warn(xsc.MalformedCharRefWarning(name)) 
    326326                        node.append(ct(name)) 
    327327                else: # entity reference 
     
    331331                        try: 
    332332                            entity = self.getContentHandler().createEntity(name) 
    333                         except errors.IllegalEntityError: 
     333                        except xsc.IllegalEntityError: 
    334334                            try: 
    335335                                entity = html.entity(name, xml=True) 
     
    338338                                else: 
    339339                                    entity = entity() 
    340                             except errors.IllegalEntityError: 
     340                            except xsc.IllegalEntityError: 
    341341                                name = u"&%s;" % name 
    342                                 warnings.warn(errors.MalformedCharRefWarning(name)) 
     342                                warnings.warn(xsc.MalformedCharRefWarning(name)) 
    343343                                entity = ct(name) 
    344344                    else: 
     
    392392        # Check whether this element is allowed in the current context 
    393393        if self._stack and name not in htmldtd.HTML_DTD.get(self._stack[-1], []): 
    394             warnings.warn(errors.IllegalDTDChildWarning(name, self._stack[-1])) 
     394            warnings.warn(xsc.IllegalDTDChildWarning(name, self._stack[-1])) 
    395395 
    396396        # Skip unknown attributes (but warn about them) 
     
    401401                newattrs[attrname.lower()] = attrvalue 
    402402            else: 
    403                 warnings.warn(errors.IllegalAttrError(element.Attrs, attrname.lower(), xml=True)) 
     403                warnings.warn(xsc.IllegalAttrError(element.Attrs, attrname.lower(), xml=True)) 
    404404        BadEntityParser.finish_starttag(self, name, newattrs) 
    405405 
     
    425425            del self._stack[-1] 
    426426        else: 
    427             warnings.warn(errors.IllegalCloseTagWarning(name)) 
     427            warnings.warn(xsc.IllegalCloseTagWarning(name)) 
    428428 
    429429 
     
    525525                try: 
    526526                    newnode = ns.element(name, xml=True)() 
    527                 except errors.IllegalElementError: 
     527                except xsc.IllegalElementError: 
    528528                    newnode = xsc.Frag() 
    529529                else: 
     
    537537                        try: 
    538538                            attrnode = newnode.attrs.set(name, content, xml=True) 
    539                         except errors.IllegalAttrError: 
     539                        except xsc.IllegalAttrError: 
    540540                            pass 
    541541                        else: 
     
    691691        element = self.createElement(name) # Unfortunately this creates the element a second time. 
    692692        if element is not None and element.__class__ is not currentelement.__class__: 
    693             raise errors.ElementNestingError(currentelement.__class__, element.__class__) 
     693            raise xsc.ElementNestingError(currentelement.__class__, element.__class__) 
    694694        self.skippingwhitespace = False 
    695695 
  • _xist/publishers.py

    r2235 r2270  
    2121from ll import url 
    2222 
    23 import xsc, options, helpers, errors 
     23import xsc, options, helpers 
    2424 
    2525 
     
    175175        # Determine if we have multiple roots 
    176176        if prefixes2def and isinstance(node, xsc.Frag) and len(node.find(xsc.FindType(xsc.Element))) > 1: 
    177             raise errors.MultipleRootsError() 
     177            raise xsc.MultipleRootsError() 
    178178 
    179179        if prefixes2def: 
  • _xist/sims.py

    r2235 r2270  
    1818 
    1919import warnings 
    20 from ll.xist import xsc, errors 
    21  
    22  
    23 class SIMSWarning(errors.Warning): 
     20from ll.xist import xsc 
     21 
     22 
     23class SIMSWarning(xsc.Warning): 
    2424    """ 
    2525    Base class for simplified filtering 
  • _xist/xsc.py

    r2269 r2270  
    6565        except TypeError: 
    6666            pass 
    67     from ll.xist import errors 
    68     warnings.warn(errors.IllegalObjectWarning(value)) # none of the above, so we report it and maybe throw an exception 
     67    warnings.warn(IllegalObjectWarning(value)) # none of the above, so we report it and maybe throw an exception 
    6968    return Null 
    7069 
     
    221220 
    222221_Context = Context 
     222 
     223 
     224### 
     225### Exceptions and warnings 
     226### 
     227 
     228class Error(Exception): 
     229    """ 
     230    base class for all &xist; exceptions 
     231    """ 
     232    pass 
     233 
     234 
     235class Warning(UserWarning): 
     236    """ 
     237    base class for all warning exceptions (i.e. those that won't 
     238    result in a program termination.) 
     239    """ 
     240    pass 
     241 
     242 
     243class IllegalAttrError(Warning, LookupError): 
     244    """ 
     245    exception that is raised, when an element has an illegal attribute 
     246    (i.e. one that isn't defined in the appropriate attributes class) 
     247    """ 
     248 
     249    def __init__(self, attrs, attrname, xml=False): 
     250        self.attrs = attrs 
     251        self.attrname = attrname 
     252        self.xml = xml 
     253 
     254    def __str__(self): 
     255        if self.attrs is not None: 
     256            return "Attribute with %s name %r not allowed for %s" % (("Python", "XML")[self.xml], self.attrname, self.attrs._str(fullname=True, xml=False, decorate=False)) 
     257        else: 
     258            return "Global attribute with %s name %r not allowed" % (("Python", "XML")[self.xml], self.attrname) 
     259 
     260 
     261class IllegalAttrValueWarning(Warning): 
     262    """ 
     263    warning that is issued when an attribute has an illegal value when parsing or publishing. 
     264    """ 
     265 
     266    def __init__(self, attr): 
     267        self.attr = attr 
     268 
     269    def __str__(self): 
     270        attr = self.attr 
     271        return "Attribute value %r not allowed for %s. " % (str(attr), attr._str(fullname=True, xml=False, decorate=False)) 
     272 
     273 
     274class RequiredAttrMissingWarning(Warning): 
     275    """ 
     276    warning that is issued when a required attribute is missing during parsing or publishing. 
     277    """ 
     278 
     279    def __init__(self, attrs, reqattrs): 
     280        self.attrs = attrs 
     281        self.reqattrs = reqattrs 
     282 
     283    def __str__(self): 
     284        v = ["Required attribute"] 
     285        if len(self.reqattrs)>1: 
     286            v.append("s ") 
     287            v.append(", ".join("%r" % attr for attr in self.reqattrs)) 
     288        else: 
     289            v.append(" %r" % self.reqattrs[0]) 
     290        v.append(" missing in %s." % self.attrs._str(fullname=True, xml=False, decorate=False)) 
     291        return "".join(v) 
     292 
     293 
     294class IllegalDTDChildWarning(Warning): 
     295    """ 
     296    warning that is issued when the <pyref module="ll.xist.parsers" class="HTMLParser"><class>HTMLParser</class></pyref> 
     297    detects an element that is not allowed inside its parent element according to the &html; &dtd; 
     298    """ 
     299 
     300    def __init__(self, childname, parentname): 
     301        self.childname = childname 
     302        self.parentname = parentname 
     303 
     304    def __str__(self): 
     305        return "Element %s not allowed as a child of element %s" % (self.childname, self.parentname) 
     306 
     307 
     308class IllegalCloseTagWarning(Warning): 
     309    """ 
     310    warning that is issued when the <pyref module="ll.xist.parsers" class="HTMLParser"><class>HTMLParser</class></pyref> 
     311    finds an end tag that has no corresponding start tag. 
     312    """ 
     313 
     314    def __init__(self, name): 
     315        self.name = name 
     316 
     317    def __str__(self): 
     318        return "Element %s has never been opened" % (self.name,) 
     319 
     320 
     321class IllegalPrefixError(Error, LookupError): 
     322    """ 
     323    Exception that is raised when a namespace prefix is undefined. 
     324    """ 
     325    def __init__(self, prefix): 
     326        self.prefix = prefix 
     327 
     328    def __str__(self): 
     329        return "namespace prefix %r is undefined" % self.prefix 
     330 
     331 
     332class IllegalNamespaceError(Error, LookupError): 
     333    """ 
     334    Exception that is raised when a namespace name is undefined 
     335    i.e. if there is no namespace with this name. 
     336    """ 
     337    def __init__(self, name): 
     338        self.name = name 
     339 
     340    def __str__(self): 
     341        return "namespace name %r is undefined" % self.name 
     342 
     343 
     344class IllegalNodeError(Error, LookupError): 
     345    """ 
     346    exception that is raised, when an illegal node class (element, procinst, entity or charref) is requested 
     347    """ 
     348 
     349    type = "node" 
     350 
     351    def __init__(self, name, xml=False): 
     352        self.name = name 
     353        self.xml = xml 
     354 
     355    def __str__(self): 
     356        return "%s with %s name %r not allowed" % (self.type, ("Python", "XML")[self.xml], self.name, ) 
     357 
     358 
     359class IllegalElementError(IllegalNodeError): 
     360    type = "element" 
     361 
     362 
     363class IllegalProcInstError(IllegalNodeError): 
     364    type = "procinst" 
     365 
     366 
     367class IllegalEntityError(IllegalNodeError): 
     368    type = "entity" 
     369 
     370 
     371class IllegalCharRefError(IllegalNodeError): 
     372    type = "charref" 
     373 
     374    def __str__(self): 
     375        if isinstance(self.name, (int, long)): 
     376            return "%s with codepoint %s not allowed" % (self.type, self.name) 
     377        else: 
     378            return IllegalNodeError.__str__(self) 
     379 
     380 
     381class AmbiguousNodeError(Error, LookupError): 
     382    """ 
     383    exception that is raised, when an node class is ambiguous (most commonly for processing instructions or entities) 
     384    """ 
     385 
     386    type = "node" 
     387 
     388    def __init__(self, name, xml=False): 
     389        self.name = name 
     390        self.xml = xml 
     391 
     392    def __str__(self): 
     393        return "%s with %s name %r is ambigous" % (self.type, ("Python", "XML")[self.xml], self.name) 
     394 
     395 
     396class AmbiguousProcInstError(AmbiguousNodeError): 
     397    type = "procinst" 
     398 
     399 
     400class AmbiguousEntityError(AmbiguousNodeError): 
     401    type = "entity" 
     402 
     403 
     404class AmbiguousCharRefError(AmbiguousNodeError): 
     405    type = "charref" 
     406 
     407    def __str__(self): 
     408        if isinstance(self.name, (int, long)): 
     409            return "%s with codepoint %r is ambigous" % (self.type, self.name) 
     410        else: 
     411            return AmbiguousNodeError.__str__(self) 
     412 
     413 
     414class MultipleRootsError(Error): 
     415    def __str__(self): 
     416        return "can't add namespace attributes: XML tree has multiple roots" 
     417 
     418 
     419class ElementNestingError(Error): 
     420    """ 
     421    exception that is raised, when an element has an illegal nesting 
     422    (e.g. <lit>&lt;a&gt;&lt;b&gt;&lt;/a&gt;&lt;/b&gt;</lit>) 
     423    """ 
     424 
     425    def __init__(self, expectedelement, foundelement): 
     426        self.expectedelement = expectedelement 
     427        self.foundelement = foundelement 
     428 
     429    def __str__(self): 
     430        return "mismatched element nesting (close tag for %s expected; close tag for %s found)" % (self.expectedelement._str(fullname=1, xml=0, decorate=1), self.foundelement._str(fullname=1, xml=0, decorate=1)) 
     431 
     432 
     433class IllegalAttrNodeError(Error): 
     434    """ 
     435    exception that is raised, when something is found 
     436    in an attribute that doesn't belong there (e.g. an element or a comment). 
     437    """ 
     438 
     439    def __init__(self, node): 
     440        self.node = node 
     441 
     442    def __str__(self): 
     443        return "illegal node of type %s found inside attribute" % self.node.__class__.__name__ 
     444 
     445 
     446class NodeNotFoundError(Error): 
     447    """ 
     448    exception that is raised when <pyref module="ll.xist.xsc" class="Node" method="findfirst"><method>findfirst</method></pyref> fails. 
     449    """ 
     450    def __str__(self): 
     451        return "no appropriate node found" 
     452 
     453 
     454class FileNotFoundWarning(Warning): 
     455    """ 
     456    warning that is raised, when a file can't be found 
     457    """ 
     458    def __init__(self, message, filename, exc): 
     459        Warning.__init__(self, message, filename, exc) 
     460        self.message = message 
     461        self.filename = filename 
     462        self.exc = exc 
     463 
     464    def __str__(self): 
     465        return "%s: %r not found (%s)" % (self.message, self.filename, self.exc) 
     466 
     467 
     468class IllegalObjectWarning(Warning): 
     469    """ 
     470    warning that is issued when &xist; finds an illegal object in its object tree. 
     471    """ 
     472 
     473    def __init__(self, object): 
     474        self.object = object 
     475 
     476    def __str__(self): 
     477        s = "an illegal object %r of type %s has been found in the XSC tree. The object will be ignored." % (self.object, type(self.object).__name__) 
     478        return s 
     479 
     480 
     481class MalformedCharRefWarning(Warning): 
     482    """ 
     483    exception that is raised when a character reference is malformed (e.g. <lit>&amp;#foo;</lit>) 
     484    """ 
     485 
     486    def __init__(self, name): 
     487        self.name = name 
     488 
     489    def __str__(self): 
     490        return "malformed character reference: &%s;" % self.name 
     491 
     492 
     493class IllegalCommentContentWarning(Warning): 
     494    """ 
     495    warning that is issued when there is an illegal comment, i.e. one 
     496    containing <lit>--</lit> or ending in <lit>-</lit>. 
     497    (This can only happen, when the comment is instantiated by the 
     498    program, not when parsed from an &xml; file.) 
     499    """ 
     500 
     501    def __init__(self, comment): 
     502        self.comment = comment 
     503 
     504    def __str__(self): 
     505        return "comment with content %s is illegal, as it contains '--' or ends in '-'." % presenters.strTextOutsideAttr(self.comment.content) 
     506 
     507 
     508class IllegalProcInstFormatError(Error): 
     509    """ 
     510    exception that is raised, when there is an illegal processing instruction, i.e. one containing <lit>?&gt;</lit>. 
     511    (This can only happen, when the processing instruction is instantiated by the 
     512    program, not when parsed from an &xml; file.) 
     513    """ 
     514 
     515    def __init__(self, procinst): 
     516        self.procinst = procinst 
     517 
     518    def __str__(self): 
     519        return "processing instruction with content %s is illegal, as it contains %r." % (presenters.strProcInstContent(self.procinst.content), "?>") 
     520 
     521 
     522class IllegalXMLDeclFormatError(Error): 
     523    """ 
     524    exception that is raised, when there is an illegal XML declaration, 
     525    i.e. there something wrong in <lit>&lt;?xml ...?&gt;</lit>. 
     526    (This can only happen, when the processing instruction is instantiated by the 
     527    program, not when parsed from an &xml; file.) 
     528    """ 
     529 
     530    def __init__(self, procinst): 
     531        self.procinst = procinst 
     532 
     533    def __str__(self): 
     534        return "XML declaration with content %r is malformed." % presenters.strProcInstContent(self.procinst.content) 
     535 
     536 
     537class ParseWarning(Warning): 
     538    """ 
     539    General warning issued during parsing. 
     540    """ 
     541 
     542 
     543class IllegalElementParseWarning(IllegalElementError, ParseWarning): 
     544    """ 
     545    Warning about an illegal element that is issued during parsing. 
     546    """ 
     547warnings.filterwarnings("error", category=IllegalElementParseWarning) 
     548 
     549 
     550class IllegalProcInstParseWarning(IllegalProcInstError, ParseWarning): 
     551    """ 
     552    Warning about an illegal processing instruction that is issued during parsing. 
     553    """ 
     554warnings.filterwarnings("error", category=IllegalProcInstParseWarning) 
     555 
     556 
     557class AmbiguousProcInstParseWarning(AmbiguousProcInstError, ParseWarning): 
     558    """ 
     559    Warning about an ambigous processing instruction that is issued during parsing. 
     560    """ 
     561warnings.filterwarnings("error", category=AmbiguousProcInstParseWarning) 
     562 
     563 
     564class IllegalEntityParseWarning(IllegalEntityError, ParseWarning): 
     565    """ 
     566    Warning about an illegal entity that is issued during parsing. 
     567    """ 
     568warnings.filterwarnings("error", category=IllegalEntityParseWarning) 
     569 
     570 
     571class AmbiguousEntityParseWarning(AmbiguousEntityError, ParseWarning): 
     572    """ 
     573    Warning about an ambigous entity that is issued during parsing. 
     574    """ 
     575warnings.filterwarnings("error", category=AmbiguousEntityParseWarning) 
     576 
     577 
     578class IllegalCharRefParseWarning(IllegalCharRefError, ParseWarning): 
     579    """ 
     580    Warning about an illegal character references that is issued during parsing. 
     581    """ 
     582warnings.filterwarnings("error", category=IllegalCharRefParseWarning) 
     583 
     584 
     585class AmbiguousCharRefParseWarning(AmbiguousCharRefError, ParseWarning): 
     586    """ 
     587    Warning about an ambigous character references that is issued during parsing. 
     588    """ 
     589warnings.filterwarnings("error", category=AmbiguousCharRefParseWarning) 
     590 
     591 
     592class IllegalAttrParseWarning(IllegalAttrError, ParseWarning): 
     593    """ 
     594    Warning about an illegal attribute that is issued during parsing. 
     595    """ 
     596warnings.filterwarnings("error", category=IllegalAttrParseWarning) 
     597 
     598 
     599class NodeOutsideContextError(Error): 
     600    """ 
     601    Error that is raised, when a convert method can't find required context 
     602    info. 
     603    """ 
     604 
     605    def __init__(self, node, outerclass): 
     606        self.node = node 
     607        self.outerclass = outerclass 
     608 
     609    def __str__(self): 
     610        s = "node %s" % self.node._str(fullname=True, xml=False, decorate=True) 
     611        if self.node.startloc is not None: 
     612            s += " at %s" % self.node.startloc 
     613        s += " outside of %r" % self.outerclass 
     614        return s 
    223615 
    224616 
     
    7081100        for item in self.walk(filter, filterpath, False): 
    7091101            return item 
    710         from ll.xist import errors 
    711         raise errors.NodeNotFoundError() 
     1102        raise NodeNotFoundError() 
    7121103 
    7131104    def __div__(self, other): 
     
    12941685    def publish(self, publisher): 
    12951686        if publisher.inattr: 
    1296             from ll.xist import errors 
    1297             raise errors.IllegalAttrNodeError(self) 
     1687            raise IllegalAttrNodeError(self) 
    12981688        content = self.content 
    12991689        if u"--" in content or content.endswith(u"-"): 
    1300             from ll.xist import errors 
    1301             warnings.warn(errors.IllegalCommentContentWarning(self)) 
     1690            warnings.warn(IllegalCommentContentWarning(self)) 
    13021691        publisher.write(u"<!--") 
    13031692        publisher.write(content) 
     
    13181707    def publish(self, publisher): 
    13191708        if publisher.inattr: 
    1320             from ll.xist import errors 
    1321             raise errors.IllegalAttrNodeError(self) 
     1709            raise IllegalAttrNodeError(self) 
    13221710        publisher.write(u"<!DOCTYPE ") 
    13231711        publisher.write(self.content) 
     
    13631751        content = self.content 
    13641752        if u"?>" in content: 
    1365             from ll.xist import errors 
    1366             raise errors.IllegalProcInstFormatError(self) 
     1753            raise IllegalProcInstFormatError(self) 
    13671754        publisher.write(u"<?") 
    13681755        publisher.write(self.xmlname[True]) 
     
    15081895            value = unicode(self) 
    15091896            if value not in values: 
    1510                 from ll.xist import errors 
    1511                 warnings.warn(errors.IllegalAttrValueWarning(self)) 
     1897                warnings.warn(IllegalAttrValueWarning(self)) 
    15121898 
    15131899    def _walk(self, filter, path, filterpath, walkpath): 
     
    18692255        # are there any required attributes remaining that haven't been specified? => warn about it 
    18702256        if attrs: 
    1871             from ll.xist import errors 
    1872             warnings.warn(errors.RequiredAttrMissingWarning(self, list(attrs))) 
     2257            warnings.warn(RequiredAttrMissingWarning(self, list(attrs))) 
    18732258 
    18742259    def publish(self, publisher): 
     
    20772462            return cls._attrs[xml][name].xmlname[False] 
    20782463        except KeyError: 
    2079             from ll.xist import errors 
    2080             raise errors.IllegalAttrError(cls, name, xml=xml) 
     2464            raise IllegalAttrError(cls, name, xml=xml) 
    20812465 
    20822466    @classmethod 
     
    20852469            return cls._attrs[xml][name] 
    20862470        except KeyError: 
    2087             from ll.xist import errors 
    2088             raise errors.IllegalAttrError(cls, name, xml=xml) 
     2471            raise IllegalAttrError(cls, name, xml=xml) 
    20892472 
    20902473    def __iter__(self): 
     
    22442627                return cls._attrs[xml][name].xmlname[False] 
    22452628            except KeyError: 
    2246                 from ll.xist import errors 
    2247                 raise errors.IllegalAttrError(cls, name, xml=xml) 
     2629                raise IllegalAttrError(cls, name, xml=xml) 
    22482630 
    22492631        @classmethod 
     
    22562638                    return cls._attrs[xml][name] 
    22572639                except KeyError: 
    2258                     from ll.xist import errors 
    2259                     raise errors.IllegalAttrError(cls, name, xml=xml) 
     2640                    raise IllegalAttrError(cls, name, xml=xml) 
    22602641 
    22612642        def with(self, names=[], namespaces=(), keepglobals=False, xml=False): 
     
    24272808            size = url.openread().imagesize 
    24282809        except IOError, exc: 
    2429             from ll.xist import errors 
    2430             warnings.warn(errors.FileNotFoundWarning("can't read image", url, exc)) 
     2810            warnings.warn(FileNotFoundWarning("can't read image", url, exc)) 
    24312811        else: 
    24322812            for attr in (heightattr, widthattr): 
     
    29353315    DECLAREANDUSEPREFIX = 2 
    29363316 
    2937     from ll.xist import errors 
    29383317    # Warning classes 
    2939     IllegalElementWarning = errors.IllegalElementParseWarning 
    2940     IllegalProcInstWarning = errors.IllegalProcInstParseWarning 
    2941     AmbiguousProcInstWarning = errors.AmbiguousProcInstParseWarning 
    2942     IllegalEntityWarning = errors.IllegalEntityParseWarning 
    2943     AmbiguousEntityWarning = errors.AmbiguousEntityParseWarning 
    2944     IllegalCharRefWarning = errors.IllegalCharRefParseWarning 
    2945     AmbiguousCharRefWarning = errors.AmbiguousCharRefParseWarning 
    2946     IllegalAttrWarning = errors.IllegalAttrParseWarning 
     3318    IllegalElementWarning = IllegalElementParseWarning 
     3319    IllegalProcInstWarning = IllegalProcInstParseWarning 
     3320    AmbiguousProcInstWarning = AmbiguousProcInstParseWarning 
     3321    IllegalEntityWarning = IllegalEntityParseWarning 
     3322    AmbiguousEntityWarning = AmbiguousEntityParseWarning 
     3323    IllegalCharRefWarning = IllegalCharRefParseWarning 
     3324    AmbiguousCharRefWarning = AmbiguousCharRefParseWarning 
     3325    IllegalAttrWarning = IllegalAttrParseWarning 
    29473326 
    29483327    def __init__(self, nswithoutprefix=None, **nswithprefix): 
     
    30983477            try: 
    30993478                return element.Attrs.allowedattr(qname[1], xml=True).xmlname[False] 
    3100             except errors.IllegalAttrError: 
     3479            except IllegalAttrError: 
    31013480                warnings.warn(self.IllegalAttrWarning(element.attrs, qname[1], xml=True)) 
    31023481        else: 
     
    31063485                    if attr.register: 
    31073486                        return (ns, attr.xmlname[False]) 
    3108                 except errors.IllegalAttrError: # no attribute in this namespace with this name 
     3487                except IllegalAttrError: # no attribute in this namespace with this name 
    31093488                    pass 
    31103489            warnings.warn(self.IllegalAttrWarning(None, qname, xml=True)) 
     
    34123791            return cls._getcache()[0][xml][name] 
    34133792        except KeyError: 
    3414             raise errors.IllegalElementError(name, xml=xml) 
     3793            raise IllegalElementError(name, xml=xml) 
    34153794 
    34163795    @classmethod 
     
    34783857            return cls._getcache()[1][xml][name] 
    34793858        except KeyError: 
    3480             raise errors.IllegalProcInstError(name, xml=xml) 
     3859            raise IllegalProcInstError(name, xml=xml) 
    34813860 
    34823861    @classmethod 
     
    35473926            return cls._getcache()[2][xml][name] 
    35483927        except KeyError: 
    3549             raise errors.IllegalEntityError(name, xml=xml) 
     3928            raise IllegalEntityError(name, xml=xml) 
    35503929 
    35513930    @classmethod 
     
    36183997                charrefs = cache[3][2][name] 
    36193998                if len(charrefs) > 1: 
    3620                     raise errors.AmbiguousCharRefError(name, xml) 
     3999                    raise AmbiguousCharRefError(name, xml) 
    36214000                return charrefs[0] 
    36224001            else: 
    36234002                return cache[3][xml][name] 
    36244003        except KeyError: 
    3625             raise errors.IllegalCharRefError(name, xml=xml) 
     4004            raise IllegalCharRefError(name, xml=xml) 
    36264005 
    36274006    @classmethod 
     
    36884067            try: 
    36894068                yield (cls.procinst(unicode(target, encoding), xml=True), data) 
    3690             except errors.IllegalProcInstError: 
     4069            except IllegalProcInstError: 
    36914070                yield (str, "<?%s %s?>" % (target, data)) # return unknown PIs as text 
    36924071            pos = pos2+2 
  • test/test.py

    r2261 r2270  
    1515 
    1616from ll import url 
    17 from ll.xist import xsc, parsers, cssparsers, presenters, converters, helpers, errors, options, sims, xnd, xfind 
     17from ll.xist import xsc, parsers, cssparsers, presenters, converters, helpers, options, sims, xnd, xfind 
    1818from ll.xist.ns import wml, ihtml, html, chars, css, abbr, specials, htmlspecials, php, xml, tld 
    1919 
     
    729729        self.assert_(node.attrs.has("withdef")) 
    730730        self.assert_(not node.attrs.has("withoutdef")) 
    731         self.assertRaises(errors.IllegalAttrError, node.attrs.has, "illegal") 
     731        self.assertRaises(xsc.IllegalAttrError, node.attrs.has, "illegal") 
    732732        node = Test(withdef=None) 
    733733        self.assert_(not node.attrs.has("withdef")) 
     
    861861    def test_allowedattr(self): 
    862862        self.assertEquals(html.a.Attrs.allowedattr("href"), html.a.Attrs.href) 
    863         self.assertRaises(errors.IllegalAttrError, html.a.Attrs.allowedattr, "gurk") 
     863        self.assertRaises(xsc.IllegalAttrError, html.a.Attrs.allowedattr, "gurk") 
    864864        self.assertEquals(html.a.Attrs.allowedattr((xml, "lang")), xml.Attrs.lang) 
    865865 
     
    920920 
    921921        # No global attributes inside global attributes 
    922         self.assertRaises(errors.IllegalAttrError, xml.Attrs, xml.Attrs(lang="de")) 
     922        self.assertRaises(xsc.IllegalAttrError, xml.Attrs, xml.Attrs(lang="de")) 
    923923 
    924924    def test_classrepr(self): 
     
    12171217        self.assertEquals(ns.element("foo"), ns2.foo) 
    12181218        self.assertEquals(ns.element("bar"), ns2.bar) 
    1219         self.assertRaises(errors.IllegalElementError, ns.element, "foo2") 
    1220         self.assertRaises(errors.IllegalElementError, ns.element, "bar2") 
     1219        self.assertRaises(xsc.IllegalElementError, ns.element, "foo2") 
     1220        self.assertRaises(xsc.IllegalElementError, ns.element, "bar2") 
    12211221 
    12221222    def test_attributeexamples(self): 
     
    15711571        self.assertEqual(str(node[0]["required"]), "foo") 
    15721572 
    1573         warnings.filterwarnings("error", category=errors.RequiredAttrMissingWarning) 
    1574         self.assertSAXRaises(errors.RequiredAttrMissingWarning, parsers.parseString, '<Test/>', prefixes=prefixes) 
     1573        warnings.filterwarnings("error", category=xsc.RequiredAttrMissingWarning) 
     1574        self.assertSAXRaises(xsc.RequiredAttrMissingWarning, parsers.parseString, '<Test/>', prefixes=prefixes) 
    15751575 
    15761576    def test_parsevalueattrs(self): 
     
    15831583        prefixes = xsc.Prefixes(__ns__) 
    15841584 
    1585         warnings.filterwarnings("error", category=errors.IllegalAttrValueWarning) 
     1585        warnings.filterwarnings("error", category=xsc.IllegalAttrValueWarning) 
    15861586        node = parsers.parseString('<Test withvalues="bar"/>', prefixes=prefixes) 
    15871587        self.assertEqual(str(node[0]["withvalues"]), "bar") 
    1588         self.assertSAXRaises(errors.IllegalAttrValueWarning, parsers.parseString, '<Test withvalues="baz"/>', prefixes=prefixes) 
     1588        self.assertSAXRaises(xsc.IllegalAttrValueWarning, parsers.parseString, '<Test withvalues="baz"/>', prefixes=prefixes) 
    15891589 
    15901590    class __ns__(xsc.Namespace): 
     
    16081608    def check_parsestrictentities(self, source, result, parserfactory): 
    16091609        # in the strict parser the errors will always be raised, so change them into errors to verify that 
    1610         warnings.filterwarnings("error", category=errors.MalformedCharRefWarning) 
     1610        warnings.filterwarnings("error", category=xsc.MalformedCharRefWarning) 
    16111611 
    16121612        prefixes = xsc.Prefixes([self.__class__.__ns__, chars]) 
    16131613        self.check_parseentities(source, result, prefixes=prefixes, saxparser=parserfactory) 
    16141614        for bad in ("&", "&#x", "&&", "&#x;", "&#fg;", "&#999999999;", "&#;", "&#y;", "&#x;", "&#xy;"): 
    1615             self.assertSAXRaises((errors.MalformedCharRefWarning, expat.ExpatError), self.check_parseentities, bad, u"", prefixes=prefixes, saxparser=parserfactory) 
    1616         self.assertSAXRaises(errors.IllegalEntityError, self.check_parseentities, "&baz;", u"", prefixes=prefixes, saxparser=parserfactory) 
     1615            self.assertSAXRaises((xsc.MalformedCharRefWarning, expat.ExpatError), self.check_parseentities, bad, u"", prefixes=prefixes, saxparser=parserfactory) 
     1616        self.assertSAXRaises(xsc.IllegalEntityError, self.check_parseentities, "&baz;", u"", prefixes=prefixes, saxparser=parserfactory) 
    16171617 
    16181618    def test_parsestrictentities_sgmlop(self): 
     
    16311631 
    16321632    def check_parsebadentities(self, parserfactory): 
    1633         warnings.filterwarnings("ignore", category=errors.MalformedCharRefWarning) 
     1633        warnings.filterwarnings("ignore", category=xsc.MalformedCharRefWarning) 
    16341634 
    16351635        prefixes = xsc.Prefixes([self.__class__.__ns__, chars])