From: achbed Date: Tue, 27 Jan 2015 05:41:59 +0000 (-0600) Subject: Removal of .keys() lookup where not needed (for speed) X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=f9a8592ff9aa7911f879be2675bfc18802f6daec;p=deefuzzer.git Removal of .keys() lookup where not needed (for speed) Removed the remaining calls to has_key() --- diff --git a/NEWS.rst b/NEWS.rst index 602c6d2..b3a7e4d 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -1,5 +1,5 @@ Old news -========= +======== See README.rst for last news. diff --git a/README.rst b/README.rst index ca679be..fcccbf4 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/deefuzzer/core.py b/deefuzzer/core.py index 954c290..ad84834 100644 --- a/deefuzzer/core.py +++ b/deefuzzer/core.py @@ -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 diff --git a/deefuzzer/station.py b/deefuzzer/station.py index 4e34f09..4cef3fa 100644 --- a/deefuzzer/station.py +++ b/deefuzzer/station.py @@ -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) diff --git a/deefuzzer/tools/logger.py b/deefuzzer/tools/logger.py index ae46e2b..e6b7107 100644 --- a/deefuzzer/tools/logger.py +++ b/deefuzzer/tools/logger.py @@ -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: diff --git a/deefuzzer/tools/mp3.py b/deefuzzer/tools/mp3.py index eb3f61e..f0e52c1 100644 --- a/deefuzzer/tools/mp3.py +++ b/deefuzzer/tools/mp3.py @@ -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) diff --git a/deefuzzer/tools/ogg.py b/deefuzzer/tools/ogg.py index 5fea49b..a970f8a 100644 --- a/deefuzzer/tools/ogg.py +++ b/deefuzzer/tools/ogg.py @@ -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)) diff --git a/deefuzzer/tools/xmltodict2.py b/deefuzzer/tools/xmltodict2.py index ad44f03..bf0ea46 100644 --- a/deefuzzer/tools/xmltodict2.py +++ b/deefuzzer/tools/xmltodict2.py @@ -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("<", "<") - if dct.has_key("code"): + if "code" in dct: if len(dct["code"].keys()): ret += "%s%s%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%s" % ("\t" * (level + 1), eol) - if dct.has_key("properties"): + if "properties" in dct: if len(dct["properties"].keys()): ret += "%s%s%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" % (currTab, prop, eol) ret += "%s%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