CPE class¶
- class cpe.cpe.CPE(cpe_str, *args, **kwargs)[source]¶
Represents a generic CPE Name compatible with all versions of CPE specification.
Parts of CPE are stored in a dictionary.
- CPE structure (dictionary):
- └─ part {hw, os, sw, undefined}
- └─ element list (list)
- └─ component list (dictionary)
- CPE_PART_KEYS = ('hw', 'os', 'app', 'undef')¶
List of keys associated with the types of system included in CPE specification
- KEY_APP = 'app'¶
Type of system “application”
- KEY_HW = 'hw'¶
Type of system “hardware”
- KEY_OS = 'os'¶
Type of system “operating system”
- KEY_UNDEFINED = 'undef'¶
Undefined type of system
- VERSION = 'undefined'¶
Version of CPE Name
- VERSION_1_1 = '1.1'¶
Version 1.1 of CPE specification
- VERSION_2_2 = '2.2'¶
Version 2.2 of CPE specification
- VERSION_2_3 = '2.3'¶
Version 2.3 of CPE specification
- VERSION_UNDEFINED = 'undefined'¶
Version not set
- __eq__(other)[source]¶
Returns True if other (first element of operation) and self (second element of operation) are equal CPE Names, false otherwise.
Parameters: other (CPE) – CPE Name to compare Returns: True if other == self, False otherwise Return type: boolean
- __getitem__(i)[source]¶
Returns the i’th component name of CPE Name.
Parameters: i (int) – component index to find Returns: component string found Return type: CPEComponent Exception: IndexError - index not found in CPE Name TEST: good index
>>> str = 'cpe:///sun_microsystem:sun@os:5.9:#update' >>> c = CPE(str) >>> c[0] CPEComponent1_1(sun_microsystem)
- __init__(cpe_str, *args, **kwargs)[source]¶
Store the CPE Name.
Parameters: cpe_str (string) – CPE Name Returns: None
- __len__()[source]¶
Returns the number of components of CPE Name.
Returns: count of components of CPE Name Return type: int TEST: a CPE Name with two parts (hw and os) and some elements empty and with values
>>> str = "cpe:/cisco::3825/cisco:ios:12.3" >>> c = CPE(str) >>> len(c) 6
- static __new__(cpe_str, version=None, *args, **kwargs)[source]¶
Generator of CPE Names.
Parameters: Returns: CPE object with version of CPE detected correctly
Return type: CPE
Exception: NotImplementedError - incorrect CPE Name or version of CPE not implemented
This class implements the factory pattern, that is, this class centralizes the creation of objects of a particular CPE version, hiding the user the requested object instance.
- __repr__()[source]¶
Returns a unambiguous representation of CPE Name.
Returns: Representation of CPE Name as string Return type: string
- __str__()[source]¶
Returns a human-readable representation of CPE Name.
Returns: Representation of CPE Name as string Return type: string
- __weakref__¶
list of weak references to the object (if defined)
- as_dict()[source]¶
Returns the CPE Name dict as string.
Returns: CPE Name dict as string Return type: string
- as_fs()[source]¶
Returns the CPE Name as formatted string of version 2.3.
Returns: CPE Name as formatted string Return type: string Exception: TypeError - incompatible version
- as_uri_2_3()[source]¶
Returns the CPE Name as URI string of version 2.3.
Returns: CPE Name as URI string of version 2.3 Return type: string Exception: TypeError - incompatible version
- as_wfn()[source]¶
Returns the CPE Name as Well-Formed Name string of version 2.3.
Returns: CPE Name as WFN string Return type: string Exception: TypeError - incompatible version
- get_edition()[source]¶
Returns the edition of product of CPE Name as a list. According to the CPE version, this list can contains one or more items.
Returns: Value of edition attribute as string list. Return type: list
- get_language()[source]¶
Returns the internationalization information of CPE Name as a list. According to the CPE version, this list can contains one or more items.
Returns: Value of language attribute as string list. Return type: list
- get_other()[source]¶
Returns the other information part of CPE Name.
Returns: Value of other attribute as string list. Return type: list
- get_part()[source]¶
Returns the part component of CPE Name as a list. According to the CPE version, this list can contains one or more items.
Returns: Value of part attribute as string list. Return type: list
- get_product()[source]¶
Returns the product name of CPE Name as a list. According to the CPE version, this list can contains one or more items.
Returns: Value of product attribute as string list. Return type: list
- get_software_edition()[source]¶
Returns the software edition of CPE Name.
Returns: Value of sw_edition attribute as string list. Return type: list
- get_target_hardware()[source]¶
Returns the arquitecture of CPE Name.
Returns: Value of target_hw attribute as string list. Return type: list
- get_target_software()[source]¶
Returns the software computing environment of CPE Name within which the product operates.
Returns: Value of target_sw attribute as string list. Return type: list
- get_update()[source]¶
Returns the update or service pack information of CPE Name as a list. According to the CPE version, this list can contains one or more items.
Returns: Value of update attribute as string list. Return type: list
- get_vendor()[source]¶
Returns the vendor name of CPE Name as a list. According to the CPE version, this list can contains one or more items.
Returns: Value of vendor attribute as string list. Return type: list
- get_version()[source]¶
Returns the version of product of CPE Name as a list. According to the CPE version, this list can contains one or more items.
Returns: Value of version attribute as string list. Return type: list
- is_application()[source]¶
Returns True if CPE Name corresponds to application elem.
Returns: True if CPE Name corresponds to application elem, False otherwise. Return type: boolean