Skip to content

Commit

Permalink
Drop support of Python<3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
acutaia committed Jan 9, 2020
1 parent 34eaac8 commit d499288
Show file tree
Hide file tree
Showing 185 changed files with 487 additions and 1,150 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ zeroconf = "==0.19"
[dev-packages]

[requires]
python_version = "3.6"
python_version = ">=3.7"
2 changes: 1 addition & 1 deletion pelix/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -- Content-Encoding: UTF-8 --
"""
Constants and exceptions for Pelix.
Expand Down
55 changes: 16 additions & 39 deletions pelix/framework.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -- Content-Encoding: UTF-8 --
"""
Core module for Pelix.
Expand Down Expand Up @@ -36,14 +36,9 @@
import sys
import threading
import uuid

# Standard typing module should be optional
try:
# pylint: disable=W0611
from typing import Any, List, Optional, Set, Union
import types
except ImportError:
pass
# pylint: disable=W0611
from typing import Any, List, Optional, Set, Union
import types

# Pelix beans and constants
from pelix.constants import (
Expand All @@ -64,38 +59,20 @@
ServiceRegistration,
)

# Pelix utility modules
from pelix.utilities import is_string


if hasattr(importlib, "reload"):
# This method has been added in Python 3.4 and deprecates imp.reload()
def reload_module(module_):
"""
Reloads a module using ``importlib.reload()`` when available

:param module_: The module to update
:return: The new version of the module
:raise ImportError: Error looking for file
:raise SyntaxError: Syntax error in imported module
"""
return importlib.reload(module_)

def reload_module(module_):
"""
Reloads a module using ``importlib.reload()`` when available
else:
# Before Python 3.4
import imp
:param module_: The module to update
:return: The new version of the module
:raise ImportError: Error looking for file
:raise SyntaxError: Syntax error in imported module
"""
return importlib.reload(module_)

def reload_module(module_):
"""
Reloads a module using ``imp.reload()`` as fallback

:param module_: The module to update
:return: The new version of the module
:raise ImportError: Error looking for file
:raise SyntaxError: Syntax error in imported module
"""
return imp.reload(module_)


def walk_modules(path):
Expand Down Expand Up @@ -955,7 +932,7 @@ def install_package(self, path, recursive=False, prefix=None):
"""
if not path:
raise ValueError("Empty path")
elif not is_string(path):
elif not isinstance(path, str):
raise ValueError("Path must be a string")

# Use an absolute path
Expand Down Expand Up @@ -1020,7 +997,7 @@ def install_visiting(self, path, visitor, prefix=None):
# Validate the path
if not path:
raise ValueError("Empty path")
elif not is_string(path):
elif not isinstance(path, str):
raise ValueError("Path must be a string")

# Validate the visitor
Expand Down Expand Up @@ -1121,7 +1098,7 @@ def register_service(
# Keep the type name
svc_clazz = svc_clazz.__name__

if not svc_clazz or not is_string(svc_clazz):
if not svc_clazz or not isinstance(svc_clazz, str):
# Invalid class name
raise BundleException(
"Invalid class name: {0}".format(svc_clazz)
Expand Down
21 changes: 7 additions & 14 deletions pelix/http/basic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -- Content-Encoding: UTF-8 --
"""
Pelix basic HTTP service bundle.
Expand Down Expand Up @@ -35,18 +35,11 @@
import traceback

# Basic HTTP server
try:
# Python 3
# pylint: disable=F0401,E0611
from http.server import HTTPServer
from http.server import BaseHTTPRequestHandler
from socketserver import ThreadingMixIn, TCPServer
except ImportError:
# Python 2 or IronPython
# pylint: disable=F0401
from BaseHTTPServer import HTTPServer
from BaseHTTPServer import BaseHTTPRequestHandler
from SocketServer import ThreadingMixIn, TCPServer
# pylint: disable=F0401,E0611
from http.server import HTTPServer
from http.server import BaseHTTPRequestHandler
from socketserver import ThreadingMixIn, TCPServer


