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
6f276cc8
Commit
6f276cc8
authored
3 months ago
by
I. Nüske
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Support separate connect/read timeouts and timeout None
parent
4ba40593
No related branches found
No related tags found
2 merge requests
!175
BUG: Request responses without the "Set-Cookie" header no longer overwrite the...
,
!167
Separate connect/read timeouts in pylinkahead.ini
Pipeline
#58636
failed
3 months ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/linkahead/configuration.py
+20
-5
20 additions, 5 deletions
src/linkahead/configuration.py
src/linkahead/connection/connection.py
+12
-4
12 additions, 4 deletions
src/linkahead/connection/connection.py
src/linkahead/schema-pycaosdb-ini.yml
+7
-1
7 additions, 1 deletion
src/linkahead/schema-pycaosdb-ini.yml
with
39 additions
and
10 deletions
src/linkahead/configuration.py
+
20
−
5
View file @
6f276cc8
...
...
@@ -30,6 +30,14 @@ import yaml
try
:
optional_jsonschema_validate
:
Optional
[
Callable
]
=
None
from
jsonschema
import
validate
as
optional_jsonschema_validate
# Adapted from https://github.com/python-jsonschema/jsonschema/issues/148
# Defines Validator to allow parsing of all iterables as array in jsonschema
from
collections.abc
import
Iterable
from
jsonschema
import
validators
default
=
validators
.
_LATEST_VERSION
t_c
=
(
default
.
TYPE_CHECKER
.
redefine
(
'
array
'
,
lambda
x
,
y
:
isinstance
(
y
,
Iterable
)))
CustomValidator
=
validators
.
extend
(
default
,
type_checker
=
t_c
)
except
ImportError
:
pass
...
...
@@ -72,14 +80,20 @@ def get_config() -> ConfigParser:
return
_pycaosdbconf
def
config_to_yaml
(
config
:
ConfigParser
)
->
dict
[
str
,
dict
[
str
,
Union
[
int
,
str
,
bool
]]]:
valobj
:
dict
[
str
,
dict
[
str
,
Union
[
int
,
str
,
bool
]]]
=
{}
def
config_to_yaml
(
config
:
ConfigParser
)
->
dict
[
str
,
dict
[
str
,
Union
[
int
,
str
,
bool
,
tuple
,
None
]]]:
valobj
:
dict
[
str
,
dict
[
str
,
Union
[
int
,
str
,
bool
,
tuple
,
None
]]]
=
{}
for
s
in
config
.
sections
():
valobj
[
s
]
=
{}
for
key
,
value
in
config
[
s
].
items
():
# TODO: Can the type be inferred from the config object?
if
key
in
[
"
timeout
"
,
"
debug
"
]:
valobj
[
s
][
key
]
=
int
(
value
)
if
str
(
value
).
lower
()
in
[
"
none
"
,
"
null
"
]:
valobj
[
s
][
key
]
=
None
elif
value
.
startswith
(
'
(
'
)
and
value
.
endswith
(
'
)
'
):
content
=
[
int
(
s
)
for
s
in
value
[
1
:
-
1
].
split
(
'
,
'
)]
valobj
[
s
][
key
]
=
tuple
(
content
)
else
:
valobj
[
s
][
key
]
=
int
(
value
)
elif
key
in
[
"
ssl_insecure
"
]:
valobj
[
s
][
key
]
=
bool
(
value
)
else
:
...
...
@@ -88,11 +102,12 @@ def config_to_yaml(config: ConfigParser) -> dict[str, dict[str, Union[int, str,
return
valobj
def
validate_yaml_schema
(
valobj
:
dict
[
str
,
dict
[
str
,
Union
[
int
,
str
,
bool
]]]):
def
validate_yaml_schema
(
valobj
:
dict
[
str
,
dict
[
str
,
Union
[
int
,
str
,
bool
,
tuple
,
None
]]]):
if
optional_jsonschema_validate
:
with
open
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"
schema-pycaosdb-ini.yml
"
))
as
f
:
schema
=
yaml
.
load
(
f
,
Loader
=
yaml
.
SafeLoader
)
optional_jsonschema_validate
(
instance
=
valobj
,
schema
=
schema
[
"
schema-pycaosdb-ini
"
])
optional_jsonschema_validate
(
instance
=
valobj
,
schema
=
schema
[
"
schema-pycaosdb-ini
"
],
cls
=
CustomValidator
)
else
:
warnings
.
warn
(
"""
Warning: The validation could not be performed because `jsonschema` is not installed.
...
...
This diff is collapsed.
Click to expand it.
src/linkahead/connection/connection.py
+
12
−
4
View file @
6f276cc8
...
...
@@ -39,7 +39,7 @@ from requests.adapters import HTTPAdapter
from
requests.exceptions
import
ConnectionError
as
HTTPConnectionError
from
urllib3.poolmanager
import
PoolManager
from
..configuration
import
get_config
from
..configuration
import
get_config
,
config_to_yaml
from
..exceptions
import
(
ConfigurationError
,
HTTPClientError
,
HTTPForbiddenError
,
HTTPResourceNotFoundError
,
HTTPServerError
,
HTTPURITooLongError
,
...
...
@@ -465,21 +465,29 @@ def configure_connection(**kwargs):
global_conf
=
{}
conf
=
get_config
()
# Convert config to dict, with preserving types
int_opts
=
[
"
timeout
"
]
int_opts
=
[]
bool_opts
=
[
"
ssl_insecure
"
]
other_opts
=
[
"
timeout
"
]
if
conf
.
has_section
(
"
Connection
"
):
global_conf
=
dict
(
conf
.
items
(
"
Connection
"
))
# Integer options
# Integer options
for
opt
in
int_opts
:
if
opt
in
global_conf
:
global_conf
[
opt
]
=
conf
.
getint
(
"
Connection
"
,
opt
)
# Boolean options
# Boolean options
for
opt
in
bool_opts
:
if
opt
in
global_conf
:
global_conf
[
opt
]
=
conf
.
getboolean
(
"
Connection
"
,
opt
)
# Other options, defer parsing to configuration.config_to_yaml:
connection_config
=
config_to_yaml
(
conf
)[
"
Connection
"
]
for
opt
in
other_opts
:
if
opt
in
global_conf
:
global_conf
[
opt
]
=
connection_config
[
opt
]
local_conf
=
_make_conf
(
_DEFAULT_CONF
,
global_conf
,
kwargs
)
connection
=
_Connection
.
get_instance
()
...
...
This diff is collapsed.
Click to expand it.
src/linkahead/schema-pycaosdb-ini.yml
+
7
−
1
View file @
6f276cc8
...
...
@@ -67,7 +67,13 @@ schema-pycaosdb-ini:
description
:
This option is used internally and for testing. Do not override.
examples
:
[
_DefaultCaosDBServerConnection
]
timeout
:
type
:
integer
oneOf
:
-
type
:
[
integer
,
"
null"
]
-
type
:
array
items
:
type
:
[
integer
,
"
null"
]
minItems
:
2
maxItems
:
2
allOf
:
-
if
:
properties
:
...
...
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