Skip to content

Commit

Permalink
Compare with None should be done with 'is [not]', not equality operator.
Browse files Browse the repository at this point in the history
PEP 8 says:
  Comparisons to singletons like None should always be done with 'is' or 'is not', never the equality operators.
  • Loading branch information
jpopelka committed Aug 25, 2015
1 parent 91d108f commit 8dc784c
Show file tree
Hide file tree
Showing 42 changed files with 281 additions and 280 deletions.
2 changes: 1 addition & 1 deletion OpenPrintingRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __del__ (self):

def cancel (self):
debugprint ("%s: cancel()" % self)
if self._handle != None:
if self._handle is not None:
self.openprinting.cancelOperation (self._handle)
self._handle = None

Expand Down
22 changes: 11 additions & 11 deletions PhysicalDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _get_host_from_uri (self, uri):
if rest.startswith ("/net/"):
(rest, ipparam) = urllib.parse.splitquery (rest[5:])

if ipparam != None:
if ipparam is not None:
if ipparam.startswith("ip="):
hostport = ipparam[3:]
elif ipparam.startswith ("hostname="):
Expand All @@ -77,7 +77,7 @@ def _get_host_from_uri (self, uri):
return None, None
else:
(hostport, rest) = urllib.parse.splithost (rest)
if hostport == None:
if hostport is None:
return None, None

if hostport:
Expand All @@ -90,19 +90,19 @@ def add_device (self, device):
host, dnssdhost = self._get_host_from_uri (device.uri)
if (hasattr (device, 'address')):
host = device.address
if (hasattr (device, 'hostname') and dnssdhost == None):
if (hasattr (device, 'hostname') and dnssdhost is None):
dnssdhost = device.hostname
if (host == None and dnssdhost == None) or \
if (host is None and dnssdhost is None) or \
(host and self._network_host and \
host != self._network_host) or \
(dnssdhost and self.dnssd_hostname and \
dnssdhost != self.dnssd_hostname) or \
(host == None and self.dnssd_hostname == None) or \
(dnssdhost == None and self._network_host == None):
(host is None and self.dnssd_hostname is None) or \
(dnssdhost is None and self._network_host is None):
raise ValueError
else:
(mfg, mdl) = self._canonical_id (device)
if self.devices == None:
if self.devices is None:
self.mfg = mfg
self.mdl = mdl
self.mfg_lower = mfg.lower ()
Expand Down Expand Up @@ -157,11 +157,11 @@ def count_lower (s):
if dnssdhost:
self.dnssd_hostname = dnssdhost;

if (hasattr (device, 'address') and self._network_host == None):
if (hasattr (device, 'address') and self._network_host is None):
address = device.address
if address:
self._network_host = address
if (hasattr (device, 'hostname') and self.dnssd_hostname == None):
if (hasattr (device, 'hostname') and self.dnssd_hostname is None):
hostname = device.hostname
if hostname:
self.dnssd_hostname = hostname
Expand Down Expand Up @@ -275,10 +275,10 @@ def __lt__(self, other):
return False

if self._network_host != other._network_host:
if self._network_host == None:
if self._network_host is None:
return True

if other._network_host == None:
if other._network_host is None:
return False

return self._network_host < other._network_host
Expand Down
2 changes: 1 addition & 1 deletion applet.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def handle_dbus_signal (self, *args):
def check_for_jobs (self, *args):
debugprint ("checking for jobs")
if any_jobs ():
if self.timer != None:
if self.timer is not None:
GLib.source_remove (self.timer)

