Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Member Functions
kss.core.pluginregistry._concatresource.compression.thirdparty.packer.Packer Class Reference
Inheritance diagram for kss.core.pluginregistry._concatresource.compression.thirdparty.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 234 of file packer.py.


Constructor & Destructor Documentation

Definition at line 235 of file packer.py.

00235 
00236     def __init__(self):
00237         self.patterns = []

Here is the caller graph for this function:


Member Function Documentation

Definition at line 243 of file packer.py.

00243 
00244     def _repl(self, match):
00245         # store protected part
00246         self.replacelist.append(match.group(1))
00247         # return escaped index
00248         return "\x00%i" % len(self.replacelist)

Definition at line 238 of file packer.py.

00238 
00239     def copy(self):
00240         result = Packer()
00241         result.patterns = self.patterns[:]
00242         return result

Here is the caller graph for this function:

def kss.core.pluginregistry._concatresource.compression.thirdparty.packer.Packer.keywordSub (   self,
  pattern,
  keyword_encoder,
  flags = None 
)

Definition at line 292 of file packer.py.

00292 
00293     def keywordSub(self, pattern, keyword_encoder, flags=None):
00294         if flags is None:
00295             self.patterns.append((re.compile(pattern), None, keyword_encoder))
00296         else:
00297             self.patterns.append((re.compile(pattern, flags), None, keyword_encoder))
00298 

Here is the caller graph for this function:

Definition at line 249 of file packer.py.

00249 
00250     def pack(self, input):
00251         # list of protected parts
00252         self.replacelist = []
00253         # escape the escapechar
00254         output = input.replace('\x00','\x00\x00')
00255         for regexp, replacement, keyword_encoder in self.patterns:
00256             if replacement is None:
00257                 if keyword_encoder is None:
00258                     # protect the matched parts
00259                     output = regexp.sub(self._repl, output)
00260                 else:
00261                     mapper = KeywordMapper(regexp=regexp,
00262                                            encoder=keyword_encoder)
00263                     # get keywords
00264                     mapper.analyse(output)
00265                     # replace keywords
00266                     output = mapper.sub(output)
00267             else:
00268                 # substitute
00269                 output = regexp.sub(replacement, output)
00270         # restore protected parts
00271         replacelist = list(enumerate(self.replacelist))
00272         replacelist.reverse() # from back to front, so 1 doesn't break 10 etc.
00273         for index, replacement in replacelist:
00274             # we use lambda in here, so the real string is used and no escaping
00275             # is done on it
00276             before = len(output)
00277             regexp = re.compile('(?<!\x00)\x00%i' % (index+1))
00278             output = regexp.sub(lambda m:replacement, output)
00279         # unescape
00280         output = output.replace('\x00\x00','\x00')
00281         # done
00282         return output

Definition at line 283 of file packer.py.

00283 
00284     def protect(self, pattern, flags=None):
00285         self.keywordSub(pattern, None, flags)

Here is the call graph for this function:

Here is the caller graph for this function:

def kss.core.pluginregistry._concatresource.compression.thirdparty.packer.Packer.sub (   self,
  pattern,
  replacement,
  flags = None 
)

Definition at line 286 of file packer.py.

00286 
00287     def sub(self, pattern, replacement, flags=None):
00288         if flags is None:
00289             self.patterns.append((re.compile(pattern), replacement, None))
00290         else:
00291             self.patterns.append((re.compile(pattern, flags), replacement, None))

Here is the caller graph for this function:


Member Data Documentation

Definition at line 236 of file packer.py.

Definition at line 251 of file packer.py.


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