Merge pull request #21701 from edx/python3-swarm

Python3 swarm
This commit is contained in:
Feanil Patel
2019-09-19 10:23:04 -04:00
committed by GitHub
40 changed files with 199 additions and 142 deletions

View File

@@ -270,7 +270,7 @@ class StaticContent(object):
if query_val.startswith("/static/"):
new_val = StaticContent.get_canonicalized_asset_path(
course_key, query_val, base_url, excluded_exts, encode=False)
updated_query_params.append((query_name, new_val))
updated_query_params.append((query_name, new_val.encode('utf-8')))
else:
# Make sure we're encoding Unicode strings down to their byte string
# representation so that `urlencode` can handle it.
@@ -286,11 +286,11 @@ class StaticContent(object):
# Only encode this if told to. Important so that we don't double encode
# when working with paths that are in query parameters.
asset_path = asset_path.encode('utf-8')
if encode:
asset_path = asset_path.encode('utf-8')
asset_path = quote_plus(asset_path, '/:+@')
return urlunparse(('', base_url.encode('utf-8'), asset_path, params, urlencode(updated_query_params), ''))
return urlunparse(('', base_url, asset_path, params, urlencode(updated_query_params), ''))
def stream_data(self):
yield self._data

View File

@@ -99,7 +99,10 @@ class MongoContentStore(ContentStore):
import_path=content.import_path,
# getattr b/c caching may mean some pickled instances don't have attr
locked=getattr(content, 'locked', False)) as fp:
if hasattr(content.data, '__iter__'):
# It seems that this code thought that only some specific object would have the `__iter__` attribute
# but the bytes object in python 3 has one and should not use the chunking logic.
if hasattr(content.data, '__iter__') and not isinstance(content.data, six.binary_type):
for chunk in content.data:
fp.write(chunk)
else:

View File

@@ -1298,7 +1298,8 @@ class ModuleStoreWriteBase(ModuleStoreReadBase, ModuleStoreWrite):
result = defaultdict(dict)
if fields is None:
return result
cls = self.mixologist.mix(XBlock.load_class(category, select=prefer_xmodules))
classes = XBlock.load_class(category, select=prefer_xmodules)
cls = self.mixologist.mix(classes)
for field_name, value in six.iteritems(fields):
field = getattr(cls, field_name)
result[field.scope][field_name] = value

View File

@@ -126,7 +126,7 @@ def save_subs_to_store(subs, subs_id, item, language='en'):
Returns: location of saved subtitles.
"""
filedata = json.dumps(subs, indent=2)
filedata = json.dumps(subs, indent=2).encode('utf-8')
filename = subs_filename(subs_id, language)
return save_to_store(filedata, filename, 'application/json', item.location)