Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Python
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
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
xAAL
Code
Python
Commits
7f631254
Commit
7f631254
authored
4 months ago
by
KERDREUX Jerome
Browse files
Options
Downloads
Patches
Plain Diff
Format
parent
d126e837
No related branches found
No related tags found
1 merge request
!1
First try of type hints
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libs/lib/xaal/lib/cbor.py
+15
-10
15 additions, 10 deletions
libs/lib/xaal/lib/cbor.py
with
15 additions
and
10 deletions
libs/lib/xaal/lib/cbor.py
+
15
−
10
View file @
7f631254
...
@@ -16,25 +16,30 @@ def tag_hook(decoder, tag, shareable_index=None):
...
@@ -16,25 +16,30 @@ def tag_hook(decoder, tag, shareable_index=None):
return
bindings
.
URL
(
tag
.
value
)
return
bindings
.
URL
(
tag
.
value
)
return
tag
return
tag
def
default_encoder
(
encoder
,
value
):
def
default_encoder
(
encoder
,
value
):
if
isinstance
(
value
,
bindings
.
UUID
):
if
isinstance
(
value
,
bindings
.
UUID
):
encoder
.
encode
(
CBORTag
(
37
,
value
.
bytes
))
encoder
.
encode
(
CBORTag
(
37
,
value
.
bytes
))
if
isinstance
(
value
,
bindings
.
URL
):
if
isinstance
(
value
,
bindings
.
URL
):
encoder
.
encode
(
CBORTag
(
32
,
value
.
bytes
))
encoder
.
encode
(
CBORTag
(
32
,
value
.
bytes
))
def
dumps
(
obj
,
**
kwargs
):
def
dumps
(
obj
,
**
kwargs
):
return
cbor2
.
dumps
(
obj
,
default
=
default_encoder
,
**
kwargs
)
return
cbor2
.
dumps
(
obj
,
default
=
default_encoder
,
**
kwargs
)
def
loads
(
payload
,
**
kwargs
):
def
loads
(
payload
,
**
kwargs
):
#return cbor2.loads(payload,tag_hook=tag_hook,**kwargs)
# return cbor2.loads(payload,tag_hook=tag_hook,**kwargs)
return
_loads
(
payload
,
tag_hook
=
tag_hook
,
**
kwargs
)
return
_loads
(
payload
,
tag_hook
=
tag_hook
,
**
kwargs
)
def
_loads
(
s
,
**
kwargs
):
def
_loads
(
s
,
**
kwargs
):
with
BytesIO
(
s
)
as
fp
:
with
BytesIO
(
s
)
as
fp
:
return
CBORDecoder
(
fp
,
**
kwargs
).
decode
()
return
CBORDecoder
(
fp
,
**
kwargs
).
decode
()
#class CustomDecoder(CBORDecoder):pass
# class CustomDecoder(CBORDecoder):pass
def
cleanup
(
obj
):
def
cleanup
(
obj
):
...
@@ -45,14 +50,14 @@ def cleanup(obj):
...
@@ -45,14 +50,14 @@ def cleanup(obj):
Warning: This operate in-place changes.
Warning: This operate in-place changes.
Warning: This won
'
t work for tags in dict keys.
Warning: This won
'
t work for tags in dict keys.
"""
"""
if
isinstance
(
obj
,
list
):
if
isinstance
(
obj
,
list
):
for
i
in
range
(
0
,
len
(
obj
)):
for
i
in
range
(
0
,
len
(
obj
)):
obj
[
i
]
=
cleanup
(
obj
[
i
])
obj
[
i
]
=
cleanup
(
obj
[
i
])
return
obj
return
obj
if
isinstance
(
obj
,
dict
):
if
isinstance
(
obj
,
dict
):
for
k
in
obj
.
keys
():
for
k
in
obj
.
keys
():
obj
.
update
({
k
:
cleanup
(
obj
[
k
])})
obj
.
update
({
k
:
cleanup
(
obj
[
k
])})
return
obj
return
obj
if
type
(
obj
)
in
bindings
.
classes
:
if
type
(
obj
)
in
bindings
.
classes
:
...
...
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