Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102579443
depends_on_parser.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Feb 22, 04:59
Size
2 KB
Mime Type
text/x-python
Expires
Mon, Feb 24, 04:59 (1 d, 7 h)
Engine
blob
Format
Raw Data
Handle
24363488
Attached To
R3600 invenio-infoscience
depends_on_parser.py
View Options
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2014 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.
from
pyparsing
import
Keyword
,
Literal
,
delimitedList
,
quotedString
,
\
removeQuotes
from
invenio.modules.jsonalchemy.parser
import
\
DecoratorBeforeEvalBaseExtensionParser
class
DependsOnParser
(
DecoratorBeforeEvalBaseExtensionParser
):
"""
Handles the @depends_on decorator::
authors:
derived:
@depends_on('creators', 'contributors')
self.get_list('creators') + self.get_list(contributors)
"""
__parsername__
=
'depends_on'
@classmethod
def
parse_element
(
cls
,
indent_stack
):
return
(
Keyword
(
"@depends_on"
)
.
suppress
()
+
\
Literal
(
'('
)
.
suppress
()
+
delimitedList
(
quotedString
.
setParseAction
(
removeQuotes
))
+
Literal
(
')'
)
.
suppress
()
)
.
setResultsName
(
"depends_on"
)
@classmethod
def
create_element
(
cls
,
rule
,
field_def
,
content
,
namespace
):
"""Just returns the list with the field names"""
return
content
.
asList
()
@classmethod
def
evaluate
(
cls
,
reader
,
args
):
"""
Tries to apply the rules for each field, if it fails on one of them
returns False
"""
for
key
in
args
:
if
key
in
reader
.
_json
:
continue
if
not
reader
.
_unpack_rule
(
key
):
return
False
return
True
parser
=
DependsOnParser
Event Timeline
Log In to Comment