diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-07-15 16:02:55 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-07-15 16:02:55 +0200 |
commit | f8e0412210772db73786dcd4e0cf94479758194a (patch) | |
tree | c4d101709b2208eb1ac87e09572bab59c3d0b52e | |
parent | Added missing shebangs, removed unnecessary ones (diff) | |
download | pyload-f8e0412210772db73786dcd4e0cf94479758194a.tar.xz |
Improved uniqify method
-rw-r--r-- | module/PullEvents.py | 2 | ||||
-rw-r--r-- | module/utils.py | 20 |
2 files changed, 6 insertions, 16 deletions
diff --git a/module/PullEvents.py b/module/PullEvents.py index d1c885f26..3835a34ac 100644 --- a/module/PullEvents.py +++ b/module/PullEvents.py @@ -46,7 +46,7 @@ class PullManager: if not validUuid: self.newClient(uuid) events = [ReloadAllEvent("queue").toList(), ReloadAllEvent("collector").toList()] - return uniqify(events, repr) + return uniqify(events) def addEvent(self, event): for client in self.clients: diff --git a/module/utils.py b/module/utils.py index 424aeaf37..fa6b84095 100644 --- a/module/utils.py +++ b/module/utils.py @@ -136,21 +136,11 @@ def fs_bsize(path): return os.statvfs(path).f_bsize -def uniqify(seq, idfun=None): -# order preserving - if idfun is None: - def idfun(x): return x - seen = {} - result = [] - for item in seq: - marker = idfun(item) - # in old Python versions: - # if seen.has_key(marker) - # but in new ones: - if marker in seen: continue - seen[marker] = 1 - result.append(item) - return result +def uniqify(seq): #: Originally by Dave Kirby + """ removes duplicates from list, preserve order """ + seen = set() + seen_add = seen.add + return [x for x in seq if x not in seen and not seen_add(x)] def parseFileSize(string, unit=None): #returns bytes |