File: //lib/python2.7/site-packages/requests_toolbelt/utils/deprecated.pyc
ó
Óµ Yc @ sŒ d Z d d l Z d d l Z d d l m Z e j d d e j ƒj Z e j d d e j ƒj Z e j d ƒ j Z
d „ Z d „ Z d S(
s7 A collection of functions deprecated in requests.utils.iÿÿÿÿN( t utilss! <meta.*?charset=["\']*(.+?)["\'>]t flagss+ <meta.*?content=["\']*;?charset=(.+?)["\'>]s$ ^<\?xml.*?encoding=["\']*(.+?)["\'>]c C sh t | ƒ t | ƒ t | ƒ } d t j k o: d k n rd g | D] } | j d ƒ ^ qF } n | S( s™ Return encodings from given content string.
.. code-block:: python
import requests
from requests_toolbelt.utils import deprecated
r = requests.get(url)
encodings = deprecated.get_encodings_from_content(r)
:param content: bytestring to extract encodings from
:type content: bytes
:return: encodings detected in the provided content
:rtype: list(str)
i i i t utf8( i i ( i i ( t find_charsett find_pragmat find_xmlt syst version_infot decode( t contentt encodingst encoding( ( sF /usr/lib/python2.7/site-packages/requests_toolbelt/utils/deprecated.pyt get_encodings_from_content s %c C s t ƒ } t j | j ƒ } | r_ y t | j | ƒ SWq_ t k
r[ | j | j ƒ ƒ q_ Xn t | j ƒ } xa | D]Y } | j ƒ } | | k r™ qu n y t | j | ƒ SWqu t k
rÍ | j | ƒ qu Xqu W| r y t | j | d d ƒSWq t
k
rq Xn | j S( sM Return the requested content back in unicode.
This will first attempt to retrieve the encoding from the response
headers. If that fails, it will use
:func:`requests_toolbelt.utils.deprecated.get_encodings_from_content`
to determine encodings from HTML elements.
.. code-block:: python
import requests
from requests_toolbelt.utils import deprecated
r = requests.get(url)
text = deprecated.get_unicode_from_response(r)
:param response: Response object to get unicode content from.
:type response: requests.models.Response
t errorst replace( t setR t get_encoding_from_headerst headerst strR t UnicodeErrort addt lowerR t TypeErrort text( t responset tried_encodingsR R
t _encoding( ( sF /usr/lib/python2.7/site-packages/requests_toolbelt/utils/deprecated.pyt get_unicode_from_response, s,
(
t __doc__t reR t requestsR t compilet It findallR R R R R ( ( ( sF /usr/lib/python2.7/site-packages/requests_toolbelt/utils/deprecated.pyt <module> s