[kupfer] pretty: Remove keyword silliness



commit c1702ad8d1f76bf9c27a24a43d99c0e5763a665f
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Mon Nov 2 23:01:50 2009 +0100

    pretty: Remove keyword silliness

 kupfer/pretty.py |   28 ++++++----------------------
 1 files changed, 6 insertions(+), 22 deletions(-)
---
diff --git a/kupfer/pretty.py b/kupfer/pretty.py
index 5304c58..fa10d88 100644
--- a/kupfer/pretty.py
+++ b/kupfer/pretty.py
@@ -2,34 +2,19 @@ debug = False
 
 import functools
 
-def keywords(**defaults):
-	"""Add and enforce keywords to a function"""
-	def decorator(func):
-		@functools.wraps(func)
-		def wrapper(*args, **kwargs):
-			for key in kwargs:
-				if key not in defaults:
-					raise TypeError("Invalid keyword %s" % key)
-			kwd = defaults.copy()
-			kwd.update(kwargs)
-			return func(*args, **kwd)
-		return wrapper
-	return decorator
-
 class OutputMixin (object):
 	"""
 	A mixin class providing prefixed output
 	standard output and debug output
 	"""
-	@keywords(category="", sep=" ", end="\n")
 	def output_info(self, *items, **kwargs):
 		"""
 		Output given items using @sep as separator,
 		ending the line with @end
 		"""
-		sep = kwargs["sep"]
-		end = kwargs["end"]
-		category = kwargs["category"]
+		sep = kwargs.get("sep", " ")
+		end = kwargs.get("end", "\n")
+		category = kwargs.get("category", "")
 		stritems = (str(it) for it in items)
 		sformat = "%s[%s] %s: %s%s"
 		try:
@@ -45,15 +30,14 @@ class OutputMixin (object):
 	def output_error(self, *items, **kwargs):
 		self.output_info(category="Error ", *items, **kwargs)
 
- keywords(category="", sep=" ", end="\n")
 def print_info(name, *items, **kwargs):
 	"""
 	Output given items using @sep as separator,
 	ending the line with @end
 	"""
-	sep = kwargs["sep"]
-	end = kwargs["end"]
-	category = kwargs["category"]
+	sep = kwargs.get("sep", " ")
+	end = kwargs.get("end", "\n")
+	category = kwargs.get("category", "")
 	stritems = (str(it) for it in items)
 	sformat = "%s[%s]: %s%s"
 	print sformat % (category, name, sep.join(stritems), end),



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]