Skip to content

Commit

Permalink
Merge pull request #1412 from garberg/pynipap_as_a_package
Browse files Browse the repository at this point in the history
pynipap as a package
  • Loading branch information
garberg authored Jan 9, 2025
2 parents f2c7af7 + 0e5d6da commit d47c5f6
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 31 deletions.
3 changes: 1 addition & 2 deletions nipap-cli/nipap
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import socket
import nipap_cli
import nipap_cli.nipap_cli
from nipap_cli.command import Command, CommandError
from pynipap import NipapError
import tracing
from pynipap import NipapError, tracing

# early close of stdout to avoid broken pipe, see #464
# If our output is being piped and the receiver of the pipe is killed off before
Expand Down
2 changes: 1 addition & 1 deletion pynipap/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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.
Expand Down Expand Up @@ -261,8 +241,6 @@ class XMLRPCConnection:
""" Handles a shared XML-RPC connection.
"""

__shared_state = {}

connection = None
_logger = None

Expand All @@ -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":
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pynipap/tracing.py → pynipap/pynipap/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def decorated(*args, **kwargs):
"""
"""

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

if args[0].__class__ == type:
Expand Down
5 changes: 2 additions & 3 deletions pynipap/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 d47c5f6

Please sign in to comment.