bibtexparser 1.4.3__tar.gz → 1.4.4__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 (31) hide show
  1. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/PKG-INFO +1 -1
  2. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/bibtexparser/__init__.py +108 -108
  3. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/bibtexparser/bibtexexpression.py +32 -24
  4. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/bibtexparser/bparser.py +6 -6
  5. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/bibtexparser.egg-info/PKG-INFO +1 -1
  6. bibtexparser-1.4.4/requirements.txt +1 -0
  7. bibtexparser-1.4.3/requirements.txt +0 -1
  8. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/CODE_OF_CONDUCT.md +0 -0
  9. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/CONTRIBUTING.md +0 -0
  10. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/COPYING +0 -0
  11. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/MANIFEST.in +0 -0
  12. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/README.rst +0 -0
  13. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/bibtexparser/bibdatabase.py +0 -0
  14. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/bibtexparser/bwriter.py +0 -0
  15. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/bibtexparser/customization.py +0 -0
  16. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/bibtexparser/latexenc.py +0 -0
  17. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/bibtexparser.egg-info/SOURCES.txt +0 -0
  18. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/bibtexparser.egg-info/dependency_links.txt +0 -0
  19. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/bibtexparser.egg-info/requires.txt +0 -0
  20. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/bibtexparser.egg-info/top_level.txt +0 -0
  21. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/docs/Makefile +0 -0
  22. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/docs/source/bibtex_conv.rst +0 -0
  23. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/docs/source/bibtexparser.rst +0 -0
  24. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/docs/source/conf.py +0 -0
  25. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/docs/source/demo.py +0 -0
  26. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/docs/source/index.rst +0 -0
  27. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/docs/source/install.rst +0 -0
  28. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/docs/source/logging.rst +0 -0
  29. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/docs/source/tutorial.rst +0 -0
  30. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/setup.cfg +0 -0
  31. {bibtexparser-1.4.3 → bibtexparser-1.4.4}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bibtexparser
3
- Version: 1.4.3
3
+ Version: 1.4.4
4
4
  Summary: Bibtex parser for python 3
5
5
  Home-page: https://github.com/sciunto-org/python-bibtexparser
6
6
  Author: Francois Boulogne and other contributors
@@ -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.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))
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.4'
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))
@@ -29,7 +29,7 @@ def add_logger_parse_action(expr, log_func):
29
29
  """Register a callback on expression parsing with the adequate message."""
30
30
  def action(s, l, t):
31
31
  log_func("Found {}: {}".format(expr.resultsName, t))
32
- expr.addParseAction(action)
32
+ expr.add_parse_action(action)
33
33
 
34
34
 
35
35
  # Parse action helpers
@@ -111,7 +111,7 @@ class BibtexExpression(object):
111
111
  # String names
112
112
  string_name = pp.Word(pp.alphanums + '_-:')('StringName')
113
113
  self.set_string_name_parse_action(lambda s, l, t: None)
114
- string_name.addParseAction(self._string_name_parse_action)
114
+ string_name.add_parse_action(self._string_name_parse_action)
115
115
 
116
116
  # Values inside bibtex fields
117
117
  # Values can be integer or string expressions. The latter may use
@@ -123,27 +123,27 @@ class BibtexExpression(object):
123
123
  # Braced values: braced values can contain nested (but balanced) braces
124
124
  braced_value_content = pp.CharsNotIn('{}')
125
125
  braced_value = pp.Forward() # Recursive definition for nested braces
