def configure(self, request):
        form = FeedImportForm()

        if request.method == 'POST' and form.validate(request.form):
            feed = request.files.get('feed')
            if form.data['download_url']:
                if not form.data['download_url'].endswith('.tpxa'):
                    error = _(u"Don't pass a real feed URL, it should be a "
                              u"regular URL where you're serving the file "
                              u"generated with the textpress_exporter.py script")
                    flash(error, 'error')
                    return self.render_admin_page('import_textpress.html',
                                                  form=form.as_widget(),
                                                  bugs_link=BUGS_LINK)
                try:
                    feed = urllib.urlopen(form.data['download_url'])
                except Exception, e:
                    error = _(u'Error downloading from URL: %s') % e
                    flash(error, 'error')
                    return self.render_admin_page('import_textpress.html',
                                                  form=form.as_widget(),
                                                  bugs_link=BUGS_LINK)
            elif not feed:
                return redirect_to('import/feed')

            try:
                blog = parse_feed(feed)
            except Exception, e:
                log.exception(_(u'Error parsing uploaded file'))
                print repr(e)
                flash(_(u'Error parsing feed: %s') % e, 'error')
Example #2
0
 def process_result_value(self, value, dialect):
     from zine.utils.zeml import load_parser_data
     try:
         return load_parser_data(value)
     except ValueError: # Parser data invalid. Database corruption?
         from zine.i18n import _
         from zine.utils import log
         log.exception(_(u'Error when loading parsed data from database. '
                         u'Maybe the database was manually edited and got '
                         u'corrupted? The system returned an empty value.'))
         return {}
Example #3
0
 def process_result_value(self, value, dialect):
     from zine.utils.zeml import load_parser_data
     try:
         return load_parser_data(value)
     except ValueError: # Parser data invalid. Database corruption?
         from zine.i18n import _
         from zine.utils import log
         log.exception(_(u'Error when loading parsed data from database. '
                         u'Maybe the database was manually edited and got '
                         u'corrupted? The system returned an empty value.'))
         return {}
Example #4
0
    def configure(self, request):
        form = WordPressImportForm()

        if request.method == 'POST' and form.validate(request.form):
            dump = request.files.get('dump')
            if form.data['download_url']:
                try:
                    dump = open_url(form.data['download_url']).stream
                except Exception, e:
                    error = _(u'Error downloading from URL: %s') % e
            elif not dump:
                return redirect_to('import/wordpress')

            try:
                blog = parse_feed(dump)
            except Exception, e:
                log.exception(_(u'Error parsing uploaded file'))
                flash(_(u'Error parsing uploaded file: %s') % e, 'error')
Example #5
0
    def configure(self, request):
        form = FeedImportForm()

        if request.method == 'POST' and form.validate(request.form):
            feed = request.files.get('feed')
            if form.data['download_url']:
                try:
                    feed = open_url(form.data['download_url']).stream
                except Exception, e:
                    log.exception(_('Error downloading feed'))
                    flash(_(u'Error downloading from URL: %s') % e, 'error')
            if not feed:
                return redirect_to('import/feed')

            try:
                blog = parse_feed(feed)
            except Exception, e:
                log.exception(_(u'Error parsing uploaded file'))
                flash(_(u'Error parsing feed: %s') % e, 'error')
Example #6
0
    def configure(self, request):
        form = FeedImportForm()

        if request.method == 'POST' and form.validate(request.form):
            feed = request.files.get('feed')
            if form.data['download_url']:
                try:
                    feed = open_url(form.data['download_url']).stream
                except Exception, e:
                    log.exception(_('Error downloading feed'))
                    flash(_(u'Error downloading from URL: %s') % e, 'error')
            if not feed:
                return redirect_to('import/feed')

            try:
                blog = parse_feed(feed)
            except Exception, e:
                log.exception(_(u'Error parsing uploaded file'))
                flash(_(u'Error parsing feed: %s') % e, 'error')
