예제 #1
0
 def _request(self, req_id=None, params=None, data=None, cookies=None):
     params = {} if params is None else params
     data = {} if data is None else data
     cookies = {} if cookies is None else cookies
     if req_id not in REQUEST_TEMPLATE:
         LOG.error("Request cfg of %s not found" % req_id)
         return None
     return self._req(req_id, params, data, cookies)
예제 #2
0
 def __init__(self, file_path=""):
     LOG.info(u"session path:{}".format(file_path))
     self.file_path = file_path
     self.session = {}
     if self.file_path == "":
         LOG.error("session file path is empty which shouldn't happen")
     elif os.path.isfile(self.file_path):
         with open(self.file_path, "rb") as f:
             self.session = cPickle.load(f)
예제 #3
0
 def wrapper(*args, **kwargs):
     ret = func(*args, **kwargs)
     if type(ret) == requests.Response:
         try:
             foo = json.loads(ret.content.decode('utf-8'))
             if 'errno' in foo and foo['errno'] == -6:
                 LOG.debug('Offline, deleting cookies file then relogin.')
                 args[0]._remove_cookies()
                 args[0]._initiate()
         except:
             LOG.error('User unsigned in.')
     return ret
예제 #4
0
 def __init__(self, file_path=None, file_type="json"):
     LOG.info(u"cfg path:{}".format(file_path))
     self.path = file_path
     self.type = file_type
     if self.path is None:
         LOG.error("cfg file path is None which shouldn't happen")
     elif not os.path.isfile(self.path):
         with open(self.path, "w") as f:
             if "json" == file_type:
                 json.dump(CFG_JSON, f, sort_keys=True, indent=4, separators=(',', ': '))
             elif "ini" == file_type:
                 f.write(CFG_INI)