Commits

Jason R. Coombs  committed bddbe6e

Require jaraco.util (for dictlib and numbers)

  • Participants
  • Parent commits 9531dd7
  • Tags 1101.9.2

Comments (0)

Files changed (3)

File pmxbot/dictlib.py

-from __future__ import unicode_literals
-
 import yaml
-
-# from jaraco.util.dictlib
-class ItemsAsAttributes(object):
-	"""
-	Mix-in class to enable a mapping object to provide items as
-	attributes.
-
-	>>> C = type(str('C'), (dict, ItemsAsAttributes), dict())
-	>>> i = C()
-	>>> i['foo'] = 'bar'
-	>>> i.foo
-	u'bar'
-
-	# natural attribute access takes precedence
-	>>> i.foo = 'henry'
-	>>> i.foo
-	u'henry'
-
-	# but as you might expect, the mapping functionality is preserved.
-	>>> i['foo']
-	u'bar'
-
-	# A normal attribute error should be raised if an attribute is
-	#  requested that doesn't exist.
-	>>> i.missing
-	Traceback (most recent call last):
-	...
-	AttributeError: 'C' object has no attribute 'missing'
-
-	It also works on dicts that customize __getitem__
-	>>> missing_func = lambda self, key: 'missing item'
-	>>> C = type(str('C'), (dict, ItemsAsAttributes), dict(__missing__ = missing_func))
-	>>> i = C()
-	>>> i.missing
-	u'missing item'
-	>>> i.foo
-	u'missing item'
-	"""
-	def __getattr__(self, key):
-		try:
-			return getattr(super(ItemsAsAttributes, self), key)
-		except AttributeError as e:
-			# attempt to get the value from the mapping (return self[key])
-			#  but be careful not to lose the original exception context.
-			noval = object()
-			def _safe_getitem(cont, key, missing_result):
-				try:
-					return cont[key]
-				except KeyError:
-					return missing_result
-			result = _safe_getitem(self, key, noval)
-			if result is not noval:
-				return result
-			# raise the original exception, but use the original class
-			#  name, not 'super'.
-			e.message = e.message.replace('super',
-				self.__class__.__name__, 1)
-			e.args = (e.message,)
-			raise
+from jaraco.util.dictlib import ItemsAsAttributes
 
 class ConfigDict(ItemsAsAttributes, dict):
 	@classmethod
 	def from_yaml(cls, filename):
 		with open(filename) as f:
 			return cls(yaml.load(f))
-

File pmxbotweb/viewer.py

 
 from jinja2 import Environment, FileSystemLoader
 import pytz
+from jaraco.util.numbers import ordinalth as th_it
 
 from pmxbot.logging import init_logger
 import pmxbot.util
 	time, nick = line
 	return "%s.%s" % (str(time).replace(':', '.'), nick)
 
-
-th_map = {1: 'st', 2: 'nd', 3: 'rd'}
-def th_it(num):
-	if num in range(11, 14):
-		end = 'th'
-	elif num % 10 in th_map:
-		end = th_map[num % 10]
-	else:
-		end = 'th'
-	return '%s%s' % (num, end)
-
 def pmon(month):
 	"""
 	P the month
 		"feedparser",
 		"pytz",
 		"wordnik>=2.0,<3.0",
+		"jaraco.util",
 		#for viewer
 		"jinja2",
 		"cherrypy",