Author: Carl Friedrich Bolz <[email protected]>
Branch: space-newtext
Changeset: r88123:8a20e656b14d
Date: 2016-11-03 14:59 +0100
http://bitbucket.org/pypy/pypy/changeset/8a20e656b14d/

Log:    _file

diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -57,7 +57,7 @@
         if self.space.sys.track_resources:
             w_repr = self.space.repr(self)
             str_repr = self.space.str_w(w_repr)
-            w_msg = self.space.wrap("WARNING: unclosed file: " + str_repr)
+            w_msg = self.space.newtext("WARNING: unclosed file: " + str_repr)
             self.space.resource_warning(w_msg, self.w_tb)
         #
         try:
@@ -159,7 +159,7 @@
 
     def direct_fdopen(self, fd, mode='r', buffering=-1):
         self.direct_close()
-        self.w_name = self.space.wrap('<fdopen>')
+        self.w_name = self.space.newtext('<fdopen>')
         self.check_mode_ok(mode)
         stream = streamio.fdopen_as_stream(fd, mode, buffering,
                                            signal_checker(self.space))
@@ -311,9 +311,9 @@
             if space.isinstance_w(w_data, space.w_unicode):
                 w_errors = w_encoding = None
                 if self.encoding:
-                    w_encoding = space.wrap(self.encoding)
+                    w_encoding = space.newtext(self.encoding)
                 if self.errors:
-                    w_errors = space.wrap(self.errors)
+                    w_errors = space.newtext(self.errors)
                 w_data = space.call_method(w_data, "encode",
                                            w_encoding, w_errors)
             data = space.charbuf_w(w_data)
@@ -349,9 +349,9 @@
     _exposed_method_names = []
 
     def _decl(class_scope, name, docstring,
-              wrapresult="space.wrap(result)"):
+              wrapresult="space.newtext(result)"):
         # hack hack to build a wrapper around the direct_xxx methods.
-        # The wrapper adds lock/unlock calls and a space.wrap() on
+        # The wrapper adds lock/unlock calls and a wraps
         # the result, conversion of stream errors to OperationErrors,
         # and has the specified docstring and unwrap_spec.
         direct_fn = class_scope['direct_' + name]
@@ -392,9 +392,11 @@
         class_scope['_exposed_method_names'].append(name)
 
 
-    _decl(locals(), "__init__", """Opens a file.""")
+    _decl(locals(), "__init__", """Opens a file.""",
+          wrapresult="space.w_None")
 
-    _decl(locals(), "__enter__", """__enter__() -> self.""")
+    _decl(locals(), "__enter__", """__enter__() -> self.""",
+          wrapresult="self")
 
     _decl(locals(), "close",
         """close() -> None or (perhaps) an integer.  Close the file.
@@ -402,7 +404,8 @@
 Sets data attribute .closed to True.  A closed file cannot be used for
 further I/O operations.  close() may be called more than once without
 error.  Some kinds of file objects (for example, opened by popen())
-may return an exit status upon closing.""")
+may return an exit status upon closing.""",
+          wrapresult="space.w_None")
         # NB. close() needs to use the stream lock to avoid double-closes or
         # close-while-another-thread-uses-it.
 
@@ -410,13 +413,16 @@
     _decl(locals(), "fileno",
         '''fileno() -> integer "file descriptor".
 
-This is needed for lower-level file interfaces, such os.read().''')
+This is needed for lower-level file interfaces, such os.read().''',
+          wrapresult="space.newint(result)")
 
     _decl(locals(), "flush",
-        """flush() -> None.  Flush the internal I/O buffer.""")
+        """flush() -> None.  Flush the internal I/O buffer.""",
+        wrapresult="space.w_None")
 
     _decl(locals(), "isatty",
-        """isatty() -> true or false.  True if the file is connected to a tty 
device.""")
+        """isatty() -> true or false.  True if the file is connected to a tty 
device.""",
+        wrapresult="space.newbool(result)")
 
     _decl(locals(), "next",
         """next() -> the next line in the file, or raise StopIteration""")
@@ -429,7 +435,8 @@
 may be returned, even if no size parameter was given.""")
 
     _decl(locals(), "readinto",
-        """readinto(buf) -> length.  Read into the given read-write buffer.""")
+        """readinto(buf) -> length.  Read into the given read-write buffer.""",
+        wrapresult="result")
 
     _decl(locals(), "readline",
         """readline([size]) -> next line from the file, as a string.
@@ -456,31 +463,37 @@
 seeking beyond the end of a file).  If the file is opened in text mode,
 only offsets returned by tell() are legal.  Use of other offsets causes
 undefined behavior.
-Note that not all file objects are seekable.""")
+Note that not all file objects are seekable.""",
+        wrapresult="space.w_None")
 
     _decl(locals(), "tell",
-        "tell() -> current file position, an integer (may be a long integer).")
+        "tell() -> current file position, an integer (may be a long integer).",
+        wrapresult="space.newint(result)")
 
     _decl(locals(), "truncate",
         """truncate([size]) -> None.  Truncate the file to at most size bytes.
 
