# coding: utf8

import urllib2
import urlparse
import os
import sys

class UrlAudit():
    def __init__(self):
        payload = []
        filename = os.path.join(sys.path[0], "Data", "xss_payload.txt")
        f = open(filename)
        for i in f:
            payload.append(i.strip())

        self.paichu = ['.css', '.js?', '.gif', '.jpg', '.png', '.swf']


    def param(self,arg):           # 判断是否含有参数
        r = urlparse.urlparse(arg)  # 分解url
        pairs = urlparse.parse_qsl(r.query)
        #print "pairs:", pairs
        #print type(pairs)
        #print r.query
        #print r.query.find('='),arg.find('?'),len(pairs),r.path

        if r.query.find('=') == -1 or len(pairs) > 10 or arg.find('?') == -1:
            return

        for case in self.paichu:
            if case in r.path:  # 网页文件在服务器中存放的位置
                return

        return True

    def split(self, arg):
        url = arg.split('?')
        query = url[1].split('&')
        # print 'query====',query
        rooturl = url[0]
        # print 'rooturl===',rooturl
        query_length = len(query)
        return rooturl, query, query_length
