Jason R. Coombs avatar Jason R. Coombs committed feacdfc

Moved file_path property into a dynamic, data property.

Comments (0)

Files changed (2)

keyring/backend.py

 import ConfigParser
 
 from keyring.util.escape import escape as escape_for_ini
+from keyring.util import properties
 
 try:
-    from abc import ABCMeta, abstractmethod
+    from abc import ABCMeta, abstractmethod, abstractproperty
 except ImportError:
     # to keep compatible with older Python versions.
     class ABCMeta(type):
     def abstractmethod(funcobj):
         return funcobj
 
+    def abstractproperty(funcobj):
+        return property(funcobj)
+
 try:
     import gnomekeyring
 except ImportError:
     format.
     """
 
-    def __init__(self):
-        self.file_path = os.path.join(os.path.expanduser("~"), self.filename())
+    @properties.NonDataProperty
+    def file_path(self):
+        """
+        The path to the file where passwords are stored.
+        """
+        return os.path.join(os.path.expanduser('~'), self.filename)
 
-    @abstractmethod
+    @abstractproperty
     def filename(self):
-        """Return the filename used to store the passwords.
+        """The filename used to store the passwords.
         """
         pass
 
 
 class UncryptedFileKeyring(BasicFileKeyring):
     """Uncrypted File Keyring"""
-    def filename(self):
-        """Return the filename of the password file. It should be
-        "keyring_pass.cfg" .
-        """
-        return "keyring_pass.cfg"
+
+    filename = 'keyring_pass.cfg'
 
     def encrypt(self, password):
         """Directly return the password itself.
 
 class CryptedFileKeyring(BasicFileKeyring):
     """PyCrypto File Keyring"""
-    def __init__(self):
-        super(CryptedFileKeyring, self).__init__()
-        self.crypted_password = None
 
-    def filename(self):
-        """Return the filename for the password file.
-        """
-        return "crypted_pass.cfg"
+    filename = 'crypted_pass.cfg'
+    crypted_password = None
 
     def supported(self):
         """Applicable for all platforms, but not recommend"
 
 class Win32CryptoKeyring(BasicFileKeyring):
     """Win32 Cryptography Keyring"""
+
+    filename = 'wincrypto_pass.cfg'
+
     def __init__(self):
         super(Win32CryptoKeyring, self).__init__()
 
         except ImportError, e:
             self.crypt_handler = None
 
-    def filename(self):
-        """Return the filename for the password storages file.
-        """
-        return "wincrypto_pass.cfg"
-
     def supported(self):
         """Recommended when other Windows backends are unavailable
         """

keyring/util/properties.py

+# borrowed from jaraco.util.dictlib
+class NonDataProperty(object):
+	"""Much like the property builtin, but only implements __get__,
+	making it a non-data property, and can be subsequently reset.
+
+	See http://users.rcn.com/python/download/Descriptor.htm for more
+	information.
+
+	>>> class X(object):
+	...   @NonDataProperty
+	...   def foo(self):
+	...     return 3
+	>>> x = X()
+	>>> x.foo
+	3
+	>>> x.foo = 4
+	>>> x.foo
+	4
+	"""
+
+	def __init__(self, fget):
+		assert fget is not None, "fget cannot be none"
+		assert callable(fget), "fget must be callable"
+		self.fget = fget
+
+	def __get__(self, obj, objtype=None):
+		if obj is None:
+			return self
+		return self.fget(obj)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.