mac-alias 2.0.2__tar.gz → 2.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.1
2
2
  Name: mac_alias
3
- Version: 2.0.2
3
+ Version: 2.0.5
4
4
  Summary: Generate/parse Mac OS Alias records from Python
5
5
  Home-page: http://alastairs-place.net/projects/mac_alias
6
6
  Author: Alastair Houghton
@@ -14,6 +14,11 @@ import sys
14
14
  if sys.platform == 'darwin':
15
15
  from . import osx
16
16
 
17
+ try:
18
+ long
19
+ except NameError:
20
+ long = int
21
+
17
22
  from .utils import *
18
23
 
19
24
  ALIAS_KIND_FILE = 0
@@ -30,6 +35,16 @@ ALIAS_EJECTABLE_DISK = 5
30
35
 
31
36
  ALIAS_NO_CNID = 0xffffffff
32
37
 
38
+ def encode_utf8(s):
39
+ if isinstance(s, bytes):
40
+ return s
41
+ return s.encode('utf-8')
42
+
43
+ def decode_utf8(s):
44
+ if isinstance(s, bytes):
45
+ return s.decode('utf-8')
46
+ return s
47
+
33
48
  class AppleShareInfo (object):
34
49
  def __init__(self, zone=None, server=None, user=None):
35
50
  #: The AppleShare zone
@@ -324,8 +339,7 @@ class Alias (object):
324
339
  if sys.platform != 'darwin':
325
340
  raise Exception('Not implemented (requires special support)')
326
341
 
327
- if not isinstance(path, bytes):
328
- path = path.encode('utf-8')
342
+ path = encode_utf8(path)
329
343
 
330
344
  a = Alias()
331
345
 
@@ -340,7 +354,7 @@ class Alias (object):
340
354
  volinfo = osx.getattrlist(vol_path, attrs, 0)
341
355
 
342
356
  vol_crtime = volinfo[0]
343
- vol_name = volinfo[1].encode('utf-8')
357
+ vol_name = encode_utf8(volinfo[1])
344
358
 
345
359
  # Also grab various attributes of the file
