A function that validate the statsd stat name, apply changes to the stat name if necessary and return the transformed stat name.
(stat_name, max_length=250)
| 182 | |
| 183 | |
| 184 | def stat_name_default_handler(stat_name, max_length=250) -> str: |
| 185 | """A function that validate the statsd stat name, apply changes to the stat name |
| 186 | if necessary and return the transformed stat name. |
| 187 | """ |
| 188 | if not isinstance(stat_name, str): |
| 189 | raise InvalidStatsNameException('The stat_name has to be a string') |
| 190 | if len(stat_name) > max_length: |
| 191 | raise InvalidStatsNameException( |
| 192 | textwrap.dedent( |
| 193 | """\ |
| 194 | The stat_name ({stat_name}) has to be less than {max_length} characters. |
| 195 | """.format( |
| 196 | stat_name=stat_name, max_length=max_length |
| 197 | ) |
| 198 | ) |
| 199 | ) |
| 200 | if not all((c in ALLOWED_CHARACTERS) for c in stat_name): |
| 201 | raise InvalidStatsNameException( |
| 202 | textwrap.dedent( |
| 203 | """\ |
| 204 | The stat name ({stat_name}) has to be composed with characters in |
| 205 | {allowed_characters}. |
| 206 | """.format( |
| 207 | stat_name=stat_name, allowed_characters=ALLOWED_CHARACTERS |
| 208 | ) |
| 209 | ) |
| 210 | ) |
| 211 | return stat_name |
| 212 | |
| 213 | |
| 214 | def get_current_handler_stat_name_func() -> Callable[[str], str]: |
nothing calls this directly
no test coverage detected