py3k port helpers
This commit is contained in:
1 parent
08e2a3a883
commit
29a34fef8c
28 files changed
+58
-44
No files matched your search
@@ -5,6 +5,7 @@ import os
|
||||
import re
|
||||
import traceback
|
||||
import unicodedata
|
||||
import six
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
@@ -29,7 +30,7 @@ def toUnicode(original, *args):
|
||||
return original
|
||||
else:
|
||||
try:
|
||||
return unicode(original, *args)
|
||||
return six.text_type(original, *args)
|
||||
except:
|
||||
try:
|
||||
return ek(original, *args)
|
||||
@@ -102,10 +103,10 @@ def stripAccents(s):
|
||||
|
||||
|
||||
def tryUrlencode(s):
|
||||
new = u''
|
||||
new = six.u('')
|
||||
if isinstance(s, dict):
|
||||
for key, value in s.iteritems():
|
||||
new += u'&%s=%s' % (key, tryUrlencode(value))
|
||||
for key, value in s.items():
|
||||
new += six.u('&%s=%s') % (key, tryUrlencode(value))
|
||||
|
||||
return new[1:]
|
||||
else:
|
||||
|
||||
@@ -9,7 +9,7 @@ def getParams(params):
|
||||
reg = re.compile('^[a-z0-9_\.]+$')
|
||||
|
||||
temp = {}
|
||||
for param, value in sorted(params.iteritems()):
|
||||
for param, value in sorted(params.items()):
|
||||
|
||||
nest = re.split("([\[\]]+)", param)
|
||||
if len(nest) > 1:
|
||||
@@ -42,9 +42,9 @@ def dictToList(params):
|
||||
|
||||
if type(params) is dict:
|
||||
new = {}
|
||||
for x, value in params.iteritems():
|
||||
for x, value in params.items():
|
||||
try:
|
||||
new_value = [dictToList(value[k]) for k in sorted(value.iterkeys(), cmp = natcmp)]
|
||||
new_value = [dictToList(value[k]) for k in sorted(value.keys(), cmp = natcmp)]
|
||||
except:
|
||||
new_value = value
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import random
|
||||
import re
|
||||
import string
|
||||
import sys
|
||||
import six
|
||||
from six.moves import map, zip
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
@@ -19,7 +21,7 @@ def fnEscape(pattern):
|
||||
def link(src, dst):
|
||||
if os.name == 'nt':
|
||||
import ctypes
|
||||
if ctypes.windll.kernel32.CreateHardLinkW(unicode(dst), unicode(src), 0) == 0: raise ctypes.WinError()
|
||||
if ctypes.windll.kernel32.CreateHardLinkW(six.text_type(dst), six.text_type(src), 0) == 0: raise ctypes.WinError()
|
||||
else:
|
||||
os.link(src, dst)
|
||||
|
||||
@@ -27,7 +29,7 @@ def link(src, dst):
|
||||
def symlink(src, dst):
|
||||
if os.name == 'nt':
|
||||
import ctypes
|
||||
if ctypes.windll.kernel32.CreateSymbolicLinkW(unicode(dst), unicode(src), 1 if os.path.isdir(src) else 0) in [0, 1280]: raise ctypes.WinError()
|
||||
if ctypes.windll.kernel32.CreateSymbolicLinkW(six.text_type(dst), six.text_type(src), 1 if os.path.isdir(src) else 0) in [0, 1280]: raise ctypes.WinError()
|
||||
else:
|
||||
os.symlink(src, dst)
|
||||
|
||||
@@ -253,7 +255,7 @@ def randomString(size = 8, chars = string.ascii_uppercase + string.digits):
|
||||
|
||||
def splitString(str, split_on = ',', clean = True):
|
||||
l = [x.strip() for x in str.split(split_on)] if str else []
|
||||
return filter(None, l) if clean else l
|
||||
return [x for x in l if x] if clean else l
|
||||
|
||||
|
||||
def dictIsSubset(a, b):
|
||||
|
||||
Reference in new issue
Block a user