Example #1
0
def get_files_from_data(data, original, files, inlinefiles, original_files, prefix):
    if isinstance(data, File):
        get_file_from_item(data, original, files, inlinefiles, original_files, get_attr(prefix))
        return
    if not isinstance(data, dict) and not isinstance(data, list):
        return
    dd = dotted_or_emptydict(data)
    ddoriginal = dotted_or_emptydict(original)
    if not dd:
        return
    file_names = {}
    for _, d in flatten(ddoriginal):
        if isinstance(d, File):
            file_names[couch_attachement_to_full_id(d)] = d
    for k,f in flatten(dd):
        
        if isinstance(f, File):
            name = couch_attachement_to_full_id(f)
            if name in file_names:
                of = file_names[name]
            elif isinstance(ddoriginal.get(k), File):
                of = ddoriginal[k]
            else:
                of = None
            get_file_from_item(f, of, files, inlinefiles, original_files, get_attr(prefix, k))
Example #2
0
def find_all_file_names(src):
    if isinstance(src, File):
        yield couch_attachement_to_full_id(src)
    elif isinstance(src, dict) or isinstance(src, list):
        dd = dotted_or_emptydict(src)
        for _, item in flatten(dd):
            if isinstance(item, File):
                yield couch_attachement_to_full_id(item)
Example #3
0
def get_files_from_original(data, original, files, inlinefiles, original_files, prefix):
    if isinstance(original, File):
        get_file_from_original(data, original, files, inlinefiles, original_files, get_attr(prefix))
        return
    if not isinstance(original, dict) and not isinstance(original, list):
        return
    dd = dotted_or_emptydict(data)
    ddoriginal = dotted_or_emptydict(original)
    if not ddoriginal:
        return
    for k, of in flatten(ddoriginal):
        if isinstance(of, File):
            f = dd.get(k)
            get_file_from_original(f, of, files, inlinefiles, original_files, get_attr(prefix, k))
    def request(self, d):
        r = webob.Request.blank('http://localhost/')
        r.method = 'POST'
        r.content_type = 'application/x-www-form-urlencoded'
        kvpairs = []
        for k,v in flatten(d):
            lastsegment = k.split('.')[-1]
            try:
                int(lastsegment)
                k = '.'.join(k.split('.')[:-1])
            except ValueError:
                pass
            for v in d[k]:
                kvpairs.append( (k,v) )

        r.body = urllib.urlencode(kvpairs)
        return r
Example #5
0
def add_id_and_attr_to_files(data, session=None):
    if not isinstance(data, dict):
        return data
    dd = dotted(data)
    for k,f in flatten(data):
        if isinstance(f,File):
            if '_id' in dd and '_rev' in dd:
                if session:
                    f.file = AttachmentFileLike(session, dd['_id'], f.id)
                f.doc_id = dd['_id']
                f.rev = dd['_rev']
            segments = k.split('.')
            for n in xrange(1,len(segments)):
                subpath = '.'.join(segments[:-n])
                if '_id' in dd[subpath] and '_rev' in dd[subpath]:
                    f.doc_id = dd[subpath]['_id']
                    f.rev = dd[subpath]['_rev']
    return data