aboutsummaryrefslogtreecommitdiffstats
path: root/src/3rdparty/python/lib/python2.7/site-packages/mac_alias/bookmark.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/python/lib/python2.7/site-packages/mac_alias/bookmark.py')
-rw-r--r--src/3rdparty/python/lib/python2.7/site-packages/mac_alias/bookmark.py55
1 files changed, 38 insertions, 17 deletions
diff --git a/src/3rdparty/python/lib/python2.7/site-packages/mac_alias/bookmark.py b/src/3rdparty/python/lib/python2.7/site-packages/mac_alias/bookmark.py
index 41b9acf35..409ed8297 100644
--- a/src/3rdparty/python/lib/python2.7/site-packages/mac_alias/bookmark.py
+++ b/src/3rdparty/python/lib/python2.7/site-packages/mac_alias/bookmark.py
@@ -4,7 +4,7 @@
# for the old-fashioned alias format. The details of this format were
# reverse engineered; some things are still not entirely clear.
#
-from __future__ import unicode_literals
+from __future__ import unicode_literals, print_function
import struct
import uuid
@@ -13,11 +13,26 @@ import os
import sys
import pprint
-from urlparse import urljoin
+try:
+ from urlparse import urljoin
+except ImportError:
+ from urllib.parse import urljoin
if sys.platform == 'darwin':
from . import osx
+def iteritems(x):
+ return x.iteritems()
+
+try:
+ unicode
+except NameError:
+ unicode = str
+ long = int
+ xrange = range
+ def iteritems(x):
+ return x.items()
+
from .utils import *
BMK_DATA_TYPE_MASK = 0xffffff00
@@ -144,7 +159,7 @@ kBookmarkFileCreationDate = 0x1040
# = 0x1055 # ?
# = 0x1056 # ?
# = 0x1101 # ?
-# = 0x1102 # ?
+# = 0x1102 # ?
kBookmarkTOCPath = 0x2000 # A list of (TOC id, ?) pairs
kBookmarkVolumePath = 0x2002
kBookmarkVolumeURL = 0x2005
@@ -292,23 +307,20 @@ class Bookmark (object):
elif dtype == BMK_NULL:
return None
- print 'Unknown data type %08x' % typecode
+ print('Unknown data type %08x' % typecode)
return (typecode, databytes)
@classmethod
def from_bytes(cls, data):
"""Create a :class:`Bookmark` given byte data."""
- if isinstance(data, bytearray):
- data = bytes(data)
-
if len(data) < 16:
raise ValueError('Not a bookmark file (too short)')
magic,size,dummy,hdrsize = struct.unpack(b'<4sIII', data[0:16])
- if magic != 'book':
- raise ValueError('Not a bookmark file (bad magic)')
+ if magic != b'book':
+ raise ValueError('Not a bookmark file (bad magic) %r' % magic)
if hdrsize < 16:
raise ValueError('Not a bookmark file (header size too short)')
@@ -445,7 +457,7 @@ class Bookmark (object):
ioffset = offset + 8 + len(item) * 8
result = [struct.pack(b'<II', len(item) * 8, BMK_DICT | BMK_ST_ONE)]
enc = []
- for k,v in item.iteritems():
+ for k,v in iteritems(item):
result.append(struct.pack(b'<I', ioffset))
ioffset, ienc = cls._encode_item(k, ioffset)
enc.append(ienc)
@@ -479,8 +491,8 @@ class Bookmark (object):
for tid,toc in self.tocs:
entries = []
- for k,v in toc.iteritems():
- if isinstance(k, basestring):
+ for k,v in iteritems(toc):
+ if isinstance(k, (str, unicode)):
noffset = offset
voffset, enc = self._encode_item(k, offset)
result.append(enc)
@@ -496,7 +508,7 @@ class Bookmark (object):
# binary search to find data
entries.sort()
- tocs.append((tid, b''.join([struct.pack(b'<III',k,o,0)
+ tocs.append((tid, b''.join([struct.pack('<III',k,o,0)
for k,o in entries])))
first_toc_offset = offset
@@ -513,7 +525,7 @@ class Bookmark (object):
0xfffffffe,
tid,
next_offset,
- len(data) / 12))
+ len(data) // 12))
result.append(data)
offset += 20 + len(data)
@@ -536,7 +548,7 @@ class Bookmark (object):
# Find the filesystem
st = osx.statfs(path)
- vol_path = st.f_mntonname
+ vol_path = st.f_mntonname.decode('utf-8')
# Grab its attributes
attrs = [osx.ATTR_CMN_CRTIME,
@@ -583,6 +595,9 @@ class Bookmark (object):
foldername = os.path.basename(dirname)
+ print(repr(path))
+ print(repr(vol_path))
+
rel_path = os.path.relpath(path, vol_path)
# Build the path arrays
@@ -609,6 +624,12 @@ class Bookmark (object):
volprops = Data(struct.pack(b'<QQQ', 0x81 | kCFURLVolumeSupportsPersistentIDs,
0x13ef | kCFURLVolumeSupportsPersistentIDs, 0))
+ print(repr(name_path))
+ print(repr(cnid_path))
+ print(repr(fileprops))
+ print(repr(vol_path))
+ print(repr(vol_name))
+
toc = {
kBookmarkPath: name_path,
kBookmarkCNIDPath: cnid_path,
@@ -638,8 +659,8 @@ class Bookmark (object):
result = ['Bookmark([']
for tid,toc in self.tocs:
result.append('(0x%x, {\n' % tid)
- for k,v in toc.iteritems():
- if isinstance(k, basestring):
+ for k,v in iteritems(toc):
+ if isinstance(k, (str, unicode)):
kf = repr(k)
else:
kf = '0x%04x' % k