bibtexparser 1.4.0__tar.gz → 1.4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. bibtexparser-1.4.2/CODE_OF_CONDUCT.md +128 -0
  2. bibtexparser-1.4.2/CONTRIBUTING.md +20 -0
  3. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/COPYING +0 -0
  4. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/MANIFEST.in +0 -0
  5. bibtexparser-1.4.2/PKG-INFO +67 -0
  6. bibtexparser-1.4.2/README.rst +55 -0
  7. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/bibtexparser/__init__.py +108 -108
  8. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/bibtexparser/bibdatabase.py +7 -9
  9. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/bibtexparser/bibtexexpression.py +0 -0
  10. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/bibtexparser/bparser.py +1 -1
  11. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/bibtexparser/bwriter.py +20 -15
  12. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/bibtexparser/customization.py +78 -1
  13. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/bibtexparser/latexenc.py +1 -1
  14. bibtexparser-1.4.2/bibtexparser.egg-info/PKG-INFO +67 -0
  15. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/bibtexparser.egg-info/SOURCES.txt +2 -0
  16. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/bibtexparser.egg-info/dependency_links.txt +0 -0
  17. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/bibtexparser.egg-info/requires.txt +0 -0
  18. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/bibtexparser.egg-info/top_level.txt +0 -0
  19. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/docs/Makefile +0 -0
  20. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/docs/source/bibtex_conv.rst +0 -0
  21. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/docs/source/bibtexparser.rst +0 -0
  22. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/docs/source/conf.py +0 -0
  23. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/docs/source/demo.py +0 -0
  24. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/docs/source/index.rst +0 -0
  25. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/docs/source/install.rst +0 -0
  26. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/docs/source/logging.rst +0 -0
  27. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/docs/source/tutorial.rst +0 -0
  28. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/requirements.txt +0 -0
  29. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/setup.cfg +4 -4
  30. {bibtexparser-1.4.0 → bibtexparser-1.4.2}/setup.py +33 -33
  31. bibtexparser-1.4.0/PKG-INFO +0 -58
  32. bibtexparser-1.4.0/README.rst +0 -44
  33. bibtexparser-1.4.0/bibtexparser.egg-info/PKG-INFO +0 -58
