author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Fri, 13 Jun 2014 12:07:51 +0200 | |
changeset 10352 | bab2befaac9b |
parent 9735 | b71158815bc8 |
child 10594 | 6a55853f14c9 |
permissions | -rw-r--r-- |
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
1 |
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
"""This package contains all WSGI specific code for cubicweb |
19 |
||
20 |
NOTE: this package borrows a lot of code to Django |
|
21 |
(http://www.djangoproject.com) and to the wsgiref module |
|
22 |
of the python2.5's stdlib. |
|
23 |
||
24 |
WSGI corresponding PEP: http://www.python.org/dev/peps/pep-0333/ |
|
25 |
||
26 |
""" |
|
27 |
__docformat__ = "restructuredtext en" |
|
28 |
||
29 |
from email import message, message_from_string |
|
30 |
from Cookie import SimpleCookie |
|
31 |
from StringIO import StringIO |
|
9735
b71158815bc8
[wsgi] avoid reading the entire request body in memory
Julien Cristau <julien.cristau@logilab.fr>
parents:
7815
diff
changeset
|
32 |
from cgi import parse_header |
0 | 33 |
from pprint import pformat as _pformat |
34 |
||
35 |
||
36 |
def pformat(obj): |
|
37 |
"""pretty prints `obj` if possible""" |
|
38 |
try: |
|
39 |
return _pformat(obj) |
|
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
40 |
except Exception: |
0 | 41 |
return u'<could not parse>' |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
42 |
|
0 | 43 |
def normalize_header(header): |
44 |
"""returns a normalized header name |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
45 |
|
0 | 46 |
>>> normalize_header('User_Agent') |
47 |
'User-agent' |
|
48 |
""" |
|
49 |
return header.replace('_', '-').capitalize() |
|
50 |
||
51 |
def safe_copyfileobj(fsrc, fdst, length=16*1024, size=0): |
|
52 |
""" |
|
53 |
THIS COMES FROM DJANGO |
|
54 |
A version of shutil.copyfileobj that will not read more than 'size' bytes. |
|
55 |
This makes it safe from clients sending more than CONTENT_LENGTH bytes of |
|
56 |
data in the body. |
|
57 |
""" |
|
58 |
if not size: |
|
59 |
return |
|
60 |
while size > 0: |
|
61 |
buf = fsrc.read(min(length, size)) |
|
62 |
if not buf: |
|
63 |
break |
|
64 |
fdst.write(buf) |
|
65 |
size -= len(buf) |