class documentation

class BaseSettings(MutableMapping): (source)

Known subclasses: scrapy.settings.Settings

View In Hierarchy

Instances of this class behave like dictionaries, but store priorities along with their ``(key, value)`` pairs, and can be frozen (i.e. marked immutable). Key-value entries can be passed on initialization with the ``values`` argument, and they would take the ``priority`` level (unless ``values`` is already an instance of :class:`~scrapy.settings.BaseSettings`, in which case the existing priority levels will be kept). If the ``priority`` argument is a string, the priority name will be looked up in :attr:`~scrapy.settings.SETTINGS_PRIORITIES`. Otherwise, a specific integer should be provided. Once the object is created, new settings can be loaded or updated with the :meth:`~scrapy.settings.BaseSettings.set` method, and can be accessed with the square bracket notation of dictionaries, or with the :meth:`~scrapy.settings.BaseSettings.get` method of the instance and its value conversion variants. When requesting a stored key, the value with the highest priority will be retrieved.

Method __contains__ Undocumented
Method __delitem__ Undocumented
Method __getitem__ Undocumented
Method __init__ Undocumented
Method __iter__ Undocumented
Method __len__ Undocumented
Method __setitem__ Undocumented
Method copy Make a deep copy of current settings.
Method copy_to_dict Make a copy of current settings and convert to a dict.
Method delete Undocumented
Method freeze Disable further changes to the current settings.
Method frozencopy Return an immutable copy of the current settings.
Method get Get a setting value without affecting its original type.
Method getbool Get a setting value as a boolean.
Method getdict Get a setting value as a dictionary. If the setting original type is a dictionary, a copy of it will be returned. If it is a string it will be evaluated as a JSON dictionary. In the case that it is a :class:`~scrapy...
Method getdictorlist Get a setting value as either a :class:`dict` or a :class:`list`.
Method getfloat Get a setting value as a float.
Method getint Get a setting value as an int.
Method getlist Get a setting value as a list. If the setting original type is a list, a copy of it will be returned. If it's a string it will be split by ",".
Method getpriority Return the current numerical priority value of a setting, or ``None`` if the given ``name`` does not exist.
Method getwithbase Get a composition of a dictionary-like setting and its `_BASE` counterpart.
Method maxpriority Return the numerical value of the highest priority present throughout all settings, or the numerical value for ``default`` from :attr:`~scrapy.settings.SETTINGS_PRIORITIES` if there are no settings stored.
Method set Store a key/value attribute with a given priority.
Method setdict Undocumented
Method setmodule Store settings from a module with a given priority.
Method update Store key/value pairs with a given priority.
Instance Variable attributes Undocumented
Instance Variable frozen Undocumented
Method _assert_mutability Undocumented
Method _get_key Undocumented
Method _repr_pretty_ Undocumented
Method _to_dict Undocumented
def __contains__(self, name): (source)

Undocumented

def __delitem__(self, name): (source)

Undocumented

def __getitem__(self, opt_name): (source)

Undocumented

def __init__(self, values=None, priority='project'): (source)

Undocumented

def __iter__(self): (source)

Undocumented

def __len__(self): (source)

Undocumented

def __setitem__(self, name, value): (source)

Undocumented

def copy(self): (source)

Make a deep copy of current settings. This method returns a new instance of the :class:`Settings` class, populated with the same values and their priorities. Modifications to the new object won't be reflected on the original settings.

def copy_to_dict(self): (source)

Make a copy of current settings and convert to a dict. This method returns a new dict populated with the same values and their priorities as the current settings. Modifications to the returned dict won't be reflected on the original settings. This method can be useful for example for printing settings in Scrapy shell.

def delete(self, name, priority='project'): (source)

Undocumented

def freeze(self): (source)

Disable further changes to the current settings. After calling this method, the present state of the settings will become immutable. Trying to change values through the :meth:`~set` method and its variants won't be possible and will be alerted.

def frozencopy(self): (source)

Return an immutable copy of the current settings. Alias for a :meth:`~freeze` call in the object returned by :meth:`copy`.

def get(self, name, default=None): (source)

Get a setting value without affecting its original type. :param name: the setting name :type name: str :param default: the value to return if no setting is found :type default: object

def getbool(self, name, default=False): (source)

Get a setting value as a boolean. ``1``, ``'1'``, `True`` and ``'True'`` return ``True``, while ``0``, ``'0'``, ``False``, ``'False'`` and ``None`` return ``False``. For example, settings populated through environment variables set to ``'0'`` will return ``False`` when using this method. :param name: the setting name :type name: str :param default: the value to return if no setting is found :type default: object

def getdict(self, name, default=None): (source)

Get a setting value as a dictionary. If the setting original type is a dictionary, a copy of it will be returned. If it is a string it will be evaluated as a JSON dictionary. In the case that it is a :class:`~scrapy.settings.BaseSettings` instance itself, it will be converted to a dictionary, containing all its current settings values as they would be returned by :meth:`~scrapy.settings.BaseSettings.get`, and losing all information about priority and mutability. :param name: the setting name :type name: str :param default: the value to return if no setting is found :type default: object

def getdictorlist(self, name, default=None): (source)

Get a setting value as either a :class:`dict` or a :class:`list`. If the setting is already a dict or a list, a copy of it will be returned. If it is a string it will be evaluated as JSON, or as a comma-separated list of strings as a fallback. For example, settings populated from the command line will return: - ``{'key1': 'value1', 'key2': 'value2'}`` if set to ``'{"key1": "value1", "key2": "value2"}'`` - ``['one', 'two']`` if set to ``'["one", "two"]'`` or ``'one,two'`` :param name: the setting name :type name: string :param default: the value to return if no setting is found :type default: any

def getfloat(self, name, default=0.0): (source)

Get a setting value as a float. :param name: the setting name :type name: str :param default: the value to return if no setting is found :type default: object

def getint(self, name, default=0): (source)

Get a setting value as an int. :param name: the setting name :type name: str :param default: the value to return if no setting is found :type default: object

def getlist(self, name, default=None): (source)

Get a setting value as a list. If the setting original type is a list, a copy of it will be returned. If it's a string it will be split by ",". For example, settings populated through environment variables set to ``'one,two'`` will return a list ['one', 'two'] when using this method. :param name: the setting name :type name: str :param default: the value to return if no setting is found :type default: object

def getpriority(self, name): (source)

Return the current numerical priority value of a setting, or ``None`` if the given ``name`` does not exist. :param name: the setting name :type name: str

def getwithbase(self, name): (source)

Get a composition of a dictionary-like setting and its `_BASE` counterpart. :param name: name of the dictionary-like setting :type name: str

def maxpriority(self): (source)

Return the numerical value of the highest priority present throughout all settings, or the numerical value for ``default`` from :attr:`~scrapy.settings.SETTINGS_PRIORITIES` if there are no settings stored.

def set(self, name, value, priority='project'): (source)

Store a key/value attribute with a given priority. Settings should be populated *before* configuring the Crawler object (through the :meth:`~scrapy.crawler.Crawler.configure` method), otherwise they won't have any effect. :param name: the setting name :type name: str :param value: the value to associate with the setting :type value: object :param priority: the priority of the setting. Should be a key of :attr:`~scrapy.settings.SETTINGS_PRIORITIES` or an integer :type priority: str or int

def setdict(self, values, priority='project'): (source)

Undocumented

def setmodule(self, module, priority='project'): (source)

Store settings from a module with a given priority. This is a helper function that calls :meth:`~scrapy.settings.BaseSettings.set` for every globally declared uppercase variable of ``module`` with the provided ``priority``. :param module: the module or the path of the module :type module: types.ModuleType or str :param priority: the priority of the settings. Should be a key of :attr:`~scrapy.settings.SETTINGS_PRIORITIES` or an integer :type priority: str or int

def update(self, values, priority='project'): (source)

Store key/value pairs with a given priority. This is a helper function that calls :meth:`~scrapy.settings.BaseSettings.set` for every item of ``values`` with the provided ``priority``. If ``values`` is a string, it is assumed to be JSON-encoded and parsed into a dict with ``json.loads()`` first. If it is a :class:`~scrapy.settings.BaseSettings` instance, the per-key priorities will be used and the ``priority`` parameter ignored. This allows inserting/updating settings with different priorities with a single command. :param values: the settings names and values :type values: dict or string or :class:`~scrapy.settings.BaseSettings` :param priority: the priority of the settings. Should be a key of :attr:`~scrapy.settings.SETTINGS_PRIORITIES` or an integer :type priority: str or int

attributes: dict = (source)

Undocumented

Undocumented

def _assert_mutability(self): (source)

Undocumented

def _get_key(self, key_value): (source)

Undocumented

def _repr_pretty_(self, p, cycle): (source)

Undocumented

def _to_dict(self): (source)

Undocumented