Commit b5dc23cf authored by's avatar
Browse files

should not change encoding if specified

parent bbf46c9b4cc4
......@@ -45,7 +45,7 @@ CHARDET_MIN_SIZE = 20
def is_text_mimetype(mimetype):
return (mimetype.startswith('text/') or mimetype in TEXT_MIMETYPES)
return (mimetype.startswith('text/') or mimetype in TEXT_MIMETYPES)
def guess_encoding(buffer, fallbackencoding=None):
"""try to guess encoding from a buffer"""
......@@ -72,13 +72,14 @@ def guess_mimetype_and_encoding(format=None, encoding=None, data=None,
if filename and not format:
format, enc = mimetypes.guess_type(filename)
if format:
encoding = enc
if not encoding:
encoding = enc
elif enc:
format = u'application/%s' % enc
format = u'application/octet-stream'
if not encoding and data and format and is_text_mimetype(format):
encoding = guess_encoding(data, fallbackencoding)
encoding = guess_encoding(data, fallbackencoding)
return format, encoding
def html_escape(data):
......@@ -111,7 +112,7 @@ class TransformData(object):
def get(self, attr, default=None):
"""get an optional data attribute"""
return getattr(self, attr, default)
def decode(self, force=False):
"""return the data as an unicode string"""
if isinstance(, unicode):
......@@ -159,10 +160,10 @@ class TransformData(object): = base64.decodestring(
self.encoding = guess_encoding(
class MtConverterError(Exception):
"""base class for this package's errors"""
class MissingBinary(MtConverterError):
"""raised when a system binary on whic rely a transform has not been found
Supports Markdown
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