Edgewall Software

Changeset 1139


Ignore:
Timestamp:
Oct 24, 2010, 11:38:19 PM (13 years ago)
Author:
hodgestar
Message:

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

Location:
branches/experimental/py3k/genshi
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • branches/experimental/py3k/genshi/util.py

    r1082 r1139  
    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.