Skip to content

Commit

Permalink
Added xmlconst.py. Fixed import issue in STIXPackage.from_xml()
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Worrell committed Feb 28, 2015
1 parent d013f6a commit 7386b46
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
7 changes: 3 additions & 4 deletions stix/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import lxml

# internal
import stix.bindings as bindings
from . import bindings

# lazy imports
cybox = None
Expand Down Expand Up @@ -243,9 +243,8 @@ def dict_from_object(cls, entity_obj):
return cls.from_obj(entity_obj).to_dict()

def walk(self):
from stix.utils import walk
return walk.iterwalk(self)

_load_lazy_mods()
return utils.walk.iterwalk(self)

def find(self, id_):
"""Searches the children of a :class:`Entity` implementation for an
Expand Down
4 changes: 3 additions & 1 deletion stix/core/stix_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# internal
import stix
import stix.utils as utils
import stix.utils.parser as parser

from stix.campaign import Campaign
from stix.coa import CourseOfAction
from stix.exploit_target import ExploitTarget
Expand Down Expand Up @@ -454,7 +456,7 @@ def from_xml(cls, xml_file, encoding=None):
An instance of :class:`STIXPackage`.
"""
entity_parser = utils.parser.EntityParser()
entity_parser = parser.EntityParser()
return entity_parser.parse_xml(xml_file, encoding=encoding)


Expand Down
1 change: 1 addition & 0 deletions stix/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def is_entity(entity):
def is_entitylist(entity):
return isinstance(entity, (cybox.EntityList, stix.EntityList))


def attr_name(name):
if name.startswith("_"):
name = name[1:]
Expand Down
15 changes: 9 additions & 6 deletions stix/utils/parser.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Copyright (c) 2015, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.

import stix
from lxml import etree
# stdlib
from distutils.version import StrictVersion

# external
from lxml import etree

# internal
import stix
import stix.xmlconst as xmlconst
from stix.utils import ignored

NS_XSI = "http://www.w3.org/2001/XMLSchema-instance"
TAG_XSI_TYPE = "{%s}type" % NS_XSI
TAG_SCHEMALOCATION = "{%s}schemaLocation" % NS_XSI

class UnknownVersionError(Exception):
pass
Expand Down Expand Up @@ -86,7 +89,7 @@ def get_schemaloc_pairs(node):
KeyError: If `node` does not have an xsi:schemaLocation attribute.
"""
schemalocs = node.attrib[TAG_SCHEMALOCATION]
schemalocs = node.attrib[xmlconst.TAG_SCHEMALOCATION]
l = schemalocs.split()
return zip(l[::2], l[1::2])

Expand Down
6 changes: 6 additions & 0 deletions stix/xmlconst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2015, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.

NS_XSI = "http://www.w3.org/2001/XMLSchema-instance"
TAG_XSI_TYPE = "{%s}type" % NS_XSI
TAG_SCHEMALOCATION = "{%s}schemaLocation" % NS_XSI

0 comments on commit 7386b46

Please sign in to comment.