text
stringlengths
0
828
self._config['user_stream'] = config_parser.get('stream', 'user_stream').lower() == 'true'
else:
self._config['user_stream'] = False
if config_parser.has_option('general', 'min_seconds_between_errors'):
self._config['min_seconds_between_errors'] = config_parser.get('general', 'min_seconds_between_errors')
if config_parser.has_option('general', 'sleep_seconds_on_consecutive_errors'):
self._config['sleep_seconds_on_consecutive_errors'] = config_parser.get(
'general', 'sleep_seconds_on_consecutive_errors')"
1722,"def load_config_from_cli_arguments(self, *args, **kwargs):
""""""
Get config values of passed in CLI options.
:param dict kwargs: CLI options
""""""
self._load_config_from_cli_argument(key='handlers_package', **kwargs)
self._load_config_from_cli_argument(key='auth', **kwargs)
self._load_config_from_cli_argument(key='user_stream', **kwargs)
self._load_config_from_cli_argument(key='min_seconds_between_errors', **kwargs)
self._load_config_from_cli_argument(key='sleep_seconds_on_consecutive_errors', **kwargs)"
1723,"def validate_configs(self):
""""""
Check that required config are set.
:raises :class:`~responsebot.common.exceptions.MissingConfigError`: if a required config is missing
""""""
# Check required arguments, validate values
for conf in self.REQUIRED_CONFIGS:
if conf not in self._config:
raise MissingConfigError('Missing required configuration %s' % conf)"
1724,"def get(self, id):
"""""" Gets the dict data and builds the item object.
""""""
data = self.db.get_data(self.get_path, id=id)
return self._build_item(**data['Data'][self.name])"
1725,"def save(self, entity):
""""""Maps entity to dict and returns future""""""
assert isinstance(entity, Entity), "" entity must have an instance of Entity""
return self.__collection.save(entity.as_dict())"
1726,"def find_one(self, **kwargs):
""""""Returns future.
Executes collection's find_one method based on keyword args
maps result ( dict to instance ) and return future
Example::
manager = EntityManager(Product)
product_saved = yield manager.find_one(_id=object_id)
""""""
future = TracebackFuture()
def handle_response(result, error):
if error:
future.set_exception(error)
else:
instance = self.__entity()
instance.map_dict(result)
future.set_result(instance)
self.__collection.find_one(kwargs, callback=handle_response)
return future"
1727,"def find(self, **kwargs):
""""""Returns List(typeof=).
Executes collection's find method based on keyword args
maps results ( dict to list of entity instances).
Set max_limit parameter to limit the amount of data send back through network
Example::
manager = EntityManager(Product)
products = yield manager.find(age={'$gt': 17}, max_limit=100)
""""""
max_limit = None
if 'max_limit' in kwargs:
max_limit = kwargs.pop('max_limit')
cursor = self.__collection.find(kwargs)
instances = []
for doc in (yield cursor.to_list(max_limit)):
instance = self.__entity()
instance.map_dict(doc)
instances.append(instance)
return instances"
1728,"def update(self, entity):
"""""" Executes collection's update method based on keyword args.
Example::
manager = EntityManager(Product)
p = Product()
p.name = 'new name'
p.description = 'new description'
p.price = 300.0
yield manager.update(p)