Skip to content

Commit

Permalink
gc3libs.persistence.sql: Try to use shorter idioms for default values.
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardomurri committed Apr 18, 2018
1 parent 2e85ba8 commit 93203c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
14 changes: 4 additions & 10 deletions gc3libs/persistence/idfactory.py 100644 → 100755
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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()
Expand Down
5 changes: 1 addition & 4 deletions gc3libs/persistence/sql.py
Expand Up @@ -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:
Expand Down

0 comments on commit 93203c9

Please sign in to comment.