home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1443 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.3 KB  |  49 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
  6. import re
  7. import imp
  8. import inspect
  9. import time
  10. import os
  11. from calibre.web.feeds.news import BasicNewsRecipe, CustomIndexRecipe, AutomaticNewsRecipe, CalibrePeriodical
  12. from calibre.ebooks.BeautifulSoup import BeautifulSoup
  13. from calibre.ptempfile import PersistentTemporaryDirectory
  14. from calibre import __appname__, english_sort
  15. (BeautifulSoup, time, english_sort)
  16. basic_recipes = (BasicNewsRecipe, AutomaticNewsRecipe, CustomIndexRecipe, CalibrePeriodical)
  17. _tdir = None
  18. _crep = 0
  19.  
  20. def compile_recipe(src):
  21.     global _tdir, _crep
  22.     if _tdir is None or not os.path.exists(_tdir):
  23.         _tdir = PersistentTemporaryDirectory('_recipes')
  24.     
  25.     temp = os.path.join(_tdir, 'recipe%d.py' % _crep)
  26.     _crep += 1
  27.     if not isinstance(src, unicode):
  28.         match = re.search('coding[:=]\\s*([-\\w.]+)', src[:200])
  29.         enc = None if match else 'utf-8'
  30.         src = src.decode(enc)
  31.     
  32.     src = re.sub('from __future__.*', '', src)
  33.     f = open(temp, 'wb')
  34.     src = 'from %s.web.feeds.news import BasicNewsRecipe, AutomaticNewsRecipe\n' % __appname__ + src
  35.     src = '# coding: utf-8\n' + src
  36.     src = 'from __future__ import with_statement\n' + src
  37.     src = src.replace('from libprs500', 'from calibre').encode('utf-8')
  38.     f.write(src)
  39.     f.close()
  40.     module = imp.find_module(os.path.splitext(os.path.basename(temp))[0], [
  41.         os.path.dirname(temp)])
  42.     module = imp.load_module(os.path.splitext(os.path.basename(temp))[0], *module)
  43.     classes = inspect.getmembers(module, (lambda x: if inspect.isclass(x) and issubclass(x, (BasicNewsRecipe,)):
  44. passx not in basic_recipes))
  45.     if not classes:
  46.         return None
  47.     return classes[0][1]
  48.  
  49.