mirror of https://github.com/scrapy/scrapy.git
Add more code blocks in docstrings.
This commit is contained in:
parent
26677fede5
commit
8573026049
|
|
@ -9,7 +9,9 @@ its documentation in: docs/topics/link-extractors.rst
|
|||
class Link:
|
||||
"""Link objects represent an extracted link by the LinkExtractor.
|
||||
|
||||
Using the anchor tag sample below to illustrate the parameters::
|
||||
Using the anchor tag sample below to illustrate the parameters:
|
||||
|
||||
.. code-block:: html
|
||||
|
||||
<a href="https://example.com/nofollow.html#foo" rel="nofollow">Dont follow this one</a>
|
||||
|
||||
|
|
|
|||
|
|
@ -58,18 +58,20 @@ class LogFormatter:
|
|||
logging an action the method must return ``None``.
|
||||
|
||||
Here is an example on how to create a custom log formatter to lower the severity level of
|
||||
the log message when an item is dropped from the pipeline::
|
||||
the log message when an item is dropped from the pipeline:
|
||||
|
||||
class PoliteLogFormatter(logformatter.LogFormatter):
|
||||
def dropped(self, item, exception, response, spider):
|
||||
return {
|
||||
'level': logging.INFO, # lowering the level from logging.WARNING
|
||||
'msg': "Dropped: %(exception)s" + os.linesep + "%(item)s",
|
||||
'args': {
|
||||
'exception': exception,
|
||||
'item': item,
|
||||
}
|
||||
}
|
||||
.. code-block:: python
|
||||
|
||||
class PoliteLogFormatter(logformatter.LogFormatter):
|
||||
def dropped(self, item, exception, response, spider):
|
||||
return {
|
||||
"level": logging.INFO, # lowering the level from logging.WARNING
|
||||
"msg": "Dropped: %(exception)s" + os.linesep + "%(item)s",
|
||||
"args": {
|
||||
"exception": exception,
|
||||
"item": item,
|
||||
},
|
||||
}
|
||||
"""
|
||||
|
||||
def crawled(
|
||||
|
|
|
|||
|
|
@ -43,15 +43,18 @@ def create_deprecated_class(
|
|||
It can be used to rename a base class in a library. For example, if we
|
||||
have
|
||||
|
||||
class OldName(SomeClass):
|
||||
# ...
|
||||
.. code-block:: python
|
||||
|
||||
and we want to rename it to NewName, we can do the following::
|
||||
class OldName(SomeClass): ...
|
||||
|
||||
class NewName(SomeClass):
|
||||
# ...
|
||||
and we want to rename it to NewName, we can do the following:
|
||||
|
||||
OldName = create_deprecated_class('OldName', NewName)
|
||||
.. code-block:: python
|
||||
|
||||
class NewName(SomeClass): ...
|
||||
|
||||
|
||||
OldName = create_deprecated_class("OldName", NewName)
|
||||
|
||||
Then, if user class inherits from OldName, warning is issued. Also, if
|
||||
some code uses ``issubclass(sub, OldName)`` or ``isinstance(sub(), OldName)``
|
||||
|
|
|
|||
Loading…
Reference in New Issue