def build_parameters(self, args, kargs): # bind here, as default self.parameters = {'format': self.payload_format} for idx, arg in enumerate(args): try: self.parameters[self.allowed_param[idx]] = quote(convert_to_utf8_str(arg)) except IndexError: raise QWeiboError('Too many parameters supplied!') for k, arg in kargs.items(): if bool(arg) == False: continue if k in self.parameters: raise QWeiboError('Multiple values for parameter `%s` supplied!' % k) #if k not in self.allowed_param: # raise QWeiboError('`%s` is not allowd in this API function.' % k) self.parameters[k] = quote(convert_to_utf8_str(arg))
def build_parameters(self, args, kargs): # bind here, as default self.parameters = {'format': self.payload_format} for idx, arg in enumerate(args): try: self.parameters[self.allowed_param[idx]] = quote( convert_to_utf8_str(arg)) except IndexError: raise QWeiboError('Too many parameters supplied!') for k, arg in kargs.items(): if bool(arg) == False: continue if k in self.parameters: raise QWeiboError( 'Multiple values for parameter `%s` supplied!' % k) #if k not in self.allowed_param: # raise QWeiboError('`%s` is not allowd in this API function.' % k) self.parameters[k] = quote(convert_to_utf8_str(arg))
def escape(s): """Escape a URL including any /. return py2str py3str """ # py3k if hasattr(str, 'decode') and type(s) != str: # FIXME assume py2unicode s = s.encode('utf-8') ret = quote(s, safe='~') if type(ret) != str: return str(ret) return ret
def build_path(self): for variable in re_path_template.findall(self.path): name = variable.strip('{}') if name == 'user' and self.api.auth: value = self.api.auth.get_username() else: try: value = quote(self.parameters[name]) except KeyError: raise QWeiboError('No parameter value found for path variable: %s' % name) del self.parameters[name] self.path = self.path.replace(variable, value)
def build_path(self): for variable in re_path_template.findall(self.path): name = variable.strip('{}') if name == 'user' and self.api.auth: value = self.api.auth.get_username() else: try: value = quote(self.parameters[name]) except KeyError: raise QWeiboError( 'No parameter value found for path variable: %s' % name) del self.parameters[name] self.path = self.path.replace(variable, value)