-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
874 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.. | ||
This file is part of Invenio. | ||
Copyright (C) 2016 CERN. | ||
Invenio is free software; you can redistribute it | ||
and/or modify it under the terms of the GNU General Public License as | ||
published by the Free Software Foundation; either version 2 of the | ||
License, or (at your option) any later version. | ||
|
||
Invenio is distributed in the hope that it will be | ||
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with Invenio; if not, write to the | ||
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | ||
MA 02111-1307, USA. | ||
|
||
In applying this license, CERN does not | ||
waive the privileges and immunities granted to it by virtue of its status | ||
as an Intergovernmental Organization or submit itself to any jurisdiction. | ||
|
||
|
||
API Docs | ||
======== | ||
|
||
.. automodule:: invenio_sequencegenerator.api | ||
:members: | ||
|
||
Models | ||
------ | ||
|
||
.. automodule:: invenio_sequencegenerator.models | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.. | ||
This file is part of Invenio. | ||
Copyright (C) 2016 CERN. | ||
Invenio is free software; you can redistribute it | ||
and/or modify it under the terms of the GNU General Public License as | ||
published by the Free Software Foundation; either version 2 of the | ||
License, or (at your option) any later version. | ||
|
||
Invenio is distributed in the hope that it will be | ||
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with Invenio; if not, write to the | ||
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | ||
MA 02111-1307, USA. | ||
|
||
In applying this license, CERN does not | ||
waive the privileges and immunities granted to it by virtue of its status | ||
as an Intergovernmental Organization or submit itself to any jurisdiction. | ||
|
||
|
||
Usage | ||
===== | ||
|
||
.. automodule:: invenio_sequencegenerator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of Invenio. | ||
# Copyright (C) 2016 CERN. | ||
# | ||
# Invenio is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License as | ||
# published by the Free Software Foundation; either version 2 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# Invenio is distributed in the hope that it will be useful, but | ||
# WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Invenio; if not, write to the Free Software Foundation, Inc., | ||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | ||
|
||
"""User-level API.""" | ||
|
||
from __future__ import absolute_import, print_function | ||
|
||
from invenio_sequencegenerator.models import SequenceDefinition | ||
|
||
|
||
class Sequence(object): | ||
"""Iterator for sequences.""" | ||
|
||
def __init__(self, sequence, **kwargs): | ||
"""Initialise sequence iterator, with or without keyword arguments.""" | ||
self.sequence = sequence | ||
self.kwargs = kwargs | ||
|
||
@staticmethod | ||
def create(id, template, start=0, step=1): | ||
"""Create a new sequence. | ||
:param id: the identifying name of the sequence | ||
:param template: the template string of the sequence | ||
:param start: the starting counter of the sequence | ||
:param step: the amount to increment at each generation | ||
:return: an iterator of this sequence | ||
""" | ||
return Sequence(SequenceDefinition(id, template, start, step)) | ||
|
||
@staticmethod | ||
def get(name): | ||
"""Get a new sequence. | ||
:param name: the identifying name of the sequence | ||
:return: an iterator of this sequence | ||
""" | ||
return Sequence(SequenceDefinition.get(name)) | ||
|
||
def instantiate(self, **kwargs): | ||
"""Fixed keyword arguments for the subsequent calls to `next`. | ||
:param kwargs The formatting arguments of the sequence's template. | ||
""" | ||
return Sequence(self.sequence, **kwargs) | ||
|
||
def next(self): # Python 2.x | ||
"""Get next.""" | ||
return self.sequence.next(**self.kwargs) | ||
|
||
def __next__(self): # Python 3.x | ||
"""Get next.""" | ||
return self.next() | ||
|
||
def reset(self, start=0): | ||
"""Reset enclosed sequence.""" | ||
return self.sequence.reset(start, **self.kwargs) | ||
|
||
def erase(self): | ||
"""Erase enclosed sequence.""" | ||
self.sequence.erase() | ||
|
||
def __iter__(self): | ||
"""Enable iterative capabilities.""" | ||
return self |
Oops, something went wrong.