Move enum_extend_if_invalid
to utils.py
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
from __future__ import unicode_literals
|
||||
import json
|
||||
import re
|
||||
import aenum
|
||||
from .models import *
|
||||
from .utils import *
|
||||
|
||||
@@ -24,14 +23,6 @@ class ConcatJSONDecoder(json.JSONDecoder):
|
||||
return objs
|
||||
# End shameless copy
|
||||
|
||||
def enum_extend_if_invalid(enumeration, value):
|
||||
try:
|
||||
return enumeration(value)
|
||||
except ValueError:
|
||||
log.warning("Failed parsing {}({!r}). Extending enum.".format(enumeration, value))
|
||||
aenum.extend_enum(enumeration, "UNKNOWN_{}".format(value).upper(), value)
|
||||
return enumeration(value)
|
||||
|
||||
def graphql_color_to_enum(color):
|
||||
if color is None:
|
||||
return None
|
||||
|
@@ -11,6 +11,7 @@ from os.path import basename
|
||||
import warnings
|
||||
import logging
|
||||
import requests
|
||||
import aenum
|
||||
from .models import *
|
||||
|
||||
try:
|
||||
@@ -297,3 +298,12 @@ def get_files_from_paths(filenames):
|
||||
yield files
|
||||
for fn, fp, ft in files:
|
||||
fp.close()
|
||||
|
||||
|
||||
def enum_extend_if_invalid(enumeration, value):
|
||||
try:
|
||||
return enumeration(value)
|
||||
except ValueError:
|
||||
log.warning("Failed parsing {}({!r}). Extending enum.".format(enumeration, value))
|
||||
aenum.extend_enum(enumeration, "UNKNOWN_{}".format(value).upper(), value)
|
||||
return enumeration(value)
|
||||
|
Reference in New Issue
Block a user