Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.

Commit 7126f2b

Browse files
authored
Merge pull request #386 from bear/feature/UpdateBackgroundImage_deprecation
Add Descriptive Deprecations
2 parents 3f99eaf + 98a943f commit 7126f2b

5 files changed

Lines changed: 69 additions & 8 deletions

File tree

doc/changelog.rst

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,37 @@ Changelog
44
Version 3.2
55
===========
66

7+
Deprecations
8+
------------
9+
10+
Nothing is being deprecationed this version, however here's what's being deprecated as of v. 3.3.0:
11+
12+
* :py:func:`twitter.api.Api.UpdateBackgroundImage`. Please make sure that your code does not call this function as it will be returning a hard error. There is no replace function. This was deprecated by Twitter around July 2015.
13+
14+
* :py:func:`twitter.api.Api.PostMedia` will be removed. Please use :py:func:`twitter.api.Api.PostUpdate` instead.
15+
16+
* :py:func:`twitter.api.Api.PostMultipleMedia`. Please use :py:func:`twitter.api.Api.PostUpdate` instead.
17+
18+
* :py:func:`twitter.api.GetFriends` will no longer accept a `cursor` or `count` parameter. Please use :py:func:`twitter.api.GetFriendsPaged` instead.
19+
20+
* :py:func:`twitter.api.GetFollowers` will no longer accept a `cursor` or `count` parameter. Please use :py:func:`twitter.api.GetFollowersPaged` instead.
21+
22+
723
What's New
824
----------
925

26+
* We've added new deprecation warnings, so it's easier to track when things go away. All of python-twitter's deprecation warnings will be a subclass of :py:class:`twitter.error.PythonTwitterDeprecationWarning` and will have a version number associated with them such as :py:class:`twitter.error.PythonTwitterDeprecationWarning330`.
27+
28+
1029
* :py:class:`twitter.models.User` now contains a ``following`` attribute, which describes whether the authenticated user is following the User. `PR #351 <https://github.com/bear/python-twitter/pull/351>`_
1130

12-
* :py:class:`twitter.models.DirectMessage` now contains a full :py:class:`twitter.models.User` object for both the ``DirectMessage.sender`` and ``DirectMessage.recipient`` properties. `PR #384 <https://github.com/bear/python-twitter/pull/384>`_.
31+
* :py:class:`twitter.models.DirectMessage` contains a full :py:class:`twitter.models.User` object for both the ``DirectMessage.sender`` and ``DirectMessage.recipient`` properties. `PR #384 <https://github.com/bear/python-twitter/pull/384>`_.
1332

1433
* You can now upload Quicktime movies (``*.mov``). `PR #372 <https://github.com/bear/python-twitter/pull/372>`_.
1534

1635
* If you have a whitelisted app, you can now get the authenticated user's email address through a call to :py:func:`twitter.api.Api.VerifyCredentials()`. If your app isn't whitelisted, no error is returned. `PR #376 <https://github.com/bear/python-twitter/pull/376>`_.
1736

18-
* **Google App Engine support has been reintegrated into the library!** Check out `PR #383 <https://github.com/bear/python-twitter/pull/383>`_.
37+
* Google App Engine support has been reintegrated into the library. Check out `PR #383 <https://github.com/bear/python-twitter/pull/383>`_.
1938

2039
What's Changed
2140
--------------

doc/twitter.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ API
1010
:undoc-members:
1111
:show-inheritance:
1212

13+
.. automodule:: twitter.error
14+
:members:
15+
:undoc-members:
16+
:show-inheritance:
17+
1318
Models
1419
---------------------
1520

tests/test_api_30.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,3 +1854,10 @@ def testShowFriendship(self):
18541854
twitter.TwitterError,
18551855
lambda: self.api.ShowFriendship(target_screen_name='__jcbl__')
18561856
)
1857+
@responses.activate
1858+
def test_UpdateBackgroundImage_deprecation(self):
1859+
responses.add(responses.POST, DEFAULT_URL, body='{}', status=200)
1860+
warnings.simplefilter("always")
1861+
with warnings.catch_warnings(record=True) as w:
1862+
resp = self.api.UpdateBackgroundImage(image='testdata/168NQ.jpg')
1863+
self.assertTrue(issubclass(w[0].category, DeprecationWarning))

