File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77import re
88import textwrap
99import typing
10- import typing_inspect
1110from collections import defaultdict
1211from glob import glob
1312from pathlib import Path
1413from typing import Any , Mapping , Sequence , TypeVar
1514
15+ import typing_inspect
16+
1617from . import codegen
1718
1819_marker = object ()
@@ -664,14 +665,31 @@ def from_json(cls, data):
664665 data = json .loads (data )
665666 except json .JSONDecodeError :
666667 raise
667- d = {}
668- for k , v in (data or {}).items ():
669- d [cls ._toPy .get (k , k )] = v
670-
671- try :
668+ if isinstance (data , dict ):
669+ d = {}
670+ for k , v in (data or {}).items ():
671+ d [cls ._toPy .get (k , k )] = v
672+ try :
673+ return cls (** d )
674+ except TypeError :
675+ raise
676+ if isinstance (data , list ):
677+ # WARNING: not tested with any-all
678+ # check: https://juju.is/docs/sdk/assumes
679+ # assumes are in the form of a list
680+ d = {}
681+ for entry in data :
682+ if '>' or '>=' in entry :
683+ # something like juju >= 2.9.31
684+ i = entry .index ('>' )
685+ key = entry [:i ].strip ()
686+ value = entry [i :].strip ()
687+ d [key ] = value
688+ else :
689+ # something like k8s-api
690+ d [entry ]= ''
672691 return cls (** d )
673- except TypeError :
674- raise
692+ return None
675693
676694 def serialize (self ):
677695 d = {}
You can’t perform that action at this time.
0 commit comments