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 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 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 testEqSuccess(self): rs = Ok() self.assertTrue(rs == Result.Ok, 'test result equal success fail')
def testGetMultiSuccessData(self): ok = Ok(1, 2) n1, n2 = ok() self.assertEqual(n1, 1, 'test get multi success data1 fail') self.assertEqual(n2, 2, 'test get multi success data2 fail')
def testGetSuccessData(self): ok = Ok(1) self.assertEqual(ok(), 1, 'test get success data fail')