How do I set up a timer as a subprocess?

2005-03-10 Thread Dfenestr8
Hi.

Trying to set up a timer function for my irc bot, which uses the python
irclib.py.

If I use time.sleep(20), it tends to freeze up the bot completely for 20
secs. That's not what I want though! I want the program to wait 20 secs,
then perform another function, but in the meantime be able to accept other
commands.

How do I do that? 
-- 
http://mail.python.org/mailman/listinfo/python-list


How do I import everything in a subdir?

2005-03-05 Thread Dfenestr8
Hi.

I have a program which I want a plugin directory for. I figured the way to
go about that would be to just add a plugin/ dir to sys.path, and import
everything in it. Then my program can just execute the main() method of
each imported plugin.

Is that a good way to go about it?

If so, how do I import everything in the plugins dir? The method raises an
error as you can see.

>>> import sys
>>> import os
>>> sys.path.append("plugins")
>>> ls = os.popen("ls plugins").readlines()
>>> for x in ls:
... plugs.append(x[0:x.rfind(".py")])
>>> for x in plugs:
... import x
...
Traceback (most recent call last):
  File "", line 2, in ?
ImportError: No module named x

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An mysql-python tutorial?

2005-01-29 Thread Dfenestr8
On Sat, 29 Jan 2005 06:41:37 +, Kartic wrote:

[snip]
> And here is one more site, good stuff here too:-
> http://www.kitebird.com/articles/pydbapi.html
> 

Hi.

I followed the instructions there, tried out the test script they
recommend. 

Can you tell me why this command, in the python interpreter:

>>>conn = MySQLdb.connect (host = "localhost", user = "flipper", passwd =
"[hidden]", db = "mydb")

produces this error:
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.3/site-packages/MySQLdb/__init__.py", line 63, in 
Connect
return apply(Connection, args, kwargs)
  File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line 115, in 
__init__
self._make_connection(args, kwargs2)
  File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line 41, in 
_make_connection
apply(super(ConnectionBase, self).__init__, args, kwargs)
_mysql_exceptions.OperationalError: (1045, "Access denied for user:
'[EMAIL PROTECTED]' (Using password: YES)")

I also have MySQL installed, and tried setting up the user flipper with
the mysql client, as per the instructions here:
http://vsbabu.org/mt/archives/2003/04/17/mysql_in_mandrake_91.html
-- 
http://mail.python.org/mailman/listinfo/python-list


An mysql-python tutorial?

2005-01-28 Thread Dfenestr8
Hi.

Been told by the admin of my (free!) server that he'd rather I should
learn to use mysql if I want to continue writing cgi scripts there.

Not even sure exactly what mysql is.

Is there a simple tutorial anywhere on the web about using python + mysql?  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python/cgi/html bug

2005-01-19 Thread Dfenestr8
On Wed, 19 Jan 2005 12:15:18 -0800, Paul Rubin wrote:

> Dfenestr8 <[EMAIL PROTECTED]> writes:
>> No glaring security holes that you noticed? Other than being able to
>> hide things in html tags?
> 
> Looks like you can also embed arbitrary javascript (I just tried it). I
> haven't looked at the script itself yet.

fixed that.
try doing it now..

http://funkmunch.net/~pirch/cgi-bin/betaforum/pptopic.py

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python/cgi/html bug

2005-01-19 Thread Dfenestr8
On Wed, 19 Jan 2005 04:32:04 -0800, Fuzzyman wrote:

> This looks very good.
> I've been looking for a python messageboard CGI for a long time.
> 

Thanx!

No glaring security holes that you noticed? Other than being able to hide
things in html tags?

> If you wanted to add user accounts/login/admin etc. you could use 'Login
> Tools'. This is a python module built especially to do that. It also
> provides a convenient way of saving user preferences etc.
> 
> http://www.voidspace.org.uk/python/logintools.html
> 
> If you want any help using it then feel free to ask.
> 
> Regards,

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python/cgi/html bug

2005-01-19 Thread Dfenestr8
On Tue, 18 Jan 2005 21:50:58 -0800, Dan Bishop wrote:

> 
> Dfenestr8 wrote:
>> Hi.
>>
>> I've written a cgi messageboard script in python, for an irc chan I
> happen
>> to frequent.
>>
>> Bear with me, it's hard for me to describe what the bug is. So I've
>> divided this post into two sections: HOW MY SCRIPTS WORKS, and WHAT
> THE
>> BUG IS.
>> ...
>> The problem is when someone posts a new topic, and that topic happens
> to
>> have "" double quotes, or any other strange character, some strange
>> glitches occur.
> 
> Use cgi.escape(topic, True) to convert HTML special characters to the
> equivalent ampersand escape sequences.

Thanx.

Seems to work now. :)

-- 
http://mail.python.org/mailman/listinfo/python-list


python/cgi/html bug

2005-01-18 Thread Dfenestr8
Hi.

I've written a cgi messageboard script in python, for an irc chan I happen
to frequent.

Bear with me, it's hard for me to describe what the bug is. So I've
divided this post into two sections: HOW MY SCRIPTS WORKS, and WHAT THE
BUG IS.



HOW MY SCRIPT WORKS 

Basically, it's divided into two executable scripts..

One is the thread viewer, ppthread.py, which views threads. When someone
posts a new topic, for instance called "Generic new topic", it creates
a file called "Generic new topic.thread". It stores the post, and any
subsequent posts under in the thread in that file. Nice and simple I
figured.

The other executable script is the topic viewer, pptopic.py. All that does
is display the topics, by doing a "tops = os.popen('ls -c *.thread')" The
"ls -c" part reads the threads in the order in which they've been
modified, so the first item in the list is always the thread most recently
posted in. 

It then creates an html link to each of the threads ... on the page the
html looks like

foo

WHAT THE BUG IS 

The problem is when someone posts a new topic, and that topic happens to
have "" double quotes, or any other strange character, some strange
glitches occur. 

Best way to describe is to demonstrate it is go to the forum and try
it yourself. Try entering a topic with straight, ordindary characters, not
that you can re enter the thread any time you want and make new posts
under it. Then try entering a thread with new or whacky characters and see
how far you get.

http://funkmunch.net/~pirch/cgi-bin/alphaforum/pptopic.py

BTW, if you want to download the script, here it is in gzipped form
http://funkmunch.net/~pirch/pepperpot.tgz





-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help using sockets, and OOP?

2004-12-06 Thread Dfenestr8
On Sun, 05 Dec 2004 22:29:26 +, Jp Calderone wrote:

>> >   Your problem doesn't seem to have anything to do with "OOP"
>> >   (whatever that is).  Rather, you are trying to use two blocking
>> >   sockets at once.
>> > 
>> >   socket.connect() and socket.recv() are both "blocking" operations by
>> >   default - they can take an arbitrary amount of time to return.
>> >   Additionally, Botling.receiveData, one of your own functions, is
>> >   also blocking: it will actually loop forever, never returning (until
>> >   an exception blows it up).  So execution of your program never even
>> >   _gets_ to the "bert2 = ..." line.  It's stuck running
>> >   bert1.receiveData().
>> 
>> 
>> Ok, so what if I remove the while loop from the Botling class, and
>> include it in the __main__ ? Might this work as a solution then?
> 
>   No.

Ok, so are there other types of sockets that aren't "blocking" ?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help using sockets, and OOP?

2004-12-05 Thread Dfenestr8
On Sun, 05 Dec 2004 20:17:31 +, Jp Calderone wrote:

>   Your problem doesn't seem to have anything to do with "OOP" (whatever
>   that is).  Rather, you are trying to use two blocking sockets at once.
> 
>   socket.connect() and socket.recv() are both "blocking" operations by
>   default - they can take an arbitrary amount of time to return.
>   Additionally, Botling.receiveData, one of your own functions, is also
>   blocking: it will actually loop forever, never returning (until an
>   exception blows it up).  So execution of your program never even
>   _gets_ to the "bert2 = ..." line.  It's stuck running
>   bert1.receiveData().


Ok, so what if I remove the while loop from the Botling class, and include
it in the __main__ ? Might this work as a solution then?
 
if __name__ == '__main__':
bert1 = Botling("^berty^", "#exciting", "irc.interesting.org")
bert2=Botling("^berty^", "#interesing", "irc.exciting.org")

bert1.connectBot()
bert2.connectBot()

while 1:
bert1.receiveData()
bert2.receiveData()
-- 
http://mail.python.org/mailman/listinfo/python-list


help using sockets, and OOP?

2004-12-05 Thread Dfenestr8
Hi.

I realise, that there's probably something intrinsic to OOP that I don't
understand here. Or maybe it's something to do with sockets. I'm not sure.

Basically, I'm trying to hack up an IRC bot, that joins two servers at
once. I use two object instancs of the same class, both of which make
connections using the socket module.

Problem is, I can't seem to get both objects to connect to their
constituent servers at the same time. I'm not sure whether it's that both
objects can't instantiate at once, or whether only one can use the socket
module at any one time.

Here's my code:

http://plz.donthack.us/~hairyman/mybot.py

Can anybody see what it is I'm missing? 
-- 
http://mail.python.org/mailman/listinfo/python-list