1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5This file is part of cpe package.
6
7This module allows to store the value of the logical components
8of a CPE name and compare it with others.
9
10Copyright (C) 2013  Alejandro Galindo García, Roberto Abdelkader Martínez Pérez
11
12This program is free software: you can redistribute it and/or modify
13it under the terms of the GNU Lesser General Public License as published by
14the Free Software Foundation, either version 3 of the License, or
15(at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU Lesser General Public License for more details.
21
22You should have received a copy of the GNU Lesser General Public License
23along with this program. If not, see <http://www.gnu.org/licenses/>.
24
25For any problems using the cpe package, or general questions and
26feedback about it, please contact:
27
28- Alejandro Galindo García: galindo.garcia.alejandro@gmail.com
29- Roberto Abdelkader Martínez Pérez: robertomartinezp@gmail.com
30"""
31
32from .cpecomp import CPEComponent
33
34
35class CPEComponentLogical(CPEComponent):
36    """
37    Represents a generic logical component of CPE name,
38    compatible with the components of all versions of CPE specification.
39    """
40
41    ###############
42    #  CONSTANTS  #
43    ###############
44
45    # Logical values in integer format
46
47    #: Value of an undefined component. For example, edition attribute in the
48    #: CPE name cpe:/cisco::2345 of version 1.1 of CPE specification
49    _VALUE_INT_UNDEFINED = -1
50
51    #: Value of an empty component. For example, product attribute in the
52    #: CPE name cpe:/cisco::2345 of version 1.1 of CPE specification
53    _VALUE_INT_EMPTY = 0
54
55    #: Value of a component "any value". For example, product attribute in the
56    #: CPE name cpe:/h:cisco:*:2345 of version 2.3 of CPE specification
57    _VALUE_INT_ANY = 1
58
59    #: Value of a not applicable component. For example, product attribute in
60    #: the CPE name cpe:/h:cisco:-:2345 of version 2.3 of CPE specification
61    _VALUE_INT_NA = 2
62
63    ####################
64    #  OBJECT METHODS  #
65    ####################
66
67    def __contains__(self, item):
68        """
69        Returns True if item is included in set of values of self.
70
71        :param CPEComponent item: component to find in self
72        :returns: True if item is included in set of self
73        :rtype: boolean
74        """
75
76        return True
77
78    def __eq__(self, other):
79        """
80        Returns True if other (first element of operation) and
81        self (second element of operation) are equal components,
82        false otherwise.
83
84        :param CPEComponent other: component to compare
85        :returns: True if other == self, False otherwise
86        :rtype: boolean
87        :exception: NotImplementedError - class method not implemented
88        """
89
90        errmsg = "Class method not implemented. Use the method of some child class"
91        raise NotImplementedError(errmsg)
92
93    def __str__(self):
94        """
95        Returns a human-readable representation of CPE component.
96
97        :returns: Representation of CPE component as string
98        :rtype: string
99        :exception: NotImplementedError - class method not implemented
100        """
101
102        errmsg = "Class method not implemented. Use the method of some child class"
103        raise NotImplementedError(errmsg)
104
105if __name__ == "__main__":
106    import doctest
107    doctest.testmod()
108    doctest.testfile('../tests/testfile_cpecomp_logical.txt')
109