Server IP : 85.214.239.14 / Your IP : 18.226.186.153 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /srv/modoboa/env/lib64/python3.5/site-packages/uritemplate/ |
Upload File : |
""" uritemplate.api =============== This module contains the very simple API provided by uritemplate. """ from uritemplate.orderedset import OrderedSet from uritemplate.template import URITemplate def expand(uri, var_dict=None, **kwargs): """Expand the template with the given parameters. :param str uri: The templated URI to expand :param dict var_dict: Optional dictionary with variables and values :param kwargs: Alternative way to pass arguments :returns: str Example:: expand('https://api.github.com{/end}', {'end': 'users'}) expand('https://api.github.com{/end}', end='gists') .. note:: Passing values by both parts, may override values in ``var_dict``. For example:: expand('https://{var}', {'var': 'val1'}, var='val2') ``val2`` will be used instead of ``val1``. """ return URITemplate(uri).expand(var_dict, **kwargs) def partial(uri, var_dict=None, **kwargs): """Partially expand the template with the given parameters. If all of the parameters for the template are not given, return a partially expanded template. :param dict var_dict: Optional dictionary with variables and values :param kwargs: Alternative way to pass arguments :returns: :class:`URITemplate` Example:: t = URITemplate('https://api.github.com{/end}') t.partial() # => URITemplate('https://api.github.com{/end}') """ return URITemplate(uri).partial(var_dict, **kwargs) def variables(uri): """Parse the variables of the template. This returns all of the variable names in the URI Template. :returns: Set of variable names :rtype: set Example:: variables('https://api.github.com{/end}) # => {'end'} variables('https://api.github.com/repos{/username}{/repository}') # => {'username', 'repository'} """ return OrderedSet(URITemplate(uri).variable_names)