### Navigation

- index
- modules |
- CCHR 1.0 documentation »

# `Utility Functions`

`src.util.``key_as_str`(value, inner_trim=True)

  Produces a key value for looking up in a crosswalk.

  If value is None than returns an empty string. >>> v = None >>> key_as_str(v) + ‘XXX’ XXX

  If value is a basestring removes leading and trailing whitespace if inner_trim = True, multiple line spaces made into one space, value is lowered: >>> v = ‘ DS sS ‘ >>> key_as_str(v) ds ss

  If inner_trime is false just strim leading and trailing and lower >>> v = ‘ DF sdsD’ >>> v df sdsd

`src.util.``check_file`(file_path, as_dir=False)

  Helper function to check if file or directory is valid.

`src.util.``calc`(expr, advanced=False)

`src.util.``re_escape`(value)

  Escape a regular expression.

      >>> re_escape(ab(#))
      u'ab\((\d+|#\d+|#)\)'

`src.util.``get_state_key`(value)

`src.util.``get_cnxn`(db_name, opt)

`src.util.``get_conv_cnxn`(db_name, opt)

`src.util.``is_file`(file_path)

`src.util.``is_none`(value)

`src.util.``memoize`(func)

  This function integrates memoization, an optimization technique, into cardsharp. Memoize wraps a function with a single argument. When it is called the first time, the result is cached with the argument as the key. If it is called in the future with the same argument, it returns the cached value.

      >>> from random import random
      >>> func = lambda x: random()
      >>> func(1) == func(1)
      False
      >>> func = memoize(func)
      >>> func(1) == func(1)
      True

`src.util.``str_to_boolean`(s)

  Converts a string to a boolean.

  1 | True |
  true | True |
  0 | False |
  false | False |

  If s is None returns None instead.

      >>> str_to_boolean('1')
      True
      >>> str_to_boolean(0)
      False
      >>> str_to_boolean('  FAlse  ')
      False
      >>> str_to_boolean('3')
      Traceback (most recent call last):
          ...
      FormatError: Invalid input data, 3: must be true, false, 1 or 0

`src.util.``get_state_name`(value)

`src.util.``get_max_review_round`(segment, region, set=1, **kw)

`src.util.``copy_to_review`(name, region, orig_path)

  Copy output file to review directory and return the path to the review directory

`src.util.``set_LOOKUPS`(db_info)

`src.util.``check_format`(format)

  Helper funtion to ensure that cradsharp is able to handle the format arg.

`src.util.``capture_input`(text, float_range=None, int_range=None, str_opt=None, open=None, default=None, as_tuple=False, as_list=False, allow_int=False, as_bool=False, **kw)

`src.util.``get_hash`(key)

`src.``util`

  alias of `src.util`

### Navigation

- index
- modules |
- CCHR 1.0 documentation »