#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Scour Web
#
# Copyright 2009 Jeff Schiller
#
# This file is part of Scour, http://www.codedread.com/scour/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from mod_python import apache
from mod_python import util
from scour import scourString
from optparse import OptionParser
def form(req):
return """
Scrape Your SVG Files
"""
# defaults
class ScourOptions:
simple_colors = True
style_to_xml = True
group_collapse = True
strip_ids = False
digits = 5
embed_rasters = False
keep_editor_data = False
strip_xml_prolog = False
indent_type = "space"
# params are the form elements (if a checkbox is unchecked it will not be present)
def fetch(req, indoc,**params):
req.content_type = "image/svg+xml"
fs = req.form
options = ScourOptions()
# interpret form options
if not params.has_key('convertStyleToXml'):
options.style_to_xml = False
if not params.has_key('collapseGroups'):
options.group_collapse = False
if params.has_key('stripIds'):
options.strip_ids = True
if not params.has_key('simplifyColors'):
options.simple_colors = False
if params.has_key('stripXmlProlog'):
options.strip_xml_prolog = True
options.digits = int(params['digits'])
fileitem = fs['upload']
if fileitem.filename:
req.write(scourString(fileitem.file.read(), options))
else:
req.write(scourString(indoc,options))