diff options
author | Ilya Etingof <etingof@gmail.com> | 2019-02-10 16:38:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-10 16:38:35 +0100 |
commit | 588b9b902d191d8010cb6b247fcb07887d59542c (patch) | |
tree | 419b01d2598e91331db784ac3a6675324aba8c24 /pysnmp/debug.py | |
parent | 9664858b145140a4fbb2a22b633c1ab41c2555bd (diff) | |
download | pysnmp-git-588b9b902d191d8010cb6b247fcb07887d59542c.tar.gz |
Uppercase global constants (#238)
This is a massive patch essentially upper-casing global/class attributes
that mean to be constants.
Some previously exposed constants have been preserved for compatibility
reasons (notably, in `hlapi`), though the rest might break user code relying
on pysnmp 4.
Diffstat (limited to 'pysnmp/debug.py')
-rw-r--r-- | pysnmp/debug.py | 66 |
1 files changed, 35 insertions, 31 deletions
diff --git a/pysnmp/debug.py b/pysnmp/debug.py index 715a3876..8217569d 100644 --- a/pysnmp/debug.py +++ b/pysnmp/debug.py @@ -9,30 +9,32 @@ from pyasn1.compat.octets import octs2ints from pysnmp import error from pysnmp import __version__ -flagNone = 0x0000 -flagIO = 0x0001 -flagDsp = 0x0002 -flagMP = 0x0004 -flagSM = 0x0008 -flagBld = 0x0010 -flagMIB = 0x0020 -flagIns = 0x0040 -flagACL = 0x0080 -flagPrx = 0x0100 -flagApp = 0x0200 -flagAll = 0xffff - -flagMap = {'io': flagIO, - 'dsp': flagDsp, - 'msgproc': flagMP, - 'secmod': flagSM, - 'mibbuild': flagBld, - 'mibview': flagMIB, - 'mibinstrum': flagIns, - 'acl': flagACL, - 'proxy': flagPrx, - 'app': flagApp, - 'all': flagAll} +FLAG_NONE = 0x0000 +FLAG_IO = 0x0001 +FLAG_DSP = 0x0002 +FLAG_MP = 0x0004 +FLAG_SM = 0x0008 +FLAG_BLD = 0x0010 +FLAG_MIB = 0x0020 +FLAG_INS = 0x0040 +FLAG_ACL = 0x0080 +FLAG_PRX = 0x0100 +FLAG_APP = 0x0200 +FLAG_ALL = 0xffff + +FLAG_MAP = { + 'io': FLAG_IO, + 'dsp': FLAG_DSP, + 'msgproc': FLAG_MP, + 'secmod': FLAG_SM, + 'mibbuild': FLAG_BLD, + 'mibview': FLAG_MIB, + 'mibinstrum': FLAG_INS, + 'acl': FLAG_ACL, + 'proxy': FLAG_PRX, + 'app': FLAG_APP, + 'all': FLAG_ALL +} class Printer(object): @@ -58,6 +60,7 @@ class Printer(object): if hasattr(logging, 'NullHandler'): NullHandler = logging.NullHandler + else: # Python 2.6 and older class NullHandler(logging.Handler): @@ -66,14 +69,14 @@ else: class Debug(object): - defaultPrinter = None + DEFAULT_PRINTER = None def __init__(self, *flags, **options): - self._flags = flagNone + self._flags = FLAG_NONE if options.get('printer') is not None: self._printer = options.get('printer') - elif self.defaultPrinter is not None: - self._printer = self.defaultPrinter + elif self.DEFAULT_PRINTER is not None: + self._printer = self.DEFAULT_PRINTER else: if 'loggerName' in options: # route our logs to parent logger @@ -90,9 +93,9 @@ class Debug(object): f = f[1:] try: if inverse: - self._flags &= ~flagMap[f] + self._flags &= ~FLAG_MAP[f] else: - self._flags |= flagMap[f] + self._flags |= FLAG_MAP[f] except KeyError: raise error.PySnmpError('bad debug flag %s' % f) @@ -123,4 +126,5 @@ def setLogger(l): def hexdump(octets): return ' '.join( - ['%s%.2X' % (n % 16 == 0 and ('\n%.5d: ' % n) or '', x) for n, x in zip(range(len(octets)), octs2ints(octets))]) + ['%s%.2X' % (n % 16 == 0 and ('\n%.5d: ' % n) or '', x) + for n, x in zip(range(len(octets)), octs2ints(octets))]) |