@@ -0,0 +1,128 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ < various means of contact provided at mweiss.ch >.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
+
121
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
+ enforcement ladder](https://github.com/mozilla/diversity).
123
+
124
+ [homepage]: https://www.contributor-covenant.org
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ https://www.contributor-covenant.org/faq. Translations are available at
128
+ https://www.contributor-covenant.org/translations.
@@ -0,0 +1,20 @@
1
+ Thanks heaps for being interested in contributing to python-bibtexparser.
2
+
3
+ We are always looking for people to improve the library. Contributions include, but are not limited to:
4
+
5
+ 1. Opening well described issues for bugs or feature requests.
6
+ 2. Providing bugfixing PRs
7
+ 3. Implementing any of the issues or continuing any of the PRs labelled with `needs help` or `good first issue`.
8
+
9
+ Some guidelines:
10
+
11
+ 1. Be nice! Were all doing this in our free time; no one is obligated to do anything.
12
+ 2. Add sufficient tests to your PRs
13
+ 3. Document your code.
14
+ 4. Don't hesitate to ask questions.
15
+
16
+ Also note that there are currently two independent "default" branches:
17
+ First, `master`, where we maintain a stable `v1.x` and where we merge almost only backwards-compatible bugfixes.
18
+ Second, `v2` where we work on a full re-implementation of the library.
19
+
20
+ Issues targeting the `v2` branch are labelled `v2`.
File without changes
File without changes
@@ -0,0 +1,67 @@
1
+ Metadata-Version: 2.1
2
+ Name: bibtexparser
3
+ Version: 1.4.2
4
+ Summary: Bibtex parser for python 3
5
+ Home-page: https://github.com/sciunto-org/python-bibtexparser
6
+ Author: Francois Boulogne and other contributors
7
+ Author-email: code@mweiss.ch
8
+ License: LGPLv3 or BSD
9
+ Description-Content-Type: text/x-rst
10
+ License-File: COPYING
11
+ Requires-Dist: pyparsing>=2.0.3
12
+
13
+ python-bibtexparser
14
+ ===================
15
+
16
+ Python 3 library to parse `bibtex <https://en.wikipedia.org/wiki/BibTeX>`_ files.
17
+
18
+
19
+ .. contents::
20
+
21
+
22
+ Documentation
23
+ -------------
24
+
25
+ Our documentation includes the installation procedure, a tutorial, the API and advices to report a bug:
26
+ `Documentation on readthedocs.io <https://bibtexparser.readthedocs.io/>`_
27
+
28
+ Upgrading
29
+ ---------
30
+
31
+ Please, read the changelog before upgrading regarding API modifications.
32
+
33
+ License
34
+ -------
35
+
36
+ Dual license (at your choice):
37
+
38
+ * LGPLv3.
39
+ * BSD
40
+
41
+ See COPYING for details.
42
+
43
+ History and evolutions
44
+ ----------------------
45
+
46
+ The original source code was part of bibserver from `OKFN <http://github.com/okfn/bibserver>`_. This project is released under the AGPLv3. OKFN and the original authors kindly provided the permission to use a subpart of their project (ie the bibtex parser) under LGPLv3. Many thanks to them!
47
+
48
+ The parser evolved to a new core based on pyparsing.
49
+
50
+ Since 2022, after a long stale period, this library has a new maintainer (`@MiWeiss <https://github.com/MiWeiss>`_).
51
+
52
+
53
+ `v2` Announcement
54
+ -----------------
55
+
56
+ Version 1.x, is trusted and used by more than 1300 projects, with much of its code being ~10 years old. Our primary objective in maintaining v1.x is to provide stability and backwards compatibility to these projects - such that they can safely and easily migrate to new versions.
57
+
58
+ Still, there's much room for large-scale improvements and changes to modernize bibtexparser. Hence, we are working on a new version 2.0.0 which is a complete rewrite of the library, providing amongst other the following advantages:
59
+
60
+ - Order of magnitudes faster
61
+ - Type-Hints and extensive documentation
62
+ - Easily customizable parsing **and** writing
63
+ - Access to raw, unparsed bibtex.
64
+ - Fault-Tolerant: Able to parse files with syntax errors
65
+ - Massively simplified, robuster handling of de- and encoding (special chars, ...).
66
+
67
+ Check out the `v2 dev branch <https://github.com/sciunto-org/python-bibtexparser/tree/v2>`_ and the `v2 coordination issue <https://github.com/sciunto-org/python-bibtexparser/issues/318>`_ to get a sneak preview. Also - if you're keen - we're always looking for contributors. Do not hesitate to get in contact with us.
@@ -0,0 +1,55 @@
1
+ python-bibtexparser
2
+ ===================
3
+
4
+ Python 3 library to parse `bibtex <https://en.wikipedia.org/wiki/BibTeX>`_ files.
5
+
6
+
7
+ .. contents::
8
+
9
+
10
+ Documentation
11
+ -------------
12
+
13
+ Our documentation includes the installation procedure, a tutorial, the API and advices to report a bug:
14
+ `Documentation on readthedocs.io <https://bibtexparser.readthedocs.io/>`_
15
+
16
+ Upgrading
17
+ ---------
18
+
19
+ Please, read the changelog before upgrading regarding API modifications.
20
+
21
+ License
22
+ -------
23
+
24
+ Dual license (at your choice):
25
+
26
+ * LGPLv3.
27
+ * BSD
28
+
29
+ See COPYING for details.
30
+
31
+ History and evolutions
32
+ ----------------------
33
+
34
+ The original source code was part of bibserver from `OKFN <http://github.com/okfn/bibserver>`_. This project is released under the AGPLv3. OKFN and the original authors kindly provided the permission to use a subpart of their project (ie the bibtex parser) under LGPLv3. Many thanks to them!
35
+
36
+ The parser evolved to a new core based on pyparsing.
37
+
38
+ Since 2022, after a long stale period, this library has a new maintainer (`@MiWeiss <https://github.com/MiWeiss>`_).
39
+
40
+
41
+ `v2` Announcement
42
+ -----------------
43
+
44
+ Version 1.x, is trusted and used by more than 1300 projects, with much of its code being ~10 years old. Our primary objective in maintaining v1.x is to provide stability and backwards compatibility to these projects - such that they can safely and easily migrate to new versions.
45
+
46
+ Still, there's much room for large-scale improvements and changes to modernize bibtexparser. Hence, we are working on a new version 2.0.0 which is a complete rewrite of the library, providing amongst other the following advantages:
47
+
48
+ - Order of magnitudes faster
49
+ - Type-Hints and extensive documentation
50
+ - Easily customizable parsing **and** writing
51
+ - Access to raw, unparsed bibtex.
52
+ - Fault-Tolerant: Able to parse files with syntax errors
53
+ - Massively simplified, robuster handling of de- and encoding (special chars, ...).
54
+
55
+ Check out the `v2 dev branch <https://github.com/sciunto-org/python-bibtexparser/tree/v2>`_ and the `v2 coordination issue <https://github.com/sciunto-org/python-bibtexparser/issues/318>`_ to get a sneak preview. Also - if you're keen - we're always looking for contributors. Do not hesitate to get in contact with us.
@@ -1,108 +1,108 @@
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.0'
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) (not yet implemented)
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) (not yet implemented)
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.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))
@@ -86,17 +86,15 @@ class BibDatabase(object):
86
86
  result.append(str(entry.get(field, '')).lower()) # Sorting always as string
