mirror of
https://github.com/python/cpython.git
synced 2025-09-21 16:10:33 +00:00
Whitespace normalization.
This commit is contained in:
parent
f6922aa435
commit
11cf605f84
3 changed files with 98 additions and 98 deletions
|
@ -32,31 +32,31 @@ XXX To do:
|
||||||
|
|
||||||
# Log files
|
# Log files
|
||||||
# ---------
|
# ---------
|
||||||
#
|
#
|
||||||
# Here's a quote from the NCSA httpd docs about log file format.
|
# Here's a quote from the NCSA httpd docs about log file format.
|
||||||
#
|
#
|
||||||
# | The logfile format is as follows. Each line consists of:
|
# | The logfile format is as follows. Each line consists of:
|
||||||
# |
|
# |
|
||||||
# | host rfc931 authuser [DD/Mon/YYYY:hh:mm:ss] "request" ddd bbbb
|
# | host rfc931 authuser [DD/Mon/YYYY:hh:mm:ss] "request" ddd bbbb
|
||||||
# |
|
# |
|
||||||
# | host: Either the DNS name or the IP number of the remote client
|
# | host: Either the DNS name or the IP number of the remote client
|
||||||
# | rfc931: Any information returned by identd for this person,
|
# | rfc931: Any information returned by identd for this person,
|
||||||
# | - otherwise.
|
# | - otherwise.
|
||||||
# | authuser: If user sent a userid for authentication, the user name,
|
# | authuser: If user sent a userid for authentication, the user name,
|
||||||
# | - otherwise.
|
# | - otherwise.
|
||||||
# | DD: Day
|
# | DD: Day
|
||||||
# | Mon: Month (calendar name)
|
# | Mon: Month (calendar name)
|
||||||
# | YYYY: Year
|
# | YYYY: Year
|
||||||
# | hh: hour (24-hour format, the machine's timezone)
|
# | hh: hour (24-hour format, the machine's timezone)
|
||||||
# | mm: minutes
|
# | mm: minutes
|
||||||
# | ss: seconds
|
# | ss: seconds
|
||||||
# | request: The first line of the HTTP request as sent by the client.
|
# | request: The first line of the HTTP request as sent by the client.
|
||||||
# | ddd: the status code returned by the server, - if not available.
|
# | ddd: the status code returned by the server, - if not available.
|
||||||
# | bbbb: the total number of bytes sent,
|
# | bbbb: the total number of bytes sent,
|
||||||
# | *not including the HTTP/1.0 header*, - if not available
|
# | *not including the HTTP/1.0 header*, - if not available
|
||||||
# |
|
# |
|
||||||
# | You can determine the name of the file accessed through request.
|
# | You can determine the name of the file accessed through request.
|
||||||
#
|
#
|
||||||
# (Actually, the latter is only true if you know the server configuration
|
# (Actually, the latter is only true if you know the server configuration
|
||||||
# at the time the request was made!)
|
# at the time the request was made!)
|
||||||
|
|
||||||
|
@ -429,13 +429,13 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
|
||||||
'Request accepted, processing continues off-line'),
|
'Request accepted, processing continues off-line'),
|
||||||
203: ('Partial information', 'Request fulfilled from cache'),
|
203: ('Partial information', 'Request fulfilled from cache'),
|
||||||
204: ('No response', 'Request fulfilled, nothing follows'),
|
204: ('No response', 'Request fulfilled, nothing follows'),
|
||||||
|
|
||||||
301: ('Moved', 'Object moved permanently -- see URI list'),
|
301: ('Moved', 'Object moved permanently -- see URI list'),
|
||||||
302: ('Found', 'Object moved temporarily -- see URI list'),
|
302: ('Found', 'Object moved temporarily -- see URI list'),
|
||||||
303: ('Method', 'Object moved -- see Method and URL list'),
|
303: ('Method', 'Object moved -- see Method and URL list'),
|
||||||
304: ('Not modified',
|
304: ('Not modified',
|
||||||
'Document has not changed singe given time'),
|
'Document has not changed singe given time'),
|
||||||
|
|
||||||
400: ('Bad request',
|
400: ('Bad request',
|
||||||
'Bad request syntax or unsupported method'),
|
'Bad request syntax or unsupported method'),
|
||||||
401: ('Unauthorized',
|
401: ('Unauthorized',
|
||||||
|
@ -445,7 +445,7 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
|
||||||
403: ('Forbidden',
|
403: ('Forbidden',
|
||||||
'Request forbidden -- authorization will not help'),
|
'Request forbidden -- authorization will not help'),
|
||||||
404: ('Not found', 'Nothing matches the given URI'),
|
404: ('Not found', 'Nothing matches the given URI'),
|
||||||
|
|
||||||
500: ('Internal error', 'Server got itself in trouble'),
|
500: ('Internal error', 'Server got itself in trouble'),
|
||||||
501: ('Not implemented',
|
501: ('Not implemented',
|
||||||
'Server does not support this operation'),
|
'Server does not support this operation'),
|
||||||
|
@ -453,7 +453,7 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
|
||||||
'The server cannot process the request due to a high load'),
|
'The server cannot process the request due to a high load'),
|
||||||
503: ('Gateway timeout',
|
503: ('Gateway timeout',
|
||||||
'The gateway server did not receive a timely response'),
|
'The gateway server did not receive a timely response'),
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
88
Lib/bdb.py
88
Lib/bdb.py
|
@ -8,7 +8,7 @@ BdbQuit = 'bdb.BdbQuit' # Exception to give up completely
|
||||||
|
|
||||||
|
|
||||||
class Bdb:
|
class Bdb:
|
||||||
|
|
||||||
"""Generic Python debugger base class.
|
"""Generic Python debugger base class.
|
||||||
|
|
||||||
This class takes care of details of the trace facility;
|
This class takes care of details of the trace facility;
|
||||||
|
@ -26,7 +26,7 @@ class Bdb:
|
||||||
canonic = os.path.abspath(filename)
|
canonic = os.path.abspath(filename)
|
||||||
self.fncache[filename] = canonic
|
self.fncache[filename] = canonic
|
||||||
return canonic
|
return canonic
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
import linecache
|
import linecache
|
||||||
linecache.checkcache()
|
linecache.checkcache()
|
||||||
|
@ -34,7 +34,7 @@ class Bdb:
|
||||||
self.stopframe = None
|
self.stopframe = None
|
||||||
self.returnframe = None
|
self.returnframe = None
|
||||||
self.quitting = 0
|
self.quitting = 0
|
||||||
|
|
||||||
def trace_dispatch(self, frame, event, arg):
|
def trace_dispatch(self, frame, event, arg):
|
||||||
if self.quitting:
|
if self.quitting:
|
||||||
return # None
|
return # None
|
||||||
|
@ -48,13 +48,13 @@ class Bdb:
|
||||||
return self.dispatch_exception(frame, arg)
|
return self.dispatch_exception(frame, arg)
|
||||||
print 'bdb.Bdb.dispatch: unknown debugging event:', `event`
|
print 'bdb.Bdb.dispatch: unknown debugging event:', `event`
|
||||||
return self.trace_dispatch
|
return self.trace_dispatch
|
||||||
|
|
||||||
def dispatch_line(self, frame):
|
def dispatch_line(self, frame):
|
||||||
if self.stop_here(frame) or self.break_here(frame):
|
if self.stop_here(frame) or self.break_here(frame):
|
||||||
self.user_line(frame)
|
self.user_line(frame)
|
||||||
if self.quitting: raise BdbQuit
|
if self.quitting: raise BdbQuit
|
||||||
return self.trace_dispatch
|
return self.trace_dispatch
|
||||||
|
|
||||||
def dispatch_call(self, frame, arg):
|
def dispatch_call(self, frame, arg):
|
||||||
# XXX 'arg' is no longer used
|
# XXX 'arg' is no longer used
|
||||||
if self.botframe is None:
|
if self.botframe is None:
|
||||||
|
@ -67,22 +67,22 @@ class Bdb:
|
||||||
self.user_call(frame, arg)
|
self.user_call(frame, arg)
|
||||||
if self.quitting: raise BdbQuit
|
if self.quitting: raise BdbQuit
|
||||||
return self.trace_dispatch
|
return self.trace_dispatch
|
||||||
|
|
||||||
def dispatch_return(self, frame, arg):
|
def dispatch_return(self, frame, arg):
|
||||||
if self.stop_here(frame) or frame == self.returnframe:
|
if self.stop_here(frame) or frame == self.returnframe:
|
||||||
self.user_return(frame, arg)
|
self.user_return(frame, arg)
|
||||||
if self.quitting: raise BdbQuit
|
if self.quitting: raise BdbQuit
|
||||||
|
|
||||||
def dispatch_exception(self, frame, arg):
|
def dispatch_exception(self, frame, arg):
|
||||||
if self.stop_here(frame):
|
if self.stop_here(frame):
|
||||||
self.user_exception(frame, arg)
|
self.user_exception(frame, arg)
|
||||||
if self.quitting: raise BdbQuit
|
if self.quitting: raise BdbQuit
|
||||||
return self.trace_dispatch
|
return self.trace_dispatch
|
||||||
|
|
||||||
# Normally derived classes don't override the following
|
# Normally derived classes don't override the following
|
||||||
# methods, but they may if they want to redefine the
|
# methods, but they may if they want to redefine the
|
||||||
# definition of stopping and breakpoints.
|
# definition of stopping and breakpoints.
|
||||||
|
|
||||||
def stop_here(self, frame):
|
def stop_here(self, frame):
|
||||||
if self.stopframe is None:
|
if self.stopframe is None:
|
||||||
return 1
|
return 1
|
||||||
|
@ -110,53 +110,53 @@ class Bdb:
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def break_anywhere(self, frame):
|
def break_anywhere(self, frame):
|
||||||
return self.breaks.has_key(
|
return self.breaks.has_key(
|
||||||
self.canonic(frame.f_code.co_filename))
|
self.canonic(frame.f_code.co_filename))
|
||||||
|
|
||||||
# Derived classes should override the user_* methods
|
# Derived classes should override the user_* methods
|
||||||
# to gain control.
|
# to gain control.
|
||||||
|
|
||||||
def user_call(self, frame, argument_list):
|
def user_call(self, frame, argument_list):
|
||||||
"""This method is called when there is the remote possibility
|
"""This method is called when there is the remote possibility
|
||||||
that we ever need to stop in this function."""
|
that we ever need to stop in this function."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def user_line(self, frame):
|
def user_line(self, frame):
|
||||||
"""This method is called when we stop or break at this line."""
|
"""This method is called when we stop or break at this line."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def user_return(self, frame, return_value):
|
def user_return(self, frame, return_value):
|
||||||
"""This method is called when a return trap is set here."""
|
"""This method is called when a return trap is set here."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def user_exception(self, frame, (exc_type, exc_value, exc_traceback)):
|
def user_exception(self, frame, (exc_type, exc_value, exc_traceback)):
|
||||||
"""This method is called if an exception occurs,
|
"""This method is called if an exception occurs,
|
||||||
but only if we are to stop at or just below this level."""
|
but only if we are to stop at or just below this level."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Derived classes and clients can call the following methods
|
# Derived classes and clients can call the following methods
|
||||||
# to affect the stepping state.
|
# to affect the stepping state.
|
||||||
|
|
||||||
def set_step(self):
|
def set_step(self):
|
||||||
"""Stop after one line of code."""
|
"""Stop after one line of code."""
|
||||||
self.stopframe = None
|
self.stopframe = None
|
||||||
self.returnframe = None
|
self.returnframe = None
|
||||||
self.quitting = 0
|
self.quitting = 0
|
||||||
|
|
||||||
def set_next(self, frame):
|
def set_next(self, frame):
|
||||||
"""Stop on the next line in or below the given frame."""
|
"""Stop on the next line in or below the given frame."""
|
||||||
self.stopframe = frame
|
self.stopframe = frame
|
||||||
self.returnframe = None
|
self.returnframe = None
|
||||||
self.quitting = 0
|
self.quitting = 0
|
||||||
|
|
||||||
def set_return(self, frame):
|
def set_return(self, frame):
|
||||||
"""Stop when returning from the given frame."""
|
"""Stop when returning from the given frame."""
|
||||||
self.stopframe = frame.f_back
|
self.stopframe = frame.f_back
|
||||||
self.returnframe = frame
|
self.returnframe = frame
|
||||||
self.quitting = 0
|
self.quitting = 0
|
||||||
|
|
||||||
def set_trace(self):
|
def set_trace(self):
|
||||||
"""Start debugging from here."""
|
"""Start debugging from here."""
|
||||||
try:
|
try:
|
||||||
|
@ -186,20 +186,20 @@ class Bdb:
|
||||||
while frame and frame is not self.botframe:
|
while frame and frame is not self.botframe:
|
||||||
del frame.f_trace
|
del frame.f_trace
|
||||||
frame = frame.f_back
|
frame = frame.f_back
|
||||||
|
|
||||||
def set_quit(self):
|
def set_quit(self):
|
||||||
self.stopframe = self.botframe
|
self.stopframe = self.botframe
|
||||||
self.returnframe = None
|
self.returnframe = None
|
||||||
self.quitting = 1
|
self.quitting = 1
|
||||||
sys.settrace(None)
|
sys.settrace(None)
|
||||||
|
|
||||||
# Derived classes and clients can call the following methods
|
# Derived classes and clients can call the following methods
|
||||||
# to manipulate breakpoints. These methods return an
|
# to manipulate breakpoints. These methods return an
|
||||||
# error message is something went wrong, None if all is well.
|
# error message is something went wrong, None if all is well.
|
||||||
# Set_break prints out the breakpoint line and file:lineno.
|
# Set_break prints out the breakpoint line and file:lineno.
|
||||||
# Call self.get_*break*() to see the breakpoints or better
|
# Call self.get_*break*() to see the breakpoints or better
|
||||||
# for bp in Breakpoint.bpbynumber: if bp: bp.bpprint().
|
# for bp in Breakpoint.bpbynumber: if bp: bp.bpprint().
|
||||||
|
|
||||||
def set_break(self, filename, lineno, temporary=0, cond = None):
|
def set_break(self, filename, lineno, temporary=0, cond = None):
|
||||||
filename = self.canonic(filename)
|
filename = self.canonic(filename)
|
||||||
import linecache # Import as late as possible
|
import linecache # Import as late as possible
|
||||||
|
@ -229,7 +229,7 @@ class Bdb:
|
||||||
self.breaks[filename].remove(lineno)
|
self.breaks[filename].remove(lineno)
|
||||||
if not self.breaks[filename]:
|
if not self.breaks[filename]:
|
||||||
del self.breaks[filename]
|
del self.breaks[filename]
|
||||||
|
|
||||||
def clear_bpbynumber(self, arg):
|
def clear_bpbynumber(self, arg):
|
||||||
try:
|
try:
|
||||||
number = int(arg)
|
number = int(arg)
|
||||||
|
@ -252,7 +252,7 @@ class Bdb:
|
||||||
for bp in blist:
|
for bp in blist:
|
||||||
bp.deleteMe()
|
bp.deleteMe()
|
||||||
del self.breaks[filename]
|
del self.breaks[filename]
|
||||||
|
|
||||||
def clear_all_breaks(self):
|
def clear_all_breaks(self):
|
||||||
if not self.breaks:
|
if not self.breaks:
|
||||||
return 'There are no breakpoints'
|
return 'There are no breakpoints'
|
||||||
|
@ -260,31 +260,31 @@ class Bdb:
|
||||||
if bp:
|
if bp:
|
||||||
bp.deleteMe()
|
bp.deleteMe()
|
||||||
self.breaks = {}
|
self.breaks = {}
|
||||||
|
|
||||||
def get_break(self, filename, lineno):
|
def get_break(self, filename, lineno):
|
||||||
filename = self.canonic(filename)
|
filename = self.canonic(filename)
|
||||||
return self.breaks.has_key(filename) and \
|
return self.breaks.has_key(filename) and \
|
||||||
lineno in self.breaks[filename]
|
lineno in self.breaks[filename]
|
||||||
|
|
||||||
def get_breaks(self, filename, lineno):
|
def get_breaks(self, filename, lineno):
|
||||||
filename = self.canonic(filename)
|
filename = self.canonic(filename)
|
||||||
return self.breaks.has_key(filename) and \
|
return self.breaks.has_key(filename) and \
|
||||||
lineno in self.breaks[filename] and \
|
lineno in self.breaks[filename] and \
|
||||||
Breakpoint.bplist[filename, lineno] or []
|
Breakpoint.bplist[filename, lineno] or []
|
||||||
|
|
||||||
def get_file_breaks(self, filename):
|
def get_file_breaks(self, filename):
|
||||||
filename = self.canonic(filename)
|
filename = self.canonic(filename)
|
||||||
if self.breaks.has_key(filename):
|
if self.breaks.has_key(filename):
|
||||||
return self.breaks[filename]
|
return self.breaks[filename]
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def get_all_breaks(self):
|
def get_all_breaks(self):
|
||||||
return self.breaks
|
return self.breaks
|
||||||
|
|
||||||
# Derived classes and clients can call the following method
|
# Derived classes and clients can call the following method
|
||||||
# to get a data structure representing a stack trace.
|
# to get a data structure representing a stack trace.
|
||||||
|
|
||||||
def get_stack(self, f, t):
|
def get_stack(self, f, t):
|
||||||
stack = []
|
stack = []
|
||||||
if t and t.tb_frame is f:
|
if t and t.tb_frame is f:
|
||||||
|
@ -300,9 +300,9 @@ class Bdb:
|
||||||
stack.append((t.tb_frame, t.tb_lineno))
|
stack.append((t.tb_frame, t.tb_lineno))
|
||||||
t = t.tb_next
|
t = t.tb_next
|
||||||
return stack, i
|
return stack, i
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
||||||
def format_stack_entry(self, frame_lineno, lprefix=': '):
|
def format_stack_entry(self, frame_lineno, lprefix=': '):
|
||||||
import linecache, repr, string
|
import linecache, repr, string
|
||||||
frame, lineno = frame_lineno
|
frame, lineno = frame_lineno
|
||||||
|
@ -327,10 +327,10 @@ class Bdb:
|
||||||
line = linecache.getline(filename, lineno)
|
line = linecache.getline(filename, lineno)
|
||||||
if line: s = s + lprefix + string.strip(line)
|
if line: s = s + lprefix + string.strip(line)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
# The following two methods can be called by clients to use
|
# The following two methods can be called by clients to use
|
||||||
# a debugger to debug a statement, given as a string.
|
# a debugger to debug a statement, given as a string.
|
||||||
|
|
||||||
def run(self, cmd, globals=None, locals=None):
|
def run(self, cmd, globals=None, locals=None):
|
||||||
if globals is None:
|
if globals is None:
|
||||||
import __main__
|
import __main__
|
||||||
|
@ -349,7 +349,7 @@ class Bdb:
|
||||||
finally:
|
finally:
|
||||||
self.quitting = 1
|
self.quitting = 1
|
||||||
sys.settrace(None)
|
sys.settrace(None)
|
||||||
|
|
||||||
def runeval(self, expr, globals=None, locals=None):
|
def runeval(self, expr, globals=None, locals=None):
|
||||||
if globals is None:
|
if globals is None:
|
||||||
import __main__
|
import __main__
|
||||||
|
@ -435,7 +435,7 @@ class Breakpoint:
|
||||||
else:
|
else:
|
||||||
self.bplist[file, line] = [self]
|
self.bplist[file, line] = [self]
|
||||||
|
|
||||||
|
|
||||||
def deleteMe(self):
|
def deleteMe(self):
|
||||||
index = (self.file, self.line)
|
index = (self.file, self.line)
|
||||||
self.bpbynumber[self.number] = None # No longer in list
|
self.bpbynumber[self.number] = None # No longer in list
|
||||||
|
@ -452,13 +452,13 @@ class Breakpoint:
|
||||||
|
|
||||||
def bpprint(self):
|
def bpprint(self):
|
||||||
if self.temporary:
|
if self.temporary:
|
||||||
disp = 'del '
|
disp = 'del '
|
||||||
else:
|
else:
|
||||||
disp = 'keep '
|
disp = 'keep '
|
||||||
if self.enabled:
|
if self.enabled:
|
||||||
disp = disp + 'yes'
|
disp = disp + 'yes'
|
||||||
else:
|
else:
|
||||||
disp = disp + 'no '
|
disp = disp + 'no '
|
||||||
print '%-4dbreakpoint %s at %s:%d' % (self.number, disp,
|
print '%-4dbreakpoint %s at %s:%d' % (self.number, disp,
|
||||||
self.file, self.line)
|
self.file, self.line)
|
||||||
if self.cond:
|
if self.cond:
|
||||||
|
@ -506,7 +506,7 @@ def effective(file, line, frame):
|
||||||
# condition evaluates to true.
|
# condition evaluates to true.
|
||||||
try:
|
try:
|
||||||
val = eval(b.cond, frame.f_globals,
|
val = eval(b.cond, frame.f_globals,
|
||||||
frame.f_locals)
|
frame.f_locals)
|
||||||
if val:
|
if val:
|
||||||
if b.ignore > 0:
|
if b.ignore > 0:
|
||||||
b.ignore = b.ignore -1
|
b.ignore = b.ignore -1
|
||||||
|
@ -518,7 +518,7 @@ def effective(file, line, frame):
|
||||||
except:
|
except:
|
||||||
# if eval fails, most conservative
|
# if eval fails, most conservative
|
||||||
# thing is to stop on breakpoint
|
# thing is to stop on breakpoint
|
||||||
# regardless of ignore count.
|
# regardless of ignore count.
|
||||||
# Don't delete temporary,
|
# Don't delete temporary,
|
||||||
# as another hint to user.
|
# as another hint to user.
|
||||||
return (b,0)
|
return (b,0)
|
||||||
|
|
|
@ -26,7 +26,7 @@ import os
|
||||||
import struct
|
import struct
|
||||||
import string
|
import string
|
||||||
import binascii
|
import binascii
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -51,10 +51,10 @@ if os.name == 'mac':
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# Backward compatibility
|
# Backward compatibility
|
||||||
openrf = open
|
openrf = open
|
||||||
|
|
||||||
def FInfo():
|
def FInfo():
|
||||||
return macfs.FInfo()
|
return macfs.FInfo()
|
||||||
|
|
||||||
def getfileinfo(name):
|
def getfileinfo(name):
|
||||||
finfo = macfs.FSSpec(name).GetFInfo()
|
finfo = macfs.FSSpec(name).GetFInfo()
|
||||||
dir, file = os.path.split(name)
|
dir, file = os.path.split(name)
|
||||||
|
@ -66,7 +66,7 @@ if os.name == 'mac':
|
||||||
fp.seek(0, 2)
|
fp.seek(0, 2)
|
||||||
rlen = fp.tell()
|
rlen = fp.tell()
|
||||||
return file, finfo, dlen, rlen
|
return file, finfo, dlen, rlen
|
||||||
|
|
||||||
def openrsrc(name, *mode):
|
def openrsrc(name, *mode):
|
||||||
if not mode:
|
if not mode:
|
||||||
mode = '*rb'
|
mode = '*rb'
|
||||||
|
@ -78,7 +78,7 @@ else:
|
||||||
#
|
#
|
||||||
# Glue code for non-macintosh usage
|
# Glue code for non-macintosh usage
|
||||||
#
|
#
|
||||||
|
|
||||||
class FInfo:
|
class FInfo:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.Type = '????'
|
self.Type = '????'
|
||||||
|
@ -106,19 +106,19 @@ else:
|
||||||
class openrsrc:
|
class openrsrc:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def read(self, *args):
|
def read(self, *args):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def write(self, *args):
|
def write(self, *args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class _Hqxcoderengine:
|
class _Hqxcoderengine:
|
||||||
"""Write data to the coder in 3-byte chunks"""
|
"""Write data to the coder in 3-byte chunks"""
|
||||||
|
|
||||||
def __init__(self, ofp):
|
def __init__(self, ofp):
|
||||||
self.ofp = ofp
|
self.ofp = ofp
|
||||||
self.data = ''
|
self.data = ''
|
||||||
|
@ -253,12 +253,12 @@ class BinHex:
|
||||||
self.ofp.close()
|
self.ofp.close()
|
||||||
self.state = None
|
self.state = None
|
||||||
del self.ofp
|
del self.ofp
|
||||||
|
|
||||||
def binhex(inp, out):
|
def binhex(inp, out):
|
||||||
"""(infilename, outfilename) - Create binhex-encoded copy of a file"""
|
"""(infilename, outfilename) - Create binhex-encoded copy of a file"""
|
||||||
finfo = getfileinfo(inp)
|
finfo = getfileinfo(inp)
|
||||||
ofp = BinHex(finfo, out)
|
ofp = BinHex(finfo, out)
|
||||||
|
|
||||||
ifp = open(inp, 'rb')
|
ifp = open(inp, 'rb')
|
||||||
# XXXX Do textfile translation on non-mac systems
|
# XXXX Do textfile translation on non-mac systems
|
||||||
while 1:
|
while 1:
|
||||||
|
@ -274,11 +274,11 @@ def binhex(inp, out):
|
||||||
if not d: break
|
if not d: break
|
||||||
ofp.write_rsrc(d)
|
ofp.write_rsrc(d)
|
||||||
ofp.close()
|
ofp.close()
|
||||||
ifp.close()
|
ifp.close()
|
||||||
|
|
||||||
class _Hqxdecoderengine:
|
class _Hqxdecoderengine:
|
||||||
"""Read data via the decoder in 4-byte chunks"""
|
"""Read data via the decoder in 4-byte chunks"""
|
||||||
|
|
||||||
def __init__(self, ifp):
|
def __init__(self, ifp):
|
||||||
self.ifp = ifp
|
self.ifp = ifp
|
||||||
self.eof = 0
|
self.eof = 0
|
||||||
|
@ -288,7 +288,7 @@ class _Hqxdecoderengine:
|
||||||
decdata = ''
|
decdata = ''
|
||||||
wtd = totalwtd
|
wtd = totalwtd
|
||||||
#
|
#
|
||||||
# The loop here is convoluted, since we don't really now how
|
# The loop here is convoluted, since we don't really now how
|
||||||
# much to decode: there may be newlines in the incoming data.
|
# much to decode: there may be newlines in the incoming data.
|
||||||
while wtd > 0:
|
while wtd > 0:
|
||||||
if self.eof: return decdata
|
if self.eof: return decdata
|
||||||
|
@ -343,7 +343,7 @@ class _Rledecoderengine:
|
||||||
binascii.rledecode_hqx(self.pre_buffer)
|
binascii.rledecode_hqx(self.pre_buffer)
|
||||||
self.pre_buffer = ''
|
self.pre_buffer = ''
|
||||||
return
|
return
|
||||||
|
|
||||||
#
|
#
|
||||||
# Obfuscated code ahead. We have to take care that we don't
|
# Obfuscated code ahead. We have to take care that we don't
|
||||||
# end up with an orphaned RUNCHAR later on. So, we keep a couple
|
# end up with an orphaned RUNCHAR later on. So, we keep a couple
|
||||||
|
@ -393,17 +393,17 @@ class HexBin:
|
||||||
break
|
break
|
||||||
if ch != '\n':
|
if ch != '\n':
|
||||||
dummy = ifp.readline()
|
dummy = ifp.readline()
|
||||||
|
|
||||||
hqxifp = _Hqxdecoderengine(ifp)
|
hqxifp = _Hqxdecoderengine(ifp)
|
||||||
self.ifp = _Rledecoderengine(hqxifp)
|
self.ifp = _Rledecoderengine(hqxifp)
|
||||||
self.crc = 0
|
self.crc = 0
|
||||||
self._readheader()
|
self._readheader()
|
||||||
|
|
||||||
def _read(self, len):
|
def _read(self, len):
|
||||||
data = self.ifp.read(len)
|
data = self.ifp.read(len)
|
||||||
self.crc = binascii.crc_hqx(data, self.crc)
|
self.crc = binascii.crc_hqx(data, self.crc)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _checkcrc(self):
|
def _checkcrc(self):
|
||||||
filecrc = struct.unpack('>h', self.ifp.read(2))[0] & 0xffff
|
filecrc = struct.unpack('>h', self.ifp.read(2))[0] & 0xffff
|
||||||
#self.crc = binascii.crc_hqx('\0\0', self.crc)
|
#self.crc = binascii.crc_hqx('\0\0', self.crc)
|
||||||
|
@ -419,21 +419,21 @@ class HexBin:
|
||||||
fname = self._read(ord(len))
|
fname = self._read(ord(len))
|
||||||
rest = self._read(1+4+4+2+4+4)
|
rest = self._read(1+4+4+2+4+4)
|
||||||
self._checkcrc()
|
self._checkcrc()
|
||||||
|
|
||||||
type = rest[1:5]
|
type = rest[1:5]
|
||||||
creator = rest[5:9]
|
creator = rest[5:9]
|
||||||
flags = struct.unpack('>h', rest[9:11])[0]
|
flags = struct.unpack('>h', rest[9:11])[0]
|
||||||
self.dlen = struct.unpack('>l', rest[11:15])[0]
|
self.dlen = struct.unpack('>l', rest[11:15])[0]
|
||||||
self.rlen = struct.unpack('>l', rest[15:19])[0]
|
self.rlen = struct.unpack('>l', rest[15:19])[0]
|
||||||
|
|
||||||
self.FName = fname
|
self.FName = fname
|
||||||
self.FInfo = FInfo()
|
self.FInfo = FInfo()
|
||||||
self.FInfo.Creator = creator
|
self.FInfo.Creator = creator
|
||||||
self.FInfo.Type = type
|
self.FInfo.Type = type
|
||||||
self.FInfo.Flags = flags
|
self.FInfo.Flags = flags
|
||||||
|
|
||||||
self.state = _DID_HEADER
|
self.state = _DID_HEADER
|
||||||
|
|
||||||
def read(self, *n):
|
def read(self, *n):
|
||||||
if self.state != _DID_HEADER:
|
if self.state != _DID_HEADER:
|
||||||
raise Error, 'Read data at wrong time'
|
raise Error, 'Read data at wrong time'
|
||||||
|
@ -447,7 +447,7 @@ class HexBin:
|
||||||
rv = rv + self._read(n-len(rv))
|
rv = rv + self._read(n-len(rv))
|
||||||
self.dlen = self.dlen - n
|
self.dlen = self.dlen - n
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
def close_data(self):
|
def close_data(self):
|
||||||
if self.state != _DID_HEADER:
|
if self.state != _DID_HEADER:
|
||||||
raise Error, 'close_data at wrong time'
|
raise Error, 'close_data at wrong time'
|
||||||
|
@ -455,7 +455,7 @@ class HexBin:
|
||||||
dummy = self._read(self.dlen)
|
dummy = self._read(self.dlen)
|
||||||
self._checkcrc()
|
self._checkcrc()
|
||||||
self.state = _DID_DATA
|
self.state = _DID_DATA
|
||||||
|
|
||||||
def read_rsrc(self, *n):
|
def read_rsrc(self, *n):
|
||||||
if self.state == _DID_HEADER:
|
if self.state == _DID_HEADER:
|
||||||
self.close_data()
|
self.close_data()
|
||||||
|
@ -468,14 +468,14 @@ class HexBin:
|
||||||
n = self.rlen
|
n = self.rlen
|
||||||
self.rlen = self.rlen - n
|
self.rlen = self.rlen - n
|
||||||
return self._read(n)
|
return self._read(n)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if self.rlen:
|
if self.rlen:
|
||||||
dummy = self.read_rsrc(self.rlen)
|
dummy = self.read_rsrc(self.rlen)
|
||||||
self._checkcrc()
|
self._checkcrc()
|
||||||
self.state = _DID_RSRC
|
self.state = _DID_RSRC
|
||||||
self.ifp.close()
|
self.ifp.close()
|
||||||
|
|
||||||
def hexbin(inp, out):
|
def hexbin(inp, out):
|
||||||
"""(infilename, outfilename) - Decode binhexed file"""
|
"""(infilename, outfilename) - Decode binhexed file"""
|
||||||
ifp = HexBin(inp)
|
ifp = HexBin(inp)
|
||||||
|
@ -494,7 +494,7 @@ def hexbin(inp, out):
|
||||||
ofp.write(d)
|
ofp.write(d)
|
||||||
ofp.close()
|
ofp.close()
|
||||||
ifp.close_data()
|
ifp.close_data()
|
||||||
|
|
||||||
d = ifp.read_rsrc(128000)
|
d = ifp.read_rsrc(128000)
|
||||||
if d:
|
if d:
|
||||||
ofp = openrsrc(out, 'wb')
|
ofp = openrsrc(out, 'wb')
|
||||||
|
@ -511,7 +511,7 @@ def hexbin(inp, out):
|
||||||
nfinfo.Type = finfo.Type
|
nfinfo.Type = finfo.Type
|
||||||
nfinfo.Flags = finfo.Flags
|
nfinfo.Flags = finfo.Flags
|
||||||
ofss.SetFInfo(nfinfo)
|
ofss.SetFInfo(nfinfo)
|
||||||
|
|
||||||
ifp.close()
|
ifp.close()
|
||||||
|
|
||||||
def _test():
|
def _test():
|
||||||
|
@ -526,6 +526,6 @@ def _test():
|
||||||
hexbin(fname+'.hqx', fname+'.viahqx')
|
hexbin(fname+'.hqx', fname+'.viahqx')
|
||||||
#hexbin(fname, fname+'.unpacked')
|
#hexbin(fname, fname+'.unpacked')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
_test()
|
_test()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue