Skip to content

Commit c552fa2

Browse files
chore(python): run blacken session for all directories with a noxfile (#291)
* chore(python): run blacken session for all directories with a noxfile Source-Link: googleapis/synthtool@bc0de6e Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:39ad8c0570e4f5d2d3124a509de4fe975e799e2b97e0f58aed88f8880d5a8b60 * lint Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent 3e01468 commit c552fa2

File tree

4 files changed

+35
-82
lines changed

4 files changed

+35
-82
lines changed

dlp/snippets/custom_infotype.py

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ def inspect_string_with_exclusion_dict(
5555
"rules": [
5656
{
5757
"exclusion_rule": {
58-
"dictionary": {
59-
"word_list": {
60-
"words": exclusion_list
61-
},
62-
},
58+
"dictionary": {"word_list": {"words": exclusion_list}},
6359
"matching_type": google.cloud.dlp_v2.MatchingType.MATCHING_TYPE_FULL_MATCH,
6460
}
6561
}
@@ -94,6 +90,7 @@ def inspect_string_with_exclusion_dict(
9490
else:
9591
print("No findings.")
9692

93+
9794
# [END dlp_inspect_string_with_exclusion_dict]
9895

9996

@@ -134,9 +131,7 @@ def inspect_string_with_exclusion_regex(
134131
"rules": [
135132
{
136133
"exclusion_rule": {
137-
"regex": {
138-
"pattern": exclusion_regex,
139-
},
134+
"regex": {"pattern": exclusion_regex},
140135
"matching_type": google.cloud.dlp_v2.MatchingType.MATCHING_TYPE_FULL_MATCH,
141136
}
142137
}
@@ -171,6 +166,7 @@ def inspect_string_with_exclusion_regex(
171166
else:
172167
print("No findings.")
173168

169+
174170
# [END dlp_inspect_string_with_exclusion_regex]
175171

176172

@@ -211,11 +207,7 @@ def inspect_string_with_exclusion_dict_substring(
211207
"rules": [
212208
{
213209
"exclusion_rule": {
214-
"dictionary": {
215-
"word_list": {
216-
"words": exclusion_list
217-
},
218-
},
210+
"dictionary": {"word_list": {"words": exclusion_list}},
219211
"matching_type": google.cloud.dlp_v2.MatchingType.MATCHING_TYPE_PARTIAL_MATCH,
220212
}
221213
}
@@ -250,6 +242,7 @@ def inspect_string_with_exclusion_dict_substring(
250242
else:
251243
print("No findings.")
252244

245+
253246
# [END dlp_inspect_string_with_exclusion_dict_substring]
254247

255248

@@ -293,11 +286,7 @@ def inspect_string_custom_excluding_substring(
293286
"rules": [
294287
{
295288
"exclusion_rule": {
296-
"dictionary": {
297-
"word_list": {
298-
"words": exclusion_list
299-
},
300-
},
289+
"dictionary": {"word_list": {"words": exclusion_list}},
301290
"matching_type": google.cloud.dlp_v2.MatchingType.MATCHING_TYPE_PARTIAL_MATCH,
302291
}
303292
}
@@ -332,13 +321,12 @@ def inspect_string_custom_excluding_substring(
332321
else:
333322
print("No findings.")
334323

324+
335325
# [END dlp_inspect_string_custom_excluding_substring]
336326

337327

338328
# [START dlp_inspect_string_custom_omit_overlap]
339-
def inspect_string_custom_omit_overlap(
340-
project, content_string
341-
):
329+
def inspect_string_custom_omit_overlap(project, content_string):
342330
"""Matches PERSON_NAME and a custom detector,
343331
but if they overlap only matches the custom detector
344332
@@ -414,6 +402,7 @@ def inspect_string_custom_omit_overlap(
414402
else:
415403
print("No findings.")
416404

405+
417406
# [END dlp_inspect_string_custom_omit_overlap]
418407

419408

@@ -489,13 +478,12 @@ def omit_name_if_also_email(
489478
else:
490479
print("No findings.")
491480

481+
492482
# [END dlp_omit_name_if_also_email]
493483

494484

495485
# [START dlp_inspect_string_without_overlap]
496-
def inspect_string_without_overlap(
497-
project, content_string
498-
):
486+
def inspect_string_without_overlap(project, content_string):
499487
"""Matches EMAIL_ADDRESS and DOMAIN_NAME, but DOMAIN_NAME is omitted
500488
if it overlaps with EMAIL_ADDRESS
501489
@@ -575,6 +563,7 @@ def inspect_string_without_overlap(
575563
else:
576564
print("No findings.")
577565

566+
578567
# [END dlp_inspect_string_without_overlap]
579568

580569

@@ -647,13 +636,12 @@ def inspect_with_person_name_w_custom_hotword(
647636
else:
648637
print("No findings.")
649638

639+
650640
# [END inspect_with_person_name_w_custom_hotword]
651641

652642

653643
# [START dlp_inspect_string_multiple_rules]
654-
def inspect_string_multiple_rules(
655-
project, content_string
656-
):
644+
def inspect_string_multiple_rules(project, content_string):
657645
"""Uses the Data Loss Prevention API to modify likelihood for matches on
658646
PERSON_NAME combining multiple hotword and exclusion rules.
659647
@@ -689,11 +677,7 @@ def inspect_string_multiple_rules(
689677

690678
# Construct exclusion rules
691679
quasimodo_rule = {
692-
"dictionary": {
693-
"word_list": {
694-
"words": ["quasimodo"]
695-
},
696-
},
680+
"dictionary": {"word_list": {"words": ["quasimodo"]}},
697681
"matching_type": google.cloud.dlp_v2.MatchingType.MATCHING_TYPE_PARTIAL_MATCH,
698682
}
699683
redacted_rule = {
@@ -741,6 +725,7 @@ def inspect_string_multiple_rules(
741725
else:
742726
print("No findings.")
743727

728+
744729
# [END dlp_inspect_string_multiple_rules]
745730

746731

dlp/snippets/custom_infotype_test.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ def test_inspect_string_custom_omit_overlap(capsys):
7171

7272

7373
def test_omit_name_if_also_email(capsys):
74-
custom_infotype.omit_name_if_also_email(
75-
GCLOUD_PROJECT, "[email protected]"
76-
)
74+
custom_infotype.omit_name_if_also_email(GCLOUD_PROJECT, "[email protected]")
7775

7876
# Ensure we found only EMAIL_ADDRESS, and not PERSON_NAME.
7977
out, _ = capsys.readouterr()
@@ -111,9 +109,7 @@ def test_inspect_string_multiple_rules_patient(capsys):
111109

112110

113111
def test_inspect_string_multiple_rules_doctor(capsys):
114-
custom_infotype.inspect_string_multiple_rules(
115-
GCLOUD_PROJECT, "doctor: Jane Doe"
116-
)
112+
custom_infotype.inspect_string_multiple_rules(GCLOUD_PROJECT, "doctor: Jane Doe")
117113

118114
out, _ = capsys.readouterr()
119115
assert "No findings" in out

dlp/snippets/deid.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,12 @@ def deidentify_with_fpe(
290290

291291
# [START dlp_deidentify_deterministic]
292292
def deidentify_with_deterministic(
293-
project,
294-
input_str,
295-
info_types,
296-
surrogate_type=None,
297-
key_name=None,
298-
wrapped_key=None,
293+
project,
294+
input_str,
295+
info_types,
296+
surrogate_type=None,
297+
key_name=None,
298+
wrapped_key=None,
299299
):
300300
"""Deidentifies sensitive data in a string using deterministic encryption.
301301
Args:
@@ -338,7 +338,9 @@ def deidentify_with_deterministic(
338338

339339
# Add surrogate type
340340
if surrogate_type:
341-
crypto_replace_deterministic_config["surrogate_info_type"] = {"name": surrogate_type}
341+
crypto_replace_deterministic_config["surrogate_info_type"] = {
342+
"name": surrogate_type
343+
}
342344

343345
# Construct inspect configuration dictionary
344346
inspect_config = {"info_types": [{"name": info_type} for info_type in info_types]}
@@ -372,6 +374,7 @@ def deidentify_with_deterministic(
372374
# Print results
373375
print(response.item.value)
374376

377+
375378
# [END dlp_deidentify_deterministic]
376379

377380

@@ -468,11 +471,7 @@ def reidentify_with_fpe(
468471

469472
# [START dlp_reidentify_deterministic]
470473
def reidentify_with_deterministic(
471-
project,
472-
input_str,
473-
surrogate_type=None,
474-
key_name=None,
475-
wrapped_key=None,
474+
project, input_str, surrogate_type=None, key_name=None, wrapped_key=None,
476475
):
477476
"""Deidentifies sensitive data in a string using deterministic encryption.
478477
Args:
@@ -547,6 +546,7 @@ def reidentify_with_deterministic(
547546
# Print results
548547
print(response.item.value)
549548

549+
550550
# [END dlp_reidentify_deterministic]
551551

552552

dlp/snippets/risk_test.py

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -118,40 +118,12 @@ def bigquery_project():
118118

119119
rows_to_insert = [(u"Gary Smith", u"My email is [email protected]")]
120120
harmful_rows_to_insert = [
121-
(
122-
u"Gandalf",
123-
u"(123) 456-7890",
124-
"4231 5555 6781 9876",
125-
27,
126-
"Male",
127-
"US",
128-
),
129-
(
130-
u"Dumbledore",
131-
u"(313) 337-1337",
132-
"6291 8765 1095 7629",
133-
27,
134-
"Male",
135-
"US",
136-
),
121+
(u"Gandalf", u"(123) 456-7890", "4231 5555 6781 9876", 27, "Male", "US",),
122+
(u"Dumbledore", u"(313) 337-1337", "6291 8765 1095 7629", 27, "Male", "US",),
137123
(u"Joe", u"(452) 123-1234", "3782 2288 1166 3030", 35, "Male", "US"),
138124
(u"James", u"(567) 890-1234", "8291 3627 8250 1234", 19, "Male", "US"),
139-
(
140-
u"Marie",
141-
u"(452) 123-1234",
142-
"8291 3627 8250 1234",
143-
35,
144-
"Female",
145-
"US",
146-
),
147-
(
148-
u"Carrie",
149-
u"(567) 890-1234",
150-
"2253 5218 4251 4526",
151-
35,
152-
"Female",
153-
"US",
154-
),
125+
(u"Marie", u"(452) 123-1234", "8291 3627 8250 1234", 35, "Female", "US",),
126+
(u"Carrie", u"(567) 890-1234", "2253 5218 4251 4526", 35, "Female", "US",),
155127
]
156128

157129
bigquery_client.insert_rows(table, rows_to_insert)

0 commit comments

Comments
 (0)