Skip to content

Commit

Permalink
[TOOLSLIBS-403] Deprecations for version 6.0 (#170)
Browse files Browse the repository at this point in the history
* adds deprecation warnings

* adds deprecation warnings

* typos

* proper Python
  • Loading branch information
aschuman0 authored Nov 4, 2021
1 parent 001062d commit 453ebd6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
- 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.
- Adds support for setting attributes on channel ids and named user ids
- Adds support for removing attributes from channel ids and named user ids
- Deprecates location-based audience selectors: location, recent_date, absolute_date. These will be removed in version 6.0
- Deprecates class LocationFinder. This will be removed in version 6.0
- Deprecates support for Python 2. Support will be removed in version 6.0

---

Expand Down
12 changes: 10 additions & 2 deletions urbanairship/core.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import logging
import re
import sys
import warnings

import requests

from . import common, __about__
from . import __about__, common
from .push import Push, ScheduledPush, TemplatePush

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

if sys.version[0] == "2":
warnings.warn(
"Support for Python 2.x will be removed in urbanairship version 6.0",
DeprecationWarning,
)

@property
def timeout(self):
return self._timeout
Expand Down Expand Up @@ -132,7 +140,7 @@ def _request(
):

headers = {
"User-agent": "UAPythonLib/{0} {1}".format(__about__.__version__, self.key),
"User-agent": "UAPythonLib/{0} {1}".format(__about__.__version__, self.key)
}
if content_type:
headers["Content-type"] = content_type
Expand Down
14 changes: 10 additions & 4 deletions urbanairship/devices/locationfinder.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import logging
import warnings

logger = logging.getLogger("urbanairship")


class LocationFinder(object):
def __init__(self, airship):
"""
DEPRECATED - Will be removed in version 6.0
"""
self.airship = airship

warnings.warn(
"LocationFinder is deprecated and will be removed in version 6.0",
DeprecationWarning,
)

def name_lookup(self, name, location_type=None):
"""Lookup a location by name
Expand Down Expand Up @@ -146,9 +155,6 @@ def polygon_lookup(self, polygon_id, zoom):

def date_ranges(self):
resp = self.airship._request(
"GET",
None,
self.airship.urls.get("segments_url") + "dates/",
version=3,
"GET", None, self.airship.urls.get("segments_url") + "dates/", version=3
)
return resp.json()
25 changes: 22 additions & 3 deletions urbanairship/push/audience.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import re
import sys
import warnings

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

# Location selectors
def location(date=None, **kwargs):
"""Select a location expression.
"""DEPRECATED - Will be removed in version 6.0
Select a location expression.
Location selectors are made up of either an id or an alias and a date
period specifier. Use a date specification function to generate the time
Expand All @@ -260,6 +262,11 @@ def location(date=None, **kwargs):
'us_zip': '94103'}}
"""
warnings.warn(
"The location audience selector is deprecated and will be removed in version 6.0",
DeprecationWarning,
)

if not len(kwargs) == 1:
raise ValueError("Must specify a single location id or alias")
if date is None:
Expand All @@ -269,7 +276,8 @@ def location(date=None, **kwargs):


def recent_date(**kwargs):
"""Select a recent date range for a location selector.
"""DEPRECATED - Will be removed in version 6.0
Select a recent date range for a location selector.
:keyword resolution: One keyword time resolution specifier, e.g. ``hours``
or ``days``.
Expand All @@ -280,6 +288,11 @@ def recent_date(**kwargs):
>>> recent_date(weeks=3)
{'recent': {'weeks': 3}}
"""
warnings.warn(
"The recent_date audience selector is deprecated and will be removed in version 6.0",
DeprecationWarning,
)

if not len(kwargs) == 1:
raise ValueError("Must specify a single date resolution")
resolution = list(kwargs.keys())[0]
Expand All @@ -292,7 +305,8 @@ def recent_date(**kwargs):


def absolute_date(resolution, start, end):
"""Select an absolute date range for a location selector.
"""DEPRECATED - Will be removed in version 6.0
Select an absolute date range for a location selector.
:keyword resolution: Time resolution specifier, e.g. ``hours`` or ``days``.
:keyword start: UTC start time in ISO 8601 format.
Expand All @@ -308,6 +322,11 @@ def absolute_date(resolution, start, end):
{'minutes': {'end': '2012-01-01 12:45', 'start': '2012-01-01 12:00'}}
"""
warnings.warn(
"The absolute_date audience selector is deprecated and will be removed in version 6.0",
DeprecationWarning,
)

if resolution not in ("minutes" "hours" "days" "weeks" "months" "years"):
raise ValueError("Invalid date resolution: %s" % resolution)

Expand Down

0 comments on commit 453ebd6

Please sign in to comment.