File: index.py

package info (click to toggle)
python-pkginfo 1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 416 kB
  • ctags: 354
  • sloc: python: 1,487; makefile: 76
file content (15 lines) | stat: -rw-r--r-- 525 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from pkginfo.distribution import Distribution

class Index(dict):

    def __setitem__(self, key, value):
        if not isinstance(value, Distribution):
            raise ValueError('Not a distribution: %r.' % value)
        if key != '%s-%s' % (value.name, value.version):
            raise ValueError('Key must match <name>-<version>.')
        super(Index, self).__setitem__(key, value)

    def add(self, distribution):
        key = '%s-%s' % (distribution.name, distribution.version)
        self[key] = distribution