diff --git a/gc3libs/persistence/idfactory.py b/gc3libs/persistence/idfactory.py old mode 100644 new mode 100755 index 15bac2bf..0d192113 --- a/gc3libs/persistence/idfactory.py +++ b/gc3libs/persistence/idfactory.py @@ -2,7 +2,7 @@ # """ """ -# Copyright (C) 2011 S3IT, Zentrale Informatik, University of Zurich. All rights reserved. +# Copyright (C) 2011, 2018 University of Zurich. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by @@ -121,10 +121,7 @@ def __init__(self, prefix=None, next_id_fn=None, id_class=Id): (which is the one used by default). """ self._prefix = prefix - if next_id_fn is None: - self._next_id_fn = progressive_number - else: - self._next_id_fn = next_id_fn + self._next_id_fn = next_id_fn or progressive_number self._idclass = id_class def reserve(self, n): @@ -142,11 +139,8 @@ def new(self, obj): """ Return a new "unique identifier" instance (a string). """ - if self._prefix is None: - prefix = obj.__class__.__name__ - else: - prefix = self._prefix - if len(IdFactory._seqno_pool) > 0: + prefix = self._prefix or obj.__class__.__name__ + if IdFactory._seqno_pool: seqno = IdFactory._seqno_pool.pop() else: seqno = self._next_id_fn() diff --git a/gc3libs/persistence/sql.py b/gc3libs/persistence/sql.py index 8a0863ac..3d45850d 100755 --- a/gc3libs/persistence/sql.py +++ b/gc3libs/persistence/sql.py @@ -133,10 +133,7 @@ def __init__(self, url, table_name=None, idfactory=None, kv = {} # init static public args - if not idfactory: - self.idfactory = IdFactory(id_class=IntId) - else: - self.idfactory = idfactory + self.idfactory = idfactory or IdFactory(id_class=IntId) url_table_names = kv.get('table') if url_table_names: