Skip to content

Commit ec85af2

Browse files
committed
fixed bytes handling
1 parent d72caed commit ec85af2

File tree

2 files changed

+12
-37
lines changed

2 files changed

+12
-37
lines changed

test_proxy/client_handler.py

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -123,54 +123,35 @@ async def ReadRow(self, row_key, **kwargs):
123123

124124
@error_safe
125125
async def MutateRow(self, request, **kwargs):
126-
import base64
127126
from google.cloud.bigtable.mutations import Mutation
128127
table_id = request["table_name"].split("/")[-1]
129128
app_profile_id = self.app_profile_id or request.get("app_profile_id", None)
130129
table = self.client.get_table(self.instance_id, table_id, app_profile_id)
131130
kwargs["operation_timeout"] = kwargs.get("operation_timeout", self.per_operation_timeout) or 20
132131
row_key = request["row_key"]
133-
try:
134-
# conformance tests send row keys as base64 encoded strings
135-
row_key = base64.b64decode(row_key)
136-
except Exception:
137-
pass
138132
mutations = [Mutation._from_dict(d) for d in request["mutations"]]
139133
await table.mutate_row(row_key, mutations, **kwargs)
140134
return "OK"
141135

142136
@error_safe
143137
async def BulkMutateRows(self, request, **kwargs):
144138
from google.cloud.bigtable.mutations import RowMutationEntry
145-
import base64
146139
table_id = request["table_name"].split("/")[-1]
147140
app_profile_id = self.app_profile_id or request.get("app_profile_id", None)
148141
table = self.client.get_table(self.instance_id, table_id, app_profile_id)
149142
kwargs["operation_timeout"] = kwargs.get("operation_timeout", self.per_operation_timeout) or 20
150-
# conformance tests send row keys as base64 encoded strings
151-
for entry in request["entries"]:
152-
try:
153-
entry["row_key"] = base64.b64decode(entry["row_key"])
154-
except Exception:
155-
pass
156143
entry_list = [RowMutationEntry._from_dict(entry) for entry in request["entries"]]
157144
await table.bulk_mutate_rows(entry_list, **kwargs)
158145
return "OK"
159146

160147
@error_safe
161148
async def CheckAndMutateRow(self, request, **kwargs):
162149
from google.cloud.bigtable.mutations import Mutation, SetCell
163-
import base64
164150
table_id = request["table_name"].split("/")[-1]
165151
app_profile_id = self.app_profile_id or request.get("app_profile_id", None)
166152
table = self.client.get_table(self.instance_id, table_id, app_profile_id)
167153
kwargs["operation_timeout"] = kwargs.get("operation_timeout", self.per_operation_timeout) or 20
168154
row_key = request["row_key"]
169-
try:
170-
# conformance tests send row keys as base64 encoded strings
171-
row_key = base64.b64decode(row_key)
172-
except Exception:
173-
pass
174155
# add default values for incomplete dicts, so they can still be parsed to objects
175156
true_mutations = []
176157
for mut_dict in request.get("true_mutations", []):
@@ -200,32 +181,16 @@ async def CheckAndMutateRow(self, request, **kwargs):
200181
async def ReadModifyWriteRow(self, request, **kwargs):
201182
from google.cloud.bigtable.read_modify_write_rules import IncrementRule
202183
from google.cloud.bigtable.read_modify_write_rules import AppendValueRule
203-
import base64
204184
table_id = request["table_name"].split("/")[-1]
205185
app_profile_id = self.app_profile_id or request.get("app_profile_id", None)
206186
table = self.client.get_table(self.instance_id, table_id, app_profile_id)
207187
kwargs["operation_timeout"] = kwargs.get("operation_timeout", self.per_operation_timeout) or 20
208188
row_key = request["row_key"]
209-
try:
210-
# conformance tests send row keys as base64 encoded strings
211-
row_key = base64.b64decode(row_key)
212-
except Exception:
213-
pass
214189
rules = []
215-
# conformance tests send qualifiers and values as base64 encoded strings
216190
for rule_dict in request.get("rules", []):
217191
qualifier = rule_dict["column_qualifier"]
218-
try:
219-
qualifier = base64.b64decode(qualifier)
220-
except Exception:
221-
pass
222192
if "append_value" in rule_dict:
223-
value = rule_dict["append_value"]
224-
try:
225-
value = base64.b64decode(value)
226-
except Exception:
227-
pass
228-
new_rule = AppendValueRule(rule_dict["family_name"], qualifier, value)
193+
new_rule = AppendValueRule(rule_dict["family_name"], qualifier, rule_dict["append_value"])
229194
else:
230195
new_rule = IncrementRule(rule_dict["family_name"], qualifier, rule_dict["increment_amount"])
231196
rules.append(new_rule)

test_proxy/test_proxy.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ async def client_handler_process_async(request_q, queue_pool, use_legacy_client=
5656
Defines a process that recives Bigtable requests from a grpc_server_process,
5757
and runs the request using a client library instance
5858
"""
59+
import base64
5960
import re
6061
import asyncio
6162
import warnings
@@ -75,6 +76,15 @@ def format_dict(input_obj):
7576
# check for time encodings
7677
if re.match("^[0-9]+s$", input_obj):
7778
return int(input_obj[:-1])
79+
# check for encoded bytes
80+
if re.match("^[A-Za-z0-9+/=]+$", input_obj):
81+
try:
82+
decoded_str = base64.b64decode(input_obj)
83+
# if the string contains non-ascii bytes, raise exception
84+
decoded_str.decode("ascii")
85+
return decoded_str
86+
except Exception:
87+
pass
7888
# check for int strings
7989
try:
8090
return int(input_obj)
@@ -174,4 +184,4 @@ def client_handler_process(request_q, queue_pool, legacy_client=False):
174184
# )
175185
# client.start()
176186
# grpc_server_process(request_q, response_queue_pool, port)
177-
# client.join()
187+
client.join()

0 commit comments

Comments
 (0)