def __new__(cls, name, bases, dict): deprecate = deprecated( "Use variable_providers instead of variableProviders.") for key, value in dict.items(): if key == "__metaclass__": continue if callable(value): dict[key] = deprecate(value) return type.__new__(cls, name, bases, dict)
def test_deprecated(): def some_old_function(x, y): """some old function""" return x + y some_old_function = util.deprecated('this is old')(some_old_function) assert "some old function" in some_old_function.__doc__ some_old_function.__name__ == 'some_old_function' stderr, sys.stderr = sys.stderr, StringIO() try: assert some_old_function(1, 2) == 3 finally: stderr, sys.stderr = sys.stderr, stderr assert 'DeprecationWarning: this is old' in stderr.getvalue() stderr.close()
elif algorithm == 'custom': custom_encryption_path = turbogears.config.get( 'identity.custom_encryption', None) if custom_encryption_path: custom_encryption = turbogears.util.load_class( custom_encryption_path) if custom_encryption: hashed_password = custom_encryption(password_8bit) # Make sure the hashed password is a unicode object at the end of the # process, because SQLAlchemy _wants_ that for Unicode columns. if not isinstance(hashed_password, unicode): hashed_password = hashed_password.decode('utf-8') return hashed_password _encrypt_password = deprecated( "Use identity.encrypt_pw_with_algorithm instead." )(encrypt_pw_with_algorithm) def encrypt_password(cleartext): return current_provider.encrypt_password(cleartext) class IdentityWrapper(object): """A wrapper class for the thread local data. This allows developers to access the current user information via turbogears.identity.current and get the identity for the current request. """ def identity(self):
database.metadata.drop_all() # Determine which class to use for "DBTest". Setup & teardown should behave # simularly regardless of which ORM you choose. if config.get("sqlobject.dburi"): DBTest = DBTestSO elif config.get("sqlalchemy.dburi"): DBTest = DBTestSA else: raise Exception("Unable to find sqlalchemy or sqlobject dburi") # deprecated functions kept for backward compability start_cp = deprecated('start_cp is superceded by start_server')(start_server) reset_cp = deprecated('reset_cp has been superceded by unmount.')(unmount) test_user = None @deprecated() def set_identity_user(user): """Setup a user for configuring request's identity.""" global test_user test_user = user @deprecated() def attach_identity(req): if config.get("identity.on", False): req.identity = (test_user