diff --git a/interfaces/python/igraph/compat.py b/interfaces/python/igraph/compat.py index 7bb6616bb0..be085557e8 100644 --- a/interfaces/python/igraph/compat.py +++ b/interfaces/python/igraph/compat.py @@ -23,7 +23,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA """ @@ -52,10 +52,18 @@ def setter(self, fset): if v == self: propname = k break - cls_ns[propname] = property(self.fget, fset, self.fdel, - self.__doc__) + cls_ns[propname] = property(self.fget, fset, self.fdel, self.__doc__) return cls_ns[propname] else: property = __builtins__["property"] +############################################################################# +# Providing BytesIO for Python 2.5 +try: + from io import BytesIO +except ImportError: + # We are on Python 2.5 or earlier because Python 2.6 has a BytesIO + # class already + from cStringIO import StringIO + BytesIO = StringIO diff --git a/interfaces/python/igraph/drawing/__init__.py b/interfaces/python/igraph/drawing/__init__.py index 5f31d36d2b..3760d05f0a 100644 --- a/interfaces/python/igraph/drawing/__init__.py +++ b/interfaces/python/igraph/drawing/__init__.py @@ -14,14 +14,13 @@ from __future__ import with_statement -from cStringIO import StringIO from warnings import warn import os import platform import time -from igraph.compat import property +from igraph.compat import property, BytesIO from igraph.configuration import Configuration from igraph.drawing.colors import Palette, palettes from igraph.drawing.graph import DefaultGraphDrawer @@ -346,7 +345,7 @@ def _repr_svg_(self): This method is used by IPython to display this plot inline. """ - io = StringIO() + io = BytesIO() # Create a new SVG surface and use that to get the SVG representation, # which will end up in io surface = cairo.SVGSurface(io, self.bbox.width, self.bbox.height) @@ -357,7 +356,7 @@ def _repr_svg_(self): context.show_page() surface.finish() # Return the raw SVG representation - return io.getvalue() + return io.getvalue().encode("utf-8") @property def bounding_box(self): diff --git a/interfaces/python/igraph/remote/nexus.py b/interfaces/python/igraph/remote/nexus.py index 785c3d588c..c8ec33ddc1 100644 --- a/interfaces/python/igraph/remote/nexus.py +++ b/interfaces/python/igraph/remote/nexus.py @@ -11,7 +11,6 @@ tags, L{NexusConnection.search} to search in the dataset descriptions, or L{NexusConnection.info} to show the info sheet of a dataset.""" -from cStringIO import StringIO from gzip import GzipFile from itertools import izip from textwrap import TextWrapper @@ -19,7 +18,7 @@ from urlparse import urlparse, urlunparse from textwrap import TextWrapper -from igraph.compat import property +from igraph.compat import property, BytesIO from igraph.configuration import Configuration from igraph.utils import multidict @@ -44,7 +43,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA """ @@ -198,8 +197,7 @@ def _ensure_uncompressed(response): compressed = bool(re.match(r'attachment; *filename=.*\.gz\"?$', content_disp)) if compressed: - return GzipFile(fileobj=StringIO(response.read()), mode="rb") - print response.headers + return GzipFile(fileobj=BytesIO(response.read()), mode="rb") return response def _get_response(self, path, params={}, compressed=False): @@ -240,7 +238,7 @@ def _parse_text_response(response): whitespace. Examples: - + >>> d = Nexus._parse_text_response("Id: 17\\nName: foo") >>> sorted(d.items()) [('Id', '17'), ('Name', 'foo')] @@ -297,7 +295,7 @@ def url(self, value): class NexusDatasetInfo(object): """Information about a dataset in the Nexus repository. - + @undocumented: _update_from_multidict, vertices_edges""" def __init__(self, id=None, sid=None, name=None, networks=None,