Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
caosdb
Software
caosdb-pylib
Commits
837dccbd
Verified
Commit
837dccbd
authored
2 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
FIX: implementation of WrappedResponse
parent
e50affa0
No related branches found
No related tags found
2 merge requests
!79
Release 0.10.0
,
!75
F http proxy
Pipeline
#30210
passed
2 years ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosdb/connection/connection.py
+40
-5
40 additions, 5 deletions
src/caosdb/connection/connection.py
with
40 additions
and
5 deletions
src/caosdb/connection/connection.py
+
40
−
5
View file @
837dccbd
...
...
@@ -65,6 +65,9 @@ class _WrappedHTTPResponse(CaosDBHTTPResponse):
def
__init__
(
self
,
response
):
self
.
response
=
response
self
.
_generator
=
None
self
.
_buffer
=
b
''
self
.
_stream_consumed
=
False
@property
def
reason
(
self
):
...
...
@@ -75,12 +78,44 @@ class _WrappedHTTPResponse(CaosDBHTTPResponse):
return
self
.
response
.
status_code
def
read
(
self
,
size
=
None
):
if
size
is
None
or
size
==
0
:
result
=
b
''
for
chunk
in
self
.
response
.
iter_content
(
chunk_size
=
1024
):
result
=
result
+
chunk
if
self
.
_stream_consumed
is
True
:
raise
RuntimeError
(
"
Stream is consumed
"
)
if
self
.
_buffer
is
None
:
# the buffer has been drained in the previous call.
self
.
_stream_consumed
=
True
return
b
''
if
self
.
_generator
is
None
and
(
size
is
None
or
size
==
0
):
# return full content at once
self
.
_stream_consumed
=
True
return
self
.
response
.
content
if
len
(
self
.
_buffer
)
>=
size
:
# still enough bytes in the buffer
result
=
chunk
[:
size
]
self
.
_buffer
=
chunk
[
size
:]
return
result
if
self
.
_generator
is
None
:
# first call to this method
if
size
is
None
or
size
==
0
:
size
=
512
self
.
_generator
=
self
.
response
.
iter_content
(
size
)
try
:
# read new data into the buffer
chunk
=
self
.
_buffer
+
next
(
self
.
_generator
)
result
=
chunk
[:
size
]
if
len
(
result
)
==
0
:
self
.
_stream_consumed
=
True
self
.
_buffer
=
chunk
[
size
:]
return
result
except
StopIteration
:
# drain buffer
result
=
self
.
_buffer
self
.
_buffer
=
None
return
result
return
self
.
response
.
iter_content
(
size
)
def
getheader
(
self
,
name
,
default
=
None
):
return
self
.
response
.
headers
[
name
]
if
name
in
self
.
response
.
headers
else
default
...
...
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