n00b formatting

Verde Denim tdldev at gmail.com
Thu Feb 24 17:46:51 EST 2011


On Thu, Feb 24, 2011 at 12:49 PM, MRAB <python at mrabarnett.plus.com> wrote:

> On 24/02/2011 16:41, Verde Denim wrote:
>
>> hi, all
>> i can't believe i don't see this, but
>> python from the command line:
>>  >>> x = '0D'
>>  >>> y = '0x' + x
>>  >>> print "%d" % int(y,0)
>> 13
>>
>> content of testme.py:
>> x = '0D'
>> y = '0x' + x
>> print "%d" % int(y,0)
>> TypeError: 'int' object is not callable
>>
>> what am i not seeing here??
>>
>>  I can only assume that at some point you assigned an int to 'int'.
>

To put this in context, here is the code -
#!/usr/bin/env python

from scapy.all import *
from binascii import hexlify
import sys, re, pprint

class C12Pcap:

    __acse_pdu_open = []  # 1-byte indicating start of packet
    __acse_pdu_len = []   # 1-byte indicating the length of the packet
    __asn1_called_ident_type = []   # 1-byte indicating universal identifier
    __asn1_called_ident_length = []   # 1-byte indicating the length of this
identifier

    def __init__(self, pcap=None, portno=0):
        self.__pcap = pcap
        self.__portno = portno
        self.__pcktList = []

    def __action(self):
        if self.__pcap:
            self.__rdpcap()
            self.__dump()
            return

    def __rdpcap(self):
        self.__pcktList = rdpcap(self.__pcap)
        return

    def __dump(self):
        x = int = 0
        z = int = -1
        for pckt in self.__pcktList: # for each packet
            z += 1                   # debug a smaller subset...
            if z == 50: break         # debug a smaller subset...
            layers = []              # a list of the layers' classes
            layerDicts = []          # a list of each layer's fields and
values
            cltype = pckt.__class__
            cl = pckt
            flds = cl.__dict__['fields']
            while 1:
                #   walk down the layers until no payload
                layers.append(cltype)
                layerDicts.append(flds)
                cltype = cl.__dict__['payload'].__class__
                cl =  cl.__dict__['payload']
                flds = cl.__dict__['fields']

                # if tcp, we'll guess at req/resp and if psh is on (for now)
                if re.search('TCP', str(cltype)):
                    i = 0
                    for key, value in flds.items():
                        if key == 'flags' and long(value) == 24:   #
PUSH,ACK
                            i = 1
                        if i == 1 and key == 'dport' and str(value) ==
str(portno):
                            pktType = 'REQUEST'
                        if i == 1 and key == 'sport' and str(value) ==
str(portno):
                            pktType = 'RESPONSE'

                # Do we have a Raw packet - the interesting ones for us
                if re.search('Raw', str(cltype)):
                    h = hexlify(flds['load'])   # hex representation of
payload
                    self.__acse_pdu_open = h[0:2]
                    self.__acse_pdu_len = h[2:4]
                    self.__asn1_called_ident_type = h[4:6]
                    self.__asn1_called_ident_length = '0x' + h[6:8]
                    print self.__asn1_called_ident_length # WORKS FINE
                    print "%d" % (int(self.__asn1_called_ident_length,0)) #
FAILS WITH:
#TypeError: 'int' object is not callable
#File "/home/Scripts/Py/Elster_Lab/strip_raw_data1.py", line 103, in
<module>
  #inst.run(pcap,portno)
#File "/home/Scripts/Py/Elster_Lab/strip_raw_data1.py", line 92, in run
  #self.__action()
#File "/home/Scripts/Py/Elster_Lab/strip_raw_data1.py", line 41, in __action
  #self.__dump()
#File "/home/Scripts/Py/Elster_Lab/strip_raw_data1.py", line 86, in __dump
  #print "%d" % (int(self.__asn1_called_ident_length,0))

                if 'NoPayload' in str(cltype): break

    def run(self,pcap,portno):
        self.__pcap = pcap
        self.__portno = portno
        self.__action()

def main():

    return 0

if __name__ == '__main__':
    inst = C12Pcap()
    argl = sys.argv
    pcap = argl[1]
    portno = argl[2]
    inst.run(pcap,portno)
    main()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110224/166e5230/attachment-0001.html>


More information about the Python-list mailing list