Created
December 20, 2017 07:31
-
-
Save xuanyu-h/fde105c61c5e03c89039895c5acd575c to your computer and use it in GitHub Desktop.
Python 单例模式
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AuthManager(object): | |
"""Authentication Manager.""" | |
def __new__(cls): | |
singleton = cls.__dict__.get('__singleton__') | |
if singleton is not None: | |
return singleton | |
cls.__singleton__ = singleton = object.__new__(cls) | |
return singleton | |
def __init__(self): | |
self.passwd = {} | |
self._auth = {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment