def get_valid_user_by_email(email): """ Return user instance """ user = get_user(email) if user: if user.valid is False: return Err("user not valid") return Ok(user) return Err("user not exists")
def client(self): if self.check_lock(): with open(getpath(self.abs_path, '.reps'), 'r') as f: ak, sk, bk = f.read().split(' ') self.ak = ak.strip() self.sk = sk.strip() self.bucket = bk.strip() return Ok(Auth(self.ak, self.sk)) return Err("Err:Folder not inited!")
def update_reponsitory(self, ak, sk, bk): """ 更新rep :param ak: :type ak: :param sk: :type sk: :return: :rtype: """ if not self.check_lock(): return Err("Err:Folder not inited!") self.ak = ak self.sk = sk self.bucket = bk self.set_lock() return Ok('')
def new_reponsitory(self, ak, sk, bk): """ 新建rep :param ak: :type ak: :param sk: :type sk: :return: :rtype: """ if self.check_lock(): return Err("Err:Folder already inited!") self.ak = ak self.sk = sk self.bucket = bk self.set_lock() return Ok('')
def upfile(self, fk, fn): """ 实际上传文件 :param fk: :type fk: :param fn: :type fn: :return: :rtype: """ try: token = self.q.upload_token(self.reponsitoryConfig.bucket, fk, 120) ret, info = put_file(token, fk, fn) assert ret['key'] == fk, 'up faild' return Ok('') except: return Err('Err:upfile %s faild' % fk)
def auth(self): rs = self.reponsitoryConfig.client() if rs == Result.Ok: self.q = rs() return Ok('') return Err('Err:Invalid AK and SK')
def testEqError(self): rs = Err("error") self.assertTrue(rs == Result.Err, 'test result equal failure fail')
def testGetErrorData(self): err = Err('error') self.assertEqual(err(), 'error', 'test get error data fail')