Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6febe6f

Browse files
committed
Merge branch 'master' into namespaces_integration
2 parents 837ea59 + e985cd1 commit 6febe6f

21 files changed

Lines changed: 279 additions & 269 deletions

.travis.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
language: python
2+
3+
python:
4+
- 3.5
5+
26
env:
37
- TOXENV=py26
48
- TOXENV=py27
9+
- TOXENV=py33
10+
- TOXENV=py34
11+
- TOXENV=py35
512
- TOXENV=rhel6
613

714
install:
8-
- pip install tox
15+
- pip install -U tox
916

1017
script:
1118
- tox

README.rst

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
python-maec
22
===========
33

4-
A Python library for parsing, manipulating, and generating MAEC content.
4+
A Python library for parsing, manipulating, and generating `Malware Attribute Enumeration and Characterization (MAEC™) <https://maecproject.github.io/>`_ content.
55

66
:Source: https://github.com/MAECProject/python-maec
77
:Documentation: http://maec.readthedocs.org
8-
:Information: http://maec.mitre.org
8+
:Information: https://maecproject.github.io/
99
:Download: https://pypi.python.org/pypi/maec/
1010

1111
|travis badge| |landscape.io badge| |version badge| |downloads badge|
1212

1313
.. |travis badge| image:: https://api.travis-ci.org/MAECProject/python-maec.png?branch=master
1414
:target: https://travis-ci.org/MAECProject/python-maec
15-
:alt: Build Status
15+
:alt: Build Status
1616
.. |landscape.io badge| image:: https://landscape.io/github/MAECProject/python-maec/master/landscape.png
1717
:target: https://landscape.io/github/MAECProject/python-maec/master
18-
:alt: Code Health
19-
.. |version badge| image:: https://pypip.in/v/maec/badge.png
18+
:alt: Code Health
19+
.. |Version Badge| image:: https://img.shields.io/pypi/v/maec.png?maxAge=2592000
2020
:target: https://pypi.python.org/pypi/maec/
21-
.. |downloads badge| image:: https://pypip.in/d/maec/badge.png
21+
.. |Downloads Badge| image:: https://img.shields.io/pypi/dm/maec.png?maxAge=2592000
2222
:target: https://pypi.python.org/pypi/maec/
2323

2424

@@ -49,7 +49,7 @@ There are currently two levels of APIs for dealing with MAEC content:
4949

5050
Compatibility
5151
-------------
52-
The python-maec library is tested and written against python ``2.7.x``. Compatibility with other python versions is neither guaranteed nor implied.
52+
The python-maec library is tested and written against python ``2.6, 2.7, and 3.3+``. Compatibility with other python versions is neither guaranteed nor implied.
5353

5454
Versioning
5555
----------
@@ -62,6 +62,20 @@ to indicate new versions of the python-maec library itself.
6262
Installation
6363
------------
6464

65+
The python-maec library can be installed via the distutils setup.py script
66+
included at the root directory:
67+
68+
$ python setup.py install
69+
70+
The python-maec library is also hosted on `PyPI
71+
<https://pypi.python.org/pypi/maec/>`_ and can be installed with `pip
72+
<https://pypi.python.org/pypi/pip>`_:
73+
74+
$ pip install maec
75+
76+
Dependencies
77+
------------
78+
6579
The ``maec`` package depends on the following Python libraries:
6680

6781
* ``lxml``
@@ -86,11 +100,10 @@ Ubuntu package repository:
86100
* zlib1g-dev
87101

88102
For more information about installing lxml, see
89-
http://lxml.de/installation.html
103+
http://lxml.de/installation.html.
90104

91105
Feedback
92106
--------
93107

94108
Bug reports and feature requests are welcome and encouraged. Pull requests are
95-
especially appreciated. Feel free to use the issue tracker on GitHub or send an
96-
email directly to [email protected].
109+
especially appreciated. Feel free to use the issue tracker on GitHub, join the `MAEC Community Email Discussion List <https://maec.mitre.org/community/discussionlist.html>`_, or send an email directly to [email protected].

docs/api_vs_bindings/api_snippet.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
b.add_action(a)
3333
3434
# Output the Bundle to stdout
35-
print b.to_xml(include_namespaces = False)
35+
print(b.to_xml(include_namespaces = False))

docs/examples.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ different types of analysis.
4141
ms = MalwareSubject()
4242
p.add_malware_subject(ms)
4343

44-
print p.to_xml(include_namespaces=False)
44+
print(p.to_xml(include_namespaces=False, encoding=None))
4545

4646
Which outputs:
4747

@@ -77,7 +77,7 @@ that it is characterizing.
7777
ms.malware_instance_object_attributes.properties = File()
7878
ms.malware_instance_object_attributes.properties.file_name = "malware.exe"
7979
ms.malware_instance_object_attributes.properties.file_path = "C:\Windows\Temp\malware.exe"
80-
print ms.to_xml(include_namespaces=False)
80+
print(ms.to_xml(include_namespaces=False, encoding=None))
8181

8282
Which outputs:
8383

