コード例 #1
0
ファイル: views.py プロジェクト: yeputons/website
def pduencode(request):
    pdu = None
    if request.method == "POST":
        form = PDUEncodeForm(request.POST)
        if form.is_valid():
            # Prepare message data
            smsinfo = {
                "Class":
                form.cleaned_data["cls"],
                "Unicode":
                form.cleaned_data["unicode"],
                "Entries": [{
                    "ID": "ConcatenatedTextLong",
                    "Buffer": form.cleaned_data["text"],
                }],
            }
            # Encode SMS
            encoded = gammu.EncodeSMS(smsinfo)
            # Fill in remaining data
            for msg in encoded:
                msg["SMSC"] = {
                    "Location": 0,
                    "Number": form.cleaned_data["smsc"],
                    "Validity": "Max",
                }
                msg["Number"] = form.cleaned_data["number"]
                msg["Class"] = form.cleaned_data["cls"]
            # Encode PDU
            pdu = enumerate(
                gammu.EncodePDU(e, "Submit").hex() for e in encoded)

    else:
        form = PDUEncodeForm()
    return render(
        request,
        "tools/pduencode.html",
        {
            "form": form,
            "pdu": pdu,
        },
    )
コード例 #2
0
    def do_smstest(self, smsinfo, expected):
        # encode SMSes
        sms = gammu.EncodeSMS(smsinfo)

        # decode back SMSes
        decodedsms = gammu.DecodeSMS(sms)

        # compare text
        self.assertEqual(decodedsms['Entries'][0]['Buffer'], expected)

        # do conversion to PDU
        pdu = [gammu.EncodePDU(s) for s in sms]

        # Convert back
        pdusms = [gammu.DecodePDU(p) for p in pdu]

        # decode back SMS from PDU
        decodedsms = gammu.DecodeSMS(pdusms)

        # compare PDU results
        self.assertEqual(decodedsms['Entries'][0]['Buffer'], expected)
コード例 #3
0
def pduencode(request):
    pdu = None
    if request.method == 'POST':
        form = PDUEncodeForm(request.POST)
        if form.is_valid():
            # Prepare message data
            smsinfo = {
                'Class':
                form.cleaned_data['cls'],
                'Unicode':
                form.cleaned_data['unicode'],
                'Entries': [{
                    'ID': 'ConcatenatedTextLong',
                    'Buffer': form.cleaned_data['text'],
                }]
            }
            # Encode SMS
            encoded = gammu.EncodeSMS(smsinfo)
            # Fill in remaining data
            for msg in encoded:
                msg['SMSC'] = {
                    'Location': 0,
                    'Number': form.cleaned_data['smsc'],
                    'Validity': 'Max',
                }
                msg['Number'] = form.cleaned_data['number']
                msg['Class'] = form.cleaned_data['cls']
            # Encode PDU
            pdu = enumerate([
                binascii.hexlify(gammu.EncodePDU(e, 'Submit')) for e in encoded
            ])

    else:
        form = PDUEncodeForm()
    return render(request, 'tools/pduencode.html', {
        'form': form,
        'pdu': pdu,
    })
コード例 #4
0
import gammu

# text of sms
txt = u'.........1$........2..Ø......3...åÅ....4....Λ....5....Æ....6....ñ....7.........8.........9........0.........1.........2.........3.........4.........5.........6.........7.........8.........9........0.........1.........2.........3.........4.........5.........6.........7.........8.........9....¥€..0'

# SMS info about message
smsinfo = {'Entries': [{'ID': 'ConcatenatedTextLong', 'Buffer': txt}]}

# encode SMSes
sms = gammu.EncodeSMS(smsinfo)

# decode back SMSes
decodedsms = gammu.DecodeSMS(sms)

# show results
print "Text:", repr(decodedsms['Entries'][0]['Buffer'])
print "Comparsion:", (decodedsms['Entries'][0]['Buffer'] == txt)

# do conversion to PDU
pdu = [gammu.EncodePDU(s) for s in sms]

# Convert back
pdusms = [gammu.DecodePDU(p) for p in pdu]

# decode back SMS from PDU
decodedsms = gammu.DecodeSMS(pdusms)

# show PDU results
print "PDU Text:", repr(decodedsms['Entries'][0]['Buffer'])
print "PDU Comparsion:", (decodedsms['Entries'][0]['Buffer'] == txt)