Skip to content

Commit 453ebd6

Browse files
authored
[TOOLSLIBS-403] Deprecations for version 6.0 (#170)
* adds deprecation warnings * adds deprecation warnings * typos * proper Python
1 parent 001062d commit 453ebd6

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

CHANGELOG

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
- Adds attributes, device_attributes, named_user_id, commercial_opted_in, commercial_opted_out, transactional_opted_in, transactional_opted_out to channel look up and listing.
77
- Adds support for setting attributes on channel ids and named user ids
88
- Adds support for removing attributes from channel ids and named user ids
9+
- Deprecates location-based audience selectors: location, recent_date, absolute_date. These will be removed in version 6.0
10+
- Deprecates class LocationFinder. This will be removed in version 6.0
11+
- Deprecates support for Python 2. Support will be removed in version 6.0
912

1013
---
1114

urbanairship/core.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import logging
22
import re
3+
import sys
4+
import warnings
35

46
import requests
57

6-
from . import common, __about__
8+
from . import __about__, common
79
from .push import Push, ScheduledPush, TemplatePush
810

911
logger = logging.getLogger("urbanairship")
@@ -77,6 +79,12 @@ def __init__(self, key, secret, location=None, timeout=None):
7779
self.session.auth = (key, secret)
7880
self.urls = Urls(self.location)
7981

82+
if sys.version[0] == "2":
83+
warnings.warn(
84+
"Support for Python 2.x will be removed in urbanairship version 6.0",
85+
DeprecationWarning,
86+
)
87+
8088
@property
8189
def timeout(self):
8290
return self._timeout
@@ -132,7 +140,7 @@ def _request(
132140
):
133141

134142
headers = {
135-
"User-agent": "UAPythonLib/{0} {1}".format(__about__.__version__, self.key),
143+
"User-agent": "UAPythonLib/{0} {1}".format(__about__.__version__, self.key)
136144
}
137145
if content_type:
138146
headers["Content-type"] = content_type

urbanairship/devices/locationfinder.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import logging
2+
import warnings
23

34
logger = logging.getLogger("urbanairship")
45

56

67
class LocationFinder(object):
78
def __init__(self, airship):
9+
"""
10+
DEPRECATED - Will be removed in version 6.0
11+
"""
812
self.airship = airship
913

14+
warnings.warn(
15+
"LocationFinder is deprecated and will be removed in version 6.0",
16+
DeprecationWarning,
17+
)
18+
1019
def name_lookup(self, name, location_type=None):
1120
"""Lookup a location by name
1221
@@ -146,9 +155,6 @@ def polygon_lookup(self, polygon_id, zoom):
146155

147156
def date_ranges(self):
148157
resp = self.airship._request(
149-
"GET",
150-
None,
151-
self.airship.urls.get("segments_url") + "dates/",
152-
version=3,
158+
"GET", None, self.airship.urls.get("segments_url") + "dates/", version=3
153159
)
154160
return resp.json()

urbanairship/push/audience.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22
import re
33
import sys
4+
import warnings
45

56
DEVICE_TOKEN_FORMAT = re.compile(r"^[0-9a-fA-F]{64}$")
67
UUID_FORMAT = re.compile(
@@ -236,7 +237,8 @@ def not_(child):
236237

237238
# Location selectors
238239
def location(date=None, **kwargs):
239-
"""Select a location expression.
240+
"""DEPRECATED - Will be removed in version 6.0
241+
Select a location expression.
240242
241243
Location selectors are made up of either an id or an alias and a date
242244
period specifier. Use a date specification function to generate the time
@@ -260,6 +262,11 @@ def location(date=None, **kwargs):
260262
'us_zip': '94103'}}
261263
262264
"""
265+
warnings.warn(
266+
"The location audience selector is deprecated and will be removed in version 6.0",
267+
DeprecationWarning,
268+
)
269+
263270
if not len(kwargs) == 1:
264271
raise ValueError("Must specify a single location id or alias")
265272
if date is None:
@@ -269,7 +276,8 @@ def location(date=None, **kwargs):
269276

270277

271278
def recent_date(**kwargs):
272-
"""Select a recent date range for a location selector.
279+
"""DEPRECATED - Will be removed in version 6.0
280+
Select a recent date range for a location selector.
273281
274282
:keyword resolution: One keyword time resolution specifier, e.g. ``hours``
275283
or ``days``.
@@ -280,6 +288,11 @@ def recent_date(**kwargs):
280288
>>> recent_date(weeks=3)
281289
{'recent': {'weeks': 3}}
282290
"""
291+
warnings.warn(
292+
"The recent_date audience selector is deprecated and will be removed in version 6.0",
293+
DeprecationWarning,
294+
)
295+
283296
if not len(kwargs) == 1:
284297
raise ValueError("Must specify a single date resolution")
285298
resolution = list(kwargs.keys())[0]
@@ -292,7 +305,8 @@ def recent_date(**kwargs):
292305

293306

294307
def absolute_date(resolution, start, end):
295-
"""Select an absolute date range for a location selector.
308+
"""DEPRECATED - Will be removed in version 6.0
309+
Select an absolute date range for a location selector.
296310
297311
:keyword resolution: Time resolution specifier, e.g. ``hours`` or ``days``.
298312
:keyword start: UTC start time in ISO 8601 format.
@@ -308,6 +322,11 @@ def absolute_date(resolution, start, end):
308322
{'minutes': {'end': '2012-01-01 12:45', 'start': '2012-01-01 12:00'}}
309323
310324
"""
325+
warnings.warn(
326+
"The absolute_date audience selector is deprecated and will be removed in version 6.0",
327+
DeprecationWarning,
328+
)
329+
311330
if resolution not in ("minutes" "hours" "days" "weeks" "months" "years"):
312331
raise ValueError("Invalid date resolution: %s" % resolution)
313332

0 commit comments

Comments
 (0)