backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / lib / port_no.py
1 # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
2 #
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
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
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
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # Internal representation of port_no id is int(32bit)
17 # string representation is in hex without '0x'
18
19 _PORT_NO_LEN = 8
20 _PORT_NO_FMT = '%0{0}x'.format(_PORT_NO_LEN)
21 PORT_NO_PATTERN = r'[0-9a-f]{%d}' % _PORT_NO_LEN
22
23
24 def port_no_to_str(port_no):
25     return _PORT_NO_FMT % port_no
26
27
28 def str_to_port_no(port_no_str):
29     assert len(port_no_str) == _PORT_NO_LEN
30     return int(port_no_str, 16)