Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1fa3db

Browse files
committed
Added docstrings excerpted from Python Library Reference.
Closes patch 556161.
1 parent 55956c9 commit d1fa3db

4 files changed

Lines changed: 121 additions & 1 deletion

File tree

Lib/StringIO.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@
3737
__all__ = ["StringIO"]
3838

3939
class StringIO:
40+
"""class StringIO([buffer])
41+
42+
When a StringIO object is created, it can be initialized to an existing
43+
string by passing the string to the constructor. If no string is given,
44+
the StringIO will start empty.
45+
46+
The StringIO object can accept either Unicode or 8-bit strings, but
47+
mixing the two may take some care. If both are used, 8-bit strings that
48+
cannot be interpreted as 7-bit ASCII (that use the 8th bit) will cause
49+
a UnicodeError to be raised when getvalue() is called.
50+
"""
4051
def __init__(self, buf = ''):
4152
# Force self.buf to be a string or unicode
4253
if not isinstance(buf, types.StringTypes):
@@ -52,6 +63,8 @@ def __iter__(self):
5263
return iter(self.readline, '')
5364

5465
def close(self):
66+
"""Free the memory buffer.
67+
"""
5568
if not self.closed:
5669
self.closed = 1
5770
del self.buf, self.pos
@@ -165,6 +178,16 @@ def flush(self):
165178
raise ValueError, "I/O operation on closed file"
166179

167180
def getvalue(self):
181+
"""
182+
Retrieve the entire contents of the "file" at any time before
183+
the StringIO object's close() method is called.
184+
185+
The StringIO object can accept either Unicode or 8-bit strings,
186+
but mixing the two may take some care. If both are used, 8-bit
187+
strings that cannot be interpreted as 7-bit ASCII (that use the
188+
8th bit) will cause a UnicodeError to be raised when getvalue()
189+
is called.
190+
"""
168191
if self.buflist:
169192
self.buf += ''.join(self.buflist)
170193
self.buflist = []

Lib/fileinput.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,50 +89,99 @@
8989
DEFAULT_BUFSIZE = 8*1024
9090

9191
def input(files=None, inplace=0, backup="", bufsize=0):
92+
"""input([files[, inplace[, backup]]])
93+
94+
Create an instance of the FileInput class. The instance will be used
95+
as global state for the functions of this module, and is also returned
96+
to use during iteration. The parameters to this function will be passed
97+
along to the constructor of the FileInput class.
98+
"""
9299
global _state
93100
if _state and _state._file:
94101
raise RuntimeError, "input() already active"
95102
_state = FileInput(files, inplace, backup, bufsize)
96103
return _state
97104

98105
def close():
106+
"""Close the sequence."""
99107
global _state
100108
state = _state
101109
_state = None
102110
if state:
103111
state.close()
104112

105113
def nextfile():
114+
"""
115+
Close the current file so that the next iteration will read the first
116+
line from the next file (if any); lines not read from the file will
117+
not count towards the cumulative line count. The filename is not
118+
changed until after the first line of the next file has been read.
119+
Before the first line has been read, this function has no effect;
120+
it cannot be used to skip the first file. After the last line of the
121+
last file has been read, this function has no effect.
122+
"""
106123
if not _state:
107124
raise RuntimeError, "no active input()"
108125
return _state.nextfile()
109126

110127
def filename():
128+
"""
129+
Return the name of the file currently being read.
130+
Before the first line has been read, returns None.
131+
"""
111132
if not _state:
112133
raise RuntimeError, "no active input()"
113134
return _state.filename()
114135

115136
def lineno():
137+
"""
138+
Return the cumulative line number of the line that has just been read.
139+
Before the first line has been read, returns 0. After the last line
140+
of the last file has been read, returns the line number of that line.
141+
"""
116142
if not _state:
117143
raise RuntimeError, "no active input()"
118144
return _state.lineno()
119145

120146
def filelineno():
147+
"""
148+
Return the line number in the current file. Before the first line
149+
has been read, returns 0. After the last line of the last file has
150+
been read, returns the line number of that line within the file.
151+
"""
121152
if not _state:
122153
raise RuntimeError, "no active input()"
123154
return _state.filelineno()
124155

125156
def isfirstline():
157+
"""
158+
Returns true the line just read is the first line of its file,
159+
otherwise returns false.
160+
"""
126161
if not _state:
127162
raise RuntimeError, "no active input()"
128163
return _state.isfirstline()
129164

