Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Unified Diff: third_party/google-endpoints/future/types/newopen.py

Issue 2666783008: Add google-endpoints to third_party/. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/google-endpoints/future/types/newopen.py
diff --git a/third_party/google-endpoints/future/types/newopen.py b/third_party/google-endpoints/future/types/newopen.py
new file mode 100644
index 0000000000000000000000000000000000000000..8da064274f6650c1ee518d65689635466ae87d30
--- /dev/null
+++ b/third_party/google-endpoints/future/types/newopen.py
@@ -0,0 +1,33 @@
+"""
+A substitute for the Python 3 open() function.
+
+Note that io.open() is more complete but maybe slower. Even so, the
+completeness may be a better default. TODO: compare these
+"""
+
+_builtin_open = open
+
+class newopen(object):
+ """Wrapper providing key part of Python 3 open() interface.
+
+ From IPython's py3compat.py module. License: BSD.
+ """
+ def __init__(self, fname, mode="r", encoding="utf-8"):
+ self.f = _builtin_open(fname, mode)
+ self.enc = encoding
+
+ def write(self, s):
+ return self.f.write(s.encode(self.enc))
+
+ def read(self, size=-1):
+ return self.f.read(size).decode(self.enc)
+
+ def close(self):
+ return self.f.close()
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, etype, value, traceback):
+ self.f.close()
+
« no previous file with comments | « third_party/google-endpoints/future/types/newobject.py ('k') | third_party/google-endpoints/future/types/newrange.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698