Commits

Xathos  committed ee3c556

Re-adding all new files (oops)

  • Participants
  • Parent commits b81ad0b

Comments (0)

Files changed (57)

File actors/__init__.py

Empty file added.

File actors/controllers.py

+
+def PlayerController (key_input):
+    pass

File actors/event.py

+
+class Event (object):
+    pass

File actors/tank.py

+from sys import path
+path.append("..")
+from physics.object import GraphicsObject
+
+class Tank (object):
+    pass
+##!/usr/bin/python
+import math
+
+
+class Angle (object):
+    """A simple class to handle angles."""
+    def __init__ (self, degrees = 0.0):
+        self.degrees = float(degrees)
+        self.degrees %= 360.0
+
+    def __repr__ (self):
+        return "Angle(degrees: %0.2f)"%(self.degrees)
+    
+    def __str__ (self):
+        return str(self.degrees)
+    
+    def __add__ (self, other):
+        try:
+            return Angle(self.degrees + other.degrees)
+        except AttributeError:
+            return Angle(self.degrees + other)
+    
+    def __sub__ (self, other):
+        try:
+            return Angle(self.degrees - other.degrees)
+        except AttributeError:
+            return Angle(self.degrees - other)
+            
+    def __mul__ (self, scalar):
+        return Angle(self.degrees * scalar)
+    
+    def __div__ (self, scalar):
+        return Angle(self.degrees / scalar)
+    
+    @property
+    def radians (self):
+        return math.radians(self.degrees)
+    
+    @radians.setter
+    def radians (self, radian_value):
+        self.degrees = math.degrees(radian_value)
+        self.degrees %= 360.0
+
+# Example:
+# 
+# x = Angle(188)
+# print(x.radians / math.pi)
+# x += Angle(90)
+# x /= 2
+# print(x)
+# my_val = x.degrees
+#

File colliders.py

+
+import sys
+sys.path.append("..")
+from extensions import XObject
+from vector2 import Vector2
+from collision import detect_line_collision, LineSegment
+from math import pi, sin, cos, sqrt, acos, asin
+
+#
+# Defines three collider types:
+# 
+# BoxCollider - General purpose, relatively well optimized collider
+# SphereCollider - A circular extension of BoxCollider; may have issues, so don't use it.
+# PolyCollider - A polygon collider, that can represent complex shapes of variable complexity.
+#       Use static PolyColliders for backgrounds; BoxColliders for moving objects.
+#       Note: PolyCollider is more trig heavy than BoxCollider, and is expected to perform
+#       slower than its counterpart.
+
+#
+# Finished:
+#   detect_line_collision()  (the core of the physics system) works flawlessly (AFAIK)
+#   BaseCollider, BoxCollider, and PolyCollider classes are (mostly) finished
+#   LineSegment class is done.
+#
+# Todo List:
+#   Finish collider classes
+#   Physics world/simulation core
+#   Add any remaining collision functionality
+#   Rigidbodies?
+#   Visualization
+#   Stress testing
+#
+#   Fine tuning
+#   Rebuild cantankerous classes around physics engine
+#       'offline' simulation if necessary for performance
+#       (separated 'viewer' and 'simulation' cores)
+
+
+
+class BaseCollider (XObject):
+    def __init__ (self, position, rotation = 0.0):
+        self._position = position
+        self._rotation = rotation
+        self._physics_changes = False
+        self._move_vector = Vector2()
+        self.is_solid = True
+        self.is_static = False
+        self.on_collide = None #Callback function
+        self.xbounds = [position.x, position.x]
+        self.ybounds = [position.y, position.y]
+        # eg: collider.on_collide = lambda self, other, point: DoSomething()
+
+    def move (self, move_vector):
+        self._physics_changes = True
+        self._move_vector = move_vector
+
+    def rotate (self, angle):
+        self._physics_changes = True
+        self._rotation += angle
+        self._rotation %= (pi * 2)
+        self._recalc_points()
+
+    def get_collider_segments (self):
+        return None, None, None
+
+    def _on_collision (self, other_collider, point):
+        if self.on_collide is not None:
+            self.on_collide(self, other_collider, point)
+
+class PolyCollider (BaseCollider):
+    def __init__ (self, position, rotation = 0.0, points = []):
+        BaseCollider.__init__(self, position, rotation)
+        self._cache = (None, None, None)
+        self._points = points
+        
+    def _recalc_points (self):
+        npoints = []
+
+    def move (self, direction_vector):
+        self._physics_changes = True
+        for point in self._points:
+            point += direction_vector
+
+    def rotate (self, angle):
+        self._physics_changes = True
+        self.xbounds = [self.position.x, self.position.x]
+        self.ybounds = [self.position.x, self.position.x]
+        new_rotation = (self._rotation + angle) % (pi * 2)
+
+        newpoints = []
+        for point in self._points:
+            r = point.x / cos(self._rotation)
+            newpoint = Vector2(r * cos(new_rotation), r * sin(new_rotation))
+            if newpoint.x > self.xbounds[1]:
+                self.xbounds[1] = newpoint.x
+            elif newpoint.x < self.xbounds[0]:
+                self.xbounds[0] = newpoint.x
+            if newpoint.y > self.ybounds[1]:
+                self.ybounds[1] = newpoint.y
+            elif newpoint.y < self.ybounds[0]:
+                self.ybounds[0] = newpoint.y
+            newpoints += [newpoint]
+        self._points = newpoints
+
+    def get_collider_segments (self):
+        if self._physics_changes or self.cache[0] is None:
+            if self.is_static:
+                segments = []
+                j = len(self._points - 1)
+                for i in range(len(self.points)):
+                    segments += [LineSegment(self._points[i], self._points[j])]
+                    j = i
+                self.cache = (segments, None, None)
+                return self.cache
+            else:
+                pass
+        else:
+            return self.cache
+
+    def get_collider_segments (self):
+        if move_vector.x != 0 and move_vector.y != 0:
+            cur_segments = []
+            move_segments = []
+            projected_segments = []
+            j = len(self._points - 1)
+            for i in range(len(self._points)):
+                cur_segments += [LineSegment(self._points[i], self._points[j])]
+                move_segments += [LineSegment(self._points[i], self._points[i] + self.move_vector)]
+                projected_segments += [LineSegment(self._points[i] + self.move_vector, self._points[j] + self.move_vector)]
+                j = i
+            return cur_segments, move_segments, projected_segments
+        else:
+            cur_segments = []
+            j = len(self._points - 1)
+            for i in range(len(self._points)):
+                cur_segments += [LineSegment(self._points[i], self._points[j])]
+                j = i
+            return cur_segments, None, None
+        
+            
+class BoxCollider (BaseCollider):
+    def __init__ (self, position, rotation = 0.0, width = 10.0, height = 10.0):
+        BaseCollider.__init__(self, position, rotation)
+        self._width = width
+        self._height = height
+        self._recalc_points()
+
+    def _recalc_points (self):
+        self._points = [Vector2(cos(self._rotation) * self._width, sin(self._rotation) * self._width),
+                        Vector2(cos(self._rotation + pi / 2) * self._height, sin(self._rotation + pi / 2) * self._height),
+                        Vector2(cos(self._rotation + pi) * self._width, sin(self._rotation + pi) * self._width),
+                        Vector2(cos(self._rotation - pi / 2) * self._height, sin(self._rotation - pi / 2) * self._height)]
+
+    def get_collider_segments (self):
+        if move_vector.x != 0 and move_vector.y != 0:
+            cur_segments = []
+            move_segments = []
+            projected_segments = []
+            j = len(self._points - 1)
+            for i in range(len(self._points)):
+                cur_segments += [LineSegment(self._points[i], self._points[j])]
+                move_segments += [LineSegment(self._points[i], self._points[j])]
+                projected_segments += [LineSegment(self._points[i] + self.move_vector, self._points[j] + self.move_vector)]
+                j = i
+            return cur_segments, move_segments, projected_segments
+        else:
+            cur_segments = []
+            j = len(self._points - 1)
+            for i in range(len(self._points)):
+                cur_segments += [LineSegment(self._points[i], self._points[j])]
+                j = i
+            return cur_segments, None, None
+
+    def get_width (self):
+        return self._width
+
+    def set_width (self, value):
+        self._width = value
+        self._recalc_points()
+
+    def get_height (self):
+        return self._height
+
+    def set_height (self, value):
+        self._height = value
+        self._recalc_points()
+
+    def get_rough_bounds (self):
+        if self._height > self._width:
+            return self._height
+        return self._width
+
+class SphereCollider (BoxCollider):
+    def __init__ (self, position, rotation = 0.0, radius = 10.0):
+        BoxCollider.__init__(position, rotation, radius, radius)
+        self.radius = radius
+
+    def _on_collision (self, other, point):
+        dpos = point - self.position
+        if sqrt(dpos.x * dpos.x + dpos.y * dpos.y) > radius:
+            return #Cancel if collision is outside of circle radius
+        super(SphereCollider, self).on_collide(other, point)
+
+#def p (box):
+#    for point in box._points:
+#        print("%0.2f, %0.2f"%(point.x, point.y))
+#
+#box = BoxCollider(Vector2(), 0.0, 100, 50)
+

File colliders.pyc

Binary file added.

File collision.cpp

+
+
+Vector2 detect_line_collision (LineSegment l1, LineSegment l2) {
+    if (l1.cx != 0) {
+        double a = l1.cx; double c = l2.cx;
+        double b = l1.cy; double d = l2.cy;
+        double e = l1.cv; double f = l2.cv;
+    }
+    else if (l2 != 0) {
+        double a = l2.cx; double c = l1.cx;
+        double b = l2.cy; double d = l1.cy;
+        double e = l2.cv; double f = l1.cv;
+    }
+    else
+        return null;
+
+    double x = e / a - b / a * (f - c * e / a) / (d - c * b / a);
+    double y = (f - c * e / a) / (d - c * b / a);
+
+    if (x > ls1.xmax || x < ls1.xmin)
+        return null;
+    if (x > ls2.xmax || x < ls2.xmin)
+        return null;
+    if (y > ls1.ymax || y < ls1.ymin)
+        return null;
+    if (y > ls2.ymax || y < ls2.ymin)
+        return null;
+    return new Vector2(x, y);
+}

File collision.py

