示例#1
0
文件: test.py 项目: djiesamsoe/url-py
    def test_strict_escape(self):
        '''Test strict mode escaping'''
        examples = [
            ('danny%27s pub'                , 'danny%27s%20pub'                  ),
            ('http://*****:*****@foo.com'     , 'http://*****:*****@foo.com'         ),
            (u'http://José:no [email protected]'  , 'http://Jos%C3%A9:no%[email protected]'),
            ('http://oops!:don%[email protected]' , 'http://oops!:don%[email protected]'     ),
            (u'española,nm%2cusa.html?gunk=junk+glunk&foo=bar baz',
                'espa%C3%B1ola,nm%2Cusa.html?gunk=junk+glunk&foo=bar%20baz')
        ]

        base = 'http://testing.com/'
        for bad, good in examples:
            bad = base + bad
            good = base + good
            self.assertEqual(url.parse(bad).escape(strict=True).utf8(), good)
            # Escaping should also be idempotent
            self.assertEqual(
                url.parse(bad).escape(strict=True).escape(strict=True).utf8(), good)

        # Examples with userinfo
        examples = [
            ('http://user%[email protected]/', 'http://user%[email protected]/')
        ]
        for bad, good in examples:
            self.assertEqual(url.parse(bad).escape(strict=True).utf8(), good)
            # Escaping should also be idempotent
            self.assertEqual(
                url.parse(bad).escape(strict=True).escape(strict=True).utf8(), good)

        # Test Unicode escaping in strict mode
        u = url.URL(u'http', u'foo.com', None, u'española,nm%2cusa.html', u'', u'gunk=junk+glunk&foo=bar baz', u'')
        u.escape(strict=True)
        self.assertTrue(isinstance(u._path, str))
        self.assertEqual(u._path, 'espa%C3%B1ola,nm%2Cusa.html')
示例#2
0
    def run_test(self):
        # init
        self.mutex = threading.Lock()

        self.listbox.delete(0, END)
        self.url = url.URL(self.confger.url_file)
        count = self.url.get_count()
        txt = "total:%d" %count
        self.url_total_label.config(text = txt)

        self.running = True
        self.pausing = False
        self.index = 0
        txt = "now:%d" %0
        self.url_left_label.config(text = txt)

        browser.close_browser()
        
        self.run_button.config(state = "disabled")
        self.pause_button.config(state = "normal")
        self.pause_button.config(text = "pause")

        self.period_call()
        #self.root.iconify()
        # start work thread
        handle = threading.Thread(target = Main.run_thread, args=(self,))
        handle.setDaemon(True)
        handle.start()
示例#3
0
文件: test.py 项目: brugeman/url-py
def test_strict_unicode_escape():
    '''Test Unicode escaping in strict mode'''
    u = url.URL(u'http', u'foo.com', None, u'española,nm%2cusa.html', u'',
                u'gunk=junk+glunk&foo=bar baz', u'')
    u.escape(strict=True)
    assert isinstance(u._path, str)
    assert_equal(u._path, 'espa%C3%B1ola,nm%2Cusa.html')
示例#4
0
 def create(self):
     import url
     f_url = url.URL()
     f_url.add_method('filters').add_method('create').add_parameter(
         'base', self._filter_id)
     f_url.set_post_data({
         'include': ';'.join(self._includes),
         'exclude': ';'.join(self._excludes),
     })
     self._filter_id = f_url.fetch(True)['items'][0]['filter']
     self._dirty = False
     return self
示例#5
0
    def __init__(self):
        # 当前目录加入环境变量中
        path.add_path()

        # 界面控制变量
        self.root = None
        self.text_frame = None
        self.list_frame = None
        self.next_botton = None
        self.scrollbar = None
        self.score_entry = None
        self.listbox = None
        self.label = None
        self.save_button = None
        self.prefix = "   "

        # 配置
        self.configer = config.Config()

        # url获取
        self.url = url.URL(self.configer.url_dir, self.configer.url_dir_cn,
                           self.configer.class_num, self.configer.url_num,
                           self.configer.url_num_cn)

        # 当前测试url序列号
        self.index = 0
        # 当前剩余url数
        self.all_url_num = 0
        # 当前测试url
        self.cur_url = None

        # 保存测试结果
        self.saver = save.Save(self.configer.result_file)
        self.db_saver = db.DBSaver(self.configer.host, self.configer.port,
                                   self.configer.user, self.configer.passwd,
                                   self.configer.db)

        # 线程通信队列
        self.queue = Queue.Queue()

        # 运行停止标识
        self.running = False
        self.stop_flag = False

        # 文件主窗口
        self.question_win = None
        # 用户标识
        self.user_id = 0
示例#6
0
 def __init__(self):
     self.root = None
     self.text_frame = None
     self.list_frame = None
     self.next_botton = None
     self.scrollbar = None
     self.score_entry = None
     self.listbox = None
     self.label = None
     self.logger = log.get_logger()
     self.confger = config.Config()
     self.url = url.URL(self.confger.url_file)
     self.index = 0
     self.saver = save.Save(self.confger.result_file)
     self.cur_url = None
     self.save_button = None
     self.queue = Queue.Queue()
     self.running = False
     self.prefix = "..."
示例#7
0
#v.0.3.2

import json, url

headers = {}
headers['Content-Type'] = 'application/json'
headers['Accept'] = 'application/json'
JSONURL = url.URL('json', headers=headers)
TXTURL = url.URL()


class API(object):
    def __init__(self, user='', apikey=''):
        self.PUBLICURL = 'https://api.tvmaze.com'
        self.USER = user
        self.APIKEY = apikey
        if user and apikey:
            self.AUTHURL = 'https://api.tvmaze.com/v1/user'
        else:
            self.AUTHURL = self.PUBLICURL

    def getShow(self, tvmazeid, params=None):
        return self._call('shows/%s' % tvmazeid, params)

    def getEpisode(self, episodeid, params=None):
        return self._call('episodes/%s' % episodeid, params)

    def getEpisodeBySeasonEpNumber(self, tvmazeid, params):
        return self._call('shows/%s/episodebynumber' % tvmazeid, params)

    def getFollowedShows(self, params=None):
示例#8
0
# Atome Login
atomeLogin = config['atome_login']

# Atome password
atomePassword = config['atome_password']

# Domoticz API
if domoticzLogin:
    b64domoticzlogin = base64.b64encode(domoticzLogin.encode())
    b64domoticzpassword = base64.b64encode(domoticzPassword.encode())
    domoticzServer = domoticzServer + '/json.htm?username='******'&password='******'/json.htm'

domoticzApi = url.URL(domoticzServer)


def get_counter_value():
    # Get value from Domoticz
    counter = domoticzApi.call({'type': 'devices', 'rid': domoticzIdx}).json()

    # T1: creuse, T2: pleine
    counterValues = counter['result'][0]['Data'].split(";")

    return {
        'creuse': int(counterValues[0]),
        'pleine': int(counterValues[1]),
    }