Using reserved keywoards in postDownloadFunction

3 views
Skip to first unread message

Sanmarcos

unread,
Mar 14, 2009, 4:36:23 AM3/14/09
to rssdler
I am trying to use the socket module in a function, to send a
notification to my desktop client machine via the Growl notification
system.

Here is my userFunctions.py

#! /usr/bin/env python
# -*- coding: utf8 -*-
from netgrowl import *
import sys
import datetime

def growlNotify(directory=None, filename="None", rssItemNode=None,
retrievedLink=None, downloadDict=None, threadName=None):
addr = ("myserver.com", GROWL_UDP_PORT)
s = socket(AF_INET,SOCK_DGRAM)

p = GrowlNotificationPacket(application="rssdler",
notification="Torrent downloaded", title="Got torrent - %s" %
(datetime.datetime.now().strftime("%m/%d %H:%M")),
description=filename, priority=1,
sticky=True, password="password")
s.sendto(p.payload(),addr)
s.close()

However, I am getting:

20090314.09:01 CRITICAL Unexpected Error: Traceback (most recent call
last):
File "/usr/lib/python2.5/site-packages/rssdler.py", line 2044, in
main
run()
File "/usr/lib/python2.5/site-packages/rssdler.py", line 2016, in
run
rssparse(key)
File "/usr/lib/python2.5/site-packages/rssdler.py", line 1930, in
rssparse
callUserFunction( getConfig()['threads'][tName]
['postDownloadFunction'], *userFunctArgs )
File "/usr/lib/python2.5/site-packages/rssdler.py", line 1699, in
callUserFunction
userFunct( *args )
File "/home/marc/.rssdler/userFunctions.py", line 28, in growlNotify
s = socket(AF_INET,SOCK_DGRAM)
TypeError: 'module' object is not callable


Obviously I am hitting the reserved 'socket' keyword. I could modify
the code, open the DGRAM socket on the main thread, global the
reference in my userFunctions and use that, but I was wondering if
there was a cleaner solution. I read through the source code and I
couldn't find a way to fix this. Note that the interpreter halted
before even starting to compile my Growl packet stack on "p =
GrowlNotificationPacket" which might hit more reserved keywords and
make things more complicated...

Any help would be appreciated, thanks!.

Also, is there any way to "test fire" the postDownloadFunction, so I
don't have to wait for a download to test it?

Thanks.

Sanmarcos

unread,
Mar 20, 2009, 6:06:09 AM3/20/09
to rssdler
lostnihilist: Any ideas?

lostnihilist

unread,
Mar 20, 2009, 12:37:11 PM3/20/09
to rss...@googlegroups.com

well, the line it is tripping up on is:

s = socket(AF_INET,SOCK_DGRAM)

I'm not at all familiar with this netgrowl thing. I think if you change
socket() to socket.socket() you wil lbe good to go, assuming the rest of the
code is correct. What the error says is that you have effectively
done "import socket; socket()" which of course won't work since you cannot
call a module. You need to call the socket function (actually, it is a class,
but either way, it is a callable) within the socket module.

Another thing you could do is just do "import netgrowl" and call the netgrowl
specific stuff by name in your function. This would avoid any other potential
namespace collision issues, I think. If there is a socket function within
netgrowl that you were intending to use instead of socket.socket, this would
be the better solution.

> > Also, is there any way to "test fire" the postDownloadFunction, so I
> > don't have to wait for a download to test it?

As for test firing your function, just make a regex that will hit something in
the current feed.

--
lostnihilist

Reply all
Reply to author
Forward
0 new messages