1- # -*- encoding: utf8 -*-
21#
32# $Id: html.py 5409 2011-06-29 07:07:25Z rjones $
43# $HeadURL: svn+ssh://svn/svn/trunk/api/eklib/html.py $
223222See the end of the source file for the license of use.
224223XHTML support was contributed by Michael Haubenwallner.
225224"""
226- from __future__ import with_statement
227225
228226__version__ = "1.16"
229227
232230import unittest
233231
234232
235- class HTML ( object ) :
233+ class HTML :
236234 """Easily generate HTML.
237235
238236 >>> print HTML('html', 'some text')
@@ -254,7 +252,9 @@ class HTML(object):
254252
255253 newline_default_on = set ("table ol ul dl" .split ())
256254
257- def __init__ (self , name = None , text = None , stack = None , newlines = True , escape = True ):
255+ def __init__ (
256+ self , name = None , text = None , stack = None , newlines = True , escape = True
257+ ):
258258 self ._name = name
259259 self ._content = []
260260 self ._attrs = {}
@@ -311,10 +311,13 @@ def __call__(self, *content, **kw):
311311 if self ._name == "read" :
312312 if len (content ) == 1 and isinstance (content [0 ], int ):
313313 raise TypeError (
314- "you appear to be calling read(%d) on " "a HTML instance" % content
314+ "you appear to be calling read(%d) on "
315+ "a HTML instance" % content
315316 )
316317 elif len (content ) == 0 :
317- raise TypeError ("you appear to be calling read() on a " "HTML instance" )
318+ raise TypeError (
319+ "you appear to be calling read() on a " "HTML instance"
320+ )
318321
319322 # customising a tag with content or attributes
320323 escape = kw .pop ("escape" , True )
@@ -343,7 +346,7 @@ def __exit__(self, exc_type, exc_value, exc_tb):
343346 self ._stack .pop ()
344347
345348 def __repr__ (self ):
346- return "<HTML %s 0x%x>" % (self ._name , id (self ))
349+ return "<HTML {} 0x{:x}>" . format (self ._name , id (self ))
347350
348351 def _stringify (self , str_type ):
349352 # turn me and my content into text
@@ -352,7 +355,7 @@ def _stringify(self, str_type):
352355 return join .join (map (str_type , self ._content ))
353356 a = ['%s="%s"' % i for i in self ._attrs .items ()]
354357 l = [self ._name ] + a
355- s = "<%s>%s" % (" " .join (l ), join )
358+ s = "<{}>{}" . format (" " .join (l ), join )
356359 if self ._content :
357360 s += join .join (map (str_type , self ._content ))
358361 s += join + "</%s>" % self ._name
@@ -384,12 +387,12 @@ def _stringify(self, str_type):
384387 return join .join (map (str_type , self ._content ))
385388 a = ['%s="%s"' % i for i in self ._attrs .items ()]
386389 l = [self ._name ] + a
387- s = "<%s>%s" % (" " .join (l ), join )
390+ s = "<{}>{}" . format (" " .join (l ), join )
388391 if self ._content or not (self ._name .lower () in self .empty_elements ):
389392 s += join .join (map (str_type , self ._content ))
390393 s += join + "</%s>" % self ._name
391394 else :
392- s = "<%s />%s" % (" " .join (l ), join )
395+ s = "<{} />{}" . format (" " .join (l ), join )
393396 return s
394397
395398
@@ -409,12 +412,12 @@ def _stringify(self, str_type):
409412 return join .join (map (str_type , self ._content ))
410413 a = ['%s="%s"' % i for i in self ._attrs .items ()]
411414 l = [self ._name ] + a
412- s = "<%s>%s" % (" " .join (l ), join )
415+ s = "<{}>{}" . format (" " .join (l ), join )
413416 if self ._content :
414417 s += join .join (map (str_type , self ._content ))
415418 s += join + "</%s>" % self ._name
416419 else :
417- s = "<%s />%s" % (" " .join (l ), join )
420+ s = "<{} />{}" . format (" " .join (l ), join )
418421 return s
419422
420423
@@ -443,7 +446,8 @@ def test_iadd_tag(self):
443446 h += XML ("some-tag" , "spam" , newlines = False )
444447 h += XML ("text" , "spam" , newlines = False )
445448 self .assertEquals (
446- str (h ), "<xml>\n <some-tag>spam</some-tag>\n <text>spam</text>\n </xml>"
449+ str (h ),
450+ "<xml>\n <some-tag>spam</some-tag>\n <text>spam</text>\n </xml>" ,
447451 )
448452
449453 def test_iadd_text (self ):
@@ -523,15 +527,19 @@ def test_subtag_direct(self):
523527 l = h .ol
524528 l .li ("foo" )
525529 l .li .b ("bar" )
526- self .assertEquals (str (h ), "<ol>\n <li>foo</li>\n <li><b>bar</b></li>\n </ol>" )
530+ self .assertEquals (
531+ str (h ), "<ol>\n <li>foo</li>\n <li><b>bar</b></li>\n </ol>"
532+ )
527533
528534 def test_subtag_direct_context (self ):
529535 'generation of sub-tags directly on the parent tag in "with" context'
530536 h = HTML ()
531537 with h .ol as l :
532538 l .li ("foo" )
533539 l .li .b ("bar" )
534- self .assertEquals (str (h ), "<ol>\n <li>foo</li>\n <li><b>bar</b></li>\n </ol>" )
540+ self .assertEquals (
541+ str (h ), "<ol>\n <li>foo</li>\n <li><b>bar</b></li>\n </ol>"
542+ )
535543
536544 def test_subtag_no_newlines (self ):
537545 "prevent generation of newlines against default"
0 commit comments