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 empty 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
24For any problems using the cpe package, or general questions and
25feedback about it, please contact:
26
27- Alejandro Galindo García: galindo.garcia.alejandro@gmail.com
28- Roberto Abdelkader Martínez Pérez: robertomartinezp@gmail.com
29"""
30
31from .cpecomp_logical import CPEComponentLogical
32
33
34class CPEComponentEmpty(CPEComponentLogical):
35    """
36    Represents an empty component of CPE name,
37    compatible with the components of all versions of CPE specification.
38
39    For example, in version 1.1 of CPE specification, an empty component
40    is version attribute in CPE name cpe:/microsft:windows::sp2.
41    """
42
43    ####################
44    #  OBJECT METHODS  #
45    ####################
46
47    def __eq__(self, other):
48        """
49        Returns True if other (first element of operation) and
50        self (second element of operation) are equal components,
51        false otherwise.
52
53        :param CPEComponent other: component to compare
54        :returns: True if other == self, False otherwise
55        :rtype: boolean
56        """
57
58        from .cpecomp_anyvalue import CPEComponentAnyValue
59        from .cpecomp_undefined import CPEComponentUndefined
60
61        return (isinstance(other, CPEComponentEmpty) or
62                isinstance(other, CPEComponentUndefined) or
63                isinstance(other, CPEComponentAnyValue))
64
65    def __init__(self):
66        """
67        Initializes the component.
68        """
69
70        super(CPEComponentEmpty, self).__init__(
71            CPEComponentLogical._VALUE_INT_EMPTY)
72
73    def __str__(self):
74        """
75        Returns a human-readable representation of CPE component.
76
77        :returns: Representation of CPE component as string
78        :rtype: string
79        """
80
81        return "<EMPTY>"
82
83
84if __name__ == "__main__":
85    import doctest
86    doctest.testmod()
87    doctest.testfile('../tests/testfile_cpecomp_empty.txt')
88