1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5This file is part of cpe package.
6
7This module allows to create an undefined component of CPE name.
8
9Copyright (C) 2013  Alejandro Galindo García, Roberto Abdelkader Martínez Pérez
10
11This program is free software: you can redistribute it and/or modify
12it under the terms of the GNU Lesser General Public License as published by
13the Free Software Foundation, either version 3 of the License, or
14(at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU Lesser General Public License for more details.
20
21You should have received a copy of the GNU Lesser General Public License
22along with this program. If not, see <http://www.gnu.org/licenses/>.
23
24- Alejandro Galindo García: galindo.garcia.alejandro@gmail.com
25- Roberto Abdelkader Martínez Pérez: robertomartinezp@gmail.com
26"""
27
28from .cpecomp_logical import CPEComponentLogical
29
30
31class CPEComponentUndefined(CPEComponentLogical):
32    """
33    Represents an undefined component of CPE name,
34    compatible with the components of all versions of CPE specification.
35
36    For example, in version 1.1 of CPE specification, an undefined component
37    is edition attribute in CPE name cpe:/microsft:windows:xp.
38    """
39
40    ####################
41    #  OBJECT METHODS  #
42    ####################
43
44    def __contains__(self, item):
45        """
46        Returns True if item is included in set of values of self.
47
48        :param CPEComponent item: component to find in self
49        :returns: True if item is included in set of self
50        :rtype: boolean
51        """
52
53        return super(CPEComponentUndefined, self).__contains__(item)
54
55    def __eq__(self, other):
56        """
57        Returns True if other (first element of operation) and
58        self (second element of operation) are equal components,
59        false otherwise.
60
61        :param CPEComponent other: component to compare
62        :returns: True if other == self, False otherwise
63        """
64
65        from .cpecomp_anyvalue import CPEComponentAnyValue
66        from .cpecomp_empty import CPEComponentEmpty
67
68        return (isinstance(other, CPEComponentUndefined) or
69                isinstance(other, CPEComponentEmpty) or
70                isinstance(other, CPEComponentAnyValue))
71
72    def __init__(self):
73        """
74        Initializes the component.
75        """
76
77        super(CPEComponentUndefined, self).__init__(
78            CPEComponentLogical._VALUE_INT_UNDEFINED)
79
80    def __str__(self):
81        """
82        Returns a human-readable representation of CPE component.
83
84        :returns: Representation of CPE component as string
85        :rtype: string
86        """
87
88        return "<UNDEFINED>"
89
90if __name__ == "__main__":
91    import doctest
92    doctest.testmod()
93    doctest.testfile('../tests/testfile_cpecomp_undefined.txt')
94