/usr/lib/python2.7/dist-packages/pygame_sdl2/compat.py is in python-pygame-sdl2 6.99.14.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | """Python 2.x/3.x compatibility tools"""
import sys
__all__ = ['geterror', 'long_', 'xrange_', 'ord_', 'unichr_',
'unicode_', 'raw_input_', 'as_bytes', 'as_unicode',
'file_type'
]
if sys.version_info[0] >= 3:
import io
file_type = io.FileIO
else:
file_type = file
def geterror ():
return sys.exc_info()[1]
try:
long_ = long
except NameError:
long_ = int
try:
xrange_ = xrange
except NameError:
xrange_ = range
def get_BytesIO():
try:
from cStringIO import StringIO as BytesIO
except ImportError:
from io import BytesIO
return BytesIO
def get_StringIO():
try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
return StringIO
def ord_(o):
try:
return ord(o)
except TypeError:
return o
try:
unichr_ = unichr
except NameError:
unichr_ = chr
try:
unicode_ = unicode
except NameError:
unicode_ = str
try:
bytes_ = bytes
except NameError:
bytes_ = str
try:
raw_input_ = raw_input
except NameError:
raw_input_ = input
if sys.platform == 'win32':
filesystem_errors = "replace"
elif sys.version_info >= (3, 0, 0):
filesystem_errors = "surrogateescape"
else:
filesystem_errors = "strict"
def filesystem_encode(u):
return u.encode(sys.getfilesystemencoding(), filesystem_errors)
# Represent escaped bytes and strings in a portable way.
#
# as_bytes: Allow a Python 3.x string to represent a bytes object.
# e.g.: as_bytes("a\x01\b") == b"a\x01b" # Python 3.x
# as_bytes("a\x01\b") == "a\x01b" # Python 2.x
# as_unicode: Allow a Python "r" string to represent a unicode string.
# e.g.: as_unicode(r"Bo\u00F6tes") == u"Bo\u00F6tes" # Python 2.x
# as_unicode(r"Bo\u00F6tes") == "Bo\u00F6tes" # Python 3.x
try:
unicode
def as_bytes(string):
""" '<binary literal>' => '<binary literal>' """
return string
def as_unicode(rstring):
""" r'<Unicode literal>' => u'<Unicode literal>' """
return rstring.decode('unicode_escape', 'strict')
except NameError:
def as_bytes(string):
""" '<binary literal>' => b'<binary literal>' """
return string.encode('latin-1', 'strict')
def as_unicode(rstring):
""" r'<Unicode literal>' => '<Unicode literal>' """
return rstring.encode('ascii', 'strict').decode('unicode_escape',
'stict')
# Include a next compatible function for Python versions < 2.6
try:
next_ = next
except NameError:
def next_(i, *args):
try:
return i.next()
except StopIteration:
if args:
return args[0]
raise
# itertools.imap is missing in 3.x
try:
import itertools.imap as imap_
except ImportError:
imap_ = map
|