+
+from vector2 import Vector2
+from math import sqrt
+
+class LineSegment (object):
+    def __init__ (self, v1, v2):
+        # Two vector points define the line segment:
+        self.v1 = v1
+        self.v2 = v2
+        # The following is used internally:
+        # cx, cy, and cv represent entries in an augumented matrix
+        # (LineSegment stands in for a matrix row)
+        self.cx = -1 * (v1.y - v2.y)
+        self.cy = v1.x - v2.x
+        self.cv = v1.y * (v1.x - v2.x) - v1.x * (v1.y - v2.y)
+        # xbounds and ybounds define the limit of the line segment.
+        if v1.x < v2.x:
+            self.xbounds = (v1.x, v2.x)
+        else:
+            self.xbounds = (v2.x, v1.x)
+        if v1.y < v2.y:
+            self.ybounds = (v1.y, v2.y)
+        else:
+            self.ybounds = (v2.y, v1.y)
+
+    def point_at_x (self, x):
+        y = (self.cv - self.cx * x) / self.cy
+        if x < self.xbounds[0] or x > self.xbounds[1]:
+            return None, Vector2(x, y)
+        if y < self.ybounds[0] or y > self.ybounds[1]:
+            return None, Vector2(x, y)
+        return Vector2(x, y)
+
+    def point_at_y (self, y):
+        x = (self.cv - self.cy * y) / self.cx
+        if x < self.xbounds[0] or x > self.xbounds[1]:
+            return None, Vector2(x, y)
+        if y < self.ybounds[0] or y > self.ybounds[1]:
+            return None, Vector2(x, y)
+        return Vector2(x, y)
+
+    def __repr__ (self):
+        return "LineSegment(%s, %s)"%(repr(self.v1), repr(self.v2))
+
+    def __str__ (self):
+        return "(%s, %s)\n%0.2f %0.2f | %0.2f\nx bounds: %s\ny bounds: %s"%(self.v1,
+                                self.v2, self.cx, self.cy, self.cv, self.xbounds, self.ybounds)
+
+class Ray (LineSegment):
+    def __init__ (self, start_point, end_point):
+        LineSegment.__init__(self, start_point, end_point)
+ #       self.length = 
+
+    def get_length (self):
+        return sqrt((self.v1.x - self.v2.x) ** 2 + (self.v1.y - self.v2.y) ** 2)
+
+    def set_length (self, new_length):
+        pass
+
+
+
+def detect_line_collision (segment1, segment2):
+    #Uses matrix-based solving algorithm
+    #(line segment objects stand in for matrix rows)
+    # cx, cy, and cv correspond to entries in a 2d augumented matrix's rows.
+    #Swap rows if m1.cx == 0
+    if segment1.cx != 0:
+        m = [segment1, segment2]
+    elif segment2.cx != 0:
+        m = [segment2, segment1]
+    else:
+        return None
+       # raise Exception, "Both cx values are zero!"
+    # Divide row1 by row1.cx (set row1.cx to 1)
+    m[0].cy /= m[0].cx
+    m[0].cv /= m[0].cx
+    m[0].cx /= m[0].cx
+    # Add row1 * -row2.cx to row2 (clear row2.cx)
+    m[1].cy -= m[1].cx * m[0].cy
+    m[1].cv -= m[1].cx * m[0].cv
+    m[1].cx -= m[1].cx
+    # Divide row2 by row2.cy (set row2.cy to 1)
+    m[1].cv /= m[1].cy
+    m[1].cy /= m[1].cy
+    # Add row2 * row1.cy to row1 (clear row1.cy)
+    m[0].cv -= m[0].cy * m[1].cv
+    m[0].cy -= m[0].cy
+    #
+    # Matrix is now solved: point of intersection is (row1.cv, row2.cv)
+    #
+    # Next, check to see if solution is within both line segment's x/y bounds:
+    # if this fails, return None; else return the intersection point as a Vector2   
+    if m[0].cv > m[0].xbounds[1] or m[0].cv < m[0].xbounds[0]:
+        return None
+    if m[0].cv > m[1].xbounds[1] or m[0].cv < m[1].xbounds[0]:
+        return None
+    if m[1].cv > m[0].ybounds[1] or m[1].cv < m[0].ybounds[0]:
+        return None
+    if m[1].cv > m[1].ybounds[1] or m[1].cv < m[1].ybounds[0]:
+        return None
+    return Vector2(m[0].cv, m[1].cv)
+
+def condensed_detect_line_collision (segment1, segment2):
+    # Condensed version of detect_line_collision:
+    # Uses algebraic version of the above matrix operations
+     # m1.cx m1.cy | m1.cv -> a b | x
+     # m2.cx m2.cy | m2.cv -> c d | y
+     # x = x / a - b / a * (y - c * x / a) / (d - c * b / a)
+     # y = (y - c * x / a) / (d - c * b / a)
+    if segment1.cx != 0:
+         a = segment1.cx; c = segment2.cx
+         b = segment1.cy; d = segment2.cy
+         x = segment1.cv; y = segment2.cv
+    elif segment2.cx != 0:
+        a = segment2.cx; c = segment1.cx
+        b = segment2.cy; d = segment1.cy
+        x = segment2.cv; d = segment1.cv
+    else:
+        return None
+
+    fx = x / a - b / a * (y - c * x / a) / (d - c * b / a)
+    fy = (y - c * x / a) / (d - c * b / a)
+    if fx > segment1.xbounds[1] or fx < segment1.xbounds[0]:
+        return None
+    if fx > segment2.xbounds[1] or fx < segment2.xbounds[0]:
+        return None
+    if fy > segment1.ybounds[1] or fy < segment1.ybounds[0]:
+        return None
+    if fy > segment2.ybounds[1] or fy < segment2.ybounds[0]:
+        return None
+    return Vector2(fx, fy)
+
+        
+def alt_detect_line_collision (line1_point1, line1_point2, line2_point1, line2_point2):
+    return detect_line_collision(LineSegment(line1_point1, line1_point2),
+                                 _LineSegment(line2_point1, line2_point2))

File collision.pyc

Binary file added.

File docs/Makefile

