Skip to content

Commit

Permalink
Allow access to PDB procedures via strings
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilburda committed Aug 20, 2023
1 parent a6d02db commit fc0e2dc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.1
===

* Allowed access to PDB procedures via strings as `pdb['some-procedure-name']`.
* Python exceptions are now raised if attempting to access non-existent procedure names.

1.0
===

Expand Down
21 changes: 21 additions & 0 deletions pdb-wrapper/pypdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,32 @@ def last_error(self):
def __getattr__(self, name):
proc_name = name.replace('_', '-')

if not self._procedure_exists(proc_name):
raise AttributeError(f'procedure "{proc_name}" does not exist')

return self._get_proc_by_name(proc_name)

def __getitem__(self, name):
proc_name = name.replace('_', '-')

if not self._procedure_exists(proc_name):
raise KeyError(f'procedure "{proc_name}" does not exist')

return self._get_proc_by_name(proc_name)

def __contains__(self, name):
return self._procedure_exists(name)

def _get_proc_by_name(self, proc_name):
if proc_name not in self._proc_cache:
self._proc_cache[proc_name] = PyPDBProcedure(self, proc_name)

return self._proc_cache[proc_name]

@staticmethod
def _procedure_exists(proc_name):
return _gimp_pdb.procedure_exists(proc_name)


class PyPDBProcedure:

Expand Down

0 comments on commit fc0e2dc

Please sign in to comment.