def xml2axon(from_, to_=None, pretty=1, braces=0): ''' Convert from `XML` to `AXON`. :from: The path of input file with `XML` or `XML` string. :to: The path of output file with `XML`` (default is `None`). If `to` is valid path then result of convertion to `AXON` will write to the file. :result: If `to` is `None` then return string with `AXON`, else return `None`. ''' _text = from_.lstrip() if _text.startswith('<'): tree = etree.fromstring(from_) else: tree = etree.parse(from_) root = tree._root if to_ is None: return axon.dumps([root], pretty=pretty, braces=braces) else: axon.dump(to_, [root], pretty=pretty, braces=braces)
def xml2axon(from_, to_=None): ''' Convert from `XML` to `AXON`. :from: The path of input file with `XML` or `XML` string. :to: The path of output file with `XML`` (default is `None`). If `to` is valid path then result of convertion to `AXON` will write to the file. :result: If `to` is `None` then return string with `AXON`, else return `None`. ''' _text = from_.lstrip() if _text.startswith('<'): tree = etree.fromstring(from_) else: tree = etree.parse(from_) root = tree._root if to_ is None: return axon.dumps([root], pretty=1) else: axon.dump(to_, [root], pretty=1)
def json2axon(from_, to_=None, pretty=1, braces=1): ''' Convert from `JSON` to `AXON`. :from: The path of input file with `JSON` or `JSON` string. :to: The path of output file with `JSON` (default is `None`). If `to` is valid path then result of convertion to `AXON` will write to the file. :result: If `to` is `None` then return string with `AXON`, else return `None`. ''' text = from_.lstrip() if text.startswith('[') or text.startswith('{'): val = json.loads(from_) else: val = json.load(from_) if to_ is None: return axon.dumps([val], pretty=pretty, braces=braces) else: axon.dump(to_, [val], pretty=pretty, braces=braces)
def json2axon(from_, to_=None): ''' Convert from `JSON` to `AXON`. :from: The path of input file with `JSON` or `JSON` string. :to: The path of output file with `JSON` (default is `None`). If `to` is valid path then result of convertion to `AXON` will write to the file. :result: If `to` is `None` then return string with `AXON`, else return `None`. ''' text = from_.lstrip() if text.startswith('[') or text.startswith('{'): val = json.loads(from_) else: val = json.load(from_) if to_ is None: return axon.dumps([val], pretty=1) else: axon.dump(to_, [val], pretty=1)