def __init__(self, recipe, metadata=None, **kw): kw.setdefault('attrName', getattr(recipe, '__name__', None)) recipe = self.computeValue = adapt(recipe, IRecipe) kw.setdefault('doc', getattr(recipe, '__doc__', None)) kw['metadata'] = metadata _warnIfPermission(kw) super(Make, self).__init__(**kw)
def addName(self, other): if not other: return self name = adapt(other, IName, None) if name is None: raise TypeError("Only names can be added to URLs", self, other) other = name if other.nameKind == URL_KIND: return other na = self.nameAttr if not na: raise TypeError("Addition not supported for pure address types", self, other) d = dict(self._hashAndCompare) d['body'] = None # before the below in case 'na' is "body" d[na] = getattr(self, na, CompoundName(())) + other res = self.__class__(**d) return res
def onSet(self, obj, attrName, value): if self.adaptTo is not None: value = adapt(value, self.adaptTo) if self.suggestParent: suggestParentComponent(obj, attrName, value) return value
def getURLContext(parent, scheme, iface, componentName=None, **options): """Return a context object for the given URL scheme and interface This is done by looking up 'scheme' in the 'peak.naming.schemes.*' property namespace. (That is, the '"ldap:"' URL scheme is retrieved from the 'peak.naming.schemes.ldap' property. Per RFC 1738, the lowercase form of the scheme name is always used; note that the '":"' should not be included in the scheme name.) The property value found, if a string, will be treated as an import specification, and the relevant object imported. The property value or imported object must do one of the following: * Implement 'naming.IURLContextFactory', in which case its 'getURLContext()' method will be called with the same arguments as supplied to this function. * Be a class whose instances implement the requested context interface (e.g. 'naming.IBasicContext'), in which case an instance will be constructed and returned, using 'parent' as its parent component, and 'componentName' as its name. (Note that the class must also implement the 'binding.IComponentFactory' constructor signature for this to work.) * Be a class whose instances implement 'naming.IAddress', in which case a generic 'AddressContext' will be returned, with its 'schemeParser' set to the appropriate address class. If none of these conditions apply, or the property isn't found in the first place, this function returns 'None', as per the 'naming.IURLContextFactory' interface. """ factory = SCHEMES_PREFIX.of(parent).get(scheme.lower()) if factory is None: return None factory = adapt(importObject(factory), IURLContextFactory, None) if factory is not None: return factory.getURLContext(parent, scheme, iface, componentName, **options) return None
def _syntax(feature): syntax = feature.syntax if syntax is None: syntax = adapt(feature.typeObject, IRule, None) if syntax is None: syntax = Conversion(ExtractQuoted(unquote=feature.unquote), converter=feature.fromString, formatter=feature.toString, defaultValue=feature._defaultValue, canBeEmpty=feature.canBeEmpty) if feature.isMany: syntax = Repeat(syntax, minCt=feature.lowerBound, maxCt=feature.upperBound, separator=feature.separator, sepMayTerm=feature.sepMayTerm) return Named(feature.attrName, syntax)
def getObjectInstance(self, context, refInfo, name, attrs=None): addr, = refInfo.addresses addr = adapt(addr, smtpURL) return smtplib.SMTP(addr.host, addr.port)
def __call__(self, component, instDict, attrName): return adapt(importString(self.subject), IRecipe)(component, instDict, attrName)
def __init__(self, rule=MatchString(), unquote=True, terminators=''): self.rule = adapt(rule, IRule) self.unquote = unquote self.terminators = terminators