mirror of https://github.com/python/cpython
* 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.
This commit is contained in:
parent
a2b7f40513
commit
fea2af1e9b
|
@ -31,6 +31,7 @@ error = 'calendar error'
|
|||
# Turn seconds since epoch into calendar time
|
||||
def gmtime(secs):
|
||||
if secs < 0: raise error, 'negative input to gmtime()'
|
||||
secs = int(secs)
|
||||
mins, secs = divmod(secs, 60)
|
||||
hours, mins = divmod(mins, 60)
|
||||
days, hours = divmod(hours, 24)
|
||||
|
@ -146,7 +147,7 @@ def monthcalendar(year, month):
|
|||
key = `year` + month_abbr[month]
|
||||
try:
|
||||
return mc_cache[key]
|
||||
except IOError:
|
||||
except KeyError:
|
||||
mc_cache[key] = ret = _monthcalendar(year, month)
|
||||
return ret
|
||||
|
||||
|
|
|
@ -27,15 +27,14 @@ class BoxParent(TransParent):
|
|||
def getbounds(self):
|
||||
return self.bounds
|
||||
#
|
||||
def draw(self, args):
|
||||
d, area = args
|
||||
def draw(self, d, area):
|
||||
(left, top), (right, bottom) = self.bounds
|
||||
left = left + 1
|
||||
top = top + 1
|
||||
right = right - 1
|
||||
bottom = bottom - 1
|
||||
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 currently the only user restricts itself to child's bounds
|
||||
|
|
|
@ -28,7 +28,7 @@ class DirList(VSplit):
|
|||
class DirListWindow(WindowParent):
|
||||
#
|
||||
def create(self, dirname):
|
||||
self = WindowParent.create(self, (dirname, (0, 0)))
|
||||
self = WindowParent.create(self, dirname, (0, 0))
|
||||
child = DirList().create(self, dirname)
|
||||
self.realize()
|
||||
return self
|
||||
|
|
|
@ -55,8 +55,8 @@ class HVSplit(Split):
|
|||
|
||||
class HSplit(HVSplit):
|
||||
def create(self, parent):
|
||||
return HVSplit.create(self, (parent, 0))
|
||||
return HVSplit.create(self, parent, 0)
|
||||
|
||||
class VSplit(HVSplit):
|
||||
def create(self, parent):
|
||||
return HVSplit.create(self, (parent, 1))
|
||||
return HVSplit.create(self, parent, 1)
|
||||
|
|
|
@ -50,10 +50,10 @@ class Split:
|
|||
for child in self.children:
|
||||
child.realize()
|
||||
#
|
||||
def draw(self, d_detail):
|
||||
def draw(self, d, detail):
|
||||
# (Could avoid calls to children outside the area)
|
||||
for child in self.children:
|
||||
child.draw(d_detail)
|
||||
child.draw(d, detail)
|
||||
#
|
||||
def altdraw(self, detail):
|
||||
for child in self.altdraw_interest:
|
||||
|
@ -112,15 +112,14 @@ class Split:
|
|||
if self.keybd_focus:
|
||||
self.keybd_focus.deactivate()
|
||||
#
|
||||
def keybd(self, type_detail):
|
||||
def keybd(self, type, detail):
|
||||
if not self.keybd_focus:
|
||||
self.set_keybd_focus(self.keybd_interest[0])
|
||||
type, detail = type_detail
|
||||
if type == WE_COMMAND and detail == WC_TAB and \
|
||||
len(self.keybd_interest) > 1:
|
||||
self.next_keybd_focus()
|
||||
return
|
||||
self.keybd_focus.keybd(type_detail)
|
||||
self.keybd_focus.keybd(type, detail)
|
||||
#
|
||||
def timer(self):
|
||||
for child in self.timer_interest:
|
||||
|
@ -206,7 +205,7 @@ class Split:
|
|||
#
|
||||
def change(self, area):
|
||||
self.parent.change(area)
|
||||
def scroll(self, area_vector):
|
||||
self.parent.scroll(area_vector)
|
||||
def scroll(self, area, vector):
|
||||
self.parent.scroll(area, vector)
|
||||
def settimer(self, itimer):
|
||||
self.parent.settimer(itimer)
|
||||
|
|
|
@ -60,12 +60,12 @@ class TransParent(ManageOneChild):
|
|||
def realize(self):
|
||||
if self.child:
|
||||
self.child.realize()
|
||||
def draw(self, args):
|
||||
def draw(self, d, area):
|
||||
if self.child:
|
||||
self.child.draw(args)
|
||||
def altdraw(self, args):
|
||||
self.child.draw(d, area)
|
||||
def altdraw(self, area):
|
||||
if self.child:
|
||||
self.child.altdraw(args)
|
||||
self.child.altdraw(area)
|
||||
#
|
||||
# Downcalls only made after certain upcalls
|
||||
#
|
||||
|
@ -117,7 +117,7 @@ class TransParent(ManageOneChild):
|
|||
#
|
||||
def change(self, area):
|
||||
self.parent.change(area)
|
||||
def scroll(self, args):
|
||||
self.parent.scroll(args)
|
||||
def scroll(self, area, vector):
|
||||
self.parent.scroll(area, vector)
|
||||
def settimer(self, itimer):
|
||||
self.parent.settimer(itimer)
|
||||
|
|
|
@ -136,9 +136,9 @@ class WindowParent(ManageOneChild):
|
|||
if self.win:
|
||||
self.win.change(area)
|
||||
#
|
||||
def scroll(self, args):
|
||||
def scroll(self, area, vector):
|
||||
if self.win:
|
||||
self.win.scroll(args)
|
||||
self.win.scroll(area, vector)
|
||||
#
|
||||
def settimer(self, itimer):
|
||||
if self.win:
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
# - 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
|
||||
from stdwinevents import *
|
||||
|
||||
|
@ -123,23 +126,38 @@ def do_select():
|
|||
# Python's stdwin.getevent() turns WE_COMMAND/WC_CANCEL events
|
||||
# into KeyboardInterrupt exceptions; these are turned back in events.
|
||||
#
|
||||
recursion_level = 0 # Hack to make it reentrant
|
||||
def mainloop():
|
||||
stdwin_select_handler() # Process events already in stdwin queue
|
||||
fd = stdwin.fileno()
|
||||
while 1:
|
||||
if windows:
|
||||
registerfd(fd, 'r', stdwin_select_handler)
|
||||
try:
|
||||
while windows:
|
||||
global recursion_level
|
||||
recursion_level = recursion_level + 1
|
||||
try:
|
||||
stdwin_select_handler() # Process events already in queue
|
||||
fd = stdwin.fileno()
|
||||
while 1:
|
||||
if windows:
|
||||
if recursion_level == 1:
|
||||
registerfd(fd, 'r', stdwin_select_handler)
|
||||
try:
|
||||
while windows:
|
||||
do_select()
|
||||
stdwin_select_handler()
|
||||
finally:
|
||||
if recursion_level == 1:
|
||||
unregisterfd(fd)
|
||||
elif fdlist:
|
||||
while fdlist and not windows:
|
||||
do_select()
|
||||
stdwin_select_handler()
|
||||
finally:
|
||||
unregisterfd(fd)
|
||||
elif fdlist:
|
||||
while fdlist and not windows:
|
||||
do_select()
|
||||
else:
|
||||
break
|
||||
else:
|
||||
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
|
||||
|
|
|
@ -108,6 +108,6 @@ def choose_boundary():
|
|||
pid = `os.getpid()`
|
||||
seed = `rand.rand()`
|
||||
_prefix = hostid + '.' + uid + '.' + pid
|
||||
timestamp = `time.time()`
|
||||
timestamp = `int(time.time())`
|
||||
seed = `rand.rand()`
|
||||
return _prefix + '.' + timestamp + '.' + seed
|
||||
|
|
|
@ -11,11 +11,13 @@ class Prog:
|
|||
finally:
|
||||
xxx = regex.set_syntax(save_syntax)
|
||||
return self
|
||||
def match(self, args):
|
||||
if type(args) == type(()):
|
||||
def match(self, *args):
|
||||
if len(args) == 2:
|
||||
str, offset = args
|
||||
elif len(args) == 1:
|
||||
str, offset = args[0], 0
|
||||
else:
|
||||
str, offset = args, 0
|
||||
raise TypeError, 'wrong argument count'
|
||||
if self.prog.search(str, offset) < 0:
|
||||
return ()
|
||||
regs = self.prog.regs
|
||||
|
|
|
@ -27,15 +27,14 @@ class BoxParent(TransParent):
|
|||
def getbounds(self):
|
||||
return self.bounds
|
||||
#
|
||||
def draw(self, args):
|
||||
d, area = args
|
||||
def draw(self, d, area):
|
||||
(left, top), (right, bottom) = self.bounds
|
||||
left = left + 1
|
||||
top = top + 1
|
||||
right = right - 1
|
||||
bottom = bottom - 1
|
||||
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 currently the only user restricts itself to child's bounds
|
||||
|
|
|
@ -28,7 +28,7 @@ class DirList(VSplit):
|
|||
class DirListWindow(WindowParent):
|
||||
#
|
||||
def create(self, dirname):
|
||||
self = WindowParent.create(self, (dirname, (0, 0)))
|
||||
self = WindowParent.create(self, dirname, (0, 0))
|
||||
child = DirList().create(self, dirname)
|
||||
self.realize()
|
||||
return self
|
||||
|
|
|
@ -55,8 +55,8 @@ class HVSplit(Split):
|
|||
|
||||
class HSplit(HVSplit):
|
||||
def create(self, parent):
|
||||
return HVSplit.create(self, (parent, 0))
|
||||
return HVSplit.create(self, parent, 0)
|
||||
|
||||
class VSplit(HVSplit):
|
||||
def create(self, parent):
|
||||
return HVSplit.create(self, (parent, 1))
|
||||
return HVSplit.create(self, parent, 1)
|
||||
|
|
|
@ -50,10 +50,10 @@ class Split:
|
|||
for child in self.children:
|
||||
child.realize()
|
||||
#
|
||||
def draw(self, d_detail):
|
||||
def draw(self, d, detail):
|
||||
# (Could avoid calls to children outside the area)
|
||||
for child in self.children:
|
||||
child.draw(d_detail)
|
||||
child.draw(d, detail)
|
||||
#
|
||||
def altdraw(self, detail):
|
||||
for child in self.altdraw_interest:
|
||||
|
@ -112,15 +112,14 @@ class Split:
|
|||
if self.keybd_focus:
|
||||
self.keybd_focus.deactivate()
|
||||
#
|
||||
def keybd(self, type_detail):
|
||||
def keybd(self, type, detail):
|
||||
if not self.keybd_focus:
|
||||
self.set_keybd_focus(self.keybd_interest[0])
|
||||
type, detail = type_detail
|
||||
if type == WE_COMMAND and detail == WC_TAB and \
|
||||
len(self.keybd_interest) > 1:
|
||||
self.next_keybd_focus()
|
||||
return
|
||||
self.keybd_focus.keybd(type_detail)
|
||||
self.keybd_focus.keybd(type, detail)
|
||||
#
|
||||
def timer(self):
|
||||
for child in self.timer_interest:
|
||||
|
@ -206,7 +205,7 @@ class Split:
|
|||
#
|
||||
def change(self, area):
|
||||
self.parent.change(area)
|
||||
def scroll(self, area_vector):
|
||||
self.parent.scroll(area_vector)
|
||||
def scroll(self, area, vector):
|
||||
self.parent.scroll(area, vector)
|
||||
def settimer(self, itimer):
|
||||
self.parent.settimer(itimer)
|
||||
|
|
|
@ -60,12 +60,12 @@ class TransParent(ManageOneChild):
|
|||
def realize(self):
|
||||
if self.child:
|
||||
self.child.realize()
|
||||
def draw(self, args):
|
||||
def draw(self, d, area):
|
||||
if self.child:
|
||||
self.child.draw(args)
|
||||
def altdraw(self, args):
|
||||
self.child.draw(d, area)
|
||||
def altdraw(self, area):
|
||||
if self.child:
|
||||
self.child.altdraw(args)
|
||||
self.child.altdraw(area)
|
||||
#
|
||||
# Downcalls only made after certain upcalls
|
||||
#
|
||||
|
@ -117,7 +117,7 @@ class TransParent(ManageOneChild):
|
|||
#
|
||||
def change(self, area):
|
||||
self.parent.change(area)
|
||||
def scroll(self, args):
|
||||
self.parent.scroll(args)
|
||||
def scroll(self, area, vector):
|
||||
self.parent.scroll(area, vector)
|
||||
def settimer(self, itimer):
|
||||
self.parent.settimer(itimer)
|
||||
|
|
|
@ -136,9 +136,9 @@ class WindowParent(ManageOneChild):
|
|||
if self.win:
|
||||
self.win.change(area)
|
||||
#
|
||||
def scroll(self, args):
|
||||
def scroll(self, area, vector):
|
||||
if self.win:
|
||||
self.win.scroll(args)
|
||||
self.win.scroll(area, vector)
|
||||
#
|
||||
def settimer(self, itimer):
|
||||
if self.win:
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
# - 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
|
||||
from stdwinevents import *
|
||||
|
||||
|
@ -123,23 +126,38 @@ def do_select():
|
|||
# Python's stdwin.getevent() turns WE_COMMAND/WC_CANCEL events
|
||||
# into KeyboardInterrupt exceptions; these are turned back in events.
|
||||
#
|
||||
recursion_level = 0 # Hack to make it reentrant
|
||||
def mainloop():
|
||||
stdwin_select_handler() # Process events already in stdwin queue
|
||||
fd = stdwin.fileno()
|
||||
while 1:
|
||||
if windows:
|
||||
registerfd(fd, 'r', stdwin_select_handler)
|
||||
try:
|
||||
while windows:
|
||||
global recursion_level
|
||||
recursion_level = recursion_level + 1
|
||||
try:
|
||||
stdwin_select_handler() # Process events already in queue
|
||||
fd = stdwin.fileno()
|
||||
while 1:
|
||||
if windows:
|
||||
if recursion_level == 1:
|
||||
registerfd(fd, 'r', stdwin_select_handler)
|
||||
try:
|
||||
while windows:
|
||||
do_select()
|
||||
stdwin_select_handler()
|
||||
finally:
|
||||
if recursion_level == 1:
|
||||
unregisterfd(fd)
|
||||
elif fdlist:
|
||||
while fdlist and not windows:
|
||||
do_select()
|
||||
stdwin_select_handler()
|
||||
finally:
|
||||
unregisterfd(fd)
|
||||
elif fdlist:
|
||||
while fdlist and not windows:
|
||||
do_select()
|
||||
else:
|
||||
break
|
||||
else:
|
||||
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
|
||||
|
|
|
@ -39,7 +39,7 @@ class whrandom:
|
|||
if not xyz:
|
||||
# Initialize from current time
|
||||
import time
|
||||
t = time.time()
|
||||
t = int(time.time())
|
||||
t, x = divmod(t, 256)
|
||||
t, y = divmod(t, 256)
|
||||
t, z = divmod(t, 256)
|
||||
|
|
Loading…
Reference in New Issue