Skip to content

Commit

Permalink
general: Merge branch 'skatromb-code-composter/python2'
Browse files Browse the repository at this point in the history
Bug-Url: #1299
  • Loading branch information
svinota committed Feb 23, 2025
2 parents 4bc7cb5 + c23977c commit bd83d51
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 112 deletions.
28 changes: 26 additions & 2 deletions pyroute2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,23 @@
from pyroute2.config.version import __version__
except ImportError:
__version__ = 'unknown'
import sys

from pyroute2 import loader
from pyroute2.cli.console import Console
from pyroute2.cli.server import Server

##
#
# Logging setup
#
# See the history:
# * https://github.com/svinota/pyroute2/issues/246
# * https://github.com/svinota/pyroute2/issues/255
# * https://github.com/svinota/pyroute2/issues/270
# * https://github.com/svinota/pyroute2/issues/573
# * https://github.com/svinota/pyroute2/issues/601
#
from pyroute2.config import log
from pyroute2.conntrack import Conntrack, ConntrackEntry
from pyroute2.devlink import DL
from pyroute2.ethtool.ethtool import Ethtool
Expand Down Expand Up @@ -58,6 +71,17 @@
from pyroute2.plan9.server import Plan9ServerSocket
from pyroute2.wiset import WiSet

##
#
# Windows platform specific: socket module monkey patching
#
# To use the library on Windows, run::
# pip install win-inet-pton
#
if sys.platform.startswith('win'): # noqa: E402
import win_inet_pton # noqa: F401


modules = [
AcpiEventSocket,
AsyncIPRoute,
Expand Down Expand Up @@ -106,8 +130,8 @@
UeventSocket,
WireGuard,
WiSet,
log,
]

loader.init()
__all__ = []
__all__.extend(modules)
9 changes: 2 additions & 7 deletions pyroute2/cli/server.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import json
from http.server import BaseHTTPRequestHandler
from http.server import HTTPServer as HTTPServer

from pyroute2.cli.session import Session
from pyroute2.ndb.main import NDB

try:
from BaseHTTPServer import BaseHTTPRequestHandler
from BaseHTTPServer import HTTPServer as HTTPServer
except ImportError:
from http.server import BaseHTTPRequestHandler
from http.server import HTTPServer as HTTPServer


class ProxyEncoder(object):
def __init__(self, wfile):
Expand Down
3 changes: 1 addition & 2 deletions pyroute2/dhcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class array8(option):

import logging
import struct
import sys
from array import array
from typing import ClassVar, NamedTuple, Optional, TypedDict, TypeVar, Union

Expand Down Expand Up @@ -188,7 +187,7 @@ def encode(self: _optionSelf) -> _optionSelf:
fmt = '%is' % len(value)
else:
fmt = self.policy.format
if sys.version_info[0] == 3 and isinstance(value, str):
if isinstance(value, str):
value = value.encode('utf-8')
self.buf = struct.pack(fmt, value)
else:
Expand Down
6 changes: 1 addition & 5 deletions pyroute2/iproute/bsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

import errno
import os
import queue
import select
import struct
import threading
Expand All @@ -71,11 +72,6 @@
from pyroute2.netlink.rtnl.ndmsg import ndmsg
from pyroute2.netlink.rtnl.rtmsg import rtmsg

try:
import queue
except ImportError:
import Queue as queue


class IPRoute(object):
def __init__(self, *argv, **kwarg):
Expand Down
43 changes: 0 additions & 43 deletions pyroute2/loader.py

This file was deleted.

12 changes: 2 additions & 10 deletions pyroute2/ndb/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@
import ctypes.util
import logging
import logging.handlers
import queue
import threading
from urllib.parse import urlparse

from pyroute2.common import basestring

Expand All @@ -287,16 +289,6 @@
from .transaction import Transaction
from .view import SourcesView, View

try:
from urlparse import urlparse
except ImportError:
from urllib.parse import urlparse

try:
import queue
except ImportError:
import Queue as queue

log = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion pyroute2/ndb/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def fetch(self, *argv, **kwarg):

