This file is indexed.

/usr/share/pyshared/couchdbkit/loaders.py is in python-couchdbkit 0.6.5-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# -*- coding: utf-8 -
#
# This file is part of couchdbkit released under the MIT license. 
# See the NOTICE for more information.

"""
Loaders are a simple way to manage design docs in your Python application. 
Loaders are compatible with couchapp script (http://github.com/couchapp/couchapp).
So it means that you can simply use couchdbkit as replacement for your python
applications with advantages of couchdbkit client. Compatibility with couchapp means that
you can also use macros to include javascript code or design doc members in your views,
shows & lists.

Loaders are FileSystemDocsLoader and FileSystemDocLoader. The first
one takes a directory and retrieve all design docs before sending them to
CouchDB. Second allow you to send only one design doc.

This module is here for compatibility reason and will be removed in 0.6.
It's replaced by couchdbkit.designer module and push* functions.
"""
from __future__ import with_statement

from .designer import document, push, pushapps, pushdocs

class BaseDocsLoader(object):
    """Baseclass for all doc loaders. """
   
    def get_docs(self):
        raise NotImplementedError

    def sync(self, dbs, atomic=True, **kwargs):
        raise NotImplementedError

class FileSystemDocsLoader(BaseDocsLoader):
    """ Load docs from the filesystem. This loader can find docs
    in folders on the filesystem and is the preferred way to load them. 
    
    The loader takes the path for design docs as a string  or if multiple
    locations are wanted a list of them which is then looked up in the
    given order:

    >>> loader = FileSystemDocsLoader('/path/to/templates')
    >>> loader = FileSystemDocsLoader(['/path/to/templates', '/other/path'])
    
    You could also do the same to loads docs.
    """

    def __init__(self, designpath, docpath=None):
        if isinstance(designpath, basestring):
            self.designpaths = [designpath]
        else:
            self.designpaths = designpath

        docpath = docpath or []
        if isinstance(docpath, basestring):
            docpath = [docpath]
        self.docpaths = docpath            
        

    def get_docs(self):
        docs = []
        for path in self.docpaths:
            ret = pushdocs(path, [], export=True)
            docs.extend(ret['docs'])

        for path in self.designpaths:
            ret = pushapps(path, [], export=True)
            docs.extend(ret['docs'])
        return docs

        
    def sync(self, dbs, atomic=True, **kwargs):
        for path in self.docpaths:
            pushdocs(path, dbs, atomic=atomic)

        for path in self.designpaths:
            pushapps(path, dbs, atomic=atomic)
 
class FileSystemDocLoader(BaseDocsLoader):
    """ Load only one design doc from a path on the filesystem.
        
        >>> loader = FileSystemDocLoader("/path/to/designdocfolder", "nameodesigndoc")
    """
    
    def __init__(self, designpath, name, design_name=None):
        self.designpath = designpath
        self.name = name
        if not design_name.startswith("_design"):
            design_name = "_design/%s" % design_name
        self.design_name = design_name

    def get_docs(self):
        return document(self.design_path, create=False,
                docid=self.design_name)

    def sync(self, dbs, atomic=True, **kwargs):
        push(self.design_path, dbs, atomic=atomic,
                docid=self.design_name)