self.remove_signal_receiver ()
Expand Down
2 changes: 1 addition & 1 deletion asyncconn.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__ (self, reply_handler=None, error_handler=None,
self._destroyed = False

# Decide whether to use direct IPP or PolicyKit.
if host == None:
if host is None:
host = cups.getServer()
use_pk = ((host.startswith ('/') or host == 'localhost') and
os.getuid () != 0)
Expand Down
26 changes: 13 additions & 13 deletions asyncipp.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ def set_auth_info (self, password):
self._auth_queue.put (password)

def run (self):
if self.host == None:
if self.host is None:
self.host = cups.getServer ()
if self.port == None:
if self.port is None:
self.port = cups.getPort ()
if self._encryption == None:
if self._encryption is None:
self._encryption = cups.getEncryption ()

if self.user:
Expand All @@ -100,7 +100,7 @@ def run (self):
self.idle = self._queue.empty ()
item = self._queue.get ()
debugprint ("Next task: %s" % repr (item))
if item == None:
if item is None:
# Our signal to quit.
self._queue.task_done ()
break
Expand Down Expand Up @@ -176,15 +176,15 @@ def stop (self):
def _auth (self, prompt, conn=None, method=None, resource=None):
def prompt_auth (prompt):
Gdk.threads_enter ()
if conn == None:
if conn is None:
self._auth_handler (prompt, self._conn)
else:
self._auth_handler (prompt, self._conn, method, resource)

Gdk.threads_leave ()
return False

if self._auth_handler == None:
if self._auth_handler is None:
return ""

GLib.idle_add (prompt_auth, prompt)
Expand Down Expand Up @@ -349,7 +349,7 @@ def _destroy (self):
del self._client_error_handler

def error_handler (self, conn, exc):
if self._client_fn == None:
if self._client_fn is None:
# This is the initial "connection" operation, or a
# subsequent reconnection attempt.
debugprint ("Connection/reconnection failed")
Expand Down Expand Up @@ -433,7 +433,7 @@ def error_handler (self, conn, exc):

def auth_handler (self, prompt, conn, method=None, resource=None):
if self._auth_called == False:
if self._user == None:
if self._user is None:
self._user = cups.getUser()
if self._user:
host = conn.thread.host
Expand Down Expand Up @@ -479,15 +479,15 @@ def auth_handler (self, prompt, conn, method=None, resource=None):
if conn.semantic:
op = conn.semantic.current_operation ()

if op == None:
if op is None:
d = authconn.AuthDialog (parent=conn.parent)
else:
title = _("Authentication (%s)") % op
d = authconn.AuthDialog (title=title,
parent=conn.parent)

d.set_prompt ('')
if self._user == None:
if self._user is None:
self._user = cups.getUser()
d.set_auth_info (['', ''])
d.field_grab_focus ('username')
Expand Down Expand Up @@ -543,7 +543,7 @@ def _reconnect_reply (self, conn, result):
# so we've reconnected as that user. Alternatively, the
# connection has failed and we're retrying.
debugprint ("Connected as %s" % self._user)
if self._client_fn != None:
if self._client_fn is not None:
self.submit_task ()

def _reconnect_error (self, conn, exc):
Expand All @@ -556,7 +556,7 @@ def _reconnect_error (self, conn, exc):
if conn.semantic:
op = conn.semantic.current_operation ()

if op == None:
if op is None:
msg = _("CUPS server error")
else:
msg = _("CUPS server error (%s)") % op
Expand All @@ -567,7 +567,7 @@ def _reconnect_error (self, conn, exc):
buttons=Gtk.ButtonsType.NONE,
text=msg)

if self._client_fn == None and type (exc) == RuntimeError:
if self._client_fn is None and type (exc) == RuntimeError:
# This was a connection failure.
message = 'service-error-service-unavailable'
elif type (exc) == cups.IPPError:
Expand Down
6 changes: 3 additions & 3 deletions asyncpk1.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def __init__(self, reply_handler=None, error_handler=None,
self._system_bus = None

global _DevicesGet_uses_new_api
if _DevicesGet_uses_new_api == None and self._system_bus:
if _DevicesGet_uses_new_api is None and self._system_bus:
try:
obj = self._system_bus.get_object(CUPS_PK_NAME, CUPS_PK_PATH)
proxy = dbus.Interface (obj, dbus.INTROSPECTABLE_IFACE)
Expand Down Expand Up @@ -324,7 +324,7 @@ def _args_kwds_to_tuple (self, types, params, args, kwds):
del leftover_kwds["auth_handler"]

result = [True, reply_handler, error_handler, ()]
if self._system_bus == None:
if self._system_bus is None:
return result

tup = []
Expand Down Expand Up @@ -461,7 +461,7 @@ def _unpack_getDevices_reply (self, dbusdict):
else:
device_uri = result_str[keywithaffix]

if device_uri != None:
if device_uri is not None:
devices[device_uri] = device_dict

n += 1
Expand Down
16 changes: 8 additions & 8 deletions authconn.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__ (self, title=None, parent=None,
Gtk.STOCK_OK, Gtk.ResponseType.OK),
auth_info_required=None,
allow_remember=False):
if title == None:
if title is None:
title = _("Authentication")
if auth_info_required is None:
auth_info_required = ['username', 'password']
Expand Down Expand Up @@ -124,13 +124,13 @@ def __init__ (self):
self.creds = dict() # by (host,port)

