]> git.parisson.com Git - deefuzzer.git/commitdiff
Removal of .keys() lookup where not needed (for speed)
authorachbed <github@achbed.org>
Tue, 27 Jan 2015 05:41:59 +0000 (23:41 -0600)
committerachbed <github@achbed.org>
Tue, 27 Jan 2015 05:41:59 +0000 (23:41 -0600)
Removed the remaining calls to has_key()

NEWS.rst
README.rst
deefuzzer/core.py
deefuzzer/station.py
deefuzzer/tools/logger.py
deefuzzer/tools/mp3.py
deefuzzer/tools/ogg.py
deefuzzer/tools/xmltodict2.py

index 602c6d2c98b8fe4290b0308b163104df84a0ff07..b3a7e4deebe8663dea0fe977780fe3535d2600de 100644 (file)
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -1,5 +1,5 @@
 Old news
-=========
+========
 
 See README.rst for last news.
 
index ca679bef87bddfb6c347190f98f9024bfd193462..fcccbf464cc953c0e222e0f7e07fd3202894be99 100644 (file)
@@ -20,7 +20,7 @@ live multimedia relays or personal home radios, with metadata management and coo
 
 
 Features
-=========
+========
 
  * MP3, OGG Vorbis file and live streaming over Internet
  * Full metadata encapsulation and management
index 954c29096718ec69278d7bfab772e9b7574ed53f..ad848344648a27da2120673da53ed21e5433f53a 100644 (file)
@@ -68,7 +68,7 @@ class DeeFuzzer(Thread):
         self.conf_file = conf_file
         self.conf = get_conf_dict(self.conf_file)
 
-        if 'deefuzzer' not in self.conf.keys():
+        if 'deefuzzer' not in self.conf:
             return
 
         # Get the log setting first (if possible)
@@ -145,12 +145,12 @@ class DeeFuzzer(Thread):
         """Scan a folder for subfolders containing media, and make stations from them all."""
 
         options = self.watchfolder
-        if 'folder' not in options.keys():
+        if 'folder' not in options:
             # We have no folder specified.  Bail.
             return
 
         if self.mainLoop:
-            if 'livecreation' not in options.keys():
+            if 'livecreation' not in options:
                 # We have no folder specified.  Bail.
                 return
 
@@ -166,9 +166,9 @@ class DeeFuzzer(Thread):
         # This makes the log file a lot more verbose.  Commented out since we report on new stations anyway.
         # self._info('Scanning folder ' + folder + ' for stations')
 
-        if 'infos' not in options.keys():
+        if 'infos' not in options:
             options['infos'] = {}
-        if 'short_name' not in options['infos'].keys():
+        if 'short_name' not in options['infos']:
             options['infos']['short_name'] = '[name]'
 
         files = os.listdir(folder)
@@ -181,9 +181,9 @@ class DeeFuzzer(Thread):
     def station_exists(self, name):
         try:
             for s in self.station_settings:
-                if 'infos' not in s.keys():
+                if 'infos' not in s:
                     continue
-                if 'short_name' not in s['infos'].keys():
+                if 'short_name' not in s['infos']:
                     continue
                 if s['infos']['short_name'] == name:
                     return True
@@ -204,7 +204,7 @@ class DeeFuzzer(Thread):
         for i in options.keys():
             if 'folder' not in i:
                 s[i] = replace_all(options[i], d)
-        if 'media' not in s.keys():
+        if 'media' not in s:
             s['media'] = {}
         s['media']['source'] = folder
         
@@ -241,7 +241,7 @@ class DeeFuzzer(Thread):
         self._info('Loading station config file ' + file)
         stationdef = get_conf_dict(file)
         if isinstance(stationdef, dict):
-            if 'station' in stationdef.keys():
+            if 'station' in stationdef:
                 if isinstance(stationdef['station'], dict):
                     self.add_station(stationdef['station'])
                 elif isinstance(stationdef['station'], list):
@@ -272,14 +272,14 @@ class DeeFuzzer(Thread):
             for i in range(0, ns_new):
                 name = ''
                 try:
-                    if 'station_name' in self.station_settings[i].keys():
+                    if 'station_name' in self.station_settings[i]:
                         name = self.station_settings[i]['station_name']
                     
-                    if 'retries' not in self.station_settings[i].keys():
+                    if 'retries' not in self.station_settings[i]:
                         self.station_settings[i]['retries'] = 0
                         
                     try:
-                        if 'station_instance' in self.station_settings[i].keys():
+                        if 'station_instance' in self.station_settings[i]:
                             # Check for station running here
                             if self.station_settings[i]['station_instance'].isAlive():
                                 # Station exists and is alive.  Don't recreate.
@@ -288,7 +288,7 @@ class DeeFuzzer(Thread):
                             
                             if self.maxretry >= 0 and self.station_settings[i]['retries'] <= self.maxretry:
                                 # Station passed the max retries count is will not be reloaded
-                                if 'station_stop_logged' not in self.station_settings[i].keys():
+                                if 'station_stop_logged' not in self.station_settings[i]:
                                     self._err('Station ' + name + ' is stopped and will not be restarted.')
                                     self.station_settings[i]['station_stop_logged'] = True
                                 continue
@@ -312,7 +312,7 @@ class DeeFuzzer(Thread):
 
                     if name == '':
                         name = 'Station ' + str(i)
-                        if 'info' in self.station_settings[i].keys():
+                        if 'info' in self.station_settings[i]:
                             if 'short_name' in self.station_settings[i]['infos']:
                                 name = self.station_settings[i]['infos']['short_name']
                                 y = 1
index 4e34f09ebd950a78926758ce89aca41e45a088fc..4cef3faee4bff0476375feb6adc8d50abd93167d 100644 (file)
@@ -109,15 +109,15 @@ class Station(Thread):
             self.base_directory = self.station['base_dir'].strip()
 
         # Media
-        if 'm3u' in self.station['media'].keys():
+        if 'm3u' in self.station['media']:
             if not self.station['media']['m3u'].strip() == '':
                 self.media_source = self._path_add_base(self.station['media']['m3u'])
 
-        if 'dir' in self.station['media'].keys():
+        if 'dir' in self.station['media']:
             if not self.station['media']['dir'].strip() == '':
                 self.media_source = self._path_add_base(self.station['media']['dir'])
 
-        if 'source' in self.station['media'].keys():
+        if 'source' in self.station['media']:
             if not self.station['media']['source'].strip() == '':
                 self.media_source = self._path_add_base(self.station['media']['source'])
 
@@ -129,16 +129,16 @@ class Station(Thread):
         self.voices = int(self.station['media']['voices'])
 
         # Server
-        if 'mountpoint' in self.station['server'].keys():
+        if 'mountpoint' in self.station['server']:
             self.mountpoint = self.station['server']['mountpoint']
-        elif 'short_name' in self.station['infos'].keys():
+        elif 'short_name' in self.station['infos']:
             self.mountpoint = self.station['infos']['short_name']
         else:
             self.mountpoint = 'default'
 
         self.short_name = self.mountpoint
 
-        if 'appendtype' in self.station['server'].keys():
+        if 'appendtype' in self.station['server']:
             self.appendtype = int(self.station['server']['appendtype'])
 
         if 'type' in self.station['server']:
@@ -730,7 +730,7 @@ class Station(Thread):
     def update_twitter_current(self):
         if not self.__twitter_should_update():
             return
-        artist_names = self.artist.split(' ')
+        artist_names = self.artist.split(' ')
         # artist_tags = ' #'.join(list(set(artist_names) - {'&', '-'}))
         message = '%s %s on #%s' % (self.prefix, self.song, self.short_name)
         tags = '#' + ' #'.join(self.twitter_tags)
index ae46e2bff497e5042753c77f65cf4e4c5ef32af9..e6b7107f70c5ab01942bfca3af1111885286951a 100644 (file)
@@ -38,10 +38,10 @@ class QueueLogger(Thread):
                 if not isinstance(msg, dict):
                     self.logger.write_error(str(msg))
                 else:
-                    if 'msg' not in msg.keys():
+                    if 'msg' not in msg:
                         continue
 
-                    if 'level' in msg.keys():
+                    if 'level' in msg:
                         if msg['level'] == 'info':
                             self.logger.write_info(msg['msg'])
                         else:
