mirror of
https://github.com/samba-team/samba.git
synced 2025-02-26 21:57:41 +03:00
python: samba.compat rejects Python 2
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: David Mulder <dmulder@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Fri Jul 17 08:39:38 UTC 2020 on sn-devel-184
This commit is contained in:
parent
914226bf52
commit
d05fc858bf
@ -83,76 +83,7 @@ if PY3:
|
||||
def ConfigParser(defaults=None, dict_type=dict, allow_no_value=False):
|
||||
from configparser import ConfigParser
|
||||
return ConfigParser(defaults, dict_type, allow_no_value, interpolation=None)
|
||||
|
||||
|
||||
else:
|
||||
# Helper function to return bytes.
|
||||
# if 'unicode' is passed in then it is decoded using 'utf8' and
|
||||
# the result returned. If 'str' is passed then it is returned unchanged.
|
||||
# Using this function is PY2/PY3 code should ensure in most cases
|
||||
# the PY2 code runs unchanged in PY2 whereas the code in PY3 possibly
|
||||
# encodes the variable (see PY3 implementation of this function above)
|
||||
def get_bytes(bytesorstring):
|
||||
tmp = bytesorstring
|
||||
if isinstance(bytesorstring, unicode):
|
||||
tmp = bytesorstring.encode('utf8')
|
||||
elif not isinstance(bytesorstring, str):
|
||||
raise ValueError('Expected string for %s:%s' % (type(bytesorstring), bytesorstring))
|
||||
return tmp
|
||||
|
||||
# Helper function to return string.
|
||||
# if 'str' or 'unicode' passed in they are returned unchanged
|
||||
# otherwise an exception is generated
|
||||
# Using this function is PY2/PY3 code should ensure in most cases
|
||||
# the PY2 code runs unchanged in PY2 whereas the code in PY3 possibly
|
||||
# decodes the variable (see PY3 implementation of this function above)
|
||||
def get_string(bytesorstring):
|
||||
tmp = bytesorstring
|
||||
if not(isinstance(bytesorstring, str) or isinstance(bytesorstring, unicode)):
|
||||
raise ValueError('Expected str or unicode for %s:%s' % (type(bytesorstring), bytesorstring))
|
||||
return tmp
|
||||
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
def cmp_to_key_fn(mycmp):
|
||||
|
||||
"""Convert a cmp= function into a key= function"""
|
||||
class K(object):
|
||||
__slots__ = ['obj']
|
||||
|
||||
def __init__(self, obj, *args):
|
||||
self.obj = obj
|
||||
|
||||
def __lt__(self, other):
|
||||
return mycmp(self.obj, other.obj) < 0
|
||||
|
||||
def __gt__(self, other):
|
||||
return mycmp(self.obj, other.obj) > 0
|
||||
|
||||
def __eq__(self, other):
|
||||
return mycmp(self.obj, other.obj) == 0
|
||||
|
||||
def __le__(self, other):
|
||||
return mycmp(self.obj, other.obj) <= 0
|
||||
|
||||
def __ge__(self, other):
|
||||
return mycmp(self.obj, other.obj) >= 0
|
||||
|
||||
def __ne__(self, other):
|
||||
return mycmp(self.obj, other.obj) != 0
|
||||
|
||||
def __hash__(self):
|
||||
raise TypeError('hash not implemented')
|
||||
return K
|
||||
else:
|
||||
from functools import cmp_to_key as cmp_to_key_fn
|
||||
|
||||
# compat types
|
||||
integer_types = (int, long)
|
||||
string_types = basestring
|
||||
text_type = unicode
|
||||
binary_type = str
|
||||
|
||||
# alias
|
||||
import cStringIO
|
||||
StringIO = cStringIO.StringIO
|
||||
from ConfigParser import ConfigParser
|
||||
cmp_fn = cmp
|
||||
raise NotImplementedError("Samba versions >= 4.11 do not support Python 2.x")
|
||||
|
Loading…
x
Reference in New Issue
Block a user