# iPOPO
from pelix.ipopo.decorators import (
Expand Down Expand Up @@ -560,7 +553,7 @@ def __register_servlet_service(self, service, service_reference):
"""
# Servlet bound
paths = service_reference.get_property(http.HTTP_SERVLET_PATH)
if utilities.is_string(paths):
if isinstance(paths, str):
# Register the servlet to a single path
self.register_servlet(paths, service)
elif isinstance(paths, (list, tuple)):
Expand Down
19 changes: 7 additions & 12 deletions pelix/http/routing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -- Content-Encoding: UTF-8 --
"""
Provides utility classes to develop REST-like API and to simplify the routing
Expand Down Expand Up @@ -30,17 +30,12 @@
import inspect
import re
import uuid

# Standard typing module should be optional
try:
# pylint: disable=W0611
from typing import Any, Callable, Dict, Pattern, Tuple
from pelix.http import (
AbstractHTTPServletRequest,
AbstractHTTPServletResponse,
)
except ImportError:
pass
# pylint: disable=W0611
from typing import Any, Callable, Dict, Pattern, Tuple
from pelix.http import (
AbstractHTTPServletRequest,
AbstractHTTPServletResponse,
)

# Pelix utility methods
from pelix.utilities import get_method_arguments
Expand Down
2 changes: 1 addition & 1 deletion pelix/internals/events.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -- Content-Encoding: UTF-8 --
"""
Event beans for Pelix.
Expand Down
2 changes: 1 addition & 1 deletion pelix/internals/hooks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -- Content-Encoding: UTF-8 --
"""
EventListenerHook for Pelix.
Expand Down
14 changes: 4 additions & 10 deletions pelix/internals/registry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -- Content-Encoding: UTF-8 --
"""
Service registry and event dispatcher for Pelix.
Expand Down Expand Up @@ -29,13 +29,8 @@
import bisect
import logging
import threading

# Standard typing module should be optional
try:
# pylint: disable=W0611
from typing import Any, Dict, List, Optional, Set, Tuple, Union
except ImportError:
pass
# pylint: disable=W0611
from typing import Any, Dict, List, Optional, Set, Tuple, Union

# Pelix beans
from pelix.constants import (
Expand All @@ -53,7 +48,6 @@
from pelix.internals.events import ServiceEvent

# Pelix utility modules
from pelix.utilities import is_string
import pelix.ldapfilter as ldapfilter

# Event hooks
Expand Down Expand Up @@ -1224,7 +1218,7 @@ def find_service_references(
if hasattr(clazz, "__name__"):
# Escape the type name
clazz = ldapfilter.escape_LDAP(clazz.__name__)
elif is_string(clazz):
elif isinstance(clazz, str):
# Escape the class name
clazz = ldapfilter.escape_LDAP(clazz)

Expand Down
16 changes: 5 additions & 11 deletions pelix/ipopo/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -- Content-Encoding: UTF-8 --
"""
Defines some iPOPO constants
Expand Down Expand Up @@ -27,17 +27,11 @@

# Standard library
import contextlib
# pylint: disable=W0611
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple

# Standard typing module should be optional
try:
# pylint: disable=W0611
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple

# Pelix
from pelix.framework import BundleContext, ServiceReference
except ImportError:
pass

# Pelix
from pelix.framework import BundleContext, ServiceReference
from pelix.framework import BundleException

# ------------------------------------------------------------------------------
Expand Down
17 changes: 6 additions & 11 deletions pelix/ipopo/contexts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -- Content-Encoding: UTF-8 --
"""
Definition of Factory and Component context classes
Expand All @@ -25,17 +25,12 @@
limitations under the License.
"""

# Standard typing module should be optional
try:
# pylint: disable=W0611
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple
from pelix.framework import BundleContext
except ImportError:
pass
# pylint: disable=W0611
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple
from pelix.framework import BundleContext

# Pelix utilities
from pelix.constants import OBJECTCLASS
from pelix.utilities import is_string
import pelix.ldapfilter as ldapfilter

# iPOPO constants
Expand Down Expand Up @@ -90,7 +85,7 @@ def __init__(
:raise TypeError: A parameter has an invalid type
:raise ValueError: An error occurred while parsing the filter
"""
if not is_string(specification):
if not isinstance(specification, str):
raise TypeError("A Requirement specification must be a string")

if not specification:
Expand Down Expand Up @@ -200,7 +195,7 @@ def set_filter(self, props_filter):
:raise TypeError: Unknown filter type
"""
if props_filter is not None and not (
is_string(props_filter)
isinstance(props_filter, str)
or isinstance(
props_filter, (ldapfilter.LDAPFilter, ldapfilter.LDAPCriteria)
)
Expand Down
24 changes: 10 additions & 14 deletions pelix/ipopo/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -- Content-Encoding: UTF-8 --
"""
Core iPOPO implementation
Expand Down Expand Up @@ -31,20 +31,16 @@
import logging
import sys
import threading
# pylint: disable=W0611
from typing import Any, Dict, List, Optional, Set, Tuple
from pelix.framework import BundleContext, ServiceReference

# Standard typing module should be optional
try:
# pylint: disable=W0611
from typing import Any, Dict, List, Optional, Set, Tuple
from pelix.framework import BundleContext, ServiceReference
except ImportError:
pass

# Pelix
from pelix.constants import SERVICE_ID, BundleActivator
from pelix.framework import Bundle, BundleException
from pelix.internals.events import BundleEvent, ServiceEvent
from pelix.utilities import add_listener, remove_listener, is_string
from pelix.utilities import add_listener, remove_listener

# iPOPO constants
import pelix.ipopo.constants as constants
Expand Down Expand Up @@ -570,7 +566,7 @@ def _register_factory(self, factory_name, factory, override):
:raise ValueError: The factory name already exists or is invalid
:raise TypeError: Invalid factory type
"""
if not factory_name or not is_string(factory_name):
if not factory_name or not isinstance(factory_name, str):
raise ValueError("A factory name must be a non-empty string")

if not inspect.isclass(factory):
Expand Down Expand Up @@ -720,10 +716,10 @@ def instantiate(self, factory_name, name, properties=None):
:raise Exception: Something wrong occurred in the factory
"""
# Test parameters
if not factory_name or not is_string(factory_name):
if not factory_name or not isinstance(factory_name, str):
raise ValueError("Invalid factory name")

if not name or not is_string(name):
if not name or not isinstance(name, str):
raise ValueError("Invalid component name")

if not self.running:
Expand Down Expand Up @@ -919,7 +915,7 @@ def unregister_factory(self, factory_name):
:return: True the factory has been removed, False if the factory is
unknown
"""
if not factory_name or not is_string(factory_name):
if not factory_name or not isinstance(factory_name, str):
# Invalid name
return False

Expand Down Expand Up @@ -1070,7 +1066,7 @@ def get_instance_details(self, name):
:return: A dictionary of details
:raise ValueError: Invalid component name
"""
if not is_string(name):
if not isinstance(name, str):
raise ValueError("Component name must be a string")

with self.__instances_lock:
Expand Down
Loading

0 comments on commit d499288

Please sign in to comment.