1 # Copyright (c) 2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 from urlparse import urlsplit
19 from urllib.parse import urlsplit
22 def do_prefix_to_netmask(arg):
23 return '.'.join(str((0xffffffff << (32 - int(arg)) >> i) & 0xff) for i in
27 def do_netmask_to_prefix(arg):
28 return sum([bin(int(x)).count('1') for x in arg.split('.')])
35 class FilterModule(object):
38 'prefix_to_netmask': do_prefix_to_netmask,
39 'netmask_to_prefix': do_netmask_to_prefix,
40 'urlsplit': do_urlsplit,