Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Renaud Boyer
swh-web
Commits
6063c7e1
Commit
6063c7e1
authored
9 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
Update JSONRenderer to deal with jsonp
parent
ab34eb70
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
swh/web/ui/controller.py
+0
-10
0 additions, 10 deletions
swh/web/ui/controller.py
swh/web/ui/decorators.py
+0
-32
0 additions, 32 deletions
swh/web/ui/decorators.py
swh/web/ui/renderers.py
+12
-2
12 additions, 2 deletions
swh/web/ui/renderers.py
with
12 additions
and
44 deletions
swh/web/ui/controller.py
+
0
−
10
View file @
6063c7e1
...
...
@@ -12,7 +12,6 @@ from flask.ext.api.renderers import HTMLRenderer
from
swh.core.hashutil
import
ALGORITHMS
from
swh.web.ui.main
import
app
from
swh.web.ui
import
service
,
renderers
from
swh.web.ui.decorators
import
jsonp
from
swh.web.ui.exc
import
BadInputExc
,
NotFoundExc
...
...
@@ -148,7 +147,6 @@ def content(hash, sha):
@app.route
(
'
/api/1/stat/counters
'
)
@jsonp
def
api_stats
():
"""
Return statistics as a JSON object
"""
return
service
.
stat_counters
()
...
...
@@ -171,7 +169,6 @@ def value_not_found(error):
@app.route
(
'
/api/1/search/<string:q>/
'
)
@jsonp
def
api_search
(
q
):
"""
Return search results as a JSON object
"""
return
{
'
found
'
:
service
.
lookup_hash
(
q
)}
...
...
@@ -186,7 +183,6 @@ def _api_lookup(criteria, lookup_fn, error_msg_if_not_found):
@app.route
(
'
/api/1/origin/<int:origin_id>
'
)
@jsonp
def
api_origin
(
origin_id
):
"""
Return information about origin.
"""
return
_api_lookup
(
...
...
@@ -195,7 +191,6 @@ def api_origin(origin_id):
@app.route
(
'
/api/1/person/<int:person_id>
'
)
@jsonp
def
api_person
(
person_id
):
"""
Return information about person.
"""
return
_api_lookup
(
...
...
@@ -204,7 +199,6 @@ def api_person(person_id):
@app.route
(
'
/api/1/release/<string:sha1_git>
'
)
@jsonp
def
api_release
(
sha1_git
):
"""
Return information about release with id sha1_git.
"""
error_msg
=
'
Release with sha1_git %s not found.
'
%
sha1_git
...
...
@@ -215,7 +209,6 @@ def api_release(sha1_git):
@app.route
(
'
/api/1/revision/<string:sha1_git>
'
)
@jsonp
def
api_revision
(
sha1_git
):
"""
Return information about revision with id sha1_git.
...
...
@@ -228,7 +221,6 @@ def api_revision(sha1_git):
@app.route
(
'
/api/1/directory/<string:sha1_git>
'
)
@jsonp
def
api_directory
(
sha1_git
):
"""
Return information about release with id sha1_git.
"""
recursive_flag
=
request
.
args
.
get
(
'
recursive
'
,
False
)
...
...
@@ -240,7 +232,6 @@ def api_directory(sha1_git):
@app.route
(
'
/api/1/content/<string:q>/
'
)
@jsonp
def
api_content_with_details
(
q
):
"""
Return content information up to its origin if found.
...
...
@@ -264,7 +255,6 @@ def api_content_with_details(q):
@app.route
(
'
/api/1/uploadnsearch/
'
,
methods
=
[
'
POST
'
])
@jsonp
def
api_uploadnsearch
():
"""
Upload the file
'
s content in the post body request.
Compute the hash and determine if it exists in the storage.
...
...
This diff is collapsed.
Click to expand it.
swh/web/ui/decorators.py
deleted
100644 → 0
+
0
−
32
View file @
ab34eb70
# Copyright (C) 2015 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
from
functools
import
wraps
from
flask
import
request
,
current_app
def
jsonp
(
func
):
"""
Wraps JSONified output for JSONP requests.
"""
@wraps
(
func
)
def
decorated_function
(
*
args
,
**
kwargs
):
callback
=
request
.
args
.
get
(
'
callback
'
,
False
)
if
callback
:
res
=
func
(
*
args
,
**
kwargs
)
if
hasattr
(
res
,
'
data
'
):
# for a response object, data
data
=
res
.
data
if
isinstance
(
data
,
bytes
):
# we're dealing in utf-8 bytes
data
=
data
.
decode
(
'
utf-8
'
)
else
:
data
=
str
(
data
)
else
:
# fallback case...
data
=
str
(
res
)
content
=
''
.
join
([
str
(
callback
),
'
(
'
,
data
,
'
)
'
])
return
current_app
.
response_class
(
content
,
mimetype
=
'
application/javascript
'
)
return
func
(
*
args
,
**
kwargs
)
return
decorated_function
This diff is collapsed.
Click to expand it.
swh/web/ui/renderers.py
+
12
−
2
View file @
6063c7e1
...
...
@@ -17,8 +17,18 @@ class YAMLRenderer(renderers.BaseRenderer):
return
yaml
.
dump
(
data
,
encoding
=
self
.
charset
)
class
JSONPRenderer
(
renderers
.
JSONRenderer
):
def
render
(
self
,
data
,
media_type
,
**
options
):
# Requested indentation may be set in the Accept header.
res
=
super
().
render
(
data
,
media_type
,
**
options
)
jsonp
=
request
.
args
.
get
(
'
callback
'
)
if
jsonp
:
return
'
%s(%s)
'
%
(
jsonp
,
res
)
return
res
RENDERERS
=
[
'
flask.ext.ap
i.renderers.JSONRenderer
'
,
'
swh.web.u
i.renderers.JSON
P
Renderer
'
,
'
flask.ext.api.renderers.BrowsableAPIRenderer
'
,
'
flask.ext.api.parsers.URLEncodedParser
'
,
'
swh.web.ui.renderers.YAMLRenderer
'
,
...
...
@@ -26,7 +36,7 @@ RENDERERS = [
RENDERERS_INSTANCE
=
[
renderers
.
JSONRenderer
(),
JSON
P
Renderer
(),
renderers
.
BrowsableAPIRenderer
(),
parsers
.
URLEncodedParser
(),
YAMLRenderer
(),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment