This file is indexed.

/usr/share/pyshared/zope/dublincore/property.py is in python-zope.dublincore 3.8.2-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
##############################################################################
#
# Copyright (c) 2005 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Base DublinCore property adapter.
"""
__docformat__ = 'restructuredtext'
from zope import schema

from zope.dublincore.interfaces import IZopeDublinCore
from zope.dublincore.zopedublincore import SequenceProperty

_marker = object()


class DCProperty(object):
    """Adapt to a dublin core property
    
    Handles DC list properties as scalar property.
    """

    def __init__(self, name):
        self.__name = name

    def __get__(self, inst, klass):
        if inst is None:
            return self
        name = self.__name
        inst = IZopeDublinCore(inst)
        value = getattr(inst, name, _marker)
        if value is _marker:
            field = IZopeDublinCore[name].bind(inst)
            value = getattr(field, 'default', _marker)
            if value is _marker:
                raise AttributeError(name)
        if isinstance(value, (list, tuple)):
            value = value[0]
        return value

    def __set__(self, inst, value):
        name = self.__name
        inst = IZopeDublinCore(inst)
        field = IZopeDublinCore[name].bind(inst)
        if isinstance(field, schema.List):
            if isinstance(value, tuple):
                value = list(value)
            else:
                value = [value]
        elif isinstance(field, schema.Tuple):
            if isinstance(value, list):
                value = tuple(value)
            else:
                value = (value,)
        field.validate(value)
        if field.readonly and inst.__dict__.has_key(name):
            raise ValueError(name, 'field is readonly')
        setattr(inst, name, value)

    def __getattr__(self, name):
        return getattr(IZopeDublinCore[self.__name], name)


class DCListProperty(DCProperty):
    """Adapt to a dublin core list property
    
    Returns the DC property unchanged.
    """

    def __init__(self, name):
        self.__name = name

    def __get__(self, inst, klass):
        if inst is None:
            return self
        name = self.__name
        inst = IZopeDublinCore(inst)
        value = getattr(inst, name, _marker)
        if value is _marker:
            field = IZopeDublinCore[name].bind(inst)
            value = getattr(field, 'default', _marker)
            if value is _marker:
                raise AttributeError(name)
        return value

    def __set__(self, inst, value):
        name = self.__name
        inst = IZopeDublinCore(inst)
        field = IZopeDublinCore[name].bind(inst)
        if isinstance(field, schema.Tuple):
            value = tuple(value)
        field.validate(value)
        if field.readonly and inst.__dict__.has_key(name):
            raise ValueError(name, 'field is readonly')
        setattr(inst, name, value)