def _parse_community (self, scope, data): separator = data.find(':') if separator > 0: prefix = int(data[:separator]) suffix = int(data[separator+1:]) if prefix >= pow(2,16): raise ValueError('invalid community %s (prefix too large)' % data) if suffix >= pow(2,16): raise ValueError('invalid community %s (suffix too large)' % data) return Community.cached(pack('!L',(prefix << 16) + suffix)) elif len(data) >= 2 and data[1] in 'xX': value = long(data,16) if value >= pow(2,32): raise ValueError('invalid community %s (too large)' % data) return Community.cached(pack('!L',value)) else: low = data.lower() if low == 'no-export': return Community.cached(Community.NO_EXPORT) elif low == 'no-advertise': return Community.cached(Community.NO_ADVERTISE) elif low == 'no-export-subconfed': return Community.cached(Community.NO_EXPORT_SUBCONFED) # no-peer is not a correct syntax but I am sure someone will make the mistake :) elif low == 'nopeer' or low == 'no-peer': return Community.cached(Community.NO_PEER) elif data.isdigit(): value = long(data) if value >= pow(2,32): raise ValueError('invalid community %s (too large)' % data) # return Community.cached(pack('!L',value)) return Community.cached(pack('!L',value)) else: raise ValueError('invalid community name %s' % data)
def _parse_community(self, scope, data): separator = data.find(':') if separator > 0: prefix = int(data[:separator]) suffix = int(data[separator + 1:]) if prefix >= pow(2, 16): raise ValueError('invalid community %s (prefix too large)' % data) if suffix >= pow(2, 16): raise ValueError('invalid community %s (suffix too large)' % data) return Community.cached(pack('!L', (prefix << 16) + suffix)) elif len(data) >= 2 and data[1] in 'xX': value = long(data, 16) if value >= pow(2, 32): raise ValueError('invalid community %s (too large)' % data) return Community.cached(pack('!L', value)) else: low = data.lower() if low == 'no-export': return Community.cached(Community.NO_EXPORT) elif low == 'no-advertise': return Community.cached(Community.NO_ADVERTISE) elif low == 'no-export-subconfed': return Community.cached(Community.NO_EXPORT_SUBCONFED) # no-peer is not a correct syntax but I am sure someone will make the mistake :) elif low == 'nopeer' or low == 'no-peer': return Community.cached(Community.NO_PEER) elif data.isdigit(): value = long(data) if value >= pow(2, 32): raise ValueError('invalid community %s (too large)' % data) # return Community.cached(pack('!L',value)) return Community.cached(pack('!L', value)) else: raise ValueError('invalid community name %s' % data)