-Size defaults to the current file position, as returned by tell().""")
+Size defaults to the current file position, as returned by tell().""",
+        wrapresult="space.w_None")
 
     _decl(locals(), "write",
         """write(str) -> None.  Write string str to file.
 
 Note that due to buffering, flush() or close() may be needed before
-the file on disk reflects the data written.""")
+the file on disk reflects the data written.""",
+        wrapresult="space.w_None")
 
     _decl(locals(), "__iter__",
         """Iterating over files, as in 'for line in f:', returns each line of
-the file one by one.""")
+the file one by one.""",
+        wrapresult="result")
 
     _decl(locals(), "xreadlines",
         """xreadlines() -> returns self.
 
 For backward compatibility. File objects now include the performance
-optimizations previously implemented in the xreadlines module.""")
+optimizations previously implemented in the xreadlines module.""",
+        wrapresult="result")
 
     def file__repr__(self):
         if self.stream is None:
@@ -523,7 +536,7 @@
                                 "writelines() argument must be a sequence of "
                                 "strings")
                 else:
-                    lines[i] = space.wrap(line)
+                    lines[i] = space.newtext(line)
         for w_line in lines:
             self.file_write(w_line)
 
@@ -534,17 +547,17 @@
 def descr_file__new__(space, w_subtype, __args__):
     file = space.allocate_instance(W_File, w_subtype)
     W_File.__init__(file, space)
-    return space.wrap(file)
+    return file
 
 @unwrap_spec(fd=int, mode=str, buffering=int)
 def descr_file_fdopen(space, w_subtype, fd, mode='r', buffering=-1):
     file = space.allocate_instance(W_File, w_subtype)
     W_File.__init__(file, space)
     file.file_fdopen(fd, mode, buffering)
-    return space.wrap(file)
+    return file
 
 def descr_file_closed(space, file):
-    return space.wrap(file.stream is None)
+    return space.newbool(file.stream is None)
 
 def descr_file_newlines(space, file):
     if file.stream:
@@ -554,22 +567,22 @@
     if newlines == 0:
         return space.w_None
     elif newlines == 1:
-        return space.wrap("\r")
+        return space.newtext("\r")
     elif newlines == 2:
-        return space.wrap("\n")
+        return space.newtext("\n")
     elif newlines == 4:
-        return space.wrap("\r\n")
+        return space.newtext("\r\n")
     result = []
     if newlines & 1:
-        result.append(space.wrap('\r'))
+        result.append(space.newtext('\r'))
     if newlines & 2:
-        result.append(space.wrap('\n'))
+        result.append(space.newtext('\n'))
     if newlines & 4:
-        result.append(space.wrap('\r\n'))
+        result.append(space.newtext('\r\n'))
     return space.newtuple(result[:])
 
 def descr_file_softspace(space, file):
-    return space.wrap(file.softspace)
+    return space.newint(file.softspace)
 
 def descr_file_setsoftspace(space, file, w_newvalue):
     file.softspace = space.int_w(w_newvalue)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to