Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
ResourceRegistries.tools.packer.CSSPacker Class Reference
Inheritance diagram for ResourceRegistries.tools.packer.CSSPacker:
Inheritance graph
[legend]
Collaboration diagram for ResourceRegistries.tools.packer.CSSPacker:
Collaboration 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

Detailed Description

Definition at line 348 of file packer.py.


Constructor & Destructor Documentation

def ResourceRegistries.tools.packer.CSSPacker.__init__ (   self,
  level = 'safe' 
)

Definition at line 349 of file packer.py.

00349 
00350     def __init__(self, level='safe'):
00351         Packer.__init__(self)
00352         # protect strings
00353         # these sometimes catch to much, but in safe mode this doesn't hurt
00354         self.protect(r"""('(?:\\'|\\\n|.)*?')""")
00355         self.protect(r'''("(?:\\"|\\\n|.)*?")''')
00356         # strip whitespace
00357         self.sub(r'^[ \t\r\f\v]*(.*?)[ \t\r\f\v]*$', r'\1', re.MULTILINE)
00358         if level == 'full':
00359             # remove comments
00360             self.sub(r'/\*.*? ?[\\/*]*\*/', r'', re.DOTALL)
00361             #remove more whitespace
00362             self.sub(r'\s*([{,;:])\s+', r'\1')
00363         else:
00364             # remove comment contents
00365             self.sub(r'/\*.*?( ?[\\/*]*\*/)', r'/*\1', re.DOTALL)
00366             # remove lines with comments only (consisting of stars only)
00367             self.sub(r'^/\*+\*/$', '', re.MULTILINE)
00368         # excessive newlines
00369         self.sub(r'\n+', '\n')
00370         # first newline
00371         self.sub(r'^\n', '')
00372 

Here is the call graph for this function:


Member Function Documentation

def ResourceRegistries.tools.packer.Packer.copy (   self) [inherited]

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 
) [inherited]

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 
) [inherited]

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 
) [inherited]

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 
) [inherited]

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: