From 5d455ac3c43a2e967e179d497a40ee59fb3ff0c1 Mon Sep 17 00:00:00 2001 From: Wojtek Porczyk Date: Wed, 8 Feb 2017 15:20:15 +0100 Subject: [PATCH] misc pylint fixes related to qubesd --- ci/pylintrc | 2 +- qubes/libvirtaio.py | 20 +++++++++----------- qubes/tools/qubesd.py | 26 ++++++++++++-------------- qubes/utils.py | 8 ++++---- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/ci/pylintrc b/ci/pylintrc index 2bf4f092..f16a9aa3 100644 --- a/ci/pylintrc +++ b/ci/pylintrc @@ -72,7 +72,7 @@ variable-rgx=[a-z_][a-z0-9_]{2,30}$ inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ # 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-names=foo,bar,baz,toto,tutu,tata diff --git a/qubes/libvirtaio.py b/qubes/libvirtaio.py index b2077815..37dcf49a 100644 --- a/qubes/libvirtaio.py +++ b/qubes/libvirtaio.py @@ -1,17 +1,12 @@ #!/usr/bin/env python3 import asyncio -import collections import ctypes -import functools import itertools import logging -import signal import libvirt -import pdb - ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p ctypes.pythonapi.PyCapsule_GetPointer.argtypes = ( ctypes.py_object, ctypes.c_char_p) @@ -25,6 +20,7 @@ except AttributeError: class LibvirtAsyncIOEventImpl(object): class Callback(object): + # pylint: disable=too-few-public-methods _iden_counter = itertools.count() def __init__(self, impl, cb, opaque, *args, **kwargs): super().__init__(*args, **kwargs) @@ -42,7 +38,7 @@ class LibvirtAsyncIOEventImpl(object): self.impl.log.debug('callback %d close(), scheduling ff', self.iden) # 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( caps_ff, b'virFreeCallback')) @@ -53,6 +49,7 @@ class LibvirtAsyncIOEventImpl(object): class FDCallback(Callback): + # pylint: disable=too-few-public-methods def __init__(self, *args, descriptor, event, **kwargs): super().__init__(*args, **kwargs) self.descriptor = descriptor @@ -75,9 +72,9 @@ class LibvirtAsyncIOEventImpl(object): def timer(self): while True: try: - t = self.timeout * 1e-3 - self.impl.log.debug('sleeping %r', t) - yield from asyncio.sleep(t) + timeout = self.timeout * 1e-3 + self.impl.log.debug('sleeping %r', timeout) + yield from asyncio.sleep(timeout) except asyncio.CancelledError: self.impl.log.debug('timer %d cancelled', self.iden) break @@ -94,7 +91,7 @@ class LibvirtAsyncIOEventImpl(object): self.impl.log.debug('timer %r stop', self.iden) if self.task is None: return - self.task.cancel() + self.task.cancel() # pylint: disable=no-member self.task = None def close(self): @@ -128,7 +125,7 @@ class LibvirtAsyncIOEventImpl(object): super().__init__() self.loop = loop def __missing__(self, fd): - descriptor = self.Descriptor(loop, fd) + descriptor = self.Descriptor(self.loop, fd) self[fd] = descriptor return descriptor @@ -139,6 +136,7 @@ class LibvirtAsyncIOEventImpl(object): self.log = logging.getLogger(self.__class__.__name__) def register(self): + # pylint: disable=bad-whitespace libvirt.virEventRegisterImpl( self.add_handle, self.update_handle, self.remove_handle, self.add_timeout, self.update_timeout, self.remove_timeout) diff --git a/qubes/tools/qubesd.py b/qubes/tools/qubesd.py index d06efe05..d77ed1da 100644 --- a/qubes/tools/qubesd.py +++ b/qubes/tools/qubesd.py @@ -3,13 +3,9 @@ import asyncio import functools import io -import json -import operator import os import reprlib import signal -import socket -import sys import types import qubes @@ -26,6 +22,8 @@ class ProtocolRepr(reprlib.Repr): x = x.name return super().repr1(x, level) + # pylint: disable=invalid-name + def repr_str(self, x, level): '''Warning: this is incompatible with python 3 wrt to b'' ''' return "'{}'".format(''.join( @@ -79,17 +77,17 @@ class QubesMgmt(object): except AttributeError: raise ProtocolError( 'no such attribute: {!r}'.format( - untrusted_function_name)) + untrusted_func_name)) if not isinstance(untrusted_func, types.MethodType): raise ProtocolError( 'no such method: {!r}'.format( - untrusted_function_name)) + untrusted_func_name)) if getattr(untrusted_func, 'not_in_api', False): raise ProtocolError( 'attempt to call private method: {!r}'.format( - untrusted_function_name)) + untrusted_func_name)) self.execute = untrusted_func del untrusted_func_name @@ -141,18 +139,19 @@ class QubesMgmt(object): return 'default=True ' else: return 'default={} {}'.format( - str(dest.property_is_default(self.arg)), - self.repr(self.value)) + str(self.dest.property_is_default(self.arg)), + self.repr(value)) class QubesDaemonProtocol(asyncio.Protocol): buffer_size = 65536 def __init__(self, *args, app, **kwargs): - super().__init__() + super().__init__(*args, **kwargs) self.app = app self.untrusted_buffer = io.BytesIO() - self.untrusted_buffer_trusted_len = 0 + self.len_untrusted_buffer = 0 + self.transport = None def connection_made(self, transport): print('connection_made()') @@ -164,13 +163,12 @@ class QubesDaemonProtocol(asyncio.Protocol): def data_received(self, untrusted_data): print('data_received(untrusted_data={!r})'.format(untrusted_data)) - if self.untrusted_buffer_trusted_len + len(untrusted_data) \ - > self.buffer_size: + if self.len_untrusted_buffer + len(untrusted_data) > self.buffer_size: print(' request too long') self.transport.close() return - self.untrusted_buffer_trusted_len += \ + self.len_untrusted_buffer += \ self.untrusted_buffer.write(untrusted_data) def eof_received(self): diff --git a/qubes/utils.py b/qubes/utils.py index bfa5970f..39a78943 100644 --- a/qubes/utils.py +++ b/qubes/utils.py @@ -172,7 +172,7 @@ def systemd_notify(): return if nofity_socket.startswith('@'): nofity_socket = '\0' + nofity_socket[1:] - s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) - s.connect(nofity_socket) - s.sendall(b'READY=1') - s.close() + sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) + sock.connect(nofity_socket) + sock.sendall(b'READY=1') + sock.close()