How to use environ method in autotest

Best Python code snippet using autotest_python Github


Full Screen

1"""Miscellaneous WSGI-related Utilities"""2import posixpath3__all__ = [4 'FileWrapper', 'guess_scheme', 'application_uri', 'request_uri',5 'shift_path_info', 'setup_testing_defaults',6]7class FileWrapper:8 """Wrapper to convert file-like objects to iterables"""9 def __init__(self, filelike, blksize=8192):10 self.filelike = filelike11 self.blksize = blksize12 if hasattr(filelike,'close'):13 self.close = filelike.close14 def __getitem__(self,key):15 data = if data:17 return data18 raise IndexError19 def __iter__(self):20 return self21 def next(self):22 data = if data:24 return data25 raise StopIteration26def guess_scheme(environ):27 """Return a guess for whether 'wsgi.url_scheme' should be 'http' or 'https'28 """29 if environ.get("HTTPS") in ('yes','on','1'):30 return 'https'31 else:32 return 'http'33def application_uri(environ):34 """Return the application's base URI (no PATH_INFO or QUERY_STRING)"""35 url = environ['wsgi.url_scheme']+'://'36 from urllib import quote37 if environ.get('HTTP_HOST'):38 url += environ['HTTP_HOST']39 else:40 url += environ['SERVER_NAME']41 if environ['wsgi.url_scheme'] == 'https':42 if environ['SERVER_PORT'] != '443':43 url += ':' + environ['SERVER_PORT']44 else:45 if environ['SERVER_PORT'] != '80':46 url += ':' + environ['SERVER_PORT']47 url += quote(environ.get('SCRIPT_NAME') or '/')48 return url49def request_uri(environ, include_query=1):50 """Return the full request URI, optionally including the query string"""51 url = application_uri(environ)52 from urllib import quote53 path_info = quote(environ.get('PATH_INFO',''),safe='/;=,')54 if not environ.get('SCRIPT_NAME'):55 url += path_info[1:]56 else:57 url += path_info58 if include_query and environ.get('QUERY_STRING'):59 url += '?' + environ['QUERY_STRING']60 return url61def shift_path_info(environ):62 """Shift a name from PATH_INFO to SCRIPT_NAME, returning it63 If there are no remaining path segments in PATH_INFO, return None.64 Note: 'environ' is modified in-place; use a copy if you need to keep65 the original PATH_INFO or SCRIPT_NAME.66 Note: when PATH_INFO is just a '/', this returns '' and appends a trailing67 '/' to SCRIPT_NAME, even though empty path segments are normally ignored,68 and SCRIPT_NAME doesn't normally end in a '/'. This is intentional69 behavior, to ensure that an application can tell the difference between70 '/x' and '/x/' when traversing to objects.71 """72 path_info = environ.get('PATH_INFO','')73 if not path_info:74 return None75 path_parts = path_info.split('/')76 path_parts[1:-1] = [p for p in path_parts[1:-1] if p and p != '.']77 name = path_parts[1]78 del path_parts[1]79 script_name = environ.get('SCRIPT_NAME','')80 script_name = posixpath.normpath(script_name+'/'+name)81 if script_name.endswith('/'):82 script_name = script_name[:-1]83 if not name and not script_name.endswith('/'):84 script_name += '/'85 environ['SCRIPT_NAME'] = script_name86 environ['PATH_INFO'] = '/'.join(path_parts)87 # Special case: '/.' on PATH_INFO doesn't get stripped,88 # because we don't strip the last element of PATH_INFO89 # if there's only one path part left. Instead of fixing this90 # above, we fix it here so that PATH_INFO gets normalized to91 # an empty string in the environ.92 if name=='.':93 name = None94 return name95def setup_testing_defaults(environ):96 """Update 'environ' with trivial defaults for testing purposes97 This adds various parameters required for WSGI, including HTTP_HOST,98 SERVER_NAME, SERVER_PORT, REQUEST_METHOD, SCRIPT_NAME, PATH_INFO,99 and all of the wsgi.* variables. It only supplies default values,100 and does not replace any existing settings for these variables.101 This routine is intended to make it easier for unit tests of WSGI102 servers and applications to set up dummy environments. It should *not*103 be used by actual WSGI servers or applications, since the data is fake!104 """105 environ.setdefault('SERVER_NAME','')106 environ.setdefault('SERVER_PROTOCOL','HTTP/1.0')107 environ.setdefault('HTTP_HOST',environ['SERVER_NAME'])108 environ.setdefault('REQUEST_METHOD','GET')109 if 'SCRIPT_NAME' not in environ and 'PATH_INFO' not in environ:110 environ.setdefault('SCRIPT_NAME','')111 environ.setdefault('PATH_INFO','/')112 environ.setdefault('wsgi.version', (1,0))113 environ.setdefault('wsgi.run_once', 0)114 environ.setdefault('wsgi.multithread', 0)115 environ.setdefault('wsgi.multiprocess', 0)116 from StringIO import StringIO117 environ.setdefault('wsgi.input', StringIO(""))118 environ.setdefault('wsgi.errors', StringIO())119 environ.setdefault('wsgi.url_scheme',guess_scheme(environ))120 if environ['wsgi.url_scheme']=='http':121 environ.setdefault('SERVER_PORT', '80')122 elif environ['wsgi.url_scheme']=='https':123 environ.setdefault('SERVER_PORT', '443')124_hoppish = {125 'connection':1, 'keep-alive':1, 'proxy-authenticate':1,126 'proxy-authorization':1, 'te':1, 'trailers':1, 'transfer-encoding':1,127 'upgrade':1128}.__contains__129def is_hop_by_hop(header_name):130 """Return true if 'header_name' is an HTTP/1.1 "Hop-by-Hop" header"""...

Full Screen

Full Screen Github


Full Screen

1# IF YOU ARE HOSTING HELLBOT ON OTHER VPS OR LOCALLY RATHER THAN HEROKU2# THEN DON'T EDIT THIS FILE.3# GO AND EDIT AND RENAME IT TO config.py4# AND FILL THE REQUIRED VARS THERE.5# !!! DO NOT EDIT THIS FILE !!!6import os7from import ChatBannedRights8class Config(object):9 LOGGER = True10 ABUSE = os.environ.get("ABUSE", None)11 API_HASH = os.environ.get("API_HASH", None)12 APP_ID = os.environ.get("APP_ID", None)13 BL_CHAT = set(int(x) for x in os.environ.get("BL_CHAT", "").split())14 BOT_HANDLER = os.environ.get("BOT_HANDLER", "\/")15 BOT_TOKEN = os.environ.get("BOT_TOKEN", None)16 BOT_USERNAME = os.environ.get("BOT_USERNAME", None)17 BUTTONS_IN_HELP = int(os.environ.get("BUTTONS_IN_HELP", 7))18 CHROME_BIN = os.environ.get("CHROME_BIN", "/app/.apt/usr/bin/google-chrome")19 CHROME_DRIVER = os.environ.get("CHROME_DRIVER", "/app/.chromedriver/bin/chromedriver")20 DB_URI = os.environ.get("DATABASE_URL", None)21 EMOJI_IN_HELP = os.environ.get("EMOJI_IN_HELP", "✧")22 FBAN_LOG_GROUP = os.environ.get("FBAN_LOG_GROUP", None)23 if FBAN_LOG_GROUP:24 FBAN_LOG_GROUP = int(FBAN_LOG_GROUP)25 G_DRIVE_CLIENT_ID = os.environ.get("G_DRIVE_CLIENT_ID", None)26 G_DRIVE_CLIENT_SECRET = os.environ.get("G_DRIVE_CLIENT_SECRET", None)27 GBAN_LOG_GROUP = os.environ.get("GBAN_LOG_GROUP", None)28 if GBAN_LOG_GROUP:29 GBAN_LOG_GROUP = int(GBAN_LOG_GROUP)30 GDRIVE_FOLDER_ID = os.environ.get("GDRIVE_FOLDER_ID", None)31 GIT_REPO_NAME = os.environ.get("GIT_REPO_NAME", None)32 GITHUB_ACCESS_TOKEN = os.environ.get("GITHUB_ACCESS_TOKEN", None)33 GOOGLE_CHROME_BIN = os.environ.get("GOOGLE_CHROME_BIN", "/app/.apt/usr/bin/google-chrome")34 HANDLER = os.environ.get("HANDLER", ".")35 HEROKU_API_KEY = os.environ.get("HEROKU_API_KEY", None)36 HEROKU_APP_NAME = os.environ.get("HEROKU_APP_NAME", None)37 INSTANT_BLOCK = os.environ.get("INSTANT_BLOCK", None)38 LOGGER_ID = os.environ.get("LOGGER_ID", None)39 if LOGGER_ID:40 LOGGER_ID = int(LOGGER_ID)41 MAX_MESSAGE_SIZE_LIMIT = 409542 MAX_SPAM = int(os.environ.get("MAX_SPAM", 3))43 MY_CHANNEL = os.environ.get("YOUR_CHANNEL", "Its_HellBot")44 MY_GROUP = os.environ.get("YOUR_GROUP", "HellBot_Chat")45 OCR_API = os.environ.get("OCR_API", None)46 PLUGIN_CHANNEL = os.environ.get("PLUGIN_CHANNEL", None)47 if PLUGIN_CHANNEL:48 PLUGIN_CHANNEL = int(PLUGIN_CHANNEL)49 PM_LOG_ID = os.environ.get("PM_LOG_ID", None)50 if PM_LOG_ID:51 PM_LOG_ID = int(PM_LOG_ID)52 PM_PERMIT = os.environ.get("PM_PERMIT", None)53 REMOVE_BG_API = os.environ.get("REMOVE_BG_API", None)54 HELLBOT_SESSION = os.environ.get("HELLBOT_SESSION", None)55 SESSION_2 = os.environ.get("SESSION_2", None)56 SESSION_3 = os.environ.get("SESSION_3", None)57 SESSION_4 = os.environ.get("SESSION_4", None)58 SESSION_5 = os.environ.get("SESSION_5", None)59 SUDO_HANDLER = os.environ.get("SUDO_HANDLER", ".")60 SUDO_USERS = []61 TAG_LOGGER = os.environ.get("TAG_LOGGER", None)62 if TAG_LOGGER: 63 TAG_LOGGER = int(TAG_LOGGER)64 TEMP_DIR = os.environ.get("TEMP_DIR", None)65 TMP_DOWNLOAD_DIRECTORY = os.environ.get("TMP_DOWNLOAD_DIRECTORY", "./DOWNLOADS/")66 THUMB_IMG = os.environ.get("THUMB_IMG", "./hellbot/resources/pics/hellbot_logo.jpg")67 UNLOAD = list(os.environ.get("UNLOAD", "").split())68 UPSTREAM_REPO = os.environ.get("UPSTREAM_REPO", "")69 WEATHER_API = os.environ.get("WEATHER_API", None)70class Production(Config):71 LOGGER = False72class Development(Config):...

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:


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

Run autotest 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?