[PATCH] zeroconf: Use BadDomainName exception instead of string exceptions

Javi Merino cibervicho at gmail.com
Wed Jun 23 03:54:21 CDT 2010


Hi,

In a previous message to this list[0], I was suggested to use exception
classes to remove string exceptions, which are no longer supported in
python 2.6. This patch does that.

[0] http://www.selenic.com/pipermail/mercurial-devel/2010-June/021789.html

Regards,
Javi (Vicho)

# HG changeset patch
# User Javi Merino <cibervicho at gmail.com>
# Date 1277282753 -7200
# Node ID da3213329ec4a727afe396d38e3b9aff0ff02c99
# Parent  8b452fe4bf506a1a08bbc7e1bac81aceda8f4d10
zeroconf: Use BadDomainName exception instead of string exceptions

String exceptions no longer work in python 2.6. Use exception classes
instead.

diff --git a/hgext/zeroconf/Zeroconf.py b/hgext/zeroconf/Zeroconf.py
--- a/hgext/zeroconf/Zeroconf.py
+++ b/hgext/zeroconf/Zeroconf.py
@@ -204,6 +204,13 @@ class AbstractMethodException(Exception)
 class BadTypeInNameException(Exception):
        pass
 
+class BadDomainName(Exception):
+       def __init__(self, pos):
+               Exception.__init__(self, "at position " + str(pos))
+
+class BadDomainNameCircular(BadDomainName):
+       pass
+
 # implementation classes
 
 class DNSEntry(object):
@@ -598,10 +605,10 @@ class DNSIncoming(object):
                                        next = off + 1
                                off = ((len & 0x3F) << 8) | ord(self.data[off])
                                if off >= first:
-                                       raise "Bad domain name (circular) at " + str(off)
+                                       raise BadDomainNameCircular(off)
                                first = off
                        else:
-                               raise "Bad domain name at " + str(off)
+                               raise BadDomainName(off)
 
                if next >= 0:
                        self.offset = next

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20100623/ec8709fa/attachment.pgp>


More information about the Mercurial-devel mailing list