twitter/api.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from __future__ import division
2121
from __future__ import print_function
2222

23+
import json
2324
import sys
2425
import gzip
2526
import time
@@ -43,8 +44,17 @@
4344
from urllib import urlencode
4445
from urllib import __version__ as urllib_version
4546

46-
from twitter import (__version__, _FileCache, json, DirectMessage, List,
47-
Status, Trend, TwitterError, User, UserStatus, Category)
47+
from twitter import (
48+
__version__,
49+
_FileCache,
50+
Category,
51+
DirectMessage,
52+
List,
53+
Status,
54+
Trend,
55+
User,
56+
UserStatus,
57+
)
4858

4959
from twitter.ratelimit import RateLimit
5060

@@ -54,6 +64,11 @@
5464
parse_media_file,
5565
enf_type)
5666

67+
from twitter.error import (
68+
TwitterError,
69+
PythonTwitterDeprecationWarning330,
70+
)
71+
5772

5873
warnings.simplefilter('always', DeprecationWarning)
5974

@@ -1299,7 +1314,7 @@ def PostMedia(self,
12991314
"PostUpdate() instead. Details of Twitter's deprecation can be "
13001315
"found at: "
13011316
"dev.twitter.com/rest/reference/post/statuses/update_with_media"),
1302-
DeprecationWarning)
1317+
PythonTwitterDeprecationWarning330)
13031318

13041319
url = '%s/statuses/update_with_media.json' % self.base_url
13051320

@@ -1366,7 +1381,7 @@ def PostMultipleMedia(self, status, media, possibly_sensitive=None,
13661381
warnings.warn((
13671382
"This method is deprecated. Please use PostUpdate instead, "
13681383
"passing a list of media that you would like to associate "
1369-
"with the updated."), DeprecationWarning, stacklevel=2)
1384+
"with the update."), PythonTwitterDeprecationWarning330)
13701385
if type(media) is not list:
13711386
raise TwitterError("Must by multiple media elements")
13721387

@@ -2613,8 +2628,9 @@ def _GetFriendsFollowers(self,
26132628
if cursor is not None or count is not None:
26142629
warnings.warn(
26152630
"Use of 'cursor' and 'count' parameters are deprecated as of "
2616-
"python-twitter 3.0. Please use GetFriendsPaged instead.",
2617-
DeprecationWarning, stacklevel=2)
2631+
"python-twitter 3.0. Please use GetFriendsPaged or "
2632+
"GetFollowersPaged instead.",
2633+
PythonTwitterDeprecationWarning330)
26182634

26192635
count = 200
26202636
cursor = -1
@@ -4320,6 +4336,10 @@ def UpdateBackgroundImage(self,
43204336
include_entities=False,
43214337
skip_status=False):
43224338

4339+
warnings.warn((
4340+
"This method has been deprecated by Twitter as of July 2015 and "
4341+
"will be removed in future versions of python-twitter."),
4342+
PythonTwitterDeprecationWarning330)
43234343
url = '%s/account/update_profile_background_image.json' % (self.base_url)
43244344
with open(image, 'rb') as image_file:
43254345
encoded_image = base64.b64encode(image_file.read())

twitter/error.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,13 @@ class TwitterError(Exception):
88
def message(self):
99
'''Returns the first argument used to construct this error.'''
1010
return self.args[0]
11+
12+
13+
class PythonTwitterDeprecationWarning(DeprecationWarning):
14+
"""Base class for python-twitter deprecation warnings"""
15+
pass
16+
17+
18+
class PythonTwitterDeprecationWarning330(PythonTwitterDeprecationWarning):
19+
"""Warning for features to be removed in version 3.3.0"""
20+
pass

0 commit comments

Comments
 (0)