Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
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
Yoji Takeuchi
erp5
Commits
489f9d57
Commit
489f9d57
authored
May 02, 2019
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
187b19df
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
0 deletions
+71
-0
erp5/util/zopewsgi/__init__.py
erp5/util/zopewsgi/__init__.py
+71
-0
No files found.
erp5/util/zopewsgi/__init__.py
0 → 100644
View file @
489f9d57
import
os
import
sys
import
argparse
from
gevent
import
pywsgi
,
threadpool
from
tempfile
import
TemporaryFile
from
io
import
BytesIO
import
socket
import
Zope2
from
Zope2.Startup.run
import
make_wsgi_app
import
ZConfig
from
Products.ERP5Type.patches.WSGIPublisher
import
publish_module
def
app_wrapper
(
large_file_threshold
):
def
app
(
environ
,
start_response
):
original_wsgi_input
=
environ
[
'wsgi.input'
]
if
not
hasattr
(
original_wsgi_input
,
'seek'
):
# Convert environ['wsgi.input'] to a file-like object.
cl
=
environ
.
get
(
'CONTENT_LENGTH'
)
cl
=
int
(
cl
)
if
cl
else
0
if
cl
>
large_file_threshold
:
new_wsgi_input
=
environ
[
'wsgi.input'
]
=
TemporaryFile
(
'w+b'
)
else
:
new_wsgi_input
=
environ
[
'wsgi.input'
]
=
BytesIO
()
rest
=
cl
chunksize
=
1
<<
20
try
:
while
rest
:
if
rest
<=
chunksize
:
chunk
=
original_wsgi_input
.
read
(
rest
)
rest
=
0
else
:
chunk
=
original_wsgi_input
.
read
(
chunksize
)
rest
=
rest
-
chunksize
new_wsgi_input
.
write
(
chunk
)
except
(
socket
.
error
,
IOError
):
msg
=
b'Not enough data in request or socket error'
start_response
(
'400 Bad Request'
,
[
(
'Content-Type'
,
'text/plain'
),
(
'Content-Length'
,
str
(
len
(
msg
))),
]
)
return
[
msg
]
new_wsgi_input
.
seek
(
0
)
return
publish_module
(
environ
,
start_response
)
return
app
def
runwsgi
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'-w'
,
'--webdav'
,
action
=
'store_true'
)
parser
.
add_argument
(
'address'
,
help
=
'<ip>:<port>'
)
parser
.
add_argument
(
'zope_conf'
,
help
=
'path to zope.conf'
)
args
=
parser
.
parse_args
()
# We read some "old" values used by the Medusa HTTP Server in order to reuse
# them for the WSGI mode.
startup
=
os
.
path
.
dirname
(
Zope2
.
Startup
.
__file__
)
schema
=
ZConfig
.
loadSchema
(
os
.
path
.
join
(
startup
,
'zopeschema.xml'
))
conf
,
_
=
ZConfig
.
loadConfig
(
schema
,
args
.
zope_conf
)
make_wsgi_app
({},
zope_conf
=
args
.
zope_conf
)
pywsgi
.
WSGIServer
(
listener
=
args
.
address
,
application
=
app_wrapper
(
conf
.
large_file_threshold
),
spawn
=
threadpool
.
ThreadPool
(
conf
.
zserver_threads
),
log
=
conf
.
access
(),
# Z2.log
).
serve_forever
()
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