Beispiel #1
0
def create_typed_message(raw_message_, payload_):
    component = payload_.getComponent()
    if isinstance(component, asn1.SkrRawResponse):
        response = component.getComponent()
        if isinstance(response, asn1.SkrDataTypesResponse):
            return unformatted.DataTypesResponse.create(
                raw_message_, response
            )
        if isinstance(response, asn1.SkrDataStartResponse):
            return unformatted.DataStartResponse.create(
                raw_message_, bool(response)
            )
        if isinstance(response, asn1.SkrDataStopResponse):
            return unformatted.DataStopResponse.create(
                raw_message_, bool(response)
            )
        raise exceptions.GeneralFault(
            f'unable to chose response by "{response.getName()}" name'
        )
    else:
        if isinstance(component, asn1.SkrRawReport):
            return unformatted.RawReport.create(raw_message_, component)
    raise exceptions.GeneralFault(
        f'unable to chose unformatted message by "{payload_.getName()}" name'
    )
Beispiel #2
0
    def to_asn1(self):
        task = asn1.SkrConnectionsTask(tagSet=(tag.initTagSet(
            tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2))))
        body = task.getComponentByName(self.component_name)
        for item in self.items:
            choice = asn1.SkrRequestedConnectionParameter()
            if isinstance(item, operations.LogicalOperation):
                choice.setComponentByName('separator', item.code)
            else:
                component = choice.getComponentByName('find-mask')
                descriptor = tagged_components.get(item.__class__.__name__,
                                                   None)
                if descriptor is None:
                    raise exceptions.GeneralFault(
                        f'unable to construct connection request ' +
                        f'item by the "{item.__class__.__name__}" class')
                component.setComponentByName('id', descriptor[0])
                if isinstance(item, base.ASN1Constructable):
                    component.setComponentByName(
                        'data', univ.Any(der_encode(item.to_asn1())))
                else:
                    if isinstance(item, base.ASN1Copyable):
                        predicate = descriptor[1]()
                        item.copy_to(predicate)
                        component.setComponentByName(
                            'data', univ.Any(der_encode(predicate)))
                    else:
                        raise exceptions.GeneralFault(
                            f'unable to encode predicate item ' +
                            f'by the "{item.__class__.__name__}" class')
            body.append(choice)

        return task
Beispiel #3
0
    def construct_workable_task_id_list(self, tasks):
        workable_task_ids = []
        if tasks is None:
            for task_id in self.tasks.keys():
                workable_task_ids.append(task_id)

        else:
            if isinstance(tasks, int):
                workable_task_ids.append(tasks)
            else:
                if isinstance(tasks, TaskInfo):
                    workable_task_ids.append(tasks.task_id)
                else:
                    if isinstance(tasks, list) or isinstance(tasks, tuple):
                        for task in tasks:
                            if isinstance(task, int):
                                workable_task_ids.append(task)
                            else:
                                if isinstance(task, TaskInfo):
                                    workable_task_ids.append(task.task_id)
                                else:
                                    raise exceptions.GeneralFault(
                                        'invalid task description class: "{0}"'
                                        .format(task.__class__.__name__))

                    else:
                        raise exceptions.GeneralFault(
                            f'invalid task description class: "{tasks.__class__.__name__}"'
                        )
        return workable_task_ids
Beispiel #4
0
 def __init__(self, asn1_choice_, component_name_, component_value_):
     if component_name_ not in asn1_choice_.componentType.keys():
         raise exceptions.GeneralFault(
             f'an invalid component name "{component_name_}" is ' +
             f'specified for the "{asn1_choice_.__class__.__name__}"' +
             f' ASN.1 CHOICE')
     if component_value_ is None:
         raise exceptions.GeneralFault(
             f'a value for the "{component_name_}" component name of ' +
             f'the "{asn1_choice_.__class__.__name__}" ASN.1 CHOICE is ' +
             f'not specified')
     self.asn1_choice = asn1_choice_
     self.component_name = component_name_
     self.component_value = component_value_
Beispiel #5
0
    def to_asn1(self):
        task = asn1.SkrAbonentsTask(tagSet=(tag.initTagSet(
            tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))))
        body = task.getComponentByName('validate-identifiers')
        for item in self.items:
            choice = asn1.SkrRequestedAbonentsParameters()
            if isinstance(item, operations.LogicalOperation):
                choice.setComponentByName('separator', item.code)
            else:
                component = choice.getComponentByName('find-mask')
                if isinstance(item, RequestedPerson):
                    predicate = asn1.SkrRequestedPerson()
                    item.copy_to(predicate)
                    component.setComponentByName(
                        'id', asn1.sorm_request_abonent_person)
                    component.setComponentByName(
                        'data', univ.Any(der_encode(predicate)))
                else:
                    if isinstance(item, RequestedOrganization):
                        predicate = asn1.SkrRequestedOrganization()
                        item.copy_to(predicate)
                        component.setComponentByName(
                            'id', asn1.sorm_request_abonent_organization)
                        component.setComponentByName(
                            'data', univ.Any(der_encode(predicate)))
                    else:
                        raise exceptions.GeneralFault(
                            'an invalid object type "{0}" in the "{1}" class'.
                            format(item.__class__.__name__,
                                   self.__class__.__name__))
            body.append(choice)

        return task
Beispiel #6
0
 def __init__(self,
              given_name_=None,
              patronymic_name_=None,
              surname_=None,
              document_info_=None,
              address_=None,
              icc_=None,
              contract_=None):
     if given_name_ is None:
         if patronymic_name_ is None:
             if surname_ is None:
                 if document_info_ is None:
                     if address_ is None:
                         if icc_ is None:
                             if contract_ is None:
                                 raise exceptions.GeneralFault(
                                     'no one parameter is defined for the "{0}" class'
                                     .format(self.__class__.__name__))
     self.given_name = given_name_
     self.patronymic_name = patronymic_name_
     self.surname = surname_
     self.document_info = document_info_
     self.address = address_
     self.icc = icc_
     self.contract = contract_
Beispiel #7
0
    def wait_for_tasks_completion(self, tasks=None, timeout=None):
        list_of_task_id = self.construct_workable_task_id_list(tasks)
        if len(list_of_task_id) == 0:
            return []
        waiting_finish_time = time.time() + (timeout
                                             if timeout is not None else 60)
        while time.time() < waiting_finish_time:
            self.waiting_responses += 1
            self.session.channel(1).send_request(data_ready.DataReadyRequest())
            self.wait_for_responses(time.time() + min(
                self.session.channel(1).channel_parameters.
                request_response_timeout, waiting_finish_time - time.time()))
            have_incomplete_tasks = False
            reported_info = []
            for task_id in list_of_task_id:
                task_info = self.tasks.get(task_id, None)
                if task_info is None:
                    reported_info.append(None)
                elif task_info.status.code != TaskExecutionStatus.data_not_ready:
                    reported_info.append(task_info)
                else:
                    have_incomplete_tasks = True
                    break

            if not have_incomplete_tasks:
                return reported_info
            time.sleep(1)

        raise exceptions.GeneralFault(
            'waiting for tasks completion timeout exceeded')
Beispiel #8
0
def create_typed_message(raw_message_, payload_):
    name = payload_.getName()
    creator = message_creators.get(name, None)
    if creator is None or not callable(creator):
        raise exceptions.GeneralFault(
            f'unable to chose trap message by "{name}" name')
    return creator(raw_message_, payload_.getComponent())
Beispiel #9
0
def create(raw_identifier_: asn1.SkrReportedIdentifier):
    raw_id = raw_identifier_['id']
    creator = identifier_creators.get(raw_id, None)
    if creator is None or not callable(creator):
        raise exceptions.GeneralFault(
            'unable to create reported identifier by "{0}" id'.format(id))
    return creator(raw_identifier_['data'])
Beispiel #10
0
    def encode_data(self):
        body = asn1.SkrRequestedBankCardTransferPays()
        for item in self.items:
            choice = asn1.SkrRequestedTransferParameters()
            if isinstance(item, operations.LogicalOperation):
                choice.setComponentByName('separator', item.code)
            else:
                if isinstance(
                        item,
                        identifiers.RequestedCdmaIdentifier) or isinstance(
                            item, identifiers.RequestedDataNetworkIdentifier
                        ) or isinstance(
                            item,
                            identifiers.RequestedGsmIdentifier) or isinstance(
                                item, identifiers.RequestedPstnIdentifier
                            ) or isinstance(
                                item, identifiers.RequestedPagerIdentifier
                            ) or isinstance(
                                item, identifiers.RequestedVoipIdentifier):
                    item.copy_to(
                        choice.getComponentByName('source-identifier'))
                else:
                    raise exceptions.GeneralFault(
                        'Invalid item "{0}" specified in "{1}"'.format(
                            item.__class__.__name__, self.__class__.__name__))
            body.append(choice)

        return der_encode(body)
Beispiel #11
0
 def __init__(self,
              zip_=None,
              country_=None,
              region_=None,
              zone_=None,
              city_=None,
              street_=None,
              building_=None,
              building_section_=None,
              apartment_=None):
     if zip_ is None:
         if country_ is None:
             if region_ is None:
                 if zone_ is None:
                     if city_ is None:
                         if street_ is None:
                             if building_ is None:
                                 if building_section_ is None:
                                     if apartment_ is None:
                                         raise exceptions.GeneralFault(
                                             f'no one parameter is '
                                             f'defined for the "{self.__class__.__name__}" class'
                                         )
     self.zip = zip_
     self.country = country_
     self.region = region_
     self.zone = zone_
     self.city = city_
     self.street = street_
     self.building = building_
     self.building_section = building_section_
     self.apartment = apartment_
Beispiel #12
0
 def register_incoming_message(self, message):
     request = self.not_responded_requests.pop(message.message_id, None)
     if request is not None:
         return request
     raise exceptions.GeneralFault(
         f'unable to find sent request for received response' +
         f' {message.__class__.__name__} (message_id: {message.message_id})'
     )
Beispiel #13
0
    def wait_for_responses(self, finish_time):
        while time.time() < finish_time and self.waiting_responses > 0:
            with self.cv_incoming_message:
                self.cv_incoming_message.wait(1)

        if self.waiting_responses > 0:
            raise exceptions.GeneralFault(
                'not all sent requests have been completed in specified time')
Beispiel #14
0
def create(raw_message_, payload_):
    component = payload_['report-block']['data-content']
    oid = component['id']
    if oid == asn1.sorm_report_data_content_raw:
        return RawRecordContentReport.create(raw_message_, payload_,
                                             component['data'])
    raise exceptions.GeneralFault(
        f'unable to create data content report data block' +
        f' by the "{str(oid)}" OID')
Beispiel #15
0
def create(raw_message_, payload_):
    component = payload_['report-block']['dictionary']
    oid = component['id']
    creator = report_creators.get(oid, None)
    if creator is None or not callable(creator):
        raise exceptions.GeneralFault(
            f'unable to create dictionary report data ' +
            f'block by the "{str(oid)}" OID')
    return creator(raw_message_, payload_, component['data'])
Beispiel #16
0
def create_typed_message(raw_message_):
    payload_id = str(raw_message_['id'])
    descriptor = message_descriptors.get(payload_id, None)
    if descriptor is None:
        raise exceptions.GeneralFault(
            'unable to recognize message with id: "{payload_id}"')
    payload, rest = ber_decode(raw_message_['data'],
                               descriptor.descriptor_reference())
    return descriptor.creator(raw_message_, payload)
Beispiel #17
0
    def __init__(self, host, channel_ports):
        if len(channel_ports) != 5:
            raise exceptions.GeneralFault(
                f'5 channel ports required, but {len(channel_ports)} are provided'
            )
        self.lg = logger.instance()
        self.channels = self.create_channels_list()
        self.there_were_errors = False
        channel_id = 0
        have_channels = False
        for port in channel_ports:
            channel_id += 1
            if port is not None:
                have_channels = True
                self.channels[channel_id - 1] = Channel(channel_id, host, port)

        if not have_channels:
            raise exceptions.GeneralFault('no one channel port is provided')
Beispiel #18
0
def create(raw_message_, payload_):
    component = payload_['report-block']['abonents']
    oid = component['id']
    if oid == asn1.sorm_report_abonent_abonent:
        return SubscriberReport.create(raw_message_, payload_,
                                       component['data'])
    if oid == asn1.sorm_report_abonent_service:
        return ServiceReport.create(raw_message_, payload_, component['data'])
    raise exceptions.GeneralFault(
        f'unable to create subscriber report data block ' +
        f'by the "{str(oid)}" OID')
