~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/media.py

  • Committer: David Coles
  • Date: 2010-08-30 03:26:13 UTC
  • Revision ID: coles.david@gmail.com-20100830032613-d14vng0jkelniu3l
python-console: Fix globals broken with new JSON library.

simplejson always returns unicode strings. cJSON would return ordinary strings 
if possible. cPickle.loads() only accepts strings. At present we use pickle 
version 0 so they should all works as ASCII strings. Higher versions of pickle 
are not plain ASCII and are likely to break this and so this should be fixed 
at some point.

Also replaced unconditional exception with one that catches Pickle errors. Not 
sure the best way to report failures of these functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
# This maps a media namespace to an external dependency directory (in this
35
35
# case specified by the configuration option media/externals/jquery) and a
36
36
# list of permitted subpaths.
37
 
EXTERNAL_MEDIA_MAP = {'jquery': ('jquery', ['jquery.js'])}
 
37
EXTERNAL_MEDIA_MAP = {'jquery': ('jquery', ['jquery.js']),
 
38
                      'codemirror': ('codemirror', None),
 
39
                      }
38
40
 
39
41
def media_url(req, plugin, path):
40
42
    '''Generates a URL to a media file.
70
72
                return None
71
73
 
72
74
            # Unless it's a whitelisted path, we don't want to hear about it.
73
 
            if self.path not in extern[1]:
 
75
            # If the whitelist is None (not []), we allow all.
 
76
            if extern[1] is not None and self.path not in extern[1]:
74
77
                return None
75
78
 
76
79
            # Grab the admin-configured path for this particular external dep.
94
97
            return os.path.join(plugindir, mediadir, self.path)
95
98
 
96
99
class MediaFileView(BaseView):
97
 
    permission = None
 
100
    def authorize(self, req):
 
101
        return True
98
102
 
99
103
    def render(self, req):
100
104
        # If it begins with ".." or separator, it's illegal. Die.
130
134
    def get_filename(self, req):
131
135
        return self.context.filename
132
136
 
133
 
    def get_permissions(self, user):
134
 
        return set()
135
 
 
136
137
def root_to_media(root, *segments):
137
138
    if segments[0].startswith('+'):
138
139
        if segments[0] == '+external':