[Python-modules-commits] [keyrings.alt] 01/02: Import keyrings.alt_1.3.orig.tar.gz
Dmitry Shachnev
mitya57 at moszumanska.debian.org
Wed Dec 14 10:44:45 UTC 2016
This is an automated email from the git hooks/post-receive script.
mitya57 pushed a commit to branch master
in repository keyrings.alt.
commit cb9680343609637c56f5a6567447d3095efd55ce
Author: Dmitry Shachnev <mitya57 at gmail.com>
Date: Wed Dec 14 13:43:46 2016 +0300
Import keyrings.alt_1.3.orig.tar.gz
---
CHANGES.rst | 7 ++
PKG-INFO | 2 +-
keyrings.alt.egg-info/PKG-INFO | 2 +-
keyrings.alt.egg-info/SOURCES.txt | 1 +
keyrings/alt/Windows.py | 4 +-
keyrings/alt/file.py | 135 ++-----------------------------------
keyrings/alt/file_base.py | 138 ++++++++++++++++++++++++++++++++++++++
tests/requirements.txt | 2 +-
8 files changed, 156 insertions(+), 135 deletions(-)
diff --git a/CHANGES.rst b/CHANGES.rst
index 7beaf00..a3bec54 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,3 +1,10 @@
+1.3
+===
+
+#9: Moved base file backend functionality from 'keyrings.alt.file'
+to 'keyrings.alt.base_file'. This allows the 'Windows' module to
+no longer trigger a circular import with the 'file' module.
+
1.2
===
diff --git a/PKG-INFO b/PKG-INFO
index 9a55837..30df9d9 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: keyrings.alt
-Version: 1.2
+Version: 1.3
Summary: Alternate keyring implementations
Home-page: https://github.com/jaraco/keyrings.alt
Author: Jason R. Coombs
diff --git a/keyrings.alt.egg-info/PKG-INFO b/keyrings.alt.egg-info/PKG-INFO
index 9a55837..30df9d9 100644
--- a/keyrings.alt.egg-info/PKG-INFO
+++ b/keyrings.alt.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: keyrings.alt
-Version: 1.2
+Version: 1.3
Summary: Alternate keyring implementations
Home-page: https://github.com/jaraco/keyrings.alt
Author: Jason R. Coombs
diff --git a/keyrings.alt.egg-info/SOURCES.txt b/keyrings.alt.egg-info/SOURCES.txt
index cfaa397..2afd3fd 100644
--- a/keyrings.alt.egg-info/SOURCES.txt
+++ b/keyrings.alt.egg-info/SOURCES.txt
@@ -24,6 +24,7 @@ keyrings/alt/Windows.py
keyrings/alt/__init__.py
keyrings/alt/_win_crypto.py
keyrings/alt/file.py
+keyrings/alt/file_base.py
keyrings/alt/keyczar.py
keyrings/alt/kwallet.py
keyrings/alt/multi.py
diff --git a/keyrings/alt/Windows.py b/keyrings/alt/Windows.py
index 1b591c0..7910181 100644
--- a/keyrings/alt/Windows.py
+++ b/keyrings/alt/Windows.py
@@ -6,7 +6,7 @@ import functools
from keyring.util import properties
from keyring.backend import KeyringBackend
from keyring.errors import PasswordDeleteError, ExceptionRaisedContext
-from . import file
+from . import file_base
try:
# prefer pywin32-ctypes
@@ -56,7 +56,7 @@ def has_wincrypto():
_win_crypto.__name__
return not bool(exc)
-class EncryptedKeyring(file.BaseKeyring):
+class EncryptedKeyring(file_base.Keyring):
"""
A File-based keyring secured by Windows Crypto API.
"""
diff --git a/keyrings/alt/file.py b/keyrings/alt/file.py
index ad3e19f..89b3142 100644
--- a/keyrings/alt/file.py
+++ b/keyrings/alt/file.py
@@ -5,142 +5,16 @@ import getpass
import base64
import sys
import json
-import abc
from keyring.py27compat import configparser
-from keyring.errors import PasswordDeleteError
-from keyring.backend import KeyringBackend
-from keyring.util import platform_, properties
+from keyring.util import properties
from keyring.util.escape import escape as escape_for_ini
+from . import file_base
-class FileBacked(object):
- @abc.abstractproperty
- def filename(self):
- """
- The filename used to store the passwords.
- """
-
- @properties.NonDataProperty
- def file_path(self):
- """
- The path to the file where passwords are stored. This property
- may be overridden by the subclass or at the instance level.
- """
- return os.path.join(platform_.data_root(), self.filename)
-
- def __repr__(self):
- tmpl = "<{self.__class__.__name__} at {self.file_path}>"
- return tmpl.format(**locals())
-
-
-class BaseKeyring(FileBacked, KeyringBackend):
- """
- BaseKeyring is a file-based implementation of keyring.
-
- This keyring stores the password directly in the file and provides methods
- which may be overridden by subclasses to support
- encryption and decryption. The encrypted payload is stored in base64
- format.
- """
-
- @abc.abstractmethod
- def encrypt(self, password):
- """
- Given a password (byte string), return an encrypted byte string.
- """
-
- @abc.abstractmethod
- def decrypt(self, password_encrypted):
- """
- Given a password encrypted by a previous call to `encrypt`, return
- the original byte string.
- """
-
- def get_password(self, service, username):
- """
- Read the password from the file.
- """
- service = escape_for_ini(service)
- username = escape_for_ini(username)
- # load the passwords from the file
- config = configparser.RawConfigParser()
- if os.path.exists(self.file_path):
- config.read(self.file_path)
-
- # fetch the password
- try:
- password_base64 = config.get(service, username).encode()
- # decode with base64
- password_encrypted = base64.decodestring(password_base64)
- # decrypted the password
- password = self.decrypt(password_encrypted).decode('utf-8')
- except (configparser.NoOptionError, configparser.NoSectionError):
- password = None
- return password
-
- def set_password(self, service, username, password):
- """Write the password in the file.
- """
- service = escape_for_ini(service)
- username = escape_for_ini(username)
-
- # encrypt the password
- password_encrypted = self.encrypt(password.encode('utf-8'))
- # encode with base64
- password_base64 = base64.encodestring(password_encrypted).decode()
-
- # ensure the file exists
- self._ensure_file_path()
-
- # load the keyring from the disk
- config = configparser.RawConfigParser()
- config.read(self.file_path)
-
- # update the keyring with the password
- if not config.has_section(service):
- config.add_section(service)
- config.set(service, username, password_base64)
-
- # save the keyring back to the file
- with open(self.file_path, 'w') as config_file:
- config.write(config_file)
-
- def _ensure_file_path(self):
- """
- Ensure the storage path exists.
- If it doesn't, create it with "go-rwx" permissions.
- """
- storage_root = os.path.dirname(self.file_path)
- if storage_root and not os.path.isdir(storage_root):
- os.makedirs(storage_root)
- if not os.path.isfile(self.file_path):
- # create the file without group/world permissions
- with open(self.file_path, 'w'):
- pass
- user_read_write = 0o600
- os.chmod(self.file_path, user_read_write)
-
- def delete_password(self, service, username):
- """Delete the password for the username of the service.
- """
- service = escape_for_ini(service)
- username = escape_for_ini(username)
- config = configparser.RawConfigParser()
- if os.path.exists(self.file_path):
- config.read(self.file_path)
- try:
- if not config.remove_option(service, username):
- raise PasswordDeleteError("Password not found")
- except configparser.NoSectionError:
- raise PasswordDeleteError("Password not found")
- # update the file
- with open(self.file_path, 'w') as config_file:
- config.write(config_file)
-
-class PlaintextKeyring(BaseKeyring):
+class PlaintextKeyring(file_base.Keyring):
"""Simple File Keyring with no encryption"""
priority = .5
@@ -158,6 +32,7 @@ class PlaintextKeyring(BaseKeyring):
"""
return password_encrypted
+
class Encrypted(object):
"""
PyCrypto-backed Encryption support
@@ -189,7 +64,7 @@ class Encrypted(object):
return password
-class EncryptedKeyring(Encrypted, BaseKeyring):
+class EncryptedKeyring(Encrypted, file_base.Keyring):
"""PyCrypto File Keyring"""
filename = 'crypted_pass.cfg'
diff --git a/keyrings/alt/file_base.py b/keyrings/alt/file_base.py
new file mode 100644
index 0000000..f0e4cd2
--- /dev/null
+++ b/keyrings/alt/file_base.py
@@ -0,0 +1,138 @@
+from __future__ import with_statement
+
+import os
+import base64
+import abc
+
+from keyring.py27compat import configparser
+
+from keyring.errors import PasswordDeleteError
+from keyring.backend import KeyringBackend
+from keyring.util import platform_, properties
+from keyring.util.escape import escape as escape_for_ini
+
+
+class FileBacked(object):
+ @abc.abstractproperty
+ def filename(self):
+ """
+ The filename used to store the passwords.
+ """
+
+ @properties.NonDataProperty
+ def file_path(self):
+ """
+ The path to the file where passwords are stored. This property
+ may be overridden by the subclass or at the instance level.
+ """
+ return os.path.join(platform_.data_root(), self.filename)
+
+ def __repr__(self):
+ tmpl = "<{self.__class__.__name__} at {self.file_path}>"
+ return tmpl.format(**locals())
+
+
+class Keyring(FileBacked, KeyringBackend):
+ """
+ BaseKeyring is a file-based implementation of keyring.
+
+ This keyring stores the password directly in the file and provides methods
+ which may be overridden by subclasses to support
+ encryption and decryption. The encrypted payload is stored in base64
+ format.
+ """
+
+ @abc.abstractmethod
+ def encrypt(self, password):
+ """
+ Given a password (byte string), return an encrypted byte string.
+ """
+
+ @abc.abstractmethod
+ def decrypt(self, password_encrypted):
+ """
+ Given a password encrypted by a previous call to `encrypt`, return
+ the original byte string.
+ """
+
+ def get_password(self, service, username):
+ """
+ Read the password from the file.
+ """
+ service = escape_for_ini(service)
+ username = escape_for_ini(username)
+
+ # load the passwords from the file
+ config = configparser.RawConfigParser()
+ if os.path.exists(self.file_path):
+ config.read(self.file_path)
+
+ # fetch the password
+ try:
+ password_base64 = config.get(service, username).encode()
+ # decode with base64
+ password_encrypted = base64.decodestring(password_base64)
+ # decrypted the password
+ password = self.decrypt(password_encrypted).decode('utf-8')
+ except (configparser.NoOptionError, configparser.NoSectionError):
+ password = None
+ return password
+
+ def set_password(self, service, username, password):
+ """Write the password in the file.
+ """
+ service = escape_for_ini(service)
+ username = escape_for_ini(username)
+
+ # encrypt the password
+ password_encrypted = self.encrypt(password.encode('utf-8'))
+ # encode with base64
+ password_base64 = base64.encodestring(password_encrypted).decode()
+
+ # ensure the file exists
+ self._ensure_file_path()
+
+ # load the keyring from the disk
+ config = configparser.RawConfigParser()
+ config.read(self.file_path)
+
+ # update the keyring with the password
+ if not config.has_section(service):
+ config.add_section(service)
+ config.set(service, username, password_base64)
+
+ # save the keyring back to the file
+ with open(self.file_path, 'w') as config_file:
+ config.write(config_file)
+
+ def _ensure_file_path(self):
+ """
+ Ensure the storage path exists.
+ If it doesn't, create it with "go-rwx" permissions.
+ """
+ storage_root = os.path.dirname(self.file_path)
+ if storage_root and not os.path.isdir(storage_root):
+ os.makedirs(storage_root)
+ if not os.path.isfile(self.file_path):
+ # create the file without group/world permissions
+ with open(self.file_path, 'w'):
+ pass
+ user_read_write = 0o600
+ os.chmod(self.file_path, user_read_write)
+
+ def delete_password(self, service, username):
+ """Delete the password for the username of the service.
+ """
+ service = escape_for_ini(service)
+ username = escape_for_ini(username)
+ config = configparser.RawConfigParser()
+ if os.path.exists(self.file_path):
+ config.read(self.file_path)
+ try:
+ if not config.remove_option(service, username):
+ raise PasswordDeleteError("Password not found")
+ except configparser.NoSectionError:
+ raise PasswordDeleteError("Password not found")
+ # update the file
+ with open(self.file_path, 'w') as config_file:
+ config.write(config_file)
diff --git a/tests/requirements.txt b/tests/requirements.txt
index e84f9c9..21a1a09 100644
--- a/tests/requirements.txt
+++ b/tests/requirements.txt
@@ -2,7 +2,7 @@ pytest >= 2.8
backports.unittest_mock
keyring[test]
-fs>=0.5
+fs>=0.5,<2
pycrypto
# gdata doesn't currently install on Python 3
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/keyrings.alt.git
More information about the Python-modules-commits
mailing list