Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Member Functions
ResourceRegistries.tools.packer.Packer Class Reference
Inheritance diagram for ResourceRegistries.tools.packer.Packer:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def copy
def pack
def protect
def sub
def keywordSub

Public Attributes

 patterns
 replacelist

Private Member Functions

def _repl

Detailed Description

Definition at line 214 of file packer.py.


Constructor & Destructor Documentation

Definition at line 215 of file packer.py.

00215 
00216     def __init__(self):
00217         self.patterns = []


Member Function Documentation

def ResourceRegistries.tools.packer.Packer._repl (   self,
  match 
) [private]

Definition at line 223 of file packer.py.

00223 
00224     def _repl(self, match):
00225         # store protected part
00226         self.replacelist.append(match.group(1))
00227         # return escaped index
00228         return "\x00%i\x00" % len(self.replacelist)

Definition at line 218 of file packer.py.

00218 
00219     def copy(self):
00220         result = Packer()
00221         result.patterns = self.patterns[:]
00222         return result

def ResourceRegistries.tools.packer.Packer.keywordSub (   self,
  pattern,
  keyword_encoder,
  flags = None 
)

Definition at line 269 of file packer.py.

00269 
00270     def keywordSub(self, pattern, keyword_encoder, flags=None):
00271         if flags is None:
00272             self.patterns.append((re.compile(pattern), None, keyword_encoder))
00273         else:
00274             self.patterns.append((re.compile(pattern, flags), None, keyword_encoder))
00275 

Here is the caller graph for this function:

def ResourceRegistries.tools.packer.Packer.pack (   self,
  input 
)

Definition at line 229 of file packer.py.

00229 
00230     def pack(self, input):
00231         # list of protected parts
00232         self.replacelist = []
00233         output = input
00234         for regexp, replacement, keyword_encoder in self.patterns:
00235             if replacement is None:
00236                 if keyword_encoder is None:
00237                     # protect the matched parts
00238                     output = regexp.sub(self._repl, output)
00239                 else:
00240                     mapper = KeywordMapper(regexp=regexp,
00241                                            encoder=keyword_encoder)
00242                     # get keywords
00243                     mapper.analyse(output)
00244                     # replace keywords
00245                     output = mapper.sub(output)
00246             else:
00247                 # substitute
00248                 output = regexp.sub(replacement, output)
00249         # restore protected parts
00250         replacelist = list(enumerate(self.replacelist))
00251         replacelist.reverse() # from back to front, so 1 doesn't break 10 etc.
00252         for index, replacement in replacelist:
00253             # we use lambda in here, so the real string is used and no escaping
00254             # is done on it
00255             before = len(output)
00256             regexp = re.compile('\x00%i\x00' % (index+1))
00257             output = regexp.sub(lambda m:replacement, output)
00258         # done
00259         return output

def ResourceRegistries.tools.packer.Packer.protect (   self,
  pattern,
  flags = None 
)

Definition at line 260 of file packer.py.

00260 
00261     def protect(self, pattern, flags=None):
00262         self.keywordSub(pattern, None, flags)

Here is the call graph for this function:

Here is the caller graph for this function:

def ResourceRegistries.tools.packer.Packer.sub (   self,
  pattern,
  replacement,
  flags = None 
)

Definition at line 263 of file packer.py.

00263 
00264     def sub(self, pattern, replacement, flags=None):
00265         if flags is None:
00266             self.patterns.append((re.compile(pattern), replacement, None))
00267         else:
00268             self.patterns.append((re.compile(pattern, flags), replacement, None))

Here is the caller graph for this function:


Member Data Documentation

Definition at line 216 of file packer.py.

Definition at line 231 of file packer.py.


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