CPEComponent1_1 class

class cpe.comp.cpecomp1_1.CPEComponent1_1(comp_str, comp_att)[source]

Represents a component of version 1.1 of CPE specification.

TEST: simple value

>>> value = "microsoft"
>>> comp = CPEComponent1_1(value, CPEComponentSimple.ATT_VENDOR)
NON_STANDARD_VALUES = ['.', '-', ',', '(', ')', '@', '#']

Characters of version 1.1 of CPE name to convert to standard value (WFN value)

SEPARATOR_COMP = ':'

Separator of components of CPE name with URI style

VALUE_EMPTY = ''

Logical value associated with a component without value set

VALUE_UNDEFINED = None

Logical value associated with a undefined component of CPE Name

__contains__(item)[source]

Returns True if item is included in set of values of self.

Comparatives in name matching of version 1.1 of CPE:

c = self._standard_value
d = item._standard_value
IF c is empty THEN match True.
ELSE IF c is a singleton AND c = d THEN match True.
ELSE IF c has form ~v AND v != d THEN match True.
ELSE IF c has form v1!v2!..!vn AND v = d for some v THEN match True.
ENDIF.
Parameters:item (CPEComponent) – component to find in self
Returns:True if item is included in set of self
Return type:boolean

TEST: two different simple values

>>> comp1 = CPEComponent1_1('5.0', CPEComponentSimple.ATT_VERSION)
>>> comp2 = CPEComponent1_1('9.0', CPEComponentSimple.ATT_VERSION)
>>> comp1 in comp2
False
__repr__()[source]

Returns a unambiguous representation of CPE component.

Returns:Representation of CPE component as string
Return type:string
as_fs()[source]

Returns the value of compoment encoded as formatted string.

Inspect each character in value of component. Certain nonalpha characters pass thru without escaping into the result, but most retain escaping.

Returns:Formatted string associated with the component
Return type:string

TEST:

>>> val = 'xp!vista'
>>> comp1 = CPEComponent1_1(val, CPEComponentSimple.ATT_VERSION)
>>> comp1.as_fs()
'xp\\!vista'
as_uri_2_3()[source]

Returns the value of compoment encoded as URI string.

Scans an input string s and applies the following transformations:

  • Pass alphanumeric characters thru untouched
  • Percent-encode quoted non-alphanumerics as needed
  • Unquoted special characters are mapped to their special forms.
Returns:URI string
Return type:string

TEST:

>>> val = '#nvidi@'
>>> comp1 = CPEComponent1_1(val, CPEComponentSimple.ATT_VENDOR)
>>> comp1.as_uri_2_3()
'%23nvidi%40'
as_wfn()[source]

Returns the value of compoment encoded as Well-Formed Name (WFN) string.

Returns:WFN string
Return type:string

TEST:

>>> val = 'xp!vista'
>>> comp1 = CPEComponent1_1(val, CPEComponentSimple.ATT_VERSION)
>>> comp1.as_wfn()
'xp\\!vista'
set_value(comp_str, comp_att)[source]

Set the value of component. By default, the component has a simple value.

Parameters:comp_att (string) – attribute associated with value of component
Returns:None
Exception:ValueError - incorrect value of component

TEST:

>>> val = 'xp!vista'
>>> val2 = 'sp2'
>>> att = CPEComponentSimple.ATT_VERSION
>>> comp1 = CPEComponent1_1(val, att)
>>> comp1.set_value(val2, att)
>>> comp1.get_value()
'sp2'