Skip to content
This repository has been archived by the owner on May 15, 2019. It is now read-only.

XMLParser is now a specialization of JSONParser #72

Merged
merged 11 commits into from
Jul 11, 2017
Merged

Conversation

dbarrosop
Copy link
Member

@dbarrosop dbarrosop commented Jul 9, 2017

  1. Instead of having two different parsers for XML and JSON now the XMLParser instead is a subclass of JSONParser. The XMLParser will just initialize the native data, which means that it will convert XML into a dict and implement only what's needed piggybacking from the JSONParser.

  2. When accessing native data instead of interfaces.0 you have to access native data with root_interfaces.0. The reason to prepend root_ is that under some circumstances native data would be masked. For example, this would work:

---
interfaces:
     _process: unnecessary
     ...

But this would mask the native data:

---
interfaces:
     _process:
            - #do something here

As now interfaces would actually what was captured by the action.

  1. There is now the method napalm_yang.helpers.config_logging to simplify configuring logging parameters.

@bewing thoughts?

@bewing
Copy link
Member

bewing commented Jul 9, 2017

I like the base idea! However, it always kinda bugged me that JSONParser really operated internally on Python Dicts, and not the JSON -- maybe for clarity, have a parent class StructuredParser that operates on dicts, and then a JSON and XML sub-class that overrides init_native to translate JSON and XML into dictionaries?

@dbarrosop
Copy link
Member Author

it always kinda bugged me that JSONParser really operated internally on Python Dicts, and not the JSON

As a matter of fact it works on both like the XMLParser:

class JSONParser(BaseParser):

    @classmethod
    def init_native(cls, native):
        resp = []
        for k in native:
            if isinstance(k, dict):
                resp.append(k)
            else:
                resp.append(json.loads(k))

        return resp

@dbarrosop dbarrosop merged commit 83712d2 into develop Jul 11, 2017
@dbarrosop dbarrosop deleted the xml_to_json branch July 11, 2017 10:25
matejv added a commit to ArnesSI/napalm-yang that referenced this pull request Jul 11, 2017
matejv added a commit to ArnesSI/napalm-yang that referenced this pull request Jul 18, 2017
matejv added a commit to ArnesSI/napalm-yang that referenced this pull request Jul 24, 2017
matejv added a commit to ArnesSI/napalm-yang that referenced this pull request Jul 30, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants