global name not defined

2006-05-22 Thread NetKev
I added a function 'warn_Admin' and defined it just before another
function 'process_log'.  'process_log' calls this warn_Admin' function.
 However, when it gets called i get the following error every time:
---
Traceback (most recent call last):
  File "/usr/bin/denyhosts.py", line 202, in ?
first_time, noemail, daemon)
  File "/usr/lib/python2.3/site-packages/DenyHosts/deny_hosts.py", line
86, in __init__
last_offset)
  File "/usr/lib/python2.3/site-packages/DenyHosts/daemon.py", line 74,
in createDaemon
apply(func, args)
  File "/usr/lib/python2.3/site-packages/DenyHosts/deny_hosts.py", line
137, in runDaemon
purge_time, purge_sleep_ratio)
  File "/usr/lib/python2.3/site-packages/DenyHosts/deny_hosts.py", line
178, in daemonLoop
last_offset = self.process_log(logfile, last_offset)
  File "/usr/lib/python2.3/site-packages/DenyHosts/deny_hosts.py", line
380, in process_log
[warn_Admin(ip) for ip in new_denied_hosts]
NameError: global name 'warn_Admin' is not defined
--
If I take the two functions out of their current environment and store
them in test file and run it, it doesn't complain.  I'm new  to python
so I'm guessing there is some weird scope rule I am missing.  I did try
'self.warn_Admin(ip)' just to be safe but then I got a 'too many
arguments' error?

I'm lost :)

the added function plus the header of the existing function(its too
large):

 def warn_Admin(warn_ip):
SENDMAIL = "/usr/sbin/sendmail" # sendmail location
p = os.popen("%s -t" % SENDMAIL, "w")
p.write("To: [EMAIL PROTECTED]")
p.write("Subject: test from denyhosts\n")
p.write("\n") # blank line separating headers from body
p.write("Some text\n")
p.write(warn_ip)
sts = p.close()
if sts != 0:
info("Sendmail exit status: %s", sts)
return sts


def process_log(self, logfile, offset):
-

the call to warn_Admin from process_log:
---
if new_denied_hosts:
info("new denied hosts: %s", str(new_denied_hosts))
#[info(ip) for ip in new_denied_hosts]
[warn_Admin(ip) for ip in new_denied_hosts]
else:
debug("no new denied hosts")

-kevin

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


global name not defined

2006-05-22 Thread NetKev
I added a function 'warn_Admin' and defined it just before another
function 'process_log'.  'process_log' calls this warn_Admin' function.
 However, when it gets called i get the following error every time:
---
Traceback (most recent call last):
  File "/usr/bin/denyhosts.py", line 202, in ?
first_time, noemail, daemon)
  File "/usr/lib/python2.3/site-packages/DenyHosts/deny_hosts.py", line
86, in __init__
last_offset)
  File "/usr/lib/python2.3/site-packages/DenyHosts/daemon.py", line 74,
in createDaemon
apply(func, args)
  File "/usr/lib/python2.3/site-packages/DenyHosts/deny_hosts.py", line
137, in runDaemon
purge_time, purge_sleep_ratio)
  File "/usr/lib/python2.3/site-packages/DenyHosts/deny_hosts.py", line
178, in daemonLoop
last_offset = self.process_log(logfile, last_offset)
  File "/usr/lib/python2.3/site-packages/DenyHosts/deny_hosts.py", line
380, in process_log
[warn_Admin(ip) for ip in new_denied_hosts]
NameError: global name 'warn_Admin' is not defined
--
If I take the two functions out of their current environment and store
them in test file and run it, it doesn't complain.  I'm new  to python
so I'm guessing there is some weird scope rule I am missing.  I did try
'self.warn_Admin(ip)' just to be safe but then I got a 'too many
arguments' error?

I'm lost :)

-kevin

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


Re: global name not defined

2006-05-22 Thread NetKev
google groups told me it had a "server error" the first time i posted
this.  Sorry for the dupe.  Anyways the second one is more complete.
Also, I made a mistake in my vocabulary.  These are methods and not
functions.

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


Re: global name not defined

2006-05-22 Thread NetKev
You are probably right and I think I will do so but just for the sake
of my understanding of python...I noticed somthing.  process_log takes
two arguments when called but it's definition has 3 and one of them is
"self".  So I'm thinking if I modify my warn_Admin definition to
include "self" and then call it from process_log with
self.warn_Admin... it will work.  This explains why I was getting the
"too many arguments" error.

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


Re: global name not defined

2006-05-23 Thread NetKev
good point

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