David Reid | dcf62db | 2013-11-18 13:02:00 -0800 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | # you may not use this file except in compliance with the License. |
| 3 | # You may obtain a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 10 | # implied. |
| 11 | # See the License for the specific language governing permissions and |
| 12 | # limitations under the License. |
| 13 | |
| 14 | from __future__ import absolute_import, division, print_function |
| 15 | |
Mohammed Attia | cd2a1a8 | 2014-03-05 21:54:06 +0200 | [diff] [blame] | 16 | import sys |
| 17 | |
David Reid | dcf62db | 2013-11-18 13:02:00 -0800 | [diff] [blame] | 18 | |
Paul Kehrer | 62e5003 | 2014-05-03 10:06:57 -0500 | [diff] [blame] | 19 | DeprecatedIn04 = DeprecationWarning |
Paul Kehrer | dc378d1 | 2014-04-02 17:55:46 -0500 | [diff] [blame] | 20 | |
| 21 | |
David Reid | dcf62db | 2013-11-18 13:02:00 -0800 | [diff] [blame] | 22 | def register_interface(iface): |
| 23 | def register_decorator(klass): |
| 24 | iface.register(klass) |
| 25 | return klass |
| 26 | return register_decorator |
Mohammed Attia | cd2a1a8 | 2014-03-05 21:54:06 +0200 | [diff] [blame] | 27 | |
| 28 | |
| 29 | def bit_length(x): |
| 30 | if sys.version_info >= (2, 7): |
| 31 | return x.bit_length() |
| 32 | else: |
| 33 | return len(bin(x)) - (2 + (x <= 0)) |