Edgewall Software

Changeset 1156


Ignore:
Timestamp:
Mar 18, 2011, 10:05:58 AM (13 years ago)
Author:
hodgestar
Message:

Merge r1139 from py3k: add compatibility functions for dealing with python 3; factor existing compatibility functions out from genshi utils.

Location:
trunk
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/genshi/util.py

    r1082 r1156  
    1616import htmlentitydefs as entities
    1717import re
     18
     19from compat import any, all, stringrepr
    1820
    1921__docformat__ = 'restructuredtext en'
     
    247249    return _STRIPTAGS_RE.sub('', text)
    248250
    249 
    250 def stringrepr(string):
    251     ascii = string.encode('ascii', 'backslashreplace')
    252     quoted = "'" +  ascii.replace("'", "\\'") + "'"
    253     if len(ascii) > len(string):
    254         return 'u' + quoted
    255     return quoted
    256 
    257 
    258 # Compatibility fallback implementations for older Python versions
    259 
    260 try:
    261     all = all
    262     any = any
    263 except NameError:
    264     def any(S):
    265         for x in S:
    266             if x:
    267                return True
    268         return False
    269 
    270     def all(S):
    271         for x in S:
    272             if not x:
    273                return False
    274         return True
Note: See TracChangeset for help on using the changeset viewer.