Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubes
rqlcontroller
Commits
80103b2ba9b4
Commit
9f1e01cc
authored
Jan 19, 2017
by
David Douard
Browse files
[views] flake8
Related to #17047898.
parent
6356699c3343
Changes
2
Hide whitespace changes
Inline
Side-by-side
__pkginfo__.py
View file @
80103b2b
...
...
@@ -13,7 +13,10 @@ author_email = 'contact@logilab.fr'
description
=
'restfull rql edition capabilities'
web
=
'http://www.cubicweb.org/project/%s'
%
distname
__depends__
=
{
'cubicweb'
:
'>= 3.19.0'
}
__depends__
=
{
'cubicweb'
:
'>= 3.19.0'
,
'six'
:
None
,
}
__recommends__
=
{
'cubicweb-signedrequest'
:
None
}
classifiers
=
[
...
...
views.py
View file @
80103b2b
...
...
@@ -12,14 +12,20 @@
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
along
# with this program. If not, see <http://www.gnu.org/licenses/>.
# You should have received a copy of the GNU Lesser General Public License
#
along
with this program. If not, see <http://www.gnu.org/licenses/>.
"""cubicweb-rqlcontroller views/forms/actions/components for web ui"""
import
re
from
cubicweb.predicates
import
ExpectedValuePredicate
,
match_http_method
,
match_form_params
from
six
import
string_types
from
cubicweb.predicates
import
(
ExpectedValuePredicate
,
match_form_params
,
match_http_method
,
)
from
cubicweb.uilib
import
exc_message
from
cubicweb.utils
import
json
,
json_dumps
from
cubicweb.web
import
RemoteCallFailed
,
DirectResponse
...
...
@@ -27,13 +33,14 @@ from cubicweb.web.controller import Controller
from
cubicweb.web.views.urlrewrite
import
rgx_action
,
SchemaBasedRewriter
from
cubicweb
import
Binary
ARGRE
=
re
.
compile
(
'__r(?P<ref>\d+)$'
)
DATARE
=
re
.
compile
(
'__f(?P<ref>.+)$'
)
def
rewrite_args
(
args
,
output
,
form
):
for
k
,
v
in
args
.
items
():
if
not
isinstance
(
v
,
base
string
):
if
not
isinstance
(
v
,
string
_types
):
continue
match
=
ARGRE
.
match
(
v
)
if
match
:
...
...
@@ -48,14 +55,15 @@ def rewrite_args(args, output, form):
(
v
,
rset
))
row
=
rset
.
rows
[
0
]
if
len
(
row
)
>
1
:
raise
Exception
(
'%s references multi column result set %s'
%
(
v
,
rset
))
raise
Exception
(
'%s references multi column result set %s'
%
(
v
,
rset
))
args
[
k
]
=
row
[
0
]
continue
match
=
DATARE
.
match
(
v
)
if
match
:
args
[
k
]
=
Binary
(
form
[
v
][
1
].
read
())
class
match_request_content_type
(
ExpectedValuePredicate
):
"""check that the request body has the right content type"""
def
_get_value
(
self
,
cls
,
req
,
**
kwargs
):
...
...
@@ -64,6 +72,7 @@ class match_request_content_type(ExpectedValuePredicate):
header
=
header
.
split
(
';'
,
1
)[
0
].
strip
()
return
header
class
RqlIOController
(
Controller
):
"""posted rql queries and arguments use the following pattern:
...
...
@@ -77,10 +86,10 @@ class RqlIOController(Controller):
{'content': '__f0', 'fname': 'toto.txt'}),
]
The later query is an example of query built to upload binety
data as
a file object. It requires to have a multipart query
in which there is
a part holding a file named '__f0'. See
cwclientlib for examples of such
queries.
The later query is an example of query built to upload binety
data as
a file object. It requires to have a multipart query
in which there is
a part holding a file named '__f0'. See
cwclientlib for examples of such
queries.
Limitations: back references can only work if one entity has been
created.
...
...
@@ -88,13 +97,14 @@ class RqlIOController(Controller):
"""
__regid__
=
'rqlio'
__select__
=
(
match_http_method
(
'POST'
)
&
match_request_content_type
(
'application/json'
,
'multipart/form-data'
,
mode
=
'any'
)
&
match_request_content_type
(
'application/json'
,
'multipart/form-data'
,
mode
=
'any'
)
&
match_form_params
(
'version'
))
def
json
(
self
):
try
:
contenttype
=
self
.
_cw
.
get_header
(
'Content-Type'
,
raw
=
False
)
if
(
contenttype
.
mediaType
,
contenttype
.
mediaSubtype
)
==
(
'application'
,
'json'
):
if
(
contenttype
.
mediaType
,
contenttype
.
mediaSubtype
)
==
(
'application'
,
'json'
):
# noqa: E501
encoding
=
contenttype
.
params
.
get
(
'charset'
,
'utf-8'
)
args
=
json
.
load
(
self
.
_cw
.
content
,
encoding
=
encoding
)
self
.
_cw
.
content
.
seek
(
0
,
0
)
...
...
@@ -112,7 +122,8 @@ class RqlIOController(Controller):
self
.
_cw
.
set_content_type
(
'application/json'
)
if
self
.
_cw
.
form
[
'version'
]
!=
'1.0'
:
raise
RemoteCallFailed
(
'unknown rqlio version %r'
,
self
.
_cw
.
form
[
'version'
])
raise
RemoteCallFailed
(
'unknown rqlio version %r'
,
self
.
_cw
.
form
[
'version'
])
args
=
self
.
json
()
try
:
...
...
@@ -128,7 +139,7 @@ class RqlIOController(Controller):
def
rqlio
(
self
,
*
rql_args
):
try
:
output
=
self
.
_rqlio
(
rql_args
)
except
Exception
as
exc
:
except
Exception
:
self
.
_cw
.
cnx
.
rollback
()
raise
else
:
...
...
@@ -144,7 +155,9 @@ class RqlIOController(Controller):
output
.
append
(
self
.
_cw
.
execute
(
rql
,
args
))
return
output
class
RQLIORewriter
(
SchemaBasedRewriter
):
rules
=
[
(
re
.
compile
(
'/rqlio/(?P<version>.+)$'
),
rgx_action
(
controller
=
'rqlio'
,
formgroups
=
(
'version'
,)))
]
(
re
.
compile
(
'/rqlio/(?P<version>.+)$'
),
rgx_action
(
controller
=
'rqlio'
,
formgroups
=
(
'version'
,))),
]
Write
Preview
Supports
Markdown
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