Commit f31e370f by Syed Hasan raza

Merge pull request #12607 from edx/shr/bug/PLAT-1040-video-module-non-ASCII-values-fixed

Fixed logging and unicode handling
parents 962fa807 745e4815
...@@ -758,6 +758,14 @@ class VideoExportTestCase(VideoDescriptorTestBase): ...@@ -758,6 +758,14 @@ class VideoExportTestCase(VideoDescriptorTestBase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
self.descriptor.definition_to_xml(None) self.descriptor.definition_to_xml(None)
def test_export_to_xml_unicode_characters(self):
"""
Test XML export handles the unicode characters.
"""
self.descriptor.display_name = '这是文'
xml = self.descriptor.definition_to_xml(None)
self.assertEqual(xml.get('display_name'), u'\u8fd9\u662f\u6587')
class VideoDescriptorIndexingTestCase(unittest.TestCase): class VideoDescriptorIndexingTestCase(unittest.TestCase):
""" """
......
...@@ -38,7 +38,7 @@ from xmodule.exceptions import NotFoundError ...@@ -38,7 +38,7 @@ from xmodule.exceptions import NotFoundError
from xmodule.contentstore.content import StaticContent from xmodule.contentstore.content import StaticContent
from .transcripts_utils import VideoTranscriptsMixin, Transcript, get_html5_ids from .transcripts_utils import VideoTranscriptsMixin, Transcript, get_html5_ids
from .video_utils import create_youtube_string, get_poster, rewrite_video_url from .video_utils import create_youtube_string, get_poster, rewrite_video_url, format_xml_exception_message
from .bumper_utils import bumperize from .bumper_utils import bumperize
from .video_xfields import VideoFields from .video_xfields import VideoFields
from .video_handlers import VideoStudentViewHandlers, VideoStudioViewHandlers from .video_handlers import VideoStudentViewHandlers, VideoStudioViewHandlers
...@@ -563,14 +563,16 @@ class VideoDescriptor(VideoFields, VideoTranscriptsMixin, VideoStudioViewHandler ...@@ -563,14 +563,16 @@ class VideoDescriptor(VideoFields, VideoTranscriptsMixin, VideoStudioViewHandler
if key in self.fields and self.fields[key].is_set_on(self): if key in self.fields and self.fields[key].is_set_on(self):
try: try:
xml.set(key, unicode(value)) xml.set(key, unicode(value))
except ValueError as exception: except UnicodeDecodeError:
exception_message = "{message}, Block-location:{location}, Key:{key}, Value:{value}".format( exception_message = format_xml_exception_message(self.location, key, value)
message=exception.message, log.exception(exception_message)
location=unicode(self.location), # If exception is UnicodeDecodeError set value using unicode 'utf-8' scheme.
key=key, log.info("Setting xml value using 'utf-8' scheme.")
value=unicode(value) xml.set(key, unicode(value, 'utf-8'))
) except ValueError:
raise ValueError(exception_message) exception_message = format_xml_exception_message(self.location, key, value)
log.exception(exception_message)
raise
for source in self.html5_sources: for source in self.html5_sources:
ele = etree.Element('source') ele = etree.Element('source')
......
...@@ -98,6 +98,19 @@ def get_poster(video): ...@@ -98,6 +98,19 @@ def get_poster(video):
return poster return poster
def format_xml_exception_message(location, key, value):
"""
Generate exception message for VideoDescriptor class which will use for ValueError and UnicodeDecodeError
when setting xml attributes.
"""
exception_message = "Block-location:{location}, Key:{key}, Value:{value}".format(
location=unicode(location),
key=key,
value=value
)
return exception_message
def set_query_parameter(url, param_name, param_value): def set_query_parameter(url, param_name, param_value):
""" """
Given a URL, set or replace a query parameter and return the Given a URL, set or replace a query parameter and return the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment