Ejemplo n.º 1
0
       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""
import struct, StringIO
from smpp.pdu.operations import DeliverSM, DataSM
from smpp.pdu.pdu_types import *
from smpp.pdu.namedtuple import namedtuple
from smpp.pdu.gsm_types import InformationElementIdentifier
from smpp.pdu.gsm_encoding import UserDataHeaderEncoder

ShortMessageString = namedtuple('ShortMessageString', 'bytes, unicode, udh')


class SMStringEncoder(object):
    userDataHeaderEncoder = UserDataHeaderEncoder()

    def decodeSM(self, pdu):
        data_coding = pdu.params['data_coding']
        #TODO - when to look for message_payload instead of short_message??
        (smBytes, udhBytes, smStrBytes) = self.splitSM(pdu)
        udh = self.decodeUDH(udhBytes)

        if data_coding.scheme == DataCodingScheme.DEFAULT:
            unicodeStr = None
            if data_coding.schemeData == DataCodingDefault.SMSC_DEFAULT_ALPHABET:
                unicodeStr = unicode(smStrBytes, 'ascii')
Ejemplo n.º 2
0
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""
from enum import Enum
from smpp.pdu.namedtuple import namedtuple
from smpp.pdu import constants

CommandId = Enum(*constants.command_id_name_map.keys())

CommandStatus = Enum(*constants.command_status_name_map.keys())

Tag = Enum(*constants.tag_name_map.keys())

Option = namedtuple('Option', 'tag, value')

EsmClassMode = Enum(*constants.esm_class_mode_name_map.keys())
EsmClassType = Enum(*constants.esm_class_type_name_map.keys())
EsmClassGsmFeatures = Enum(*constants.esm_class_gsm_features_name_map.keys())

EsmClassBase = namedtuple('EsmClass', 'mode, type, gsmFeatures')

class EsmClass(EsmClassBase):
    
    def __new__(cls, mode, type, gsmFeatures=[]):
        return EsmClassBase.__new__(cls, mode, type, set(gsmFeatures))
        
    def __repr__(self):
        return 'EsmClass[mode: %s, type: %s, gsmFeatures: %s]' % (self.mode, self.type, self.gsmFeatures)
Ejemplo n.º 3
0
    """Fixed offset in minutes east from UTC."""
    def __init__(self, offsetMin, name):
        self.__offset = timedelta(minutes=offsetMin)
        self.__name = name

    def utcoffset(self, dt):
        return self.__offset

    def tzname(self, dt):
        return self.__name

    def dst(self, dt):
        return timedelta(0)


SMPPRelativeTime = namedtuple('SMPPRelativeTime',
                              'years, months, days, hours, minutes, seconds')

YYMMDDHHMMSS_FORMAT = "%y%m%d%H%M%S"


def parse_t(t_str):
    if len(t_str) != 1:
        raise ValueError("tenths of second must be one digit")
    return int(t_str)


def unparse_t(t):
    if t < 0 or t > 9:
        raise ValueError("tenths of second must be one digit")
    return '%1d' % t
Ejemplo n.º 4
0
SMPPSessionStates = Enum(
    'NONE',
    'OPEN',
    'BIND_TX_PENDING',
    'BOUND_TX',
    'BIND_RX_PENDING',
    'BOUND_RX',
    'BIND_TRX_PENDING',
    'BOUND_TRX',
    'UNBIND_PENDING',
    'UNBIND_RECEIVED',
    'UNBOUND'
)

SMPPOutboundTxn = namedtuple('SMPPOutboundTxn', 'request, timer, ackDeferred')
SMPPOutboundTxnResult = namedtuple('SMPPOutboundTxnResult', 'smpp, request, response')


def _safelylogOutPdu(content):
    try:
        return binascii.b2a_hex(content)
    except exceptions.UnicodeEncodeError:
        return "Couldn't log out the pdu content due to non-ascii characters."


class DataHandlerResponse(object):
    def __init__(self, status, **params):
        self.status = status
        self.params = params
