Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
sre_parse.SubPattern Class Reference

List of all members.

Public Member Functions

def __init__
def dump
def __repr__
def __len__
def __delitem__
def __getitem__
def __setitem__
def insert
def append
def getwidth

Public Attributes

 pattern
 data
 width

Detailed Description

Definition at line 89 of file sre_parse.py.


Constructor & Destructor Documentation

def sre_parse.SubPattern.__init__ (   self,
  pattern,
  data = None 
)

Definition at line 91 of file sre_parse.py.

00091 
00092     def __init__(self, pattern, data=None):
00093         self.pattern = pattern
00094         if data is None:
00095             data = []
00096         self.data = data
        self.width = None

Here is the caller graph for this function:


Member Function Documentation

def sre_parse.SubPattern.__delitem__ (   self,
  index 
)

Definition at line 129 of file sre_parse.py.

00129 
00130     def __delitem__(self, index):
        del self.data[index]
def sre_parse.SubPattern.__getitem__ (   self,
  index 
)

Definition at line 131 of file sre_parse.py.

00131 
00132     def __getitem__(self, index):
00133         if isinstance(index, slice):
00134             return SubPattern(self.pattern, self.data[index])
        return self.data[index]

Definition at line 127 of file sre_parse.py.

00127 
00128     def __len__(self):
        return len(self.data)

Definition at line 125 of file sre_parse.py.

00125 
00126     def __repr__(self):
        return repr(self.data)
def sre_parse.SubPattern.__setitem__ (   self,
  index,
  code 
)

Definition at line 135 of file sre_parse.py.

00135 
00136     def __setitem__(self, index, code):
        self.data[index] = code
def sre_parse.SubPattern.append (   self,
  code 
)

Definition at line 139 of file sre_parse.py.

00139 
00140     def append(self, code):
        self.data.append(code)

Here is the caller graph for this function:

def sre_parse.SubPattern.dump (   self,
  level = 0 
)

Definition at line 97 of file sre_parse.py.

00097 
00098     def dump(self, level=0):
00099         nl = 1
00100         seqtypes = (tuple, list)
00101         for op, av in self.data:
00102             print(level*"  " + op, end=' '); nl = 0
00103             if op == "in":
00104                 # member sublanguage
00105                 print(); nl = 1
00106                 for op, a in av:
00107                     print((level+1)*"  " + op, a)
00108             elif op == "branch":
00109                 print(); nl = 1
00110                 i = 0
00111                 for a in av[1]:
00112                     if i > 0:
00113                         print(level*"  " + "or")
00114                     a.dump(level+1); nl = 1
00115                     i = i + 1
00116             elif isinstance(av, seqtypes):
00117                 for a in av:
00118                     if isinstance(a, SubPattern):
00119                         if not nl: print()
00120                         a.dump(level+1); nl = 1
00121                     else:
00122                         print(a, end=' ') ; nl = 0
00123             else:
00124                 print(av, end=' ') ; nl = 0
            if not nl: print()

Definition at line 141 of file sre_parse.py.

00141 
00142     def getwidth(self):
00143         # determine the width (min, max) for this subpattern
00144         if self.width:
00145             return self.width
00146         lo = hi = 0
00147         UNITCODES = (ANY, RANGE, IN, LITERAL, NOT_LITERAL, CATEGORY)
00148         REPEATCODES = (MIN_REPEAT, MAX_REPEAT)
00149         for op, av in self.data:
00150             if op is BRANCH:
00151                 i = sys.maxsize
00152                 j = 0
00153                 for av in av[1]:
00154                     l, h = av.getwidth()
00155                     i = min(i, l)
00156                     j = max(j, h)
00157                 lo = lo + i
00158                 hi = hi + j
00159             elif op is CALL:
00160                 i, j = av.getwidth()
00161                 lo = lo + i
00162                 hi = hi + j
00163             elif op is SUBPATTERN:
00164                 i, j = av[1].getwidth()
00165                 lo = lo + i
00166                 hi = hi + j
00167             elif op in REPEATCODES:
00168                 i, j = av[2].getwidth()
00169                 lo = lo + int(i) * av[0]
00170                 hi = hi + int(j) * av[1]
00171             elif op in UNITCODES:
00172                 lo = lo + 1
00173                 hi = hi + 1
00174             elif op == SUCCESS:
00175                 break
00176         self.width = int(min(lo, sys.maxsize)), int(min(hi, sys.maxsize))
00177         return self.width

def sre_parse.SubPattern.insert (   self,
  index,
  code 
)

Definition at line 137 of file sre_parse.py.

00137 
00138     def insert(self, index, code):
        self.data.insert(index, code)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 95 of file sre_parse.py.

Definition at line 92 of file sre_parse.py.

Definition at line 96 of file sre_parse.py.


The documentation for this class was generated from the following file: