示例#1
0
 def get(self):
     t = Token()
     userId = localStorage['payload']['sub']
     try:
         u = User.query.get(userId)
     except Exception as e:
         abort(500, message="Error %s" % e)
     if not u:
         abort(404, message="El usuario no existe")
     return {'message': 'Success!', 'token': t.encode(u.id, u.email, u.typ)}
示例#2
0
    def get_next_token(self):
        self.skip_whitespace()

        if self.pos >= len(self.text):
            return Token(EOF, None)

        current_char = self.text[self.pos]

        token = {}

        if current_char.isdigit():
            token = Token(INTEGER, self.parse_number())
        elif current_char == '+':
            token = Token(PLUS, '+')
        elif current_char == '-':
            token = Token(MINUS, '-')
        elif current_char == '/':
            token = Token(DIV, '/')
        elif current_char == '*':
            token = Token(MUL, '*')
        elif current_char == '(':
            token = Token(LPAREN, '(')
        elif current_char == ')':
            token = Token(RPAREN, ')')
        # since we are not using variables in input_mode = 1
        # checking if current char is letter is okay
        # for checking if next token is function
        elif current_char.isalpha():
            token = Token(FUN, self.parse_function())
        else:
            self.error("")

        self.pos += 1
        return token
示例#3
0
 def wrapper(*args, **kwargs):
     if not "Authorization" in request.headers.keys():
         abort(401, message="Unauthorized")
     t = Token()
     try:
         localStorage['payload'] = t.decode(
             request.headers['authorization'].split(' ')[1])
     except Exception as e:
         abort(500, message=e)
     except TypeError as e:
         abort(403, message=e)
     return func(*args, **kwargs)
示例#4
0
 def post(self):
     email = request.json['email']
     passw = request.json['passw']
     t = Token()
     try:
         u = User.query.filter_by(email=email).first()
     except Exception as e:
         abort(500, message="Error %s" % e)
     if not u:
         abort(404, message="El usuario no existe")
     if not u.check_pass(passw):
         abort(401, message="La contraseña no es correcta")
     return {'message': 'Success!', 'token': t.encode(u.id, u.email, u.typ)}
示例#5
0
    def __call__(self, request):

        isurlauth = Urls(request.path_info).isSafe

        if not isurlauth:
            try:
                token = Token(request.META['HTTP_AUTHORIZATION'])
            except KeyError:
                return JsonResponse(
                    {'error': "El request no tiene token de autorizacion"},
                    status=status.HTTP_400_BAD_REQUEST)

            if not token.validate:
                return JsonResponse({'error': "El token no es valido"},
                                    status=status.HTTP_403_FORBIDDEN)

        response = self.get_response(request)

        if not isurlauth:
            if token.refresh:
                data = response.data
                data['token'] = token.new
                return JsonResponse(data, status=response.status_code)

        return response
示例#6
0
    def auth(self, request):
        try:
            credentials = Request(request).data
            credentials["password"] = hashlib.md5(
                credentials["password"]).hexdigest()
            query = translate(UsuarioSerializer, credentials)
        except KeyError:
            return Response({}, status.HTTP_400_BAD_REQUEST,
                            "Envio erroneo de parametros")

        try:
            usuarios = Usuario.objects.filter(**query)

            if usuarios.count() is not 1:
                raise ObjectDoesNotExist

        except ObjectDoesNotExist:
            return Response({}, status.HTTP_404_NOT_FOUND,
                            "No se encontro el usuario")

        token = Token.getToken(UsuarioSerializer(usuarios[0]).data)

        return Response({'token': token})
示例#7
0
文件: lexer.py 项目: jelic98/raf_pp
 def parse_keyword(self):
         string = ''
         while(self.pos < len(self.text)
             and (self.text[self.pos].isalpha()
             or self.text[self.pos].isdigit()
             or self.text[self.pos] == '_'
             or self.text[self.pos] == '#'
             or self.text[self.pos] == '~')):
                 string += self.text[self.pos]
                 self.pos += 1
         self.pos -= 1
         if string == '#program':
                 return Token(PROGRAM_POCETAK, string)
         elif string == '##program':
                 return Token(PROGRAM_KRAJ, string)
         elif string == '#postojanje':
                 return Token(POSTOJANJE_POCETAK, string)
         elif string == '##postojanje':
                 return Token(POSTOJANJE_KRAJ, string)
         elif string == '#dodela':
                 return Token(DODELA_POCETAK, string)
         elif string == '##dodela':
                 return Token(DODELA_KRAJ, string)
         elif string == '#polje':
                 return Token(POLJE_POCETAK, string)
         elif string == '##polje':
                 return Token(POLJE_KRAJ, string)
         elif string == '#naredba':
                 return Token(NAREDBA_POCETAK, string)
         elif string == '##naredba':
                 return Token(NAREDBA_KRAJ, string)
         elif string == '#celina':
                 return Token(CELINA_POCETAK, string)
         elif string == '##celina':
                 return Token(CELINA_KRAJ, string)
         elif string == '#rutina':
                 return Token(RUTINA_POCETAK, string)
         elif string == '##rutina':
                 return Token(RUTINA_KRAJ, string)
         elif string == '#~rutina':
                 return Token(RUTINA_POZIV_POCETAK, string)
         elif string == '##~rutina':
                 return Token(RUTINA_POZIV_KRAJ, string)
         elif string == '#~ugradjena_rutina':
                 return Token(UGRADJENA_RUTINA_POZIV_POCETAK, string)
         elif string == '##~ugradjena_rutina':
                 return Token(UGRADJENA_RUTINA_POZIV_KRAJ, string)
         elif string == '#vrati':
                 return Token(VRATI_POCETAK, string)
         elif string == '##vrati':
                 return Token(VRATI_KRAJ, string)
         elif string == '#prekini_ponavljanje':
                 return Token(PREKINI_PONAVLJANJE, string)
         elif string == 'uslov':
                 return Token(NAREDBA_USLOV, string)
         elif string == 'ponavljanje':
                 return Token(NAREDBA_PONAVLJANJE, string)
         elif string == 'pitanje':
                 return Token(CELINA_PITANJE, string)
         elif string == 'da':
                 return Token(CELINA_DA, string)
         elif string == 'ne':
                 return Token(CELINA_NE, string)
         elif string == 'ponovi':
                 return Token(CELINA_PONOVI, string)
         elif string == 'polja':
                 return Token(CELINA_POLJA, string)
         elif string == 'sadrzaj_rutine':
                 return Token(CELINA_SADRZAJ_RUTINE, string)
         elif string == '~ceo_broj' or string == '~struna' or string == '~jeste_nije':
                 return Token(TIP_PODATKA, string)
         elif string == 'jeste' or string == 'nije':
                 return Token(JESTE_NIJE, string)
         return Token(NAZIV, string)
