comparison genshi/core.py @ 907:bb813ef5fe25 experimental-inline

inline branch: merged r1129 from trunk.
author cmlenz
date Wed, 28 Apr 2010 21:36:59 +0000
parents 09cc3627654c
children
comparison
equal deleted inserted replaced
906:be8d2d828be6 907:bb813ef5fe25
377 """ 377 """
378 return Attrs(tuple.__getslice__(self, i, j)) 378 return Attrs(tuple.__getslice__(self, i, j))
379 379
380 def __or__(self, attrs): 380 def __or__(self, attrs):
381 """Return a new instance that contains the attributes in `attrs` in 381 """Return a new instance that contains the attributes in `attrs` in
382 addition to any already existing attributes. 382 addition to any already existing attributes. Any attributes in the new
383 set that have a value of `None` are removed.
383 384
384 :return: a new instance with the merged attributes 385 :return: a new instance with the merged attributes
385 :rtype: `Attrs` 386 :rtype: `Attrs`
386 """ 387 """
387 repl = dict([(an, av) for an, av in attrs if an in self]) 388 remove = set([an for an, av in attrs if av is None])
388 return Attrs([(sn, repl.get(sn, sv)) for sn, sv in self] + 389 replace = dict([(an, av) for an, av in attrs
389 [(an, av) for an, av in attrs if an not in self]) 390 if an in self and av is not None])
391 return Attrs([(sn, replace.get(sn, sv)) for sn, sv in self
392 if sn not in remove] +
393 [(an, av) for an, av in attrs
394 if an not in self and an not in remove])
390 395
391 def __repr__(self): 396 def __repr__(self):
392 if not self: 397 if not self:
393 return 'Attrs()' 398 return 'Attrs()'
394 return 'Attrs([%s])' % ', '.join([repr(item) for item in self]) 399 return 'Attrs([%s])' % ', '.join([repr(item) for item in self])
505 if not text: 510 if not text:
506 return cls() 511 return cls()
507 if type(text) is cls: 512 if type(text) is cls:
508 return text 513 return text
509 if hasattr(text, '__html__'): 514 if hasattr(text, '__html__'):
510 return Markup(text.__html__()) 515 return cls(text.__html__())
511 516
512 text = text.replace('&', '&') \ 517 text = text.replace('&', '&') \
513 .replace('<', '&lt;') \ 518 .replace('<', '&lt;') \
514 .replace('>', '&gt;') 519 .replace('>', '&gt;')
515 if quotes: 520 if quotes:
Copyright (C) 2012-2017 Edgewall Software