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

« back to all changes in this revision

Viewing changes to Lib/io.py

  • 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:
124
124
    returned as strings, the bytes having been first decoded using a
125
125
    platform-dependent encoding or using the specified encoding if given.
126
126
 
127
 
    buffering is an optional integer used to set the buffering policy. By
128
 
    default full buffering is on. Pass 0 to switch buffering off (only
129
 
    allowed in binary mode), 1 to set line buffering, and an integer > 1
130
 
    for full buffering.
 
127
    buffering is an optional integer used to set the buffering policy.
 
128
    Pass 0 to switch buffering off (only allowed in binary mode), 1 to select
 
129
    line buffering (only usable in text mode), and an integer > 1 to indicate
 
130
    the size of a fixed-size chunk buffer.  When no buffering argument is
 
131
    given, the default buffering policy works as follows:
 
132
 
 
133
    * Binary files are buffered in fixed-size chunks; the size of the buffer
 
134
      is chosen using a heuristic trying to determine the underlying device's
 
135
      "block size" and falling back on `io.DEFAULT_BUFFER_SIZE`.
 
136
      On many systems, the buffer will typically be 4096 or 8192 bytes long.
 
137
 
 
138
    * "Interactive" text files (files for which isatty() returns True)
 
139
      use line buffering.  Other text files use the policy described above
 
140
      for binary files.
131
141
 
132
142
    encoding is the name of the encoding used to decode or encode the
133
143
    file. This should only be used in text mode. The default encoding is
870
880
        elif pos < 0:
871
881
            raise ValueError("negative truncate position %r" % (pos,))
872
882
        del self._buffer[pos:]
873
 
        return self.seek(pos)
 
883
        return pos
874
884
 
875
885
    def readable(self):
876
886
        return True
1205
1215
        if pos is None:
1206
1216
            pos = self.tell()
1207
1217
        # Use seek to flush the read buffer.
1208
 
        self.seek(pos)
1209
 
        return BufferedWriter.truncate(self)
 
1218
        return BufferedWriter.truncate(self, pos)
1210
1219
 
1211
1220
    def read(self, n=None):
1212
1221
        if n is None:
1657
1666
        self.flush()
1658
1667
        if pos is None:
1659
1668
            pos = self.tell()
1660
 
        self.seek(pos)
1661
 
        return self.buffer.truncate()
 
1669
        return self.buffer.truncate(pos)
1662
1670
 
1663
1671
    def seek(self, cookie, whence=0):
1664
1672
        if self.closed: