##// END OF EJS Templates
Translation updates from RhodeCode v2.2.5...
Translation updates from RhodeCode v2.2.5 Includes a new German translation. These are licensed under GPLv3, for various reasons, including since they include textual copies of strings from the GPLv3'd Python and HTML files.

File last commit:

r1203:6832ef66 beta
r4137:6c485794 rhodecode-2.2.5-gpl
Show More
keyedinstance.py
36 lines | 1.1 KiB | text/x-python | PythonLexer
added dbmigrate package, added model changes...
r833 #!/usr/bin/env python
# -*- coding: utf-8 -*-
class KeyedInstance(object):
"""A class whose instances have a unique identifier of some sort
No two instances with the same unique ID should exist - if we try to create
source code cleanup: remove trailing white space, normalize file endings
r1203 a second instance, the first should be returned.
added dbmigrate package, added model changes...
r833 """
_instances = dict()
def __new__(cls, *p, **k):
instances = cls._instances
clskey = str(cls)
if clskey not in instances:
instances[clskey] = dict()
instances = instances[clskey]
key = cls._key(*p, **k)
if key not in instances:
instances[key] = super(KeyedInstance, cls).__new__(cls)
return instances[key]
@classmethod
def _key(cls, *p, **k):
"""Given a unique identifier, return a dictionary key
source code cleanup: remove trailing white space, normalize file endings
r1203 This should be overridden by child classes, to specify which parameters
added dbmigrate package, added model changes...
r833 should determine an object's uniqueness
"""
raise NotImplementedError()
@classmethod
def clear(cls):
# Allow cls.clear() as well as uniqueInstance.clear(cls)
if str(cls) in cls._instances:
del cls._instances[str(cls)]