Exemplo n.º 1
0
class RecipeFormPage(Page):
    form = Element('.recipe-form')
    name = FormField('[name="name"]')
    enabled = FormField('[name="enabled"]')
    extra_filter_expression = FormField('[name="extra_filter_expression"]')
    action = SelectField('select[name="action"]')
    delete_button = Element('a.delete')
Exemplo n.º 2
0
 def scanIdentifier(self):
     s = ""
     while True:
         c = self.getc()
         if c == '':
             break
         if not (c.isdigit() or c.isalpha() or c == '_'):
             self.goback()
             break
         s += c
     if s in keywords:
         return Token(Element('"' + s + '"'), s, self.row, self.col)
     else:
         return Token(Element('"IDN"'), s, self.row, self.col)
Exemplo n.º 3
0
 def onlineParse(self, token, initFlag):
     if initFlag:
         self.stateStack = [self.initialState]
         self.symbolStack = [Element('"#"')]
     w = token.elem
     print("---------------------------")
     print(w)
     S = self.stateStack[-1]
     if w not in self.action[S]:
         print("Failed")
         raise Exception("Parse Failed")
         return False
     if self.action[S][w][0] == Action.Reduce:
         while w in self.action[S] and self.action[S][w][0] == Action.Reduce:
             rule = self.action[S][w][1]
             A = rule.L
             if rule.R[0] != self.empty:
                 self.stateStack = self.stateStack[:-len(rule.R)]
                 self.symbolStack = self.symbolStack[:-len(rule.R)]
             S = self.stateStack[-1]
             self.symbolStack.append(A)
             self.stateStack.append(self.goto[S][A])
             S = self.stateStack[-1]
             print("Reduction:", rule)
     S = self.stateStack[-1]
     if self.action[S][w][0] == Action.Shift:
         self.symbolStack.append(w)
         self.stateStack.append(self.action[S][w][1])
     # for i in range(len(self.stateStack)):
     #     self.printClosure(self.stateStack[i])
     #     print(self.symbolStack[i])
     if self.action[S][w][0] == Action.Acc:
         print("OK")
         return True
Exemplo n.º 4
0
 def __init__(self, cfl_file_name):
     self.cfl = pickle.load(open(cfl_file_name, "rb"))
     self.stateStack = [self.cfl.initialState]
     self.symbolStack = [(SynInfo(), Element('"#"'))]
     self.tableStack = [SymbolTable()]
     self.offsetStack = [0]
     self.tempCount = 0
     self.labelCount = 0
Exemplo n.º 5
0
 def __init__(self):
     self.rules = []
     self.elementsDict = {}
     self.elements = []
     self.starter = ""
     self.ender = ""
     self.first = {}
     self.empty = Element('"$"')
Exemplo n.º 6
0
class RecipeFormPage(Page):
    form = Element('.recipe-form')
    name = FormField('[name="name"]')
    extra_filter_expression = FormField('[name="extra_filter_expression"]')
    action = SelectField('select[name="action"]')
    delete_button = Element('a.action-delete')
    request_approval_button = Element('.action-request')
    approve_button = Element('.action-approve')
    reject_button = Element('.action-reject')
    approve_comment = FormField('.approve-dropdown textarea')
    reject_comment = FormField('.reject-dropdown textarea')
    approve_confirm_button = Element('.approve-dropdown .mini-button')
    reject_confirm_button = Element('.reject-dropdown .mini-button')
    approved_status_indicator = Element('.status-indicator.approved')
    rejected_status_indicator = Element('.status-indicator.rejected')
Exemplo n.º 7
0
class LoginPage(Page):
    form = Element('#login-form')
    username = FormField('#id_username')
    password = FormField('#id_password')

    def login(self, username=None, password=None):
        self.wait_for_element('form')
        self.username = username or 'user1'
        self.password = password or 'testpass'
        self.password.submit()
Exemplo n.º 8
0
class LoginPage(Page):
    form = Element('#login-form')
    username = FormField('#id_username')
    password = FormField('#id_password')

    def login(self):
        self.wait_for_element('form')
        self.username = '******'
        self.password = '******'
        self.password.submit()
