FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-bibtexparser/bibtexparser/__init__.py at master · NeoIO/python-bibtexparser · GitHub
NeoIO
/
python-bibtexparser
Public
forked from
sciunto-org/python-bibtexparser
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-bibtexparser
/
bibtexparser
/
__init__.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
91 lines (72 loc) · 2.71 KB
Breadcrumbs
python-bibtexparser
/
bibtexparser
/
__init__.py
Copy path
File metadata and controls
91 lines (72 loc) · 2.71 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
"""
BibTeX <http://en.wikipedia.org/wiki/BibTeX> is a bibliographic data file format.
The :mod:`bibtexparser` module provides parsing and writing of BibTeX files functionality. The API is similar to the
:mod:`json` module. The parsed data is returned as a simple :class:`BibDatabase` object with the main attribute being
:attr:`entries` representing bibliographic sources such as books and journal articles.
Parsing is a simple as::
>>>> import bibtexparser
>>>> with open('bibtex.bib') as bibtex_file:
>>>> bibtex_database = bibtexparser.load(bibtex_file)
And writing::
>>>> import bibtexparser
>>>> with open('bibtex.bib', 'w') as bibtex_file:
>>>> bibtexparser.dump(bibtex_database, bibtex_file)
"""
__all__
=
[
'loads'
,
'load'
,
'dumps'
,
'dump'
'bparser'
,
'bwrite'
,
'info'
,
'latexenc'
,
'customization'
]
__version__
=
'0.5.5'
from
.
import
bparser
,
bwriter
,
info
,
latexenc
,
customization
def
loads
(
bibtex_str
,
parser
=
None
):
"""
Load :class:`BibDatabase` object from a string
:param bibtex_str: input BibTeX string to be parsed
:type bibtex_str: str or unicode
:param parser: custom parser to use (optional)
:type parser: BibTexParser
:return: bibliographic database object
:rtype: BibDatabase
"""
if
parser
is
None
:
parser
=
bparser
.
BibTexParser
()
return
parser
.
parse
(
bibtex_str
)
def
load
(
bibtex_file
,
parser
=
None
):
"""
Load :class:`BibDatabase` object from a file
:param bibtex_file: input file to be parsed
:type bibtex_file: file
:param parser: custom parser to use (optional)
:type parser: BibTexParser
:return: bibliographic database object
:rtype: BibDatabase
"""
if
parser
is
None
:
parser
=
bparser
.
BibTexParser
()
return
parser
.
parse_file
(
bibtex_file
)
def
dumps
(
bib_database
,
writer
=
None
):
"""
Dump :class:`BibDatabase` object to a BibTeX string
:param bib_database: bibliographic database object
:type bib_database: BibDatabase
:param writer: custom writer to use (optional) (not yet implemented)
:type writer: BibTexWriter
:return: BibTeX string
:rtype: unicode
"""
if
writer
is
None
:
writer
=
bwriter
.
BibTexWriter
()
return
writer
.
write
(
bib_database
)
def
dump
(
bib_database
,
bibtex_file
,
writer
=
None
):
"""
Save :class:`BibDatabase` object as a BibTeX text file
:param bib_database: bibliographic database object
:type bib_database: BibDatabase
:param bibtex_file: file to write to
:type bibtex_file: file
:param writer: custom writer to use (optional) (not yet implemented)
:type writer: BibTexWriter
"""
if
writer
is
None
:
writer
=
bwriter
.
BibTexWriter
()
bibtex_file
.
write
(
writer
.
write
(
bib_database
))
Back
|
FazBrowse Home
|
New Git URL