@publish
def backup(self, spec):
if sys.version_info >= (3, 7) and self.provider == DBProvider.sqlite3:
if self.provider == DBProvider.sqlite3:
backup_connection = sqlite3.connect(spec)
self.connection.backup(backup_connection)
backup_connection.close()
Expand Down
12 changes: 5 additions & 7 deletions pyroute2/netlink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,7 @@ class NotInitialized(Exception):
##
# That's a hack for the code linter, which works under
# Python3, see unicode reference in the code below
if sys.version[0] == '3':
unicode = str
unicode = str

NLMSG_MIN_TYPE = 0x10

Expand Down Expand Up @@ -2336,11 +2335,10 @@ def encode(self):
def decode(self):
nla_base_string.decode(self)
self.value = self['value']
if sys.version_info[0] >= 3:
try:
self.value = self.value.decode('utf-8')
except UnicodeDecodeError:
pass # Failed to decode, keep undecoded value
try:
self.value = self.value.decode('utf-8')
except UnicodeDecodeError:
pass # Failed to decode, keep undecoded value

class asciiz(string):
'''
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ classifiers =
[options]
install_requires =
win_inet_pton ; platform_system == "Windows"
importlib-metadata ; python_version < "3.8"
packages_dir =
=pyroute2
packages = find:
Expand Down
1 change: 0 additions & 1 deletion setup.minimal.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ classifiers =
[options]
install_requires =
win_inet_pton ; platform_system == "Windows"
importlib-metadata ; python_version < "3.8"
packages_dir =
=pyroute2
packages =
Expand Down
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Requirements
============

* nox
* python >= 3.8
* python >= 3.9
* `-r requirements.dev.txt`

Run tests
Expand Down
3 changes: 1 addition & 2 deletions tests/test_linux/pr2test/context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import itertools
import logging
import os
import sys
import uuid
from collections import namedtuple
from socket import AF_INET, AF_INET6
Expand Down Expand Up @@ -313,7 +312,7 @@ def teardown(self):
2. remove the registered interfaces, ignore not existing
'''
# save postmortem DB for SQLite3
if self.db_provider == 'sqlite3' and sys.version_info >= (3, 7):
if self.db_provider == 'sqlite3':
self.ndb.backup(f'{self.spec.uid}-post.db')
self.ndb.close()
self.ipr.close()
Expand Down
10 changes: 0 additions & 10 deletions tests/test_linux/test_dquot/test_dquot.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import os
import subprocess
import sys

import pytest
from pr2test.marks import require_root

from pyroute2 import DQuotSocket

pytestmark = [
pytest.mark.skipif(
sys.version_info < (3, 7),
reason='the test module requires Python > 3.6',
),
require_root(),
]


class DQuotContextManager:
def __init__(self):
Expand Down
7 changes: 0 additions & 7 deletions tests/test_linux/test_ndb/test_backup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import sqlite3
import sys
import uuid

import pytest


@pytest.mark.skipif(
sys.version_info < (3, 7),
reason='SQLite3 backup not supported on this Python version',
)
def test_file_backup(context):
filename = str(uuid.uuid4()) + '-backup.db'
context.ndb.backup(filename)
Expand Down
7 changes: 0 additions & 7 deletions tests/test_repo/test_noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import collections
import inspect
import os
import sys

import nox
import pytest
Expand All @@ -24,9 +23,6 @@ def session(request):
)


@pytest.mark.skipif(
sys.version_info < (3, 8), reason='unsupported Python version'
)
@pytest.mark.parametrize('session', nox_sessions, indirect=True)
def test_options_call(session):
# walk the AST tree
Expand All @@ -53,9 +49,6 @@ def test_session_parameters(session):
assert args == ['session']


@pytest.mark.skipif(
sys.version_info < (3, 8), reason='unsupported Python version'
)
@pytest.mark.parametrize('session', nox_sessions, indirect=True)
def test_requirements_files(session):
for node in ast.walk(ast.parse(inspect.getsource(session.src_func))):
Expand Down
6 changes: 0 additions & 6 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import re
import stat
import subprocess
import sys
import uuid
from socket import AF_INET, AF_INET6

Expand Down Expand Up @@ -105,11 +104,6 @@ def require_kernel(major, minor=None):
pytest.skip('incompatible kernel version')


def require_python(target):
if sys.version_info[0] != target:
pytest.skip('test requires Python %i' % target)


def require_8021q():
try:
os.stat('/proc/net/vlan/config')
Expand Down

0 comments on commit bd83d51

Please sign in to comment.