示例#1
0
def api2():
    print("\n")
    print("################### API V2 Called ###################")
    flag = False
    if request.method == 'POST':
        key = request.form['key']
        url = request.form['url']
        flag=True
    elif request.method == 'GET':
        if 'key' in request.args and 'url' in request.args:
            key = str(request.args['key'])
            url = str(request.args['url'])
            flag=True
        else:
            dashboard['failed']+=1
            print(dashboard)
            return "Please Follow the format ------> ?key=key&url=url"
    if(flag):
        if key == apiKey:
            print("Key Validation Successful")
            PhishTankResult = PhishTankObj.check(url)
            if PhishTankResult.in_database:
                if PhishTankResult.valid:
                    print("\n")
                    print("{url} is a phish!".format(url=PhishTankResult.url))
                    print("\n")
                    ret = {'url':url, 'pish':"True"}
                else:
                    print("\n")
                    # print("{url} is not a phish!".format(url=PhishTankResult.url))
                    # print("\n")
                    # ret = {'url':url,'pish':"False"}
                    x = test.check(url,model)
                    ret = {'url':url, 'pish':str(x)}
            else:
                # print("{url} is not in the PhishTank database".format(url=PhishTankResult.url))
                x = test.check(url,model)
                ret = {'url':url, 'pish':str(x)}

            return jsonify(ret)
        else:
            print("Key Validation Failed")
            return "Key Validation failed"
    else:
        return "Please Follow the format ------> ?key=key&url=url"
示例#2
0
def main():
	local_ip="0.0.0.0"
	local_port=80
	local_socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
	local_socket.bind((local_ip,local_port))
	local_socket.listen(50)
	poll=[]
	while True:
		#sleep(2)
		print("waiting for cnnection!")
		con,addrs=local_socket.accept()
		poll.append((con,addrs))
		#client.setblocking(0)
		while len(poll):
			(client,addr)=poll.pop()
			buff=client.recv(BUFFSIZE)
		
			data=buff.decode()
			print("conecting from",addr)
			try:
				path=data.split(' ')[1]
			except:
				client.close()
				continue
			if path=='/hack.jpg':
				client.send(hacks)
				client.close()
			else :
				lines=len(data.split('\r\n'))
				i=0
				while(lines>i):
					#print(data.split('\r\n')[i])
					if len(data.split('\r\n')[i]):
						checked=check(model,w_model,data.split('\r\n')[i])
						if(checked==[0]):
							i+=1
						else :
							break
					else:
						i+=1
				if(checked!=0):
					client.send((text_content+convert2label(checked)).encode())
				else:
				
					proxy_thread=threading.Thread(target=proxy_handler,args=(client,"10.10.10.133",80,buff))
					proxy_thread.start()
					print("client close:",addr)
示例#3
0
def upload_file():
    if request.method == 'POST':
        option = request.form['option']
        f = request.files['picture']
        f.save('test_image/1.jpg')
        #        ou=jsonify(test.check())
        #        return option
        #        ou = test.check()
        if option == 'xml':
            ou = test2.check()
            ou = tp5.text_xml(ou)


#            os.system("python3 tp5.py")
        else:
            ou = test.check()
            os.system("python3 tp4.py")
        return ou + '<br/><br/>Ok! <a href="/uppage" onClick=”javascript :history.go(-1);”>back</a>'
    return 'Ok! <a href="/uppage" onClick=”javascript :history.go(-1);”>back</a>'
示例#4
0
def delete_files(list_of_files):
    """Delete a list of files with checking for folders"""
    TRASH = '/Users/Dima/.MyTrash'
    temp = open('python_lab_2/database/DB.txt', 'w')
    checked_list = test.check(list_of_files)
    n = checked_list.__len__()
    # file_name = 'File', index
    arr_files = [file_object.FileObject() for i in xrange(1, n + 2)]
    index = 0
    try:
        for each_file in checked_list:
            index += 1
            arr_files[index].add_name(each_file)
            arr_files[index].add_path(os.path.abspath(each_file))
            arr_files[index].add_time_of_life(os.path.getctime(each_file))
            shutil.move(each_file, TRASH)
            arr_files[index].set_type(True)

        for i in xrange(n + 1):
            json.dump(arr_files[i].__dict__, temp)

    except Exception as e:
        print 'Error:', e
示例#5
0
文件: appl.py 项目: Leehow/pictes
def upload_file():
    #用时间命名图片id
    t=time.time()
    t=int(t)
    t=str(t)
    img_path = 'static/'
    img_name = '1.jpg'
    img_save = 'pic_'+t+'.jpg'
    imge=img_path+img_name
    imge2=img_path+img_save
    json_name = 'json_'+t+'.json'
    json_save =img_path+json_name
    if request.method == 'POST':
        #option = request.form['option']
        f = request.files['picture']
        if f==None:
            return 'You should update picture <a href="/" onClick=”javascript :history.go(-1);”>back</a>'
        f.save(imge)
        ou = test.check(imge,imge2)
        tp4.imge(imge2)
        out = test2.check(imge)
        out = tp5.text_xml(out,imge)
        with open(json_save, 'w') as f:
            json.dump(out, f)
            f.close()
        with open(img_path+'list.json', 'r') as f1:
            data = json.load(f1)
            item = [{'id':t}]
            data.append(item)
            #print(data[0]['id'])
            f1.close()
        with open(img_path+'list.json', 'w') as f2:
            json.dump(data, f2)
        return 'ok <a href="/" onClick=”javascript :history.go(-1);”>back</a>'
    else:
        return 'You should update picture <a href="/" onClick=”javascript :history.go(-1);”>back</a>'
示例#6
0
weight0 = 2 * np.random.random((784, 50)) - 1
weight1 = 2 * np.random.random((50, 10)) - 1
"""Loading the MNIST data set into three lists two containg the training data
    and the third one containing the test data"""

tr_data, val_data, test_data = ml.load_data()
"""Fitting the 28*28 input image into a numpy array of 784*1 dimension"""

tr_inputs = [np.reshape(a, (784, 1)) for a in tr_data[0]]
"""Converting the single output into a numpy array of 10 dimensions with 1 at
    the index of the output an 0 elsewhere"""
tr_output = [ml.vectr_result(a) for a in tr_data[1]]
"""Loop to train the data taking an input of 10,000 images"""
for i in range(50000):

    weight0, weight1 = net.train(tr_inputs[i], tr_output[i], weight0, weight1)
    if (i % 500) == 0:
        br.progress(i, 50000)
br.progress(50000, 50000, cond=True)

print("\n")

print("Network Trained and ready to be operated")

te_inputs = [np.reshape(a, (784, 1)) for a in test_data[0]]
te_output = test_data[1]
"""Function to check the accuracy of our trained network by testing it on
    unchecked data of 10,000 images"""
tt.check(te_inputs, te_output, weight0, weight1)
示例#7
0
    rs.calibration_status.retry, rs.calibration_status.scene_invalid,
    rs.calibration_status.bad_result
]

#############################################################################################
# Test #1
test.start("Depth sensor is off, should get an error")
try:
    d2r.trigger_device_calibration(rs.calibration_type.manual_depth_to_rgb)
    ac.wait_for_calibration()
except Exception as e:
    test.check_exception(e, RuntimeError, "not streaming")
else:
    test.unexpected_exception(
    )  # No error Occurred, should have received a RuntimeError
test.check(ac.status_list_is_empty()
           )  # No status changes are expected, list should remain empty
test.finish()

#############################################################################################
# Test #2
test.start("Color sensor is off, calibration should succeed")
ac.reset_status_list()  # Deleting previous test
depth_sensor.open(dp)
depth_sensor.start(lambda f: None)
try:
    d2r.trigger_device_calibration(rs.calibration_type.manual_depth_to_rgb)
    ac.wait_for_calibration()
    ac.trim_irrelevant_statuses(irrelevant_statuses)
    test.check_equal_lists(ac.status_list, successful_calibration_status_list)
