Skip to content

Commit

Permalink
PEP8 optimize imports (etingof#242)
Browse files Browse the repository at this point in the history
To make them PEP8-compliant
  • Loading branch information
etingof authored and lextm committed Aug 24, 2024
1 parent a3de3ca commit c455f37
Show file tree
Hide file tree
Showing 66 changed files with 642 additions and 428 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
import-order-style = smarkets
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,pysnmp/smi/mibs
ignore = D100, D101, D102, D103, D104, D105, D107, D400, D401, E203, E266, E722, E501, W503, F403, F401, I202, N801, N802, N803, N806, N815, N818, RST304
82 changes: 81 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ black = "23.1.0"
pre-commit = "2.21.0"
doc8 = "^1.0.0"
sphinx-notfound-page = "^1.0.0"
flake8 = "5.0.4"
flake8-import-order = "^0.18.2"
flake8-docstrings = "^1.7.0"
flake8-rst-docstrings = "^0.3.0"

[tool.poetry_bumpversion.file."pysnmp/__init__.py"]

Expand Down
8 changes: 4 additions & 4 deletions pysnmp/carrier/asyncio/dgram/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
# THE POSSIBILITY OF SUCH DAMAGE.
#

import asyncio
import sys
import traceback
from socket import socket

from pysnmp import debug
from pysnmp.carrier import error
from pysnmp.carrier.asyncio.base import AbstractAsyncioTransport
from pysnmp.carrier.base import AbstractTransportAddress
from pysnmp.carrier import error
from pysnmp import debug

import asyncio


class DgramAsyncioProtocol(asyncio.DatagramProtocol, AbstractAsyncioTransport):
Expand Down
6 changes: 4 additions & 2 deletions pysnmp/carrier/asyncio/dgram/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
#

import socket
from typing import Tuple
import warnings
from pysnmp.carrier.base import AbstractTransportAddress
from typing import Tuple

from pysnmp.carrier.asyncio.dgram.base import DgramAsyncioProtocol
from pysnmp.carrier.base import AbstractTransportAddress

DOMAIN_NAME: Tuple[int, ...]
SNMP_UDP6_DOMAIN: Tuple[int, ...]
Expand Down
6 changes: 4 additions & 2 deletions pysnmp/carrier/asyncio/dgram/udp6.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
# License: https://www.pysnmp.com/pysnmp/license.html
#

import socket
from typing import Tuple
import warnings
from pysnmp.carrier.base import AbstractTransportAddress
from typing import Tuple

from pysnmp.carrier.asyncio.dgram.base import DgramAsyncioProtocol
from pysnmp.carrier.base import AbstractTransportAddress

DOMAIN_NAME: Tuple[int, ...]
SNMP_UDP6_DOMAIN: Tuple[int, ...]
Expand Down
6 changes: 3 additions & 3 deletions pysnmp/carrier/asyncio/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
#
import asyncio
import sys
from time import time
import traceback
from time import time
from typing import Tuple

from pysnmp.carrier.base import AbstractTransport, AbstractTransportDispatcher
from pysnmp.error import PySnmpError

import asyncio


class AsyncioDispatcher(AbstractTransportDispatcher):
"""AsyncioDispatcher based on asyncio event loop"""
Expand Down
2 changes: 1 addition & 1 deletion pysnmp/carrier/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# License: https://www.pysnmp.com/pysnmp/license.html
#
from typing import Any, Callable

from pysnmp.carrier import error
from typing import Callable


class TimerCallable:
Expand Down
4 changes: 2 additions & 2 deletions pysnmp/carrier/sockmsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
# Parts of the code below is taken from:
# http://carnivore.it/2012/10/12/python3.3_sendmsg_and_recvmsg
#
from pysnmp import debug

import ctypes
import ipaddress
import socket

from pysnmp import debug


uint32_t = ctypes.c_uint32
in_addr_t = uint32_t
Expand Down
6 changes: 3 additions & 3 deletions pysnmp/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
# License: https://www.pysnmp.com/pysnmp/license.html
#
import logging
import warnings

from pyasn1.compat.octets import octs2ints
from pysnmp import error
from pysnmp import __version__

import warnings
from pysnmp import __version__, error


def __getattr__(attr: str):
Expand Down
24 changes: 11 additions & 13 deletions pysnmp/entity/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
# License: https://www.pysnmp.com/pysnmp/license.html
#
import warnings

from pyasn1.compat.octets import null

from pysnmp import debug, error
from pysnmp.carrier.asyncio.dgram import udp, udp6
from pysnmp.carrier.base import AbstractTransport
from pysnmp.entity.engine import SnmpEngine
from pysnmp.proto import rfc1902, rfc1905
from pysnmp.proto.secmod.eso.priv import aes192, aes256, des3
from pysnmp.proto.secmod.rfc3414.auth import hmacmd5, hmacsha, noauth
from pysnmp.proto.secmod.rfc3414.priv import des, nopriv
from pysnmp.proto.secmod.rfc3826.priv import aes
from pysnmp.proto.secmod.rfc7860.auth import hmacsha2
from pysnmp.proto.secmod.eso.priv import des3, aes192, aes256
from pysnmp.proto import rfc1902
from pysnmp.proto import rfc1905
from pysnmp import error
from pysnmp import debug

# Old to new attribute mapping
deprecated_attributes = {
Expand Down Expand Up @@ -61,8 +61,8 @@ def __getattr__(attr: str):
# A shortcut to popular constants

# Transports
snmpUDPDomain = udp.SNMP_UDP_DOMAIN
snmpUDP6Domain = udp6.SNMP_UDP6_DOMAIN
SNMP_UDP_DOMAIN = udp.SNMP_UDP_DOMAIN
SNMP_UDP6_DOMAIN = udp6.SNMP_UDP6_DOMAIN

# Auth protocol
USM_AUTH_HMAC96_MD5 = hmacmd5.HmacMd5.SERVICE_ID
Expand Down Expand Up @@ -395,8 +395,6 @@ def delV3User(
userName,
securityEngineId=None,
):
if securityEngineId is None: # backward compatibility
securityEngineId = contextEngineId
(
securityEngineId,
usmUserEntry,
Expand Down Expand Up @@ -516,13 +514,13 @@ def addTargetAddr(
snmpEngine, addrName
)

if transportDomain[: len(snmpUDPDomain)] == snmpUDPDomain:
if transportDomain[: len(SNMP_UDP_DOMAIN)] == SNMP_UDP_DOMAIN:
(SnmpUDPAddress,) = mibBuilder.importSymbols("SNMPv2-TM", "SnmpUDPAddress")
transportAddress = SnmpUDPAddress(transportAddress)
if sourceAddress is None:
sourceAddress = ("0.0.0.0", 0)
sourceAddress = SnmpUDPAddress(sourceAddress)
elif transportDomain[: len(snmpUDP6Domain)] == snmpUDP6Domain:
elif transportDomain[: len(SNMP_UDP6_DOMAIN)] == SNMP_UDP6_DOMAIN:
(TransportAddressIPv6,) = mibBuilder.importSymbols(
"TRANSPORT-ADDRESS-MIB", "TransportAddressIPv6"
)
Expand Down Expand Up @@ -616,8 +614,8 @@ def delTransport(snmpEngine: SnmpEngine, transportDomain: "tuple[int, ...]"):
return transport


addSocketTransport = addTransport
delSocketTransport = delTransport
addSocketTransport = addTransport # noqa: N816
delSocketTransport = delTransport # noqa: N816


# VACM shortcuts
Expand Down
14 changes: 8 additions & 6 deletions pysnmp/entity/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@
import sys
import tempfile
from typing import Any

from pyasn1.compat.octets import str2octs


from pysnmp import debug, error
from pysnmp.carrier.base import AbstractTransportAddress, AbstractTransportDispatcher
from pysnmp.proto.rfc1902 import OctetString
from pysnmp.proto.rfc3412 import MsgAndPduDispatcher
from pysnmp.entity import observer
from pysnmp.proto.acmod import rfc3415, void
from pysnmp.proto.mpmod.rfc2576 import (
SnmpV1MessageProcessingModel,
SnmpV2cMessageProcessingModel,
)
from pysnmp.proto.mpmod.rfc3412 import SnmpV3MessageProcessingModel
from pysnmp.proto.rfc1902 import OctetString
from pysnmp.proto.rfc3412 import MsgAndPduDispatcher
from pysnmp.proto.secmod.rfc2576 import SnmpV1SecurityModel, SnmpV2cSecurityModel
from pysnmp.proto.secmod.rfc3414 import SnmpUSMSecurityModel
from pysnmp.proto.acmod import rfc3415, void
from pysnmp.entity import observer
from pysnmp import debug
from pysnmp import error

__all__ = ["SnmpEngine"]

Expand Down
8 changes: 4 additions & 4 deletions pysnmp/entity/observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@


class MetaObserver:
"""This is a simple facility for exposing internal SNMP Engine
working details to pysnmp applications. These details are
basically local scope variables at a fixed point of execution.
r"""This is a simple facility for exposing internal SNMP Engine working details to pysnmp applications.
These details are basically local scope variables at a fixed point of
execution. Two modes of operations are offered:
Two modes of operations are offered:
1. Consumer: app can request an execution point context by execution point ID.
2. Provider: app can register its callback function (and context) to be invoked
once execution reaches specified point. All local scope variables
Expand Down
13 changes: 8 additions & 5 deletions pysnmp/entity/rfc3413/cmdgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
# License: https://www.pysnmp.com/pysnmp/license.html
#
import sys

from pyasn1.type import univ


from pysnmp import debug, error, nextid
from pysnmp.entity.engine import SnmpEngine
from pysnmp.entity.rfc3413 import config
from pysnmp.proto import rfc1905, errind
from pysnmp.proto import errind, rfc1905
from pysnmp.proto.api import v2c
from pysnmp.proto.proxy import rfc2576
from pysnmp import error, nextid, debug
from pysnmp.proto.error import StatusInformation
from pyasn1.type import univ
from pysnmp.proto.proxy import rfc2576

getNextHandle = nextid.Integer(0x7FFFFFFF)
getNextHandle = nextid.Integer(0x7FFFFFFF) # noqa: N816

__null = univ.Null("")

Expand Down
Loading

0 comments on commit c455f37

Please sign in to comment.