1 # -*- coding: utf-8 -*-
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
7 # https://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, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
15 """linebot.http_client module."""
17 from __future__ import unicode_literals
23 LOGGER = logging.getLogger('linebot')
25 PY3 = sys.version_info[0] == 3
28 def to_snake_case(text):
29 """Convert to snake case.
35 s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', text)
36 return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
39 def to_camel_case(text):
40 """Convert to camel case.
46 split = text.split('_')
47 return split[0] + "".join(x.title() for x in split[1:])
50 def safe_compare_digest(val1, val2):
51 """safe_compare_digest method.
53 :param val1: string or bytes for compare
54 :type val1: str | bytes
55 :param val2: string or bytes for compare
56 :type val2: str | bytes
58 if len(val1) != len(val2):
62 if PY3 and isinstance(val1, bytes) and isinstance(val2, bytes):
63 for i, j in zip(val1, val2):
66 for i, j in zip(val1, val2):
67 result |= (ord(i) ^ ord(j))