repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
EnergieID/smappy | smappy/smappy.py | LocalSmappee.active_cosfi | def active_cosfi(self):
"""
Takes the average of all instantaneous cosfi values
Returns
-------
float
"""
inst = self.load_instantaneous()
values = [float(i['value']) for i in inst if i['key'].endswith('Cosfi')]
return sum(values) / len(values) | python | def active_cosfi(self):
"""
Takes the average of all instantaneous cosfi values
Returns
-------
float
"""
inst = self.load_instantaneous()
values = [float(i['value']) for i in inst if i['key'].endswith('Cosfi')]
return sum(values) / len(values) | [
"def",
"active_cosfi",
"(",
"self",
")",
":",
"inst",
"=",
"self",
".",
"load_instantaneous",
"(",
")",
"values",
"=",
"[",
"float",
"(",
"i",
"[",
"'value'",
"]",
")",
"for",
"i",
"in",
"inst",
"if",
"i",
"[",
"'key'",
"]",
".",
"endswith",
"(",
... | Takes the average of all instantaneous cosfi values
Returns
-------
float | [
"Takes",
"the",
"average",
"of",
"all",
"instantaneous",
"cosfi",
"values"
] | 1ada3abc9a51c76205c072369258f6f4f4e8fd0f | https://github.com/EnergieID/smappy/blob/1ada3abc9a51c76205c072369258f6f4f4e8fd0f/smappy/smappy.py#L586-L596 | train |
EnergieID/smappy | smappy/smappy.py | LocalSmappee.on_command_control | def on_command_control(self, val_id):
"""
Parameters
----------
val_id : str
Returns
-------
requests.Response
"""
data = "control,controlId=1|" + val_id
return self._basic_post(url='commandControlPublic', data=data) | python | def on_command_control(self, val_id):
"""
Parameters
----------
val_id : str
Returns
-------
requests.Response
"""
data = "control,controlId=1|" + val_id
return self._basic_post(url='commandControlPublic', data=data) | [
"def",
"on_command_control",
"(",
"self",
",",
"val_id",
")",
":",
"data",
"=",
"\"control,controlId=1|\"",
"+",
"val_id",
"return",
"self",
".",
"_basic_post",
"(",
"url",
"=",
"'commandControlPublic'",
",",
"data",
"=",
"data",
")"
] | Parameters
----------
val_id : str
Returns
-------
requests.Response | [
"Parameters",
"----------",
"val_id",
":",
"str"
] | 1ada3abc9a51c76205c072369258f6f4f4e8fd0f | https://github.com/EnergieID/smappy/blob/1ada3abc9a51c76205c072369258f6f4f4e8fd0f/smappy/smappy.py#L697-L708 | train |
EnergieID/smappy | smappy/smappy.py | LocalSmappee.off_command_control | def off_command_control(self, val_id):
"""
Parameters
----------
val_id : str
Returns
-------
requests.Response
"""
data = "control,controlId=0|" + val_id
return self._basic_post(url='commandControlPublic', data=data) | python | def off_command_control(self, val_id):
"""
Parameters
----------
val_id : str
Returns
-------
requests.Response
"""
data = "control,controlId=0|" + val_id
return self._basic_post(url='commandControlPublic', data=data) | [
"def",
"off_command_control",
"(",
"self",
",",
"val_id",
")",
":",
"data",
"=",
"\"control,controlId=0|\"",
"+",
"val_id",
"return",
"self",
".",
"_basic_post",
"(",
"url",
"=",
"'commandControlPublic'",
",",
"data",
"=",
"data",
")"
] | Parameters
----------
val_id : str
Returns
-------
requests.Response | [
"Parameters",
"----------",
"val_id",
":",
"str"
] | 1ada3abc9a51c76205c072369258f6f4f4e8fd0f | https://github.com/EnergieID/smappy/blob/1ada3abc9a51c76205c072369258f6f4f4e8fd0f/smappy/smappy.py#L710-L721 | train |
EnergieID/smappy | smappy/smappy.py | LocalSmappee.delete_command_control | def delete_command_control(self, val_id):
"""
Parameters
----------
val_id : str
Returns
-------
requests.Response
"""
data = "delete,controlId=" + val_id
return self._basic_post(url='commandControlPublic', data=data) | python | def delete_command_control(self, val_id):
"""
Parameters
----------
val_id : str
Returns
-------
requests.Response
"""
data = "delete,controlId=" + val_id
return self._basic_post(url='commandControlPublic', data=data) | [
"def",
"delete_command_control",
"(",
"self",
",",
"val_id",
")",
":",
"data",
"=",
"\"delete,controlId=\"",
"+",
"val_id",
"return",
"self",
".",
"_basic_post",
"(",
"url",
"=",
"'commandControlPublic'",
",",
"data",
"=",
"data",
")"
] | Parameters
----------
val_id : str
Returns
-------
requests.Response | [
"Parameters",
"----------",
"val_id",
":",
"str"
] | 1ada3abc9a51c76205c072369258f6f4f4e8fd0f | https://github.com/EnergieID/smappy/blob/1ada3abc9a51c76205c072369258f6f4f4e8fd0f/smappy/smappy.py#L739-L751 | train |
EnergieID/smappy | smappy/smappy.py | LocalSmappee.delete_command_control_timers | def delete_command_control_timers(self, val_id):
"""
Parameters
----------
val_id : str
Returns
-------
requests.Response
"""
data = "deleteTimers,controlId=" + val_id
return self._basic_post(url='commandControlPublic', data=data) | python | def delete_command_control_timers(self, val_id):
"""
Parameters
----------
val_id : str
Returns
-------
requests.Response
"""
data = "deleteTimers,controlId=" + val_id
return self._basic_post(url='commandControlPublic', data=data) | [
"def",
"delete_command_control_timers",
"(",
"self",
",",
"val_id",
")",
":",
"data",
"=",
"\"deleteTimers,controlId=\"",
"+",
"val_id",
"return",
"self",
".",
"_basic_post",
"(",
"url",
"=",
"'commandControlPublic'",
",",
"data",
"=",
"data",
")"
] | Parameters
----------
val_id : str
Returns
-------
requests.Response | [
"Parameters",
"----------",
"val_id",
":",
"str"
] | 1ada3abc9a51c76205c072369258f6f4f4e8fd0f | https://github.com/EnergieID/smappy/blob/1ada3abc9a51c76205c072369258f6f4f4e8fd0f/smappy/smappy.py#L753-L764 | train |
EnergieID/smappy | smappy/smappy.py | LocalSmappee.select_logfile | def select_logfile(self, logfile):
"""
Parameters
----------
logfile : str
Returns
-------
dict
"""
data = 'logFileSelect,' + logfile
r = self._basic_post(url='logBrowser', data=data)
return r.json() | python | def select_logfile(self, logfile):
"""
Parameters
----------
logfile : str
Returns
-------
dict
"""
data = 'logFileSelect,' + logfile
r = self._basic_post(url='logBrowser', data=data)
return r.json() | [
"def",
"select_logfile",
"(",
"self",
",",
"logfile",
")",
":",
"data",
"=",
"'logFileSelect,'",
"+",
"logfile",
"r",
"=",
"self",
".",
"_basic_post",
"(",
"url",
"=",
"'logBrowser'",
",",
"data",
"=",
"data",
")",
"return",
"r",
".",
"json",
"(",
")"
... | Parameters
----------
logfile : str
Returns
-------
dict | [
"Parameters",
"----------",
"logfile",
":",
"str"
] | 1ada3abc9a51c76205c072369258f6f4f4e8fd0f | https://github.com/EnergieID/smappy/blob/1ada3abc9a51c76205c072369258f6f4f4e8fd0f/smappy/smappy.py#L791-L803 | train |
vpelletier/python-functionfs | functionfs/__init__.py | getInterfaceInAllSpeeds | def getInterfaceInAllSpeeds(interface, endpoint_list, class_descriptor_list=()):
"""
Produce similar fs, hs and ss interface and endpoints descriptors.
Should be useful for devices desiring to work in all 3 speeds with maximum
endpoint wMaxPacketSize. Reduces data duplication from descriptor
declara... | python | def getInterfaceInAllSpeeds(interface, endpoint_list, class_descriptor_list=()):
"""
Produce similar fs, hs and ss interface and endpoints descriptors.
Should be useful for devices desiring to work in all 3 speeds with maximum
endpoint wMaxPacketSize. Reduces data duplication from descriptor
declara... | [
"def",
"getInterfaceInAllSpeeds",
"(",
"interface",
",",
"endpoint_list",
",",
"class_descriptor_list",
"=",
"(",
")",
")",
":",
"interface",
"=",
"getDescriptor",
"(",
"USBInterfaceDescriptor",
",",
"bNumEndpoints",
"=",
"len",
"(",
"endpoint_list",
")",
",",
"*"... | Produce similar fs, hs and ss interface and endpoints descriptors.
Should be useful for devices desiring to work in all 3 speeds with maximum
endpoint wMaxPacketSize. Reduces data duplication from descriptor
declarations.
Not intended to cover fancy combinations.
interface (dict):
Keyword arg... | [
"Produce",
"similar",
"fs",
"hs",
"and",
"ss",
"interface",
"and",
"endpoints",
"descriptors",
".",
"Should",
"be",
"useful",
"for",
"devices",
"desiring",
"to",
"work",
"in",
"all",
"3",
"speeds",
"with",
"maximum",
"endpoint",
"wMaxPacketSize",
".",
"Reduces... | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/functionfs/__init__.py#L120-L260 | train |
vpelletier/python-functionfs | functionfs/__init__.py | getDescriptor | def getDescriptor(klass, **kw):
"""
Automatically fills bLength and bDescriptorType.
"""
# XXX: ctypes Structure.__init__ ignores arguments which do not exist
# as structure fields. So check it.
# This is annoying, but not doing it is a huge waste of time for the
# developer.
empty = kla... | python | def getDescriptor(klass, **kw):
"""
Automatically fills bLength and bDescriptorType.
"""
# XXX: ctypes Structure.__init__ ignores arguments which do not exist
# as structure fields. So check it.
# This is annoying, but not doing it is a huge waste of time for the
# developer.
empty = kla... | [
"def",
"getDescriptor",
"(",
"klass",
",",
"*",
"*",
"kw",
")",
":",
"# XXX: ctypes Structure.__init__ ignores arguments which do not exist",
"# as structure fields. So check it.",
"# This is annoying, but not doing it is a huge waste of time for the",
"# developer.",
"empty",
"=",
"... | Automatically fills bLength and bDescriptorType. | [
"Automatically",
"fills",
"bLength",
"and",
"bDescriptorType",
"."
] | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/functionfs/__init__.py#L262-L283 | train |
vpelletier/python-functionfs | functionfs/__init__.py | getOSDesc | def getOSDesc(interface, ext_list):
"""
Return an OS description header.
interface (int)
Related interface number.
ext_list (list of OSExtCompatDesc or OSExtPropDesc)
List of instances of extended descriptors.
"""
try:
ext_type, = {type(x) for x in ext_list}
except Va... | python | def getOSDesc(interface, ext_list):
"""
Return an OS description header.
interface (int)
Related interface number.
ext_list (list of OSExtCompatDesc or OSExtPropDesc)
List of instances of extended descriptors.
"""
try:
ext_type, = {type(x) for x in ext_list}
except Va... | [
"def",
"getOSDesc",
"(",
"interface",
",",
"ext_list",
")",
":",
"try",
":",
"ext_type",
",",
"=",
"{",
"type",
"(",
"x",
")",
"for",
"x",
"in",
"ext_list",
"}",
"except",
"ValueError",
":",
"raise",
"TypeError",
"(",
"'Extensions of a single type are requir... | Return an OS description header.
interface (int)
Related interface number.
ext_list (list of OSExtCompatDesc or OSExtPropDesc)
List of instances of extended descriptors. | [
"Return",
"an",
"OS",
"description",
"header",
".",
"interface",
"(",
"int",
")",
"Related",
"interface",
"number",
".",
"ext_list",
"(",
"list",
"of",
"OSExtCompatDesc",
"or",
"OSExtPropDesc",
")",
"List",
"of",
"instances",
"of",
"extended",
"descriptors",
"... | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/functionfs/__init__.py#L285-L329 | train |
vpelletier/python-functionfs | functionfs/__init__.py | getOSExtPropDesc | def getOSExtPropDesc(data_type, name, value):
"""
Returns an OS extension property descriptor.
data_type (int)
See wPropertyDataType documentation.
name (string)
See PropertyName documentation.
value (string)
See PropertyData documentation.
NULL chars must be explicit... | python | def getOSExtPropDesc(data_type, name, value):
"""
Returns an OS extension property descriptor.
data_type (int)
See wPropertyDataType documentation.
name (string)
See PropertyName documentation.
value (string)
See PropertyData documentation.
NULL chars must be explicit... | [
"def",
"getOSExtPropDesc",
"(",
"data_type",
",",
"name",
",",
"value",
")",
":",
"klass",
"=",
"type",
"(",
"'OSExtPropDesc'",
",",
"(",
"OSExtPropDescHead",
",",
")",
",",
"{",
"'_fields_'",
":",
"[",
"(",
"'bPropertyName'",
",",
"ctypes",
".",
"c_char",... | Returns an OS extension property descriptor.
data_type (int)
See wPropertyDataType documentation.
name (string)
See PropertyName documentation.
value (string)
See PropertyData documentation.
NULL chars must be explicitely included in the value when needed,
this functi... | [
"Returns",
"an",
"OS",
"extension",
"property",
"descriptor",
".",
"data_type",
"(",
"int",
")",
"See",
"wPropertyDataType",
"documentation",
".",
"name",
"(",
"string",
")",
"See",
"PropertyName",
"documentation",
".",
"value",
"(",
"string",
")",
"See",
"Pro... | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/functionfs/__init__.py#L331-L361 | train |
vpelletier/python-functionfs | functionfs/__init__.py | getDescsV2 | def getDescsV2(flags, fs_list=(), hs_list=(), ss_list=(), os_list=()):
"""
Return a FunctionFS descriptor suitable for serialisation.
flags (int)
Any combination of VIRTUAL_ADDR, EVENTFD, ALL_CTRL_RECIP,
CONFIG0_SETUP.
{fs,hs,ss,os}_list (list of descriptors)
Instances of the fo... | python | def getDescsV2(flags, fs_list=(), hs_list=(), ss_list=(), os_list=()):
"""
Return a FunctionFS descriptor suitable for serialisation.
flags (int)
Any combination of VIRTUAL_ADDR, EVENTFD, ALL_CTRL_RECIP,
CONFIG0_SETUP.
{fs,hs,ss,os}_list (list of descriptors)
Instances of the fo... | [
"def",
"getDescsV2",
"(",
"flags",
",",
"fs_list",
"=",
"(",
")",
",",
"hs_list",
"=",
"(",
")",
",",
"ss_list",
"=",
"(",
")",
",",
"os_list",
"=",
"(",
")",
")",
":",
"count_field_list",
"=",
"[",
"]",
"descr_field_list",
"=",
"[",
"]",
"kw",
"... | Return a FunctionFS descriptor suitable for serialisation.
flags (int)
Any combination of VIRTUAL_ADDR, EVENTFD, ALL_CTRL_RECIP,
CONFIG0_SETUP.
{fs,hs,ss,os}_list (list of descriptors)
Instances of the following classes:
{fs,hs,ss}_list:
USBInterfaceDescriptor
... | [
"Return",
"a",
"FunctionFS",
"descriptor",
"suitable",
"for",
"serialisation",
"."
] | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/functionfs/__init__.py#L389-L480 | train |
vpelletier/python-functionfs | functionfs/__init__.py | getStrings | def getStrings(lang_dict):
"""
Return a FunctionFS descriptor suitable for serialisation.
lang_dict (dict)
Key: language ID (ex: 0x0409 for en-us)
Value: list of unicode objects
All values must have the same number of items.
"""
field_list = []
kw = {}
try:
s... | python | def getStrings(lang_dict):
"""
Return a FunctionFS descriptor suitable for serialisation.
lang_dict (dict)
Key: language ID (ex: 0x0409 for en-us)
Value: list of unicode objects
All values must have the same number of items.
"""
field_list = []
kw = {}
try:
s... | [
"def",
"getStrings",
"(",
"lang_dict",
")",
":",
"field_list",
"=",
"[",
"]",
"kw",
"=",
"{",
"}",
"try",
":",
"str_count",
"=",
"len",
"(",
"next",
"(",
"iter",
"(",
"lang_dict",
".",
"values",
"(",
")",
")",
")",
")",
"except",
"StopIteration",
"... | Return a FunctionFS descriptor suitable for serialisation.
lang_dict (dict)
Key: language ID (ex: 0x0409 for en-us)
Value: list of unicode objects
All values must have the same number of items. | [
"Return",
"a",
"FunctionFS",
"descriptor",
"suitable",
"for",
"serialisation",
"."
] | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/functionfs/__init__.py#L482-L530 | train |
vpelletier/python-functionfs | functionfs/__init__.py | serialise | def serialise(structure):
"""
structure (ctypes.Structure)
The structure to serialise.
Returns a ctypes.c_char array.
Does not copy memory.
"""
return ctypes.cast(
ctypes.pointer(structure),
ctypes.POINTER(ctypes.c_char * ctypes.sizeof(structure)),
).contents | python | def serialise(structure):
"""
structure (ctypes.Structure)
The structure to serialise.
Returns a ctypes.c_char array.
Does not copy memory.
"""
return ctypes.cast(
ctypes.pointer(structure),
ctypes.POINTER(ctypes.c_char * ctypes.sizeof(structure)),
).contents | [
"def",
"serialise",
"(",
"structure",
")",
":",
"return",
"ctypes",
".",
"cast",
"(",
"ctypes",
".",
"pointer",
"(",
"structure",
")",
",",
"ctypes",
".",
"POINTER",
"(",
"ctypes",
".",
"c_char",
"*",
"ctypes",
".",
"sizeof",
"(",
"structure",
")",
")"... | structure (ctypes.Structure)
The structure to serialise.
Returns a ctypes.c_char array.
Does not copy memory. | [
"structure",
"(",
"ctypes",
".",
"Structure",
")",
"The",
"structure",
"to",
"serialise",
"."
] | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/functionfs/__init__.py#L532-L543 | train |
vpelletier/python-functionfs | functionfs/__init__.py | Endpoint0File.halt | def halt(self, request_type):
"""
Halt current endpoint.
"""
try:
if request_type & ch9.USB_DIR_IN:
self.read(0)
else:
self.write(b'')
except IOError as exc:
if exc.errno != errno.EL2HLT:
raise
... | python | def halt(self, request_type):
"""
Halt current endpoint.
"""
try:
if request_type & ch9.USB_DIR_IN:
self.read(0)
else:
self.write(b'')
except IOError as exc:
if exc.errno != errno.EL2HLT:
raise
... | [
"def",
"halt",
"(",
"self",
",",
"request_type",
")",
":",
"try",
":",
"if",
"request_type",
"&",
"ch9",
".",
"USB_DIR_IN",
":",
"self",
".",
"read",
"(",
"0",
")",
"else",
":",
"self",
".",
"write",
"(",
"b''",
")",
"except",
"IOError",
"as",
"exc... | Halt current endpoint. | [
"Halt",
"current",
"endpoint",
"."
] | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/functionfs/__init__.py#L559-L572 | train |
vpelletier/python-functionfs | functionfs/__init__.py | Endpoint0File.getRealInterfaceNumber | def getRealInterfaceNumber(self, interface):
"""
Returns the host-visible interface number, or None if there is no such
interface.
"""
try:
return self._ioctl(INTERFACE_REVMAP, interface)
except IOError as exc:
if exc.errno == errno.EDOM:
... | python | def getRealInterfaceNumber(self, interface):
"""
Returns the host-visible interface number, or None if there is no such
interface.
"""
try:
return self._ioctl(INTERFACE_REVMAP, interface)
except IOError as exc:
if exc.errno == errno.EDOM:
... | [
"def",
"getRealInterfaceNumber",
"(",
"self",
",",
"interface",
")",
":",
"try",
":",
"return",
"self",
".",
"_ioctl",
"(",
"INTERFACE_REVMAP",
",",
"interface",
")",
"except",
"IOError",
"as",
"exc",
":",
"if",
"exc",
".",
"errno",
"==",
"errno",
".",
"... | Returns the host-visible interface number, or None if there is no such
interface. | [
"Returns",
"the",
"host",
"-",
"visible",
"interface",
"number",
"or",
"None",
"if",
"there",
"is",
"no",
"such",
"interface",
"."
] | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/functionfs/__init__.py#L574-L584 | train |
vpelletier/python-functionfs | functionfs/__init__.py | EndpointFile.getDescriptor | def getDescriptor(self):
"""
Returns the currently active endpoint descriptor
(depending on current USB speed).
"""
result = USBEndpointDescriptor()
self._ioctl(ENDPOINT_DESC, result, True)
return result | python | def getDescriptor(self):
"""
Returns the currently active endpoint descriptor
(depending on current USB speed).
"""
result = USBEndpointDescriptor()
self._ioctl(ENDPOINT_DESC, result, True)
return result | [
"def",
"getDescriptor",
"(",
"self",
")",
":",
"result",
"=",
"USBEndpointDescriptor",
"(",
")",
"self",
".",
"_ioctl",
"(",
"ENDPOINT_DESC",
",",
"result",
",",
"True",
")",
"return",
"result"
] | Returns the currently active endpoint descriptor
(depending on current USB speed). | [
"Returns",
"the",
"currently",
"active",
"endpoint",
"descriptor",
"(",
"depending",
"on",
"current",
"USB",
"speed",
")",
"."
] | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/functionfs/__init__.py#L621-L628 | train |
vpelletier/python-functionfs | functionfs/__init__.py | EndpointFile.halt | def halt(self):
"""
Halt current endpoint.
"""
try:
self._halt()
except IOError as exc:
if exc.errno != errno.EBADMSG:
raise
else:
raise ValueError('halt did not return EBADMSG ?')
self._halted = True | python | def halt(self):
"""
Halt current endpoint.
"""
try:
self._halt()
except IOError as exc:
if exc.errno != errno.EBADMSG:
raise
else:
raise ValueError('halt did not return EBADMSG ?')
self._halted = True | [
"def",
"halt",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"_halt",
"(",
")",
"except",
"IOError",
"as",
"exc",
":",
"if",
"exc",
".",
"errno",
"!=",
"errno",
".",
"EBADMSG",
":",
"raise",
"else",
":",
"raise",
"ValueError",
"(",
"'halt did not r... | Halt current endpoint. | [
"Halt",
"current",
"endpoint",
"."
] | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/functionfs/__init__.py#L633-L644 | train |
vpelletier/python-functionfs | functionfs/__init__.py | Function.close | def close(self):
"""
Close all endpoint file descriptors.
"""
ep_list = self._ep_list
while ep_list:
ep_list.pop().close()
self._closed = True | python | def close(self):
"""
Close all endpoint file descriptors.
"""
ep_list = self._ep_list
while ep_list:
ep_list.pop().close()
self._closed = True | [
"def",
"close",
"(",
"self",
")",
":",
"ep_list",
"=",
"self",
".",
"_ep_list",
"while",
"ep_list",
":",
"ep_list",
".",
"pop",
"(",
")",
".",
"close",
"(",
")",
"self",
".",
"_closed",
"=",
"True"
] | Close all endpoint file descriptors. | [
"Close",
"all",
"endpoint",
"file",
"descriptors",
"."
] | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/functionfs/__init__.py#L800-L807 | train |
vpelletier/python-functionfs | functionfs/__init__.py | Function.onSetup | def onSetup(self, request_type, request, value, index, length):
"""
Called when a setup USB transaction was received.
Default implementation:
- handles USB_REQ_GET_STATUS on interface and endpoints
- handles USB_REQ_CLEAR_FEATURE(USB_ENDPOINT_HALT) on endpoints
- handles... | python | def onSetup(self, request_type, request, value, index, length):
"""
Called when a setup USB transaction was received.
Default implementation:
- handles USB_REQ_GET_STATUS on interface and endpoints
- handles USB_REQ_CLEAR_FEATURE(USB_ENDPOINT_HALT) on endpoints
- handles... | [
"def",
"onSetup",
"(",
"self",
",",
"request_type",
",",
"request",
",",
"value",
",",
"index",
",",
"length",
")",
":",
"if",
"(",
"request_type",
"&",
"ch9",
".",
"USB_TYPE_MASK",
")",
"==",
"ch9",
".",
"USB_TYPE_STANDARD",
":",
"recipient",
"=",
"requ... | Called when a setup USB transaction was received.
Default implementation:
- handles USB_REQ_GET_STATUS on interface and endpoints
- handles USB_REQ_CLEAR_FEATURE(USB_ENDPOINT_HALT) on endpoints
- handles USB_REQ_SET_FEATURE(USB_ENDPOINT_HALT) on endpoints
- halts on everything e... | [
"Called",
"when",
"a",
"setup",
"USB",
"transaction",
"was",
"received",
"."
] | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/functionfs/__init__.py#L956-L1036 | train |
vpelletier/python-functionfs | examples/usbcat/slowprinter.py | main | def main():
"""
Slowly writes to stdout, without emitting a newline so any output
buffering (or input for next pipeline command) can be detected.
"""
now = datetime.datetime.now
try:
while True:
sys.stdout.write(str(now()) + ' ')
time.sleep(1)
except KeyboardI... | python | def main():
"""
Slowly writes to stdout, without emitting a newline so any output
buffering (or input for next pipeline command) can be detected.
"""
now = datetime.datetime.now
try:
while True:
sys.stdout.write(str(now()) + ' ')
time.sleep(1)
except KeyboardI... | [
"def",
"main",
"(",
")",
":",
"now",
"=",
"datetime",
".",
"datetime",
".",
"now",
"try",
":",
"while",
"True",
":",
"sys",
".",
"stdout",
".",
"write",
"(",
"str",
"(",
"now",
"(",
")",
")",
"+",
"' '",
")",
"time",
".",
"sleep",
"(",
"1",
"... | Slowly writes to stdout, without emitting a newline so any output
buffering (or input for next pipeline command) can be detected. | [
"Slowly",
"writes",
"to",
"stdout",
"without",
"emitting",
"a",
"newline",
"so",
"any",
"output",
"buffering",
"(",
"or",
"input",
"for",
"next",
"pipeline",
"command",
")",
"can",
"be",
"detected",
"."
] | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/examples/usbcat/slowprinter.py#L22-L36 | train |
vpelletier/python-functionfs | examples/usbcat/device.py | USBCat.onEnable | def onEnable(self):
"""
The configuration containing this function has been enabled by host.
Endpoints become working files, so submit some read operations.
"""
trace('onEnable')
self._disable()
self._aio_context.submit(self._aio_recv_block_list)
self._rea... | python | def onEnable(self):
"""
The configuration containing this function has been enabled by host.
Endpoints become working files, so submit some read operations.
"""
trace('onEnable')
self._disable()
self._aio_context.submit(self._aio_recv_block_list)
self._rea... | [
"def",
"onEnable",
"(",
"self",
")",
":",
"trace",
"(",
"'onEnable'",
")",
"self",
".",
"_disable",
"(",
")",
"self",
".",
"_aio_context",
".",
"submit",
"(",
"self",
".",
"_aio_recv_block_list",
")",
"self",
".",
"_real_onCanSend",
"(",
")",
"self",
"."... | The configuration containing this function has been enabled by host.
Endpoints become working files, so submit some read operations. | [
"The",
"configuration",
"containing",
"this",
"function",
"has",
"been",
"enabled",
"by",
"host",
".",
"Endpoints",
"become",
"working",
"files",
"so",
"submit",
"some",
"read",
"operations",
"."
] | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/examples/usbcat/device.py#L121-L130 | train |
vpelletier/python-functionfs | examples/usbcat/device.py | USBCat._disable | def _disable(self):
"""
The configuration containing this function has been disabled by host.
Endpoint do not work anymore, so cancel AIO operation blocks.
"""
if self._enabled:
self._real_onCannotSend()
has_cancelled = 0
for block in self._aio... | python | def _disable(self):
"""
The configuration containing this function has been disabled by host.
Endpoint do not work anymore, so cancel AIO operation blocks.
"""
if self._enabled:
self._real_onCannotSend()
has_cancelled = 0
for block in self._aio... | [
"def",
"_disable",
"(",
"self",
")",
":",
"if",
"self",
".",
"_enabled",
":",
"self",
".",
"_real_onCannotSend",
"(",
")",
"has_cancelled",
"=",
"0",
"for",
"block",
"in",
"self",
".",
"_aio_recv_block_list",
"+",
"self",
".",
"_aio_send_block_list",
":",
... | The configuration containing this function has been disabled by host.
Endpoint do not work anymore, so cancel AIO operation blocks. | [
"The",
"configuration",
"containing",
"this",
"function",
"has",
"been",
"disabled",
"by",
"host",
".",
"Endpoint",
"do",
"not",
"work",
"anymore",
"so",
"cancel",
"AIO",
"operation",
"blocks",
"."
] | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/examples/usbcat/device.py#L136-L155 | train |
vpelletier/python-functionfs | examples/usbcat/device.py | USBCat.onAIOCompletion | def onAIOCompletion(self):
"""
Call when eventfd notified events are available.
"""
event_count = self.eventfd.read()
trace('eventfd reports %i events' % event_count)
# Even though eventfd signaled activity, even though it may give us
# some number of pending even... | python | def onAIOCompletion(self):
"""
Call when eventfd notified events are available.
"""
event_count = self.eventfd.read()
trace('eventfd reports %i events' % event_count)
# Even though eventfd signaled activity, even though it may give us
# some number of pending even... | [
"def",
"onAIOCompletion",
"(",
"self",
")",
":",
"event_count",
"=",
"self",
".",
"eventfd",
".",
"read",
"(",
")",
"trace",
"(",
"'eventfd reports %i events'",
"%",
"event_count",
")",
"# Even though eventfd signaled activity, even though it may give us",
"# some number ... | Call when eventfd notified events are available. | [
"Call",
"when",
"eventfd",
"notified",
"events",
"are",
"available",
"."
] | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/examples/usbcat/device.py#L157-L168 | train |
vpelletier/python-functionfs | examples/usbcat/device.py | USBCat.write | def write(self, value):
"""
Queue write in kernel.
value (bytes)
Value to send.
"""
aio_block = libaio.AIOBlock(
mode=libaio.AIOBLOCK_MODE_WRITE,
target_file=self.getEndpoint(1),
buffer_list=[bytearray(value)],
offset=0,... | python | def write(self, value):
"""
Queue write in kernel.
value (bytes)
Value to send.
"""
aio_block = libaio.AIOBlock(
mode=libaio.AIOBLOCK_MODE_WRITE,
target_file=self.getEndpoint(1),
buffer_list=[bytearray(value)],
offset=0,... | [
"def",
"write",
"(",
"self",
",",
"value",
")",
":",
"aio_block",
"=",
"libaio",
".",
"AIOBlock",
"(",
"mode",
"=",
"libaio",
".",
"AIOBLOCK_MODE_WRITE",
",",
"target_file",
"=",
"self",
".",
"getEndpoint",
"(",
"1",
")",
",",
"buffer_list",
"=",
"[",
... | Queue write in kernel.
value (bytes)
Value to send. | [
"Queue",
"write",
"in",
"kernel",
".",
"value",
"(",
"bytes",
")",
"Value",
"to",
"send",
"."
] | e19f729bb47a7d1edd2488531af24551bb86726f | https://github.com/vpelletier/python-functionfs/blob/e19f729bb47a7d1edd2488531af24551bb86726f/examples/usbcat/device.py#L196-L213 | train |
oasis-open/cti-stix-validator | stix2validator/errors.py | pretty_error | def pretty_error(error, verbose=False):
"""Return an error message that is easier to read and more useful.
May require updating if the schemas change significantly.
"""
error_loc = ''
if error.path:
while len(error.path) > 0:
path_elem = error.path.popleft()
if type(... | python | def pretty_error(error, verbose=False):
"""Return an error message that is easier to read and more useful.
May require updating if the schemas change significantly.
"""
error_loc = ''
if error.path:
while len(error.path) > 0:
path_elem = error.path.popleft()
if type(... | [
"def",
"pretty_error",
"(",
"error",
",",
"verbose",
"=",
"False",
")",
":",
"error_loc",
"=",
"''",
"if",
"error",
".",
"path",
":",
"while",
"len",
"(",
"error",
".",
"path",
")",
">",
"0",
":",
"path_elem",
"=",
"error",
".",
"path",
".",
"pople... | Return an error message that is easier to read and more useful.
May require updating if the schemas change significantly. | [
"Return",
"an",
"error",
"message",
"that",
"is",
"easier",
"to",
"read",
"and",
"more",
"useful",
".",
"May",
"require",
"updating",
"if",
"the",
"schemas",
"change",
"significantly",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/errors.py#L71-L252 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | _iter_errors_custom | def _iter_errors_custom(instance, checks, options):
"""Perform additional validation not possible merely with JSON schemas.
Args:
instance: The STIX object to be validated.
checks: A sequence of callables which do the checks. Each callable
may be written to accept 1 arg, which is t... | python | def _iter_errors_custom(instance, checks, options):
"""Perform additional validation not possible merely with JSON schemas.
Args:
instance: The STIX object to be validated.
checks: A sequence of callables which do the checks. Each callable
may be written to accept 1 arg, which is t... | [
"def",
"_iter_errors_custom",
"(",
"instance",
",",
"checks",
",",
"options",
")",
":",
"# Perform validation",
"for",
"v_function",
"in",
"checks",
":",
"try",
":",
"result",
"=",
"v_function",
"(",
"instance",
")",
"except",
"TypeError",
":",
"result",
"=",
... | Perform additional validation not possible merely with JSON schemas.
Args:
instance: The STIX object to be validated.
checks: A sequence of callables which do the checks. Each callable
may be written to accept 1 arg, which is the object to check,
or 2 args, which are the ob... | [
"Perform",
"additional",
"validation",
"not",
"possible",
"merely",
"with",
"JSON",
"schemas",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L34-L63 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | list_json_files | def list_json_files(directory, recursive=False):
"""Return a list of file paths for JSON files within `directory`.
Args:
directory: A path to a directory.
recursive: If ``True``, this function will descend into all
subdirectories.
Returns:
A list of JSON file paths dire... | python | def list_json_files(directory, recursive=False):
"""Return a list of file paths for JSON files within `directory`.
Args:
directory: A path to a directory.
recursive: If ``True``, this function will descend into all
subdirectories.
Returns:
A list of JSON file paths dire... | [
"def",
"list_json_files",
"(",
"directory",
",",
"recursive",
"=",
"False",
")",
":",
"json_files",
"=",
"[",
"]",
"for",
"top",
",",
"dirs",
",",
"files",
"in",
"os",
".",
"walk",
"(",
"directory",
")",
":",
"dirs",
".",
"sort",
"(",
")",
"# Get pat... | Return a list of file paths for JSON files within `directory`.
Args:
directory: A path to a directory.
recursive: If ``True``, this function will descend into all
subdirectories.
Returns:
A list of JSON file paths directly under `directory`. | [
"Return",
"a",
"list",
"of",
"file",
"paths",
"for",
"JSON",
"files",
"within",
"directory",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L281-L306 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | get_json_files | def get_json_files(files, recursive=False):
"""Return a list of files to validate from `files`. If a member of `files`
is a directory, its children with a ``.json`` extension will be added to
the return value.
Args:
files: A list of file paths and/or directory paths.
recursive: If ``tru... | python | def get_json_files(files, recursive=False):
"""Return a list of files to validate from `files`. If a member of `files`
is a directory, its children with a ``.json`` extension will be added to
the return value.
Args:
files: A list of file paths and/or directory paths.
recursive: If ``tru... | [
"def",
"get_json_files",
"(",
"files",
",",
"recursive",
"=",
"False",
")",
":",
"json_files",
"=",
"[",
"]",
"if",
"not",
"files",
":",
"return",
"json_files",
"for",
"fn",
"in",
"files",
":",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"fn",
")",
... | Return a list of files to validate from `files`. If a member of `files`
is a directory, its children with a ``.json`` extension will be added to
the return value.
Args:
files: A list of file paths and/or directory paths.
recursive: If ``true``, this will descend into any subdirectories
... | [
"Return",
"a",
"list",
"of",
"files",
"to",
"validate",
"from",
"files",
".",
"If",
"a",
"member",
"of",
"files",
"is",
"a",
"directory",
"its",
"children",
"with",
"a",
".",
"json",
"extension",
"will",
"be",
"added",
"to",
"the",
"return",
"value",
"... | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L309-L339 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | run_validation | def run_validation(options):
"""Validate files based on command line options.
Args:
options: An instance of ``ValidationOptions`` containing options for
this validation run.
"""
if options.files == sys.stdin:
results = validate(options.files, options)
return [FileVa... | python | def run_validation(options):
"""Validate files based on command line options.
Args:
options: An instance of ``ValidationOptions`` containing options for
this validation run.
"""
if options.files == sys.stdin:
results = validate(options.files, options)
return [FileVa... | [
"def",
"run_validation",
"(",
"options",
")",
":",
"if",
"options",
".",
"files",
"==",
"sys",
".",
"stdin",
":",
"results",
"=",
"validate",
"(",
"options",
".",
"files",
",",
"options",
")",
"return",
"[",
"FileValidationResults",
"(",
"is_valid",
"=",
... | Validate files based on command line options.
Args:
options: An instance of ``ValidationOptions`` containing options for
this validation run. | [
"Validate",
"files",
"based",
"on",
"command",
"line",
"options",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L342-L360 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | validate_parsed_json | def validate_parsed_json(obj_json, options=None):
"""
Validate objects from parsed JSON. This supports a single object, or a
list of objects. If a single object is given, a single result is
returned. Otherwise, a list of results is returned.
If an error occurs, a ValidationErrorResults instance ... | python | def validate_parsed_json(obj_json, options=None):
"""
Validate objects from parsed JSON. This supports a single object, or a
list of objects. If a single object is given, a single result is
returned. Otherwise, a list of results is returned.
If an error occurs, a ValidationErrorResults instance ... | [
"def",
"validate_parsed_json",
"(",
"obj_json",
",",
"options",
"=",
"None",
")",
":",
"validating_list",
"=",
"isinstance",
"(",
"obj_json",
",",
"list",
")",
"if",
"not",
"options",
":",
"options",
"=",
"ValidationOptions",
"(",
")",
"if",
"not",
"options"... | Validate objects from parsed JSON. This supports a single object, or a
list of objects. If a single object is given, a single result is
returned. Otherwise, a list of results is returned.
If an error occurs, a ValidationErrorResults instance or list which
includes one of these instances, is returned... | [
"Validate",
"objects",
"from",
"parsed",
"JSON",
".",
"This",
"supports",
"a",
"single",
"object",
"or",
"a",
"list",
"of",
"objects",
".",
"If",
"a",
"single",
"object",
"is",
"given",
"a",
"single",
"result",
"is",
"returned",
".",
"Otherwise",
"a",
"l... | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L363-L408 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | validate | def validate(in_, options=None):
"""
Validate objects from JSON data in a textual stream.
:param in_: A textual stream of JSON data.
:param options: Validation options
:return: An ObjectValidationResults instance, or a list of such.
"""
obj_json = json.load(in_)
results = validate_pars... | python | def validate(in_, options=None):
"""
Validate objects from JSON data in a textual stream.
:param in_: A textual stream of JSON data.
:param options: Validation options
:return: An ObjectValidationResults instance, or a list of such.
"""
obj_json = json.load(in_)
results = validate_pars... | [
"def",
"validate",
"(",
"in_",
",",
"options",
"=",
"None",
")",
":",
"obj_json",
"=",
"json",
".",
"load",
"(",
"in_",
")",
"results",
"=",
"validate_parsed_json",
"(",
"obj_json",
",",
"options",
")",
"return",
"results"
] | Validate objects from JSON data in a textual stream.
:param in_: A textual stream of JSON data.
:param options: Validation options
:return: An ObjectValidationResults instance, or a list of such. | [
"Validate",
"objects",
"from",
"JSON",
"data",
"in",
"a",
"textual",
"stream",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L411-L423 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | validate_file | def validate_file(fn, options=None):
"""Validate the input document `fn` according to the options passed in.
If any exceptions are raised during validation, no further validation
will take place.
Args:
fn: The filename of the JSON file to be validated.
options: An instance of ``Validat... | python | def validate_file(fn, options=None):
"""Validate the input document `fn` according to the options passed in.
If any exceptions are raised during validation, no further validation
will take place.
Args:
fn: The filename of the JSON file to be validated.
options: An instance of ``Validat... | [
"def",
"validate_file",
"(",
"fn",
",",
"options",
"=",
"None",
")",
":",
"file_results",
"=",
"FileValidationResults",
"(",
"filepath",
"=",
"fn",
")",
"output",
".",
"info",
"(",
"\"Performing JSON schema validation on %s\"",
"%",
"fn",
")",
"if",
"not",
"op... | Validate the input document `fn` according to the options passed in.
If any exceptions are raised during validation, no further validation
will take place.
Args:
fn: The filename of the JSON file to be validated.
options: An instance of ``ValidationOptions``.
Returns:
An insta... | [
"Validate",
"the",
"input",
"document",
"fn",
"according",
"to",
"the",
"options",
"passed",
"in",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L426-L467 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | validate_string | def validate_string(string, options=None):
"""Validate the input `string` according to the options passed in.
If any exceptions are raised during validation, no further validation
will take place.
Args:
string: The string containing the JSON to be validated.
options: An instance of ``V... | python | def validate_string(string, options=None):
"""Validate the input `string` according to the options passed in.
If any exceptions are raised during validation, no further validation
will take place.
Args:
string: The string containing the JSON to be validated.
options: An instance of ``V... | [
"def",
"validate_string",
"(",
"string",
",",
"options",
"=",
"None",
")",
":",
"output",
".",
"info",
"(",
"\"Performing JSON schema validation on input string: \"",
"+",
"string",
")",
"stream",
"=",
"io",
".",
"StringIO",
"(",
"string",
")",
"return",
"valida... | Validate the input `string` according to the options passed in.
If any exceptions are raised during validation, no further validation
will take place.
Args:
string: The string containing the JSON to be validated.
options: An instance of ``ValidationOptions``.
Returns:
An Objec... | [
"Validate",
"the",
"input",
"string",
"according",
"to",
"the",
"options",
"passed",
"in",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L470-L486 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | load_validator | def load_validator(schema_path, schema):
"""Create a JSON schema validator for the given schema.
Args:
schema_path: The filename of the JSON schema.
schema: A Python object representation of the same schema.
Returns:
An instance of Draft4Validator.
"""
# Get correct prefix... | python | def load_validator(schema_path, schema):
"""Create a JSON schema validator for the given schema.
Args:
schema_path: The filename of the JSON schema.
schema: A Python object representation of the same schema.
Returns:
An instance of Draft4Validator.
"""
# Get correct prefix... | [
"def",
"load_validator",
"(",
"schema_path",
",",
"schema",
")",
":",
"# Get correct prefix based on OS",
"if",
"os",
".",
"name",
"==",
"'nt'",
":",
"file_prefix",
"=",
"'file:///'",
"else",
":",
"file_prefix",
"=",
"'file:'",
"resolver",
"=",
"RefResolver",
"(... | Create a JSON schema validator for the given schema.
Args:
schema_path: The filename of the JSON schema.
schema: A Python object representation of the same schema.
Returns:
An instance of Draft4Validator. | [
"Create",
"a",
"JSON",
"schema",
"validator",
"for",
"the",
"given",
"schema",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L489-L509 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | find_schema | def find_schema(schema_dir, obj_type):
"""Search the `schema_dir` directory for a schema called `obj_type`.json.
Return the file path of the first match it finds.
"""
schema_filename = obj_type + '.json'
for root, dirnames, filenames in os.walk(schema_dir):
if schema_filename in filenames:
... | python | def find_schema(schema_dir, obj_type):
"""Search the `schema_dir` directory for a schema called `obj_type`.json.
Return the file path of the first match it finds.
"""
schema_filename = obj_type + '.json'
for root, dirnames, filenames in os.walk(schema_dir):
if schema_filename in filenames:
... | [
"def",
"find_schema",
"(",
"schema_dir",
",",
"obj_type",
")",
":",
"schema_filename",
"=",
"obj_type",
"+",
"'.json'",
"for",
"root",
",",
"dirnames",
",",
"filenames",
"in",
"os",
".",
"walk",
"(",
"schema_dir",
")",
":",
"if",
"schema_filename",
"in",
"... | Search the `schema_dir` directory for a schema called `obj_type`.json.
Return the file path of the first match it finds. | [
"Search",
"the",
"schema_dir",
"directory",
"for",
"a",
"schema",
"called",
"obj_type",
".",
"json",
".",
"Return",
"the",
"file",
"path",
"of",
"the",
"first",
"match",
"it",
"finds",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L512-L520 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | load_schema | def load_schema(schema_path):
"""Load the JSON schema at the given path as a Python object.
Args:
schema_path: A filename for a JSON schema.
Returns:
A Python object representation of the schema.
"""
try:
with open(schema_path) as schema_file:
schema = json.loa... | python | def load_schema(schema_path):
"""Load the JSON schema at the given path as a Python object.
Args:
schema_path: A filename for a JSON schema.
Returns:
A Python object representation of the schema.
"""
try:
with open(schema_path) as schema_file:
schema = json.loa... | [
"def",
"load_schema",
"(",
"schema_path",
")",
":",
"try",
":",
"with",
"open",
"(",
"schema_path",
")",
"as",
"schema_file",
":",
"schema",
"=",
"json",
".",
"load",
"(",
"schema_file",
")",
"except",
"ValueError",
"as",
"e",
":",
"raise",
"SchemaInvalidE... | Load the JSON schema at the given path as a Python object.
Args:
schema_path: A filename for a JSON schema.
Returns:
A Python object representation of the schema. | [
"Load",
"the",
"JSON",
"schema",
"at",
"the",
"given",
"path",
"as",
"a",
"Python",
"object",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L523-L540 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | _get_error_generator | def _get_error_generator(type, obj, schema_dir=None, version=DEFAULT_VER, default='core'):
"""Get a generator for validating against the schema for the given object type.
Args:
type (str): The object type to find the schema for.
obj: The object to be validated.
schema_dir (str): The pat... | python | def _get_error_generator(type, obj, schema_dir=None, version=DEFAULT_VER, default='core'):
"""Get a generator for validating against the schema for the given object type.
Args:
type (str): The object type to find the schema for.
obj: The object to be validated.
schema_dir (str): The pat... | [
"def",
"_get_error_generator",
"(",
"type",
",",
"obj",
",",
"schema_dir",
"=",
"None",
",",
"version",
"=",
"DEFAULT_VER",
",",
"default",
"=",
"'core'",
")",
":",
"# If no schema directory given, use default for the given STIX version,",
"# which comes bundled with this p... | Get a generator for validating against the schema for the given object type.
Args:
type (str): The object type to find the schema for.
obj: The object to be validated.
schema_dir (str): The path in which to search for schemas.
version (str): The version of the STIX specification to ... | [
"Get",
"a",
"generator",
"for",
"validating",
"against",
"the",
"schema",
"for",
"the",
"given",
"object",
"type",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L543-L598 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | _get_musts | def _get_musts(options):
"""Return the list of 'MUST' validators for the correct version of STIX.
Args:
options: ValidationOptions instance with validation options for this
validation run, including the STIX spec version.
"""
if options.version == '2.0':
return musts20.list_... | python | def _get_musts(options):
"""Return the list of 'MUST' validators for the correct version of STIX.
Args:
options: ValidationOptions instance with validation options for this
validation run, including the STIX spec version.
"""
if options.version == '2.0':
return musts20.list_... | [
"def",
"_get_musts",
"(",
"options",
")",
":",
"if",
"options",
".",
"version",
"==",
"'2.0'",
":",
"return",
"musts20",
".",
"list_musts",
"(",
"options",
")",
"else",
":",
"return",
"musts21",
".",
"list_musts",
"(",
"options",
")"
] | Return the list of 'MUST' validators for the correct version of STIX.
Args:
options: ValidationOptions instance with validation options for this
validation run, including the STIX spec version. | [
"Return",
"the",
"list",
"of",
"MUST",
"validators",
"for",
"the",
"correct",
"version",
"of",
"STIX",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L601-L611 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | _get_shoulds | def _get_shoulds(options):
"""Return the list of 'SHOULD' validators for the correct version of STIX.
Args:
options: ValidationOptions instance with validation options for this
validation run, including the STIX spec version.
"""
if options.version == '2.0':
return shoulds20... | python | def _get_shoulds(options):
"""Return the list of 'SHOULD' validators for the correct version of STIX.
Args:
options: ValidationOptions instance with validation options for this
validation run, including the STIX spec version.
"""
if options.version == '2.0':
return shoulds20... | [
"def",
"_get_shoulds",
"(",
"options",
")",
":",
"if",
"options",
".",
"version",
"==",
"'2.0'",
":",
"return",
"shoulds20",
".",
"list_shoulds",
"(",
"options",
")",
"else",
":",
"return",
"shoulds21",
".",
"list_shoulds",
"(",
"options",
")"
] | Return the list of 'SHOULD' validators for the correct version of STIX.
Args:
options: ValidationOptions instance with validation options for this
validation run, including the STIX spec version. | [
"Return",
"the",
"list",
"of",
"SHOULD",
"validators",
"for",
"the",
"correct",
"version",
"of",
"STIX",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L614-L624 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | _schema_validate | def _schema_validate(sdo, options):
"""Set up validation of a single STIX object against its type's schema.
This does no actual validation; it just returns generators which must be
iterated to trigger the actual generation.
This function first creates generators for the built-in schemas, then adds
... | python | def _schema_validate(sdo, options):
"""Set up validation of a single STIX object against its type's schema.
This does no actual validation; it just returns generators which must be
iterated to trigger the actual generation.
This function first creates generators for the built-in schemas, then adds
... | [
"def",
"_schema_validate",
"(",
"sdo",
",",
"options",
")",
":",
"error_gens",
"=",
"[",
"]",
"if",
"'id'",
"in",
"sdo",
":",
"try",
":",
"error_prefix",
"=",
"sdo",
"[",
"'id'",
"]",
"+",
"\": \"",
"except",
"TypeError",
":",
"error_prefix",
"=",
"'un... | Set up validation of a single STIX object against its type's schema.
This does no actual validation; it just returns generators which must be
iterated to trigger the actual generation.
This function first creates generators for the built-in schemas, then adds
generators for additional schemas from the ... | [
"Set",
"up",
"validation",
"of",
"a",
"single",
"STIX",
"object",
"against",
"its",
"type",
"s",
"schema",
".",
"This",
"does",
"no",
"actual",
"validation",
";",
"it",
"just",
"returns",
"generators",
"which",
"must",
"be",
"iterated",
"to",
"trigger",
"t... | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L627-L692 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | validate_instance | def validate_instance(instance, options=None):
"""Perform STIX JSON Schema validation against STIX input.
Find the correct schema by looking at the 'type' property of the
`instance` JSON object.
Args:
instance: A Python dictionary representing a STIX object with a
'type' property.
... | python | def validate_instance(instance, options=None):
"""Perform STIX JSON Schema validation against STIX input.
Find the correct schema by looking at the 'type' property of the
`instance` JSON object.
Args:
instance: A Python dictionary representing a STIX object with a
'type' property.
... | [
"def",
"validate_instance",
"(",
"instance",
",",
"options",
"=",
"None",
")",
":",
"if",
"'type'",
"not",
"in",
"instance",
":",
"raise",
"ValidationError",
"(",
"\"Input must be an object with a 'type' property.\"",
")",
"if",
"not",
"options",
":",
"options",
"... | Perform STIX JSON Schema validation against STIX input.
Find the correct schema by looking at the 'type' property of the
`instance` JSON object.
Args:
instance: A Python dictionary representing a STIX object with a
'type' property.
options: ValidationOptions instance with valid... | [
"Perform",
"STIX",
"JSON",
"Schema",
"validation",
"against",
"STIX",
"input",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L695-L766 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | FileValidationResults.object_result | def object_result(self):
"""
Get the object result object, assuming there is only one. Raises
an error if there is more than one.
:return: The result object
:raises ValueError: If there is more than one result
"""
num_obj_results = len(self._object_results)
... | python | def object_result(self):
"""
Get the object result object, assuming there is only one. Raises
an error if there is more than one.
:return: The result object
:raises ValueError: If there is more than one result
"""
num_obj_results = len(self._object_results)
... | [
"def",
"object_result",
"(",
"self",
")",
":",
"num_obj_results",
"=",
"len",
"(",
"self",
".",
"_object_results",
")",
"if",
"num_obj_results",
"<",
"1",
":",
"return",
"None",
"elif",
"num_obj_results",
"<",
"2",
":",
"return",
"self",
".",
"_object_result... | Get the object result object, assuming there is only one. Raises
an error if there is more than one.
:return: The result object
:raises ValueError: If there is more than one result | [
"Get",
"the",
"object",
"result",
"object",
"assuming",
"there",
"is",
"only",
"one",
".",
"Raises",
"an",
"error",
"if",
"there",
"is",
"more",
"than",
"one",
".",
":",
"return",
":",
"The",
"result",
"object",
":",
"raises",
"ValueError",
":",
"If",
... | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L129-L143 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | FileValidationResults.object_results | def object_results(self, object_results):
"""
Set the results to an iterable of values. The values will be collected
into a list. A single value is allowed; it will be converted to a
length 1 list.
:param object_results: The results to set
"""
if _is_iterable_no... | python | def object_results(self, object_results):
"""
Set the results to an iterable of values. The values will be collected
into a list. A single value is allowed; it will be converted to a
length 1 list.
:param object_results: The results to set
"""
if _is_iterable_no... | [
"def",
"object_results",
"(",
"self",
",",
"object_results",
")",
":",
"if",
"_is_iterable_non_string",
"(",
"object_results",
")",
":",
"self",
".",
"_object_results",
"=",
"list",
"(",
"object_results",
")",
"elif",
"object_results",
"is",
"None",
":",
"self",... | Set the results to an iterable of values. The values will be collected
into a list. A single value is allowed; it will be converted to a
length 1 list.
:param object_results: The results to set | [
"Set",
"the",
"results",
"to",
"an",
"iterable",
"of",
"values",
".",
"The",
"values",
"will",
"be",
"collected",
"into",
"a",
"list",
".",
"A",
"single",
"value",
"is",
"allowed",
";",
"it",
"will",
"be",
"converted",
"to",
"a",
"length",
"1",
"list",... | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L167-L179 | train |
oasis-open/cti-stix-validator | stix2validator/validator.py | ObjectValidationResults.as_dict | def as_dict(self):
"""A dictionary representation of the :class:`.ObjectValidationResults`
instance.
Keys:
* ``'result'``: The validation results (``True`` or ``False``)
* ``'errors'``: A list of validation errors.
Returns:
A dictionary representatio... | python | def as_dict(self):
"""A dictionary representation of the :class:`.ObjectValidationResults`
instance.
Keys:
* ``'result'``: The validation results (``True`` or ``False``)
* ``'errors'``: A list of validation errors.
Returns:
A dictionary representatio... | [
"def",
"as_dict",
"(",
"self",
")",
":",
"d",
"=",
"super",
"(",
"ObjectValidationResults",
",",
"self",
")",
".",
"as_dict",
"(",
")",
"if",
"self",
".",
"errors",
":",
"d",
"[",
"'errors'",
"]",
"=",
"[",
"x",
".",
"as_dict",
"(",
")",
"for",
"... | A dictionary representation of the :class:`.ObjectValidationResults`
instance.
Keys:
* ``'result'``: The validation results (``True`` or ``False``)
* ``'errors'``: A list of validation errors.
Returns:
A dictionary representation of an instance of this class... | [
"A",
"dictionary",
"representation",
"of",
"the",
":",
"class",
":",
".",
"ObjectValidationResults",
"instance",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L226-L243 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | custom_prefix_strict | def custom_prefix_strict(instance):
"""Ensure custom content follows strict naming style conventions.
"""
for error in chain(custom_object_prefix_strict(instance),
custom_property_prefix_strict(instance),
custom_observable_object_prefix_strict(instance),
... | python | def custom_prefix_strict(instance):
"""Ensure custom content follows strict naming style conventions.
"""
for error in chain(custom_object_prefix_strict(instance),
custom_property_prefix_strict(instance),
custom_observable_object_prefix_strict(instance),
... | [
"def",
"custom_prefix_strict",
"(",
"instance",
")",
":",
"for",
"error",
"in",
"chain",
"(",
"custom_object_prefix_strict",
"(",
"instance",
")",
",",
"custom_property_prefix_strict",
"(",
"instance",
")",
",",
"custom_observable_object_prefix_strict",
"(",
"instance",... | Ensure custom content follows strict naming style conventions. | [
"Ensure",
"custom",
"content",
"follows",
"strict",
"naming",
"style",
"conventions",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L32-L40 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | custom_prefix_lax | def custom_prefix_lax(instance):
"""Ensure custom content follows lenient naming style conventions
for forward-compatibility.
"""
for error in chain(custom_object_prefix_lax(instance),
custom_property_prefix_lax(instance),
custom_observable_object_prefix_lax... | python | def custom_prefix_lax(instance):
"""Ensure custom content follows lenient naming style conventions
for forward-compatibility.
"""
for error in chain(custom_object_prefix_lax(instance),
custom_property_prefix_lax(instance),
custom_observable_object_prefix_lax... | [
"def",
"custom_prefix_lax",
"(",
"instance",
")",
":",
"for",
"error",
"in",
"chain",
"(",
"custom_object_prefix_lax",
"(",
"instance",
")",
",",
"custom_property_prefix_lax",
"(",
"instance",
")",
",",
"custom_observable_object_prefix_lax",
"(",
"instance",
")",
",... | Ensure custom content follows lenient naming style conventions
for forward-compatibility. | [
"Ensure",
"custom",
"content",
"follows",
"lenient",
"naming",
"style",
"conventions",
"for",
"forward",
"-",
"compatibility",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L43-L52 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | custom_object_prefix_strict | def custom_object_prefix_strict(instance):
"""Ensure custom objects follow strict naming style conventions.
"""
if (instance['type'] not in enums.TYPES and
instance['type'] not in enums.RESERVED_OBJECTS and
not CUSTOM_TYPE_PREFIX_RE.match(instance['type'])):
yield JSONError("... | python | def custom_object_prefix_strict(instance):
"""Ensure custom objects follow strict naming style conventions.
"""
if (instance['type'] not in enums.TYPES and
instance['type'] not in enums.RESERVED_OBJECTS and
not CUSTOM_TYPE_PREFIX_RE.match(instance['type'])):
yield JSONError("... | [
"def",
"custom_object_prefix_strict",
"(",
"instance",
")",
":",
"if",
"(",
"instance",
"[",
"'type'",
"]",
"not",
"in",
"enums",
".",
"TYPES",
"and",
"instance",
"[",
"'type'",
"]",
"not",
"in",
"enums",
".",
"RESERVED_OBJECTS",
"and",
"not",
"CUSTOM_TYPE_P... | Ensure custom objects follow strict naming style conventions. | [
"Ensure",
"custom",
"objects",
"follow",
"strict",
"naming",
"style",
"conventions",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L55-L65 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | custom_object_prefix_lax | def custom_object_prefix_lax(instance):
"""Ensure custom objects follow lenient naming style conventions
for forward-compatibility.
"""
if (instance['type'] not in enums.TYPES and
instance['type'] not in enums.RESERVED_OBJECTS and
not CUSTOM_TYPE_LAX_PREFIX_RE.match(instance['typ... | python | def custom_object_prefix_lax(instance):
"""Ensure custom objects follow lenient naming style conventions
for forward-compatibility.
"""
if (instance['type'] not in enums.TYPES and
instance['type'] not in enums.RESERVED_OBJECTS and
not CUSTOM_TYPE_LAX_PREFIX_RE.match(instance['typ... | [
"def",
"custom_object_prefix_lax",
"(",
"instance",
")",
":",
"if",
"(",
"instance",
"[",
"'type'",
"]",
"not",
"in",
"enums",
".",
"TYPES",
"and",
"instance",
"[",
"'type'",
"]",
"not",
"in",
"enums",
".",
"RESERVED_OBJECTS",
"and",
"not",
"CUSTOM_TYPE_LAX_... | Ensure custom objects follow lenient naming style conventions
for forward-compatibility. | [
"Ensure",
"custom",
"objects",
"follow",
"lenient",
"naming",
"style",
"conventions",
"for",
"forward",
"-",
"compatibility",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L68-L78 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | custom_property_prefix_strict | def custom_property_prefix_strict(instance):
"""Ensure custom properties follow strict naming style conventions.
Does not check property names in custom objects.
"""
for prop_name in instance.keys():
if (instance['type'] in enums.PROPERTIES and
prop_name not in enums.PROPERTIES[... | python | def custom_property_prefix_strict(instance):
"""Ensure custom properties follow strict naming style conventions.
Does not check property names in custom objects.
"""
for prop_name in instance.keys():
if (instance['type'] in enums.PROPERTIES and
prop_name not in enums.PROPERTIES[... | [
"def",
"custom_property_prefix_strict",
"(",
"instance",
")",
":",
"for",
"prop_name",
"in",
"instance",
".",
"keys",
"(",
")",
":",
"if",
"(",
"instance",
"[",
"'type'",
"]",
"in",
"enums",
".",
"PROPERTIES",
"and",
"prop_name",
"not",
"in",
"enums",
".",... | Ensure custom properties follow strict naming style conventions.
Does not check property names in custom objects. | [
"Ensure",
"custom",
"properties",
"follow",
"strict",
"naming",
"style",
"conventions",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L81-L97 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | custom_property_prefix_lax | def custom_property_prefix_lax(instance):
"""Ensure custom properties follow lenient naming style conventions
for forward-compatibility.
Does not check property names in custom objects.
"""
for prop_name in instance.keys():
if (instance['type'] in enums.PROPERTIES and
prop_n... | python | def custom_property_prefix_lax(instance):
"""Ensure custom properties follow lenient naming style conventions
for forward-compatibility.
Does not check property names in custom objects.
"""
for prop_name in instance.keys():
if (instance['type'] in enums.PROPERTIES and
prop_n... | [
"def",
"custom_property_prefix_lax",
"(",
"instance",
")",
":",
"for",
"prop_name",
"in",
"instance",
".",
"keys",
"(",
")",
":",
"if",
"(",
"instance",
"[",
"'type'",
"]",
"in",
"enums",
".",
"PROPERTIES",
"and",
"prop_name",
"not",
"in",
"enums",
".",
... | Ensure custom properties follow lenient naming style conventions
for forward-compatibility.
Does not check property names in custom objects. | [
"Ensure",
"custom",
"properties",
"follow",
"lenient",
"naming",
"style",
"conventions",
"for",
"forward",
"-",
"compatibility",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L100-L116 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | open_vocab_values | def open_vocab_values(instance):
"""Ensure that the values of all properties which use open vocabularies are
in lowercase and use hyphens instead of spaces or underscores as word
separators.
"""
if instance['type'] not in enums.VOCAB_PROPERTIES:
return
properties = enums.VOCAB_PROPERTIE... | python | def open_vocab_values(instance):
"""Ensure that the values of all properties which use open vocabularies are
in lowercase and use hyphens instead of spaces or underscores as word
separators.
"""
if instance['type'] not in enums.VOCAB_PROPERTIES:
return
properties = enums.VOCAB_PROPERTIE... | [
"def",
"open_vocab_values",
"(",
"instance",
")",
":",
"if",
"instance",
"[",
"'type'",
"]",
"not",
"in",
"enums",
".",
"VOCAB_PROPERTIES",
":",
"return",
"properties",
"=",
"enums",
".",
"VOCAB_PROPERTIES",
"[",
"instance",
"[",
"'type'",
"]",
"]",
"for",
... | Ensure that the values of all properties which use open vocabularies are
in lowercase and use hyphens instead of spaces or underscores as word
separators. | [
"Ensure",
"that",
"the",
"values",
"of",
"all",
"properties",
"which",
"use",
"open",
"vocabularies",
"are",
"in",
"lowercase",
"and",
"use",
"hyphens",
"instead",
"of",
"spaces",
"or",
"underscores",
"as",
"word",
"separators",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L119-L142 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | kill_chain_phase_names | def kill_chain_phase_names(instance):
"""Ensure the `kill_chain_name` and `phase_name` properties of
`kill_chain_phase` objects follow naming style conventions.
"""
if instance['type'] in enums.KILL_CHAIN_PHASE_USES and 'kill_chain_phases' in instance:
for phase in instance['kill_chain_phases']:... | python | def kill_chain_phase_names(instance):
"""Ensure the `kill_chain_name` and `phase_name` properties of
`kill_chain_phase` objects follow naming style conventions.
"""
if instance['type'] in enums.KILL_CHAIN_PHASE_USES and 'kill_chain_phases' in instance:
for phase in instance['kill_chain_phases']:... | [
"def",
"kill_chain_phase_names",
"(",
"instance",
")",
":",
"if",
"instance",
"[",
"'type'",
"]",
"in",
"enums",
".",
"KILL_CHAIN_PHASE_USES",
"and",
"'kill_chain_phases'",
"in",
"instance",
":",
"for",
"phase",
"in",
"instance",
"[",
"'kill_chain_phases'",
"]",
... | Ensure the `kill_chain_name` and `phase_name` properties of
`kill_chain_phase` objects follow naming style conventions. | [
"Ensure",
"the",
"kill_chain_name",
"and",
"phase_name",
"properties",
"of",
"kill_chain_phase",
"objects",
"follow",
"naming",
"style",
"conventions",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L145-L168 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | check_vocab | def check_vocab(instance, vocab, code):
"""Ensure that the open vocabulary specified by `vocab` is used properly.
This checks properties of objects specified in the appropriate `_USES`
dictionary to determine which properties SHOULD use the given vocabulary,
then checks that the values in those propert... | python | def check_vocab(instance, vocab, code):
"""Ensure that the open vocabulary specified by `vocab` is used properly.
This checks properties of objects specified in the appropriate `_USES`
dictionary to determine which properties SHOULD use the given vocabulary,
then checks that the values in those propert... | [
"def",
"check_vocab",
"(",
"instance",
",",
"vocab",
",",
"code",
")",
":",
"vocab_uses",
"=",
"getattr",
"(",
"enums",
",",
"vocab",
"+",
"\"_USES\"",
")",
"for",
"k",
"in",
"vocab_uses",
".",
"keys",
"(",
")",
":",
"if",
"instance",
"[",
"'type'",
... | Ensure that the open vocabulary specified by `vocab` is used properly.
This checks properties of objects specified in the appropriate `_USES`
dictionary to determine which properties SHOULD use the given vocabulary,
then checks that the values in those properties are from the vocabulary. | [
"Ensure",
"that",
"the",
"open",
"vocabulary",
"specified",
"by",
"vocab",
"is",
"used",
"properly",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L171-L195 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | vocab_marking_definition | def vocab_marking_definition(instance):
"""Ensure that the `definition_type` property of `marking-definition`
objects is one of the values in the STIX 2.0 specification.
"""
if (instance['type'] == 'marking-definition' and
'definition_type' in instance and not
instance['definitio... | python | def vocab_marking_definition(instance):
"""Ensure that the `definition_type` property of `marking-definition`
objects is one of the values in the STIX 2.0 specification.
"""
if (instance['type'] == 'marking-definition' and
'definition_type' in instance and not
instance['definitio... | [
"def",
"vocab_marking_definition",
"(",
"instance",
")",
":",
"if",
"(",
"instance",
"[",
"'type'",
"]",
"==",
"'marking-definition'",
"and",
"'definition_type'",
"in",
"instance",
"and",
"not",
"instance",
"[",
"'definition_type'",
"]",
"in",
"enums",
".",
"MAR... | Ensure that the `definition_type` property of `marking-definition`
objects is one of the values in the STIX 2.0 specification. | [
"Ensure",
"that",
"the",
"definition_type",
"property",
"of",
"marking",
"-",
"definition",
"objects",
"is",
"one",
"of",
"the",
"values",
"in",
"the",
"STIX",
"2",
".",
"0",
"specification",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L258-L268 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | relationships_strict | def relationships_strict(instance):
"""Ensure that only the relationship types defined in the specification are
used.
"""
# Don't check objects that aren't relationships or that are custom objects
if (instance['type'] != 'relationship' or
instance['type'] not in enums.TYPES):
ret... | python | def relationships_strict(instance):
"""Ensure that only the relationship types defined in the specification are
used.
"""
# Don't check objects that aren't relationships or that are custom objects
if (instance['type'] != 'relationship' or
instance['type'] not in enums.TYPES):
ret... | [
"def",
"relationships_strict",
"(",
"instance",
")",
":",
"# Don't check objects that aren't relationships or that are custom objects",
"if",
"(",
"instance",
"[",
"'type'",
"]",
"!=",
"'relationship'",
"or",
"instance",
"[",
"'type'",
"]",
"not",
"in",
"enums",
".",
... | Ensure that only the relationship types defined in the specification are
used. | [
"Ensure",
"that",
"only",
"the",
"relationship",
"types",
"defined",
"in",
"the",
"specification",
"are",
"used",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L271-L315 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | valid_hash_value | def valid_hash_value(hashname):
"""Return true if given value is a valid, recommended hash name according
to the STIX 2 specification.
"""
custom_hash_prefix_re = re.compile(r"^x_")
if hashname in enums.HASH_ALGO_OV or custom_hash_prefix_re.match(hashname):
return True
else:
retu... | python | def valid_hash_value(hashname):
"""Return true if given value is a valid, recommended hash name according
to the STIX 2 specification.
"""
custom_hash_prefix_re = re.compile(r"^x_")
if hashname in enums.HASH_ALGO_OV or custom_hash_prefix_re.match(hashname):
return True
else:
retu... | [
"def",
"valid_hash_value",
"(",
"hashname",
")",
":",
"custom_hash_prefix_re",
"=",
"re",
".",
"compile",
"(",
"r\"^x_\"",
")",
"if",
"hashname",
"in",
"enums",
".",
"HASH_ALGO_OV",
"or",
"custom_hash_prefix_re",
".",
"match",
"(",
"hashname",
")",
":",
"retur... | Return true if given value is a valid, recommended hash name according
to the STIX 2 specification. | [
"Return",
"true",
"if",
"given",
"value",
"is",
"a",
"valid",
"recommended",
"hash",
"name",
"according",
"to",
"the",
"STIX",
"2",
"specification",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L318-L326 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | vocab_hash_algo | def vocab_hash_algo(instance):
"""Ensure objects with 'hashes' properties only use values from the
hash-algo-ov vocabulary.
"""
for key, obj in instance['objects'].items():
if 'type' not in obj:
continue
if obj['type'] == 'file':
try:
hashes = obj... | python | def vocab_hash_algo(instance):
"""Ensure objects with 'hashes' properties only use values from the
hash-algo-ov vocabulary.
"""
for key, obj in instance['objects'].items():
if 'type' not in obj:
continue
if obj['type'] == 'file':
try:
hashes = obj... | [
"def",
"vocab_hash_algo",
"(",
"instance",
")",
":",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"'type'",
"not",
"in",
"obj",
":",
"continue",
"if",
"obj",
"[",
"'type'",
"]",
"==",
"'file'",... | Ensure objects with 'hashes' properties only use values from the
hash-algo-ov vocabulary. | [
"Ensure",
"objects",
"with",
"hashes",
"properties",
"only",
"use",
"values",
"from",
"the",
"hash",
"-",
"algo",
"-",
"ov",
"vocabulary",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L330-L427 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | vocab_windows_pebinary_type | def vocab_windows_pebinary_type(instance):
"""Ensure file objects with the windows-pebinary-ext extension have a
'pe-type' property that is from the windows-pebinary-type-ov vocabulary.
"""
for key, obj in instance['objects'].items():
if 'type' in obj and obj['type'] == 'file':
try:
... | python | def vocab_windows_pebinary_type(instance):
"""Ensure file objects with the windows-pebinary-ext extension have a
'pe-type' property that is from the windows-pebinary-type-ov vocabulary.
"""
for key, obj in instance['objects'].items():
if 'type' in obj and obj['type'] == 'file':
try:
... | [
"def",
"vocab_windows_pebinary_type",
"(",
"instance",
")",
":",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"'type'",
"in",
"obj",
"and",
"obj",
"[",
"'type'",
"]",
"==",
"'file'",
":",
"try",
... | Ensure file objects with the windows-pebinary-ext extension have a
'pe-type' property that is from the windows-pebinary-type-ov vocabulary. | [
"Ensure",
"file",
"objects",
"with",
"the",
"windows",
"-",
"pebinary",
"-",
"ext",
"extension",
"have",
"a",
"pe",
"-",
"type",
"property",
"that",
"is",
"from",
"the",
"windows",
"-",
"pebinary",
"-",
"type",
"-",
"ov",
"vocabulary",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L431-L446 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | vocab_account_type | def vocab_account_type(instance):
"""Ensure a user-account objects' 'account-type' property is from the
account-type-ov vocabulary.
"""
for key, obj in instance['objects'].items():
if 'type' in obj and obj['type'] == 'user-account':
try:
acct_type = obj['account_type'... | python | def vocab_account_type(instance):
"""Ensure a user-account objects' 'account-type' property is from the
account-type-ov vocabulary.
"""
for key, obj in instance['objects'].items():
if 'type' in obj and obj['type'] == 'user-account':
try:
acct_type = obj['account_type'... | [
"def",
"vocab_account_type",
"(",
"instance",
")",
":",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"'type'",
"in",
"obj",
"and",
"obj",
"[",
"'type'",
"]",
"==",
"'user-account'",
":",
"try",
... | Ensure a user-account objects' 'account-type' property is from the
account-type-ov vocabulary. | [
"Ensure",
"a",
"user",
"-",
"account",
"objects",
"account",
"-",
"type",
"property",
"is",
"from",
"the",
"account",
"-",
"type",
"-",
"ov",
"vocabulary",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L450-L464 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | observable_object_keys | def observable_object_keys(instance):
"""Ensure observable-objects keys are non-negative integers.
"""
digits_re = re.compile(r"^\d+$")
for key in instance['objects']:
if not digits_re.match(key):
yield JSONError("'%s' is not a good key value. Observable Objects "
... | python | def observable_object_keys(instance):
"""Ensure observable-objects keys are non-negative integers.
"""
digits_re = re.compile(r"^\d+$")
for key in instance['objects']:
if not digits_re.match(key):
yield JSONError("'%s' is not a good key value. Observable Objects "
... | [
"def",
"observable_object_keys",
"(",
"instance",
")",
":",
"digits_re",
"=",
"re",
".",
"compile",
"(",
"r\"^\\d+$\"",
")",
"for",
"key",
"in",
"instance",
"[",
"'objects'",
"]",
":",
"if",
"not",
"digits_re",
".",
"match",
"(",
"key",
")",
":",
"yield"... | Ensure observable-objects keys are non-negative integers. | [
"Ensure",
"observable",
"-",
"objects",
"keys",
"are",
"non",
"-",
"negative",
"integers",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L468-L476 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | custom_observable_object_prefix_strict | def custom_observable_object_prefix_strict(instance):
"""Ensure custom observable objects follow strict naming style conventions.
"""
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] not in enums.OBSERVABLE_TYPES and
obj['type'] not in enums.OBSERVABLE_R... | python | def custom_observable_object_prefix_strict(instance):
"""Ensure custom observable objects follow strict naming style conventions.
"""
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] not in enums.OBSERVABLE_TYPES and
obj['type'] not in enums.OBSERVABLE_R... | [
"def",
"custom_observable_object_prefix_strict",
"(",
"instance",
")",
":",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"(",
"'type'",
"in",
"obj",
"and",
"obj",
"[",
"'type'",
"]",
"not",
"in",
... | Ensure custom observable objects follow strict naming style conventions. | [
"Ensure",
"custom",
"observable",
"objects",
"follow",
"strict",
"naming",
"style",
"conventions",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L504-L516 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | custom_observable_object_prefix_lax | def custom_observable_object_prefix_lax(instance):
"""Ensure custom observable objects follow naming style conventions.
"""
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] not in enums.OBSERVABLE_TYPES and
obj['type'] not in enums.OBSERVABLE_RESERVED_OB... | python | def custom_observable_object_prefix_lax(instance):
"""Ensure custom observable objects follow naming style conventions.
"""
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] not in enums.OBSERVABLE_TYPES and
obj['type'] not in enums.OBSERVABLE_RESERVED_OB... | [
"def",
"custom_observable_object_prefix_lax",
"(",
"instance",
")",
":",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"(",
"'type'",
"in",
"obj",
"and",
"obj",
"[",
"'type'",
"]",
"not",
"in",
"e... | Ensure custom observable objects follow naming style conventions. | [
"Ensure",
"custom",
"observable",
"objects",
"follow",
"naming",
"style",
"conventions",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L520-L530 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | custom_object_extension_prefix_strict | def custom_object_extension_prefix_strict(instance):
"""Ensure custom observable object extensions follow strict naming style
conventions.
"""
for key, obj in instance['objects'].items():
if not ('extensions' in obj and 'type' in obj and
obj['type'] in enums.OBSERVABLE_EXTENSIONS... | python | def custom_object_extension_prefix_strict(instance):
"""Ensure custom observable object extensions follow strict naming style
conventions.
"""
for key, obj in instance['objects'].items():
if not ('extensions' in obj and 'type' in obj and
obj['type'] in enums.OBSERVABLE_EXTENSIONS... | [
"def",
"custom_object_extension_prefix_strict",
"(",
"instance",
")",
":",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"not",
"(",
"'extensions'",
"in",
"obj",
"and",
"'type'",
"in",
"obj",
"and",
... | Ensure custom observable object extensions follow strict naming style
conventions. | [
"Ensure",
"custom",
"observable",
"object",
"extensions",
"follow",
"strict",
"naming",
"style",
"conventions",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L534-L550 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | custom_object_extension_prefix_lax | def custom_object_extension_prefix_lax(instance):
"""Ensure custom observable object extensions follow naming style
conventions.
"""
for key, obj in instance['objects'].items():
if not ('extensions' in obj and 'type' in obj and
obj['type'] in enums.OBSERVABLE_EXTENSIONS):
... | python | def custom_object_extension_prefix_lax(instance):
"""Ensure custom observable object extensions follow naming style
conventions.
"""
for key, obj in instance['objects'].items():
if not ('extensions' in obj and 'type' in obj and
obj['type'] in enums.OBSERVABLE_EXTENSIONS):
... | [
"def",
"custom_object_extension_prefix_lax",
"(",
"instance",
")",
":",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"not",
"(",
"'extensions'",
"in",
"obj",
"and",
"'type'",
"in",
"obj",
"and",
"o... | Ensure custom observable object extensions follow naming style
conventions. | [
"Ensure",
"custom",
"observable",
"object",
"extensions",
"follow",
"naming",
"style",
"conventions",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L554-L568 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | custom_observable_properties_prefix_strict | def custom_observable_properties_prefix_strict(instance):
"""Ensure observable object custom properties follow strict naming style
conventions.
"""
for key, obj in instance['objects'].items():
if 'type' not in obj:
continue
type_ = obj['type']
for prop in obj:
... | python | def custom_observable_properties_prefix_strict(instance):
"""Ensure observable object custom properties follow strict naming style
conventions.
"""
for key, obj in instance['objects'].items():
if 'type' not in obj:
continue
type_ = obj['type']
for prop in obj:
... | [
"def",
"custom_observable_properties_prefix_strict",
"(",
"instance",
")",
":",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"'type'",
"not",
"in",
"obj",
":",
"continue",
"type_",
"=",
"obj",
"[",
... | Ensure observable object custom properties follow strict naming style
conventions. | [
"Ensure",
"observable",
"object",
"custom",
"properties",
"follow",
"strict",
"naming",
"style",
"conventions",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L572-L657 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | network_traffic_ports | def network_traffic_ports(instance):
"""Ensure network-traffic objects contain both src_port and dst_port.
"""
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] == 'network-traffic' and
('src_port' not in obj or 'dst_port' not in obj)):
yield ... | python | def network_traffic_ports(instance):
"""Ensure network-traffic objects contain both src_port and dst_port.
"""
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] == 'network-traffic' and
('src_port' not in obj or 'dst_port' not in obj)):
yield ... | [
"def",
"network_traffic_ports",
"(",
"instance",
")",
":",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"(",
"'type'",
"in",
"obj",
"and",
"obj",
"[",
"'type'",
"]",
"==",
"'network-traffic'",
"a... | Ensure network-traffic objects contain both src_port and dst_port. | [
"Ensure",
"network",
"-",
"traffic",
"objects",
"contain",
"both",
"src_port",
"and",
"dst_port",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L733-L741 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | mime_type | def mime_type(instance):
"""Ensure the 'mime_type' property of file objects comes from the Template
column in the IANA media type registry.
"""
mime_pattern = re.compile(r'^(application|audio|font|image|message|model'
'|multipart|text|video)/[a-zA-Z0-9.+_-]+')
for key, ... | python | def mime_type(instance):
"""Ensure the 'mime_type' property of file objects comes from the Template
column in the IANA media type registry.
"""
mime_pattern = re.compile(r'^(application|audio|font|image|message|model'
'|multipart|text|video)/[a-zA-Z0-9.+_-]+')
for key, ... | [
"def",
"mime_type",
"(",
"instance",
")",
":",
"mime_pattern",
"=",
"re",
".",
"compile",
"(",
"r'^(application|audio|font|image|message|model'",
"'|multipart|text|video)/[a-zA-Z0-9.+_-]+'",
")",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
... | Ensure the 'mime_type' property of file objects comes from the Template
column in the IANA media type registry. | [
"Ensure",
"the",
"mime_type",
"property",
"of",
"file",
"objects",
"comes",
"from",
"the",
"Template",
"column",
"in",
"the",
"IANA",
"media",
"type",
"registry",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L745-L767 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | protocols | def protocols(instance):
"""Ensure the 'protocols' property of network-traffic objects contains only
values from the IANA Service Name and Transport Protocol Port Number
Registry.
"""
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] == 'network-traffic' and
... | python | def protocols(instance):
"""Ensure the 'protocols' property of network-traffic objects contains only
values from the IANA Service Name and Transport Protocol Port Number
Registry.
"""
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] == 'network-traffic' and
... | [
"def",
"protocols",
"(",
"instance",
")",
":",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"(",
"'type'",
"in",
"obj",
"and",
"obj",
"[",
"'type'",
"]",
"==",
"'network-traffic'",
"and",
"'pro... | Ensure the 'protocols' property of network-traffic objects contains only
values from the IANA Service Name and Transport Protocol Port Number
Registry. | [
"Ensure",
"the",
"protocols",
"property",
"of",
"network",
"-",
"traffic",
"objects",
"contains",
"only",
"values",
"from",
"the",
"IANA",
"Service",
"Name",
"and",
"Transport",
"Protocol",
"Port",
"Number",
"Registry",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L771-L796 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | ipfix | def ipfix(instance):
"""Ensure the 'ipfix' property of network-traffic objects contains only
values from the IANA IP Flow Information Export (IPFIX) Entities Registry.
"""
ipf_pattern = re.compile(r'^[a-z][a-zA-Z0-9]+')
for key, obj in instance['objects'].items():
if ('type' in obj and obj['... | python | def ipfix(instance):
"""Ensure the 'ipfix' property of network-traffic objects contains only
values from the IANA IP Flow Information Export (IPFIX) Entities Registry.
"""
ipf_pattern = re.compile(r'^[a-z][a-zA-Z0-9]+')
for key, obj in instance['objects'].items():
if ('type' in obj and obj['... | [
"def",
"ipfix",
"(",
"instance",
")",
":",
"ipf_pattern",
"=",
"re",
".",
"compile",
"(",
"r'^[a-z][a-zA-Z0-9]+'",
")",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"(",
"'type'",
"in",
"obj",
... | Ensure the 'ipfix' property of network-traffic objects contains only
values from the IANA IP Flow Information Export (IPFIX) Entities Registry. | [
"Ensure",
"the",
"ipfix",
"property",
"of",
"network",
"-",
"traffic",
"objects",
"contains",
"only",
"values",
"from",
"the",
"IANA",
"IP",
"Flow",
"Information",
"Export",
"(",
"IPFIX",
")",
"Entities",
"Registry",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L800-L825 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | http_request_headers | def http_request_headers(instance):
"""Ensure the keys of the 'request_headers' property of the http-request-
ext extension of network-traffic objects conform to the format for HTTP
request headers. Use a regex because there isn't a definitive source.
https://www.iana.org/assignments/message-headers/mes... | python | def http_request_headers(instance):
"""Ensure the keys of the 'request_headers' property of the http-request-
ext extension of network-traffic objects conform to the format for HTTP
request headers. Use a regex because there isn't a definitive source.
https://www.iana.org/assignments/message-headers/mes... | [
"def",
"http_request_headers",
"(",
"instance",
")",
":",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"(",
"'type'",
"in",
"obj",
"and",
"obj",
"[",
"'type'",
"]",
"==",
"'network-traffic'",
")"... | Ensure the keys of the 'request_headers' property of the http-request-
ext extension of network-traffic objects conform to the format for HTTP
request headers. Use a regex because there isn't a definitive source.
https://www.iana.org/assignments/message-headers/message-headers.xhtml does
not differentia... | [
"Ensure",
"the",
"keys",
"of",
"the",
"request_headers",
"property",
"of",
"the",
"http",
"-",
"request",
"-",
"ext",
"extension",
"of",
"network",
"-",
"traffic",
"objects",
"conform",
"to",
"the",
"format",
"for",
"HTTP",
"request",
"headers",
".",
"Use",
... | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L829-L850 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | socket_options | def socket_options(instance):
"""Ensure the keys of the 'options' property of the socket-ext extension of
network-traffic objects are only valid socket options (SO_*).
"""
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] == 'network-traffic'):
try:
... | python | def socket_options(instance):
"""Ensure the keys of the 'options' property of the socket-ext extension of
network-traffic objects are only valid socket options (SO_*).
"""
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] == 'network-traffic'):
try:
... | [
"def",
"socket_options",
"(",
"instance",
")",
":",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"(",
"'type'",
"in",
"obj",
"and",
"obj",
"[",
"'type'",
"]",
"==",
"'network-traffic'",
")",
":... | Ensure the keys of the 'options' property of the socket-ext extension of
network-traffic objects are only valid socket options (SO_*). | [
"Ensure",
"the",
"keys",
"of",
"the",
"options",
"property",
"of",
"the",
"socket",
"-",
"ext",
"extension",
"of",
"network",
"-",
"traffic",
"objects",
"are",
"only",
"valid",
"socket",
"options",
"(",
"SO_",
"*",
")",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L854-L870 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | pdf_doc_info | def pdf_doc_info(instance):
"""Ensure the keys of the 'document_info_dict' property of the pdf-ext
extension of file objects are only valid PDF Document Information
Dictionary Keys.
"""
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] == 'file'):
try... | python | def pdf_doc_info(instance):
"""Ensure the keys of the 'document_info_dict' property of the pdf-ext
extension of file objects are only valid PDF Document Information
Dictionary Keys.
"""
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] == 'file'):
try... | [
"def",
"pdf_doc_info",
"(",
"instance",
")",
":",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"(",
"'type'",
"in",
"obj",
"and",
"obj",
"[",
"'type'",
"]",
"==",
"'file'",
")",
":",
"try",
... | Ensure the keys of the 'document_info_dict' property of the pdf-ext
extension of file objects are only valid PDF Document Information
Dictionary Keys. | [
"Ensure",
"the",
"keys",
"of",
"the",
"document_info_dict",
"property",
"of",
"the",
"pdf",
"-",
"ext",
"extension",
"of",
"file",
"objects",
"are",
"only",
"valid",
"PDF",
"Document",
"Information",
"Dictionary",
"Keys",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L874-L893 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | countries | def countries(instance):
"""Ensure that the `country` property of `location` objects is a valid
ISO 3166-1 ALPHA-2 Code.
"""
if (instance['type'] == 'location' and 'country' in instance and not
instance['country'].upper() in enums.COUNTRY_CODES):
return JSONError("Location `country`... | python | def countries(instance):
"""Ensure that the `country` property of `location` objects is a valid
ISO 3166-1 ALPHA-2 Code.
"""
if (instance['type'] == 'location' and 'country' in instance and not
instance['country'].upper() in enums.COUNTRY_CODES):
return JSONError("Location `country`... | [
"def",
"countries",
"(",
"instance",
")",
":",
"if",
"(",
"instance",
"[",
"'type'",
"]",
"==",
"'location'",
"and",
"'country'",
"in",
"instance",
"and",
"not",
"instance",
"[",
"'country'",
"]",
".",
"upper",
"(",
")",
"in",
"enums",
".",
"COUNTRY_CODE... | Ensure that the `country` property of `location` objects is a valid
ISO 3166-1 ALPHA-2 Code. | [
"Ensure",
"that",
"the",
"country",
"property",
"of",
"location",
"objects",
"is",
"a",
"valid",
"ISO",
"3166",
"-",
"1",
"ALPHA",
"-",
"2",
"Code",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L896-L905 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | windows_process_priority_format | def windows_process_priority_format(instance):
"""Ensure the 'priority' property of windows-process-ext ends in '_CLASS'.
"""
class_suffix_re = re.compile(r'.+_CLASS$')
for key, obj in instance['objects'].items():
if 'type' in obj and obj['type'] == 'process':
try:
pr... | python | def windows_process_priority_format(instance):
"""Ensure the 'priority' property of windows-process-ext ends in '_CLASS'.
"""
class_suffix_re = re.compile(r'.+_CLASS$')
for key, obj in instance['objects'].items():
if 'type' in obj and obj['type'] == 'process':
try:
pr... | [
"def",
"windows_process_priority_format",
"(",
"instance",
")",
":",
"class_suffix_re",
"=",
"re",
".",
"compile",
"(",
"r'.+_CLASS$'",
")",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"'type'",
"in... | Ensure the 'priority' property of windows-process-ext ends in '_CLASS'. | [
"Ensure",
"the",
"priority",
"property",
"of",
"windows",
"-",
"process",
"-",
"ext",
"ends",
"in",
"_CLASS",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L909-L922 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | hash_length | def hash_length(instance):
"""Ensure keys in 'hashes'-type properties are no more than 30 characters long.
"""
for key, obj in instance['objects'].items():
if 'type' not in obj:
continue
if obj['type'] == 'file':
try:
hashes = obj['hashes']
... | python | def hash_length(instance):
"""Ensure keys in 'hashes'-type properties are no more than 30 characters long.
"""
for key, obj in instance['objects'].items():
if 'type' not in obj:
continue
if obj['type'] == 'file':
try:
hashes = obj['hashes']
... | [
"def",
"hash_length",
"(",
"instance",
")",
":",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"'type'",
"not",
"in",
"obj",
":",
"continue",
"if",
"obj",
"[",
"'type'",
"]",
"==",
"'file'",
"... | Ensure keys in 'hashes'-type properties are no more than 30 characters long. | [
"Ensure",
"keys",
"in",
"hashes",
"-",
"type",
"properties",
"are",
"no",
"more",
"than",
"30",
"characters",
"long",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L926-L1016 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | duplicate_ids | def duplicate_ids(instance):
"""Ensure objects with duplicate IDs have different `modified` timestamps.
"""
if instance['type'] != 'bundle' or 'objects' not in instance:
return
unique_ids = {}
for obj in instance['objects']:
if 'id' not in obj or 'modified' not in obj:
c... | python | def duplicate_ids(instance):
"""Ensure objects with duplicate IDs have different `modified` timestamps.
"""
if instance['type'] != 'bundle' or 'objects' not in instance:
return
unique_ids = {}
for obj in instance['objects']:
if 'id' not in obj or 'modified' not in obj:
c... | [
"def",
"duplicate_ids",
"(",
"instance",
")",
":",
"if",
"instance",
"[",
"'type'",
"]",
"!=",
"'bundle'",
"or",
"'objects'",
"not",
"in",
"instance",
":",
"return",
"unique_ids",
"=",
"{",
"}",
"for",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
":",... | Ensure objects with duplicate IDs have different `modified` timestamps. | [
"Ensure",
"objects",
"with",
"duplicate",
"IDs",
"have",
"different",
"modified",
"timestamps",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L1028-L1044 | train |
oasis-open/cti-stix-validator | stix2validator/v21/shoulds.py | list_shoulds | def list_shoulds(options):
"""Construct the list of 'SHOULD' validators to be run by the validator.
"""
validator_list = []
# Default: enable all
if not options.disabled and not options.enabled:
validator_list.extend(CHECKS['all'])
return validator_list
# --disable
# Add SH... | python | def list_shoulds(options):
"""Construct the list of 'SHOULD' validators to be run by the validator.
"""
validator_list = []
# Default: enable all
if not options.disabled and not options.enabled:
validator_list.extend(CHECKS['all'])
return validator_list
# --disable
# Add SH... | [
"def",
"list_shoulds",
"(",
"options",
")",
":",
"validator_list",
"=",
"[",
"]",
"# Default: enable all",
"if",
"not",
"options",
".",
"disabled",
"and",
"not",
"options",
".",
"enabled",
":",
"validator_list",
".",
"extend",
"(",
"CHECKS",
"[",
"'all'",
"]... | Construct the list of 'SHOULD' validators to be run by the validator. | [
"Construct",
"the",
"list",
"of",
"SHOULD",
"validators",
"to",
"be",
"run",
"by",
"the",
"validator",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L1193-L1298 | train |
oasis-open/cti-stix-validator | stix2validator/v20/musts.py | timestamp | def timestamp(instance):
"""Ensure timestamps contain sane months, days, hours, minutes, seconds.
"""
ts_re = re.compile(r"^[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?Z$")
timestamp_props = ['created', 'modified']
if instance['type'] i... | python | def timestamp(instance):
"""Ensure timestamps contain sane months, days, hours, minutes, seconds.
"""
ts_re = re.compile(r"^[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?Z$")
timestamp_props = ['created', 'modified']
if instance['type'] i... | [
"def",
"timestamp",
"(",
"instance",
")",
":",
"ts_re",
"=",
"re",
".",
"compile",
"(",
"r\"^[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\\.[0-9]+)?Z$\"",
")",
"timestamp_props",
"=",
"[",
"'created'",
",",
"'modified'",
"... | Ensure timestamps contain sane months, days, hours, minutes, seconds. | [
"Ensure",
"timestamps",
"contain",
"sane",
"months",
"days",
"hours",
"minutes",
"seconds",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L23-L70 | train |
oasis-open/cti-stix-validator | stix2validator/v20/musts.py | modified_created | def modified_created(instance):
"""`modified` property must be later or equal to `created` property
"""
if 'modified' in instance and 'created' in instance and \
instance['modified'] < instance['created']:
msg = "'modified' (%s) must be later or equal to 'created' (%s)"
return JS... | python | def modified_created(instance):
"""`modified` property must be later or equal to `created` property
"""
if 'modified' in instance and 'created' in instance and \
instance['modified'] < instance['created']:
msg = "'modified' (%s) must be later or equal to 'created' (%s)"
return JS... | [
"def",
"modified_created",
"(",
"instance",
")",
":",
"if",
"'modified'",
"in",
"instance",
"and",
"'created'",
"in",
"instance",
"and",
"instance",
"[",
"'modified'",
"]",
"<",
"instance",
"[",
"'created'",
"]",
":",
"msg",
"=",
"\"'modified' (%s) must be later... | `modified` property must be later or equal to `created` property | [
"modified",
"property",
"must",
"be",
"later",
"or",
"equal",
"to",
"created",
"property"
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L73-L80 | train |
oasis-open/cti-stix-validator | stix2validator/v20/musts.py | object_marking_circular_refs | def object_marking_circular_refs(instance):
"""Ensure that marking definitions do not contain circular references (ie.
they do not reference themselves in the `object_marking_refs` property).
"""
if instance['type'] != 'marking-definition':
return
if 'object_marking_refs' in instance:
... | python | def object_marking_circular_refs(instance):
"""Ensure that marking definitions do not contain circular references (ie.
they do not reference themselves in the `object_marking_refs` property).
"""
if instance['type'] != 'marking-definition':
return
if 'object_marking_refs' in instance:
... | [
"def",
"object_marking_circular_refs",
"(",
"instance",
")",
":",
"if",
"instance",
"[",
"'type'",
"]",
"!=",
"'marking-definition'",
":",
"return",
"if",
"'object_marking_refs'",
"in",
"instance",
":",
"for",
"ref",
"in",
"instance",
"[",
"'object_marking_refs'",
... | Ensure that marking definitions do not contain circular references (ie.
they do not reference themselves in the `object_marking_refs` property). | [
"Ensure",
"that",
"marking",
"definitions",
"do",
"not",
"contain",
"circular",
"references",
"(",
"ie",
".",
"they",
"do",
"not",
"reference",
"themselves",
"in",
"the",
"object_marking_refs",
"property",
")",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L83-L95 | train |
oasis-open/cti-stix-validator | stix2validator/v20/musts.py | granular_markings_circular_refs | def granular_markings_circular_refs(instance):
"""Ensure that marking definitions do not contain circular references (ie.
they do not reference themselves in the `granular_markings` property).
"""
if instance['type'] != 'marking-definition':
return
if 'granular_markings' in instance:
... | python | def granular_markings_circular_refs(instance):
"""Ensure that marking definitions do not contain circular references (ie.
they do not reference themselves in the `granular_markings` property).
"""
if instance['type'] != 'marking-definition':
return
if 'granular_markings' in instance:
... | [
"def",
"granular_markings_circular_refs",
"(",
"instance",
")",
":",
"if",
"instance",
"[",
"'type'",
"]",
"!=",
"'marking-definition'",
":",
"return",
"if",
"'granular_markings'",
"in",
"instance",
":",
"for",
"marking",
"in",
"instance",
"[",
"'granular_markings'"... | Ensure that marking definitions do not contain circular references (ie.
they do not reference themselves in the `granular_markings` property). | [
"Ensure",
"that",
"marking",
"definitions",
"do",
"not",
"contain",
"circular",
"references",
"(",
"ie",
".",
"they",
"do",
"not",
"reference",
"themselves",
"in",
"the",
"granular_markings",
"property",
")",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L98-L110 | train |
oasis-open/cti-stix-validator | stix2validator/v20/musts.py | marking_selector_syntax | def marking_selector_syntax(instance):
"""Ensure selectors in granular markings refer to items which are actually
present in the object.
"""
if 'granular_markings' not in instance:
return
list_index_re = re.compile(r"\[(\d+)\]")
for marking in instance['granular_markings']:
if '... | python | def marking_selector_syntax(instance):
"""Ensure selectors in granular markings refer to items which are actually
present in the object.
"""
if 'granular_markings' not in instance:
return
list_index_re = re.compile(r"\[(\d+)\]")
for marking in instance['granular_markings']:
if '... | [
"def",
"marking_selector_syntax",
"(",
"instance",
")",
":",
"if",
"'granular_markings'",
"not",
"in",
"instance",
":",
"return",
"list_index_re",
"=",
"re",
".",
"compile",
"(",
"r\"\\[(\\d+)\\]\"",
")",
"for",
"marking",
"in",
"instance",
"[",
"'granular_marking... | Ensure selectors in granular markings refer to items which are actually
present in the object. | [
"Ensure",
"selectors",
"in",
"granular",
"markings",
"refer",
"to",
"items",
"which",
"are",
"actually",
"present",
"in",
"the",
"object",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L113-L156 | train |
oasis-open/cti-stix-validator | stix2validator/v20/musts.py | observable_object_references | def observable_object_references(instance):
"""Ensure certain observable object properties reference the correct type
of object.
"""
for key, obj in instance['objects'].items():
if 'type' not in obj:
continue
elif obj['type'] not in enums.OBSERVABLE_PROP_REFS:
con... | python | def observable_object_references(instance):
"""Ensure certain observable object properties reference the correct type
of object.
"""
for key, obj in instance['objects'].items():
if 'type' not in obj:
continue
elif obj['type'] not in enums.OBSERVABLE_PROP_REFS:
con... | [
"def",
"observable_object_references",
"(",
"instance",
")",
":",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"'type'",
"not",
"in",
"obj",
":",
"continue",
"elif",
"obj",
"[",
"'type'",
"]",
"n... | Ensure certain observable object properties reference the correct type
of object. | [
"Ensure",
"certain",
"observable",
"object",
"properties",
"reference",
"the",
"correct",
"type",
"of",
"object",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L191-L240 | train |
oasis-open/cti-stix-validator | stix2validator/v20/musts.py | artifact_mime_type | def artifact_mime_type(instance):
"""Ensure the 'mime_type' property of artifact objects comes from the
Template column in the IANA media type registry.
"""
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] == 'artifact' and 'mime_type' in obj):
if enums.... | python | def artifact_mime_type(instance):
"""Ensure the 'mime_type' property of artifact objects comes from the
Template column in the IANA media type registry.
"""
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] == 'artifact' and 'mime_type' in obj):
if enums.... | [
"def",
"artifact_mime_type",
"(",
"instance",
")",
":",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"(",
"'type'",
"in",
"obj",
"and",
"obj",
"[",
"'type'",
"]",
"==",
"'artifact'",
"and",
"'m... | Ensure the 'mime_type' property of artifact objects comes from the
Template column in the IANA media type registry. | [
"Ensure",
"the",
"mime_type",
"property",
"of",
"artifact",
"objects",
"comes",
"from",
"the",
"Template",
"column",
"in",
"the",
"IANA",
"media",
"type",
"registry",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L244-L265 | train |
oasis-open/cti-stix-validator | stix2validator/v20/musts.py | character_set | def character_set(instance):
"""Ensure certain properties of cyber observable objects come from the IANA
Character Set list.
"""
char_re = re.compile(r'^[a-zA-Z0-9_\(\)-]+$')
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] == 'directory' and 'path_enc' in obj):... | python | def character_set(instance):
"""Ensure certain properties of cyber observable objects come from the IANA
Character Set list.
"""
char_re = re.compile(r'^[a-zA-Z0-9_\(\)-]+$')
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] == 'directory' and 'path_enc' in obj):... | [
"def",
"character_set",
"(",
"instance",
")",
":",
"char_re",
"=",
"re",
".",
"compile",
"(",
"r'^[a-zA-Z0-9_\\(\\)-]+$'",
")",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"(",
"'type'",
"in",
"... | Ensure certain properties of cyber observable objects come from the IANA
Character Set list. | [
"Ensure",
"certain",
"properties",
"of",
"cyber",
"observable",
"objects",
"come",
"from",
"the",
"IANA",
"Character",
"Set",
"list",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L269-L303 | train |
oasis-open/cti-stix-validator | stix2validator/v20/musts.py | software_language | def software_language(instance):
"""Ensure the 'language' property of software objects is a valid ISO 639-2
language code.
"""
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] == 'software' and
'languages' in obj):
for lang in obj['langua... | python | def software_language(instance):
"""Ensure the 'language' property of software objects is a valid ISO 639-2
language code.
"""
for key, obj in instance['objects'].items():
if ('type' in obj and obj['type'] == 'software' and
'languages' in obj):
for lang in obj['langua... | [
"def",
"software_language",
"(",
"instance",
")",
":",
"for",
"key",
",",
"obj",
"in",
"instance",
"[",
"'objects'",
"]",
".",
"items",
"(",
")",
":",
"if",
"(",
"'type'",
"in",
"obj",
"and",
"obj",
"[",
"'type'",
"]",
"==",
"'software'",
"and",
"'la... | Ensure the 'language' property of software objects is a valid ISO 639-2
language code. | [
"Ensure",
"the",
"language",
"property",
"of",
"software",
"objects",
"is",
"a",
"valid",
"ISO",
"639",
"-",
"2",
"language",
"code",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L307-L319 | train |
oasis-open/cti-stix-validator | stix2validator/v20/musts.py | types_strict | def types_strict(instance):
"""Ensure that no custom object types are used, but only the official ones
from the specification.
"""
if instance['type'] not in enums.TYPES:
yield JSONError("Object type '%s' is not one of those defined in the"
" specification." % instance['t... | python | def types_strict(instance):
"""Ensure that no custom object types are used, but only the official ones
from the specification.
"""
if instance['type'] not in enums.TYPES:
yield JSONError("Object type '%s' is not one of those defined in the"
" specification." % instance['t... | [
"def",
"types_strict",
"(",
"instance",
")",
":",
"if",
"instance",
"[",
"'type'",
"]",
"not",
"in",
"enums",
".",
"TYPES",
":",
"yield",
"JSONError",
"(",
"\"Object type '%s' is not one of those defined in the\"",
"\" specification.\"",
"%",
"instance",
"[",
"'type... | Ensure that no custom object types are used, but only the official ones
from the specification. | [
"Ensure",
"that",
"no",
"custom",
"object",
"types",
"are",
"used",
"but",
"only",
"the",
"official",
"ones",
"from",
"the",
"specification",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L322-L336 | train |
oasis-open/cti-stix-validator | stix2validator/v20/musts.py | properties_strict | def properties_strict(instance):
"""Ensure that no custom properties are used, but only the official ones
from the specification.
"""
if instance['type'] not in enums.TYPES:
return # only check properties for official objects
defined_props = enums.PROPERTIES.get(instance['type'], [])
f... | python | def properties_strict(instance):
"""Ensure that no custom properties are used, but only the official ones
from the specification.
"""
if instance['type'] not in enums.TYPES:
return # only check properties for official objects
defined_props = enums.PROPERTIES.get(instance['type'], [])
f... | [
"def",
"properties_strict",
"(",
"instance",
")",
":",
"if",
"instance",
"[",
"'type'",
"]",
"not",
"in",
"enums",
".",
"TYPES",
":",
"return",
"# only check properties for official objects",
"defined_props",
"=",
"enums",
".",
"PROPERTIES",
".",
"get",
"(",
"in... | Ensure that no custom properties are used, but only the official ones
from the specification. | [
"Ensure",
"that",
"no",
"custom",
"properties",
"are",
"used",
"but",
"only",
"the",
"official",
"ones",
"from",
"the",
"specification",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L339-L396 | train |
oasis-open/cti-stix-validator | stix2validator/v20/musts.py | patterns | def patterns(instance, options):
"""Ensure that the syntax of the pattern of an indicator is valid, and that
objects and properties referenced by the pattern are valid.
"""
if instance['type'] != 'indicator' or 'pattern' not in instance:
return
pattern = instance['pattern']
if not isins... | python | def patterns(instance, options):
"""Ensure that the syntax of the pattern of an indicator is valid, and that
objects and properties referenced by the pattern are valid.
"""
if instance['type'] != 'indicator' or 'pattern' not in instance:
return
pattern = instance['pattern']
if not isins... | [
"def",
"patterns",
"(",
"instance",
",",
"options",
")",
":",
"if",
"instance",
"[",
"'type'",
"]",
"!=",
"'indicator'",
"or",
"'pattern'",
"not",
"in",
"instance",
":",
"return",
"pattern",
"=",
"instance",
"[",
"'pattern'",
"]",
"if",
"not",
"isinstance"... | Ensure that the syntax of the pattern of an indicator is valid, and that
objects and properties referenced by the pattern are valid. | [
"Ensure",
"that",
"the",
"syntax",
"of",
"the",
"pattern",
"of",
"an",
"indicator",
"is",
"valid",
"and",
"that",
"objects",
"and",
"properties",
"referenced",
"by",
"the",
"pattern",
"are",
"valid",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L399-L470 | train |
oasis-open/cti-stix-validator | stix2validator/v20/musts.py | list_musts | def list_musts(options):
"""Construct the list of 'MUST' validators to be run by the validator.
"""
validator_list = [
timestamp,
modified_created,
object_marking_circular_refs,
granular_markings_circular_refs,
marking_selector_syntax,
observable_object_refere... | python | def list_musts(options):
"""Construct the list of 'MUST' validators to be run by the validator.
"""
validator_list = [
timestamp,
modified_created,
object_marking_circular_refs,
granular_markings_circular_refs,
marking_selector_syntax,
observable_object_refere... | [
"def",
"list_musts",
"(",
"options",
")",
":",
"validator_list",
"=",
"[",
"timestamp",
",",
"modified_created",
",",
"object_marking_circular_refs",
",",
"granular_markings_circular_refs",
",",
"marking_selector_syntax",
",",
"observable_object_references",
",",
"artifact_... | Construct the list of 'MUST' validators to be run by the validator. | [
"Construct",
"the",
"list",
"of",
"MUST",
"validators",
"to",
"be",
"run",
"by",
"the",
"validator",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L473-L497 | train |
oasis-open/cti-stix-validator | stix2validator/v21/enums.py | media_types | def media_types():
"""Return a list of the IANA Media (MIME) Types, or an empty list if the
IANA website is unreachable.
Store it as a function attribute so that we only build the list once.
"""
if not hasattr(media_types, 'typelist'):
tlist = []
categories = [
'applicati... | python | def media_types():
"""Return a list of the IANA Media (MIME) Types, or an empty list if the
IANA website is unreachable.
Store it as a function attribute so that we only build the list once.
"""
if not hasattr(media_types, 'typelist'):
tlist = []
categories = [
'applicati... | [
"def",
"media_types",
"(",
")",
":",
"if",
"not",
"hasattr",
"(",
"media_types",
",",
"'typelist'",
")",
":",
"tlist",
"=",
"[",
"]",
"categories",
"=",
"[",
"'application'",
",",
"'audio'",
",",
"'font'",
",",
"'image'",
",",
"'message'",
",",
"'model'"... | Return a list of the IANA Media (MIME) Types, or an empty list if the
IANA website is unreachable.
Store it as a function attribute so that we only build the list once. | [
"Return",
"a",
"list",
"of",
"the",
"IANA",
"Media",
"(",
"MIME",
")",
"Types",
"or",
"an",
"empty",
"list",
"if",
"the",
"IANA",
"website",
"is",
"unreachable",
".",
"Store",
"it",
"as",
"a",
"function",
"attribute",
"so",
"that",
"we",
"only",
"build... | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/enums.py#L1618-L1656 | train |
oasis-open/cti-stix-validator | stix2validator/v21/enums.py | char_sets | def char_sets():
"""Return a list of the IANA Character Sets, or an empty list if the
IANA website is unreachable.
Store it as a function attribute so that we only build the list once.
"""
if not hasattr(char_sets, 'setlist'):
clist = []
try:
data = requests.get('http://w... | python | def char_sets():
"""Return a list of the IANA Character Sets, or an empty list if the
IANA website is unreachable.
Store it as a function attribute so that we only build the list once.
"""
if not hasattr(char_sets, 'setlist'):
clist = []
try:
data = requests.get('http://w... | [
"def",
"char_sets",
"(",
")",
":",
"if",
"not",
"hasattr",
"(",
"char_sets",
",",
"'setlist'",
")",
":",
"clist",
"=",
"[",
"]",
"try",
":",
"data",
"=",
"requests",
".",
"get",
"(",
"'http://www.iana.org/assignments/character-'",
"'sets/character-sets-1.csv'",
... | Return a list of the IANA Character Sets, or an empty list if the
IANA website is unreachable.
Store it as a function attribute so that we only build the list once. | [
"Return",
"a",
"list",
"of",
"the",
"IANA",
"Character",
"Sets",
"or",
"an",
"empty",
"list",
"if",
"the",
"IANA",
"website",
"is",
"unreachable",
".",
"Store",
"it",
"as",
"a",
"function",
"attribute",
"so",
"that",
"we",
"only",
"build",
"the",
"list",... | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/enums.py#L1659-L1683 | train |
oasis-open/cti-stix-validator | stix2validator/v21/enums.py | protocols | def protocols():
"""Return a list of values from the IANA Service Name and Transport
Protocol Port Number Registry, or an empty list if the IANA website is
unreachable.
Store it as a function attribute so that we only build the list once.
"""
if not hasattr(protocols, 'protlist'):
plist ... | python | def protocols():
"""Return a list of values from the IANA Service Name and Transport
Protocol Port Number Registry, or an empty list if the IANA website is
unreachable.
Store it as a function attribute so that we only build the list once.
"""
if not hasattr(protocols, 'protlist'):
plist ... | [
"def",
"protocols",
"(",
")",
":",
"if",
"not",
"hasattr",
"(",
"protocols",
",",
"'protlist'",
")",
":",
"plist",
"=",
"[",
"]",
"try",
":",
"data",
"=",
"requests",
".",
"get",
"(",
"'http://www.iana.org/assignments/service-names'",
"'-port-numbers/service-nam... | Return a list of values from the IANA Service Name and Transport
Protocol Port Number Registry, or an empty list if the IANA website is
unreachable.
Store it as a function attribute so that we only build the list once. | [
"Return",
"a",
"list",
"of",
"values",
"from",
"the",
"IANA",
"Service",
"Name",
"and",
"Transport",
"Protocol",
"Port",
"Number",
"Registry",
"or",
"an",
"empty",
"list",
"if",
"the",
"IANA",
"website",
"is",
"unreachable",
".",
"Store",
"it",
"as",
"a",
... | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/enums.py#L1686-L1716 | train |
oasis-open/cti-stix-validator | stix2validator/v21/enums.py | ipfix | def ipfix():
"""Return a list of values from the list of IANA IP Flow Information Export
(IPFIX) Entities, or an empty list if the IANA website is unreachable.
Store it as a function attribute so that we only build the list once.
"""
if not hasattr(ipfix, 'ipflist'):
ilist = []
try:
... | python | def ipfix():
"""Return a list of values from the list of IANA IP Flow Information Export
(IPFIX) Entities, or an empty list if the IANA website is unreachable.
Store it as a function attribute so that we only build the list once.
"""
if not hasattr(ipfix, 'ipflist'):
ilist = []
try:
... | [
"def",
"ipfix",
"(",
")",
":",
"if",
"not",
"hasattr",
"(",
"ipfix",
",",
"'ipflist'",
")",
":",
"ilist",
"=",
"[",
"]",
"try",
":",
"data",
"=",
"requests",
".",
"get",
"(",
"'http://www.iana.org/assignments/ipfix/ipfix-'",
"'information-elements.csv'",
")",
... | Return a list of values from the list of IANA IP Flow Information Export
(IPFIX) Entities, or an empty list if the IANA website is unreachable.
Store it as a function attribute so that we only build the list once. | [
"Return",
"a",
"list",
"of",
"values",
"from",
"the",
"list",
"of",
"IANA",
"IP",
"Flow",
"Information",
"Export",
"(",
"IPFIX",
")",
"Entities",
"or",
"an",
"empty",
"list",
"if",
"the",
"IANA",
"website",
"is",
"unreachable",
".",
"Store",
"it",
"as",
... | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/enums.py#L1719-L1741 | train |
oasis-open/cti-stix-validator | stix2validator/output.py | print_level | def print_level(log_function, fmt, level, *args):
"""Print a formatted message to stdout prepended by spaces. Useful for
printing hierarchical information, like bullet lists.
Note:
If the application is running in "Silent Mode"
(i.e., ``_SILENT == True``), this function will return
... | python | def print_level(log_function, fmt, level, *args):
"""Print a formatted message to stdout prepended by spaces. Useful for
printing hierarchical information, like bullet lists.
Note:
If the application is running in "Silent Mode"
(i.e., ``_SILENT == True``), this function will return
... | [
"def",
"print_level",
"(",
"log_function",
",",
"fmt",
",",
"level",
",",
"*",
"args",
")",
":",
"if",
"_SILENT",
":",
"return",
"msg",
"=",
"fmt",
"%",
"args",
"spaces",
"=",
"' '",
"*",
"level",
"log_function",
"(",
"\"%s%s\"",
"%",
"(",
"spaces",... | Print a formatted message to stdout prepended by spaces. Useful for
printing hierarchical information, like bullet lists.
Note:
If the application is running in "Silent Mode"
(i.e., ``_SILENT == True``), this function will return
immediately and no message will be printed.
Args:
... | [
"Print",
"a",
"formatted",
"message",
"to",
"stdout",
"prepended",
"by",
"spaces",
".",
"Useful",
"for",
"printing",
"hierarchical",
"information",
"like",
"bullet",
"lists",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/output.py#L62-L94 | train |
oasis-open/cti-stix-validator | stix2validator/output.py | print_fatal_results | def print_fatal_results(results, level=0):
"""Print fatal errors that occurred during validation runs.
"""
print_level(logger.critical, _RED + "[X] Fatal Error: %s", level, results.error) | python | def print_fatal_results(results, level=0):
"""Print fatal errors that occurred during validation runs.
"""
print_level(logger.critical, _RED + "[X] Fatal Error: %s", level, results.error) | [
"def",
"print_fatal_results",
"(",
"results",
",",
"level",
"=",
"0",
")",
":",
"print_level",
"(",
"logger",
".",
"critical",
",",
"_RED",
"+",
"\"[X] Fatal Error: %s\"",
",",
"level",
",",
"results",
".",
"error",
")"
] | Print fatal errors that occurred during validation runs. | [
"Print",
"fatal",
"errors",
"that",
"occurred",
"during",
"validation",
"runs",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/output.py#L97-L100 | train |
oasis-open/cti-stix-validator | stix2validator/output.py | print_schema_results | def print_schema_results(results, level=0):
"""Print JSON Schema validation errors to stdout.
Args:
results: An instance of ObjectValidationResults.
level: The level at which to print the results.
"""
for error in results.errors:
print_level(logger.error, _RED + "[X] %s", level... | python | def print_schema_results(results, level=0):
"""Print JSON Schema validation errors to stdout.
Args:
results: An instance of ObjectValidationResults.
level: The level at which to print the results.
"""
for error in results.errors:
print_level(logger.error, _RED + "[X] %s", level... | [
"def",
"print_schema_results",
"(",
"results",
",",
"level",
"=",
"0",
")",
":",
"for",
"error",
"in",
"results",
".",
"errors",
":",
"print_level",
"(",
"logger",
".",
"error",
",",
"_RED",
"+",
"\"[X] %s\"",
",",
"level",
",",
"error",
")"
] | Print JSON Schema validation errors to stdout.
Args:
results: An instance of ObjectValidationResults.
level: The level at which to print the results. | [
"Print",
"JSON",
"Schema",
"validation",
"errors",
"to",
"stdout",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/output.py#L103-L112 | train |
oasis-open/cti-stix-validator | stix2validator/output.py | print_warning_results | def print_warning_results(results, level=0):
"""Print warning messages found during validation.
"""
marker = _YELLOW + "[!] "
for warning in results.warnings:
print_level(logger.warning, marker + "Warning: %s", level, warning) | python | def print_warning_results(results, level=0):
"""Print warning messages found during validation.
"""
marker = _YELLOW + "[!] "
for warning in results.warnings:
print_level(logger.warning, marker + "Warning: %s", level, warning) | [
"def",
"print_warning_results",
"(",
"results",
",",
"level",
"=",
"0",
")",
":",
"marker",
"=",
"_YELLOW",
"+",
"\"[!] \"",
"for",
"warning",
"in",
"results",
".",
"warnings",
":",
"print_level",
"(",
"logger",
".",
"warning",
",",
"marker",
"+",
"\"Warni... | Print warning messages found during validation. | [
"Print",
"warning",
"messages",
"found",
"during",
"validation",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/output.py#L115-L121 | train |
oasis-open/cti-stix-validator | stix2validator/output.py | print_results_header | def print_results_header(identifier, is_valid):
"""Print a header for the results of either a file or an object.
"""
print_horizontal_rule()
print_level(logger.info, "[-] Results for: %s", 0, identifier)
if is_valid:
marker = _GREEN + "[+]"
verdict = "Valid"
log_func = logg... | python | def print_results_header(identifier, is_valid):
"""Print a header for the results of either a file or an object.
"""
print_horizontal_rule()
print_level(logger.info, "[-] Results for: %s", 0, identifier)
if is_valid:
marker = _GREEN + "[+]"
verdict = "Valid"
log_func = logg... | [
"def",
"print_results_header",
"(",
"identifier",
",",
"is_valid",
")",
":",
"print_horizontal_rule",
"(",
")",
"print_level",
"(",
"logger",
".",
"info",
",",
"\"[-] Results for: %s\"",
",",
"0",
",",
"identifier",
")",
"if",
"is_valid",
":",
"marker",
"=",
"... | Print a header for the results of either a file or an object. | [
"Print",
"a",
"header",
"for",
"the",
"results",
"of",
"either",
"a",
"file",
"or",
"an",
"object",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/output.py#L139-L154 | train |
oasis-open/cti-stix-validator | stix2validator/output.py | print_object_results | def print_object_results(obj_result):
"""Print the results of validating an object.
Args:
obj_result: An ObjectValidationResults instance.
"""
print_results_header(obj_result.object_id, obj_result.is_valid)
if obj_result.warnings:
print_warning_results(obj_result, 1)
if obj_re... | python | def print_object_results(obj_result):
"""Print the results of validating an object.
Args:
obj_result: An ObjectValidationResults instance.
"""
print_results_header(obj_result.object_id, obj_result.is_valid)
if obj_result.warnings:
print_warning_results(obj_result, 1)
if obj_re... | [
"def",
"print_object_results",
"(",
"obj_result",
")",
":",
"print_results_header",
"(",
"obj_result",
".",
"object_id",
",",
"obj_result",
".",
"is_valid",
")",
"if",
"obj_result",
".",
"warnings",
":",
"print_warning_results",
"(",
"obj_result",
",",
"1",
")",
... | Print the results of validating an object.
Args:
obj_result: An ObjectValidationResults instance. | [
"Print",
"the",
"results",
"of",
"validating",
"an",
"object",
"."
] | a607014e3fa500a7678f8b61b278456ca581f9d0 | https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/output.py#L157-L169 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.