<commit_before>=======================
Images and image groups
=======================

Images contain the image data and some metadata. An image group contains
several images[#functional]_.


Image
=====

Test the image xml reference:

>>> import lxml.etree
>>> import zope.component
>>> import zeit.cms.repository.interfaces
>>> repository = zope.component.getUtility(
...     zeit.cms.repository.interfaces.IRepository)
>>> image = repository['2006']['DSC00109_2.JPG']
>>> ref = zope.component.getAdapter(
...     image,
...     zeit.cms.content.interfaces.IXMLReference, name='image')
>>> print lxml.etree.tostring(ref, pretty_print=True)
<image ...src="http://xml.zeit.de/2006/DSC00109_2.JPG"
  type="JPG"...>
  <bu xsi:nil="true"/>
  <copyright py:pytype="str">&#169;</copyright>
</image>


When the image is adapted to ILocalContent we'll get a LocalImage:

>>> image
<zeit.content.image.image.RepositoryImage object at 0x...>
>>> image.mimeType
'image/jpeg'
>>> import zeit.cms.workingcopy.interfaces
>>> local = zeit.cms.workingcopy.interfaces.ILocalContent(image)
>>> local
<zeit.content.image.image.LocalImage object at 0x...>
>>> local.__name__
u'DSC00109_2.JPG'
>>> local.mimeType
'image/jpeg'

Let's set some metadata on the local image:

>>> metadata = zeit.content.image.interfaces.IImageMetadata(local)
>>> metadata.title = 'my title'

When we make a resource from a LocalImage the contentType is set correctly:

>>> import zeit.connector.interfaces
>>> resource = zeit.connector.interfaces.IResource(local)
>>> resource.contentType
'image/jpeg'

The properties contain the title:

>>> import pprint
>>> pprint.pprint(dict(resource.properties))
{('getlastmodified', 'DAV:'): u'Fri, 07 Mar 2008 12:47:16 GMT',
 ('title', 'http://namespaces.zeit.de/CMS/document'): u'my title',
 ('type', 'http://namespaces.zeit.de/CMS/meta'): 'image'}

Le's add the local image to the repository:

>>> repository['2006']['DSC00109_2.JPG'] = local

The metadata is still there:
<commit_msg>Re VIV-252: Make doctest less overspecific<commit_after>=======================
Images and image groups
=======================

Images contain the image data and some metadata. An image group contains
several images[#functional]_.


Image
=====

Test the image xml reference:

>>> import lxml.etree
>>> import zope.component
>>> import zeit.cms.repository.interfaces
>>> repository = zope.component.getUtility(
...     zeit.cms.repository.interfaces.IRepository)
>>> image = repository['2006']['DSC00109_2.JPG']
>>> ref = zope.component.getAdapter(
...     image,
...     zeit.cms.content.interfaces.IXMLReference, name='image')
>>> print lxml.etree.tostring(ref, pretty_print=True)
<image ...src="http://xml.zeit.de/2006/DSC00109_2.JPG"
  type="JPG"...>
  <bu xsi:nil="true"/>
  <copyright py:pytype="str">&#169;</copyright>
</image>


When the image is adapted to ILocalContent we'll get a LocalImage:

>>> image
<zeit.content.image.image.RepositoryImage object at 0x...>
>>> image.mimeType
'image/jpeg'
>>> import zeit.cms.workingcopy.interfaces
>>> local = zeit.cms.workingcopy.interfaces.ILocalContent(image)
>>> local
<zeit.content.image.image.LocalImage object at 0x...>
>>> local.__name__
u'DSC00109_2.JPG'
>>> local.mimeType
'image/jpeg'

Let's set some metadata on the local image:

>>> metadata = zeit.content.image.interfaces.IImageMetadata(local)
>>> metadata.title = 'my title'

When we make a resource from a LocalImage the contentType is set correctly:

>>> import zeit.connector.interfaces
>>> resource = zeit.connector.interfaces.IResource(local)
>>> resource.contentType
'image/jpeg'

The properties contain the title:

>>> import pprint
>>> resource.properties[('title', 'http://namespaces.zeit.de/CMS/document')]
u'my title'

Le's add the local image to the repository:

>>> repository['2006']['DSC00109_2.JPG'] = local

The metadata is still there:

{'fraction_non_alphanumeric': 0.17849740932642488, 'fraction_numerical': 0.025129533678756477, 'mean_word_length': 5.051724137931035, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 149, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '649321', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1210, 'n_words': 299}