Difference between revisions of "Makepacketdict"

From Second Life Wiki
Jump to navigation Jump to search
(New page: brain-dead import. While it should work as-is for testing, the parsing requires you eleiminate all extraneous spaces in the white space in "message_template.msg" before the "{" and replace...)
 
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
brain-dead import. While it should work as-is for testing, the parsing requires you eleiminate all extraneous spaces in the white space in "message_template.msg" before the "{" and replace it with tabs
brain-dead import. While it should work as-is for testing, the parsing requires you eliminate all extraneous spaces in the white space in "message_template.msg" before the "{" and replace it with tabs
 
<python>


<syntaxhighlight lang="python">
import re
import re


def makepacketdict():
def makepacketdict():
     dict = {}
     dict = {}
     for line in open("message_template.msg", ).xreadlines():
     for line in open("message_template.msg"):
         results = re.match("^\t([^\t{}]+.+)",line)
         results = re.match("^\t([^\t{}]+.+)",line)
         if results:
         if results:
Line 18: Line 16:
                 #print (aline[1],aline[2])  
                 #print (aline[1],aline[2])  
                 #print (aline[1],"0x"+aline[2]), dict[(aline[1],"0x"+aline[2])]  
                 #print (aline[1],"0x"+aline[2]), dict[(aline[1],"0x"+aline[2])]  
                 #dict[(aline[1],int("0x"+aline[2][8:],16))] = (aline[0],aline[3], aline[4])
                 #dict[(aline[1],int(aline[2][8:],16))] = (aline[0],aline[3], aline[4])
             else:
             else:
                 dict[(aline[1],int(aline[2]))] = (aline[0],aline[3], aline[4])
                 dict[(aline[1],int(aline[2]))] = (aline[0],aline[3], aline[4])
     return dict
     return dict


</python>
</syntaxhighlight>
[[Category: AW Groupies]]
[[Category: AW Groupies]]

Latest revision as of 07:45, 27 June 2017

brain-dead import. While it should work as-is for testing, the parsing requires you eliminate all extraneous spaces in the white space in "message_template.msg" before the "{" and replace it with tabs

import re

def makepacketdict():
    dict = {}
    for line in open("message_template.msg"):
        results = re.match("^\t([^\t{}]+.+)",line)
        if results:
            aline = results.group(1)
            aline = aline.split()
            if aline[1] == "Fixed": 
                dict[(aline[1],aline[2])] = (aline[0],aline[3], aline[4])
                
                #print (aline[1],aline[2]) 
                #print (aline[1],"0x"+aline[2]), dict[(aline[1],"0x"+aline[2])] 
                #dict[(aline[1],int(aline[2][8:],16))] = (aline[0],aline[3], aline[4])
            else:
                dict[(aline[1],int(aline[2]))] = (aline[0],aline[3], aline[4])
    return dict