How to use _port_follows_standard method in gabbi

Best Python code snippet using gabbi_python

utils.py

Source:utils.py Github

copy

Full Screen

...22def create_url(base_url, host, port=None, prefix='', ssl=False):23 """Given pieces of a path-based url, return a fully qualified url."""24 scheme = 'http'25 netloc = host26 if port and not _port_follows_standard(port, ssl):27 netloc = '%s:%s' % (host, port)28 if ssl:29 scheme = 'https'30 parsed_url = urlparse.urlsplit(base_url)31 query_string = parsed_url.query32 path = parsed_url.path33 # Guard against a prefix of None34 if prefix:35 path = '%s%s' % (prefix, path)36 return urlparse.urlunsplit((scheme, netloc, path, query_string, ''))37def decode_response_content(header_dict, content):38 """Decode content to a proper string."""39 content_type, charset = extract_content_type(header_dict)40 if not_binary(content_type):41 return content.decode(charset)42 else:43 return content44def extract_content_type(header_dict):45 """Extract content-type from headers."""46 content_type = header_dict.get('content-type',47 'application/binary').strip().lower()48 charset = 'utf-8'49 if ';' in content_type:50 content_type, parameter_strings = (attr.strip() for attr51 in content_type.split(';', 1))52 try:53 parameter_pairs = [atom.strip().split('=')54 for atom in parameter_strings.split(';')]55 parameters = {name: value for name, value in parameter_pairs}56 charset = parameters['charset']57 except (ValueError, KeyError):58 # KeyError when no charset found.59 # ValueError when the parameter_strings are poorly60 # formed (for example trailing ;)61 pass62 return (content_type, charset)63def get_colorizer(stream):64 """Return a function to colorize a string.65 Only if stream is a tty .66 """67 if stream.isatty() or os.environ.get('GABBI_FORCE_COLOR', False):68 colorama.init()69 return _colorize70 else:71 return lambda x, y: y72def not_binary(content_type):73 """Decide if something is content we'd like to treat as a string."""74 return (content_type.startswith('text/') or75 content_type.endswith('+xml') or76 content_type.endswith('+json') or77 content_type == 'application/javascript' or78 content_type.startswith('application/json'))79def _colorize(color, message):80 """Add a color to the message."""81 try:82 return getattr(colorama.Fore, color) + message + colorama.Fore.RESET83 except AttributeError:84 return message85def _port_follows_standard(port, ssl):86 """Return True if a standard port is using a non-standard ssl setting."""87 port = int(port)...

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 gabbi 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