def application_factory(global_conf, **local_conf): 'Paste Script compatible application faactory.' url_map = resolve(local_conf['urls']) handler = resolve(local_conf['handler']) app_secret = load_secret(os.path.join(global_conf['here'], local_conf['secret-file'])) return Application(url_map, handler, app_secret)
def _parse_line(self, line, path, methods): """Parse one line of a mapping file. This method is for the use of selector.slurp_file. """ # Comment or line: if not line.strip() or line.strip()[0] == '#': pass # Directive: elif line.strip()[0] == '@': parts = line.strip()[1:].split(' ', 1) if len(parts) == 2: directive, rest = parts else: directive = parts[0] rest = '' if directive == 'prefix': self.prefix = rest.strip() if directive == 'parser': self.parser = resolver.resolve(rest.strip()) if directive == 'wrap': self.wrap = resolver.resolve(rest.strip()) # HTTP Method -> Handler: elif line[0] in ' \t': if path is None: raise MappingFileError("Specify a path expression first.") meth, app = line.strip().split(' ', 1) methods[meth.strip()] = resolver.resolve(app) # Path Expression: else: if path and methods: self.add(path, methods) path = line.strip() methods = {} return path, methods
def test_resolve_missingexternal(self): options1 = {'name1_options1':'hello ${./name2_options1}', 'name2_options1':'${./name3_options1} goodbye', 'name3_options1':'${default_options1}', 'name4_options1':'this is name4', 'another_options1':'another'} options2 = {'name1_options2':'hello ${./name2_options2}', 'name2_options2':'${./name3_options2} goodbye', 'name3_options2':'${default_options2}', 'name4_options2':'this is name4', 'another_options2':'another', 'external1':'${options1/missing1}', 'external2':'${options1/missing2}'} defaults = {'default_options1':'default_for_options1', 'default_options2':'default_for_options2'} sections = {'options1':options1, 'options2':options2} from resolver import resolve from resolver import resolve_options from resolver import MissingDependencyError from resolver import LOCAL from resolver import DEFAULT try: resolve(sections, defaults) except MissingDependencyError, why: self.assertEqual(why.section_name, 'options2') self.assertEqual(why.option_name, 'external1') self.assertEqual(why.value, '${options1/missing1}') self.assertEqual(why.offender, 'missing1')
def test_resolve_missingexternal(self): options1 = { "name1_options1": "hello ${./name2_options1}", "name2_options1": "${./name3_options1} goodbye", "name3_options1": "${default_options1}", "name4_options1": "this is name4", "another_options1": "another", } options2 = { "name1_options2": "hello ${./name2_options2}", "name2_options2": "${./name3_options2} goodbye", "name3_options2": "${default_options2}", "name4_options2": "this is name4", "another_options2": "another", "external1": "${options1/missing1}", "external2": "${options1/missing2}", } defaults = {"default_options1": "default_for_options1", "default_options2": "default_for_options2"} sections = {"options1": options1, "options2": options2} from resolver import resolve from resolver import resolve_options from resolver import MissingDependencyError from resolver import LOCAL from resolver import DEFAULT try: resolve(sections, defaults) except MissingDependencyError, why: self.assertEqual(why.section_name, "options2") self.assertEqual(why.option_name, "external1") self.assertEqual(why.value, "${options1/missing1}") self.assertEqual(why.offender, "missing1")
def _parse_line(self, line, path, methods): """Parse one line of a mapping file. This method is for the use of selector.slurp_file. """ if not line.strip() or line.strip()[0] == '#': pass elif not line.strip() or line.strip()[0] == '@': # if path and methods: self.add(path, methods) path = line.strip() methods = {} # parts = line.strip()[1:].split(' ', 1) if len(parts) == 2: directive, rest = parts else: directive = parts[0] rest = '' if directive == 'prefix': self.prefix = rest.strip() if directive == 'parser': self.parser = resolve(rest.strip()) if directive == 'wrap': self.wrap = resolve(rest.strip()) elif line and line[0] not in ' \t': if path and methods: self.add(path, methods) path = line.strip() methods = {} else: meth, app = line.strip().split(' ', 1) methods[meth.strip()] = resolve(app) return path, methods
def test_mx_record(self): with self.subTest(msg="MX record for TLD: .com"): self.assertTrue(resolve("google.com", True) in [ "aspmx.l.google.com", "alt2.aspmx.l.google.com", "alt3.aspmx.l.google.com", "alt4.aspmx.l.google.com", "alt1.aspmx.l.google.com" ]) with self.subTest(msg="MX record for TLD: .edu"): self.assertEqual(resolve("drexel.edu", True), "drexel-edu.mail.protection.outlook.com") with self.subTest(msg="MX record for TLD: .org"): self.assertEqual(resolve("archive.org", True), "mail.archive.org")
def test_cname_record(self): """ Tests for valid A records that end up being CNAME entries. """ with self.subTest(msg="CNAME to same TLD: .com -> .com"): self.assertEqual(resolve("www.campuswire.com"), "35.241.17.106") with self.subTest(msg="CNAME to same TLD: .org -> .org"): self.assertEqual(resolve("en.wikipedia.org"), "198.35.26.96") with self.subTest(msg="CNAME to different TLD: .edu -> .com"): self.assertEqual(resolve("catalogs.sandiego.edu"), "12.2.169.179")
def test_resolve_directloop(self): options1 = {"name1": "hello ${options2/name1}"} options2 = {"name1": "hello ${options1/name1}"} sections = {"options1": options1, "options2": options2} from resolver import resolve from resolver import CyclicDependencyError try: resolve(sections) except CyclicDependencyError, why: self.assertEqual(why[0], {(None, "options1"): ["options2"], (None, "options2"): ["options1"]})
def test_resolve_directloop(self): options1 = {'name1': 'hello ${options2/name1}'} options2 = {'name1': 'hello ${options1/name1}'} sections = {'options1': options1, 'options2': options2} from resolver import resolve from resolver import CyclicDependencyError try: resolve(sections) except CyclicDependencyError, why: self.assertEqual(why[0], { (None, 'options1'): ['options2'], (None, 'options2'): ['options1'] })
def resolve(): records = triplestore.to_records() t0 = time.time() graph, _ = resolver.resolve(records) t1 = time.time() print(f"Resolve took {t1-t0:.2f} seconds, had {len(graph)} triples") return jsonify({'size': len(graph)})
def test_resolve_directloop(self): options1 = {'name1':'hello ${options2/name1}'} options2 = {'name1':'hello ${options1/name1}'} sections = {'options1':options1, 'options2':options2} from resolver import resolve from resolver import CyclicDependencyError try: resolve(sections) except CyclicDependencyError, why: self.assertEqual( why[0], {(None, 'options1'): ['options2'], (None, 'options2'): ['options1']} )
def resolve(self): if self._resolved is None: selections = select(self.namespace_selections) for ns_name, D in selections.items(): overrides = self.namespace_overrides.get(ns_name, {}) D.update(overrides) self._resolved = resolver.resolve(selections, self.globals) return self._resolved
def resolve_file_section(filename, section_name, defaults=None): if defaults is None: defaults = {} namespace = select_one(filename, section_name) namespaces = {'whatever':namespace} sections = resolver.resolve(namespaces, defaults) return sections['whatever']
def test_resolve_with_ordering(): rule_path = get_rule_file('test_resolve_with_ordering.json') ruleset = rules.parse_file(rule_path.as_posix()) assert len(ruleset.rules) == 5 context = resolver.make_context() result = resolver.resolve(ruleset, context) assert len(result.goals) == 5 assert all(goal.points == 1 for goal in result.goals)
def process(data, resolver): line = data.strip() if line == 'HELO\t1' or line == 'HELO\t2' or line == 'HELO\t3': logger.info('Got %s. Responding OK.' % line) sys.stdout.write('OK\t\n') sys.stdout.flush() return chunks = line.split('\t') qname = chunks[1] qclass = chunks[2] qtype = chunks[3] qid = chunks[4] remote_ip = chunks[5] local_ip = None edns_subnet = None if len(chunks) >= 7: #at least atlas pipe protocol version 2 local_ip = chunks[6] if len(chunks) == 8: edns_subnet = chunks[7] """ Generate response and respond """ hostname = qname.lower() if hostname[-1] == '.': hostname = hostname[:-1] if hostname.endswith(HOSTNAME_BASE): if qtype == 'ANY' or qtype == 'A' or qtype == 'AAAA': dest = resolver.resolve(hostname) if not is_ip(dest): qtype = 'CNAME' else: qtype = 'A' response = DATA_TEMPLATE % (qname, qclass, qtype, TTL, qid, dest) sys.stdout.write(response) if qtype == 'ANY' or qtype == 'SOA': response = DATA_TEMPLATE % ( qname, qclass, 'SOA', TTL, qid, 'ns1.m.ripeatlasdns.net\troot.ripeatlasdns.net\t2008080300\t1800\t3600\t604800\t3600' ) sys.stdout.write(response) else: logger.error('FAIL for %s' % line) sys.stdout.write('FAIL\n') sys.stdout.flush() return sys.stdout.write('END\n') sys.stdout.flush()
def test_resolve_basic(): rule_path = get_rule_file('test_resolve_basic.json') ruleset = rules.parse_file(rule_path.as_posix()) assert len(ruleset.rules) == 1 context = resolver.make_context() result = resolver.resolve(ruleset, context) assert any(goal.name == 'resolve-basic-goal' and goal.points == 1 for goal in result.goals) assert len(result.goals) == 1
def test_resolve_two_to_same(): rule_path = get_rule_file('test_resolve_two_to_same.json') ruleset = rules.parse_file(rule_path.as_posix()) assert len(ruleset.rules) == 2 context = resolver.make_context() result = resolver.resolve(ruleset, context) assert len(result.goals) == 1 goal = result.goals[0] assert goal.name == 'resolve-two-of-same' and goal.points == 2 and \ len(goal.resolved_rules) == 2 and len(goal.non_resolved_rules) == 0
def handle_student(student): kattis = aaps.KattisResult() if is_student: kattis.resolve_sessions_with_input() add_sub = lambda sub: kattis.add_submission(sub) util.map_now(add_sub, student.submissions) context = resolver.make_context() plugins = kattis.get_plugins() add_plugin = lambda c, r: resolver.context_add_plugin(context, c, r) util.starmap_now(add_plugin, plugins) result = resolver.resolve(ruleset, context) return make_student_result(student, ruleset, kattis, context, result)
def zodb_init(root, conf, store_id=STORE_ID, btree='BTrees.IOBTree:IOBTree'): """ initializes the zodb for a single rtree reverse index this function should only ever be run once by zodbmiddleware """ store = root.setdefault(store_id, PersistentMapping()) btree_spec = conf.get('psid_btree', btree) btree = resolver.resolve(btree_spec) key = conf['psid_rindex_key'] assert store.get(key) is None, "Your psid_rindex_key is not unique" store[key] = btree()
def test_resolve_with_overrides(self): options1 = { 'name1_options1': 'hello ${./name2_options1}', 'name2_options1': '${./name3_options1} goodbye', 'name3_options1': '${default_options1}', 'name4_options1': 'this is name4', 'another_options1': 'another' } options2 = { 'name1_options2': 'hello ${./name2_options2}', 'name2_options2': '${./name3_options2} goodbye', 'name3_options2': '${default_options2}', 'name4_options2': 'this is name4', 'another_options2': 'another', 'external1': '${options1/name3_options1}', 'external2': '${options1/name2_options1}' } defaults = { 'default_options1': 'default_for_options1', 'default_options2': 'default_for_options2' } sections = {'options1': options1, 'options2': options2} from resolver import resolve overrides = { 'options1': { 'name1_options1': 'hello ${./name4_options1}' } } resolved = resolve(sections, defaults, overrides) self.assertEqual( resolved['options1'], { 'name1_options1': 'hello this is name4', 'name2_options1': 'default_for_options1 goodbye', 'name3_options1': 'default_for_options1', 'name4_options1': 'this is name4', 'another_options1': 'another' }, ) self.assertEqual( resolved['options2'], { 'name1_options2': 'hello default_for_options2 goodbye', 'name2_options2': 'default_for_options2 goodbye', 'name3_options2': 'default_for_options2', 'name4_options2': 'this is name4', 'another_options2': 'another', 'external1': 'default_for_options1', 'external2': 'default_for_options1 goodbye' })
def run(): args = docopt.docopt(__doc__, help=True, version=__version__) config_file = args['--config'] or '.redbike.conf' parser = SafeConfigParser() parser.read([config_file]) conf = dict(parser.items('redbike')) try: redis_conf = dict(parser.items('redbike-redis')) except: redis_conf = {} command = [k for k, v in args.items() if v and k[0].isalpha()][0] stop_event = threading.Event() bike = Redbike(resolver.resolve(args['<WORKER>'] or conf['worker']), prefix=conf.get('prefix'), redis_config=redis_conf, log=log, timefile=conf.get('timefile'), stop_event=stop_event, default_timeout=conf.get('default-timeout', 10)) func = globals()['do_' + command] pipe_r, pipe_w = os.pipe() flags = fcntl.fcntl(pipe_w, fcntl.F_GETFL, 0) flags |= os.O_NONBLOCK flags = fcntl.fcntl(pipe_w, fcntl.F_SETFL, flags) signal.set_wakeup_fd(pipe_w) signal.signal(signal.SIGTERM, sig_handler) signal.signal(signal.SIGINT, sig_handler) signal.signal(signal.SIGHUP, sig_handler) signal.signal(signal.SIGQUIT, sig_handler) signal.signal(signal.SIGTSTP, sig_handler) def wrapper(bike, args): global _shutdown try: func(bike, args) finally: _shutdown = True os.write(pipe_w, '0') thd = threading.Thread(target=wrapper, args=(bike, args)) thd.start() while not _shutdown: while True: try: os.read(pipe_r, 1) break except OSError, e: if e.errno != errno.EINTR: stop_event.set() raise
def test_resolve_missingexternal(self): options1 = { 'name1_options1': 'hello ${./name2_options1}', 'name2_options1': '${./name3_options1} goodbye', 'name3_options1': '${default_options1}', 'name4_options1': 'this is name4', 'another_options1': 'another' } options2 = { 'name1_options2': 'hello ${./name2_options2}', 'name2_options2': '${./name3_options2} goodbye', 'name3_options2': '${default_options2}', 'name4_options2': 'this is name4', 'another_options2': 'another', 'external1': '${options1/missing1}', 'external2': '${options1/missing2}' } defaults = { 'default_options1': 'default_for_options1', 'default_options2': 'default_for_options2' } sections = {'options1': options1, 'options2': options2} from resolver import resolve from resolver import resolve_options from resolver import MissingDependencyError from resolver import LOCAL from resolver import DEFAULT try: resolve(sections, defaults) except MissingDependencyError, why: self.assertEqual(why.section_name, 'options2') self.assertEqual(why.option_name, 'external1') self.assertEqual(why.value, '${options1/missing1}') self.assertEqual(why.offender, 'missing1')
def _parse_line(self, line, path, methods): """Parse one line of a mapping file. This method is for the use of selector.slurp_file. """ # Comment or line: if not line.strip() or line.strip()[0] == '#': pass # Directive: elif line.strip()[0] == '@': parts = line.strip()[1:].split(' ', 1) if len(parts) == 2: directive, rest = parts else: directive = parts[0] rest = '' if directive == 'prefix': self.prefix = rest.strip() if directive == 'parser': self.parser = resolver.resolve(rest.strip()) if directive == 'wrap': self.wrap = resolver.resolve(rest.strip()) # HTTP Method -> Handler: elif line[0] in ' \t': if path is None: raise MappingFileError( "Specify a path expression first.") meth, app = line.strip().split(' ', 1) methods[meth.strip()] = resolver.resolve(app) # Path Expression: else: if path and methods: self.add(path, methods) path = line.strip() methods = {} return path, methods
def test_resolve_with_overrides(self): options1 = { "name1_options1": "hello ${./name2_options1}", "name2_options1": "${./name3_options1} goodbye", "name3_options1": "${default_options1}", "name4_options1": "this is name4", "another_options1": "another", } options2 = { "name1_options2": "hello ${./name2_options2}", "name2_options2": "${./name3_options2} goodbye", "name3_options2": "${default_options2}", "name4_options2": "this is name4", "another_options2": "another", "external1": "${options1/name3_options1}", "external2": "${options1/name2_options1}", } defaults = {"default_options1": "default_for_options1", "default_options2": "default_for_options2"} sections = {"options1": options1, "options2": options2} from resolver import resolve overrides = {"options1": {"name1_options1": "hello ${./name4_options1}"}} resolved = resolve(sections, defaults, overrides) self.assertEqual( resolved["options1"], { "name1_options1": "hello this is name4", "name2_options1": "default_for_options1 goodbye", "name3_options1": "default_for_options1", "name4_options1": "this is name4", "another_options1": "another", }, ) self.assertEqual( resolved["options2"], { "name1_options2": "hello default_for_options2 goodbye", "name2_options2": "default_for_options2 goodbye", "name3_options2": "default_for_options2", "name4_options2": "this is name4", "another_options2": "another", "external1": "default_for_options1", "external2": "default_for_options1 goodbye", }, )
def test_custom_plugin(): def checker(context, tree): return isinstance(tree, dict) and 'identity' in tree def handler(context, tree): return tree['identity'] rule_path = get_rule_file('test_custom_plugin.json') ruleset = rules.parse_file(rule_path.as_posix()) assert len(ruleset.rules) == 1 context = resolver.make_context() resolver.context_add_plugin(context, checker, handler) result = resolver.resolve(ruleset, context) assert len(result.goals) == 1 assert all(goal.points == 42 for goal in result.goals)
def test_resolve_with_overrides(self): options1 = {'name1_options1':'hello ${./name2_options1}', 'name2_options1':'${./name3_options1} goodbye', 'name3_options1':'${default_options1}', 'name4_options1':'this is name4', 'another_options1':'another'} options2 = {'name1_options2':'hello ${./name2_options2}', 'name2_options2':'${./name3_options2} goodbye', 'name3_options2':'${default_options2}', 'name4_options2':'this is name4', 'another_options2':'another', 'external1':'${options1/name3_options1}', 'external2':'${options1/name2_options1}'} defaults = {'default_options1':'default_for_options1', 'default_options2':'default_for_options2'} sections = {'options1':options1, 'options2':options2} from resolver import resolve overrides = {'options1':{'name1_options1':'hello ${./name4_options1}'}} resolved = resolve(sections, defaults, overrides) self.assertEqual(resolved['options1'], {'name1_options1':'hello this is name4', 'name2_options1': 'default_for_options1 goodbye', 'name3_options1': 'default_for_options1', 'name4_options1': 'this is name4', 'another_options1': 'another'}, ) self.assertEqual(resolved['options2'], { 'name1_options2':'hello default_for_options2 goodbye', 'name2_options2': 'default_for_options2 goodbye', 'name3_options2': 'default_for_options2', 'name4_options2': 'this is name4', 'another_options2': 'another', 'external1':'default_for_options1', 'external2':'default_for_options1 goodbye' } )
def handle_tcp_request(client_bytes): request = json.loads(client_bytes.decode()) if(validate_request(request)): action = request.get('action') controller = resolve(action, INSTALLED_APPS) if controller: try: response = controller(request) logging.info(f'Sending server response {response}') except Exception as err: response = make_response(request, 500, 'Internal server error') logging.critical(f'Exception - {err}') else: response = make_response(request, 404, f'Action {action} not found') logging.error(f'Client call unknown action {action}') else: response = make_response(request, 400, 'Wrong request') logging.error(f'Client sent wrong request {request}') return json.dumps(response).encode()
def test_invalid_requests(self): with self.subTest(msg="Bad A Request: no TLD given"): self.assertIsNone(resolve("floobatuba")) with self.subTest(msg="Bad A Request: non-existent TLD"): self.assertIsNone(resolve("devo.whipit")) with self.subTest(msg="Bad A Request: non-existent domain"): self.assertIsNone(resolve("asdkjfasjafby.com")) with self.subTest(msg="Bad A Request: non-existent subdomain"): self.assertIsNone(resolve("evil.sandiego.edu")) with self.subTest(msg="Bad MX Request: no MX record"): self.assertIsNone(resolve("www.sandiego.edu", True)) with self.subTest(msg="Bad MX Request: non-existent domain"): self.assertIsNone(resolve("asdkjfasjafby.com", True))
def request_object_factory(resolver): global_object = resolver.resolve(SampleBase) return RequestObject(global_object)
def do_something(resolver): return SampleOp(resolver.resolve(SampleBase))
import argparse from resolver import resolve if __name__ == '__main__': parser = argparse.ArgumentParser( description='load a Schism document store into Solr') parser.add_argument('configuration', metavar='CONFIG', help='a Resolver statement pointing to a SchismSite') args = parser.parse_args() site = resolve(args.configuration) document_paths = site.list_documents() documents = [] for document_path in document_paths: documents.append(site.retrieve_document(document_path)) site.index.add(documents)
def handle(self, packet, address): 'Handle an incoming DNS request' response = resolver.resolve(packet, cache) self.socket.sendto(response, address)
import sys sys.path.append('.') import resolver from brickschema.namespaces import BRICK import rdflib from server import Triplestore ts = Triplestore("triples.db") with ts.cursor() as cur: res = cur.execute("SELECT DISTINCT src FROM latest_triples") srcs = [row[0] for row in res] print(srcs) graphs = {} full_graph, canonical = resolver.resolve(ts.to_records()) full_graph.serialize('graph-eval.ttl', format='ttl') # canonicalize def canonicalize_ent(t): for cluster, ent in canonical: if t[0] in cluster: return (ent, t[1], t[2]) return t # get one "authoritative" ID per cluster # clusters = [] # res = full_graph.query("SELECT ?e1 ?e2 WHERE { \ # ?e1 owl:sameAs ?e2 . ?e1 brick:sourcelabel ?l1 . \ # ?e2 brick:sourcelabel ?l2 }") # for row in res:
def test_a_record(self): """ Tests for valid A records. These should not be CNAME entries. """ with self.subTest(msg="A record for TLD: .com"): self.assertTrue(resolve("webopedia.com") in ["141.193.213.20", "141.193.213.21"]) self.assertEqual(resolve("pokemon.com"), "69.172.200.183") with self.subTest(msg="A record for TLD: .net"): self.assertTrue(resolve("happycow.net") in ["107.154.146.2", "45.60.96.2"]) self.assertEqual(resolve("sdcoe.net"), "209.66.192.225") with self.subTest(msg="A record for TLD: .edu"): self.assertEqual(resolve("www.sandiego.edu"), "192.195.155.200") self.assertEqual(resolve("www.harvard.edu"), "23.185.0.1") with self.subTest(msg="A record for TLD: .org"): self.assertTrue(resolve("consumerreports.org") in ["65.8.158.100", "65.8.158.14", "65.8.158.67", "65.8.158.37", "99.84.203.46", "99.84.203.50", "99.84.203.93", "99.84.203.105"]) self.assertTrue(resolve("pcta.org") in ["172.67.69.188", "104.26.15.163", "104.26.14.163"]) with self.subTest(msg="A record for TLD: .io"): self.assertTrue(resolve("github.io") in [ "185.199.109.153", "185.199.111.153", "185.199.108.153", "185.199.110.153" ]) self.assertEqual(resolve("gigatron.io"), "85.17.207.47") with self.subTest(msg="A record for TLD: .gov"): self.assertEqual(resolve("mentalhealth.gov"), "52.23.42.165") self.assertEqual(resolve("ca.gov"), "13.87.221.220") with self.subTest(msg="A record for TLD: .ca"): self.assertTrue(resolve("thecanadianencyclopedia.ca") in [ "15.222.77.222", "3.96.106.51" ]) self.assertEqual(resolve("sportsnet.ca"), "23.57.52.245")
def otvori_epizodu(url,title,thumb): #prvo pogledaj ako ima vise dijelova try: html=read_url(url) soup=bs(html) tag=soup.find('div',{'id':'Playerholder'}) frames=tag.findAll('iframe') if len(frames)>1: progress = xbmcgui.DialogProgress() progress.create('Ucitavam', 'Ucitavam dijelove epizoda u playlistu...') playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist.clear() message ="0 od %s"%(len(frames)) progress.update( 0, "", message, "" ) for i in range(len(frames)): link=frames[i]['src'] import urlresolver resolved=urlresolver.resolve(link) li = xbmcgui.ListItem('%s'%title) li.setInfo('video', { 'title': '%s'%title }) li.setThumbnailImage(thumb) playlist.add(resolved,li) message = str(i+1) + " od %s"%(len(frames)) perc=((i+1)/(len(frames)))*100 progress.update( perc, "", message, "" ) xbmc.Player().play(playlist) return except: pass try: html=read_url(url) soup=bs(html) link=soup.findAll('iframe')[1]['src'] except: try: html=read_url(url) soup=bs(html) link=soup.findAll('iframe')[1]['src'] except: try: html=read_url(url) soup=bs(html) try: link=soup.find('div',{'id':'Playerholder'}).find('embed')['src'] except: link=soup.find('div',{'id':'Playerholder'}).find('iframe')['src'] except: html=read_url(url).lower() ind=html.index('player.src') html=html[ind:ind+80] reg=r'watch\?v=(.+?)"' link=re.findall(re.compile(reg),html)[0] link='http://www.youtube.com/watch?v=' + link try: import urlresolver resolved=urlresolver.resolve(link) except: import resolver as srr resolved=srr.resolve(link)[0]['url'] li = xbmcgui.ListItem('%s'%title) li.setInfo('video', { 'title': '%s'%title }) li.setThumbnailImage(thumb) xbmc.Player().play(item=resolved, listitem=li)
def otvori_epizodu(url, title, thumb): #prvo pogledaj ako ima vise dijelova try: html = read_url(url) soup = bs(html) tag = soup.find('div', {'id': 'Playerholder'}) frames = tag.findAll('iframe') if len(frames) > 1: progress = xbmcgui.DialogProgress() progress.create('Ucitavam', 'Ucitavam dijelove epizoda u playlistu...') playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist.clear() message = "0 od %s" % (len(frames)) progress.update(0, "", message, "") for i in range(len(frames)): link = frames[i]['src'] import urlresolver resolved = urlresolver.resolve(link) li = xbmcgui.ListItem('%s' % title) li.setInfo('video', {'title': '%s' % title}) li.setThumbnailImage(thumb) playlist.add(resolved, li) message = str(i + 1) + " od %s" % (len(frames)) perc = ((i + 1) / (len(frames))) * 100 progress.update(perc, "", message, "") xbmc.Player().play(playlist) return except: pass try: html = read_url(url) soup = bs(html) link = soup.findAll('iframe')[1]['src'] except: try: html = read_url(url) soup = bs(html) link = soup.findAll('iframe')[1]['src'] except: try: html = read_url(url) soup = bs(html) try: link = soup.find('div', { 'id': 'Playerholder' }).find('embed')['src'] except: link = soup.find('div', { 'id': 'Playerholder' }).find('iframe')['src'] except: html = read_url(url).lower() ind = html.index('player.src') html = html[ind:ind + 80] reg = r'watch\?v=(.+?)"' link = re.findall(re.compile(reg), html)[0] link = 'http://www.youtube.com/watch?v=' + link try: import urlresolver resolved = urlresolver.resolve(link) except: import resolver as srr resolved = srr.resolve(link)[0]['url'] li = xbmcgui.ListItem('%s' % title) li.setInfo('video', {'title': '%s' % title}) li.setThumbnailImage(thumb) xbmc.Player().play(item=resolved, listitem=li)
def test_resolve(): action = resolve(TEST_ACTION, TEST_INSTALLED_APPS) assert action == EXPECTED_CONTROLLER
def resolve_for_result(kattis, ruleset): context = resolver.make_context() plugins = kattis.get_plugins() func = lambda c, h: resolver.context_add_plugin(context, c, h) util.starmap_now(func, plugins) return resolver.resolve(ruleset, context)
class DNSResponder: def __init__(self, config): self.config = config self.resolver = resolver.Resolver(config) self.server_ip = config['server-ip'] self.hostname_base = config['hostname-base'] def get_response(self, pkt): conf = self.config resolver = self.resolver server_ip = self.server_ip hostname_base = self.hostname_base if (DNS not in pkt or pkt[DNS].opcode != 0L or pkt[DNS].ancount != 0 or pkt[IP].src == server_ip): #sys.stderr.write("no qd.qtype in this dns request?!\n") #TODO figure out what to log here? return try: """ First make sure that we support this query type """ pkt_proto = None if pkt[DNS].qd.qtype == 1: pkt_proto = 'v4' elif pkt[DNS].qd.qtype == 28: pkt_proto = 'v6' else: ### won't respond to non A or AAAA packet sys.stderr.write('Ignoring DNS query type %d\n' % pkt[DNS].qd.qtype) resp = generate_no_answer(pkt) send(resp, verbose=0) return record(pkt[IP].src, pkt[DNS].qd.qname, pkt[DNS].qd.qtype, 'none') """ Find result """ hostname = pkt[DNS].qd.qname.lower() if hostname[-1] == '.': hostname = hostname[:-1] sys.stderr.write('query src: %s query: %s\n' % (pkt[IP].src, hostname)) if not hostname.endswith(hostname_base): return dest = resolver.resolve(hostname) if not is_ip(dest): #return CNAME is this is a hostname pkt_proto = 'cname' """ Build response """ resp = generate_response(pkt, dest, pkt_proto) send(resp, verbose=0) return record(pkt[IP].src, hostname, pkt_proto, dest) except: sys.stderr.write('Error processing response\n') traceback.print_exc(file=sys.stderr)
from kb import get_indexed_kb, indexed_kb from resolver import resolve import copy if __name__ == '__main__': with open("input.txt", "r") as f: raw_data = f.readlines() raw_data = [x.rstrip() for x in raw_data] number_of_queries = int(raw_data[0]) queries = raw_data[1:number_of_queries + 1] number_of_data = int(raw_data[number_of_queries + 1]) data = raw_data[number_of_queries + 2:number_of_queries + 2 + number_of_data] kb = get_indexed_kb(data) answers = [] for query in queries: if query[0] == '~': query = '(' + query + ')' answers.append(resolve(query, copy.deepcopy(kb))) with open("output.txt", "w") as f: for ans in answers: f.write(str(ans) + '\n')