/usr/lib/python2.7/dist-packages/pybtex/backends/__init__.py is in pybtex 0.20.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | # Copyright (c) 2006-2016 Andrey Golovizin
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import pybtex.io
from pybtex.plugin import Plugin
class BaseBackend(Plugin):
"""This is the base class for the backends. We encourage
you to implement as many of the symbols and tags as
possible when you create a new plugin.
symbols[u'ndash'] : Used to separate pages
symbols[u'newblock'] : Used to separate entries in the bibliography
symbols[u'nbsp'] : A non-breakable space
tags[u'em'] : emphasize text
tags[u'strong'] : emphasize text even more
tags[u'i'] : italicize text, not semantic
tags[u'b'] : embolden text, not semantic
tags[u'tt'] : typewrite text, not semantic
"""
RenderType = basestring #: the result of render and render_sequence
default_suffix = None #: the default suffix for an output file
def __init__(self, encoding=None):
self.encoding = encoding or pybtex.io.get_default_encoding()
def write_prologue(self):
pass
def write_epilogue(self):
pass
def format_str(self, str_):
"""Format the given string *str_*.
The default implementation simply returns the string ad verbatim.
Override this method for non-string backends.
"""
return str_
def format_tag(self, tag_name, text):
"""Format a tag with some text inside.
*tag_name* is a str, and *text* is a rendered Text object.
"""
raise NotImplementedError
def format_href(self, url, text):
"""Format a hyperlink with some text inside.
*url* is a str, and *text* is a rendered Text object.
"""
raise NotImplementedError
def format_protected(self, text):
"""Format a "protected" piece of text.
In LaTeX backend, it is formatted as a {braced group}.
Most other backends would just output the text as-is.
"""
return text
def render_sequence(self, rendered_list):
"""Render a sequence of rendered Text objects.
The default implementation simply concatenates
the strings in rendered_list.
Override this method for non-string backends.
"""
return "".join(rendered_list)
def write_entry(self, label, key, text):
raise NotImplementedError
def write_to_file(self, formatted_entries, filename):
with pybtex.io.open_unicode(filename, "w", self.encoding) as stream:
self.write_to_stream(formatted_entries, stream)
if hasattr(stream, 'getvalue'):
return stream.getvalue()
def write_to_stream(self, formatted_bibliography, stream):
self.output = stream.write
self.formatted_bibliography = formatted_bibliography
self.write_prologue()
for entry in formatted_bibliography:
self.write_entry(entry.key, entry.label, entry.text.render(self))
self.write_epilogue()
|