Beispiel #1
0
def state(request, doc, type=None):
    slug = "%s-%s" % (doc,type) if type else doc
    debug.show('slug')
    statetype = get_object_or_404(StateType, slug=slug)
    states = State.objects.filter(used=True, type=statetype).order_by('order')
    return render_to_response('help/states.html', {"doc": doc, "type": statetype, "states":states},
        context_instance=RequestContext(request))
Beispiel #2
0
 def to_simple_html(self, data, options):
     """
     """
     from django.template.loader import render_to_string as render
     #
     if isinstance(data, (list, tuple)):
         return render("api/listitem.html", {"data": [self.to_simple_html(item, options) for item in data]})
     if isinstance(data, dict):
         return render("api/dictitem.html", {"data": dict((key, self.to_simple_html(val, options)) for (key, val) in data.items())})
     elif isinstance(data, Bundle):
         return render("api/dictitem.html", {"data":dict((key, self.to_simple_html(val, options)) for (key, val) in data.data.items())})
     elif hasattr(data, 'dehydrated_type'):
         debug.show('data')
         if getattr(data, 'dehydrated_type', None) == 'related' and data.is_m2m == False:
             return render("api/relitem.html", {"fk": data.fk_resource, "val": self.to_simple_html(data.value, options)})
         elif getattr(data, 'dehydrated_type', None) == 'related' and data.is_m2m == True:
             render("api/listitem.html", {"data": [self.to_simple_html(bundle, options) for bundle in data.m2m_bundles]})
         else:
             return self.to_simple_html(data.value, options)
     elif isinstance(data, datetime.datetime):
         return self.format_datetime(data)
     elif isinstance(data, datetime.date):
         return self.format_date(data)
     elif isinstance(data, datetime.time):
         return self.format_time(data)
     elif isinstance(data, bool):
         return data
     elif isinstance(data, (six.integer_types, float)):
         return data
     elif data is None:
         return None
     elif isinstance(data, basestring) and data.startswith("/api/v1/"):  # XXX Will not work for Python 3
         return render("api/relitem.html", {"fk": data, "val": data.split('/')[-2]})
     else:
         return force_text(data)
Beispiel #3
0
def ical_agenda(request, num=None, schedule_name=None):
    meeting = get_meeting(num)

    q = request.META.get('QUERY_STRING','') or ""
    filter = urllib.unquote(q).lower().split(',');
    include = set(filter)
    include_types = set(["Plenary","Other"])
    exclude = []

    # Process the special flags.
    #   "-wgname" will remove a working group from the output.
    #   "~Type" will add that type to the output.
    #   "-~Type" will remove that type from the output
    # Current types are:
    #   Session, Other (default on), Break, Plenary (default on)
    # Non-Working Group "wg names" include:
    #   edu, ietf, tools, iesg, iab

    for item in include:
        if item:
            if item[0] == '-' and item[1] == '~':
                include_types -= set([item[2:3].upper()+item[3:]])
            elif item[0] == '-':
                exclude.append(item[1:])
            elif item[0] == '~':
                include_types |= set([item[1:2].upper()+item[2:]])

    schedule = get_schedule(meeting, schedule_name)
    scheduledsessions = get_scheduledsessions_from_schedule(schedule)

    scheduledsessions = scheduledsessions.filter(
        Q(timeslot__type__name__in = include_types) |
        Q(session__group__acronym__in = filter) |
        Q(session__group__parent__acronym__in = filter)
        ).exclude(Q(session__group__acronym__in = exclude))
        #.exclude(Q(session__group__isnull = False),
        #Q(session__group__acronym__in = exclude) |
        #Q(session__group__parent__acronym__in = exclude))

    if meeting.time_zone:
        try:
            tzfn = os.path.join(settings.TZDATA_ICS_PATH, meeting.time_zone + ".ics")
            tzf = open(tzfn)
            icstext = tzf.read()
            debug.show('icstext[:128]')
            vtimezone = re.search("(?sm)(\nBEGIN:VTIMEZONE.*\nEND:VTIMEZONE\n)", icstext).group(1).strip()
            debug.show('vtimezone[:128]')
            tzf.close()
        except IOError:
            vtimezone = None
    else:
        vtimezone = None

    return HttpResponse(render_to_string("meeting/agendaREDESIGN.ics",
        {"scheduledsessions":scheduledsessions, "meeting":meeting, "vtimezone": vtimezone },
        RequestContext(request)), mimetype="text/calendar")
Beispiel #4
0
def main():
    lines = input_as_list()
    debug.show('Input : [' + ','.join(lines) + ']')

    # Code
    # Constant cast
    # lines = [int(elem) for elem in lines]  # Cast lines values in wanted type !!!

    # Start of code
    print('test')
Beispiel #5
0
def state(request, doc, type=None):
    slug = "%s-%s" % (doc, type) if type else doc
    debug.show('slug')
    statetype = get_object_or_404(StateType, slug=slug)
    states = State.objects.filter(used=True, type=statetype).order_by('order')
    return render_to_response('help/states.html', {
        "doc": doc,
        "type": statetype,
        "states": states
    },
                              context_instance=RequestContext(request))
Beispiel #6
0
def main():
    if CAM == 0:
        provider = MovieImageProvider('../resources/Video5.avi', 0, 0)
    else:
        provider = CamImageProvider(0, '../resources/Video5.avi')
    db.start_at(provider, 110)
    img, imgtime = provider.update_image()
    print(img, imgtime, time.time())
    db.pr([img])
    sd = SquareDetector(img)  # ,imgtime,1, False )
    for i in [0, 30]:
        sd.add_marker(Square(i))

    # win='Result'
    # canny='Canny'
    # tmp='Temp'
    # cv.NamedWindow(win)
    # cv.NamedWindow(tmp)
    # cv.MoveWindow(win,0,0)
    # cv.MoveWindow(tmp,650,0)
    ti = 0.01
    while True:
        k = cv.WaitKey(1)
        if k == 27:
            break
        elif k == 2424832:
            step = -1
        elif k == 32:
            cv.WaitKey(delay=0)
            step = 1
        else:
            step = 1
        start = time.time()
        img, imgtime = provider.update_image()
        if img is None:
            break
        if provider.index == 112:
            pass
        sq = sd.find_markers(img, imgtime)
        sd.draw_markers(img)
        sd.putText("Frame: %d %.3f FPS" % (provider.index, (1 / ti)), (0, 15),
                   (0, 0, 0))
        cv.ShowImage('test', sd.draw_img)
        db.show([img, sd.draw_img, sd.bw_img], 'main', 0, 10)
        ti = time.time() - start
        cv.WaitKey(1)
Beispiel #7
0
def main():
    if CAM == 0:
        provider = MovieImageProvider('../resources/Video5.avi', 0, 0)
    else:
        provider = CamImageProvider(0, '../resources/Video5.avi')
    db.start_at(provider, 110)
    img, imgtime = provider.update_image()
    print(img, imgtime, time.time())
    db.pr([img]);
    sd = SquareDetector(img)  # ,imgtime,1, False )
    for i in [0, 30]:
        sd.add_marker(Square(i))

    # win='Result'
    # canny='Canny'
    # tmp='Temp'
    # cv.NamedWindow(win)
    # cv.NamedWindow(tmp)
    # cv.MoveWindow(win,0,0)
    # cv.MoveWindow(tmp,650,0)
    ti = 0.01
    while True:
        k = cv.WaitKey(1)
        if k == 27:
            break
        elif k == 2424832:
            step = -1
        elif k == 32:
            cv.WaitKey(delay=0)
            step = 1
        else:
            step = 1;
        start = time.time()
        img, imgtime = provider.update_image()
        if img == None:
            break;
        if provider.index == 112:
            pass
        sq = sd.find_markers(img, imgtime)
        sd.draw_markers(img)
        sd.putText("Frame: %d %.3f FPS" % (provider.index, (1 / ti)), (0, 15), (0, 0, 0))
        cv.ShowImage('test', sd.draw_img)
        db.show([img, sd.draw_img, sd.bw_img], 'main', 0, 10)
        ti = time.time() - start
        cv.WaitKey(1)
 def test_validate_corners(self):
     print self.corners
     print self.old_corners
     ncorners = self._prepare_corners(self.points)
     c= ncorners[0]
     prev = add(c.prev,(2,0))
     p = add(c.p,(1,1))
     next= add(c.next,(2,0))
     ncorners[0] = Corner([prev,p,next],1,imgtime=2)
     ncorners[0].compute_change(self.corners[0])
     res = list(ncorners)
     res[0]=None
     print ncorners
     for i,cor in enumerate(ncorners):
         cor.draw(self.draw_img)
         cor.compute_change(self.corners[i])
     db.show(self.draw_img,"main")
     CP = CornerPredictor(self.corners, 1, self.tmp_img, self.timg, self.draw_img)
     CP.validate_corners(ncorners)
     self.assertEqual(ncorners,res,
                      "First corner is invalid:"+ncorners.__repr__())
def main():
    ip= CamImageProvider(0, "../resources/testdata.avi")
    #ip = MovieImageProvider("../resources/testdata.avi",0,0)
    sq = Square(0)
    img,imgtime = ip.getImage(1)
    m_d = SquareDetector(img, imgtime, 2, 0)
    m_d.add_marker(sq)
    angle_min = math.pi
    angle_max = 0
    angle_diff_min = 100
    angle_diff_max = 0
    prop_min  = 40
    prop_max = 0
    rot_max = 0
    debug.start_at(ip, 0)
    while cv.WaitKey(1)<>27:
        img,imgtime = ip.getImage(1)
        if img is None:
            return
#        tmpimg = cv.CloneImage(draw_img)
#        tmpimg2 = cv.CloneImage(draw_img)
#        gray2 = cv.CloneImage(gray)
#        gray3 = cv.CloneImage(gray)
#        tmp = cv.CloneImage(gray)
#        mask = cv.CloneImage(gray)
#        mask2=cv.CloneImage(gray)
#        cv.Set(mask2,1)
#        cv.CvtColor(draw_img, gray, cv.CV_BGR2GRAY)
#        cv.CvtColor(draw_img, tmpimg, cv.CV_BGR2HSV)
#        cv.SetImageCOI(tmpimg, 1)
#        cv.Copy(tmpimg, gray)
#        print cv.MinMaxLoc(gray)
#        cv.ShowImage("gray", gray)
        if debug.is_time():
            pass
        m_d.find_markers(img,imgtime,True)
        mar = m_d.markers[0]
        points = mar.points
        m_d.draw_markers(m_d.draw_img)
        debug.show([m_d.draw_img],"main",1,1)
        #debug.show_images()
        if len(points)<>4 or cv.WaitKey(50)<>32: 
            continue
        a = length(vector(points[0],points[1]))
        b = length(vector(points[1],points[2]))
        c = length(vector(points[2],points[3]))
        d = length(vector(points[3],points[0]))
        if a>c:
            a,c = c,a
        if b>d:
            b,d = d,b
        if c == 0.0:
            print mar
        else:
            print "sides a/c:", a/c
            if a/c > prop_max: prop_max = a/c
            if a/c < prop_min: prop_min = a/c
        if d==0.0:
            print mar
        else:
            print "sides b/d", b/d
            if b/d > prop_max: prop_max = b/d
            if b/d < prop_min: prop_min = b/d
        for cor in mar.corners:
            if cor.angle < angle_min:angle_min = cor.angle
            if cor.angle > angle_max:angle_max = cor.angle
            if cor.rotation > rot_max: rot_max = cor.rotation
        a,b,c,d = [c.angle for c in mar.corners]
        if a>c:
            a,c=c,a
        if b>d:
            b,d=d,b
        if a/c > angle_diff_max: angle_diff_max=a/c
        if a/c< angle_diff_min: angle_diff_min = a/c
        print "angle diff a/c", a/c
        if b/d > angle_diff_max: angle_diff_max=b/d
        if b/d< angle_diff_min: angle_diff_min = b/d
        print "angle diff b/d", b/d
                
    print "angle_min", angle_min
    print "angle_max", angle_max
    print "prop_min", prop_min
    print "prop_max", prop_max
    print "rot_max",rot_max
    print "angle_diff_min", angle_diff_min
    print "angle_diff_max",angle_diff_max
Beispiel #10
0
        verif.append(lines)


builtins.input = fake_input
builtins.print = fake_print

if __name__ == '__main__':
    resume.append("######################################################\n")
    resume.append("######################################################\n")
    resume.append("\t\t\t\t\tRESULTAT\n")
    resume.append("######################################################\n")
    resume.append("######################################################\n")

    for files in glob.glob(folder_path_input + "*"):
        if filtre != "" and files.find(filtre) < 0: continue
        input_file = open(files)
        outputFile = open(files.replace(name_input, name_output))
        read_output()
        coding.main()

        resume.append("Result file : " + input_file.name + "\t\t")
        resume.append("votre sortie : " + str(output) + " ")
        resume.append("vs attendu " + str(verif))
        resume.append(" \t ===========> " + str(output == verif))
        if (output != verif):
            resume.append(" \t ===========>  même joueur joue encore...")
        resume.append("\n")
        output.clear()
        verif.clear()
    debug.show(''.join(resume))
Beispiel #11
0
def main():
    ip = CamImageProvider(0, "../resources/testdata.avi")
    #ip = MovieImageProvider("../resources/testdata.avi",0,0)
    sq = Square(0)
    img, imgtime = ip.getImage(1)
    m_d = SquareDetector(img, imgtime, 2, 0)
    m_d.add_marker(sq)
    angle_min = math.pi
    angle_max = 0
    angle_diff_min = 100
    angle_diff_max = 0
    prop_min = 40
    prop_max = 0
    rot_max = 0
    debug.start_at(ip, 0)
    while cv.WaitKey(1) <> 27:
        img, imgtime = ip.getImage(1)
        if img is None:
            return


#        tmpimg = cv.CloneImage(draw_img)
#        tmpimg2 = cv.CloneImage(draw_img)
#        gray2 = cv.CloneImage(gray)
#        gray3 = cv.CloneImage(gray)
#        tmp = cv.CloneImage(gray)
#        mask = cv.CloneImage(gray)
#        mask2=cv.CloneImage(gray)
#        cv.Set(mask2,1)
#        cv.CvtColor(draw_img, gray, cv.CV_BGR2GRAY)
#        cv.CvtColor(draw_img, tmpimg, cv.CV_BGR2HSV)
#        cv.SetImageCOI(tmpimg, 1)
#        cv.Copy(tmpimg, gray)
#        print cv.MinMaxLoc(gray)
#        cv.ShowImage("gray", gray)
        if debug.is_time():
            pass
        m_d.find_markers(img, imgtime, True)
        mar = m_d.markers[0]
        points = mar.points
        m_d.draw_markers(m_d.draw_img)
        debug.show([m_d.draw_img], "main", 1, 1)
        #debug.show_images()
        if len(points) <> 4 or cv.WaitKey(50) <> 32:
            continue
        a = length(vector(points[0], points[1]))
        b = length(vector(points[1], points[2]))
        c = length(vector(points[2], points[3]))
        d = length(vector(points[3], points[0]))
        if a > c:
            a, c = c, a
        if b > d:
            b, d = d, b
        if c == 0.0:
            print mar
        else:
            print "sides a/c:", a / c
            if a / c > prop_max: prop_max = a / c
            if a / c < prop_min: prop_min = a / c
        if d == 0.0:
            print mar
        else:
            print "sides b/d", b / d
            if b / d > prop_max: prop_max = b / d
            if b / d < prop_min: prop_min = b / d
        for cor in mar.corners:
            if cor.angle < angle_min: angle_min = cor.angle
            if cor.angle > angle_max: angle_max = cor.angle
            if cor.rotation > rot_max: rot_max = cor.rotation
        a, b, c, d = [c.angle for c in mar.corners]
        if a > c:
            a, c = c, a
        if b > d:
            b, d = d, b
        if a / c > angle_diff_max: angle_diff_max = a / c
        if a / c < angle_diff_min: angle_diff_min = a / c
        print "angle diff a/c", a / c
        if b / d > angle_diff_max: angle_diff_max = b / d
        if b / d < angle_diff_min: angle_diff_min = b / d
        print "angle diff b/d", b / d

    print "angle_min", angle_min
    print "angle_max", angle_max
    print "prop_min", prop_min
    print "prop_max", prop_max
    print "rot_max", rot_max
    print "angle_diff_min", angle_diff_min
    print "angle_diff_max", angle_diff_max
Beispiel #12
0
def ical_agenda(request, num=None, schedule_name=None):
    meeting = get_meeting(num)

    q = request.META.get('QUERY_STRING', '') or ""
    filter = urllib.unquote(q).lower().split(',')
    include = set(filter)
    include_types = set(["Plenary", "Other"])
    exclude = []

    # Process the special flags.
    #   "-wgname" will remove a working group from the output.
    #   "~Type" will add that type to the output.
    #   "-~Type" will remove that type from the output
    # Current types are:
    #   Session, Other (default on), Break, Plenary (default on)
    # Non-Working Group "wg names" include:
    #   edu, ietf, tools, iesg, iab

    for item in include:
        if item:
            if item[0] == '-' and item[1] == '~':
                include_types -= set([item[2:3].upper() + item[3:]])
            elif item[0] == '-':
                exclude.append(item[1:])
            elif item[0] == '~':
                include_types |= set([item[1:2].upper() + item[2:]])

    schedule = get_schedule(meeting, schedule_name)
    scheduledsessions = get_scheduledsessions_from_schedule(schedule)

    scheduledsessions = scheduledsessions.filter(
        Q(timeslot__type__name__in=include_types)
        | Q(session__group__acronym__in=filter)
        | Q(session__group__parent__acronym__in=filter)).exclude(
            Q(session__group__acronym__in=exclude))
    #.exclude(Q(session__group__isnull = False),
    #Q(session__group__acronym__in = exclude) |
    #Q(session__group__parent__acronym__in = exclude))

    if meeting.time_zone:
        try:
            tzfn = os.path.join(settings.TZDATA_ICS_PATH,
                                meeting.time_zone + ".ics")
            tzf = open(tzfn)
            icstext = tzf.read()
            debug.show('icstext[:128]')
            vtimezone = re.search(
                "(?sm)(\nBEGIN:VTIMEZONE.*\nEND:VTIMEZONE\n)",
                icstext).group(1).strip()
            debug.show('vtimezone[:128]')
            tzf.close()
        except IOError:
            vtimezone = None
    else:
        vtimezone = None

    return HttpResponse(render_to_string(
        "meeting/agendaREDESIGN.ics", {
            "scheduledsessions": scheduledsessions,
            "meeting": meeting,
            "vtimezone": vtimezone
        }, RequestContext(request)),
                        mimetype="text/calendar")
Beispiel #13
0
 def get (_s):
     #TODO: COMMENT OUT the test flash :-
     ema = _s.ssn['ema'] 
     debug.show(_s, 'forgot', ema)
     #
     _s.serve ('message.html', txt='An email has been sent to you.' )
Beispiel #14
0
def do(args, payload):
    request_object = None
    # try loading --request file
    if args.request is not None:
        try:
            fp = open(args.request, "rb")
            request_object = Request.from_buffer(args.url, args.crlf,
                                                 args.mode, fp.read())
            fp.close()
        except Exception as e:
            debug.error(e)
    # parse request from arguments
    else:
        request_object = Request(
            args.url, args.crlf, args.mode,
            args.connect_timeout if args.connect_timeout is not None else 10)
    if args.mode == MODES_CLTE and args.two != "-1":
        isIn = False
        for k in args.header2:
            if "Content-Length:".lower() in k.lower():
                isIn = True
                break
        if not isIn:
            args.header2.append("Content-Length: 100")
            print("=" * 50)
    for i in range(1, MAX_REQUESTS + 1):
        args_val = getattr(args, enum_field[i - 1])
        if args_val != "-1":
            request_object.append_request(args_val,
                                          getattr(args, f"header{i}"),
                                          getattr(args, f"method{i}"), i)
    if args.random_agent:
        request_object.agent = random.choice(AGENTS)
    request_object.end()
    if args.align is not None and args.mode == MODES_TECL:
        request_object.align(args.align)
    debug.show_verbose("Base request:", 1)
    result = request_object.start(payload)
    if args.align is not None and args.mode == MODES_CLTE:
        url = args.url + args.align
        if args.align[0] == "/" and args.url[0] == "/":
            url = args.url + args.align[1:]
        r = requests.get(url)
        result.append((len(r.text), r.text))
    debug.show_verbose(request_object.show(), 1)
    if (len(result) > 1):
        meet = False
        for res in result:
            if args.filter is not None and args.filter in res[1]:
                meet = True
                debug.show(res[1])
            else:
                debug.show_verbose(res[1], 3)
                debug.show_verbose("=" * 50, 3)
            if not meet and args.filter is None:
                meet = True
        debug.show(f"{len(result)} requests returned.")
        debug.show(f"Payload: {payload} looks exploitable.\n")
        if args.mode == MODES_CLTE:
            debug.show(
                "If you don't see the second response, should try this payload with different Content-Length."
            )
        if meet and args.stop:
            exit(0)
    else:
        debug.show_verbose(result[0][1], 3)
        debug.show(f"Probably {payload} is not exploitable.")
Beispiel #15
0
 for cnt in contours:
     if (cv2.contourArea(cnt) > int(config)):
         x, y, w, h = cv2.boundingRect(cnt)
         if (x - 10 > 0 and y - 10 > 0 and h + 10 < r.shape[:2][0]
                 and w + 10 < r.shape[:2][1]):
             y -= 10
             x -= 10
             h += 10
             w += 10
         roi = imgs[y:y + h, x:x + w]
         color = cases[classificacao.predictSingleImage(roi)]
         cv2.imshow("Corte", roi.copy())
         cv2.imshow("Menor Circulo", debug.showMinCircle(roi.copy())[0])
         cv2.imshow("Menor Elipse", debug.showMinCircle(roi.copy())[1])
         cv2.imshow("Menor Retangulo", debug.showMinRec(roi.copy()))
         cv2.imshow("Defeitos", debug.show(roi.copy()))
         cv2.drawContours(r, [cnt], -1, color, 2, cv2.LINE_AA)
         cv2.imshow("Resultado", r)
         ch = cv2.waitKey(5)
         if ch == 27:
             cont = 0
             break
         if ch == 13:
             cv2.waitKey(0)
         if ch == 32:
             break
 ch = cv2.waitKey(1000)
 if ch == 27:
     cont = 0
     break
 if ch == 13: