Пример #1
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 ptsmpp.enum import Enum
from ptsmpp.pdu.namedtuple import namedtuple
from ptsmpp.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)
Пример #2
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
Пример #3
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 ptsmpp.pdu.operations import DeliverSM, DataSM
from ptsmpp.pdu.pdu_types import *
from ptsmpp.pdu.namedtuple import namedtuple
from ptsmpp.pdu.gsm_types import InformationElementIdentifier
from ptsmpp.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)
Пример #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