def __init__(self, identifier, enc, filters): try: self.context = misc.getClassByName(identifier) self.type = 2 except: self.context = identifier if identifier[-4:] == '.psp': self.type = 1 else: self.type = 0 self.encoding = enc self.filters = [misc.getClassByName(filter) for filter in filters]
def setParams(self): self.response.setHeader('cache-control', 'no-cache') self.response.setExpiration(1200) sLang = self.request.getLang() sCC = self.request.queryString['cc'][0] oNewItem = misc.getClassByName(sCC)() self.params = { 'TITLE': '%s "%s"' % (self.server.resources.getResource('CREATE', sLang), self.server.resources.getResource(oNewItem.contentclass, sLang)), 'CREATE': self.server.resources.getResource('CREATE', sLang), 'CANCEL': self.server.resources.getResource('CANCEL', sLang), 'CC': sCC, 'URI': self.request.serverVariables['SCRIPT_NAME'] + '/' + self.item.id, 'ICON': oNewItem.__image__, 'PROPERTIES_TAB': '', 'EXTRA_TABS': '', 'SECURITY_TAB': self.getSecurity(self.item, True) } # inspect item properties sProperties = '' for attr_name in oNewItem.__props__: attr = getattr(oNewItem, attr_name) if isinstance(attr, datatypes.DataType): control, tab = self.getControlFromAttribute(attr_name, attr, False, True) sProperties += control self.params['EXTRA_TABS'] += tab self.params['PROPERTIES_TAB'] = '<a:tab caption="%s">%s</a:tab>' % (self.server.resources.getResource('PROPERTIES', sLang), sProperties)
def getInfo(self): sLang = self.request.getLang() lstChildren = [] children = self.item.getChildren() for child in children: obj = { 'id' : child.id, 'image': child.__image__, 'displayName' : child.displayName.value, 'isCollection': child.isCollection, 'modified': date.Date(child.modified) } if hasattr(child, 'size'): obj['size'] = child.size lstChildren.append(obj) containment = [] for contained in self.item.containment: image = misc.getClassByName(contained).__image__ if not type(image)==str: image = '' localestring = self.server.resources.getResource(contained, sLang) containment.append( [localestring, contained, image] ) return { 'displayName': self.item.displayName.value, 'path': misc.getFullPath(self.item), 'parentid': self.item.parentid, 'iscollection': self.item.isCollection, 'containment': containment, 'user_role': objectAccess.getAccess(self.item, self.session.user), 'contents': lstChildren }
def create(self, data): # create new item oNewItem = misc.getClassByName(data.pop('CC'))() # get user role iUserRole = objectAccess.getAccess(self.item, self.session.user) if data.has_key('__rolesinherited') and iUserRole == objectAccess.COORDINATOR: oNewItem.inheritRoles = data.pop('__rolesinherited') if not oNewItem.inheritRoles: acl = data.pop('__acl') if acl: security = {} for descriptor in acl: security[descriptor['id']] = int(descriptor['role']) oNewItem.security = security # set props for prop in data: oAttr = getattr(oNewItem, prop) if isinstance(oAttr, datatypes.File): if data[prop]['tempfile']: oAttr.filename = data[prop]['filename'] sPath = self.server.temp_folder + '/' + data[prop]['tempfile'] oAttr.loadFromFile(sPath) os.remove(sPath) elif isinstance(oAttr, datatypes.Date): oAttr.value = data[prop].value else: oAttr.value = data[prop] txn = self.server.store.getTransaction() oNewItem.appendTo(self.item.id, txn) txn.commit() return True
def commitChanges(self): GenericSchemaEditor.commitChanges(self) if len(self._addedProps): #we must reload the class module oMod = misc.getClassByName(self._class.__module__) reload(oMod) from porcupine.oql.command import OqlCommand db = offlinedb.getHandle() oql_command = OqlCommand() rs = oql_command.execute( "select * from deep('/') where instanceof('%s')" % self._instance.contentclass) try: if len(rs): txn = offlinedb.OfflineTransaction() try: for item in rs: for name in self._addedProps: if not hasattr(item, name): setattr(item, name, self._addedProps[name]) db.putItem(item, txn) txn.commit() except Exception, e: txn.abort() raise e sys.exit(2) finally: offlinedb.close()
def apply(response, request, registration, args): language = request.getLang() resources = misc.getClassByName( args['using'] ) output = response._getBody() tokens = frozenset(re.findall(TOKEN, output, re.DOTALL)) for token, key in tokens: output = output.replace(token, resources.getResource(key, language)) response._body = [output]
def getFiltersList(contextNode): filterList = contextNode.getElementsByTagName('filter') filters = [] for filterNode in filterList: type = filterNode.getAttribute('type').encode('iso-8859-1') filter = [misc.getClassByName(type), {}] for attr in filterNode.attributes.keys(): filter[1][str(attr)] = filterNode.getAttribute(attr).encode('iso-8859-1') filters.append( tuple(filter) ) return tuple(filters)
def execute(self): self.response.setExpiration(1200) sLang = self.request.getLang() if (self.item.resourcesImportPath.value): stringResources = misc.getClassByName(self.item.resourcesImportPath.value) dctLocStrings = stringResources.getLocale(sLang) else: dctLocStrings = {} self.response.content_type = 'text/javascript' self.response.write(self.item.script.value % dctLocStrings)
def __init__(self, identifier, enc, filters, max_age): try: self.context = misc.getClassByName(identifier) self.type = 2 except: self.context = identifier if identifier[-4:] == '.psp': self.type = 1 else: self.type = 0 self.encoding = enc self.filters = filters self.max_age = int(max_age);
def execute(self): self.response.setExpiration(1200) self.response.content_type = 'text/xml'; rootUri = self.request.serverVariables['SCRIPT_NAME'] sInterface = self.item.getInterface(rootUri) sLang = self.request.getLang() if (self.item.resourcesImportPath.value): stringResources = misc.getClassByName(self.item.resourcesImportPath.value) dctLocStrings = stringResources.getLocale(sLang) else: dctLocStrings = {} self.response.write(sInterface % dctLocStrings)
def _getFullName(self, callable): module = misc.getClassByName(callable.__module__) if self._imports.has_key(module): return self._imports[module] + '.' + callable.__name__ else: if module == self._module: return callable.__name__ self._newimports.append(module) local_name = callable.__module__.split('.')[-1] counter = 2 while local_name in self._module.__dict__: local_name += str(counter) counter += 1 self._imports[module] = local_name return(local_name + '.' + callable.__name__)
def __init__(self, classobj): self._class = misc.getClassByName(classobj) self._bases = self._class.__bases__ self.doc = self._class.__doc__ self._attrs = {} self._methods = {} self._properties = {} sourcelines = inspect.getsourcelines(self._class) startline = sourcelines[1] endline = startline + len(sourcelines[0]) - 1 self.boundaries = (startline, endline) self._instance = self._class() for prop in self._class.__slots__: self._attrs[prop] = getattr(self._instance, prop) for member_name in self._class.__dict__: member = self._class.__dict__[member_name] if type(member) == types.FunctionType: self._methods[member_name] = member elif type(member) == property: self._properties[member_name] = member self._module = sys.modules[self._class.__module__] self._newimports = [] self._imports = {} moduledict = self._module.__dict__ for x in moduledict: if type(moduledict[x]) == types.ModuleType: self._imports[moduledict[x]] = x elif callable(moduledict[x]) and \ (sys.modules[moduledict[x].__module__] != self._module): imported = misc.getClassByName(moduledict[x].__module__ + \ '.' + x) self._imports[imported] = x
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public License # along with Porcupine; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #=============================================================================== "Server request interfaces" from porcupine.config.settings import settings from porcupine.utils import misc from porcupine import serverExceptions requestInterfaces = {} try: ris = settings.requestinterfaces.options except AttributeError: raise serverExceptions.ConfigurationError, 'The configuration file either has no [requestinterfaces] section or the aforementioned section is blank' for ri in ris: sInterface = getattr(settings.requestinterfaces, ri) try: requestInterfaces[ri.upper()] = misc.getClassByName(sInterface) except AttributeError: raise serverExceptions.ConfigurationError, 'Invalid request interface "%s"' % sInterface except ImportError: raise serverExceptions.ConfigurationError, 'Invalid request interface "%s"' % sInterface del ris
from porcupine.config.settings import settings from porcupine.utils import misc from porcupine import serverExceptions try: sm_class = settings.sessionmanager.interface except AttributeError: raise serverExceptions.ConfigurationError, \ (('interface', 'sessionmanager'),) try: timeout = int(settings.sessionmanager.timeout) except AttributeError: # default timeout set to 20 minutes timeout = 1200 except ValueError: raise serverExceptions.ConfigurationError, \ 'Invalid value for session manager timeout: %s' % \ settings.sessionmanager.timeout try: sm_class = misc.getClassByName(sm_class) except AttributeError: raise serverExceptions.ConfigurationError, \ 'Invalid session manager interface "%s"' % \ settings.sessionmanager.interface except ImportError: raise serverExceptions.ConfigurationError, \ 'Invalid session manager interface "%s"' % \ settings.sessionmanager.interface
# the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # Porcupine is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public License # along with Porcupine; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #=============================================================================== "Server database parameters" from porcupine import serverExceptions from porcupine.config.settings import settings from porcupine.utils import misc try: db_class = settings.store.interface except AttributeError: raise serverExceptions.ConfigurationError, (('interface', 'store'),) try: db_class = misc.getClassByName(db_class) except AttributeError: raise serverExceptions.ConfigurationError, 'Invalid store interface "%s"' % settings.store.interface except ImportError: raise serverExceptions.ConfigurationError, 'Invalid store interface "%s"' % settings.store.interface params = settings.storeparameters.toDict()
def h_66(params, variables, forObject): className = evaluateStack(params[0][:], variables, forObject) return isinstance(forObject, misc.getClassByName(className))