CPEComponent1_1 class

class cpe.comp.cpecomp1_1.CPEComponent1_1(comp_str, comp_att)

Represents a component of version 1.1 of CPE specification.

TEST: simple value

>>> value = "microsoft"
>>> comp = CPEComponent1_1(value, CPEComponentSimple.ATT_VENDOR)
__contains__(item)

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

Returns a unambiguous representation of CPE component.

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

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

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

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)

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'