Skip to content

Commit

Permalink
Whitespace normalization.
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-one committed May 23, 2002
1 parent f655328 commit 8ac1495
Show file tree
Hide file tree
Showing 20 changed files with 100 additions and 101 deletions.
12 changes: 6 additions & 6 deletions Lib/StringIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@
__all__ = ["StringIO"]

class StringIO:
"""class StringIO([buffer])
"""class StringIO([buffer])
When a StringIO object is created, it can be initialized to an existing
string by passing the string to the constructor. If no string is given,
the StringIO will start empty.
the StringIO will start empty.
The StringIO object can accept either Unicode or 8-bit strings, but
mixing the two may take some care. If both are used, 8-bit strings that
cannot be interpreted as 7-bit ASCII (that use the 8th bit) will cause
a UnicodeError to be raised when getvalue() is called.
a UnicodeError to be raised when getvalue() is called.
"""
def __init__(self, buf = ''):
# Force self.buf to be a string or unicode
Expand All @@ -63,7 +63,7 @@ def __iter__(self):
return iter(self.readline, '')

def close(self):
"""Free the memory buffer.
"""Free the memory buffer.
"""
if not self.closed:
self.closed = 1
Expand Down Expand Up @@ -186,7 +186,7 @@ def getvalue(self):
but mixing the two may take some care. If both are used, 8-bit
strings that cannot be interpreted as 7-bit ASCII (that use the
8th bit) will cause a UnicodeError to be raised when getvalue()
is called.
is called.
"""
if self.buflist:
self.buf += ''.join(self.buflist)
Expand Down
8 changes: 4 additions & 4 deletions Lib/email/Charset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
BASE64 = 2 # Base64

# In "=?charset?q?hello_world?=", the =?, ?q?, and ?= add up to 7
MISC_LEN = 7
MISC_LEN = 7

DEFAULT_CHARSET = 'us-ascii'

Expand All @@ -22,11 +22,11 @@
# Defaults
CHARSETS = {
# input header enc body enc output conv
'iso-8859-1': (QP, QP, None),
'iso-8859-1': (QP, QP, None),
'iso-8859-2': (QP, QP, None),
'us-ascii': (None, None, None),
'big5': (BASE64, BASE64, None),
'gb2312': (BASE64, BASE64, None),
'gb2312': (BASE64, BASE64, None),
'euc-jp': (BASE64, None, 'iso-2022-jp'),
'shift_jis': (BASE64, None, 'iso-2022-jp'),
'iso-2022-jp': (BASE64, None, None),
Expand Down Expand Up @@ -125,7 +125,7 @@ class Charset:
converting between character sets, given the availability of the
applicable codecs. Given an character set, it will do its best to provide
information on how to use that character set in an email.
Certain character sets must be encoded with quoted-printable or base64
when used in email headers or bodies. Certain character sets must be
converted outright, and are not allowed in email. Instances of this
Expand Down
8 changes: 4 additions & 4 deletions Lib/email/Header.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def decode_header(header):
if not ecre.search(line):
decoded.append((line, None))
continue

parts = ecre.split(line)
while parts:
unenc = parts.pop(0).strip()
Expand Down Expand Up @@ -149,14 +149,14 @@ def append(self, s, charset=None):
if charset is None:
charset = self._charset
self._chunks.append((s, charset))

def _split(self, s, charset):
# Split up a header safely for use with encode_chunks. BAW: this
# appears to be a private convenience method.
splittable = charset.to_splittable(s)
encoded = charset.from_splittable(splittable)
elen = charset.encoded_header_len(encoded)

if elen <= self._maxlinelen:
return [(encoded, charset)]
# BAW: should we use encoded?
Expand Down Expand Up @@ -185,7 +185,7 @@ def encode(self):
Base64 or quoted-printable) header strings. In addition, there is a
75-character length limit on any given encoded header field, so
line-wrapping must be performed, even with double-byte character sets.
This method will do its best to convert the string to the correct
character set used in email, and encode and line wrap it safely with
the appropriate scheme for that character set.
Expand Down
2 changes: 1 addition & 1 deletion Lib/email/Message.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def set_charset(self, charset):
def get_charset(self):
"""Return the Charset object associated with the message's payload."""
return self._charset

