61
61
"""
62
62
63
63
from __future__ import absolute_import , division , print_function
64
+
64
65
__metaclass__ = type
65
66
66
67
import os
91
92
from .workers import threadpool
92
93
from .makefile import MakeFile , StreamWriter
93
94
94
-
95
95
__all__ = (
96
96
'HTTPRequest' , 'HTTPConnection' , 'HTTPServer' ,
97
97
'HeaderReader' , 'DropUnderscoreHeaderReader' ,
98
98
'SizeCheckWrapper' , 'KnownLengthRFile' , 'ChunkedRFile' ,
99
99
'Gateway' , 'get_ssl_adapter_class' ,
100
100
)
101
101
102
-
103
102
IS_WINDOWS = platform .system () == 'Windows'
104
103
"""Flag indicating whether the app is running under Windows."""
105
104
106
-
107
105
IS_GAE = os .getenv ('SERVER_SOFTWARE' , '' ).startswith ('Google App Engine/' )
108
106
"""Flag indicating whether the app is running in GAE env.
109
107
112
110
/using-local-server#detecting_application_runtime_environment
113
111
"""
114
112
115
-
116
113
IS_UID_GID_RESOLVABLE = not IS_WINDOWS and not IS_GAE
117
114
"""Indicates whether UID/GID resolution's available under current platform."""
118
115
119
-
120
116
if IS_UID_GID_RESOLVABLE :
121
117
try :
122
118
import grp
131
127
grp , pwd = None , None
132
128
import struct
133
129
134
-
135
130
if IS_WINDOWS and hasattr (socket , 'AF_INET6' ):
136
131
if not hasattr (socket , 'IPPROTO_IPV6' ):
137
132
socket .IPPROTO_IPV6 = 41
138
133
if not hasattr (socket , 'IPV6_V6ONLY' ):
139
134
socket .IPV6_V6ONLY = 27
140
135
141
-
142
136
if not hasattr (socket , 'SO_PEERCRED' ):
143
137
"""
144
138
NOTE: the value for SO_PEERCRED can be architecture specific, in
147
141
"""
148
142
socket .SO_PEERCRED = 21 if IS_PPC else 17
149
143
150
-
151
144
LF = b'\n '
152
145
CRLF = b'\r \n '
153
146
TAB = b'\t '
160
153
QUOTED_SLASH = b'%2F'
161
154
QUOTED_SLASH_REGEX = re .compile (b'' .join ((b'(?i)' , QUOTED_SLASH )))
162
155
163
-
164
156
comma_separated_headers = [
165
157
b'Accept' , b'Accept-Charset' , b'Accept-Encoding' ,
166
158
b'Accept-Language' , b'Accept-Ranges' , b'Allow' , b'Cache-Control' ,
170
162
b'WWW-Authenticate' ,
171
163
]
172
164
173
-
174
165
if not hasattr (logging , 'statistics' ):
175
166
logging .statistics = {}
176
167
@@ -533,7 +524,7 @@ def _fetch(self):
533
524
raise ValueError (
534
525
'Bad chunked transfer size: {chunk_size!r}' .
535
526
format (chunk_size = chunk_size ),
536
- )
527
+ )
537
528
538
529
if chunk_size <= 0 :
539
530
self ._read_trailers ()
@@ -555,7 +546,7 @@ def _fetch(self):
555
546
raise ValueError (
556
547
"Bad chunked transfer coding (expected '\\ r\\ n', "
557
548
'got ' + repr (crlf ) + ')' ,
558
- )
549
+ )
559
550
560
551
def read (self , size = None ):
561
552
"""Read a chunk from ``rfile`` buffer and return it.
@@ -793,7 +784,7 @@ def parse_request(self):
793
784
self .inheaders [header [0 ]] = header [1 ]
794
785
795
786
if (b'transfer-encoding' in self .inheaders and
796
- self .inheaders [b'transfer-encoding' ].lower () == b"chunked" ):
787
+ self .inheaders [b'transfer-encoding' ].lower () == b"chunked" ):
797
788
self .chunked_read = True
798
789
799
790
uri_is_absolute_form = scheme or authority
@@ -1020,7 +1011,6 @@ def send_headers(self):
1020
1011
self .conn .wfile .write (res_bytes )
1021
1012
1022
1013
1023
-
1024
1014
class HTTPConnection :
1025
1015
"""An HTTP connection (active socket)."""
1026
1016
@@ -1101,7 +1091,7 @@ def communicate(self):
1101
1091
self .server .error_log (
1102
1092
'socket.error %s' % repr (errnum ),
1103
1093
level = logging .WARNING , traceback = True ,
1104
- )
1094
+ )
1105
1095
self ._conditional_error (req , '500 Internal Server Error' )
1106
1096
except (KeyboardInterrupt , SystemExit ):
1107
1097
raise
0 commit comments