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
cd0e0bc8
Commit
cd0e0bc8
authored
Sep 12, 2011
by
Jacek Furmankiewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
work on json/xml parsing
parent
21de6ca2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
8 deletions
+26
-8
enums.py
corepost/enums.py
+6
-1
__init__.py
corepost/extras/__init__.py
+0
-0
security.py
corepost/extras/security.py
+1
-1
web.py
corepost/web.py
+19
-6
No files found.
corepost/enums.py
View file @
cd0e0bc8
...
...
@@ -11,6 +11,10 @@ class Http:
PUT
=
"PUT"
DELETE
=
"DELETE"
class
HttpHeader
:
"""Enumerates common HTTP headers"""
CONTENT_TYPE
=
"content-type"
class
MediaType
:
"""Enumerates media types"""
WILDCARD
=
"*/*"
...
...
@@ -24,4 +28,5 @@ class MediaType:
APPLICATION_OCTET_STREAM
=
"application/octet-stream"
TEXT_PLAIN
=
"text/plain"
TEXT_XML
=
"text/xml"
TEXT_HTML
=
"text/html"
\ No newline at end of file
TEXT_HTML
=
"text/html"
TEXT_YAML
=
"text/yaml"
\ No newline at end of file
corepost/extras/__init__.py
0 → 100644
View file @
cd0e0bc8
corepost/security.py
→
corepost/
extras/
security.py
View file @
cd0e0bc8
...
...
@@ -3,7 +3,7 @@ Stand-alone security module with support for role-based authorization and IP add
@author: jacekf
'''
from
IPy
import
IP
#
from IPy import IP
class
SecurityRole
:
'''Represents a security role'''
...
...
corepost/web.py
View file @
cd0e0bc8
...
...
@@ -4,7 +4,7 @@ Main server classes
@author: jacekf
'''
from
collections
import
defaultdict
from
corepost.enums
import
Http
from
corepost.enums
import
Http
,
HttpHeader
from
corepost.utils
import
getMandatoryArgumentNames
from
enums
import
MediaType
from
formencode
import
FancyValidator
,
Invalid
...
...
@@ -12,10 +12,9 @@ from twisted.internet import reactor, defer
from
twisted.web.http
import
parse_qs
from
twisted.web.resource
import
Resource
from
twisted.web.server
import
Site
,
NOT_DONE_YET
import
re
import
copy
import
exceptions
import
re
,
copy
,
exceptions
,
json
from
xml.etree
import
ElementTree
class
RequestRouter
:
''' Common class for containing info related to routing a request to a function '''
...
...
@@ -208,7 +207,7 @@ class CorePost(Resource):
allargs
[
arg
]
=
requestargs
[
arg
][
0
]
# if POST/PUT, check if we need to automatically parse JSON
# TODO
self
.
__parseRequestData
(
request
)
#handle Deferreds natively
try
:
...
...
@@ -240,6 +239,20 @@ class CorePost(Resource):
request
.
setResponseCode
(
code
)
request
.
setHeader
(
"content-type"
,
MediaType
.
TEXT_PLAIN
)
return
message
def
__parseRequestData
(
self
,
request
):
'''Automatically parses JSON,XML,YAML if present'''
if
HttpHeader
.
CONTENT_TYPE
in
request
.
headers
.
keys
():
type
=
request
.
headers
[
"content-type"
]
if
type
==
MediaType
.
APPLICATION_JSON
:
request
.
json
=
json
.
loads
(
request
.
content
.
read
())
pass
elif
type
in
(
MediaType
.
APPLICATION_XML
,
MediaType
.
TEXT_XML
):
request
.
xml
=
ElementTree
.
XML
(
request
.
content
.
read
())
pass
elif
type
==
MediaType
.
TEXT_YAML
:
#TODO: parse YAML
pass
def
run
(
self
,
port
=
8080
):
"""Shortcut for running app within Twisted reactor"""
...
...
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