python类get()的实例源码

dal.py 文件源码 项目:spc 作者: whbrewer 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _create_references(self):
        db = self._db
        pr = db._pending_references
        self._referenced_by = []
        for field in self:
            fieldname = field.name
            field_type = field.type
            if isinstance(field_type,str) and field_type[:10] == 'reference ':
                ref = field_type[10:].strip()
                if not ref.split():
                    raise SyntaxError('Table: reference to nothing: %s' %ref)
                refs = ref.split('.')
                rtablename = refs[0]
                if not rtablename in db:
                    pr[rtablename] = pr.get(rtablename,[]) + [field]
                    continue
                rtable = db[rtablename]
                if len(refs)==2:
                    rfieldname = refs[1]
                    if not hasattr(rtable,'_primarykey'):
                        raise SyntaxError(
                            'keyed tables can only reference other keyed tables (for now)')
                    if rfieldname not in rtable.fields:
                        raise SyntaxError(
                            "invalid field '%s' for referenced table '%s' in table '%s'" \
                            % (rfieldname, rtablename, self._tablename))
                rtable._referenced_by.append(field)
        for referee in pr.get(self._tablename,[]):
            self._referenced_by.append(referee)
dal.py 文件源码 项目:spc 作者: whbrewer 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _select(self, *fields, **attributes):
        adapter = self.db._adapter
        tablenames = adapter.tables(self.query,
                                    attributes.get('join',None),
                                    attributes.get('left',None),
                                    attributes.get('orderby',None),
                                    attributes.get('groupby',None))
        fields = adapter.expand_all(fields, tablenames)
        return adapter._select(self.query,fields,attributes)
dal.py 文件源码 项目:spc 作者: whbrewer 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def select(self, *fields, **attributes):
        adapter = self.db._adapter
        tablenames = adapter.tables(self.query,
                                    attributes.get('join',None),
                                    attributes.get('left',None),
                                    attributes.get('orderby',None),
                                    attributes.get('groupby',None))
        fields = adapter.expand_all(fields, tablenames)
        return adapter.select(self.query,fields,attributes)
dal.py 文件源码 项目:spc 作者: whbrewer 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def delete_uploaded_files(self, upload_fields=None):
        table = self.db[self.db._adapter.tables(self.query)[0]]
        # ## mind uploadfield==True means file is not in DB
        if upload_fields:
            fields = upload_fields.keys()
        else:
            fields = table.fields
        fields = [f for f in fields if table[f].type == 'upload'
                   and table[f].uploadfield == True
                   and table[f].autodelete]
        if not fields:
            return False
        for record in self.select(*[table[f] for f in fields]):
            for fieldname in fields:
                field = table[fieldname]
                oldname = record.get(fieldname, None)
                if not oldname:
                    continue
                if upload_fields and oldname == upload_fields[fieldname]:
                    continue
                if field.custom_delete:
                    field.custom_delete(oldname)
                else:
                    uploadfolder = field.uploadfolder
                    if not uploadfolder:
                        uploadfolder = pjoin(
                            self.db._adapter.folder, '..', 'uploads')
                    if field.uploadseparate:
                        items = oldname.split('.')
                        uploadfolder = pjoin(
                            uploadfolder,
                            "%s.%s" % (items[0], items[1]),
                            items[2][:2])
                    oldpath = pjoin(uploadfolder, oldname)
                    if exists(oldpath):
                        os.unlink(oldpath)
        return False
base.py 文件源码 项目:Problematica-public 作者: TechMaz 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _select_aux(self, sql, fields, attributes):
        args_get = attributes.get
        cache = args_get('cache',None)
        if not cache:
            self.execute(sql)
            rows = self._fetchall()
        else:
            if isinstance(cache, dict):
                cache_model = cache['model']
                time_expire = cache['expiration']
                key = cache.get('key')
                if not key:
                    key = self.uri + '/' + sql + '/rows'
                    key = hashlib_md5(key).hexdigest()
            else:
                (cache_model, time_expire) = cache
                key = self.uri + '/' + sql + '/rows'
                key = hashlib_md5(key).hexdigest()
            def _select_aux2():
                self.execute(sql)
                return self._fetchall()
            rows = cache_model(key,_select_aux2,time_expire)
        if isinstance(rows,tuple):
            rows = list(rows)
        limitby = args_get('limitby', None) or (0,)
        rows = self.rowslice(rows,limitby[0],None)
        processor = args_get('processor', self.parse)
        cacheable = args_get('cacheable',False)
        return processor(rows,fields,self._colnames,cacheable=cacheable)
base.py 文件源码 项目:Problematica-public 作者: TechMaz 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def EXPAND_CASE(self, query, true_false):
        def represent(x):
            types = {type(True):'boolean',type(0):'integer',type(1.0):'double'}
            if x is None: return 'NULL'
            elif isinstance(x,Expression): return str(x)
            else: return self.represent(x,types.get(type(x),'string'))

        return 'CASE WHEN %s THEN %s ELSE %s END' % (
            self.expand(query),
            represent(true_false[0]),
            represent(true_false[1]))
lldbinit.py 文件源码 项目:LLDB_Tools 作者: blankwall 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def eval(self, **kwds):
            """
            modules -- dictionary of module name to SBModule
            current_module -- current frame's module
            """
            modules = kwds['modules']
            m = modules.get(self.module, kwds['current_module'])
            s = next(s for s in m.symbols if s.name == self.symbol)
            a = s.addr
            return a.load_addr
lldbinit.py 文件源码 项目:LLDB_Tools 作者: blankwall 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def repr(cls, s):
        TYPE_PREFIX = 'eTypeClass'
        start = cls.address(s)
        end = start + cls.size(s)

        types = {getattr(lldb,n) : n[len(TYPE_PREFIX):] for n in dir(lldb) if n.startswith(TYPE_PREFIX)}
        attributes = (n for n in ('external','synthetic') if getattr(s,n))
        if s.type in (lldb.eTypeClassFunction,):
            attributes = itertools.chain(attributes, ('instructions={:d}'.format(len(s.instructions))))
        attributes=filter(None,attributes)
        return '{name:s}{opt_mangled:s} type={type:s} 0x{addr:x}{opt_size:s}'.format(name=s.name, type=types.get(s.type,str(s.type)), opt_mangled=(' ('+s.mangled+')') if s.mangled else '', addr=start, opt_size=':+0x{:x}'.format(end-start) if end > start else '') + ((' ' + ' '.join(attributes)) if attributes else '')
lldbinit.py 文件源码 项目:LLDB_Tools 作者: blankwall 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _dump(cls, data, kind=1):
        lookup = {1:'B', 2:'H', 4:'I', 8:'L'}
        itemtype = lookup.get(kind, kind)
        return array.array(itemtype, data)

    ## specific dumping formats
lldbinit.py 文件源码 项目:LLDB_Tools 作者: blankwall 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __set_enabled(cls, id, bool):
        bp = cls.get(id)
        res, _ = bp.IsEnabled(), bp.SetEnabled(bool)
        return res
lldbinit.py 文件源码 项目:LLDB_Tools 作者: blankwall 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get(cls, id):
        res = cls.cache[id]
        return cls.__internal__[res]
lldbinit.py 文件源码 项目:LLDB_Tools 作者: blankwall 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def rm_command(cls, target, id):
        debugger = target.GetDebugger()
        bp = cls.get(id)
        bptype = 'breakpoint' if isinstance(bp, lldb.SBBreakpoint) else 'watchpoint'
        return debugger.HandleCommand("{:s} command delete {:d}".format(bptype, bp.GetID()))
lldbinit.py 文件源码 项目:LLDB_Tools 作者: blankwall 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def remove(cls, target, id):
        key, bp = cls.cache[id], cls.get(id)
        if not isinstance(bp, (lldb.SBBreakpoint, lldb.SBWatchpoint)):
            raise TypeError("{:s}.{:s}.remove : Unable to remove unknown breakpoint type. : {!r}".format(__name__, cls.__name__, bp.__class__))
        cls.rm_command(target, id)
        cls.__rm_cache(id)
        cls.__rm_address(bp)
        cls.__expression__.pop(key)
        cls.__function__.pop(key)
        return target.BreakpointDelete(bp.GetID()) if isinstance(bp, lldb.SBBreakpoint) else target.DeleteWatchpoint(bp.GetID())
lldbinit.py 文件源码 项目:LLDB_Tools 作者: blankwall 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def repr(cls, id):
        key, bp = cls.cache[id], cls.get(id)
        addr, size = cls.__location(bp)
        expr = cls.__expression__.get(key, None)
        if isinstance(expr, list):
            expr = ' -- ' + ';'.join(expr)
        elif expr is None:
            expr = ''
        else:
            expr = ' -- ' + repr(expr)
        return '0x{:x}:+{:d} -- {{{:s}}}'.format(addr, size, 'enabled' if bp.IsEnabled() else 'disabled') + expr
static.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def getCachedPath(self, path):
        return self._pathCache.get(path)
static.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def getTypeAndEncoding(filename, types, encodings, defaultType):
    p, ext = os.path.splitext(filename)
    ext = ext.lower()
    if encodings.has_key(ext):
        enc = encodings[ext]
        ext = os.path.splitext(p)[1].lower()
    else:
        enc = None
    type = types.get(ext, defaultType)
    return type, enc
static.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def getChild(self, path, request):
        """See twisted.web.Resource.getChild.
        """
        self.restat()

        if not self.isdir():
            return self.childNotFound

        if path:
            fpath = self.child(path)
        else:
            fpath = self.childSearchPreauth(*self.indexNames)
            if fpath is None:
                return self.directoryListing()

        if not fpath.exists():
            fpath = fpath.siblingExtensionSearch(*self.ignoredExts)
            if fpath is None:
                return self.childNotFound

        if platformType == "win32":
            # don't want .RPY to be different than .rpy, since that would allow
            # source disclosure.
            processor = InsensitiveDict(self.processors).get(fpath.splitext()[1])
        else:
            processor = self.processors.get(fpath.splitext()[1])
        if processor:
            return resource.IResource(processor(fpath.path, self.registry))
        return self.createSimilarFile(fpath.path)

    # methods to allow subclasses to e.g. decrypt files on the fly:
lldbinit.py 文件源码 项目:MacHeap 作者: blankwall 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def eval(self, **kwds):
            """
            modules -- dictionary of module name to SBModule
            current_module -- current frame's module
            """
            modules = kwds['modules']
            m = modules.get(self.module, kwds['current_module'])
            s = next(s for s in m.symbols if s.name == self.symbol)
            a = s.addr
            return a.load_addr
lldbinit.py 文件源码 项目:MacHeap 作者: blankwall 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def repr(cls, s):
        TYPE_PREFIX = 'eTypeClass'
        start = cls.address(s)
        end = start + cls.size(s)

        types = {getattr(lldb,n) : n[len(TYPE_PREFIX):] for n in dir(lldb) if n.startswith(TYPE_PREFIX)}
        attributes = (n for n in ('external','synthetic') if getattr(s,n))
        if s.type in (lldb.eTypeClassFunction,):
            attributes = itertools.chain(attributes, ('instructions={:d}'.format(len(s.instructions))))
        attributes=filter(None,attributes)
        return '{name:s}{opt_mangled:s} type={type:s} 0x{addr:x}{opt_size:s}'.format(name=s.name, type=types.get(s.type,str(s.type)), opt_mangled=(' ('+s.mangled+')') if s.mangled else '', addr=start, opt_size=':+0x{:x}'.format(end-start) if end > start else '') + ((' ' + ' '.join(attributes)) if attributes else '')
lldbinit.py 文件源码 项目:MacHeap 作者: blankwall 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _dump(cls, data, kind=1):
        lookup = {1:'B', 2:'H', 4:'I', 8:'L'}
        itemtype = lookup.get(kind, kind)
        return array.array(itemtype, data)

    ## specific dumping formats


问题


面经


文章

微信
公众号

扫码关注公众号