Exemplo n.º 1
0
    def find(self, p="_", depth=-1, skip=None, keys=(),
             tops=False, setns=False):
        '''
        p is an argument to search.pattern,
        depth: int, skip: function, keys: (str...) -> r: generator

        this is a generator over keys k such that p == self[k]

        if keys is specified, then depth and skip are ignored, and the search
        is performed only over keys. Otherwise, the search is performed over
        self.iter(depth, skip)

        if tops is true, and p can match Docs, then the subkeys of any subdoc that
        matches p will not be searched. This will only work as expected if "keys"
        is not set.

        If setns is True, then p should be a search.Pattern instance. This function
        will assign self to the key "doc" in p.ns, and call p.setup before searching.

        Note that this is a generator, not a function that returns a collection.
        To get the list of hits, use [k for k in self.find(...)]

        (this idiom is bound to self.findall)

        To get the first hit, use:
        try:
            v = self.find.next()
        except StopIteration:
            #nothing found
            v = None

        '''
        if keys:
            keys = keys.__iter__()
        else:
            keys = self.iter(depth, skip)
        p = search.pattern(p)
        if setns:
            p.ns['doc'] = self
            p.setup()
        v = False
        while True:
            if v and tops:
                k = keys.send(True)
            else:
                k = keys.next()
            v = bool(p == self.get(k))
            if v:
                (yield k)
Exemplo n.º 2
0
 def __init__(self):
     if self.inputs:
         self.inputs = search.pattern(self.inputs)
     if self.inputs:
         self.outputs = search.pattern(self.outputs)
Exemplo n.º 3
0
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#

#ClassCase, functionCase, datacase

import search
import re
from gicdat.control import report
from threading import Lock

LINK = search.pattern({'_link': 's'})
SLICE = search.pattern({'_link': 's', '_slice': '['})
EXTERN = search.pattern({'_extern_url': 's'})


def ishashable(o):
    try:
        _ = hash(o)
        return True
    except TypeError:
        return False


class DictAccessor(object):
    '''
    This class provides a mapping from item access ([]) to attribute access
Exemplo n.º 4
0
 def __init__(self, pat, info):
     self.__doc__ = info
     self.pat = search.pattern(pat)