346
360
  attrs = [(osx.ATTR_CMN_OBJTYPE
@@ -417,8 +431,8 @@ class Alias (object):
417
431
  pos = b.tell()
418
432
  b.write(struct.pack(b'>4shh', self.appinfo, 0, self.version))
419
433
 
420
- carbon_volname = self.volume.name.replace(':','/').encode('utf-8')
421
- carbon_filename = self.target.filename.replace(':','/').encode('utf-8')
434
+ carbon_volname = encode_utf8(self.volume.name).replace(b':',b'/')
435
+ carbon_filename = encode_utf8(self.target.filename).replace(b':',b'/')
422
436
  voldate = (self.volume.creation_date - mac_epoch).total_seconds()
423
437
  crdate = (self.target.creation_date - mac_epoch).total_seconds()
424
438
 
@@ -426,13 +440,13 @@ class Alias (object):
426
440
  # (so doing so is ridiculous, and nothing could rely on it).
427
441
  b.write(struct.pack(b'>h28pI2shI64pII4s4shhI2s10s',
428
442
  self.target.kind,
429
- carbon_volname, voldate,
443
+ carbon_volname, int(voldate),
430
444
  self.volume.fs_type,
431
445
  self.volume.disk_type,
432
446
  self.target.folder_cnid,
433
447
  carbon_filename,
434
448
  self.target.cnid,
435
- crdate,
449
+ int(crdate),
436
450
  self.target.creator_code,
437
451
  self.target.type_code,
438
452
  self.target.levels_from,
@@ -443,8 +457,8 @@ class Alias (object):
443
457
 
444
458
  # Excuse the odd order; we're copying Finder
445
459
  if self.target.folder_name:
446
- carbon_foldername = self.target.folder_name.replace(b':',b'/')\
447
- .encode('utf-8')
460
+ carbon_foldername = encode_utf8(self.target.folder_name)\
461
+ .replace(b':',b'/')
448
462
  b.write(struct.pack(b'>hh', TAG_CARBON_FOLDER_NAME,
449
463
  len(carbon_foldername)))
450
464
  b.write(carbon_foldername)
@@ -465,7 +479,7 @@ class Alias (object):
465
479
  b.write(cnid_path)
466
480
 
467
481
  if self.target.carbon_path:
468
- carbon_path=self.target.carbon_path.encode('utf-8')
482
+ carbon_path=encode_utf8(self.target.carbon_path)
469
483
  b.write(struct.pack(b'>hh', TAG_CARBON_PATH,
470
484
  len(carbon_path)))
471
485
  b.write(carbon_path)
@@ -494,7 +508,7 @@ class Alias (object):
494
508
  b.write(b'\0')
495
509
 
496
510
  if self.volume.driver_name:
497
- driver_name = self.volume.driver_name.encode('utf-8')
511
+ driver_name = encode_utf8(self.volume.driver_name)
498
512
  b.write(struct.pack(b'>hh', TAG_DRIVER_NAME,
499
513
  len(driver_name)))
500
514
  b.write(driver_name)
@@ -515,20 +529,22 @@ class Alias (object):
515
529
  if len(self.volume.network_mount_info) & 1:
516
530
  b.write(b'\0')
517
531
 
518
- utf16 = self.target.filename.replace(':','/').encode('utf-16-be')
532
+ utf16 = decode_utf8(self.target.filename)\
533
+ .replace(':','/').encode('utf-16-be')
519
534
  b.write(struct.pack(b'>hhh', TAG_UNICODE_FILENAME,
520
535
  len(utf16) + 2,
521
536
  len(utf16) // 2))
522
537
  b.write(utf16)
523
538
 
524
- utf16 = self.volume.name.replace(':','/').encode('utf-16-be')
539
+ utf16 = decode_utf8(self.volume.name)\
540
+ .replace(':','/').encode('utf-16-be')
525
541
  b.write(struct.pack(b'>hhh', TAG_UNICODE_VOLUME_NAME,
526
542
  len(utf16) + 2,
527
543
  len(utf16) // 2))
528
544
  b.write(utf16)
529
545
 
530
546
  if self.target.posix_path:
531
- posix_path = self.target.posix_path.encode('utf-8')
547
+ posix_path = encode_utf8(self.target.posix_path)
532
548
  b.write(struct.pack(b'>hh', TAG_POSIX_PATH,
533
549
  len(posix_path)))
534
550
  b.write(posix_path)
@@ -536,7 +552,7 @@ class Alias (object):
536
552
  b.write(b'\0')
537
553
 
538
554
  if self.volume.posix_path:
539
- posix_path = self.volume.posix_path.encode('utf-8')
555
+ posix_path = encode_utf8(self.volume.posix_path)
540
556
  b.write(struct.pack(b'>hh', TAG_POSIX_PATH_TO_MOUNTPOINT,
541
557
  len(posix_path)))
542
558
  b.write(posix_path)
@@ -21,6 +21,18 @@ except ImportError:
21
21
  if sys.platform == 'darwin':
22
22
  from . import osx
23
23
 
24
+ def iteritems(x):
25
+ return x.iteritems()
26
+
27
+ try:
28
+ unicode
29
+ except NameError:
30
+ unicode = str
31
+ long = int
32
+ xrange = range
33
+ def iteritems(x):
34
+ return x.items()
35
+
24
36
  from .utils import *
25
37
 
26
38
  BMK_DATA_TYPE_MASK = 0xffffff00
@@ -307,8 +319,8 @@ class Bookmark (object):
307
319
 
308
320
  magic,size,dummy,hdrsize = struct.unpack(b'<4sIII', data[0:16])
309
321
 
310
- if magic != 'book':
311
- raise ValueError('Not a bookmark file (bad magic)')
322
+ if magic != b'book':
323
+ raise ValueError('Not a bookmark file (bad magic) %r' % magic)
312
324
 
313
325
  if hdrsize < 16:
314
326
  raise ValueError('Not a bookmark file (header size too short)')
@@ -445,7 +457,7 @@ class Bookmark (object):
445
457
  ioffset = offset + 8 + len(item) * 8
446
458
  result = [struct.pack(b'<II', len(item) * 8, BMK_DICT | BMK_ST_ONE)]
447
459
  enc = []
448
- for k,v in item.iteritems():
460
+ for k,v in iteritems(item):
449
461
  result.append(struct.pack(b'<I', ioffset))
450
462
  ioffset, ienc = cls._encode_item(k, ioffset)
451
463
  enc.append(ienc)
@@ -479,8 +491,8 @@ class Bookmark (object):
479
491
  for tid,toc in self.tocs:
480
492
  entries = []
481
493
 
482
- for k,v in toc.iteritems():
483
- if isinstance(k, basestring):
494
+ for k,v in iteritems(toc):
495
+ if isinstance(k, (str, unicode)):
484
496
  noffset = offset
485
497
  voffset, enc = self._encode_item(k, offset)
486
498
  result.append(enc)
@@ -496,7 +508,7 @@ class Bookmark (object):
496
508
  # binary search to find data
497
509
  entries.sort()
498
510
 
499
- tocs.append((tid, b''.join([struct.pack('<III',k,o,0)
511
+ tocs.append((tid, b''.join([struct.pack(b'<III',k,o,0)
500
512
  for k,o in entries])))
501
513
 
502
514
  first_toc_offset = offset
@@ -513,7 +525,7 @@ class Bookmark (object):
513
525
  0xfffffffe,
514
526
  tid,
515
527
  next_offset,
516
- len(data) / 12))
528
+ len(data) // 12))
517
529
  result.append(data)
518
530
 
519
531
  offset += 20 + len(data)
@@ -647,8 +659,8 @@ class Bookmark (object):
647
659
  result = ['Bookmark([']
648
660
  for tid,toc in self.tocs:
649
661
  result.append('(0x%x, {\n' % tid)
650
- for k,v in toc.iteritems():
651
- if isinstance(k, basestring):
662
+ for k,v in iteritems(toc):
663
+ if isinstance(k, (str, unicode)):
652
664
  kf = repr(k)
653
665
  else:
654
666
  kf = '0x%04x' % k
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.1
2
2
  Name: mac-alias
3
- Version: 2.0.2
3
+ Version: 2.0.5
4
4
  Summary: Generate/parse Mac OS Alias records from Python
5
5
  Home-page: http://alastairs-place.net/projects/mac_alias
6
6
  Author: Alastair Houghton
@@ -19,7 +19,7 @@ with open('README.rst', 'rb') as f:
19
19
  longdesc = f.read().decode('utf-8')
20
20
 
21
21
  setup(name='mac_alias',
22
- version='2.0.2',
22
+ version='2.0.5',
23
23
  description='Generate/parse Mac OS Alias records from Python',
24
24
  long_description=longdesc,
25
25
  author='Alastair Houghton',
File without changes
File without changes
File without changes
File without changes