Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
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
go
Commits
404d4915
Commit
404d4915
authored
May 13, 2011
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
codereview: handle 'null as missing field' in rietveld json
R=golang-dev, r CC=golang-dev
https://golang.org/cl/4543046
parent
3b4a8ff6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
5 deletions
+15
-5
lib/codereview/codereview.py
lib/codereview/codereview.py
+15
-5
No files found.
lib/codereview/codereview.py
View file @
404d4915
...
@@ -2025,25 +2025,35 @@ def JSONGet(ui, path):
...
@@ -2025,25 +2025,35 @@ def JSONGet(ui, path):
try
:
try
:
data
=
MySend
(
path
,
force_auth
=
False
)
data
=
MySend
(
path
,
force_auth
=
False
)
typecheck
(
data
,
str
)
typecheck
(
data
,
str
)
d
=
coerce_to_utf8
(
json
.
loads
(
data
))
d
=
fix_json
(
json
.
loads
(
data
))
except
:
except
:
ui
.
warn
(
"JSONGet %s: %s
\
n
"
%
(
path
,
ExceptionDetail
()))
ui
.
warn
(
"JSONGet %s: %s
\
n
"
%
(
path
,
ExceptionDetail
()))
return
None
return
None
return
d
return
d
def
coerce_to_utf8
(
x
):
# Clean up json parser output to match our expectations:
# * all strings are UTF-8-encoded str, not unicode.
# * missing fields are missing, not None,
# so that d.get("foo", defaultvalue) works.
def
fix_json
(
x
):
if
type
(
x
)
in
[
str
,
int
,
float
,
bool
,
type
(
None
)]:
if
type
(
x
)
in
[
str
,
int
,
float
,
bool
,
type
(
None
)]:
pass
pass
elif
type
(
x
)
is
unicode
:
elif
type
(
x
)
is
unicode
:
x
=
x
.
encode
(
"utf-8"
)
x
=
x
.
encode
(
"utf-8"
)
elif
type
(
x
)
is
list
:
elif
type
(
x
)
is
list
:
for
i
in
range
(
len
(
x
)):
for
i
in
range
(
len
(
x
)):
x
[
i
]
=
coerce_to_utf8
(
x
[
i
])
x
[
i
]
=
fix_json
(
x
[
i
])
elif
type
(
x
)
is
dict
:
elif
type
(
x
)
is
dict
:
todel
=
[]
for
k
in
x
:
for
k
in
x
:
x
[
k
]
=
coerce_to_utf8
(
x
[
k
])
if
x
[
k
]
is
None
:
todel
.
append
(
k
)
else
:
x
[
k
]
=
fix_json
(
x
[
k
])
for
k
in
todel
:
del
x
[
k
]
else
:
else
:
raise
util
.
Abort
(
"unknown type "
+
str
(
type
(
x
))
+
" in
coerce_to_utf8
"
)
raise
util
.
Abort
(
"unknown type "
+
str
(
type
(
x
))
+
" in
fix_json
"
)
if
type
(
x
)
is
str
:
if
type
(
x
)
is
str
:
x
=
x
.
replace
(
'
\
r
\
n
'
,
'
\
n
'
)
x
=
x
.
replace
(
'
\
r
\
n
'
,
'
\
n
'
)
return
x
return
x
...
...
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