Beispiel #19
0
def create_subscriber_info(payload_: asn1.SkrAbonentInfo):
    oid = payload_['id']
    if oid == asn1.sorm_report_abonent_person:
        item, rest = ber_decode(payload_['data'], asn1.SkrAbonentPerson())
        return PersonInfo.create(item)
    if oid == asn1.sorm_report_abonent_organization:
        item, rest = ber_decode(payload_['data'],
                                asn1.SkrAbonentOrganization())
        return OrganizationInfo.create(item)
    raise exceptions.GeneralFault(
        f'unable to create subscriber info by the "{str(oid)}" OID')
Beispiel #20
0
 def handle_data_drop_response(self, chnl: sessions.Channel,
                               reqs: data_drop.DataDropRequest,
                               resp: data_drop.DataDropResponse):
     if not resp.successful:
         raise exceptions.GeneralFault(
             'unable to drop the task #{0}, error - {1}'.format(
                 resp.task_id, resp.error_description
                 if resp.error_description is not None else 'unknown'))
     self.tasks.pop(resp.task_id, None)
     self.waiting_responses -= 1
     with self.cv_incoming_message:
         self.cv_incoming_message.notify_all()
Beispiel #21
0
 def handle_data_load_response(self, chnl: sessions.Channel,
                               reqs: data_load.DataLoadRequest,
                               resp: data_load.DataLoadResponse):
     if resp.error_description is not None:
         raise exceptions.GeneralFault(
             'unable to start loading the task #{0}, error - {1}'.format(
                 resp.task_id, resp.error_description))
     task_info = self.tasks.get(resp.task_id, None)
     if task_info is not None:
         task_info.report_data_blocks = resp.data_blocks_number
     self.waiting_responses -= 1
     with self.cv_incoming_message:
         self.cv_incoming_message.notify_all()
Beispiel #22
0
 def __init__(self,
              document_type_id_=None,
              document_serial_=None,
              document_number_=None):
     if document_type_id_ is None:
         if document_serial_ is None:
             if document_number_ is None:
                 raise exceptions.GeneralFault(
                     'no one parameter is defined for the "{0}" class'.
                     format(self.__class__.__name__))
     self.document_type_id = document_type_id_
     self.document_serial = document_serial_
     self.document_number = document_number_
Beispiel #23
0
    def encode_data(self):
        body = asn1.SkrRequestedExpressPays()
        for item in self.items:
            choice = asn1.SkrRequestedExpressPaysParameters()
            if isinstance(item, operations.LogicalOperation):
                choice.setComponentByName('separator', item.code)
            else:
                if isinstance(item, ExpressCardNumber):
                    choice.setComponentByName('express-card', str(item))
                else:
                    raise exceptions.GeneralFault(
                        'Invalid item "{0}" specified in "{1}"'.format(
                            item.__class__.__name__, self.__class__.__name__))
            body.append(choice)

        return der_encode(body)
Beispiel #24
0
def create(raw_message_, payload_):
    name = payload_['report-block'].getName()
    creator = report_creators.get(name, None)
    if creator is None or not callable(creator):
        raise exceptions.GeneralFault(
            f'unable to chose report data block by "{name}" name')
    try:
        return creator(raw_message_, payload_)
    except error.PyAsn1Error:
        if isinstance(payload_, asn1.SkrReport):
            task_id = int(payload_.getComponentByName('task-id'))
            block_number = int(payload_.getComponentByName('block-number'))
            logger.instance().error(
                f'Unable to parse ASN.1 data of report ' +
                f'block #{block_number} of the task #{task_id}')
        raise
Beispiel #25
0
    def handle_create_task_response(self, chnl: sessions.Channel,
                                    reqs: create_task.CreateTaskRequest,
                                    resp: create_task.CreateTaskResponse):
        for task in self.task_creation_info:
            if task.request_id == reqs.message_id:
                if not resp.successful:
                    raise exceptions.GeneralFault(
                        'unable to create task: {0}, error - {1}'.format(
                            str(reqs), resp.error_description if
                            resp.error_description is not None else 'unknown'))
                task.task_id = resp.task_id
                self.tasks[task.task_id] = task
                break

        self.waiting_responses -= 1
        with self.cv_incoming_message:
            self.cv_incoming_message.notify_all()
