def request(*args, **kargs): # Save PEP 3122! if "." in __name__: from . import web else: import web return web.request(*args, **kargs)
def GetGithubLines(user, repo, revision, path, from_line=1, to_line=999999, highlight=None): url = "https://raw.githubusercontent.com/" + user + "/" + repo + "/" + revision + "/" + path try: page_data = web.request(url, cache=True) except Exception as e: print("Unable to get '%s' (%s)" % (url, str(e))) return None the_page = page_data.decode() lines = the_page.splitlines() for i in range(from_line - 1, to_line): if i < 0: continue if i >= len(lines): break line = lines[i] line_index = i + 1 #FIXME: Does not work if from_line is negative #print(str(line_index)) if highlight != None and highlight == line_index: print(Fore.YELLOW + line + Style.RESET_ALL) else: print(line) return lines
def main(args): parser = argparse.ArgumentParser(description='Process uri to create request.') parser.add_argument('--version', action='version', version='%(prog)s {0}'.format(version)) parser.add_argument('uri', help="the uri where the request will be sent") group = parser.add_mutually_exclusive_group() group.add_argument(REQUEST_OPTION_SHORT, REQUEST_OPTION_LONG, dest=REQUEST_OPTION_DESTINATION, help="(HTTP) Specifies a custom request method to use when communicating with the HTTP server. The specified request will be used instead of the method otherwise used (which defaults to GET). Read the HTTP 1.1 specification for details and explanations. (Common additional HTTP requests include PUT and DELETE, but related technologies like WebDAV offers PROPFIND, COPY, MOVE and more). It can be: {0}".format( ", ".join(HTTP_METHODS)), default=HTTP_GET) group.add_argument('-G', '--get', help="Activate the get method", dest=REQUEST_OPTION_DESTINATION, action='store_const', const=HTTP_GET) group.add_argument('--put', help="Activate the put method", dest=REQUEST_OPTION_DESTINATION, action='store_const', const=HTTP_PUT) group.add_argument('--post', help="Activate the post method", dest=REQUEST_OPTION_DESTINATION, action='store_const', const=HTTP_POST) group.add_argument('--del', help="Activate the delete method", dest=REQUEST_OPTION_DESTINATION, action='store_const' , const=HTTP_DELETE) group.add_argument('--head', help="Activate the head method", dest=REQUEST_OPTION_DESTINATION, action='store_const', const=HTTP_HEAD) group.add_argument('--opts', help="Activate the options method", dest=REQUEST_OPTION_DESTINATION, action='store_const', const=HTTP_OPTIONS) group.add_argument('--trace', help="Activate the trace method", dest=REQUEST_OPTION_DESTINATION, action='store_const', const=HTTP_TRACE) group.add_argument('--conn', help="Activate the connect method", dest=REQUEST_OPTION_DESTINATION, action='store_const', const=HTTP_CONNECT) args = parser.parse_args(args) target = uri(args.uri) if not validate_method(args.request): parser.error("invalid method name: {0}".format(args.request)) response = request(target, args.request) _print(response)
def instruction_lf2stream(self): stream_on = 'stream_on' in self.lf2stream and self.lf2stream['stream_on'] page = web.request('https://api.twitch.tv/kraken/streams/lf2stream')['text'] stream_on_now = page and json.loads(page)['stream'] since = None viewers = None if stream_on_now: try: since = stream_on_now['created_at'] viewers = stream_on_now['viewers'] except KeyError: pass if stream_on_now and not stream_on: self.send("PRIVMSG", "#lfe", "GREEN LAMP YO http://www.lf-empire.de/forum/lf2stream.php" + " (since %s, %s viewers)" % (since, viewers)) elif stream_on and not stream_on_now: self.send("PRIVMSG", "#lfe", "lf2 stream ova (started %s)" % stream_on['created_at']) self.lf2stream['last_checked'] = time.time() self.lf2stream['stream_on'] = stream_on_now self.lf2stream['since'] = since self.lf2stream['viewers'] = viewers
def main(): print """----------- Vault Automation Test -----------""" print """This program executes some test cases to evaluate VAULT""" host = raw_input('Enter the IP Address of the host: ') user = raw_input("Enter the Username of the host: ") password = raw_input("Enter the Password of the host: ") ch = raw_input("Enter the choice of connectivity (SSH/WEB)? ") if (ch == "SSH" or ch == "ssh"): handle = connect.connect(host, user, password) out, err = connect.sendcmd(handle, "uname -a") print("The Machine Details are %s \n" % out.readlines()[0]) out, err = connect.sendcmd(handle, 'vault') print("The Vault Status is %s \n" % out.readlines()) elif (ch == "WEB" or ch == "web"): port = raw_input("Enter the port number of the request: ") handle = web.request(host, "sys/health", port) print web.url(handle + "sys/seal-status") else: print("Enter the Right Choice ! \n") sys.exit() print "\nBEGIN: Test Case Execution ---->\n" print "Basic TestCase: " print """"""
def save_img(url, img_type, save_dir, rm_meta=False): raw_img = request(url, sleep=(.5, 1.5)).content ext = img_type or 'jpg' name = str(uuid.uuid4().hex) + '.' + ext save_path = os.path.join(save_dir, name) with open(save_path, 'wb+') as f: f.write(raw_img) if rm_meta: Image.open(save_path).save(save_path)
def get_imgs(query, lang=None, debug=None): query_url = QUERY_URL(query) if is_(lang): query_url += '&' + lang_params(lang) if debug: print('query_url for %s: %s' % (query, query_url)) resp = request(query_url, sleep=(.5, 1.5)) soup = BeautifulSoup(resp.text, 'lxml') return get_imgs_from_soup(soup)
def test_hello_word_get(self): target = uri("http://localhost:8080/hello/tutu") response = request(target) assert_that(response.status_code, is_(200))