-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from eclecticiq/taxii2-implementation
Add taxii2 reference implementation
- Loading branch information
Showing
46 changed files
with
9,477 additions
and
361 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,29 @@ | ||
def sorted_dicts(obj): | ||
""" | ||
sort all dicts contained in obj, for repeatable repr | ||
""" | ||
if isinstance(obj, dict): | ||
response = {} | ||
for key, value in sorted(obj.items()): | ||
value = sorted_dicts(value) | ||
response[key] = value | ||
elif isinstance(obj, (list, tuple)): | ||
response = type(obj)(sorted_dicts(item) for item in obj) | ||
else: | ||
response = obj | ||
return response | ||
|
||
|
||
class Entity: | ||
'''Abstract TAXII entity class. | ||
''' | ||
|
||
def __repr__(self): | ||
pairs = ["%s=%s" % (k, v) for k, v in sorted(self.__dict__.items())] | ||
pairs = ["%s=%s" % (k, v) for k, v in sorted(sorted_dicts(self.__dict__).items())] | ||
return "%s(%s)" % (self.__class__.__name__, ", ".join(pairs)) | ||
|
||
def to_dict(self): | ||
return {key: value for key, value in self.__dict__.items()} | ||
|
||
def __eq__(self, other): | ||
return repr(self) == repr(other) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.