File: Utils.py

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,092 kB
  • sloc: python: 83,539; ansic: 18,831; cpp: 1,402; xml: 1,031; javascript: 511; makefile: 403; sh: 204; sed: 11
file content (36 lines) | stat: -rw-r--r-- 1,065 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import copy

from .. import Options


def backup_Options():
    backup = {}
    for name, value in vars(Options).items():
        # we need a deep copy of _directive_defaults, because they can be changed
        if name == '_directive_defaults':
            value = copy.deepcopy(value)
        backup[name] = value
    return backup


def restore_Options(backup):
    no_value = object()
    for name, orig_value in backup.items():
        if getattr(Options, name, no_value) != orig_value:
            setattr(Options, name, orig_value)
    # strip Options from new keys that might have been added:
    for name in vars(Options).keys():
        if name not in backup:
            delattr(Options, name)


def check_global_options(expected_options, white_list=[]):
    """
    returns error message of "" if check Ok
    """
    no_value = object()
    for name, orig_value in expected_options.items():
        if name not in white_list:
            if getattr(Options, name, no_value) != orig_value:
                return "error in option " + name
    return ""