Python pyasn1.compat.octets.isStringType() Examples

The following are 30 code examples of pyasn1.compat.octets.isStringType(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyasn1.compat.octets , or try the search function .
Example #1
Source File: univ.py    From learn_python3_spider with MIT License 6 votes vote down vote up
def __getitem__(self, idx):
        if octets.isStringType(idx):
            try:
                return self.getComponentByName(idx)

            except error.PyAsn1Error:
                # duck-typing dict
                raise KeyError(sys.exc_info()[1])

        else:
            try:
                return self.getComponentByPosition(idx)

            except error.PyAsn1Error:
                # duck-typing list
                raise IndexError(sys.exc_info()[1]) 
Example #2
Source File: univ.py    From aws-kube-codesuite with Apache License 2.0 6 votes vote down vote up
def __setitem__(self, idx, value):
        if octets.isStringType(idx):
            try:
                self.setComponentByName(idx, value)

            except error.PyAsn1Error:
                # duck-typing dict
                raise KeyError(sys.exc_info()[1])

        else:
            try:
                self.setComponentByPosition(idx, value)

            except error.PyAsn1Error:
                # duck-typing list
                raise IndexError(sys.exc_info()[1]) 
Example #3
Source File: univ.py    From aws-kube-codesuite with Apache License 2.0 6 votes vote down vote up
def __getitem__(self, idx):
        if octets.isStringType(idx):
            try:
                return self.getComponentByName(idx)

            except error.PyAsn1Error:
                # duck-typing dict
                raise KeyError(sys.exc_info()[1])

        else:
            try:
                return self.getComponentByPosition(idx)

            except error.PyAsn1Error:
                # duck-typing list
                raise IndexError(sys.exc_info()[1]) 
Example #4
Source File: univ.py    From luci-py with Apache License 2.0 6 votes vote down vote up
def __setitem__(self, idx, value):
        if octets.isStringType(idx):
            try:
                self.setComponentByName(idx, value)

            except error.PyAsn1Error:
                # duck-typing dict
                raise KeyError(sys.exc_info()[1])

        else:
            try:
                self.setComponentByPosition(idx, value)

            except error.PyAsn1Error:
                # duck-typing list
                raise IndexError(sys.exc_info()[1]) 
Example #5
Source File: univ.py    From luci-py with Apache License 2.0 6 votes vote down vote up
def __getitem__(self, idx):
        if octets.isStringType(idx):
            try:
                return self.getComponentByName(idx)

            except error.PyAsn1Error:
                # duck-typing dict
                raise KeyError(sys.exc_info()[1])

        else:
            try:
                return self.getComponentByPosition(idx)

            except error.PyAsn1Error:
                # duck-typing list
                raise IndexError(sys.exc_info()[1]) 
Example #6
Source File: univ.py    From bash-lambda-layer with MIT License 6 votes vote down vote up
def __setitem__(self, idx, value):
        if octets.isStringType(idx):
            try:
                self.setComponentByName(idx, value)

            except error.PyAsn1Error:
                # duck-typing dict
                raise KeyError(sys.exc_info()[1])

        else:
            try:
                self.setComponentByPosition(idx, value)

            except error.PyAsn1Error:
                # duck-typing list
                raise IndexError(sys.exc_info()[1]) 
Example #7
Source File: univ.py    From bash-lambda-layer with MIT License 6 votes vote down vote up
def __getitem__(self, idx):
        if octets.isStringType(idx):
            try:
                return self.getComponentByName(idx)

            except error.PyAsn1Error:
                # duck-typing dict
                raise KeyError(sys.exc_info()[1])

        else:
            try:
                return self.getComponentByPosition(idx)

            except error.PyAsn1Error:
                # duck-typing list
                raise IndexError(sys.exc_info()[1]) 
Example #8
Source File: univ.py    From learn_python3_spider with MIT License 6 votes vote down vote up
def __setitem__(self, idx, value):
        if octets.isStringType(idx):
            try:
                self.setComponentByName(idx, value)

            except error.PyAsn1Error:
                # duck-typing dict
                raise KeyError(sys.exc_info()[1])

        else:
            try:
                self.setComponentByPosition(idx, value)

            except error.PyAsn1Error:
                # duck-typing list
                raise IndexError(sys.exc_info()[1]) 
Example #9
Source File: univ.py    From teleport with Apache License 2.0 6 votes vote down vote up
def __setitem__(self, idx, value):
        if octets.isStringType(idx):
            try:
                self.setComponentByName(idx, value)

            except error.PyAsn1Error:
                # duck-typing dict
                raise KeyError(sys.exc_info()[1])

        else:
            try:
                self.setComponentByPosition(idx, value)

            except error.PyAsn1Error:
                # duck-typing list
                raise IndexError(sys.exc_info()[1]) 
Example #10
Source File: univ.py    From teleport with Apache License 2.0 6 votes vote down vote up
def __getitem__(self, idx):
        if octets.isStringType(idx):
            try:
                return self.getComponentByName(idx)

            except error.PyAsn1Error:
                # duck-typing dict
                raise KeyError(sys.exc_info()[1])

        else:
            try:
                return self.getComponentByPosition(idx)

            except error.PyAsn1Error:
                # duck-typing list
                raise IndexError(sys.exc_info()[1]) 
Example #11
Source File: univ.py    From teleport with Apache License 2.0 6 votes vote down vote up
def __setitem__(self, idx, value):
        if octets.isStringType(idx):
            try:
                self.setComponentByName(idx, value)

            except error.PyAsn1Error:
                # duck-typing dict
                raise KeyError(sys.exc_info()[1])

        else:
            try:
                self.setComponentByPosition(idx, value)

            except error.PyAsn1Error:
                # duck-typing list
                raise IndexError(sys.exc_info()[1]) 
Example #12
Source File: univ.py    From teleport with Apache License 2.0 6 votes vote down vote up
def __getitem__(self, idx):
        if octets.isStringType(idx):
            try:
                return self.getComponentByName(idx)

            except error.PyAsn1Error:
                # duck-typing dict
                raise KeyError(sys.exc_info()[1])

        else:
            try:
                return self.getComponentByPosition(idx)

            except error.PyAsn1Error:
                # duck-typing list
                raise IndexError(sys.exc_info()[1]) 
Example #13
Source File: univ.py    From teleport with Apache License 2.0 6 votes vote down vote up
def __setitem__(self, idx, value):
        if octets.isStringType(idx):
            try:
                self.setComponentByName(idx, value)

            except error.PyAsn1Error:
                # duck-typing dict
                raise KeyError(sys.exc_info()[1])

        else:
            try:
                self.setComponentByPosition(idx, value)

            except error.PyAsn1Error:
                # duck-typing list
                raise IndexError(sys.exc_info()[1]) 
Example #14
Source File: univ.py    From teleport with Apache License 2.0 6 votes vote down vote up
def __getitem__(self, idx):
        if octets.isStringType(idx):
            try:
                return self.getComponentByName(idx)

            except error.PyAsn1Error:
                # duck-typing dict
                raise KeyError(sys.exc_info()[1])

        else:
            try:
                return self.getComponentByPosition(idx)

            except error.PyAsn1Error:
                # duck-typing list
                raise IndexError(sys.exc_info()[1]) 
Example #15
Source File: univ.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
def prettyIn(self, value):
        if not octets.isStringType(value):
            try:
                return int(value)
            except:
                raise error.PyAsn1Error(
                    'Can\'t coerce %r into integer: %s' % (value, sys.exc_info()[1])
                )
        r = self.__namedValues.getValue(value)
        if r is not None:
            return r
        try:
            return int(value)
        except:
            raise error.PyAsn1Error(
                'Can\'t coerce %r into integer: %s' % (value, sys.exc_info()[1])
            ) 
Example #16
Source File: univ.py    From pelisalacarta-ce with GNU General Public License v3.0 5 votes vote down vote up
def prettyIn(self, value):
        """Dotted -> tuple of numerics OID converter"""
        if isinstance(value, tuple):
            pass
        elif isinstance(value, ObjectIdentifier):
            return tuple(value)        
        elif octets.isStringType(value):
            r = []
            for element in [ x for x in value.split('.') if x != '' ]:
                try:
                    r.append(int(element, 0))
                except ValueError:
                    raise error.PyAsn1Error(
                        'Malformed Object ID %s at %s: %s' %
                        (str(value), self.__class__.__name__, sys.exc_info()[1])
                        )
            value = tuple(r)
        else:
            try:
                value = tuple(value)
            except TypeError:
                raise error.PyAsn1Error(
                        'Malformed Object ID %s at %s: %s' %
                        (str(value), self.__class__.__name__,sys.exc_info()[1])
                        )

        for x in value:
            if not isinstance(x, intTypes) or x < 0:
                raise error.PyAsn1Error(
                    'Invalid sub-ID in %s at %s' % (value, self.__class__.__name__)
                    )
    
        return value 
Example #17
Source File: univ.py    From teleport with Apache License 2.0 5 votes vote down vote up
def prettyIn(self, value):
        if isinstance(value, ObjectIdentifier):
            return tuple(value)
        elif octets.isStringType(value):
            if '-' in value:
                raise error.PyAsn1Error(
                    'Malformed Object ID %s at %s: %s' % (value, self.__class__.__name__, sys.exc_info()[1])
                )
            try:
                return tuple([int(subOid) for subOid in value.split('.') if subOid])
            except ValueError:
                raise error.PyAsn1Error(
                    'Malformed Object ID %s at %s: %s' % (value, self.__class__.__name__, sys.exc_info()[1])
                )

        try:
            tupleOfInts = tuple([int(subOid) for subOid in value if subOid >= 0])

        except (ValueError, TypeError):
            raise error.PyAsn1Error(
                'Malformed Object ID %s at %s: %s' % (value, self.__class__.__name__, sys.exc_info()[1])
            )

        if len(tupleOfInts) == len(value):
            return tupleOfInts

        raise error.PyAsn1Error('Malformed Object ID %s at %s' % (value, self.__class__.__name__)) 
Example #18
Source File: univ.py    From scalyr-agent-2 with Apache License 2.0 5 votes vote down vote up
def prettyIn(self, value):
        """Dotted -> tuple of numerics OID converter"""
        if isinstance(value, tuple):
            pass
        elif isinstance(value, ObjectIdentifier):
            return tuple(value)        
        elif octets.isStringType(value):
            r = []
            for element in [ x for x in value.split('.') if x != '' ]:
                try:
                    r.append(int(element, 0))
                except ValueError:
                    raise error.PyAsn1Error(
                        'Malformed Object ID %s at %s: %s' %
                        (str(value), self.__class__.__name__, sys.exc_info()[1])
                        )
            value = tuple(r)
        else:
            try:
                value = tuple(value)
            except TypeError:
                raise error.PyAsn1Error(
                        'Malformed Object ID %s at %s: %s' %
                        (str(value), self.__class__.__name__,sys.exc_info()[1])
                        )

        for x in value:
            if not isinstance(x, intTypes) or x < 0:
                raise error.PyAsn1Error(
                    'Invalid sub-ID in %s at %s' % (value, self.__class__.__name__)
                    )
    
        return value 
Example #19
Source File: univ.py    From addon with GNU General Public License v3.0 5 votes vote down vote up
def prettyIn(self, value):
        """Dotted -> tuple of numerics OID converter"""
        if isinstance(value, tuple):
            pass
        elif isinstance(value, ObjectIdentifier):
            return tuple(value)        
        elif octets.isStringType(value):
            r = []
            for element in [ x for x in value.split('.') if x != '' ]:
                try:
                    r.append(int(element, 0))
                except ValueError:
                    raise error.PyAsn1Error(
                        'Malformed Object ID %s at %s: %s' %
                        (str(value), self.__class__.__name__, sys.exc_info()[1])
                        )
            value = tuple(r)
        else:
            try:
                value = tuple(value)
            except TypeError:
                raise error.PyAsn1Error(
                        'Malformed Object ID %s at %s: %s' %
                        (str(value), self.__class__.__name__,sys.exc_info()[1])
                        )

        for x in value:
            if not isinstance(x, intTypes) or x < 0:
                raise error.PyAsn1Error(
                    'Invalid sub-ID in %s at %s' % (value, self.__class__.__name__)
                    )
    
        return value 
Example #20
Source File: univ.py    From xbmc-addons-chinese with GNU General Public License v2.0 5 votes vote down vote up
def prettyIn(self, value):
        """Dotted -> tuple of numerics OID converter"""
        if isinstance(value, tuple):
            pass
        elif isinstance(value, ObjectIdentifier):
            return tuple(value)        
        elif octets.isStringType(value):
            r = []
            for element in [ x for x in value.split('.') if x != '' ]:
                try:
                    r.append(int(element, 0))
                except ValueError:
                    raise error.PyAsn1Error(
                        'Malformed Object ID %s at %s: %s' %
                        (str(value), self.__class__.__name__, sys.exc_info()[1])
                        )
            value = tuple(r)
        else:
            try:
                value = tuple(value)
            except TypeError:
                raise error.PyAsn1Error(
                        'Malformed Object ID %s at %s: %s' %
                        (str(value), self.__class__.__name__,sys.exc_info()[1])
                        )

        for x in value:
            if not isinstance(x, intTypes) or x < 0:
                raise error.PyAsn1Error(
                    'Invalid sub-ID in %s at %s' % (value, self.__class__.__name__)
                    )
    
        return value 
Example #21
Source File: univ.py    From luci-py with Apache License 2.0 5 votes vote down vote up
def prettyIn(self, value):
        if isinstance(value, ObjectIdentifier):
            return tuple(value)
        elif octets.isStringType(value):
            if '-' in value:
                raise error.PyAsn1Error(
                    'Malformed Object ID %s at %s: %s' % (value, self.__class__.__name__, sys.exc_info()[1])
                )
            try:
                return tuple([int(subOid) for subOid in value.split('.') if subOid])
            except ValueError:
                raise error.PyAsn1Error(
                    'Malformed Object ID %s at %s: %s' % (value, self.__class__.__name__, sys.exc_info()[1])
                )

        try:
            tupleOfInts = tuple([int(subOid) for subOid in value if subOid >= 0])

        except (ValueError, TypeError):
            raise error.PyAsn1Error(
                'Malformed Object ID %s at %s: %s' % (value, self.__class__.__name__, sys.exc_info()[1])
            )

        if len(tupleOfInts) == len(value):
            return tupleOfInts

        raise error.PyAsn1Error('Malformed Object ID %s at %s' % (value, self.__class__.__name__)) 
Example #22
Source File: univ.py    From luci-py with Apache License 2.0 5 votes vote down vote up
def prettyIn(self, value):
        if isinstance(value, tuple) and len(value) == 3:
            if (not isinstance(value[0], numericTypes) or
                    not isinstance(value[1], intTypes) or
                    not isinstance(value[2], intTypes)):
                raise error.PyAsn1Error('Lame Real value syntax: %s' % (value,))
            if (isinstance(value[0], float) and
                    self._inf and value[0] in self._inf):
                return value[0]
            if value[1] not in (2, 10):
                raise error.PyAsn1Error(
                    'Prohibited base for Real value: %s' % (value[1],)
                )
            if value[1] == 10:
                value = self.__normalizeBase10(value)
            return value
        elif isinstance(value, intTypes):
            return self.__normalizeBase10((value, 10, 0))
        elif isinstance(value, float) or octets.isStringType(value):
            if octets.isStringType(value):
                try:
                    value = float(value)
                except ValueError:
                    raise error.PyAsn1Error(
                        'Bad real value syntax: %s' % (value,)
                    )
            if self._inf and value in self._inf:
                return value
            else:
                e = 0
                while int(value) != value:
                    value *= 10
                    e -= 1
                return self.__normalizeBase10((int(value), 10, e))
        elif isinstance(value, Real):
            return tuple(value)
        raise error.PyAsn1Error(
            'Bad real value syntax: %s' % (value,)
        ) 
Example #23
Source File: univ.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def prettyIn(self, value):
        if isinstance(value, tuple):
            pass
        elif isinstance(value, ObjectIdentifier):
            return tuple(value)
        elif octets.isStringType(value):
            r = []
            for element in [x for x in value.split('.') if x != '']:
                try:
                    r.append(int(element, 0))
                except ValueError:
                    raise error.PyAsn1Error(
                        'Malformed Object ID %s at %s: %s' %
                        (str(value), self.__class__.__name__, sys.exc_info()[1])
                    )
            value = tuple(r)
        else:
            try:
                value = tuple(value)
            except TypeError:
                raise error.PyAsn1Error(
                    'Malformed Object ID %s at %s: %s' %
                    (str(value), self.__class__.__name__, sys.exc_info()[1])
                )

        for x in value:
            if not isinstance(x, intTypes) or x < 0:
                raise error.PyAsn1Error(
                    'Invalid sub-ID in %s at %s' % (value, self.__class__.__name__)
                )

        return value 
Example #24
Source File: univ.py    From plugin.video.bdyun with GNU General Public License v3.0 5 votes vote down vote up
def prettyIn(self, value):
        """Dotted -> tuple of numerics OID converter"""
        if isinstance(value, tuple):
            pass
        elif isinstance(value, ObjectIdentifier):
            return tuple(value)        
        elif octets.isStringType(value):
            r = []
            for element in [ x for x in value.split('.') if x != '' ]:
                try:
                    r.append(int(element, 0))
                except ValueError:
                    raise error.PyAsn1Error(
                        'Malformed Object ID %s at %s: %s' %
                        (str(value), self.__class__.__name__, sys.exc_info()[1])
                        )
            value = tuple(r)
        else:
            try:
                value = tuple(value)
            except TypeError:
                raise error.PyAsn1Error(
                        'Malformed Object ID %s at %s: %s' %
                        (str(value), self.__class__.__name__,sys.exc_info()[1])
                        )

        for x in value:
            if not isinstance(x, intTypes) or x < 0:
                raise error.PyAsn1Error(
                    'Invalid sub-ID in %s at %s' % (value, self.__class__.__name__)
                    )
    
        return value 
Example #25
Source File: univ.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def prettyIn(self, value):
        if isinstance(value, tuple) and len(value) == 3:
            if not isinstance(value[0], numericTypes) or \
                    not isinstance(value[1], intTypes) or \
                    not isinstance(value[2], intTypes):
                raise error.PyAsn1Error('Lame Real value syntax: %s' % (value,))
            if isinstance(value[0], float) and \
                    self._inf and value[0] in self._inf:
                return value[0]
            if value[1] not in (2, 10):
                raise error.PyAsn1Error(
                    'Prohibited base for Real value: %s' % (value[1],)
                )
            if value[1] == 10:
                value = self.__normalizeBase10(value)
            return value
        elif isinstance(value, intTypes):
            return self.__normalizeBase10((value, 10, 0))
        elif isinstance(value, float) or octets.isStringType(value):
            if octets.isStringType(value):
                try:
                    value = float(value)
                except ValueError:
                    raise error.PyAsn1Error(
                        'Bad real value syntax: %s' % (value,)
                    )
            if self._inf and value in self._inf:
                return value
            else:
                e = 0
                while int(value) != value:
                    value *= 10
                    e -= 1
                return self.__normalizeBase10((int(value), 10, e))
        elif isinstance(value, Real):
            return tuple(value)
        raise error.PyAsn1Error(
            'Bad real value syntax: %s' % (value,)
        ) 
Example #26
Source File: univ.py    From xunfengES with GNU General Public License v3.0 5 votes vote down vote up
def prettyIn(self, value):
        """Dotted -> tuple of numerics OID converter"""
        if isinstance(value, tuple):
            pass
        elif isinstance(value, ObjectIdentifier):
            return tuple(value)        
        elif octets.isStringType(value):
            r = []
            for element in [ x for x in value.split('.') if x != '' ]:
                try:
                    r.append(int(element, 0))
                except ValueError:
                    raise error.PyAsn1Error(
                        'Malformed Object ID %s at %s: %s' %
                        (str(value), self.__class__.__name__, sys.exc_info()[1])
                        )
            value = tuple(r)
        else:
            try:
                value = tuple(value)
            except TypeError:
                raise error.PyAsn1Error(
                        'Malformed Object ID %s at %s: %s' %
                        (str(value), self.__class__.__name__,sys.exc_info()[1])
                        )

        for x in value:
            if not isinstance(x, intTypes) or x < 0:
                raise error.PyAsn1Error(
                    'Invalid sub-ID in %s at %s' % (value, self.__class__.__name__)
                    )
    
        return value 
Example #27
Source File: univ.py    From xunfengES with GNU General Public License v3.0 5 votes vote down vote up
def prettyIn(self, value):
        """Dotted -> tuple of numerics OID converter"""
        if isinstance(value, tuple):
            pass
        elif isinstance(value, ObjectIdentifier):
            return tuple(value)        
        elif octets.isStringType(value):
            r = []
            for element in [ x for x in value.split('.') if x != '' ]:
                try:
                    r.append(int(element, 0))
                except ValueError:
                    raise error.PyAsn1Error(
                        'Malformed Object ID %s at %s: %s' %
                        (str(value), self.__class__.__name__, sys.exc_info()[1])
                        )
            value = tuple(r)
        else:
            try:
                value = tuple(value)
            except TypeError:
                raise error.PyAsn1Error(
                        'Malformed Object ID %s at %s: %s' %
                        (str(value), self.__class__.__name__,sys.exc_info()[1])
                        )

        for x in value:
            if not isinstance(x, intTypes) or x < 0:
                raise error.PyAsn1Error(
                    'Invalid sub-ID in %s at %s' % (value, self.__class__.__name__)
                    )
    
        return value 
Example #28
Source File: univ.py    From aws-kube-codesuite with Apache License 2.0 5 votes vote down vote up
def prettyIn(self, value):
        if isinstance(value, ObjectIdentifier):
            return tuple(value)
        elif octets.isStringType(value):
            if '-' in value:
                raise error.PyAsn1Error(
                    'Malformed Object ID %s at %s: %s' % (value, self.__class__.__name__, sys.exc_info()[1])
                )
            try:
                return tuple([int(subOid) for subOid in value.split('.') if subOid])
            except ValueError:
                raise error.PyAsn1Error(
                    'Malformed Object ID %s at %s: %s' % (value, self.__class__.__name__, sys.exc_info()[1])
                )

        try:
            tupleOfInts = tuple([int(subOid) for subOid in value if subOid >= 0])

        except (ValueError, TypeError):
            raise error.PyAsn1Error(
                'Malformed Object ID %s at %s: %s' % (value, self.__class__.__name__, sys.exc_info()[1])
            )

        if len(tupleOfInts) == len(value):
            return tupleOfInts

        raise error.PyAsn1Error('Malformed Object ID %s at %s' % (value, self.__class__.__name__)) 
Example #29
Source File: univ.py    From aws-kube-codesuite with Apache License 2.0 5 votes vote down vote up
def prettyIn(self, value):
        if isinstance(value, tuple) and len(value) == 3:
            if not isinstance(value[0], numericTypes) or \
                    not isinstance(value[1], intTypes) or \
                    not isinstance(value[2], intTypes):
                raise error.PyAsn1Error('Lame Real value syntax: %s' % (value,))
            if isinstance(value[0], float) and \
                    self._inf and value[0] in self._inf:
                return value[0]
            if value[1] not in (2, 10):
                raise error.PyAsn1Error(
                    'Prohibited base for Real value: %s' % (value[1],)
                )
            if value[1] == 10:
                value = self.__normalizeBase10(value)
            return value
        elif isinstance(value, intTypes):
            return self.__normalizeBase10((value, 10, 0))
        elif isinstance(value, float) or octets.isStringType(value):
            if octets.isStringType(value):
                try:
                    value = float(value)
                except ValueError:
                    raise error.PyAsn1Error(
                        'Bad real value syntax: %s' % (value,)
                    )
            if self._inf and value in self._inf:
                return value
            else:
                e = 0
                while int(value) != value:
                    value *= 10
                    e -= 1
                return self.__normalizeBase10((int(value), 10, e))
        elif isinstance(value, Real):
            return tuple(value)
        raise error.PyAsn1Error(
            'Bad real value syntax: %s' % (value,)
        ) 
Example #30
Source File: namedtype.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def __getitem__(self, idx):
        if octets.isStringType(idx):
            nameToPosIdx = self.__getNameToPosIdx()
            return self.__namedTypes[nameToPosIdx[idx]]
        else:
            return self.__namedTypes[idx]