def writeLog(self, collectedLog):
     if self._out is None:
         return
     if self._rejectLog(collectedLog):
         return
     httpRequest = getScoped(collectedLog, scopeNames=(), key='httpRequest')
     httpResponse = getScoped(collectedLog, scopeNames=(), key='httpResponse')
     if not 'Client' in httpRequest:
         return
     headers = getFirst(httpRequest, 'Headers', {})
     template = APACHE_LOGLINE
     exception = getFirst(httpResponse, 'exception')
     if exception:
         template = ERROR_LOGLINE
     self._out.write(template.format(
         ipaddress=getFirst(httpRequest, key='Client', default=('-', 0))[0],
         user='******',
         timestamp=strftime('%d/%b/%Y:%H:%M:%S +0000', gmtime(getFirst(httpRequest, 'timestamp'))),
         Method=getFirst(httpRequest, 'Method', '-'),
         pathAndQuery=stripToPathAndQuery(getFirst(httpRequest, 'RequestURI', '')),
         status=getFirst(httpResponse, 'httpStatus', '0'),
         responseSize=getFirst(httpResponse, 'size') or '-',
         Referer=headers.get('Referer', '-'),
         UserAgent=headers.get('User-Agent', '-'),
         HTTPVersion=getFirst(httpRequest, 'HTTPVersion', '1.0'),
         Exception=None if not exception else repr(exception)
     ))
     self._out.flush()
Beispiel #2
0
 def writeLog(self, collectedLog):
     if self._out is None:
         return
     if self._rejectLog(collectedLog):
         return
     httpRequest = getScoped(collectedLog, scopeNames=(), key='httpRequest')
     httpResponse = getScoped(collectedLog,
                              scopeNames=(),
                              key='httpResponse')
     if not 'Client' in httpRequest:
         return
     headers = getFirst(httpRequest, 'Headers', {})
     template = APACHE_LOGLINE
     exception = getFirst(httpResponse, 'exception')
     if exception:
         template = ERROR_LOGLINE
     self._out.write(
         template.format(
             ipaddress=getFirst(httpRequest, key='Client',
                                default=('-', 0))[0],
             user='******',
             timestamp=strftime('%d/%b/%Y:%H:%M:%S +0000',
                                gmtime(getFirst(httpRequest, 'timestamp'))),
             Method=getFirst(httpRequest, 'Method', '-'),
             pathAndQuery=stripToPathAndQuery(
                 getFirst(httpRequest, 'RequestURI', '')),
             status=getFirst(httpResponse, 'httpStatus', '0'),
             responseSize=getFirst(httpResponse, 'size') or '-',
             Referer=headers.get('Referer', '-'),
             UserAgent=headers.get('User-Agent', '-'),
             HTTPVersion=getFirst(httpRequest, 'HTTPVersion', '1.0'),
             Exception=None if not exception else repr(exception)))
     self._out.flush()
def createPreAnalySheet(gramar: list):
    '''
    
    :param gramar:  文法
    :return:  预测分析表 字典 key(非终结者符,终结者) value(预测替换的式子)
    '''
    # 获取所有非终结符
    res = {}
    follow = getFollow(gramar)
    first = getFirst(gramar)
    for l, r in gramar:
        # #print(l, r, 'yyy')
        key = l + '->' + ''.join(r)
        fst = getFirstSet(gramar, first, key)[0]

        if 'none' in fst:
            follow_ = getFollowSet(follow, l)[0]
            append(fst, follow_)
        for s in fst:
            if s != 'none':
                key_ = l + '->' + s
                res[key_] = r
                # if key_ in res:
                #     res[key_].append(r)
                # else:
                #     res[key_] = [r]

    return res
def isLL1(grammar):
    '''
    判断grammar是不是以S_开头的LL1文法
    :param grammar:
    :return:
    '''
    #判断是不是以S_开头的
    if grammar[0][0] != 'S_':
        return False

    # 判断是否左递归
    for l, r in grammar:
        if l == r[0]:
            return False

    #判断First相交
    first = getFirst(grammar)
    Vt = get_NVT(grammar)  #获取全部非终结符
    follow = getFollow(grammar)
    for v in Vt:
        res_v = []
        for l, r in grammar:
            if l == v:
                fg = append(res_v, first[l + '->' + ''.join(r)])
                if fg:  #有交集
                    return False
        if 'none' in res_v:
            follow_v = getFollowSet(follow, v)
            for f in follow_v:
                if f in res_v:  # 某非终结符含空的First集和其follow其有交集
                    return False
    return True
Beispiel #5
0
def closeure(I: list, Gramar: list):
    '''
    计算制定项目集的闭包
    :param I:  给定项目集  [[('X',['E'->'A'], a)], ...]
    :param Gramar:  给定文法
    :return:  返回项目集闭包
    '''

    J = I[:]  #deep copy
    first = getFirst(Gramar)
    while True:
        fg = False
        for l, r, c in J:
            idx = list(r).index('.')
            if idx < len(r) - 1 and r[idx + 1][0].isupper():  # A -> * . B * 形式
                for lg, rg in Gramar:
                    fs = get_FirstSet_full(Gramar, first, r[idx + 2:] +
                                           [c])  #  求First(后面的* 后接着c)
                    for b in fs:
                        if lg == r[idx + 1] and (lg, ['.'] + rg, b) not in J:
                            fg = True
                            J.append((lg, ['.'] + rg, b))
        if not fg:
            break
    return J
 def _queryArguments(self, collectedLog):
     args = collectedLog
     if self._argumentSelectionScope is not None:
         args = getScoped(collectedLog, scopeNames=self._scopeNames, key=self._argumentSelectionScope)
     if self._argumentSelectionKey is not None:
         args = getFirst(
             args,
             key=self._argumentSelectionKey,
             default={}
         )
     try:
         args = self.call.determineQueryArguments(collectedLog=collectedLog, scopeNames=self._scopeNames, currentArgs=args)
     except NoneOfTheObserversRespond:
         pass
     return sortedUrlEncode(args)
    def writeLog(self, collectedLog):
        if not scopePresent(collectedLog, self._scopeNames):
            return
        httpRequest = getScoped(collectedLog, scopeNames=self._scopeNames, key='httpRequest')
        httpResponse = getScoped(collectedLog, scopeNames=self._scopeNames, key='httpResponse')
        if not 'Client' in httpRequest:
            return

        path = getFirst(httpRequest, 'path')
        self._log.log(
            timestamp=getFirst(httpRequest, 'timestamp') or time(),
            path=path,
            ipAddress=getFirst(httpRequest, 'Client')[0],
            size=getFirst(httpResponse, 'size', 0)/1024.0,
            duration=getFirst(httpResponse, 'duration'),
            numberOfRecords=self._numberOfRecords(collectedLog),
            queryArguments=self._queryArguments(collectedLog),
            status=getFirst(httpResponse, 'httpStatus', '0'),
        )
 def _numberOfRecords(self, collectedLog):
     return getFirst(getScoped(collectedLog, scopeNames=self._scopeNames, key=self._numberOfRecordsSelectionScope), self._numberOfRecordsSelectionKey)