当前位置: 首页>>代码示例>>Python>>正文


Python match.match函数代码示例

本文整理汇总了Python中match.match函数的典型用法代码示例。如果您正苦于以下问题:Python match函数的具体用法?Python match怎么用?Python match使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了match函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: seek_time_ok

def seek_time_ok(FILENAME,ERRORS):

  # create a video reader using the tiny videofile VIDEOS+FILENAME
  video=cvCreateFileCapture(VIDEOS+FILENAME)

  if video is None:
    # couldn't open video (FAIL)
    return 1

  if show_frames:
    cvNamedWindow("test", CV_WINDOW_AUTOSIZE)

  # skip 2 frames and read 3rd frame each until EOF and check if the read image is ok
  for k in [0,3,6,9,12,15,18,21,24,27]:

    cvSetCaptureProperty(video, CV_CAP_PROP_POS_MSEC, k*40)

    # try to query frame
    image=cvQueryFrame(video)

    if image is None:
    # returned image is NULL (FAIL)
      return 1

    compresult = match.match(image,k,ERRORS[k])
    if not compresult:
      return 1

    if show_frames:
      cvShowImage("test",image)
      cvWaitKey(200)

  # same as above, just backwards...
  for k in [27,24,21,18,15,12,9,6,3,0]:

    cvSetCaptureProperty(video, CV_CAP_PROP_POS_MSEC, k*40)

    # try to query frame
    image=cvQueryFrame(video)

    if image is None:
    # returned image is NULL (FAIL)
      return 1

    compresult = match.match(image,k,ERRORS[k])
    if not compresult:
      return 1

    if show_frames:
      cvShowImage("test",image)
      cvWaitKey(200)

  # ATTENTION: We do not release the video reader, window or any image.
  # This is bad manners, but Python and OpenCV don't care,
  # the whole memory segment will be freed on finish anyway...

  del video
  # everything is fine (PASS)
  return 0
开发者ID:Ikem,项目名称:opencv-1.1.0,代码行数:59,代码来源:seek_test.py

示例2: test_no_match

    def test_no_match(self):
        vals = []
        vals.append(match("a"))
        vals.append(match("AB"))
        vals.append(match("A B"))

        for val in vals:
            self.assertIsNone(val, msg="Invalid pattern matched!")
开发者ID:astonshane,项目名称:DavisPutnamNoCNF,代码行数:8,代码来源:test_match.py

示例3: test_find_match

 def test_find_match(self):
     body1 = Mock()
     body2 = Mock()
     match_cases = {
         MatchKey('tests', [], []) : 'body1()',
         MatchKey('test', [], []) : 'body2()'}
     match('test', match_cases)
     self.assertFalse(body1.called)
     self.assertTrue(body2.called)
开发者ID:mnussbaum,项目名称:python-match,代码行数:9,代码来源:match_tests.py

示例4: test_harder_match

 def test_harder_match(self):
     body1 = Mock()
     body2 = Mock()
     match_cases = {
         MatchKey('test %s %M %M', ['this'], ['var1', 'var2']) : \
           'body1()',
         MatchKey('test %s %M', ['this'], ['var1']) : 'body2(var1)'}
     match('test this case', match_cases)
     self.assertFalse(body1.called)
     body2.assert_called_once_with('case')
开发者ID:mnussbaum,项目名称:python-match,代码行数:10,代码来源:match_tests.py

示例5: test_condition_match

 def test_condition_match(self):
     body1 = Mock()
     body2 = Mock()
     match_cases = {
         MatchKey('test %M', [], [(lambda x : False, 'var1')]) \
         : 'body1()',
         MatchKey('test %M', [], [(lambda x : x == 'a', 'var1')]) \
         : 'body2()'}
     match('test a', match_cases)
     self.assertFalse(body1.called)
     self.assertTrue(body2.called)
开发者ID:mnussbaum,项目名称:python-match,代码行数:11,代码来源:match_tests.py

示例6: checkstatus

def checkstatus(repo, subset, pat, field):
    m = None
    s = []
    fast = not matchmod.patkind(pat)
    for r in subset:
        c = repo[r]
        if fast:
            if pat not in c.files():
                continue
        else:
            if not m or matchmod.patkind(pat) == 'set':
                m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
            for f in c.files():
                if m(f):
                    break
            else:
                continue
        files = repo.status(c.p1().node(), c.node())[field]
        if fast:
            if pat in files:
                s.append(r)
        else:
            for f in files:
                if m(f):
                    s.append(r)
                    break
    return s
开发者ID:agbiotec,项目名称:galaxy-tools-vcr,代码行数:27,代码来源:revset.py

示例7: apply_promo_store

def apply_promo_store(userid, store_name):
    itemlist = find_shelf(userid, store_name)
    num_items = len(itemlist)
    print "Apply_promo: We have " + str(num_items) + " items in " + store_name + " shelf."
    total_combinations = 1 << (num_items)
    total_combinations -= 1
    print "Total combination: " + str(total_combinations)
    date_ = datetime.date.today()
    promo_date = Promoinfo.objects.filter(d=date_)
    if store_name == "Express":
        i = 0
    if store_name == "J.Crew":
        i = 1
    promo = promo_date.filter(store__id=i)

    # for all possible combinations
    # find the price by calling match.py
    # upper bound is total_combinations+1 because we are starting with index 1
    # and that is because we don't want to calculate discount for an empty wishlist
    # which will happen when j = 0

    for j in range(1, total_combinations + 1):
        wishlist = find_combination(itemlist, j)
        cached_result, digest = check_if_combination_exists(wishlist)
        if cached_result == None:
            print "No, didn't find result for list " + str(j) + " in cache, so storing it"
            orig_cost, total_cost, savings, shipping = match.match(store_name, date_, copy.deepcopy(wishlist), promo)
            # store this result
            new_result = StoreItemCombinationResults(
                combination_id=digest, price=orig_cost, saleprice=total_cost, free_shipping=shipping
            )
            new_result.save()

    print "Done with apply_promo_store"
开发者ID:rkishore,项目名称:shelf_on_rails,代码行数:34,代码来源:view_shelf.py

示例8: checkstatus

def checkstatus(repo, subset, pat, field):
    m = None
    s = []
    hasset = matchmod.patkind(pat) == 'set'
    fname = None
    for r in subset:
        c = repo[r]
        if not m or hasset:
            m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
            if not m.anypats() and len(m.files()) == 1:
                fname = m.files()[0]
        if fname is not None:
            if fname not in c.files():
                continue
        else:
            for f in c.files():
                if m(f):
                    break
            else:
                continue
        files = repo.status(c.p1().node(), c.node())[field]
        if fname is not None:
            if fname in files:
                s.append(r)
        else:
            for f in files:
                if m(f):
                    s.append(r)
                    break
    return s
开发者ID:Pelonza,项目名称:Learn2Mine-Main,代码行数:30,代码来源:revset.py

示例9: do_match

def do_match(img1, img2, cang, crat, cdesc):
    M = None

    # Get features and distances between every pair of points from both images
    (kpts1, des1) = get_features(img1, M, 'target.jpg')
    (kpts2, des2) = get_features(img2, M, 'reference.jpg')

    Hgt = Hypergraph(kpts1, des1)
    Hgr = Hypergraph(kpts2, des2)

    # draw.triangulation(kpts1, Hgt.E, img1, 'Triangulation 1')
    # draw.triangulation(kpts2, Hgr.E, img2, 'Triangulation 2')

    print 'Hypergraph construction done'
    edge_matches, point_matches = match(
        Hgt.E, Hgr.E, kpts1, kpts2, des1, des2,
        cang, crat, cdesc,
        0.7, 0.75, True
    )
    print 'Hyperedges matching done'

    # draw.edges_match(edge_matches, kpts1, kpts2, Hgt.E, Hgr.E, img1, img2)

    point_matches = sorted(point_matches, key=lambda x: x.distance)
    draw.points_match(point_matches, kpts1, kpts2, img1, img2)

    cv2.waitKey()
    cv2.destroyAllWindows()
开发者ID:kala855,项目名称:hypergraphs-matching,代码行数:28,代码来源:main.py

示例10: validate

 def validate(self, first, second):
     """
     Compares first to second to determine if they sufficiently agree.
     """
     matches = match(first, second,
                     lambda x, y: self.overlapcost(x, y))
     return sum(x[2] != 0 for x in matches) <= self.mistakes
开发者ID:ALexanderpu,项目名称:vatic,代码行数:7,代码来源:qa.py

示例11: checkstatus

def checkstatus(repo, subset, pat, field):
    m = matchmod.match(repo.root, repo.getcwd(), [pat])
    s = []
    fast = (m.files() == [pat])
    for r in subset:
        c = repo[r]
        if fast:
            if pat not in c.files():
                continue
        else:
            for f in c.files():
                if m(f):
                    break
            else:
                continue
        files = repo.status(c.p1().node(), c.node())[field]
        if fast:
            if pat in files:
                s.append(r)
                continue
        else:
            for f in files:
                if m(f):
                    s.append(r)
                    continue
    return s
开发者ID:MezzLabs,项目名称:mercurial,代码行数:26,代码来源:revset.py

示例12: _matchfiles

def _matchfiles(repo, subset, x):
    # _matchfiles takes a revset list of prefixed arguments:
    #
    #   [p:foo, i:bar, x:baz]
    #
    # builds a match object from them and filters subset. Allowed
    # prefixes are 'p:' for regular patterns, 'i:' for include
    # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass
    # a revision identifier, or the empty string to reference the
    # working directory, from which the match object is
    # initialized. Use 'd:' to set the default matching mode, default
    # to 'glob'. At most one 'r:' and 'd:' argument can be passed.

    # i18n: "_matchfiles" is a keyword
    l = getargs(x, 1, -1, _("_matchfiles requires at least one argument"))
    pats, inc, exc = [], [], []
    hasset = False
    rev, default = None, None
    for arg in l:
        s = getstring(arg, _("_matchfiles requires string arguments"))
        prefix, value = s[:2], s[2:]
        if prefix == 'p:':
            pats.append(value)
        elif prefix == 'i:':
            inc.append(value)
        elif prefix == 'x:':
            exc.append(value)
        elif prefix == 'r:':
            if rev is not None:
                raise error.ParseError(_('_matchfiles expected at most one '
                                         'revision'))
            rev = value
        elif prefix == 'd:':
            if default is not None:
                raise error.ParseError(_('_matchfiles expected at most one '
                                         'default mode'))
            default = value
        else:
            raise error.ParseError(_('invalid _matchfiles prefix: %s') % prefix)
        if not hasset and matchmod.patkind(value) == 'set':
            hasset = True
    if not default:
        default = 'glob'
    m = None
    s = []
    for r in subset:
        c = repo[r]
        if not m or (hasset and rev is None):
            ctx = c
            if rev is not None:
                ctx = repo[rev or None]
            m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc,
                               exclude=exc, ctx=ctx, default=default)
        for f in c.files():
            if m(f):
                s.append(r)
                break
    return s
开发者ID:Pelonza,项目名称:Learn2Mine-Main,代码行数:58,代码来源:revset.py

示例13: apply_promo

def apply_promo(request, d1, d2):
    if "u" in request.GET and request.GET["u"]:
        userid = urllib.unquote(request.GET["u"].decode("utf-8"))
        result_list = {}
        # for each store-shelf
        shelf_per_store = find_shelf_store_based_for_user(userid)
        for i in range(0, len(shelf_per_store)):
            # how many items in this shelf
            store_name = stores[i]
            num_items = len(shelf_per_store[store_name])
            print "Apply_promo: We have " + str(num_items) + " items in " + store_name + " shelf."
            total_combinations = 1 << (num_items)
            total_combinations -= 1
            print "Total combination: " + str(total_combinations)
            date_ = datetime.date.today()
            promo_date = Promoinfo.objects.filter(d=date_)
            promo = promo_date.filter(store__id=i)

            # for all possible combinations
            # find the price by calling match.py
            # upper bound is total_combinations+1 because we are starting with index 1
            # and that is because we don't want to calculate discount for an empty wishlist
            # which will happen when j = 0
            itemlist = []
            for j in range(1, total_combinations + 1):
                wishlist = find_combination(shelf_per_store[store_name], j)
                cached_result, digest = check_if_combination_exists(wishlist)
                if cached_result == None:
                    print "No, didn't find result for list " + str(j) + " in cache, so storing it"
                    orig_cost, total_cost, savings, shipping = match.match(
                        store_name, date_, copy.deepcopy(wishlist), promo
                    )
                    # store this result
                    new_result = StoreItemCombinationResults(
                        combination_id=digest, price=orig_cost, saleprice=total_cost, free_shipping=shipping
                    )
                    new_result.save()
                else:
                    print "Great, found the result! Using it here."
                    orig_cost = cached_result.price
                    total_cost = cached_result.saleprice
                    savings = cached_result.price - cached_result.saleprice
                    shipping = cached_result.free_shipping

                print "RESULT:: " + str(j) + " " + str(store_name) + " " + str(orig_cost) + " " + str(
                    total_cost
                ) + " " + str(savings)
                itemlist.append(
                    {"orig_cost": orig_cost, "total_cost": total_cost, "savings": savings, "shipping": shipping}
                )

            result_list[store_name] = itemlist
        return list_detail.object_list(
            request,
            queryset=WishlistI.objects.none(),
            template_name="apply_promo.html",
            extra_context={"uid": userid, "result_list": result_list},
        )
开发者ID:rkishore,项目名称:shelf_on_rails,代码行数:58,代码来源:view_shelf.py

示例14: match

def match(repo, pats=[], opts={}, globbed=False, default='relpath'):
    if not globbed and default == 'relpath':
        pats = expandpats(pats or [])
    m = _match.match(repo.root, repo.getcwd(), pats,
                    opts.get('include'), opts.get('exclude'), default)
    def badfn(f, msg):
        repo.ui.warn("%s: %s\n" % (m.rel(f), msg))
    m.bad = badfn
    return m
开发者ID:Frostman,项目名称:intellij-community,代码行数:9,代码来源:cmdutil.py

示例15: find_price_of_wishlist_for_store

def find_price_of_wishlist_for_store(wishlist, store_name, store_id, date_):
    '''
    Find the total price for the items in the wishlist from store_name and on date_
    '''
    promo_date = Promoinfo.objects.filter(d = date_)
    promo_store = promo_date.filter(store__id = store_id)
    promo = promo_store
    orig_cost, total_cost, savings, shipping = match.match(store_name, date_, copy.deepcopy(wishlist), promo)
    return (orig_cost, total_cost, savings, shipping)
开发者ID:rkishore,项目名称:shelf_on_rails,代码行数:9,代码来源:view_mock_wishlist.py


注:本文中的match.match函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。