Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
33848ae3
Commit
33848ae3
authored
Apr 24, 2001
by
Andreas Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
regex, ready for Medusa migration
parent
518cee1f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
10 deletions
+26
-10
ZServer/HTTPServer.py
ZServer/HTTPServer.py
+13
-5
lib/python/ZServer/HTTPServer.py
lib/python/ZServer/HTTPServer.py
+13
-5
No files found.
ZServer/HTTPServer.py
View file @
33848ae3
...
@@ -104,7 +104,7 @@ changes from Medusa's http_server
...
@@ -104,7 +104,7 @@ changes from Medusa's http_server
"""
"""
import
sys
import
sys
import
re
gex
import
re
import
string
import
string
import
os
import
os
import
types
import
types
...
@@ -131,8 +131,8 @@ from medusa import logger
...
@@ -131,8 +131,8 @@ from medusa import logger
register_subsystem
(
'ZServer HTTPServer'
)
register_subsystem
(
'ZServer HTTPServer'
)
CONTENT_LENGTH
=
regex
.
compile
(
'Content-Length:
\
([
0
-9]+
\
)
'
,regex.casefold
)
CONTENT_LENGTH
=
re
.
compile
(
'Content-Length: ([0-9]+)'
,
re
.
I
)
CONNECTION
= regex.compile ('
Connection
:
\
(.
*
\
)
', regex.casefold
)
CONNECTION
=
re
.
compile
(
'Connection: (.*)'
,
re
.
I
)
# maps request some headers to environment variables.
# maps request some headers to environment variables.
# (those that don't start with 'HTTP_')
# (those that don't start with 'HTTP_')
...
@@ -141,6 +141,14 @@ header2env={'content-length' : 'CONTENT_LENGTH',
...
@@ -141,6 +141,14 @@ header2env={'content-length' : 'CONTENT_LENGTH',
'connection'
:
'CONNECTION_TYPE'
,
'connection'
:
'CONNECTION_TYPE'
,
}
}
# stolen from Medusa
def
get_header
(
head_reg
,
lines
,
group
=
1
):
for
line
in
lines
:
if
head_reg
.
match
(
line
):
return
head_reg
.
group
(
group
)
return
''
class
zhttp_collector
:
class
zhttp_collector
:
def
__init__
(
self
,
handler
,
request
,
size
):
def
__init__
(
self
,
handler
,
request
,
size
):
self
.
handler
=
handler
self
.
handler
=
handler
...
@@ -201,11 +209,11 @@ class zhttp_handler:
...
@@ -201,11 +209,11 @@ class zhttp_handler:
uri_base
=
uri_base
[:
-
1
]
uri_base
=
uri_base
[:
-
1
]
self
.
uri_base
=
uri_base
self
.
uri_base
=
uri_base
uri_regex
=
'%s.*'
%
self
.
uri_base
uri_regex
=
'%s.*'
%
self
.
uri_base
self
.
uri_regex
=
re
gex
.
compile
(
uri_regex
)
self
.
uri_regex
=
re
.
compile
(
uri_regex
)
def
match
(
self
,
request
):
def
match
(
self
,
request
):
uri
=
request
.
uri
uri
=
request
.
uri
if
self
.
uri_regex
.
match
(
uri
)
==
len
(
uri
)
:
if
self
.
uri_regex
.
match
(
uri
):
return
1
return
1
else
:
else
:
return
0
return
0
...
...
lib/python/ZServer/HTTPServer.py
View file @
33848ae3
...
@@ -104,7 +104,7 @@ changes from Medusa's http_server
...
@@ -104,7 +104,7 @@ changes from Medusa's http_server
"""
"""
import
sys
import
sys
import
re
gex
import
re
import
string
import
string
import
os
import
os
import
types
import
types
...
@@ -131,8 +131,8 @@ from medusa import logger
...
@@ -131,8 +131,8 @@ from medusa import logger
register_subsystem
(
'ZServer HTTPServer'
)
register_subsystem
(
'ZServer HTTPServer'
)
CONTENT_LENGTH
=
regex
.
compile
(
'Content-Length:
\
([
0
-9]+
\
)
'
,regex.casefold
)
CONTENT_LENGTH
=
re
.
compile
(
'Content-Length: ([0-9]+)'
,
re
.
I
)
CONNECTION
= regex.compile ('
Connection
:
\
(.
*
\
)
', regex.casefold
)
CONNECTION
=
re
.
compile
(
'Connection: (.*)'
,
re
.
I
)
# maps request some headers to environment variables.
# maps request some headers to environment variables.
# (those that don't start with 'HTTP_')
# (those that don't start with 'HTTP_')
...
@@ -141,6 +141,14 @@ header2env={'content-length' : 'CONTENT_LENGTH',
...
@@ -141,6 +141,14 @@ header2env={'content-length' : 'CONTENT_LENGTH',
'connection'
:
'CONNECTION_TYPE'
,
'connection'
:
'CONNECTION_TYPE'
,
}
}
# stolen from Medusa
def
get_header
(
head_reg
,
lines
,
group
=
1
):
for
line
in
lines
:
if
head_reg
.
match
(
line
):
return
head_reg
.
group
(
group
)
return
''
class
zhttp_collector
:
class
zhttp_collector
:
def
__init__
(
self
,
handler
,
request
,
size
):
def
__init__
(
self
,
handler
,
request
,
size
):
self
.
handler
=
handler
self
.
handler
=
handler
...
@@ -201,11 +209,11 @@ class zhttp_handler:
...
@@ -201,11 +209,11 @@ class zhttp_handler:
uri_base
=
uri_base
[:
-
1
]
uri_base
=
uri_base
[:
-
1
]
self
.
uri_base
=
uri_base
self
.
uri_base
=
uri_base
uri_regex
=
'%s.*'
%
self
.
uri_base
uri_regex
=
'%s.*'
%
self
.
uri_base
self
.
uri_regex
=
re
gex
.
compile
(
uri_regex
)
self
.
uri_regex
=
re
.
compile
(
uri_regex
)
def
match
(
self
,
request
):
def
match
(
self
,
request
):
uri
=
request
.
uri
uri
=
request
.
uri
if
self
.
uri_regex
.
match
(
uri
)
==
len
(
uri
)
:
if
self
.
uri_regex
.
match
(
uri
):
return
1
return
1
else
:
else
:
return
0
return
0
...
...
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