def cache_auth_info (self, data, host=None, port=None):
if port == None:
if port is None:
port = 631

self.creds[(host,port)] = data

def lookup_auth_info (self, host=None, port=None):
if port == None:
if port is None:
port = 631

try:
Expand All @@ -139,7 +139,7 @@ def lookup_auth_info (self, host=None, port=None):
return None

def remove_auth_info (self, host=None, port=None):
if port == None:
if port is None:
port = 631

try:
Expand All @@ -152,11 +152,11 @@ def remove_auth_info (self, host=None, port=None):
class Connection:
def __init__ (self, parent=None, try_as_root=True, lock=False,
host=None, port=None, encryption=None):
if host != None:
if host is not None:
cups.setServer (host)
if port != None:
if port is not None:
cups.setPort (port)
if encryption != None:
if encryption is not None:
cups.setEncryption (encryption)

self._use_password = ''
Expand Down Expand Up @@ -341,7 +341,7 @@ def _perform_authentication (self):
self._passes += 1

creds = global_authinfocache.lookup_auth_info (host=self._server, port=self._port)
if creds != None:
if creds is not None:
if (creds[0] != 'root' or self._try_as_root):
(self._use_user, self._use_password) = creds
del creds
Expand Down
6 changes: 3 additions & 3 deletions check-device-ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"by temporarily disabling your firewall (or by allowing\n"
"incoming UDP packets on port 161).\n")

if devices == None:
if devices is None:
if not SPECIFIC_URI:
print("Examining connected devices")

Expand All @@ -87,7 +87,7 @@
sys.exit (1)

if SPECIFIC_URI:
if devices.get (SPECIFIC_URI) == None:
if devices.get (SPECIFIC_URI) is None:
devices = { SPECIFIC_URI:
{ 'device-make-and-model': '',
'device-id': ''} }
Expand Down Expand Up @@ -123,7 +123,7 @@
devs = []

def got_device (dev):
if dev != None:
if dev is not None:
devs.append (dev)

import probe_printer
Expand Down
12 changes: 6 additions & 6 deletions cupshelpers/cupshelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, name, connection, **kw):
self._ppd = None # load on demand

def __del__ (self):
if self._ppd != None:
if self._ppd is not None:
os.unlink(self._ppd)

def __repr__ (self):
Expand Down Expand Up @@ -210,7 +210,7 @@ def getPPD(self):
else:
raise

if result == None and self._ppd != None:
if result is None and self._ppd is not None:
result = cups.PPD (self._ppd)

return result
Expand Down Expand Up @@ -368,7 +368,7 @@ def jobsQueued(self, only_tests=False, limit=None):
attrs['job-name'] == 'Test Page')):
ret.append (id)

if limit != None and len (ret) == limit:
if limit is not None and len (ret) == limit:
break
return ret

Expand Down Expand Up @@ -402,7 +402,7 @@ def jobsPreserved(self, limit=None):
cups.IPP_JOB_PENDING) < cups.IPP_JOB_COMPLETED):
continue
ret.append (id)
if limit != None and len (ret) == limit:
if limit is not None and len (ret) == limit:
break

return ret
Expand Down Expand Up @@ -546,7 +546,7 @@ def __lt__(self, other):
"""
Compare devices by order of preference.
"""
if other == None:
if other is None:
return True

if self.is_class != other.is_class:
Expand Down Expand Up @@ -665,7 +665,7 @@ def activateNewPrinter(connection, name):
connection.acceptJobs (name)

# Set as the default if there is not already a default printer.
if connection.getDefault () == None:
if connection.getDefault () is None:
connection.setDefault (name)

def copyPPDOptions(ppd1, ppd2):
Expand Down
Loading

0 comments on commit 8dc784c

Please sign in to comment.