Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
corepost
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
nexlab
corepost
Commits
1e4b1c51
Commit
1e4b1c51
authored
Mar 05, 2012
by
Jacek Furmankiewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
0.0.13: perf fix to avoid string concatenation in URL routing
parent
64af036f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
9 deletions
+12
-9
routing.py
corepost/routing.py
+9
-7
setup.py
setup.py
+3
-2
No files found.
corepost/routing.py
View file @
1e4b1c51
...
...
@@ -26,7 +26,7 @@ class UrlRouter:
''' Common class for containing info related to routing a request to a function '''
__urlMatcher
=
re
.
compile
(
r"<(int|float|):?([a-zA-Z0-9]+)>"
)
__urlRegexReplace
=
{
""
:
r"(?P<arg>
.+
)"
,
"int"
:
r"(?P<arg>\d+)"
,
"float"
:
r"(?P<arg>\d+.?\d*)"
}
__urlRegexReplace
=
{
""
:
r"(?P<arg>
([a-zA-Z0-9]+)
)"
,
"int"
:
r"(?P<arg>\d+)"
,
"float"
:
r"(?P<arg>\d+.?\d*)"
}
__typeConverters
=
{
"int"
:
int
,
"float"
:
float
}
def
__init__
(
self
,
f
,
url
,
methods
,
accepts
,
produces
,
cache
):
...
...
@@ -187,9 +187,10 @@ class RequestRouter:
# if specified, add class path to each function's path
rq
=
func
.
corepostRequestRouter
rq
.
url
=
"
%
s
%
s"
%
(
rootPath
,
rq
.
url
)
# remove trailing '/' to standardize URLs
if
rq
.
url
!=
"/"
and
rq
.
url
[
-
1
]
==
"/"
:
rq
.
url
=
rq
.
url
[:
-
1
]
# remove first and trailing '/' to standardize URLs
start
=
1
if
rq
.
url
[
0
:
1
]
==
"/"
else
0
end
=
-
1
if
rq
.
url
[
len
(
rq
.
url
)
-
1
]
==
'/'
else
len
(
rq
.
url
)
rq
.
url
=
rq
.
url
[
start
:
end
]
# now that the full URL is set, compile the matcher for it
rq
.
compileMatcherForFullUrl
()
...
...
@@ -200,6 +201,7 @@ class RequestRouter:
self
.
__urls
[
method
][
rq
.
url
][
accepts
]
=
urlRouterInstance
self
.
__urlRouterInstances
[
func
]
=
urlRouterInstance
# needed so that we can lookup the urlRouterInstance for a specific function
def
getResponse
(
self
,
request
):
"""Finds the appropriate instance and dispatches the request to the registered function. Returns the appropriate Response object"""
# see if already cached
...
...
@@ -210,7 +212,7 @@ class RequestRouter:
# standardize URL and remove trailing "/" if necessary
standardized_postpath
=
request
.
postpath
if
(
request
.
postpath
[
-
1
]
!=
''
or
request
.
postpath
==
[
''
])
else
request
.
postpath
[:
-
1
]
path
=
'/'
+
'/'
.
join
(
standardized_postpath
)
path
=
'/'
.
join
(
standardized_postpath
)
contentType
=
MediaType
.
WILDCARD
if
HttpHeader
.
CONTENT_TYPE
not
in
request
.
received_headers
else
request
.
received_headers
[
HttpHeader
.
CONTENT_TYPE
]
...
...
setup.py
View file @
1e4b1c51
...
...
@@ -101,7 +101,8 @@ Links
Changelog
`````````
* 0.0.13:
- perf fix to avoid unnecessary string concatenation when doing URL routing, after code review (thanks to Gerald Tremblay)
* 0.0.12:
- backwards incompatible change: added advanced URL routing for nested REST services.
CorePost object is gone, REST services are now just standard classes.
...
...
@@ -131,7 +132,7 @@ from setuptools import setup
setup
(
name
=
"CorePost"
,
version
=
"0.0.1
2
"
,
version
=
"0.0.1
3
"
,
author
=
"Jacek Furmankiewicz"
,
author_email
=
"jacek99@gmail.com"
,
description
=
(
"A Twisted Web REST micro-framework"
),
...
...
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