Ejemplo n.º 5
0
    """Fixed offset in minutes east from UTC."""

    def __init__(self, offsetMin, name):
        self.__offset = timedelta(minutes = offsetMin)
        self.__name = name

    def utcoffset(self, dt):
        return self.__offset

    def tzname(self, dt):
        return self.__name

    def dst(self, dt):
        return timedelta(0)

SMPPRelativeTime = namedtuple('SMPPRelativeTime', 'years, months, days, hours, minutes, seconds')

YYMMDDHHMMSS_FORMAT = "%y%m%d%H%M%S"

def parse_t(t_str):
    if len(t_str) != 1:
        raise ValueError("tenths of second must be one digit")
    return int(t_str)

def unparse_t(t):
    if t < 0 or t > 9:
        raise ValueError("tenths of second must be one digit")
    return '%1d' % t

def parse_nn(nn_str):
    if len(nn_str) != 2:
Ejemplo n.º 6
0
       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""
import struct, StringIO
from smpp.pdu.operations import DeliverSM, DataSM
from smpp.pdu.pdu_types import *
from smpp.pdu.namedtuple import namedtuple
from smpp.pdu.gsm_types import InformationElementIdentifier
from smpp.pdu.gsm_encoding import UserDataHeaderEncoder

ShortMessageString = namedtuple('ShortMessageString', 'bytes, unicode, udh')

class SMStringEncoder(object):
    userDataHeaderEncoder = UserDataHeaderEncoder()
        
    def decodeSM(self, pdu):
        data_coding = pdu.params['data_coding']
        #TODO - when to look for message_payload instead of short_message??
        (smBytes, udhBytes, smStrBytes) = self.splitSM(pdu)
        udh = self.decodeUDH(udhBytes)
        
        if data_coding.scheme == DataCodingScheme.DEFAULT:
            unicodeStr = None
            if data_coding.schemeData == DataCodingDefault.SMSC_DEFAULT_ALPHABET:
                unicodeStr = unicode(smStrBytes, 'ascii')
            elif data_coding.schemeData == DataCodingDefault.IA5_ASCII:
Ejemplo n.º 7
0
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""
from enum import Enum
from smpp.pdu.namedtuple import namedtuple
from smpp.pdu import constants

CommandId = Enum(*constants.command_id_name_map.keys())

CommandStatus = Enum(*constants.command_status_name_map.keys())

Tag = Enum(*constants.tag_name_map.keys())

Option = namedtuple('Option', 'tag, value')

EsmClassMode = Enum(*constants.esm_class_mode_name_map.keys())
EsmClassType = Enum(*constants.esm_class_type_name_map.keys())
EsmClassGsmFeatures = Enum(*constants.esm_class_gsm_features_name_map.keys())

EsmClassBase = namedtuple('EsmClass', 'mode, type, gsmFeatures')


class EsmClass(EsmClassBase):
    def __new__(cls, mode, type, gsmFeatures=[]):
        return EsmClassBase.__new__(cls, mode, type, set(gsmFeatures))

    def __repr__(self):
        return 'EsmClass[mode: %s, type: %s, gsmFeatures: %s]' % (
            self.mode, self.type, self.gsmFeatures)
Ejemplo n.º 8
0
from enum import Enum
from smpp.pdu.namedtuple import namedtuple
from twisted.internet import protocol, defer, reactor
from smpp.pdu.operations import *
from smpp.pdu.pdu_encoding import PDUEncoder
from smpp.pdu.pdu_types import PDURequest, PDUResponse, PDUDataRequest, CommandStatus
from smpp.pdu.error import *

LOG_CATEGORY = "smpp.twisted.protocol"

SMPPSessionStates = Enum('NONE', 'OPEN', 'BIND_TX_PENDING', 'BOUND_TX',
                         'BIND_RX_PENDING', 'BOUND_RX', 'BIND_TRX_PENDING',
                         'BOUND_TRX', 'UNBIND_PENDING', 'UNBIND_RECEIVED',
                         'UNBOUND')

SMPPOutboundTxn = namedtuple('SMPPOutboundTxn', 'request, timer, ackDeferred')
SMPPOutboundTxnResult = namedtuple('SMPPOutboundTxnResult',
                                   'smpp, request, response')


class DataHandlerResponse(object):
    def __init__(self, status, **params):
        self.status = status
        self.params = params


class SMPPClientProtocol(protocol.Protocol):
    """Short Message Peer to Peer Protocol v3.4 implementing ESME (client)"""
    version = 0x34

    def __init__(self):
Ejemplo n.º 9
0
"""
Copyright 2009-2010 Mozes, Inc.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""
from enum import Enum

from smpp.pdu.namedtuple import namedtuple
from smpp.pdu import gsm_constants


InformationElementIdentifier = Enum(*gsm_constants.information_element_identifier_name_map.keys())

InformationElement = namedtuple('InformationElement', 'identifier, data')

IEConcatenatedSM = namedtuple('IEConcatenatedSM', 'referenceNum, maximumNum, sequenceNum')
Ejemplo n.º 10
0
"""
Copyright 2009-2010 Mozes, Inc.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""
from enum import Enum
from smpp.pdu.namedtuple import namedtuple
from smpp.pdu import gsm_constants

InformationElementIdentifier = Enum(
    *gsm_constants.information_element_identifier_name_map.keys())

InformationElement = namedtuple('InformationElement', 'identifier, data')

IEConcatenatedSM = namedtuple('IEConcatenatedSM',
                              'referenceNum, maximumNum, sequenceNum')
Ejemplo n.º 11
0
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""
import struct
import StringIO
from smpp.pdu.operations import DeliverSM, DataSM
from smpp.pdu.pdu_types import *
from smpp.pdu.namedtuple import namedtuple
from smpp.pdu.gsm_types import InformationElementIdentifier
from smpp.pdu.gsm_encoding import UserDataHeaderEncoder

ShortMessageString = namedtuple("ShortMessageString", "bytes, unicode, udh")


class SMStringEncoder(object):
    userDataHeaderEncoder = UserDataHeaderEncoder()

    def decodeSM(self, pdu, smsc_default_alphabet_encoding="ascii"):
        data_coding = pdu.params["data_coding"]
        (smBytes, udhBytes, smStrBytes) = self.splitSM(pdu)
        udh = self.decodeUDH(udhBytes)

        try:
            if data_coding.scheme == DataCodingScheme.DEFAULT:
                unicodeStr = None
                if data_coding.schemeData == DataCodingDefault.SMSC_DEFAULT_ALPHABET:
                    unicodeStr = unicode(smStrBytes, smsc_default_alphabet_encoding)
Ejemplo n.º 12
0
from smpp.pdu import constants
from smpp.pdu.enum import old_style_enum as Enum
from smpp.pdu.namedtuple import namedtuple

CommandId = Enum(*list(constants.command_id_name_map.keys()))

CommandStatus = Enum(*list(constants.command_status_name_map.keys()))

Tag = Enum(*list(constants.tag_name_map.keys()))

Option = namedtuple('Option', 'tag, value')

EsmClassMode = Enum(*list(constants.esm_class_mode_name_map.keys()))
EsmClassType = Enum(*list(constants.esm_class_type_name_map.keys()))
EsmClassGsmFeatures = Enum(
    *list(constants.esm_class_gsm_features_name_map.keys()))

EsmClassBase = namedtuple('EsmClass', 'mode, type, gsm_features')


class EsmClass(EsmClassBase):
    def __new__(cls, mode, type, gsm_features=None):
        if gsm_features is None:
            gsm_features = []
        return EsmClassBase.__new__(cls, mode, type, set(gsm_features))

    def __repr__(self):
        return 'EsmClass[mode: %s, type: %s, gsm_features: %s]' % (
            self.mode, self.type, self.gsm_features)