def params(self, params): if params: return '?' + '&'.join( '%s=%s' % (uquote(str(k)), uquote(str(v))) for k, v in iteritems(params) ) return ''
def getJsonReponse(tweetCriteria, refreshCursor, cookieJar, proxy): url, data = tweetCriteria.url(), tweetCriteria.get_data() url = url % (uquote(data), refreshCursor) headers = [('Host', "twitter.com"), ('User-Agent', "Mozilla/5.0 (Windows NT 6.1; Win64; x64)"), ('Accept', "application/json, text/javascript, */*; q=0.01"), ('Accept-Language', "de,en-US;q=0.7,en;q=0.3"), ('X-Requested-With', "XMLHttpRequest"), ('Referer', url), ('Connection', "keep-alive")] if proxy: opener = rq.build_opener( rq.ProxyHandler({ 'http': proxy, 'https': proxy }), rq.HTTPCookieProcessor(cookieJar)) else: opener = rq.build_opener(rq.HTTPCookieProcessor(cookieJar)) opener.addheaders = headers try: #print( url ) response = opener.open(url) jsonResponse = response.read() except Exception as e: sys.stderr.write( "Twitter weird response. Try to see on browser: https://twitter.com/search?q={}&src=typd" .format(uquote(data))) sys.exit() dataJson = jsonlib.loads(jsonResponse.decode()) return dataJson
def params(self, params): if params: return '?' + '&'.join('%s=%s' % (uquote(str(k)), uquote(str(v))) for k, v in iteritems(params)) return ''
def url(path, args=[], params={}, extension=None, sign=None, scheme=None, host=None, language=None): """ usages: url('index') # assumes app or default expose file url('.index') # use current exposed file url('mod.index') # index function in 'mod' module url('static', 'file') # for static files url('/myurl') # a normal url """ if not isinstance(args, (list, tuple)): args = [args] # allow user to use url('static', 'file') if path == 'static': path = '/static' # routes urls with 'dot' notation if '/' not in path: # urls like 'function' refers to same module if '.' not in path: namespace = Expose.application.config.url_default_namespace or \ Expose.application.name path = namespace + "." + path # urls like '.function' refers to main app module elif path.startswith('.'): if not hasattr(current, 'request'): raise RuntimeError( 'cannot build url("%s",...) without current request' % path ) module = current.request.name.rsplit('.', 1)[0] path = module + path # find correct route try: url = Expose.routes_out[path]['path'] url_host = Expose.routes_out[path]['host'] # try to rebuild url if midargs found midargs = url.split("{{:arg:}}") if len(midargs) > 1: u = "" if len(args) >= len(midargs) - 1: for i in range(0, len(midargs) - 1): u += midargs[i] + uquote(str(args[i])) u += midargs[-1] url = u args = args[len(midargs) - 1:] else: raise RuntimeError( 'invalid url("%s",...): needs args for params' % path ) # try to use the correct hostname if url_host is not None: try: if current.request.hostname != url_host: #url = current.request.scheme+"://"+url_host+url scheme = current.request.scheme host = url_host except: pass except KeyError: raise RuntimeError('invalid url("%s",...)' % path) # handle classic urls else: url = path # add static versioning if url[0:7] == '/static': if Expose.static_versioning(): url = url[0:7] + "/_" + str(Expose.static_versioning()) + url[7:] # language if Expose.application.language_force_on_url: if url.startswith("/"): lang = None if language: #: use the given language if is enabled in application if language in Expose.application.languages: lang = language else: #: try to use the request language if context exists if hasattr(current, 'request'): lang = current.request.language if lang and lang != Expose.application.language_default: url = '/' + lang + url # add extension (useless??) if extension: url = url + '.' + extension # add args if args: if not isinstance(args, (list, tuple)): args = (args,) url = url + '/' + '/'.join(uquote(str(a)) for a in args) # add signature if sign: params['_signature'] = sign(url) # add params if params: url = url + '?' + '&'.join( '%s=%s' % ( uquote(str(k)), uquote(str(v))) for k, v in iteritems(params) ) # scheme=True means to use current scheme if scheme is True: if not hasattr(current, 'request'): raise RuntimeError( 'cannot build url("%s",...) without current request' % path ) scheme = current.request.scheme # add scheme and host if scheme: if host is None: if not hasattr(current, 'request'): raise RuntimeError( 'cannot build url("%s",...) without current request' % path ) host = current.request.hostname url = '%s://%s%s' % (scheme, host, url) return url
def quote(s): s = to_string(s) return uquote(s, '~')