Uh oh!
There was an error while loading. Please reload this page.
Add google.api.core.path_template - #3851
Conversation
theacodes
commented
Aug 22, 2017
@lukesneeringer@dhermes this gave me more trouble than I anticipated, but the tests give me confidence that this works as expected. |
lukesneeringer
commented
Aug 22, 2017
Still simpler than a lex-yacc implementation. ;-) Sanity check: Correct? |
theacodes
commented
Aug 22, 2017
via email
Much simpler …On Mon, Aug 21, 2017, 7:48 PM Luke Sneeringer ***@***.***> wrote:
Still simpler than a lex-yacc implementation. ;-)
Sanity check: Correct?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3851 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAPUc6HWLCb78HkRVkBspwrTMa-n4IIbks5sakF9gaJpZM4O-Cw2>
.
|
| raise ValueError( | ||
| 'Named variable \'{}\' not specified and needed by template ' | ||
| '`{}` at position {}'.format( | ||
| name, match.string, match.start())) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| Raises: | ||
| ValueError: If a positional or named variable is required by the | ||
| template but not specified. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| if not template: | ||
| return _SINGLE_SEGEMENT_PATTERN.format(name) | ||
| elif template == '**': | ||
| return _MULTI_SEGEMENT_PATTERN.format(name) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| Returns: | ||
| bool: True if the path matches. | ||
| """ | ||
| pattern = _generate_pattern_for_template(tmpl) + '$' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| @pytest.mark.parametrize('tmpl, args, kwargs, exc_match', [ | ||
| # Missing positional arg. | ||
| ['v1/*', [], {}, 'Positional'], |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| ['/v1/*/{name}', ['a'], {'name': 'parent'}, '/v1/a/parent'], | ||
| ['/v1/{name}/*', ['a'], {'name': 'parent'}, '/v1/parent/a'], | ||
| ['/v1/{parent}/*/{child}/*', ['a', 'b'], | ||
| {'parent': 'parent', 'child': 'child'}, '/v1/parent/a/child/b'], |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| import six | ||
| # Regular expression for extracting variable parts from a path template. | ||
| # The variables can be expressed as: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| ['/v1/{name=parent/*}/*', ['a'], {'name': 'parent/child'}, | ||
| '/v1/parent/child/a'], | ||
| ['/v1/*/{name=parent/**}', ['a'], {'name': 'parent/child/object'}, | ||
| '/v1/a/parent/child/object'], |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| match (re.Match): A regular expression match. | ||
| Returns: | ||
| str: The expaned variable to replace the match. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| import six | ||
| # Regular expression for extracting variable parts from a path template. | ||
| # The variables can be expressed as: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| is encountered. | ||
| """ | ||
| replacer = functools.partial(_expand_variable_match, list(args), kwargs) | ||
| return _VARIABLE_RE.sub(replacer, tmpl) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Towards #3842