Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
52cec359
Commit
52cec359
authored
Feb 26, 2014
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python: Fix NameError if asyncio is not available
parent
13cc3f2f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
237 additions
and
231 deletions
+237
-231
python/nghttp2.pyx
python/nghttp2.pyx
+237
-231
No files found.
python/nghttp2.pyx
View file @
52cec359
...
...
@@ -250,7 +250,7 @@ try:
import
datetime
import
time
except
ImportError
:
pass
asyncio
=
None
cdef
_get_stream_user_data
(
cnghttp2
.
nghttp2_session
*
session
,
int32_t
stream_id
):
...
...
@@ -659,7 +659,9 @@ cdef class _HTTP2SessionCore:
datestr
,
method
,
path
,
handler
.
status
,
'P'
if
handler
.
pushed
else
'-'
))
class
BaseRequestHandler
:
if
asyncio
:
class
BaseRequestHandler
:
"""HTTP/2 request (stream) handler base class.
...
...
@@ -737,8 +739,8 @@ class BaseRequestHandler:
def
on_data
(
self
,
data
):
'''Called when a chunk of request body is arrived. This method will be
called multiple times until all data are received.
'''Called when a chunk of request body is arrived. This method
will be
called multiple times until all data are received.
'''
pass
...
...
@@ -786,12 +788,14 @@ class BaseRequestHandler:
def
push
(
self
,
path
,
method
=
'GET'
,
request_headers
=
None
,
status
=
200
,
headers
=
None
,
body
=
None
):
'''Push a resource. The path is a path portion of request URI for this
resource. The method is a method to access this resource. The
request_headers is additional request headers to access this
resource. The :scheme, :method, :authority and :path are
appended by the library. The :scheme and :authority are
inherited from the request (not request_headers parameter).
'''Push a resource. The path is a path portion of request URI
for this
resource. The method is a method to access this
resource. The request_headers is additional request
headers to access this resource. The :scheme, :method,
:authority and :path are appended by the library. The
:scheme and :authority are inherited from the request (not
request_headers parameter).
The status is HTTP status code. The headers is additional
response headers. The :status header field is appended by the
...
...
@@ -845,7 +849,8 @@ class BaseRequestHandler:
headers
=
[]
self
.
response_headers
=
_encode_headers
(
headers
)
self
.
response_headers
.
append
((
b':status'
,
str
(
status
).
encode
(
'utf-8'
)))
self
.
response_headers
.
append
((
b':status'
,
str
(
status
)
\
.
encode
(
'utf-8'
)))
self
.
response_body
=
body
...
...
@@ -859,15 +864,15 @@ class BaseRequestHandler:
elif
isinstance
(
body
,
io
.
IOBase
):
return
body
else
:
raise
Exception
((
'body must be None or instance of str or bytes
'
'
or io.IOBase'
))
raise
Exception
((
'body must be None or instance of str or
'
'bytes
or io.IOBase'
))
def
_encode_headers
(
headers
):
def
_encode_headers
(
headers
):
return
[(
k
if
isinstance
(
k
,
bytes
)
else
k
.
encode
(
'utf-8'
),
v
if
isinstance
(
v
,
bytes
)
else
v
.
encode
(
'utf-8'
))
\
for
k
,
v
in
headers
]
class
_HTTP2Session
(
asyncio
.
Protocol
):
class
_HTTP2Session
(
asyncio
.
Protocol
):
def
__init__
(
self
,
RequestHandlerClass
):
asyncio
.
Protocol
.
__init__
(
self
)
...
...
@@ -897,7 +902,8 @@ class _HTTP2Session(asyncio.Protocol):
self
.
connection_header
=
self
.
connection_header
[
nread
:]
if
len
(
self
.
connection_header
)
==
0
:
try
:
self
.
http2
=
_HTTP2SessionCore
(
self
.
transport
,
self
.
http2
=
_HTTP2SessionCore
\
(
self
.
transport
,
self
.
RequestHandlerClass
)
except
Exception
as
err
:
sys
.
stderr
.
write
(
traceback
.
format_exc
())
...
...
@@ -926,7 +932,7 @@ class _HTTP2Session(asyncio.Protocol):
self
.
transport
.
close
()
return
class
HTTP2Server
:
class
HTTP2Server
:
'''HTTP/2 server.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment