Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
fail-fast: false
matrix:
tox_env: [py27, py36, py37, py38, py39, py310, pypy2, pypy3, pep8]
tox_env: [py39, py310, py311, py312, py313, pypy3, pep8]

# Use GitHub's Linux Docker host
runs-on: ubuntu-latest
8 changes: 3 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
[build-system]
requires = [
"setuptools >= 44; python_version < '3'",
"setuptools >= 48; python_version > '3'",
"setuptools_scm >= 4, <6; python_version < '3'",
"setuptools_scm[toml]; python_version > '3'",
"setuptools >= 48",
"setuptools_scm[toml]",
"setuptools_scm_git_archive",
"wheel >= 0.29.0",
]
build-backend = 'setuptools.build_meta'

[tool.setuptools_scm]
local_scheme = "no-local-version"
local_scheme = "no-local-version"
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

15 changes: 7 additions & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@ classifiers =
Intended Audience :: Developers
License :: OSI Approved :: Apache Software License
Programming Language :: Python
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3.13
Topic :: System :: Networking

[options]
zip_safe = False
python_requires=>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
python_requires=>=3.9
include_package_data = True
packages = varlink
setup_requires =
setuptools_scm < 6 ; python_version < "3"
setuptools_scm ; python_version >= "3"
setuptools_scm

[options.package_data]
varlink = *.varlink
Expand Down
3 changes: 1 addition & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
future
fixtures
nose2
nose2
14 changes: 1 addition & 13 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# and then run "tox" from this directory.

[tox]
envlist = py310,py39,py38,py37,py36,py27,pep8,pypy2,pypy3
envlist = py313,py312,py311,py310,py39,pep8,pypy3

[testenv]
usedevelop = True
Expand All @@ -15,18 +15,6 @@ setenv =
CLIENT_NAME=varlink
deps =
-r{toxinidir}/test-requirements.txt
-r{toxinidir}/requirements.txt
commands =
nose2 \
--coverage varlink

[testenv:py27]
commands =
python -m unittest varlink

[testenv:pypy2]
commands =
python -m unittest varlink

[travis]
python = 3.7: py37
8 changes: 3 additions & 5 deletions varlink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
__all__ = ['Client', 'ClientInterfaceHandler', 'SimpleClientInterfaceHandler',
'Service', 'RequestHandler', 'Server', 'ThreadingServer', 'ForkingServer',
'InterfaceNotFound', 'MethodNotFound', 'MethodNotImplemented', 'InvalidParameter',
'ConnectionError', 'VarlinkEncoder', 'VarlinkError',
'VarlinkEncoder', 'VarlinkError',
'Interface', 'Scanner', 'get_listen_fd']
from .server import ForkingServer
else:
__all__ = ['Client', 'ClientInterfaceHandler', 'SimpleClientInterfaceHandler',
'Service', 'RequestHandler', 'Server', 'ThreadingServer',
'InterfaceNotFound', 'MethodNotFound', 'MethodNotImplemented', 'InvalidParameter',
'ConnectionError', 'VarlinkEncoder', 'VarlinkError',
'VarlinkEncoder', 'VarlinkError',
'Interface', 'Scanner', 'get_listen_fd']

from .client import (Client, ClientInterfaceHandler, SimpleClientInterfaceHandler)
from .error import (VarlinkEncoder, VarlinkError, InvalidParameter, InterfaceNotFound, MethodNotImplemented,
MethodNotFound, ConnectionError, BrokenPipeError)
MethodNotFound)
from .scanner import (Scanner, Interface)
from .server import (Service, get_listen_fd, Server, ThreadingServer, RequestHandler)

Expand All @@ -51,8 +51,6 @@ def load_tests(loader, tests, pattern):
test_dir = os.path.dirname(__file__) + "/tests"
for fn in os.listdir(test_dir):
if fnmatch(fn, pattern):
if sys.version_info[0] == 2 and fn == "test_mocks.py":
continue
modname = "varlink.tests." + fn[:-3]
__import__(modname)
module = sys.modules[modname]
Expand Down
5 changes: 1 addition & 4 deletions varlink/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

"""

from __future__ import print_function
from __future__ import unicode_literals

import argparse
import json
import shlex
Expand Down Expand Up @@ -60,7 +57,7 @@ def new_client(address):
got = True
except varlink.VarlinkError as e:
print(e, file=sys.stderr)
except varlink.BrokenPipeError:
except BrokenPipeError:
if not got or args.more:
print("Connection closed")
sys.exit(1)
Expand Down
33 changes: 4 additions & 29 deletions varlink/client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# coding=utf-8

from __future__ import print_function
from __future__ import unicode_literals

import json
import os
import shutil
Expand All @@ -13,30 +10,11 @@
import subprocess
import threading

try:
from builtins import next
from builtins import object
from builtins import open
from builtins import str
except ImportError:
pass

from .error import (VarlinkError, InterfaceNotFound, VarlinkEncoder, BrokenPipeError)
from .error import (VarlinkError, InterfaceNotFound, VarlinkEncoder)
from .scanner import (Interface, _Method)

PY2 = sys.version_info[0] == 2
PY3 = (sys.version_info[0] >= 3)

if PY2:
FileNotFoundError = IOError
ChildProcessError = OSError


class ConnectionError(OSError):
pass


class ClientInterfaceHandler(object):
class ClientInterfaceHandler:
"""Base class for varlink client, which wraps varlink methods of an interface to the class"""

def __init__(self, interface, namespaced=False):
Expand Down Expand Up @@ -88,10 +66,7 @@ def _wrapped(*args, **kwargs):
else:
return self._call(method.name, *args, **kwargs)

if sys.version_info.major >= 3:
_wrapped.__name__ = method.name
else:
_wrapped.__name__ = method.name.encode("latin-1")
_wrapped.__name__ = method.name

# FIXME: add comments
if method.signature:
Expand Down Expand Up @@ -306,7 +281,7 @@ def pipe_bridge(reader, writer):
return


class Client(object):
class Client:
"""Varlink client class.

>>> with varlink.Client("unix:/run/org.example.ping") as client, client.open('org.example.ping') as connection:
Expand Down
18 changes: 1 addition & 17 deletions varlink/error.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
from __future__ import print_function
from __future__ import unicode_literals

import json

try:
from types import SimpleNamespace

ConnectionError = ConnectionError
BrokenPipeError = BrokenPipeError
except: # Python 2
from argparse import Namespace as SimpleNamespace


class ConnectionError(OSError):
pass


class BrokenPipeError(ConnectionError):
pass
from types import SimpleNamespace


class VarlinkEncoder(json.JSONEncoder):
Expand Down
4 changes: 0 additions & 4 deletions varlink/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
import varlink


if sys.version_info[0] == 2:
raise ImportError("The mock module isn't compatible with python 2")


def cast_type(typeof):
cast = {'str': 'string'}
typeof = str(typeof).replace("<class '", "").replace("'>", "")
Expand Down
54 changes: 16 additions & 38 deletions varlink/scanner.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,16 @@
#!-*-coding:utf8-*-
from __future__ import print_function
from __future__ import unicode_literals

try:
from builtins import str
from builtins import int
from builtins import object
from builtins import unicode
except ImportError:
pass

import re

try:
basestring
except NameError:
basestring = str

try:
from types import SimpleNamespace
except: # Python 2
from argparse import Namespace as SimpleNamespace

try:
from collections.abc import (Set, Mapping)
except: # Python 2
from collections import (Set, Mapping)
from types import SimpleNamespace
from collections.abc import (Set, Mapping)

from collections import OrderedDict

from .error import (MethodNotFound, InvalidParameter)


class Scanner(object):
class Scanner:
"""Class for scanning a varlink interface definition."""

def __init__(self, string):
Expand Down Expand Up @@ -217,55 +195,55 @@ def read_member(self):
raise SyntaxError('expected type, method, or error')


class _Object(object):
class _Object:
pass


class _Struct(object):
class _Struct:

def __init__(self, fields):
self.fields = OrderedDict(fields)


class _Enum(object):
class _Enum:

def __init__(self, fields):
self.fields = fields


class _Array(object):
class _Array:

def __init__(self, element_type):
self.element_type = element_type


class _Maybe(object):
class _Maybe:

def __init__(self, element_type):
self.element_type = element_type


class _Dict(object):
class _Dict:

def __init__(self, element_type):
self.element_type = element_type


class _CustomType(object):
class _CustomType:

def __init__(self, name):
self.name = name


class _Alias(object):
class _Alias:

def __init__(self, name, varlink_type, doc=None):
self.name = name
self.type = varlink_type
self.doc = doc


class _Method(object):
class _Method:

def __init__(self, name, in_type, out_type, _signature, doc=None):
self.name = name
Expand All @@ -275,15 +253,15 @@ def __init__(self, name, in_type, out_type, _signature, doc=None):
self.doc = doc


class _Error(object):
class _Error:

def __init__(self, name, varlink_type, doc=None):
self.name = name
self.type = varlink_type
self.doc = doc


class Interface(object):
class Interface:
"""Class for a parsed varlink interface definition."""

def __init__(self, description):
Expand Down Expand Up @@ -341,7 +319,7 @@ def filter_params(self, parent_name, varlink_type, _namespaced, args, kwargs):
if isinstance(varlink_type, _Object):
return args

if isinstance(varlink_type, _Enum) and ( isinstance(args, str) or isinstance(args, unicode) ):
if isinstance(varlink_type, _Enum) and isinstance(args, str):
# print("Returned str:", args)
return args

Expand All @@ -356,7 +334,7 @@ def filter_params(self, parent_name, varlink_type, _namespaced, args, kwargs):
# print("Returned set:", set(args))
return set(args)

if isinstance(varlink_type, basestring) and isinstance(args, basestring):
if isinstance(varlink_type, str) and isinstance(args, str):
return args

if isinstance(varlink_type, float) and (isinstance(args, float) or isinstance(args, int)):
Expand Down
Loading