Changeset 5936
- Timestamp:
- Aug 17, 2007, 11:33:34 PM (17 years ago)
- Location:
- trunk/trac
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/trac/config.py
r5250 r5936 15 15 from ConfigParser import ConfigParser 16 16 import os 17 try:18 set19 except NameError:20 from sets import Set as set21 import sys22 17 23 18 from trac.core import ExtensionPoint, TracError 24 from trac.util importsorted19 from trac.util.compat import set, sorted 25 20 from trac.util.text import to_unicode, CRLF 26 from trac.util.compat import set, sorted27 21 28 22 __all__ = ['Configuration', 'Option', 'BoolOption', 'IntOption', 'ListOption', … … 163 157 sections.append((section, sorted(options))) 164 158 165 fileobj = file(self.filename, 'w')159 fileobj = open(self.filename, 'w') 166 160 try: 167 print>>fileobj, '# -*- coding: utf-8 -*-' 168 print>>fileobj 161 fileobj.write('# -*- coding: utf-8 -*-\n\n') 169 162 for section, options in sections: 170 print>>fileobj, '[%s]' % section163 fileobj.write('[%s]\n' % section) 171 164 for key, val in options: 172 165 if key in self[section].overridden: 173 print>>fileobj, '# %s = <set in global trac.ini>' % key166 fileobj.write('# %s = <inherited>\n' % key) 174 167 else: 175 168 val = val.replace(CRLF, '\n').replace('\n', '\n ') 176 print>>fileobj, '%s = %s' % \ 177 (key, to_unicode(val).encode('utf-8')) 178 print>>fileobj 169 fileobj.write('%s = %s\n' % ( 170 key, to_unicode(val).encode('utf-8') 171 )) 172 fileobj.write('\n') 179 173 finally: 180 174 fileobj.close() -
trunk/trac/context.py
r5837 r5936 1 1 # -*- coding: utf-8 -*- 2 2 # 3 # Copyright (C) 200 3-2007 Edgewall Software4 # Copyright (C) 200 3-2007 Christian Boos <cboos@neuf.fr>5 # Copyright (C) 200 3-2007 Alec Thomas <alec@swapoff.org>3 # Copyright (C) 2006-2007 Edgewall Software 4 # Copyright (C) 2006-2007 Alec Thomas <alec@swapoff.org> 5 # Copyright (C) 2007 Christian Boos <cboos@neuf.fr> 6 6 # All rights reserved. 7 7 # … … 56 56 def __init__(self, **kwargs): 57 57 self.__dict__.update(kwargs) 58 58 59 59 60 class Context(object): 60 61 """Base class for Wiki rendering contexts. -
trunk/trac/core.py
r5686 r5936 60 60 def extensions(self, component): 61 61 """Return a list of components that declare to implement the extension 62 point interface.""" 62 point interface. 63 """ 63 64 extensions = ComponentMeta._registry.get(self.interface, []) 64 65 return filter(None, [component.compmgr[cls] for cls in extensions]) … … 79 80 def __new__(cls, name, bases, d): 80 81 """Create the component class.""" 81 82 d['_implements'] = _implements[:]83 del _implements[:]84 82 85 83 new_class = type.__new__(cls, name, bases, d) … … 128 126 129 127 130 _implements = []131 132 def implements(*interfaces):133 """Can be used in the class definiton of `Component` subclasses to declare134 the extension points that are extended.135 """136 _implements.extend(interfaces)137 138 139 128 class Component(object): 140 129 """Base class for components. … … 164 153 return self 165 154 155 def implements(*interfaces): 156 """Can be used in the class definiton of `Component` subclasses to 157 declare the extension points that are extended. 158 """ 159 import sys 160 161 frame = sys._getframe(1) 162 locals_ = frame.f_locals 163 164 # Some sanity checks 165 assert locals_ is not frame.f_globals and '__module__' in locals_, \ 166 'implements() can only be used in a class definition' 167 168 locals_.setdefault('_implements', []).extend(interfaces) 169 implements = staticmethod(implements) 170 171 172 implements = Component.implements 173 166 174 167 175 class ComponentManager(object): … … 181 189 def __getitem__(self, cls): 182 190 """Activate the component instance for the given class, or return the 183 existing the instance if the component has already been activated.""" 191 existing the instance if the component has already been activated. 192 """ 184 193 if cls not in self.enabled: 185 194 self.enabled[cls] = self.is_component_enabled(cls)
Note:
See TracChangeset
for help on using the changeset viewer.