/usr/share/pyshared/pyramid/asset.py is in python-pyramid 1.2.3+dfsg-1.
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 | import os
import pkg_resources
from pyramid.path import package_path
from pyramid.path import package_name
def resolve_asset_spec(spec, pname='__main__'):
if pname and not isinstance(pname, basestring):
pname = pname.__name__ # as package
if os.path.isabs(spec):
return None, spec
filename = spec
if ':' in spec:
pname, filename = spec.split(':', 1)
elif pname is None:
pname, filename = None, spec
return pname, filename
def asset_spec_from_abspath(abspath, package):
""" Try to convert an absolute path to a resource in a package to
a resource specification if possible; otherwise return the
absolute path. """
if getattr(package, '__name__', None) == '__main__':
return abspath
pp = package_path(package) + os.path.sep
if abspath.startswith(pp):
relpath = abspath[len(pp):]
return '%s:%s' % (package_name(package),
relpath.replace(os.path.sep, '/'))
return abspath
def abspath_from_asset_spec(spec, pname='__main__'):
if pname is None:
return spec
pname, filename = resolve_asset_spec(spec, pname)
if pname is None:
return filename
return pkg_resources.resource_filename(pname, filename)
|