示例#8
0
文件: lexer.py 项目: jelic98/raf_pp
 def get_next_token(self):
         self.skip_whitespace()
         if self.pos >= len(self.text):
                 return Token(EOF, None)
         current_char = self.text[self.pos]
         token = None
         if current_char.isdigit():
                 token =  Token(CEO_BROJ, self.parse_number())
         elif self.text[self.pos].isalpha() or self.text[self.pos] == '#' or self.text[self.pos] == '~':
                 token = self.parse_keyword()
         elif current_char == '"':
                 token =  Token(STRUNA, self.parse_string())
         elif current_char == '+':
                 token =  Token(PLUS, '+')
         elif current_char == '-':
                 token = Token(MINUS, '-')
         elif current_char == '*':
                 token = Token(MNOZENJE, '*')
         elif current_char == '/':
                 token = Token(DELJENJE, '/')
         elif current_char == '%':
                 token = Token(OSTATAK, '%')
         elif current_char == '(':
                 token = Token(ZAGRADA_OTVORENA, '(')
         elif current_char == ')':
                 token = Token(ZAGRADA_ZATVORENA, ')')
         elif current_char == '<':
                 token = Token(MANJE, '<')
         elif current_char == '>':
                 token = Token(VECE, '>')
         elif current_char == '<=':
                 token = Token(MANJE_JEDNAKO, '<')
         elif current_char == '>=':
                 token = Token(VECE_JEDNAKO, '>')
         elif current_char == '=':
                 token = Token(JEDNAKO, '=')
         elif current_char == ':':
             token = Token(COLON, ':')
         elif current_char == ',':
             token = Token(COMMA, ',')
         elif current_char == '<':
                 token = Token(MANJE, '<')
         elif current_char == '>':
                 token = Token(VECE, '>')
         elif current_char == '<=':
                 token = Token(MANJE_JEDNAKO, '<')
         elif current_char == '>=':
                 token = Token(VECE_JEDNAKO, '>')
         elif current_char == '=':
                 token = Token(JEDNAKO, '=')
         elif current_char == ':':
                 token = Token(COLON, ':')
         elif current_char == ',':
                 token = Token(COMMA, ',')
         elif current_char == '!':
                 self.advance()
                 if self.current_char == '=':
                         token = Token(NIJE_JEDNAKO, '!=')
                 else:
                         token = Token(LOGICKO_NE, '!')
                         self.pos -= 1
         elif current_char == '&':
                 self.advance()
                 if self.current_char == '&':
                         token = Token(LOGICKO_I, '&&')
         elif current_char == '|':
                 self.advance()
                 if self.current_char == '|':
                         token = Token(LOGICKO_ILI, '||')
                 else:
                         token = Token(PIPE, '|')
                         self.pos -= 1
         else:
                 self.error(current_char)
         self.pos += 1
         return token
示例#9
0
文件: main.py 项目: jelic98/raf_pp
    def factor(self):
        token = self.current_token

        if token is None:
            return None

        # check if current token is function (only in input_mode = 1)
        if token.token_type == FUN:
            if token.value is None:
                print("Function not defined correctly")
                input_mode = 1
                return None

            # token value is tupple
            # first element is function map
            # second element is concrete usage of defined function
            fun = token.value[0]
            fun_call = token.value[1]

            # check if function is defined
            if not fun["name"] in funs:
                print("Function not defined")
                return None

            # get defined function
            fun_defined = funs[fun["name"]]

            # check parameter
            if len(fun["params"]) != len(fun_defined["params"]):
                print("Calling function {} with {} instead of {} parameters".
                      format(fun["name"], len(fun["params"]),
                             len(fun_defined["params"])))
                return None

            pos = 0

            # check if defined function has infinite recursion
            if (self.inf_recur(fun, fun["name"])):
                return None

            # put replacement expression in parenthesis to isolate computation
            expr = "(" + fun_defined["expr"] + ")"

            # replace defined parameters with concrete arguments
            for param in fun_defined["params"]:
                expr = expr.replace(param, fun["params"][pos])
                pos += 1

            # shift cursor to adapt to replacement expression
            self.lexer.pos = self.lexer.text.find(fun_call) + 1
            self.lexer.text = self.lexer.text.replace(fun_call, expr, 1)

            # resolve expression in parenthesis
            self.current_token = Token(LPAREN, "(")
            return self.factor()
        if token.token_type == INTEGER:
            self.eat(INTEGER)
            return token.value
        elif token.token_type == LPAREN:
            self.eat(LPAREN)
            result = self.expr()
            if not result is None:
                self.eat(RPAREN)
            return result
        elif token.token_type == MINUS:
            self.eat(MINUS)
            value = self.current_token.value
            self.eat(INTEGER)
            return (-1 * value)