-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Field path class #4392
Field path class #4392
Conversation
@schmidt-sebastian, please take a look. |
invalid_characters = '~*/[]' | ||
if len(parts) == 1: | ||
parts = parts[0] | ||
if isinstance(parts, basestring): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
for part in parts: | ||
if (not part | ||
or not isinstance(part, basestring) | ||
or part in invalid_characters): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
else: | ||
part_ans += letter | ||
ans.append('`' + part_ans + '`') | ||
return '.'.join(ans) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
def test_empty_string_inside_string_fails(self): | ||
with self.assertRaises(ValueError): | ||
field_path = self._make_one('a..b') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
def __init__(self, *parts): | ||
invalid_characters = '~*/[]' | ||
if len(parts) == 1: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
if (not part | ||
or not isinstance(part, basestring) | ||
or part in invalid_characters): | ||
raise ValueError |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
Returns: string representation of the path stored within | ||
""" | ||
pattern = re.compile(r'[A-Za-z_][A-Za-z_0-9]*') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
if match: | ||
ans.append(part) | ||
else: | ||
part_ans = '' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ed331d7
to
1592e66
Compare
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
dcdfd4e
to
6425b42
Compare
@jba @schmidt-sebastian PTAL. I used the string replace method like node. Please check my tests to see that they are still the desired behavior. In addition, what about unicode? I will work on the update and query methods in a separate PR. |
I will wait on updating |
1b4a259
to
dd1ff57
Compare
@jba @schmidt-sebastian I understand each language has different quirks and that each user would probably not be using cross language. However, shouldn't something like this be consistent across all languages? Also, according to the docs that was here: Thanks. |
The doc is now at https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1beta1#google.firestore.v1beta1.Document and it explicitly allows unicode keys (it refers to UTF-8). It's not important that the names of unexposed functions are the same across languages. We only care about the exposed surface and the behavior. |
|
||
@classmethod | ||
def from_string(cls, string): | ||
""" Creates a FieldPath with a string representation. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
self.parts = tuple(parts) | ||
|
||
@classmethod | ||
def from_string(cls, string): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
return FieldPath(*string) | ||
|
||
def to_api_repr(self): | ||
""" Returns string representation of the FieldPath |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
parts: (one or more strings) | ||
Indicating path of the key to be used. | ||
""" | ||
pattern = re.compile(r'[A-Za-z_][A-Za-z_0-9]*') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
field_path = self._make_one(parts) | ||
self.assertEqual(r'`\\\\`', field_path.to_api_repr()) | ||
|
||
def test_to_api_repr_underscore_valid(self): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
with self.assertRaises(ValueError): | ||
field_path = self._make_one(parts) | ||
|
||
def test_key(self): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
def __hash__(self): | ||
return hash(self.to_api_repr()) | ||
|
||
def __eq__(self, other): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
""" | ||
invalid_characters = '~*/[]' | ||
string = string.split('.') | ||
for part in string: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
0d0e214
to
0a379dd
Compare
@schmidt-sebastian I moved the validation and did the empty string check in the constructor. Please take a look at my 3rd review changes (4th commit) and see if that's what you meant. Line 135 did not check for an empty string before. |
0a379dd
to
9fb3721
Compare
Looks good to me. Thanks. |
Sorry I don't have cycles for this right now. @tseaver can you tap in? (In particular, we want to avoid re-inventing the wheel for code that already does this.) |
@dhermes it's ok. I am just trying to clean out some issues/prs. |
9fb3721
to
ed6e22e
Compare
ed6e22e
to
3d2631b
Compare
I'm going to go ahead and merge this in. Let me know if there are any issues. |
@jba please see if this is the desired behavior you wanted or feel free to give me any comments.