Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
logilab-mtconverter
Commits
a9a6c611aae8
Commit
b5dc23cf
authored
May 04, 2009
by
sylvain.thenault@logilab.fr
Browse files
should not change encoding if specified
parent
bbf46c9b4cc4
Changes
1
Hide whitespace changes
Inline
Side-by-side
__init__.py
View file @
a9a6c611
...
...
@@ -45,7 +45,7 @@ CHARDET_MIN_SIZE = 20
CHARDET_CONFIDENCE_THRESHOLD
=
0.75
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
else
:
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
(
self
.
data
,
unicode
):
...
...
@@ -159,10 +160,10 @@ class TransformData(object):
self
.
data
=
base64
.
decodestring
(
self
.
data
)
self
.
encoding
=
guess_encoding
(
self
.
data
)
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
"""
...
...
Write
Preview
Supports
Markdown
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