diff options
| author | Kenneth Reitz <me@kennethreitz.com> | 2011-02-17 16:35:36 -0500 |
|---|---|---|
| committer | Kenneth Reitz <me@kennethreitz.com> | 2011-02-17 16:35:36 -0500 |
| commit | ff0de1377af883c79e522b2f31e085540e6e245b (patch) | |
| tree | 7f4254bd9308d58699220d2db859e2dd9671717d | |
| parent | ccb29c68fa814424f9fc761fc6ab3d24779a8cc6 (diff) | |
| download | tablib-ff0de1377af883c79e522b2f31e085540e6e245b.tar.gz | |
wow, that was ugly
| -rw-r--r-- | tablib/packages/markup.py | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/tablib/packages/markup.py b/tablib/packages/markup.py index 72a7162..98d9b1d 100644 --- a/tablib/packages/markup.py +++ b/tablib/packages/markup.py @@ -29,10 +29,10 @@ class element: def __init__( self, tag, case='lower', parent=None ): self.parent = parent - if case == 'lower': - self.tag = tag.lower( ) - else: - self.tag = tag.upper( ) + if case == 'lower': + self.tag = tag.lower( ) + else: + self.tag = tag.upper( ) def __call__( self, *args, **kwargs ): if len( args ) > 1: @@ -67,8 +67,8 @@ class element: def render( self, tag, single, between, kwargs ): """Append the actual tags to content.""" - out = "<%s" % tag - for key, value in kwargs.iteritems( ): + out = "<%s" % tag + for key, value in kwargs.iteritems( ): if value is not None: # when value is None that means stuff like <... checked> key = key.strip('_') # strip this so class_ will mean class, etc. if key == 'http_equiv': # special cases, maybe change _ to - overall? @@ -78,13 +78,13 @@ class element: out = "%s %s=\"%s\"" % ( out, key, escape( value ) ) else: out = "%s %s" % ( out, key ) - if between is not None: - out = "%s>%s</%s>" % ( out, between, tag ) - else: - if single: - out = "%s />" % out - else: - out = "%s>" % out + if between is not None: + out = "%s>%s</%s>" % ( out, between, tag ) + else: + if single: + out = "%s />" % out + else: + out = "%s>" % out if self.parent is not None: self.parent.content.append( out ) else: @@ -145,30 +145,30 @@ class page: deprecated_twotags = [ "APPLET", "CENTER", "DIR", "FONT", "MENU", "S", "STRIKE", "U" ] self.header = [ ] - self.content = [ ] + self.content = [ ] self.footer = [ ] - self.case = case + self.case = case self.separator = separator # init( ) sets it to True so we know that </body></html> has to be printed at the end self._full = False self.class_= class_ - if mode == 'strict_html' or mode == 'html': - self.onetags = valid_onetags - self.onetags += map( string.lower, self.onetags ) - self.twotags = valid_twotags - self.twotags += map( string.lower, self.twotags ) - self.deptags = deprecated_onetags + deprecated_twotags - self.deptags += map( string.lower, self.deptags ) - self.mode = 'strict_html' - elif mode == 'loose_html': - self.onetags = valid_onetags + deprecated_onetags - self.onetags += map( string.lower, self.onetags ) - self.twotags = valid_twotags + deprecated_twotags - self.twotags += map( string.lower, self.twotags ) - self.mode = mode - elif mode == 'xml': + if mode == 'strict_html' or mode == 'html': + self.onetags = valid_onetags + self.onetags += map( string.lower, self.onetags ) + self.twotags = valid_twotags + self.twotags += map( string.lower, self.twotags ) + self.deptags = deprecated_onetags + deprecated_twotags + self.deptags += map( string.lower, self.deptags ) + self.mode = 'strict_html' + elif mode == 'loose_html': + self.onetags = valid_onetags + deprecated_onetags + self.onetags += map( string.lower, self.onetags ) + self.twotags = valid_twotags + deprecated_twotags + self.twotags += map( string.lower, self.twotags ) + self.mode = mode + elif mode == 'xml': if onetags and twotags: self.onetags = onetags self.twotags = twotags @@ -178,8 +178,8 @@ class page: self.onetags = russell( ) self.twotags = russell( ) self.mode = mode - else: - raise ModeError( mode ) + else: + raise ModeError( mode ) def __getattr__( self, attr ): if attr.startswith("__") and attr.endswith("__"): @@ -192,7 +192,7 @@ class page: end = [ '</body>', '</html>' ] else: end = [ ] - + return self.separator.join( self.header + self.content + self.footer + end ) def __call__( self, escape=False ): @@ -444,37 +444,37 @@ class russell: """A dummy class that contains anything.""" def __contains__( self, item ): - return True + return True class MarkupError( Exception ): """All our exceptions subclass this.""" def __str__( self ): - return self.message + return self.message class ClosingError( MarkupError ): def __init__( self, tag ): - self.message = "The element '%s' does not accept non-keyword arguments (has no closing tag)." % tag + self.message = "The element '%s' does not accept non-keyword arguments (has no closing tag)." % tag class OpeningError( MarkupError ): def __init__( self, tag ): - self.message = "The element '%s' can not be opened." % tag + self.message = "The element '%s' can not be opened." % tag class ArgumentError( MarkupError ): def __init__( self, tag ): - self.message = "The element '%s' was called with more than one non-keyword argument." % tag + self.message = "The element '%s' was called with more than one non-keyword argument." % tag class InvalidElementError( MarkupError ): def __init__( self, tag, mode ): - self.message = "The element '%s' is not valid for your mode '%s'." % ( tag, mode ) + self.message = "The element '%s' is not valid for your mode '%s'." % ( tag, mode ) class DeprecationError( MarkupError ): def __init__( self, tag ): - self.message = "The element '%s' is deprecated, instantiate markup.page with mode='loose_html' to allow it." % tag + self.message = "The element '%s' is deprecated, instantiate markup.page with mode='loose_html' to allow it." % tag class ModeError( MarkupError ): def __init__( self, mode ): - self.message = "Mode '%s' is invalid, possible values: strict_html, loose_html, xml." % mode + self.message = "Mode '%s' is invalid, possible values: strict_html, loose_html, xml." % mode class CustomizationError( MarkupError ): def __init__( self ): |
