Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../lib64/python2....
File: uuid.py
r"""UUID objects (universally unique identifiers) according to RFC 4122.
[0] Fix | Delete
[1] Fix | Delete
This module provides immutable UUID objects (class UUID) and the functions
[2] Fix | Delete
uuid1(), uuid3(), uuid4(), uuid5() for generating version 1, 3, 4, and 5
[3] Fix | Delete
UUIDs as specified in RFC 4122.
[4] Fix | Delete
[5] Fix | Delete
If all you want is a unique ID, you should probably call uuid1() or uuid4().
[6] Fix | Delete
Note that uuid1() may compromise privacy since it creates a UUID containing
[7] Fix | Delete
the computer's network address. uuid4() creates a random UUID.
[8] Fix | Delete
[9] Fix | Delete
Typical usage:
[10] Fix | Delete
[11] Fix | Delete
>>> import uuid
[12] Fix | Delete
[13] Fix | Delete
# make a UUID based on the host ID and current time
[14] Fix | Delete
>>> uuid.uuid1()
[15] Fix | Delete
UUID('a8098c1a-f86e-11da-bd1a-00112444be1e')
[16] Fix | Delete
[17] Fix | Delete
# make a UUID using an MD5 hash of a namespace UUID and a name
[18] Fix | Delete
>>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org')
[19] Fix | Delete
UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e')
[20] Fix | Delete
[21] Fix | Delete
# make a random UUID
[22] Fix | Delete
>>> uuid.uuid4()
[23] Fix | Delete
UUID('16fd2706-8baf-433b-82eb-8c7fada847da')
[24] Fix | Delete
[25] Fix | Delete
# make a UUID using a SHA-1 hash of a namespace UUID and a name
[26] Fix | Delete
>>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')
[27] Fix | Delete
UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d')
[28] Fix | Delete
[29] Fix | Delete
# make a UUID from a string of hex digits (braces and hyphens ignored)
[30] Fix | Delete
>>> x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}')
[31] Fix | Delete
[32] Fix | Delete
# convert a UUID to a string of hex digits in standard form
[33] Fix | Delete
>>> str(x)
[34] Fix | Delete
'00010203-0405-0607-0809-0a0b0c0d0e0f'
[35] Fix | Delete
[36] Fix | Delete
# get the raw 16 bytes of the UUID
[37] Fix | Delete
>>> x.bytes
[38] Fix | Delete
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
[39] Fix | Delete
[40] Fix | Delete
# make a UUID from a 16-byte string
[41] Fix | Delete
>>> uuid.UUID(bytes=x.bytes)
[42] Fix | Delete
UUID('00010203-0405-0607-0809-0a0b0c0d0e0f')
[43] Fix | Delete
"""
[44] Fix | Delete
[45] Fix | Delete
import os
[46] Fix | Delete
[47] Fix | Delete
__author__ = 'Ka-Ping Yee <ping@zesty.ca>'
[48] Fix | Delete
[49] Fix | Delete
RESERVED_NCS, RFC_4122, RESERVED_MICROSOFT, RESERVED_FUTURE = [
[50] Fix | Delete
'reserved for NCS compatibility', 'specified in RFC 4122',
[51] Fix | Delete
'reserved for Microsoft compatibility', 'reserved for future definition']
[52] Fix | Delete
[53] Fix | Delete
class UUID(object):
[54] Fix | Delete
"""Instances of the UUID class represent UUIDs as specified in RFC 4122.
[55] Fix | Delete
UUID objects are immutable, hashable, and usable as dictionary keys.
[56] Fix | Delete
Converting a UUID to a string with str() yields something in the form
[57] Fix | Delete
'12345678-1234-1234-1234-123456789abc'. The UUID constructor accepts
[58] Fix | Delete
five possible forms: a similar string of hexadecimal digits, or a tuple
[59] Fix | Delete
of six integer fields (with 32-bit, 16-bit, 16-bit, 8-bit, 8-bit, and
[60] Fix | Delete
48-bit values respectively) as an argument named 'fields', or a string
[61] Fix | Delete
of 16 bytes (with all the integer fields in big-endian order) as an
[62] Fix | Delete
argument named 'bytes', or a string of 16 bytes (with the first three
[63] Fix | Delete
fields in little-endian order) as an argument named 'bytes_le', or a
[64] Fix | Delete
single 128-bit integer as an argument named 'int'.
[65] Fix | Delete
[66] Fix | Delete
UUIDs have these read-only attributes:
[67] Fix | Delete
[68] Fix | Delete
bytes the UUID as a 16-byte string (containing the six
[69] Fix | Delete
integer fields in big-endian byte order)
[70] Fix | Delete
[71] Fix | Delete
bytes_le the UUID as a 16-byte string (with time_low, time_mid,
[72] Fix | Delete
and time_hi_version in little-endian byte order)
[73] Fix | Delete
[74] Fix | Delete
fields a tuple of the six integer fields of the UUID,
[75] Fix | Delete
which are also available as six individual attributes
[76] Fix | Delete
and two derived attributes:
[77] Fix | Delete
[78] Fix | Delete
time_low the first 32 bits of the UUID
[79] Fix | Delete
time_mid the next 16 bits of the UUID
[80] Fix | Delete
time_hi_version the next 16 bits of the UUID
[81] Fix | Delete
clock_seq_hi_variant the next 8 bits of the UUID
[82] Fix | Delete
clock_seq_low the next 8 bits of the UUID
[83] Fix | Delete
node the last 48 bits of the UUID
[84] Fix | Delete
[85] Fix | Delete
time the 60-bit timestamp
[86] Fix | Delete
clock_seq the 14-bit sequence number
[87] Fix | Delete
[88] Fix | Delete
hex the UUID as a 32-character hexadecimal string
[89] Fix | Delete
[90] Fix | Delete
int the UUID as a 128-bit integer
[91] Fix | Delete
[92] Fix | Delete
urn the UUID as a URN as specified in RFC 4122
[93] Fix | Delete
[94] Fix | Delete
variant the UUID variant (one of the constants RESERVED_NCS,
[95] Fix | Delete
RFC_4122, RESERVED_MICROSOFT, or RESERVED_FUTURE)
[96] Fix | Delete
[97] Fix | Delete
version the UUID version number (1 through 5, meaningful only
[98] Fix | Delete
when the variant is RFC_4122)
[99] Fix | Delete
"""
[100] Fix | Delete
[101] Fix | Delete
def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None,
[102] Fix | Delete
int=None, version=None):
[103] Fix | Delete
r"""Create a UUID from either a string of 32 hexadecimal digits,
[104] Fix | Delete
a string of 16 bytes as the 'bytes' argument, a string of 16 bytes
[105] Fix | Delete
in little-endian order as the 'bytes_le' argument, a tuple of six
[106] Fix | Delete
integers (32-bit time_low, 16-bit time_mid, 16-bit time_hi_version,
[107] Fix | Delete
8-bit clock_seq_hi_variant, 8-bit clock_seq_low, 48-bit node) as
[108] Fix | Delete
the 'fields' argument, or a single 128-bit integer as the 'int'
[109] Fix | Delete
argument. When a string of hex digits is given, curly braces,
[110] Fix | Delete
hyphens, and a URN prefix are all optional. For example, these
[111] Fix | Delete
expressions all yield the same UUID:
[112] Fix | Delete
[113] Fix | Delete
UUID('{12345678-1234-5678-1234-567812345678}')
[114] Fix | Delete
UUID('12345678123456781234567812345678')
[115] Fix | Delete
UUID('urn:uuid:12345678-1234-5678-1234-567812345678')
[116] Fix | Delete
UUID(bytes='\x12\x34\x56\x78'*4)
[117] Fix | Delete
UUID(bytes_le='\x78\x56\x34\x12\x34\x12\x78\x56' +
[118] Fix | Delete
'\x12\x34\x56\x78\x12\x34\x56\x78')
[119] Fix | Delete
UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678))
[120] Fix | Delete
UUID(int=0x12345678123456781234567812345678)
[121] Fix | Delete
[122] Fix | Delete
Exactly one of 'hex', 'bytes', 'bytes_le', 'fields', or 'int' must
[123] Fix | Delete
be given. The 'version' argument is optional; if given, the resulting
[124] Fix | Delete
UUID will have its variant and version set according to RFC 4122,
[125] Fix | Delete
overriding the given 'hex', 'bytes', 'bytes_le', 'fields', or 'int'.
[126] Fix | Delete
"""
[127] Fix | Delete
[128] Fix | Delete
if [hex, bytes, bytes_le, fields, int].count(None) != 4:
[129] Fix | Delete
raise TypeError('need one of hex, bytes, bytes_le, fields, or int')
[130] Fix | Delete
if hex is not None:
[131] Fix | Delete
hex = hex.replace('urn:', '').replace('uuid:', '')
[132] Fix | Delete
hex = hex.strip('{}').replace('-', '')
[133] Fix | Delete
if len(hex) != 32:
[134] Fix | Delete
raise ValueError('badly formed hexadecimal UUID string')
[135] Fix | Delete
int = long(hex, 16)
[136] Fix | Delete
if bytes_le is not None:
[137] Fix | Delete
if len(bytes_le) != 16:
[138] Fix | Delete
raise ValueError('bytes_le is not a 16-char string')
[139] Fix | Delete
bytes = (bytes_le[3] + bytes_le[2] + bytes_le[1] + bytes_le[0] +
[140] Fix | Delete
bytes_le[5] + bytes_le[4] + bytes_le[7] + bytes_le[6] +
[141] Fix | Delete
bytes_le[8:])
[142] Fix | Delete
if bytes is not None:
[143] Fix | Delete
if len(bytes) != 16:
[144] Fix | Delete
raise ValueError('bytes is not a 16-char string')
[145] Fix | Delete
int = long(('%02x'*16) % tuple(map(ord, bytes)), 16)
[146] Fix | Delete
if fields is not None:
[147] Fix | Delete
if len(fields) != 6:
[148] Fix | Delete
raise ValueError('fields is not a 6-tuple')
[149] Fix | Delete
(time_low, time_mid, time_hi_version,
[150] Fix | Delete
clock_seq_hi_variant, clock_seq_low, node) = fields
[151] Fix | Delete
if not 0 <= time_low < 1<<32L:
[152] Fix | Delete
raise ValueError('field 1 out of range (need a 32-bit value)')
[153] Fix | Delete
if not 0 <= time_mid < 1<<16L:
[154] Fix | Delete
raise ValueError('field 2 out of range (need a 16-bit value)')
[155] Fix | Delete
if not 0 <= time_hi_version < 1<<16L:
[156] Fix | Delete
raise ValueError('field 3 out of range (need a 16-bit value)')
[157] Fix | Delete
if not 0 <= clock_seq_hi_variant < 1<<8L:
[158] Fix | Delete
raise ValueError('field 4 out of range (need an 8-bit value)')
[159] Fix | Delete
if not 0 <= clock_seq_low < 1<<8L:
[160] Fix | Delete
raise ValueError('field 5 out of range (need an 8-bit value)')
[161] Fix | Delete
if not 0 <= node < 1<<48L:
[162] Fix | Delete
raise ValueError('field 6 out of range (need a 48-bit value)')
[163] Fix | Delete
clock_seq = (clock_seq_hi_variant << 8L) | clock_seq_low
[164] Fix | Delete
int = ((time_low << 96L) | (time_mid << 80L) |
[165] Fix | Delete
(time_hi_version << 64L) | (clock_seq << 48L) | node)
[166] Fix | Delete
if int is not None:
[167] Fix | Delete
if not 0 <= int < 1<<128L:
[168] Fix | Delete
raise ValueError('int is out of range (need a 128-bit value)')
[169] Fix | Delete
if version is not None:
[170] Fix | Delete
if not 1 <= version <= 5:
[171] Fix | Delete
raise ValueError('illegal version number')
[172] Fix | Delete
# Set the variant to RFC 4122.
[173] Fix | Delete
int &= ~(0xc000 << 48L)
[174] Fix | Delete
int |= 0x8000 << 48L
[175] Fix | Delete
# Set the version number.
[176] Fix | Delete
int &= ~(0xf000 << 64L)
[177] Fix | Delete
int |= version << 76L
[178] Fix | Delete
self.__dict__['int'] = int
[179] Fix | Delete
[180] Fix | Delete
def __cmp__(self, other):
[181] Fix | Delete
if isinstance(other, UUID):
[182] Fix | Delete
return cmp(self.int, other.int)
[183] Fix | Delete
return NotImplemented
[184] Fix | Delete
[185] Fix | Delete
def __hash__(self):
[186] Fix | Delete
return hash(self.int)
[187] Fix | Delete
[188] Fix | Delete
def __int__(self):
[189] Fix | Delete
return self.int
[190] Fix | Delete
[191] Fix | Delete
def __repr__(self):
[192] Fix | Delete
return 'UUID(%r)' % str(self)
[193] Fix | Delete
[194] Fix | Delete
def __setattr__(self, name, value):
[195] Fix | Delete
raise TypeError('UUID objects are immutable')
[196] Fix | Delete
[197] Fix | Delete
def __str__(self):
[198] Fix | Delete
hex = '%032x' % self.int
[199] Fix | Delete
return '%s-%s-%s-%s-%s' % (
[200] Fix | Delete
hex[:8], hex[8:12], hex[12:16], hex[16:20], hex[20:])
[201] Fix | Delete
[202] Fix | Delete
def get_bytes(self):
[203] Fix | Delete
bytes = ''
[204] Fix | Delete
for shift in range(0, 128, 8):
[205] Fix | Delete
bytes = chr((self.int >> shift) & 0xff) + bytes
[206] Fix | Delete
return bytes
[207] Fix | Delete
[208] Fix | Delete
bytes = property(get_bytes)
[209] Fix | Delete
[210] Fix | Delete
def get_bytes_le(self):
[211] Fix | Delete
bytes = self.bytes
[212] Fix | Delete
return (bytes[3] + bytes[2] + bytes[1] + bytes[0] +
[213] Fix | Delete
bytes[5] + bytes[4] + bytes[7] + bytes[6] + bytes[8:])
[214] Fix | Delete
[215] Fix | Delete
bytes_le = property(get_bytes_le)
[216] Fix | Delete
[217] Fix | Delete
def get_fields(self):
[218] Fix | Delete
return (self.time_low, self.time_mid, self.time_hi_version,
[219] Fix | Delete
self.clock_seq_hi_variant, self.clock_seq_low, self.node)
[220] Fix | Delete
[221] Fix | Delete
fields = property(get_fields)
[222] Fix | Delete
[223] Fix | Delete
def get_time_low(self):
[224] Fix | Delete
return self.int >> 96L
[225] Fix | Delete
[226] Fix | Delete
time_low = property(get_time_low)
[227] Fix | Delete
[228] Fix | Delete
def get_time_mid(self):
[229] Fix | Delete
return (self.int >> 80L) & 0xffff
[230] Fix | Delete
[231] Fix | Delete
time_mid = property(get_time_mid)
[232] Fix | Delete
[233] Fix | Delete
def get_time_hi_version(self):
[234] Fix | Delete
return (self.int >> 64L) & 0xffff
[235] Fix | Delete
[236] Fix | Delete
time_hi_version = property(get_time_hi_version)
[237] Fix | Delete
[238] Fix | Delete
def get_clock_seq_hi_variant(self):
[239] Fix | Delete
return (self.int >> 56L) & 0xff
[240] Fix | Delete
[241] Fix | Delete
clock_seq_hi_variant = property(get_clock_seq_hi_variant)
[242] Fix | Delete
[243] Fix | Delete
def get_clock_seq_low(self):
[244] Fix | Delete
return (self.int >> 48L) & 0xff
[245] Fix | Delete
[246] Fix | Delete
clock_seq_low = property(get_clock_seq_low)
[247] Fix | Delete
[248] Fix | Delete
def get_time(self):
[249] Fix | Delete
return (((self.time_hi_version & 0x0fffL) << 48L) |
[250] Fix | Delete
(self.time_mid << 32L) | self.time_low)
[251] Fix | Delete
[252] Fix | Delete
time = property(get_time)
[253] Fix | Delete
[254] Fix | Delete
def get_clock_seq(self):
[255] Fix | Delete
return (((self.clock_seq_hi_variant & 0x3fL) << 8L) |
[256] Fix | Delete
self.clock_seq_low)
[257] Fix | Delete
[258] Fix | Delete
clock_seq = property(get_clock_seq)
[259] Fix | Delete
[260] Fix | Delete
def get_node(self):
[261] Fix | Delete
return self.int & 0xffffffffffff
[262] Fix | Delete
[263] Fix | Delete
node = property(get_node)
[264] Fix | Delete
[265] Fix | Delete
def get_hex(self):
[266] Fix | Delete
return '%032x' % self.int
[267] Fix | Delete
[268] Fix | Delete
hex = property(get_hex)
[269] Fix | Delete
[270] Fix | Delete
def get_urn(self):
[271] Fix | Delete
return 'urn:uuid:' + str(self)
[272] Fix | Delete
[273] Fix | Delete
urn = property(get_urn)
[274] Fix | Delete
[275] Fix | Delete
def get_variant(self):
[276] Fix | Delete
if not self.int & (0x8000 << 48L):
[277] Fix | Delete
return RESERVED_NCS
[278] Fix | Delete
elif not self.int & (0x4000 << 48L):
[279] Fix | Delete
return RFC_4122
[280] Fix | Delete
elif not self.int & (0x2000 << 48L):
[281] Fix | Delete
return RESERVED_MICROSOFT
[282] Fix | Delete
else:
[283] Fix | Delete
return RESERVED_FUTURE
[284] Fix | Delete
[285] Fix | Delete
variant = property(get_variant)
[286] Fix | Delete
[287] Fix | Delete
def get_version(self):
[288] Fix | Delete
# The version bits are only meaningful for RFC 4122 UUIDs.
[289] Fix | Delete
if self.variant == RFC_4122:
[290] Fix | Delete
return int((self.int >> 76L) & 0xf)
[291] Fix | Delete
[292] Fix | Delete
version = property(get_version)
[293] Fix | Delete
[294] Fix | Delete
def _popen(command, args):
[295] Fix | Delete
import os
[296] Fix | Delete
path = os.environ.get("PATH", os.defpath).split(os.pathsep)
[297] Fix | Delete
path.extend(('/sbin', '/usr/sbin'))
[298] Fix | Delete
for dir in path:
[299] Fix | Delete
executable = os.path.join(dir, command)
[300] Fix | Delete
if (os.path.exists(executable) and
[301] Fix | Delete
os.access(executable, os.F_OK | os.X_OK) and
[302] Fix | Delete
not os.path.isdir(executable)):
[303] Fix | Delete
break
[304] Fix | Delete
else:
[305] Fix | Delete
return None
[306] Fix | Delete
# LC_ALL to ensure English output, 2>/dev/null to prevent output on
[307] Fix | Delete
# stderr (Note: we don't have an example where the words we search for
[308] Fix | Delete
# are actually localized, but in theory some system could do so.)
[309] Fix | Delete
cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args)
[310] Fix | Delete
return os.popen(cmd)
[311] Fix | Delete
[312] Fix | Delete
def _find_mac(command, args, hw_identifiers, get_index):
[313] Fix | Delete
try:
[314] Fix | Delete
pipe = _popen(command, args)
[315] Fix | Delete
if not pipe:
[316] Fix | Delete
return
[317] Fix | Delete
with pipe:
[318] Fix | Delete
for line in pipe:
[319] Fix | Delete
words = line.lower().rstrip().split()
[320] Fix | Delete
for i in range(len(words)):
[321] Fix | Delete
if words[i] in hw_identifiers:
[322] Fix | Delete
try:
[323] Fix | Delete
word = words[get_index(i)]
[324] Fix | Delete
mac = int(word.replace(':', ''), 16)
[325] Fix | Delete
if mac:
[326] Fix | Delete
return mac
[327] Fix | Delete
except (ValueError, IndexError):
[328] Fix | Delete
# Virtual interfaces, such as those provided by
[329] Fix | Delete
# VPNs, do not have a colon-delimited MAC address
[330] Fix | Delete
# as expected, but a 16-byte HWAddr separated by
[331] Fix | Delete
# dashes. These should be ignored in favor of a
[332] Fix | Delete
# real MAC address
[333] Fix | Delete
pass
[334] Fix | Delete
except IOError:
[335] Fix | Delete
pass
[336] Fix | Delete
[337] Fix | Delete
def _ifconfig_getnode():
[338] Fix | Delete
"""Get the hardware address on Unix by running ifconfig."""
[339] Fix | Delete
# This works on Linux ('' or '-a'), Tru64 ('-av'), but not all Unixes.
[340] Fix | Delete
keywords = ('hwaddr', 'ether', 'address:', 'lladdr')
[341] Fix | Delete
for args in ('', '-a', '-av'):
[342] Fix | Delete
mac = _find_mac('ifconfig', args, keywords, lambda i: i+1)
[343] Fix | Delete
if mac:
[344] Fix | Delete
return mac
[345] Fix | Delete
[346] Fix | Delete
def _arp_getnode():
[347] Fix | Delete
"""Get the hardware address on Unix by running arp."""
[348] Fix | Delete
import os, socket
[349] Fix | Delete
try:
[350] Fix | Delete
ip_addr = socket.gethostbyname(socket.gethostname())
[351] Fix | Delete
except EnvironmentError:
[352] Fix | Delete
return None
[353] Fix | Delete
[354] Fix | Delete
# Try getting the MAC addr from arp based on our IP address (Solaris).
[355] Fix | Delete
mac = _find_mac('arp', '-an', [ip_addr], lambda i: -1)
[356] Fix | Delete
if mac:
[357] Fix | Delete
return mac
[358] Fix | Delete
[359] Fix | Delete
# This works on OpenBSD
[360] Fix | Delete
mac = _find_mac('arp', '-an', [ip_addr], lambda i: i+1)
[361] Fix | Delete
if mac:
[362] Fix | Delete
return mac
[363] Fix | Delete
[364] Fix | Delete
# This works on Linux, FreeBSD and NetBSD
[365] Fix | Delete
mac = _find_mac('arp', '-an', ['(%s)' % ip_addr],
[366] Fix | Delete
lambda i: i+2)
[367] Fix | Delete
if mac:
[368] Fix | Delete
return mac
[369] Fix | Delete
[370] Fix | Delete
def _lanscan_getnode():
[371] Fix | Delete
"""Get the hardware address on Unix by running lanscan."""
[372] Fix | Delete
# This might work on HP-UX.
[373] Fix | Delete
return _find_mac('lanscan', '-ai', ['lan0'], lambda i: 0)
[374] Fix | Delete
[375] Fix | Delete
def _netstat_getnode():
[376] Fix | Delete
"""Get the hardware address on Unix by running netstat."""
[377] Fix | Delete
# This might work on AIX, Tru64 UNIX and presumably on IRIX.
[378] Fix | Delete
try:
[379] Fix | Delete
pipe = _popen('netstat', '-ia')
[380] Fix | Delete
if not pipe:
[381] Fix | Delete
return
[382] Fix | Delete
with pipe:
[383] Fix | Delete
words = pipe.readline().rstrip().split()
[384] Fix | Delete
try:
[385] Fix | Delete
i = words.index('Address')
[386] Fix | Delete
except ValueError:
[387] Fix | Delete
return
[388] Fix | Delete
for line in pipe:
[389] Fix | Delete
try:
[390] Fix | Delete
words = line.rstrip().split()
[391] Fix | Delete
word = words[i]
[392] Fix | Delete
if len(word) == 17 and word.count(':') == 5:
[393] Fix | Delete
mac = int(word.replace(':', ''), 16)
[394] Fix | Delete
if mac:
[395] Fix | Delete
return mac
[396] Fix | Delete
except (ValueError, IndexError):
[397] Fix | Delete
pass
[398] Fix | Delete
except OSError:
[399] Fix | Delete
pass
[400] Fix | Delete
[401] Fix | Delete
def _ipconfig_getnode():
[402] Fix | Delete
"""Get the hardware address on Windows by running ipconfig.exe."""
[403] Fix | Delete
import os, re
[404] Fix | Delete
dirs = ['', r'c:\windows\system32', r'c:\winnt\system32']
[405] Fix | Delete
try:
[406] Fix | Delete
import ctypes
[407] Fix | Delete
buffer = ctypes.create_string_buffer(300)
[408] Fix | Delete
ctypes.windll.kernel32.GetSystemDirectoryA(buffer, 300)
[409] Fix | Delete
dirs.insert(0, buffer.value.decode('mbcs'))
[410] Fix | Delete
except:
[411] Fix | Delete
pass
[412] Fix | Delete
for dir in dirs:
[413] Fix | Delete
try:
[414] Fix | Delete
pipe = os.popen(os.path.join(dir, 'ipconfig') + ' /all')
[415] Fix | Delete
except IOError:
[416] Fix | Delete
continue
[417] Fix | Delete
with pipe:
[418] Fix | Delete
for line in pipe:
[419] Fix | Delete
value = line.split(':')[-1].strip().lower()
[420] Fix | Delete
if re.match('(?:[0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]$', value):
[421] Fix | Delete
return int(value.replace('-', ''), 16)
[422] Fix | Delete
[423] Fix | Delete
def _netbios_getnode():
[424] Fix | Delete
"""Get the hardware address on Windows using NetBIOS calls.
[425] Fix | Delete
See http://support.microsoft.com/kb/118623 for details."""
[426] Fix | Delete
import win32wnet, netbios
[427] Fix | Delete
ncb = netbios.NCB()
[428] Fix | Delete
ncb.Command = netbios.NCBENUM
[429] Fix | Delete
ncb.Buffer = adapters = netbios.LANA_ENUM()
[430] Fix | Delete
adapters._pack()
[431] Fix | Delete
if win32wnet.Netbios(ncb) != 0:
[432] Fix | Delete
return
[433] Fix | Delete
adapters._unpack()
[434] Fix | Delete
for i in range(adapters.length):
[435] Fix | Delete
ncb.Reset()
[436] Fix | Delete
ncb.Command = netbios.NCBRESET
[437] Fix | Delete
ncb.Lana_num = ord(adapters.lana[i])
[438] Fix | Delete
if win32wnet.Netbios(ncb) != 0:
[439] Fix | Delete
continue
[440] Fix | Delete
ncb.Reset()
[441] Fix | Delete
ncb.Command = netbios.NCBASTAT
[442] Fix | Delete
ncb.Lana_num = ord(adapters.lana[i])
[443] Fix | Delete
ncb.Callname = '*'.ljust(16)
[444] Fix | Delete
ncb.Buffer = status = netbios.ADAPTER_STATUS()
[445] Fix | Delete
if win32wnet.Netbios(ncb) != 0:
[446] Fix | Delete
continue
[447] Fix | Delete
status._unpack()
[448] Fix | Delete
bytes = map(ord, status.adapter_address)
[449] Fix | Delete
return ((bytes[0]<<40L) + (bytes[1]<<32L) + (bytes[2]<<24L) +
[450] Fix | Delete
(bytes[3]<<16L) + (bytes[4]<<8L) + bytes[5])
[451] Fix | Delete
[452] Fix | Delete
# Thanks to Thomas Heller for ctypes and for his help with its use here.
[453] Fix | Delete
[454] Fix | Delete
# If ctypes is available, use it to find system routines for UUID generation.
[455] Fix | Delete
_uuid_generate_time = _UuidCreate = None
[456] Fix | Delete
_uuid_generate_md5 = None
[457] Fix | Delete
try:
[458] Fix | Delete
import ctypes, ctypes.util
[459] Fix | Delete
import sys
[460] Fix | Delete
[461] Fix | Delete
# The uuid_generate_* routines are provided by libuuid on at least
[462] Fix | Delete
# Linux and FreeBSD, and provided by libc on Mac OS X.
[463] Fix | Delete
_libnames = ['uuid']
[464] Fix | Delete
if not sys.platform.startswith('win'):
[465] Fix | Delete
_libnames.append('c')
[466] Fix | Delete
for libname in _libnames:
[467] Fix | Delete
try:
[468] Fix | Delete
lib = ctypes.CDLL(ctypes.util.find_library(libname))
[469] Fix | Delete
except:
[470] Fix | Delete
continue
[471] Fix | Delete
if hasattr(lib, 'uuid_generate_time'):
[472] Fix | Delete
_uuid_generate_time = lib.uuid_generate_time
[473] Fix | Delete
# The library that has uuid_generate_time should have md5 too.
[474] Fix | Delete
_uuid_generate_md5 = getattr(lib, 'uuid_generate_md5')
[475] Fix | Delete
break
[476] Fix | Delete
del _libnames
[477] Fix | Delete
[478] Fix | Delete
# The uuid_generate_* functions are broken on MacOS X 10.5, as noted
[479] Fix | Delete
# in issue #8621 the function generates the same sequence of values
[480] Fix | Delete
# in the parent process and all children created using fork (unless
[481] Fix | Delete
# those children use exec as well).
[482] Fix | Delete
#
[483] Fix | Delete
# Assume that the uuid_generate functions are broken from 10.5 onward,
[484] Fix | Delete
# the test can be adjusted when a later version is fixed.
[485] Fix | Delete
if sys.platform == 'darwin':
[486] Fix | Delete
import os
[487] Fix | Delete
if int(os.uname()[2].split('.')[0]) >= 9:
[488] Fix | Delete
_uuid_generate_time = None
[489] Fix | Delete
[490] Fix | Delete
# On Windows prior to 2000, UuidCreate gives a UUID containing the
[491] Fix | Delete
# hardware address. On Windows 2000 and later, UuidCreate makes a
[492] Fix | Delete
# random UUID and UuidCreateSequential gives a UUID containing the
[493] Fix | Delete
# hardware address. These routines are provided by the RPC runtime.
[494] Fix | Delete
# NOTE: at least on Tim's WinXP Pro SP2 desktop box, while the last
[495] Fix | Delete
# 6 bytes returned by UuidCreateSequential are fixed, they don't appear
[496] Fix | Delete
# to bear any relationship to the MAC address of any network device
[497] Fix | Delete
# on the box.
[498] Fix | Delete
try:
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function