Example #7
0
    def configure(self, request):
        form = WordPressImportForm()

        if request.method == 'POST' and form.validate(request.form):
            dump = request.files.get('dump')
            if form.data['download_url']:
                try:
                    dump = open_url(form.data['download_url']).stream
                except Exception, e:
                    log.exception(_('Error downloading feed'))
                    flash(_(u'Error downloading from URL: %s') % e, 'error')
            if not dump:
                return redirect_to('import/wordpress')

            try:
                blog = parse_feed(dump)
            except Exception, e:
                raise
                log.exception(_(u'Error parsing uploaded file'))
                flash(_(u'Error parsing uploaded file: %s') % e, 'error')
Example #8
0
def make_setup_error(exc_info=None):
    """Create a new SetupError for the last exception and log it."""
    if exc_info is None:
        exc_info = sys.exc_info()

    # log the exception
    log.exception(_(u"Plugin setup error"), "pluginsystem", exc_info)
    exc_type, exc_value, tb = exc_info

    # if the exception is already a SetupError we only
    # have to return it unchanged.
    if isinstance(exc_value, SetupError):
        return exc_value

    # otherwise create an error message for it and return a new
    # exception.
    error, (filename, line) = summarize_exception(exc_info)
    return SetupError(
        _(u"Exception happend on setup: " u"%(error)s (%(file)s, line %(line)d)")
        % {"error": escape(error), "file": filename, "line": line}
    )
Example #9
0
def make_setup_error(exc_info=None):
    """Create a new SetupError for the last exception and log it."""
    if exc_info is None:
        exc_info = sys.exc_info()

    # log the exception
    log.exception(_(u'Plugin setup error'), 'pluginsystem', exc_info)
    exc_type, exc_value, tb = exc_info

    # if the exception is already a SetupError we only
    # have to return it unchanged.
    if isinstance(exc_value, SetupError):
        return exc_value

    # otherwise create an error message for it and return a new
    # exception.
    error, (filename, line) = summarize_exception(exc_info)
    return SetupError(
        _(u'Exception happend on setup: '
          u'%(error)s (%(file)s, line %(line)d)') % {
              'error': escape(error),
              'file': filename,
              'line': line
          })
Example #10
0
        XML-RPC methods are dispatched from the marshalled (XML) data
        using the _dispatch method and the result is returned as
        marshalled data.
        """
        try:
            params, method = xmlrpclib.loads(data)
            response = xmlrpclib.dumps((self._wrap_obj(self._dispatch(method, params)),),
                                       methodresponse=True, allow_none=True,
                                       encoding=self.charset)
        except xmlrpclib.Fault, fault:
            response = xmlrpclib.dumps(fault, allow_none=self.allow_none,
                                       encoding=self.charset)
        except:
            exc_type, exc_value, tb = exc_info = sys.exc_info()
            log.exception('Exception in XMLRPC request:', 'xmlrpc', exc_info)
            response = xmlrpclib.dumps(
                xmlrpclib.Fault(1, '%s:%s' % (exc_type, exc_value)),
                encoding=self.charset, allow_none=self.allow_none
            )

        return response

    def handle_request(self, request):
        if request.method == 'POST':
            response = self._marshaled_dispatch(request.data)
            return BaseResponse(response, mimetype='application/xml')
        return BaseResponse('\n'.join((
            '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">',
            '<title>XMLRPC Interface</title>',
            '<h1>XMLRPC Interface</h1>',
Example #11
0
        marshalled data.
        """
        try:
            params, method = xmlrpclib.loads(data)
            response = xmlrpclib.dumps(
                (self._wrap_obj(self._dispatch(method, params)), ),
                methodresponse=True,
                allow_none=True,
                encoding=self.charset)
        except xmlrpclib.Fault, fault:
            response = xmlrpclib.dumps(fault,
                                       allow_none=self.allow_none,
                                       encoding=self.charset)
        except:
            exc_type, exc_value, tb = exc_info = sys.exc_info()
            log.exception('Exception in XMLRPC request:', 'xmlrpc', exc_info)
            response = xmlrpclib.dumps(xmlrpclib.Fault(
                1, '%s:%s' % (exc_type, exc_value)),
                                       encoding=self.charset,
                                       allow_none=self.allow_none)

        return response

    def handle_request(self, request):
        if request.method == 'POST':
            response = self._marshaled_dispatch(request.data)
            return BaseResponse(response, mimetype='application/xml')
        return BaseResponse(
            '\n'.join(
                ('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">',
                 '<title>XMLRPC Interface</title>',