[pywin32-checkins] pywin32/com/win32com/makegw makegwparse.py, 1.11, 1.12
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2008-04-09 10:03:20
|
Update of /cvsroot/pywin32/pywin32/com/win32com/makegw In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8857/com/win32com/makegw Modified Files: makegwparse.py Log Message: [ 1894593 ] Convert regex to re in makegwparse.py Thanks to Alexandr Zamaraev Index: makegwparse.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/makegw/makegwparse.py,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** makegwparse.py 8 Oct 2003 23:47:07 -0000 1.11 --- makegwparse.py 9 Apr 2008 10:03:21 -0000 1.12 *************** *** 12,21 **** interface """ ! import regex import traceback import string ! error_not_found = "The requested item could not be found" ! error_not_supported = "The required functionality is not supported" VERBOSE=0 --- 12,26 ---- interface """ ! import re import traceback import string ! class error_not_found(Exception): ! def __init__(self, msg="The requested item could not be found"): ! super(error_not_found, self).__init__(msg) ! ! class error_not_supported(Exception): ! def __init__(self, msg="The required functionality is not supported"): ! super(error_not_supported, self).__init__(msg) VERBOSE=0 *************** *** 475,479 **** "PARSEACTION": ("int", "int", "i"), } ! class ArgFormatterSimple(ArgFormatter): """An arg formatter for simple integer etc types""" --- 480,484 ---- "PARSEACTION": ("int", "int", "i"), } ! class ArgFormatterSimple(ArgFormatter): """An arg formatter for simple integer etc types""" *************** *** 556,560 **** raise error_not_supported, "The type '%s' (%s) is unknown." % (arg.type, arg.name) ! ############################################################# # --- 561,565 ---- raise error_not_supported, "The type '%s' (%s) is unknown." % (arg.type, arg.name) ! ############################################################# # *************** *** 569,573 **** # in,out type name [ ] # -------------- -------- ------------ ------ ! regex = regex.compile('/\\* \\[\\([^\\]]*.*\\)] \\*/[ \t]\\(.*[\\* ]\\)\\([a-zA-Z0-9]+\\)\\(\\[ *]\\)?[),]') def __init__(self, good_interface_names): self.good_interface_names = good_interface_names --- 574,578 ---- # in,out type name [ ] # -------------- -------- ------------ ------ ! regex = re.compile(r'/\* \[([^\]]*.*?)] \*/[ \t](.*[* ]+)(\w+)(\[ *])?[\),]') def __init__(self, good_interface_names): self.good_interface_names = good_interface_names *************** *** 583,607 **** """ line = file.readline() ! if self.regex.search(line)<0: raise error_not_found ! self.name = self.regex.group(3) ! self.inout = string.split(self.regex.group(1),'][') ! typ = string.strip(self.regex.group(2)) self.raw_type = typ self.indirectionLevel = 0 ! if self.regex.group(4): # Has "[ ]" decl self.arrayDecl = 1 try: ! pos = string.rindex(typ, "__RPC_FAR") self.indirectionLevel = self.indirectionLevel + 1 ! typ = string.strip(typ[:pos]) except ValueError: pass ! while 1: try: ! pos = string.rindex(typ, "__RPC_FAR *") self.indirectionLevel = self.indirectionLevel + 1 ! typ = string.strip(typ[:pos]) except ValueError: break --- 588,614 ---- """ line = file.readline() ! mo = self.regex.search(line) ! if not mo: raise error_not_found ! self.name = mo.group(3) ! self.inout = mo.group(1).split('][') ! typ = mo.group(2).strip() self.raw_type = typ self.indirectionLevel = 0 ! if mo.group(4): # Has "[ ]" decl self.arrayDecl = 1 try: ! pos = typ.rindex("__RPC_FAR") self.indirectionLevel = self.indirectionLevel + 1 ! typ = typ[:pos].strip() except ValueError: pass ! ! typ = typ.replace("__RPC_FAR", "") while 1: try: ! pos = typ.rindex("*") self.indirectionLevel = self.indirectionLevel + 1 ! typ = typ[:pos].strip() except ValueError: break *************** *** 638,643 **** # options ret type callconv name # ----------------- -------- -------- -------- ! regex = regex.compile('virtual \\(/\\*.*\\*/ \\)?\\(.*\\) \\(.*\\) \\(.*\\)(\w?') ! def __init__(self, good_interface_names ): self.good_interface_names = good_interface_names self.name = self.result = self.callconv = None --- 645,650 ---- # options ret type callconv name # ----------------- -------- -------- -------- ! regex = re.compile(r'virtual (/\*.*?\*/ )?(.*?) (.*?) (.*?)\(\w?') ! def __init__(self, good_interface_names): self.good_interface_names = good_interface_names self.name = self.result = self.callconv = None *************** *** 650,658 **** is raised. """ ! str = file.readline() ! if self.regex.search(str, 0) == -1: raise error_not_found ! self.name = self.regex.group(4) ! self.result = self.regex.group(2) if self.result != "HRESULT": if self.result=="DWORD": # DWORD is for old old stuff? --- 657,666 ---- is raised. """ ! line = file.readline() ! mo = self.regex.search(line) ! if not mo: raise error_not_found ! self.name = mo.group(4) ! self.result = mo.group(2) if self.result != "HRESULT": if self.result=="DWORD": # DWORD is for old old stuff? *************** *** 678,686 **** # name base # -------- -------- ! regex = regex.compile("\\(interface\\|\\) \\([^ ]*\\) : public \\(.*\\)$") ! def __init__(self): self.methods = [] ! self.name = self.regex.group(2) ! self.base = self.regex.group(3) if VERBOSE: print "Interface %s : public %s" % (self.name, self.base) --- 686,694 ---- # name base # -------- -------- ! regex = re.compile("(interface|) ([^ ]*) : public (.*)$") ! def __init__(self, mo): self.methods = [] ! self.name = mo.group(2) ! self.base = mo.group(3) if VERBOSE: print "Interface %s : public %s" % (self.name, self.base) *************** *** 697,701 **** except error_not_found: break ! def find_interface(interfaceName, file): """Find and return an interface in a file --- 705,709 ---- except error_not_found: break ! def find_interface(interfaceName, file): """Find and return an interface in a file *************** *** 706,721 **** but not the methods. """ ! line = file.readline() while line: ! if Interface.regex.search(line, 0) >=0: ! name = Interface.regex.group(2) print name if name==interfaceName: ! return Interface() line = file.readline() raise error_not_found ! def parse_interface_info(interfaceName, file): """Find, parse and return an interface in a file --- 714,734 ---- but not the methods. """ ! interface = None line = file.readline() while line: ! mo = Interface.regex.search(line) ! if mo: ! name = mo.group(2) print name + AllConverters[name] = (ArgFormatterInterface, 0, 1) if name==interfaceName: ! interface = Interface(mo) ! interface.BuildMethods(file) line = file.readline() + if interface: + return interface raise error_not_found ! def parse_interface_info(interfaceName, file): """Find, parse and return an interface in a file *************** *** 726,733 **** """ try: ! interface = find_interface(interfaceName, file) ! interface.BuildMethods(file) ! return interface ! except regex.error: traceback.print_exc() print "The interface could not be built, as the regular expression failed!" --- 739,744 ---- """ try: ! return find_interface(interfaceName, file) ! except re.error: traceback.print_exc() print "The interface could not be built, as the regular expression failed!" *************** *** 745,747 **** else: print "%d\n%s\n%s\n%s\n%s" % (res, r.group(1), r.group(2), r.group(3), r.group(4)) - --- 756,757 ---- |