#
# MAPPING INTERFACE (partial)
#
Expand Down
2 changes: 1 addition & 1 deletion Lib/email/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def formataddr(pair):
"""The inverse of parseaddr(), this takes a 2-tuple of the form
(realname, email_address) and returns the string value suitable
for an RFC 2822 From:, To: or Cc:.
If the first element of pair is false, then the second element is
returned unmodified.
"""
Expand Down
26 changes: 13 additions & 13 deletions Lib/email/base64MIME.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@
# Helpers
def base64_len(s):
"""Return the length of s when it is encoded with base64."""
groups_of_3, leftover = divmod(len(s), 3)
# 4 bytes out for each 3 bytes (or nonzero fraction thereof) in.
groups_of_3, leftover = divmod(len(s), 3)
# 4 bytes out for each 3 bytes (or nonzero fraction thereof) in.
# Thanks, Tim!
n = groups_of_3 * 4
if leftover:
n += 4
return n
n = groups_of_3 * 4
if leftover:
n += 4
return n



def header_encode(header, charset='iso-8859-1', keep_eols=0, maxlinelen=76,
eol=NL):
"""Encode a single header line with Base64 encoding in a given charset.
Defined in RFC 2045, this Base64 encoding is identical to normal Base64
encoding, except that each line must be intelligently wrapped (respecting
the Base64 encoding), and subsequent lines must start with a space.
Expand All @@ -72,7 +72,7 @@ def header_encode(header, charset='iso-8859-1', keep_eols=0, maxlinelen=76,
"=?charset?b?WW/5ciBtYXp66XLrIHf8eiBhIGhhbXBzdGHuciBBIFlv+XIgbWF6euly?=\\n
=?charset?b?6yB3/HogYSBoYW1wc3Rh7nIgQkMgWW/5ciBtYXp66XLrIHf8eiBhIGhh?="
with each line wrapped at, at most, maxlinelen characters (defaults to 76
characters).
"""
Expand All @@ -82,7 +82,7 @@ def header_encode(header, charset='iso-8859-1', keep_eols=0, maxlinelen=76,

if not keep_eols:
header = fix_eols(header)

# Base64 encode each line, in encoded chunks no greater than maxlinelen in
# length, after the RFC chrome is added in.
base64ed = []
Expand All @@ -91,7 +91,7 @@ def header_encode(header, charset='iso-8859-1', keep_eols=0, maxlinelen=76,

# BAW: Ben's original code used a step of max_unencoded, but I think it
# ought to be max_encoded. Otherwise, where's max_encoded used? I'm
# still not sure what the
# still not sure what the
for i in range(0, len(header), max_unencoded):
base64ed.append(b2a_base64(header[i:i+max_unencoded]))

Expand Down Expand Up @@ -126,10 +126,10 @@ def encode(s, binary=1, maxlinelen=76, eol=NL):
"""
if not s:
return s

if not binary:
s = fix_eols(s)

encvec = []
max_unencoded = maxlinelen * 3 / 4
for i in range(0, len(s), max_unencoded):
Expand Down Expand Up @@ -162,7 +162,7 @@ def decode(s, convert_eols=None):
"""
if not s:
return s

dec = a2b_base64(s)
if convert_eols:
return dec.replace(CRLF, convert_eols)
Expand Down
8 changes: 4 additions & 4 deletions Lib/email/quopriMIME.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
This module does not do the line wrapping or end-of-line character
conversion necessary for proper internationalized headers; it only
does dumb encoding and decoding. To deal with the various line
wrapping issues, use the email.Header module.
wrapping issues, use the email.Header module.
"""

import re
Expand Down Expand Up @@ -50,7 +50,7 @@ def body_quopri_check(c):
"""Return true if the character should be escaped with body quopri."""
return bqre.match(c) and 1


def header_quopri_len(s):
"""Return the length of str when it is encoded with header quopri."""
count = 0
Expand Down Expand Up @@ -131,7 +131,7 @@ def header_encode(header, charset="iso-8859-1", keep_eols=0, maxlinelen=76,
# lenght, after the RFC chrome is added in.
quoted = []
max_encoded = maxlinelen - len(charset) - MISC_LEN

for c in header:
# Space may be represented as _ instead of =20 for readability
if c == ' ':
Expand Down Expand Up @@ -187,7 +187,7 @@ def encode(body, binary=0, maxlinelen=76, eol=NL):
line = line[:-2]
elif line[-1] in CRLF:
line = line[:-1]

lineno += 1
encoded_line = ''
prev = None
Expand Down
18 changes: 9 additions & 9 deletions Lib/fileinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def input(files=None, inplace=0, backup="", bufsize=0):
Create an instance of the FileInput class. The instance will be used
as global state for the functions of this module, and is also returned
to use during iteration. The parameters to this function will be passed
along to the constructor of the FileInput class.
along to the constructor of the FileInput class.
"""
global _state
if _state and _state._file:
Expand All @@ -118,7 +118,7 @@ def nextfile():
changed until after the first line of the next file has been read.
Before the first line has been read, this function has no effect;
it cannot be used to skip the first file. After the last line of the
last file has been read, this function has no effect.
last file has been read, this function has no effect.
"""
if not _state:
raise RuntimeError, "no active input()"
Expand All @@ -127,7 +127,7 @@ def nextfile():
def filename():
"""
Return the name of the file currently being read.
Before the first line has been read, returns None.
Before the first line has been read, returns None.
"""
if not _state:
raise RuntimeError, "no active input()"
Expand All @@ -137,7 +137,7 @@ def lineno():
"""
Return the cumulative line number of the line that has just been read.
Before the first line has been read, returns 0. After the last line
of the last file has been read, returns the line number of that line.
of the last file has been read, returns the line number of that line.
"""
if not _state:
raise RuntimeError, "no active input()"
Expand All @@ -147,7 +147,7 @@ def filelineno():
"""
Return the line number in the current file. Before the first line
has been read, returns 0. After the last line of the last file has
been read, returns the line number of that line within the file.
been read, returns the line number of that line within the file.
"""
if not _state:
raise RuntimeError, "no active input()"
Expand All @@ -156,7 +156,7 @@ def filelineno():
def isfirstline():
"""
Returns true the line just read is the first line of its file,
otherwise returns false.
otherwise returns false.
"""
if not _state:
raise RuntimeError, "no active input()"
Expand All @@ -165,22 +165,22 @@ def isfirstline():
def isstdin():
"""
Returns true if the last line was read from sys.stdin,
otherwise returns false.
otherwise returns false.
"""
if not _state:
raise RuntimeError, "no active input()"
return _state.isstdin()

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

def __init__(self, files=None, inplace=0, backup="", bufsize=0):
Expand Down
26 changes: 13 additions & 13 deletions Lib/macpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,16 @@ def abspath(path):

# realpath is a no-op on systems without islink support
def realpath(path):
path = abspath(path)
try:
import macfs
except ImportError:
return path
if not path:
return path
components = path.split(':')
path = components[0] + ':'
for c in components[1:]:
path = join(path, c)
path = macfs.ResolveAliasFile(path)[0].as_pathname()
return path
path = abspath(path)
try:
import macfs
except ImportError:
return path
if not path:
return path
components = path.split(':')
path = components[0] + ':'
for c in components[1:]:
path = join(path, c)
path = macfs.ResolveAliasFile(path)[0].as_pathname()
return path
2 changes: 1 addition & 1 deletion Lib/pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ def load_reduce(self):
import warnings
warnings.warn("The None return argument form of __reduce__ is "
"deprecated. Return a tuple of arguments instead.",
DeprecationWarning)
DeprecationWarning)
value = callable.__basicnew__()
else:
value = apply(callable, arg_tup)
Expand Down
10 changes: 5 additions & 5 deletions Lib/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,14 +445,14 @@ def vonmisesvariate(self, mu, kappa):
## -------------------- gamma distribution --------------------

def gammavariate(self, alpha, beta):

# alpha > 0, beta > 0, mean is alpha*beta, variance is alpha*beta**2

# Warning: a few older sources define the gamma distribution in terms
# of alpha > -1.0
if alpha <= 0.0 or beta <= 0.0:
raise ValueError, 'gammavariate: alpha and beta must be > 0.0'

random = self.random
if alpha > 1.0:

Expand All @@ -463,7 +463,7 @@ def gammavariate(self, alpha, beta):
ainv = _sqrt(2.0 * alpha - 1.0)
bbb = alpha - LOG4
ccc = alpha + ainv

while 1:
u1 = random()
u2 = random()
Expand Down Expand Up @@ -630,7 +630,7 @@ def _test(N=20000):
_test_generator(N, 'vonmisesvariate(0.0, 1.0)')
_test_generator(N, 'gammavariate(0.01, 1.0)')
_test_generator(N, 'gammavariate(0.1, 1.0)')
_test_generator(N, 'gammavariate(0.1, 2.0)')
_test_generator(N, 'gammavariate(0.1, 2.0)')
_test_generator(N, 'gammavariate(0.5, 1.0)')
_test_generator(N, 'gammavariate(0.9, 1.0)')
_test_generator(N, 'gammavariate(1.0, 1.0)')
Expand Down
Loading

0 comments on commit 8ac1495

Please sign in to comment.