Skip to content

Commit

Permalink
Updated to Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
jinxo13 committed May 18, 2020
1 parent 535a64a commit cb44999
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 4,431 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.pyc
.vscode
.env
.env
*.log
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Huawei B525 Router Python API
Python2 code to interact with the underlying API for the Huawei B525 router (tested on model B525s-65a).
Python3 code to interact with the underlying API for the Huawei B525 router (tested on model B525s-65a).
This implements a proxy for the API calls with some additional features.
The API responses are in XML.
Any errors in the API calls are also returned in XML.
Expand Down
4 changes: 2 additions & 2 deletions huawei_lte/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '1.1.0'
__releasedate__ = '20200412'
__version__ = '2.0.0'
__releasedate__ = '20200518'
8 changes: 4 additions & 4 deletions huawei_lte/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_client_proof(clientnonce, servernonce, password, salt, iterations):
""" calculates server client proof (part of the SCRAM algorithm) """
msg = "%s,%s,%s" % (clientnonce, servernonce, servernonce)
salted_pass = hashlib.pbkdf2_hmac(
'sha256', password, bytearray.fromhex(salt), iterations)
'sha256', password.encode('utf_8'), bytearray.fromhex(salt), iterations)
client_key = hmac.new(b'Client Key', msg=salted_pass,
digestmod=hashlib.sha256)
stored_key = hashlib.sha256()
Expand All @@ -27,14 +27,14 @@ def get_client_proof(clientnonce, servernonce, password, salt, iterations):
client_proof = bytearray()
i = 0
while i < client_key.digest_size:
client_proof.append(ord(client_key_digest[i]) ^ ord(signature_digest[i]))
client_proof.append(client_key_digest[i] ^ signature_digest[i])
i = i + 1
return hexlify(client_proof)

def rsa_encrypt(rsae, rsan, data):
if (data is None or data == ''): return ''
N = long(rsan,16)
E = long(rsae,16)
N = int(rsan,16)
E = int(rsae,16)
b64data = base64.b64encode(data)
pubkey = construct((N, E))
cipher = PKCS1_v1_5.new(pubkey)
Expand Down
2 changes: 1 addition & 1 deletion huawei_lte/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import xmlobjects as xmlobjects
import huawei_lte.xmlobjects as xmlobjects

class RouterError(Exception):

Expand Down
10 changes: 5 additions & 5 deletions huawei_lte/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def decorated_function(*args):
return inst.router.api(api)
return inst.api(api)
except ValueError as err:
return xmlobjects.Error.xml_error(f.__name__, escape(err.message))
return xmlobjects.Error.xml_error(f.__name__, escape(str(err)))
except:
logger.exception('message')
msg = 'Unexpected error: %s' % sys.exc_info()[0]
Expand All @@ -45,7 +45,7 @@ def decorated_function(*args, **kwargs):
try:
return f(*args, **kwargs)
except ValueError as err:
return xmlobjects.Error.xml_error(f.__name__, escape(err.message))
return xmlobjects.Error.xml_error(f.__name__, escape(str(err)))
except:
logger.exception('message')
msg = 'Unexpected error: %s' % sys.exc_info()[0]
Expand Down Expand Up @@ -306,10 +306,10 @@ def connection(self):
state = xmlobjects.CustomXml({'connectionmode': 0, 'connectstatus': 0})
state.parseXML(self.status)

connection_mode = self.CONNECTION_MODE[int(state.connectionmode)]
connection_mode = self.CONNECTION_MODE[int(state.getValue('connectionmode'))]
connection_status = 'Unknown'
if int(state.connectstatus) in self.CONNECTION_STATUS.keys():
connection_status = self.CONNECTION_STATUS[int(state.connectstatus)]
if int(state.getValue('connectstatus')) in self.CONNECTION_STATUS.keys():
connection_status = self.CONNECTION_STATUS[int(state.getValue('connectstatus'))]
xml = xmlobjects.CustomXml({
'ConnectionStatus': connection_status,
'ConnectionMode': connection_mode
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_version():
license='BSD',
packages=find_packages(),
install_requires=[
'huawei_lte>=1.0.0',
'huawei_lte>=2.0.0',
'pycrypto>=2.6.1',
'IPy>=1.0.0'
],
Expand All @@ -40,9 +40,9 @@ def get_version():
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Topic :: Software Development :: Libraries :: Python Modules',
'Natural Language :: English',
],
Expand Down
Loading

0 comments on commit cb44999

Please sign in to comment.