Skip to content

Commit

Permalink
avoid try/except to handle versions
Browse files Browse the repository at this point in the history
  • Loading branch information
doudz committed Feb 20, 2020
1 parent eb3a954 commit e878bfa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ docs/_build/*
/build_upload.sh
/build.sh
/.settings/
.history
12 changes: 8 additions & 4 deletions rpc4django/rpcdispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,34 @@
It also contains a decorator to mark methods as rpc methods.
'''

import sys
import inspect
import pydoc
import django
from django.contrib.auth import authenticate, login, logout
from .jsonrpcdispatcher import JSONRPCDispatcher, json
from .xmlrpcdispatcher import XMLRPCDispatcher
from django.conf import settings

try:
from importlib import import_module
except ImportError:
from django.utils.importlib import import_module

try:
if django.VERSION[0] == 1:
# Django 1.x
from django.core.urlresolvers import get_mod_func
except ImportError:
else:
# Django 2.x
from django.urls import get_mod_func

try:
if sys.version_info.major == 2:
# Python2.x
from xmlrpclib import Fault
except ImportError:
else:
# Python3
from xmlrpc.client import Fault


from defusedxml import xmlrpc

Expand Down
6 changes: 4 additions & 2 deletions rpc4django/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
try:
import sys

if sys.version_info.major == 2:
# Python2
from httplib import HTTPConnection
from xmlrpclib import SafeTransport, Transport, ProtocolError
except ImportError:
else:
# Python3
from http.client import HTTPConnection
from xmlrpc.client import SafeTransport, Transport, ProtocolError
Expand Down
2 changes: 1 addition & 1 deletion rpc4django/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
_MAJOR = 0
_MINOR = 6
_PATCH = 2
_PATCH = 3

__version__ = str(_MAJOR) + '.' + str(_MINOR) + '.' + str(_PATCH)

Expand Down

0 comments on commit e878bfa

Please sign in to comment.