index eb3f61e29aa32d689745f9140290a6feeff4b1a8..f0e52c19ce635157aca8d16395bcea48dda6b6db 100644 (file)
@@ -133,7 +133,7 @@ class Mp3:
         '''
         # media_id3 = id3.ID3(self.media)
         # for tag in self.metadata.keys():
-            # if tag in self.dub2id3_dict.keys():
+            # if tag in self.dub2id3_dict:
                 # frame_text = self.dub2id3_dict[tag]
                 # value = self.metadata[tag]
                 # frame = mutagen.id3.Frames[frame_text](3,value)
index 5fea49b694f81e5f04bd334df42df53979ab3d9d..a970f8ae707567b5f33acaac0b4112db0ca9f1fa 100644 (file)
@@ -145,7 +145,7 @@ class Ogg:
         for tag in self.metadata.keys():
             value = clean_word(self.metadata[tag])
             args.append('-c %s="%s"' % (tag, value))
-            if tag in self.dub2args_dict.keys():
+            if tag in self.dub2args_dict:
                 arg = self.dub2args_dict[tag]
                 args.append('-c %s="%s"' % (arg, value))
 
index ad44f038d8d1e1ad83d18a0d50aac64f13ef13a8..bf0ea4683fb04f3591736c373f7260d3bf502dca 100644 (file)
@@ -55,7 +55,7 @@ class Xml2Obj:
             # This is code for the parent element
             self._inCode = True
             parent = self.nodeStack[-1]
-            if not parent.has_key("code"):
+            if "code" not in parent:
                 parent["code"] = {}
                 self._codeDict = parent["code"]
 
@@ -65,7 +65,7 @@ class Xml2Obj:
             self._propName = ""
             self._propData = ""
             parent = self.nodeStack[-1]
-            if not parent.has_key("properties"):
+            if "properties" not in parent:
                 parent["properties"] = {}
                 self._propDict = parent["properties"]
 
@@ -84,14 +84,14 @@ class Xml2Obj:
                 element = {"name": name.encode()}
                 if len(attributes) > 0:
                     for att in self.attsToSkip:
-                        if attributes.has_key(att):
+                        if att in attributes:
                             del attributes[att]
                     element["attributes"] = attributes
 
                 # Push element onto the stack and make it a child of parent
                 if len(self.nodeStack) > 0:
                     parent = self.nodeStack[-1]
-                    if not parent.has_key("children"):
+                    if "children" not in parent:
                         parent["children"] = []
                     parent["children"].append(element)
                 else:
@@ -141,7 +141,7 @@ class Xml2Obj:
                 self._propData += data
             else:
                 element = self.nodeStack[-1]
-                if not element.has_key("cdata"):
+                if "cdata" not in element:
                     element["cdata"] = ""
                 element["cdata"] += data
 
@@ -245,7 +245,7 @@ def dicttoxml(dct, level=0, header=None, linesep=None):
     att = ""
     ret = ""
 
-    if dct.has_key("attributes"):
+    if "attributes" in dct:
         for key, val in dct["attributes"].items():
             # Some keys are already handled.
             noEscape = key in ("sizerInfo",)
@@ -253,15 +253,15 @@ def dicttoxml(dct, level=0, header=None, linesep=None):
             att += " %s=%s" % (key, val)
     ret += "%s<%s%s" % ("\t" * level, dct["name"], att)
 
-    if (not dct.has_key("cdata") and not dct.has_key("children")
-            and not dct.has_key("code") and not dct.has_key("properties")):
+    if ("cdata" not in dct and "children" not in dct
+            and "code" not in dct and "properties" not in dct):
         ret += " />%s" % eol
     else:
         ret += ">"
-        if dct.has_key("cdata"):
+        if "cdata" in dct:
             ret += "%s" % dct["cdata"].replace("<", "&lt;")
 
-        if dct.has_key("code"):
+        if "code" in dct:
             if len(dct["code"].keys()):
                 ret += "%s%s<code>%s" % (eol, "\t" * (level + 1), eol)
                 methodTab = "\t" * (level + 2)
@@ -280,7 +280,7 @@ def dicttoxml(dct, level=0, header=None, linesep=None):
                     )
                 ret += "%s</code>%s" % ("\t" * (level + 1), eol)
 
-        if dct.has_key("properties"):
+        if "properties" in dct:
             if len(dct["properties"].keys()):
                 ret += "%s%s<properties>%s" % (eol, "\t" * (level + 1), eol)
                 currTab = "\t" * (level + 2)
@@ -292,10 +292,11 @@ def dicttoxml(dct, level=0, header=None, linesep=None):
                     ret += "%s</%s>%s" % (currTab, prop, eol)
                 ret += "%s</properties>%s" % ("\t" * (level + 1), eol)
 
-        if dct.has_key("children") and len(dct["children"]) > 0:
-            ret += eol
-            for child in dct["children"]:
-                ret += dicttoxml(child, level + 1, linesep=linesep)
+        if "children" in dct:
+            if len(dct["children"]) > 0:
+                ret += eol
+                for child in dct["children"]:
+                    ret += dicttoxml(child, level + 1, linesep=linesep)
         indnt = ""
         if ret.endswith(eol):
             # Indent the closing tag