Tres Seaver
2012-03-18 53987b9276f10ae080383c9001fe4c20408c741c
commit | author | age
9df42f 1 try:
TS 2     STRING_TYPES = (str, unicode)
3 except NameError:
4     STRING_TYPES = (str,)
5
fdc787 6 try:
TS 7     u = unicode
8 except NameError: #pragma NO COVER Python >= 3.0
9     u = str
10
a90306 11 try:
TS 12     from base64 import decodebytes
13     from base64 import encodebytes
14 except: # Python < 3.0
15     from base64 import decodestring as decodebytes
16     from base64 import encodestring as encodebytes
17
adef05 18 try:
TS 19     from ConfigParser import ConfigParser
20     from ConfigParser import ParsingError
21 except ImportError: #pragma NO COVER Python >= 3.0
22     from configparser import ConfigParser
23     from configparser import ParsingError
24
25 try:
26     from Cookie import SimpleCookie
27     from Cookie import CookieError
28 except ImportError: #pragma NO COVER Python >= 3.0
29     from http.cookies import SimpleCookie
30     from http.cookies import CookieError
31
32 try:
33     from itertools import izip_longest
34 except ImportError: #pragma NO COVER Python >= 3.0
35     from itertools import zip_longest as izip_longest
36
37 try:
38     from StringIO import StringIO
39 except ImportError: #pragma NO COVER Python >= 3.0
40     from io import StringIO
41
42 try:
53987b 43     from urllib import urlencode
adef05 44     from urllib import quote as url_quote
TS 45     from urllib import unquote as url_unquote
46 except ImportError: #pragma NO COVER Python >= 3.0
53987b 47     from urllib.parse import urlencode
adef05 48     from urllib.parse import quote as url_quote
TS 49     from urllib.parse import unquote as url_unquote
50
53987b 51 try:
TS 52     from urlparse import urlparse
53     from urlparse import urlunparse
54 except ImportError: #pragma NO COVER Python >= 3.0
55     from urllib.parse import urlparse
56     from urllib.parse import urlunparse
57
adef05 58 import wsgiref.util
TS 59 import wsgiref.headers
60
02a504 61 def REQUEST_METHOD(environ):
AO 62     return environ['REQUEST_METHOD']
63
64 def CONTENT_TYPE(environ):
65     return environ['CONTENT_TYPE']
66
67 def USER_AGENT(environ):
68     return environ.get('HTTP_USER_AGENT')
69
70 def AUTHORIZATION(environ):
71     return environ.get('HTTP_AUTHORIZATION', '')
72
73 def get_cookies(environ):
74     header = environ.get('HTTP_COOKIE', '')
d853a7 75     if 'paste-cookies' in environ:
02a504 76         cookies, check_header = environ['paste.cookies']
AO 77         if check_header == header:
78             return cookies
79     cookies = SimpleCookie()
80     try:
81         cookies.load(header)
82     except CookieError:
83         pass
84     environ['paste.cookies'] = (cookies, header)
85     return cookies
86
87 def construct_url(environ):
88     return wsgiref.util.request_uri(environ)
89
90 def header_value(environ, key):
91     headers = wsgiref.headers.Headers(environ)
92     values = headers.get(key)
93     if not values:
94         return ""
95     if isinstance(values, list):
96         return ",".join(values)
97     else:
98         return values