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

Commit aed90e4

Browse files
committed
deprecate UpdateBackgroundImage and convert DeprecationWarnings to version specifc warnings
1 parent 3f4e3e3 commit aed90e4

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

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: 24 additions & 5 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

@@ -2614,7 +2629,7 @@ def _GetFriendsFollowers(self,
26142629
warnings.warn(
26152630
"Use of 'cursor' and 'count' parameters are deprecated as of "
26162631
"python-twitter 3.0. Please use GetFriendsPaged instead.",
2617-
DeprecationWarning, stacklevel=2)
2632+
PythonTwitterDeprecationWarning330)
26182633

26192634
count = 200
26202635
cursor = -1
@@ -4320,6 +4335,10 @@ def UpdateBackgroundImage(self,
43204335
include_entities=False,
43214336
skip_status=False):
43224337

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

0 commit comments

Comments
 (0)