@@ -125,7 +125,7 @@ instance that it is characterizing.
125125
b.malware_instance_object_attributes.properties.file_name = "malware.exe"
126126
b.malware_instance_object_attributes.properties.file_path = "C:\Windows\Temp\malware.exe"
127127

128-
print b.to_xml(include_namespaces=False)
128+
print(b.to_xml(include_namespaces=False, encoding=None))
129129

130130
Which outputs:
131131

@@ -168,7 +168,7 @@ be defined in their parent Malware Subject.
168168
b = Bundle()
169169
ms.add_findings_bundle(b)
170170

171-
print ms.to_xml(include_namespaces=False)
171+
print(ms.to_xml(include_namespaces=False, encoding=None))
172172

173173
Which outputs:
174174

@@ -227,7 +227,7 @@ needed.
227227

228228
b.add_action(a)
229229

230-
print b.to_xml(include_namespaces = False)
230+
print(b.to_xml(include_namespaces = False, encoding=None))
231231

232232
.. testoutput::
233233

maec/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Copyright (c) 2015, The MITRE Corporation. All rights reserved.
22
# See LICENSE.txt for complete terms.
33

4+
from __future__ import absolute_import
45
from mixbox.entities import Entity as cyboxEntity
56
from mixbox.entities import EntityList
67
from mixbox.namespaces import ( get_xmlns_string,
78
make_namespace_subset_from_uris, get_schemaloc_string, lookup_prefix)
9+
from mixbox.vendor.six import iteritems, string_types
810

911
import maec
1012
from maec.utils import flip_dict, EntityParser
@@ -47,7 +49,7 @@ def to_xml_file(self, file, namespace_dict=None, custom_header=None):
4749
namespace_dict.update(input_namespaces)
4850

4951
# Check whether we're dealing with a filename or file-like Object
50-
if isinstance(file, basestring):
52+
if isinstance(file, string_types):
5153
out_file = open(file, 'w')
5254
else:
5355
out_file = file
@@ -60,12 +62,12 @@ def to_xml_file(self, file, namespace_dict=None, custom_header=None):
6062
out_file.write("-->\n")
6163
elif isinstance(custom_header, dict):
6264
out_file.write("<!--\n")
63-
for key, value in custom_header.iteritems():
65+
for key, value in iteritems(custom_header):
6466
sanitized_key = str(key).replace("-->", "\\-\\->")
6567
sanitized_value = str(value).replace("-->", "\\-\\->")
6668
out_file.write(sanitized_key + ": " + sanitized_value + "\n")
6769
out_file.write("-->\n")
68-
elif isinstance(custom_header, basestring):
70+
elif isinstance(custom_header, string_types):
6971
out_file.write("<!--\n")
7072
out_file.write(custom_header.replace("-->", "\\-\\->") + "\n")
7173
out_file.write("-->\n")
@@ -85,7 +87,7 @@ def _get_namespace_def(self, additional_ns_dict=None):
8587

8688
ns_set = make_namespace_subset_from_uris(namespaces)
8789
if additional_ns_dict:
88-
for ns, prefix in additional_ns_dict.iteritems():
90+
for ns, prefix in iteritems(additional_ns_dict):
8991
ns_set.add_namespace_uri(ns, prefix)
9092
else:
9193
return ""
@@ -108,7 +110,7 @@ def _get_namespaces(self, recurse=True):
108110

109111
# Add any additional namespaces that may be included in the entity
110112
input_ns = self._ns_to_prefix_input_namespaces()
111-
for namespace, alias in input_ns.iteritems():
113+
for namespace, alias in iteritems(input_ns):
112114
nsset.update(namespace)
113115

114116
return nsset

maec/bindings/maec_bundle.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def exportAttributes(self, write, level, already_processed, namespace_='maecBund
103103
write(' status=%s' % (quote_attrib(self.status), ))
104104
if self.duration is not None and 'duration' not in already_processed:
105105
already_processed.add('duration')
106-
write(' duration=%s' % (quote_attrib(self.duration).encode(ExternalEncoding)))
106+
write(' duration=%s' % (quote_attrib(self.duration)))
107107
if self.ordinal_position is not None and 'ordinal_position' not in already_processed:
108108
already_processed.add('ordinal_position')
109109
write(' ordinal_position="%s"' % self.gds_format_integer(self.ordinal_position, input_name='ordinal_position'))
@@ -149,7 +149,7 @@ def buildAttributes(self, node, attrs, already_processed):
149149
already_processed.add('ordinal_position')
150150
try:
151151
self.ordinal_position = int(value)
152-
except ValueError, exp:
152+
except ValueError as exp:
153153
raise_parse_error(node, 'Bad integer attribute: %s' % exp)
154154
if self.ordinal_position <= 0:
155155
raise_parse_error(node, 'Invalid PositiveInteger')
@@ -357,7 +357,7 @@ def buildAttributes(self, node, attrs, already_processed):
357357
already_processed.add('timestamp')
358358
try:
359359
self.timestamp = self.gds_parse_datetime(value, node, 'timestamp')
360-
except ValueError, exp:
360+
except ValueError as exp:
361361
raise ValueError('Bad date-time attribute (timestamp): %s' % exp)
362362
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
363363
if nodeName_ == 'Malware_Instance_Object_Attributes':
@@ -1016,7 +1016,7 @@ def buildAttributes(self, node, attrs, already_processed):
10161016
already_processed.add('ordinal_position')
10171017
try:
10181018
self.ordinal_position = int(value)
1019-
except ValueError, exp:
1019+
except ValueError as exp:
10201020
raise_parse_error(node, 'Bad integer attribute: %s' % exp)
10211021
if self.ordinal_position <= 0:
10221022
raise_parse_error(node, 'Invalid PositiveInteger')
@@ -2002,7 +2002,7 @@ def buildAttributes(self, node, attrs, already_processed):
20022002
already_processed.add('behavioral_ordering')
20032003
try:
20042004
self.behavioral_ordering = int(value)
2005-
except ValueError, exp:
2005+
except ValueError as exp:
20062006
raise_parse_error(node, 'Bad integer attribute: %s' % exp)
20072007
if self.behavioral_ordering <= 0:
20082008
raise_parse_error(node, 'Invalid PositiveInteger')
@@ -2342,7 +2342,7 @@ def buildAttributes(self, node, attrs, already_processed):
23422342
already_processed.add('creation_datetime')
23432343
try:
23442344
self.creation_datetime = value
2345-
except ValueError, exp:
2345+
except ValueError as exp:
23462346
raise ValueError('Bad date-time attribute (creation_datetime): %s' % exp)
23472347
value = find_attr_value_('id', node)
23482348
if value is not None and 'id' not in already_processed:
@@ -2353,7 +2353,7 @@ def buildAttributes(self, node, attrs, already_processed):
23532353
already_processed.add('lastupdate_datetime')
23542354
try:
23552355
self.lastupdate_datetime = value
2356-
except ValueError, exp:
2356+
except ValueError as exp:
23572357
raise ValueError('Bad date-time attribute (lastupdate_datetime): %s' % exp)
23582358
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
23592359
if nodeName_ == 'Importance':
@@ -2364,7 +2364,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
23642364
sval_ = child_.text
23652365
try:
23662366
ival_ = int(sval_)
2367-
except (TypeError, ValueError), exp:
2367+
except (TypeError, ValueError) as exp:
23682368
raise_parse_error(child_, 'requires integer: %s' % exp)
23692369
if ival_ <= 0:
23702370
raise_parse_error(child_, 'requires positiveInteger')
@@ -3522,7 +3522,7 @@ def buildAttributes(self, node, attrs, already_processed):
35223522
already_processed.add('behavioral_ordering')
35233523
try:
35243524
self.behavioral_ordering = int(value)
3525-
except ValueError, exp:
3525+
except ValueError as exp:
35263526
raise_parse_error(node, 'Bad integer attribute: %s' % exp)
35273527
if self.behavioral_ordering <= 0:
35283528
raise_parse_error(node, 'Invalid PositiveInteger')
@@ -3935,7 +3935,7 @@ def buildAttributes(self, node, attrs, already_processed):
39353935
already_processed.add('behavioral_ordering')
39363936
try:
39373937
self.behavioral_ordering = int(value)
3938-
except ValueError, exp:
3938+
except ValueError as exp:
39393939
raise_parse_error(node, 'Bad integer attribute: %s' % exp)
39403940
if self.behavioral_ordering <= 0:
39413941
raise_parse_error(node, 'Invalid PositiveInteger')
@@ -4681,7 +4681,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
46814681
"""
46824682

46834683
def usage():
4684-
print USAGE_TEXT
4684+
print(USAGE_TEXT)
46854685
sys.exit(1)
46864686

46874687
def get_root_tag(node):
@@ -4721,7 +4721,7 @@ def parseEtree(inFileName):
47214721
return rootObj, rootElement
47224722

47234723
def parseString(inString):
4724-
from StringIO import StringIO
4724+
from mixbox.vendor.six import StringIO
47254725
doc = parsexml_(StringIO(inString))
47264726
rootNode = doc.getroot()
47274727
rootTag, rootClass = get_root_tag(rootNode)

maec/bindings/maec_container.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def buildAttributes(self, node, attrs, already_processed):
9090
already_processed.add('timestamp')
9191
try:
9292
self.timestamp = value
93-
except ValueError, exp:
93+
except ValueError as exp:
9494
raise ValueError('Bad date-time attribute (timestamp): %s' % exp)
9595
value = find_attr_value_('id', node)
9696
if value is not None and 'id' not in already_processed:
@@ -179,7 +179,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
179179
"""
180180

181181
def usage():
182-
print USAGE_TEXT
182+
print(USAGE_TEXT)
183183
sys.exit(1)
184184

185185
def get_root_tag(node):
@@ -219,7 +219,7 @@ def parseEtree(inFileName):
219219
return rootObj, rootElement
220220

221221
def parseString(inString):
222-
from StringIO import StringIO
222+
from mixbox.vendor.six import StringIO
223223
doc = parsexml_(StringIO(inString))
224224
rootNode = doc.getroot()
225225
rootTag, rootClass = get_root_tag(rootNode)

0 commit comments

Comments
 (0)