Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 824a124

Browse files
committed
Merge branch 'master' into api_v2
2 parents 0d46495 + c23229d commit 824a124

10 files changed

Lines changed: 44 additions & 51 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,19 @@ on:
1111
jobs:
1212
build:
1313
if: github.repository == 'python-twitter-tools/twitter'
14-
runs-on: ubuntu-20.04
14+
runs-on: ubuntu-latest
1515

1616
steps:
1717
- uses: actions/checkout@v2
1818
with:
1919
fetch-depth: 0
2020

21-
- name: Cache
22-
uses: actions/cache@v2
23-
with:
24-
path: ~/.cache/pip
25-
key: deploy-${{ hashFiles('**/setup.py') }}
26-
restore-keys: |
27-
deploy-
28-
2921
- name: Set up Python
30-
uses: actions/setup-python@v2
22+
uses: actions/setup-python@v4
3123
with:
32-
python-version: 3.9
24+
python-version: "3.x"
25+
cache: pip
26+
cache-dependency-path: setup.py
3327

3428
- name: Install dependencies
3529
run: |

.github/workflows/tests.yml

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,21 @@ jobs:
1818
"3.7",
1919
"3.8",
2020
"3.9",
21-
"3.10-dev",
22-
"pypy2",
21+
"3.10",
22+
"3.11-dev",
23+
"pypy2.7",
2324
]
2425
os: [ubuntu-latest]
2526

2627
steps:
27-
- uses: actions/checkout@v2
28+
- uses: actions/checkout@v3
2829

2930
- name: Set up Python ${{ matrix.python-version }}
30-
uses: actions/setup-python@v2
31+
uses: actions/setup-python@v4
3132
with:
3233
python-version: ${{ matrix.python-version }}
33-
34-
- name: Get pip cache dir
35-
id: pip-cache
36-
run: |
37-
echo "::set-output name=dir::$(pip cache dir)"
38-
39-
- name: Cache
40-
uses: actions/cache@v2
41-
with:
42-
path: ${{ steps.pip-cache.outputs.dir }}
43-
key:
44-
${{ matrix.os }}-${{ matrix.python-version }}-v1-${{ hashFiles('**/setup.py') }}
45-
restore-keys: |
46-
${{ matrix.os }}-${{ matrix.python-version }}-v1-
34+
cache: pip
35+
cache-dependency-path: setup.py
4736

4837
- name: Install dependencies
4938
run: |

