Kaydet (Commit) fea2af1e authored tarafından Guido van Rossum's avatar Guido van Rossum

* More changes due to stricter argument passing rules

* Fixed calendar.py, mimetools.py, whrandom.py to cope with time.time()
  returning a floating point number.  (And fix old bug in calendar)
* Add recursion level to mainloop.mainloop(), to make it reentrant.
üst a2b7f405
...@@ -31,6 +31,7 @@ error = 'calendar error' ...@@ -31,6 +31,7 @@ error = 'calendar error'
# Turn seconds since epoch into calendar time # Turn seconds since epoch into calendar time
def gmtime(secs): def gmtime(secs):
if secs < 0: raise error, 'negative input to gmtime()' if secs < 0: raise error, 'negative input to gmtime()'
secs = int(secs)
mins, secs = divmod(secs, 60) mins, secs = divmod(secs, 60)
hours, mins = divmod(mins, 60) hours, mins = divmod(mins, 60)
days, hours = divmod(hours, 24) days, hours = divmod(hours, 24)
...@@ -146,7 +147,7 @@ def monthcalendar(year, month): ...@@ -146,7 +147,7 @@ def monthcalendar(year, month):
key = `year` + month_abbr[month] key = `year` + month_abbr[month]
try: try:
return mc_cache[key] return mc_cache[key]
except IOError: except KeyError:
mc_cache[key] = ret = _monthcalendar(year, month) mc_cache[key] = ret = _monthcalendar(year, month)
return ret return ret
......
...@@ -27,15 +27,14 @@ class BoxParent(TransParent): ...@@ -27,15 +27,14 @@ class BoxParent(TransParent):
def getbounds(self): def getbounds(self):
return self.bounds return self.bounds
# #
def draw(self, args): def draw(self, d, area):
d, area = args
(left, top), (right, bottom) = self.bounds (left, top), (right, bottom) = self.bounds
left = left + 1 left = left + 1
top = top + 1 top = top + 1
right = right - 1 right = right - 1
bottom = bottom - 1 bottom = bottom - 1
d.box((left, top), (right, bottom)) d.box((left, top), (right, bottom))
TransParent.draw(self, args) # XXX clip to innerbounds? TransParent.draw(self, d, area) # XXX clip to innerbounds?
# #
# XXX should scroll clip to innerbounds??? # XXX should scroll clip to innerbounds???
# XXX currently the only user restricts itself to child's bounds # XXX currently the only user restricts itself to child's bounds
...@@ -28,7 +28,7 @@ class DirList(VSplit): ...@@ -28,7 +28,7 @@ class DirList(VSplit):
class DirListWindow(WindowParent): class DirListWindow(WindowParent):
# #
def create(self, dirname): def create(self, dirname):
self = WindowParent.create(self, (dirname, (0, 0))) self = WindowParent.create(self, dirname, (0, 0))
child = DirList().create(self, dirname) child = DirList().create(self, dirname)
self.realize() self.realize()
return self return self
......
...@@ -55,8 +55,8 @@ class HVSplit(Split): ...@@ -55,8 +55,8 @@ class HVSplit(Split):
class HSplit(HVSplit): class HSplit(HVSplit):
def create(self, parent): def create(self, parent):
return HVSplit.create(self, (parent, 0)) return HVSplit.create(self, parent, 0)
class VSplit(HVSplit): class VSplit(HVSplit):
def create(self, parent): def create(self, parent):
return HVSplit.create(self, (parent, 1)) return HVSplit.create(self, parent, 1)
...@@ -50,10 +50,10 @@ class Split: ...@@ -50,10 +50,10 @@ class Split:
for child in self.children: for child in self.children:
child.realize() child.realize()
# #
def draw(self, d_detail): def draw(self, d, detail):
# (Could avoid calls to children outside the area) # (Could avoid calls to children outside the area)
for child in self.children: for child in self.children:
child.draw(d_detail) child.draw(d, detail)
# #
def altdraw(self, detail): def altdraw(self, detail):
for child in self.altdraw_interest: for child in self.altdraw_interest:
...@@ -112,15 +112,14 @@ class Split: ...@@ -112,15 +112,14 @@ class Split:
if self.keybd_focus: if self.keybd_focus:
self.keybd_focus.deactivate() self.keybd_focus.deactivate()
# #
def keybd(self, type_detail): def keybd(self, type, detail):
if not self.keybd_focus: if not self.keybd_focus:
self.set_keybd_focus(self.keybd_interest[0]) self.set_keybd_focus(self.keybd_interest[0])
type, detail = type_detail
if type == WE_COMMAND and detail == WC_TAB and \ if type == WE_COMMAND and detail == WC_TAB and \
len(self.keybd_interest) > 1: len(self.keybd_interest) > 1:
self.next_keybd_focus() self.next_keybd_focus()
return return
self.keybd_focus.keybd(type_detail) self.keybd_focus.keybd(type, detail)
# #
def timer(self): def timer(self):
for child in self.timer_interest: for child in self.timer_interest:
...@@ -206,7 +205,7 @@ class Split: ...@@ -206,7 +205,7 @@ class Split:
# #
def change(self, area): def change(self, area):
self.parent.change(area) self.parent.change(area)
def scroll(self, area_vector): def scroll(self, area, vector):
self.parent.scroll(area_vector) self.parent.scroll(area, vector)
def settimer(self, itimer): def settimer(self, itimer):
self.parent.settimer(itimer) self.parent.settimer(itimer)
...@@ -60,12 +60,12 @@ class TransParent(ManageOneChild): ...@@ -60,12 +60,12 @@ class TransParent(ManageOneChild):
def realize(self): def realize(self):
if self.child: if self.child:
self.child.realize() self.child.realize()
def draw(self, args): def draw(self, d, area):
if self.child: if self.child:
self.child.draw(args) self.child.draw(d, area)
def altdraw(self, args): def altdraw(self, area):
if self.child: if self.child:
self.child.altdraw(args) self.child.altdraw(area)
# #
# Downcalls only made after certain upcalls # Downcalls only made after certain upcalls
# #
...@@ -117,7 +117,7 @@ class TransParent(ManageOneChild): ...@@ -117,7 +117,7 @@ class TransParent(ManageOneChild):
# #
def change(self, area): def change(self, area):
self.parent.change(area) self.parent.change(area)
def scroll(self, args): def scroll(self, area, vector):
self.parent.scroll(args) self.parent.scroll(area, vector)
def settimer(self, itimer): def settimer(self, itimer):
self.parent.settimer(itimer) self.parent.settimer(itimer)
...@@ -136,9 +136,9 @@ class WindowParent(ManageOneChild): ...@@ -136,9 +136,9 @@ class WindowParent(ManageOneChild):
if self.win: if self.win:
self.win.change(area) self.win.change(area)
# #
def scroll(self, args): def scroll(self, area, vector):
if self.win: if self.win:
self.win.scroll(args) self.win.scroll(area, vector)
# #
def settimer(self, itimer): def settimer(self, itimer):
if self.win: if self.win:
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
# - have a 'dispatch' function as a window member # - have a 'dispatch' function as a window member
# XXX This is UNIX specific! For the Mac we need to use a simpler version!
import stdwin, stdwinq import stdwin, stdwinq
from stdwinevents import * from stdwinevents import *
...@@ -123,23 +126,38 @@ def do_select(): ...@@ -123,23 +126,38 @@ def do_select():
# Python's stdwin.getevent() turns WE_COMMAND/WC_CANCEL events # Python's stdwin.getevent() turns WE_COMMAND/WC_CANCEL events
# into KeyboardInterrupt exceptions; these are turned back in events. # into KeyboardInterrupt exceptions; these are turned back in events.
# #
recursion_level = 0 # Hack to make it reentrant
def mainloop(): def mainloop():
stdwin_select_handler() # Process events already in stdwin queue global recursion_level
recursion_level = recursion_level + 1
try:
stdwin_select_handler() # Process events already in queue
fd = stdwin.fileno() fd = stdwin.fileno()
while 1: while 1:
if windows: if windows:
if recursion_level == 1:
registerfd(fd, 'r', stdwin_select_handler) registerfd(fd, 'r', stdwin_select_handler)
try: try:
while windows: while windows:
do_select() do_select()
stdwin_select_handler() stdwin_select_handler()
finally: finally:
if recursion_level == 1:
unregisterfd(fd) unregisterfd(fd)
elif fdlist: elif fdlist:
while fdlist and not windows: while fdlist and not windows:
do_select() do_select()
else: else:
break break
finally:
recursion_level = recursion_level - 1
# Check for events without ever blocking
#
def check():
stdwin_select_handler()
# XXX Should check for socket stuff as well
# Handle stdwin events until none are left # Handle stdwin events until none are left
......
...@@ -108,6 +108,6 @@ def choose_boundary(): ...@@ -108,6 +108,6 @@ def choose_boundary():
pid = `os.getpid()` pid = `os.getpid()`
seed = `rand.rand()` seed = `rand.rand()`
_prefix = hostid + '.' + uid + '.' + pid _prefix = hostid + '.' + uid + '.' + pid
timestamp = `time.time()` timestamp = `int(time.time())`
seed = `rand.rand()` seed = `rand.rand()`
return _prefix + '.' + timestamp + '.' + seed return _prefix + '.' + timestamp + '.' + seed
...@@ -11,11 +11,13 @@ class Prog: ...@@ -11,11 +11,13 @@ class Prog:
finally: finally:
xxx = regex.set_syntax(save_syntax) xxx = regex.set_syntax(save_syntax)
return self return self
def match(self, args): def match(self, *args):
if type(args) == type(()): if len(args) == 2:
str, offset = args str, offset = args
elif len(args) == 1:
str, offset = args[0], 0
else: else:
str, offset = args, 0 raise TypeError, 'wrong argument count'
if self.prog.search(str, offset) < 0: if self.prog.search(str, offset) < 0:
return () return ()
regs = self.prog.regs regs = self.prog.regs
......
...@@ -27,15 +27,14 @@ class BoxParent(TransParent): ...@@ -27,15 +27,14 @@ class BoxParent(TransParent):
def getbounds(self): def getbounds(self):
return self.bounds return self.bounds
# #
def draw(self, args): def draw(self, d, area):
d, area = args
(left, top), (right, bottom) = self.bounds (left, top), (right, bottom) = self.bounds
left = left + 1 left = left + 1
top = top + 1 top = top + 1
right = right - 1 right = right - 1
bottom = bottom - 1 bottom = bottom - 1
d.box((left, top), (right, bottom)) d.box((left, top), (right, bottom))
TransParent.draw(self, args) # XXX clip to innerbounds? TransParent.draw(self, d, area) # XXX clip to innerbounds?
# #
# XXX should scroll clip to innerbounds??? # XXX should scroll clip to innerbounds???
# XXX currently the only user restricts itself to child's bounds # XXX currently the only user restricts itself to child's bounds
...@@ -28,7 +28,7 @@ class DirList(VSplit): ...@@ -28,7 +28,7 @@ class DirList(VSplit):
class DirListWindow(WindowParent): class DirListWindow(WindowParent):
# #
def create(self, dirname): def create(self, dirname):
self = WindowParent.create(self, (dirname, (0, 0))) self = WindowParent.create(self, dirname, (0, 0))
child = DirList().create(self, dirname) child = DirList().create(self, dirname)
self.realize() self.realize()
return self return self
......
...@@ -55,8 +55,8 @@ class HVSplit(Split): ...@@ -55,8 +55,8 @@ class HVSplit(Split):
class HSplit(HVSplit): class HSplit(HVSplit):
def create(self, parent): def create(self, parent):
return HVSplit.create(self, (parent, 0)) return HVSplit.create(self, parent, 0)
class VSplit(HVSplit): class VSplit(HVSplit):
def create(self, parent): def create(self, parent):
return HVSplit.create(self, (parent, 1)) return HVSplit.create(self, parent, 1)
...@@ -50,10 +50,10 @@ class Split: ...@@ -50,10 +50,10 @@ class Split:
for child in self.children: for child in self.children:
child.realize() child.realize()
# #
def draw(self, d_detail): def draw(self, d, detail):
# (Could avoid calls to children outside the area) # (Could avoid calls to children outside the area)
for child in self.children: for child in self.children:
child.draw(d_detail) child.draw(d, detail)
# #
def altdraw(self, detail): def altdraw(self, detail):
for child in self.altdraw_interest: for child in self.altdraw_interest:
...@@ -112,15 +112,14 @@ class Split: ...@@ -112,15 +112,14 @@ class Split:
if self.keybd_focus: if self.keybd_focus:
self.keybd_focus.deactivate() self.keybd_focus.deactivate()
# #
def keybd(self, type_detail): def keybd(self, type, detail):
if not self.keybd_focus: if not self.keybd_focus:
self.set_keybd_focus(self.keybd_interest[0]) self.set_keybd_focus(self.keybd_interest[0])
type, detail = type_detail
if type == WE_COMMAND and detail == WC_TAB and \ if type == WE_COMMAND and detail == WC_TAB and \
len(self.keybd_interest) > 1: len(self.keybd_interest) > 1:
self.next_keybd_focus() self.next_keybd_focus()
return return
self.keybd_focus.keybd(type_detail) self.keybd_focus.keybd(type, detail)
# #
def timer(self): def timer(self):
for child in self.timer_interest: for child in self.timer_interest:
...@@ -206,7 +205,7 @@ class Split: ...@@ -206,7 +205,7 @@ class Split:
# #
def change(self, area): def change(self, area):
self.parent.change(area) self.parent.change(area)
def scroll(self, area_vector): def scroll(self, area, vector):
self.parent.scroll(area_vector) self.parent.scroll(area, vector)
def settimer(self, itimer): def settimer(self, itimer):
self.parent.settimer(itimer) self.parent.settimer(itimer)
...@@ -60,12 +60,12 @@ class TransParent(ManageOneChild): ...@@ -60,12 +60,12 @@ class TransParent(ManageOneChild):
def realize(self): def realize(self):
if self.child: if self.child:
self.child.realize() self.child.realize()
def draw(self, args): def draw(self, d, area):
if self.child: if self.child:
self.child.draw(args) self.child.draw(d, area)
def altdraw(self, args): def altdraw(self, area):
if self.child: if self.child:
self.child.altdraw(args) self.child.altdraw(area)
# #
# Downcalls only made after certain upcalls # Downcalls only made after certain upcalls
# #
...@@ -117,7 +117,7 @@ class TransParent(ManageOneChild): ...@@ -117,7 +117,7 @@ class TransParent(ManageOneChild):
# #
def change(self, area): def change(self, area):
self.parent.change(area) self.parent.change(area)
def scroll(self, args): def scroll(self, area, vector):
self.parent.scroll(args) self.parent.scroll(area, vector)
def settimer(self, itimer): def settimer(self, itimer):
self.parent.settimer(itimer) self.parent.settimer(itimer)
...@@ -136,9 +136,9 @@ class WindowParent(ManageOneChild): ...@@ -136,9 +136,9 @@ class WindowParent(ManageOneChild):
if self.win: if self.win:
self.win.change(area) self.win.change(area)
# #
def scroll(self, args): def scroll(self, area, vector):
if self.win: if self.win:
self.win.scroll(args) self.win.scroll(area, vector)
# #
def settimer(self, itimer): def settimer(self, itimer):
if self.win: if self.win:
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
# - have a 'dispatch' function as a window member # - have a 'dispatch' function as a window member
# XXX This is UNIX specific! For the Mac we need to use a simpler version!
import stdwin, stdwinq import stdwin, stdwinq
from stdwinevents import * from stdwinevents import *
...@@ -123,23 +126,38 @@ def do_select(): ...@@ -123,23 +126,38 @@ def do_select():
# Python's stdwin.getevent() turns WE_COMMAND/WC_CANCEL events # Python's stdwin.getevent() turns WE_COMMAND/WC_CANCEL events
# into KeyboardInterrupt exceptions; these are turned back in events. # into KeyboardInterrupt exceptions; these are turned back in events.
# #
recursion_level = 0 # Hack to make it reentrant
def mainloop(): def mainloop():
stdwin_select_handler() # Process events already in stdwin queue global recursion_level
recursion_level = recursion_level + 1
try:
stdwin_select_handler() # Process events already in queue
fd = stdwin.fileno() fd = stdwin.fileno()
while 1: while 1:
if windows: if windows:
if recursion_level == 1:
registerfd(fd, 'r', stdwin_select_handler) registerfd(fd, 'r', stdwin_select_handler)
try: try:
while windows: while windows:
do_select() do_select()
stdwin_select_handler() stdwin_select_handler()
finally: finally:
if recursion_level == 1:
unregisterfd(fd) unregisterfd(fd)
elif fdlist: elif fdlist:
while fdlist and not windows: while fdlist and not windows:
do_select() do_select()
else: else:
break break
finally:
recursion_level = recursion_level - 1
# Check for events without ever blocking
#
def check():
stdwin_select_handler()
# XXX Should check for socket stuff as well
# Handle stdwin events until none are left # Handle stdwin events until none are left
......
...@@ -39,7 +39,7 @@ class whrandom: ...@@ -39,7 +39,7 @@ class whrandom:
if not xyz: if not xyz:
# Initialize from current time # Initialize from current time
import time import time
t = time.time() t = int(time.time())
t, x = divmod(t, 256) t, x = divmod(t, 256)
t, y = divmod(t, 256) t, y = divmod(t, 256)
t, z = divmod(t, 256) t, z = divmod(t, 256)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment