rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
else: self._keys = [] | def __init__(self, dict=None): BaseDict.__init__(self, dict) if dict is not None: self._keys = self.data.keys() else: self._keys = [] | |
if not data: | if not data and mimetype != 'text/plain': | def get(self, instance, mimetype=None, raw=0, **kwargs): """ Return value of object, transformed into requested mime type. If no requested type, then return value in default type. If raw format is specified, try to transform data into the default output type or to plain text. If we are unable to transform data, return ... |
if idatastream.isImplementedBy(data): data = data.getData() if type(data) == type({}) and data.has_key('html'): return data['html'] | def get(self, instance, mimetype=None, raw=0, **kwargs): """ Return value of object, transformed into requested mime type. If no requested type, then return value in default type. If raw format is specified, try to transform data into the default output type or to plain text. If we are unable to transform data, return ... | |
o = %(name)s(id) self._setObject(id, o) o = getattr(self, id) o.initializeArchetype(**kwargs) | obj = %(name)s(id) self._setObject(id, obj) obj = self._getOb(id) obj.initializeArchetype(**kwargs) | def add%(name)s(self, id, **kwargs): o = %(name)s(id) self._setObject(id, o) o = getattr(self, id) o.initializeArchetype(**kwargs) return id |
field.set(instance, default) | mutator = field.getMutator(instance) mutator(default) | def setDefaults(self, instance): """Only call during object initialization. Sets fields to schema defaults """ ## XXX think about layout/vs dyn defaults for field in self.values(): if field.getName().lower() != 'id': # always set defaults #if not hasattr(aq_base(instance), field.getName()) and \ # getattr(instance, f... |
if isinstance(value, FileType) or hasattr(value, name): | if isinstance(value, FileType) or hasattr(value, 'name'): | def _process_input(self, value, default=None, mimetype=None, **kwargs): # We also need to handle the case where there is a baseUnit # for this field containing a valid set of data that would # not be reuploaded in a subsequent edit, this is basically # migrated from the old BaseObject.set method if type(value) in STRIN... |
print "unset img", id | def set(self, instance, value, **kwargs): # Do we have to delete the image? if value=="DELETE_IMAGE": # unset different sizes for n, size in self.sizes.items(): id = self.getName() + "_" + n print "unset img", id self.storage.unset(id, instance, **kwargs) # set field to none ObjectField.unset(self, instance, **kwargs) ... | |
security.declarePublic('getAccessor') | security.declarePrivate('getAccessor') | def getDefault(self): """Return the default value to be used for initializing this field""" return self.default |
security.declarePublic('getEditAccessor') | security.declarePrivate('getEditAccessor') | def getAccessor(self, instance): """Return the accessor method for getting data out of this field""" if self.accessor: return getattr(instance, self.accessor, None) return None |
args = [instance,] return mapply(self.get, *args, **kwargs) return mapply(accessor, **kwargs) | return self.get(instance, **kwargs) return accessor(**kwargs) | def getRaw(self, instance, **kwargs): if self.accessor is not None: accessor = self.getAccessor(instance) else: # self.accessor is None for fields wrapped by an I18NMixIn accessor = None if accessor is None: args = [instance,] return mapply(self.get, *args, **kwargs) return mapply(accessor, **kwargs) |
__traceback_info__ = (self, value) | def _to_tuple(self, value): """ COMMENT TO-DO """ if not value: value = self.default # Does this sounds right? value = value.split('.') __traceback_info__ = (self, value) if len(value) < 2: value = (int(value[0]), 0) else: fra = value[1][:self.precision] fra += '0' * (self.precision - len(fra)) value = (int(value[0]), ... | |
'allowed_type_column' : 'portal_type', | def get(self, instance, **kwargs): template = '%%d.%%0%dd' % self.precision value = ObjectField.get(self, instance, **kwargs) __traceback_info__ = (template, value) if value is None: return self.default if type(value) in [StringType]: value = self._to_tuple(value) return template % value | |
catalog = getToolByName(content_instance, config.UID_CATALOG) if self.allowed_type_column in catalog.indexes(): kw = {self.allowed_type_column:self.allowed_types} else: kw = {'Type':self.allowed_types} results = catalog(**kw) | catalog = getToolByName(content_instance, 'portal_catalog') results = catalog(portal_type=self.allowed_types) | def Vocabulary(self, content_instance=None): # If we have a method providing the list of types go with it, # it can always pull allowed_types if it needs to (not that we # pass the field name) value = ObjectField.Vocabulary(self, content_instance) if value: return value results = [] if self.allowed_types: catalog = get... |
if not self.required and not self.multiValued: | if not self.required: | def Vocabulary(self, content_instance=None): # If we have a method providing the list of types go with it, # it can always pull allowed_types if it needs to (not that we # pass the field name) value = ObjectField.Vocabulary(self, content_instance) if value: return value results = [] if self.allowed_types: catalog = get... |
__implements__ = ObjectField.__implements__ + (IImageField,) | def isBinary(self): return 1 | |
image = self.image_class(self.getName(), self.getName(), imgdata, mimetype) | image = Image(self.getName(), self.getName(), imgdata, mimetype) | def set(self, instance, value, **kwargs): # Do we have to delete the image? if value=="DELETE_IMAGE": ObjectField.set(self, instance, None, **kwargs) return |
return date is None and self.FLOOR_DATE or date | return date is None and FLOOR_DATE or date | def created(self): """Dublin Core element - date resource created, returned as DateTime. """ # allow for non-existent creation_date, existed always date = getattr( self, 'creation_date', None ) return date is None and self.FLOOR_DATE or date |
msgids.update(getattr(other, '_i18n_msgids', {}) | msgids.update(getattr(other, '_i18n_msgids', {})) | def __add__(self, other): a = tuple(self.items()) if hasattr(other, 'items'): b = other.items() else: #assume a seq b = tuple(zip(other, other)) |
dtool.overrideDiscussionFor(self, allowDiscussion) | try: dtool.overrideDiscussionFor(self, allowDiscussion) except KeyError, err: if allowDiscussion is None: msg = "Unable to set discussion on %s to None. Already " \ "deleted allow_discussion attribute? Message: %s" % ( self.getPhysicalPath(), str(err)) log(msg, level=ERROR) else: raise | def allowDiscussion(self, allowDiscussion=None, **kw): if allowDiscussion is not None: try: allowDiscussion = int(allowDiscussion) except (TypeError, ValueError): allowDiscussion = allowDiscussion.lower().strip() d = {'on' : 1, 'off': 0, 'none':None, '':None} allowDiscussion = d.get(allowDiscussion, None) dtool = getTo... |
fp = open("/tmp/ref.dot", "w") fp.write(data) fp.close() | def get_image(inst, fmt): g = local_refernece_graph(inst) data = build_graph(g, inst) | |
field.widget.isVisible(instance, 'edit')): | field.widget.isVisible(instance, 'edit')!='invisible'): | def editableFields(self, instance, visible_only=False): """Returns a list of editable fields for the given instance """ ret = [] for field in self.fields(): if field.writeable(instance, debug=False) and \ (not visible_only or field.widget.isVisible(instance, 'edit')): ret.append(field) return ret |
values = value if type(value) in STRING_TYPES: | vocab = self.Vocabulary(instance) if type(value) in (IntType,): pass elif type(value) in STRING_TYPES: | def validate_vocabulary(self, instance, value, errors): """Make sure value is inside the allowed values for a given vocabulary""" error = None if value: # coerce value into a list called values values = value if type(value) in STRING_TYPES: values = [value] elif type(value) not in (TupleType, ListType): raise TypeError... |
vocab = self.Vocabulary(instance) values = [instance.unicodeEncode(v) for v in values if v.strip()] valids = [] for v in vocab: if type(v) in (TupleType, ListType): v = v[0] if not type(v) in [type(''), type(u'')]: v = str(v) valids.append(instance.unicodeEncode(v)) for val in values: error = 1 for v in valids: if v... | def validate_vocabulary(self, instance, value, errors): """Make sure value is inside the allowed values for a given vocabulary""" error = None if value: # coerce value into a list called values values = value if type(value) in STRING_TYPES: values = [value] elif type(value) not in (TupleType, ListType): raise TypeError... | |
if isinstance(value, StringType): | if type(value) is StringType: | def set(self, instance, value, **kw): if isinstance(value, StringType): value = StringIO(value) image = ScalableImage(self.getName(), file=value, displays=self.displays) ObjectField.set(self, instance, image, **kw) |
s = '%s: {' % self.__class__.__name__ | s = '%s(%s): {' % ( self.__class__.__name__, self.__name__ ) | def toString(self): """Utility method for converting a Field to a string for the purpose of comparing fields. This comparison is used for determining whether a schema has changed in the auto update function. Right now it's pretty crude.""" # XXX fixme s = '%s: {' % self.__class__.__name__ sorted_keys = self._properti... |
s = s + '%s:%s,' % (k, self._properties[k]) | value = getattr( self, k, self._properties[k] ) if k == 'widget': value = value.__class__.__name__ s = s + '%s:%s,' % (k, value ) | def toString(self): """Utility method for converting a Field to a string for the purpose of comparing fields. This comparison is used for determining whether a schema has changed in the auto update function. Right now it's pretty crude.""" # XXX fixme s = '%s: {' % self.__class__.__name__ sorted_keys = self._properti... |
self.fp = self.target | fp = self.target | def _open(self): if self.fp is not None and not self.fp.closed: return self.fp |
def lookupObject(self, uuid): | def lookupObject(self, uuid, REQUEST=None): | def lookupObject(self, uuid): """Lookup an object by its uuid""" return self._objectByUUID(uuid) |
return self._objectByUUID(uuid) | tool = getToolByName(self, config.REFERENCE_CATALOG) obj = tool.lookupObject(uuid) if REQUEST: return REQUEST.RESPONSE.redirect(obj.absolute_url()) else: return obj | def lookupObject(self, uuid): """Lookup an object by its uuid""" return self._objectByUUID(uuid) |
imgdata=value | def set(self, instance, value, **kwargs): # do we have to delete the image? if value=="DELETE_IMAGE": ObjectField.set(self, instance, None, **kwargs) return | |
hasattr(object, 'isReferenceable')) | hasattr(aq_base(object), 'isReferenceable')) | def isReferenceable(self, object): return (IReferenceable.isImplementedBy(object) or hasattr(object, 'isReferenceable')) |
chainname = 'Validator_%s' % self.getName | chainname = 'Validator_%s' % self.getName() | def _validationLayer(self): """ Resolve that each validator is in the service. If validator is not, log a warning. |
""" Certain IDs give an error and are unusable | """ Certain IDs used to give an error and are unusable | def test_strangeUnallowedIds(self): """ Certain IDs give an error and are unusable |
home, version, icon. | home, version. This test used to include 'icon', too, but that's apparently really an id that's already been taken (instead of a bug). | def test_strangeUnallowedIds(self): """ Certain IDs give an error and are unusable |
strangeIds = ['home', 'version', 'icon'] | strangeIds = ['home', 'version'] | def test_strangeUnallowedIds(self): """ Certain IDs give an error and are unusable |
'alt' : alt and alt or instance.Title(), 'title' : title and title or instance.Title(), | 'alt' : escape(alt and alt or instance.Title()), 'title' : escape(title and title or instance.Title()), | def tag(self, instance, scale=None, height=None, width=None, alt=None, css_class=None, title=None, **kwargs): """Create a tag including scale """ image = self.getScale(instance, scale=scale) if image: img_height=image.height img_width=image.width else: img_height=0 img_width=0 |
if not field: | if field is None: | def widget(self, field_name, mode="view", field=None, **kwargs): if not field: field = self.Schema()[field_name] widget = field.widget return renderer.render(field_name, mode, widget, self, field=field, **kwargs) |
return obj.manage_edit%(name)sForm( REQUEST, management_view='Edit', manage_tabs_message=manage_tabs_message) | url = obj.absolute_url() REQUEST.RESPONSE.redirect(url + '/manage_edit%(name)sForm?manage_tabs_message=' + manage_tabs_message) | def manage_add%(name)s(self, id, REQUEST=None): ''' Constructor for %(name)s ''' kwargs = {} if REQUEST is not None: kwargs = REQUEST.form.copy() del kwargs['id'] id = add%(name)s(self, id, **kwargs) obj = self._getOb(id) manage_tabs_message = 'Successfully added %(name)s' if REQUEST is not None: return obj.manage_edit... |
return | else: print >>out, 'migrating reference from Archetypes 1.3. beta2' sids = rc.uniqueValuesFor('sourceUID') for sid in sids: set = rc(sourceUID=sid) sourceObject = uc(UID=sid)[0].getObject() if not sourceObject: continue annotations = sourceObject._getReferenceAnnotations() for brain in set: targetObj... | def migrateReferences(portal, out): # FIRST # a 1.2 -> 1.3 (new annotation style) migration path at = getToolByName(portal, TOOL_NAME) rc = getToolByName(portal, REFERENCE_CATALOG) uc = getToolByName(portal, UID_CATALOG) # Old 1.2 style references are stored inside archetype_tool on the 'ref' # attribute refs = getat... |
sids = rc.uniqueValuesFor('sourceUID') for sid in sids: set = rc(sourceUID=sid) sourceObject = uc(UID=sid)[0].getObject() if not sourceObject: continue annotations = sourceObject._getReferenceAnnotations() for brain in set: path = brain.getPath() ref = getattr(rc, path, None) if ref is None: continue if path.find('r... | count+=1 sourceObject.addReference(targetObject,relationship=brain.relationship) print >>out, "%s old references migrated (reference metadata not restored)." % count | def migrateReferences(portal, out): # FIRST # a 1.2 -> 1.3 (new annotation style) migration path at = getToolByName(portal, TOOL_NAME) rc = getToolByName(portal, REFERENCE_CATALOG) uc = getToolByName(portal, UID_CATALOG) # Old 1.2 style references are stored inside archetype_tool on the 'ref' # attribute refs = getat... |
if not objUID: continue setattr(obj, olduididx, objUID) delattr(obj, '_uid') setattr(obj, UUID_ATTR, None) | if objUID: setattr(obj, olduididx, objUID) delattr(obj, '_uid') setattr(obj, UUID_ATTR, None) | def migrateUIDs(portal, out): count=0 uc = getToolByName(portal, UID_CATALOG) # temporary add a new index if olduididx not in uc.indexes(): uc.addIndex(olduididx, 'FieldIndex', extra=None) if not olduididx in uc.schema(): uc.addColumn(olduididx) # clear UID Catalog uc.manage_catalogClear() # rebuild UIDS on objects ... |
mime_type, enc = guess_content_type('', value, 'text/plain') | mime_type, enc = guess_content_type('', value, mime_type) | def _process_input(self, value, default=None, mime_type=None, **kwargs): # We also need to handle the case where there is a baseUnit # for this field containing a valid set of data that would # not be reuploaded in a subsequent edit, this is basically # migrated from the old BaseObject.set method if type(value) is Stri... |
mime_type, enc = guess_content_type(f_name, value, 'text/plain') | mime_type, enc = guess_content_type(f_name, value, mime_type) | def _process_input(self, value, default=None, mime_type=None, **kwargs): # We also need to handle the case where there is a baseUnit # for this field containing a valid set of data that would # not be reuploaded in a subsequent edit, this is basically # migrated from the old BaseObject.set method if type(value) is Stri... |
return instance._FileField_types.get(self.getName(), 'text/plain') | return instance._FileField_types.get(self.getName(), None) | def getContentType(self, instance): if hasattr(aq_base(instance), '_FileField_types'): return instance._FileField_types.get(self.getName(), 'text/plain') return None |
instance._p_changed = 1 | def set(self, instance, value, **kwargs): if not kwargs.has_key('mime_type'): kwargs['mime_type'] = None | |
mime_type, enc = guess_content_type(f_name, value, self.default_content_type) | mime_type, enc = guess_content_type(f_name, value, mime_type) | def _process_input(self, value, default=None, \ mime_type=None, **kwargs): # We also need to handle the case where there is a baseUnit # for this field containing a valid set of data that would # not be reuploaded in a subsequent edit, this is basically # migrated from the old BaseObject.set method if type(value) != St... |
mime_type, enc = guess_content_type(f_name, str(value), self.default_content_type) | mime_type, enc = guess_content_type(f_name, str(value), mime_type) | def _process_input(self, value, default=None, \ mime_type=None, **kwargs): # We also need to handle the case where there is a baseUnit # for this field containing a valid set of data that would # not be reuploaded in a subsequent edit, this is basically # migrated from the old BaseObject.set method if type(value) != St... |
mime_type, enc = guess_content_type('', str(value), self.default_content_type) | mime_type, enc = guess_content_type('', str(value), None) | def getContentType(self, instance): value = '' accessor = self.getAccessor(instance) if accessor is not None: value = accessor() mime_type = getattr(aq_base(value), 'mimetype', None) if mime_type is None: mime_type, enc = guess_content_type('', str(value), self.default_content_type) return mime_type |
protect('registerObject', CMFCorePermissions.ModifyPortalContent) | protect(CMFCorePermissions.ModifyPortalContent, 'registerObject') | def lookupObject(self, uuid): """Lookup an object by its uuid""" return self._objectByUUID(uuid) |
protect('unregisterObject', CMFCorePermissions.ModifyPortalContent) | protect(CMFCorePermissions.ModifyPortalContent, 'unregisterObject') | def registerObject(self, object): self._uidFor(object) |
if self.description == '': | if not self.description: | def populateProps(self, field): """This is called when the field is created.""" name = field.getName() if not self.label: self.label = capitalize(name) if self.description == '': self.description = 'Enter a value for %s.' % self.label |
instance._md = PersistentMapping() | def initializeInstance(self, instance, item=None, container=None): base = aq_base(instance) if not hasattr(base, "_md"): instance._p_changed = 1 instance._md = PersistentMapping() | |
del base._md[name] | def unset(self, name, instance, **kwargs): base = aq_base(instance) if not hasattr(base, "_md"): log("Broken instance %s, no _md" % instance) else: base._p_changed = 1 del base._md[name] | |
"""Called by the generated add* factory in types tool. | """Called by the generated addXXX factory in types tool. | def initializeArchetype(self, **kwargs): """Called by the generated add* factory in types tool. """ try: self.initializeLayers() self.markCreationFlag() self.setDefaults() if kwargs: kwargs['_initializing_'] = True self.edit(**kwargs) self._signature = self.Schema().signature() except (ConflictError, KeyboardInterrupt)... |
element = getattr(self, key, None) if element and shasattr(element, 'isBinary'): return element.isBinary() | field = self.getField(key) if IFileField.isImplementedBy(field): value = field.getBaseUnit(self) return value.isBinary() | def isBinary(self, key): """Return wether a field contains binary data. """ element = getattr(self, key, None) if element and shasattr(element, 'isBinary'): return element.isBinary() mimetype = self.getContentType(key) if mimetype and shasattr(mimetype, 'binary'): return mimetype.binary elif mimetype and mimetype.find(... |
schema = getattr(pmt, 'DCMI', None) spec = schema.getElementSpec(field.accessor) | spec = pmt.getElementSpec(field.accessor) | def get_portal_metadata(self, field): """Returns the portal_metadata for a field. """ pmt = getToolByName(self, 'portal_metadata') policy = None try: schema = getattr(pmt, 'DCMI', None) spec = schema.getElementSpec(field.accessor) policy = spec.getPolicy(self.portal_type) except (ConflictError, KeyboardInterrupt): rais... |
return None, False | return None, 0 | def get_portal_metadata(self, field): """Returns the portal_metadata for a field. """ pmt = getToolByName(self, 'portal_metadata') policy = None try: schema = getattr(pmt, 'DCMI', None) spec = schema.getElementSpec(field.accessor) policy = spec.getPolicy(self.portal_type) except (ConflictError, KeyboardInterrupt): rais... |
event.notify(ObjectPreValidatingEvent(self, REQUEST, errors)) | def validate(self, REQUEST=None, errors=None, data=None, metadata=None): """Validates the form data from the request. """ if errors is None: errors = {} self.pre_validate(REQUEST, errors) event.notify(ObjectPreValidatingEvent(self, REQUEST, errors)) if errors: return errors self.Schema().validate(instance=self, REQUEST... | |
event.notify(ObjectPostValidatingEvent(self, REQUEST, errors)) | def validate(self, REQUEST=None, errors=None, data=None, metadata=None): """Validates the form data from the request. """ if errors is None: errors = {} self.pre_validate(REQUEST, errors) event.notify(ObjectPreValidatingEvent(self, REQUEST, errors)) if errors: return errors self.Schema().validate(instance=self, REQUEST... | |
event.notify(ObjectInitializedEvent(self)) | def processForm(self, data=1, metadata=0, REQUEST=None, values=None): """Processes the schema looking for data in the form. """ is_new_object = self.checkCreationFlag() self._processForm(data=data, metadata=metadata, REQUEST=REQUEST, values=values) self.unmarkCreationFlag() if self._at_rename_after_creation and is_new_... | |
event.notify(ObjectEditedEvent(self)) | def processForm(self, data=1, metadata=0, REQUEST=None, values=None): """Processes the schema looking for data in the form. """ is_new_object = self.checkCreationFlag() self._processForm(data=data, metadata=metadata, REQUEST=REQUEST, values=values) self.unmarkCreationFlag() if self._at_rename_after_creation and is_new_... | |
parent = aq_parent(aq_inner(self)) parent_ids = parent.objectIds() if id not in parent_ids: | check_id = getattr(self, 'check_id', None) if check_id is None: parent = aq_parent(aq_inner(self)) parent_ids = parent.objectIds() check_id = lambda id, required: id in parent_ids invalid_id = check_id(id, required=1) if not invalid_id: | def _findUniqueId(self, id): """Find a unique id in the parent folder, based on the given id, by appending -n, where n is a number between 1 and the constant RENAME_AFTER_CREATION_ATTEMPTS, set in config.py. If no id can be found, return None. """ parent = aq_parent(aq_inner(self)) parent_ids = parent.objectIds() |
if new_id not in parent_ids: | if not check_id(new_id, required=1): | def _findUniqueId(self, id): """Find a unique id in the parent folder, based on the given id, by appending -n, where n is a number between 1 and the constant RENAME_AFTER_CREATION_ATTEMPTS, set in config.py. If no id can be found, return None. """ parent = aq_parent(aq_inner(self)) parent_ids = parent.objectIds() |
schema = ISchema(self) | schema = self.schema | def Schema(self): """Return a (wrapped) schema instance for this object instance. """ schema = ISchema(self) return ImplicitAcquisitionWrapper(schema, self) |
if target is not None: return target if (method not in ('GET', 'POST') and not | if (target is None and method not in ('GET', 'POST') and not | def __bobo_traverse__(self, REQUEST, name): """Allows transparent access to session subobjects. """ # sometimes, the request doesn't have a response, e.g. when # PageTemplates traverse through the object path, they pass in # a phony request (a dict). RESPONSE = getattr(REQUEST, 'RESPONSE', None) |
def _old_process_input(self, value, default=None, mimetype=None, **kwargs): if not (isinstance(value, FileUpload) or type(value) is FileType) \ and shasattr(value, 'read') and shasattr(value, 'seek'): value.seek(0) kwargs['filename'] = getattr(value, 'filename', '') mimetype = getattr(value, 'mimetype', None) val... | def _old_process_input(self, value, default=None, mimetype=None, **kwargs): # We also need to handle the case where there is a baseUnit # for this field containing a valid set of data that would # not be reuploaded in a subsequent edit, this is basically # migrated from the old BaseObject.set method if not (isinstance(... | |
def _process_input(self, value, file=None, default=None, mimetype=None, instance=None, **kwargs): | def _process_input(self, value, file=None, default=None, mimetype=None, instance=None, filename='', **kwargs): | def _process_input(self, value, file=None, default=None, mimetype=None, instance=None, **kwargs): if file is None: file = self._make_file(self.getName(), title='', file='', instance=instance) filename = kwargs.get('filename') or '' if IBaseUnit.isImplementedBy(value): mimetype = value.getContentType() or mimetype filen... |
filename = kwargs.get('filename') or '' | def _process_input(self, value, file=None, default=None, mimetype=None, instance=None, **kwargs): if file is None: file = self._make_file(self.getName(), title='', file='', instance=instance) filename = kwargs.get('filename') or '' if IBaseUnit.isImplementedBy(value): mimetype = value.getContentType() or mimetype filen... | |
d, f, mimetype = mtr(body, **kw) | d, f, mimetype = mtr(body[:8096], **kw) | def _process_input(self, value, file=None, default=None, mimetype=None, instance=None, **kwargs): if file is None: file = self._make_file(self.getName(), title='', file='', instance=instance) filename = kwargs.get('filename') or '' if IBaseUnit.isImplementedBy(value): mimetype = value.getContentType() or mimetype filen... |
mimetype, enc = guess_content_type(filename, body, mimetype) | mimetype = getattr(file, 'content_type', None) if mimetype is None: mimetype, enc = guess_content_type(filename, body, mimetype) | def _process_input(self, value, file=None, default=None, mimetype=None, instance=None, **kwargs): if file is None: file = self._make_file(self.getName(), title='', file='', instance=instance) filename = kwargs.get('filename') or '' if IBaseUnit.isImplementedBy(value): mimetype = value.getContentType() or mimetype filen... |
if not isinstance(value, self.content_class): | if value and not isinstance(value, self.content_class): | def get(self, instance, **kwargs): value = ObjectField.get(self, instance, **kwargs) if not isinstance(value, self.content_class): value = self._wrapValue(instance, value) if (shasattr(value, '__of__', acquire=True) and not kwargs.get('unwrapped', False)): return value.__of__(instance) else: return value |
_process_input = _old_process_input | def isBinary(self): return True | |
if not kwargs.has_key('mimetype'): kwargs['mimetype'] = None value, mimetype, filename = self._process_input(value, default=self.getDefault(instance), **kwargs) | kwargs.setdefault('mimetype', None) default = self.getDefault(instance) value, mimetype, filename = self._process_input(value, default=default, instance=instance, **kwargs) size = getattr(value, 'size', None) if size == 0: return import pdb; pdb.set_trace() | def set(self, instance, value, **kwargs): if not value: return |
kwargs = self._updateKwargs(instance, value, **kwargs) | def set(self, instance, value, **kwargs): if not value: return | |
imgdata = self.rescaleOriginal(value, **kwargs) | data = self.rescaleOriginal(value, **kwargs) | def set(self, instance, value, **kwargs): if not value: return |
imgdata = value | def set(self, instance, value, **kwargs): if not value: return | |
self.createOriginal(instance, imgdata, **kwargs) self.createScales(instance, value=imgdata) def _updateKwargs(self, instance, value, **kwargs): vfilename = getattr(value, 'filename', '') kfilename = kwargs.get('filename', '') if kfilename: filename = kfilename else: filename = vfilename kwargs['filename'] = filename... | self.createOriginal(instance, data, **kwargs) self.createScales(instance, value=data) | def set(self, instance, value, **kwargs): if not value: return |
image = self.content_class(self.getName(), self.getName(), value, mimetype) data = str(image.data) if not data: | if not value: | def rescaleOriginal(self, value, **kwargs): """rescales the original image and sets the data |
if image.width > self.max_size[0] or \ image.height > self.max_size[1]: factor = min(float(self.max_size[0])/float(image.width), float(self.max_size[1])/float(image.height)) w = int(factor*image.width) h = int(factor*image.height) | if value.width > self.max_size[0] or \ value.height > self.max_size[1]: factor = min(float(self.max_size[0])/float(value.width), float(self.max_size[1])/float(value.height)) w = int(factor*value.width) h = int(factor*value.height) | def rescaleOriginal(self, value, **kwargs): """rescales the original image and sets the data |
fvalue, format = self.scale(data, w, h) value = fvalue.read() return value | fvalue, format = self.scale(value, w, h) data = fvalue.read() else: data = str(value.data) else: data = str(value.data) return data | def rescaleOriginal(self, value, **kwargs): """rescales the original image and sets the data |
return getattr(self, UUID_ATTR) | return getattr(aq_base(self), UUID_ATTR) | def UID(self): """the uid method for compat""" return getattr(self, UUID_ATTR) |
setattr(self.REFERENCE_CONTENT_INSTANCE_NAME,self.contentType(REFERENCE_CONTENT_INSTANCE_NAME)) getattr(self.REFERENCE_CONTENT_INSTANCE_NAME)._md=PersistentMapping() | setattr(self, REFERENCE_CONTENT_INSTANCE_NAME, self.contentType(REFERENCE_CONTENT_INSTANCE_NAME)) getattr(self, REFERENCE_CONTENT_INSTANCE_NAME)._md=PersistentMapping() | def addHook(self, *args, **kw): #creates the content instance if type(self.contentType) in (type(''),type(u'')): #type given as string tt=getToolByName(self,'portal_types') tt.constructContent(self.contentType,self,REFERENCE_CONTENT_INSTANCE_NAME) else: #type given as class setattr(self.REFERENCE_CONTENT_INSTANCE_NAME,... |
return getattr(self,REFERENCE_CONTENT_INSTANCE_NAME) | return getattr(self.aq_inner.aq_explicit, REFERENCE_CONTENT_INSTANCE_NAME) | def getContentObject(self): return getattr(self,REFERENCE_CONTENT_INSTANCE_NAME) |
if not getattr(uobject, UUID_ATTR, None): | if not getattr(aq_base(uobject), UUID_ATTR, None): | def _uidFor(self, obj): # We should really check for the interface but I have an idea # about simple annotated objects I want to play out if type(obj) not in STRING_TYPES: uobject = aq_base(obj) if not self.isReferenceable(uobject): raise ReferenceException, "%r not referenceable" % uobject |
if target: | if target is not None: | def targetId(self): target = self.getTargetObject() if target: return target.getId() return '' |
if target: | if target is not None: | def targetTitle(self): target = self.getTargetObject() if target: return target.Title() return '' |
q = {} if sid: q['sourceUID'] = sid if tid: q['targetUID'] = tid if relationship: q['relationship'] = relationship if targetId: q['targetId'] = targetId brains = self.searchResults(q, merge=merge) | query = {} if sid: query['sourceUID'] = sid if tid: query['targetUID'] = tid if relationship: query['relationship'] = relationship if targetId: query['targetId'] = targetId brains = self.searchResults(query, merge=merge) | def _queryFor(self, sid=None, tid=None, relationship=None, targetId=None, merge=1): """query reference catalog for object matching the info we are given, returns brains |
install_portal_transforms() | install_portal_transforms(self) | def setupEnvironment(self, out, types, package_name, globals=types_globals, product_skins_dir='skins'): types = filterTypes(self, out, types, package_name) install_tools(self, out) install_subskin(self, out, globals, product_skins_dir) install_indexes(self, out, types) install_actions(self, out, types) install_porta... |
self.mimetype = aq_base(mimetype) | self.mimetype = mimetype | def update(self, data, instance, **kw): #Convert from str to unicode as needed mimetype = kw.get('mimetype', None) filename = kw.get('filename', None) encoding = kw.get('encoding', None) |
_field_count = 0 | def decode(value, instance, **kwargs): """ensure value is an unicode string""" if type(value) is type(''): encoding = kwargs.get('encoding') if encoding is None: try: encoding = instance.getCharset() except AttributeError: # that occurs during object initialization # (no acquisition wrapper) encoding = 'UTF8' value = u... | |
def __init__(self, name=None, **kwargs): | def __init__(self, name, **kwargs): | def __init__(self, name=None, **kwargs): """ Assign name to __name__. Add properties and passed-in keyword args to __dict__. Validate assigned validator(s). """ DefaultLayerContainer.__init__(self) |
if name is None: global _field_count _field_count += 1 name = 'field.%s' % _field_count | def __init__(self, name=None, **kwargs): """ Assign name to __name__. Add properties and passed-in keyword args to __dict__. Validate assigned validator(s). """ DefaultLayerContainer.__init__(self) | |
for v in value if v.strip()] value = filter(None, value) | for v in value if v and v.strip()] | def set(self, instance, value, **kwargs): """ If passed-in value is a string, split at line breaks and remove leading and trailing white space before storing in object with rest of properties. """ __traceback_info__ = value, type(value) if type(value) in STRING_TYPES: value = value.split('\n') value = [decode(v.strip(... |
imgdata, format = self.rescaleOriginal(value, **kwargs) | imgdata = self.rescaleOriginal(value, **kwargs) | def set(self, instance, value, **kwargs): # Do we have to delete the image? if value=="DELETE_IMAGE": self.removeScales(image) # unset main field too ObjectField.unset(self, instance, **kwargs) return |
value = self.scale(data,w,h) | value, format = self.scale(data,w,h) | def rescaleOriginal(self, value, **kwargs): """rescales the original image and sets the data |
from Products.Archetypes import SQLStorage from Products.Archetypes import SQLMethod | from Products.Archetypes.storage.sql import storage as SQLStorage from Products.Archetypes.storage.sql import method as SQLMethod | def pretty_exc(self, exc): t, e, tb = exc try: return ''.join(format_exception(t, e, tb, format_src=1)) except: return ''.join(format_exception(t, e, tb)) |
data = str(data) | if hasattr(data, 'data'): data = data.data else: data = str(data) | def marshall(self, instance, **kwargs): p = instance.getPrimaryField() data = p and instance[p.getName()] or '' content_type = length = None # Gather/Guess content type if IBaseUnit.isImplementedBy(data): content_type = data.getContentType() length = data.get_size() data = data.getRaw() else: log("WARNING: PrimaryFie... |
KERNEL_UUID = '/proc/sys/kernel/random/uuids' | KERNEL_UUID = '/proc/sys/kernel/random/uuid' | def make_uuid(*args): t = str(time() * 1000L) r = str(random()*100000000000000000L) data = t +' '+ r +' '+ _v_network +' '+ str(args) uid = md5(data).hexdigest() return uid |
if type(key) not in (StringType, UnicodeType, IntType): raise TypeError('DisplayList keys must be strings or ints, got %s' % | if type(key) not in (StringType, UnicodeType): raise TypeError('DisplayList msgids must be strings, got %s' % | def getMsgId(self, key): "get i18n msgid" if type(key) not in (StringType, UnicodeType, IntType): raise TypeError('DisplayList keys must be strings or ints, got %s' % type(key)) if self._i18n_msgids.has_key(key): return self._i18n_msgids[key] else: return self._keys[key][1] |
def get(self, instance, mimetype=None, raw=1, **kwargs): | def get(self, instance, mimetype=None, raw=0, **kwargs): | def get(self, instance, mimetype=None, raw=1, **kwargs): try: kwargs['field'] = self value = self.storage.get(self.getName(), instance, **kwargs) if not IBaseUnit.isImplementedBy(value): return value except AttributeError: # happens if new Atts are added and not yet stored in the instance if not kwargs.get('_initializi... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.