Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
grumpy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
grumpy
Commits
89f4c7cc
Commit
89f4c7cc
authored
Jan 17, 2017
by
YOU
Committed by
Dylan Trotter
Jan 16, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add json to stdlib (#134)
parent
de506699
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1274 additions
and
3 deletions
+1274
-3
Makefile
Makefile
+2
-2
third_party/pypy/_struct.py
third_party/pypy/_struct.py
+2
-1
third_party/stdlib/json/__init__.py
third_party/stdlib/json/__init__.py
+358
-0
third_party/stdlib/json/decoder.py
third_party/stdlib/json/decoder.py
+386
-0
third_party/stdlib/json/encoder.py
third_party/stdlib/json/encoder.py
+458
-0
third_party/stdlib/json_scanner.py
third_party/stdlib/json_scanner.py
+68
-0
No files found.
Makefile
View file @
89f4c7cc
...
...
@@ -54,8 +54,8 @@ RUNNER = $(RUNNER_BIN) $(COMPILER) $(RUNTIME) $(STDLIB)
GRUMPY_STDLIB_SRCS
:=
$(
shell
find lib
-name
'*.py'
)
GRUMPY_STDLIB_PACKAGES
:=
$(
foreach
x,
$(GRUMPY_STDLIB_SRCS)
,
$(
patsubst
lib/%.py,%,
$(
patsubst
lib/%/__init__.py,%,
$(x)
)))
THIRD_PARTY_STDLIB_SRCS
:=
$(
wildcard
third_party/stdlib/
*
.py
)
$(
wildcard
third_party/pypy/
*
.py
)
THIRD_PARTY_STDLIB_PACKAGES
:=
$(
foreach
x,
$(THIRD_PARTY_STDLIB_SRCS)
,
$(
patsubst
third_party/stdlib/%.py,%,
$(
patsubst
third_party/pypy/%.py,%,
$(
x
)
)))
THIRD_PARTY_STDLIB_SRCS
:=
$(
shell
find third_party
-name
'*.py'
)
THIRD_PARTY_STDLIB_PACKAGES
:=
$(
foreach
x,
$(THIRD_PARTY_STDLIB_SRCS)
,
$(
patsubst
third_party/stdlib/%.py,%,
$(
patsubst
third_party/pypy/%.py,%,
$(
patsubst
third_party/pypy/%/__init__.py,%,
$(
patsubst
third_party/stdlib/%/__init__.py,%,
$(x)
)
))))
STDLIB_SRCS
:=
$(GRUMPY_STDLIB_SRCS)
$(THIRD_PARTY_STDLIB_SRCS)
STDLIB_PACKAGES
:=
$(GRUMPY_STDLIB_PACKAGES)
$(THIRD_PARTY_STDLIB_PACKAGES)
STDLIB
:=
$(
patsubst
%,
$(PKG_DIR)
/grumpy/lib/%.a,
$(STDLIB_PACKAGES)
)
...
...
third_party/pypy/_struct.py
View file @
89f4c7cc
...
...
@@ -136,7 +136,8 @@ def unpack_float(data, index, size, le):
binary
.
reverse
()
unsigned
=
0
for
i
in
range
(
8
):
unsigned
|=
binary
[
i
]
<<
(
i
*
8
)
# unsigned |= binary[i] << (i * 8)
unsigned
|=
ord
(
binary
[
i
])
<<
(
i
*
8
)
return
float_unpack
(
unsigned
,
size
,
le
)
...
...
third_party/stdlib/json/__init__.py
0 → 100644
View file @
89f4c7cc
This diff is collapsed.
Click to expand it.
third_party/stdlib/json/decoder.py
0 → 100644
View file @
89f4c7cc
This diff is collapsed.
Click to expand it.
third_party/stdlib/json/encoder.py
0 → 100644
View file @
89f4c7cc
This diff is collapsed.
Click to expand it.
third_party/stdlib/json_scanner.py
0 → 100644
View file @
89f4c7cc
"""JSON token scanner
"""
import
re
# try:
# from _json import make_scanner as c_make_scanner
# except ImportError:
# c_make_scanner = None
c_make_scanner
=
None
__all__
=
[
'make_scanner'
]
NUMBER_RE
=
re
.
compile
(
r'(-?(?:0|[1-9]\
d*))(
\.\
d+)?([eE][-+]?
\d+)?'
,
(
re
.
VERBOSE
|
re
.
MULTILINE
|
re
.
DOTALL
))
def
py_make_scanner
(
context
):
parse_object
=
context
.
parse_object
parse_array
=
context
.
parse_array
parse_string
=
context
.
parse_string
match_number
=
NUMBER_RE
.
match
encoding
=
context
.
encoding
strict
=
context
.
strict
parse_float
=
context
.
parse_float
parse_int
=
context
.
parse_int
parse_constant
=
context
.
parse_constant
object_hook
=
context
.
object_hook
object_pairs_hook
=
context
.
object_pairs_hook
def
_scan_once
(
string
,
idx
):
try
:
nextchar
=
string
[
idx
]
except
IndexError
:
raise
StopIteration
if
nextchar
==
'"'
:
return
parse_string
(
string
,
idx
+
1
,
encoding
,
strict
)
elif
nextchar
==
'{'
:
return
parse_object
((
string
,
idx
+
1
),
encoding
,
strict
,
_scan_once
,
object_hook
,
object_pairs_hook
)
elif
nextchar
==
'['
:
return
parse_array
((
string
,
idx
+
1
),
_scan_once
)
elif
nextchar
==
'n'
and
string
[
idx
:
idx
+
4
]
==
'null'
:
return
None
,
idx
+
4
elif
nextchar
==
't'
and
string
[
idx
:
idx
+
4
]
==
'true'
:
return
True
,
idx
+
4
elif
nextchar
==
'f'
and
string
[
idx
:
idx
+
5
]
==
'false'
:
return
False
,
idx
+
5
m
=
match_number
(
string
,
idx
)
if
m
is
not
None
:
integer
,
frac
,
exp
=
m
.
groups
()
if
frac
or
exp
:
res
=
parse_float
(
integer
+
(
frac
or
''
)
+
(
exp
or
''
))
else
:
res
=
parse_int
(
integer
)
return
res
,
m
.
end
()
elif
nextchar
==
'N'
and
string
[
idx
:
idx
+
3
]
==
'NaN'
:
return
parse_constant
(
'NaN'
),
idx
+
3
elif
nextchar
==
'I'
and
string
[
idx
:
idx
+
8
]
==
'Infinity'
:
return
parse_constant
(
'Infinity'
),
idx
+
8
elif
nextchar
==
'-'
and
string
[
idx
:
idx
+
9
]
==
'-Infinity'
:
return
parse_constant
(
'-Infinity'
),
idx
+
9
else
:
raise
StopIteration
return
_scan_once
make_scanner
=
c_make_scanner
or
py_make_scanner
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment