text
stringlengths
81
112k
Placeholders are custom magic variables defined during configuration time. .. note:: These are accessible, like any uWSGI option, in your application code via ``.runtime.environ.uwsgi_env.config``. :param str|unicode key: :param str|unicode value: def set_placeholder(self...
Processes (sets/unsets) environment variable. If is not given in `set` mode value will be taken from current env. :param str|unicode key: :param value: :param bool unset: Whether to unset this variable. :param bool asap: If True env variable will be set as soon as possible. ...
Includes target contents into config. :param str|unicode|Section|list target: File path or Section to include. def include(self, target): """Includes target contents into config. :param str|unicode|Section|list target: File path or Section to include. """ for target_ in listif...
Creates a new section based on the given. :param Section section: Section to derive from, :param str|unicode name: New section name. :rtype: Section def derive_from(cls, section, name=None): """Creates a new section based on the given. :param Section section: Section to deri...
Validates sections types and uniqueness. def _validate_sections(cls, sections): """Validates sections types and uniqueness.""" names = [] for section in sections: if not hasattr(section, 'name'): raise ConfigurationError('`sections` attribute requires a list of Sect...
Applies formatting to configuration. *Currently formats to .ini* :param bool do_print: Whether to print out formatted config. :param bool stamp: Whether to add stamp data to the first configuration section. :rtype: str|unicode def format(self, do_print=False, stamp=True): """A...
Saves configuration into a file and returns its path. Convenience method. :param str|unicode filepath: Filepath to save configuration into. If not provided a temporary file will be automatically generated. :rtype: str|unicode def tofile(self, filepath=None): """Saves conf...
Returns plugin name. def _set_name(self, version=AUTO): """Returns plugin name.""" name = 'python' if version: if version is AUTO: version = sys.version_info[0] if version == 2: version = '' name = '%s%s' % (name, v...
Sets ``sys.argv`` for python apps. Examples: * pyargv="one two three" will set ``sys.argv`` to ``('one', 'two', 'three')``. :param args: def set_app_args(self, *args): """Sets ``sys.argv`` for python apps. Examples: * pyargv="one two three" will set ``sys.argv...
Set wsgi related parameters. :param str|unicode module: * load .wsgi file as the Python application * load a WSGI module as the application. .. note:: The module (sans ``.py``) must be importable, ie. be in ``PYTHONPATH``. Examples: * mypackage....
Sets autoreload related parameters. :param int scan_interval: Seconds. Monitor Python modules' modification times to trigger reload. .. warning:: Use only in development. :param list|st|unicode ignore_modules: Ignore the specified module during auto-reload scan. def set_autoreload_params...
Adds an alias for a module. http://uwsgi-docs.readthedocs.io/en/latest/PythonModuleAlias.html :param str|unicode alias: :param str|unicode module_path: :param bool after_init: add a python module alias after uwsgi module initialization def register_module_alias(self, alias, module_pat...
Imports a python module. :param list|str|unicode modules: :param bool shared: Import a python module in all of the processes. This is done after fork but before request processing. :param bool into_spooler: Import a python module in the spooler. http://uwsgi-docs.readt...
Sets subscription server related params. :param str|unicode client_notify_address: Set the notification socket for subscriptions. When you subscribe to a server, you can ask it to "acknowledge" the acceptance of your request. pointing address (Unix socket or UDP), on which your instance...
Sets peer verification params for subscription server. These are for secured subscriptions. :param str|unicode digest_algo: Digest algorithm. Example: SHA1 .. note:: Also requires ``dir_cert`` to be set. :param str|unicode dir_cert: Certificate directory. .. note:: A...
Sets subscribers related params. :param bool start_unsubscribed: Configure subscriptions but do not send them. .. note:: Useful with master FIFO. :param bool clear_on_exit: Force clear instead of unsubscribe during shutdown. :param bool unsubscribe_on_reload: Force unsubscribe req...
Registers a subscription intent. :param str|unicode server: Subscription server address (UDP or UNIX socket). Examples: * 127.0.0.1:7171 :param str|unicode key: Key to subscribe. Generally the domain name (+ optional '/< mountpoint>'). Examples: ...
Runs up the stack to find the location of manage.py which will be considered a project base path. :rtype: str|unicode def find_project_dir(): """Runs up the stack to find the location of manage.py which will be considered a project base path. :rtype: str|unicode """ frame = inspect.curren...
Runs uWSGI using the given section configuration. :param Section config_section: :param bool compile_only: Do not run, only compile and output configuration file for run. def run_uwsgi(config_section, compile_only=False): """Runs uWSGI using the given section configuration. :param Section config_sect...
Alternative constructor. Creates a mutator and returns section object. :param dict options: :param str|unicode dir_base: :rtype: SectionMutator def spawn(cls, options=None, dir_base=None): """Alternative constructor. Creates a mutator and returns section object. :param dict o...
Loads config section from existing configuration file (aka uwsgicfg.py) :param str|unicode name_module: :param str|unicode name_project: :rtype: Section def _get_section_existing(self, name_module, name_project): """Loads config section from existing configuration file (aka uwsgicfg.py...
Creates a new section with default settings. :param str|unicode dir_base: :rtype: Section def _get_section_new(cls, dir_base): """Creates a new section with default settings. :param str|unicode dir_base: :rtype: Section """ from uwsgiconf.presets.nice import P...
Contributes static and media file serving settings to an existing section. def contribute_static(self): """Contributes static and media file serving settings to an existing section.""" options = self.options if options['compile'] or not options['use_static_handler']: return ...
Contributes generic static error massage pages to an existing section. def contribute_error_pages(self): """Contributes generic static error massage pages to an existing section.""" static_dir = self.settings.STATIC_ROOT if not static_dir: # Source static directory is not configur...
Mutates current section. def mutate(self): """Mutates current section.""" section = self.section project_name = self.project_name section.project_name = project_name self.contribute_runtime_dir() main = section.main_process main.set_naming_params(prefix='[%s] ...
Maps a specific file/directory modification event to a signal. :param str|unicode filename: File or a directory to watch for its modification. :param int|Signal|str|unicode target: Existing signal to raise or Signal Target to register signal implicitly. Available targets: * ``wor...
Sets metric value. :param int|long value: New value. :param str|unicode mode: Update mode. * None - Unconditional update. * max - Sets metric value if it is greater that the current one. * min - Sets metric value if it is less that the current one. :rtype:...
Block until a mule message is received and return it. This can be called from multiple threads in the same programmed mule. :param bool signals: Whether to manage signals. :param bool farms: Whether to manage farms. :param int buffer_size: :param int timeout: Seconds. ...
Regenerates header files for cmark under ./generated. def regenerate(session): """Regenerates header files for cmark under ./generated.""" if platform.system() == 'Windows': output_dir = '../generated/windows' else: output_dir = '../generated/unix' session.run(shutil.rmtree, 'bu...
Temporarily captures/redirects stdout. def output_capturing(): """Temporarily captures/redirects stdout.""" out = sys.stdout sys.stdout = StringIO() try: yield finally: sys.stdout = out
Filters a dictionary produced by locals(). :param dict locals_dict: :param list drop: Keys to drop from dict. :param list include: Keys to include into dict. :rtype: dict def filter_locals(locals_dict, drop=None, include=None): """Filters a dictionary produced by locals(). :param dict loca...
Runs a command and returns its output (stdout + stderr). :param str|unicode cmd: :param str|unicode|list[str|unicode] args: :rtype: str|unicode def get_output(cmd, args): """Runs a command and returns its output (stdout + stderr). :param str|unicode cmd: :param str|unicode|list[str|unicode] ...
Parses ``plugin-list`` command output from uWSGI and returns object containing lists of embedded plugin names. :param str|unicode out: :rtype EmbeddedPlugins: def parse_command_plugins_output(out): """Parses ``plugin-list`` command output from uWSGI and returns object containing lists of embedded...
Returns attributes difference two elements tuple between real uwsgi module and its stub. Might be of use while describing in stub new uwsgi functions. :return: (uwsgi_only_attrs, stub_only_attrs) :rtype: tuple def get_uwsgi_stub_attrs_diff(): """Returns attributes difference two elements tuple b...
Spawns uWSGI process(es) which will use configuration(s) from the module. Returns list of tuples: (configuration_alias, uwsgi_process_id) If only one configuration found current process (uwsgiconf) is replaced with a new one (uWSGI), otherwise a number of new detached processes is ...
Configurations from uwsgiconf module. def configurations(self): """Configurations from uwsgiconf module.""" if self._confs is not None: return self._confs with output_capturing(): module = self.load(self.fpath) confs = getattr(module, CONFIGS_MODULE_ATTR) ...
Loads a module and returns its object. :param str|unicode fpath: :rtype: module def load(cls, fpath): """Loads a module and returns its object. :param str|unicode fpath: :rtype: module """ module_name = os.path.splitext(os.path.basename(fpath))[0] sys....
Allows managing of uWSGI log related stuff :param bool reopen: Reopen log file. Could be required after third party rotation. :param bool rotate: Trigger built-in log rotation. def cmd_log(self, reopen=False, rotate=False): """Allows managing of uWSGI log related stuff :param bool reo...
Reloads uWSGI master process, workers. :param bool force: Use forced (brutal) reload instead of a graceful one. :param bool workers_only: Reload only workers. :param bool workers_chain: Run chained workers reload (one after another, instead of destroying all of them in bulk). def c...
Sends a generic command into FIFO. :param bytes cmd: Command chars to send into FIFO. def send_command(self, cmd): """Sends a generic command into FIFO. :param bytes cmd: Command chars to send into FIFO. """ if not cmd: return with open(self.fifo, 'wb') a...
Returns PATH environment variable updated to run uwsgiconf in (e.g. for virtualenv). :rtype: str|unicode def get_env_path(cls): """Returns PATH environment variable updated to run uwsgiconf in (e.g. for virtualenv). :rtype: str|unicode """ return os.path.dirnam...
Prepares current environment and returns Python binary name. This adds some virtualenv friendliness so that we try use uwsgi from it. :rtype: str|unicode def prepare_env(cls): """Prepares current environment and returns Python binary name. This adds some virtualenv friendliness so th...
Spawns uWSGI using the given configuration module. :param str|unicode filepath: :param str|unicode configuration_alias: :param bool replace: Whether a new process should replace current one. def spawn(self, filepath, configuration_alias, replace=False): """Spawns uWSGI using the give...
Gets a value from the cache. :param str|unicode key: The cache key to get value for. :param default: Value to return if none found in cache. :param bool as_int: Return 64bit number instead of str. :param callable setter: Setter callable to automatically set cache value if...
Sets the specified key value. :param str|unicode key: :param int|str|unicode value: :rtype: bool def set(self, key, value): """Sets the specified key value. :param str|unicode key: :param int|str|unicode value: :rtype: bool """ return uwsgi....
Increments the specified key value by the specified value. :param str|unicode key: :param int delta: :rtype: bool def incr(self, key, delta=1): """Increments the specified key value by the specified value. :param str|unicode key: :param int del...
Decrements the specified key value by the specified value. :param str|unicode key: :param int delta: :rtype: bool def decr(self, key, delta=1): """Decrements the specified key value by the specified value. :param str|unicode key: :param int delta: :rtype: b...
Multiplies the specified key value by the specified value. :param str|unicode key: :param int value: :rtype: bool def mul(self, key, value=2): """Multiplies the specified key value by the specified value. :param str|unicode key: :param int value: :rtype: bo...
Divides the specified key value by the specified value. :param str|unicode key: :param int value: :rtype: bool def div(self, key, value=2): """Divides the specified key value by the specified value. :param str|unicode key: :param int value: :rtype: bool ...
Receives data from websocket. :param request_context: :param bool non_blocking: :rtype: bytes|str :raises IOError: If unable to receive a message. def recv(request_context=None, non_blocking=False): """Receives data from websocket. :param request_context: :param bool non_blocking: ...
Sends a message to websocket. :param str message: data to send :param request_context: :raises IOError: If unable to send a message. def send(message, request_context=None, binary=False): """Sends a message to websocket. :param str message: data to send :param request_context: :raises...
Render the given text to Markdown. This is a direct interface to ``cmark_markdown_to_html``. Args: text (str): The text to render to Markdown. options (int): The cmark options. Returns: str: The rendered markdown. def markdown_to_html(text, options=0): """Render the...
Render the given text to Markdown, using extensions. This is a high-level wrapper over the various functions needed to enable extensions, attach them to a parser, and render html. Args: text (str): The text to render to Markdown. options (int): The cmark options. extensions...
Parse a document and return the root node. Args: text (str): The text to parse. options (int): The cmark options. Returns: Any: Opaque reference to the root node of the parsed syntax tree. def parse_document(text, options=0): """Parse a document and return the root node. ...
Direct wrapper over cmark_parser_feed. def parser_feed(parser, text): """Direct wrapper over cmark_parser_feed.""" encoded_text = text.encode('utf-8') return _cmark.lib.cmark_parser_feed( parser, encoded_text, len(encoded_text))
Render a given syntax tree as HTML. Args: root (Any): The reference to the root node of the syntax tree. options (int): The cmark options. extensions (Any): The reference to the syntax extensions, generally from :func:`parser_get_syntax_extensions` Returns: ...
Direct wrapper over cmark_find_syntax_extension. def find_syntax_extension(name): """Direct wrapper over cmark_find_syntax_extension.""" encoded_name = name.encode('utf-8') extension = _cmark.lib.cmark_find_syntax_extension(encoded_name) if extension == _cmark.ffi.NULL: return None ...
:param bool no_expire: Disable auto sweep of expired items. Since uWSGI 1.2, cache item expiration is managed by a thread in the master process, to reduce the risk of deadlock. This thread can be disabled (making item expiry a no-op) with the this option. :param int expire_s...
Add an item into the given cache. This is a commodity option (mainly useful for testing) allowing you to store an item in a uWSGI cache during startup. :param str|unicode key: :param value: :param str|unicode cache_name: If not set, default will be used. def add_item(self, k...
Load a static file in the cache. .. note:: Items are stored with the filepath as is (relative or absolute) as the key. :param str|unicode filepath: :param bool gzip: Use gzip compression. :param str|unicode cache_name: If not set, default will be used. def add_file(self, filepath, g...
Creates cache. Default mode: single block. .. note:: This uses new generation ``cache2`` option available since uWSGI 1.9. .. note:: When at least one cache is configured without ``full_purge_lru`` and the master is enabled a thread named "the cache sweeper" is started. Its mai...
Add timer. Can be used as a decorator: .. code-block:: python @register_timer(3) def repeat(): do() :param int period: The interval (seconds) at which to raise the signal. :param int|Signal|str|unicode target: Existing signal to raise or Signal Ta...
Add a red-black timer (based on black-red tree). .. code-block:: python @register_timer_rb(3) def repeat(): do() :param int period: The interval (seconds) at which the signal is raised. :param int repeat: How many times to repeat. Default: None - infinitely. ...
Adds cron. The interface to the uWSGI signal cron facility. .. code-block:: python @register_cron(hour=-3) # Every 3 hours. def repeat(): do() .. note:: Arguments work similarly to a standard crontab, but instead of "*", use -1, and instead of "/2"...
Truncate a line to the specified length followed by ``...`` unless its shorter than length already. def truncate_ellipsis(line, length=30): """Truncate a line to the specified length followed by ``...`` unless its shorter than length already.""" l = len(line) return line if l < length else line[:length - ...
The main method of pyle. def pyle_evaluate(expressions=None, modules=(), inplace=False, files=None, print_traceback=False): """The main method of pyle.""" eval_globals = {} eval_globals.update(STANDARD_MODULES) for module_arg in modules or (): for module in module_arg.strip().split(","): ...
Execute pyle with the specified arguments, or sys.argv if no arguments specified. def pyle(argv=None): """Execute pyle with the specified arguments, or sys.argv if no arguments specified.""" parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("-m", "--modules", dest="modules", actio...
转换成国际音标 :param arpabet: :return: def convert_to_international_phonetic_alphabet(self, arpabet): ''' 转换成国际音标 :param arpabet: :return: ''' word = self._convert_to_word(arpabet=arpabet) if not word: return None return word.tran...
转换成美音 :param arpabet: :return: def convert_to_american_phonetic_alphabet(self, arpabet): ''' 转换成美音 :param arpabet: :return: ''' word = self._convert_to_word(arpabet=arpabet) if not word: return None return word.translate_to_...
转换成英音 :param arpabet: :return: def convert_to_english_phonetic_alphabet(self, arpabet): ''' 转换成英音 :param arpabet: :return: ''' word = self._convert_to_word(arpabet=arpabet) if not word: return None return word.translate_to_e...
转换成arpabet :return: def translate_to_arpabet(self): ''' 转换成arpabet :return: ''' translations = [] for phoneme in self._phoneme_list: if phoneme.is_vowel: translations.append(phoneme.arpabet + self.stress.mark_arpabet()) e...
转换成美音音。只要一个元音的时候需要隐藏重音标识 :param hide_stress_mark: :return: def translate_to_american_phonetic_alphabet(self, hide_stress_mark=False): ''' 转换成美音音。只要一个元音的时候需要隐藏重音标识 :param hide_stress_mark: :return: ''' translations = self.stress.mark_ipa() if (not hide_s...
转换成英音。只要一个元音的时候需要隐藏重音标识 :param hide_stress_mark: :return: def translate_to_english_phonetic_alphabet(self, hide_stress_mark=False): ''' 转换成英音。只要一个元音的时候需要隐藏重音标识 :param hide_stress_mark: :return: ''' translations = self.stress.mark_ipa() if (not hide_stres...
转换成国际音标。只要一个元音的时候需要隐藏重音标识 :param hide_stress_mark: :return: def translate_to_international_phonetic_alphabet(self, hide_stress_mark=False): ''' 转换成国际音标。只要一个元音的时候需要隐藏重音标识 :param hide_stress_mark: :return: ''' translations = self.stress.mark_ipa() if (not ...
Initializes and returns the login form component @rtype: LoginForm @return: Initialized component def get_login_form_component(self): """Initializes and returns the login form component @rtype: LoginForm @return: Initialized component """ self.dw.wait_until( ...
Converts a dictionary into a named tuple (shallow) def objectify(dictionary, name='Object'): """Converts a dictionary into a named tuple (shallow) """ o = namedtuple(name, dictionary.keys())(*dictionary.values()) return o
Creates a directory if it does not exist (in a thread-safe way) @param directory: The directory to create @return: The directory specified def create_directory(directory): """Creates a directory if it does not exist (in a thread-safe way) @param directory: The directory to create @return: The dir...
Adds a comment line to the query to be executed containing the line number of the calling function. This is useful for debugging slow queries, as the comment will show in the slow query log @type sql: str @param sql: sql needing comment @return: def __add_query_comment(sql): ...
Returns an instance of class_type populated with attributes from the DB record; throws an error if no records are found @param sql: Sql statement to execute @param class_type: The type of class to instantiate and populate with DB record @return: Return an instance with attributes set to...
Returns a list of instances of class_type populated with attributes from the DB record @param sql: Sql statement to execute @param class_type: The type of class to instantiate and populate with DB record @return: Return a list of instances with attributes set to values from DB def get_all_inst...
Escape dictionary values with keys as column names and values column values @type dictionary: dict @param dictionary: Key-values def escape_dictionary(dictionary, datetime_format='%Y-%m-%d %H:%M:%S'): """Escape dictionary values with keys as column names and values column values @type...
Formats a dictionary to strings of fields and values for insert statements @param dictionary: The dictionary whose keys and values are to be inserted @param db_escape: If true, will db escape values @return: Tuple of strings containing string fields and values, e.g. ('user_id, username', '5, "p...
This method should be used in query functions where user can query on any number of fields >>> def get_instances(entity_id=NOTSET, my_field=NOTSET): >>> kwargs = CoyoteDb.get_kwargs(entity_id=entity_id, my_field=my_field) def get_kwargs(**kwargs): """This method should be used in q...
Builds the update values clause of an update statement based on the dictionary representation of an instance def get_update_clause_from_dict(dictionary, datetime_format='%Y-%m-%d %H:%M:%S'): """Builds the update values clause of an update statement based on the dictionary representation of an i...
Builds a where clause from a dictionary def get_where_clause_from_dict(dictionary, join_operator='AND'): """Builds a where clause from a dictionary """ CoyoteDb.escape_dictionary(dictionary) clause = join_operator.join( (' {k} is {v} ' if str(v).lower() == 'null' else ' {k} ...
Returns a dictionary of object's attributes, ignoring methods @param obj: The object to represent as dict @param omit_null_fields: If true, will not include fields in the dictionary that are null @return: Dictionary of the object's attributes def get_dictionary_representation_of_object_attribu...
Instantiates a new class (that takes no init params) and populates its attributes with a dictionary @type dictionary: dict @param dictionary: Dictionary representation of the object @param class_type: type @return: None def get_object_from_dictionary_representation(dictionary, class_ty...
Constructs the where clause based on a dictionary of values >>> build_where_clause({'id': 456, 'name': 'myrecord'}, operator='OR') >>> 'WHERE id = 456 OR name = "myrecord" ' def build_where_clause(mappings, operator='AND'): """Constructs the where clause based on a dictionary of values ...
Executes the sql statement, but does not commit. Returns the cursor to commit @return: DB and cursor instance following sql execution def execute(*args, **kwargs): """Executes the sql statement, but does not commit. Returns the cursor to commit @return: DB and cursor instance following sql ex...
Executes the sql statement, but does not commit. Returns the cursor to commit @return: DB and cursor instance following sql execution def execute_read_only(*args, **kwargs): # TODO: consolidate with execute """Executes the sql statement, but does not commit. Returns the cursor to commit ...
Executes and commits the sql statement @return: None def execute_and_commit(*args, **kwargs): """Executes and commits the sql statement @return: None """ db, cursor = CoyoteDb.execute(*args, **kwargs) db.commit() return cursor
Inserts an object's values into a given table, will not populate Nonetype values @param instance: Instance of an object to insert @param table: Table in which to insert instance values @return: ID of the last inserted row def insert_instance(instance, table, **kwargs): """Inserts an ob...
Updates and commits with an insert sql statement, returns the record, but with a small chance of a race condition @param sql: sql to execute @return: The last row inserted def update(sql, *args, **kwargs): """Updates and commits with an insert sql statement, returns the record, but wit...
Deletes and commits with an insert sql statement def delete(sql, *args, **kwargs): """Deletes and commits with an insert sql statement""" assert "delete" in sql.lower(), 'This function requires a delete statement, provided: {}'.format(sql) CoyoteDb.execute_and_commit(sql, *args, **kwargs)
Given a dictionary and an object instance, will set all object attributes equal to the dictionary's keys and values. Assumes dictionary does not have any keys for which object does not have attributes @type dictionary: dict @param dictionary: Dictionary representation of the object @par...
Formats a time to be Shapeways database-compatible @param time: Datetime or string object to format @rtype: str @return: Time formatted as a string def format_time(time): """Formats a time to be Shapeways database-compatible @param time: Datetime or string object to format ...
Formats a date to be Shapeways database-compatible @param date: Datetime or string object to format @rtype: str @return: Date formatted as a string def format_date(date): """Formats a date to be Shapeways database-compatible @param date: Datetime or string object to format ...
Driver gets the provided url in the browser, returns True if successful url -- An absolute or relative url stored as a string def visit(self, url=''): """ Driver gets the provided url in the browser, returns True if successful url -- An absolute or relative url stored as a string ...
Tests if an alert is present @return: True if alert is present, False otherwise def is_alert_present(self): """Tests if an alert is present @return: True if alert is present, False otherwise """ current_frame = None try: current_frame = self.driver.current_...
Attempts to locate an element, trying the number of times specified by the driver wrapper; Will throw a WebDriverWrapperException if no element is found @type locator: webdriverwrapper.support.locator.Locator @param locator: the locator or css string used to query the element ...