Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
minijson
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
minijson
Commits
a04f5137
Commit
a04f5137
authored
4 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
99% coverage
parent
c871a3c5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
minijson.pyx
+3
-9
3 additions, 9 deletions
minijson.pyx
tests/test_minijson.py
+0
-7
0 additions, 7 deletions
tests/test_minijson.py
with
3 additions
and
16 deletions
minijson.pyx
+
3
−
9
View file @
a04f5137
...
...
@@ -318,9 +318,7 @@ cpdef int dump(object data, cio: io.BytesIO) except -1:
return
1
elif
isinstance
(
data
,
str
):
length
=
len
(
data
)
if
length
<
0
:
raise
EncodingError
(
'
Invalid length!
'
)
elif
length
<
128
:
if
length
<
128
:
cio
.
write
(
bytearray
([
0x80
|
length
]))
cio
.
write
(
data
.
encode
(
'
utf-8
'
))
return
1
+
length
...
...
@@ -333,13 +331,11 @@ cpdef int dump(object data, cio: io.BytesIO) except -1:
cio
.
write
(
STRUCT_H
.
pack
(
length
))
cio
.
write
(
data
.
encode
(
'
utf-8
'
))
return
3
+
length
el
if
length
<=
0xFFFFFFFF
:
el
se
:
# Python strings cannot grow past 0xFFFFFFFF characters
cio
.
write
(
b
'
\x0E
'
)
cio
.
write
(
STRUCT_L
.
pack
(
length
))
cio
.
write
(
data
.
encode
(
'
utf-8
'
))
return
5
+
length
else
:
raise
EncodingError
(
'
String is too long!
'
)
elif
isinstance
(
data
,
int
):
if
-
128
<=
data
<=
127
:
# signed char, type 3
cio
.
write
(
b
'
\x03
'
)
...
...
@@ -439,12 +435,10 @@ cpdef int dump(object data, cio: io.BytesIO) except -1:
cio
.
write
(
b
'
\x15
'
)
cio
.
write
(
STRUCT_H
.
pack
(
length
))
offset
=
3
el
if
length
<=
0xFFFFFFFF
:
el
se
:
# Python objects cannot grow to have more than
0xFFFFFFFF
members
cio
.
write
(
b
'
\x13
'
)
cio
.
write
(
STRUCT_L
.
pack
(
length
))
offset
=
5
else
:
raise
EncodingError
(
'
Too long of a sdict!
'
)
for
key
,
value
in
data
.
items
():
offset
+=
dump
(
key
,
cio
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_minijson.py
+
0
−
7
View file @
a04f5137
...
...
@@ -50,13 +50,6 @@ class TestMiniJSON(unittest.TestCase):
self
.
assertSameAfterDumpsAndLoads
(
c
)
self
.
assertSameAfterDumpsAndLoads
(
d
)
def
test_too_long_string
(
self
):
class
Test
(
str
):
def
__len__
(
self
):
return
0x1FFFFFFFF
self
.
assertRaises
(
EncodingError
,
lambda
:
dumps
(
Test
()))
def
test_lists
(
self
):
a
=
[
None
]
*
4
self
.
assertSameAfterDumpsAndLoads
(
a
)
...
...
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