Module gnupg.handlers.scan_keys_handler
View Source
from __future__ import annotations
from .list_keys_handler import ListKeysHandler
class ScanKeysHandler(ListKeysHandler):
"""
This class handles status messages during scanning keys.
"""
def sub(self, args: list[str]) -> None:
"""
Internal method used to update the instance from a `gpg` status message.
"""
# --with-fingerprint --with-colons somehow outputs fewer colons,
# use the last value args[-1] instead of args[11]
subkey = [args[4], args[-1], None, None]
self.curkey["subkeys"].append(subkey)
self._collect_subkey_info(self.curkey, args)
self.in_subkey = True
Classes
ScanKeysHandler
class ScanKeysHandler(
gpg: 'GPG'
)
This class handles status messages during scanning keys.
View Source
class ScanKeysHandler(ListKeysHandler):
"""
This class handles status messages during scanning keys.
"""
def sub(self, args: list[str]) -> None:
"""
Internal method used to update the instance from a `gpg` status message.
"""
# --with-fingerprint --with-colons somehow outputs fewer colons,
# use the last value args[-1] instead of args[11]
subkey = [args[4], args[-1], None, None]
self.curkey["subkeys"].append(subkey)
self._collect_subkey_info(self.curkey, args)
self.in_subkey = True
Ancestors (in MRO)
- gnupg.handlers.list_keys_handler.ListKeysHandler
- gnupg.handlers.search_keys_handler.SearchKeysHandler
- gnupg.handlers.status_handler.StatusHandler
- builtins.list
Class variables
FIELDS
UID_INDEX
returncode
Methods
append
def append(
self,
object,
/
)
Append object to the end of the list.
clear
def clear(
self,
/
)
Remove all items from list.
copy
def copy(
self,
/
)
Return a shallow copy of the list.
count
def count(
self,
value,
/
)
Return number of occurrences of value.
extend
def extend(
self,
iterable,
/
)
Extend list by appending elements from the iterable.
fpr
def fpr(
self,
args: 'list[str]'
) -> 'None'
Internal method used to update the instance from a gpg status message.
View Source
def fpr(self, args: list[str]) -> None:
"""
Internal method used to update the instance from a `gpg` status message.
"""
fp = args[9]
if fp in self.key_map and self.gpg.check_fingerprint_collisions: # pragma: no cover
msg = f"Unexpected fingerprint collision: {fp}"
raise ValueError(msg)
if not self.in_subkey:
self.curkey["fingerprint"] = fp
self.fingerprints.append(fp)
self.key_map[fp] = self.curkey
else:
self.curkey["subkeys"][-1][2] = fp
self.key_map[fp] = self.curkey
get_fields
def get_fields(
self,
args: 'list[str]'
) -> 'dict[str, str]'
Internal method used to update the instance from a gpg status message.
View Source
def get_fields(self, args: list[str]) -> dict[str, str]:
"""
Internal method used to update the instance from a `gpg` status message.
"""
result = {}
_set_fields(result, self.FIELDS, args)
result["uids"] = []
result["sigs"] = []
return result
grp
def grp(
self,
args: 'list[str]'
) -> 'None'
Internal method used to update the instance from a gpg status message.
View Source
def grp(self, args: list[str]) -> None:
"""
Internal method used to update the instance from a `gpg` status message.
"""
grp = args[9]
if not self.in_subkey:
self.curkey["keygrip"] = grp
else:
self.curkey["subkeys"][-1][3] = grp
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: # pragma: no cover
pass
index
def index(
self,
value,
start=0,
stop=9223372036854775807,
/
)
Return first index of value.
Raises ValueError if the value is not present.
insert
def insert(
self,
index,
object,
/
)
Insert object before index.
key
def key(
self,
args: 'list[str]'
) -> 'None'
Internal method used to update the instance from a gpg status message.
View Source
def key(self, args: list[str]) -> None:
"""
Internal method used to update the instance from a `gpg` status message.
"""
self.curkey = curkey = self.get_fields(args)
if curkey["uid"]: # pragma: no cover
curkey["uids"].append(curkey["uid"])
del curkey["uid"]
curkey["subkeys"] = []
self.append(curkey)
self.in_subkey = False
pop
def pop(
self,
index=-1,
/
)
Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
pub
def pub(
self,
args: 'list[str]'
) -> 'None'
Internal method used to update the instance from a gpg status message.
View Source
def key(self, args: list[str]) -> None:
"""
Internal method used to update the instance from a `gpg` status message.
"""
self.curkey = curkey = self.get_fields(args)
if curkey["uid"]: # pragma: no cover
curkey["uids"].append(curkey["uid"])
del curkey["uid"]
curkey["subkeys"] = []
self.append(curkey)
self.in_subkey = False
remove
def remove(
self,
value,
/
)
Remove first occurrence of value.
Raises ValueError if the value is not present.
reverse
def reverse(
self,
/
)
Reverse IN PLACE.
sec
def sec(
self,
args: 'list[str]'
) -> 'None'
Internal method used to update the instance from a gpg status message.
View Source
def key(self, args: list[str]) -> None:
"""
Internal method used to update the instance from a `gpg` status message.
"""
self.curkey = curkey = self.get_fields(args)
if curkey["uid"]: # pragma: no cover
curkey["uids"].append(curkey["uid"])
del curkey["uid"]
curkey["subkeys"] = []
self.append(curkey)
self.in_subkey = False
sig
def sig(
self,
args: 'list[str]'
) -> 'None'
Internal method used to update the instance from a gpg status message.
View Source
def sig(self, args: list[str]) -> None:
"""
Internal method used to update the instance from a `gpg` status message.
"""
# keyid, uid, sigclass
self.curkey["sigs"].append((args[4], args[9], args[10]))
sort
def sort(
self,
/,
*,
key=None,
reverse=False
)
Sort the list in ascending order and return None.
The sort is in-place (i.e. the list itself is modified) and stable (i.e. the order of two equal elements is maintained).
If a key function is given, apply it once to each list item and sort them, ascending or descending, according to their function values.
The reverse flag can be set to sort in descending order.
ssb
def ssb(
self,
args: 'list[str]'
) -> 'None'
Internal method used to update the instance from a gpg status message.
View Source
def ssb(self, args: list[str]) -> None:
"""
Internal method used to update the instance from a `gpg` status message.
"""
subkey = [args[4], None, None, None] # keyid, type, fp, grp
self.curkey["subkeys"].append(subkey)
self._collect_subkey_info(self.curkey, args)
self.in_subkey = True
sub
def sub(
self,
args: 'list[str]'
) -> 'None'
Internal method used to update the instance from a gpg status message.
View Source
def sub(self, args: list[str]) -> None:
"""
Internal method used to update the instance from a `gpg` status message.
"""
# --with-fingerprint --with-colons somehow outputs fewer colons,
# use the last value args[-1] instead of args[11]
subkey = [args[4], args[-1], None, None]
self.curkey["subkeys"].append(subkey)
self._collect_subkey_info(self.curkey, args)
self.in_subkey = True
uid
def uid(
self,
args: 'list[str]'
) -> 'None'
Internal method used to update the instance from a gpg status message.
View Source
def uid(self, args: list[str]) -> None:
"""
Internal method used to update the instance from a `gpg` status message.
"""
uid = args[self.UID_INDEX]
uid = ESCAPE_PATTERN.sub(lambda m: chr(int(m.group(1), 16)), uid)
for k, v in BASIC_ESCAPES.items():
uid = uid.replace(k, v)
self.curkey["uids"].append(uid)
self.uids.append(uid)