This file is indexed.

/usr/share/pyshared/cherrypy/config.py is in python-cherrypy 2.3.0-3build1.

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
"""Configuration system for CherryPy."""

import ConfigParser
import os

import cherrypy
from cherrypy import _cputil
from cherrypy.lib import autoreload, cptools, httptools


# This configs dict holds the settings metadata for all cherrypy objects.
# Keys are URL paths, and values are dicts.
configs = {}
configMap = configs # Backward compatibility

default_global = {
    'server.socket_port': 8080,
    'server.socket_host': '',
    'server.socket_file': '',
    'server.socket_queue_size': 5,
    'server.socket_timeout': 10,
    'server.protocol_version': 'HTTP/1.0',
    'server.log_to_screen': True,
    'server.log_tracebacks': True,
    'server.log_file': '',
    'server.reverse_dns': False,
    'server.thread_pool': 10,
    'server.environment': "development",
    
    '/favicon.ico': {
        'static_filter.on': True,
        'static_filter.file': os.path.join(os.path.dirname(__file__), "favicon.ico"),}
    }

environments = {
    "development": {
        'autoreload.on': True,
        'log_debug_info_filter.on': True,
        'server.log_file_not_found': True,
        'server.show_tracebacks': True,
        'server.log_request_headers': True,
        },
    "staging": {
        'autoreload.on': False,
        'log_debug_info_filter.on': False,
        'server.log_file_not_found': False,
        'server.show_tracebacks': False,
        'server.log_request_headers': False,
        },
    "production": {
        'autoreload.on': False,
        'log_debug_info_filter.on': False,
        'server.log_file_not_found': False,
        'server.show_tracebacks': False,
        'server.log_request_headers': False,
        },
    "embedded": {
        'autoreload.on': False,
        'server.log_to_screen': False,
        'server.init_only': True,
        'server.class': None,
        },
    }

def update(updateMap=None, file=None, overwrite=True, baseurl=""):
    """Update configs from a dictionary or a config file.
    
    If overwrite is False then the update will not modify values
    already defined in the configs.
    """
    if updateMap is None:
        updateMap = {}
    
    if file:
        if file not in autoreload.reloadFiles:
            autoreload.reloadFiles.append(file)
        updateMap = updateMap.copy()
        updateMap.update(dict_from_config_file(file))
    
    # Load new conf into cherrypy.configs
    for section, valueMap in updateMap.iteritems():
        # Handle shortcut syntax for "global" section
        #   example: update({'server.socket_port': 80})
        if not isinstance(valueMap, dict):
            valueMap = {section: valueMap}
            section = 'global'
        
        if baseurl and section.startswith("/"):
            if section == "/":
                section = baseurl
            else:
                section = httptools.urljoin(baseurl, section)
        
        bucket = configs.setdefault(section, {})
        if overwrite:
            bucket.update(valueMap)
        else:
            for key, value in valueMap.iteritems():
                bucket.setdefault(key, value)

def reset(useDefaults=True):
    """Clear configuration and restore defaults"""
    configs.clear()
    if useDefaults:
        update(default_global)
reset()

def get(key, default_value=None, return_section=False, path = None):
    """Return the configuration value corresponding to key
    If specified, return default_value on lookup failure. If return_section is
    specified, return the path to the value, instead of the value itself.
    """
    
    if path is None:
        try:
            path = cherrypy.request.object_path
        except AttributeError:
            # There's no request.object_path yet, so use the global settings.
            path = "global"
    
    while True:
        if path == "":
            path = "/"
        
        if cherrypy.lowercase_api is False:
            # We don't know for sure if user uses the new lowercase API
            try:
                result = configs[path][_cputil.lower_to_camel(key)]
                break
            except KeyError:
                try:
                    result = configs[path][key]
                    break
                except KeyError:
                    pass
                pass
            
            try:
                # Check for a server.environment entry at this node.
                env = configs[path]["server.environment"]
                # For backward compatibility, check for camelCase key first
                result = environments[env][_cputil.lower_to_camel(key)]
                break
            except KeyError:
                try:
                    env = configs[path]["server.environment"]
                    result = environments[env][key]
                    break
                except KeyError:
                    pass
                pass
        else:
            # We know for sure that user uses the new lowercase api
            try:
                result = configs[path][key]
                break
            except KeyError:
                pass
            
            try:
                env = configs[path]["server.environment"]
                result = environments[env][key]
                break
            except KeyError:
                pass
            pass

        if path == "global":
            result = default_value
            break
        
        # Move one node up the tree and try again.
        if path == "/":
            path = "global"
        elif path in cherrypy.tree.mount_points:
            # We've reached the mount point for an application,
            # and should skip the rest of the tree (up to "global").
            path = "global"
        else:
            path = path[:path.rfind("/")]
    
    if return_section:
        return path
    else:
        return result

def getAll(key):
    """Return a list of (path, value) pairs for current node and all parents."""
    try:
        results = [('global', configs['global'][key])]
    except KeyError:
        results = []
    
    try:
        path = cherrypy.request.object_path
    except AttributeError:
        return results
    
    try:
        results.append(('/', configs['/'][key]))
    except KeyError:
        pass
    
    atoms = path.strip('/').split('/')
    path = ""
    for atom in atoms:
        path = path + "/" + atom
        try:
            results.append((path, configs[path][key]))
        except KeyError:
            pass
    
    return results


class CaseSensitiveConfigParser(ConfigParser.ConfigParser):
    """Sub-class of ConfigParser that keeps the case of options and that raises
    an exception if the file cannot be read.
    """
    
    def optionxform(self, optionstr):
        return optionstr
    
    def read(self, filenames):
        if isinstance(filenames, basestring):
            filenames = [filenames]
        for filename in filenames:
            # try:
            #     fp = open(filename)
            # except IOError:
            #     continue
            fp = open(filename)
            try:
                self._read(fp, filename)
            finally:
                fp.close()

def dict_from_config_file(configFile, raw=False, vars=None):
    """Convert an INI file to a dictionary"""
    
    # Parse config file
    configParser = CaseSensitiveConfigParser()
    if hasattr(configFile, 'read'):
        configParser.readfp(configFile)
    else:
        configParser.read(configFile)
    
    # Load INI file into a dict
    result = {}
    for section in configParser.sections():
        if section not in result:
            result[section] = {}
        for option in configParser.options(section):
            value = configParser.get(section, option, raw, vars)
            try:
                value = cptools.unrepr(value)
            except Exception, x:
                msg = ("section: %s, option: %s, value: %s" %
                       (repr(section), repr(option), repr(value)))
                e = cherrypy.WrongConfigValue(msg)
                e.args += (x.__class__.__name__, x.args)
                raise e
            result[section][option] = value
    return result


def outputConfigMap():
    """Log server configuration parameters"""
    cherrypy.log("Server parameters:", 'CONFIG')
    
    serverVars = [
                  'server.environment',
                  'server.log_to_screen',
                  'server.log_file',
                  'server.log_tracebacks',
                  'server.log_request_headers',
                  'server.protocol_version',
                  'server.socket_host',
                  'server.socket_port',
                  'server.socket_file',
                  'server.reverse_dns',
                  'server.socket_queue_size',
                  'server.thread_pool',
                 ]

    for var in serverVars:
        cherrypy.log("  %s: %s" % (var, get(var)), 'CONFIG')