except Exception:
    test.unexpected_exception()
weights = 2 * np.random.random((784, 50)) - 1
weights1 = 2 * np.random.random((50, 10)) - 1
"""Loading the MNIST data set into three lists two containg the training data
    and the third one containing the test data"""

tr_data, val_data, test_data = ml.load_data()
"""Fitting the 28*28 input image into a numpy array of 784*1 dimension"""

tr_inputs = [np.reshape(x, (784, 1)) for x in tr_data[0]]
"""Converting the single output into a numpy array of 10 dimensions with 1 at
    the index of the output an 0 elsewhere"""
tr_outputs = [ml.vectorized_result(x) for x in tr_data[1]]
"""Loop to train the data taking an input of 10,000 images"""
for i in range(50000):

    weights, weights1 = net.train(tr_inputs[i], tr_outputs[i], weights,
                                  weights1)
    if (i % 500) == 0:
        br.progress(i, 50000)
br.progress(50000, 50000, cond=True)

print("\n")

print("Network Trained and ready to be operated")

te_inputs = [np.reshape(x, (784, 1)) for x in test_data[0]]
te_outputs = test_data[1]
"""Function to check the accuracy of our trained network by testing it on
    unchecked data of 10,000 images"""
tt.check(te_inputs, te_outputs, weights, weights1)
示例#9
0
__author__ = "Mr Bancroft"

import test

print('''All variables in Python must star with a letter (upper or          
lower case) or an underscore. you cannot use a number at the start
or special characters anywhere in the name'''
      )  # Print information about variables
print()  # Print blank line
print('''valid names include:
_hello, _Hello, hello_world, Hello_world, _123, _a1, a123
invalid names include:
!hello, 123, $help, **123, _!help, _%^test, _help%'''
      )  # Print information about variables
print()  # Print blank line
print('''Another thing to remember is case sensitivity,
so Hello is different from hello''')  # Print information about variables
print()  # Print blank line
print("Try it out, enter a variable name and see if it is valid:"
      )  # Print instructions
checkName = "blank"  # Set checkName string to arbitrary value so initial while check passes
while checkName:  # While checkName uses a boolean check because an empty string is false and a populated one true in Python
    checkName = input("press enter on its own when you are finished: "
                      )  # Input the variable name into checkName string
    if checkName:  # Check variable contains something to prevent odd error message when pressing enter alone to exit while loop
        test.check(
            checkName
        )  # Pass the variable name string to the check() method in the test.py file
示例#10
0
from test import init,check,convert2label
import time
model,w_model=init()
count=0
sql=0
xss=0
normal=0
start=time.time()
for line in open('data/test_normal.txt','r'):
    if len(line):
        count+=1
        checked=check(model,w_model,line)
        print(checked)
        if checked==0:
            normal+=1
        elif checked==1:
            sql+=1
        else :
            xss+=1
