Ejemplo n.º 1
0
 def add_token(self,user,token):
     token_map=self.db.find_one(DB.TOKEN_TABLE,{DB.USER_NAME_KEY:user})
     if not token_map:
         token_map={DB.USER_NAME_KEY:user,DB.TOKEN_KEY:token,DB.MD5_KEY:MD5.get(token)}
         self.db.insert(DB.TOKEN_TABLE,token_map)
     
     if token != token_map[DB.TOKEN_KEY]:
         token_map[DB.TOKEN_KEY]=token
         token_map[DB.MD5_KEY]=MD5.get(token)
         self.db.update(DB.TOKEN_TABLE,{DB.USER_NAME_KEY:user},token_map)
Ejemplo n.º 2
0
def decode_char(font_handler, char, use_image=False):
    json_md5 = MD5(font_handler.get_font_json(char))
    decoded_word = rc.hget(DECODE_KEY, json_md5)
    if decoded_word is None and use_image:
        image_path = font_handler.save_image(char)
        print(('发现新字体,生成图片:%s' % image_path), end=', ')
        decoded_word = input('请根据图片手动输入解码字符:')
        rc.hset(DECODE_KEY, json_md5, decoded_word)
        rc.hset(REVERSE_DECODE_KEY, decoded_word, json_md5)
    return decoded_word
Ejemplo n.º 3
0
    def _add_token(self):
        if not request.json:
            return jsonify({"error":HTTP_BAD_REQUEST_STR}),HTTP_BAD_REQUEST

        username=request.json[RestServer.USER_NAME]
        token_id=self.token_mgr.find_token_id(username)
        if not token_id:
            self.log.info("username %s find token failed, request keystone"%(username))
            token=self.auth.get_token(username,request.json[RestServer.PASSWORD])
            if not token:
                self.log.error("request token from keystone failed.")
                return jsonify({RestServer.RESULT:HTTP_UNAUTHORIZED_STR}),HTTP_UNAUTHORIZED 
            
            self.token_mgr.add_token(username,token)
            token_id=MD5.get(token)

        return jsonify({RestServer.TOKEN:token_id}),HTTP_OK
Ejemplo n.º 4
0
def add_font_map(font_handler, src_word, dst_word):
    json_md5 = MD5(font_handler.get_font_json(src_word))
    rc.hset(DECODE_KEY, json_md5, dst_word)
    rc.hset(REVERSE_DECODE_KEY, dst_word, json_md5)