Skip to content

Commit af85667

Browse files
egalpinegalpin
authored andcommitted
Adds optional location_prefix kwarg in to_legacy_urlsafe
1 parent a62931a commit af85667

File tree

1 file changed

+15
-3
lines changed
  • datastore/google/cloud/datastore

1 file changed

+15
-3
lines changed

datastore/google/cloud/datastore/key.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def to_protobuf(self):
298298

299299
return key
300300

301-
def to_legacy_urlsafe(self):
301+
def to_legacy_urlsafe(self, location_prefix=None):
302302
"""Convert to a base64 encode urlsafe string for App Engine.
303303
304304
This is intended to work with the "legacy" representation of a
@@ -310,13 +310,25 @@ def to_legacy_urlsafe(self):
310310
.. note::
311311
312312
The string returned by ``to_legacy_urlsafe`` is equivalent, but
313-
not identical, to the string returned by ``ndb``.
313+
not identical, to the string returned by ``ndb``. The location
314+
prefix may need to be specified to obtain idendentical urlsafe
315+
keys.
316+
317+
:type location_prefix: str
318+
:param location_prefix: The location prefix of ones project. Often
319+
this value is 's~', but may be 'dev~', 'e~', or
320+
other location prefixes currently unknown.
314321
315322
:rtype: bytes
316323
:returns: A bytestring containing the key encoded as URL-safe base64.
317324
"""
325+
if location_prefix:
326+
project_id = location_prefix + self.project
327+
else:
328+
project_id = self.project
329+
318330
reference = _app_engine_key_pb2.Reference(
319-
app=self.project,
331+
app=project_id,
320332
path=_to_legacy_path(self._path), # Avoid the copy.
321333
name_space=self.namespace,
322334
)

0 commit comments

Comments
 (0)