MCPcopy
hub / github.com/django/django / parse_color_setting

Function parse_color_setting

django/utils/termcolors.py:143–221  ·  view source on GitHub ↗

Parse a DJANGO_COLORS environment variable to produce the system palette The general form of a palette definition is: "palette;role=fg;role=fg/bg;role=fg,option,option;role=fg/bg,option,option" where: palette is a named palette; one of 'light', 'dark', or 'nocolor'.

(config_string)

Source from the content-addressed store, hash-verified

141
142
143def parse_color_setting(config_string):
144 """Parse a DJANGO_COLORS environment variable to produce the system palette
145
146 The general form of a palette definition is:
147
148 "palette;role=fg;role=fg/bg;role=fg,option,option;role=fg/bg,option,option"
149
150 where:
151 palette is a named palette; one of 'light', 'dark', or 'nocolor'.
152 role is a named style used by Django
153 fg is a foreground color.
154 bg is a background color.
155 option is a display options.
156
157 Specifying a named palette is the same as manually specifying the
158 individual definitions for each role. Any individual definitions following
159 the palette definition will augment the base palette definition.
160
161 Valid roles:
162 'error', 'success', 'warning', 'notice', 'sql_field', 'sql_coltype',
163 'sql_keyword', 'sql_table', 'http_info', 'http_success',
164 'http_redirect', 'http_not_modified', 'http_bad_request',
165 'http_not_found', 'http_server_error', 'migrate_heading',
166 'migrate_label'
167
168 Valid colors:
169 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'
170
171 Valid options:
172 'bold', 'underscore', 'blink', 'reverse', 'conceal', 'noreset'
173 """
174 if not config_string:
175 return PALETTES[DEFAULT_PALETTE]
176
177 # Split the color configuration into parts
178 parts = config_string.lower().split(";")
179 palette = PALETTES[NOCOLOR_PALETTE].copy()
180 for part in parts:
181 if part in PALETTES:
182 # A default palette has been specified
183 palette.update(PALETTES[part])
184 elif "=" in part:
185 # Process a palette defining string
186 definition = {}
187
188 # Break the definition into the role,
189 # plus the list of specific instructions.
190 # The role must be in upper case
191 role, instructions = part.split("=")
192 role = role.upper()
193
194 styles = instructions.split(",")
195 styles.reverse()
196
197 # The first instruction can contain a slash
198 # to break apart fg/bg.
199 colors = styles.pop().split("/")
200 colors.reverse()

Callers 15

test_empty_stringMethod · 0.90
test_simple_paletteMethod · 0.90
test_fgMethod · 0.90
test_fg_bgMethod · 0.90
test_fg_optsMethod · 0.90
test_fg_bg_optsMethod · 0.90
test_override_paletteMethod · 0.90
test_override_nocolorMethod · 0.90
test_reverse_overrideMethod · 0.90
test_multiple_rolesMethod · 0.90
test_empty_definitionMethod · 0.90

Calls 5

splitMethod · 0.45
copyMethod · 0.45
updateMethod · 0.45
reverseMethod · 0.45
popMethod · 0.45

Tested by 15

test_empty_stringMethod · 0.72
test_simple_paletteMethod · 0.72
test_fgMethod · 0.72
test_fg_bgMethod · 0.72
test_fg_optsMethod · 0.72
test_fg_bg_optsMethod · 0.72
test_override_paletteMethod · 0.72
test_override_nocolorMethod · 0.72
test_reverse_overrideMethod · 0.72
test_multiple_rolesMethod · 0.72
test_empty_definitionMethod · 0.72