Skip to content

Commit

Permalink
chore(python): use black==22.3.0 (#359)
Browse files Browse the repository at this point in the history
Source-Link: googleapis/synthtool@6fab84a
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:7cffbc10910c3ab1b852c05114a08d374c195a81cdec1d4a67a1d129331d0bfe
  • Loading branch information
gcf-owl-bot[bot] committed Mar 29, 2022
1 parent c08e9dd commit cfb490a
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 49 deletions.
9 changes: 6 additions & 3 deletions dlp/snippets/custom_infotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ def inspect_string_custom_omit_overlap(project, content_string):

# [START dlp_omit_name_if_also_email]
def omit_name_if_also_email(
project, content_string,
project,
content_string,
):
"""Matches PERSON_NAME and EMAIL_ADDRESS, but not both.
Expand Down Expand Up @@ -731,7 +732,8 @@ def inspect_string_multiple_rules(project, content_string):

# [START dlp_inspect_with_medical_record_number_custom_regex_detector]
def inspect_with_medical_record_number_custom_regex_detector(
project, content_string,
project,
content_string,
):
"""Uses the Data Loss Prevention API to analyze string with medical record
number custom regex detector
Expand Down Expand Up @@ -793,7 +795,8 @@ def inspect_with_medical_record_number_custom_regex_detector(

# [START dlp_inspect_with_medical_record_number_w_custom_hotwords]
def inspect_with_medical_record_number_w_custom_hotwords(
project, content_string,
project,
content_string,
):
"""Uses the Data Loss Prevention API to analyze string with medical record
number custom regex detector, with custom hotwords rules to boost finding
Expand Down
37 changes: 27 additions & 10 deletions dlp/snippets/deid.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ def deidentify_with_mask(

# [START dlp_deidentify_redact]
def deidentify_with_redact(
project, input_str, info_types,
project,
input_str,
info_types,
):
"""Uses the Data Loss Prevention API to deidentify sensitive data in a
string by redacting matched input values.
Expand Down Expand Up @@ -135,7 +137,10 @@ def deidentify_with_redact(

# [START dlp_deidentify_replace]
def deidentify_with_replace(
project, input_str, info_types, replacement_str="REPLACEMENT_STR",
project,
input_str,
info_types,
replacement_str="REPLACEMENT_STR",
):
"""Uses the Data Loss Prevention API to deidentify sensitive data in a
string by replacing matched input values with a value you specify.
Expand Down Expand Up @@ -471,7 +476,11 @@ def reidentify_with_fpe(

# [START dlp_reidentify_deterministic]
def reidentify_with_deterministic(
project, input_str, surrogate_type=None, key_name=None, wrapped_key=None,
project,
input_str,
surrogate_type=None,
key_name=None,
wrapped_key=None,
):
"""Re-identifies content that was previously de-identified through deterministic encryption.
Args:
Expand Down Expand Up @@ -949,7 +958,8 @@ def deidentify_with_replace_infotype(project, item, info_types):
default=["FIRST_NAME", "LAST_NAME", "EMAIL_ADDRESS"],
)
mask_parser.add_argument(
"project", help="The Google Cloud project id to use as a parent resource.",
"project",
help="The Google Cloud project id to use as a parent resource.",
)
mask_parser.add_argument("item", help="The string to deidentify.")
mask_parser.add_argument(
Expand Down Expand Up @@ -982,7 +992,8 @@ def deidentify_with_replace_infotype(project, item, info_types):
default=["FIRST_NAME", "LAST_NAME", "EMAIL_ADDRESS"],
)
replace_parser.add_argument(
"project", help="The Google Cloud project id to use as a parent resource.",
"project",
help="The Google Cloud project id to use as a parent resource.",
)
replace_parser.add_argument("item", help="The string to deidentify.")
replace_parser.add_argument(
Expand All @@ -1004,7 +1015,8 @@ def deidentify_with_replace_infotype(project, item, info_types):
default=["FIRST_NAME", "LAST_NAME", "EMAIL_ADDRESS"],
)
fpe_parser.add_argument(
"project", help="The Google Cloud project id to use as a parent resource.",
"project",
help="The Google Cloud project id to use as a parent resource.",
)
fpe_parser.add_argument(
"item",
Expand Down Expand Up @@ -1046,7 +1058,8 @@ def deidentify_with_replace_infotype(project, item, info_types):
"Encryption (FPE).",
)
reid_parser.add_argument(
"project", help="The Google Cloud project id to use as a parent resource.",
"project",
help="The Google Cloud project id to use as a parent resource.",
)
reid_parser.add_argument(
"item",
Expand Down Expand Up @@ -1086,7 +1099,8 @@ def deidentify_with_replace_infotype(project, item, info_types):
help="Deidentify dates in a CSV file by pseudorandomly shifting them.",
)
date_shift_parser.add_argument(
"project", help="The Google Cloud project id to use as a parent resource.",
"project",
help="The Google Cloud project id to use as a parent resource.",
)
date_shift_parser.add_argument(
"input_csv_file",
Expand Down Expand Up @@ -1149,7 +1163,8 @@ def deidentify_with_replace_infotype(project, item, info_types):
default=["FIRST_NAME", "LAST_NAME", "EMAIL_ADDRESS"],
)
replace_with_infotype_parser.add_argument(
"project", help="The Google Cloud project id to use as a parent resource.",
"project",
help="The Google Cloud project id to use as a parent resource.",
)
replace_with_infotype_parser.add_argument(
"item",
Expand Down Expand Up @@ -1207,5 +1222,7 @@ def deidentify_with_replace_infotype(project, item, info_types):
)
elif args.content == "replace_with_infotype":
deidentify_with_replace_infotype(
args.project, item=args.item, info_types=args.info_types,
args.project,
item=args.item,
info_types=args.info_types,
)
9 changes: 7 additions & 2 deletions dlp/snippets/deid_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ def test_deidentify_with_mask_masking_character_specified(capsys):

def test_deidentify_with_mask_masking_number_specified(capsys):
deid.deidentify_with_mask(
GCLOUD_PROJECT, HARMFUL_STRING, ["US_SOCIAL_SECURITY_NUMBER"], number_to_mask=7,
GCLOUD_PROJECT,
HARMFUL_STRING,
["US_SOCIAL_SECURITY_NUMBER"],
number_to_mask=7,
)

out, _ = capsys.readouterr()
Expand Down Expand Up @@ -278,7 +281,9 @@ def test_reidentify_free_text_with_fpe_using_surrogate(capsys):
def test_deidentify_with_replace_infotype(capsys):
url_to_redact = "https://cloud.google.com"
deid.deidentify_with_replace_infotype(
GCLOUD_PROJECT, "My favorite site is " + url_to_redact, ["URL"],
GCLOUD_PROJECT,
"My favorite site is " + url_to_redact,
["URL"],
)

out, _ = capsys.readouterr()
Expand Down
10 changes: 7 additions & 3 deletions dlp/snippets/inspect_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

# [START dlp_inspect_string_basic]
def inspect_string_basic(
project, content_string, info_types=["PHONE_NUMBER"],
project,
content_string,
info_types=["PHONE_NUMBER"],
):
"""Uses the Data Loss Prevention API to analyze strings for protected data.
Args:
Expand Down Expand Up @@ -1197,7 +1199,8 @@ def callback(message):
help="The Google Cloud project id of the target Datastore.",
)
parser_datastore.add_argument(
"kind", help='The kind of the Datastore entity to inspect, e.g. "Person".',
"kind",
help='The kind of the Datastore entity to inspect, e.g. "Person".',
)
parser_datastore.add_argument(
"topic_id",
Expand Down Expand Up @@ -1273,7 +1276,8 @@ def callback(message):
"bigquery", help="Inspect files on Google BigQuery."
)
parser_bigquery.add_argument(
"bigquery_project", help="The Google Cloud project id of the target table.",
"bigquery_project",
help="The Google Cloud project id of the target table.",
)
parser_bigquery.add_argument(
"dataset_id", help="The ID of the target BigQuery dataset."
Expand Down
2 changes: 1 addition & 1 deletion dlp/snippets/inspect_content_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def bigquery_project():
except google.api_core.exceptions.Conflict:
table = bigquery_client.get_table(table)

rows_to_insert = [(u"Gary Smith", u"My email is gary@example.com")]
rows_to_insert = [("Gary Smith", "My email is gary@example.com")]

bigquery_client.insert_rows(table, rows_to_insert)

Expand Down
5 changes: 3 additions & 2 deletions dlp/snippets/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def list_info_types(language_code=None, result_filter=None):
print("Info types:")
for info_type in response.info_types:
print(
u"{name}: {display_name}".format(
"{name}: {display_name}".format(
name=info_type.name, display_name=info_type.display_name
)
)
Expand All @@ -58,7 +58,8 @@ def list_info_types(language_code=None, result_filter=None):
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--language_code", help="The BCP-47 language code to use, e.g. 'en-US'.",
"--language_code",
help="The BCP-47 language code to use, e.g. 'en-US'.",
)
parser.add_argument(
"--filter",
Expand Down
4 changes: 2 additions & 2 deletions dlp/snippets/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# WARNING - WARNING - WARNING - WARNING - WARNING
# WARNING - WARNING - WARNING - WARNING - WARNING

BLACK_VERSION = "black==19.10b0"
BLACK_VERSION = "black==22.3.0"

# Copy `noxfile_config.py` to your directory and modify it instead.

Expand Down Expand Up @@ -253,7 +253,7 @@ def py(session: nox.sessions.Session) -> None:


def _get_repo_root() -> Optional[str]:
""" Returns the root folder of the project. """
"""Returns the root folder of the project."""
# Get root of this repository. Assume we don't have directories nested deeper than 10 items.
p = Path(os.getcwd())
for i in range(10):
Expand Down
18 changes: 14 additions & 4 deletions dlp/snippets/redact.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@


def redact_image(
project, filename, output_filename, info_types, min_likelihood=None, mime_type=None,
project,
filename,
output_filename,
info_types,
min_likelihood=None,
mime_type=None,
):
"""Uses the Data Loss Prevention API to redact protected data in an image.
Args:
Expand Down Expand Up @@ -122,7 +127,9 @@ def redact_image(


def redact_image_all_text(
project, filename, output_filename,
project,
filename,
output_filename,
):
"""Uses the Data Loss Prevention API to redact all text in an image.
Expand Down Expand Up @@ -184,7 +191,8 @@ def redact_image_all_text(
)
common_args_parser.add_argument("filename", help="The path to the file to inspect.")
common_args_parser.add_argument(
"output_filename", help="The path to which the redacted image will be written.",
"output_filename",
help="The path to which the redacted image will be written.",
)

parser = argparse.ArgumentParser(description=__doc__)
Expand Down Expand Up @@ -246,5 +254,7 @@ def redact_image_all_text(
)
elif args.content == "all_text":
redact_image_all_text(
args.project, args.filename, args.output_filename,
args.project,
args.filename,
args.output_filename,
)
9 changes: 7 additions & 2 deletions dlp/snippets/redact_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def test_redact_image_file(tempdir, capsys):
output_filepath = os.path.join(tempdir, "redacted.png")

redact.redact_image(
GCLOUD_PROJECT, test_filepath, output_filepath, ["FIRST_NAME", "EMAIL_ADDRESS"],
GCLOUD_PROJECT,
test_filepath,
output_filepath,
["FIRST_NAME", "EMAIL_ADDRESS"],
)

out, _ = capsys.readouterr()
Expand All @@ -48,7 +51,9 @@ def test_redact_image_all_text(tempdir, capsys):
output_filepath = os.path.join(tempdir, "redacted.png")

redact.redact_image_all_text(
GCLOUD_PROJECT, test_filepath, output_filepath,
GCLOUD_PROJECT,
test_filepath,
output_filepath,
)

out, _ = capsys.readouterr()
Expand Down
Loading

0 comments on commit cfb490a

Please sign in to comment.