87
87
  return tuple(result)
88
88
 
89
- def _make_entries_dict(self):
90
- for entry in self.entries:
91
- self._entries_dict[entry['ID']] = entry
92
-
93
89
  def get_entry_dict(self):
94
- """Return a dictionary of BibTeX entries.
95
- The dict key is the BibTeX entry key
90
+ """Return a dictionary of BibTeX entries, where dict key is the BibTeX entry key.
91
+
92
+ This method re-creates the dict every time it is called,
93
+ hence subsequent calls should be avoided with large databases.
96
94
  """
97
- # If the hash has never been made, make it
98
- if not self._entries_dict:
99
- self._make_entries_dict()
95
+ self._entries_dict = dict()
96
+ for entry in self.entries:
97
+ self._entries_dict[entry['ID']] = entry
100
98
  return self._entries_dict
101
99
 
102
100
  entries_dict = property(get_entry_dict)
@@ -49,7 +49,7 @@ class BibTexParser(object):
49
49
  :param interpolate_strings: bool (default True)
50
50
  If True, replace bibtex string by their value, else uses
51
51
  BibDataString objects.
52
- :param common_strings: bool (default False)
52
+ :param common_strings: bool (default True)
53
53
  Include common string definitions (e.g. month abbreviations) to
54
54
  the bibtex file.
55
55
  :param add_missing_from_crossref: bool (default False)
@@ -5,7 +5,7 @@
5
5
 
6
6
  import logging
7
7
  from enum import Enum, auto
8
- from typing import Dict, Callable, Iterable
8
+ from typing import Dict, Callable, Iterable, Union
9
9
  from bibtexparser.bibdatabase import (BibDatabase, COMMON_STRINGS,
10
10
  BibDataString,
11
11
  BibDataStringExpression)
@@ -15,6 +15,9 @@ logger = logging.getLogger(__name__)
15
15
 
16
16
  __all__ = ['BibTexWriter']
17
17
 
18
+ # A list of entries that should not be included in the content (key = value) of a BibTex entry
19
+ ENTRY_TO_BIBTEX_IGNORE_ENTRIES = ['ENTRYTYPE', 'ID']
20
+
18
21
 
19
22
  class SortingStrategy(Enum):
20
23
  """
