Skip to content

Commit

Permalink
Remove backwards compatible imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawk committed Aug 8, 2024
1 parent fe238f0 commit 8296131
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 100 deletions.
10 changes: 1 addition & 9 deletions pysnmp/proto/secmod/eso/priv/aesbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,14 @@
# Copyright (c) 2005-2020, Ilya Etingof <[email protected]>
# License: https://www.pysnmp.com/pysnmp/license.html
#
from hashlib import md5, sha1
from pysnmp.proto.secmod.rfc3826.priv import aes
from pysnmp.proto.secmod.rfc3414.auth import hmacmd5, hmacsha
from pysnmp.proto.secmod.rfc7860.auth import hmacsha2
from pysnmp.proto.secmod.rfc3414 import localkey
from pysnmp.proto import error
from math import ceil

try:
from hashlib import md5, sha1
except ImportError:
import md5
import sha

md5 = md5.new
sha1 = sha.new


class AbstractAesBlumenthal(aes.Aes):
serviceID = ()
Expand Down
10 changes: 1 addition & 9 deletions pysnmp/proto/secmod/eso/priv/des3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@
# Copyright (c) 2005-2020, Ilya Etingof <[email protected]>
# License: https://www.pysnmp.com/pysnmp/license.html
#
from hashlib import md5, sha1
import random

try:
from hashlib import md5, sha1
except ImportError:
import md5
import sha

md5 = md5.new
sha1 = sha.new

try:
from pysnmpcrypto import des3, PysnmpCryptoError

Expand Down
7 changes: 1 addition & 6 deletions pysnmp/proto/secmod/rfc3414/auth/hmacmd5.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
# Copyright (c) 2005-2020, Ilya Etingof <[email protected]>
# License: https://www.pysnmp.com/pysnmp/license.html
#
try:
from hashlib import md5
except ImportError:
import md5

md5 = md5.new
from hashlib import md5
from pyasn1.type import univ
from pysnmp.proto.secmod.rfc3414.auth import base
from pysnmp.proto.secmod.rfc3414 import localkey
Expand Down
7 changes: 1 addition & 6 deletions pysnmp/proto/secmod/rfc3414/auth/hmacsha.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
# Copyright (c) 2005-2020, Ilya Etingof <[email protected]>
# License: https://www.pysnmp.com/pysnmp/license.html
#
try:
from hashlib import sha1
except ImportError:
import sha

sha1 = sha.new
from hashlib import sha1
from pyasn1.type import univ
from pysnmp.proto.secmod.rfc3414.auth import base
from pysnmp.proto.secmod.rfc3414 import localkey
Expand Down
11 changes: 1 addition & 10 deletions pysnmp/proto/secmod/rfc3414/localkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@
# Copyright (c) 2005-2020, Ilya Etingof <[email protected]>
# License: https://www.pysnmp.com/pysnmp/license.html
#
try:
from hashlib import md5, sha1

except ImportError:
import md5
import sha

md5 = md5.new
sha1 = sha.new

from hashlib import md5, sha1
from pyasn1.type import univ


Expand Down
12 changes: 1 addition & 11 deletions pysnmp/proto/secmod/rfc3414/priv/des.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,9 @@
# Copyright (c) 2005-2020, Ilya Etingof <[email protected]>
# License: https://www.pysnmp.com/pysnmp/license.html
#
from hashlib import md5, sha1
import random

try:
from hashlib import md5, sha1
except ImportError:
import md5
import sha

md5 = md5.new
sha1 = sha.new

from sys import version_info

try:
from pysnmpcrypto import des, PysnmpCryptoError

Expand Down
10 changes: 1 addition & 9 deletions pysnmp/proto/secmod/rfc3826/priv/aes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@
# Copyright (c) 2005-2020, Ilya Etingof <[email protected]>
# License: https://www.pysnmp.com/pysnmp/license.html
#
from hashlib import md5, sha1
import random

try:
from hashlib import md5, sha1
except ImportError:
import md5
import sha

md5 = md5.new
sha1 = sha.new

try:
from pysnmpcrypto import aes, PysnmpCryptoError

Expand Down
13 changes: 1 addition & 12 deletions pysnmp/proto/secmod/rfc7860/auth/hmacsha2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,7 @@
#
import sys
import hmac

try:
from hashlib import sha224, sha256, sha384, sha512

except ImportError:

class NotAvailable:
def __call__(self, *args, **kwargs):
raise errind.authenticationError

sha224 = sha256 = sha384 = sha512 = NotAvailable()

from hashlib import sha224, sha256, sha384, sha512
from pyasn1.type import univ
from pysnmp.proto.secmod.rfc3414.auth import base
from pysnmp.proto.secmod.rfc3414 import localkey
Expand Down
34 changes: 6 additions & 28 deletions pysnmp/smi/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,16 @@
import marshal
import time
import traceback

try:
import importlib
import importlib.util
import importlib.machinery

try:
PY_MAGIC_NUMBER = importlib.util.MAGIC_NUMBER
SOURCE_SUFFIXES = importlib.machinery.SOURCE_SUFFIXES
BYTECODE_SUFFIXES = importlib.machinery.BYTECODE_SUFFIXES

except Exception:
raise ImportError()

except ImportError:
import imp

PY_MAGIC_NUMBER = imp.get_magic()
SOURCE_SUFFIXES = [s[0] for s in imp.get_suffixes() if s[2] == imp.PY_SOURCE]
BYTECODE_SUFFIXES = [s[0] for s in imp.get_suffixes() if s[2] == imp.PY_COMPILED]

PY_SUFFIXES = SOURCE_SUFFIXES + BYTECODE_SUFFIXES

try:
from errno import ENOENT
except ImportError:
ENOENT = -1

from errno import ENOENT
from importlib.machinery import SOURCE_SUFFIXES, BYTECODE_SUFFIXES
from importlib.util import MAGIC_NUMBER as PY_MAGIC_NUMBER
from pysnmp import version as pysnmp_version
from pysnmp.smi import error
from pysnmp import debug


PY_SUFFIXES = SOURCE_SUFFIXES + BYTECODE_SUFFIXES

classTypes = (type,)


Expand Down

0 comments on commit 8296131

Please sign in to comment.