126
- braced_value <<= pp.originalTextFor(
126
+ braced_value <<= pp.original_text_for(
127
127
  '{' + pp.ZeroOrMore(braced_value | braced_value_content) + '}'
128
128
  )('BracedValue')
129
- braced_value.setParseAction(remove_braces)
129
+ braced_value.set_parse_action(remove_braces)
130
130
  # TODO add ignore for "\}" and "\{" ?
131
131
  # TODO @ are not parsed by bibtex in braces
132
132
 
133
133
  # Quoted values: may contain braced content with balanced braces
134
- brace_in_quoted = pp.nestedExpr('{', '}', ignoreExpr=None)
134
+ brace_in_quoted = pp.nested_expr('{', '}', ignore_expr=None)
135
135
  text_in_quoted = pp.CharsNotIn('"{}')
136
136
  # (quotes should be escaped by braces in quoted value)
137
- quoted_value = pp.originalTextFor(
137
+ quoted_value = pp.original_text_for(
138
138
  '"' + pp.ZeroOrMore(text_in_quoted | brace_in_quoted) + '"'
139
139
  )('QuotedValue')
140
- quoted_value.addParseAction(pp.removeQuotes)
140
+ quoted_value.add_parse_action(pp.remove_quotes)
141
141
 
142
142
  # String expressions
143
- string_expr = pp.delimitedList(
143
+ string_expr = pp.DelimitedList(
144
144
  (quoted_value | braced_value | string_name), delim='#'
145
145
  )('StringExpression')
146
- string_expr.addParseAction(self._string_expr_parse_action)
146
+ string_expr.add_parse_action(self._string_expr_parse_action)
147
147
 
148
148
  value = (integer | string_expr)('Value')
149
149
 
@@ -151,7 +151,7 @@ class BibtexExpression(object):
151
151
 
152
152
  # @EntryType { ...
153
153
  entry_type = (pp.Suppress('@') + pp.Word(pp.alphas))('EntryType')
154
- entry_type.setParseAction(first_token)
154
+ entry_type.set_parse_action(first_token)
155
155
 
156
156
  # Entry key: any character up to a ',' without leading and trailing
157
157
  # spaces. Also exclude spaces and prevent it from being empty.
@@ -175,20 +175,20 @@ class BibtexExpression(object):
175
175
  msg="Whitespace not allowed in citekeys.")
176
176
  return key
177
177
 
178
- key.setParseAction(citekeyParseAction)
178
+ key.set_parse_action(citekeyParseAction)
179
179
 
180
180
  # Field name: word of letters, digits, dashes and underscores
181
181
  field_name = pp.Word(pp.alphanums + '_-().+')('FieldName')
182
- field_name.setParseAction(first_token)
182
+ field_name.set_parse_action(first_token)
183
183
 
184
184
  # Field: field_name = value
185
185
  field = pp.Group(field_name + pp.Suppress('=') + value)('Field')
186
- field.setParseAction(field_to_pair)
186
+ field.set_parse_action(field_to_pair)
187
187
 
188
188
  # List of fields: comma separeted fields
189
- field_list = (pp.delimitedList(field) + pp.Suppress(pp.Optional(','))
189
+ field_list = (pp.DelimitedList(field) + pp.Suppress(pp.Optional(','))
190
190
  )('Fields')
191
- field_list.setParseAction(
191
+ field_list.set_parse_action(
192
192
  lambda s, l, t: {k: v for (k, v) in reversed(t.get('Fields'))})
193
193
 
194
194
  # Entry: type, key, and fields
@@ -204,10 +204,10 @@ class BibtexExpression(object):
204
204
  ) | pp.StringEnd()
205
205
  self.explicit_comment = (
206
206
  pp.Suppress(comment_line_start) +
207
- pp.originalTextFor(pp.SkipTo(not_an_implicit_comment),
208
- asString=True))('ExplicitComment')
209
- self.explicit_comment.addParseAction(remove_trailing_newlines)
210
- self.explicit_comment.addParseAction(remove_braces)
207
+ pp.original_text_for(pp.SkipTo(not_an_implicit_comment),
208
+ as_string=True))('ExplicitComment')
209
+ self.explicit_comment.add_parse_action(remove_trailing_newlines)
210
+ self.explicit_comment.add_parse_action(remove_braces)
211
211
  # Previous implementation included comment until next '}'.
212
212
  # This is however not inline with bibtex behavior that is to only
213
213
  # ignore until EOL. Brace stipping is arbitrary here but avoids
@@ -219,10 +219,10 @@ class BibtexExpression(object):
219
219
  raise pp.ParseException("Match must not be empty.")
220
220
 
221
221
  # Implicit comments: not anything else
222
- self.implicit_comment = pp.originalTextFor(
223
- pp.SkipTo(not_an_implicit_comment).setParseAction(mustNotBeEmpty),
224
- asString=True)('ImplicitComment')
225
- self.implicit_comment.addParseAction(remove_trailing_newlines)
222
+ self.implicit_comment = pp.original_text_for(
223
+ pp.SkipTo(not_an_implicit_comment).set_parse_action(mustNotBeEmpty),
224
+ as_string=True)('ImplicitComment')
225
+ self.implicit_comment.add_parse_action(remove_trailing_newlines)
226
226
 
227
227
  # String definition
228
228
  self.string_def = (pp.Suppress(string_def_start) + in_braces_or_pars(
@@ -274,5 +274,13 @@ class BibtexExpression(object):
274
274
  def _string_expr_parse_action(self, s, l, t):
275
275
  return BibDataStringExpression.expression_if_needed(t)
276
276
 
277
+ def parse_file(self, file_obj):
278
+ """Execute parse expression on a file object"""
279
+ return self.main_expression.parse_file(file_obj, parse_all=True)
280
+
277
281
  def parseFile(self, file_obj):
278
- return self.main_expression.parseFile(file_obj, parseAll=True)
282
+ """Execute parse expression on a file object
283
+
284
+ Alias for parse_file()
285
+ """
286
+ return self.parse_file(file_obj)
@@ -159,7 +159,7 @@ class BibTexParser(object):
159
159
 
160
160
  bibtex_file_obj = self._bibtex_file_obj(bibtex_str)
161
161
  try:
162
- self._expr.parseFile(bibtex_file_obj)
162
+ self._expr.parse_file(bibtex_file_obj)
163
163
  except self._expr.ParseException as exc:
164
164
  logger.error("Could not parse properly, starting at %s", exc.line)
165
165
  if not partial:
@@ -198,20 +198,20 @@ class BibTexParser(object):
198
198
  self._expr.add_log_function(logger.debug)
199
199
 
200
200
  # Set actions
201
- self._expr.entry.addParseAction(
201
+ self._expr.entry.add_parse_action(
202
202
  lambda s, l, t: self._add_entry(
203
203
  t.get('EntryType'), t.get('Key'), t.get('Fields'))
204
204
  )
205
- self._expr.implicit_comment.addParseAction(
205
+ self._expr.implicit_comment.add_parse_action(
206
206
  lambda s, l, t: self._add_comment(t[0])
207
207
  )
208
- self._expr.explicit_comment.addParseAction(
208
+ self._expr.explicit_comment.add_parse_action(
209
209
  lambda s, l, t: self._add_comment(t[0])
210
210
  )
211
- self._expr.preamble_decl.addParseAction(
211
+ self._expr.preamble_decl.add_parse_action(
212
212
  lambda s, l, t: self._add_preamble(t[0])
213
213
  )
214
- self._expr.string_def.addParseAction(
214
+ self._expr.string_def.add_parse_action(
215
215
  lambda s, l, t: self._add_string(t['StringName'].name,
216
216
  t['StringValue'])
217
217
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bibtexparser
3
- Version: 1.4.3
3
+ Version: 1.4.4
4
4
  Summary: Bibtex parser for python 3
5
5
  Home-page: https://github.com/sciunto-org/python-bibtexparser
6
6
  Author: Francois Boulogne and other contributors
@@ -0,0 +1 @@
1
+ pyparsing>=3.0.0
@@ -1 +0,0 @@
1
- pyparsing>=2.0.3
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes