How to use read_static method in Splinter

Best Python code snippet using splinter

main.py

Source:main.py Github

copy

Full Screen

...38 if client_etag == server_etag:39 self.response.set_status(304)40 return41 self.response.headers['Etag'] = server_etag42 self.response.write(content or self.read_static(path))43 def calculate_etag(self, path):44 """Calculates the hash of the given static file or grabs it from cache.45 Returns:46 Tuple (etag, the body of the file if it was read)47 """48 version = utils.get_app_version()49 # Tainted versions are frequently overwritten, do not cache static files for50 # too long for them. Same for devserver.51 expiration_sec = 360052 if '-tainted' in version or utils.is_local_dev_server():53 expiration_sec = 154 key = '%s:%s' % (version, path)55 value = memcache.get(key, namespace='etag')56 if value:57 return value, None58 body = self.read_static(path)59 value = '"%s"' % hashlib.sha1(body).hexdigest()60 memcache.set(key, value, time=expiration_sec, namespace='etag')61 return value, body62 def read_static(self, path):63 """Reads static file body or raises HTTP 404 if not found."""64 abs_path = os.path.abspath(os.path.join(STATIC_DIR, path))65 assert abs_path.startswith(STATIC_DIR + '/'), abs_path66 try:67 with open(abs_path, 'rb') as f:68 body = f.read()69 # HACK: index.html doesn't expect to be served from the site root.70 # Tweak it to make it work anyway. This code path should never be71 # triggered in prod (since prod always serves vulcanized version).72 if abs_path.endswith('/static/html/index.html'):73 assert utils.is_local_dev_server()74 body = body.replace('../bower_components/', '/static/bower_components/')75 body = body.replace('cipd-app.html', '/static/html/cipd-app.html')76 return body...

Full Screen

Full Screen

fake_webapp.py

Source:fake_webapp.py Github

copy

Full Screen

...5from flask import Flask, request, abort, Response, redirect, url_for6from os import path7from functools import wraps8this_folder = path.abspath(path.dirname(__file__))9def read_static(static_name):10 return open(path.join(this_folder, 'static', static_name)).read()11EXAMPLE_APP = "http://127.0.0.1:5000/"12EXAMPLE_HTML = read_static('index.html')13EXAMPLE_IFRAME_HTML = read_static('iframe.html')14EXAMPLE_ALERT_HTML = read_static('alert.html')15EXAMPLE_TYPE_HTML = read_static('type.html')16EXAMPLE_POPUP_HTML = read_static('popup.html')17EXAMPLE_NO_BODY_HTML = read_static('no-body.html')18EXAMPLE_REDIRECT_LOCATION_HTML = read_static('redirect-location.html')19# Functions for http basic auth.20# Taken verbatim from http://flask.pocoo.org/snippets/8/21def check_auth(username, password):22 """This function is called to check if a username /23 password combination is valid.24 """25 return username == 'admin' and password == 'secret'26def authenticate():27 """Sends a 401 response that enables basic auth"""28 return Response(29 'Could not verify your access level for that URL.\n'30 'You have to login with proper credentials', 401,31 {'WWW-Authenticate': 'Basic realm="Login Required"'})32def requires_auth(f):...

Full Screen

Full Screen

webserv.py

Source:webserv.py Github

copy

Full Screen

...47 def handle_http(self, status_code, header, path):48 self.send_response(status_code)49 self.send_header(header[0], header[1])50 self.end_headers()51 return bytes(self.read_static(path))52 def read_static(self, path):53 with open(WEBDIR+path, 'rb') as outfile:54 print(WEBDIR+path)55 content = outfile.read()56 return content57 def respond(self, stat_hd_path):58 response = self.handle_http(stat_hd_path['status'], stat_hd_path['header'], stat_hd_path['path'])59 self.wfile.write(response)60def runserv(server_class=HTTPServer, handler_class=HttpProcessor):61 server_address = ('', 8000)62 httpd = server_class(server_address, handler_class)...

Full Screen

Full Screen

intrinsic_contextual_sentence_reader.py

Source:intrinsic_contextual_sentence_reader.py Github

copy

Full Screen

...19 :param directory:20 :return: dict with the sentences as keys and the indices as values21 """22 sentences = defaultdict(list)23 read_static(os.path.join(directory, 'test.txt'), sentences)24 read_static(os.path.join(directory, 'dev.txt'), sentences)25 read_static(os.path.join(directory, 'train.txt'), sentences)26 return sentences27def read_context(file_path, sentences):28 with open(file_path, encoding='utf-8') as f:29 for line in f:30 items = line.strip().split('\t')31 sentence = items[0]32 index = int(items[1])33 sentences[sentence].append(index)34def read_static(file_path, sentences):35 with open(file_path, encoding='utf-8') as f:36 for line in f:37 items = line.strip().split('\t')38 word = items[0]39 sentences[word].append(0)40 if len(items) == 3:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Splinter automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful