Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f78133e

Browse files
committed
Simplify producing warnings for bad PDF metadata.
1 parent 2bcec28 commit f78133e

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,36 +183,39 @@ def _create_pdf_info_dict(backend, metadata):
183183
info = {k: v for (k, v) in info.items() if v is not None}
184184

185185
def is_string_like(x):
186+
"""an instance of str"""
186187
return isinstance(x, str)
187188

188189
def is_date(x):
190+
"""an instance of datetime.datetime"""
189191
return isinstance(x, datetime)
190192

191193
def check_trapped(x):
194+
"""one of {"True", "False", "Unknown"}"""
192195
if isinstance(x, Name):
193196
return x.name in (b'True', b'False', b'Unknown')
194197
else:
195198
return x in ('True', 'False', 'Unknown')
196199

197200
keywords = {
198-
'Title': (is_string_like, 'an instance of str'),
199-
'Author': (is_string_like, 'an instance of str'),
200-
'Subject': (is_string_like, 'an instance of str'),
201-
'Keywords': (is_string_like, 'an instance of str'),
202-
'Creator': (is_string_like, 'an instance of str'),
203-
'Producer': (is_string_like, 'an instance of str'),
204-
'CreationDate': (is_date, 'an instance of datetime.datetime'),
205-
'ModDate': (is_date, 'an instance of datetime.datetime'),
206-
'Trapped': (check_trapped, 'one of {"True", "False", "Unknown"}'),
201+
'Title': is_string_like,
202+
'Author': is_string_like,
203+
'Subject': is_string_like,
204+
'Keywords': is_string_like,
205+
'Creator': is_string_like,
206+
'Producer': is_string_like,
207+
'CreationDate': is_date,
208+
'ModDate': is_date,
209+
'Trapped': check_trapped,
207210
}
208211
for k in info:
209212
if k not in keywords:
210213
cbook._warn_external(f'Unknown infodict keyword: {k!r}. '
211214
f'Must be one of {set(keywords)!r}.')
212-
elif not keywords[k][0](info[k]):
215+
elif not keywords[k](info[k]):
213216
cbook._warn_external(f'Bad value for infodict keyword {k}. '
214217
f'Got {info[k]!r} which is not '
215-
f'{keywords[k][1]}.')
218+
f'{keywords[k].__doc__}.')
216219
if 'Trapped' in info:
217220
info['Trapped'] = Name(info['Trapped'])
218221

0 commit comments

Comments
 (0)