misc pylint fixes related to qubesd
This commit is contained in:
parent
0be3b1fbb1
commit
5d455ac3c4
@ -72,7 +72,7 @@ variable-rgx=[a-z_][a-z0-9_]{2,30}$
|
|||||||
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
|
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
|
||||||
|
|
||||||
# Good variable names which should always be accepted, separated by a comma
|
# Good variable names which should always be accepted, separated by a comma
|
||||||
good-names=e,i,j,k,m,p,ex,Run,_,log,vm,xc,xs,ip,fd,fh,rw,st,tb
|
good-names=e,i,j,k,m,p,ex,Run,_,log,vm,xc,xs,ip,fd,fh,rw,st,tb,cb,ff
|
||||||
|
|
||||||
# Bad variable names which should always be refused, separated by a comma
|
# Bad variable names which should always be refused, separated by a comma
|
||||||
bad-names=foo,bar,baz,toto,tutu,tata
|
bad-names=foo,bar,baz,toto,tutu,tata
|
||||||
|
@ -1,17 +1,12 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import collections
|
|
||||||
import ctypes
|
import ctypes
|
||||||
import functools
|
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
import signal
|
|
||||||
|
|
||||||
import libvirt
|
import libvirt
|
||||||
|
|
||||||
import pdb
|
|
||||||
|
|
||||||
ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p
|
ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p
|
||||||
ctypes.pythonapi.PyCapsule_GetPointer.argtypes = (
|
ctypes.pythonapi.PyCapsule_GetPointer.argtypes = (
|
||||||
ctypes.py_object, ctypes.c_char_p)
|
ctypes.py_object, ctypes.c_char_p)
|
||||||
@ -25,6 +20,7 @@ except AttributeError:
|
|||||||
|
|
||||||
class LibvirtAsyncIOEventImpl(object):
|
class LibvirtAsyncIOEventImpl(object):
|
||||||
class Callback(object):
|
class Callback(object):
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
_iden_counter = itertools.count()
|
_iden_counter = itertools.count()
|
||||||
def __init__(self, impl, cb, opaque, *args, **kwargs):
|
def __init__(self, impl, cb, opaque, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
@ -42,7 +38,7 @@ class LibvirtAsyncIOEventImpl(object):
|
|||||||
self.impl.log.debug('callback %d close(), scheduling ff', self.iden)
|
self.impl.log.debug('callback %d close(), scheduling ff', self.iden)
|
||||||
|
|
||||||
# Now this is cheating but we have no better option.
|
# Now this is cheating but we have no better option.
|
||||||
caps_cb, caps_opaque, caps_ff = self.opaque
|
dummy, caps_opaque, caps_ff = self.opaque
|
||||||
ff = virFreeCallback(ctypes.pythonapi.PyCapsule_GetPointer(
|
ff = virFreeCallback(ctypes.pythonapi.PyCapsule_GetPointer(
|
||||||
caps_ff, b'virFreeCallback'))
|
caps_ff, b'virFreeCallback'))
|
||||||
|
|
||||||
@ -53,6 +49,7 @@ class LibvirtAsyncIOEventImpl(object):
|
|||||||
|
|
||||||
|
|
||||||
class FDCallback(Callback):
|
class FDCallback(Callback):
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
def __init__(self, *args, descriptor, event, **kwargs):
|
def __init__(self, *args, descriptor, event, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.descriptor = descriptor
|
self.descriptor = descriptor
|
||||||
@ -75,9 +72,9 @@ class LibvirtAsyncIOEventImpl(object):
|
|||||||
def timer(self):
|
def timer(self):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
t = self.timeout * 1e-3
|
timeout = self.timeout * 1e-3
|
||||||
self.impl.log.debug('sleeping %r', t)
|
self.impl.log.debug('sleeping %r', timeout)
|
||||||
yield from asyncio.sleep(t)
|
yield from asyncio.sleep(timeout)
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
self.impl.log.debug('timer %d cancelled', self.iden)
|
self.impl.log.debug('timer %d cancelled', self.iden)
|
||||||
break
|
break
|
||||||
@ -94,7 +91,7 @@ class LibvirtAsyncIOEventImpl(object):
|
|||||||
self.impl.log.debug('timer %r stop', self.iden)
|
self.impl.log.debug('timer %r stop', self.iden)
|
||||||
if self.task is None:
|
if self.task is None:
|
||||||
return
|
return
|
||||||
self.task.cancel()
|
self.task.cancel() # pylint: disable=no-member
|
||||||
self.task = None
|
self.task = None
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
@ -128,7 +125,7 @@ class LibvirtAsyncIOEventImpl(object):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.loop = loop
|
self.loop = loop
|
||||||
def __missing__(self, fd):
|
def __missing__(self, fd):
|
||||||
descriptor = self.Descriptor(loop, fd)
|
descriptor = self.Descriptor(self.loop, fd)
|
||||||
self[fd] = descriptor
|
self[fd] = descriptor
|
||||||
return descriptor
|
return descriptor
|
||||||
|
|
||||||
@ -139,6 +136,7 @@ class LibvirtAsyncIOEventImpl(object):
|
|||||||
self.log = logging.getLogger(self.__class__.__name__)
|
self.log = logging.getLogger(self.__class__.__name__)
|
||||||
|
|
||||||
def register(self):
|
def register(self):
|
||||||
|
# pylint: disable=bad-whitespace
|
||||||
libvirt.virEventRegisterImpl(
|
libvirt.virEventRegisterImpl(
|
||||||
self.add_handle, self.update_handle, self.remove_handle,
|
self.add_handle, self.update_handle, self.remove_handle,
|
||||||
self.add_timeout, self.update_timeout, self.remove_timeout)
|
self.add_timeout, self.update_timeout, self.remove_timeout)
|
||||||
|
@ -3,13 +3,9 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import functools
|
import functools
|
||||||
import io
|
import io
|
||||||
import json
|
|
||||||
import operator
|
|
||||||
import os
|
import os
|
||||||
import reprlib
|
import reprlib
|
||||||
import signal
|
import signal
|
||||||
import socket
|
|
||||||
import sys
|
|
||||||
import types
|
import types
|
||||||
|
|
||||||
import qubes
|
import qubes
|
||||||
@ -26,6 +22,8 @@ class ProtocolRepr(reprlib.Repr):
|
|||||||
x = x.name
|
x = x.name
|
||||||
return super().repr1(x, level)
|
return super().repr1(x, level)
|
||||||
|
|
||||||
|
# pylint: disable=invalid-name
|
||||||
|
|
||||||
def repr_str(self, x, level):
|
def repr_str(self, x, level):
|
||||||
'''Warning: this is incompatible with python 3 wrt to b'' '''
|
'''Warning: this is incompatible with python 3 wrt to b'' '''
|
||||||
return "'{}'".format(''.join(
|
return "'{}'".format(''.join(
|
||||||
@ -79,17 +77,17 @@ class QubesMgmt(object):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise ProtocolError(
|
raise ProtocolError(
|
||||||
'no such attribute: {!r}'.format(
|
'no such attribute: {!r}'.format(
|
||||||
untrusted_function_name))
|
untrusted_func_name))
|
||||||
|
|
||||||
if not isinstance(untrusted_func, types.MethodType):
|
if not isinstance(untrusted_func, types.MethodType):
|
||||||
raise ProtocolError(
|
raise ProtocolError(
|
||||||
'no such method: {!r}'.format(
|
'no such method: {!r}'.format(
|
||||||
untrusted_function_name))
|
untrusted_func_name))
|
||||||
|
|
||||||
if getattr(untrusted_func, 'not_in_api', False):
|
if getattr(untrusted_func, 'not_in_api', False):
|
||||||
raise ProtocolError(
|
raise ProtocolError(
|
||||||
'attempt to call private method: {!r}'.format(
|
'attempt to call private method: {!r}'.format(
|
||||||
untrusted_function_name))
|
untrusted_func_name))
|
||||||
|
|
||||||
self.execute = untrusted_func
|
self.execute = untrusted_func
|
||||||
del untrusted_func_name
|
del untrusted_func_name
|
||||||
@ -141,18 +139,19 @@ class QubesMgmt(object):
|
|||||||
return 'default=True '
|
return 'default=True '
|
||||||
else:
|
else:
|
||||||
return 'default={} {}'.format(
|
return 'default={} {}'.format(
|
||||||
str(dest.property_is_default(self.arg)),
|
str(self.dest.property_is_default(self.arg)),
|
||||||
self.repr(self.value))
|
self.repr(value))
|
||||||
|
|
||||||
|
|
||||||
class QubesDaemonProtocol(asyncio.Protocol):
|
class QubesDaemonProtocol(asyncio.Protocol):
|
||||||
buffer_size = 65536
|
buffer_size = 65536
|
||||||
|
|
||||||
def __init__(self, *args, app, **kwargs):
|
def __init__(self, *args, app, **kwargs):
|
||||||
super().__init__()
|
super().__init__(*args, **kwargs)
|
||||||
self.app = app
|
self.app = app
|
||||||
self.untrusted_buffer = io.BytesIO()
|
self.untrusted_buffer = io.BytesIO()
|
||||||
self.untrusted_buffer_trusted_len = 0
|
self.len_untrusted_buffer = 0
|
||||||
|
self.transport = None
|
||||||
|
|
||||||
def connection_made(self, transport):
|
def connection_made(self, transport):
|
||||||
print('connection_made()')
|
print('connection_made()')
|
||||||
@ -164,13 +163,12 @@ class QubesDaemonProtocol(asyncio.Protocol):
|
|||||||
|
|
||||||
def data_received(self, untrusted_data):
|
def data_received(self, untrusted_data):
|
||||||
print('data_received(untrusted_data={!r})'.format(untrusted_data))
|
print('data_received(untrusted_data={!r})'.format(untrusted_data))
|
||||||
if self.untrusted_buffer_trusted_len + len(untrusted_data) \
|
if self.len_untrusted_buffer + len(untrusted_data) > self.buffer_size:
|
||||||
> self.buffer_size:
|
|
||||||
print(' request too long')
|
print(' request too long')
|
||||||
self.transport.close()
|
self.transport.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
self.untrusted_buffer_trusted_len += \
|
self.len_untrusted_buffer += \
|
||||||
self.untrusted_buffer.write(untrusted_data)
|
self.untrusted_buffer.write(untrusted_data)
|
||||||
|
|
||||||
def eof_received(self):
|
def eof_received(self):
|
||||||
|
@ -172,7 +172,7 @@ def systemd_notify():
|
|||||||
return
|
return
|
||||||
if nofity_socket.startswith('@'):
|
if nofity_socket.startswith('@'):
|
||||||
nofity_socket = '\0' + nofity_socket[1:]
|
nofity_socket = '\0' + nofity_socket[1:]
|
||||||
s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
||||||
s.connect(nofity_socket)
|
sock.connect(nofity_socket)
|
||||||
s.sendall(b'READY=1')
|
sock.sendall(b'READY=1')
|
||||||
s.close()
|
sock.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user