Commits

Dan Villiom Podlaski Christiansen committed 1502aef

New patch.

  • Participants
  • Parent commits fd9a31e

Comments (0)

Files changed (2)

File PyFile_GetLine.diff

+# HG changeset patch
+# Parent 75c929374e5954f5e52618825c074901e83a8652
+# User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
+Add PyFile_GetLine() to cpyext.
+
+
+diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
+--- a/pypy/module/cpyext/object.py
++++ b/pypy/module/cpyext/object.py
+@@ -438,3 +438,36 @@ def PyFile_FromString(space, filename, m
+     w_mode = space.wrap(rffi.charp2str(mode))
+     return space.call_method(space.builtin, 'file', w_filename, w_mode)
+ 
++@cpython_api([PyObject, rffi.INT_real], PyObject)
++def PyFile_GetLine(space, w_obj, n):
++    """
++    Equivalent to p.readline([n]), this function reads one line from the
++    object p.  p may be a file object or any object with a readline()
++    method.  If n is 0, exactly one line is read, regardless of the length of
++    the line.  If n is greater than 0, no more than n bytes will be read
++    from the file; a partial line can be returned.  In both cases, an empty string
++    is returned if the end of the file is reached immediately.  If n is less than
++    0, however, one line is read regardless of length, but EOFError is
++    raised if the end of the file is reached immediately."""
++    try:
++        w_meth = space.getattr(w_obj, space.wrap('readline'))
++    except OperationError:
++        raise OperationError(
++            space.w_TypeError, space.wrap(
++            "argument must be a file, or have a readline() method."))
++
++    if n > 0:
++        return space.call_method(p, 'readline', n)
++    elif n == 0:
++        return space.call_method(p, 'readline')
++    else:
++        r = space.call_method(p, 'readline')
++        offset = space.int_w(space.call_method(p, 'readline'))
++
++    if fd < 0:
++        raise OperationError(
++            space.w_ValueError, space.wrap(
++            "file descriptor cannot be a negative integer"))
++
++    return rffi.cast(rffi.INT_real, fd)
++        t = 
+diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py
+--- a/pypy/module/cpyext/stubs.py
++++ b/pypy/module/cpyext/stubs.py
+@@ -857,22 +857,6 @@ def PyFile_DecUseCount(space, p):
+     """
+     raise NotImplementedError
+ 
+-@cpython_api([PyObject, rffi.INT_real], PyObject)
+-def PyFile_GetLine(space, p, n):
+-    """
+-    
+-    
+-    
+-    Equivalent to p.readline([n]), this function reads one line from the
+-    object p.  p may be a file object or any object with a readline()
+-    method.  If n is 0, exactly one line is read, regardless of the length of
+-    the line.  If n is greater than 0, no more than n bytes will be read
+-    from the file; a partial line can be returned.  In both cases, an empty string
+-    is returned if the end of the file is reached immediately.  If n is less than
+-    0, however, one line is read regardless of length, but EOFError is
+-    raised if the end of the file is reached immediately."""
+-    raise NotImplementedError
+-
+ @cpython_api([PyObject], PyObject)
+ def PyFile_Name(space, p):
+     """Return the name of the file specified by p as a string object."""
 no-macports.diff
 ldflags.diff
 strip-x.diff
+PyFile_GetLine.diff #+incomplete