Ejemplo n.º 1
0
 def flushImpl(self, final=0):
   self._flushed = 1
   s = self._buf.getvalue()
   self._buf = StringIO()
   if self._space:
     s = spyceUtil.spaceCompact(s)
   if self._gzip:
     self._gzip.write(s)
     self._gzip.flush()
     if final:
       self._module._api.getModule('response').addHeader('Content-Encoding', 'gzip')
       self._gzip.close()
       self._gzip = None
     s = self._gzipfile.getvalue()
     self._gzipfile.truncate(0)
   self.next.write(s)
Ejemplo n.º 2
0
 def flushImpl(self, final=0):
     self._flushed = 1
     s = self._buf.getvalue()
     self._buf = StringIO()
     if self._space:
         s = spyceUtil.spaceCompact(s)
     if self._gzip:
         self._gzip.write(s)
         self._gzip.flush()
         if final:
             self._module._api.getModule('response').addHeader(
                 'Content-Encoding', 'gzip')
             self._gzip.close()
             self._gzip = None
         s = self._gzipfile.getvalue()
         self._gzipfile.truncate(0)
     self.next.write(s)
Ejemplo n.º 3
0
 def compaction(self, ast):
     elements, leafs = ast['elements'], ast['leafs']
     compact = COMPACT_LINE
     for el in elements.keys():
         self.compaction(elements[el])
     if leafs:
         i = 0
         while i < len(leafs):
             type, text, ref = leafs[i]
             if type == AST_COMPACT:
                 compact = text
             elif type == AST_TEXT:
                 # line compaction
                 if compact == COMPACT_LINE or compact == COMPACT_FULL:
                     # remove any trailing whitespace
                     text = string.split(text, '\n')
                     for j in range(len(text) - 1):
                         text[j] = string.rstrip(text[j])
                     text = string.join(text, '\n')
                     # gobble the end of the line
                     ((row, _), _, _, file) = ref
                     rowtext = string.split(text, '\n')
                     if rowtext: rowtext = string.strip(rowtext[0])
                     crow = row
                     cfile = file
                     j = i
                     while j and not rowtext:
                         j = j - 1
                         type2, text2, ref2 = leafs[j]
                         if ref2: (_, (crow, _), _, cfile) = ref2
                         if crow != row or file != cfile: break
                         if type2 == AST_TEXT:
                             text2 = string.split(text2, '\n')
                             if text2: text2 = text2[-1]
                             rowtext = rowtext + string.strip(text2)
                         elif type2 == AST_PYEVAL:
                             rowtext = 'x'
                     if not rowtext:
                         text = string.split(text, '\n')
                         if text and not string.strip(text[0]):
                             text = text[1:]
                         text = string.join(text, '\n')
                     # gobble beginning of the line
                     (_, (row, _), _, file) = ref
                     rowtext = string.split(text, '\n')
                     if rowtext: rowtext = string.strip(rowtext[-1])
                     crow = row
                     cfile = file
                     j = i + 1
                     while j < len(leafs) and not rowtext:
                         type2, text2, ref2 = leafs[j]
                         if ref2: ((crow, _), _, _, cfile) = ref2
                         if crow != row or file != cfile: break
                         if type2 == AST_TEXT:
                             text2 = string.split(text2, '\n')
                             if text2: text2 = text2[0]
                             rowtext = rowtext + string.strip(text2)
                         elif type2 == AST_PYEVAL:
                             rowtext = 'x'
                         j = j + 1
                     if not rowtext:
                         text = string.split(text, '\n')
                         if text: text[-1] = string.strip(text[-1])
                         text = string.join(text, '\n')
                 # space compaction
                 if compact == COMPACT_SPACE or compact == COMPACT_FULL:
                     text = spyceUtil.spaceCompact(text)
                 # update text, if any
                 if text: leafs[i] = type, text, ref
                 else:
                     del leafs[i]
                     i = i - 1
             elif type in [AST_PY, AST_PYEVAL]:
                 pass
             else:
                 raise 'error: unknown AST node type'
             i = i + 1
Ejemplo n.º 4
0
 def compaction(self, ast):
   elements, leafs = ast['elements'], ast['leafs']
   compact = COMPACT_LINE
   for el in elements.keys():
     self.compaction(elements[el])
   if leafs:
     i = 0
     while i<len(leafs):
       type, text, ref = leafs[i]
       if type==AST_COMPACT:
         compact = text
       elif type==AST_TEXT:
         # line compaction
         if compact==COMPACT_LINE or compact==COMPACT_FULL:
           # remove any trailing whitespace
           text = string.split(text, '\n')
           for j in range(len(text)-1):
             text[j] = string.rstrip(text[j])
           text = string.join(text, '\n')
           # gobble the end of the line
           ((row, _), _, _, file) = ref
           rowtext = string.split(text, '\n')
           if rowtext: rowtext = string.strip(rowtext[0])
           crow = row ; cfile = file
           j = i
           while j and not rowtext:
             j = j - 1
             type2, text2, ref2 = leafs[j]
             if ref2: (_, (crow, _), _, cfile) = ref2
             if crow != row or file != cfile: break
             if type2 == AST_TEXT:
               text2 = string.split(text2, '\n')
               if text2: text2 = text2[-1]
               rowtext = rowtext + string.strip(text2)
             elif type2 == AST_PYEVAL:
               rowtext = 'x'
           if not rowtext:
             text = string.split(text, '\n')
             if text and not string.strip(text[0]):
               text = text[1:]
             text = string.join(text, '\n')
           # gobble beginning of the line
           (_, (row, _), _, file) = ref
           rowtext = string.split(text, '\n')
           if rowtext: rowtext = string.strip(rowtext[-1])
           crow = row ; cfile = file
           j = i + 1
           while j<len(leafs) and not rowtext:
             type2, text2, ref2 = leafs[j]
             if ref2: ((crow, _), _, _, cfile) = ref2
             if crow != row or file != cfile: break
             if type2 == AST_TEXT:
               text2 = string.split(text2, '\n')
               if text2: text2 = text2[0]
               rowtext = rowtext + string.strip(text2)
             elif type2 == AST_PYEVAL:
               rowtext = 'x'
             j = j + 1
           if not rowtext:
             text = string.split(text, '\n')
             if text: text[-1] = string.strip(text[-1])
             text = string.join(text, '\n')
         # space compaction
         if compact==COMPACT_SPACE or compact==COMPACT_FULL:
           text = spyceUtil.spaceCompact(text)
         # update text, if any
         if text: leafs[i] = type, text, ref
         else: 
           del leafs[i]
           i = i -1
       elif type in [AST_PY, AST_PYEVAL]:
         pass
       else:
         raise 'error: unknown AST node type'
       i = i + 1