Best Python code snippet using fMBT_python
config.py
Source:config.py
1import configparser2import os3from distutils.util import strtobool4class EnvInterpolation(configparser.BasicInterpolation):5 """Interpolation which expands environment variables in values."""6 def before_get(self, parser, section, option, value, defaults):7 value = super().before_get(parser, section, option, value, defaults)8 envvar = os.getenv(option)9 if value == "" and envvar:10 return process_string_var(envvar)11 else:12 return value13def process_string_var(value):14 if value == "":15 return None16 if value.isdigit():17 return int(value)18 elif value.replace(".", "", 1).isdigit():19 return float(value)20 try:21 return bool(strtobool(value))22 except ValueError:23 return value24def process_boolean_str(value):25 if type(value) is bool:26 return value27 if value is None:28 return False29 if value == "":30 return None31 return bool(strtobool(value))32def empty_str_cast(value, default=None):33 if value == "":34 return default35 return value36def gen_secret_key():37 # Attempt to read the secret from the secret file38 # This will fail if the secret has not been written39 try:40 with open(".ctfd_secret_key", "rb") as secret:41 key = secret.read()42 except OSError:43 key = None44 if not key:45 key = os.urandom(64)46 # Attempt to write the secret file47 # This will fail if the filesystem is read-only48 try:49 with open(".ctfd_secret_key", "wb") as secret:50 secret.write(key)51 secret.flush()52 except OSError:53 pass54 return key55config_ini = configparser.ConfigParser(interpolation=EnvInterpolation())56config_ini.optionxform = str # Makes the key value case-insensitive57path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "config.ini")58config_ini.read(path)59# fmt: off60class ServerConfig(object):61 SECRET_KEY: str = empty_str_cast(config_ini["server"]["SECRET_KEY"]) \62 or gen_secret_key()63 DATABASE_URL: str = empty_str_cast(config_ini["server"]["DATABASE_URL"]) \64 or f"sqlite:///{os.path.dirname(os.path.abspath(__file__))}/ctfd.db"65 REDIS_URL: str = empty_str_cast(config_ini["server"]["REDIS_URL"])66 SQLALCHEMY_DATABASE_URI = DATABASE_URL67 CACHE_REDIS_URL = REDIS_URL68 if CACHE_REDIS_URL:69 CACHE_TYPE: str = "redis"70 else:71 CACHE_TYPE: str = "filesystem"72 CACHE_DIR: str = os.path.join(73 os.path.dirname(__file__), os.pardir, ".data", "filesystem_cache"74 )75 # Override the threshold of cached values on the filesystem. The default is 500. Don't change unless you know what you're doing.76 CACHE_THRESHOLD: int = 077 # === SECURITY ===78 SESSION_COOKIE_HTTPONLY: bool = config_ini["security"].getboolean("SESSION_COOKIE_HTTPONLY", fallback=True)79 SESSION_COOKIE_SAMESITE: str = empty_str_cast(config_ini["security"]["SESSION_COOKIE_SAMESITE"]) \80 or "Lax"81 PERMANENT_SESSION_LIFETIME: int = config_ini["security"].getint("PERMANENT_SESSION_LIFETIME") \82 or 60480083 """84 TRUSTED_PROXIES:85 Defines a set of regular expressions used for finding a user's IP address if the CTFd instance86 is behind a proxy. If you are running a CTF and users are on the same network as you, you may choose to remove87 some proxies from the list.88 CTFd only uses IP addresses for cursory tracking purposes. It is ill-advised to do anything complicated based89 solely on IP addresses unless you know what you are doing.90 """91 TRUSTED_PROXIES = [92 r"^127\.0\.0\.1$",93 # Remove the following proxies if you do not trust the local network94 # For example if you are running a CTF on your laptop and the teams are95 # all on the same network96 r"^::1$",97 r"^fc00:",98 r"^10\.",99 r"^172\.(1[6-9]|2[0-9]|3[0-1])\.",100 r"^192\.168\.",101 ]102 # === EMAIL ===103 MAILFROM_ADDR: str = config_ini["email"]["MAILFROM_ADDR"] \104 or "noreply@examplectf.com"105 MAIL_SERVER: str = empty_str_cast(config_ini["email"]["MAIL_SERVER"])106 MAIL_PORT: int = empty_str_cast(config_ini["email"]["MAIL_PORT"])107 MAIL_USEAUTH: bool = process_boolean_str(config_ini["email"]["MAIL_USEAUTH"])108 MAIL_USERNAME: str = empty_str_cast(config_ini["email"]["MAIL_USERNAME"])109 MAIL_PASSWORD: str = empty_str_cast(config_ini["email"]["MAIL_PASSWORD"])110 MAIL_TLS: bool = process_boolean_str(config_ini["email"]["MAIL_TLS"])111 MAIL_SSL: bool = process_boolean_str(config_ini["email"]["MAIL_SSL"])112 MAILSENDER_ADDR: str = empty_str_cast(config_ini["email"]["MAILSENDER_ADDR"])113 MAILGUN_API_KEY: str = empty_str_cast(config_ini["email"]["MAILGUN_API_KEY"])114 MAILGUN_BASE_URL: str = empty_str_cast(config_ini["email"]["MAILGUN_API_KEY"])115 # === LOGS ===116 LOG_FOLDER: str = empty_str_cast(config_ini["logs"]["LOG_FOLDER"]) \117 or os.path.join(os.path.dirname(os.path.abspath(__file__)), "logs")118 # === UPLOADS ===119 UPLOAD_PROVIDER: str = empty_str_cast(config_ini["uploads"]["UPLOAD_PROVIDER"]) \120 or "filesystem"121 UPLOAD_FOLDER: str = empty_str_cast(config_ini["uploads"]["UPLOAD_FOLDER"]) \122 or os.path.join(os.path.dirname(os.path.abspath(__file__)), "uploads")123 if UPLOAD_PROVIDER == "s3":124 AWS_ACCESS_KEY_ID: str = empty_str_cast(config_ini["uploads"]["AWS_ACCESS_KEY_ID"])125 AWS_SECRET_ACCESS_KEY: str = empty_str_cast(config_ini["uploads"]["AWS_SECRET_ACCESS_KEY"])126 AWS_S3_BUCKET: str = empty_str_cast(config_ini["uploads"]["AWS_S3_BUCKET"])127 AWS_SESSION_TOKEN: str = empty_str_cast(config_ini["uploads"]["AWS_SESSION_TOKEN"])128 AWS_S3_ENDPOINT_URL: str = empty_str_cast(config_ini["uploads"]["AWS_S3_ENDPOINT_URL"])129 # === OPTIONAL ===130 REVERSE_PROXY: bool = process_boolean_str(empty_str_cast(config_ini["optional"]["REVERSE_PROXY"], default=False))131 TEMPLATES_AUTO_RELOAD: bool = process_boolean_str(empty_str_cast(config_ini["optional"]["TEMPLATES_AUTO_RELOAD"], default=True))132 THEME_FALLBACK: bool = process_boolean_str(empty_str_cast(config_ini["optional"]["THEME_FALLBACK"], default=True))133 SQLALCHEMY_TRACK_MODIFICATIONS: bool = process_boolean_str(empty_str_cast(config_ini["optional"]["SQLALCHEMY_TRACK_MODIFICATIONS"], default=False))134 SWAGGER_UI: bool = process_boolean_str(empty_str_cast(config_ini["optional"]["SWAGGER_UI"], default=False))135 SWAGGER_UI_ENDPOINT: str = "/" if SWAGGER_UI else None136 UPDATE_CHECK: bool = process_boolean_str(empty_str_cast(config_ini["optional"]["UPDATE_CHECK"], default=True))137 APPLICATION_ROOT: str = empty_str_cast(config_ini["optional"]["APPLICATION_ROOT"], default="/")138 SERVER_SENT_EVENTS: bool = process_boolean_str(empty_str_cast(config_ini["optional"]["SERVER_SENT_EVENTS"], default=True))139 HTML_SANITIZATION: bool = process_boolean_str(empty_str_cast(config_ini["optional"]["HTML_SANITIZATION"], default=False))140 if DATABASE_URL.startswith("sqlite") is False:141 SQLALCHEMY_ENGINE_OPTIONS = {142 "max_overflow": int(empty_str_cast(config_ini["optional"]["SQLALCHEMY_MAX_OVERFLOW"], default=20)), # noqa: E131143 "pool_pre_ping": empty_str_cast(config_ini["optional"]["SQLALCHEMY_POOL_PRE_PING"], default=True), # noqa: E131144 }145 # === OAUTH ===146 OAUTH_CLIENT_ID: str = empty_str_cast(config_ini["oauth"]["OAUTH_CLIENT_ID"])147 OAUTH_CLIENT_SECRET: str = empty_str_cast(config_ini["oauth"]["OAUTH_CLIENT_SECRET"])148# fmt: on149class TestingConfig(ServerConfig):150 SECRET_KEY = "AAAAAAAAAAAAAAAAAAAA"151 PRESERVE_CONTEXT_ON_EXCEPTION = False152 TESTING = True153 DEBUG = True154 SQLALCHEMY_DATABASE_URI = os.getenv("TESTING_DATABASE_URL") or "sqlite://"155 MAIL_SERVER = os.getenv("TESTING_MAIL_SERVER")156 SERVER_NAME = "localhost"157 UPDATE_CHECK = False158 REDIS_URL = None159 CACHE_TYPE = "simple"160 CACHE_THRESHOLD = 500161 SAFE_MODE = True162# Actually initialize ServerConfig to allow us to add more attributes on163Config = ServerConfig()164for k, v in config_ini.items("extra"):...
moz.build
Source:moz.build
1# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-2# vim: set filetype=python:3# This Source Code Form is subject to the terms of the Mozilla Public4# License, v. 2.0. If a copy of the MPL was not distributed with this5# file, You can obtain one at http://mozilla.org/MPL/2.0/.6A11Y_MANIFESTS += [7 'a11y.ini',8 'actions/a11y.ini',9 'attributes/a11y.ini',10 'bounds/a11y.ini',11 'editabletext/a11y.ini',12 'elm/a11y.ini',13 'events/a11y.ini',14 'focus/a11y.ini',15 'hittest/a11y.ini',16 'hyperlink/a11y.ini',17 'hypertext/a11y.ini',18 'jsat/a11y.ini',19 'name/a11y.ini',20 'pivot/a11y.ini',21 'relations/a11y.ini',22 'role/a11y.ini',23 'scroll/a11y.ini',24 'selectable/a11y.ini',25 'states/a11y.ini',26 'table/a11y.ini',27 'text/a11y.ini',28 'textattrs/a11y.ini',29 'textcaret/a11y.ini',30 'textrange/a11y.ini',31 'textselection/a11y.ini',32 'tree/a11y.ini',33 'treeupdate/a11y.ini',34 'value/a11y.ini',...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!