; w?c @sdZdkZdkZdkZdkZdkZdkZdkiZdk ii Z dk Z dk ZdZdeZdfdYZeZeieiegZeidfeidfeidfgZd dddd d d d ddg ZeidfeidfeidfeidfeidfeidfgZdfdYZdeeifdYZdeeifdYZde i fdYZ!dei"i#fdYZ$dZ%e&djo&eZ'e'i(ei)d e'GHndS(!s RSS.py by Mark Nottingham Classes for working with RSS channels as arbitrary data structures. Requires Python 2.2 or newer and PyXML 0.7.1 or newer. ChannelBase - Base class for RSS Channels. CollectionChannel - RSS Channel modeled as a URI-per-entry dictionary. TrackingChannel - RSS Channel modeled as an item-per-entry dictionary. RSSParser - Multi-format RSS/XML Parser. Typically, the *Channel clases will be most useful to developers. This library provides tools for working with RSS feeds as data structures. The core is an RSS parser capable of understanding most RSS formats, and a serializer that produces RSS1.0. The RSS channel itself can be represented as any arbitrary data structure; two such structures are provided both as examples and to service common usage. This approach allows channels to be manipulated and stored in a fashion that suits both their semantics and the applications that access them. Both the parser and the serializer have the following limitations: - RSS 1.0 "rich content" modules are not supported - RSS 0.9x features that rely on attributes are not supported - RDF is not understood; this library does not expose statements or understand RDF syntax beyond that documented in RSS1.0 (taking into account the previously listed limitations) The RSS format is made up of three metadata sections (channel, image, and textinput) and a list of items. Each individual metadata section and each item is passed around as an "item dictionary", which is a Python dictionary with (namespace, localname) tuples as keys. The values of the dictionaries are always strings; they may contain markup, which will be rendered into the RSS/XML when serialized. Individual items are found by using an "item identifier"; this is a channel-unique, string identifier for any given item. Item identifiers may be generated in a variety of ways, depending on the requirements of the channel. Certain types of channel metadata are automatically generated, and will not be returned or honored when accessed. They includes the "items", "image" and "textinput" children of the channel element. TODO: - any markup (and the content inside) in item or metadata children (e.g., HTML in a will be silently ignored. - test suite - a function (XPath-based?) to detect a channel's type and return the appropriate class. - pay attention to when appropriate. Ns0.44s,http://www.mnot.net/python/RSS.py?version=%ss _NamespaceMapcBs)tZdZdZdZdZRS(s Prefix <-> Namespace map. Hold prefix->namespace mappings, and generate new prefixes when necessary. Exposes prefix->URI map as attributes, URI->prefix through getPrefix(URI). cCsd|_h|_d|_d|_d|_d|_d|_d|_d|_ d |_ d |_ d |_ d |_ d |_d|_d|_d|_dS(Nis+http://www.w3.org/1999/02/22-rdf-syntax-ns#shttp://purl.org/rss/1.0/s&http://my.netscape.com/rdf/simple/0.9/s'http://purl.org/rss/1.0/modules/rss091/s http://purl.org/dc/elements/1.1/s(http://purl.org/rss/modules/syndication/s(http://purl.org/rss/1.0/modules/content/shttp://webself.net/mvcb/s(http://purl.org/rss/modules/aggregation/s)http://purl.org/rss/1.0/modules/annotate/s&http://my.theinfo.org/changed/1.0/rss/s'http://purl.org/rss/1.0/modules/companys&http://purl.org/rss/1.0/modules/event/s&http://purl.org/rss/1.0/modules/slash/shttp://www.w3.org/html4/(sselfs_nsIDs _prefixMapsrdfsrss10srss09srss091sdcssynscontentsadminsagsannotatescpscompanyseventsslashshtml(sself((s"/home/sfvlug/psyche/modules/RSS.pys__init__Vs"                cCs3||i|<|ddjo||i|~sN(sURIsselfsrss10sNones _prefixMapsKeyErrorsos_nsIDsdsinsertsjoinsmaps candidatesvaluess getPrefixssetattr(sselfsURIsds candidateso((s"/home/sfvlug/psyche/modules/RSS.pys getPrefixns(   (s__name__s __module__s__doc__s__init__s __setattr__s getPrefix(((s"/home/sfvlug/psyche/modules/RSS.pys _NamespaceMapMs   schannelsimagestextareasrsssitemsitemsstitleslinks descriptionsurlserrorReportsTosgeneratorAgents referencesservers ChannelBasecBswtZdZdZdZddZdZdZdZdd Z d Z d Z d Z d Z RS(s$ Base class for RSS Channels. A number of generic methods for accessing and setting channel data and metadata are exposed, for the benefit of subclasses. They may be used by applications as well, or the data structure of the subclass may be directly manipulated. cCs d|_dS(Nsutf-8(sselfsencoding(sself((s"/home/sfvlug/psyche/modules/RSS.pys__init__scCsdS(s8List the items in a channel, with a list of identifiers.N((sself((s"/home/sfvlug/psyche/modules/RSS.pys listItemssicCsdS(s7Add an item to the channel. Expects an item dictionary.N((sselfsitemsindex((s"/home/sfvlug/psyche/modules/RSS.pysaddItemscCsdS(s;Get the appropriate item dictionary for a given identifier.N((sselfs identifier((s"/home/sfvlug/psyche/modules/RSS.pysgetItemscCsdS(s Get the [name] metadata as an item dictionary, where type is a tuple (typically, in the ns:rss10 namespace, with a localname of channel|image|textinput). MUST return an empty dictionary if the metadata isn't found. N((sselfsname((s"/home/sfvlug/psyche/modules/RSS.pysgetMDscCsdS(s Set the [name] metadata, where name is a tuple (typically, it will be in the ns:rss10 namespace, and have a localname of channel|image|textinput), and metadata is an item dictionary. N((sselfsnamesmetadata((s"/home/sfvlug/psyche/modules/RSS.pyssetMDsicCst|}tii}|i||iti i dt i t i |i t i|z|it|Wdt idX|SdS(s] Fetch a channel representation from a URL and populate the channel. iNi(s RSSParsersselfsdhssaxssax2extss make_parserspssetContentHandlers setFeatureshandlersfeature_namespacesssignalsSIGALRMs_timeoutsalarmstimeoutsparsesstrsurl(sselfsurlstimeoutsdhsp((s"/home/sfvlug/psyche/modules/RSS.pysparses   cKs tddS(Nstimeout(sIOError(sselfsargs((s"/home/sfvlug/psyche/modules/RSS.pys_timeoutscCsSt|}tii}|i||iti i d|i ||SdS(s&Parse a file and populate the channel.iN( s RSSParsersselfsdhssaxssax2extss make_parserspssetContentHandlers setFeatureshandlersfeature_namespacess parseFilesfile(sselfsfilesdhsp((s"/home/sfvlug/psyche/modules/RSS.pys parseFiles   cCs|i|iSdS(N(sselfsoutputs listItems(sself((s"/home/sfvlug/psyche/modules/RSS.pys__str__sc Cs t|tijptdt|ti}t||i d} |i t i df}|i t i df}|i t i df}t|t idftZdZddZdZdZdZdZRS(sb Multi-format RSS/XML Parser. Parse XML into RSS Channel objects. May optionally be passed a Channel() instance to append to. Formats understood include: - RSS 0.9 - RSS 0.91 - RSS 0.92 - RSS 1.0 (EXCEPT "rich content" modules) "Core" RSS elements are normalized to the RSS1.0 namespace. sutf-8cCstiii|||_||_g|_h|_ht i dfh<t i dfh<t i dfh<|_ d|_ t |_dS(Nschannelsimages textinputs(ssaxshandlersContentHandlers__init__sselfschannelsencodings_contexts _tmp_itemsnssrss10s_tmp_mds_tmp_bufsNonesversion(sselfschannelsencoding((s"/home/sfvlug/psyche/modules/RSS.pys__init__.s    ? cCsK|ddjo;|dtjo|idt|_qL|d|_n|dtjo|dtjoti |df}n)|dtjoti |df}n|i i ||ti dfjoh|_ d|_n_t|i djo'|i dti dfjo |tjo|tidf|i |