end=time.time()
print("normal %f"%(normal/count)," xss:",xss," sql:",sql)
print("sql %f"%(sql/count)," normal:",normal," xss:",xss)
print("xss %f"%(xss/count)," sql:",sql," normal:",normal)
print("cost time is "+str(end-start)+"s")
示例#11
0
    def Game(self):
        turn = 0
        turnCounter = 15
        turnCondition = True
        key = True
        while turnCondition:
            stddraw.show(0)
            Graphics.drawTurnCounter(turnCounter)
            Graphics.drawWinThing()
            if turn == 0:
                if stddraw.mousePressed():
                    mx = stddraw.mouseX()
                    my = stddraw.mouseY()

                    if mx < 4.69 and my >= 1 and my < 10:
                        Graphics.clickHelp()
                        for i in range(self.x):
                            if mx > i / 1.5 and mx < i / 1.5 + (2 / 3):
                                mDrawX1 = i / 1.5
                                mEmojiX1 = i + 1

                        for i in range(self.y + 1):
                            if my > i and my < i + 1:
                                mDrawY1 = i
                                mEmojiY1 = i + 1 / 2

                        for i in range(self.y):
                            for j in range(self.x):
                                if self.board[i][
                                        j].x == mEmojiX1 and self.board[i][
                                            j].y == mEmojiY1:
                                    e1emoji = self.board[i][j].emoji
                                    e1i, e1j = i, j

                        Graphics.tileSelected(mDrawX1, mDrawY1)
                        turn = 1

            if turn == 1:
                if stddraw.mousePressed():
                    mx = stddraw.mouseX()
                    my = stddraw.mouseY()

                    if mx < 4.69 and my >= 1 and my < 10:

                        for i in range(self.x):
                            if mx > i / 1.5 and mx < i / 1.5 + (2 / 3):
                                mEmojiX2 = i + 1

                        for i in range(self.y + 1):
                            if my > i and my < i + 1:
                                mEmojiY2 = i + 1 / 2

                        for i in range(self.y):
                            for j in range(self.x):
                                if self.board[i][
                                        j].x == mEmojiX2 and self.board[i][
                                            j].y == mEmojiY2:
                                    e2emoji = self.board[i][j].emoji
                                    e2i, e2j = i, j

                        #Swapping the emojis
                        """
                        NOTE THAT THE X POSITIONS ETC HAVE STILL NOT BEEN FIXED
                        11/18/2018 12:14 AM
                        Conversion system new: when x == 1, emoji true position is 1/3, x == 2, 1,
                        x == 3, 5/3
                        """

                        if mEmojiX2 == mEmojiX1 + 1 and mEmojiY2 == mEmojiY1 or mEmojiX2 == mEmojiX1 - 1 and mEmojiY2 == mEmojiY1 or mEmojiY2 == mEmojiY1 + 1 and mEmojiX2 == mEmojiX1 or mEmojiY2 == mEmojiY1 - 1 and mEmojiX2 == mEmojiX1:

                            Graphics.clickHelpClear()
                            self.board[e1i][e1j].emoji = e2emoji
                            self.board[e2i][e2j].emoji = e1emoji

                            counter = 0

                            while test.check(self.board) != 0:
                                self.checkDraw(mDrawX1, mDrawY1)

                                #Erase Vertical
                                if test.getD() == 0:
                                    counter = 0
                                    marker = self.board[test.getY()][
                                        test.getX()].emoji
                                    while marker != 0:
                                        if test.getY() + counter != 9:

                                            if marker == self.board[test.getY(
                                            ) + counter][test.getX()].emoji:
                                                self.board[test.getY() +
                                                           counter][test.getX(
                                                           )].emoji = 0
                                                Score.score += 1
                                                counter += 1
                                            else:
                                                marker = 0
                                        else:
                                            marker = 0

                                    self.checkDraw(mDrawX1, mDrawY1)

                                    #Vertical Drop
                                    count = 0

                                    for j in range(9):
                                        if test.getY() + count + counter < 9:
                                            self.board[
                                                test.getY() + count][test.getX(
                                                )].emoji = self.board[
                                                    test.getY() + count +
                                                    counter][test.getX()].emoji
                                            self.board[
                                                test.getY() + count +
                                                counter][test.getX()].emoji = 0

                                            count += 1

                                    self.checkDraw(mDrawX1, mDrawY1)

                                    temp = 9 - counter

                                    for i in range(counter):
                                        self.board[temp][
                                            test.getX()].emoji = self.ranNum()
                                        temp += 1

                                    self.checkDraw(mDrawX1, mDrawY1)

                                #Erase Horizontal
                                else:
                                    counter = 0
                                    marker = self.board[test.getY()][
                                        test.getX()].emoji
                                    while marker != 0:
                                        if test.getX() + counter != 7:

                                            if marker == self.board[test.getY(
                                            )][test.getX() + counter].emoji:
                                                self.board[test.getY()][
                                                    test.getX() +
                                                    counter].emoji = 0
                                                Score.score += 1
                                                counter += 1
                                            else:
                                                marker = 0
                                        else:
                                            marker = 0

                                    self.checkDraw(mDrawX1, mDrawY1)

                                    #Horizontal Drop
                                    count = 0
                                    for i in range(counter):
                                        count = 0
                                        for j in range(9):
                                            if test.getY() + count < 8:
                                                temp = count + 1
                                                self.board[
                                                    test.getY() + count][
                                                        test.getX() +
                                                        i].emoji = self.board[
                                                            test.getY() +
                                                            temp][test.getX() +
                                                                  i].emoji
                                                self.board[test.getY() +
                                                           temp][test.getX() +
                                                                 i].emoji = 0

                                            count += 1
                                    self.checkDraw(mDrawX1, mDrawY1)

                                    for i in range(counter):
                                        self.board[8][test.getX() +
                                                      i].emoji = self.ranNum()
                                    self.checkDraw(mDrawX1, mDrawY1)

                                turn = 0

                            #For when it is not a match 3
                            if counter == 0:
                                self.board[e1i][e1j].emoji = e1emoji
                                self.board[e2i][e2j].emoji = e2emoji
                                Graphics.clickHelpClear()
                                Graphics.drawInvalidMatch3()
                                Graphics.clearInvalidSwitch()
                                Graphics.tileSelectedClear(mDrawX1, mDrawY1)
                                turn = 0
                            else:
                                turnCounter -= 1

                        #For when you want to select the tile again
                        elif mEmojiX1 == mEmojiX2 and mEmojiY1 == mEmojiY2:
                            Graphics.clickHelpClear()
                            Graphics.tileSelectedClear(mDrawX1, mDrawY1)
                            turn = 0

                        #For when there is an invaid switch
                        else:
                            Graphics.clickHelpClear()
                            Graphics.tileSelectedClear(mDrawX1, mDrawY1)
                            Graphics.drawInvalidSwitch()
                            Graphics.clearInvalidSwitch()
                            turn = 0

                    else:
                        turn = 1

                #Note, mouse does not need to be pressed in order for this CheckWin
                if turnCounter == 0 and Score.score >= 75:
                    Graphics.drawTurnCounter(turnCounter)
                    turnCondition = False
                    while key:
                        Graphics.drawWinCondition()
                        if stddraw.mousePressed():
                            key = False
                elif turnCounter == 0 and Score.score <= 75:
                    Graphics.drawTurnCounter(turnCounter)
                    turnCondition = False
                    while key:
                        Graphics.drawLossCondition()
                        if stddraw.mousePressed():
                            key = False
