tensor/logs/parsers.py
def _parse_format(self, format):
        """
        Converts the input format to a regular
        expression, as well as extracting fields

        Raises an exception if it couldn't compile
        the generated regex.
        """
        format = format.strip()
        format = re.sub('[ \t]+',' ',format)
        
        subpatterns = []

        findquotes = re.compile(r'^\\"')
        findreferreragent = re.compile('Referer|User-Agent')
        findpercent = re.compile('^%.*t$')
        lstripquotes = re.compile(r'^\\"')
        rstripquotes = re.compile(r'\\"$')
        header = re.compile(r'.*%\{([^\}]+)\}i')
        
        for element in format.split(' '):

            hasquotes = 0
            if findquotes.search(element): hasquotes = 1

            if hasquotes:
                element = lstripquotes.sub('', element)
                element = rstripquotes.sub('', element)
            
            head = header.match(element)
            if head:
                self._names.append(head.groups()[0].lower())
                self._types.append(str)
            else:
                self._names.append(self.alias(element))
                self._types.append(self.types.get(element, [None, str])[1])
            
            subpattern = '(\S*)'
            
            if hasquotes:
                if element == '%r' or findreferreragent.search(element):
                    subpattern = r'\"([^"\\]*(?:\\.[^"\\]*)*)\"'
                else:
                    subpattern = r'\"([^\"]*)\"'
                
            elif findpercent.search(element):
                subpattern = r'(\[[^\]]+\])'
                
            elif element == '%U':
                subpattern = '(.+?)'
            
            subpatterns.append(subpattern)
        
        self._pattern = '^' + ' '.join(subpatterns) + '$'
        try:
            self._regex = re.compile(self._pattern)
        except Exception as e:
            raise ApacheLogParserError(e)
def _parse_format(self, format):
        format = format.strip()
        format = re.sub('[ \t]+',' ',format)
        
        subpatterns = []

        findquotes = re.compile(r'^\\"')
        findreferreragent = re.compile('Referer|User-Agent')
        findpercent = re.compile('^%.*t$')
        lstripquotes = re.compile(r'^\\"')
        rstripquotes = re.compile(r'\\"$')
        header = re.compile(r'.*%\{([^\}]+)\}i')
        
        for element in format.split(' '):

            hasquotes = 0
            if findquotes.search(element): hasquotes = 1

            if hasquotes:
                element = lstripquotes.sub('', element)
                element = rstripquotes.sub('', element)
            
            head = header.match(element)
            if head:
                self._names.append(head.groups()[0].lower())
                self._types.append(str)
            else:
                self._names.append(self.alias(element))
                self._types.append(self.types.get(element, [None, str])[1])
            
            subpattern = '(\S*)'
            
            if hasquotes:
                if element == '%r' or findreferreragent.search(element):
                    subpattern = r'\"([^"\\]*(?:\\.[^"\\]*)*)\"'
                else:
                    subpattern = r'\"([^\"]*)\"'
                
            elif findpercent.search(element):
                subpattern = r'(\[[^\]]+\])'
                
            elif element == '%U':
                subpattern = '(.+?)'
            
            subpatterns.append(subpattern)
        
        self._pattern = '^' + ' '.join(subpatterns) + '$'
        try:
            self._regex = re.compile(self._pattern)
        except Exception as e:
            raise ApacheLogParserError(e)
def _parse_format ( self , format ) : format = format . strip ( ) format = re . sub ( '[ \t]+' , ' ' , format ) subpatterns = [ ] findquotes = re . compile ( r'^\\"' ) findreferreragent = re . compile ( 'Referer|User-Agent' ) findpercent = re . compile ( '^%.*t$' ) lstripquotes = re . compile ( r'^\\"' ) rstripquotes = re . compile ( r'\\"$' ) header = re . compile ( r'.*%\{([^\}]+)\}i' ) for element in format . split ( ' ' ) : hasquotes = 0 if findquotes . search ( element ) : hasquotes = 1 if hasquotes : element = lstripquotes . sub ( '' , element ) element = rstripquotes . sub ( '' , element ) head = header . match ( element ) if head : self . _names . append ( head . groups ( ) [ 0 ] . lower ( ) ) self . _types . append ( str ) else : self . _names . append ( self . alias ( element ) ) self . _types . append ( self . types . get ( element , [ None , str ] ) [ 1 ] ) subpattern = '(\S*)' if hasquotes : if element == '%r' or findreferreragent . search ( element ) : subpattern = r'\"([^"\\]*(?:\\.[^"\\]*)*)\"' else : subpattern = r'\"([^\"]*)\"' elif findpercent . search ( element ) : subpattern = r'(\[[^\]]+\])' elif element == '%U' : subpattern = '(.+?)' subpatterns . append ( subpattern ) self . _pattern = '^' + ' ' . join ( subpatterns ) + '$' try : self . _regex = re . compile ( self . _pattern ) except Exception as e : raise ApacheLogParserError ( e )
Converts the input format to a regular
        expression, as well as extracting fields

        Raises an exception if it couldn't compile
        the generated regex.
Converts the input format to a regular expression as well as extracting fields