Code Search for Developers
 
 
  

ChangeDict.py from Thousand Parsec at Krugle


Show ChangeDict.py syntax highlighted

from types import TupleType

class ChangeDict(dict):
	"""\
	A simple dictionary which also stores the "times" an object was last updated.

	Used so that we only upload/download items which have changed.
	"""
	def __init__(self):
		dict.__init__(self)
		self.times = {}
	
	def __setitem__(self, key, value):
		"""\
		This set item is special, it only takes keys of the form,
		(<last modified time>, <normal key>)
		"""
		if type(value) is TupleType and len(value) == 2:
			time, value = value
		else:
			time = -1

		if time != -1 and self.times.has_key(key) and self.times[key] > time:
			raise ValueError("The object isn't new enough to update the dictionary with! Current %s, update %s" % (self.times[key], time))
		
		self.times[key] = time
		dict.__setitem__(self, key, value)

	def __delitem__(self, key):
		del self.times[key]
		dict.__delitem__(self, key)

ChangeDict.__repr__ = dict.__repr__




See more files for this project here

Thousand Parsec

Thousand Parsec is a framework for turn based 4 X\'s game (eXplore, eXpand, eXploit, eXterminate). Designed for long games, supporting massive universes and has an easily expanded tech tree.

Project homepage: http://sourceforge.net/projects/thousandparsec
Programming language(s): C++,Python
License: other

  pyscheme/
    t/
      factorial.scm
      generators.scm
      hello.scm
      pairs1.scm
      pocket.scm
      quine.scm
      stack.scm
      test1.scm
    LICENSE
    __init__.py
    all_tests.py
    analyzer.py
    builtins.py
    environment.py
    error.py
    evaluator.py
    expander.py
    expressions.py
    pair.py
    parser.py
    pogo.py
    prompt.py
    scheme.py
    symbol.py
    test_analyzer.py
    test_scheme.py
  ChangeDict.py
  Log.py
  __init__.py
  cache.py
  config.py
  media.py
  parser.py
  strptime.py
  threads.py
  version.py