author | Julien Cristau <julien.cristau@logilab.fr> |
Fri, 16 Oct 2015 17:06:28 +0200 | |
changeset 10807 | bb0c7dbd1fe7 |
parent 10605 | 61521bee2b68 |
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 pprint import pformat as _pformat |
|
31 |
||
10605
61521bee2b68
[py3k] import SimpleCookie using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10594
diff
changeset
|
32 |
from six.moves.http_cookies import SimpleCookie |
0 | 33 |
|
34 |
def pformat(obj): |
|
35 |
"""pretty prints `obj` if possible""" |
|
36 |
try: |
|
37 |
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
|
38 |
except Exception: |
0 | 39 |
return u'<could not parse>' |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
40 |
|
0 | 41 |
def normalize_header(header): |
42 |
"""returns a normalized header name |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
43 |
|
0 | 44 |
>>> normalize_header('User_Agent') |
45 |
'User-agent' |
|
46 |
""" |
|
47 |
return header.replace('_', '-').capitalize() |
|
48 |
||
49 |
def safe_copyfileobj(fsrc, fdst, length=16*1024, size=0): |
|
50 |
""" |
|
51 |
THIS COMES FROM DJANGO |
|
52 |
A version of shutil.copyfileobj that will not read more than 'size' bytes. |
|
53 |
This makes it safe from clients sending more than CONTENT_LENGTH bytes of |
|
54 |
data in the body. |
|
55 |
""" |
|
56 |
if not size: |
|
57 |
return |
|
58 |
while size > 0: |
|
59 |
buf = fsrc.read(min(length, size)) |
|
60 |
if not buf: |
|
61 |
break |
|
62 |
fdst.write(buf) |
|
63 |
size -= len(buf) |