repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
optimizely/python-sdk
optimizely/bucketer.py
Bucketer.bucket
def bucket(self, experiment, user_id, bucketing_id): """ For a given experiment and bucketing ID determines variation to be shown to user. Args: experiment: Object representing the experiment for which user is to be bucketed. user_id: ID for user. bucketing_id: ID to be used for bucketing the...
python
def bucket(self, experiment, user_id, bucketing_id): """ For a given experiment and bucketing ID determines variation to be shown to user. Args: experiment: Object representing the experiment for which user is to be bucketed. user_id: ID for user. bucketing_id: ID to be used for bucketing the...
[ "def", "bucket", "(", "self", ",", "experiment", ",", "user_id", ",", "bucketing_id", ")", ":", "if", "not", "experiment", ":", "return", "None", "# Determine if experiment is in a mutually exclusive group", "if", "experiment", ".", "groupPolicy", "in", "GROUP_POLICIE...
For a given experiment and bucketing ID determines variation to be shown to user. Args: experiment: Object representing the experiment for which user is to be bucketed. user_id: ID for user. bucketing_id: ID to be used for bucketing the user. Returns: Variation in which user with ID us...
[ "For", "a", "given", "experiment", "and", "bucketing", "ID", "determines", "variation", "to", "be", "shown", "to", "user", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/bucketer.py#L94-L147
train
optimizely/python-sdk
optimizely/project_config.py
ProjectConfig._generate_key_map
def _generate_key_map(entity_list, key, entity_class): """ Helper method to generate map from key to entity object for given list of dicts. Args: entity_list: List consisting of dict. key: Key in each dict which will be key in the map. entity_class: Class representing the entity. Returns...
python
def _generate_key_map(entity_list, key, entity_class): """ Helper method to generate map from key to entity object for given list of dicts. Args: entity_list: List consisting of dict. key: Key in each dict which will be key in the map. entity_class: Class representing the entity. Returns...
[ "def", "_generate_key_map", "(", "entity_list", ",", "key", ",", "entity_class", ")", ":", "key_map", "=", "{", "}", "for", "obj", "in", "entity_list", ":", "key_map", "[", "obj", "[", "key", "]", "]", "=", "entity_class", "(", "*", "*", "obj", ")", ...
Helper method to generate map from key to entity object for given list of dicts. Args: entity_list: List consisting of dict. key: Key in each dict which will be key in the map. entity_class: Class representing the entity. Returns: Map mapping key to entity object.
[ "Helper", "method", "to", "generate", "map", "from", "key", "to", "entity", "object", "for", "given", "list", "of", "dicts", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/project_config.py#L134-L150
train
optimizely/python-sdk
optimizely/project_config.py
ProjectConfig._deserialize_audience
def _deserialize_audience(audience_map): """ Helper method to de-serialize and populate audience map with the condition list and structure. Args: audience_map: Dict mapping audience ID to audience object. Returns: Dict additionally consisting of condition list and structure on every audience o...
python
def _deserialize_audience(audience_map): """ Helper method to de-serialize and populate audience map with the condition list and structure. Args: audience_map: Dict mapping audience ID to audience object. Returns: Dict additionally consisting of condition list and structure on every audience o...
[ "def", "_deserialize_audience", "(", "audience_map", ")", ":", "for", "audience", "in", "audience_map", ".", "values", "(", ")", ":", "condition_structure", ",", "condition_list", "=", "condition_helper", ".", "loads", "(", "audience", ".", "conditions", ")", "a...
Helper method to de-serialize and populate audience map with the condition list and structure. Args: audience_map: Dict mapping audience ID to audience object. Returns: Dict additionally consisting of condition list and structure on every audience object.
[ "Helper", "method", "to", "de", "-", "serialize", "and", "populate", "audience", "map", "with", "the", "condition", "list", "and", "structure", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/project_config.py#L153-L170
train
optimizely/python-sdk
optimizely/project_config.py
ProjectConfig.get_typecast_value
def get_typecast_value(self, value, type): """ Helper method to determine actual value based on type of feature variable. Args: value: Value in string form as it was parsed from datafile. type: Type denoting the feature flag type. Return: Value type-casted based on type of feature variab...
python
def get_typecast_value(self, value, type): """ Helper method to determine actual value based on type of feature variable. Args: value: Value in string form as it was parsed from datafile. type: Type denoting the feature flag type. Return: Value type-casted based on type of feature variab...
[ "def", "get_typecast_value", "(", "self", ",", "value", ",", "type", ")", ":", "if", "type", "==", "entities", ".", "Variable", ".", "Type", ".", "BOOLEAN", ":", "return", "value", "==", "'true'", "elif", "type", "==", "entities", ".", "Variable", ".", ...
Helper method to determine actual value based on type of feature variable. Args: value: Value in string form as it was parsed from datafile. type: Type denoting the feature flag type. Return: Value type-casted based on type of feature variable.
[ "Helper", "method", "to", "determine", "actual", "value", "based", "on", "type", "of", "feature", "variable", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/project_config.py#L172-L190
train
optimizely/python-sdk
optimizely/project_config.py
ProjectConfig.get_experiment_from_key
def get_experiment_from_key(self, experiment_key): """ Get experiment for the provided experiment key. Args: experiment_key: Experiment key for which experiment is to be determined. Returns: Experiment corresponding to the provided experiment key. """ experiment = self.experiment_key_...
python
def get_experiment_from_key(self, experiment_key): """ Get experiment for the provided experiment key. Args: experiment_key: Experiment key for which experiment is to be determined. Returns: Experiment corresponding to the provided experiment key. """ experiment = self.experiment_key_...
[ "def", "get_experiment_from_key", "(", "self", ",", "experiment_key", ")", ":", "experiment", "=", "self", ".", "experiment_key_map", ".", "get", "(", "experiment_key", ")", "if", "experiment", ":", "return", "experiment", "self", ".", "logger", ".", "error", ...
Get experiment for the provided experiment key. Args: experiment_key: Experiment key for which experiment is to be determined. Returns: Experiment corresponding to the provided experiment key.
[ "Get", "experiment", "for", "the", "provided", "experiment", "key", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/project_config.py#L228-L245
train
optimizely/python-sdk
optimizely/project_config.py
ProjectConfig.get_experiment_from_id
def get_experiment_from_id(self, experiment_id): """ Get experiment for the provided experiment ID. Args: experiment_id: Experiment ID for which experiment is to be determined. Returns: Experiment corresponding to the provided experiment ID. """ experiment = self.experiment_id_map.get...
python
def get_experiment_from_id(self, experiment_id): """ Get experiment for the provided experiment ID. Args: experiment_id: Experiment ID for which experiment is to be determined. Returns: Experiment corresponding to the provided experiment ID. """ experiment = self.experiment_id_map.get...
[ "def", "get_experiment_from_id", "(", "self", ",", "experiment_id", ")", ":", "experiment", "=", "self", ".", "experiment_id_map", ".", "get", "(", "experiment_id", ")", "if", "experiment", ":", "return", "experiment", "self", ".", "logger", ".", "error", "(",...
Get experiment for the provided experiment ID. Args: experiment_id: Experiment ID for which experiment is to be determined. Returns: Experiment corresponding to the provided experiment ID.
[ "Get", "experiment", "for", "the", "provided", "experiment", "ID", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/project_config.py#L247-L264
train
optimizely/python-sdk
optimizely/project_config.py
ProjectConfig.get_group
def get_group(self, group_id): """ Get group for the provided group ID. Args: group_id: Group ID for which group is to be determined. Returns: Group corresponding to the provided group ID. """ group = self.group_id_map.get(group_id) if group: return group self.logger.e...
python
def get_group(self, group_id): """ Get group for the provided group ID. Args: group_id: Group ID for which group is to be determined. Returns: Group corresponding to the provided group ID. """ group = self.group_id_map.get(group_id) if group: return group self.logger.e...
[ "def", "get_group", "(", "self", ",", "group_id", ")", ":", "group", "=", "self", ".", "group_id_map", ".", "get", "(", "group_id", ")", "if", "group", ":", "return", "group", "self", ".", "logger", ".", "error", "(", "'Group ID \"%s\" is not in datafile.'",...
Get group for the provided group ID. Args: group_id: Group ID for which group is to be determined. Returns: Group corresponding to the provided group ID.
[ "Get", "group", "for", "the", "provided", "group", "ID", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/project_config.py#L266-L283
train
optimizely/python-sdk
optimizely/project_config.py
ProjectConfig.get_audience
def get_audience(self, audience_id): """ Get audience object for the provided audience ID. Args: audience_id: ID of the audience. Returns: Dict representing the audience. """ audience = self.audience_id_map.get(audience_id) if audience: return audience self.logger.error...
python
def get_audience(self, audience_id): """ Get audience object for the provided audience ID. Args: audience_id: ID of the audience. Returns: Dict representing the audience. """ audience = self.audience_id_map.get(audience_id) if audience: return audience self.logger.error...
[ "def", "get_audience", "(", "self", ",", "audience_id", ")", ":", "audience", "=", "self", ".", "audience_id_map", ".", "get", "(", "audience_id", ")", "if", "audience", ":", "return", "audience", "self", ".", "logger", ".", "error", "(", "'Audience ID \"%s\...
Get audience object for the provided audience ID. Args: audience_id: ID of the audience. Returns: Dict representing the audience.
[ "Get", "audience", "object", "for", "the", "provided", "audience", "ID", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/project_config.py#L285-L300
train
optimizely/python-sdk
optimizely/project_config.py
ProjectConfig.get_variation_from_key
def get_variation_from_key(self, experiment_key, variation_key): """ Get variation given experiment and variation key. Args: experiment: Key representing parent experiment of variation. variation_key: Key representing the variation. Returns Object representing the variation. """ ...
python
def get_variation_from_key(self, experiment_key, variation_key): """ Get variation given experiment and variation key. Args: experiment: Key representing parent experiment of variation. variation_key: Key representing the variation. Returns Object representing the variation. """ ...
[ "def", "get_variation_from_key", "(", "self", ",", "experiment_key", ",", "variation_key", ")", ":", "variation_map", "=", "self", ".", "variation_key_map", ".", "get", "(", "experiment_key", ")", "if", "variation_map", ":", "variation", "=", "variation_map", ".",...
Get variation given experiment and variation key. Args: experiment: Key representing parent experiment of variation. variation_key: Key representing the variation. Returns Object representing the variation.
[ "Get", "variation", "given", "experiment", "and", "variation", "key", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/project_config.py#L302-L326
train
optimizely/python-sdk
optimizely/project_config.py
ProjectConfig.get_variation_from_id
def get_variation_from_id(self, experiment_key, variation_id): """ Get variation given experiment and variation ID. Args: experiment: Key representing parent experiment of variation. variation_id: ID representing the variation. Returns Object representing the variation. """ vari...
python
def get_variation_from_id(self, experiment_key, variation_id): """ Get variation given experiment and variation ID. Args: experiment: Key representing parent experiment of variation. variation_id: ID representing the variation. Returns Object representing the variation. """ vari...
[ "def", "get_variation_from_id", "(", "self", ",", "experiment_key", ",", "variation_id", ")", ":", "variation_map", "=", "self", ".", "variation_id_map", ".", "get", "(", "experiment_key", ")", "if", "variation_map", ":", "variation", "=", "variation_map", ".", ...
Get variation given experiment and variation ID. Args: experiment: Key representing parent experiment of variation. variation_id: ID representing the variation. Returns Object representing the variation.
[ "Get", "variation", "given", "experiment", "and", "variation", "ID", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/project_config.py#L328-L352
train
optimizely/python-sdk
optimizely/project_config.py
ProjectConfig.get_event
def get_event(self, event_key): """ Get event for the provided event key. Args: event_key: Event key for which event is to be determined. Returns: Event corresponding to the provided event key. """ event = self.event_key_map.get(event_key) if event: return event self.l...
python
def get_event(self, event_key): """ Get event for the provided event key. Args: event_key: Event key for which event is to be determined. Returns: Event corresponding to the provided event key. """ event = self.event_key_map.get(event_key) if event: return event self.l...
[ "def", "get_event", "(", "self", ",", "event_key", ")", ":", "event", "=", "self", ".", "event_key_map", ".", "get", "(", "event_key", ")", "if", "event", ":", "return", "event", "self", ".", "logger", ".", "error", "(", "'Event \"%s\" is not in datafile.'",...
Get event for the provided event key. Args: event_key: Event key for which event is to be determined. Returns: Event corresponding to the provided event key.
[ "Get", "event", "for", "the", "provided", "event", "key", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/project_config.py#L354-L371
train
optimizely/python-sdk
optimizely/project_config.py
ProjectConfig.get_attribute_id
def get_attribute_id(self, attribute_key): """ Get attribute ID for the provided attribute key. Args: attribute_key: Attribute key for which attribute is to be fetched. Returns: Attribute ID corresponding to the provided attribute key. """ attribute = self.attribute_key_map.get(attrib...
python
def get_attribute_id(self, attribute_key): """ Get attribute ID for the provided attribute key. Args: attribute_key: Attribute key for which attribute is to be fetched. Returns: Attribute ID corresponding to the provided attribute key. """ attribute = self.attribute_key_map.get(attrib...
[ "def", "get_attribute_id", "(", "self", ",", "attribute_key", ")", ":", "attribute", "=", "self", ".", "attribute_key_map", ".", "get", "(", "attribute_key", ")", "has_reserved_prefix", "=", "attribute_key", ".", "startswith", "(", "RESERVED_ATTRIBUTE_PREFIX", ")", ...
Get attribute ID for the provided attribute key. Args: attribute_key: Attribute key for which attribute is to be fetched. Returns: Attribute ID corresponding to the provided attribute key.
[ "Get", "attribute", "ID", "for", "the", "provided", "attribute", "key", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/project_config.py#L373-L398
train
optimizely/python-sdk
optimizely/project_config.py
ProjectConfig.get_feature_from_key
def get_feature_from_key(self, feature_key): """ Get feature for the provided feature key. Args: feature_key: Feature key for which feature is to be fetched. Returns: Feature corresponding to the provided feature key. """ feature = self.feature_key_map.get(feature_key) if feature:...
python
def get_feature_from_key(self, feature_key): """ Get feature for the provided feature key. Args: feature_key: Feature key for which feature is to be fetched. Returns: Feature corresponding to the provided feature key. """ feature = self.feature_key_map.get(feature_key) if feature:...
[ "def", "get_feature_from_key", "(", "self", ",", "feature_key", ")", ":", "feature", "=", "self", ".", "feature_key_map", ".", "get", "(", "feature_key", ")", "if", "feature", ":", "return", "feature", "self", ".", "logger", ".", "error", "(", "'Feature \"%s...
Get feature for the provided feature key. Args: feature_key: Feature key for which feature is to be fetched. Returns: Feature corresponding to the provided feature key.
[ "Get", "feature", "for", "the", "provided", "feature", "key", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/project_config.py#L400-L415
train
optimizely/python-sdk
optimizely/project_config.py
ProjectConfig.get_rollout_from_id
def get_rollout_from_id(self, rollout_id): """ Get rollout for the provided ID. Args: rollout_id: ID of the rollout to be fetched. Returns: Rollout corresponding to the provided ID. """ layer = self.rollout_id_map.get(rollout_id) if layer: return layer self.logger.error...
python
def get_rollout_from_id(self, rollout_id): """ Get rollout for the provided ID. Args: rollout_id: ID of the rollout to be fetched. Returns: Rollout corresponding to the provided ID. """ layer = self.rollout_id_map.get(rollout_id) if layer: return layer self.logger.error...
[ "def", "get_rollout_from_id", "(", "self", ",", "rollout_id", ")", ":", "layer", "=", "self", ".", "rollout_id_map", ".", "get", "(", "rollout_id", ")", "if", "layer", ":", "return", "layer", "self", ".", "logger", ".", "error", "(", "'Rollout with ID \"%s\"...
Get rollout for the provided ID. Args: rollout_id: ID of the rollout to be fetched. Returns: Rollout corresponding to the provided ID.
[ "Get", "rollout", "for", "the", "provided", "ID", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/project_config.py#L417-L432
train
optimizely/python-sdk
optimizely/project_config.py
ProjectConfig.get_variable_value_for_variation
def get_variable_value_for_variation(self, variable, variation): """ Get the variable value for the given variation. Args: variable: The Variable for which we are getting the value. variation: The Variation for which we are getting the variable value. Returns: The variable value or None ...
python
def get_variable_value_for_variation(self, variable, variation): """ Get the variable value for the given variation. Args: variable: The Variable for which we are getting the value. variation: The Variation for which we are getting the variable value. Returns: The variable value or None ...
[ "def", "get_variable_value_for_variation", "(", "self", ",", "variable", ",", "variation", ")", ":", "if", "not", "variable", "or", "not", "variation", ":", "return", "None", "if", "variation", ".", "id", "not", "in", "self", ".", "variation_variable_usage_map",...
Get the variable value for the given variation. Args: variable: The Variable for which we are getting the value. variation: The Variation for which we are getting the variable value. Returns: The variable value or None if any of the inputs are invalid.
[ "Get", "the", "variable", "value", "for", "the", "given", "variation", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/project_config.py#L434-L476
train
optimizely/python-sdk
optimizely/project_config.py
ProjectConfig.get_variable_for_feature
def get_variable_for_feature(self, feature_key, variable_key): """ Get the variable with the given variable key for the given feature. Args: feature_key: The key of the feature for which we are getting the variable. variable_key: The key of the variable we are getting. Returns: Variable ...
python
def get_variable_for_feature(self, feature_key, variable_key): """ Get the variable with the given variable key for the given feature. Args: feature_key: The key of the feature for which we are getting the variable. variable_key: The key of the variable we are getting. Returns: Variable ...
[ "def", "get_variable_for_feature", "(", "self", ",", "feature_key", ",", "variable_key", ")", ":", "feature", "=", "self", ".", "feature_key_map", ".", "get", "(", "feature_key", ")", "if", "not", "feature", ":", "self", ".", "logger", ".", "error", "(", "...
Get the variable with the given variable key for the given feature. Args: feature_key: The key of the feature for which we are getting the variable. variable_key: The key of the variable we are getting. Returns: Variable with the given key in the given variation.
[ "Get", "the", "variable", "with", "the", "given", "variable", "key", "for", "the", "given", "feature", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/project_config.py#L478-L497
train
optimizely/python-sdk
optimizely/project_config.py
ProjectConfig.set_forced_variation
def set_forced_variation(self, experiment_key, user_id, variation_key): """ Sets users to a map of experiments to forced variations. Args: experiment_key: Key for experiment. user_id: The user ID. variation_key: Key for variation. If None, then clear the existing experiment-to-variati...
python
def set_forced_variation(self, experiment_key, user_id, variation_key): """ Sets users to a map of experiments to forced variations. Args: experiment_key: Key for experiment. user_id: The user ID. variation_key: Key for variation. If None, then clear the existing experiment-to-variati...
[ "def", "set_forced_variation", "(", "self", ",", "experiment_key", ",", "user_id", ",", "variation_key", ")", ":", "experiment", "=", "self", ".", "get_experiment_from_key", "(", "experiment_key", ")", "if", "not", "experiment", ":", "# The invalid experiment key will...
Sets users to a map of experiments to forced variations. Args: experiment_key: Key for experiment. user_id: The user ID. variation_key: Key for variation. If None, then clear the existing experiment-to-variation mapping. Returns: A boolean value that indicates if the set co...
[ "Sets", "users", "to", "a", "map", "of", "experiments", "to", "forced", "variations", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/project_config.py#L499-L555
train
optimizely/python-sdk
optimizely/project_config.py
ProjectConfig.get_forced_variation
def get_forced_variation(self, experiment_key, user_id): """ Gets the forced variation key for the given user and experiment. Args: experiment_key: Key for experiment. user_id: The user ID. Returns: The variation which the given user and experiment should be forced into. ""...
python
def get_forced_variation(self, experiment_key, user_id): """ Gets the forced variation key for the given user and experiment. Args: experiment_key: Key for experiment. user_id: The user ID. Returns: The variation which the given user and experiment should be forced into. ""...
[ "def", "get_forced_variation", "(", "self", ",", "experiment_key", ",", "user_id", ")", ":", "if", "user_id", "not", "in", "self", ".", "forced_variation_map", ":", "self", ".", "logger", ".", "debug", "(", "'User \"%s\" is not in the forced variation map.'", "%", ...
Gets the forced variation key for the given user and experiment. Args: experiment_key: Key for experiment. user_id: The user ID. Returns: The variation which the given user and experiment should be forced into.
[ "Gets", "the", "forced", "variation", "key", "for", "the", "given", "user", "and", "experiment", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/project_config.py#L557-L600
train
optimizely/python-sdk
optimizely/event_dispatcher.py
EventDispatcher.dispatch_event
def dispatch_event(event): """ Dispatch the event being represented by the Event object. Args: event: Object holding information about the request to be dispatched to the Optimizely backend. """ try: if event.http_verb == enums.HTTPVerbs.GET: requests.get(event.url, params=event.pa...
python
def dispatch_event(event): """ Dispatch the event being represented by the Event object. Args: event: Object holding information about the request to be dispatched to the Optimizely backend. """ try: if event.http_verb == enums.HTTPVerbs.GET: requests.get(event.url, params=event.pa...
[ "def", "dispatch_event", "(", "event", ")", ":", "try", ":", "if", "event", ".", "http_verb", "==", "enums", ".", "HTTPVerbs", ".", "GET", ":", "requests", ".", "get", "(", "event", ".", "url", ",", "params", "=", "event", ".", "params", ",", "timeou...
Dispatch the event being represented by the Event object. Args: event: Object holding information about the request to be dispatched to the Optimizely backend.
[ "Dispatch", "the", "event", "being", "represented", "by", "the", "Event", "object", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/event_dispatcher.py#L28-L44
train
optimizely/python-sdk
optimizely/optimizely.py
Optimizely._validate_instantiation_options
def _validate_instantiation_options(self, datafile, skip_json_validation): """ Helper method to validate all instantiation parameters. Args: datafile: JSON string representing the project. skip_json_validation: Boolean representing whether JSON schema validation needs to be skipped or not. Rai...
python
def _validate_instantiation_options(self, datafile, skip_json_validation): """ Helper method to validate all instantiation parameters. Args: datafile: JSON string representing the project. skip_json_validation: Boolean representing whether JSON schema validation needs to be skipped or not. Rai...
[ "def", "_validate_instantiation_options", "(", "self", ",", "datafile", ",", "skip_json_validation", ")", ":", "if", "not", "skip_json_validation", "and", "not", "validator", ".", "is_datafile_valid", "(", "datafile", ")", ":", "raise", "exceptions", ".", "InvalidIn...
Helper method to validate all instantiation parameters. Args: datafile: JSON string representing the project. skip_json_validation: Boolean representing whether JSON schema validation needs to be skipped or not. Raises: Exception if provided instantiation options are valid.
[ "Helper", "method", "to", "validate", "all", "instantiation", "parameters", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/optimizely.py#L89-L110
train
optimizely/python-sdk
optimizely/optimizely.py
Optimizely._validate_user_inputs
def _validate_user_inputs(self, attributes=None, event_tags=None): """ Helper method to validate user inputs. Args: attributes: Dict representing user attributes. event_tags: Dict representing metadata associated with an event. Returns: Boolean True if inputs are valid. False otherwise. ...
python
def _validate_user_inputs(self, attributes=None, event_tags=None): """ Helper method to validate user inputs. Args: attributes: Dict representing user attributes. event_tags: Dict representing metadata associated with an event. Returns: Boolean True if inputs are valid. False otherwise. ...
[ "def", "_validate_user_inputs", "(", "self", ",", "attributes", "=", "None", ",", "event_tags", "=", "None", ")", ":", "if", "attributes", "and", "not", "validator", ".", "are_attributes_valid", "(", "attributes", ")", ":", "self", ".", "logger", ".", "error...
Helper method to validate user inputs. Args: attributes: Dict representing user attributes. event_tags: Dict representing metadata associated with an event. Returns: Boolean True if inputs are valid. False otherwise.
[ "Helper", "method", "to", "validate", "user", "inputs", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/optimizely.py#L112-L134
train
optimizely/python-sdk
optimizely/optimizely.py
Optimizely._send_impression_event
def _send_impression_event(self, experiment, variation, user_id, attributes): """ Helper method to send impression event. Args: experiment: Experiment for which impression event is being sent. variation: Variation picked for user for the given experiment. user_id: ID for user. attribute...
python
def _send_impression_event(self, experiment, variation, user_id, attributes): """ Helper method to send impression event. Args: experiment: Experiment for which impression event is being sent. variation: Variation picked for user for the given experiment. user_id: ID for user. attribute...
[ "def", "_send_impression_event", "(", "self", ",", "experiment", ",", "variation", ",", "user_id", ",", "attributes", ")", ":", "impression_event", "=", "self", ".", "event_builder", ".", "create_impression_event", "(", "experiment", ",", "variation", ".", "id", ...
Helper method to send impression event. Args: experiment: Experiment for which impression event is being sent. variation: Variation picked for user for the given experiment. user_id: ID for user. attributes: Dict representing user attributes and values which need to be recorded.
[ "Helper", "method", "to", "send", "impression", "event", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/optimizely.py#L136-L162
train
optimizely/python-sdk
optimizely/optimizely.py
Optimizely._get_feature_variable_for_type
def _get_feature_variable_for_type(self, feature_key, variable_key, variable_type, user_id, attributes): """ Helper method to determine value for a certain variable attached to a feature flag based on type of variable. Args: feature_key: Key of the feature whose variable's value is being accessed. ...
python
def _get_feature_variable_for_type(self, feature_key, variable_key, variable_type, user_id, attributes): """ Helper method to determine value for a certain variable attached to a feature flag based on type of variable. Args: feature_key: Key of the feature whose variable's value is being accessed. ...
[ "def", "_get_feature_variable_for_type", "(", "self", ",", "feature_key", ",", "variable_key", ",", "variable_type", ",", "user_id", ",", "attributes", ")", ":", "if", "not", "validator", ".", "is_non_empty_string", "(", "feature_key", ")", ":", "self", ".", "lo...
Helper method to determine value for a certain variable attached to a feature flag based on type of variable. Args: feature_key: Key of the feature whose variable's value is being accessed. variable_key: Key of the variable whose value is to be accessed. variable_type: Type of variable which coul...
[ "Helper", "method", "to", "determine", "value", "for", "a", "certain", "variable", "attached", "to", "a", "feature", "flag", "based", "on", "type", "of", "variable", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/optimizely.py#L164-L263
train
optimizely/python-sdk
optimizely/optimizely.py
Optimizely.activate
def activate(self, experiment_key, user_id, attributes=None): """ Buckets visitor and sends impression event to Optimizely. Args: experiment_key: Experiment which needs to be activated. user_id: ID for user. attributes: Dict representing user attributes and values which need to be recorded. ...
python
def activate(self, experiment_key, user_id, attributes=None): """ Buckets visitor and sends impression event to Optimizely. Args: experiment_key: Experiment which needs to be activated. user_id: ID for user. attributes: Dict representing user attributes and values which need to be recorded. ...
[ "def", "activate", "(", "self", ",", "experiment_key", ",", "user_id", ",", "attributes", "=", "None", ")", ":", "if", "not", "self", ".", "is_valid", ":", "self", ".", "logger", ".", "error", "(", "enums", ".", "Errors", ".", "INVALID_DATAFILE", ".", ...
Buckets visitor and sends impression event to Optimizely. Args: experiment_key: Experiment which needs to be activated. user_id: ID for user. attributes: Dict representing user attributes and values which need to be recorded. Returns: Variation key representing the variation the user w...
[ "Buckets", "visitor", "and", "sends", "impression", "event", "to", "Optimizely", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/optimizely.py#L265-L303
train
optimizely/python-sdk
optimizely/optimizely.py
Optimizely.track
def track(self, event_key, user_id, attributes=None, event_tags=None): """ Send conversion event to Optimizely. Args: event_key: Event key representing the event which needs to be recorded. user_id: ID for user. attributes: Dict representing visitor attributes and values which need to be reco...
python
def track(self, event_key, user_id, attributes=None, event_tags=None): """ Send conversion event to Optimizely. Args: event_key: Event key representing the event which needs to be recorded. user_id: ID for user. attributes: Dict representing visitor attributes and values which need to be reco...
[ "def", "track", "(", "self", ",", "event_key", ",", "user_id", ",", "attributes", "=", "None", ",", "event_tags", "=", "None", ")", ":", "if", "not", "self", ".", "is_valid", ":", "self", ".", "logger", ".", "error", "(", "enums", ".", "Errors", ".",...
Send conversion event to Optimizely. Args: event_key: Event key representing the event which needs to be recorded. user_id: ID for user. attributes: Dict representing visitor attributes and values which need to be recorded. event_tags: Dict representing metadata associated with the event.
[ "Send", "conversion", "event", "to", "Optimizely", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/optimizely.py#L305-L346
train
optimizely/python-sdk
optimizely/optimizely.py
Optimizely.get_variation
def get_variation(self, experiment_key, user_id, attributes=None): """ Gets variation where user will be bucketed. Args: experiment_key: Experiment for which user variation needs to be determined. user_id: ID for user. attributes: Dict representing user attributes. Returns: Variati...
python
def get_variation(self, experiment_key, user_id, attributes=None): """ Gets variation where user will be bucketed. Args: experiment_key: Experiment for which user variation needs to be determined. user_id: ID for user. attributes: Dict representing user attributes. Returns: Variati...
[ "def", "get_variation", "(", "self", ",", "experiment_key", ",", "user_id", ",", "attributes", "=", "None", ")", ":", "if", "not", "self", ".", "is_valid", ":", "self", ".", "logger", ".", "error", "(", "enums", ".", "Errors", ".", "INVALID_DATAFILE", "....
Gets variation where user will be bucketed. Args: experiment_key: Experiment for which user variation needs to be determined. user_id: ID for user. attributes: Dict representing user attributes. Returns: Variation key representing the variation the user will be bucketed in. None ...
[ "Gets", "variation", "where", "user", "will", "be", "bucketed", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/optimizely.py#L348-L406
train
optimizely/python-sdk
optimizely/optimizely.py
Optimizely.is_feature_enabled
def is_feature_enabled(self, feature_key, user_id, attributes=None): """ Returns true if the feature is enabled for the given user. Args: feature_key: The key of the feature for which we are determining if it is enabled or not for the given user. user_id: ID for user. attributes: Dict represe...
python
def is_feature_enabled(self, feature_key, user_id, attributes=None): """ Returns true if the feature is enabled for the given user. Args: feature_key: The key of the feature for which we are determining if it is enabled or not for the given user. user_id: ID for user. attributes: Dict represe...
[ "def", "is_feature_enabled", "(", "self", ",", "feature_key", ",", "user_id", ",", "attributes", "=", "None", ")", ":", "if", "not", "self", ".", "is_valid", ":", "self", ".", "logger", ".", "error", "(", "enums", ".", "Errors", ".", "INVALID_DATAFILE", ...
Returns true if the feature is enabled for the given user. Args: feature_key: The key of the feature for which we are determining if it is enabled or not for the given user. user_id: ID for user. attributes: Dict representing user attributes. Returns: True if the feature is enabled for...
[ "Returns", "true", "if", "the", "feature", "is", "enabled", "for", "the", "given", "user", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/optimizely.py#L408-L476
train
optimizely/python-sdk
optimizely/optimizely.py
Optimizely.get_enabled_features
def get_enabled_features(self, user_id, attributes=None): """ Returns the list of features that are enabled for the user. Args: user_id: ID for user. attributes: Dict representing user attributes. Returns: A list of the keys of the features that are enabled for the user. """ ena...
python
def get_enabled_features(self, user_id, attributes=None): """ Returns the list of features that are enabled for the user. Args: user_id: ID for user. attributes: Dict representing user attributes. Returns: A list of the keys of the features that are enabled for the user. """ ena...
[ "def", "get_enabled_features", "(", "self", ",", "user_id", ",", "attributes", "=", "None", ")", ":", "enabled_features", "=", "[", "]", "if", "not", "self", ".", "is_valid", ":", "self", ".", "logger", ".", "error", "(", "enums", ".", "Errors", ".", "...
Returns the list of features that are enabled for the user. Args: user_id: ID for user. attributes: Dict representing user attributes. Returns: A list of the keys of the features that are enabled for the user.
[ "Returns", "the", "list", "of", "features", "that", "are", "enabled", "for", "the", "user", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/optimizely.py#L478-L505
train
optimizely/python-sdk
optimizely/optimizely.py
Optimizely.get_feature_variable_boolean
def get_feature_variable_boolean(self, feature_key, variable_key, user_id, attributes=None): """ Returns value for a certain boolean variable attached to a feature flag. Args: feature_key: Key of the feature whose variable's value is being accessed. variable_key: Key of the variable whose value is ...
python
def get_feature_variable_boolean(self, feature_key, variable_key, user_id, attributes=None): """ Returns value for a certain boolean variable attached to a feature flag. Args: feature_key: Key of the feature whose variable's value is being accessed. variable_key: Key of the variable whose value is ...
[ "def", "get_feature_variable_boolean", "(", "self", ",", "feature_key", ",", "variable_key", ",", "user_id", ",", "attributes", "=", "None", ")", ":", "variable_type", "=", "entities", ".", "Variable", ".", "Type", ".", "BOOLEAN", "return", "self", ".", "_get_...
Returns value for a certain boolean variable attached to a feature flag. Args: feature_key: Key of the feature whose variable's value is being accessed. variable_key: Key of the variable whose value is to be accessed. user_id: ID for user. attributes: Dict representing user attributes. ...
[ "Returns", "value", "for", "a", "certain", "boolean", "variable", "attached", "to", "a", "feature", "flag", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/optimizely.py#L507-L524
train
optimizely/python-sdk
optimizely/optimizely.py
Optimizely.get_feature_variable_double
def get_feature_variable_double(self, feature_key, variable_key, user_id, attributes=None): """ Returns value for a certain double variable attached to a feature flag. Args: feature_key: Key of the feature whose variable's value is being accessed. variable_key: Key of the variable whose value is to...
python
def get_feature_variable_double(self, feature_key, variable_key, user_id, attributes=None): """ Returns value for a certain double variable attached to a feature flag. Args: feature_key: Key of the feature whose variable's value is being accessed. variable_key: Key of the variable whose value is to...
[ "def", "get_feature_variable_double", "(", "self", ",", "feature_key", ",", "variable_key", ",", "user_id", ",", "attributes", "=", "None", ")", ":", "variable_type", "=", "entities", ".", "Variable", ".", "Type", ".", "DOUBLE", "return", "self", ".", "_get_fe...
Returns value for a certain double variable attached to a feature flag. Args: feature_key: Key of the feature whose variable's value is being accessed. variable_key: Key of the variable whose value is to be accessed. user_id: ID for user. attributes: Dict representing user attributes. ...
[ "Returns", "value", "for", "a", "certain", "double", "variable", "attached", "to", "a", "feature", "flag", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/optimizely.py#L526-L543
train
optimizely/python-sdk
optimizely/optimizely.py
Optimizely.get_feature_variable_integer
def get_feature_variable_integer(self, feature_key, variable_key, user_id, attributes=None): """ Returns value for a certain integer variable attached to a feature flag. Args: feature_key: Key of the feature whose variable's value is being accessed. variable_key: Key of the variable whose value is ...
python
def get_feature_variable_integer(self, feature_key, variable_key, user_id, attributes=None): """ Returns value for a certain integer variable attached to a feature flag. Args: feature_key: Key of the feature whose variable's value is being accessed. variable_key: Key of the variable whose value is ...
[ "def", "get_feature_variable_integer", "(", "self", ",", "feature_key", ",", "variable_key", ",", "user_id", ",", "attributes", "=", "None", ")", ":", "variable_type", "=", "entities", ".", "Variable", ".", "Type", ".", "INTEGER", "return", "self", ".", "_get_...
Returns value for a certain integer variable attached to a feature flag. Args: feature_key: Key of the feature whose variable's value is being accessed. variable_key: Key of the variable whose value is to be accessed. user_id: ID for user. attributes: Dict representing user attributes. ...
[ "Returns", "value", "for", "a", "certain", "integer", "variable", "attached", "to", "a", "feature", "flag", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/optimizely.py#L545-L562
train
optimizely/python-sdk
optimizely/optimizely.py
Optimizely.get_feature_variable_string
def get_feature_variable_string(self, feature_key, variable_key, user_id, attributes=None): """ Returns value for a certain string variable attached to a feature. Args: feature_key: Key of the feature whose variable's value is being accessed. variable_key: Key of the variable whose value is to be a...
python
def get_feature_variable_string(self, feature_key, variable_key, user_id, attributes=None): """ Returns value for a certain string variable attached to a feature. Args: feature_key: Key of the feature whose variable's value is being accessed. variable_key: Key of the variable whose value is to be a...
[ "def", "get_feature_variable_string", "(", "self", ",", "feature_key", ",", "variable_key", ",", "user_id", ",", "attributes", "=", "None", ")", ":", "variable_type", "=", "entities", ".", "Variable", ".", "Type", ".", "STRING", "return", "self", ".", "_get_fe...
Returns value for a certain string variable attached to a feature. Args: feature_key: Key of the feature whose variable's value is being accessed. variable_key: Key of the variable whose value is to be accessed. user_id: ID for user. attributes: Dict representing user attributes. Retur...
[ "Returns", "value", "for", "a", "certain", "string", "variable", "attached", "to", "a", "feature", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/optimizely.py#L564-L581
train
optimizely/python-sdk
optimizely/optimizely.py
Optimizely.set_forced_variation
def set_forced_variation(self, experiment_key, user_id, variation_key): """ Force a user into a variation for a given experiment. Args: experiment_key: A string key identifying the experiment. user_id: The user ID. variation_key: A string variation key that specifies the variation which the user...
python
def set_forced_variation(self, experiment_key, user_id, variation_key): """ Force a user into a variation for a given experiment. Args: experiment_key: A string key identifying the experiment. user_id: The user ID. variation_key: A string variation key that specifies the variation which the user...
[ "def", "set_forced_variation", "(", "self", ",", "experiment_key", ",", "user_id", ",", "variation_key", ")", ":", "if", "not", "self", ".", "is_valid", ":", "self", ".", "logger", ".", "error", "(", "enums", ".", "Errors", ".", "INVALID_DATAFILE", ".", "f...
Force a user into a variation for a given experiment. Args: experiment_key: A string key identifying the experiment. user_id: The user ID. variation_key: A string variation key that specifies the variation which the user. will be forced into. If null, then clear the existing experiment-to-varia...
[ "Force", "a", "user", "into", "a", "variation", "for", "a", "given", "experiment", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/optimizely.py#L583-L608
train
optimizely/python-sdk
optimizely/optimizely.py
Optimizely.get_forced_variation
def get_forced_variation(self, experiment_key, user_id): """ Gets the forced variation for a given user and experiment. Args: experiment_key: A string key identifying the experiment. user_id: The user ID. Returns: The forced variation key. None if no forced variation key. """ if...
python
def get_forced_variation(self, experiment_key, user_id): """ Gets the forced variation for a given user and experiment. Args: experiment_key: A string key identifying the experiment. user_id: The user ID. Returns: The forced variation key. None if no forced variation key. """ if...
[ "def", "get_forced_variation", "(", "self", ",", "experiment_key", ",", "user_id", ")", ":", "if", "not", "self", ".", "is_valid", ":", "self", ".", "logger", ".", "error", "(", "enums", ".", "Errors", ".", "INVALID_DATAFILE", ".", "format", "(", "'get_for...
Gets the forced variation for a given user and experiment. Args: experiment_key: A string key identifying the experiment. user_id: The user ID. Returns: The forced variation key. None if no forced variation key.
[ "Gets", "the", "forced", "variation", "for", "a", "given", "user", "and", "experiment", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/optimizely.py#L610-L634
train
optimizely/python-sdk
optimizely/helpers/audience.py
is_user_in_experiment
def is_user_in_experiment(config, experiment, attributes, logger): """ Determine for given experiment if user satisfies the audiences for the experiment. Args: config: project_config.ProjectConfig object representing the project. experiment: Object representing the experiment. attributes: Dict represen...
python
def is_user_in_experiment(config, experiment, attributes, logger): """ Determine for given experiment if user satisfies the audiences for the experiment. Args: config: project_config.ProjectConfig object representing the project. experiment: Object representing the experiment. attributes: Dict represen...
[ "def", "is_user_in_experiment", "(", "config", ",", "experiment", ",", "attributes", ",", "logger", ")", ":", "audience_conditions", "=", "experiment", ".", "getAudienceConditionsOrIds", "(", ")", "logger", ".", "debug", "(", "audience_logs", ".", "EVALUATING_AUDIEN...
Determine for given experiment if user satisfies the audiences for the experiment. Args: config: project_config.ProjectConfig object representing the project. experiment: Object representing the experiment. attributes: Dict representing user attributes which will be used in determining if...
[ "Determine", "for", "given", "experiment", "if", "user", "satisfies", "the", "audiences", "for", "the", "experiment", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/helpers/audience.py#L21-L91
train
optimizely/python-sdk
optimizely/event_builder.py
BaseEventBuilder._get_common_params
def _get_common_params(self, user_id, attributes): """ Get params which are used same in both conversion and impression events. Args: user_id: ID for user. attributes: Dict representing user attributes and values which need to be recorded. Returns: Dict consisting of parameters common to ...
python
def _get_common_params(self, user_id, attributes): """ Get params which are used same in both conversion and impression events. Args: user_id: ID for user. attributes: Dict representing user attributes and values which need to be recorded. Returns: Dict consisting of parameters common to ...
[ "def", "_get_common_params", "(", "self", ",", "user_id", ",", "attributes", ")", ":", "commonParams", "=", "{", "}", "commonParams", "[", "self", ".", "EventParams", ".", "PROJECT_ID", "]", "=", "self", ".", "_get_project_id", "(", ")", "commonParams", "[",...
Get params which are used same in both conversion and impression events. Args: user_id: ID for user. attributes: Dict representing user attributes and values which need to be recorded. Returns: Dict consisting of parameters common to both impression and conversion events.
[ "Get", "params", "which", "are", "used", "same", "in", "both", "conversion", "and", "impression", "events", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/event_builder.py#L109-L138
train
optimizely/python-sdk
optimizely/event_builder.py
EventBuilder._get_required_params_for_impression
def _get_required_params_for_impression(self, experiment, variation_id): """ Get parameters that are required for the impression event to register. Args: experiment: Experiment for which impression needs to be recorded. variation_id: ID for variation which would be presented to user. Returns: ...
python
def _get_required_params_for_impression(self, experiment, variation_id): """ Get parameters that are required for the impression event to register. Args: experiment: Experiment for which impression needs to be recorded. variation_id: ID for variation which would be presented to user. Returns: ...
[ "def", "_get_required_params_for_impression", "(", "self", ",", "experiment", ",", "variation_id", ")", ":", "snapshot", "=", "{", "}", "snapshot", "[", "self", ".", "EventParams", ".", "DECISIONS", "]", "=", "[", "{", "self", ".", "EventParams", ".", "EXPER...
Get parameters that are required for the impression event to register. Args: experiment: Experiment for which impression needs to be recorded. variation_id: ID for variation which would be presented to user. Returns: Dict consisting of decisions and events info for impression event.
[ "Get", "parameters", "that", "are", "required", "for", "the", "impression", "event", "to", "register", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/event_builder.py#L211-L236
train
optimizely/python-sdk
optimizely/event_builder.py
EventBuilder._get_required_params_for_conversion
def _get_required_params_for_conversion(self, event_key, event_tags): """ Get parameters that are required for the conversion event to register. Args: event_key: Key representing the event which needs to be recorded. event_tags: Dict representing metadata associated with the event. Returns: ...
python
def _get_required_params_for_conversion(self, event_key, event_tags): """ Get parameters that are required for the conversion event to register. Args: event_key: Key representing the event which needs to be recorded. event_tags: Dict representing metadata associated with the event. Returns: ...
[ "def", "_get_required_params_for_conversion", "(", "self", ",", "event_key", ",", "event_tags", ")", ":", "snapshot", "=", "{", "}", "event_dict", "=", "{", "self", ".", "EventParams", ".", "EVENT_ID", ":", "self", ".", "config", ".", "get_event", "(", "even...
Get parameters that are required for the conversion event to register. Args: event_key: Key representing the event which needs to be recorded. event_tags: Dict representing metadata associated with the event. Returns: Dict consisting of the decisions and events info for conversion event.
[ "Get", "parameters", "that", "are", "required", "for", "the", "conversion", "event", "to", "register", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/event_builder.py#L238-L270
train
optimizely/python-sdk
optimizely/event_builder.py
EventBuilder.create_impression_event
def create_impression_event(self, experiment, variation_id, user_id, attributes): """ Create impression Event to be sent to the logging endpoint. Args: experiment: Experiment for which impression needs to be recorded. variation_id: ID for variation which would be presented to user. user_id: I...
python
def create_impression_event(self, experiment, variation_id, user_id, attributes): """ Create impression Event to be sent to the logging endpoint. Args: experiment: Experiment for which impression needs to be recorded. variation_id: ID for variation which would be presented to user. user_id: I...
[ "def", "create_impression_event", "(", "self", ",", "experiment", ",", "variation_id", ",", "user_id", ",", "attributes", ")", ":", "params", "=", "self", ".", "_get_common_params", "(", "user_id", ",", "attributes", ")", "impression_params", "=", "self", ".", ...
Create impression Event to be sent to the logging endpoint. Args: experiment: Experiment for which impression needs to be recorded. variation_id: ID for variation which would be presented to user. user_id: ID for user. attributes: Dict representing user attributes and values which need to b...
[ "Create", "impression", "Event", "to", "be", "sent", "to", "the", "logging", "endpoint", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/event_builder.py#L272-L293
train
optimizely/python-sdk
optimizely/event_builder.py
EventBuilder.create_conversion_event
def create_conversion_event(self, event_key, user_id, attributes, event_tags): """ Create conversion Event to be sent to the logging endpoint. Args: event_key: Key representing the event which needs to be recorded. user_id: ID for user. attributes: Dict representing user attributes and values...
python
def create_conversion_event(self, event_key, user_id, attributes, event_tags): """ Create conversion Event to be sent to the logging endpoint. Args: event_key: Key representing the event which needs to be recorded. user_id: ID for user. attributes: Dict representing user attributes and values...
[ "def", "create_conversion_event", "(", "self", ",", "event_key", ",", "user_id", ",", "attributes", ",", "event_tags", ")", ":", "params", "=", "self", ".", "_get_common_params", "(", "user_id", ",", "attributes", ")", "conversion_params", "=", "self", ".", "_...
Create conversion Event to be sent to the logging endpoint. Args: event_key: Key representing the event which needs to be recorded. user_id: ID for user. attributes: Dict representing user attributes and values. event_tags: Dict representing metadata associated with the event. Returns:...
[ "Create", "conversion", "Event", "to", "be", "sent", "to", "the", "logging", "endpoint", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/event_builder.py#L295-L315
train
optimizely/python-sdk
optimizely/helpers/condition.py
_audience_condition_deserializer
def _audience_condition_deserializer(obj_dict): """ Deserializer defining how dict objects need to be decoded for audience conditions. Args: obj_dict: Dict representing one audience condition. Returns: List consisting of condition key with corresponding value, type and match. """ return [ obj_di...
python
def _audience_condition_deserializer(obj_dict): """ Deserializer defining how dict objects need to be decoded for audience conditions. Args: obj_dict: Dict representing one audience condition. Returns: List consisting of condition key with corresponding value, type and match. """ return [ obj_di...
[ "def", "_audience_condition_deserializer", "(", "obj_dict", ")", ":", "return", "[", "obj_dict", ".", "get", "(", "'name'", ")", ",", "obj_dict", ".", "get", "(", "'value'", ")", ",", "obj_dict", ".", "get", "(", "'type'", ")", ",", "obj_dict", ".", "get...
Deserializer defining how dict objects need to be decoded for audience conditions. Args: obj_dict: Dict representing one audience condition. Returns: List consisting of condition key with corresponding value, type and match.
[ "Deserializer", "defining", "how", "dict", "objects", "need", "to", "be", "decoded", "for", "audience", "conditions", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/helpers/condition.py#L328-L342
train
optimizely/python-sdk
optimizely/helpers/condition.py
CustomAttributeConditionEvaluator._get_condition_json
def _get_condition_json(self, index): """ Method to generate json for logging audience condition. Args: index: Index of the condition. Returns: String: Audience condition JSON. """ condition = self.condition_data[index] condition_log = { 'name': condition[0], 'value': c...
python
def _get_condition_json(self, index): """ Method to generate json for logging audience condition. Args: index: Index of the condition. Returns: String: Audience condition JSON. """ condition = self.condition_data[index] condition_log = { 'name': condition[0], 'value': c...
[ "def", "_get_condition_json", "(", "self", ",", "index", ")", ":", "condition", "=", "self", ".", "condition_data", "[", "index", "]", "condition_log", "=", "{", "'name'", ":", "condition", "[", "0", "]", ",", "'value'", ":", "condition", "[", "1", "]", ...
Method to generate json for logging audience condition. Args: index: Index of the condition. Returns: String: Audience condition JSON.
[ "Method", "to", "generate", "json", "for", "logging", "audience", "condition", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/helpers/condition.py#L47-L64
train
optimizely/python-sdk
optimizely/helpers/condition.py
CustomAttributeConditionEvaluator.is_value_type_valid_for_exact_conditions
def is_value_type_valid_for_exact_conditions(self, value): """ Method to validate if the value is valid for exact match type evaluation. Args: value: Value to validate. Returns: Boolean: True if value is a string, boolean, or number. Otherwise False. """ # No need to check for bool sin...
python
def is_value_type_valid_for_exact_conditions(self, value): """ Method to validate if the value is valid for exact match type evaluation. Args: value: Value to validate. Returns: Boolean: True if value is a string, boolean, or number. Otherwise False. """ # No need to check for bool sin...
[ "def", "is_value_type_valid_for_exact_conditions", "(", "self", ",", "value", ")", ":", "# No need to check for bool since bool is a subclass of int", "if", "isinstance", "(", "value", ",", "string_types", ")", "or", "isinstance", "(", "value", ",", "(", "numbers", ".",...
Method to validate if the value is valid for exact match type evaluation. Args: value: Value to validate. Returns: Boolean: True if value is a string, boolean, or number. Otherwise False.
[ "Method", "to", "validate", "if", "the", "value", "is", "valid", "for", "exact", "match", "type", "evaluation", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/helpers/condition.py#L66-L79
train
optimizely/python-sdk
optimizely/helpers/condition.py
CustomAttributeConditionEvaluator.exists_evaluator
def exists_evaluator(self, index): """ Evaluate the given exists match condition for the user attributes. Args: index: Index of the condition to be evaluated. Returns: Boolean: True if the user attributes have a non-null value for the given condition, otherwise False. ...
python
def exists_evaluator(self, index): """ Evaluate the given exists match condition for the user attributes. Args: index: Index of the condition to be evaluated. Returns: Boolean: True if the user attributes have a non-null value for the given condition, otherwise False. ...
[ "def", "exists_evaluator", "(", "self", ",", "index", ")", ":", "attr_name", "=", "self", ".", "condition_data", "[", "index", "]", "[", "0", "]", "return", "self", ".", "attributes", ".", "get", "(", "attr_name", ")", "is", "not", "None" ]
Evaluate the given exists match condition for the user attributes. Args: index: Index of the condition to be evaluated. Returns: Boolean: True if the user attributes have a non-null value for the given condition, otherwise False.
[ "Evaluate", "the", "given", "exists", "match", "condition", "for", "the", "user", "attributes", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/helpers/condition.py#L131-L142
train
optimizely/python-sdk
optimizely/helpers/condition.py
CustomAttributeConditionEvaluator.greater_than_evaluator
def greater_than_evaluator(self, index): """ Evaluate the given greater than match condition for the user attributes. Args: index: Index of the condition to be evaluated. Returns: Boolean: - True if the user attribute value is greater than the condition value. - Fal...
python
def greater_than_evaluator(self, index): """ Evaluate the given greater than match condition for the user attributes. Args: index: Index of the condition to be evaluated. Returns: Boolean: - True if the user attribute value is greater than the condition value. - Fal...
[ "def", "greater_than_evaluator", "(", "self", ",", "index", ")", ":", "condition_name", "=", "self", ".", "condition_data", "[", "index", "]", "[", "0", "]", "condition_value", "=", "self", ".", "condition_data", "[", "index", "]", "[", "1", "]", "user_val...
Evaluate the given greater than match condition for the user attributes. Args: index: Index of the condition to be evaluated. Returns: Boolean: - True if the user attribute value is greater than the condition value. - False if the user attribute value is less than or eq...
[ "Evaluate", "the", "given", "greater", "than", "match", "condition", "for", "the", "user", "attributes", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/helpers/condition.py#L144-L181
train
optimizely/python-sdk
optimizely/helpers/condition.py
CustomAttributeConditionEvaluator.substring_evaluator
def substring_evaluator(self, index): """ Evaluate the given substring match condition for the given user attributes. Args: index: Index of the condition to be evaluated. Returns: Boolean: - True if the condition value is a substring of the user attribute value. - False if the ...
python
def substring_evaluator(self, index): """ Evaluate the given substring match condition for the given user attributes. Args: index: Index of the condition to be evaluated. Returns: Boolean: - True if the condition value is a substring of the user attribute value. - False if the ...
[ "def", "substring_evaluator", "(", "self", ",", "index", ")", ":", "condition_name", "=", "self", ".", "condition_data", "[", "index", "]", "[", "0", "]", "condition_value", "=", "self", ".", "condition_data", "[", "index", "]", "[", "1", "]", "user_value"...
Evaluate the given substring match condition for the given user attributes. Args: index: Index of the condition to be evaluated. Returns: Boolean: - True if the condition value is a substring of the user attribute value. - False if the condition value is not a substring of the user...
[ "Evaluate", "the", "given", "substring", "match", "condition", "for", "the", "given", "user", "attributes", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/helpers/condition.py#L222-L252
train
optimizely/python-sdk
optimizely/helpers/condition.py
CustomAttributeConditionEvaluator.evaluate
def evaluate(self, index): """ Given a custom attribute audience condition and user attributes, evaluate the condition against the attributes. Args: index: Index of the condition to be evaluated. Returns: Boolean: - True if the user attributes match the given condition. ...
python
def evaluate(self, index): """ Given a custom attribute audience condition and user attributes, evaluate the condition against the attributes. Args: index: Index of the condition to be evaluated. Returns: Boolean: - True if the user attributes match the given condition. ...
[ "def", "evaluate", "(", "self", ",", "index", ")", ":", "if", "self", ".", "condition_data", "[", "index", "]", "[", "2", "]", "!=", "self", ".", "CUSTOM_ATTRIBUTE_CONDITION_TYPE", ":", "self", ".", "logger", ".", "warning", "(", "audience_logs", ".", "U...
Given a custom attribute audience condition and user attributes, evaluate the condition against the attributes. Args: index: Index of the condition to be evaluated. Returns: Boolean: - True if the user attributes match the given condition. - False if the user attributes don...
[ "Given", "a", "custom", "attribute", "audience", "condition", "and", "user", "attributes", "evaluate", "the", "condition", "against", "the", "attributes", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/helpers/condition.py#L262-L298
train
optimizely/python-sdk
optimizely/helpers/condition.py
ConditionDecoder.object_hook
def object_hook(self, object_dict): """ Hook which when passed into a json.JSONDecoder will replace each dict in a json string with its index and convert the dict to an object as defined by the passed in condition_decoder. The newly created condition object is appended to the conditions_list. Args:...
python
def object_hook(self, object_dict): """ Hook which when passed into a json.JSONDecoder will replace each dict in a json string with its index and convert the dict to an object as defined by the passed in condition_decoder. The newly created condition object is appended to the conditions_list. Args:...
[ "def", "object_hook", "(", "self", ",", "object_dict", ")", ":", "instance", "=", "self", ".", "decoder", "(", "object_dict", ")", "self", ".", "condition_list", ".", "append", "(", "instance", ")", "self", ".", "index", "+=", "1", "return", "self", ".",...
Hook which when passed into a json.JSONDecoder will replace each dict in a json string with its index and convert the dict to an object as defined by the passed in condition_decoder. The newly created condition object is appended to the conditions_list. Args: object_dict: Dict representing an obj...
[ "Hook", "which", "when", "passed", "into", "a", "json", ".", "JSONDecoder", "will", "replace", "each", "dict", "in", "a", "json", "string", "with", "its", "index", "and", "convert", "the", "dict", "to", "an", "object", "as", "defined", "by", "the", "pass...
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/helpers/condition.py#L310-L325
train
optimizely/python-sdk
optimizely/decision_service.py
DecisionService._get_bucketing_id
def _get_bucketing_id(self, user_id, attributes): """ Helper method to determine bucketing ID for the user. Args: user_id: ID for user. attributes: Dict representing user attributes. May consist of bucketing ID to be used. Returns: String representing bucketing ID if it is a String type ...
python
def _get_bucketing_id(self, user_id, attributes): """ Helper method to determine bucketing ID for the user. Args: user_id: ID for user. attributes: Dict representing user attributes. May consist of bucketing ID to be used. Returns: String representing bucketing ID if it is a String type ...
[ "def", "_get_bucketing_id", "(", "self", ",", "user_id", ",", "attributes", ")", ":", "attributes", "=", "attributes", "or", "{", "}", "bucketing_id", "=", "attributes", ".", "get", "(", "enums", ".", "ControlAttributes", ".", "BUCKETING_ID", ")", "if", "buc...
Helper method to determine bucketing ID for the user. Args: user_id: ID for user. attributes: Dict representing user attributes. May consist of bucketing ID to be used. Returns: String representing bucketing ID if it is a String type in attributes else return user ID.
[ "Helper", "method", "to", "determine", "bucketing", "ID", "for", "the", "user", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/decision_service.py#L36-L56
train
optimizely/python-sdk
optimizely/decision_service.py
DecisionService.get_forced_variation
def get_forced_variation(self, experiment, user_id): """ Determine if a user is forced into a variation for the given experiment and return that variation. Args: experiment: Object representing the experiment for which user is to be bucketed. user_id: ID for the user. Returns: Variation ...
python
def get_forced_variation(self, experiment, user_id): """ Determine if a user is forced into a variation for the given experiment and return that variation. Args: experiment: Object representing the experiment for which user is to be bucketed. user_id: ID for the user. Returns: Variation ...
[ "def", "get_forced_variation", "(", "self", ",", "experiment", ",", "user_id", ")", ":", "forced_variations", "=", "experiment", ".", "forcedVariations", "if", "forced_variations", "and", "user_id", "in", "forced_variations", ":", "variation_key", "=", "forced_variati...
Determine if a user is forced into a variation for the given experiment and return that variation. Args: experiment: Object representing the experiment for which user is to be bucketed. user_id: ID for the user. Returns: Variation in which the user with ID user_id is forced into. None if no ...
[ "Determine", "if", "a", "user", "is", "forced", "into", "a", "variation", "for", "the", "given", "experiment", "and", "return", "that", "variation", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/decision_service.py#L58-L77
train
optimizely/python-sdk
optimizely/decision_service.py
DecisionService.get_stored_variation
def get_stored_variation(self, experiment, user_profile): """ Determine if the user has a stored variation available for the given experiment and return that. Args: experiment: Object representing the experiment for which user is to be bucketed. user_profile: UserProfile object representing the use...
python
def get_stored_variation(self, experiment, user_profile): """ Determine if the user has a stored variation available for the given experiment and return that. Args: experiment: Object representing the experiment for which user is to be bucketed. user_profile: UserProfile object representing the use...
[ "def", "get_stored_variation", "(", "self", ",", "experiment", ",", "user_profile", ")", ":", "user_id", "=", "user_profile", ".", "user_id", "variation_id", "=", "user_profile", ".", "get_variation_for_experiment", "(", "experiment", ".", "id", ")", "if", "variat...
Determine if the user has a stored variation available for the given experiment and return that. Args: experiment: Object representing the experiment for which user is to be bucketed. user_profile: UserProfile object representing the user's profile. Returns: Variation if available. None othe...
[ "Determine", "if", "the", "user", "has", "a", "stored", "variation", "available", "for", "the", "given", "experiment", "and", "return", "that", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/decision_service.py#L79-L103
train
optimizely/python-sdk
optimizely/decision_service.py
DecisionService.get_variation
def get_variation(self, experiment, user_id, attributes, ignore_user_profile=False): """ Top-level function to help determine variation user should be put in. First, check if experiment is running. Second, check if user is forced in a variation. Third, check if there is a stored decision for the user a...
python
def get_variation(self, experiment, user_id, attributes, ignore_user_profile=False): """ Top-level function to help determine variation user should be put in. First, check if experiment is running. Second, check if user is forced in a variation. Third, check if there is a stored decision for the user a...
[ "def", "get_variation", "(", "self", ",", "experiment", ",", "user_id", ",", "attributes", ",", "ignore_user_profile", "=", "False", ")", ":", "# Check if experiment is running", "if", "not", "experiment_helper", ".", "is_experiment_running", "(", "experiment", ")", ...
Top-level function to help determine variation user should be put in. First, check if experiment is running. Second, check if user is forced in a variation. Third, check if there is a stored decision for the user and return the corresponding variation. Fourth, figure out if user is in the experiment by...
[ "Top", "-", "level", "function", "to", "help", "determine", "variation", "user", "should", "be", "put", "in", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/decision_service.py#L105-L178
train
optimizely/python-sdk
optimizely/decision_service.py
DecisionService.get_experiment_in_group
def get_experiment_in_group(self, group, bucketing_id): """ Determine which experiment in the group the user is bucketed into. Args: group: The group to bucket the user into. bucketing_id: ID to be used for bucketing the user. Returns: Experiment if the user is bucketed into an experimen...
python
def get_experiment_in_group(self, group, bucketing_id): """ Determine which experiment in the group the user is bucketed into. Args: group: The group to bucket the user into. bucketing_id: ID to be used for bucketing the user. Returns: Experiment if the user is bucketed into an experimen...
[ "def", "get_experiment_in_group", "(", "self", ",", "group", ",", "bucketing_id", ")", ":", "experiment_id", "=", "self", ".", "bucketer", ".", "find_bucket", "(", "bucketing_id", ",", "group", ".", "id", ",", "group", ".", "trafficAllocation", ")", "if", "e...
Determine which experiment in the group the user is bucketed into. Args: group: The group to bucket the user into. bucketing_id: ID to be used for bucketing the user. Returns: Experiment if the user is bucketed into an experiment in the specified group. None otherwise.
[ "Determine", "which", "experiment", "in", "the", "group", "the", "user", "is", "bucketed", "into", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/decision_service.py#L238-L265
train
optimizely/python-sdk
optimizely/notification_center.py
NotificationCenter.add_notification_listener
def add_notification_listener(self, notification_type, notification_callback): """ Add a notification callback to the notification center. Args: notification_type: A string representing the notification type from .helpers.enums.NotificationTypes notification_callback: closure of function to call wh...
python
def add_notification_listener(self, notification_type, notification_callback): """ Add a notification callback to the notification center. Args: notification_type: A string representing the notification type from .helpers.enums.NotificationTypes notification_callback: closure of function to call wh...
[ "def", "add_notification_listener", "(", "self", ",", "notification_type", ",", "notification_callback", ")", ":", "if", "notification_type", "not", "in", "self", ".", "notifications", ":", "self", ".", "notifications", "[", "notification_type", "]", "=", "[", "("...
Add a notification callback to the notification center. Args: notification_type: A string representing the notification type from .helpers.enums.NotificationTypes notification_callback: closure of function to call when event is triggered. Returns: Integer notification id used to remove the n...
[ "Add", "a", "notification", "callback", "to", "the", "notification", "center", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/notification_center.py#L29-L53
train
optimizely/python-sdk
optimizely/notification_center.py
NotificationCenter.remove_notification_listener
def remove_notification_listener(self, notification_id): """ Remove a previously added notification callback. Args: notification_id: The numeric id passed back from add_notification_listener Returns: The function returns boolean true if found and removed, false otherwise. """ for v in...
python
def remove_notification_listener(self, notification_id): """ Remove a previously added notification callback. Args: notification_id: The numeric id passed back from add_notification_listener Returns: The function returns boolean true if found and removed, false otherwise. """ for v in...
[ "def", "remove_notification_listener", "(", "self", ",", "notification_id", ")", ":", "for", "v", "in", "self", ".", "notifications", ".", "values", "(", ")", ":", "toRemove", "=", "list", "(", "filter", "(", "lambda", "tup", ":", "tup", "[", "0", "]", ...
Remove a previously added notification callback. Args: notification_id: The numeric id passed back from add_notification_listener Returns: The function returns boolean true if found and removed, false otherwise.
[ "Remove", "a", "previously", "added", "notification", "callback", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/notification_center.py#L55-L71
train
optimizely/python-sdk
optimizely/notification_center.py
NotificationCenter.send_notifications
def send_notifications(self, notification_type, *args): """ Fires off the notification for the specific event. Uses var args to pass in a arbitrary list of parameter according to which notification type was fired. Args: notification_type: Type of notification to fire (String from .helpers.enums....
python
def send_notifications(self, notification_type, *args): """ Fires off the notification for the specific event. Uses var args to pass in a arbitrary list of parameter according to which notification type was fired. Args: notification_type: Type of notification to fire (String from .helpers.enums....
[ "def", "send_notifications", "(", "self", ",", "notification_type", ",", "*", "args", ")", ":", "if", "notification_type", "in", "self", ".", "notifications", ":", "for", "notification_id", ",", "callback", "in", "self", ".", "notifications", "[", "notification_...
Fires off the notification for the specific event. Uses var args to pass in a arbitrary list of parameter according to which notification type was fired. Args: notification_type: Type of notification to fire (String from .helpers.enums.NotificationTypes) args: variable list of arguments to the...
[ "Fires", "off", "the", "notification", "for", "the", "specific", "event", ".", "Uses", "var", "args", "to", "pass", "in", "a", "arbitrary", "list", "of", "parameter", "according", "to", "which", "notification", "type", "was", "fired", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/notification_center.py#L87-L101
train
optimizely/python-sdk
optimizely/helpers/condition_tree_evaluator.py
and_evaluator
def and_evaluator(conditions, leaf_evaluator): """ Evaluates a list of conditions as if the evaluator had been applied to each entry and the results AND-ed together. Args: conditions: List of conditions ex: [operand_1, operand_2]. leaf_evaluator: Function which will be called to evaluate leaf condition v...
python
def and_evaluator(conditions, leaf_evaluator): """ Evaluates a list of conditions as if the evaluator had been applied to each entry and the results AND-ed together. Args: conditions: List of conditions ex: [operand_1, operand_2]. leaf_evaluator: Function which will be called to evaluate leaf condition v...
[ "def", "and_evaluator", "(", "conditions", ",", "leaf_evaluator", ")", ":", "saw_null_result", "=", "False", "for", "condition", "in", "conditions", ":", "result", "=", "evaluate", "(", "condition", ",", "leaf_evaluator", ")", "if", "result", "is", "False", ":...
Evaluates a list of conditions as if the evaluator had been applied to each entry and the results AND-ed together. Args: conditions: List of conditions ex: [operand_1, operand_2]. leaf_evaluator: Function which will be called to evaluate leaf condition values. Returns: Boolean: - True if all o...
[ "Evaluates", "a", "list", "of", "conditions", "as", "if", "the", "evaluator", "had", "been", "applied", "to", "each", "entry", "and", "the", "results", "AND", "-", "ed", "together", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/helpers/condition_tree_evaluator.py#L17-L40
train
optimizely/python-sdk
optimizely/helpers/condition_tree_evaluator.py
not_evaluator
def not_evaluator(conditions, leaf_evaluator): """ Evaluates a list of conditions as if the evaluator had been applied to a single entry and NOT was applied to the result. Args: conditions: List of conditions ex: [operand_1, operand_2]. leaf_evaluator: Function which will be called to evaluate leaf condi...
python
def not_evaluator(conditions, leaf_evaluator): """ Evaluates a list of conditions as if the evaluator had been applied to a single entry and NOT was applied to the result. Args: conditions: List of conditions ex: [operand_1, operand_2]. leaf_evaluator: Function which will be called to evaluate leaf condi...
[ "def", "not_evaluator", "(", "conditions", ",", "leaf_evaluator", ")", ":", "if", "not", "len", "(", "conditions", ")", ">", "0", ":", "return", "None", "result", "=", "evaluate", "(", "conditions", "[", "0", "]", ",", "leaf_evaluator", ")", "return", "N...
Evaluates a list of conditions as if the evaluator had been applied to a single entry and NOT was applied to the result. Args: conditions: List of conditions ex: [operand_1, operand_2]. leaf_evaluator: Function which will be called to evaluate leaf condition values. Returns: Boolean: - True if...
[ "Evaluates", "a", "list", "of", "conditions", "as", "if", "the", "evaluator", "had", "been", "applied", "to", "a", "single", "entry", "and", "NOT", "was", "applied", "to", "the", "result", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/helpers/condition_tree_evaluator.py#L69-L87
train
optimizely/python-sdk
optimizely/helpers/condition_tree_evaluator.py
evaluate
def evaluate(conditions, leaf_evaluator): """ Top level method to evaluate conditions. Args: conditions: Nested array of and/or conditions, or a single leaf condition value of any type. Example: ['and', '0', ['or', '1', '2']] leaf_evaluator: Function which will be called to evaluate leaf co...
python
def evaluate(conditions, leaf_evaluator): """ Top level method to evaluate conditions. Args: conditions: Nested array of and/or conditions, or a single leaf condition value of any type. Example: ['and', '0', ['or', '1', '2']] leaf_evaluator: Function which will be called to evaluate leaf co...
[ "def", "evaluate", "(", "conditions", ",", "leaf_evaluator", ")", ":", "if", "isinstance", "(", "conditions", ",", "list", ")", ":", "if", "conditions", "[", "0", "]", "in", "list", "(", "EVALUATORS_BY_OPERATOR_TYPE", ".", "keys", "(", ")", ")", ":", "re...
Top level method to evaluate conditions. Args: conditions: Nested array of and/or conditions, or a single leaf condition value of any type. Example: ['and', '0', ['or', '1', '2']] leaf_evaluator: Function which will be called to evaluate leaf condition values. Returns: Boolean: Result ...
[ "Top", "level", "method", "to", "evaluate", "conditions", "." ]
ec028d9efcf22498c3820f2650fa10f5c30bec90
https://github.com/optimizely/python-sdk/blob/ec028d9efcf22498c3820f2650fa10f5c30bec90/optimizely/helpers/condition_tree_evaluator.py#L97-L119
train
Parisson/TimeSide
timeside/core/analyzer.py
data_objet_class
def data_objet_class(data_mode='value', time_mode='framewise'): """ Factory function for Analyzer result """ classes_table = {('value', 'global'): GlobalValueObject, ('value', 'event'): EventValueObject, ('value', 'segment'): SegmentValueObject, ...
python
def data_objet_class(data_mode='value', time_mode='framewise'): """ Factory function for Analyzer result """ classes_table = {('value', 'global'): GlobalValueObject, ('value', 'event'): EventValueObject, ('value', 'segment'): SegmentValueObject, ...
[ "def", "data_objet_class", "(", "data_mode", "=", "'value'", ",", "time_mode", "=", "'framewise'", ")", ":", "classes_table", "=", "{", "(", "'value'", ",", "'global'", ")", ":", "GlobalValueObject", ",", "(", "'value'", ",", "'event'", ")", ":", "EventValue...
Factory function for Analyzer result
[ "Factory", "function", "for", "Analyzer", "result" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/core/analyzer.py#L511-L527
train
Parisson/TimeSide
timeside/core/analyzer.py
JSON_NumpyArrayEncoder
def JSON_NumpyArrayEncoder(obj): '''Define Specialize JSON encoder for numpy array''' if isinstance(obj, np.ndarray): return {'numpyArray': obj.tolist(), 'dtype': obj.dtype.__str__()} elif isinstance(obj, np.generic): return np.asscalar(obj) else: print type(obj) ...
python
def JSON_NumpyArrayEncoder(obj): '''Define Specialize JSON encoder for numpy array''' if isinstance(obj, np.ndarray): return {'numpyArray': obj.tolist(), 'dtype': obj.dtype.__str__()} elif isinstance(obj, np.generic): return np.asscalar(obj) else: print type(obj) ...
[ "def", "JSON_NumpyArrayEncoder", "(", "obj", ")", ":", "if", "isinstance", "(", "obj", ",", "np", ".", "ndarray", ")", ":", "return", "{", "'numpyArray'", ":", "obj", ".", "tolist", "(", ")", ",", "'dtype'", ":", "obj", ".", "dtype", ".", "__str__", ...
Define Specialize JSON encoder for numpy array
[ "Define", "Specialize", "JSON", "encoder", "for", "numpy", "array" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/core/analyzer.py#L1047-L1056
train
Parisson/TimeSide
timeside/core/analyzer.py
AnalyzerResult.render
def render(self): '''Render a matplotlib figure from the analyzer result Return the figure, use fig.show() to display if neeeded ''' fig, ax = plt.subplots() self.data_object._render_plot(ax) return fig
python
def render(self): '''Render a matplotlib figure from the analyzer result Return the figure, use fig.show() to display if neeeded ''' fig, ax = plt.subplots() self.data_object._render_plot(ax) return fig
[ "def", "render", "(", "self", ")", ":", "fig", ",", "ax", "=", "plt", ".", "subplots", "(", ")", "self", ".", "data_object", ".", "_render_plot", "(", "ax", ")", "return", "fig" ]
Render a matplotlib figure from the analyzer result Return the figure, use fig.show() to display if neeeded
[ "Render", "a", "matplotlib", "figure", "from", "the", "analyzer", "result" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/core/analyzer.py#L670-L678
train
Parisson/TimeSide
timeside/core/analyzer.py
Analyzer.new_result
def new_result(self, data_mode='value', time_mode='framewise'): ''' Create a new result Attributes ---------- data_object : MetadataObject id_metadata : MetadataObject audio_metadata : MetadataObject frame_metadata : MetadataObject label_metadata ...
python
def new_result(self, data_mode='value', time_mode='framewise'): ''' Create a new result Attributes ---------- data_object : MetadataObject id_metadata : MetadataObject audio_metadata : MetadataObject frame_metadata : MetadataObject label_metadata ...
[ "def", "new_result", "(", "self", ",", "data_mode", "=", "'value'", ",", "time_mode", "=", "'framewise'", ")", ":", "from", "datetime", "import", "datetime", "result", "=", "AnalyzerResult", "(", "data_mode", "=", "data_mode", ",", "time_mode", "=", "time_mode...
Create a new result Attributes ---------- data_object : MetadataObject id_metadata : MetadataObject audio_metadata : MetadataObject frame_metadata : MetadataObject label_metadata : MetadataObject parameters : dict
[ "Create", "a", "new", "result" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/core/analyzer.py#L1279-L1324
train
Parisson/TimeSide
timeside/core/preprocessors.py
downmix_to_mono
def downmix_to_mono(process_func): ''' Pre-processing decorator that downmixes frames from multi-channel to mono Downmix is achieved by averaging all channels >>> from timeside.core.preprocessors import downmix_to_mono >>> @downmix_to_mono ... def process(analyzer,frames,eod): ... prin...
python
def downmix_to_mono(process_func): ''' Pre-processing decorator that downmixes frames from multi-channel to mono Downmix is achieved by averaging all channels >>> from timeside.core.preprocessors import downmix_to_mono >>> @downmix_to_mono ... def process(analyzer,frames,eod): ... prin...
[ "def", "downmix_to_mono", "(", "process_func", ")", ":", "import", "functools", "@", "functools", ".", "wraps", "(", "process_func", ")", "def", "wrapper", "(", "analyzer", ",", "frames", ",", "eod", ")", ":", "# Pre-processing", "if", "frames", ".", "ndim",...
Pre-processing decorator that downmixes frames from multi-channel to mono Downmix is achieved by averaging all channels >>> from timeside.core.preprocessors import downmix_to_mono >>> @downmix_to_mono ... def process(analyzer,frames,eod): ... print 'Frames, eod inside process :' ... pr...
[ "Pre", "-", "processing", "decorator", "that", "downmixes", "frames", "from", "multi", "-", "channel", "to", "mono" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/core/preprocessors.py#L32-L77
train
Parisson/TimeSide
timeside/core/preprocessors.py
frames_adapter
def frames_adapter(process_func): ''' Pre-processing decorator that adapt frames to match input_blocksize and input_stepsize of the decorated analyzer >>> from timeside.core.preprocessors import frames_adapter >>> @frames_adapter ... def process(analyzer,frames,eod): ... analyzer.frames...
python
def frames_adapter(process_func): ''' Pre-processing decorator that adapt frames to match input_blocksize and input_stepsize of the decorated analyzer >>> from timeside.core.preprocessors import frames_adapter >>> @frames_adapter ... def process(analyzer,frames,eod): ... analyzer.frames...
[ "def", "frames_adapter", "(", "process_func", ")", ":", "import", "functools", "import", "numpy", "as", "np", "class", "framesBuffer", "(", "object", ")", ":", "def", "__init__", "(", "self", ",", "blocksize", ",", "stepsize", ")", ":", "self", ".", "block...
Pre-processing decorator that adapt frames to match input_blocksize and input_stepsize of the decorated analyzer >>> from timeside.core.preprocessors import frames_adapter >>> @frames_adapter ... def process(analyzer,frames,eod): ... analyzer.frames.append(frames) ... return frames, eod...
[ "Pre", "-", "processing", "decorator", "that", "adapt", "frames", "to", "match", "input_blocksize", "and", "input_stepsize", "of", "the", "decorated", "analyzer" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/core/preprocessors.py#L80-L190
train
Parisson/TimeSide
timeside/server/models.py
Item.get_uri
def get_uri(self): """Return the Item source""" if self.source_file and os.path.exists(self.source_file.path): return self.source_file.path elif self.source_url: return self.source_url return None
python
def get_uri(self): """Return the Item source""" if self.source_file and os.path.exists(self.source_file.path): return self.source_file.path elif self.source_url: return self.source_url return None
[ "def", "get_uri", "(", "self", ")", ":", "if", "self", ".", "source_file", "and", "os", ".", "path", ".", "exists", "(", "self", ".", "source_file", ".", "path", ")", ":", "return", "self", ".", "source_file", ".", "path", "elif", "self", ".", "sourc...
Return the Item source
[ "Return", "the", "Item", "source" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/server/models.py#L184-L190
train
Parisson/TimeSide
timeside/server/models.py
Item.get_audio_duration
def get_audio_duration(self): """ Return item audio duration """ decoder = timeside.core.get_processor('file_decoder')( uri=self.get_uri()) return decoder.uri_total_duration
python
def get_audio_duration(self): """ Return item audio duration """ decoder = timeside.core.get_processor('file_decoder')( uri=self.get_uri()) return decoder.uri_total_duration
[ "def", "get_audio_duration", "(", "self", ")", ":", "decoder", "=", "timeside", ".", "core", ".", "get_processor", "(", "'file_decoder'", ")", "(", "uri", "=", "self", ".", "get_uri", "(", ")", ")", "return", "decoder", ".", "uri_total_duration" ]
Return item audio duration
[ "Return", "item", "audio", "duration" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/server/models.py#L192-L198
train
Parisson/TimeSide
timeside/server/models.py
Item.get_results_path
def get_results_path(self): """ Return Item result path """ result_path = os.path.join(RESULTS_ROOT, self.uuid) if not os.path.exists(result_path): os.makedirs(result_path) return result_path
python
def get_results_path(self): """ Return Item result path """ result_path = os.path.join(RESULTS_ROOT, self.uuid) if not os.path.exists(result_path): os.makedirs(result_path) return result_path
[ "def", "get_results_path", "(", "self", ")", ":", "result_path", "=", "os", ".", "path", ".", "join", "(", "RESULTS_ROOT", ",", "self", ".", "uuid", ")", "if", "not", "os", ".", "path", ".", "exists", "(", "result_path", ")", ":", "os", ".", "makedir...
Return Item result path
[ "Return", "Item", "result", "path" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/server/models.py#L200-L207
train
Parisson/TimeSide
timeside/plugins/decoder/utils.py
get_uri
def get_uri(source): """ Check a media source as a valid file or uri and return the proper uri """ import gst src_info = source_info(source) if src_info['is_file']: # Is this a file? return get_uri(src_info['uri']) elif gst.uri_is_valid(source): # Is this a valid URI source for...
python
def get_uri(source): """ Check a media source as a valid file or uri and return the proper uri """ import gst src_info = source_info(source) if src_info['is_file']: # Is this a file? return get_uri(src_info['uri']) elif gst.uri_is_valid(source): # Is this a valid URI source for...
[ "def", "get_uri", "(", "source", ")", ":", "import", "gst", "src_info", "=", "source_info", "(", "source", ")", "if", "src_info", "[", "'is_file'", "]", ":", "# Is this a file?", "return", "get_uri", "(", "src_info", "[", "'uri'", "]", ")", "elif", "gst", ...
Check a media source as a valid file or uri and return the proper uri
[ "Check", "a", "media", "source", "as", "a", "valid", "file", "or", "uri", "and", "return", "the", "proper", "uri" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/plugins/decoder/utils.py#L100-L119
train
Parisson/TimeSide
timeside/plugins/decoder/utils.py
sha1sum_file
def sha1sum_file(filename): ''' Return the secure hash digest with sha1 algorithm for a given file >>> from timeside.core.tools.test_samples import samples >>> wav_file = samples["C4_scale.wav"] >>> print sha1sum_file(wav_file) a598e78d0b5c90da54a77e34c083abdcd38d42ba ''' import hashlib...
python
def sha1sum_file(filename): ''' Return the secure hash digest with sha1 algorithm for a given file >>> from timeside.core.tools.test_samples import samples >>> wav_file = samples["C4_scale.wav"] >>> print sha1sum_file(wav_file) a598e78d0b5c90da54a77e34c083abdcd38d42ba ''' import hashlib...
[ "def", "sha1sum_file", "(", "filename", ")", ":", "import", "hashlib", "import", "io", "sha1", "=", "hashlib", ".", "sha1", "(", ")", "chunk_size", "=", "sha1", ".", "block_size", "*", "io", ".", "DEFAULT_BUFFER_SIZE", "with", "open", "(", "filename", ",",...
Return the secure hash digest with sha1 algorithm for a given file >>> from timeside.core.tools.test_samples import samples >>> wav_file = samples["C4_scale.wav"] >>> print sha1sum_file(wav_file) a598e78d0b5c90da54a77e34c083abdcd38d42ba
[ "Return", "the", "secure", "hash", "digest", "with", "sha1", "algorithm", "for", "a", "given", "file" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/plugins/decoder/utils.py#L180-L198
train
Parisson/TimeSide
timeside/plugins/decoder/utils.py
sha1sum_url
def sha1sum_url(url): '''Return the secure hash digest with sha1 algorithm for a given url >>> url = "https://github.com/yomguy/timeside-samples/raw/master/samples/guitar.wav" >>> print sha1sum_url(url) 08301c3f9a8d60926f31e253825cc74263e52ad1 ''' import hashlib import urllib from cont...
python
def sha1sum_url(url): '''Return the secure hash digest with sha1 algorithm for a given url >>> url = "https://github.com/yomguy/timeside-samples/raw/master/samples/guitar.wav" >>> print sha1sum_url(url) 08301c3f9a8d60926f31e253825cc74263e52ad1 ''' import hashlib import urllib from cont...
[ "def", "sha1sum_url", "(", "url", ")", ":", "import", "hashlib", "import", "urllib", "from", "contextlib", "import", "closing", "sha1", "=", "hashlib", ".", "sha1", "(", ")", "chunk_size", "=", "sha1", ".", "block_size", "*", "8192", "max_file_size", "=", ...
Return the secure hash digest with sha1 algorithm for a given url >>> url = "https://github.com/yomguy/timeside-samples/raw/master/samples/guitar.wav" >>> print sha1sum_url(url) 08301c3f9a8d60926f31e253825cc74263e52ad1
[ "Return", "the", "secure", "hash", "digest", "with", "sha1", "algorithm", "for", "a", "given", "url" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/plugins/decoder/utils.py#L201-L226
train
Parisson/TimeSide
timeside/plugins/decoder/utils.py
sha1sum_numpy
def sha1sum_numpy(np_array): ''' Return the secure hash digest with sha1 algorithm for a numpy array ''' import hashlib return hashlib.sha1(np_array.view(np.uint8)).hexdigest()
python
def sha1sum_numpy(np_array): ''' Return the secure hash digest with sha1 algorithm for a numpy array ''' import hashlib return hashlib.sha1(np_array.view(np.uint8)).hexdigest()
[ "def", "sha1sum_numpy", "(", "np_array", ")", ":", "import", "hashlib", "return", "hashlib", ".", "sha1", "(", "np_array", ".", "view", "(", "np", ".", "uint8", ")", ")", ".", "hexdigest", "(", ")" ]
Return the secure hash digest with sha1 algorithm for a numpy array
[ "Return", "the", "secure", "hash", "digest", "with", "sha1", "algorithm", "for", "a", "numpy", "array" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/plugins/decoder/utils.py#L229-L234
train
Parisson/TimeSide
timeside/core/tools/package.py
import_module_with_exceptions
def import_module_with_exceptions(name, package=None): """Wrapper around importlib.import_module to import TimeSide subpackage and ignoring ImportError if Aubio, Yaafe and Vamp Host are not available""" from timeside.core import _WITH_AUBIO, _WITH_YAAFE, _WITH_VAMP if name.count('.server.'): #...
python
def import_module_with_exceptions(name, package=None): """Wrapper around importlib.import_module to import TimeSide subpackage and ignoring ImportError if Aubio, Yaafe and Vamp Host are not available""" from timeside.core import _WITH_AUBIO, _WITH_YAAFE, _WITH_VAMP if name.count('.server.'): #...
[ "def", "import_module_with_exceptions", "(", "name", ",", "package", "=", "None", ")", ":", "from", "timeside", ".", "core", "import", "_WITH_AUBIO", ",", "_WITH_YAAFE", ",", "_WITH_VAMP", "if", "name", ".", "count", "(", "'.server.'", ")", ":", "# TODO:", "...
Wrapper around importlib.import_module to import TimeSide subpackage and ignoring ImportError if Aubio, Yaafe and Vamp Host are not available
[ "Wrapper", "around", "importlib", ".", "import_module", "to", "import", "TimeSide", "subpackage", "and", "ignoring", "ImportError", "if", "Aubio", "Yaafe", "and", "Vamp", "Host", "are", "not", "available" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/core/tools/package.py#L50-L82
train
Parisson/TimeSide
timeside/core/tools/package.py
check_vamp
def check_vamp(): "Check Vamp host availability" try: from timeside.plugins.analyzer.externals import vamp_plugin except VampImportError: warnings.warn('Vamp host is not available', ImportWarning, stacklevel=2) _WITH_VAMP = False else: _WITH_VAMP = ...
python
def check_vamp(): "Check Vamp host availability" try: from timeside.plugins.analyzer.externals import vamp_plugin except VampImportError: warnings.warn('Vamp host is not available', ImportWarning, stacklevel=2) _WITH_VAMP = False else: _WITH_VAMP = ...
[ "def", "check_vamp", "(", ")", ":", "try", ":", "from", "timeside", ".", "plugins", ".", "analyzer", ".", "externals", "import", "vamp_plugin", "except", "VampImportError", ":", "warnings", ".", "warn", "(", "'Vamp host is not available'", ",", "ImportWarning", ...
Check Vamp host availability
[ "Check", "Vamp", "host", "availability" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/core/tools/package.py#L115-L128
train
Parisson/TimeSide
timeside/plugins/grapher/utils.py
im_watermark
def im_watermark(im, inputtext, font=None, color=None, opacity=.6, margin=(30, 30)): """imprints a PIL image with the indicated text in lower-right corner""" if im.mode != "RGBA": im = im.convert("RGBA") textlayer = Image.new("RGBA", im.size, (0, 0, 0, 0)) textdraw = ImageDraw.Draw(textlayer) ...
python
def im_watermark(im, inputtext, font=None, color=None, opacity=.6, margin=(30, 30)): """imprints a PIL image with the indicated text in lower-right corner""" if im.mode != "RGBA": im = im.convert("RGBA") textlayer = Image.new("RGBA", im.size, (0, 0, 0, 0)) textdraw = ImageDraw.Draw(textlayer) ...
[ "def", "im_watermark", "(", "im", ",", "inputtext", ",", "font", "=", "None", ",", "color", "=", "None", ",", "opacity", "=", ".6", ",", "margin", "=", "(", "30", ",", "30", ")", ")", ":", "if", "im", ".", "mode", "!=", "\"RGBA\"", ":", "im", "...
imprints a PIL image with the indicated text in lower-right corner
[ "imprints", "a", "PIL", "image", "with", "the", "indicated", "text", "in", "lower", "-", "right", "corner" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/plugins/grapher/utils.py#L168-L179
train
Parisson/TimeSide
timeside/plugins/analyzer/utils.py
nextpow2
def nextpow2(value): """Compute the nearest power of two greater or equal to the input value""" if value >= 1: return 2**np.ceil(np.log2(value)).astype(int) elif value > 0: return 1 elif value == 0: return 0 else: raise ValueError('Value must be positive')
python
def nextpow2(value): """Compute the nearest power of two greater or equal to the input value""" if value >= 1: return 2**np.ceil(np.log2(value)).astype(int) elif value > 0: return 1 elif value == 0: return 0 else: raise ValueError('Value must be positive')
[ "def", "nextpow2", "(", "value", ")", ":", "if", "value", ">=", "1", ":", "return", "2", "**", "np", ".", "ceil", "(", "np", ".", "log2", "(", "value", ")", ")", ".", "astype", "(", "int", ")", "elif", "value", ">", "0", ":", "return", "1", "...
Compute the nearest power of two greater or equal to the input value
[ "Compute", "the", "nearest", "power", "of", "two", "greater", "or", "equal", "to", "the", "input", "value" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/plugins/analyzer/utils.py#L65-L74
train
Parisson/TimeSide
timeside/core/processor.py
FixedSizeInputAdapter.blocksize
def blocksize(self, input_totalframes): """Return the total number of frames that this adapter will output according to the input_totalframes argument""" blocksize = input_totalframes if self.pad: mod = input_totalframes % self.buffer_size if mod: ...
python
def blocksize(self, input_totalframes): """Return the total number of frames that this adapter will output according to the input_totalframes argument""" blocksize = input_totalframes if self.pad: mod = input_totalframes % self.buffer_size if mod: ...
[ "def", "blocksize", "(", "self", ",", "input_totalframes", ")", ":", "blocksize", "=", "input_totalframes", "if", "self", ".", "pad", ":", "mod", "=", "input_totalframes", "%", "self", ".", "buffer_size", "if", "mod", ":", "blocksize", "+=", "self", ".", "...
Return the total number of frames that this adapter will output according to the input_totalframes argument
[ "Return", "the", "total", "number", "of", "frames", "that", "this", "adapter", "will", "output", "according", "to", "the", "input_totalframes", "argument" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/core/processor.py#L218-L228
train
Parisson/TimeSide
timeside/core/processor.py
ProcessPipe.append_processor
def append_processor(self, proc, source_proc=None): "Append a new processor to the pipe" if source_proc is None and len(self.processors): source_proc = self.processors[0] if source_proc and not isinstance(source_proc, Processor): raise TypeError('source_proc must be a Pr...
python
def append_processor(self, proc, source_proc=None): "Append a new processor to the pipe" if source_proc is None and len(self.processors): source_proc = self.processors[0] if source_proc and not isinstance(source_proc, Processor): raise TypeError('source_proc must be a Pr...
[ "def", "append_processor", "(", "self", ",", "proc", ",", "source_proc", "=", "None", ")", ":", "if", "source_proc", "is", "None", "and", "len", "(", "self", ".", "processors", ")", ":", "source_proc", "=", "self", ".", "processors", "[", "0", "]", "if...
Append a new processor to the pipe
[ "Append", "a", "new", "processor", "to", "the", "pipe" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/core/processor.py#L337-L369
train
Parisson/TimeSide
timeside/plugins/analyzer/externals/vamp_plugin.py
simple_host_process
def simple_host_process(argslist): """Call vamp-simple-host""" vamp_host = 'vamp-simple-host' command = [vamp_host] command.extend(argslist) # try ? stdout = subprocess.check_output(command, stderr=subprocess.STDOUT).splitlines() return stdout
python
def simple_host_process(argslist): """Call vamp-simple-host""" vamp_host = 'vamp-simple-host' command = [vamp_host] command.extend(argslist) # try ? stdout = subprocess.check_output(command, stderr=subprocess.STDOUT).splitlines() return stdout
[ "def", "simple_host_process", "(", "argslist", ")", ":", "vamp_host", "=", "'vamp-simple-host'", "command", "=", "[", "vamp_host", "]", "command", ".", "extend", "(", "argslist", ")", "# try ?", "stdout", "=", "subprocess", ".", "check_output", "(", "command", ...
Call vamp-simple-host
[ "Call", "vamp", "-", "simple", "-", "host" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/plugins/analyzer/externals/vamp_plugin.py#L33-L43
train
Parisson/TimeSide
timeside/plugins/grapher/spectrogram_lin.py
SpectrogramLinear.set_scale
def set_scale(self): """generate the lookup which translates y-coordinate to fft-bin""" f_min = float(self.lower_freq) f_max = float(self.higher_freq) y_min = f_min y_max = f_max for y in range(self.image_height): freq = y_min + y / (self.image_height - 1.0) ...
python
def set_scale(self): """generate the lookup which translates y-coordinate to fft-bin""" f_min = float(self.lower_freq) f_max = float(self.higher_freq) y_min = f_min y_max = f_max for y in range(self.image_height): freq = y_min + y / (self.image_height - 1.0) ...
[ "def", "set_scale", "(", "self", ")", ":", "f_min", "=", "float", "(", "self", ".", "lower_freq", ")", "f_max", "=", "float", "(", "self", ".", "higher_freq", ")", "y_min", "=", "f_min", "y_max", "=", "f_max", "for", "y", "in", "range", "(", "self", ...
generate the lookup which translates y-coordinate to fft-bin
[ "generate", "the", "lookup", "which", "translates", "y", "-", "coordinate", "to", "fft", "-", "bin" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/plugins/grapher/spectrogram_lin.py#L55-L67
train
Parisson/TimeSide
timeside/core/tools/hdf5.py
dict_from_hdf5
def dict_from_hdf5(dict_like, h5group): """ Load a dictionnary-like object from a h5 file group """ # Read attributes for name, value in h5group.attrs.items(): dict_like[name] = value
python
def dict_from_hdf5(dict_like, h5group): """ Load a dictionnary-like object from a h5 file group """ # Read attributes for name, value in h5group.attrs.items(): dict_like[name] = value
[ "def", "dict_from_hdf5", "(", "dict_like", ",", "h5group", ")", ":", "# Read attributes", "for", "name", ",", "value", "in", "h5group", ".", "attrs", ".", "items", "(", ")", ":", "dict_like", "[", "name", "]", "=", "value" ]
Load a dictionnary-like object from a h5 file group
[ "Load", "a", "dictionnary", "-", "like", "object", "from", "a", "h5", "file", "group" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/core/tools/hdf5.py#L34-L40
train
Parisson/TimeSide
timeside/plugins/decoder/array.py
ArrayDecoder.get_frames
def get_frames(self): "Define an iterator that will return frames at the given blocksize" nb_frames = self.input_totalframes // self.output_blocksize if self.input_totalframes % self.output_blocksize == 0: nb_frames -= 1 # Last frame must send eod=True for index in xrange(...
python
def get_frames(self): "Define an iterator that will return frames at the given blocksize" nb_frames = self.input_totalframes // self.output_blocksize if self.input_totalframes % self.output_blocksize == 0: nb_frames -= 1 # Last frame must send eod=True for index in xrange(...
[ "def", "get_frames", "(", "self", ")", ":", "nb_frames", "=", "self", ".", "input_totalframes", "//", "self", ".", "output_blocksize", "if", "self", ".", "input_totalframes", "%", "self", ".", "output_blocksize", "==", "0", ":", "nb_frames", "-=", "1", "# La...
Define an iterator that will return frames at the given blocksize
[ "Define", "an", "iterator", "that", "will", "return", "frames", "at", "the", "given", "blocksize" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/plugins/decoder/array.py#L113-L125
train
Parisson/TimeSide
timeside/core/component.py
implementations
def implementations(interface, recurse=True, abstract=False): """Returns the components implementing interface, and if recurse, any of the descendants of interface. If abstract is True, also return the abstract implementations.""" result = [] find_implementations(interface, recurse, abstract, result...
python
def implementations(interface, recurse=True, abstract=False): """Returns the components implementing interface, and if recurse, any of the descendants of interface. If abstract is True, also return the abstract implementations.""" result = [] find_implementations(interface, recurse, abstract, result...
[ "def", "implementations", "(", "interface", ",", "recurse", "=", "True", ",", "abstract", "=", "False", ")", ":", "result", "=", "[", "]", "find_implementations", "(", "interface", ",", "recurse", ",", "abstract", ",", "result", ")", "return", "result" ]
Returns the components implementing interface, and if recurse, any of the descendants of interface. If abstract is True, also return the abstract implementations.
[ "Returns", "the", "components", "implementing", "interface", "and", "if", "recurse", "any", "of", "the", "descendants", "of", "interface", ".", "If", "abstract", "is", "True", "also", "return", "the", "abstract", "implementations", "." ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/core/component.py#L65-L71
train
Parisson/TimeSide
timeside/core/component.py
find_implementations
def find_implementations(interface, recurse, abstract, result): """Find implementations of an interface or of one of its descendants and extend result with the classes found.""" for item in MetaComponent.implementations: if (item['interface'] == interface and (abstract or not item['abstract'])): ...
python
def find_implementations(interface, recurse, abstract, result): """Find implementations of an interface or of one of its descendants and extend result with the classes found.""" for item in MetaComponent.implementations: if (item['interface'] == interface and (abstract or not item['abstract'])): ...
[ "def", "find_implementations", "(", "interface", ",", "recurse", ",", "abstract", ",", "result", ")", ":", "for", "item", "in", "MetaComponent", ".", "implementations", ":", "if", "(", "item", "[", "'interface'", "]", "==", "interface", "and", "(", "abstract...
Find implementations of an interface or of one of its descendants and extend result with the classes found.
[ "Find", "implementations", "of", "an", "interface", "or", "of", "one", "of", "its", "descendants", "and", "extend", "result", "with", "the", "classes", "found", "." ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/core/component.py#L141-L152
train
Parisson/TimeSide
timeside/core/grapher.py
Grapher.draw_peaks
def draw_peaks(self, x, peaks, line_color): """Draw 2 peaks at x""" y1 = self.image_height * 0.5 - peaks[0] * (self.image_height - 4) * 0.5 y2 = self.image_height * 0.5 - peaks[1] * (self.image_height - 4) * 0.5 if self.previous_y: self.draw.line( [self.prev...
python
def draw_peaks(self, x, peaks, line_color): """Draw 2 peaks at x""" y1 = self.image_height * 0.5 - peaks[0] * (self.image_height - 4) * 0.5 y2 = self.image_height * 0.5 - peaks[1] * (self.image_height - 4) * 0.5 if self.previous_y: self.draw.line( [self.prev...
[ "def", "draw_peaks", "(", "self", ",", "x", ",", "peaks", ",", "line_color", ")", ":", "y1", "=", "self", ".", "image_height", "*", "0.5", "-", "peaks", "[", "0", "]", "*", "(", "self", ".", "image_height", "-", "4", ")", "*", "0.5", "y2", "=", ...
Draw 2 peaks at x
[ "Draw", "2", "peaks", "at", "x" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/core/grapher.py#L193-L206
train
Parisson/TimeSide
timeside/core/grapher.py
Grapher.draw_peaks_inverted
def draw_peaks_inverted(self, x, peaks, line_color): """Draw 2 inverted peaks at x""" y1 = self.image_height * 0.5 - peaks[0] * (self.image_height - 4) * 0.5 y2 = self.image_height * 0.5 - peaks[1] * (self.image_height - 4) * 0.5 if self.previous_y and x < self.image_width - 1: ...
python
def draw_peaks_inverted(self, x, peaks, line_color): """Draw 2 inverted peaks at x""" y1 = self.image_height * 0.5 - peaks[0] * (self.image_height - 4) * 0.5 y2 = self.image_height * 0.5 - peaks[1] * (self.image_height - 4) * 0.5 if self.previous_y and x < self.image_width - 1: ...
[ "def", "draw_peaks_inverted", "(", "self", ",", "x", ",", "peaks", ",", "line_color", ")", ":", "y1", "=", "self", ".", "image_height", "*", "0.5", "-", "peaks", "[", "0", "]", "*", "(", "self", ".", "image_height", "-", "4", ")", "*", "0.5", "y2",...
Draw 2 inverted peaks at x
[ "Draw", "2", "inverted", "peaks", "at", "x" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/core/grapher.py#L208-L224
train
Parisson/TimeSide
timeside/core/grapher.py
Grapher.draw_anti_aliased_pixels
def draw_anti_aliased_pixels(self, x, y1, y2, color): """ vertical anti-aliasing at y1 and y2 """ y_max = max(y1, y2) y_max_int = int(y_max) alpha = y_max - y_max_int if alpha > 0.0 and alpha < 1.0 and y_max_int + 1 < self.image_height: current_pix = self.pixel[int(...
python
def draw_anti_aliased_pixels(self, x, y1, y2, color): """ vertical anti-aliasing at y1 and y2 """ y_max = max(y1, y2) y_max_int = int(y_max) alpha = y_max - y_max_int if alpha > 0.0 and alpha < 1.0 and y_max_int + 1 < self.image_height: current_pix = self.pixel[int(...
[ "def", "draw_anti_aliased_pixels", "(", "self", ",", "x", ",", "y1", ",", "y2", ",", "color", ")", ":", "y_max", "=", "max", "(", "y1", ",", "y2", ")", "y_max_int", "=", "int", "(", "y_max", ")", "alpha", "=", "y_max", "-", "y_max_int", "if", "alph...
vertical anti-aliasing at y1 and y2
[ "vertical", "anti", "-", "aliasing", "at", "y1", "and", "y2" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/core/grapher.py#L226-L249
train
Parisson/TimeSide
timeside/plugins/grapher/spectrogram_log.py
SpectrogramLog.post_process
def post_process(self): """ Apply last 2D transforms""" self.image.putdata(self.pixels) self.image = self.image.transpose(Image.ROTATE_90)
python
def post_process(self): """ Apply last 2D transforms""" self.image.putdata(self.pixels) self.image = self.image.transpose(Image.ROTATE_90)
[ "def", "post_process", "(", "self", ")", ":", "self", ".", "image", ".", "putdata", "(", "self", ".", "pixels", ")", "self", ".", "image", "=", "self", ".", "image", ".", "transpose", "(", "Image", ".", "ROTATE_90", ")" ]
Apply last 2D transforms
[ "Apply", "last", "2D", "transforms" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/plugins/grapher/spectrogram_log.py#L105-L108
train
Parisson/TimeSide
timeside/plugins/encoder/mp3.py
Mp3Encoder.write_metadata
def write_metadata(self): """Write all ID3v2.4 tags to file from self.metadata""" import mutagen from mutagen import id3 id3 = id3.ID3(self.filename) for tag in self.metadata.keys(): value = self.metadata[tag] frame = mutagen.id3.Frames[tag](3, value) ...
python
def write_metadata(self): """Write all ID3v2.4 tags to file from self.metadata""" import mutagen from mutagen import id3 id3 = id3.ID3(self.filename) for tag in self.metadata.keys(): value = self.metadata[tag] frame = mutagen.id3.Frames[tag](3, value) ...
[ "def", "write_metadata", "(", "self", ")", ":", "import", "mutagen", "from", "mutagen", "import", "id3", "id3", "=", "id3", ".", "ID3", "(", "self", ".", "filename", ")", "for", "tag", "in", "self", ".", "metadata", ".", "keys", "(", ")", ":", "value...
Write all ID3v2.4 tags to file from self.metadata
[ "Write", "all", "ID3v2", ".", "4", "tags", "to", "file", "from", "self", ".", "metadata" ]
0618d75cd2f16021afcfd3d5b77f692adad76ea5
https://github.com/Parisson/TimeSide/blob/0618d75cd2f16021afcfd3d5b77f692adad76ea5/timeside/plugins/encoder/mp3.py#L94-L110
train
btimby/fulltext
fulltext/__main__.py
main
def main(args=sys.argv[1:]): """Extract text from a file. Commands: extract - extract text from path check - make sure all deps are installed Usage: fulltext extract [-v] [-f] <path>... fulltext check [-t] Options: -f, --file Open file first. ...
python
def main(args=sys.argv[1:]): """Extract text from a file. Commands: extract - extract text from path check - make sure all deps are installed Usage: fulltext extract [-v] [-f] <path>... fulltext check [-t] Options: -f, --file Open file first. ...
[ "def", "main", "(", "args", "=", "sys", ".", "argv", "[", "1", ":", "]", ")", ":", "opt", "=", "docopt", "(", "main", ".", "__doc__", ".", "strip", "(", ")", ",", "args", ",", "options_first", "=", "True", ")", "config_logging", "(", "opt", "[", ...
Extract text from a file. Commands: extract - extract text from path check - make sure all deps are installed Usage: fulltext extract [-v] [-f] <path>... fulltext check [-t] Options: -f, --file Open file first. -t, --title Check deps fo...
[ "Extract", "text", "from", "a", "file", "." ]
9234cc1e2099209430e20317649549026de283ce
https://github.com/btimby/fulltext/blob/9234cc1e2099209430e20317649549026de283ce/fulltext/__main__.py#L71-L103
train
btimby/fulltext
fulltext/__init__.py
is_binary
def is_binary(f): """Return True if binary mode.""" # NOTE: order matters here. We don't bail on Python 2 just yet. Both # codecs.open() and io.open() can open in text mode, both set the encoding # attribute. We must do that check first. # If it has a decoding attribute with a value, it is text mod...
python
def is_binary(f): """Return True if binary mode.""" # NOTE: order matters here. We don't bail on Python 2 just yet. Both # codecs.open() and io.open() can open in text mode, both set the encoding # attribute. We must do that check first. # If it has a decoding attribute with a value, it is text mod...
[ "def", "is_binary", "(", "f", ")", ":", "# NOTE: order matters here. We don't bail on Python 2 just yet. Both", "# codecs.open() and io.open() can open in text mode, both set the encoding", "# attribute. We must do that check first.", "# If it has a decoding attribute with a value, it is text mode...
Return True if binary mode.
[ "Return", "True", "if", "binary", "mode", "." ]
9234cc1e2099209430e20317649549026de283ce
https://github.com/btimby/fulltext/blob/9234cc1e2099209430e20317649549026de283ce/fulltext/__init__.py#L329-L362
train
btimby/fulltext
fulltext/__init__.py
handle_path
def handle_path(backend_inst, path, **kwargs): """ Handle a path. Called by `get()` when provided a path. This function will prefer the backend's `handle_path()` if one is provided Otherwise, it will open the given path then use `handle_fobj()`. """ if callable(getattr(backend_inst, 'handle...
python
def handle_path(backend_inst, path, **kwargs): """ Handle a path. Called by `get()` when provided a path. This function will prefer the backend's `handle_path()` if one is provided Otherwise, it will open the given path then use `handle_fobj()`. """ if callable(getattr(backend_inst, 'handle...
[ "def", "handle_path", "(", "backend_inst", ",", "path", ",", "*", "*", "kwargs", ")", ":", "if", "callable", "(", "getattr", "(", "backend_inst", ",", "'handle_path'", ",", "None", ")", ")", ":", "# Prefer handle_path() if present.", "LOGGER", ".", "debug", ...
Handle a path. Called by `get()` when provided a path. This function will prefer the backend's `handle_path()` if one is provided Otherwise, it will open the given path then use `handle_fobj()`.
[ "Handle", "a", "path", "." ]
9234cc1e2099209430e20317649549026de283ce
https://github.com/btimby/fulltext/blob/9234cc1e2099209430e20317649549026de283ce/fulltext/__init__.py#L365-L387
train
btimby/fulltext
fulltext/__init__.py
handle_fobj
def handle_fobj(backend, f, **kwargs): """ Handle a file-like object. Called by `get()` when provided a file-like. This function will prefer the backend's `handle_fobj()` if one is provided. Otherwise, it will write the data to a temporary file and call `handle_path()`. """ if not is_binary...
python
def handle_fobj(backend, f, **kwargs): """ Handle a file-like object. Called by `get()` when provided a file-like. This function will prefer the backend's `handle_fobj()` if one is provided. Otherwise, it will write the data to a temporary file and call `handle_path()`. """ if not is_binary...
[ "def", "handle_fobj", "(", "backend", ",", "f", ",", "*", "*", "kwargs", ")", ":", "if", "not", "is_binary", "(", "f", ")", ":", "raise", "AssertionError", "(", "'File must be opened in binary mode.'", ")", "if", "callable", "(", "getattr", "(", "backend", ...
Handle a file-like object. Called by `get()` when provided a file-like. This function will prefer the backend's `handle_fobj()` if one is provided. Otherwise, it will write the data to a temporary file and call `handle_path()`.
[ "Handle", "a", "file", "-", "like", "object", "." ]
9234cc1e2099209430e20317649549026de283ce
https://github.com/btimby/fulltext/blob/9234cc1e2099209430e20317649549026de283ce/fulltext/__init__.py#L390-L421
train
btimby/fulltext
fulltext/__init__.py
backend_from_mime
def backend_from_mime(mime): """Determine backend module object from a mime string.""" try: mod_name = MIMETYPE_TO_BACKENDS[mime] except KeyError: msg = "No handler for %r, defaulting to %r" % (mime, DEFAULT_MIME) if 'FULLTEXT_TESTING' in os.environ: warn(msg) el...
python
def backend_from_mime(mime): """Determine backend module object from a mime string.""" try: mod_name = MIMETYPE_TO_BACKENDS[mime] except KeyError: msg = "No handler for %r, defaulting to %r" % (mime, DEFAULT_MIME) if 'FULLTEXT_TESTING' in os.environ: warn(msg) el...
[ "def", "backend_from_mime", "(", "mime", ")", ":", "try", ":", "mod_name", "=", "MIMETYPE_TO_BACKENDS", "[", "mime", "]", "except", "KeyError", ":", "msg", "=", "\"No handler for %r, defaulting to %r\"", "%", "(", "mime", ",", "DEFAULT_MIME", ")", "if", "'FULLTE...
Determine backend module object from a mime string.
[ "Determine", "backend", "module", "object", "from", "a", "mime", "string", "." ]
9234cc1e2099209430e20317649549026de283ce
https://github.com/btimby/fulltext/blob/9234cc1e2099209430e20317649549026de283ce/fulltext/__init__.py#L428-L442
train
btimby/fulltext
fulltext/__init__.py
backend_from_fname
def backend_from_fname(name): """Determine backend module object from a file name.""" ext = splitext(name)[1] try: mime = EXTS_TO_MIMETYPES[ext] except KeyError: try: f = open(name, 'rb') except IOError as e: # The file may not exist, we are being asked...
python
def backend_from_fname(name): """Determine backend module object from a file name.""" ext = splitext(name)[1] try: mime = EXTS_TO_MIMETYPES[ext] except KeyError: try: f = open(name, 'rb') except IOError as e: # The file may not exist, we are being asked...
[ "def", "backend_from_fname", "(", "name", ")", ":", "ext", "=", "splitext", "(", "name", ")", "[", "1", "]", "try", ":", "mime", "=", "EXTS_TO_MIMETYPES", "[", "ext", "]", "except", "KeyError", ":", "try", ":", "f", "=", "open", "(", "name", ",", "...
Determine backend module object from a file name.
[ "Determine", "backend", "module", "object", "from", "a", "file", "name", "." ]
9234cc1e2099209430e20317649549026de283ce
https://github.com/btimby/fulltext/blob/9234cc1e2099209430e20317649549026de283ce/fulltext/__init__.py#L445-L479
train
btimby/fulltext
fulltext/__init__.py
backend_from_fobj
def backend_from_fobj(f): """Determine backend module object from a file object.""" if magic is None: warn("magic lib is not installed; assuming mime type %r" % ( DEFAULT_MIME)) return backend_from_mime(DEFAULT_MIME) else: offset = f.tell() try: f.seek...
python
def backend_from_fobj(f): """Determine backend module object from a file object.""" if magic is None: warn("magic lib is not installed; assuming mime type %r" % ( DEFAULT_MIME)) return backend_from_mime(DEFAULT_MIME) else: offset = f.tell() try: f.seek...
[ "def", "backend_from_fobj", "(", "f", ")", ":", "if", "magic", "is", "None", ":", "warn", "(", "\"magic lib is not installed; assuming mime type %r\"", "%", "(", "DEFAULT_MIME", ")", ")", "return", "backend_from_mime", "(", "DEFAULT_MIME", ")", "else", ":", "offse...
Determine backend module object from a file object.
[ "Determine", "backend", "module", "object", "from", "a", "file", "object", "." ]
9234cc1e2099209430e20317649549026de283ce
https://github.com/btimby/fulltext/blob/9234cc1e2099209430e20317649549026de283ce/fulltext/__init__.py#L482-L496
train
btimby/fulltext
fulltext/__init__.py
backend_inst_from_mod
def backend_inst_from_mod(mod, encoding, encoding_errors, kwargs): """Given a mod and a set of opts return an instantiated Backend class. """ kw = dict(encoding=encoding, encoding_errors=encoding_errors, kwargs=kwargs) try: klass = getattr(mod, "Backend") except AttributeEr...
python
def backend_inst_from_mod(mod, encoding, encoding_errors, kwargs): """Given a mod and a set of opts return an instantiated Backend class. """ kw = dict(encoding=encoding, encoding_errors=encoding_errors, kwargs=kwargs) try: klass = getattr(mod, "Backend") except AttributeEr...
[ "def", "backend_inst_from_mod", "(", "mod", ",", "encoding", ",", "encoding_errors", ",", "kwargs", ")", ":", "kw", "=", "dict", "(", "encoding", "=", "encoding", ",", "encoding_errors", "=", "encoding_errors", ",", "kwargs", "=", "kwargs", ")", "try", ":", ...
Given a mod and a set of opts return an instantiated Backend class.
[ "Given", "a", "mod", "and", "a", "set", "of", "opts", "return", "an", "instantiated", "Backend", "class", "." ]
9234cc1e2099209430e20317649549026de283ce
https://github.com/btimby/fulltext/blob/9234cc1e2099209430e20317649549026de283ce/fulltext/__init__.py#L499-L519
train
btimby/fulltext
fulltext/__init__.py
get
def get(path_or_file, default=SENTINAL, mime=None, name=None, backend=None, encoding=None, encoding_errors=None, kwargs=None, _wtitle=False): """ Get document full text. Accepts a path or file-like object. * If given, `default` is returned instead of an error. * `backend` is eithe...
python
def get(path_or_file, default=SENTINAL, mime=None, name=None, backend=None, encoding=None, encoding_errors=None, kwargs=None, _wtitle=False): """ Get document full text. Accepts a path or file-like object. * If given, `default` is returned instead of an error. * `backend` is eithe...
[ "def", "get", "(", "path_or_file", ",", "default", "=", "SENTINAL", ",", "mime", "=", "None", ",", "name", "=", "None", ",", "backend", "=", "None", ",", "encoding", "=", "None", ",", "encoding_errors", "=", "None", ",", "kwargs", "=", "None", ",", "...
Get document full text. Accepts a path or file-like object. * If given, `default` is returned instead of an error. * `backend` is either a module object or a string specifying which default backend to use (e.g. "doc"); take a look at backends directory to see a list of default backends. ...
[ "Get", "document", "full", "text", "." ]
9234cc1e2099209430e20317649549026de283ce
https://github.com/btimby/fulltext/blob/9234cc1e2099209430e20317649549026de283ce/fulltext/__init__.py#L585-L618
train
btimby/fulltext
fulltext/util.py
hilite
def hilite(s, ok=True, bold=False): """Return an highlighted version of 'string'.""" if not term_supports_colors(): return s attr = [] if ok is None: # no color pass elif ok: # green attr.append('32') else: # red attr.append('31') if bold: attr.ap...
python
def hilite(s, ok=True, bold=False): """Return an highlighted version of 'string'.""" if not term_supports_colors(): return s attr = [] if ok is None: # no color pass elif ok: # green attr.append('32') else: # red attr.append('31') if bold: attr.ap...
[ "def", "hilite", "(", "s", ",", "ok", "=", "True", ",", "bold", "=", "False", ")", ":", "if", "not", "term_supports_colors", "(", ")", ":", "return", "s", "attr", "=", "[", "]", "if", "ok", "is", "None", ":", "# no color", "pass", "elif", "ok", "...
Return an highlighted version of 'string'.
[ "Return", "an", "highlighted", "version", "of", "string", "." ]
9234cc1e2099209430e20317649549026de283ce
https://github.com/btimby/fulltext/blob/9234cc1e2099209430e20317649549026de283ce/fulltext/util.py#L254-L267
train
btimby/fulltext
fulltext/util.py
fobj_to_tempfile
def fobj_to_tempfile(f, suffix=''): """Context manager which copies a file object to disk and return its name. When done the file is deleted. """ with tempfile.NamedTemporaryFile( dir=TEMPDIR, suffix=suffix, delete=False) as t: shutil.copyfileobj(f, t) try: yield t.name ...
python
def fobj_to_tempfile(f, suffix=''): """Context manager which copies a file object to disk and return its name. When done the file is deleted. """ with tempfile.NamedTemporaryFile( dir=TEMPDIR, suffix=suffix, delete=False) as t: shutil.copyfileobj(f, t) try: yield t.name ...
[ "def", "fobj_to_tempfile", "(", "f", ",", "suffix", "=", "''", ")", ":", "with", "tempfile", ".", "NamedTemporaryFile", "(", "dir", "=", "TEMPDIR", ",", "suffix", "=", "suffix", ",", "delete", "=", "False", ")", "as", "t", ":", "shutil", ".", "copyfile...
Context manager which copies a file object to disk and return its name. When done the file is deleted.
[ "Context", "manager", "which", "copies", "a", "file", "object", "to", "disk", "and", "return", "its", "name", ".", "When", "done", "the", "file", "is", "deleted", "." ]
9234cc1e2099209430e20317649549026de283ce
https://github.com/btimby/fulltext/blob/9234cc1e2099209430e20317649549026de283ce/fulltext/util.py#L308-L318
train