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
e3c63740aca5
Commit
a8d489d4
authored
Sep 30, 2014
by
Rémi Cardona
Browse files
[py3k] Replace uses of 'unicode' and 'str'
Related to #268148.
parent
bf4de921620e
Changes
1
Hide whitespace changes
Inline
Side-by-side
__init__.py
View file @
e3c63740
...
...
@@ -38,6 +38,7 @@ import string
import
codecs
from
io
import
BytesIO
from
six
import
text_type
,
binary_type
from
six.moves.html_entities
import
name2codepoint
try
:
...
...
@@ -136,7 +137,7 @@ def html_escape(data):
def
xml_escape
(
data
):
"""escapes XML forbidden characters in attributes and PCDATA"""
if
isinstance
(
data
,
unicod
e
):
if
isinstance
(
data
,
text_typ
e
):
data
=
data
.
translate
(
ESC_UCAR_TABLE
)
else
:
data
=
data
.
translate
(
ESC_CAR_TABLE
)
...
...
@@ -158,7 +159,7 @@ class TransformData(object):
self
.
data
=
data
self
.
mimetype
=
mimetype
self
.
encoding
=
encoding
if
not
self
.
is_binary
()
and
not
encoding
and
not
isinstance
(
self
.
data
,
unicod
e
):
if
not
self
.
is_binary
()
and
not
encoding
and
not
isinstance
(
self
.
data
,
text_typ
e
):
self
.
encoding
=
guess_encoding
(
data
)
def
get
(
self
,
attr
,
default
=
None
):
...
...
@@ -167,7 +168,7 @@ class TransformData(object):
def
decode
(
self
,
force
=
False
):
"""return the data as an unicode string"""
if
isinstance
(
self
.
data
,
unicod
e
):
if
isinstance
(
self
.
data
,
text_typ
e
):
return
self
.
data
if
force
:
if
self
.
encoding
in
BINARY_ENCODINGS
:
...
...
@@ -184,7 +185,7 @@ class TransformData(object):
def
encode
(
self
,
encoding
=
None
):
"""return the data as an encoded string"""
if
(
encoding
is
None
or
self
.
encoding
==
encoding
)
and
\
isinstance
(
self
.
data
,
str
):
isinstance
(
self
.
data
,
binary_type
):
return
self
.
data
encoding
=
encoding
or
self
.
encoding
or
'utf8'
return
self
.
decode
().
encode
(
encoding
)
...
...
Write
Preview
Markdown
is supported
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