Skip to content

ENH: really really really fix the failing data.py tests #4085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
""" Common api utilities """
"""Common IO api utilities"""

import sys
import urlparse
from pandas.util import py3compat
import urllib2
import zipfile
from contextlib import contextmanager, closing
from StringIO import StringIO

from pandas.util import py3compat

_VALID_URLS = set(urlparse.uses_relative + urlparse.uses_netloc +
urlparse.uses_params)
_VALID_URLS.discard('')
Expand Down Expand Up @@ -84,3 +89,24 @@ def get_filepath_or_buffer(filepath_or_buffer, encoding=None):
return filepath_or_buffer, None

return filepath_or_buffer, None


# ----------------------
# Prevent double closing
if py3compat.PY3:
urlopen = urllib2.urlopen
else:
@contextmanager
def urlopen(*args, **kwargs):
with closing(urllib2.urlopen(*args, **kwargs)) as f:
yield f

# ZipFile is not a context manager for <= 2.6
# must be tuple index here since 2.6 doesn't use namedtuple for version_info
if sys.version_info[1] <= 6:
@contextmanager
def ZipFile(*args, **kwargs):
with closing(zipfile.ZipFile(*args, **kwargs)) as zf:
yield zf
else:
ZipFile = zipfile.ZipFile
Loading