1 This patch is for Python 3 compatibility. It has not been submitted upstream, |
1 This patch is for Python 3 compatibility. It has not been submitted upstream, |
2 as the community appears to have gone dormant. |
2 as the community appears to have gone dormant. |
3 |
3 |
4 --- pybonjour-1.1.1/pybonjour.py-orig 2013-02-13 04:39:03.391680773 -0600 |
4 --- pybonjour-1.1.1/pybonjour.py-orig 2013-02-13 04:39:03.391680773 -0600 |
5 +++ pybonjour-1.1.1/pybonjour.py 2013-02-13 04:39:15.452208372 -0600 |
5 +++ pybonjour-1.1.1/pybonjour.py 2013-02-13 04:39:15.452208372 -0600 |
|
6 @@ -63,1 +63,4 @@ |
|
7 +if sys.version[:3] > '3': |
|
8 + unicode = str |
|
9 + basestring = str |
|
10 |
6 @@ -804,7 +804,7 @@ def _create_function_bindings(): |
11 @@ -804,7 +804,7 @@ def _create_function_bindings(): |
7 } |
12 } |
8 |
13 |
9 |
14 |
10 - for name, (restype, errcheck, outparam, argtypes) in specs.iteritems(): |
15 - for name, (restype, errcheck, outparam, argtypes) in specs.iteritems(): |
11 + for name, (restype, errcheck, outparam, argtypes) in specs.items(): |
16 + for name, (restype, errcheck, outparam, argtypes) in specs.items(): |
12 prototype = _CFunc(restype, *argtypes) |
17 prototype = _CFunc(restype, *argtypes) |
13 |
18 |
14 paramflags = [1] * len(argtypes) |
19 paramflags = [1] * len(argtypes) |
|
20 @@ -848,14 +848,16 @@ |
|
21 |
|
22 def _string_to_length_and_void_p(string): |
|
23 if isinstance(string, TXTRecord): |
|
24 - string = str(string) |
|
25 + string = str(string).encode('utf-8') |
|
26 + elif isinstance(string, str): |
|
27 + string = string.encode('utf-8') |
|
28 void_p = ctypes.cast(ctypes.c_char_p(string), ctypes.c_void_p) |
|
29 return len(string), void_p |
|
30 |
|
31 |
|
32 def _length_and_void_p_to_string(length, void_p): |
|
33 char_p = ctypes.cast(void_p, ctypes.POINTER(ctypes.c_char)) |
|
34 - return ''.join(char_p[i] for i in xrange(length)) |
|
35 + return ''.join(char_p[i].decode('utf-8') for i in range(length)) |
|
36 |
|
37 |
|
38 |
|
39 @@ -1942,7 +1942,7 @@ def __init__(self, items={}, strict=True): |
|
40 self._names = [] |
|
41 self._items = {} |
|
42 |
|
43 - for name, value in items.iteritems(): |
|
44 + for name, value in items.items(): |
|
45 self[name] = value |
|
46 |
|
47 def __contains__(self, name): |
|
48 @@ -2023,8 +2023,8 @@ def __setitem__(self, name, value): |
|
49 |
|
50 if value is not None: |
|
51 - if isinstance(value, unicode): |
|
52 + if sys.version[:3] < '3' and isinstance(value, unicode): |
|
53 value = value.encode('utf-8') |
|
54 else: |
|
55 value = str(value) |
|
56 length += 1 + len(value) |
|
57 |