+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS    =
+SPHINXBUILD   = sphinx-build
+PAPER         =
+BUILDDIR      = build
+
+# Internal variables.
+PAPEROPT_a4     = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS   = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
+# the i18n builder cannot share the environment and doctrees with the others
+I18NSPHINXOPTS  = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
+
+.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
+
+help:
+	@echo "Please use \`make <target>' where <target> is one of"
+	@echo "  html       to make standalone HTML files"
+	@echo "  dirhtml    to make HTML files named index.html in directories"
+	@echo "  singlehtml to make a single large HTML file"
+	@echo "  pickle     to make pickle files"
+	@echo "  json       to make JSON files"
+	@echo "  htmlhelp   to make HTML files and a HTML help project"
+	@echo "  qthelp     to make HTML files and a qthelp project"
+	@echo "  devhelp    to make HTML files and a Devhelp project"
+	@echo "  epub       to make an epub"
+	@echo "  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+	@echo "  latexpdf   to make LaTeX files and run them through pdflatex"
+	@echo "  text       to make text files"
+	@echo "  man        to make manual pages"
+	@echo "  texinfo    to make Texinfo files"
+	@echo "  info       to make Texinfo files and run them through makeinfo"
+	@echo "  gettext    to make PO message catalogs"
+	@echo "  changes    to make an overview of all changed/added/deprecated items"
+	@echo "  linkcheck  to check all external links for integrity"
+	@echo "  doctest    to run all doctests embedded in the documentation (if enabled)"
+
+clean:
+	-rm -rf $(BUILDDIR)/*
+
+html:
+	$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+	@echo
+	@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+dirhtml:
+	$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+	@echo
+	@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+singlehtml:
+	$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+	@echo
+	@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+pickle:
+	$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+	@echo
+	@echo "Build finished; now you can process the pickle files."
+
+json:
+	$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+	@echo
+	@echo "Build finished; now you can process the JSON files."
+
+htmlhelp:
+	$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+	@echo
+	@echo "Build finished; now you can run HTML Help Workshop with the" \
+	      ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+qthelp:
+	$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+	@echo
+	@echo "Build finished; now you can run "qcollectiongenerator" with the" \
+	      ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+	@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Cantankerous.qhcp"
+	@echo "To view the help file:"
+	@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Cantankerous.qhc"
+
+devhelp:
+	$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+	@echo
+	@echo "Build finished."
+	@echo "To view the help file:"
+	@echo "# mkdir -p $$HOME/.local/share/devhelp/Cantankerous"
+	@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Cantankerous"
+	@echo "# devhelp"
+
+epub:
+	$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+	@echo
+	@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+latex:
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+	@echo
+	@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+	@echo "Run \`make' in that directory to run these through (pdf)latex" \
+	      "(use \`make latexpdf' here to do that automatically)."
+
+latexpdf:
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+	@echo "Running LaTeX files through pdflatex..."
+	$(MAKE) -C $(BUILDDIR)/latex all-pdf
+	@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+text:
+	$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+	@echo
+	@echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+man:
+	$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+	@echo
+	@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+texinfo:
+	$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+	@echo
+	@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
+	@echo "Run \`make' in that directory to run these through makeinfo" \
+	      "(use \`make info' here to do that automatically)."
+
+info:
+	$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+	@echo "Running Texinfo files through makeinfo..."
+	make -C $(BUILDDIR)/texinfo info
+	@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
+
+gettext:
+	$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
+	@echo
+	@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
+
+changes:
+	$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+	@echo
+	@echo "The overview file is in $(BUILDDIR)/changes."
+
+linkcheck:
+	$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+	@echo
+	@echo "Link check complete; look for any errors in the above output " \
+	      "or in $(BUILDDIR)/linkcheck/output.txt."
+
+doctest:
+	$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+	@echo "Testing of doctests in the sources finished, look at the " \
+	      "results in $(BUILDDIR)/doctest/output.txt."

File docs/build/doctrees/environment.pickle

Binary file added.

File docs/build/doctrees/getting_started.doctree

Binary file added.

File docs/build/doctrees/getting_started.rst.doctree

Binary file added.

File docs/build/doctrees/index.doctree

Binary file added.

File docs/build/doctrees/test.doctree

Binary file added.

File docs/build/html/.buildinfo

+# Sphinx build info version 1
+# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
+config: f16c684cbbe504575b8ae65df8bdfdf3
+tags: fbb0d17656682115ca4d033fb2f83ba1

File docs/build/html/_modules/index.html

+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>Overview: module code &mdash; Cantankerous 0.1a documentation</title>
+    
+    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
+    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../',
+        VERSION:     '0.1a',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../_static/jquery.js"></script>
+    <script type="text/javascript" src="../_static/underscore.js"></script>
+    <script type="text/javascript" src="../_static/doctools.js"></script>
+    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
+    <link rel="top" title="Cantankerous 0.1a documentation" href="../index.html" /> 
+  </head>
+  <body>
+    <div class="related">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li><a href="../index.html">Cantankerous 0.1a documentation</a> &raquo;</li> 
+      </ul>
+    </div>  
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body">
+            
+  <h1>All modules for which code is available</h1>
+<ul><li><a href="io.html">io</a></li>
+</ul>
+
+          </div>
+        </div>
+      </div>
+      <div class="sphinxsidebar">
+        <div class="sphinxsidebarwrapper">
+<div id="searchbox" style="display: none">
+  <h3>Quick search</h3>
+    <form class="search" action="../search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li><a href="../index.html">Cantankerous 0.1a documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer">
+        &copy; Copyright 2011, Seiji Emery.
+      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
+    </div>
+  </body>
+</html>

File docs/build/html/_modules/io.html

+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>io &mdash; Cantankerous 0.1a documentation</title>
+    
+    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
+    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../',
+        VERSION:     '0.1a',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../_static/jquery.js"></script>
+    <script type="text/javascript" src="../_static/underscore.js"></script>
+    <script type="text/javascript" src="../_static/doctools.js"></script>
+    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
+    <link rel="top" title="Cantankerous 0.1a documentation" href="../index.html" />
+    <link rel="up" title="Module code" href="index.html" /> 
+  </head>
+  <body>
+    <div class="related">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li><a href="../index.html">Cantankerous 0.1a documentation</a> &raquo;</li>
+          <li><a href="index.html" accesskey="U">Module code</a> &raquo;</li> 
+      </ul>
+    </div>  
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body">
+            
+  <h1>Source code for io</h1><div class="highlight"><pre>
+<span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">The io module provides the Python interfaces to stream handling. The</span>
+<span class="sd">builtin open function is defined in this module.</span>
+
+<span class="sd">At the top of the I/O hierarchy is the abstract base class IOBase. It</span>
+<span class="sd">defines the basic interface to a stream. Note, however, that there is no</span>
+<span class="sd">seperation between reading and writing to streams; implementations are</span>
+<span class="sd">allowed to throw an IOError if they do not support a given operation.</span>
+
+<span class="sd">Extending IOBase is RawIOBase which deals simply with the reading and</span>
+<span class="sd">writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide</span>
+<span class="sd">an interface to OS files.</span>
+
+<span class="sd">BufferedIOBase deals with buffering on a raw byte stream (RawIOBase). Its</span>
+<span class="sd">subclasses, BufferedWriter, BufferedReader, and BufferedRWPair buffer</span>
+<span class="sd">streams that are readable, writable, and both respectively.</span>
+<span class="sd">BufferedRandom provides a buffered interface to random access</span>
+<span class="sd">streams. BytesIO is a simple stream of in-memory bytes.</span>
+
+<span class="sd">Another IOBase subclass, TextIOBase, deals with the encoding and decoding</span>
+<span class="sd">of streams into text. TextIOWrapper, which extends it, is a buffered text</span>
+<span class="sd">interface to a buffered raw stream (`BufferedIOBase`). Finally, StringIO</span>
+<span class="sd">is a in-memory stream for text.</span>
+
+<span class="sd">Argument names are not part of the specification, and only the arguments</span>
+<span class="sd">of open() are intended to be used as keyword arguments.</span>
+
+<span class="sd">data:</span>
+
+<span class="sd">DEFAULT_BUFFER_SIZE</span>
+
+<span class="sd">   An int containing the default buffer size used by the module&#39;s buffered</span>
+<span class="sd">   I/O classes. open() uses the file&#39;s blksize (as obtained by os.stat) if</span>
+<span class="sd">   possible.</span>
+<span class="sd">&quot;&quot;&quot;</span>
+<span class="c"># New I/O library conforming to PEP 3116.</span>
+
+<span class="c"># This is a prototype; hopefully eventually some of this will be</span>
+<span class="c"># reimplemented in C.</span>
+
+<span class="c"># XXX edge cases when switching between reading/writing</span>
+<span class="c"># XXX need to support 1 meaning line-buffered</span>
+<span class="c"># XXX whenever an argument is None, use the default value</span>
+<span class="c"># XXX read/write ops should check readable/writable</span>
+<span class="c"># XXX buffered readinto should work with arbitrary buffer objects</span>
+<span class="c"># XXX use incremental encoder for text output, at least for UTF-16 and UTF-8-SIG</span>
+<span class="c"># XXX check writable, readable and seekable in appropriate places</span>
+<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span>
+<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">unicode_literals</span>
+
+<span class="n">__author__</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;Guido van Rossum &lt;guido@python.org&gt;, &quot;</span>
+              <span class="s">&quot;Mike Verdone &lt;mike.verdone@gmail.com&gt;, &quot;</span>
+              <span class="s">&quot;Mark Russell &lt;mark.russell@zen.co.uk&gt;&quot;</span><span class="p">)</span>
+
+<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s">&quot;BlockingIOError&quot;</span><span class="p">,</span> <span class="s">&quot;open&quot;</span><span class="p">,</span> <span class="s">&quot;IOBase&quot;</span><span class="p">,</span> <span class="s">&quot;RawIOBase&quot;</span><span class="p">,</span> <span class="s">&quot;FileIO&quot;</span><span class="p">,</span>
+           <span class="s">&quot;BytesIO&quot;</span><span class="p">,</span> <span class="s">&quot;StringIO&quot;</span><span class="p">,</span> <span class="s">&quot;BufferedIOBase&quot;</span><span class="p">,</span>
+           <span class="s">&quot;BufferedReader&quot;</span><span class="p">,</span> <span class="s">&quot;BufferedWriter&quot;</span><span class="p">,</span> <span class="s">&quot;BufferedRWPair&quot;</span><span class="p">,</span>
+           <span class="s">&quot;BufferedRandom&quot;</span><span class="p">,</span> <span class="s">&quot;TextIOBase&quot;</span><span class="p">,</span> <span class="s">&quot;TextIOWrapper&quot;</span><span class="p">]</span>
+
+<span class="kn">import</span> <span class="nn">os</span>
+<span class="kn">import</span> <span class="nn">abc</span>
+<span class="kn">import</span> <span class="nn">codecs</span>
+<span class="kn">import</span> <span class="nn">_fileio</span>
+<span class="kn">import</span> <span class="nn">threading</span>
+
+<span class="c"># open() uses st_blksize whenever we can</span>
+<span class="n">DEFAULT_BUFFER_SIZE</span> <span class="o">=</span> <span class="mi">8</span> <span class="o">*</span> <span class="mi">1024</span>  <span class="c"># bytes</span>
+
+<span class="c"># py3k has only new style classes</span>
+<span class="n">__metaclass__</span> <span class="o">=</span> <span class="nb">type</span>
+
+<div class="viewcode-block" id="BlockingIOError"><a class="viewcode-back" href="../test.html#io.BlockingIOError">[docs]</a><span class="k">class</span> <span class="nc">BlockingIOError</span><span class="p">(</span><span class="ne">IOError</span><span class="p">):</span>
+
+    <span class="sd">&quot;&quot;&quot;Exception raised when I/O would block on a non-blocking I/O stream.&quot;&quot;&quot;</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">errno</span><span class="p">,</span> <span class="n">strerror</span><span class="p">,</span> <span class="n">characters_written</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
+        <span class="ne">IOError</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">errno</span><span class="p">,</span> <span class="n">strerror</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">characters_written</span> <span class="o">=</span> <span class="n">characters_written</span>
+
+</div>
+<div class="viewcode-block" id="open"><a class="viewcode-back" href="../test.html#io.open">[docs]</a><span class="k">def</span> <span class="nf">open</span><span class="p">(</span><span class="nb">file</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s">&quot;r&quot;</span><span class="p">,</span> <span class="n">buffering</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
+         <span class="n">newline</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">closefd</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
+    <span class="sd">r&quot;&quot;&quot;Open file and return a stream. If the file cannot be opened, an IOError is</span>
+<span class="sd">    raised.</span>
+
+<span class="sd">    file is either a string giving the name (and the path if the file</span>
+<span class="sd">    isn&#39;t in the current working directory) of the file to be opened or an</span>
+<span class="sd">    integer file descriptor of the file to be wrapped. (If a file</span>
+<span class="sd">    descriptor is given, it is closed when the returned I/O object is</span>
+<span class="sd">    closed, unless closefd is set to False.)</span>
+
+<span class="sd">    mode is an optional string that specifies the mode in which the file</span>
+<span class="sd">    is opened. It defaults to &#39;r&#39; which means open for reading in text</span>
+<span class="sd">    mode.  Other common values are &#39;w&#39; for writing (truncating the file if</span>
+<span class="sd">    it already exists), and &#39;a&#39; for appending (which on some Unix systems,</span>
+<span class="sd">    means that all writes append to the end of the file regardless of the</span>
+<span class="sd">    current seek position). In text mode, if encoding is not specified the</span>
+<span class="sd">    encoding used is platform dependent. (For reading and writing raw</span>
+<span class="sd">    bytes use binary mode and leave encoding unspecified.) The available</span>
+<span class="sd">    modes are:</span>
+
+<span class="sd">    ========= ===============================================================</span>
+<span class="sd">    Character Meaning</span>
+<span class="sd">    --------- ---------------------------------------------------------------</span>
+<span class="sd">    &#39;r&#39;       open for reading (default)</span>
+<span class="sd">    &#39;w&#39;       open for writing, truncating the file first</span>
+<span class="sd">    &#39;a&#39;       open for writing, appending to the end of the file if it exists</span>
+<span class="sd">    &#39;b&#39;       binary mode</span>
+<span class="sd">    &#39;t&#39;       text mode (default)</span>
+<span class="sd">    &#39;+&#39;       open a disk file for updating (reading and writing)</span>
+<span class="sd">    &#39;U&#39;       universal newline mode (for backwards compatibility; unneeded</span>
+<span class="sd">              for new code)</span>
+<span class="sd">    ========= ===============================================================</span>
+
+<span class="sd">    The default mode is &#39;rt&#39; (open for reading text). For binary random</span>
+<span class="sd">    access, the mode &#39;w+b&#39; opens and truncates the file to 0 bytes, while</span>
+<span class="sd">    &#39;r+b&#39; opens the file without truncation.</span>
+
+<span class="sd">    Python distinguishes between files opened in binary and text modes,</span>
+<span class="sd">    even when the underlying operating system doesn&#39;t. Files opened in</span>
+<span class="sd">    binary mode (appending &#39;b&#39; to the mode argument) return contents as</span>
+<span class="sd">    bytes objects without any decoding. In text mode (the default, or when</span>
+<span class="sd">    &#39;t&#39; is appended to the mode argument), the contents of the file are</span>
+<span class="sd">    returned as strings, the bytes having been first decoded using a</span>
+<span class="sd">    platform-dependent encoding or using the specified encoding if given.</span>
+
+<span class="sd">    buffering is an optional integer used to set the buffering policy. By</span>
+<span class="sd">    default full buffering is on. Pass 0 to switch buffering off (only</span>
+<span class="sd">    allowed in binary mode), 1 to set line buffering, and an integer &gt; 1</span>
+<span class="sd">    for full buffering.</span>
+
+<span class="sd">    encoding is the name of the encoding used to decode or encode the</span>
+<span class="sd">    file. This should only be used in text mode. The default encoding is</span>
+<span class="sd">    platform dependent, but any encoding supported by Python can be</span>
+<span class="sd">    passed.  See the codecs module for the list of supported encodings.</span>
+
+<span class="sd">    errors is an optional string that specifies how encoding errors are to</span>
+<span class="sd">    be handled---this argument should not be used in binary mode. Pass</span>
+<span class="sd">    &#39;strict&#39; to raise a ValueError exception if there is an encoding error</span>
+<span class="sd">    (the default of None has the same effect), or pass &#39;ignore&#39; to ignore</span>
+<span class="sd">    errors. (Note that ignoring encoding errors can lead to data loss.)</span>
+<span class="sd">    See the documentation for codecs.register for a list of the permitted</span>
+<span class="sd">    encoding error strings.</span>
+
+<span class="sd">    newline controls how universal newlines works (it only applies to text</span>
+<span class="sd">    mode). It can be None, &#39;&#39;, &#39;\n&#39;, &#39;\r&#39;, and &#39;\r\n&#39;.  It works as</span>
+<span class="sd">    follows:</span>
+
+<span class="sd">    * On input, if newline is None, universal newlines mode is</span>
+<span class="sd">      enabled. Lines in the input can end in &#39;\n&#39;, &#39;\r&#39;, or &#39;\r\n&#39;, and</span>
+<span class="sd">      these are translated into &#39;\n&#39; before being returned to the</span>
+<span class="sd">      caller. If it is &#39;&#39;, universal newline mode is enabled, but line</span>
+<span class="sd">      endings are returned to the caller untranslated. If it has any of</span>
+<span class="sd">      the other legal values, input lines are only terminated by the given</span>
+<span class="sd">      string, and the line ending is returned to the caller untranslated.</span>
+
+<span class="sd">    * On output, if newline is None, any &#39;\n&#39; characters written are</span>
+<span class="sd">      translated to the system default line separator, os.linesep. If</span>
+<span class="sd">      newline is &#39;&#39;, no translation takes place. If newline is any of the</span>
+<span class="sd">      other legal values, any &#39;\n&#39; characters written are translated to</span>
+<span class="sd">      the given string.</span>
+
+<span class="sd">    If closefd is False, the underlying file descriptor will be kept open</span>
+<span class="sd">    when the file is closed. This does not work when a file name is given</span>
+<span class="sd">    and must be True in that case.</span>
+
+<span class="sd">    open() returns a file object whose type depends on the mode, and</span>
+<span class="sd">    through which the standard file operations such as reading and writing</span>
+<span class="sd">    are performed. When open() is used to open a file in a text mode (&#39;w&#39;,</span>
+<span class="sd">    &#39;r&#39;, &#39;wt&#39;, &#39;rt&#39;, etc.), it returns a TextIOWrapper. When used to open</span>
+<span class="sd">    a file in a binary mode, the returned class varies: in read binary</span>
+<span class="sd">    mode, it returns a BufferedReader; in write binary and append binary</span>
+<span class="sd">    modes, it returns a BufferedWriter, and in read/write mode, it returns</span>
+<span class="sd">    a BufferedRandom.</span>
+
+<span class="sd">    It is also possible to use a string or bytearray as a file for both</span>
+<span class="sd">    reading and writing. For strings StringIO can be used like a file</span>
+<span class="sd">    opened in a text mode, and for bytes a BytesIO can be used like a file</span>
+<span class="sd">    opened in a binary mode.</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="nb">file</span><span class="p">,</span> <span class="p">(</span><span class="nb">basestring</span><span class="p">,</span> <span class="nb">int</span><span class="p">)):</span>
+        <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;invalid file: </span><span class="si">%r</span><span class="s">&quot;</span> <span class="o">%</span> <span class="nb">file</span><span class="p">)</span>
+    <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">mode</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
+        <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;invalid mode: </span><span class="si">%r</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">mode</span><span class="p">)</span>
+    <span class="k">if</span> <span class="n">buffering</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">buffering</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
+        <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;invalid buffering: </span><span class="si">%r</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">buffering</span><span class="p">)</span>
+    <span class="k">if</span> <span class="n">encoding</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">encoding</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
+        <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;invalid encoding: </span><span class="si">%r</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">encoding</span><span class="p">)</span>
+    <span class="k">if</span> <span class="n">errors</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">errors</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
+        <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;invalid errors: </span><span class="si">%r</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">errors</span><span class="p">)</span>
+    <span class="n">modes</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">mode</span><span class="p">)</span>
+    <span class="k">if</span> <span class="n">modes</span> <span class="o">-</span> <span class="nb">set</span><span class="p">(</span><span class="s">&quot;arwb+tU&quot;</span><span class="p">)</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">mode</span><span class="p">)</span> <span class="o">&gt;</span> <span class="nb">len</span><span class="p">(</span><span class="n">modes</span><span class="p">):</span>
+        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;invalid mode: </span><span class="si">%r</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">mode</span><span class="p">)</span>
+    <span class="n">reading</span> <span class="o">=</span> <span class="s">&quot;r&quot;</span> <span class="ow">in</span> <span class="n">modes</span>
+    <span class="n">writing</span> <span class="o">=</span> <span class="s">&quot;w&quot;</span> <span class="ow">in</span> <span class="n">modes</span>
+    <span class="n">appending</span> <span class="o">=</span> <span class="s">&quot;a&quot;</span> <span class="ow">in</span> <span class="n">modes</span>
+    <span class="n">updating</span> <span class="o">=</span> <span class="s">&quot;+&quot;</span> <span class="ow">in</span> <span class="n">modes</span>
+    <span class="n">text</span> <span class="o">=</span> <span class="s">&quot;t&quot;</span> <span class="ow">in</span> <span class="n">modes</span>
+    <span class="n">binary</span> <span class="o">=</span> <span class="s">&quot;b&quot;</span> <span class="ow">in</span> <span class="n">modes</span>
+    <span class="k">if</span> <span class="s">&quot;U&quot;</span> <span class="ow">in</span> <span class="n">modes</span><span class="p">:</span>
+        <span class="k">if</span> <span class="n">writing</span> <span class="ow">or</span> <span class="n">appending</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;can&#39;t use U and writing mode at once&quot;</span><span class="p">)</span>
+        <span class="n">reading</span> <span class="o">=</span> <span class="bp">True</span>
+    <span class="k">if</span> <span class="n">text</span> <span class="ow">and</span> <span class="n">binary</span><span class="p">:</span>
+        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;can&#39;t have text and binary mode at once&quot;</span><span class="p">)</span>
+    <span class="k">if</span> <span class="n">reading</span> <span class="o">+</span> <span class="n">writing</span> <span class="o">+</span> <span class="n">appending</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
+        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;can&#39;t have read/write/append mode at once&quot;</span><span class="p">)</span>
+    <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">reading</span> <span class="ow">or</span> <span class="n">writing</span> <span class="ow">or</span> <span class="n">appending</span><span class="p">):</span>
+        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;must have exactly one of read/write/append mode&quot;</span><span class="p">)</span>
+    <span class="k">if</span> <span class="n">binary</span> <span class="ow">and</span> <span class="n">encoding</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
+        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;binary mode doesn&#39;t take an encoding argument&quot;</span><span class="p">)</span>
+    <span class="k">if</span> <span class="n">binary</span> <span class="ow">and</span> <span class="n">errors</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
+        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;binary mode doesn&#39;t take an errors argument&quot;</span><span class="p">)</span>
+    <span class="k">if</span> <span class="n">binary</span> <span class="ow">and</span> <span class="n">newline</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
+        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;binary mode doesn&#39;t take a newline argument&quot;</span><span class="p">)</span>
+    <span class="n">raw</span> <span class="o">=</span> <span class="n">FileIO</span><span class="p">(</span><span class="nb">file</span><span class="p">,</span>
+                 <span class="p">(</span><span class="n">reading</span> <span class="ow">and</span> <span class="s">&quot;r&quot;</span> <span class="ow">or</span> <span class="s">&quot;&quot;</span><span class="p">)</span> <span class="o">+</span>
+                 <span class="p">(</span><span class="n">writing</span> <span class="ow">and</span> <span class="s">&quot;w&quot;</span> <span class="ow">or</span> <span class="s">&quot;&quot;</span><span class="p">)</span> <span class="o">+</span>
+                 <span class="p">(</span><span class="n">appending</span> <span class="ow">and</span> <span class="s">&quot;a&quot;</span> <span class="ow">or</span> <span class="s">&quot;&quot;</span><span class="p">)</span> <span class="o">+</span>
+                 <span class="p">(</span><span class="n">updating</span> <span class="ow">and</span> <span class="s">&quot;+&quot;</span> <span class="ow">or</span> <span class="s">&quot;&quot;</span><span class="p">),</span>
+                 <span class="n">closefd</span><span class="p">)</span>
+    <span class="k">if</span> <span class="n">buffering</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+        <span class="n">buffering</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
+    <span class="n">line_buffering</span> <span class="o">=</span> <span class="bp">False</span>
+    <span class="k">if</span> <span class="n">buffering</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">or</span> <span class="n">buffering</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">raw</span><span class="o">.</span><span class="n">isatty</span><span class="p">():</span>
+        <span class="n">buffering</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
+        <span class="n">line_buffering</span> <span class="o">=</span> <span class="bp">True</span>
+    <span class="k">if</span> <span class="n">buffering</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
+        <span class="n">buffering</span> <span class="o">=</span> <span class="n">DEFAULT_BUFFER_SIZE</span>
+        <span class="k">try</span><span class="p">:</span>
+            <span class="n">bs</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">fstat</span><span class="p">(</span><span class="n">raw</span><span class="o">.</span><span class="n">fileno</span><span class="p">())</span><span class="o">.</span><span class="n">st_blksize</span>
+        <span class="k">except</span> <span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">error</span><span class="p">,</span> <span class="ne">AttributeError</span><span class="p">):</span>
+            <span class="k">pass</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="k">if</span> <span class="n">bs</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
+                <span class="n">buffering</span> <span class="o">=</span> <span class="n">bs</span>
+    <span class="k">if</span> <span class="n">buffering</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
+        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;invalid buffering size&quot;</span><span class="p">)</span>
+    <span class="k">if</span> <span class="n">buffering</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
+        <span class="k">if</span> <span class="n">binary</span><span class="p">:</span>
+            <span class="n">raw</span><span class="o">.</span><span class="n">_name</span> <span class="o">=</span> <span class="nb">file</span>
+            <span class="n">raw</span><span class="o">.</span><span class="n">_mode</span> <span class="o">=</span> <span class="n">mode</span>
+            <span class="k">return</span> <span class="n">raw</span>
+        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;can&#39;t have unbuffered text I/O&quot;</span><span class="p">)</span>
+    <span class="k">if</span> <span class="n">updating</span><span class="p">:</span>
+        <span class="nb">buffer</span> <span class="o">=</span> <span class="n">BufferedRandom</span><span class="p">(</span><span class="n">raw</span><span class="p">,</span> <span class="n">buffering</span><span class="p">)</span>
+    <span class="k">elif</span> <span class="n">writing</span> <span class="ow">or</span> <span class="n">appending</span><span class="p">:</span>
+        <span class="nb">buffer</span> <span class="o">=</span> <span class="n">BufferedWriter</span><span class="p">(</span><span class="n">raw</span><span class="p">,</span> <span class="n">buffering</span><span class="p">)</span>
+    <span class="k">elif</span> <span class="n">reading</span><span class="p">:</span>
+        <span class="nb">buffer</span> <span class="o">=</span> <span class="n">BufferedReader</span><span class="p">(</span><span class="n">raw</span><span class="p">,</span> <span class="n">buffering</span><span class="p">)</span>
+    <span class="k">else</span><span class="p">:</span>
+        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;unknown mode: </span><span class="si">%r</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">mode</span><span class="p">)</span>
+    <span class="k">if</span> <span class="n">binary</span><span class="p">:</span>
+        <span class="nb">buffer</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="nb">file</span>
+        <span class="nb">buffer</span><span class="o">.</span><span class="n">mode</span> <span class="o">=</span> <span class="n">mode</span>
+        <span class="k">return</span> <span class="nb">buffer</span>
+    <span class="n">text</span> <span class="o">=</span> <span class="n">TextIOWrapper</span><span class="p">(</span><span class="nb">buffer</span><span class="p">,</span> <span class="n">encoding</span><span class="p">,</span> <span class="n">errors</span><span class="p">,</span> <span class="n">newline</span><span class="p">,</span> <span class="n">line_buffering</span><span class="p">)</span>
+    <span class="n">text</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="nb">file</span>
+    <span class="n">text</span><span class="o">.</span><span class="n">mode</span> <span class="o">=</span> <span class="n">mode</span>
+    <span class="k">return</span> <span class="n">text</span>
+</div>
+<span class="k">class</span> <span class="nc">_DocDescriptor</span><span class="p">:</span>
+    <span class="sd">&quot;&quot;&quot;Helper for builtins.open.__doc__</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">def</span> <span class="nf">__get__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">,</span> <span class="n">typ</span><span class="p">):</span>
+        <span class="k">return</span> <span class="p">(</span>
+            <span class="s">&quot;open(file, mode=&#39;r&#39;, buffering=None, encoding=None, &quot;</span>
+                 <span class="s">&quot;errors=None, newline=None, closefd=True)</span><span class="se">\n\n</span><span class="s">&quot;</span> <span class="o">+</span>
+            <span class="nb">open</span><span class="o">.</span><span class="n">__doc__</span><span class="p">)</span>
+
+<span class="k">class</span> <span class="nc">OpenWrapper</span><span class="p">:</span>
+    <span class="sd">&quot;&quot;&quot;Wrapper for builtins.open</span>
+
+<span class="sd">    Trick so that open won&#39;t become a bound method when stored</span>
+<span class="sd">    as a class variable (as dumbdbm does).</span>
+
+<span class="sd">    See initstdio() in Python/pythonrun.c.</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="n">__doc__</span> <span class="o">=</span> <span class="n">_DocDescriptor</span><span class="p">()</span>
+
+    <span class="k">def</span> <span class="nf">__new__</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+        <span class="k">return</span> <span class="nb">open</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
+
+
+<span class="k">class</span> <span class="nc">UnsupportedOperation</span><span class="p">(</span><span class="ne">ValueError</span><span class="p">,</span> <span class="ne">IOError</span><span class="p">):</span>
+    <span class="k">pass</span>
+
+
+<div class="viewcode-block" id="IOBase"><a class="viewcode-back" href="../test.html#io.IOBase">[docs]</a><span class="k">class</span> <span class="nc">IOBase</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+
+    <span class="sd">&quot;&quot;&quot;The abstract base class for all I/O classes, acting on streams of</span>
+<span class="sd">    bytes. There is no public constructor.</span>
+
+<span class="sd">    This class provides dummy implementations for many methods that</span>
+<span class="sd">    derived classes can override selectively; the default implementations</span>
+<span class="sd">    represent a file that cannot be read, written or seeked.</span>
+
+<span class="sd">    Even though IOBase does not declare read, readinto, or write because</span>
+<span class="sd">    their signatures will vary, implementations and clients should</span>
+<span class="sd">    consider those methods part of the interface. Also, implementations</span>
+<span class="sd">    may raise a IOError when operations they do not support are called.</span>
+
+<span class="sd">    The basic type used for binary data read from or written to a file is</span>
+<span class="sd">    bytes. bytearrays are accepted too, and in some cases (such as</span>
+<span class="sd">    readinto) needed. Text I/O classes work with str data.</span>
+
+<span class="sd">    Note that calling any method (even inquiries) on a closed stream is</span>
+<span class="sd">    undefined. Implementations may raise IOError in this case.</span>
+
+<span class="sd">    IOBase (and its subclasses) support the iterator protocol, meaning</span>
+<span class="sd">    that an IOBase object can be iterated over yielding the lines in a</span>
+<span class="sd">    stream.</span>
+
+<span class="sd">    IOBase also supports the :keyword:`with` statement. In this example,</span>
+<span class="sd">    fp is closed after the suite of the with statment is complete:</span>
+
+<span class="sd">    with open(&#39;spam.txt&#39;, &#39;r&#39;) as fp:</span>
+<span class="sd">        fp.write(&#39;Spam and eggs!&#39;)</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">__metaclass__</span> <span class="o">=</span> <span class="n">abc</span><span class="o">.</span><span class="n">ABCMeta</span>
+
+    <span class="c">### Internal ###</span>
+
+    <span class="k">def</span> <span class="nf">_unsupported</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Internal: raise an exception for unsupported operations.&quot;&quot;&quot;</span>
+        <span class="k">raise</span> <span class="n">UnsupportedOperation</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s">.</span><span class="si">%s</span><span class="s">() not supported&quot;</span> <span class="o">%</span>
+                                   <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__class__</span><span class="o">.</span><span class="n">__name__</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span>
+
+    <span class="c">### Positioning ###</span>
+
+<div class="viewcode-block" id="IOBase.seek"><a class="viewcode-back" href="../test.html#io.IOBase.seek">[docs]</a>    <span class="k">def</span> <span class="nf">seek</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">whence</span> <span class="o">=</span> <span class="mi">0</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Change stream position.</span>
+
+<span class="sd">        Change the stream position to byte offset offset. offset is</span>
+<span class="sd">        interpreted relative to the position indicated by whence.  Values</span>
+<span class="sd">        for whence are:</span>
+
+<span class="sd">        * 0 -- start of stream (the default); offset should be zero or positive</span>
+<span class="sd">        * 1 -- current stream position; offset may be negative</span>
+<span class="sd">        * 2 -- end of stream; offset is usually negative</span>
+
+<span class="sd">        Return the new absolute position.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_unsupported</span><span class="p">(</span><span class="s">&quot;seek&quot;</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="IOBase.tell"><a class="viewcode-back" href="../test.html#io.IOBase.tell">[docs]</a>    <span class="k">def</span> <span class="nf">tell</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Return current stream position.&quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="IOBase.truncate"><a class="viewcode-back" href="../test.html#io.IOBase.truncate">[docs]</a>    <span class="k">def</span> <span class="nf">truncate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pos</span> <span class="o">=</span> <span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Truncate file to size bytes.</span>
+
+<span class="sd">        Size defaults to the current IO position as reported by tell().  Return</span>
+<span class="sd">        the new size.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_unsupported</span><span class="p">(</span><span class="s">&quot;truncate&quot;</span><span class="p">)</span>
+
+    <span class="c">### Flush and close ###</span>
+</div>
+<div class="viewcode-block" id="IOBase.flush"><a class="viewcode-back" href="../test.html#io.IOBase.flush">[docs]</a>    <span class="k">def</span> <span class="nf">flush</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Flush write buffers, if applicable.</span>
+
+<span class="sd">        This is not implemented for read-only and non-blocking streams.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="c"># XXX Should this return the number of bytes written???</span>
+</div>
+    <span class="n">__closed</span> <span class="o">=</span> <span class="bp">False</span>
+
+<div class="viewcode-block" id="IOBase.close"><a class="viewcode-back" href="../test.html#io.IOBase.close">[docs]</a>    <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Flush and close the IO object.</span>
+
+<span class="sd">        This method has no effect if the file is already closed.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__closed</span><span class="p">:</span>
+            <span class="k">try</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>
+            <span class="k">except</span> <span class="ne">IOError</span><span class="p">:</span>
+                <span class="k">pass</span>  <span class="c"># If flush() fails, just give up</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">__closed</span> <span class="o">=</span> <span class="bp">True</span>
+</div>
+    <span class="k">def</span> <span class="nf">__del__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Destructor.  Calls close().&quot;&quot;&quot;</span>
+        <span class="c"># The try/except block is in case this is called at program</span>
+        <span class="c"># exit time, when it&#39;s possible that globals have already been</span>
+        <span class="c"># deleted, and then the close() call might fail.  Since</span>
+        <span class="c"># there&#39;s nothing we can do about such failures and they annoy</span>
+        <span class="c"># the end users, we suppress the traceback.</span>
+        <span class="k">try</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
+        <span class="k">except</span><span class="p">:</span>
+            <span class="k">pass</span>
+
+    <span class="c">### Inquiries ###</span>
+
+<div class="viewcode-block" id="IOBase.seekable"><a class="viewcode-back" href="../test.html#io.IOBase.seekable">[docs]</a>    <span class="k">def</span> <span class="nf">seekable</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Return whether object supports random access.</span>
+
+<span class="sd">        If False, seek(), tell() and truncate() will raise IOError.</span>
+<span class="sd">        This method may need to do a test seek().</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="bp">False</span>
+</div>
+    <span class="k">def</span> <span class="nf">_checkSeekable</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Internal: raise an IOError if file is not seekable</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">seekable</span><span class="p">():</span>
+            <span class="k">raise</span> <span class="ne">IOError</span><span class="p">(</span><span class="s">&quot;File or stream is not seekable.&quot;</span>
+                          <span class="k">if</span> <span class="n">msg</span> <span class="ow">is</span> <span class="bp">None</span> <span class="k">else</span> <span class="n">msg</span><span class="p">)</span>
+
+
+<div class="viewcode-block" id="IOBase.readable"><a class="viewcode-back" href="../test.html#io.IOBase.readable">[docs]</a>    <span class="k">def</span> <span class="nf">readable</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Return whether object was opened for reading.</span>
+
+<span class="sd">        If False, read() will raise IOError.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="bp">False</span>
+</div>
+    <span class="k">def</span> <span class="nf">_checkReadable</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Internal: raise an IOError if file is not readable</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">readable</span><span class="p">():</span>
+            <span class="k">raise</span> <span class="ne">IOError</span><span class="p">(</span><span class="s">&quot;File or stream is not readable.&quot;</span>
+                          <span class="k">if</span> <span class="n">msg</span> <span class="ow">is</span> <span class="bp">None</span> <span class="k">else</span> <span class="n">msg</span><span class="p">)</span>
+
+<div class="viewcode-block" id="IOBase.writable"><a class="viewcode-back" href="../test.html#io.IOBase.writable">[docs]</a>    <span class="k">def</span> <span class="nf">writable</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Return whether object was opened for writing.</span>
+
+<span class="sd">        If False, write() and truncate() will raise IOError.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="bp">False</span>
+</div>
+    <span class="k">def</span> <span class="nf">_checkWritable</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Internal: raise an IOError if file is not writable</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">writable</span><span class="p">():</span>
+            <span class="k">raise</span> <span class="ne">IOError</span><span class="p">(</span><span class="s">&quot;File or stream is not writable.&quot;</span>
+                          <span class="k">if</span> <span class="n">msg</span> <span class="ow">is</span> <span class="bp">None</span> <span class="k">else</span> <span class="n">msg</span><span class="p">)</span>
+
+    <span class="nd">@property</span>
+<div class="viewcode-block" id="IOBase.closed"><a class="viewcode-back" href="../test.html#io.IOBase.closed">[docs]</a>    <span class="k">def</span> <span class="nf">closed</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;closed: bool.  True iff the file has been closed.</span>
+
+<span class="sd">        For backwards compatibility, this is a property, not a predicate.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__closed</span>
+</div>
+    <span class="k">def</span> <span class="nf">_checkClosed</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Internal: raise an ValueError if file is closed</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">closed</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;I/O operation on closed file.&quot;</span>
+                             <span class="k">if</span> <span class="n">msg</span> <span class="ow">is</span> <span class="bp">None</span> <span class="k">else</span> <span class="n">msg</span><span class="p">)</span>
+
+    <span class="c">### Context manager ###</span>
+
+    <span class="k">def</span> <span class="nf">__enter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Context management protocol.  Returns self.&quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_checkClosed</span><span class="p">()</span>
+        <span class="k">return</span> <span class="bp">self</span>
+
+    <span class="k">def</span> <span class="nf">__exit__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Context management protocol.  Calls close()&quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
+
+    <span class="c">### Lower-level APIs ###</span>
+
+    <span class="c"># XXX Should these be present even if unimplemented?</span>
+
+<div class="viewcode-block" id="IOBase.fileno"><a class="viewcode-back" href="../test.html#io.IOBase.fileno">[docs]</a>    <span class="k">def</span> <span class="nf">fileno</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Returns underlying file descriptor if one exists.</span>
+
+<span class="sd">        An IOError is raised if the IO object does not use a file descriptor.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_unsupported</span><span class="p">(</span><span class="s">&quot;fileno&quot;</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="IOBase.isatty"><a class="viewcode-back" href="../test.html#io.IOBase.isatty">[docs]</a>    <span class="k">def</span> <span class="nf">isatty</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Return whether this is an &#39;interactive&#39; stream.</span>
+
+<span class="sd">        Return False if it can&#39;t be determined.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_checkClosed</span><span class="p">()</span>
+        <span class="k">return</span> <span class="bp">False</span>
+
+    <span class="c">### Readline[s] and writelines ###</span>
+</div>
+<div class="viewcode-block" id="IOBase.readline"><a class="viewcode-back" href="../test.html#io.IOBase.readline">[docs]</a>    <span class="k">def</span> <span class="nf">readline</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">limit</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">):</span>
+        <span class="sd">r&quot;&quot;&quot;Read and return a line from the stream.</span>
+
+<span class="sd">        If limit is specified, at most limit bytes will be read.</span>
+
+<span class="sd">        The line terminator is always b&#39;\n&#39; for binary files; for text</span>
+<span class="sd">        files, the newlines argument to open can be used to select the line</span>
+<span class="sd">        terminator(s) recognized.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_checkClosed</span><span class="p">()</span>
+        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">&quot;peek&quot;</span><span class="p">):</span>
+            <span class="k">def</span> <span class="nf">nreadahead</span><span class="p">():</span>
+                <span class="n">readahead</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">peek</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
+                <span class="k">if</span> <span class="ow">not</span> <span class="n">readahead</span><span class="p">:</span>
+                    <span class="k">return</span> <span class="mi">1</span>
+                <span class="n">n</span> <span class="o">=</span> <span class="p">(</span><span class="n">readahead</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">b</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">readahead</span><span class="p">)</span>
+                <span class="k">if</span> <span class="n">limit</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">:</span>
+                    <span class="n">n</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">limit</span><span class="p">)</span>
+                <span class="k">return</span> <span class="n">n</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="k">def</span> <span class="nf">nreadahead</span><span class="p">():</span>
+                <span class="k">return</span> <span class="mi">1</span>
+        <span class="k">if</span> <span class="n">limit</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">limit</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">limit</span><span class="p">,</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="nb">long</span><span class="p">)):</span>
+            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;limit must be an integer&quot;</span><span class="p">)</span>
+        <span class="n">res</span> <span class="o">=</span> <span class="nb">bytearray</span><span class="p">()</span>
+        <span class="k">while</span> <span class="n">limit</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">res</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">limit</span><span class="p">:</span>
+            <span class="n">b</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">nreadahead</span><span class="p">())</span>
+            <span class="k">if</span> <span class="ow">not</span> <span class="n">b</span><span class="p">:</span>
+                <span class="k">break</span>
+            <span class="n">res</span> <span class="o">+=</span> <span class="n">b</span>
+            <span class="k">if</span> <span class="n">res</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="n">b</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">):</span>
+                <span class="k">break</span>
+        <span class="k">return</span> <span class="nb">bytes</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
+</div>
+    <span class="k">def</span> <span class="nf">__iter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_checkClosed</span><span class="p">()</span>
+        <span class="k">return</span> <span class="bp">self</span>
+
+    <span class="k">def</span> <span class="nf">next</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="n">line</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="n">line</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="ne">StopIteration</span>
+        <span class="k">return</span> <span class="n">line</span>
+
+<div class="viewcode-block" id="IOBase.readlines"><a class="viewcode-back" href="../test.html#io.IOBase.readlines">[docs]</a>    <span class="k">def</span> <span class="nf">readlines</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">hint</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Return a list of lines from the stream.</span>
+
+<span class="sd">        hint can be specified to control the number of lines read: no more</span>
+<span class="sd">        lines will be read if the total size (in bytes/characters) of all</span>
+<span class="sd">        lines so far exceeds hint.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">if</span> <span class="n">hint</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">hint</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">hint</span><span class="p">,</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="nb">long</span><span class="p">)):</span>
+            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;hint must be an integer&quot;</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">hint</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
+        <span class="n">n</span> <span class="o">=</span> <span class="mi">0</span>
+        <span class="n">lines</span> <span class="o">=</span> <span class="p">[]</span>
+        <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">:</span>
+            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
+            <span class="n">n</span> <span class="o">+=</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
+            <span class="k">if</span> <span class="n">n</span> <span class="o">&gt;=</span> <span class="n">hint</span><span class="p">:</span>
+                <span class="k">break</span>
+        <span class="k">return</span> <span class="n">lines</span>
+</div>
+    <span class="k">def</span> <span class="nf">writelines</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lines</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_checkClosed</span><span class="p">()</span>
+        <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
+
+</div>
+<div class="viewcode-block" id="RawIOBase"><a class="viewcode-back" href="../test.html#io.RawIOBase">[docs]</a><span class="k">class</span> <span class="nc">RawIOBase</span><span class="p">(</span><span class="n">IOBase</span><span class="p">):</span>
+
+    <span class="sd">&quot;&quot;&quot;Base class for raw binary I/O.&quot;&quot;&quot;</span>
+
+    <span class="c"># The read() method is implemented by calling readinto(); derived</span>
+    <span class="c"># classes that want to support read() only need to implement</span>
+    <span class="c"># readinto() as a primitive operation.  In general, readinto() can be</span>
+    <span class="c"># more efficient than read().</span>
+
+    <span class="c"># (It would be tempting to also provide an implementation of</span>
+    <span class="c"># readinto() in terms of read(), in case the latter is a more suitable</span>
+    <span class="c"># primitive operation, but that would lead to nasty recursion in case</span>
+    <span class="c"># a subclass doesn&#39;t implement either.)</span>
+
+<div class="viewcode-block" id="RawIOBase.read"><a class="viewcode-back" href="../test.html#io.RawIOBase.read">[docs]</a>    <span class="k">def</span> <span class="nf">read</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Read and return up to n bytes.</span>
+
+<span class="sd">        Returns an empty bytes array on EOF, or None if the object is</span>
+<span class="sd">        set not to block and has no data to read.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">if</span> <span class="n">n</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">n</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
+        <span class="k">if</span> <span class="n">n</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">readall</span><span class="p">()</span>
+        <span class="n">b</span> <span class="o">=</span> <span class="nb">bytearray</span><span class="p">(</span><span class="n">n</span><span class="o">.</span><span class="n">__index__</span><span class="p">())</span>
+        <span class="n">n</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">readinto</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
+        <span class="k">del</span> <span class="n">b</span><span class="p">[</span><span class="n">n</span><span class="p">:]</span>
+        <span class="k">return</span> <span class="nb">bytes</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="RawIOBase.readall"><a class="viewcode-back" href="../test.html#io.RawIOBase.readall">[docs]</a>    <span class="k">def</span> <span class="nf">readall</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Read until EOF, using multiple read() call.&quot;&quot;&quot;</span>
+        <span class="n">res</span> <span class="o">=</span> <span class="nb">bytearray</span><span class="p">()</span>
+        <span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
+            <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">DEFAULT_BUFFER_SIZE</span><span class="p">)</span>
+            <span class="k">if</span> <span class="ow">not</span> <span class="n">data</span><span class="p">:</span>
+                <span class="k">break</span>
+            <span class="n">res</span> <span class="o">+=</span> <span class="n">data</span>
+        <span class="k">return</span> <span class="nb">bytes</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="RawIOBase.readinto"><a class="viewcode-back" href="../test.html#io.RawIOBase.readinto">[docs]</a>    <span class="k">def</span> <span class="nf">readinto</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Read up to len(b) bytes into b.</span>
+
+<span class="sd">        Returns number of bytes read (0 for EOF), or None if the object</span>
+<span class="sd">        is set not to block as has no data to read.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_unsupported</span><span class="p">(</span><span class="s">&quot;readinto&quot;</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="RawIOBase.write"><a class="viewcode-back" href="../test.html#io.RawIOBase.write">[docs]</a>    <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Write the given buffer to the IO stream.</span>
+
+<span class="sd">        Returns the number of bytes written, which may be less than len(b).</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_unsupported</span><span class="p">(</span><span class="s">&quot;write&quot;</span><span class="p">)</span>
+
+</div></div>
+<div class="viewcode-block" id="FileIO"><a class="viewcode-back" href="../test.html#io.FileIO">[docs]</a><span class="k">class</span> <span class="nc">FileIO</span><span class="p">(</span><span class="n">_fileio</span><span class="o">.</span><span class="n">_FileIO</span><span class="p">,</span> <span class="n">RawIOBase</span><span class="p">):</span>
+
+    <span class="sd">&quot;&quot;&quot;Raw I/O implementation for OS files.&quot;&quot;&quot;</span>
+
+    <span class="c"># This multiply inherits from _FileIO and RawIOBase to make</span>
+    <span class="c"># isinstance(io.FileIO(), io.RawIOBase) return True without requiring</span>
+    <span class="c"># that _fileio._FileIO inherits from io.RawIOBase (which would be hard</span>
+    <span class="c"># to do since _fileio.c is written in C).</span>
+
+    <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="n">_fileio</span><span class="o">.</span><span class="n">_FileIO</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
+        <span class="n">RawIOBase</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
+
+    <span class="nd">@property</span>
+    <span class="k">def</span> <span class="nf">name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_name</span>
+
+    <span class="nd">@property</span>
+    <span class="k">def</span> <span class="nf">mode</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_mode</span>
+
+</div>
+<div class="viewcode-block" id="BufferedIOBase"><a class="viewcode-back" href="../test.html#io.BufferedIOBase">[docs]</a><span class="k">class</span> <span class="nc">BufferedIOBase</span><span class="p">(</span><span class="n">IOBase</span><span class="p">):</span>
+
+    <span class="sd">&quot;&quot;&quot;Base class for buffered IO objects.</span>
+
+<span class="sd">    The main difference with RawIOBase is that the read() method</span>
+<span class="sd">    supports omitting the size argument, and does not have a default</span>
+<span class="sd">    implementation that defers to readinto().</span>
+
+<span class="sd">    In addition, read(), readinto() and write() may raise</span>
+<span class="sd">    BlockingIOError if the underlying raw stream is in non-blocking</span>
+<span class="sd">    mode and not ready; unlike their raw counterparts, they will never</span>
+<span class="sd">    return None.</span>
+
+<span class="sd">    A typical implementation should not inherit from a RawIOBase</span>
+<span class="sd">    implementation, but wrap one.</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+<div class="viewcode-block" id="BufferedIOBase.read"><a class="viewcode-back" href="../test.html#io.BufferedIOBase.read">[docs]</a>    <span class="k">def</span> <span class="nf">read</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n</span> <span class="o">=</span> <span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Read and return up to n bytes.</span>
+
+<span class="sd">        If the argument is omitted, None, or negative, reads and</span>
+<span class="sd">        returns all data until EOF.</span>
+
+<span class="sd">        If the argument is positive, and the underlying raw stream is</span>
+<span class="sd">        not &#39;interactive&#39;, multiple raw reads may be issued to satisfy</span>
+<span class="sd">        the byte count (unless EOF is reached first).  But for</span>
+<span class="sd">        interactive raw streams (XXX and for pipes?), at most one raw</span>
+<span class="sd">        read will be issued, and a short result does not imply that</span>
+<span class="sd">        EOF is imminent.</span>
+
+<span class="sd">        Returns an empty bytes array on EOF.</span>
+
+<span class="sd">        Raises BlockingIOError if the underlying raw stream has no</span>
+<span class="sd">        data at the moment.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_unsupported</span><span class="p">(</span><span class="s">&quot;read&quot;</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="BufferedIOBase.readinto"><a class="viewcode-back" href="../test.html#io.BufferedIOBase.readinto">[docs]</a>    <span class="k">def</span> <span class="nf">readinto</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Read up to len(b) bytes into b.</span>
+
+<span class="sd">        Like read(), this may issue multiple reads to the underlying raw</span>
+<span class="sd">        stream, unless the latter is &#39;interactive&#39;.</span>
+
+<span class="sd">        Returns the number of bytes read (0 for EOF).</span>
+
+<span class="sd">        Raises BlockingIOError if the underlying raw stream has no</span>
+<span class="sd">        data at the moment.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="c"># XXX This ought to work with anything that supports the buffer API</span>
+        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">b</span><span class="p">))</span>
+        <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
+        <span class="k">try</span><span class="p">:</span>
+            <span class="n">b</span><span class="p">[:</span><span class="n">n</span><span class="p">]</span> <span class="o">=</span> <span class="n">data</span>
+        <span class="k">except</span> <span class="ne">TypeError</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span>
+            <span class="kn">import</span> <span class="nn">array</span>
+            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">array</span><span class="o">.</span><span class="n">array</span><span class="p">):</span>
+                <span class="k">raise</span> <span class="n">err</span>
+            <span class="n">b</span><span class="p">[:</span><span class="n">n</span><span class="p">]</span> <span class="o">=</span> <span class="n">array</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">b</span><span class="s">&#39;b&#39;</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
+        <span class="k">return</span> <span class="n">n</span>
+</div>
+<div class="viewcode-block" id="BufferedIOBase.write"><a class="viewcode-back" href="../test.html#io.BufferedIOBase.write">[docs]</a>    <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Write the given buffer to the IO stream.</span>
+
+<span class="sd">        Return the number of bytes written, which is never less than</span>
+<span class="sd">        len(b).</span>
+
+<span class="sd">        Raises BlockingIOError if the buffer is full and the</span>
+<span class="sd">        underlying raw stream cannot accept more data at the moment.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_unsupported</span><span class="p">(</span><span class="s">&quot;write&quot;</span><span class="p">)</span>
+
+</div></div>
+<span class="k">class</span> <span class="nc">_BufferedIOMixin</span><span class="p">(</span><span class="n">BufferedIOBase</span><span class="p">):</span>
+
+    <span class="sd">&quot;&quot;&quot;A mixin implementation of BufferedIOBase with an underlying raw stream.</span>
+
+<span class="sd">    This passes most requests on to the underlying raw stream.  It</span>
+<span class="sd">    does *not* provide implementations of read(), readinto() or</span>
+<span class="sd">    write().</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">raw</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="n">raw</span>
+
+    <span class="c">### Positioning ###</span>
+
+    <span class="k">def</span> <span class="nf">seek</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">whence</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">raw</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="n">pos</span><span class="p">,</span> <span class="n">whence</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">tell</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">raw</span><span class="o">.</span><span class="n">tell</span><span class="p">()</span>
+
+    <span class="k">def</span> <span class="nf">truncate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pos</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="c"># Flush the stream.  We&#39;re mixing buffered I/O with lower-level I/O,</span>
+        <span class="c"># and a flush may be necessary to synch both views of the current</span>
+        <span class="c"># file state.</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>
+
+        <span class="k">if</span> <span class="n">pos</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">pos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tell</span><span class="p">()</span>
+        <span class="c"># XXX: Should seek() be used, instead of passing the position</span>
+        <span class="c"># XXX  directly to truncate?</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">raw</span><span class="o">.</span><span class="n">truncate</span><span class="p">(</span><span class="n">pos</span><span class="p">)</span>
+
+    <span class="c">### Flush and close ###</span>
+
+    <span class="k">def</span> <span class="nf">flush</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">raw</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>
+
+    <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">closed</span><span class="p">:</span>
+            <span class="k">try</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>
+            <span class="k">except</span> <span class="ne">IOError</span><span class="p">:</span>
+                <span class="k">pass</span>  <span class="c"># If flush() fails, just give up</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">raw</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
+
+    <span class="c">### Inquiries ###</span>
+
+    <span class="k">def</span> <span class="nf">seekable</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">raw</span><span class="o">.</span><span class="n">seekable</span><span class="p">()</span>
+
+    <span class="k">def</span> <span class="nf">readable</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">raw</span><span class="o">.</span><span class="n">readable</span><span class="p">()</span>
+
+    <span class="k">def</span> <span class="nf">writable</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">raw</span><span class="o">.</span><span class="n">writable</span><span class="p">()</span>
+
+    <span class="nd">@property</span>
+    <span class="k">def</span> <span class="nf">closed</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">raw</span><span class="o">.</span><span class="n">closed</span>
+
+    <span class="c">### Lower-level APIs ###</span>
+
+    <span class="k">def</span> <span class="nf">fileno</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">raw</span><span class="o">.</span><span class="n">fileno</span><span class="p">()</span>
+
+    <span class="k">def</span> <span class="nf">isatty</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">raw</span><span class="o">.</span><span class="n">isatty</span><span class="p">()</span>
+
+
+<span class="k">class</span> <span class="nc">_BytesIO</span><span class="p">(</span><span class="n">BufferedIOBase</span><span class="p">):</span>
+
+    <span class="sd">&quot;&quot;&quot;Buffered I/O implementation using an in-memory bytes buffer.&quot;&quot;&quot;</span>
+
+    <span class="c"># XXX More docs</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">initial_bytes</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="n">buf</span> <span class="o">=</span> <span class="nb">bytearray</span><span class="p">()</span>
+        <span class="k">if</span> <span class="n">initial_bytes</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">buf</span> <span class="o">+=</span> <span class="nb">bytearray</span><span class="p">(</span><span class="n">initial_bytes</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="n">buf</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_pos</span> <span class="o">=</span> <span class="mi">0</span>
+
+    <span class="k">def</span> <span class="nf">getvalue</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Return the bytes value (contents) of the buffer</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">closed</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;getvalue on closed file&quot;</span><span class="p">)</span>
+        <span class="k">return</span> <span class="nb">bytes</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">read</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">closed</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;read from closed file&quot;</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">n</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">n</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="nb">long</span><span class="p">)):</span>
+            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;argument must be an integer&quot;</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">n</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">)</span>
+        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pos</span><span class="p">:</span>
+            <span class="k">return</span> <span class="n">b</span><span class="s">&quot;&quot;</span>
+        <span class="n">newpos</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pos</span> <span class="o">+</span> <span class="n">n</span><span class="p">)</span>
+        <span class="n">b</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_pos</span> <span class="p">:</span> <span class="n">newpos</span><span class="p">]</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_pos</span> <span class="o">=</span> <span class="n">newpos</span>
+        <span class="k">return</span> <span class="nb">bytes</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">read1</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;this is the same as read.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">closed</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;write to closed file&quot;</span><span class="p">)</span>
+        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="nb">unicode</span><span class="p">):</span>
+            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;can&#39;t write unicode to binary stream&quot;</span><span class="p">)</span>
+        <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">n</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="k">return</span> <span class="mi">0</span>
+        <span class="n">pos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pos</span>
+        <span class="k">if</span> <span class="n">pos</span> <span class="o">&gt;</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">):</span>
+            <span class="c"># Inserts null bytes between the current end of the file</span>
+            <span class="c"># and the new write position.</span>
+            <span class="n">padding</span> <span class="o">=</span> <span class="n">b</span><span class="s">&#39;</span><span class="se">\x00</span><span class="s">&#39;</span> <span class="o">*</span> <span class="p">(</span><span class="n">pos</span> <span class="o">-</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">))</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">+=</span> <span class="n">padding</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">[</span><span class="n">pos</span><span class="p">:</span><span class="n">pos</span> <span class="o">+</span> <span class="n">n</span><span class="p">]</span> <span class="o">=</span> <span class="n">b</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_pos</span> <span class="o">+=</span> <span class="n">n</span>
+        <span class="k">return</span> <span class="n">n</span>
+
+    <span class="k">def</span> <span class="nf">seek</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">whence</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">closed</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;seek on closed file&quot;</span><span class="p">)</span>
+        <span class="k">try</span><span class="p">:</span>
+            <span class="n">pos</span> <span class="o">=</span> <span class="n">pos</span><span class="o">.</span><span class="n">__index__</span><span class="p">()</span>
+        <span class="k">except</span> <span class="ne">AttributeError</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;an integer is required&quot;</span><span class="p">)</span> <span class="c"># from err</span>
+        <span class="k">if</span> <span class="n">whence</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="k">if</span> <span class="n">pos</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
+                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;negative seek position </span><span class="si">%r</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">pos</span><span class="p">,))</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">_pos</span> <span class="o">=</span> <span class="n">pos</span>
+        <span class="k">elif</span> <span class="n">whence</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">_pos</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pos</span> <span class="o">+</span> <span class="n">pos</span><span class="p">)</span>
+        <span class="k">elif</span> <span class="n">whence</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">_pos</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">)</span> <span class="o">+</span> <span class="n">pos</span><span class="p">)</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;invalid whence value&quot;</span><span class="p">)</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pos</span>
+
+    <span class="k">def</span> <span class="nf">tell</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">closed</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;tell on closed file&quot;</span><span class="p">)</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pos</span>
+
+    <span class="k">def</span> <span class="nf">truncate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pos</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">closed</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;truncate on closed file&quot;</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">pos</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">pos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pos</span>
+        <span class="k">elif</span> <span class="n">pos</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;negative truncate position </span><span class="si">%r</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">pos</span><span class="p">,))</span>
+        <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">[</span><span class="n">pos</span><span class="p">:]</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="n">pos</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">readable</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="bp">True</span>
+
+    <span class="k">def</span> <span class="nf">writable</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="bp">True</span>
+
+    <span class="k">def</span> <span class="nf">seekable</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="bp">True</span>
+
+<span class="c"># Use the faster implementation of BytesIO if available</span>
+<span class="k">try</span><span class="p">:</span>
+    <span class="kn">import</span> <span class="nn">_bytesio</span>
+
+<div class="viewcode-block" id="BytesIO"><a class="viewcode-back" href="../test.html#io.BytesIO">[docs]</a>    <span class="k">class</span> <span class="nc">BytesIO</span><span class="p">(</span><span class="n">_bytesio</span><span class="o">.</span><span class="n">_BytesIO</span><span class="p">,</span> <span class="n">BufferedIOBase</span><span class="p">):</span>
+        <span class="n">__doc__</span> <span class="o">=</span> <span class="n">_bytesio</span><span class="o">.</span><span class="n">_BytesIO</span><span class="o">.</span><span class="n">__doc__</span>
+</div>
+<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
+    <span class="n">BytesIO</span> <span class="o">=</span> <span class="n">_BytesIO</span>
+
+
+<div class="viewcode-block" id="BufferedReader"><a class="viewcode-back" href="../test.html#io.BufferedReader">[docs]</a><span class="k">class</span> <span class="nc">BufferedReader</span><span class="p">(</span><span class="n">_BufferedIOMixin</span><span class="p">):</span>
+
+    <span class="sd">&quot;&quot;&quot;BufferedReader(raw[, buffer_size])</span>
+
+<span class="sd">    A buffer for a readable, sequential BaseRawIO object.</span>
+
+<span class="sd">    The constructor creates a BufferedReader for the given readable raw</span>
+<span class="sd">    stream and buffer_size. If buffer_size is omitted, DEFAULT_BUFFER_SIZE</span>
+<span class="sd">    is used.</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">raw</span><span class="p">,</span> <span class="n">buffer_size</span><span class="o">=</span><span class="n">DEFAULT_BUFFER_SIZE</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Create a new buffered reader using the given readable raw IO object.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="n">raw</span><span class="o">.</span><span class="n">_checkReadable</span><span class="p">()</span>
+        <span class="n">_BufferedIOMixin</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">raw</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">buffer_size</span> <span class="o">=</span> <span class="n">buffer_size</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_reset_read_buf</span><span class="p">()</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_read_lock</span> <span class="o">=</span> <span class="n">threading</span><span class="o">.</span><span class="n">Lock</span><span class="p">()</span>
+
+    <span class="k">def</span> <span class="nf">_reset_read_buf</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_read_buf</span> <span class="o">=</span> <span class="n">b</span><span class="s">&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_read_pos</span> <span class="o">=</span> <span class="mi">0</span>
+
+<div class="viewcode-block" id="BufferedReader.read"><a class="viewcode-back" href="../test.html#io.BufferedReader.read">[docs]</a>    <span class="k">def</span> <span class="nf">read</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Read n bytes.</span>
+
+<span class="sd">        Returns exactly n bytes of data unless the underlying raw IO</span>
+<span class="sd">        stream reaches EOF or if the call would block in non-blocking</span>
+<span class="sd">        mode. If n is negative, read until EOF or until read() would</span>
+<span class="sd">        block.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">_read_lock</span><span class="p">:</span>
+            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_read_unlocked</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
+</div>
+    <span class="k">def</span> <span class="nf">_read_unlocked</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="n">nodata_val</span> <span class="o">=</span> <span class="n">b</span><span class="s">&quot;&quot;</span>
+        <span class="n">empty_values</span> <span class="o">=</span> <span class="p">(</span><span class="n">b</span><span class="s">&quot;&quot;</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
+        <span class="n">buf</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_read_buf</span>
+        <span class="n">pos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_read_pos</span>
+
+        <span class="c"># Special case for when the number of bytes to read is unspecified.</span>
+        <span class="k">if</span> <span class="n">n</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">n</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">_reset_read_buf</span><span class="p">()</span>
+            <span class="n">chunks</span> <span class="o">=</span> <span class="p">[</span><span class="n">buf</span><span class="p">[</span><span class="n">pos</span><span class="p">:]]</span>  <span class="c"># Strip the consumed bytes.</span>
+            <span class="n">current_size</span> <span class="o">=</span> <span class="mi">0</span>
+            <span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
+                <span class="c"># Read until EOF or until read() would block.</span>
+                <span class="n">chunk</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">raw</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
+                <span class="k">if</span> <span class="n">chunk</span> <span class="ow">in</span> <span class="n">empty_values</span><span class="p">:</span>
+                    <span class="n">nodata_val</span> <span class="o">=</span> <span class="n">chunk</span>
+                    <span class="k">break</span>
+                <span class="n">current_size</span> <span class="o">+=</span> <span class="nb">len</span><span class="p">(</span><span class="n">chunk</span><span class="p">)</span>
+                <span class="n">chunks</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">chunk</span><span class="p">)</span>
+            <span class="k">return</span> <span class="n">b</span><span class="s">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">chunks</span><span class="p">)</span> <span class="ow">or</span> <span class="n">nodata_val</span>
+