Compare commits

..

No commits in common. "f62579ce908f3baf97cddeac2918ca794c341fa6" and "72f148f7b9072a55f57c0e7b9b3b67ab6f661990" have entirely different histories.

6 changed files with 2 additions and 227 deletions

View File

@ -28,14 +28,6 @@ mitel\_ommclient2.connection module
:undoc-members: :undoc-members:
:show-inheritance: :show-inheritance:
mitel\_ommclient2.exceptions module
-----------------------------------
.. automodule:: mitel_ommclient2.exceptions
:members:
:undoc-members:
:show-inheritance:
mitel\_ommclient2.session module mitel\_ommclient2.session module
-------------------------------- --------------------------------

View File

@ -37,18 +37,6 @@ class OMMClient2:
else: else:
self.session = session self.session = session
def get_account(self, id):
"""
Get account
:param id: User id
"""
r = self.session.request(message.GetAccount(id))
r.raise_on_error()
return r.account[0]
def ping(self): def ping(self):
""" """
Is OMM still there? Is OMM still there?

View File

@ -1,156 +0,0 @@
#!/usr/bin/env python3
exception_classes = {}
def _collect_exception_class(c):
"""
Decorator that collects exception classes for parsing error codes.
"""
exception_classes[c.__name__] = c
return c
class OMResponseException(Exception):
def __init__(self, response, msg=None):
self.response = response
if msg is None:
msg = self.response.info
super().__init__(msg)
@_collect_exception_class
class EAreaFull(OMResponseException):
pass
@_collect_exception_class
class EAuth(OMResponseException):
pass
@_collect_exception_class
class EDectRegDomainInvalid(OMResponseException):
pass
@_collect_exception_class
class EEncryptNotAllowed(OMResponseException):
pass
@_collect_exception_class
class EExist(OMResponseException):
pass
@_collect_exception_class
class EFailed(OMResponseException):
pass
@_collect_exception_class
class EForbidden(OMResponseException):
pass
@_collect_exception_class
class EInProgress(OMResponseException):
pass
@_collect_exception_class
class EInval(OMResponseException):
def __init__(self, response):
super().__init__(response, response.bad)
@_collect_exception_class
class EInvalidChars(OMResponseException):
pass
@_collect_exception_class
class ELicense(OMResponseException):
pass
@_collect_exception_class
class ELicenseFile(OMResponseException):
pass
@_collect_exception_class
class ELicenseWrongInstallId(OMResponseException):
pass
@_collect_exception_class
class EMissing(OMResponseException):
def __init__(self, response):
super().__init__(response, response.bad)
@_collect_exception_class
class ENoEnt(OMResponseException):
pass
@_collect_exception_class
class ENoMem(OMResponseException):
pass
@_collect_exception_class
class EPerm(OMResponseException):
pass
@_collect_exception_class
class EPwEmpty(OMResponseException):
pass
@_collect_exception_class
class EPwSimilarToHost(OMResponseException):
pass
@_collect_exception_class
class EPwSimilarToName(OMResponseException):
pass
@_collect_exception_class
class EPwTooManySimilarChars(OMResponseException):
pass
@_collect_exception_class
class EPwTooShort(OMResponseException):
pass
@_collect_exception_class
class EPwTooSimilar(OMResponseException):
pass
@_collect_exception_class
class EPwTooWeak(OMResponseException):
pass
@_collect_exception_class
class EPwUnchanged(OMResponseException):
pass
@_collect_exception_class
class ETooLong(OMResponseException):
def __init__(self, response):
super().__init__(response, response.bad + ", maximum of " + str(response.maxLen))
@_collect_exception_class
class EWlanRegDomainInvalid(OMResponseException):
pass

View File

@ -2,8 +2,6 @@
from xml.dom.minidom import getDOMImplementation, parseString from xml.dom.minidom import getDOMImplementation, parseString
from ..exceptions import exception_classes, OMResponseException
class Request: class Request:
""" """
@ -60,23 +58,6 @@ class Response:
self.attrs = attrs self.attrs = attrs
self.childs = childs self.childs = childs
def raise_on_error(self):
"""
Raises an exception if the response contains an error.
Usage::
>>> try:
>>> r.raise_on_error()
>>> except mitel_ommclient2.exceptions.EAuth as e:
>>> print("We don't care about authentication!")
See children of :class:`mitel_ommclient2.exceptions.OMResponseException` for all possible exceptions.
"""
if self.errCode is not None:
raise exception_classes.get(self.errCode, OMResponseException)()
@property @property
def seq(self): def seq(self):
return self.attrs.get("seq") return self.attrs.get("seq")
@ -97,9 +78,10 @@ class Response:
def maxLen(self): def maxLen(self):
return self.attrs.get("maxLen") return self.attrs.get("maxLen")
from .getaccount import GetAccount, GetAccountResp
from .ping import Ping, PingResp from .ping import Ping, PingResp
def construct(request): def construct(request):
""" """
Builds the XML message DOM and returns as string Builds the XML message DOM and returns as string
@ -122,7 +104,6 @@ def construct(request):
def _response_type_by_name(name): def _response_type_by_name(name):
response_types = [ response_types = [
GetAccountResp,
PingResp, PingResp,
] ]

View File

@ -1,27 +0,0 @@
#!/usr/bin/env python3
from . import Request, Response
class GetAccount(Request):
def __init__(self, id, maxRecords=None, **kwargs):
super().__init__("GetAccount", **kwargs)
self.attrs["id"] = id
if maxRecords is not None:
self.attrs["maxRecords"] = maxRecords
@property
def id(self):
return self.attrs.get("id")
@property
def maxRecords(self):
return self.attrs.get("maxRecords")
class GetAccountResp(Response):
@property
def account(self):
return self.attrs.get("account")

View File

@ -57,13 +57,10 @@ class Session:
self._connection.connect() self._connection.connect()
# Login
self._connection.send(messages.Open(self.username, self.password)) self._connection.send(messages.Open(self.username, self.password))
res = self._wait_for_respose() res = self._wait_for_respose()
res.raise_on_error()
def request(self, request): def request(self, request):
""" """
Sends a request and waits for response Sends a request and waits for response