Browse Source

Py3: Update PyBonjour and PyStone

pull/1161/head
Safihre 8 years ago
parent
commit
15c2a7e9ef
  1. 10
      sabnzbd/utils/getperformance.py
  2. 29
      sabnzbd/utils/pybonjour.py

10
sabnzbd/utils/getperformance.py

@ -1,4 +1,5 @@
import platform, subprocess
from .pystone import pystones
def getcpu():
@ -39,15 +40,10 @@ def getcpu():
def getpystone():
value = None
for pystonemodule in ['test.pystone', 'pystone']:
try:
exec("from " + pystonemodule + " import pystones")
value = int(pystones(1000)[1])
break # import and calculation worked, so we're done. Get out of the for loop
return int(pystones(1000)[1])
except:
pass # ... the import went wrong, so continue in the for loop
return value
return None
if __name__ == '__main__':

29
sabnzbd/utils/pybonjour.py

@ -49,8 +49,9 @@ application callbacks) are always unicode instances.
"""
__author__ = 'Christopher Stawarz <cstawarz@gmail.com>'
__author__ = 'Christopher Stawarz <cstawarz@csail.mit.edu>'
__version__ = '1.1.1'
__revision__ = int('$Revision: 6125 $'.split()[1])
import ctypes
@ -305,10 +306,9 @@ class _utf8_char_p(ctypes.c_char_p):
@classmethod
def from_param(cls, obj):
if (obj is not None) and (not isinstance(obj, cls)):
if not isinstance(obj, str):
if not str(obj):
raise TypeError('parameter must be a string type instance')
if not isinstance(obj, str):
obj = str(obj)
obj = obj.encode('utf-8')
return ctypes.c_char_p.from_param(obj)
@ -803,7 +803,7 @@ def _create_function_bindings():
}
for name, (restype, errcheck, outparam, argtypes) in list(specs.items()):
for name, (restype, errcheck, outparam, argtypes) in specs.items():
prototype = _CFunc(restype, *argtypes)
paramflags = [1] * len(argtypes)
@ -854,7 +854,7 @@ def _string_to_length_and_void_p(string):
def _length_and_void_p_to_string(length, void_p):
char_p = ctypes.cast(void_p, ctypes.POINTER(ctypes.c_char))
return ''.join(char_p[i] for i in range(length))
return ''.join(char_p[i].decode('utf-8') for i in range(length))
@ -1105,6 +1105,16 @@ def DNSServiceRegister(
port = socket.htons(port)
# From here on txtRecord has to be a bytes type, so convert what
# we have:
if type(txtRecord) == TXTRecord:
txtRecord = str(txtRecord).encode('utf-8')
elif type(txtRecord) == str:
txtRecord = txtRecord.encode('utf-8')
else:
raise TypeError('txtRecord is unhandlable type: {type}'.format(
type=type(txtRecord)))
if not txtRecord:
txtLen, txtRecord = 1, '\0'
else:
@ -1941,7 +1951,7 @@ class TXTRecord(object):
self._names = []
self._items = {}
for name, value in list(items.items()):
for name, value in items.items():
self[name] = value
def __contains__(self, name):
@ -1957,7 +1967,7 @@ class TXTRecord(object):
'Return the number of name/value pairs'
return len(self._names)
def __bool__(self):
def __nonzero__(self):
'Return False if the record is empty, True otherwise'
return bool(self._items)
@ -2017,9 +2027,6 @@ class TXTRecord(object):
length = len(name)
if value is not None:
if isinstance(value, str):
value = value.encode('utf-8')
else:
value = str(value)
length += 1 + len(value)

Loading…
Cancel
Save