Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding datastore Key.(to|from)_legacy_urlsafe. #3491

Merged
merged 8 commits into from
Jun 8, 2017

Conversation

dhermes
Copy link
Contributor

@dhermes dhermes commented Jun 8, 2017

Fixes #3293.

@lukesneeringer, I'll let @jonparrott describe why this is useful to add.

/cc @pcostell

@dhermes dhermes added the api: datastore Issues related to the Datastore API. label Jun 8, 2017
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jun 8, 2017
@@ -0,0 +1,16 @@
syntax = "proto2";

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


This is intended to work with the "legacy" representation of a datastore
"Key" used within Google App Engine (a so-called "Reference"). This is
intended as a drop in for the value returned when using

This comment was marked as spam.

``ndb.Key(...).urlsafe()``.

:rtype: bytes
:returns: ASCII bytes contain the key encoded as URL-safe base64.

This comment was marked as spam.

:returns: The value that was decoded.
"""
# This is 3-4x faster than urlsafe_b64decode()
return base64.b64decode(

This comment was marked as spam.

:rtype: str
:returns: The cleaned value.
"""
if app_str.startswith('s~') or app_str.startswith('e~'):

This comment was marked as spam.

Also resolved some lint issues (line too long) and restructed
unit test to be able to re-use "stored" values.
In particular:

- Just splitting on ~ when cleaning app strings
- Rewording to_legacy_urlsafe() docstring to invoke `ndb.Key(urlsafe=...)`
  and to restate the "returns" text
- Removing the _urlsafe_b64(decode|encode) micro-optimizations that
  were brought over from the ndb codebase
@dhermes
Copy link
Contributor Author

dhermes commented Jun 8, 2017

I've got LGTM here from @jonparrott and from @lukesneeringer over Hangouts, so I'm going to merge.

@pcostell I'm happy to address any other concerns in a follow up PR. In particular, maybe you want me to add some kind of warning or note to the docstrings of these methods?

@dhermes dhermes merged commit 8682e53 into googleapis:master Jun 8, 2017
@dhermes dhermes deleted the ds-legacy-urlsafe branch June 8, 2017 23:15
landrito pushed a commit to landrito/google-cloud-python that referenced this pull request Aug 21, 2017
* Adding bare-minimum proto for converting legacy App Engine "Reference" pbs.

* Rough draft of working implementation of datastore Key.(to|from)_legacy_urlsafe.

Needs more tests but wanted to get the PR in front of reviewers ASAP.

* Adding implementation for datastore Key.to_legacy_urlsafe().

Also resolved some lint issues (line too long) and restructured
unit test to be able to re-use "stored" values.

* Adding _onestore_v3_pb2 to ignored files for flake8.

* Addressing @jonparrott feedback.

In particular:

- Just splitting on ~ when cleaning app strings
- Rewording to_legacy_urlsafe() docstring to invoke `ndb.Key(urlsafe=...)`
  and to restate the "returns" text
- Removing the _urlsafe_b64(decode|encode) micro-optimizations that
  were brought over from the ndb codebase

* Adding test coverage for helpers needed for Key.(to|from)_legacy_urlsafe.

* Adding LICENSE header to hand-written legacy GAE proto.

* Renaming _onestore_v3.proto --> _app_engine_key.proto.
landrito pushed a commit to landrito/google-cloud-python that referenced this pull request Aug 22, 2017
* Adding bare-minimum proto for converting legacy App Engine "Reference" pbs.

* Rough draft of working implementation of datastore Key.(to|from)_legacy_urlsafe.

Needs more tests but wanted to get the PR in front of reviewers ASAP.

* Adding implementation for datastore Key.to_legacy_urlsafe().

Also resolved some lint issues (line too long) and restructured
unit test to be able to re-use "stored" values.

* Adding _onestore_v3_pb2 to ignored files for flake8.

* Addressing @jonparrott feedback.

In particular:

- Just splitting on ~ when cleaning app strings
- Rewording to_legacy_urlsafe() docstring to invoke `ndb.Key(urlsafe=...)`
  and to restate the "returns" text
- Removing the _urlsafe_b64(decode|encode) micro-optimizations that
  were brought over from the ndb codebase

* Adding test coverage for helpers needed for Key.(to|from)_legacy_urlsafe.

* Adding LICENSE header to hand-written legacy GAE proto.

* Renaming _onestore_v3.proto --> _app_engine_key.proto.
landrito pushed a commit to landrito/google-cloud-python that referenced this pull request Aug 22, 2017
* Adding bare-minimum proto for converting legacy App Engine "Reference" pbs.

* Rough draft of working implementation of datastore Key.(to|from)_legacy_urlsafe.

Needs more tests but wanted to get the PR in front of reviewers ASAP.

* Adding implementation for datastore Key.to_legacy_urlsafe().

Also resolved some lint issues (line too long) and restructured
unit test to be able to re-use "stored" values.

* Adding _onestore_v3_pb2 to ignored files for flake8.

* Addressing @jonparrott feedback.

In particular:

- Just splitting on ~ when cleaning app strings
- Rewording to_legacy_urlsafe() docstring to invoke `ndb.Key(urlsafe=...)`
  and to restate the "returns" text
- Removing the _urlsafe_b64(decode|encode) micro-optimizations that
  were brought over from the ndb codebase

* Adding test coverage for helpers needed for Key.(to|from)_legacy_urlsafe.

* Adding LICENSE header to hand-written legacy GAE proto.

* Renaming _onestore_v3.proto --> _app_engine_key.proto.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants