def test_sametype_only_multipe_args_one_different(): from RestrictedPython.Utilities import same_type class Foo(object): pass assert same_type(object(), object(), Foo()) is False
def test_sametype_only_two_args_different(self): from RestrictedPython.Utilities import same_type class Foo(object): pass self.failIf(same_type(object(), Foo()))
def unicodeEncode(self, value, site_charset=None): """ unicodeEncode """ # Recursively deal with sequences tuplevalue = same_type(value, ()) if tuplevalue or same_type(value, []): encoded = [self.unicodeEncode(v) for v in value] if tuplevalue: encoded = tuple(encoded) return encoded if not isinstance(value, basestring): value = str(value) if site_charset is None: site_charset = self.context.getCharset() if same_type(value, ''): value = unicode(value, site_charset) # don't try to catch unicode error here # if one occurs, that means the site charset must be changed ! return value.encode(site_charset)
def unicodeEncode(self, value, site_charset=None): """ unicodeEncode """ # Recursively deal with sequences tuplevalue = same_type(value, ()) if tuplevalue or same_type(value, []): encoded = [self.unicodeEncode(v) for v in value] if tuplevalue: encoded = tuple(encoded) return encoded if not isinstance(value, basestring): value = str(value) if site_charset is None: site_charset = self.context.getCharset() if same_type(value, ''): value = unicode(value, site_charset) # don't try to catch unicode error here # if one occurs, that means the site charset must be changed ! return value.encode(site_charset)
def test_sametype_only_multiple_args_same(): from RestrictedPython.Utilities import same_type assert same_type(object(), object(), object(), object())
def test_sametype_only_one_arg(): from RestrictedPython.Utilities import same_type assert same_type(object())
def test_sametype_only_multipe_args_one_different(self): from RestrictedPython.Utilities import same_type class Foo(object): pass self.failIf(same_type(object(), object(), Foo()))
def test_sametype_only_multiple_args_same(self): from RestrictedPython.Utilities import same_type self.failUnless(same_type(object(), object(), object(), object()))
def convert(obj): """Convert from the old style course composer (RisaCollectionEditor) to the new one (RisaCollection)""" parent = obj.aq_parent id = obj.getId() parent.manage_renameObjects([id], [id + '.old']) parent.invokeFactory(id=id, type_name='Collection') target = getattr(parent, id) # Copy metadata target.setTitle(obj.title) target.setCreated(obj.created) target.setRevised(obj.revised) target.setAuthors(obj.authors) target.setMaintainers(obj.maintainers) target.setLicensors(obj.licensors) target.setVersion(obj.version) target.setAbstract(obj.abstract) target.setKeywords(obj.keywords) target.setLicense(obj.license) target.setInstitution(obj.institution) target.setInstructor(obj.instructor) target.setCode(obj.code) target.setHomepage(getattr(obj, 'homepage', '')) target.setState(obj.state) # Copy parameters params = obj.getParameters() if params.get('imaginaryi', '') == 'imaginaryi': del params['imaginaryi'] for key, value in params.items(): # Skip blank parameters (defaults) if not value or key.startswith('_') or key.startswith(' '): continue t = same_type(value, 0) and 'int' or 'string' target.parameters.manage_addProperty(key, value, t) # Copy annotations if hasattr(obj, 'annotations'): target.manage_delObjects('annotations') target.manage_clone(obj.annotations, 'annotations') # Convert contents convertContents(obj, target) # Copy links for m, links in obj._links.items(): m = target.getContainedObject(m) if not m: continue for l in links: now = DateTime() id = 'Link.' + now.strftime('%Y-%m-%d') + '.' + now.strftime( '%M%S') count = 0 while id in m.objectIds(): id = 'Link.' + now.strftime('%Y-%m-%d') + '.' + now.strftime( '%M%S') + '.' + str(count) count = count + 1 m.manage_addProduct['RisaRepository'].manage_addRisaLink(id) m[id].edit('me', l['url'], l['title'], l['type'], int(l['strength']))
def convert(obj): """Convert from the old style course composer (RisaCollectionEditor) to the new one (RisaCollection)""" parent = obj.aq_parent id = obj.getId() parent.manage_renameObjects([id], [id+'.old']) parent.invokeFactory(id=id, type_name='Collection') target = getattr(parent, id) # Copy metadata target.setTitle(obj.title) target.setCreated(obj.created) target.setRevised(obj.revised) target.setAuthors(obj.authors) target.setMaintainers(obj.maintainers) target.setLicensors(obj.licensors) target.setVersion(obj.version) target.setAbstract(obj.abstract) target.setKeywords(obj.keywords) target.setLicense(obj.license) target.setInstitution(obj.institution) target.setInstructor(obj.instructor) target.setCode(obj.code) target.setHomepage(getattr(obj,'homepage','')) target.setState(obj.state) # Copy parameters params = obj.getParameters() if params.get('imaginaryi', '') == 'imaginaryi': del params['imaginaryi'] for key, value in params.items(): # Skip blank parameters (defaults) if not value or key.startswith('_') or key.startswith(' '): continue t = same_type(value, 0) and 'int' or 'string' target.parameters.manage_addProperty(key, value, t) # Copy annotations if hasattr(obj, 'annotations'): target.manage_delObjects('annotations') target.manage_clone(obj.annotations, 'annotations') # Convert contents convertContents(obj, target) # Copy links for m, links in obj._links.items(): m = target.getContainedObject(m) if not m: continue for l in links: now=DateTime() id = 'Link.'+now.strftime('%Y-%m-%d')+'.'+now.strftime('%M%S') count = 0 while id in m.objectIds(): id = 'Link.'+now.strftime('%Y-%m-%d')+'.'+now.strftime('%M%S')+'.'+str(count) count = count + 1 m.manage_addProduct['RisaRepository'].manage_addRisaLink(id) m[id].edit('me', l['url'], l['title'], l['type'], int(l['strength']))
def same_type(self, arg1, *args): return same_type(arg1, *args)
def same_type(self, arg1, *args): return same_type(arg1, *args)