Bug#378459: Processed: Re: Bug#378459: formencode: exception not catched

2006-07-17 Thread Arnaud Fontaine
> "Fabio" == Fabio Tranchitella <[EMAIL PROTECTED]> writes:

Fabio> I fully agree and will  apply the patch with the next upload.
Fabio> Thanks for your report, patch and explanation. :)

Hey,

I have  forgotten something in my  patch. If the connection  is down and
there isn't DNS server configured, then a socket.error exception will be
raise, otherwise  if there  is DNS server  configured, DNS.Base.DNSError
will be  raise. The patch  i have attached  to this mail fixes  also the
second case ;). I tried it and it works, tell me if it works for you...

Regards,
Arnaud Fontaine

--- validators.py.old	2006-07-16 14:11:26.249788848 +0200
+++ validators.py	2006-07-17 14:13:23.185329064 +0200
@@ -29,6 +29,7 @@
 httplib = None
 urlparse = None
 socket = None
+DNSError = None
 from interfaces import *
 from api import *
 sha = random = None
@@ -1130,6 +1131,7 @@
 'empty': 'Please enter an email address',
 'noAt': 'An email address must contain a single @',
 'badUsername': 'The username portion of the email address is invalid (the portion before the @: %(username)s)',
+'socketError': 'An error occured when trying to connect to the server: %(error)s',
 'badDomain': 'The domain portion of the email address is invalid (the portion after the @: %(domain)s)',
 'domainDoesNotExist': 'The domain of the email address does not exist (the portion after the @: %(domain)s)',
 }
@@ -1173,7 +1175,19 @@
  domain=splitted[1]),
 value, state)
 if self.resolve_domain:
-domains = mxlookup(splitted[1])
+	global socket, DNSError
+	if socket is None:
+	import socket
+
+	if DNSError is None:
+		from DNS.Base import DNSError
+
+	try:
+domains = mxlookup(splitted[1])
+	except (socket.error, DNSError), e:
+		raise Invalid(
+		self.message('socketError', state, error=e),
+		value, state)
 if not domains:
 raise Invalid(
 self.message('domainDoesNotExist', state,


pgpwcFKiTLD6N.pgp
Description: PGP signature


Bug#378459: Processed: Re: Bug#378459: formencode: exception not catched

2006-07-17 Thread Fabio Tranchitella
Il giorno dom, 16/07/2006 alle 23.07 +0200, Arnaud Fontaine ha scritto:
> It would make sense  if the upstream author did it like  that in the URL
> class (line 1294  in validators.py). In this class,  the error exception
> is catched and then an Invalid  exception is raise with the proper error
> message. I think it is better to have an exception Invalid because every
> other exceptions in  the validators file are catched  and then a Invalid
> exception is raised.
> 
> In addition, it is necessary  for third application (like turbogears) to
> use the instance variables provided by this exception.

I fully agree and will apply the patch with the next upload.

Thanks for your report, patch and explanation. :)

-- 
Fabio Tranchitella <[EMAIL PROTECTED]>.''`.
Proud Debian GNU/Linux developer, admin and user.: :'  :
 `. `'`
   http://people.debian.org/~kobold/   `-
_
1024D/7F961564, fpr 5465 6E69 E559 6466 BF3D 9F01 2BF8 EE2B 7F96 1564


signature.asc
Description: Questa è una parte del messaggio	firmata digitalmente


Bug#378459: Processed: Re: Bug#378459: formencode: exception not catched

2006-07-16 Thread Arnaud Fontaine
> "Fabio" == Fabio Tranchitella <[EMAIL PROTECTED]> writes:

Fabio>   I'm not sure  that an  exception Invalid  is better  then a
Fabio> socket.error: all in all,  there is a problem with the socket
Fabio> and the actual behaviour is quite clear in this sense.

It would make sense  if the upstream author did it like  that in the URL
class (line 1294  in validators.py). In this class,  the error exception
is catched and then an Invalid  exception is raise with the proper error
message. I think it is better to have an exception Invalid because every
other exceptions in  the validators file are catched  and then a Invalid
exception is raised.

In addition, it is necessary  for third application (like turbogears) to
use the instance variables provided by this exception.

Fabio> Anyway, you missed to attach the patch! :)

Sorry, i have attached it to this mail.

Fabio> What about  talking with upstream about this  issue? There is
Fabio> nothing debian specific and  I would prefer to not apply this
Fabio> patch if upstream doesn't agree.

I will forward him  this patch. Do you see why i think  this is a bug in
formencode ?

Regards,
Arnaud Fontaine

--- validators.py.old	2006-07-16 14:11:26.249788848 +0200
+++ validators.py	2006-07-14 10:38:13.947459712 +0200
@@ -1130,6 +1130,7 @@
 'empty': 'Please enter an email address',
 'noAt': 'An email address must contain a single @',
 'badUsername': 'The username portion of the email address is invalid (the portion before the @: %(username)s)',
+'socketError': 'An error occured when trying to connect to the server: %(error)s',
 'badDomain': 'The domain portion of the email address is invalid (the portion after the @: %(domain)s)',
 'domainDoesNotExist': 'The domain of the email address does not exist (the portion after the @: %(domain)s)',
 }
@@ -1173,7 +1174,16 @@
  domain=splitted[1]),
 value, state)
 if self.resolve_domain:
-domains = mxlookup(splitted[1])
+	global socket
+	if socket is None:
+	import socket
+
+	try:
+domains = mxlookup(splitted[1])
+	except socket.error, e:
+		raise Invalid(
+		self.message('socketError', state, error=e),
+		value, state)
 if not domains:
 raise Invalid(
 self.message('domainDoesNotExist', state,


Bug#378459: Processed: Re: Bug#378459: formencode: exception not catched

2006-07-16 Thread Fabio Tranchitella
Hi Arnaud, thanks for your report!

I'm not sure that an exception Invalid is better then a socket.error:
all in all, there is a problem with the socket and the actual behaviour
is quite clear in this sense.

Anyway, you missed to attach the patch! :)

What about talking with upstream about this issue? There is nothing
debian specific and I would prefer to not apply this patch if upstream
doesn't agree.

Thanks,

-- 
Fabio Tranchitella <[EMAIL PROTECTED]>.''`.
Proud Debian GNU/Linux developer, admin and user.: :'  :
 `. `'`
   http://people.debian.org/~kobold/   `-
_
1024D/7F961564, fpr 5465 6E69 E559 6466 BF3D 9F01 2BF8 EE2B 7F96 1564


signature.asc
Description: Questa è una parte del messaggio	firmata digitalmente