Skip to content

Commit 8aa3f25

Browse files
author
Ryan Patrick Kyle
committed
↔️ added byteify fn to prevent str >> unicode
🐛 modified prop_names address trailing whitespace 🔧 flake8 and pylint edits 🚿 pylint edits
1 parent b9552ab commit 8aa3f25

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

dash/development/_r_components_generation.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def generate_class_string(name, props, project_shortname, prefix):
142142
'\'{}\''.format(p)
143143
for p in prop_keys
144144
if '*' not in p and
145-
p != 'setProps' + ['**kwargs']
145+
p not in ['setProps']
146146
)
147147

148148
# in R, we set parameters with no defaults to NULL
@@ -161,8 +161,7 @@ def generate_class_string(name, props, project_shortname, prefix):
161161
# Filter props to remove those we don't want to expose
162162
for item in prop_keys[:]:
163163
if item.endswith('-*') \
164-
or item in r_keywords \
165-
or item == 'setProps':
164+
or item in r_keywords + ['setProps']:
166165
prop_keys.remove(item)
167166

168167
default_argtext += ", ".join(

dash/development/component_generator.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def generate_components(components_source, project_shortname,
6565
file=sys.stderr)
6666
sys.exit(1)
6767

68-
metadata = json.loads(out.decode(), object_pairs_hook=OrderedDict)
68+
jsondata_unicode = json.loads(out.decode(), object_pairs_hook=OrderedDict)
69+
metadata = byteify(jsondata_unicode)
70+
6971
generator_methods = [generate_class_file]
7072

7173
if rprefix:
@@ -89,7 +91,8 @@ def generate_components(components_source, project_shortname,
8991

9092
if rprefix:
9193
with open('package.json', 'r') as f:
92-
pkg_data = json.load(f, object_pairs_hook=OrderedDict)
94+
jsondata_unicode = json.load(f, object_pairs_hook=OrderedDict)
95+
pkg_data = byteify(jsondata_unicode)
9396

9497
generate_exports(
9598
project_shortname, components, metadata, pkg_data, prefix
@@ -133,5 +136,16 @@ def cli():
133136
rprefix=args.r_prefix)
134137

135138

139+
def byteify(input_object):
140+
if isinstance(input_object, dict):
141+
return {byteify(key): byteify(value)
142+
for key, value in input_object.iteritems()}
143+
elif isinstance(input_object, list):
144+
return [byteify(element) for element in input_object]
145+
elif isinstance(input_object, unicode):
146+
return input_object.encode('utf-8')
147+
return input_object
148+
149+
136150
if __name__ == '__main__':
137151
cli()

0 commit comments

Comments
 (0)