Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
simplejson
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
OpenVMS
Python
Modules
simplejson
Commits
b8745da03913
Commit
b8745da03913
authored
16 years ago
by
Bob Ippolito
Browse files
Options
Downloads
Patches
Plain Diff
fixed
http://code.google.com/p/simplejson/issues/detail?id=48
git-svn-id:
http://simplejson.googlecode.com/svn/trunk@184
a4795897-2c25-0410-b006-0d3caba88fa1
parent
9f0c0860b84d
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGES.txt
+2
-0
2 additions, 0 deletions
CHANGES.txt
simplejson/encoder.py
+7
-2
7 additions, 2 deletions
simplejson/encoder.py
simplejson/tests/test_unicode.py
+19
-1
19 additions, 1 deletion
simplejson/tests/test_unicode.py
with
28 additions
and
3 deletions
CHANGES.txt
+
2
−
0
View file @
b8745da0
Version 2.1.0 released XXXX-XX-XX
* Fixed str/unicode mismatches when using ensure_ascii=False
http://code.google.com/p/simplejson/issues/detail?id=48
* Fixed error message when parsing an array with trailing comma with speedups
http://code.google.com/p/simplejson/issues/detail?id=46
* Refactor decoder errors to raise JSONDecodeError instead of ValueError
...
...
This diff is collapsed.
Click to expand it.
simplejson/encoder.py
+
7
−
2
View file @
b8745da0
...
...
@@ -36,5 +36,7 @@
"""
Return a JSON representation of a Python string
"""
if
isinstance
(
s
,
str
)
and
HAS_UTF8
.
search
(
s
)
is
not
None
:
s
=
s
.
decode
(
'
utf-8
'
)
def
replace
(
match
):
return
ESCAPE_DCT
[
match
.
group
(
0
)]
...
...
@@ -39,6 +41,6 @@
def
replace
(
match
):
return
ESCAPE_DCT
[
match
.
group
(
0
)]
return
'"'
+
ESCAPE
.
sub
(
replace
,
s
)
+
'"'
return
u
'"'
+
ESCAPE
.
sub
(
replace
,
s
)
+
u
'"'
def
py_encode_basestring_ascii
(
s
):
...
...
@@ -202,4 +204,5 @@
chunks
=
self
.
iterencode
(
o
,
_one_shot
=
True
)
if
not
isinstance
(
chunks
,
(
list
,
tuple
)):
chunks
=
list
(
chunks
)
if
self
.
ensure_ascii
:
return
''
.
join
(
chunks
)
...
...
@@ -205,4 +208,6 @@
return
''
.
join
(
chunks
)
else
:
return
u
''
.
join
(
chunks
)
def
iterencode
(
self
,
o
,
_one_shot
=
False
):
"""
Encode the given object and yield each string
...
...
This diff is collapsed.
Click to expand it.
simplejson/tests/test_unicode.py
+
19
−
1
View file @
b8745da0
...
...
@@ -78,4 +78,22 @@
def
test_unicode_preservation
(
self
):
self
.
assertEquals
(
type
(
json
.
loads
(
u
'""'
)),
unicode
)
self
.
assertEquals
(
type
(
json
.
loads
(
u
'"
a
"'
)),
unicode
)
self
.
assertEquals
(
type
(
json
.
loads
(
u
'
[
"
a
"
]
'
)[
0
]),
unicode
)
\ No newline at end of file
self
.
assertEquals
(
type
(
json
.
loads
(
u
'
[
"
a
"
]
'
)[
0
]),
unicode
)
def
test_ensure_ascii_false_returns_unicode
(
self
):
# http://code.google.com/p/simplejson/issues/detail?id=48
self
.
assertEquals
(
type
(
json
.
dumps
([],
ensure_ascii
=
False
)),
unicode
)
self
.
assertEquals
(
type
(
json
.
dumps
(
0
,
ensure_ascii
=
False
)),
unicode
)
self
.
assertEquals
(
type
(
json
.
dumps
({},
ensure_ascii
=
False
)),
unicode
)
self
.
assertEquals
(
type
(
json
.
dumps
(
""
,
ensure_ascii
=
False
)),
unicode
)
def
test_ensure_ascii_false_bytestring_encoding
(
self
):
# http://code.google.com/p/simplejson/issues/detail?id=48
doc1
=
{
u
'
quux
'
:
'
Arr
\xc3\xaa
t sur images
'
}
doc2
=
{
u
'
quux
'
:
u
'
Arr
\xea
t sur images
'
}
doc_ascii
=
'
{
"
quux
"
:
"
Arr
\\
u00eat sur images
"
}
'
doc_unicode
=
u
'
{
"
quux
"
:
"
Arr
\xea
t sur images
"
}
'
self
.
assertEquals
(
json
.
dumps
(
doc1
),
doc_ascii
)
self
.
assertEquals
(
json
.
dumps
(
doc2
),
doc_ascii
)
self
.
assertEquals
(
json
.
dumps
(
doc1
,
ensure_ascii
=
False
),
doc_unicode
)
self
.
assertEquals
(
json
.
dumps
(
doc2
,
ensure_ascii
=
False
),
doc_unicode
)
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