partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
train
pretty_error
Return an error message that is easier to read and more useful. May require updating if the schemas change significantly.
stix2validator/errors.py
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): """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(...
[ "Return", "an", "error", "message", "that", "is", "easier", "to", "read", "and", "more", "useful", ".", "May", "require", "updating", "if", "the", "schemas", "change", "significantly", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/errors.py#L71-L252
[ "def", "pretty_error", "(", "error", ",", "verbose", "=", "False", ")", ":", "error_loc", "=", "''", "if", "error", ".", "path", ":", "while", "len", "(", "error", ".", "path", ")", ">", "0", ":", "path_elem", "=", "error", ".", "path", ".", "pople...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
_iter_errors_custom
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...
stix2validator/validator.py
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 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...
[ "Perform", "additional", "validation", "not", "possible", "merely", "with", "JSON", "schemas", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L34-L63
[ "def", "_iter_errors_custom", "(", "instance", ",", "checks", ",", "options", ")", ":", "# Perform validation", "for", "v_function", "in", "checks", ":", "try", ":", "result", "=", "v_function", "(", "instance", ")", "except", "TypeError", ":", "result", "=", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
list_json_files
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`.
stix2validator/validator.py
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): """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...
[ "Return", "a", "list", "of", "file", "paths", "for", "JSON", "files", "within", "directory", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L281-L306
[ "def", "list_json_files", "(", "directory", ",", "recursive", "=", "False", ")", ":", "json_files", "=", "[", "]", "for", "top", ",", "dirs", ",", "files", "in", "os", ".", "walk", "(", "directory", ")", ":", "dirs", ".", "sort", "(", ")", "# Get pat...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
get_json_files
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 ...
stix2validator/validator.py
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): """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...
[ "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", "...
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L309-L339
[ "def", "get_json_files", "(", "files", ",", "recursive", "=", "False", ")", ":", "json_files", "=", "[", "]", "if", "not", "files", ":", "return", "json_files", "for", "fn", "in", "files", ":", "if", "os", ".", "path", ".", "isdir", "(", "fn", ")", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
run_validation
Validate files based on command line options. Args: options: An instance of ``ValidationOptions`` containing options for this validation run.
stix2validator/validator.py
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): """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...
[ "Validate", "files", "based", "on", "command", "line", "options", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L342-L360
[ "def", "run_validation", "(", "options", ")", ":", "if", "options", ".", "files", "==", "sys", ".", "stdin", ":", "results", "=", "validate", "(", "options", ".", "files", ",", "options", ")", "return", "[", "FileValidationResults", "(", "is_valid", "=", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
validate_parsed_json
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...
stix2validator/validator.py
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): """ 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 ...
[ "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...
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L363-L408
[ "def", "validate_parsed_json", "(", "obj_json", ",", "options", "=", "None", ")", ":", "validating_list", "=", "isinstance", "(", "obj_json", ",", "list", ")", "if", "not", "options", ":", "options", "=", "ValidationOptions", "(", ")", "if", "not", "options"...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
validate
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.
stix2validator/validator.py
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): """ 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...
[ "Validate", "objects", "from", "JSON", "data", "in", "a", "textual", "stream", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L411-L423
[ "def", "validate", "(", "in_", ",", "options", "=", "None", ")", ":", "obj_json", "=", "json", ".", "load", "(", "in_", ")", "results", "=", "validate_parsed_json", "(", "obj_json", ",", "options", ")", "return", "results" ]
a607014e3fa500a7678f8b61b278456ca581f9d0
train
validate_file
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...
stix2validator/validator.py
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): """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...
[ "Validate", "the", "input", "document", "fn", "according", "to", "the", "options", "passed", "in", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L426-L467
[ "def", "validate_file", "(", "fn", ",", "options", "=", "None", ")", ":", "file_results", "=", "FileValidationResults", "(", "filepath", "=", "fn", ")", "output", ".", "info", "(", "\"Performing JSON schema validation on %s\"", "%", "fn", ")", "if", "not", "op...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
validate_string
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...
stix2validator/validator.py
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): """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...
[ "Validate", "the", "input", "string", "according", "to", "the", "options", "passed", "in", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L470-L486
[ "def", "validate_string", "(", "string", ",", "options", "=", "None", ")", ":", "output", ".", "info", "(", "\"Performing JSON schema validation on input string: \"", "+", "string", ")", "stream", "=", "io", ".", "StringIO", "(", "string", ")", "return", "valida...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
load_validator
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.
stix2validator/validator.py
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): """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...
[ "Create", "a", "JSON", "schema", "validator", "for", "the", "given", "schema", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L489-L509
[ "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", "(...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
find_schema
Search the `schema_dir` directory for a schema called `obj_type`.json. Return the file path of the first match it finds.
stix2validator/validator.py
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): """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: ...
[ "Search", "the", "schema_dir", "directory", "for", "a", "schema", "called", "obj_type", ".", "json", ".", "Return", "the", "file", "path", "of", "the", "first", "match", "it", "finds", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L512-L520
[ "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", "...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
load_schema
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.
stix2validator/validator.py
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): """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...
[ "Load", "the", "JSON", "schema", "at", "the", "given", "path", "as", "a", "Python", "object", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L523-L540
[ "def", "load_schema", "(", "schema_path", ")", ":", "try", ":", "with", "open", "(", "schema_path", ")", "as", "schema_file", ":", "schema", "=", "json", ".", "load", "(", "schema_file", ")", "except", "ValueError", "as", "e", ":", "raise", "SchemaInvalidE...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
_get_error_generator
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 ...
stix2validator/validator.py
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'): """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...
[ "Get", "a", "generator", "for", "validating", "against", "the", "schema", "for", "the", "given", "object", "type", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L543-L598
[ "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...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
_get_musts
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.
stix2validator/validator.py
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): """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_...
[ "Return", "the", "list", "of", "MUST", "validators", "for", "the", "correct", "version", "of", "STIX", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L601-L611
[ "def", "_get_musts", "(", "options", ")", ":", "if", "options", ".", "version", "==", "'2.0'", ":", "return", "musts20", ".", "list_musts", "(", "options", ")", "else", ":", "return", "musts21", ".", "list_musts", "(", "options", ")" ]
a607014e3fa500a7678f8b61b278456ca581f9d0
train
_get_shoulds
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.
stix2validator/validator.py
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): """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...
[ "Return", "the", "list", "of", "SHOULD", "validators", "for", "the", "correct", "version", "of", "STIX", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L614-L624
[ "def", "_get_shoulds", "(", "options", ")", ":", "if", "options", ".", "version", "==", "'2.0'", ":", "return", "shoulds20", ".", "list_shoulds", "(", "options", ")", "else", ":", "return", "shoulds21", ".", "list_shoulds", "(", "options", ")" ]
a607014e3fa500a7678f8b61b278456ca581f9d0
train
_schema_validate
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 ...
stix2validator/validator.py
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): """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 ...
[ "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...
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L627-L692
[ "def", "_schema_validate", "(", "sdo", ",", "options", ")", ":", "error_gens", "=", "[", "]", "if", "'id'", "in", "sdo", ":", "try", ":", "error_prefix", "=", "sdo", "[", "'id'", "]", "+", "\": \"", "except", "TypeError", ":", "error_prefix", "=", "'un...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
validate_instance
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...
stix2validator/validator.py
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): """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. ...
[ "Perform", "STIX", "JSON", "Schema", "validation", "against", "STIX", "input", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L695-L766
[ "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", "...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
FileValidationResults.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
stix2validator/validator.py
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): """ 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) ...
[ "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", ...
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L129-L143
[ "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...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
FileValidationResults.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
stix2validator/validator.py
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): """ 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...
[ "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",...
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L167-L179
[ "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",...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
ObjectValidationResults.as_dict
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...
stix2validator/validator.py
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): """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...
[ "A", "dictionary", "representation", "of", "the", ":", "class", ":", ".", "ObjectValidationResults", "instance", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/validator.py#L226-L243
[ "def", "as_dict", "(", "self", ")", ":", "d", "=", "super", "(", "ObjectValidationResults", ",", "self", ")", ".", "as_dict", "(", ")", "if", "self", ".", "errors", ":", "d", "[", "'errors'", "]", "=", "[", "x", ".", "as_dict", "(", ")", "for", "...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
custom_prefix_strict
Ensure custom content follows strict naming style conventions.
stix2validator/v21/shoulds.py
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): """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), ...
[ "Ensure", "custom", "content", "follows", "strict", "naming", "style", "conventions", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L32-L40
[ "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",...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
custom_prefix_lax
Ensure custom content follows lenient naming style conventions for forward-compatibility.
stix2validator/v21/shoulds.py
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): """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...
[ "Ensure", "custom", "content", "follows", "lenient", "naming", "style", "conventions", "for", "forward", "-", "compatibility", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L43-L52
[ "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", ")", ",...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
custom_object_prefix_strict
Ensure custom objects follow strict naming style conventions.
stix2validator/v21/shoulds.py
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): """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("...
[ "Ensure", "custom", "objects", "follow", "strict", "naming", "style", "conventions", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L55-L65
[ "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...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
custom_object_prefix_lax
Ensure custom objects follow lenient naming style conventions for forward-compatibility.
stix2validator/v21/shoulds.py
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): """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...
[ "Ensure", "custom", "objects", "follow", "lenient", "naming", "style", "conventions", "for", "forward", "-", "compatibility", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L68-L78
[ "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_...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
custom_property_prefix_strict
Ensure custom properties follow strict naming style conventions. Does not check property names in custom objects.
stix2validator/v21/shoulds.py
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): """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[...
[ "Ensure", "custom", "properties", "follow", "strict", "naming", "style", "conventions", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L81-L97
[ "def", "custom_property_prefix_strict", "(", "instance", ")", ":", "for", "prop_name", "in", "instance", ".", "keys", "(", ")", ":", "if", "(", "instance", "[", "'type'", "]", "in", "enums", ".", "PROPERTIES", "and", "prop_name", "not", "in", "enums", ".",...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
custom_property_prefix_lax
Ensure custom properties follow lenient naming style conventions for forward-compatibility. Does not check property names in custom objects.
stix2validator/v21/shoulds.py
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): """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...
[ "Ensure", "custom", "properties", "follow", "lenient", "naming", "style", "conventions", "for", "forward", "-", "compatibility", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L100-L116
[ "def", "custom_property_prefix_lax", "(", "instance", ")", ":", "for", "prop_name", "in", "instance", ".", "keys", "(", ")", ":", "if", "(", "instance", "[", "'type'", "]", "in", "enums", ".", "PROPERTIES", "and", "prop_name", "not", "in", "enums", ".", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
open_vocab_values
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.
stix2validator/v21/shoulds.py
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): """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...
[ "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", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L119-L142
[ "def", "open_vocab_values", "(", "instance", ")", ":", "if", "instance", "[", "'type'", "]", "not", "in", "enums", ".", "VOCAB_PROPERTIES", ":", "return", "properties", "=", "enums", ".", "VOCAB_PROPERTIES", "[", "instance", "[", "'type'", "]", "]", "for", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
kill_chain_phase_names
Ensure the `kill_chain_name` and `phase_name` properties of `kill_chain_phase` objects follow naming style conventions.
stix2validator/v21/shoulds.py
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): """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']:...
[ "Ensure", "the", "kill_chain_name", "and", "phase_name", "properties", "of", "kill_chain_phase", "objects", "follow", "naming", "style", "conventions", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L145-L168
[ "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'", "]", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
check_vocab
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.
stix2validator/v21/shoulds.py
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): """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...
[ "Ensure", "that", "the", "open", "vocabulary", "specified", "by", "vocab", "is", "used", "properly", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L171-L195
[ "def", "check_vocab", "(", "instance", ",", "vocab", ",", "code", ")", ":", "vocab_uses", "=", "getattr", "(", "enums", ",", "vocab", "+", "\"_USES\"", ")", "for", "k", "in", "vocab_uses", ".", "keys", "(", ")", ":", "if", "instance", "[", "'type'", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
vocab_marking_definition
Ensure that the `definition_type` property of `marking-definition` objects is one of the values in the STIX 2.0 specification.
stix2validator/v21/shoulds.py
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): """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...
[ "Ensure", "that", "the", "definition_type", "property", "of", "marking", "-", "definition", "objects", "is", "one", "of", "the", "values", "in", "the", "STIX", "2", ".", "0", "specification", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L258-L268
[ "def", "vocab_marking_definition", "(", "instance", ")", ":", "if", "(", "instance", "[", "'type'", "]", "==", "'marking-definition'", "and", "'definition_type'", "in", "instance", "and", "not", "instance", "[", "'definition_type'", "]", "in", "enums", ".", "MAR...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
relationships_strict
Ensure that only the relationship types defined in the specification are used.
stix2validator/v21/shoulds.py
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): """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...
[ "Ensure", "that", "only", "the", "relationship", "types", "defined", "in", "the", "specification", "are", "used", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L271-L315
[ "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", ".", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
valid_hash_value
Return true if given value is a valid, recommended hash name according to the STIX 2 specification.
stix2validator/v21/shoulds.py
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): """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...
[ "Return", "true", "if", "given", "value", "is", "a", "valid", "recommended", "hash", "name", "according", "to", "the", "STIX", "2", "specification", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L318-L326
[ "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...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
vocab_hash_algo
Ensure objects with 'hashes' properties only use values from the hash-algo-ov vocabulary.
stix2validator/v21/shoulds.py
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): """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...
[ "Ensure", "objects", "with", "hashes", "properties", "only", "use", "values", "from", "the", "hash", "-", "algo", "-", "ov", "vocabulary", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L330-L427
[ "def", "vocab_hash_algo", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "'type'", "not", "in", "obj", ":", "continue", "if", "obj", "[", "'type'", "]", "==", "'file'",...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
vocab_windows_pebinary_type
Ensure file objects with the windows-pebinary-ext extension have a 'pe-type' property that is from the windows-pebinary-type-ov vocabulary.
stix2validator/v21/shoulds.py
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): """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: ...
[ "Ensure", "file", "objects", "with", "the", "windows", "-", "pebinary", "-", "ext", "extension", "have", "a", "pe", "-", "type", "property", "that", "is", "from", "the", "windows", "-", "pebinary", "-", "type", "-", "ov", "vocabulary", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L431-L446
[ "def", "vocab_windows_pebinary_type", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "'type'", "in", "obj", "and", "obj", "[", "'type'", "]", "==", "'file'", ":", "try", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
vocab_account_type
Ensure a user-account objects' 'account-type' property is from the account-type-ov vocabulary.
stix2validator/v21/shoulds.py
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): """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'...
[ "Ensure", "a", "user", "-", "account", "objects", "account", "-", "type", "property", "is", "from", "the", "account", "-", "type", "-", "ov", "vocabulary", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L450-L464
[ "def", "vocab_account_type", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "'type'", "in", "obj", "and", "obj", "[", "'type'", "]", "==", "'user-account'", ":", "try", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
observable_object_keys
Ensure observable-objects keys are non-negative integers.
stix2validator/v21/shoulds.py
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): """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 " ...
[ "Ensure", "observable", "-", "objects", "keys", "are", "non", "-", "negative", "integers", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L468-L476
[ "def", "observable_object_keys", "(", "instance", ")", ":", "digits_re", "=", "re", ".", "compile", "(", "r\"^\\d+$\"", ")", "for", "key", "in", "instance", "[", "'objects'", "]", ":", "if", "not", "digits_re", ".", "match", "(", "key", ")", ":", "yield"...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
custom_observable_object_prefix_strict
Ensure custom observable objects follow strict naming style conventions.
stix2validator/v21/shoulds.py
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): """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...
[ "Ensure", "custom", "observable", "objects", "follow", "strict", "naming", "style", "conventions", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L504-L516
[ "def", "custom_observable_object_prefix_strict", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "(", "'type'", "in", "obj", "and", "obj", "[", "'type'", "]", "not", "in", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
custom_observable_object_prefix_lax
Ensure custom observable objects follow naming style conventions.
stix2validator/v21/shoulds.py
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): """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...
[ "Ensure", "custom", "observable", "objects", "follow", "naming", "style", "conventions", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L520-L530
[ "def", "custom_observable_object_prefix_lax", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "(", "'type'", "in", "obj", "and", "obj", "[", "'type'", "]", "not", "in", "e...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
custom_object_extension_prefix_strict
Ensure custom observable object extensions follow strict naming style conventions.
stix2validator/v21/shoulds.py
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): """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...
[ "Ensure", "custom", "observable", "object", "extensions", "follow", "strict", "naming", "style", "conventions", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L534-L550
[ "def", "custom_object_extension_prefix_strict", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "not", "(", "'extensions'", "in", "obj", "and", "'type'", "in", "obj", "and", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
custom_object_extension_prefix_lax
Ensure custom observable object extensions follow naming style conventions.
stix2validator/v21/shoulds.py
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): """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): ...
[ "Ensure", "custom", "observable", "object", "extensions", "follow", "naming", "style", "conventions", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L554-L568
[ "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...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
custom_observable_properties_prefix_strict
Ensure observable object custom properties follow strict naming style conventions.
stix2validator/v21/shoulds.py
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): """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: ...
[ "Ensure", "observable", "object", "custom", "properties", "follow", "strict", "naming", "style", "conventions", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L572-L657
[ "def", "custom_observable_properties_prefix_strict", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "'type'", "not", "in", "obj", ":", "continue", "type_", "=", "obj", "[", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
network_traffic_ports
Ensure network-traffic objects contain both src_port and dst_port.
stix2validator/v21/shoulds.py
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): """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 ...
[ "Ensure", "network", "-", "traffic", "objects", "contain", "both", "src_port", "and", "dst_port", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L733-L741
[ "def", "network_traffic_ports", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "(", "'type'", "in", "obj", "and", "obj", "[", "'type'", "]", "==", "'network-traffic'", "a...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
mime_type
Ensure the 'mime_type' property of file objects comes from the Template column in the IANA media type registry.
stix2validator/v21/shoulds.py
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): """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, ...
[ "Ensure", "the", "mime_type", "property", "of", "file", "objects", "comes", "from", "the", "Template", "column", "in", "the", "IANA", "media", "type", "registry", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L745-L767
[ "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'", "]", ".", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
protocols
Ensure the 'protocols' property of network-traffic objects contains only values from the IANA Service Name and Transport Protocol Port Number Registry.
stix2validator/v21/shoulds.py
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): """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 ...
[ "Ensure", "the", "protocols", "property", "of", "network", "-", "traffic", "objects", "contains", "only", "values", "from", "the", "IANA", "Service", "Name", "and", "Transport", "Protocol", "Port", "Number", "Registry", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L771-L796
[ "def", "protocols", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "(", "'type'", "in", "obj", "and", "obj", "[", "'type'", "]", "==", "'network-traffic'", "and", "'pro...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
ipfix
Ensure the 'ipfix' property of network-traffic objects contains only values from the IANA IP Flow Information Export (IPFIX) Entities Registry.
stix2validator/v21/shoulds.py
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): """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['...
[ "Ensure", "the", "ipfix", "property", "of", "network", "-", "traffic", "objects", "contains", "only", "values", "from", "the", "IANA", "IP", "Flow", "Information", "Export", "(", "IPFIX", ")", "Entities", "Registry", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L800-L825
[ "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", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
http_request_headers
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...
stix2validator/v21/shoulds.py
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): """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...
[ "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", ...
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L829-L850
[ "def", "http_request_headers", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "(", "'type'", "in", "obj", "and", "obj", "[", "'type'", "]", "==", "'network-traffic'", ")"...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
socket_options
Ensure the keys of the 'options' property of the socket-ext extension of network-traffic objects are only valid socket options (SO_*).
stix2validator/v21/shoulds.py
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): """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: ...
[ "Ensure", "the", "keys", "of", "the", "options", "property", "of", "the", "socket", "-", "ext", "extension", "of", "network", "-", "traffic", "objects", "are", "only", "valid", "socket", "options", "(", "SO_", "*", ")", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L854-L870
[ "def", "socket_options", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "(", "'type'", "in", "obj", "and", "obj", "[", "'type'", "]", "==", "'network-traffic'", ")", ":...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
pdf_doc_info
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.
stix2validator/v21/shoulds.py
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): """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...
[ "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", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L874-L893
[ "def", "pdf_doc_info", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "(", "'type'", "in", "obj", "and", "obj", "[", "'type'", "]", "==", "'file'", ")", ":", "try", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
countries
Ensure that the `country` property of `location` objects is a valid ISO 3166-1 ALPHA-2 Code.
stix2validator/v21/shoulds.py
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): """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`...
[ "Ensure", "that", "the", "country", "property", "of", "location", "objects", "is", "a", "valid", "ISO", "3166", "-", "1", "ALPHA", "-", "2", "Code", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L896-L905
[ "def", "countries", "(", "instance", ")", ":", "if", "(", "instance", "[", "'type'", "]", "==", "'location'", "and", "'country'", "in", "instance", "and", "not", "instance", "[", "'country'", "]", ".", "upper", "(", ")", "in", "enums", ".", "COUNTRY_CODE...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
windows_process_priority_format
Ensure the 'priority' property of windows-process-ext ends in '_CLASS'.
stix2validator/v21/shoulds.py
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): """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...
[ "Ensure", "the", "priority", "property", "of", "windows", "-", "process", "-", "ext", "ends", "in", "_CLASS", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L909-L922
[ "def", "windows_process_priority_format", "(", "instance", ")", ":", "class_suffix_re", "=", "re", ".", "compile", "(", "r'.+_CLASS$'", ")", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "'type'", "in...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
hash_length
Ensure keys in 'hashes'-type properties are no more than 30 characters long.
stix2validator/v21/shoulds.py
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): """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'] ...
[ "Ensure", "keys", "in", "hashes", "-", "type", "properties", "are", "no", "more", "than", "30", "characters", "long", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L926-L1016
[ "def", "hash_length", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "'type'", "not", "in", "obj", ":", "continue", "if", "obj", "[", "'type'", "]", "==", "'file'", "...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
duplicate_ids
Ensure objects with duplicate IDs have different `modified` timestamps.
stix2validator/v21/shoulds.py
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): """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...
[ "Ensure", "objects", "with", "duplicate", "IDs", "have", "different", "modified", "timestamps", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L1028-L1044
[ "def", "duplicate_ids", "(", "instance", ")", ":", "if", "instance", "[", "'type'", "]", "!=", "'bundle'", "or", "'objects'", "not", "in", "instance", ":", "return", "unique_ids", "=", "{", "}", "for", "obj", "in", "instance", "[", "'objects'", "]", ":",...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
list_shoulds
Construct the list of 'SHOULD' validators to be run by the validator.
stix2validator/v21/shoulds.py
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): """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...
[ "Construct", "the", "list", "of", "SHOULD", "validators", "to", "be", "run", "by", "the", "validator", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/shoulds.py#L1193-L1298
[ "def", "list_shoulds", "(", "options", ")", ":", "validator_list", "=", "[", "]", "# Default: enable all", "if", "not", "options", ".", "disabled", "and", "not", "options", ".", "enabled", ":", "validator_list", ".", "extend", "(", "CHECKS", "[", "'all'", "]...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
timestamp
Ensure timestamps contain sane months, days, hours, minutes, seconds.
stix2validator/v20/musts.py
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): """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...
[ "Ensure", "timestamps", "contain", "sane", "months", "days", "hours", "minutes", "seconds", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L23-L70
[ "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'", "...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
modified_created
`modified` property must be later or equal to `created` property
stix2validator/v20/musts.py
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): """`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...
[ "modified", "property", "must", "be", "later", "or", "equal", "to", "created", "property" ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L73-L80
[ "def", "modified_created", "(", "instance", ")", ":", "if", "'modified'", "in", "instance", "and", "'created'", "in", "instance", "and", "instance", "[", "'modified'", "]", "<", "instance", "[", "'created'", "]", ":", "msg", "=", "\"'modified' (%s) must be later...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
object_marking_circular_refs
Ensure that marking definitions do not contain circular references (ie. they do not reference themselves in the `object_marking_refs` property).
stix2validator/v20/musts.py
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): """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: ...
[ "Ensure", "that", "marking", "definitions", "do", "not", "contain", "circular", "references", "(", "ie", ".", "they", "do", "not", "reference", "themselves", "in", "the", "object_marking_refs", "property", ")", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L83-L95
[ "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'", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
granular_markings_circular_refs
Ensure that marking definitions do not contain circular references (ie. they do not reference themselves in the `granular_markings` property).
stix2validator/v20/musts.py
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): """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: ...
[ "Ensure", "that", "marking", "definitions", "do", "not", "contain", "circular", "references", "(", "ie", ".", "they", "do", "not", "reference", "themselves", "in", "the", "granular_markings", "property", ")", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L98-L110
[ "def", "granular_markings_circular_refs", "(", "instance", ")", ":", "if", "instance", "[", "'type'", "]", "!=", "'marking-definition'", ":", "return", "if", "'granular_markings'", "in", "instance", ":", "for", "marking", "in", "instance", "[", "'granular_markings'"...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
marking_selector_syntax
Ensure selectors in granular markings refer to items which are actually present in the object.
stix2validator/v20/musts.py
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): """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 '...
[ "Ensure", "selectors", "in", "granular", "markings", "refer", "to", "items", "which", "are", "actually", "present", "in", "the", "object", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L113-L156
[ "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...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
observable_object_references
Ensure certain observable object properties reference the correct type of object.
stix2validator/v20/musts.py
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): """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...
[ "Ensure", "certain", "observable", "object", "properties", "reference", "the", "correct", "type", "of", "object", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L191-L240
[ "def", "observable_object_references", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "'type'", "not", "in", "obj", ":", "continue", "elif", "obj", "[", "'type'", "]", "n...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
artifact_mime_type
Ensure the 'mime_type' property of artifact objects comes from the Template column in the IANA media type registry.
stix2validator/v20/musts.py
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): """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....
[ "Ensure", "the", "mime_type", "property", "of", "artifact", "objects", "comes", "from", "the", "Template", "column", "in", "the", "IANA", "media", "type", "registry", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L244-L265
[ "def", "artifact_mime_type", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "(", "'type'", "in", "obj", "and", "obj", "[", "'type'", "]", "==", "'artifact'", "and", "'m...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
character_set
Ensure certain properties of cyber observable objects come from the IANA Character Set list.
stix2validator/v20/musts.py
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): """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):...
[ "Ensure", "certain", "properties", "of", "cyber", "observable", "objects", "come", "from", "the", "IANA", "Character", "Set", "list", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L269-L303
[ "def", "character_set", "(", "instance", ")", ":", "char_re", "=", "re", ".", "compile", "(", "r'^[a-zA-Z0-9_\\(\\)-]+$'", ")", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "(", "'type'", "in", "...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
software_language
Ensure the 'language' property of software objects is a valid ISO 639-2 language code.
stix2validator/v20/musts.py
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): """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...
[ "Ensure", "the", "language", "property", "of", "software", "objects", "is", "a", "valid", "ISO", "639", "-", "2", "language", "code", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L307-L319
[ "def", "software_language", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "(", "'type'", "in", "obj", "and", "obj", "[", "'type'", "]", "==", "'software'", "and", "'la...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
types_strict
Ensure that no custom object types are used, but only the official ones from the specification.
stix2validator/v20/musts.py
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): """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...
[ "Ensure", "that", "no", "custom", "object", "types", "are", "used", "but", "only", "the", "official", "ones", "from", "the", "specification", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L322-L336
[ "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...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
properties_strict
Ensure that no custom properties are used, but only the official ones from the specification.
stix2validator/v20/musts.py
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): """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...
[ "Ensure", "that", "no", "custom", "properties", "are", "used", "but", "only", "the", "official", "ones", "from", "the", "specification", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L339-L396
[ "def", "properties_strict", "(", "instance", ")", ":", "if", "instance", "[", "'type'", "]", "not", "in", "enums", ".", "TYPES", ":", "return", "# only check properties for official objects", "defined_props", "=", "enums", ".", "PROPERTIES", ".", "get", "(", "in...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
patterns
Ensure that the syntax of the pattern of an indicator is valid, and that objects and properties referenced by the pattern are valid.
stix2validator/v20/musts.py
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): """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...
[ "Ensure", "that", "the", "syntax", "of", "the", "pattern", "of", "an", "indicator", "is", "valid", "and", "that", "objects", "and", "properties", "referenced", "by", "the", "pattern", "are", "valid", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L399-L470
[ "def", "patterns", "(", "instance", ",", "options", ")", ":", "if", "instance", "[", "'type'", "]", "!=", "'indicator'", "or", "'pattern'", "not", "in", "instance", ":", "return", "pattern", "=", "instance", "[", "'pattern'", "]", "if", "not", "isinstance"...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
list_musts
Construct the list of 'MUST' validators to be run by the validator.
stix2validator/v20/musts.py
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): """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...
[ "Construct", "the", "list", "of", "MUST", "validators", "to", "be", "run", "by", "the", "validator", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/musts.py#L473-L497
[ "def", "list_musts", "(", "options", ")", ":", "validator_list", "=", "[", "timestamp", ",", "modified_created", ",", "object_marking_circular_refs", ",", "granular_markings_circular_refs", ",", "marking_selector_syntax", ",", "observable_object_references", ",", "artifact_...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
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.
stix2validator/v21/enums.py
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(): """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...
[ "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...
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/enums.py#L1618-L1656
[ "def", "media_types", "(", ")", ":", "if", "not", "hasattr", "(", "media_types", ",", "'typelist'", ")", ":", "tlist", "=", "[", "]", "categories", "=", "[", "'application'", ",", "'audio'", ",", "'font'", ",", "'image'", ",", "'message'", ",", "'model'"...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
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.
stix2validator/v21/enums.py
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(): """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...
[ "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",...
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/enums.py#L1659-L1683
[ "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'", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
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.
stix2validator/v21/enums.py
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(): """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 ...
[ "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", ...
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/enums.py#L1686-L1716
[ "def", "protocols", "(", ")", ":", "if", "not", "hasattr", "(", "protocols", ",", "'protlist'", ")", ":", "plist", "=", "[", "]", "try", ":", "data", "=", "requests", ".", "get", "(", "'http://www.iana.org/assignments/service-names'", "'-port-numbers/service-nam...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
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.
stix2validator/v21/enums.py
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(): """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: ...
[ "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", ...
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/enums.py#L1719-L1741
[ "def", "ipfix", "(", ")", ":", "if", "not", "hasattr", "(", "ipfix", ",", "'ipflist'", ")", ":", "ilist", "=", "[", "]", "try", ":", "data", "=", "requests", ".", "get", "(", "'http://www.iana.org/assignments/ipfix/ipfix-'", "'information-elements.csv'", ")", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
print_level
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: ...
stix2validator/output.py
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): """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 ...
[ "Print", "a", "formatted", "message", "to", "stdout", "prepended", "by", "spaces", ".", "Useful", "for", "printing", "hierarchical", "information", "like", "bullet", "lists", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/output.py#L62-L94
[ "def", "print_level", "(", "log_function", ",", "fmt", ",", "level", ",", "*", "args", ")", ":", "if", "_SILENT", ":", "return", "msg", "=", "fmt", "%", "args", "spaces", "=", "' '", "*", "level", "log_function", "(", "\"%s%s\"", "%", "(", "spaces",...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
print_fatal_results
Print fatal errors that occurred during validation runs.
stix2validator/output.py
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 fatal errors that occurred during validation runs. """ print_level(logger.critical, _RED + "[X] Fatal Error: %s", level, results.error)
[ "Print", "fatal", "errors", "that", "occurred", "during", "validation", "runs", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/output.py#L97-L100
[ "def", "print_fatal_results", "(", "results", ",", "level", "=", "0", ")", ":", "print_level", "(", "logger", ".", "critical", ",", "_RED", "+", "\"[X] Fatal Error: %s\"", ",", "level", ",", "results", ".", "error", ")" ]
a607014e3fa500a7678f8b61b278456ca581f9d0
train
print_schema_results
Print JSON Schema validation errors to stdout. Args: results: An instance of ObjectValidationResults. level: The level at which to print the results.
stix2validator/output.py
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): """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...
[ "Print", "JSON", "Schema", "validation", "errors", "to", "stdout", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/output.py#L103-L112
[ "def", "print_schema_results", "(", "results", ",", "level", "=", "0", ")", ":", "for", "error", "in", "results", ".", "errors", ":", "print_level", "(", "logger", ".", "error", ",", "_RED", "+", "\"[X] %s\"", ",", "level", ",", "error", ")" ]
a607014e3fa500a7678f8b61b278456ca581f9d0
train
print_warning_results
Print warning messages found during validation.
stix2validator/output.py
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): """Print warning messages found during validation. """ marker = _YELLOW + "[!] " for warning in results.warnings: print_level(logger.warning, marker + "Warning: %s", level, warning)
[ "Print", "warning", "messages", "found", "during", "validation", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/output.py#L115-L121
[ "def", "print_warning_results", "(", "results", ",", "level", "=", "0", ")", ":", "marker", "=", "_YELLOW", "+", "\"[!] \"", "for", "warning", "in", "results", ".", "warnings", ":", "print_level", "(", "logger", ".", "warning", ",", "marker", "+", "\"Warni...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
print_results_header
Print a header for the results of either a file or an object.
stix2validator/output.py
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 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...
[ "Print", "a", "header", "for", "the", "results", "of", "either", "a", "file", "or", "an", "object", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/output.py#L139-L154
[ "def", "print_results_header", "(", "identifier", ",", "is_valid", ")", ":", "print_horizontal_rule", "(", ")", "print_level", "(", "logger", ".", "info", ",", "\"[-] Results for: %s\"", ",", "0", ",", "identifier", ")", "if", "is_valid", ":", "marker", "=", "...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
print_object_results
Print the results of validating an object. Args: obj_result: An ObjectValidationResults instance.
stix2validator/output.py
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 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...
[ "Print", "the", "results", "of", "validating", "an", "object", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/output.py#L157-L169
[ "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", ")", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
print_file_results
Print the results of validating a file. Args: file_result: A FileValidationResults instance.
stix2validator/output.py
def print_file_results(file_result): """Print the results of validating a file. Args: file_result: A FileValidationResults instance. """ print_results_header(file_result.filepath, file_result.is_valid) for object_result in file_result.object_results: if object_result.warnings: ...
def print_file_results(file_result): """Print the results of validating a file. Args: file_result: A FileValidationResults instance. """ print_results_header(file_result.filepath, file_result.is_valid) for object_result in file_result.object_results: if object_result.warnings: ...
[ "Print", "the", "results", "of", "validating", "a", "file", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/output.py#L172-L188
[ "def", "print_file_results", "(", "file_result", ")", ":", "print_results_header", "(", "file_result", ".", "filepath", ",", "file_result", ".", "is_valid", ")", "for", "object_result", "in", "file_result", ".", "object_results", ":", "if", "object_result", ".", "...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
print_results
Print `results` (the results of validation) to stdout. Args: results: A list of FileValidationResults or ObjectValidationResults instances.
stix2validator/output.py
def print_results(results): """Print `results` (the results of validation) to stdout. Args: results: A list of FileValidationResults or ObjectValidationResults instances. """ if not isinstance(results, list): results = [results] for r in results: try: ...
def print_results(results): """Print `results` (the results of validation) to stdout. Args: results: A list of FileValidationResults or ObjectValidationResults instances. """ if not isinstance(results, list): results = [results] for r in results: try: ...
[ "Print", "results", "(", "the", "results", "of", "validation", ")", "to", "stdout", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/output.py#L191-L207
[ "def", "print_results", "(", "results", ")", ":", "if", "not", "isinstance", "(", "results", ",", "list", ")", ":", "results", "=", "[", "results", "]", "for", "r", "in", "results", ":", "try", ":", "r", ".", "log", "(", ")", "except", "AttributeErro...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
vocab_encryption_algo
Ensure file objects' 'encryption_algorithm' property is from the encryption-algo-ov vocabulary.
stix2validator/v20/shoulds.py
def vocab_encryption_algo(instance): """Ensure file objects' 'encryption_algorithm' property is from the encryption-algo-ov vocabulary. """ for key, obj in instance['objects'].items(): if 'type' in obj and obj['type'] == 'file': try: enc_algo = obj['encryption_algorit...
def vocab_encryption_algo(instance): """Ensure file objects' 'encryption_algorithm' property is from the encryption-algo-ov vocabulary. """ for key, obj in instance['objects'].items(): if 'type' in obj and obj['type'] == 'file': try: enc_algo = obj['encryption_algorit...
[ "Ensure", "file", "objects", "encryption_algorithm", "property", "is", "from", "the", "encryption", "-", "algo", "-", "ov", "vocabulary", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/shoulds.py#L426-L441
[ "def", "vocab_encryption_algo", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "if", "'type'", "in", "obj", "and", "obj", "[", "'type'", "]", "==", "'file'", ":", "try", ":",...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
enforce_relationship_refs
Ensures that all SDOs being referenced by the SRO are contained within the same bundle
stix2validator/v20/shoulds.py
def enforce_relationship_refs(instance): """Ensures that all SDOs being referenced by the SRO are contained within the same bundle""" if instance['type'] != 'bundle' or 'objects' not in instance: return rel_references = set() """Find and store all ids""" for obj in instance['objects']:...
def enforce_relationship_refs(instance): """Ensures that all SDOs being referenced by the SRO are contained within the same bundle""" if instance['type'] != 'bundle' or 'objects' not in instance: return rel_references = set() """Find and store all ids""" for obj in instance['objects']:...
[ "Ensures", "that", "all", "SDOs", "being", "referenced", "by", "the", "SRO", "are", "contained", "within", "the", "same", "bundle" ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v20/shoulds.py#L1036-L1060
[ "def", "enforce_relationship_refs", "(", "instance", ")", ":", "if", "instance", "[", "'type'", "]", "!=", "'bundle'", "or", "'objects'", "not", "in", "instance", ":", "return", "rel_references", "=", "set", "(", ")", "\"\"\"Find and store all ids\"\"\"", "for", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
timestamp_compare
Ensure timestamp properties with a comparison requirement are valid. E.g. `modified` must be later or equal to `created`.
stix2validator/v21/musts.py
def timestamp_compare(instance): """Ensure timestamp properties with a comparison requirement are valid. E.g. `modified` must be later or equal to `created`. """ compares = [('modified', 'ge', 'created')] additional_compares = enums.TIMESTAMP_COMPARE.get(instance.get('type', ''), []) compares.e...
def timestamp_compare(instance): """Ensure timestamp properties with a comparison requirement are valid. E.g. `modified` must be later or equal to `created`. """ compares = [('modified', 'ge', 'created')] additional_compares = enums.TIMESTAMP_COMPARE.get(instance.get('type', ''), []) compares.e...
[ "Ensure", "timestamp", "properties", "with", "a", "comparison", "requirement", "are", "valid", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/musts.py#L87-L104
[ "def", "timestamp_compare", "(", "instance", ")", ":", "compares", "=", "[", "(", "'modified'", ",", "'ge'", ",", "'created'", ")", "]", "additional_compares", "=", "enums", ".", "TIMESTAMP_COMPARE", ".", "get", "(", "instance", ".", "get", "(", "'type'", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
observable_timestamp_compare
Ensure cyber observable timestamp properties with a comparison requirement are valid.
stix2validator/v21/musts.py
def observable_timestamp_compare(instance): """Ensure cyber observable timestamp properties with a comparison requirement are valid. """ for key, obj in instance['objects'].items(): compares = enums.TIMESTAMP_COMPARE_OBSERVABLE.get(obj.get('type', ''), []) print(compares) for fir...
def observable_timestamp_compare(instance): """Ensure cyber observable timestamp properties with a comparison requirement are valid. """ for key, obj in instance['objects'].items(): compares = enums.TIMESTAMP_COMPARE_OBSERVABLE.get(obj.get('type', ''), []) print(compares) for fir...
[ "Ensure", "cyber", "observable", "timestamp", "properties", "with", "a", "comparison", "requirement", "are", "valid", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/musts.py#L108-L123
[ "def", "observable_timestamp_compare", "(", "instance", ")", ":", "for", "key", ",", "obj", "in", "instance", "[", "'objects'", "]", ".", "items", "(", ")", ":", "compares", "=", "enums", ".", "TIMESTAMP_COMPARE_OBSERVABLE", ".", "get", "(", "obj", ".", "g...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
language_contents
Ensure keys in Language Content's 'contents' dictionary are valid language codes, and that the keys in the sub-dictionaries match the rules for object property names.
stix2validator/v21/musts.py
def language_contents(instance): """Ensure keys in Language Content's 'contents' dictionary are valid language codes, and that the keys in the sub-dictionaries match the rules for object property names. """ if instance['type'] != 'language-content' or 'contents' not in instance: return ...
def language_contents(instance): """Ensure keys in Language Content's 'contents' dictionary are valid language codes, and that the keys in the sub-dictionaries match the rules for object property names. """ if instance['type'] != 'language-content' or 'contents' not in instance: return ...
[ "Ensure", "keys", "in", "Language", "Content", "s", "contents", "dictionary", "are", "valid", "language", "codes", "and", "that", "the", "keys", "in", "the", "sub", "-", "dictionaries", "match", "the", "rules", "for", "object", "property", "names", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/musts.py#L521-L537
[ "def", "language_contents", "(", "instance", ")", ":", "if", "instance", "[", "'type'", "]", "!=", "'language-content'", "or", "'contents'", "not", "in", "instance", ":", "return", "for", "key", ",", "value", "in", "instance", "[", "'contents'", "]", ".", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
list_musts
Construct the list of 'MUST' validators to be run by the validator.
stix2validator/v21/musts.py
def list_musts(options): """Construct the list of 'MUST' validators to be run by the validator. """ validator_list = [ timestamp, timestamp_compare, observable_timestamp_compare, object_marking_circular_refs, granular_markings_circular_refs, marking_selector_s...
def list_musts(options): """Construct the list of 'MUST' validators to be run by the validator. """ validator_list = [ timestamp, timestamp_compare, observable_timestamp_compare, object_marking_circular_refs, granular_markings_circular_refs, marking_selector_s...
[ "Construct", "the", "list", "of", "MUST", "validators", "to", "be", "run", "by", "the", "validator", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/v21/musts.py#L540-L567
[ "def", "list_musts", "(", "options", ")", ":", "validator_list", "=", "[", "timestamp", ",", "timestamp_compare", ",", "observable_timestamp_compare", ",", "object_marking_circular_refs", ",", "granular_markings_circular_refs", ",", "marking_selector_syntax", ",", "observab...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
get_code
Determines the exit status code to be returned from a script by inspecting the results returned from validating file(s). Status codes are binary OR'd together, so exit codes can communicate multiple error conditions.
stix2validator/codes.py
def get_code(results): """Determines the exit status code to be returned from a script by inspecting the results returned from validating file(s). Status codes are binary OR'd together, so exit codes can communicate multiple error conditions. """ status = EXIT_SUCCESS for file_result in re...
def get_code(results): """Determines the exit status code to be returned from a script by inspecting the results returned from validating file(s). Status codes are binary OR'd together, so exit codes can communicate multiple error conditions. """ status = EXIT_SUCCESS for file_result in re...
[ "Determines", "the", "exit", "status", "code", "to", "be", "returned", "from", "a", "script", "by", "inspecting", "the", "results", "returned", "from", "validating", "file", "(", "s", ")", ".", "Status", "codes", "are", "binary", "OR", "d", "together", "so...
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/codes.py#L22-L41
[ "def", "get_code", "(", "results", ")", ":", "status", "=", "EXIT_SUCCESS", "for", "file_result", "in", "results", ":", "error", "=", "any", "(", "object_result", ".", "errors", "for", "object_result", "in", "file_result", ".", "object_results", ")", "fatal", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
parse_args
Parses a list of command line arguments into a ValidationOptions object. Args: cmd_args (list of str): The list of command line arguments to be parsed. is_script: Whether the arguments are intended for use in a stand-alone script or imported into another tool. Returns: Inst...
stix2validator/util.py
def parse_args(cmd_args, is_script=False): """Parses a list of command line arguments into a ValidationOptions object. Args: cmd_args (list of str): The list of command line arguments to be parsed. is_script: Whether the arguments are intended for use in a stand-alone script or impo...
def parse_args(cmd_args, is_script=False): """Parses a list of command line arguments into a ValidationOptions object. Args: cmd_args (list of str): The list of command line arguments to be parsed. is_script: Whether the arguments are intended for use in a stand-alone script or impo...
[ "Parses", "a", "list", "of", "command", "line", "arguments", "into", "a", "ValidationOptions", "object", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/util.py#L125-L286
[ "def", "parse_args", "(", "cmd_args", ",", "is_script", "=", "False", ")", ":", "parser", "=", "argparse", ".", "ArgumentParser", "(", "description", "=", "__doc__", ",", "formatter_class", "=", "NewlinesHelpFormatter", ",", "epilog", "=", "CODES_TABLE", ")", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
cyber_observable_check
Decorator for functions that require cyber observable data.
stix2validator/util.py
def cyber_observable_check(original_function): """Decorator for functions that require cyber observable data. """ def new_function(*args, **kwargs): if not has_cyber_observable_data(args[0]): return func = original_function(*args, **kwargs) if isinstance(func, Iterable): ...
def cyber_observable_check(original_function): """Decorator for functions that require cyber observable data. """ def new_function(*args, **kwargs): if not has_cyber_observable_data(args[0]): return func = original_function(*args, **kwargs) if isinstance(func, Iterable): ...
[ "Decorator", "for", "functions", "that", "require", "cyber", "observable", "data", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/util.py#L405-L416
[ "def", "cyber_observable_check", "(", "original_function", ")", ":", "def", "new_function", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "not", "has_cyber_observable_data", "(", "args", "[", "0", "]", ")", ":", "return", "func", "=", "origina...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
init_requests_cache
Initializes a cache which the ``requests`` library will consult for responses, before making network requests. :param refresh_cache: Whether the cache should be cleared out
stix2validator/util.py
def init_requests_cache(refresh_cache=False): """ Initializes a cache which the ``requests`` library will consult for responses, before making network requests. :param refresh_cache: Whether the cache should be cleared out """ # Cache data from external sources; used in some checks dirs = A...
def init_requests_cache(refresh_cache=False): """ Initializes a cache which the ``requests`` library will consult for responses, before making network requests. :param refresh_cache: Whether the cache should be cleared out """ # Cache data from external sources; used in some checks dirs = A...
[ "Initializes", "a", "cache", "which", "the", "requests", "library", "will", "consult", "for", "responses", "before", "making", "network", "requests", "." ]
oasis-open/cti-stix-validator
python
https://github.com/oasis-open/cti-stix-validator/blob/a607014e3fa500a7678f8b61b278456ca581f9d0/stix2validator/util.py#L419-L440
[ "def", "init_requests_cache", "(", "refresh_cache", "=", "False", ")", ":", "# Cache data from external sources; used in some checks", "dirs", "=", "AppDirs", "(", "\"stix2-validator\"", ",", "\"OASIS\"", ")", "# Create cache dir if doesn't exist", "try", ":", "os", ".", ...
a607014e3fa500a7678f8b61b278456ca581f9d0
train
ActiveUrl.render_tag
render content with "active" urls logic
django_activeurl/templatetags/activeurl.py
def render_tag(self, context, kwargs, nodelist): '''render content with "active" urls logic''' # load configuration from passed options self.load_configuration(**kwargs) # get request from context request = context['request'] # get full path from request self.fu...
def render_tag(self, context, kwargs, nodelist): '''render content with "active" urls logic''' # load configuration from passed options self.load_configuration(**kwargs) # get request from context request = context['request'] # get full path from request self.fu...
[ "render", "content", "with", "active", "urls", "logic" ]
hellysmile/django-activeurl
python
https://github.com/hellysmile/django-activeurl/blob/40d7f01b217641705fc5b7fe387e28e48ce332dc/django_activeurl/templatetags/activeurl.py#L27-L53
[ "def", "render_tag", "(", "self", ",", "context", ",", "kwargs", ",", "nodelist", ")", ":", "# load configuration from passed options", "self", ".", "load_configuration", "(", "*", "*", "kwargs", ")", "# get request from context", "request", "=", "context", "[", "...
40d7f01b217641705fc5b7fe387e28e48ce332dc
train
ActiveUrl.parse
parse content of extension
django_activeurl/ext/django_jinja.py
def parse(self, parser): '''parse content of extension''' # line number of token that started the tag lineno = next(parser.stream).lineno # template context context = nodes.ContextReference() # parse keyword arguments kwargs = [] while parser.stream.loo...
def parse(self, parser): '''parse content of extension''' # line number of token that started the tag lineno = next(parser.stream).lineno # template context context = nodes.ContextReference() # parse keyword arguments kwargs = [] while parser.stream.loo...
[ "parse", "content", "of", "extension" ]
hellysmile/django-activeurl
python
https://github.com/hellysmile/django-activeurl/blob/40d7f01b217641705fc5b7fe387e28e48ce332dc/django_activeurl/ext/django_jinja.py#L17-L46
[ "def", "parse", "(", "self", ",", "parser", ")", ":", "# line number of token that started the tag", "lineno", "=", "next", "(", "parser", ".", "stream", ")", ".", "lineno", "# template context", "context", "=", "nodes", ".", "ContextReference", "(", ")", "# par...
40d7f01b217641705fc5b7fe387e28e48ce332dc
train
ActiveUrl.render_tag
render content with "active" urls logic
django_activeurl/ext/django_jinja.py
def render_tag(self, context, caller, **kwargs): '''render content with "active" urls logic''' # load configuration from passed options self.load_configuration(**kwargs) # get request from context request = context['request'] # get full path from request self.fu...
def render_tag(self, context, caller, **kwargs): '''render content with "active" urls logic''' # load configuration from passed options self.load_configuration(**kwargs) # get request from context request = context['request'] # get full path from request self.fu...
[ "render", "content", "with", "active", "urls", "logic" ]
hellysmile/django-activeurl
python
https://github.com/hellysmile/django-activeurl/blob/40d7f01b217641705fc5b7fe387e28e48ce332dc/django_activeurl/ext/django_jinja.py#L48-L72
[ "def", "render_tag", "(", "self", ",", "context", ",", "caller", ",", "*", "*", "kwargs", ")", ":", "# load configuration from passed options", "self", ".", "load_configuration", "(", "*", "*", "kwargs", ")", "# get request from context", "request", "=", "context"...
40d7f01b217641705fc5b7fe387e28e48ce332dc
train
get_cache_key
generate cache key
django_activeurl/utils.py
def get_cache_key(content, **kwargs): '''generate cache key''' cache_key = '' for key in sorted(kwargs.keys()): cache_key = '{cache_key}.{key}:{value}'.format( cache_key=cache_key, key=key, value=kwargs[key], ) cache_key = '{content}{cache_key}'.forma...
def get_cache_key(content, **kwargs): '''generate cache key''' cache_key = '' for key in sorted(kwargs.keys()): cache_key = '{cache_key}.{key}:{value}'.format( cache_key=cache_key, key=key, value=kwargs[key], ) cache_key = '{content}{cache_key}'.forma...
[ "generate", "cache", "key" ]
hellysmile/django-activeurl
python
https://github.com/hellysmile/django-activeurl/blob/40d7f01b217641705fc5b7fe387e28e48ce332dc/django_activeurl/utils.py#L42-L68
[ "def", "get_cache_key", "(", "content", ",", "*", "*", "kwargs", ")", ":", "cache_key", "=", "''", "for", "key", "in", "sorted", "(", "kwargs", ".", "keys", "(", ")", ")", ":", "cache_key", "=", "'{cache_key}.{key}:{value}'", ".", "format", "(", "cache_k...
40d7f01b217641705fc5b7fe387e28e48ce332dc
train
yesno_to_bool
Return True/False from "yes"/"no". :param value: template keyword argument value :type value: string :param varname: name of the variable, for use on exception raising :type varname: string :raises: :exc:`ImproperlyConfigured` Django > 1.5 template boolean/None variables feature.
django_activeurl/utils.py
def yesno_to_bool(value, varname): """Return True/False from "yes"/"no". :param value: template keyword argument value :type value: string :param varname: name of the variable, for use on exception raising :type varname: string :raises: :exc:`ImproperlyConfigured` Django > 1.5 template boo...
def yesno_to_bool(value, varname): """Return True/False from "yes"/"no". :param value: template keyword argument value :type value: string :param varname: name of the variable, for use on exception raising :type varname: string :raises: :exc:`ImproperlyConfigured` Django > 1.5 template boo...
[ "Return", "True", "/", "False", "from", "yes", "/", "no", "." ]
hellysmile/django-activeurl
python
https://github.com/hellysmile/django-activeurl/blob/40d7f01b217641705fc5b7fe387e28e48ce332dc/django_activeurl/utils.py#L71-L99
[ "def", "yesno_to_bool", "(", "value", ",", "varname", ")", ":", "if", "isinstance", "(", "value", ",", "bool", ")", ":", "if", "value", ":", "value", "=", "'yes'", "else", ":", "value", "=", "'no'", "elif", "value", "is", "None", ":", "value", "=", ...
40d7f01b217641705fc5b7fe387e28e48ce332dc
train
check_active
check "active" url, apply css_class
django_activeurl/utils.py
def check_active(url, element, **kwargs): '''check "active" url, apply css_class''' menu = yesno_to_bool(kwargs['menu'], 'menu') ignore_params = yesno_to_bool(kwargs['ignore_params'], 'ignore_params') # check missing href parameter if not url.attrib.get('href', None) is None: # get href att...
def check_active(url, element, **kwargs): '''check "active" url, apply css_class''' menu = yesno_to_bool(kwargs['menu'], 'menu') ignore_params = yesno_to_bool(kwargs['ignore_params'], 'ignore_params') # check missing href parameter if not url.attrib.get('href', None) is None: # get href att...
[ "check", "active", "url", "apply", "css_class" ]
hellysmile/django-activeurl
python
https://github.com/hellysmile/django-activeurl/blob/40d7f01b217641705fc5b7fe387e28e48ce332dc/django_activeurl/utils.py#L102-L185
[ "def", "check_active", "(", "url", ",", "element", ",", "*", "*", "kwargs", ")", ":", "menu", "=", "yesno_to_bool", "(", "kwargs", "[", "'menu'", "]", ",", "'menu'", ")", "ignore_params", "=", "yesno_to_bool", "(", "kwargs", "[", "'ignore_params'", "]", ...
40d7f01b217641705fc5b7fe387e28e48ce332dc
train
check_content
check content for "active" urls
django_activeurl/utils.py
def check_content(content, **kwargs): '''check content for "active" urls''' # valid html root tag try: # render elements tree from content tree = fragment_fromstring(content) # flag for prevent content rerendering, when no "active" urls found processed = False # djang...
def check_content(content, **kwargs): '''check content for "active" urls''' # valid html root tag try: # render elements tree from content tree = fragment_fromstring(content) # flag for prevent content rerendering, when no "active" urls found processed = False # djang...
[ "check", "content", "for", "active", "urls" ]
hellysmile/django-activeurl
python
https://github.com/hellysmile/django-activeurl/blob/40d7f01b217641705fc5b7fe387e28e48ce332dc/django_activeurl/utils.py#L188-L255
[ "def", "check_content", "(", "content", ",", "*", "*", "kwargs", ")", ":", "# valid html root tag", "try", ":", "# render elements tree from content", "tree", "=", "fragment_fromstring", "(", "content", ")", "# flag for prevent content rerendering, when no \"active\" urls fou...
40d7f01b217641705fc5b7fe387e28e48ce332dc
train
render_content
check content for "active" urls, store results to django cache
django_activeurl/utils.py
def render_content(content, **kwargs): '''check content for "active" urls, store results to django cache''' # try to take pre rendered content from django cache, if caching is enabled if settings.ACTIVE_URL_CACHE: cache_key = get_cache_key(content, **kwargs) # get cached content from django...
def render_content(content, **kwargs): '''check content for "active" urls, store results to django cache''' # try to take pre rendered content from django cache, if caching is enabled if settings.ACTIVE_URL_CACHE: cache_key = get_cache_key(content, **kwargs) # get cached content from django...
[ "check", "content", "for", "active", "urls", "store", "results", "to", "django", "cache" ]
hellysmile/django-activeurl
python
https://github.com/hellysmile/django-activeurl/blob/40d7f01b217641705fc5b7fe387e28e48ce332dc/django_activeurl/utils.py#L258-L278
[ "def", "render_content", "(", "content", ",", "*", "*", "kwargs", ")", ":", "# try to take pre rendered content from django cache, if caching is enabled", "if", "settings", ".", "ACTIVE_URL_CACHE", ":", "cache_key", "=", "get_cache_key", "(", "content", ",", "*", "*", ...
40d7f01b217641705fc5b7fe387e28e48ce332dc
train
Configuration.load_configuration
load configuration, merge with default settings
django_activeurl/utils.py
def load_configuration(self, **kwargs): '''load configuration, merge with default settings''' # update passed arguments with default values for key in settings.ACTIVE_URL_KWARGS: kwargs.setdefault(key, settings.ACTIVE_URL_KWARGS[key]) # "active" html tag css class se...
def load_configuration(self, **kwargs): '''load configuration, merge with default settings''' # update passed arguments with default values for key in settings.ACTIVE_URL_KWARGS: kwargs.setdefault(key, settings.ACTIVE_URL_KWARGS[key]) # "active" html tag css class se...
[ "load", "configuration", "merge", "with", "default", "settings" ]
hellysmile/django-activeurl
python
https://github.com/hellysmile/django-activeurl/blob/40d7f01b217641705fc5b7fe387e28e48ce332dc/django_activeurl/utils.py#L26-L39
[ "def", "load_configuration", "(", "self", ",", "*", "*", "kwargs", ")", ":", "# update passed arguments with default values", "for", "key", "in", "settings", ".", "ACTIVE_URL_KWARGS", ":", "kwargs", ".", "setdefault", "(", "key", ",", "settings", ".", "ACTIVE_URL_...
40d7f01b217641705fc5b7fe387e28e48ce332dc
train
MarathonClient._parse_response
Parse a Marathon response into an object or list of objects.
marathon/client.py
def _parse_response(response, clazz, is_list=False, resource_name=None): """Parse a Marathon response into an object or list of objects.""" target = response.json()[ resource_name] if resource_name else response.json() if is_list: return [clazz.from_json(resource) for res...
def _parse_response(response, clazz, is_list=False, resource_name=None): """Parse a Marathon response into an object or list of objects.""" target = response.json()[ resource_name] if resource_name else response.json() if is_list: return [clazz.from_json(resource) for res...
[ "Parse", "a", "Marathon", "response", "into", "an", "object", "or", "list", "of", "objects", "." ]
thefactory/marathon-python
python
https://github.com/thefactory/marathon-python/blob/592b253aa8edf2475c97ca438ad7b6936652caf2/marathon/client.py#L67-L74
[ "def", "_parse_response", "(", "response", ",", "clazz", ",", "is_list", "=", "False", ",", "resource_name", "=", "None", ")", ":", "target", "=", "response", ".", "json", "(", ")", "[", "resource_name", "]", "if", "resource_name", "else", "response", ".",...
592b253aa8edf2475c97ca438ad7b6936652caf2
train
MarathonClient._do_request
Query Marathon server.
marathon/client.py
def _do_request(self, method, path, params=None, data=None): """Query Marathon server.""" headers = { 'Content-Type': 'application/json', 'Accept': 'application/json'} if self.auth_token: headers['Authorization'] = "token={}".format(self.auth_token) response = N...
def _do_request(self, method, path, params=None, data=None): """Query Marathon server.""" headers = { 'Content-Type': 'application/json', 'Accept': 'application/json'} if self.auth_token: headers['Authorization'] = "token={}".format(self.auth_token) response = N...
[ "Query", "Marathon", "server", "." ]
thefactory/marathon-python
python
https://github.com/thefactory/marathon-python/blob/592b253aa8edf2475c97ca438ad7b6936652caf2/marathon/client.py#L76-L121
[ "def", "_do_request", "(", "self", ",", "method", ",", "path", ",", "params", "=", "None", ",", "data", "=", "None", ")", ":", "headers", "=", "{", "'Content-Type'", ":", "'application/json'", ",", "'Accept'", ":", "'application/json'", "}", "if", "self", ...
592b253aa8edf2475c97ca438ad7b6936652caf2
train
MarathonClient._do_sse_request
Query Marathon server for events.
marathon/client.py
def _do_sse_request(self, path, params=None): """Query Marathon server for events.""" urls = [''.join([server.rstrip('/'), path]) for server in self.servers] while urls: url = urls.pop() try: # Requests does not set the original Authorization header on cro...
def _do_sse_request(self, path, params=None): """Query Marathon server for events.""" urls = [''.join([server.rstrip('/'), path]) for server in self.servers] while urls: url = urls.pop() try: # Requests does not set the original Authorization header on cro...
[ "Query", "Marathon", "server", "for", "events", "." ]
thefactory/marathon-python
python
https://github.com/thefactory/marathon-python/blob/592b253aa8edf2475c97ca438ad7b6936652caf2/marathon/client.py#L123-L150
[ "def", "_do_sse_request", "(", "self", ",", "path", ",", "params", "=", "None", ")", ":", "urls", "=", "[", "''", ".", "join", "(", "[", "server", ".", "rstrip", "(", "'/'", ")", ",", "path", "]", ")", "for", "server", "in", "self", ".", "servers...
592b253aa8edf2475c97ca438ad7b6936652caf2