[Zope3-checkins]
SVN: Zope3/branches/zipimport-support/src/zope/filereference/
adjust the defaults and lineend handling so that text/binary
mode is handled
Fred L. Drake, Jr.
fdrake at gmail.com
Wed Nov 9 18:12:34 EST 2005
Log message for revision 40016:
adjust the defaults and lineend handling so that text/binary mode is handled
the same way as for __builtin__.open()
Changed:
U Zope3/branches/zipimport-support/src/zope/filereference/interfaces.py
U Zope3/branches/zipimport-support/src/zope/filereference/reference.py
-=-
Modified: Zope3/branches/zipimport-support/src/zope/filereference/interfaces.py
===================================================================
--- Zope3/branches/zipimport-support/src/zope/filereference/interfaces.py 2005-11-09 22:57:41 UTC (rev 40015)
+++ Zope3/branches/zipimport-support/src/zope/filereference/interfaces.py 2005-11-09 23:12:34 UTC (rev 40016)
@@ -21,7 +21,7 @@
class IResourceReference(zope.interface.Interface):
- def open(mode="rb"):
+ def open(mode="r"):
"""Open the referenced resource, returning a file-like object.
Only 'read' modes are supported.
Modified: Zope3/branches/zipimport-support/src/zope/filereference/reference.py
===================================================================
--- Zope3/branches/zipimport-support/src/zope/filereference/reference.py 2005-11-09 22:57:41 UTC (rev 40015)
+++ Zope3/branches/zipimport-support/src/zope/filereference/reference.py 2005-11-09 23:12:34 UTC (rev 40016)
@@ -53,7 +53,7 @@
return os.path.isfile(path)
-def open(path, mode="rb"):
+def open(path, mode="r"):
if not mode.startswith("r"):
raise ValueError("`mode` must be a read-only mode")
if IResourceReference.providedBy(path):
@@ -99,7 +99,7 @@
path = str(self) + other
return self.__class__(path)
- def open(self, mode="rb"):
+ def open(self, mode="r"):
return __builtin__.open(self, mode)
def isfile(self):
@@ -131,7 +131,7 @@
self._relpath = relpath
return self
- def open_pkg_resources(self, mode="rb"):
+ def open_pkg_resources(self, mode="r"):
return _open_packaged_resource(
self,
mode,
@@ -139,7 +139,7 @@
self._package.__name__,
self._relpath)
- def open_path_or_loader(self, mode="rb"):
+ def open_path_or_loader(self, mode="r"):
try:
loader = self._package.__loader__
except AttributeError:
@@ -154,7 +154,7 @@
return _open_packaged_resource(
self, mode, loader.get_data, filename)
- def open(self, mode="rb"):
+ def open(self, mode="r"):
#
# This separate wrapper method is used so that this can always
# be tested for the case when pkg_resources is not available.
@@ -242,7 +242,7 @@
self._loader = package.__loader__
return self
- def open(self, mode="rb"):
+ def open(self, mode="r"):
dir = os.path.dirname(self._package.__file__)
filename = os.path.join(dir, self._relpath)
return _open_packaged_resource(
@@ -282,6 +282,8 @@
raise IOError(errno.ENOENT, "file not found", self)
else:
raise
+ if ("b" not in mode) and os.linesep != "\n":
+ data = data.replace(os.linesep, "\n")
f = StringIO.StringIO(data)
f.name = self
f.mode = mode
More information about the Zope3-Checkins
mailing list