This file is indexed.

/usr/lib/python2.7/dist-packages/svnmailer/browser.py is in svnmailer 1.0.9-3.

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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# -*- coding: utf-8 -*-
#
# Copyright 2005-2006 André Malo or his licensors, as applicable
#
# 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.
"""
Respository Browser URL construction
"""
__author__    = "André Malo"
__docformat__ = "epytext en"
__all__       = ['getBrowserUrlGenerator']


# Exceptions
class Error(Exception):
    """ Base exception for this module """
    pass

class InvalidBaseUrlError(Error):
    """ Invalid URL was configured """
    pass


def getBrowserUrlGenerator(config):
    """ Returns an initialized repos browser generator

        @param config: The group configuration
        @type config: C{svnmailer.settings.GroupSettingsContainer}

        @return: The generator object or C{None}
        @rtype: C{object}
    """
    if config.browser_base_url:
        b_type, base_url = parseBrowserBase(config.browser_base_url)

        if b_type == "viewcvs":
            return ViewcvsGenerator(base_url)
        elif b_type == "websvn":
            return WebsvnGenerator(base_url)

    elif config.viewcvs_base_url:
        return ViewcvsGenerator(config.viewcvs_base_url)

    return None


def parseBrowserBase(base_config):
    """ Parses the given option value into type and base url

        @param base_config: The option value
        @type base_config: C{str}

        @return: The type and the base url
        @rtype: C{tuple}
    """
    if base_config:
        tokens = base_config.split(None, 1)
        if len(tokens) == 2:
            return (tokens[0].lower(), tokens[1])

    return (None, None)


class ParsedUrl(object):
    """ Container for URL parsing and modification

        @ivar scheme: The scheme
        @type scheme: C{str}
        
        @ivar netloc: The netloc
        @type netloc: C{str}
        
        @ivar path: The path
        @type path: C{str}
        
        @ivar param: The path param
        @type param:C{str}
        
        @ivar query: The query string
        @type query: C{str}
        
        @ivar fragment: The fragment
        @type fragment: C{str}
    """

    def __init__(self, url):
        """ Initialization """
        import urlparse

        (self.scheme, self.netloc, self.path, self.param, self.query,
         self.fragment) = urlparse.urlparse(url)


    def __str__(self):
        """ Returns the URL as string

            @return: The URL as string
            @rtype: C{str}
        """
        import urlparse

        return urlparse.urlunparse((
            self.scheme, self.netloc, self.path, self.param, self.query,
            self.fragment
        ))


class ViewcvsGenerator(object):
    """ viewcvs generator

        @ivar base: The base url
        @type base: C{str}
    """

    def __init__(self, base):
        """ Initialization

            @param base: The base url
            @type base: C{str}
        """
        self.base = base


    def getRevisionUrl(self, revision):
        """ Returns the revision summary URL

            @param revision: The revision number
            @type revision: C{int}

            @return: The url
            @rtype: C{str}
        """
        import urllib
        from svnmailer import util

        url = ParsedUrl(self.base)

        while url.path[-1:] == '/':
            url.path = url.path[:-1]

        url.query = util.modifyQuery(url.query,
            rem = ['p1', 'p2', 'r1', 'r2'],
            set = [
                ('view', 'rev'),
                ('rev', urllib.quote(str(revision))),
            ]
        )

        return str(url)


    def getContentDiffUrl(self, change):
        """ Returns the content diff url for a particular change

            @param change: The change to process
            @type change: C{svnmailer.subversion.VersionedPathDescriptor}
        """
        import urllib, posixpath
        from svnmailer import util

        url = ParsedUrl(self.base)

        url.path = posixpath.join(url.path, urllib.quote((
            change.wasDeleted() and [change.getBasePath()] or [change.path]
        )[0]))

        if change.isDirectory():
            url.path = "%s/" % url.path

        if change.wasDeleted():
            url.query = util.modifyQuery(url.query,
                rem = ['p1', 'p2', 'r1', 'r2'],
                set = [
                    ('view', 'auto'),
                    ('rev',  urllib.quote(str(change.getBaseRevision()))),
                ]
            )

        elif change.wasCopied():
            if change.isDirectory():
                return None # no text changes

            url.query = util.modifyQuery(url.query, set = [
                ('view', 'diff'),
                ('rev',  urllib.quote(str(change.revision))),
                ('p1',   urllib.quote(change.getBasePath())),
                ('r1',   urllib.quote(str(change.getBaseRevision()))),
                ('p2',   urllib.quote(change.path)),
                ('r2',   urllib.quote(str(change.revision))),
            ])

        elif change.wasAdded():
            url.query = util.modifyQuery(url.query,
                rem = ['p1', 'p2', 'r1', 'r2'],
                set = [
                    ('view', 'auto'),
                    ('rev',  urllib.quote(str(change.revision))),
                ]
            )

        else: # modified
            if change.isDirectory():
                return None # no text changes

            url.query = util.modifyQuery(url.query,
                rem = ['p1', 'p2'],
                set = [
                    ('view', 'diff'),
                    ('rev',  urllib.quote(str(change.revision))),
                    ('r1',   urllib.quote(str(change.getBaseRevision()))),
                    ('r2',   urllib.quote(str(change.revision))),
                ]
            )

        return str(url)


class WebsvnGenerator(object):
    """ websvn generator

        @ivar base: The base url
        @type base: C{str}
    """

    def __init__(self, base):
        """ Initialization

            @param base: The base url
            @type base: C{str}
        """
        self.base = base


    def getRevisionUrl(self, revision):
        """ Returns the revision summary URL

            @param revision: The revision number
            @type revision: C{int}

            @return: The url
            @rtype: C{str}
        """
        import urllib, posixpath
        from svnmailer import util

        url = ParsedUrl(self.base)
        parsed_query = util.parseQuery(url.query)

        # no path info...
        if parsed_query.has_key("repname"):
            dirname, basename = posixpath.split(url.path)
            if not basename:
                raise InvalidBaseUrlError("Missing PHP file...?")

            url.path = posixpath.join(dirname, 'listing.php')

        # path info configured
        else:
            while url.path[-1:] == '/':
                url.path = url.path[:-1]
            url.path = "%s/" % url.path

        url.query = util.modifyQuery(parsed_query,
            rem = ['path'],
            set = [
                ('sc', '1'),
                ('rev', urllib.quote(str(revision))),
            ]
        )

        return str(url)


    def getContentDiffUrl(self, change):
        """ Returns the content diff url for a particular change

            @param change: The change to process
            @type change: C{svnmailer.subversion.VersionedPathDescriptor}
        """
        import urllib, posixpath
        from svnmailer import util

        if change.isDirectory() and not change.wasDeleted() and (
                not change.wasAdded() or change.wasCopied()):
            # show only a directory URL on adding and deleting
            return

        url = ParsedUrl(self.base)
        parsed_query = util.parseQuery(url.query)
        cpath = urllib.quote("%s%s" % (
            (change.wasDeleted() and
                [change.getBasePath()] or [change.path])[0],
            ["", "/"][change.isDirectory()]
        ))

        toset = [("rev", urllib.quote(str((change.wasDeleted() and
            [change.getBaseRevision()] or [change.revision]
        )[0])))]

        if parsed_query.has_key("repname"):
            dirname, basename = posixpath.split(url.path)
            if not basename:
                raise InvalidBaseUrlError(
                    "Missing PHP file in '%s'?" % self.base
                )

            url.query = util.modifyQuery(parsed_query,
                set = [('path', "/%s" % cpath)]
            )
            url.path = dirname
            cpath = ["diff.php", ["filedetails.php", "listing.php"]
                    [change.isDirectory()]][
                        change.wasDeleted() or (
                        change.wasAdded() and not change.wasCopied())
                    ]

        else:
            toset.append(("op",
                ["diff", ["file", "dir"][change.isDirectory()]][
                    change.wasDeleted() or (
                    change.wasAdded() and not change.wasCopied())
                ]
            ))

        url.path = posixpath.join(url.path, cpath)
        url.query = util.modifyQuery(url.query, rem = ["sc"], set = toset)

        return str(url)