/usr/lib/python2.7/dist-packages/pygopherd/fileext.py is in pygopherd 2.0.18.5.
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 | # pygopherd -- Gopher-based protocol server in Python
# module: File extension utility
# Copyright (C) 2002 John Goerzen
# <jgoerzen@complete.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import mimetypes
typemap = {}
def extcmp(x, y):
if x.count('.') > y.count('.'):
return 1
if x.count('.') < y.count('.'):
return -1
if len(x) > len(y):
return 1
if len(x) < len(y):
return -1
return cmp(x, y)
def extstrip(file, filetype):
"""Strips off the extension from file given type and returns the result.
Returns file unmodified if no action is possible."""
if not (filetype and typemap.has_key(filetype)):
return file
for possible in typemap[filetype]:
if file.endswith(possible):
extindex = file.rfind(possible)
return file[0:extindex]
return file
def init():
for fileext, filetype in mimetypes.types_map.items():
extlist = []
if typemap.has_key(filetype):
extlist = typemap[filetype]
baselist = []
# Add the basic extension.
baselist.append(fileext)
# Add it in all encoding flavors.
baselist.extend(
[fileext + enc for enc in mimetypes.encodings_map.keys()])
for shortsuff, longsuff in mimetypes.suffix_map.items():
if longsuff in baselist:
baselist.append(shortsuff)
extlist.extend(baselist)
extlist.sort(extcmp)
extlist.reverse()
typemap[filetype] = extlist
|