~ubuntu-branches/ubuntu/gutsy/python-dns/gutsy-security

« back to all changes in this revision

Viewing changes to DNS/Lib.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2007-05-11 10:29:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070511102903-9qyhxe3d4cs5eera
Tags: 2.3.0-6
* New maintainer
* Acknowledge NMU, thanks Raphael Hertzog; (closes: #373528).
  - NMU also provided Python 2.4 packages (closes: #326155).
* debian/control:
  - Add Debian Python Modules Team as uploader 
  - Update standards version to 3.7.2
  - Update python-support build-depends to version (>= 0.3) and move from 
    Indep to build-depends
  - Add XS-Vcs-Svn
  - Removed XS-Python-Version and XB-Python-Version
* debian/pyversions and debian/pycompat added
* Add simple-patchsys.mk to debian/rules
* Bump compat to 5
* BTS Patches:
  - 01resolv-conf-parse patch, thanks to Arnaud Fontaine <arnaud@andesi.org> 
    (closes: #378991)
* Changes from Ubuntu (SF = Sourceforge project bug #) (closes: #411138):
  - 02utf-8 patch for files with UTF-8 content
  - 03socket-error-trap patch, Added DNSError trap for socket.error.
  - 04lazy-init SF 1563723 lazy should initilize defaults['server']
  - 05addr2bin2addr SF 863364 Mac OS X, Win2000 DHCP, addr2bin and bin2addr.
  - 06win32-fix SF 1180344 win32dns.py fails on windows server 2003
  - 07unpacker SF 954095 Bug in DNS.Lib.Unpacker.getbyte()
  - 08import-lib SF 658601 Missing "import Lib"; for TCP protocol

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- encoding: utf-8 -*-
2
1
"""
3
2
 $Id: Lib.py,v 1.11 2002/03/19 13:05:02 anthonybaxter Exp $
4
3
 
39
38
 
40
39
from struct import pack as struct_pack
41
40
from struct import unpack as struct_unpack
42
 
# Sourceforge 863364
43
 
from socket import inet_ntoa, inet_aton
44
41
 
45
42
def pack16bit(n):
46
43
    return struct_pack('!H', n)
55
52
    return struct_unpack('!L', s)[0]
56
53
 
57
54
def addr2bin(addr):
58
 
    # Sourceforge 863364
59
 
    return struct_unpack('!l', inet_aton(addr))[0]
 
55
    if type(addr) == type(0): return addr
 
56
    bytes = addr.split('.')
 
57
    if len(bytes) != 4: raise ValueError, 'bad IP address'
 
58
    n = 0
 
59
    for byte in bytes: n = n<<8 | int(byte)
 
60
    return n
60
61
 
61
62
def bin2addr(n):
62
 
    # Sourceforge 863364
63
 
    return inet_ntoa(struct_pack('!L', n))
 
63
    return '%d.%d.%d.%d' % ((n>>24)&0xFF, (n>>16)&0xFF,
 
64
                  (n>>8)&0xFF, n&0xFF)
64
65
 
65
66
 
66
67
# Packing class
164
165
        self.buf = buf
165
166
        self.offset = 0
166
167
    def getbyte(self):
167
 
        # Sourceforge #954095
168
 
        if self.offset >= len(self.buf):
 
168
        if self.offset > len(self.buf):
169
169
            raise UnpackError, "Ran off end of data"
170
170
        c = self.buf[self.offset]
171
171
        self.offset = self.offset + 1