CPE class

class cpe.cpe.CPE(cpe_str, *args, **kwargs)

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)
__eq__(other)

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)

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)

Store the CPE Name.

Parameters:cpe_str (string) – CPE Name
Returns:None
__len__()

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__(cls, cpe_str, version=None, *args, **kwargs)

Generator of CPE Names.

Parameters:
  • cpe_str (string) – CPE Name string
  • version (string) – version of CPE specification of CPE Name
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__()

Returns a unambiguous representation of CPE Name.

Returns:Representation of CPE Name as string
Return type:string
__str__()

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()

Returns the CPE Name dict as string.

Returns:CPE Name dict as string
Return type:string
as_fs()

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()

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()

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()

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()

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()

Returns the other information part of CPE Name.

Returns:Value of other attribute as string list.
Return type:list
get_part()

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()

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()

Returns the software edition of CPE Name.

Returns:Value of sw_edition attribute as string list.
Return type:list
get_target_hardware()

Returns the arquitecture of CPE Name.

Returns:Value of target_hw attribute as string list.
Return type:list
get_target_software()

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()

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()

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()

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()

Returns True if CPE Name corresponds to application elem.

Returns:True if CPE Name corresponds to application elem, False otherwise.
Return type:boolean
is_hardware()

Returns True if CPE Name corresponds to hardware elem.

Returns:True if CPE Name corresponds to hardware elem, False otherwise.
Return type:boolean
is_operating_system()

Returns True if CPE Name corresponds to operating system elem.

Returns:True if CPE Name corresponds to operating system elem, False otherwise.
Return type:boolean