/*###########################################################################
#
# Copyright (c) 2003 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
############################################################################*/
#include "Python.h"
#include "structmember.h"
#define TYPE(O) ((PyTypeObject*)(O))
#define OBJECT(O) ((PyObject*)(O))
#define CLASSIC(O) ((PyClassObject*)(O))
#ifndef PyVarObject_HEAD_INIT
#define PyVarObject_HEAD_INIT(a, b) PyObject_HEAD_INIT(a) b,
#endif
#ifndef Py_TYPE
#define Py_TYPE(o) ((o)->ob_type)
#endif
#if PY_MAJOR_VERSION >= 3
#define PY3K
#endif
static PyObject *str__dict__, *str__implemented__, *strextends;
static PyObject *BuiltinImplementationSpecifications, *str__provides__;
static PyObject *str__class__, *str__providedBy__;
static PyObject *empty, *fallback, *str_implied, *str_cls, *str_implements;
static PyObject *str__conform__, *str_call_conform, *adapter_hooks;
static PyObject *str_uncached_lookup, *str_uncached_lookupAll;
static PyObject *str_uncached_subscriptions;
static PyObject *str_registry, *strro, *str_generation, *strchanged;
static PyTypeObject *Implements;
static int imported_declarations = 0;
static int
import_declarations(void)
{
PyObject *declarations, *i;
declarations = PyImport_ImportModule("zope.interface.declarations");
if (declarations == NULL)
return -1;
BuiltinImplementationSpecifications = PyObject_GetAttrString(
declarations, "BuiltinImplementationSpecifications");
if (BuiltinImplementationSpecifications == NULL)
return -1;
empty = PyObject_GetAttrString(declarations, "_empty");
if (empty == NULL)
return -1;
fallback = PyObject_GetAttrString(declarations, "implementedByFallback");
if (fallback == NULL)
return -1;
i = PyObject_GetAttrString(declarations, "Implements");
if (i == NULL)
return -1;
if (! PyType_Check(i))
{
PyErr_SetString(PyExc_TypeError,
"zope.interface.declarations.Implements is not a type");
return -1;
}
Implements = (PyTypeObject *)i;
Py_DECREF(declarations);
imported_declarations = 1;
return 0;
}
static PyTypeObject SpecType; /* Forward */
static PyObject *
implementedByFallback(PyObject *cls)
{
if (imported_declarations == 0 && import_declarations() < 0)
return NULL;
return PyObject_CallFunctionObjArgs(fallback, cls, NULL);
}
static PyObject *
implementedBy(PyObject *ignored, PyObject *cls)
{
/* Fast retrieval of implements spec, if possible, to optimize
common case. Use fallback code if we get stuck.
*/
PyObject *dict = NULL, *spec;
if (PyType_Check(cls))
{
dict = TYPE(cls)->tp_dict;
Py_XINCREF(dict);
}
if (dict == NULL)
dict = PyObject_GetAttr(cls, str__dict__);
if (dict == NULL)
{
/* Probably a security proxied class, use more expensive fallback code */
PyErr_Clear();
return implementedByFallback(cls);
}
spec = PyObject_GetItem(dict, str__implemented__);
Py_DECREF(dict);
if (spec)
{
if (imported_declarations == 0 && import_declarations() < 0)
return NULL;
if (PyObject_TypeCheck(spec, Implements))
return spec;
/* Old-style declaration, use more expensive fallback code */
Py_DECREF(spec);
return implementedByFallback(cls);
}
PyErr_Clear();
/* Maybe we have a builtin */
if (imported_declarations == 0 && import_declarations() < 0)
return NULL;
spec = PyDict_GetItem(BuiltinImplementationSpecifications, cls);
if (spec != NULL)
{
Py_INCREF(spec);
return spec;
}
/* We're stuck, use fallback */
return implementedByFallback(cls);
}
static PyObject *
getObjectSpecification(PyObject *ignored, PyObject *ob)
{
PyObject *cls, *result;
result = PyObject_GetAttr(ob, str__provides__);
if (result != NULL && PyObject_TypeCheck(result, &SpecType))
return result;
PyErr_Clear();
/* We do a getattr here so as not to be defeated by proxies */
cls = PyObject_GetAttr(ob, str__class__);
if (cls == NULL)
{
PyErr_Clear();
if (imported_declarations == 0 && import_declarations() < 0)
return NULL;
Py_INCREF(empty);
return empty;
}
result = implementedBy(NULL, cls);
Py_DECREF(cls);
return result;
}
static PyObject *
providedBy(PyObject *ignored, PyObject *ob)
{
PyObject *result, *cls, *cp;
result = PyObject_GetAttr(ob, str__providedBy__);
if (result == NULL)
{
PyErr_Clear();
return getObjectSpecification(NULL, ob);
}
/* We want to make sure we have a spec. We can't do a type check
because we may have a proxy, so we'll just try to get the
only attribute.
*/
if (PyObject_TypeCheck(result, &SpecType)
||
PyObject_HasAttr(result, strextends)
)
return result;
/*
The object's class doesn't understand descriptors.
Sigh. We need to get an object descriptor, but we have to be
careful. We want to use the instance's __provides__,l if
there is one, but only if it didn't come from the class.
*/
Py_DECREF(result);
cls = PyObject_GetAttr(ob, str__class__);
if (cls == NULL)
return NULL;
result = PyObject_GetAttr(ob, str__provides__);
if (result == NULL)
{
/* No __provides__, so just fall back to implementedBy */
PyErr_Clear();
result = implementedBy(NULL, cls);
Py_DECREF(cls);
return result;
}
cp = PyObject_GetAttr(cls, str__provides__);
if (cp == NULL)
{
/* The the class has no provides, assume we're done: */
PyErr_Clear();
Py_DECREF(cls);
return result;
}
if (cp == result)
{
/*
Oops, we got the provides from the class. This means
the object doesn't have it's own. We should use implementedBy
*/
Py_DECREF(result);
result = implementedBy(NULL, cls);
}
Py_DECREF(cls);
Py_DECREF(cp);
return result;
}
/*
Get an attribute from an inst dict. Return a borrowed reference.
This has a number of advantages:
- It avoids layers of Python api
- It doesn't waste time looking for descriptors
- It fails wo raising an exception, although that shouldn't really
matter.
*/
static PyObject *
inst_attr(PyObject *self, PyObject *name)
{
PyObject **dictp, *v;
dictp = _PyObject_GetDictPtr(self);
if (dictp && *dictp && (v = PyDict_GetItem(*dictp, name)))
return v;
PyErr_SetObject(PyExc_AttributeError, name);
return NULL;
}
static PyObject *
Spec_extends(PyObject *self, PyObject *other)
{
PyObject *implied;
implied = inst_attr(self, str_implied);
if (implied == NULL)
return NULL;
#ifdef Py_True
if (PyDict_GetItem(implied, other) != NULL)
{
Py_INCREF(Py_True);
return Py_True;
}
Py_INCREF(Py_False);
return Py_False;
#else
return PyInt_FromLong(PyDict_GetItem(implied, other) != NULL);
#endif
}
static char Spec_extends__doc__[] =
"Test whether a specification is or extends another"
;
static char Spec_providedBy__doc__[] =
"Test whether an interface is implemented by the specification"
;
static PyObject *
Spec_call(PyObject *self, PyObject *args, PyObject *kw)
{
PyObject *spec;
if (! PyArg_ParseTuple(args, "O", &spec))
return NULL;
return Spec_extends(self, spec);
}
static PyObject *
Spec_providedBy(PyObject *self, PyObject *ob)
{
PyObject *decl, *item;
decl = providedBy(NULL, ob);
if (decl == NULL)
return NULL;
if (PyObject_TypeCheck(decl, &SpecType))
item = Spec_extends(decl, self);
else
/*
没有合适的资源?快使用搜索试试~ 我知道了~
尝试python+flask构建web项目.zip
共1900个文件
py:1580个
txt:51个
pyd:43个
需积分: 5 0 下载量 135 浏览量
2023-09-28
12:30:31
上传
评论
收藏 8.14MB ZIP 举报
温馨提示
尝试python+flask构建web项目
资源推荐
资源详情
资源评论
收起资源包目录
尝试python+flask构建web项目.zip (1900个子文件)
_awaittests.py.3only 6KB
_yieldfromtests.py.3only 4KB
_deprecatetests.py.3only 2KB
LICENSE.APACHE 11KB
python.bmp 778B
LICENSE.BSD 1KB
_zope_interface_coptimizations.c 45KB
_c_ast.cfg 4KB
scrapy.cfg 273B
scrapy.cfg 255B
style.css 6KB
perfmondata.dll 17KB
twist.exe 100KB
mailmail.exe 100KB
ckeygen.exe 100KB
tkconch.exe 100KB
conch.exe 100KB
cftp.exe 100KB
pyhtmlizer.exe 100KB
twistd.exe 100KB
scrapy.exe 100KB
trial.exe 100KB
automat-visualize.exe 100KB
flask.exe 100KB
pip.exe 73KB
pip3.exe 73KB
easy_install.exe 73KB
easy_install-3.6.exe 73KB
pip3.6.exe 73KB
pythonservice.exe 18KB
FONT_LICENSE 5KB
xpathparser.g 18KB
instancemessenger.glade 75KB
_embedding.h 16KB
_cffi_include.h 12KB
parse_c_type.h 6KB
_cffi_errors.h 4KB
test.h 2KB
index.html 3KB
common.html 3KB
summary.html 2KB
index.html 246B
python.ico 766B
TestFlask.iml 837B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
INSTALLER 4B
jquery.js 94KB
jquery.min.js 82KB
debugger.js 6KB
test_ajax.js 387B
metadata.json 2KB
metadata.json 1KB
metadata.json 1KB
metadata.json 1KB
metadata.json 1KB
metadata.json 1KB
metadata.json 1KB
metadata.json 1KB
metadata.json 983B
metadata.json 983B
metadata.json 927B
metadata.json 923B
metadata.json 703B
pip-selfcheck.json 59B
pbr.json 47B
pbr.json 47B
pywintypes.lib 112KB
LICENSE 2KB
LICENSE 1KB
LICENSE 352B
rfc822.message 4KB
METADATA 18KB
METADATA 18KB
METADATA 13KB
METADATA 11KB
METADATA 9KB
METADATA 7KB
共 1900 条
- 1
- 2
- 3
- 4
- 5
- 6
- 19
资源评论
天天501
- 粉丝: 605
- 资源: 4666
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功