text
stringlengths
0
828
""""""
self.display_num = 2
while os.path.isdir(XVFB_PATH % (self.display_num,)):
self.display_num += 1"
4237,"def comments(recid):
""""""Display comments.""""""
from invenio_access.local_config import VIEWRESTRCOLL
from invenio_access.mailcookie import \
mail_cookie_create_authorize_action
from .api import check_user_can_view_comments
auth_code, auth_msg = check_user_can_view_comments(current_user, recid)
if auth_code and current_user.is_guest:
cookie = mail_cookie_create_authorize_action(VIEWRESTRCOLL, {
'collection': g.collection})
url_args = {'action': cookie, 'ln': g.ln, 'referer': request.referrer}
flash(_(""Authorization failure""), 'error')
return redirect(url_for('webaccount.login', **url_args))
elif auth_code:
flash(auth_msg, 'error')
abort(401)
# FIXME check restricted discussion
comments = CmtRECORDCOMMENT.query.filter(db.and_(
CmtRECORDCOMMENT.id_bibrec == recid,
CmtRECORDCOMMENT.in_reply_to_id_cmtRECORDCOMMENT == 0,
CmtRECORDCOMMENT.star_score == 0
)).order_by(CmtRECORDCOMMENT.date_creation).all()
return render_template('comments/comments.html', comments=comments,
option='comments')"
4238,"def getattr(self, key, default=None, callback=None):
u""""""Getting the attribute of an element.
>>> xml = etree.Element('root')
>>> xml.text = 'text'
>>> Node(xml).getattr('text')
'text'
>>> Node(xml).getattr('text', callback=str.upper)
'TEXT'
>>> Node(xml).getattr('wrong_attr', default='default')
'default'
""""""
value = self._xml.text if key == 'text' else self._xml.get(key, default)
return callback(value) if callback else value"
4239,"def setattr(self, key, value):
u""""""Sets an attribute on a node.
>>> xml = etree.Element('root')
>>> Node(xml).setattr('text', 'text2')
>>> Node(xml).getattr('text')
'text2'
>>> Node(xml).setattr('attr', 'val')
>>> Node(xml).getattr('attr')
'val'
""""""
if key == 'text':
self._xml.text = str(value)
else:
self._xml.set(key, str(value))"
4240,"def get(self, default=None, callback=None):
u""""""Returns leaf's value.""""""
value = self._xml.text if self._xml.text else default
return callback(value) if callback else value"
4241,"def to_str(self, pretty_print=False, encoding=None, **kw):
u""""""Converts a node with all of it's children to a string.
Remaining arguments are passed to etree.tostring as is.
kwarg without_comments: bool because it works only in C14N flags:
'pretty print' and 'encoding' are ignored.
:param bool pretty_print: whether to format the output
:param str encoding: which encoding to use (ASCII by default)
:rtype: str
:returns: node's representation as a string
""""""
if kw.get('without_comments') and not kw.get('method'):
kw.pop('without_comments')
kw['method'] = 'c14n'
kw['with_comments'] = False
return etree.tostring(
self._xml,
pretty_print=pretty_print,
encoding=encoding,
**kw
)"
4242,"def iter_children(self, key=None):
u""""""Iterates over children.
:param key: A key for filtering children by tagname.
""""""
tag = None
if key:
tag = self._get_aliases().get(key)
if not tag:
raise KeyError(key)
for child in self._xml.iterchildren(tag=tag):
if len(child):