@@ -89,9 +92,12 @@ class BibTexWriter(object):
89
92
  self.contents = ['comments', 'preambles', 'strings', 'entries']
90
93
  #: Character(s) for indenting BibTeX field-value pairs. Default: single space.
91
94
  self.indent = ' '
92
- #: Align values. Determines the maximal number of characters used in any fieldname and aligns all values
93
- # according to that by filling up with single spaces. Default: False
94
- self.align_values = False
95
+ #: Align values. Aligns all values according to a given length by padding with single spaces.
96
+ # If align_values is true, the maximum number of characters used in any field name is used as the length.
97
+ # If align_values is a number, the greater of the specified value or the number of characters used in the
98
+ # field name is used as the length.
99
+ # Default: False
100
+ self.align_values: Union[int, bool] = False
95
101
  #: Align multi-line values. Formats a multi-line value such that the text is aligned exactly
96
102
  # on top of each other. Default: False
97
103
  self.align_multiline_values = False
@@ -112,7 +118,7 @@ class BibTexWriter(object):
112
118
  #: BibTeX syntax allows the comma to be optional at the end of the last field in an entry.
113
119
  #: Use this to enable writing this last comma in the bwriter output. Defaults: False.
114
120
  self.add_trailing_comma = False
115
- #: internal variable used if self.align_values = True
121
+ #: internal variable used if self.align_values = True or self.align_values = <number>
116
122
  self._max_field_width = 0
117
123
  #: Whether common strings are written
118
124
  self.common_strings = write_common_strings
@@ -143,10 +149,13 @@ class BibTexWriter(object):
143
149
  else:
144
150
  entries = bib_database.entries
145
151
 
146
- if self.align_values:
152
+ if self.align_values is True:
147
153
  # determine maximum field width to be used
148
- widths = [max(map(len, entry.keys())) for entry in entries]
154
+ widths = [len(ele) for entry in entries for ele in entry if ele not in ENTRY_TO_BIBTEX_IGNORE_ENTRIES]
149
155
  self._max_field_width = max(widths)
156
+ elif type(self.align_values) == int:
157
+ # Use specified value
158
+ self._max_field_width = self.align_values
150
159
 
151
160
  return self.entry_separator.join(self._entry_to_bibtex(entry) for entry in entries)
152
161
 
@@ -165,7 +174,8 @@ class BibTexWriter(object):
165
174
  else:
166
175
  field_fmt = u",\n{indent}{field:<{field_max_w}} = {value}"
167
176
  # Write field = value lines
168
- for field in [i for i in display_order if i not in ['ENTRYTYPE', 'ID']]:
177
+ for field in [i for i in display_order if i not in ENTRY_TO_BIBTEX_IGNORE_ENTRIES]:
178
+ max_field_width = max(len(field), self._max_field_width)
169
179
  try:
170
180
  value = _str_or_expr_to_bibtex(entry[field])
171
181
 
@@ -176,12 +186,7 @@ class BibTexWriter(object):
176
186
  # World}
177
187
  # Calculate the indent of "World":
178
188
  # Left of field (whitespaces before e.g. 'title')
179
- value_indent = len(self.indent)
180
- # Field itself (e.g. len('title'))
181
- if self._max_field_width > 0:
182
- value_indent += self._max_field_width
183
- else:
184
- value_indent += len(field)
189
+ value_indent = len(self.indent) + max_field_width
185
190
  # Right of field ' = ' (<- 3 chars) + '{' (<- 1 char)
186
191
  value_indent += 3 + 1
187
192
 
@@ -190,7 +195,7 @@ class BibTexWriter(object):
190
195
  bibtex += field_fmt.format(
191
196
  indent=self.indent,
192
197
  field=field,
193
- field_max_w=self._max_field_width,
198
+ field_max_w=max_field_width,
194
199
  value=value)
195
200
  except TypeError:
