Format: application/x-python-code
⬇ Download File (7.4 KB)
   1  o
   2  
   3  /'hs,�@snddlZddlZddlZddlZddlmZmZddl	m
   4  Z
   5  ddlTddlm
   6  Z
   7  ddlmZddlmZdd	lmZdd
   8  lmZddlmZddlmZddlTdd
   9  lmZmZddlmZdgZdZidd�dd�dd�dd�dd�dd�dd�dd �d!d"�d#d$�d%d&�d'd(�d)d*�d+d,�d-d.�d/d0�Z d1d2�Z!e"d3eee
  10  e#fi�Z$e"d4eeej%j&j'e#fi�Z(d7d5d6�Z)dS)8�N�)�registerDateHandler�_parse_date)�convert_to_utf8)�*)�_BaseHTMLProcessor)�http)�mixin)�_FeedParserMixin)�_LooseFeedParser)�_StrictFeedParser)�replace_doctype)�convert_to_idn�make_safe_absolute_uri)�FeedParserDictZdrv_libxml2T��unknownZrss090zRSS 0.90Zrss091nzRSS 0.91 (Netscape)Zrss091uzRSS 0.91 (Userland)Zrss092zRSS 0.92Zrss093zRSS 0.93Zrss094zRSS 0.94Zrss20zRSS 2.0Zrss10zRSS 1.0ZrsszRSS (unknown version)Zatom01zAtom 0.1Zatom02zAtom 0.2Zatom03zAtom 0.3Zatom10zAtom 1.0ZatomzAtom (unknown version)ZcdfZCDFc
  11  Cs�t|d�r	|��St|t�r$tj�|�ddvr$t�||||||||�Szt	|d��}|��}	Wd�W|	S1s;wYW|	St
  12  ttt
  13  fyOYnwt|t�sZ|�d�S|S)aEURL, filename, or string --> stream
  14  
  15      This function lets you define parsers that take any input source
  16      (URL, pathname to local or network file, or actual data as a string)
  17      and deal with it in a uniform manner.  Returned object is guaranteed
  18      to have all the basic stdio read methods (read, readline, readlines).
  19      Just .close() the object when you're done with it.
  20  
  21      If the etag argument is supplied, it will be used as the value of an
  22      If-None-Match request header.
  23  
  24      If the modified argument is supplied, it can be a tuple of 9 integers
  25      (as returned by gmtime() in the standard Python time module) or a date
  26      string in any format supported by feedparser. Regardless, it MUST
  27      be in GMT (Greenwich Mean Time). It will be reformatted into an
  28      RFC 1123-compliant date and used as the value of an If-Modified-Since
  29      request header.
  30  
  31      If the agent argument is supplied, it will be used as the value of a
  32      User-Agent request header.
  33  
  34      If the referrer argument is supplied, it will be used as the value of a
  35      Referer[sic] request header.
  36  
  37      If handlers is supplied, it is a list of handlers used to build a
  38      urllib2 opener.
  39  
  40      if request_headers is supplied it is a dictionary of HTTP request headers
  41      that will override the values generated by FeedParser.
  42  
  43      :return: A bytes object.
  44      �readr)r�https�ftp�file�feed�rbN�utf-8)�hasattrr�
  45  isinstance�str�urllib�parse�urlparser�get�open�IOError�UnicodeEncodeError�	TypeError�
  46  ValueError�bytes�encode)
  47  �url_file_stream_or_string�etag�modified�agent�referrer�handlers�request_headers�result�f�data�r2�DC:\Users\shubh\Videos\agent\nova\Lib\site-packages\feedparser/api.py�_open_resourceLs$
  48  "
  49  
  50  ����
  51  
  52  r4�LooseFeedParser�StrictFeedParserc
  53  
  54  Cs�|r
  55  |	dus
  56  |durddl}
  57  |s|
  58  j}|	dur|
  59  j}	|dur!|
  60  j}tdgt�id�}z
  61  t||||||||�}WntjjyU}
  62  z|�	d|
  63  d��|WYd}
  64  ~
  65  Sd}
  66  ~
  67  ww|sZ|S|d�	|pai�t
  68  |d||�}|drqdprd}t|�\|d	<}}|d�d
  69  d�}|�dd�}t
  70  ||�p�t
  71  |�p�|}|d�d
  72  d�}t|t�r�|dur�|�dd�}ts�d}|�r(t||d�}
  73  ||
  74  _|	|
  75  _tj�t�}|�tjjjd�z|�tjjjd�Wntjjy�Ynw|�|
  76  �|�|
  77  �tjj �!�}|�"t#�$|��z|�%|�Wn#tjj&�y'}zd|d<|
  78  j'�p||d<d}WYd}~nd}~ww|�sAt(||d|�}
  79  ||
  80  _|	|
  81  _|
  82  �)|�dd��|
  83  j*|d<|
  84  j+|d<|d	�pR|
  85  j,|d	<|
  86  j-|d<|S)a�Parse a feed from a URL, file, stream, or string.
  87  
  88      :param url_file_stream_or_string:
  89          File-like object, URL, file path, or string. Both byte and text strings
  90          are accepted. If necessary, encoding will be derived from the response
  91          headers or automatically detected.
  92  
  93          Note that strings may trigger network I/O or filesystem access
  94          depending on the value. Wrap an untrusted string in
  95          a :class:`io.StringIO` or :class:`io.BytesIO` to avoid this. Do not
  96          pass untrusted strings to this function.
  97  
  98          When a URL is not passed the feed location to use in relative URL
  99          resolution should be passed in the ``Content-Location`` response header
 100          (see ``response_headers`` below).
 101  
 102      :param str etag: HTTP ``ETag`` request header.
 103      :param modified: HTTP ``Last-Modified`` request header.
 104      :type modified: :class:`str`, :class:`time.struct_time` 9-tuple, or
 105          :class:`datetime.datetime`
 106      :param str agent: HTTP ``User-Agent`` request header, which defaults to
 107          the value of :data:`feedparser.USER_AGENT`.
 108      :param referrer: HTTP ``Referer`` [sic] request header.
 109      :param request_headers:
 110          A mapping of HTTP header name to HTTP header value to add to the
 111          request, overriding internally generated values.
 112      :type request_headers: :class:`dict` mapping :class:`str` to :class:`str`
 113      :param response_headers:
 114          A mapping of HTTP header name to HTTP header value. Multiple values may
 115          be joined with a comma. If a HTTP request was made, these headers
 116          override any matching headers in the response. Otherwise this specifies
 117          the entirety of the response headers.
 118      :type response_headers: :class:`dict` mapping :class:`str` to :class:`str`
 119  
 120      :param bool resolve_relative_uris:
 121          Should feedparser attempt to resolve relative URIs absolute ones within
 122          HTML content?  Defaults to the value of
 123          :data:`feedparser.RESOLVE_RELATIVE_URIS`, which is ``True``.
 124      :param bool sanitize_html:
 125          Should feedparser skip HTML sanitization? Only disable this if you know
 126          what you are doing!  Defaults to the value of
 127          :data:`feedparser.SANITIZE_HTML`, which is ``True``.
 128  
 129      :return: A :class:`FeedParserDict`.
 130      NrF)�bozo�entriesr�headersT)r7�bozo_exceptionr9�encoding�versionzcontent-locationr�hrefzcontent-languager�ignorerr7r:�replacerr8�
 131  namespaces).�
 132  feedparserZ
 133  USER_AGENTZ
 134  SANITIZE_HTMLZRESOLVE_RELATIVE_URISrr4r�error�URLError�updaterr
 135  r rrr&�decode�_XML_AVAILABLEr6�resolve_relative_uris�
 136  sanitize_html�xml�saxZmake_parser�PREFERRED_XML_PARSERSZ
 137  setFeature�handlerZfeature_namespacesZfeature_external_gesZSAXNotSupportedExceptionZsetContentHandlerZsetErrorHandlerZ	xmlreaderZInputSourceZ
 138  setByteStream�io�BytesIOrZSAXException�excr5rZfeeddatar8r<Znamespaces_in_use)r(r)r*r+r,r-r.�response_headersrGrHrAr/r1rBZuse_strict_parser�entitiesZ
 139  contentlocr=ZbaseuriZbaselangZ	saxparser�source�er2r2r3r�s�/�����
 140  
 141  ��
 142  
 143  
 144  r)	NNNNNNNNN)*rM�urllib.errorr�urllib.parseZxml.saxrIZ	datetimesrr�	encodingsr�
 145  exceptions�htmlrrrr	r
 146  Z
 147  parsers.looserZparsers.strictrZ	sanitizerr
 148  Zsgml�urlsrr�utilrrKrFZSUPPORTED_VERSIONSr4�type�objectr5rJrLZContentHandlerr6rr2r2r2r3�<module>s���������	�
 149  ���
 150  ����?
 151  ��