~ubuntu-branches/ubuntu/lucid/python2.6/lucid

« back to all changes in this revision

Viewing changes to Objects/fileobject.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-03-11 13:30:19 UTC
  • mto: (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: james.westby@ubuntu.com-20100311133019-sblbooa3uqrkoe70
Tags: upstream-2.6.5~rc2
ImportĀ upstreamĀ versionĀ 2.6.5~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
173
173
        f->f_encoding = Py_None;
174
174
        Py_INCREF(Py_None);
175
175
        f->f_errors = Py_None;
 
176
        f->readable = f->writable = 0;
 
177
        if (strchr(mode, 'r') != NULL || f->f_univ_newline)
 
178
                f->readable = 1;
 
179
        if (strchr(mode, 'w') != NULL || strchr(mode, 'a') != NULL)
 
180
                f->writable = 1;
 
181
        if (strchr(mode, '+') != NULL)
 
182
                f->readable = f->writable = 1;
176
183
 
177
184
        if (f->f_mode == NULL)
178
185
                return NULL;
487
494
        return NULL;
488
495
}
489
496
 
 
497
static PyObject *
 
498
err_mode(char *action)
 
499
{
 
500
        PyErr_Format(PyExc_IOError, "File not open for %s", action);
 
501
        return NULL;
 
502
}
 
503
 
490
504
/* Refuse regular file I/O if there's data in the iteration-buffer.
491
505
 * Mixing them would cause data to arrive out of order, as the read*
492
506
 * methods don't use the iteration buffer. */
701
715
 
702
716
        if (f->f_fp == NULL)
703
717
                return err_closed();
 
718
        if (!f->writable)
 
719
                return err_mode("writing");
704
720
        if (!PyArg_UnpackTuple(args, "truncate", 0, 1, &newsizeobj))
705
721
                return NULL;
706
722
 
949
965
 
950
966
        if (f->f_fp == NULL)
951
967
                return err_closed();
 
968
        if (!f->readable)
 
969
                return err_mode("reading");
952
970
        /* refuse to mix with f.next() */
953
971
        if (f->f_buf != NULL &&
954
972
            (f->f_bufend - f->f_bufptr) > 0 &&
1018
1036
 
1019
1037
        if (f->f_fp == NULL)
1020
1038
                return err_closed();
 
1039
        if (!f->readable)
 
1040
                return err_mode("reading");
1021
1041
        /* refuse to mix with f.next() */
1022
1042
        if (f->f_buf != NULL &&
1023
1043
            (f->f_bufend - f->f_bufptr) > 0 &&
1389
1409
                PyFileObject *fo = (PyFileObject *)f;
1390
1410
                if (fo->f_fp == NULL)
1391
1411
                        return err_closed();
 
1412
                if (!fo->readable)
 
1413
                        return err_mode("reading");
1392
1414
                /* refuse to mix with f.next() */
1393
1415
                if (fo->f_buf != NULL &&
1394
1416
                    (fo->f_bufend - fo->f_bufptr) > 0 &&
1477
1499
 
1478
1500
        if (f->f_fp == NULL)
1479
1501
                return err_closed();
 
1502
        if (!f->readable)
 
1503
                return err_mode("reading");
1480
1504
        /* refuse to mix with f.next() */
1481
1505
        if (f->f_buf != NULL &&
1482
1506
            (f->f_bufend - f->f_bufptr) > 0 &&
1510
1534
 
1511
1535
        if (f->f_fp == NULL)
1512
1536
                return err_closed();
 
1537
        if (!f->readable)
 
1538
                return err_mode("reading");
1513
1539
        /* refuse to mix with f.next() */
1514
1540
        if (f->f_buf != NULL &&
1515
1541
            (f->f_bufend - f->f_bufptr) > 0 &&
1628
1654
        Py_ssize_t n, n2;
1629
1655
        if (f->f_fp == NULL)
1630
1656
                return err_closed();
 
1657
        if (!f->writable)
 
1658
                return err_mode("writing");
1631
1659
        if (f->f_binary) {
1632
1660
                if (!PyArg_ParseTuple(args, "s*", &pbuf))
1633
1661
                        return NULL;
1665
1693
        assert(seq != NULL);
1666
1694
        if (f->f_fp == NULL)
1667
1695
                return err_closed();
 
1696
        if (!f->writable)
 
1697
                return err_mode("writing");
1668
1698
 
1669
1699
        result = NULL;
1670
1700
        list = NULL;
2105
2135
 
2106
2136
        if (f->f_fp == NULL)
2107
2137
                return err_closed();
 
2138
        if (!f->readable)
 
2139
                return err_mode("reading");
2108
2140
 
2109
2141
        l = readahead_get_line_skip(f, 0, READAHEAD_BUFSIZE);
2110
2142
        if (l == NULL || PyString_GET_SIZE(l) == 0) {