MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _write_metadata

Method _write_metadata

lib/matplotlib/backends/backend_svg.py:363–484  ·  view source on GitHub ↗
(self, metadata)

Source from the content-addressed store, hash-verified

361 self.writer.flush()
362
363 def _write_metadata(self, metadata):
364 # Add metadata following the Dublin Core Metadata Initiative, and the
365 # Creative Commons Rights Expression Language. This is mainly for
366 # compatibility with Inkscape.
367 if metadata is None:
368 metadata = {}
369 metadata = {
370 'Format': 'image/svg+xml',
371 'Type': 'http://purl.org/dc/dcmitype/StillImage',
372 'Creator':
373 f'Matplotlib v{mpl.__version__}, https://matplotlib.org/',
374 **metadata
375 }
376 writer = self.writer
377
378 if 'Title' in metadata:
379 title = metadata['Title']
380 _check_is_str(title, 'Title')
381 writer.element('title', text=title)
382
383 # Special handling.
384 date = metadata.get('Date', None)
385 if date is not None:
386 if isinstance(date, str):
387 dates = [date]
388 elif isinstance(date, (datetime.datetime, datetime.date)):
389 dates = [date.isoformat()]
390 elif np.iterable(date):
391 dates = []
392 for d in date:
393 if isinstance(d, str):
394 dates.append(d)
395 elif isinstance(d, (datetime.datetime, datetime.date)):
396 dates.append(d.isoformat())
397 else:
398 raise TypeError(
399 f'Invalid type for Date metadata. '
400 f'Expected iterable of str, date, or datetime, '
401 f'not {type(d)}.')
402 else:
403 raise TypeError(f'Invalid type for Date metadata. '
404 f'Expected str, date, datetime, or iterable '
405 f'of the same, not {type(date)}.')
406 metadata['Date'] = '/'.join(dates)
407 elif 'Date' not in metadata:
408 # Do not add `Date` if the user explicitly set `Date` to `None`
409 # Get source date from SOURCE_DATE_EPOCH, if set.
410 # See https://reproducible-builds.org/specs/source-date-epoch/
411 date = os.getenv("SOURCE_DATE_EPOCH")
412 if date:
413 date = datetime.datetime.fromtimestamp(int(date), datetime.timezone.utc)
414 metadata['Date'] = date.replace(tzinfo=UTC).isoformat()
415 else:
416 metadata['Date'] = datetime.datetime.today().isoformat()
417
418 mid = None
419 def ensure_metadata(mid):
420 if mid is not None:

Callers 1

__init__Method · 0.95

Calls 9

_check_is_strFunction · 0.85
elementMethod · 0.80
joinMethod · 0.80
getMethod · 0.45
popMethod · 0.45
startMethod · 0.45
endMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected