Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F69726760
parse_first_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
Wed, Jul 3, 04:53
Size
1 KB
Mime Type
text/x-python
Expires
Fri, Jul 5, 04:53 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
18747945
Attached To
R3600 invenio-infoscience
parse_first_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
ParseFirstParser
(
DecoratorBeforeEvalBaseExtensionParser
):
"""
Handle the ``@parse_first`` decorator.
.. code-block:: ini
author_aggregation:
derived:
@parse_first('creators', 'contributors')
self.get_list('creators') + self.get_list(contributors)
"""
__parsername__
=
'parse_first'
@classmethod
def
parse_element
(
cls
,
indent_stack
):
return
(
Keyword
(
"@parse_first"
)
.
suppress
()
+
Literal
(
'('
)
.
suppress
()
+
delimitedList
(
quotedString
.
setParseAction
(
removeQuotes
))
+
Literal
(
')'
)
.
suppress
()
)
.
setResultsName
(
"parse_first"
)
@classmethod
def
create_element
(
cls
,
rule
,
field_def
,
content
,
namespace
):
return
content
.
asList
()
@classmethod
def
evaluate
(
cls
,
reader
,
args
):
"""Try to parse ``args`` first and return always ``True``."""
map
(
reader
.
_unpack_rule
,
args
)
return
True
parser
=
ParseFirstParser
Event Timeline
Log In to Comment