yakumo.utils

Package yakumo :: Module utils |
[hide private]
[frames] | no frames]

# Source Code for Module yakumo.utils

     1  # Copyright 2014-2017 by Akira Yoshiyama <akirayoshiyama@gmail.com>.
     2  # All Rights Reserved.
     3  #
     4  #    Licensed under the Apache License, Version 2.0 (the "License"); you may
     5  #    not use this file except in compliance with the License. You may obtain
     6  #    a copy of the License at
     7  #
     8  #         http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  #    Unless required by applicable law or agreed to in writing, software
    11  #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    12  #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    13  #    License for the specific language governing permissions and limitations
    14  #    under the License.
    15
    16  """
    17  Miscellaneous functions/decorators
    18  """
    19
    20  import copy
    21  import functools
    22  import inspect
    23
    24
    25 -def join_path(*args):
    26      return '/'.join([str(x).strip('/') for x in args if x is not None])
    27
    28
    29 -def get_json_body(base, **params):
    30      data = {}
    31      if not params:
    32          return {base: None}
    33      for key, value in params.items():
    34          if value is not None:
    35              data[key] = value
    36      if not data:
    37          data = None
    38      return {base: data}
    39
    40
    41 -def str2bool(value):
    42      if value == u'true':
    43          return True
    44      if value == u'false':
    45          return False
    46
    47
    48 -def bool2str(value):
    49      if value is True:
    50          return u'true'
    51      if value is False:
    52          return u'false'
    53
    54
    55 -def gen_chunk(file):
    56      with open(file, 'rb') as f:
    57          while True:
    58              chunk = f.read(4096)
    59              if not chunk:
    60                  break
    61              yield chunk
    62