196
201
  raise TypeError(u"The field %s in entry %s must be a string"
@@ -299,6 +299,61 @@ def splitname(name, strict_mode=True):
299
299
  return parts
300
300
 
301
301
 
302
+ def find_matching(
303
+ text: str,
304
+ opening: str,
305
+ closing: str,
306
+ ignore_escaped: bool = True,
307
+ ) -> dict:
308
+ r"""
309
+ Find matching 'brackets'.
310
+
311
+ :param text: The string to consider.
312
+ :param opening: The opening bracket (e.g. "(", "[", "{").
313
+ :param closing: The closing bracket (e.g. ")", "]", "}").
314
+ :param ignore_escaped: Ignore escaped bracket (e.g. "\(", "\[", "\{", "\)", "\]", "\}").
315
+ :return: Dictionary with ``{index_opening: index_closing}``
316
+ """
317
+
318
+ a = []
319
+ b = []
320
+
321
+ if ignore_escaped:
322
+ opening = r"(?<!\\)" + opening
323
+ closing = r"(?<!\\)" + closing
324
+
325
+ for i in re.finditer(opening, text):
326
+ a.append(i.span()[0])
327
+
328
+ for i in re.finditer(closing, text):
329
+ b.append(-1 * i.span()[0])
330
+
331
+ if len(a) == 0 and len(b) == 0:
332
+ return {}
333
+
334
+ if len(a) != len(b):
335
+ raise IndexError(f"Unmatching {opening}...{closing} found")
336
+
337
+ brackets = sorted(a + b, key=lambda i: abs(i))
338
+
339
+ ret = {}
340
+ stack = []
341
+
342
+ for i in brackets:
343
+ if i >= 0:
344
+ stack.append(i)
345
+ else:
346
+ if len(stack) == 0:
347
+ raise IndexError(f"No closing {closing} at: {i:d}")
348
+ j = stack.pop()
349
+ ret[j] = -1 * i
350
+
351
+ if len(stack) > 0:
352
+ raise IndexError(f"No opening {opening} at {stack.pop():d}")
353
+
354
+ return ret
355
+
356
+
302
357
  def getnames(names):
303
358
  """Convert people names as surname, firstnames
304
359
  or surname, initials.
@@ -322,7 +377,29 @@ def getnames(names):
322
377
  last = namesplit[0].strip()
323
378
  firsts = [i.strip() for i in namesplit[1].split()]
324
379
  else:
325
- namesplit = namestring.split()
380
+ if "{" in namestring and "}" in namestring:
381
+ try:
382
+ brackets = find_matching(namestring, "{", "}")
383
+ except IndexError:
384
+ tidynames.append(namestring)
385
+ continue
386
+ namesplit = []
387
+ start = 0
388
+ i = 0
389
+ while True:
390
+ if i in brackets:
391
+ i = brackets[i]
392
+ else:
393
+ i += 1
394
+ if i >= len(namestring):
395
+ break
396
+ if namestring[i] == " ":
397
+ namesplit.append(namestring[start:i])
398
+ start = i + 1
399
+ elif i == len(namestring) - 1:
400
+ namesplit.append(namestring[start:])
401
+ else:
402
+ namesplit = namestring.split()
326
403
  last = namesplit.pop()
327
404
  firsts = [i.replace('.', '. ').strip() for i in namesplit]
328
405
  if last in ['jnr', 'jr', 'junior']:
@@ -90,7 +90,7 @@ def protect_uppercase(string):
90
90
  :param string: string to convert
91
91
  :returns: string
92
92
  """
93
- string = re.sub('([^{]|^)([A-Z])([^}]|$)', '\g<1>{\g<2>}\g<3>', string)
93
+ string = re.sub(r'([^{]|^)([A-Z])([^}]|$)', r'\g<1>{\g<2>}\g<3>', string)
94
94
  return string
95
95
 
96
96
 
@@ -0,0 +1,67 @@
1
+ Metadata-Version: 2.1
2
+ Name: bibtexparser
3
+ Version: 1.4.2
4
+ Summary: Bibtex parser for python 3
5
+ Home-page: https://github.com/sciunto-org/python-bibtexparser
6
+ Author: Francois Boulogne and other contributors
7
+ Author-email: code@mweiss.ch
8
+ License: LGPLv3 or BSD
9
+ Description-Content-Type: text/x-rst
10
+ License-File: COPYING
11
+ Requires-Dist: pyparsing>=2.0.3
12
+
13
+ python-bibtexparser
14
+ ===================
15
+
16
+ Python 3 library to parse `bibtex <https://en.wikipedia.org/wiki/BibTeX>`_ files.
17
+
18
+
19
+ .. contents::
20
+
21
+
22
+ Documentation
23
+ -------------
24
+
25
+ Our documentation includes the installation procedure, a tutorial, the API and advices to report a bug:
26
+ `Documentation on readthedocs.io <https://bibtexparser.readthedocs.io/>`_
27
+
28
+ Upgrading
29
+ ---------
30
+
31
+ Please, read the changelog before upgrading regarding API modifications.
32
+
33
+ License
34
+ -------
35
+
36
+ Dual license (at your choice):
37
+
38
+ * LGPLv3.
39
+ * BSD
40
+
41
+ See COPYING for details.
42
+
43
+ History and evolutions
44
+ ----------------------
45
+
46
+ The original source code was part of bibserver from `OKFN <http://github.com/okfn/bibserver>`_. This project is released under the AGPLv3. OKFN and the original authors kindly provided the permission to use a subpart of their project (ie the bibtex parser) under LGPLv3. Many thanks to them!
47
+
48
+ The parser evolved to a new core based on pyparsing.
49
+
50
+ Since 2022, after a long stale period, this library has a new maintainer (`@MiWeiss <https://github.com/MiWeiss>`_).
51
+
52
+
53
+ `v2` Announcement
54
+ -----------------
55
+
56
+ Version 1.x, is trusted and used by more than 1300 projects, with much of its code being ~10 years old. Our primary objective in maintaining v1.x is to provide stability and backwards compatibility to these projects - such that they can safely and easily migrate to new versions.
57
+
58
+ Still, there's much room for large-scale improvements and changes to modernize bibtexparser. Hence, we are working on a new version 2.0.0 which is a complete rewrite of the library, providing amongst other the following advantages:
59
+
60
+ - Order of magnitudes faster
61
+ - Type-Hints and extensive documentation
62
+ - Easily customizable parsing **and** writing
63
+ - Access to raw, unparsed bibtex.
64
+ - Fault-Tolerant: Able to parse files with syntax errors
65
+ - Massively simplified, robuster handling of de- and encoding (special chars, ...).
66
+
67
+ Check out the `v2 dev branch <https://github.com/sciunto-org/python-bibtexparser/tree/v2>`_ and the `v2 coordination issue <https://github.com/sciunto-org/python-bibtexparser/issues/318>`_ to get a sneak preview. Also - if you're keen - we're always looking for contributors. Do not hesitate to get in contact with us.
@@ -1,3 +1,5 @@
1
+ CODE_OF_CONDUCT.md
2
+ CONTRIBUTING.md
1
3
  COPYING
2
4
  MANIFEST.in
3
5
  README.rst
File without changes
@@ -1,4 +1,4 @@
1
- [egg_info]
2
- tag_build =
3
- tag_date = 0
4
-
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -1,33 +1,33 @@
1
- #!/usr/bin/env python
2
-
3
- try:
4
- from setuptools import setup
5
- except ImportError as ex:
6
- print('[python-bibtexparser] setuptools not found. Falling back to distutils.core')
7
- from distutils.core import setup
8
-
9
- with open('bibtexparser/__init__.py') as fh:
10
- for line in fh:
11
- if line.startswith('__version__'):
12
- version = line.strip().split()[-1][1:-1]
13
- break
14
-
15
-
16
- def load_readme():
17
- with open("README.rst") as f:
18
- return f.read()
19
-
20
-
21
- setup(
22
- name='bibtexparser',
23
- version=version,
24
- url="https://github.com/sciunto-org/python-bibtexparser",
25
- author="Francois Boulogne and other contributors",
26
- license="LGPLv3 or BSD",
27
- author_email="code@mweiss.ch",
28
- description="Bibtex parser for python 3",
29
- long_description_content_type="text/x-rst",
30
- long_description=load_readme(),
31
- packages=['bibtexparser'],
32
- install_requires=['pyparsing>=2.0.3'],
33
- )
1
+ #!/usr/bin/env python
2
+
3
+ try:
4
+ from setuptools import setup
5
+ except ImportError as ex:
6
+ print('[python-bibtexparser] setuptools not found. Falling back to distutils.core')
7
+ from distutils.core import setup
8
+
9
+ with open('bibtexparser/__init__.py') as fh:
10
+ for line in fh:
11
+ if line.startswith('__version__'):
12
+ version = line.strip().split()[-1][1:-1]
13
+ break
14
+
15
+
16
+ def load_readme():
17
+ with open("README.rst") as f:
18
+ return f.read()
19
+
20
+
21
+ setup(
22
+ name='bibtexparser',
23
+ version=version,
24
+ url="https://github.com/sciunto-org/python-bibtexparser",
25
+ author="Francois Boulogne and other contributors",
26
+ license="LGPLv3 or BSD",
27
+ author_email="code@mweiss.ch",
28
+ description="Bibtex parser for python 3",
29
+ long_description_content_type="text/x-rst",
30
+ long_description=load_readme(),
31
+ packages=['bibtexparser'],
32
+ install_requires=['pyparsing>=2.0.3'],
33
+ )
@@ -1,58 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: bibtexparser
3
- Version: 1.4.0
4
- Summary: Bibtex parser for python 3
5
- Home-page: https://github.com/sciunto-org/python-bibtexparser
6
- Author: Francois Boulogne and other contributors
7
- Author-email: code@mweiss.ch
8
- License: LGPLv3 or BSD
9
- Platform: UNKNOWN
10
- Description-Content-Type: text/x-rst
11
- License-File: COPYING
12
-
13
- python-bibtexparser
14
- ===================
15
-
16
- Python library to parse `bibtex <https://en.wikipedia.org/wiki/BibTeX>`_ files.
17
-
18
-
19
- .. contents::
20
-
21
-
22
- Bibtexparser relies on `pyparsing <https://pypi.python.org/pypi/pyparsing>`_ and is compatible with Python 3.3 or newer.
23
-
24
- Documentation
25
- -------------
26
-
27
- Our documentation includes the installation procedure, a tutorial, the API and advices to report a bug.
28
- References, related projects and softwares based on bibtexparser are also listed. If you would like to appear on this list, feel free to open a ticket or send an email.
29
-
30
- `Documentation on readthedocs.io <https://bibtexparser.readthedocs.io/>`_
31
-
32
- Upgrading
33
- ---------
34
-
35
- Please, read the changelog before upgrading regarding API modifications.
36
-
37
- License
38
- -------
39
-
40
- Dual license (at your choice):
41
-
42
- * LGPLv3.
43
- * BSD
44
-
45
- See COPYING for details.
46
-
47
- History and evolutions
48
- ----------------------
49
-
50
- The original source code was part of bibserver from `OKFN <http://github.com/okfn/bibserver>`_. This project is released under the AGPLv3. OKFN and the original authors kindly provided the permission to use a subpart of their project (ie the bibtex parser) under LGPLv3. Many thanks to them!
51
-
52
- The parser evolved to a new core based on pyparsing.
53
-
54
- News (July 7h, 2022): This library has a new maintainer (`@MiWeiss <https://github.com/MiWeiss>`_).
55
- Versions 1.x will be mostly bugfixes and maintenance.
56
- In the meantime, we are working on a new version 2.0.0 which will be a complete rewrite of the library.
57
-
58
-
@@ -1,44 +0,0 @@
1
- python-bibtexparser
2
- ===================
3
-
4
- Python library to parse `bibtex <https://en.wikipedia.org/wiki/BibTeX>`_ files.
5
-
6
-
7
- .. contents::
8
-
9
-
10
- Bibtexparser relies on `pyparsing <https://pypi.python.org/pypi/pyparsing>`_ and is compatible with Python 3.3 or newer.
11
-
12
- Documentation
13
- -------------
14
-
15
- Our documentation includes the installation procedure, a tutorial, the API and advices to report a bug.
16
- References, related projects and softwares based on bibtexparser are also listed. If you would like to appear on this list, feel free to open a ticket or send an email.
17
-
18
- `Documentation on readthedocs.io <https://bibtexparser.readthedocs.io/>`_
19
-
20
- Upgrading
21
- ---------
22
-
23
- Please, read the changelog before upgrading regarding API modifications.
24
-
25
- License
26
- -------
27
-
28
- Dual license (at your choice):
29
-
30
- * LGPLv3.
31
- * BSD
32
-
33
- See COPYING for details.
34
-
35
- History and evolutions
36
- ----------------------
37
-
38
- The original source code was part of bibserver from `OKFN <http://github.com/okfn/bibserver>`_. This project is released under the AGPLv3. OKFN and the original authors kindly provided the permission to use a subpart of their project (ie the bibtex parser) under LGPLv3. Many thanks to them!
39
-
40
- The parser evolved to a new core based on pyparsing.
41
-
42
- News (July 7h, 2022): This library has a new maintainer (`@MiWeiss <https://github.com/MiWeiss>`_).
43
- Versions 1.x will be mostly bugfixes and maintenance.
44
- In the meantime, we are working on a new version 2.0.0 which will be a complete rewrite of the library.
@@ -1,58 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: bibtexparser
3
- Version: 1.4.0
4
- Summary: Bibtex parser for python 3
5
- Home-page: https://github.com/sciunto-org/python-bibtexparser
6
- Author: Francois Boulogne and other contributors
7
- Author-email: code@mweiss.ch
8
- License: LGPLv3 or BSD
9
- Platform: UNKNOWN
10
- Description-Content-Type: text/x-rst
11
- License-File: COPYING
12
-
13
- python-bibtexparser
14
- ===================
15
-
16
- Python library to parse `bibtex <https://en.wikipedia.org/wiki/BibTeX>`_ files.
17
-
18
-
19
- .. contents::
20
-
21
-
22
- Bibtexparser relies on `pyparsing <https://pypi.python.org/pypi/pyparsing>`_ and is compatible with Python 3.3 or newer.
23
-
24
- Documentation
25
- -------------
26
-
27
- Our documentation includes the installation procedure, a tutorial, the API and advices to report a bug.
28
- References, related projects and softwares based on bibtexparser are also listed. If you would like to appear on this list, feel free to open a ticket or send an email.
29
-
30
- `Documentation on readthedocs.io <https://bibtexparser.readthedocs.io/>`_
31
-
32
- Upgrading
33
- ---------
34
-
35
- Please, read the changelog before upgrading regarding API modifications.
36
-
37
- License
38
- -------
39
-
40
- Dual license (at your choice):
41
-
42
- * LGPLv3.
43
- * BSD
44
-
45
- See COPYING for details.
46
-
47
- History and evolutions
48
- ----------------------
49
-
50
- The original source code was part of bibserver from `OKFN <http://github.com/okfn/bibserver>`_. This project is released under the AGPLv3. OKFN and the original authors kindly provided the permission to use a subpart of their project (ie the bibtex parser) under LGPLv3. Many thanks to them!
51
-
52
- The parser evolved to a new core based on pyparsing.
53
-
54
- News (July 7h, 2022): This library has a new maintainer (`@MiWeiss <https://github.com/MiWeiss>`_).
55
- Versions 1.x will be mostly bugfixes and maintenance.
56
- In the meantime, we are working on a new version 2.0.0 which will be a complete rewrite of the library.
57
-
58
-