/usr/share/pyshared/webtest/compat.py is in python-webtest 1.3.3-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 | # -*- coding: utf-8 -*-
import sys
if sys.version_info[0] > 2:
PY3 = True
string_types = (str,)
text_type = str
binary_type = bytes
from json import loads
from json import dumps
from io import StringIO
from io import BytesIO
from urllib.parse import urlencode
from urllib.parse import splittype
from urllib.parse import splithost
import urllib.parse as urlparse
from http.client import HTTPConnection
from http.client import CannotSendRequest
from http.server import HTTPServer
from http.server import SimpleHTTPRequestHandler
from http.cookies import SimpleCookie, CookieError
from http.cookies import _quote as cookie_quote
def to_bytes(s):
if isinstance(s, bytes):
return s
return s.encode('latin1')
def to_string(s):
if isinstance(s, str):
return s
return str(s, 'latin1')
def join_bytes(sep, l):
l = [to_bytes(e) for e in l]
return to_bytes(sep).join(l)
else:
PY3 = False
string_types = basestring
text_type = unicode
binary_type = str
from urllib import splittype
from urllib import splithost
from urllib import urlencode
from httplib import HTTPConnection
from httplib import CannotSendRequest
from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
from Cookie import SimpleCookie, CookieError
from Cookie import _quote as cookie_quote
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
BytesIO = StringIO
import urlparse
try:
from json import loads
from json import dumps
except ImportError:
try:
from simplejson import loads
from simplejson import dumps
except ImportError:
loads = None
dumps = None
def to_bytes(s):
return str(s)
def to_string(s):
return str(s)
def join_bytes(sep, l):
l = [e for e in l]
return sep.join(l)
def print_stderr(value):
if PY3:
exec('print(value, file=sys.stderr)')
else:
if isinstance(value, text_type):
# not really clean but this must *never* fail
try:
value = value.encode('utf-8')
except:
value = repr(value)
sys.stderr.write(value)
|