Skip to content

Commit

Permalink
pynipap: Move to Python package
Browse files Browse the repository at this point in the history
Mainly to avoid cluttering the global namespace with the name "tracing",
moved the pynipap module to its own package.

The intention is that the package should be fully compatible with the
stans-alone module and require no changes to the applications using it.
garberg committed Jan 9, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent e363e73 commit f9e4ec5
Showing 5 changed files with 39 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pynipap/Makefile
Original file line number Diff line number Diff line change
@@ -49,6 +49,6 @@ clean:
VER := $(shell head -n1 ../NEWS | awk '{print $$2}')
bumpversion:
# replace version number in pynipap.py
sed -i 's/\(__version__\s*= \)"[^"]\+"/\1"$(VER)"/' pynipap.py
sed -i 's/\(__version__\s*= \)"[^"]\+"/\1"$(VER)"/' pynipap/__init__.py
# # update debian/changelog
../utilities/news2dch.py ../NEWS debian/changelog
23 changes: 23 additions & 0 deletions pynipap/pynipap/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from .pynipap import *

__version__ = "0.32.5"
__author__ = "Kristian Larsson, Lukas Garberg"
__author_email__= "[email protected], [email protected]"
__copyright__ = "Copyright 2011, Kristian Larsson, Lukas Garberg"
__license__ = "MIT"
__status__ = "Development"
__url__ = "http://SpriteLink.github.io/NIPAP"


# This variable holds the URI to the nipap XML-RPC service which will be used.
# It must be set before the Pynipap can be used!
xmlrpc_uri = None

# If set, the value assigned to the variable below will be used as a bearer
# token.
bearer_token = None

# Caching of objects is enabled per default but can be disabled for certain
# scenarios. Since we don't have any cache expiration time it can be useful to
# disable for long running applications.
CACHE = True
36 changes: 12 additions & 24 deletions pynipap/pynipap.py → pynipap/pynipap/pynipap.py
Original file line number Diff line number Diff line change
@@ -209,27 +209,7 @@
import xmlrpc.client as xmlrpclib
import urllib.parse

from tracing import create_span

__version__ = "0.32.5"
__author__ = "Kristian Larsson, Lukas Garberg"
__author_email__= "[email protected], [email protected]"
__copyright__ = "Copyright 2011, Kristian Larsson, Lukas Garberg"
__license__ = "MIT"
__status__ = "Development"
__url__ = "http://SpriteLink.github.io/NIPAP"


# This variable holds the URI to the nipap XML-RPC service which will be used.
# It must be set before the Pynipap can be used!
xmlrpc_uri = None
bearer_token = None

# Caching of objects is enabled per default but can be disabled for certain
# scenarios. Since we don't have any cache expiration time it can be useful to
# disable for long running applications.
CACHE = True

from .tracing import create_span
class AuthOptions:
""" A global-ish authentication option container.
@@ -261,8 +241,6 @@ class XMLRPCConnection:
""" Handles a shared XML-RPC connection.
"""

__shared_state = {}

connection = None
_logger = None

@@ -275,13 +253,19 @@ def __init__(self):
variable is set.
"""

# This is not a pretty solution, but needed to maintain backwards
# compatibility and avoiding circular imports.
from . import xmlrpc_uri, bearer_token, CACHE as cache_enabled
global CACHE
CACHE = cache_enabled

if xmlrpc_uri is None:
raise NipapError('XML-RPC URI not specified')

p = urllib.parse.urlsplit(xmlrpc_uri)

try:
from tracing import TracingXMLTransport, TracingXMLSafeTransport
from .tracing import TracingXMLTransport, TracingXMLSafeTransport
if p.scheme == "http":
xml_transport = TracingXMLTransport
elif p.scheme == "https":
@@ -1521,6 +1505,10 @@ class NipapAuthorizationError(NipapAuthError):
'VRF': {}
}

# Will be overwritten by import from . when setting up XML-RPC-connection, but
# needs to be defined here if it's read before the connections is set up.
CACHE = False

# Map from XML-RPC Fault codes to Exception classes
_fault_to_exception_map = {
1000: NipapError,
2 changes: 1 addition & 1 deletion pynipap/tracing.py → pynipap/pynipap/tracing.py
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ def decorated(*args, **kwargs):
"""
"""

from pynipap import AuthOptions
from . import AuthOptions
signature = inspect.signature(f)

if args[0].__class__ == type:
5 changes: 2 additions & 3 deletions pynipap/setup.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
author_email = pynipap.__author_email__,
license = pynipap.__license__,
url = pynipap.__url__,
py_modules = ['pynipap','tracing'],
packages = ['pynipap'],
keywords = ['nipap'],
classifiers = [
'Development Status :: 4 - Beta',
@@ -26,7 +26,6 @@
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3',
'Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware'
'Programming Language :: Python :: 3'
]
)

0 comments on commit f9e4ec5

Please sign in to comment.