|
1 | | -""" |
2 | | -`BibTeX <http://en.wikipedia.org/wiki/BibTeX>`_ is a bibliographic data file format. |
3 | | -
|
4 | | -The :mod:`bibtexparser` module can parse BibTeX files and write them. The API is similar to the |
5 | | -:mod:`json` module. The parsed data is returned as a simple :class:`BibDatabase` object with the main attribute being |
6 | | -:attr:`entries` representing bibliographic sources such as books and journal articles. |
7 | | -
|
8 | | -The following functions provide a quick and basic way to manipulate a BibTeX file. |
9 | | -More advanced features are also available in this module. |
10 | | -
|
11 | | -Parsing a file is as simple as:: |
12 | | -
|
13 | | - import bibtexparser |
14 | | - with open('bibtex.bib') as bibtex_file: |
15 | | - bibtex_database = bibtexparser.load(bibtex_file) |
16 | | -
|
17 | | -And writing:: |
18 | | -
|
19 | | - import bibtexparser |
20 | | - with open('bibtex.bib', 'w') as bibtex_file: |
21 | | - bibtexparser.dump(bibtex_database, bibtex_file) |
22 | | -
|
23 | | -""" |
24 | | -__all__ = [ |
25 | | - 'loads', 'load', 'dumps', 'dump', 'bibdatabase', |
26 | | - 'bparser', 'bwriter', 'bibtexexpression', 'latexenc', 'customization', |
27 | | -] |
28 | | -__version__ = '1.4.2' |
29 | | - |
30 | | -from . import bibdatabase, bibtexexpression, bparser, bwriter, latexenc, customization |
31 | | - |
32 | | - |
33 | | -def loads(bibtex_str, parser=None): |
34 | | - """ |
35 | | - Load :class:`BibDatabase` object from a string |
36 | | -
|
37 | | - :param bibtex_str: input BibTeX string to be parsed |
38 | | - :type bibtex_str: str or unicode |
39 | | - :param parser: custom parser to use (optional) |
40 | | - :type parser: BibTexParser |
41 | | - :returns: bibliographic database object |
42 | | - :rtype: BibDatabase |
43 | | - """ |
44 | | - if parser is None: |
45 | | - parser = bparser.BibTexParser() |
46 | | - return parser.parse(bibtex_str) |
47 | | - |
48 | | - |
49 | | -def load(bibtex_file, parser=None): |
50 | | - """ |
51 | | - Load :class:`BibDatabase` object from a file |
52 | | -
|
53 | | - :param bibtex_file: input file to be parsed |
54 | | - :type bibtex_file: file |
55 | | - :param parser: custom parser to use (optional) |
56 | | - :type parser: BibTexParser |
57 | | - :returns: bibliographic database object |
58 | | - :rtype: BibDatabase |
59 | | -
|
60 | | - Example:: |
61 | | -
|
62 | | - import bibtexparser |
63 | | - with open('bibtex.bib') as bibtex_file: |
64 | | - bibtex_database = bibtexparser.load(bibtex_file) |
65 | | -
|
66 | | - """ |
67 | | - if parser is None: |
68 | | - parser = bparser.BibTexParser() |
69 | | - return parser.parse_file(bibtex_file) |
70 | | - |
71 | | - |
72 | | -def dumps(bib_database, writer=None): |
73 | | - """ |
74 | | - Dump :class:`BibDatabase` object to a BibTeX string |
75 | | -
|
76 | | - :param bib_database: bibliographic database object |
77 | | - :type bib_database: BibDatabase |
78 | | - :param writer: custom writer to use (optional) |
79 | | - :type writer: BibTexWriter |
80 | | - :returns: BibTeX string |
81 | | - :rtype: unicode |
82 | | - """ |
83 | | - if writer is None: |
84 | | - writer = bwriter.BibTexWriter() |
85 | | - return writer.write(bib_database) |
86 | | - |
87 | | - |
88 | | -def dump(bib_database, bibtex_file, writer=None): |
89 | | - """ |
90 | | - Dump :class:`BibDatabase` object as a BibTeX text file |
91 | | -
|
92 | | - :param bib_database: bibliographic database object |
93 | | - :type bib_database: BibDatabase |
94 | | - :param bibtex_file: file to write to |
95 | | - :type bibtex_file: file |
96 | | - :param writer: custom writer to use (optional) |
97 | | - :type writer: BibTexWriter |
98 | | -
|
99 | | - Example:: |
100 | | -
|
101 | | - import bibtexparser |
102 | | - with open('bibtex.bib', 'w') as bibtex_file: |
103 | | - bibtexparser.dump(bibtex_database, bibtex_file) |
104 | | -
|
105 | | - """ |
106 | | - if writer is None: |
107 | | - writer = bwriter.BibTexWriter() |
108 | | - bibtex_file.write(writer.write(bib_database)) |
| 1 | +""" |
| 2 | +`BibTeX <http://en.wikipedia.org/wiki/BibTeX>`_ is a bibliographic data file format. |
| 3 | +
|
| 4 | +The :mod:`bibtexparser` module can parse BibTeX files and write them. The API is similar to the |
| 5 | +:mod:`json` module. The parsed data is returned as a simple :class:`BibDatabase` object with the main attribute being |
| 6 | +:attr:`entries` representing bibliographic sources such as books and journal articles. |
| 7 | +
|
| 8 | +The following functions provide a quick and basic way to manipulate a BibTeX file. |
| 9 | +More advanced features are also available in this module. |
| 10 | +
|
| 11 | +Parsing a file is as simple as:: |
| 12 | +
|
| 13 | + import bibtexparser |
| 14 | + with open('bibtex.bib') as bibtex_file: |
| 15 | + bibtex_database = bibtexparser.load(bibtex_file) |
| 16 | +
|
| 17 | +And writing:: |
| 18 | +
|
| 19 | + import bibtexparser |
| 20 | + with open('bibtex.bib', 'w') as bibtex_file: |
| 21 | + bibtexparser.dump(bibtex_database, bibtex_file) |
| 22 | +
|
| 23 | +""" |
| 24 | +__all__ = [ |
| 25 | + 'loads', 'load', 'dumps', 'dump', 'bibdatabase', |
| 26 | + 'bparser', 'bwriter', 'bibtexexpression', 'latexenc', 'customization', |
| 27 | +] |
| 28 | +__version__ = '1.4.3' |
| 29 | + |
| 30 | +from . import bibdatabase, bibtexexpression, bparser, bwriter, latexenc, customization |
| 31 | + |
| 32 | + |
| 33 | +def loads(bibtex_str, parser=None): |
| 34 | + """ |
| 35 | + Load :class:`BibDatabase` object from a string |
| 36 | +
|
| 37 | + :param bibtex_str: input BibTeX string to be parsed |
| 38 | + :type bibtex_str: str or unicode |
| 39 | + :param parser: custom parser to use (optional) |
| 40 | + :type parser: BibTexParser |
| 41 | + :returns: bibliographic database object |
| 42 | + :rtype: BibDatabase |
| 43 | + """ |
| 44 | + if parser is None: |
| 45 | + parser = bparser.BibTexParser() |
| 46 | + return parser.parse(bibtex_str) |
| 47 | + |
| 48 | + |
| 49 | +def load(bibtex_file, parser=None): |
| 50 | + """ |
| 51 | + Load :class:`BibDatabase` object from a file |
| 52 | +
|
| 53 | + :param bibtex_file: input file to be parsed |
| 54 | + :type bibtex_file: file |
| 55 | + :param parser: custom parser to use (optional) |
| 56 | + :type parser: BibTexParser |
| 57 | + :returns: bibliographic database object |
| 58 | + :rtype: BibDatabase |
| 59 | +
|
| 60 | + Example:: |
| 61 | +
|
| 62 | + import bibtexparser |
| 63 | + with open('bibtex.bib') as bibtex_file: |
| 64 | + bibtex_database = bibtexparser.load(bibtex_file) |
| 65 | +
|
| 66 | + """ |
| 67 | + if parser is None: |
| 68 | + parser = bparser.BibTexParser() |
| 69 | + return parser.parse_file(bibtex_file) |
| 70 | + |
| 71 | + |
| 72 | +def dumps(bib_database, writer=None): |
| 73 | + """ |
| 74 | + Dump :class:`BibDatabase` object to a BibTeX string |
| 75 | +
|
| 76 | + :param bib_database: bibliographic database object |
| 77 | + :type bib_database: BibDatabase |
| 78 | + :param writer: custom writer to use (optional) |
| 79 | + :type writer: BibTexWriter |
| 80 | + :returns: BibTeX string |
| 81 | + :rtype: unicode |
| 82 | + """ |
| 83 | + if writer is None: |
| 84 | + writer = bwriter.BibTexWriter() |
| 85 | + return writer.write(bib_database) |
| 86 | + |
| 87 | + |
| 88 | +def dump(bib_database, bibtex_file, writer=None): |
| 89 | + """ |
| 90 | + Dump :class:`BibDatabase` object as a BibTeX text file |
| 91 | +
|
| 92 | + :param bib_database: bibliographic database object |
| 93 | + :type bib_database: BibDatabase |
| 94 | + :param bibtex_file: file to write to |
| 95 | + :type bibtex_file: file |
| 96 | + :param writer: custom writer to use (optional) |
| 97 | + :type writer: BibTexWriter |
| 98 | +
|
| 99 | + Example:: |
| 100 | +
|
| 101 | + import bibtexparser |
| 102 | + with open('bibtex.bib', 'w') as bibtex_file: |
| 103 | + bibtexparser.dump(bibtex_database, bibtex_file) |
| 104 | +
|
| 105 | + """ |
| 106 | + if writer is None: |
| 107 | + writer = bwriter.BibTexWriter() |
| 108 | + bibtex_file.write(writer.write(bib_database)) |
0 commit comments