Skip to content

Commit c6198c9

Browse files
Merge pull request #37 from piplcom/APPS-1302_update_regex_string
handle regex warning
2 parents 0a85b2d + 5b103e7 commit c6198c9

File tree

1 file changed

+15
-52
lines changed

1 file changed

+15
-52
lines changed

piplapis/data/fields.py

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ def __setattr__(self, attr, value):
9191
try:
9292
self.validate_type(value)
9393
except ValueError:
94-
logger.warn(
95-
"{} is not a valid type of {}. Setting to None.".format(
96-
value, type(self)
97-
)
98-
)
94+
logger.warn("{} is not a valid type of {}. Setting to None.".format(value, type(self)))
9995
value = None
10096
object.__setattr__(self, attr, value)
10197

@@ -108,29 +104,14 @@ def __str__(self):
108104

109105
@property
110106
def display(self):
111-
return (
112-
self._display
113-
if hasattr(self, "_display") and getattr(self, "_display")
114-
else None
115-
)
107+
return self._display if hasattr(self, "_display") and getattr(self, "_display") else None
116108

117109
def __repr__(self):
118110
"""Return a representation of the object (a valid value for eval())."""
119111
attrs = list(self.base_attributes + self.attributes + self.children)
120-
attrs_values = [
121-
(attr, getattr(self, attr))
122-
for attr in attrs
123-
if not attr.startswith("display")
124-
]
125-
attrs_values = [
126-
(attr, value) if attr != "type" else ("type_", value)
127-
for attr, value in attrs_values
128-
]
129-
args = [
130-
"%s=%s" % (attr, repr(value))
131-
for attr, value in attrs_values
132-
if value is not None
133-
]
112+
attrs_values = [(attr, getattr(self, attr)) for attr in attrs if not attr.startswith("display")]
113+
attrs_values = [(attr, value) if attr != "type" else ("type_", value) for attr, value in attrs_values]
114+
args = ["%s=%s" % (attr, repr(value)) for attr, value in attrs_values if value is not None]
134115
return "%s(%s)" % (self.__class__.__name__, ", ".join(args))
135116

136117
def __eq__(self, other):
@@ -260,9 +241,7 @@ class Name(Field):
260241

261242
attributes = ("type",)
262243
children = ("prefix", "first", "middle", "last", "suffix", "raw", "display")
263-
types_set = set(
264-
["present", "maiden", "former", "alias", "alternative", "autogenerated"]
265-
)
244+
types_set = set(["present", "maiden", "former", "alias", "alternative", "autogenerated"])
266245

267246
def __init__(
268247
self,
@@ -444,9 +423,7 @@ class Phone(Field):
444423
"display",
445424
"display_international",
446425
)
447-
types_set = set(
448-
["mobile", "home_phone", "home_fax", "work_phone", "work_fax", "pager", "voip"]
449-
)
426+
types_set = set(["mobile", "home_phone", "home_fax", "work_phone", "work_fax", "pager", "voip"])
450427

451428
def __init__(
452429
self,
@@ -503,7 +480,7 @@ class Email(Field):
503480
attributes = ("type", "disposable", "email_provider")
504481
children = ("address", "address_md5")
505482
types_set = set(["personal", "work"])
506-
re_email = re.compile("^[a-zA-Z0-9'._%\-+]+@[a-zA-Z0-9._%\-]+\.[a-zA-Z]{2,24}$")
483+
re_email = re.compile(r"^[a-zA-Z0-9'._%\-+]+@[a-zA-Z0-9._%\-]+\.[a-zA-Z]{2,24}$")
507484

508485
def __init__(
509486
self,
@@ -658,9 +635,7 @@ def validate_vin_checksum(vin):
658635
for digit, replacements in replace_map.items():
659636
for c in replacements:
660637
vin = vin.replace(c, digit)
661-
checksum = sum(
662-
int(num) * positional_weights[i] for i, num in enumerate(vin) if i != 8
663-
)
638+
checksum = sum(int(num) * positional_weights[i] for i, num in enumerate(vin) if i != 8)
664639
checksum %= 11
665640
if checksum == 10:
666641
checksum = "x"
@@ -706,9 +681,7 @@ class Education(Field):
706681

707682
children = ("degree", "school", "date_range", "display")
708683

709-
def __init__(
710-
self, degree=None, school=None, date_range=None, display=None, *args, **kwargs
711-
):
684+
def __init__(self, degree=None, school=None, date_range=None, display=None, *args, **kwargs):
712685
"""`degree` and `school` should both be unicode objects or utf8 encoded
713686
strs (will be decoded automatically).
714687
@@ -744,9 +717,7 @@ def is_valid_url(self):
744717
"""A bool value that indicates whether the image URL is a valid URL."""
745718
return bool(self.url and is_valid_url(self.url))
746719

747-
def get_thumbnail_url(
748-
self, width=100, height=100, zoom_face=True, favicon=True, use_https=False
749-
):
720+
def get_thumbnail_url(self, width=100, height=100, zoom_face=True, favicon=True, use_https=False):
750721
"""
751722
This method creates a thumbnail URL for this image.
752723
@@ -795,24 +766,16 @@ def generate_redundant_thumbnail_url(
795766
if first_image is None and second_image is None:
796767
raise ValueError("Please provide at least one image.")
797768

798-
images_with_tokens = [
799-
x for x in (first_image, second_image) if x and x.thumbnail_token
800-
]
769+
images_with_tokens = [x for x in (first_image, second_image) if x and x.thumbnail_token]
801770
if len(images_with_tokens) == 0:
802-
raise ValueError(
803-
"You can only generate thumbnail URLs for image objects with a thumbnail token."
804-
)
771+
raise ValueError("You can only generate thumbnail URLs for image objects with a thumbnail token.")
805772

806773
if len(images_with_tokens) == 1:
807774
tokens = images_with_tokens[0].thumbnail_token
808775
else:
809-
tokens = ",".join(
810-
[re.sub("&dsid=\d+", "", x.thumbnail_token) for x in images_with_tokens]
811-
)
776+
tokens = ",".join([re.sub(r"&dsid=\d+", "", x.thumbnail_token) for x in images_with_tokens])
812777

813-
thumb_url_base = "{}://thumb.pipl.com/image?".format(
814-
"https" if use_https else "http"
815-
)
778+
thumb_url_base = "{}://thumb.pipl.com/image?".format("https" if use_https else "http")
816779
params = {
817780
"height": height,
818781
"width": width,

0 commit comments

Comments
 (0)