/usr/share/pyshared/PyritePublisher/plugin_URLStream.py is in pyrite-publisher 2.1.1-8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | #
# $Id: plugin_URLStream.py,v 1.1 2002/03/28 04:55:14 rob Exp $
#
# Copyright 2001 Rob Tillotson <rob@pyrite.org>
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee or royalty is
# hereby granted, provided that the above copyright notice appear in
# all copies and that both the copyright notice and this permission
# notice appear in supporting documentation or portions thereof,
# including modifications, that you you make.
#
# THE AUTHOR ROB TILLOTSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE!
#
"""
"""
__version__ = '$Id: plugin_URLStream.py,v 1.1 2002/03/28 04:55:14 rob Exp $'
__author__ = 'Rob Tillotson <rob@pyrite.org>'
__copyright__ = 'Copyright 2001 Rob Tillotson <rob@pyrite.org>'
import sys, os, urlparse, mimetypes, re, urllib, tempfile
from dtkplugins import InputPlugin
from dtkmain import ConversionError
class Plugin(InputPlugin):
name = 'URLStream'
description = 'Gets input from a file or URL.'
def __init__(self, *a, **kw):
apply(InputPlugin.__init__, (self,)+a, kw)
self.f = None
self.generic_mimetypes = ["text/plain", "application/octet-stream"]
self._temp_file_name = ''
def handles_filename(self, fn):
return 1
def open_input(self, fn):
# On win32, trying to urlopen a name with a drive-letter in it
# fails, since it thinks the drive-letter is a protocol like
# "http:" or "ftp:", so we handle these names separately.
if sys.platform == 'win32' and re.match('^[a-zA-Z]:', fn):
f = open(fn)
else:
f = urllib.urlopen(fn) # raises IOError if fails
n, ext = os.path.splitext(os.path.basename(fn))
if ext == '.gz':
f = GzipFile(filename="", mode="rb", fileobj=f)
n, ext = os.path.splitext(n)
self.f = f
try: # some type of URL don't have this
mtype = f.info()["Content-Type"]
except:
mtype = "application/octet-stream"
mtypes = [mtype]
if mtype[:5] == "text/":
mtypes.append("application/octet-stream")
# try guessing a type if it is text/plain or application/octet-stream
if mtype in self.generic_mimetypes:
gtype, genc = mimetypes.guess_type(n+ext)
if gtype and gtype not in mtypes:
mtypes.insert(0, gtype)
# add types we can filter to
mt0 = []
for intype, outtype in self.api.input_filters.keys():
if intype in mtypes and outtype not in mtypes:
mt0.append(outtype)
self._unfiltered_types = mtypes
self._filtered_types = mt0
mtypes = mtypes + mt0
if not n: # handle urls with no path
up = urlparse.urlparse(fn)
n = up[1]
return mtypes, os.path.basename(n)
def close_input(self):
if self.f is not None: self.f.close()
if self._temp_file_name: os.unlink(self._temp_file_name)
self.f = None
def go(self, mimetype):
if mimetype in self._filtered_types:
for t in self._unfiltered_types:
if self.api.input_filters.has_key((t,mimetype)):
filterprog = self.api.input_filters[(t,mimetype)]
tfn = tempfile.mktemp()
tf = open(tfn,'wb')
tf.write(self.f.read())
tf.close()
self._temp_file_name = tfn
self.f = os.popen(filterprog % tfn, 'r')
break
while 1:
l = self.f.readline()
if not l: break
self.next.feed(l)
self.next.eof()
|