Exemplo n.º 9
0
    def parse(self, sentence):
        i = 0
        s = []
        while i < len(sentence):
            if sentence[i] == '[':
                j = i + 1
                while sentence[j] != '[':
                    j += 1
                s.append(self.elementsDict[sentence[i:j + 1]])
                i = j + 1
            elif sentence[i] == '"':
                j = i + 1
                while sentence[j] != '"':
                    j += 1
                s.append(self.elementsDict[sentence[i:j + 1]])
                i = j + 1
            else:
                i += 1
        for w in s:
            print(w)

        stateStack = [self.initialState]
        symbolStack = [Element('"#"')]
        i = 0
        while i < len(s):
            print("---------------------------")
            w = s[i]
            print(w)
            S = stateStack[-1]
            for j in range(len(stateStack)):
                self.printClosure(stateStack[j])
                print(symbolStack[j])
            if w not in self.action[S]:
                return False
            elif self.action[S][w][0] == Action.Shift:
                symbolStack.append(w)
                stateStack.append(self.action[S][w][1])
                i += 1
            elif self.action[S][w][0] == Action.Reduce:
                rule = self.action[S][w][1]
                A = rule.L
                print("Reduce", rule)
                if rule.R[0] != self.empty:
                    stateStack = stateStack[:-len(rule.R)]
                    symbolStack = symbolStack[:-len(rule.R)]
                S = stateStack[-1]
                symbolStack.append(A)
                stateStack.append(self.goto[S][A])
            elif self.action[S][w][0] == Action.Acc:
                print("OK")
                return True
Exemplo n.º 10
0
 def initActionGoto(self):
     self.goto = dict()
     self.action = dict()
     for clos in self.C:
         self.goto[clos] = dict()
         self.action[clos] = dict()
         for var in self.elements:
             if var.code == Code.Variable:
                 goto_tmp = self.go(clos, var)
                 if goto_tmp in self.C:
                     self.goto[clos][var] = goto_tmp
         for item in clos:
             if item[1] >= len(item[0].R):
                 self.action[clos][item[2]] = (Action.Reduce, item[0])
             else:
                 a = item[0].R[item[1]]
                 if a == self.empty:
                     raise Exception("Found empty in initActionGoto")
                 if a.code != Code.Variable:
                     self.action[clos][a] = (Action.Shift, self.go(clos, a))
             if self.rules[-1] == item[0] and item[1] == 1 and item[
                     2] == Element('"#"'):
                 self.action[clos][Element('"#"')] = (Action.Acc, 0)
Exemplo n.º 11
0
 def scanSymbol(self):
     symbol = ""
     while True:
         c = self.getc()
         if c == '':
             break
         if c not in "!,+-*/%=(){}[];<>|^&:\"":
             self.goback()
             break
         if (symbol + c) in Code.__dict__:
             symbol += c
         else:
             self.goback()
             break
     return Token(Element('"' + symbol + '"'), symbol, self.row, self.col)
Exemplo n.º 12
0
 def scanInteger(self):
     number = 0
     isDecimal = False
     decimal = 0
     factor = 1
     while True:
         c = self.getc()
         if c.isdigit():
             if not decimal:
                 number = number * 10 + int(c)
             else:
                 factor /= 10
                 decimal = decimal + factor * int(c)
         elif c == '.':
             if isDecimal == True:
                 raise Exception("Repeated '.'!")
             isDecimal = True
         else:
             self.goback()
             break
     if isDecimal:
         return Token(Element('"FLOAT"'), number, self.row, self.col)
     else:
         return Token(Element('"INT10"'), number, self.row, self.col)
Exemplo n.º 13
0
 def scan(self):
     while True:
         c = self.getc()
         if c == "":
             return Token(Element('"#"'), "", self.row, self.col)
         if c == " ":
             continue
         if c in "!,+-*/%=(){}[];<>|^&:\"":
             self.goback()
             return self.scanSymbol()
         elif c.isdigit():
             self.goback()
             return self.scanInteger()
         elif c.isalpha() or c == '_':
             self.goback()
             return self.scanIdentifier()
Exemplo n.º 14
0
class RecipeDeletePage(Page):
    form = Element('.crud-form')
    confirm_button = Element('.delete[type="submit"]')
Exemplo n.º 15
0
class RecipeListPage(Page):
    recipe_list = Element('.recipe-list')
    recipe_rows = ElementGroup('.recipe-list tbody tr')
    new_recipe_button = Element('.button[href*="/control/recipe/new"]')
Exemplo n.º 16
0
 def addElement(self, eleStr):
     if eleStr not in self.elementsDict:
         self.elements.append(Element(eleStr))
         self.elementsDict[eleStr] = self.elements[-1]
     return self.elementsDict[eleStr]