Commits

Guido van Rossum  committed f9bbb01

* 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.

  • Participants
  • Parent commits 533e36d
  • Branches legacy-trunk

Comments (0)

Files changed (18)

File Lib/calendar.py

 # 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)
 	key = `year` + month_abbr[month]
 	try:
 		return mc_cache[key]
-	except IOError:
+	except KeyError:
 		mc_cache[key] = ret = _monthcalendar(year, month)
 		return ret
 

File Lib/lib-stdwin/BoxParent.py

 	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

File Lib/lib-stdwin/DirList.py

 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

File Lib/lib-stdwin/HVSplit.py

 
 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)

File Lib/lib-stdwin/Split.py

 		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:
 		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:
 	#
 	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)

File Lib/lib-stdwin/TransParent.py

 	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
 	#
 	#
 	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)

File Lib/lib-stdwin/WindowParent.py

 		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:

File Lib/lib-stdwin/mainloop.py

 # - 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 *
 
 # 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

File Lib/mimetools.py

 		pid = `os.getpid()`
 		seed = `rand.rand()`
 		_prefix = hostid + '.' + uid + '.' + pid
-	timestamp = `time.time()`
+	timestamp = `int(time.time())`
 	seed = `rand.rand()`
 	return _prefix + '.' + timestamp + '.' + seed

File Lib/regexp.py

 		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

File Lib/stdwin/BoxParent.py

 	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

File Lib/stdwin/DirList.py

 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

File Lib/stdwin/HVSplit.py

 
 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)

File Lib/stdwin/Split.py

 		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:
 		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:
 	#
 	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)

File Lib/stdwin/TransParent.py

 	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
 	#
 	#
 	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)

File Lib/stdwin/WindowParent.py

 		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:

File Lib/stdwin/mainloop.py

 # - 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 *
 
 # 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

File Lib/whrandom.py

 		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)