Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
w2pext
plugin_dbui
Commits
d776c85e
Commit
d776c85e
authored
Nov 23, 2016
by
LE GAC Renaud
Browse files
Update MyJsonEncoder to add the type lazyT.
parent
c3cc6e27
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
21 deletions
+30
-21
modules/plugin_dbui/directsvc.py
modules/plugin_dbui/directsvc.py
+30
-21
No files found.
modules/plugin_dbui/directsvc.py
View file @
d776c85e
...
...
@@ -8,16 +8,22 @@ import json
from
basesvc
import
BaseSvc
from
gluon
import
current
from
gluon.http
import
HTTP
from
gluon.languages
import
lazyT
from
gluon.restricted
import
RestrictedError
from
helper
import
as_list
DBUI
=
'
Dbui
'
PROC_KEY
=
'
%s.%s
'
DBUI
=
"
Dbui
"
PROC_KEY
=
"
%s.%s
"
class
MyJsonEncoder
(
json
.
JSONEncoder
):
"""Add date, datetime and time to the standard JSON encoder.
"""Add to the standard JSON encoder:
- date
- datetime
- lazyT
- time
"""
def
default
(
self
,
obj
):
...
...
@@ -25,7 +31,10 @@ class MyJsonEncoder(json.JSONEncoder):
if
isinstance
(
obj
,
(
datetime
.
date
,
datetime
.
datetime
,
datetime
.
time
)):
return
obj
.
isoformat
().
replace
(
'T'
,
' '
)
return
obj
.
isoformat
().
replace
(
"T"
,
" "
)
elif
isinstance
(
obj
,
lazyT
):
return
str
(
obj
)
return
json
.
JSONEncoder
.
default
(
self
,
obj
)
...
...
@@ -47,7 +56,7 @@ class DirectSvc(BaseSvc):
@service.register
def myfunction(a, b):
The same appr
a
och can be used for methods.
The same appro
a
ch can be used for methods.
On the client-side:
...
...
@@ -92,14 +101,14 @@ class DirectSvc(BaseSvc):
or when the function / method crashed.
"""
self
.
dbg
(
'
Start directSvc.call
'
)
self
.
dbg
(
"
Start directSvc.call
"
)
myrequest
=
current
.
request
# no arguments in a J
son
-encoded raw HTPP request
# no arguments in a J
SON
-encoded raw HTPP request
if
len
(
myrequest
.
args
)
==
0
:
return
self
.
route
()
self
.
error
(
404
,
'
Object does not exist.
'
)
self
.
error
(
404
,
"
Object does not exist.
"
)
def
echo
(
self
,
x
):
"""Return the input arguments to run echo tests.
...
...
@@ -141,7 +150,7 @@ class DirectSvc(BaseSvc):
# The action is equal to Dbui for a function
# and to the name of the class for a method
action
=
DBUI
if
'
im_class
'
in
dir
(
f
):
if
"
im_class
"
in
dir
(
f
):
action
=
f
.
im_class
.
__name__
k
=
PROC_KEY
%
(
action
,
f
.
__name__
)
...
...
@@ -165,7 +174,7 @@ class DirectSvc(BaseSvc):
in the web2py ticket system.
"""
self
.
dbg
(
'
Start directSvc.route
'
)
self
.
dbg
(
"
Start directSvc.route
"
)
# decode transactions, a list of Json-encoded raw HTPP requests:
# {action: "x", method: "y", data: [], type:"rpc", tid:z}
...
...
@@ -177,26 +186,26 @@ class DirectSvc(BaseSvc):
li
=
[]
for
arg
in
transactions
:
di
=
dict
(
arg
)
self
.
dbg
(
'
transaction:
'
,
di
)
self
.
dbg
(
"
transaction:
"
,
di
)
try
:
k
=
PROC_KEY
%
(
arg
[
'
action
'
],
arg
[
'
method
'
])
if
arg
[
'
data
'
]:
di
[
'
result
'
]
=
self
.
procedures
[
k
](
*
arg
[
'
data
'
])
k
=
PROC_KEY
%
(
arg
[
"
action
"
],
arg
[
"
method
"
])
if
arg
[
"
data
"
]:
di
[
"
result
"
]
=
self
.
procedures
[
k
](
*
arg
[
"
data
"
])
else
:
di
[
'
result
'
]
=
self
.
procedures
[
k
]()
di
[
"
result
"
]
=
self
.
procedures
[
k
]()
# catch exceptions and log them in the ticker system
# inform the user that something went wrong in the server
except
:
r
=
RestrictedError
(
layer
=
'
directsvc.py
'
,
code
=
'
route
'
,
output
=
''
,
r
=
RestrictedError
(
layer
=
"
directsvc.py
"
,
code
=
"
route
"
,
output
=
""
,
environment
=
current
.
globalenv
)
r
.
log
(
myrequest
)
self
.
error
(
500
,
'
Internal server error.
'
)
self
.
error
(
500
,
"
Internal server error.
"
)
del
di
[
'
data
'
]
del
di
[
"
data
"
]
li
.
append
(
di
)
self
.
dbg
(
'
End directSvc.call
'
,
li
)
self
.
dbg
(
"
End directSvc.call
"
,
li
)
return
json
.
dumps
(
li
,
cls
=
MyJsonEncoder
)
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