130165
def isstdin():
166+
"""
167+
Returns true if the last line was read from sys.stdin,
168+
otherwise returns false.
169+
"""
131170
if not _state:
132171
raise RuntimeError, "no active input()"
133172
return _state.isstdin()
134173

135174
class FileInput:
175+
"""class FileInput([files[, inplace[, backup]]])
176+
177+
Class FileInput is the implementation of the module; its methods
178+
filename(), lineno(), fileline(), isfirstline(), isstdin(), nextfile()
179+
and close() correspond to the functions of the same name in the module.
180+
In addition it has a readline() method which returns the next
181+
input line, and a __getitem__() method which implements the
182+
sequence behavior. The sequence must be accessed in strictly
183+
sequential order; random access and readline() cannot be mixed.
184+
"""
136185

137186
def __init__(self, files=None, inplace=0, backup="", bufsize=0):
138187
if type(files) == type(''):

Lib/tabnanny.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
#! /usr/bin/env python
22

3-
"""The Tab Nanny despises ambiguous indentation. She knows no mercy."""
3+
"""The Tab Nanny despises ambiguous indentation. She knows no mercy.
4+
5+
tabnanny -- Detection of ambiguous indentation
6+
7+
For the time being this module is intended to be called as a script.
8+
However it is possible to import it into an IDE and use the function
9+
check() described below.
10+
11+
Warning: The API provided by this module is likely to change in future
12+
releases; such changes may not be backward compatible.
13+
"""
414

515
# Released to the public domain, by Tim Peters, 15 April 1998.
616

@@ -48,6 +58,10 @@ def main():
4858
check(arg)
4959

5060
class NannyNag(Exception):
61+
"""
62+
Raised by tokeneater() if detecting an ambiguous indent.
63+
Captured and handled in check().
64+
"""
5165
def __init__(self, lineno, msg, line):
5266
self.lineno, self.msg, self.line = lineno, msg, line
5367
def get_lineno(self):
@@ -58,6 +72,15 @@ def get_line(self):
5872
return self.line
5973

6074
def check(file):
75+
"""check(file_or_dir)
76+
77+
If file_or_dir is a directory and not a symbolic link, then recursively
78+
descend the directory tree named by file_or_dir, checking all .py files
79+
along the way. If file_or_dir is an ordinary Python source file, it is
80+
checked for whitespace related problems. The diagnostic messages are
81+
written to standard output using the print statement.
82+
"""
83+
6184
if os.path.isdir(file) and not os.path.islink(file):
6285
if verbose:
6386
print "%s: listing directory" % `file`

Lib/tokenize.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ def printtoken(type, token, (srow, scol), (erow, ecol), line): # for testing
121121
(srow, scol, erow, ecol, tok_name[type], repr(token))
122122

123123
def tokenize(readline, tokeneater=printtoken):
124+
"""
125+
The tokenize() function accepts two parameters: one representing the
126+
input stream, and one providing an output mechanism for tokenize().
127+
128+
The first parameter, readline, must be a callable object which provides
129+
the same interface as the readline() method of built-in file objects.
130+
Each call to the function should return one line of input as a string.
131+
132+
The second parameter, tokeneater, must also be a callable object. It is
133+
called once for each token, with five arguments, corresponding to the
134+
tuples generated by generate_tokens().
135+
"""
124136
try:
125137
tokenize_loop(readline, tokeneater)
126138
except StopTokenizing:
@@ -132,6 +144,19 @@ def tokenize_loop(readline, tokeneater):
132144
apply(tokeneater, token_info)
133145

134146
def generate_tokens(readline):
147+
"""
148+
The generate_tokens() generator requires one argment, readline, which
149+
must be a callable object which provides the same interface as the
150+
readline() method of built-in file objects. Each call to the function
151+
should return one line of input as a string.
152+
153+
The generator produces 5-tuples with these members: the token type; the
154+
token string; a 2-tuple (srow, scol) of ints specifying the row and
155+
column where the token begins in the source; a 2-tuple (erow, ecol) of
156+
ints specifying the row and column where the token ends in the source;
157+
and the line on which the token was found. The line passed is the
158+
logical line; continuation lines are included.
159+
"""
135160
lnum = parenlev = continued = 0
136161
namechars, numchars = string.ascii_letters + '_', '0123456789'
137162
contstr, needcont = '', 0

0 commit comments

Comments
 (0)