示例#12
0
import pyrealsense2 as rs, test, ac

devices = test.find_devices_by_product_line_or_exit(rs.product_line.L500)
depth_sensor = devices[0].first_depth_sensor()

debug_sensor = rs.debug_stream_sensor(depth_sensor)
debug_profiles = debug_sensor.get_debug_stream_profiles()

#############################################################################################
test.start("FG isn't exposed by get_stream_profiles")

matches = list(p for p in depth_sensor.profiles if p.format() == rs.format.fg)
test.check(len(matches) == 0)
test.finish()

#############################################################################################
test.start("FG exposed by debug_stream_sensor")

matches = list(p for p in debug_profiles if p.format() == rs.format.fg)
test.check(len(matches) > 0)
test.finish()

#############################################################################################
test.start("streaming FG 800x600")

dp = next(
    p for p in debug_profiles
    if p.fps() == 30 and p.stream_type() == rs.stream.depth and p.format() ==
    rs.format.fg and p.as_video_stream_profile().width() == 800
    and p.as_video_stream_profile().height() == 600)
depth_sensor.open(dp)
示例#13
0
文件: main.py 项目: ryo-1/rks_ml01
# -*- coding: utf-8 -*-
import train
import test

if __name__ == '__main__':
    W = train.normal_equation()
    print(test.check(W))