This repository was archived by the owner on Aug 7, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55import twitter
66
77from twitter .twitter_utils import (
8+ calc_expected_status_length ,
89 parse_media_file
910)
1011
@@ -58,3 +59,18 @@ def test_utils_error_checking(self):
5859 self .assertRaises (
5960 twitter .TwitterError ,
6061 lambda : twitter .twitter_utils .enf_type ('test' , int , 'hi' ))
62+
63+ def test_calc_expected_status_length (self ):
64+ status = 'hi a tweet there'
65+ len_status = calc_expected_status_length (status )
66+ self .assertEqual (len_status , 16 )
67+
68+ def test_calc_expected_status_length_with_url (self ):
69+ status = 'hi a tweet there example.com'
70+ len_status = calc_expected_status_length (status )
71+ self .assertEqual (len_status , 40 )
72+
73+ def test_calc_expected_status_length_with_url_and_extra_spaces (self ):
74+ status = 'hi a tweet there example.com'
75+ len_status = calc_expected_status_length (status )
76+ self .assertEqual (len_status , 63 )
Original file line number Diff line number Diff line change 2323__email__ = 'python-twitter@googlegroups.com'
2424__copyright__ = 'Copyright (c) 2007-2016 The Python-Twitter Developers'
2525__license__ = 'Apache License 2.0'
26- __version__ = '3.2'
26+ __version__ = '3.2.1 '
2727__url__ = 'https://github.com/bear/python-twitter'
2828__download_url__ = 'https://pypi.python.org/pypi/python-twitter'
2929__description__ = 'A Python wrapper around the Twitter API'
Original file line number Diff line number Diff line change @@ -161,12 +161,13 @@ def calc_expected_status_length(status, short_url_length=23):
161161 Expected length of the status message as an integer.
162162
163163 """
164- replaced_chars = 0
165- status_length = len (status )
166- match = re .findall (URL_REGEXP , status )
167- if len (match ) >= 1 :
168- replaced_chars = len ('' .join (match ))
169- status_length = status_length - replaced_chars + (short_url_length * len (match ))
164+ status_length = 0
165+ for word in re .split (r'\s' , status ):
166+ if is_url (word ):
167+ status_length += short_url_length
168+ else :
169+ status_length += len (word )
170+ status_length += len (re .findall (r'\s' , status ))
170171 return status_length
171172
172173
You can’t perform that action at this time.
0 commit comments