Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
api-client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container 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
Arkindex
api-client
Commits
310e792a
Commit
310e792a
authored
5 years ago
by
Erwan Rouchet
Committed by
Bastien Abadie
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add a timeout on all requests with a custom transport layer
parent
875dce8b
No related branches found
Branches containing commit
Tags
0.2.3-rc5
Tags containing commit
No related merge requests found
Pipeline
#28352
passed
5 years ago
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
arkindex/client.py
+6
-6
6 additions, 6 deletions
arkindex/client.py
arkindex/transports.py
+17
-0
17 additions, 0 deletions
arkindex/transports.py
requirements.txt
+1
-1
1 addition, 1 deletion
requirements.txt
with
24 additions
and
7 deletions
arkindex/client.py
+
6
−
6
View file @
310e792a
...
...
@@ -7,8 +7,9 @@ import logging
import
warnings
import
yaml
from
arkindex.auth
import
TokenSessionAuthentication
from
arkindex.pagination
import
ResponsePaginator
from
arkindex.encoders
import
XMLEncoder
from
arkindex.pagination
import
ResponsePaginator
from
arkindex.transports
import
ArkindexHTTPTransport
from
io
import
IOBase
,
BufferedIOBase
from
time
import
sleep
from
urllib.parse
import
urlsplit
,
urlunsplit
...
...
@@ -81,6 +82,9 @@ class ArkindexClient(apistar.Client):
def
__repr__
(
self
):
return
'
<{} on {}>
'
.
format
(
self
.
__class__
.
__name__
,
self
.
document
.
url
)
def
init_transport
(
self
,
*
args
,
**
kwargs
):
return
ArkindexHTTPTransport
(
*
args
,
**
kwargs
)
def
configure
(
self
,
token
=
None
,
base_url
=
None
,
sleep
=
None
):
"""
Reconfigure the API client.
...
...
@@ -104,10 +108,6 @@ class ArkindexClient(apistar.Client):
# Add the Referer header to allow Django CSRF to function
self
.
transport
.
headers
.
setdefault
(
'
Referer
'
,
self
.
document
.
url
)
# Add the XML encoder
if
not
any
(
isinstance
(
e
,
XMLEncoder
)
for
e
in
self
.
transport
.
encoders
):
self
.
transport
.
encoders
.
append
(
XMLEncoder
())
def
paginate
(
self
,
*
args
,
**
kwargs
):
"""
Perform a usual request as done by APIStar, but handle paginated endpoints.
...
...
@@ -147,7 +147,7 @@ class ArkindexClient(apistar.Client):
currently handle anything that is not JSON.
:param str operation_id: An OpenAPI operation ID.
:param content: Any kind of content to be sen
d
to
:param content: Any kind of content to be sen
t
to
the APIStar transport layer directly.
:param str encoding: A MIME type to use as the Content-Type for the request.
:param params: Query parameters for the given operation.
...
...
This diff is collapsed.
Click to expand it.
arkindex/transports.py
0 → 100644
+
17
−
0
View file @
310e792a
from
apistar.client.transports
import
HTTPTransport
from
apistar.client.encoders
import
JSONEncoder
,
MultiPartEncoder
,
URLEncodedEncoder
from
arkindex.encoders
import
XMLEncoder
class
ArkindexHTTPTransport
(
HTTPTransport
):
default_encoders
=
[
JSONEncoder
(),
MultiPartEncoder
(),
URLEncodedEncoder
(),
XMLEncoder
(),
]
def
get_request_options
(
self
,
*
args
,
**
kwargs
):
options
=
super
().
get_request_options
(
*
args
,
**
kwargs
)
options
[
'
timeout
'
]
=
(
30
,
60
)
return
options
This diff is collapsed.
Click to expand it.
requirements.txt
+
1
−
1
View file @
310e792a
requests
apistar
apistar
==0.7.2
six
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