Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-core
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
Antoine Lambert
swh-core
Commits
6492e617
Commit
6492e617
authored
4 years ago
by
David Douard
Browse files
Options
Downloads
Patches
Plain Diff
Get rid of the arrow datetime format in swh.core.api.serializers
it should not be used anymore.
parent
5bbbba61
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
requirements-http.txt
+0
-1
0 additions, 1 deletion
requirements-http.txt
swh/core/api/serializers.py
+11
-14
11 additions, 14 deletions
swh/core/api/serializers.py
swh/core/api/tests/test_serializers.py
+5
-10
5 additions, 10 deletions
swh/core/api/tests/test_serializers.py
with
16 additions
and
25 deletions
requirements-http.txt
+
0
−
1
View file @
6492e617
# requirements for swh.core.api
aiohttp
aiohttp_utils >= 3.1.1
arrow
decorator
Flask
iso8601
...
...
This diff is collapsed.
Click to expand it.
swh/core/api/serializers.py
+
11
−
14
View file @
6492e617
...
...
@@ -12,7 +12,6 @@ import types
from
typing
import
Any
,
Callable
,
Dict
,
List
,
Optional
,
Tuple
,
Type
,
Union
from
uuid
import
UUID
import
arrow
import
iso8601
import
msgpack
from
requests
import
Response
...
...
@@ -57,27 +56,25 @@ def dict_to_exception(exc_dict: Dict[str, Any]) -> Exception:
return
getattr
(
temp
,
exc_dict
[
"
type
"
])(
*
exc_dict
[
"
args
"
])
ENCODERS
=
[
(
arrow
.
Arrow
,
"
arrow
"
,
arrow
.
Arrow
.
isoformat
),
def
encode_timedelta
(
td
:
datetime
.
timedelta
)
->
Dict
[
str
,
int
]:
return
{
"
days
"
:
td
.
days
,
"
seconds
"
:
td
.
seconds
,
"
microseconds
"
:
td
.
microseconds
,
}
ENCODERS
:
List
[
Tuple
[
type
,
str
,
Callable
]]
=
[
(
datetime
.
datetime
,
"
datetime
"
,
encode_datetime
),
(
datetime
.
timedelta
,
"
timedelta
"
,
lambda
o
:
{
"
days
"
:
o
.
days
,
"
seconds
"
:
o
.
seconds
,
"
microseconds
"
:
o
.
microseconds
,
},
),
(
UUID
,
"
uuid
"
,
str
),
(
datetime
.
timedelta
,
"
timedelta
"
,
encode_timedelta
),
(
PagedResult
,
"
paged_result
"
,
_encode_paged_result
),
# Only for JSON:
(
bytes
,
"
bytes
"
,
lambda
o
:
base64
.
b85encode
(
o
).
decode
(
"
ascii
"
)),
(
Exception
,
"
exception
"
,
exception_to_dict
),
]
DECODERS
=
{
"
arrow
"
:
arrow
.
get
,
DECODERS
:
Dict
[
str
,
Callable
]
=
{
"
datetime
"
:
lambda
d
:
iso8601
.
parse_date
(
d
,
default_timezone
=
None
),
"
timedelta
"
:
lambda
d
:
datetime
.
timedelta
(
**
d
),
"
uuid
"
:
UUID
,
...
...
This diff is collapsed.
Click to expand it.
swh/core/api/tests/test_serializers.py
+
5
−
10
View file @
6492e617
...
...
@@ -8,8 +8,6 @@ import json
from
typing
import
Any
,
Callable
,
List
,
Tuple
,
Union
from
uuid
import
UUID
import
arrow
from
arrow
import
Arrow
import
pytest
import
requests
from
requests.exceptions
import
ConnectionError
...
...
@@ -66,9 +64,6 @@ ENCODED_DATA_TIMEDELTA = {
"
d
"
:
{
"
days
"
:
64
,
"
seconds
"
:
0
,
"
microseconds
"
:
0
},
}
DATA_ARROW
=
arrow
.
get
(
"
2018-04-25T16:17:53.533672+00:00
"
)
ENCODED_DATA_ARROW
=
{
"
swhtype
"
:
"
arrow
"
,
"
d
"
:
"
2018-04-25T16:17:53.533672+00:00
"
}
DATA_UUID
=
UUID
(
"
cdd8f804-9db6-40c3-93ab-5955d3836234
"
)
ENCODED_DATA_UUID
=
{
"
swhtype
"
:
"
uuid
"
,
"
d
"
:
"
cdd8f804-9db6-40c3-93ab-5955d3836234
"
}
...
...
@@ -89,16 +84,18 @@ ENCODED_DATA_PAGED_RESULT = {
"
swhtype
"
:
"
paged_result
"
,
}
TestPagedResultTuple
=
PagedResult
[
Union
[
str
,
bytes
,
Arrow
],
List
[
Union
[
str
,
UUID
]]]
TestPagedResultTuple
=
PagedResult
[
Union
[
str
,
bytes
,
datetime
.
datetime
],
List
[
Union
[
str
,
UUID
]]
]
DATA_PAGED_RESULT2
=
TestPagedResultTuple
(
results
=
[
"
data0
"
,
DATA_BYTES
,
DATA_
ARROW
],
next_page_token
=
[
"
10
"
,
DATA_UUID
],
results
=
[
"
data0
"
,
DATA_BYTES
,
DATA_
DATETIME
],
next_page_token
=
[
"
10
"
,
DATA_UUID
],
)
ENCODED_DATA_PAGED_RESULT2
=
{
"
d
"
:
{
"
results
"
:
[
"
data0
"
,
ENCODED_DATA_BYTES
,
ENCODED_DATA_
ARROW
,],
"
results
"
:
[
"
data0
"
,
ENCODED_DATA_BYTES
,
ENCODED_DATA_
DATETIME
,],
"
next_page_token
"
:
[
"
10
"
,
ENCODED_DATA_UUID
],
},
"
swhtype
"
:
"
paged_result
"
,
...
...
@@ -111,7 +108,6 @@ DATA = {
2015
,
3
,
4
,
18
,
25
,
13
,
1234
,
tzinfo
=
datetime
.
timezone
.
utc
),
"
datetime_delta
"
:
DATA_TIMEDELTA
,
"
arrow_date
"
:
DATA_ARROW
,
"
swhtype
"
:
"
fake
"
,
"
swh_dict
"
:
{
"
swhtype
"
:
42
,
"
d
"
:
"
test
"
},
"
random_dict
"
:
{
"
swhtype
"
:
43
},
...
...
@@ -125,7 +121,6 @@ ENCODED_DATA = {
"
datetime_tz
"
:
ENCODED_DATA_DATETIME
,
"
datetime_utc
"
:
{
"
swhtype
"
:
"
datetime
"
,
"
d
"
:
"
2015-03-04T18:25:13.001234+00:00
"
,},
"
datetime_delta
"
:
ENCODED_DATA_TIMEDELTA
,
"
arrow_date
"
:
ENCODED_DATA_ARROW
,
"
swhtype
"
:
"
fake
"
,
"
swh_dict
"
:
{
"
swhtype
"
:
42
,
"
d
"
:
"
test
"
},
"
random_dict
"
:
{
"
swhtype
"
:
43
},
...
...
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