Skip to content

Commit

Permalink
Python: fixed Plot._repr_svg_() and Nexus.get() on Python 3.x, closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
ntamas committed Dec 2, 2014
1 parent 4784c5d commit 037f898
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
14 changes: 11 additions & 3 deletions interfaces/python/igraph/compat.py
Expand Up @@ -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
"""

Expand Down Expand Up @@ -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
7 changes: 3 additions & 4 deletions interfaces/python/igraph/drawing/__init__.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down
12 changes: 5 additions & 7 deletions interfaces/python/igraph/remote/nexus.py
Expand Up @@ -11,15 +11,14 @@
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
from urllib import urlencode
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

Expand All @@ -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
"""

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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')]
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 037f898

Please sign in to comment.