MANIFEST.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
prune .github
2-
prune tests
2+
include tests/*.py
3+
include tests/*.png
34
prune utils
45
exclude .coveragerc
56
exclude .gitignore
6-
exclude README.md
7+
exclude README.md

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def local_scheme(version):
2828
"Programming Language :: Python :: 3.7",
2929
"Programming Language :: Python :: 3.8",
3030
"Programming Language :: Python :: 3.9",
31+
"Programming Language :: Python :: 3.10",
32+
"Programming Language :: Python :: 3.11",
3133
"Programming Language :: Python :: Implementation :: CPython",
3234
"Programming Language :: Python :: Implementation :: PyPy",
3335
"Topic :: Communications :: Chat :: Internet Relay Chat",

tests/test_cmdline.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import json
44
import re
55
import unittest
6-
from mock import patch
6+
try:
7+
from mock import patch
8+
except ImportError:
9+
from unittest.mock import patch
710

811
try:
912
import HTMLParser

tests/test_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def do_HEAD(self):
4949

5050
httpd = SocketServer.TCPServer(("", 0), MyHandler)
5151
t = threading.Thread(target=httpd.serve_forever)
52-
t.setDaemon(True)
52+
t.daemon = True
5353
t.start()
5454
port = httpd.server_address[1]
5555
yield functools.partial(url, port)

twitter/api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
except ImportError:
4141
import simplejson as json
4242

43+
try:
44+
from json.decoder import JSONDecodeError
45+
except ImportError:
46+
JSONDecodeError = ValueError
47+
4348

4449
class _DEFAULT(object):
4550
pass
@@ -397,7 +402,7 @@ def _handle_response(self, req, uri, arg_data, _timeout=None):
397402
elif "json" == self.format or uri.startswith("2/"):
398403
try:
399404
res = json.loads(data.decode('utf8'))
400-
except json.decoder.JSONDecodeError as e:
405+
except JSONDecodeError as e:
401406
# it seems like the data received was incomplete
402407
# and we should catch it to allow retries
403408
raise TwitterError("Incomplete JSON data collected for %s (%s): %s)" % (uri, arg_data, e))

twitter/cmdline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ def __call__(self, twitter, options):
578578
else str(input("message: ")))
579579
statusTxt = statusTxt.replace('\\n', '\n')
580580
replies = []
581-
ptr = re.compile("@[\w_]+")
581+
ptr = re.compile(r"@[\w_]+")
582582
while statusTxt:
583583
s = ptr.match(statusTxt)
584584
if s and s.start() == 0:

twitter/ircbot.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,18 @@ def __init__(self, configFilename):
153153
self.irc = irclib.IRC()
154154
self.irc.add_global_handler('privmsg', self.handle_privmsg)
155155
self.irc.add_global_handler('ctcp', self.handle_ctcp)
156-
self.irc.add_global_handler('umode', self.handle_umode)
156+
self.irc.add_global_handler('welcome', self.handle_welcome)
157157
self.ircServer = self.irc.server()
158158

159+
self.welcome_received = False
159160
self.sched = Scheduler(
160161
(SchedTask(self.process_events, 1),
161162
SchedTask(self.check_statuses, 120)))
162163
self.lastUpdate = (datetime.utcnow() - timedelta(minutes=10)).utctimetuple()
163164

164165
def check_statuses(self):
166+
if not self.welcome_received:
167+
return
165168
debug("In check_statuses")
166169
try:
167170
updates = reversed(self.twitter.statuses.home_timeline())
@@ -226,18 +229,16 @@ def handle_ctcp(self, conn, evt):
226229
elif args[0] == 'CLIENTINFO':
227230
conn.ctcp_reply(source, "CLIENTINFO PING VERSION CLIENTINFO")
228231

229-
def handle_umode(self, conn, evt):
232+
def handle_welcome(self, conn, evt):
230233
"""
231-
QuakeNet ignores all your commands until after the MOTD. This
232-
handler defers joining until after it sees a magic line. It
233-
also tries to join right after connect, but this will just
234-
make it join again which should be safe.
234+
Undernet and QuakeNet ignore all your commands until it receives 001. This
235+
handler defers joining until after it sees a magic line.
235236
"""
236-
args = evt.arguments()
237-
if (args and args[0] == '+i'):
238-
channels = self.config.get('irc', 'channel').split(',')
239-
for channel in channels:
240-
self.ircServer.join(channel)
237+
self.welcome_received = True
238+
channels = self.config.get('irc', 'channel').split(',')
239+
for channel in channels:
240+
self.ircServer.join(channel)
241+
self.check_statuses()
241242

242243
def privmsg_channels(self, msg):
243244
return_response=True
@@ -288,13 +289,11 @@ def unfollow(self, conn, evt, name):
288289
get_prefix('inform'), userNick, name))
289290

290291
def _irc_connect(self):
292+
self.welcome_received = False
291293
self.ircServer.connect(
292294
self.config.get('irc', 'server'),
293295
self.config.getint('irc', 'port'),
294296
self.config.get('irc', 'nick'))
295-
channels=self.config.get('irc', 'channel').split(',')
296-
for channel in channels:
297-
self.ircServer.join(channel)
298297

299298
def run(self):
300299
self._irc_connect()

twitter/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ def expand_line(line, sites):
159159

160160
def parse_host_list(list_of_hosts):
161161
"""Parse the comma separated list of hosts."""
162-
p = set(
163-
m.group(1) for m in re.finditer("\s*([^,\s]+)\s*,?\s*", list_of_hosts))
162+
p = {
163+
m.group(1) for m in re.finditer(r"\s*([^,\s]+)\s*,?\s*", list_of_hosts)}
164164
return p
165165

166166

0 commit comments

Comments
 (0)