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
1d35627fe4c7
Commit
37adbd76
authored
Sep 30, 2014
by
Rémi Cardona
Browse files
Use StringIO and BytesIO from io module
Related to #268148.
parent
4cfc2da5d5bd
Changes
4
Hide whitespace changes
Inline
Side-by-side
__init__.py
View file @
1d35627f
...
...
@@ -35,7 +35,7 @@ import re
import
string
import
htmlentitydefs
import
codecs
from
StringIO
import
String
IO
from
io
import
Bytes
IO
try
:
import
chardet
...
...
@@ -197,12 +197,12 @@ class TransformData(object):
def
binary_decode
(
self
):
if
self
.
encoding
==
'gzip'
:
import
gzip
stream
=
gzip
.
GzipFile
(
fileobj
=
String
IO
(
self
.
data
))
stream
=
gzip
.
GzipFile
(
fileobj
=
Bytes
IO
(
self
.
data
))
self
.
data
=
stream
.
read
()
self
.
encoding
=
guess_encoding
(
self
.
data
)
elif
self
.
encoding
==
'bzip2'
:
import
bz2
self
.
data
=
bz2
.
decompress
(
String
IO
(
self
.
data
))
# StringIO or not?
self
.
data
=
bz2
.
decompress
(
Bytes
IO
(
self
.
data
))
# StringIO or not?
self
.
encoding
=
guess_encoding
(
self
.
data
)
elif
self
.
encoding
==
'base64'
:
import
base64
...
...
test/unittest_utils.py
View file @
1d35627f
...
...
@@ -19,7 +19,7 @@
from
logilab.common.testlib
import
TestCase
,
unittest_main
import
locale
from
StringIO
import
String
IO
from
io
import
Bytes
IO
from
logilab.mtconverter
import
*
SPECIAL_CHARS
=
{
...
...
@@ -76,20 +76,20 @@ class HtmlEscapeTC(TestCase):
class
GuessEncodingTC
(
TestCase
):
def
test_emacs_style_declaration
(
self
):
data
=
'''# -*- coding: latin1 -*-'''
data
=
b
'''# -*- coding: latin1 -*-'''
self
.
assertEqual
(
guess_encoding
(
data
),
'latin1'
)
def
test_emacs_style_declaration_stringIO
(
self
):
data
=
'''# -*- coding: latin1 -*-'''
self
.
assertEqual
(
guess_encoding
(
String
IO
(
data
)),
'latin1'
)
data
=
b
'''# -*- coding: latin1 -*-'''
self
.
assertEqual
(
guess_encoding
(
Bytes
IO
(
data
)),
'latin1'
)
def
test_xml_style_declaration
(
self
):
data
=
'''<?xml version="1.0" encoding="latin1"?>
data
=
b
'''<?xml version="1.0" encoding="latin1"?>
<root/>'''
self
.
assertEqual
(
guess_encoding
(
data
),
'latin1'
)
def
test_html_style_declaration
(
self
):
data
=
'''<html xmlns="http://www.w3.org/1999/xhtml" xmlns:erudi="http://www.logilab.fr/" xml:lang="fr" lang="fr">
data
=
b
'''<html xmlns="http://www.w3.org/1999/xhtml" xmlns:erudi="http://www.logilab.fr/" xml:lang="fr" lang="fr">
<head>
<base href="http://intranet.logilab.fr/jpl/" /><meta http-equiv="content-type" content="text/html; charset=latin1"/>
</head>
...
...
@@ -99,7 +99,7 @@ class GuessEncodingTC(TestCase):
self
.
assertEqual
(
guess_encoding
(
data
),
'latin1'
)
def
test_bad_detection
(
self
):
data
=
'''class SchemaViewer(object):
data
=
b
'''class SchemaViewer(object):
"""return an ureport layout for some part of a schema"""
def __init__(self, req=None, encoding=None):
'''
...
...
transforms/piltransforms.py
View file @
1d35627f
...
...
@@ -17,7 +17,7 @@
# with logilab-mtconverter. If not, see <http://www.gnu.org/licenses/>.
"""PIL based transformations for images"""
from
StringIO
import
String
IO
from
io
import
Bytes
IO
from
PIL
import
Image
...
...
@@ -30,13 +30,13 @@ class PILTransform(Transform):
def
_convert
(
self
,
trdata
):
newwidth
=
trdata
.
get
(
'width'
,
None
)
newheight
=
trdata
.
get
(
'height'
,
None
)
pilimg
=
Image
.
open
(
String
IO
(
trdata
.
data
))
pilimg
=
Image
.
open
(
Bytes
IO
(
trdata
.
data
))
if
self
.
format
in
[
'jpeg'
,
'ppm'
]:
pilimg
.
draft
(
"RGB"
,
pilimg
.
size
)
pilimg
=
pilimg
.
convert
(
"RGB"
)
if
newwidth
or
newheight
:
pilimg
.
thumbnail
((
newwidth
,
newheight
),
Image
.
ANTIALIAS
)
stream
=
String
IO
()
stream
=
Bytes
IO
()
pilimg
.
save
(
stream
,
self
.
format
)
return
stream
.
getvalue
()
...
...
transforms/python.py
View file @
1d35627f
...
...
@@ -33,7 +33,7 @@ Original code from active state recipe
"""
import
keyword
,
token
,
tokenize
from
cStringIO
import
StringIO
from
io
import
StringIO
_KEYWORD
=
token
.
NT_OFFSET
+
1
_TEXT
=
token
.
NT_OFFSET
+
2
...
...
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