Module gnupg.handlers.auto_locate_key_handler
View Source
from __future__ import annotations
from datetime import datetime
from email.utils import parseaddr
from typing import TYPE_CHECKING
from .status_handler import StatusHandler
if TYPE_CHECKING:
from gnupg.gnupg import GPG
class AutoLocateKeyHandler(StatusHandler):
"""
This class handles status messages during key auto-locating.
fingerprint: str
key_length: int
created_at: date
email: str
email_real_name: str
"""
def __init__(self, gpg: GPG) -> None:
StatusHandler.__init__(self, gpg)
self.fingerprint = None
self.type = None
self.created_at = None
self.email = None
self.email_real_name = None
def handle_status(self, key: str, value: str) -> None:
if key == "IMPORTED":
_, email, display_name = value.split()
self.email = email
self.email_real_name = display_name[1:-1]
elif key == "KEY_CONSIDERED":
self.fingerprint = value.strip().split()[0]
def pub(self, args: list[str]) -> None:
"""
Internal method to handle the 'pub' status message.
`pub` message contains the fingerprint of the public key, its type and its creation date.
"""
def uid(self, args: list[str]) -> None:
local_tz = datetime.now().astimezone().tzinfo
self.created_at = datetime.fromtimestamp(int(args[5]), tz=local_tz)
raw_email_content = args[9]
email, real_name = parseaddr(raw_email_content)
self.email = email
self.email_real_name = real_name
def sub(self, args: list[str]) -> None:
self.key_length = int(args[2])
def fpr(self, args: list[str]) -> None:
# Only store the first fingerprint
self.fingerprint = self.fingerprint or args[9]
Variables
TYPE_CHECKING
Classes
AutoLocateKeyHandler
class AutoLocateKeyHandler(
gpg: 'GPG'
)
This class handles status messages during key auto-locating.
fingerprint: str key_length: int created_at: date email: str email_real_name: str
View Source
class AutoLocateKeyHandler(StatusHandler):
"""
This class handles status messages during key auto-locating.
fingerprint: str
key_length: int
created_at: date
email: str
email_real_name: str
"""
def __init__(self, gpg: GPG) -> None:
StatusHandler.__init__(self, gpg)
self.fingerprint = None
self.type = None
self.created_at = None
self.email = None
self.email_real_name = None
def handle_status(self, key: str, value: str) -> None:
if key == "IMPORTED":
_, email, display_name = value.split()
self.email = email
self.email_real_name = display_name[1:-1]
elif key == "KEY_CONSIDERED":
self.fingerprint = value.strip().split()[0]
def pub(self, args: list[str]) -> None:
"""
Internal method to handle the 'pub' status message.
`pub` message contains the fingerprint of the public key, its type and its creation date.
"""
def uid(self, args: list[str]) -> None:
local_tz = datetime.now().astimezone().tzinfo
self.created_at = datetime.fromtimestamp(int(args[5]), tz=local_tz)
raw_email_content = args[9]
email, real_name = parseaddr(raw_email_content)
self.email = email
self.email_real_name = real_name
def sub(self, args: list[str]) -> None:
self.key_length = int(args[2])
def fpr(self, args: list[str]) -> None:
# Only store the first fingerprint
self.fingerprint = self.fingerprint or args[9]
Ancestors (in MRO)
- gnupg.handlers.status_handler.StatusHandler
Methods
fpr
def fpr(
self,
args: 'list[str]'
) -> 'None'
View Source
def fpr(self, args: list[str]) -> None:
# Only store the first fingerprint
self.fingerprint = self.fingerprint or args[9]
handle_status
def handle_status(
self,
key: 'str',
value: 'str'
) -> 'None'
Handle status messages from the gpg child process. These are lines of the format
[GNUPG:]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| key | str | Identifies what the status message is. | None |
| value | str | Identifies additional data, which differs depending on the key. | None |
View Source
def handle_status(self, key: str, value: str) -> None:
if key == "IMPORTED":
_, email, display_name = value.split()
self.email = email
self.email_real_name = display_name[1:-1]
elif key == "KEY_CONSIDERED":
self.fingerprint = value.strip().split()[0]
pub
def pub(
self,
args: 'list[str]'
) -> 'None'
Internal method to handle the 'pub' status message.
pub message contains the fingerprint of the public key, its type and its creation date.
View Source
def pub(self, args: list[str]) -> None:
"""
Internal method to handle the 'pub' status message.
`pub` message contains the fingerprint of the public key, its type and its creation date.
"""
sub
def sub(
self,
args: 'list[str]'
) -> 'None'
View Source
def sub(self, args: list[str]) -> None:
self.key_length = int(args[2])
uid
def uid(
self,
args: 'list[str]'
) -> 'None'
View Source
def uid(self, args: list[str]) -> None:
local_tz = datetime.now().astimezone().tzinfo
self.created_at = datetime.fromtimestamp(int(args[5]), tz=local_tz)
raw_email_content = args[9]
email, real_name = parseaddr(raw_email_content)
self.email = email
self.email_real_name = real_name