def parseAttributesFromFieldValueString(self):
        self._parameterNamesAndValueStrings = {}
        self._sipURI = None

        # noinspection PyBroadException
        try:
            match = self.__class__.regexForAngleBracketForm.match(self.fieldValueString)
            if match:
                # URI uses angle brackets
                uriAndParametersString = match.group(2)
                self._sipURI = SIPURI.newParsedFrom(uriAndParametersString)
                # noinspection PyUnusedLocal
                foo = self._sipURI.user  # We do this to make sure the sipURI gets parsed within our exception handler.
                headerFieldParametersString = match.group(3)
            else:
                # same logic as above, but work on sample, not uriAndParametersString.  This will be factored in the real solution.
                uriAndHeaderFieldParametersMatchGroups = self.__class__.regexForNonAngleBracketForm.match(self.fieldValueString).groups()
                uriString = uriAndHeaderFieldParametersMatchGroups[0]
                self._sipURI = SIPURI.newParsedFrom(uriString)
                # noinspection PyUnusedLocal
                foo = self._sipURI.user  # We do this to make sure the sipURI gets parsed within our exception handler.
                headerFieldParametersString = uriAndHeaderFieldParametersMatchGroups[1]
            self._parameterNamesAndValueStrings = dict(self.__class__.regexForFindingParameterNamesAndValues.findall(headerFieldParametersString))
            self._attributeHasBeenSet = True
        except Exception:
            self._isValid = False
        else:
            self._isValid = True
 def test_parseSetValuesAndReParse(self):
     uriString = 'sips:[email protected]:5061;user=phone'
     uri = SIPURI.newParsedFrom(uriString)
     self.assertEqual(uriString, uri.rawString)
     self.assertEqual(uri.host, '192.168.0.99')
     self.assertEqual(uri.port, 5061)
     self.assertEqual(uri.scheme, 'sips')
     self.assertEqual(uri.user, '8005551212')
     self.assertEqual(uri.parameterNamesAndValueStrings, {'user': '******'})
     self.assertEqual(uri.parameterNamed('user'), 'phone')
     self.assertEqual(uri.parameterNamed('nonExistentKey'), None)
     uri.parameterNamedPut('foo', 42)
     self.assertEqual('sips:[email protected]:5061;foo=42;user=phone', uri.rawString)
     uri.host = '192.168.0.100'
     self.assertEqual('sips:[email protected]:5061;foo=42;user=phone', uri.rawString)
     uri.port = 5062
     self.assertEqual('sips:[email protected]:5062;foo=42;user=phone', uri.rawString)
     uri.scheme = 'sip'
     self.assertEqual('sip:[email protected]:5062;foo=42;user=phone', uri.rawString)
     uri.user = '******'
     self.assertEqual('sip:[email protected]:5062;foo=42;user=phone', uri.rawString)
     uri.parameterNamesAndValueStrings = None
     self.assertEqual('sip:[email protected]:5062', uri.rawString)
     uri.parameterNamedPut('foo', 42)
     self.assertEqual('sip:[email protected]:5062;foo=42', uri.rawString)
     uri.rawString = uriString
     self.assertEqual(uriString, uri.rawString)
     self.assertEqual(uri.host, '192.168.0.99')
     self.assertEqual(uri.port, 5061)
     self.assertEqual(uri.scheme, 'sips')
     self.assertEqual(uri.user, '8005551212')
     self.assertEqual(uri.parameterNamesAndValueStrings, {'user': '******'})
     self.assertEqual(uri.parameterNamed('user'), 'phone')
     self.assertEqual(uri.parameterNamed('nonExistentKey'), None)
 def test_parseValid007(self):
     uriString = 'sips:192.168.0.99'
     uri = SIPURI.newParsedFrom(uriString)
     self.assertEqual(uriString, uri.rawString)
     self.assertEqual(uri.host, '192.168.0.99')
     self.assertEqual(uri.port, None)
     self.assertEqual(uri.scheme, 'sips')
     self.assertEqual(uri.user, None)
     self.assertEqual(uri.parameterNamesAndValueStrings, {})
     self.assertEqual(uri.parameterNamed('nonExistentKey'), None)
 def test_parseValid002(self):
     uriString = 'sips:[email protected]:5061;user=phone'
     uri = SIPURI.newParsedFrom(uriString)
     self.assertEqual(uriString, uri.rawString)
     self.assertEqual(uri.host, '192.168.0.99')
     self.assertEqual(uri.port, 5061)
     self.assertEqual(uri.scheme, 'sips')
     self.assertEqual(uri.user, '8005551212')
     self.assertEqual(uri.parameterNamesAndValueStrings, {'user': '******'})
     self.assertEqual(uri.parameterNamed('user'), 'phone')
     self.assertEqual(uri.parameterNamed('nonExistentKey'), None)