~ubuntu-branches/ubuntu/trusty/python-urllib3/trusty-proposed

« back to all changes in this revision

Viewing changes to dummyserver/handlers.py

  • Committer: Package Import Robot
  • Author(s): Daniele Tricoli
  • Date: 2013-10-17 13:28:10 UTC
  • mfrom: (4.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20131017132810-dt44kuqupqqulnwc
Tags: 1.7.1-1
* New upstream release
* Switched to pybuild
* debian/clean
  - Switched to debian/clean for cleaning instead of using debian/rules
* debian/compat
  - Bumped debhelper compatibility level to 9
* debian/control
  - Added python-mock to Build-Depends
  - Bumped debhelper B-D to (>= 9)
* debian/copyright
  - Removed stanza about mimetools_choose_boundary since not shipped
    anymore
* debian/patches/01_do-not-use-embedded-python-six.patch
  - Refreshed
* debian/patches/02_require-cert-verification.patch
  - Refreshed
* debian/patches/04_relax_nosetests_options.patch
  - Refreshed
* debian/patches/05_fix_python3_syntax_error_in_ntlmpool.patch
  - Removed since fixed upstream
* debian/patches/06_fix_abuse_of_match_hostname_for_DoS.patch
  - Removed since fixed upstream
* debian/watch
  - Switched download URL to https

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
 
88
88
        if request.method != method:
89
89
            return Response("Wrong method: %s != %s" %
90
 
                            (method, request.method), status='400')
 
90
                            (method, request.method), status='400 Bad Request')
91
91
        return Response()
92
92
 
93
93
    def upload(self, request):
100
100
 
101
101
        if len(files_) != 1:
102
102
            return Response("Expected 1 file for '%s', not %d" %(param, len(files_)),
103
 
                                                    status='400')
 
103
                                                    status='400 Bad Request')
104
104
        file_ = files_[0]
105
105
 
106
106
        data = file_['body']
107
107
        if int(size) != len(data):
108
108
            return Response("Wrong size: %d != %d" %
109
 
                            (size, len(data)), status='400')
 
109
                            (size, len(data)), status='400 Bad Request')
110
110
 
111
111
        if filename != file_['filename']:
112
112
            return Response("Wrong filename: %s != %s" %
113
 
                            (filename, file_.filename), status='400')
 
113
                            (filename, file_.filename),
 
114
                            status='400 Bad Request')
114
115
 
115
116
        return Response()
116
117
 
118
119
        "Perform a redirect to ``target``"
119
120
        target = request.params.get('target', '/')
120
121
        headers = [('Location', target)]
121
 
        return Response(status='303', headers=headers)
 
122
        return Response(status='303 See Other', headers=headers)
122
123
 
123
124
    def keepalive(self, request):
124
125
        if request.params.get('close', b'0') == b'1':
169
170
 
170
171
    def shutdown(self, request):
171
172
        sys.exit()
 
173
 
 
174
 
 
175
# RFC2231-aware replacement of internal tornado function
 
176
def _parse_header(line):
 
177
    r"""Parse a Content-type like header.
 
178
 
 
179
    Return the main content-type and a dictionary of options.
 
180
 
 
181
    >>> d = _parse_header("CD: fd; foo=\"bar\"; file*=utf-8''T%C3%A4st")[1]
 
182
    >>> d['file'] == 'T\u00e4st'
 
183
    True
 
184
    >>> d['foo']
 
185
    'bar'
 
186
    """
 
187
    import tornado.httputil
 
188
    import email.utils
 
189
    import six
 
190
    if not six.PY3:
 
191
        line = line.encode('utf-8')
 
192
    parts = tornado.httputil._parseparam(';' + line)
 
193
    key = next(parts)
 
194
    # decode_params treats first argument special, but we already stripped key
 
195
    params = [('Dummy', 'value')]
 
196
    for p in parts:
 
197
        i = p.find('=')
 
198
        if i >= 0:
 
199
            name = p[:i].strip().lower()
 
200
            value = p[i + 1:].strip()
 
201
            params.append((name, value))
 
202
    params = email.utils.decode_params(params)
 
203
    params.pop(0) # get rid of the dummy again
 
204
    pdict = {}
 
205
    for name, value in params:
 
206
        print(repr(value))
 
207
        value = email.utils.collapse_rfc2231_value(value)
 
208
        if len(value) >= 2 and value[0] == '"' and value[-1] == '"':
 
209
            value = value[1:-1]
 
210
        pdict[name] = value
 
211
    return key, pdict
 
212
 
 
213
# TODO: make the following conditional as soon as we know a version
 
214
#       which does not require this fix.
 
215
#       See https://github.com/facebook/tornado/issues/868
 
216
if True:
 
217
    import tornado.httputil
 
218
    tornado.httputil._parse_header = _parse_header