Beispiel #26
0
    def wait_for_tasks_report(self, tasks=None, timeout=None):
        list_of_task_id = self.construct_workable_task_id_list(tasks)
        if len(list_of_task_id) == 0:
            return []
        finish_time = time.time() + (timeout if timeout is not None else 0)
        while time.time() < finish_time:
            for task_id in list_of_task_id:
                report_blocks = self.reports.get(task_id, None)
                if report_blocks is not None and len(report_blocks) > 0:
                    return report_blocks.pop(0)
                continue

            with self.cv_incoming_message:
                self.cv_incoming_message.wait(1)

        raise exceptions.GeneralFault(
            'no task reports have been received in specified time')
Beispiel #27
0
 def __init__(self,
              full_name_=None,
              address_=None,
              tax_reference_number_=None,
              internal_user_=None,
              contract_=None):
     if full_name_ is None:
         if address_ is None:
             if tax_reference_number_ is None:
                 if internal_user_ is None:
                     if contract_ is None:
                         raise exceptions.GeneralFault(
                             'no one parameter is defined for the "{0}" class'
                             .format(self.__class__.__name__))
     self.full_name = full_name_
     self.address = address_
     self.tax_reference_number = tax_reference_number_
     self.internal_user = internal_user_
     self.contract = contract_
Beispiel #28
0
    def encode_data(self):
        body = asn1.SkrRequestedBankTransactionPays()
        for item in self.items:
            choice = asn1.SkrRequestedBankTransactionPaysParameters()
            if isinstance(item, operations.LogicalOperation):
                choice.setComponentByName('separator', item.code)
            else:
                if isinstance(item, BankAccount):
                    choice.setComponentByName('bank-account', str(item))
                else:
                    if isinstance(item, BankName):
                        choice.setComponentByName('bank-name', str(item))
                    else:
                        raise exceptions.GeneralFault(
                            f'Invalid item "{0}" specified in "{1}"'.format(
                                item.__class__.__name__,
                                self.__class__.__name__))
            body.append(choice)

        return der_encode(body)
Beispiel #29
0
    def encode_data(self):
        body = asn1.SkrRequestedServiceCenterPays()
        for item in self.items:
            choice = asn1.SkrRequestedServiceCenterPaysParameters()
            if isinstance(item, operations.LogicalOperation):
                choice.setComponentByName('separator', item.code)
            else:
                if isinstance(item, ServiceCenterId):
                    choice.setComponentByName('center-id', str(item))
                else:
                    if isinstance(item, addresses.RequestedAddress):
                        item.copy_to(
                            choice.getComponentByName('center-address'))
                    else:
                        raise exceptions.GeneralFault(
                            'Invalid item "{0}" specified in "{1}"'.format(
                                item.__class__.__name__,
                                self.__class__.__name__))
            body.append(choice)

        return der_encode(body)
Beispiel #30
0
    def to_asn1(self):
        task = asn1.SkrAbonentsTask(tagSet=(tag.initTagSet(
            tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))))
        body = task.getComponentByName('validate-services')
        for item in self.items:
            choice = asn1.SkrValidateServicesParameters()
            if isinstance(item, operations.LogicalOperation):
                choice.setComponentByName('separator', item.code)
            else:
                component = choice.getComponentByName('find-mask')
                if isinstance(item, str):
                    component.setComponentByName('contract', item)
                else:
                    if isinstance(
                            item, identifiers.RequestedPagerIdentifier
                    ) or isinstance(
                            item,
                            identifiers.RequestedPstnIdentifier) or isinstance(
                                item, identifiers.RequestedGsmIdentifier
                            ) or isinstance(
                                item, identifiers.RequestedCdmaIdentifier
                            ) or isinstance(
                                item, identifiers.RequestedVoipIdentifier
                            ) or isinstance(
                                item,
                                identifiers.RequestedDataNetworkIdentifier):
                        identifier = asn1.SkrRequestedIdentifier(
                            tagSet=(tag.initTagSet(
                                tag.Tag(tag.tagClassContext,
                                        tag.tagFormatConstructed, 1))))
                        item.copy_to(identifier)
                        component.setComponentByName('identifier', identifier)
                    else:
                        raise exceptions.GeneralFault(
                            'an invalid object type "{0}" in the "{1}" class'.
                            format(item.__class__.__name__,
                                   self.__class__.__name__))
            body.append(choice)

        return task