Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
irker
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iDB
irker
Commits
da8385fc
Commit
da8385fc
authored
Aug 25, 2012
by
Eric S. Raymond
Browse files
Options
Downloads
Patches
Plain Diff
Thread implementation seems to work.
parent
b1e08362
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
irker.py
+25
-4
25 additions, 4 deletions
irker.py
with
25 additions
and
4 deletions
irker.py
+
25
−
4
View file @
da8385fc
...
...
@@ -5,17 +5,35 @@ irker - a simple IRC multiplexer daemon
Takes JSON objects of the form {
'
channel
'
:<channel-url>,
'
message
'
:<text>}
and relays to IRC channels.
Requires Python 2.6.
"""
import
os
,
sys
,
json
,
irclib
,
getopt
import
threading
,
Queue
class
Session
:
class
Session
()
:
"
IRC session and message queue processing.
"
def
__init__
(
self
,
channel
):
self
.
channel
=
channel
self
.
queue
=
[]
self
.
queue
=
Queue
.
Queue
()
self
.
thread
=
threading
.
Thread
(
target
=
self
.
dequeue
)
self
.
thread
.
daemon
=
True
self
.
thread
.
start
()
def
enqueue
(
self
,
message
):
"
Enque a message for transmission.
"
self
.
queue
.
append
(
message
)
self
.
queue
.
put
(
message
)
def
dequeue
(
self
):
"
Try to ship pending messages from the queue.
"
while
True
:
message
=
self
.
queue
.
get
()
self
.
ship
(
self
.
channel
,
message
)
self
.
queue
.
task_done
()
def
await
(
self
):
"
Block until processing of the queue is done.
"
self
.
queue
.
join
()
def
ship
(
self
,
channel
,
message
):
"
Ship a message to the channel.
"
print
"
%s: %s
"
%
(
channel
,
message
)
class
Irker
:
"
Persistent IRC multiplexer.
"
...
...
@@ -24,7 +42,7 @@ class Irker:
def
logerr
(
self
,
errmsg
):
"
Log a processing error.
"
sys
.
stderr
.
write
(
"
irker:
"
+
errmsg
+
"
\n
"
)
def
run
(
self
,
ifp
):
def
run
(
self
,
ifp
,
await
=
True
):
"
Accept JSON relay requests from specified stream.
"
while
True
:
inp
=
ifp
.
readline
()
...
...
@@ -36,6 +54,9 @@ class Irker:
self
.
logerr
(
"
can
'
t recognize JSON on input.
"
)
break
self
.
relay
(
request
)
if
await
:
for
session
in
self
.
sessions
.
values
():
session
.
await
()
def
relay
(
self
,
request
):
if
"
channel
"
not
in
request
or
"
message
"
not
in
request
:
self
.
logerr
(
"
ill-formed reqest
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment