repo_name
stringlengths
6
100
path
stringlengths
4
294
copies
stringclasses
981 values
size
stringlengths
4
6
content
stringlengths
606
896k
license
stringclasses
15 values
input_ids
listlengths
1.02k
1.02k
labels
listlengths
1.02k
1.02k
attention_mask
listlengths
1.02k
1.02k
vmahuli/contrail-controller
src/opserver/partition_handler.py
1
28794
#!/usr/bin/python from gevent import monkey monkey.patch_all() import logging import gevent from gevent.coros import BoundedSemaphore from kafka import KafkaClient, KeyedProducer, SimpleConsumer, common from uveserver import UVEServer import os import json import copy import traceback import uuid import struct import socket import discoveryclient.client as client from sandesh_common.vns.constants import ALARM_PARTITION_SERVICE_NAME from pysandesh.util import UTCTimestampUsec import select import redis from collections import namedtuple PartInfo = namedtuple("PartInfo",["ip_address","instance_id","acq_time","port"]) def sse_pack(d): """Pack data in SSE format""" buffer = '' for k in ['event','data']: if k in d.keys(): buffer += '%s: %s\n' % (k, d[k]) return buffer + '\n' class UveCacheProcessor(gevent.Greenlet): def __init__(self, logger, q, partitions): gevent.Greenlet.__init__(self) self._logger = logger self._q = q self._partkeys = {} for partno in range(0,partitions): self._partkeys[partno] = set() self._uvedb = {} def get_uve(self, key, filters=None, is_alarm=False): failures = False rsp = {} try: filters = filters or {} tfilter = filters.get('cfilt') ackfilter = filters.get('ackfilt') if is_alarm: tfilter = tfilter or {} # When returning only alarms, ignore non-alarm cfilt for k in tfilter.keys(): if k != "UVEAlarms": del tfilter[k] if len(tfilter) == 0: tfilter["UVEAlarms"] = set(["alarms"]) barekey = key.split(":",1)[1] table = key.split(":",1)[0] if table not in self._uvedb: return failures, rsp if barekey not in self._uvedb[table]: return failures, rsp for tkey,tval in self._uvedb[table][barekey].iteritems(): afilter_list = set() if tfilter is not None: if tkey not in tfilter: continue else: afilter_list = tfilter[tkey] if not tval: continue for akey, aval in tval.iteritems(): if len(afilter_list): if akey not in afilter_list: continue if ackfilter is not None and \ tkey == "UVEAlarms" and akey == "alarms": alarms = [] for alarm in aval: ack = "false" if "ack" in alarm: if alarm["ack"]: ack = "true" else: ack = "false" if ack == ackfilter: alarms.append(alarm) if not len(alarms): continue else: if not tkey in rsp: rsp[tkey] = {} rsp[tkey][akey] = alarms else: if not tkey in rsp: rsp[tkey] = {} rsp[tkey][akey] = aval except Exception as ex: template = "Exception {0} in uve cache proc. Arguments:\n{1!r}" messag = template.format(type(ex).__name__, ex.args) self._logger.error("%s : traceback %s" % \ (messag, traceback.format_exc())) return failures, rsp def _run(self): for telem in self._q: elem = telem['data'] if telem['event'] == 'clear': # remove all keys of this partition partno = elem['partition'] for key in self._partkeys[partno]: barekey = key.split(":",1)[1] table = key.split(":",1)[0] del self._uvedb[table][barekey] self._partkeys[partno].remove("%s:%s" % \ (table, barekey)) elif telem['event'] == 'sync' or telem['event'] == 'update': partno = elem['partition'] self._partkeys[partno].add(elem['key']) barekey = elem['key'].split(":",1)[1] table = elem['key'].split(":",1)[0] if table not in self._uvedb: self._uvedb[table] = {} if barekey not in self._uvedb[table]: self._uvedb[table][barekey] = {} if elem['type'] is None: # delete the entire UVE self._partkeys[partno].remove("%s:%s" % \ (table, barekey)) del self._uvedb[table][barekey] else: typ = elem['type'] if typ not in self._uvedb[table][barekey]: self._uvedb[table][barekey][typ] = None if elem['value'] is None: # remove one type of this UVE del self._uvedb[table][barekey][typ] else: self._uvedb[table][barekey][typ] = elem['value'] elif telem['event'] == 'stop': break else: pass class UveStreamPart(gevent.Greenlet): def __init__(self, partno, logger, q, pi, rpass, sse): gevent.Greenlet.__init__(self) self._logger = logger self._q = q self._pi = pi self._partno = partno self._rpass = rpass self._sse = sse def syncpart(self, redish): inst = self._pi.instance_id part = self._partno keys = list(redish.smembers("AGPARTKEYS:%s:%d" % (inst, part))) ppe = redish.pipeline() for key in keys: ppe.hgetall("AGPARTVALUES:%s:%d:%s" % (inst, part, key)) pperes = ppe.execute() idx=0 for res in pperes: for tk,tv in res.iteritems(): dt = {'partition':self._partno, 'key':keys[idx], 'type':tk, 'value':json.loads(tv)} if self._sse: msg = {'event': 'sync', 'data':json.dumps(dt)} self._q.put(sse_pack(msg)) else: msg = {'event': 'sync', 'data':dt} self._q.put(msg) idx += 1 def _run(self): lredis = None pb = None while True: try: lredis = redis.StrictRedis( host=self._pi.ip_address, port=self._pi.port, password=self._rpass, db=2) pb = lredis.pubsub() inst = self._pi.instance_id part = self._partno pb.subscribe('AGPARTPUB:%s:%d' % (inst, part)) self.syncpart(lredis) for message in pb.listen(): if message["type"] != "message": continue dataline = message["data"] try: elems = json.loads(dataline) except: self._logger.error("AggUVE Parsing failed: %s" % str(message)) continue else: self._logger.info("AggUVE loading: %s" % str(elems)) ppe = lredis.pipeline() for elem in elems: # This UVE was deleted if elem["type"] is None: ppe.exists("AGPARTVALUES:%s:%d:%s" % \ (inst, part, elem["key"])) else: ppe.hget("AGPARTVALUES:%s:%d:%s" % \ (inst, part, elem["key"]), elem["type"]) pperes = ppe.execute() idx = 0 for elem in elems: if elem["type"] is None: dt = {'partition':part, 'key':elem["key"], 'type':None} else: vjson = pperes[idx] if vjson is None: vdata = None else: vdata = json.loads(vjson) dt = {'partition':part, 'key':elem["key"], 'type':elem["type"], 'value':vdata} if self._sse: msg = {'event': 'update', 'data':json.dumps(dt)} self._q.put(sse_pack(msg)) else: msg = {'event': 'update', 'data':dt} self._q.put(msg) idx += 1 except gevent.GreenletExit: break except Exception as ex: template = "Exception {0} in uve stream proc. Arguments:\n{1!r}" messag = template.format(type(ex).__name__, ex.args) self._logger.error("%s : traceback %s" % \ (messag, traceback.format_exc())) lredis = None if pb is not None: pb.close() pb = None gevent.sleep(2) return None class UveStreamer(gevent.Greenlet): def __init__(self, logger, q, rfile, agp_cb, partitions, rpass): gevent.Greenlet.__init__(self) self._logger = logger self._q = q self._rfile = rfile self._agp_cb = agp_cb self._agp = {} self._parts = {} self._partitions = partitions self._rpass = rpass self._sse = True if self._rfile is None: self._sse = False def _run(self): inputs = [ self._rfile ] outputs = [ ] if self._sse: msg = {'event': 'init', 'data':\ json.dumps({'partitions':self._partitions})} self._q.put(sse_pack(msg)) else: msg = {'event': 'init', 'data':\ {'partitions':self._partitions}} self._q.put(msg) while True: try: if self._rfile is not None: readable, writable, exceptional = \ select.select(inputs, outputs, inputs, 1) if (readable or writable or exceptional): break else: gevent.sleep(1) newagp = self._agp_cb() set_new, set_old = set(newagp.keys()), set(self._agp.keys()) intersect = set_new.intersection(set_old) # deleted parts for elem in set_old - intersect: self.partition_stop(elem) # new parts for elem in set_new - intersect: self.partition_start(elem, newagp[elem]) # changed parts for elem in intersect: if self._agp[elem] != newagp[elem]: self.partition_stop(elem) self.partition_start(elem, newagp[elem]) self._agp = newagp except gevent.GreenletExit: break for part, pi in self._agp.iteritems(): self.partition_stop(part) if self._sse: msg = {'event': 'stop', 'data':json.dumps(None)} self._q.put(sse_pack(msg)) else: msg = {'event': 'stop', 'data':None} self._q.put(msg) def partition_start(self, partno, pi): self._logger.error("Starting agguve part %d using %s" %( partno, pi)) if self._sse: msg = {'event': 'clear', 'data':\ json.dumps({'partition':partno, 'acq_time':pi.acq_time})} self._q.put(sse_pack(msg)) else: msg = {'event': 'clear', 'data':\ {'partition':partno, 'acq_time':pi.acq_time}} self._q.put(msg) self._parts[partno] = UveStreamPart(partno, self._logger, self._q, pi, self._rpass, self._sse) self._parts[partno].start() def partition_stop(self, partno): self._logger.error("Stopping agguve part %d" % partno) self._parts[partno].kill() self._parts[partno].get() del self._parts[partno] class PartitionHandler(gevent.Greenlet): def __init__(self, brokers, group, topic, logger, limit): gevent.Greenlet.__init__(self) self._brokers = brokers self._group = group self._topic = topic self._logger = logger self._limit = limit self._uvedb = {} self._partoffset = 0 self._kfk = None def msg_handler(self, mlist): self._logger.info("%s Reading %s" % (self._topic, str(mlist))) return True def _run(self): pcount = 0 while True: try: self._logger.error("New KafkaClient %s" % self._topic) self._kfk = KafkaClient(self._brokers , "kc-" + self._topic) try: consumer = SimpleConsumer(self._kfk, self._group, self._topic, buffer_size = 4096*4, max_buffer_size=4096*32) #except: except Exception as ex: template = "Consumer Failure {0} occured. Arguments:\n{1!r}" messag = template.format(type(ex).__name__, ex.args) self._logger.error("Error: %s trace %s" % \ (messag, traceback.format_exc())) raise RuntimeError(messag) self._logger.error("Starting %s" % self._topic) # Find the offset of the last message that has been queued consumer.seek(-1,2) try: mi = consumer.get_message(timeout=0.1) consumer.commit() except common.OffsetOutOfRangeError: mi = None #import pdb; pdb.set_trace() self._logger.info("Last Queued for %s is %s" % \ (self._topic,str(mi))) # start reading from last previously processed message if mi != None: consumer.seek(0,1) else: consumer.seek(0,0) if self._limit: raise gevent.GreenletExit while True: try: mlist = consumer.get_messages(10,timeout=0.5) if not self.msg_handler(mlist): raise gevent.GreenletExit consumer.commit() pcount += len(mlist) except TypeError as ex: self._logger.error("Type Error: %s trace %s" % \ (str(ex.args), traceback.format_exc())) gevent.sleep(0.1) except common.FailedPayloadsError as ex: self._logger.error("Payload Error: %s" % str(ex.args)) gevent.sleep(0.1) except gevent.GreenletExit: break except AssertionError as ex: self._partoffset = ex break except Exception as ex: template = "An exception of type {0} occured. Arguments:\n{1!r}" messag = template.format(type(ex).__name__, ex.args) self._logger.error("%s : traceback %s" % \ (messag, traceback.format_exc())) self.stop_partition() gevent.sleep(2) self._logger.error("Stopping %s pcount %d" % (self._topic, pcount)) partdb = self.stop_partition() return self._partoffset, partdb class UveStreamProc(PartitionHandler): # Arguments: # # brokers : broker list for kafka bootstrap # partition : partition number # uve_topic : Topic to consume # logger : logging object to use # callback : Callback function for reporting the set of the UVEs # that may have changed for a given notification # rsc : Callback function to check on collector status # and get sync contents for new collectors # aginst : instance_id of alarmgen # rport : redis server port # disc : discovery client to publish to def __init__(self, brokers, partition, uve_topic, logger, callback, host_ip, rsc, aginst, rport, disc = None): super(UveStreamProc, self).__init__(brokers, "workers", uve_topic, logger, False) self._uvedb = {} self._uvein = {} self._callback = callback self._partno = partition self._host_ip = host_ip self._ip_code, = struct.unpack('>I', socket.inet_pton( socket.AF_INET, host_ip)) self.disc_rset = set() self._resource_cb = rsc self._aginst = aginst self._disc = disc self._acq_time = UTCTimestampUsec() self._rport = rport def acq_time(self): return self._acq_time def resource_check(self, msgs): ''' This function compares the known collectors with the list from discovery, and syncs UVE keys accordingly ''' newset , coll_delete, chg_res = self._resource_cb(self._partno, self.disc_rset, msgs) for coll in coll_delete: self._logger.error("Part %d lost collector %s" % (self._partno, coll)) self.stop_partition(coll) if len(chg_res): self.start_partition(chg_res) self.disc_rset = newset if self._disc: data = { 'instance-id' : self._aginst, 'partition' : str(self._partno), 'ip-address': self._host_ip, 'acq-time': str(self._acq_time), 'port':str(self._rport)} self._disc.publish(ALARM_PARTITION_SERVICE_NAME, data) def stop_partition(self, kcoll=None): clist = [] if not kcoll: clist = self._uvedb.keys() # If all collectors are being cleared, clear resoures too self.disc_rset = set() if self._disc: # TODO: Unpublish instead of setting acq-time to 0 data = { 'instance-id' : self._aginst, 'partition' : str(self._partno), 'ip-address': self._host_ip, 'acq-time': "0", 'port':str(self._rport)} self._disc.publish(ALARM_PARTITION_SERVICE_NAME, data) else: clist = [kcoll] self._logger.error("Stopping part %d collectors %s" % \ (self._partno,clist)) partdb = {} chg = {} for coll in clist: partdb[coll] = {} for gen in self._uvedb[coll].keys(): partdb[coll][gen] = {} for tab in self._uvedb[coll][gen].keys(): for rkey in self._uvedb[coll][gen][tab].keys(): uk = tab + ":" + rkey chg[uk] = None partdb[coll][gen][uk] = \ set(self._uvedb[coll][gen][tab][rkey].keys()) del self._uvedb[coll] self._logger.error("Stopping part %d UVEs %s" % \ (self._partno,str(chg.keys()))) self._callback(self._partno, chg) return partdb def start_partition(self, cbdb): ''' This function loads the initial UVE database. for the partition ''' self._logger.error("Starting part %d collectors %s" % \ (self._partno, str(cbdb.keys()))) uves = {} for kcoll,coll in cbdb.iteritems(): self._uvedb[kcoll] = {} for kgen,gen in coll.iteritems(): self._uvedb[kcoll][kgen] = {} for kk in gen.keys(): tabl = kk.split(":",1) tab = tabl[0] rkey = tabl[1] if not tab in self._uvedb[kcoll][kgen]: self._uvedb[kcoll][kgen][tab] = {} self._uvedb[kcoll][kgen][tab][rkey] = {} uves[kk] = {} for typ, contents in gen[kk].iteritems(): self._uvedb[kcoll][kgen][tab][rkey][typ] = {} self._uvedb[kcoll][kgen][tab][rkey][typ]["c"] = 0 self._uvedb[kcoll][kgen][tab][rkey][typ]["u"] = \ uuid.uuid1(self._ip_code) uves[kk][typ] = contents self._logger.error("Starting part %d UVEs %s" % \ (self._partno, str(uves.keys()))) self._callback(self._partno, uves) def contents(self): return self._uvedb def stats(self): ''' Return the UVE incoming stats collected over the last time period for this partition Also, the stats should be cleared to prepare for the next period of collection. ''' ret_in = copy.deepcopy(self._uvein) self._uvein = {} return ret_in def msg_handler(self, mlist): self.resource_check(mlist) for mm in mlist: if mm is None: continue self._logger.debug("%s Reading offset %d" % \ (self._topic, mm.offset)) if not self.msg_handler_single(mm): self._logger.info("%s could not handle %s" % \ (self._topic, str(mm))) return False return True def msg_handler_single(self, om): self._partoffset = om.offset chg = {} try: uv = json.loads(om.message.value) coll = uv["coll"] gen = uv["gen"] if not self._uvedb.has_key(coll): # This partition is not synced yet. # Ignore this message self._logger.debug("%s Ignoring UVE %s" % (self._topic, str(om))) return True if not self._uvedb[coll].has_key(gen): self._uvedb[coll][gen] = {} if (uv["message"] == "UVEUpdate"): tabl = uv["key"].split(":",1) tab = tabl[0] rkey = tabl[1] if tab not in self._uvedb[coll][gen]: self._uvedb[coll][gen][tab] = {} if not rkey in self._uvedb[coll][gen][tab]: self._uvedb[coll][gen][tab][rkey] = {} removed = False # uv["type"] and uv["value"] can be decoded as follows: # uv["type"] can be one of the following: # - None # All Types under this UVE are deleted # uv["value"] will not be present # (this option is only for agg UVE updates) # - "<Struct>" # uv["value"] refers to this struct # uv["value"] can be one of the following: # - None # This Type has been deleted. # - {} # The Type has a value, which is # not available in this message. # (this option is only for raw UVE updates) # - {<Value>} # The Value of the Type # (this option is only for agg UVE updates) if uv["type"] is None: # TODO: Handling of delete UVE case return False if uv["value"] is None: if uv["type"] in self._uvedb[coll][gen][tab][rkey]: del self._uvedb[coll][gen][tab][rkey][uv["type"]] if not len(self._uvedb[coll][gen][tab][rkey]): del self._uvedb[coll][gen][tab][rkey] removed = True if not removed: if uv["type"] in self._uvedb[coll][gen][tab][rkey]: self._uvedb[coll][gen][tab][rkey][uv["type"]]["c"] +=1 else: self._uvedb[coll][gen][tab][rkey][uv["type"]] = {} self._uvedb[coll][gen][tab][rkey][uv["type"]]["c"] = 1 self._uvedb[coll][gen][tab][rkey][uv["type"]]["u"] = \ uuid.uuid1(self._ip_code) chg[uv["key"]] = { uv["type"] : uv["value"] } # Record stats on the input UVE Notifications if not self._uvein.has_key(tab): self._uvein[tab] = {} if not self._uvein[tab].has_key(coll): self._uvein[tab][coll] = {} if not self._uvein[tab][coll].has_key(gen): self._uvein[tab][coll][gen] = {} if not self._uvein[tab][coll][gen].has_key(uv["type"]): self._uvein[tab][coll][gen][uv["type"]] = 1 else: self._uvein[tab][coll][gen][uv["type"]] += 1 else: # Record stats on UVE Keys being processed for tab in self._uvedb[coll][gen].keys(): for rkey in self._uvedb[coll][gen][tab].keys(): uk = tab + ":" + rkey # when a generator is delelted, we need to # notify for *ALL* its UVEs chg[uk] = None del self._uvedb[coll][gen] except Exception as ex: template = "An exception of type {0} in uve proc . Arguments:\n{1!r}" messag = template.format(type(ex).__name__, ex.args) self._logger.info("%s" % messag) return False else: self._callback(self._partno, chg) return True if __name__ == '__main__': logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s') workers = {} brokers = "localhost:9092,localhost:9093,localhost:9094" group = "workers" kafka = KafkaClient(brokers,str(os.getpid())) cons = SimpleConsumer(kafka, group, "ctrl") cons.provide_partition_info() print "Starting control" end_ready = False while end_ready == False: try: while True: part, mmm = cons.get_message(timeout=None) mm = mmm.message print "Consumed ctrl " + str(mm) if mm.value == "start": if workers.has_key(mm.key): print "Dup partition %s" % mm.key raise ValueError else: ph = UveStreamProc(brokers, int(mm.key), "uve-" + mm.key, "alarm-x" + mm.key, logging) ph.start() workers[int(mm.key)] = ph elif mm.value == "stop": #import pdb; pdb.set_trace() if workers.has_key(int(mm.key)): ph = workers[int(mm.key)] gevent.kill(ph) res,db = ph.get() print "Returned " + str(res) print "State :" for k,v in db.iteritems(): print "%s -> %s" % (k,str(v)) del workers[int(mm.key)] else: end_ready = True cons.commit() gevent.sleep(2) break except TypeError: gevent.sleep(0.1) except common.FailedPayloadsError as ex: print "Payload Error: " + str(ex.args) gevent.sleep(0.1) lw=[] for key, value in workers.iteritems(): gevent.kill(value) lw.append(value) gevent.joinall(lw) print "Ending Consumers"
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 199, 504, 23386, 492, 14198, 199, 20372, 14, 2068, 63, 452, 342, 199, 646, 2050, 199, 646, 23386, 199, 504, 23386, 14, 989, 736, 492, 5088, 4585, 26574, 199, 504, 29576, 492, 1804, 15294, 3041, 12, 2606, 379, 15532, 12, 5870, 18186, 12, 2863, 199, 504, 399, 432, 1000, 492, 738, 54, 654, 23685, 199, 646, 747, 199, 646, 2022, 199, 646, 1331, 199, 646, 5190, 199, 646, 5377, 199, 646, 2702, 199, 646, 2838, 199, 646, 13172, 1258, 14, 1258, 465, 1890, 221, 199, 504, 28698, 271, 609, 63, 2330, 14, 86, 561, 14, 5559, 492, 12112, 12482, 63, 30407, 63, 10486, 63, 2339, 199, 504, 10382, 290, 271, 609, 14, 1974, 492, 738, 52, 1028, 1036, 2359, 53, 3321, 199, 646, 3504, 199, 646, 16967, 199, 504, 5055, 492, 12863, 199, 199, 8416, 2354, 275, 12863, 480, 8416, 2354, 401, 905, 711, 63, 1562, 2266, 842, 63, 344, 2266, 645, 81, 63, 521, 2266, 719, 3135, 199, 199, 318, 308, 261, 63, 1389, 8, 68, 304, 272, 408, 2305, 666, 315, 428, 899, 1475, 624, 272, 3335, 275, 2125, 272, 367, 1022, 315, 788, 1430, 1673, 576, 2565, 267, 340, 1022, 315, 366, 14, 1612, 837, 288, 3335, 847, 1543, 83, 26, 450, 83, 60, 78, 7, 450, 334, 75, 12, 366, 59, 75, 566, 272, 372, 3335, 435, 1557, 78, 7, 199, 199, 533, 738, 432, 4437, 10438, 8, 303, 782, 14, 19456, 2723, 304, 272, 347, 636, 826, 721, 277, 12, 2512, 12, 1894, 12, 16394, 304, 267, 23386, 14, 19456, 2723, 855, 826, 721, 277, 9, 267, 291, 423, 2921, 275, 2512, 267, 291, 423, 81, 275, 1894, 267, 291, 423, 2064, 1612, 275, 1052, 267, 367, 1777, 889, 315, 1425, 8, 16, 12, 12553, 304, 288, 291, 423, 2064, 1612, 59, 2064, 889, 61, 275, 663, 342, 267, 291, 423, 85, 1354, 66, 275, 1052, 18407, 347, 664, 63, 85, 432, 8, 277, 12, 790, 12, 4766, 29, 403, 12, 365, 63, 14160, 29, 797, 304, 267, 9081, 275, 756, 267, 13684, 275, 1052, 267, 862, 26, 288, 4766, 275, 4766, 503, 1052, 288, 307, 1541, 275, 4766, 14, 362, 360, 67, 18872, 358, 288, 19807, 1541, 275, 4766, 14, 362, 360, 564, 18872, 358, 288, 340, 365, 63, 14160, 26, 355, 307, 1541, 275, 307, 1541, 503, 1052, 355, 327, 3979, 8152, 1454, 741, 25005, 12, 3686, 2222, 13, 14160, 286, 18872, 355, 367, 1022, 315, 307, 1541, 14, 1612, 837, 490, 340, 1022, 1137, 298, 53, 2524, 2439, 25005, 582, 717, 2150, 307, 1541, 59, 75, 61, 355, 340, 822, 8, 84, 1541, 9, 508, 378, 26, 490, 307, 1541, 905, 53, 2524, 2439, 25005, 937, 275, 663, 5234, 279, 25005, 3135, 288, 18753, 498, 275, 790, 14, 1294, 480, 6783, 17, 2788, 17, 61, 288, 1817, 275, 790, 14, 1294, 480, 6783, 17, 2788, 16, 61, 1598, 288, 340, 1817, 440, 315, 291, 423, 85, 1354, 66, 26, 355, 372, 9081, 12, 13684, 288, 340, 18753, 498, 440, 315, 291, 423, 85, 1354, 66, 59, 1224, 2189, 355, 372, 9081, 12, 13684, 7846, 367, 307, 498, 12, 84, 637, 315, 291, 423, 85, 1354, 66, 59, 1224, 1527, 14890, 498, 1055, 4611, 837, 355, 282, 1541, 63, 513, 275, 663, 342, 355, 340, 307, 1541, 365, 440, 488, 26, 490, 340, 307, 498, 440, 315, 307, 1541, 26, 717, 1980, 490, 587, 26, 717, 282, 1541, 63, 513, 275, 307, 1541, 59, 84, 498, 61, 355, 340, 440, 307, 637, 26, 490, 1980, 2234, 367, 282, 498, 12, 282, 637, 315, 307, 637, 14, 4611, 837, 490, 340, 822, 8, 65, 1541, 63, 513, 304, 717, 340, 282, 498, 440, 315, 282, 1541, 63, 513, 26, 1169, 1980, 490, 340, 19807, 1541, 365, 440, 488, 436, 971, 1169, 307, 498, 508, 298, 53, 2524, 2439, 25005, 2, 436, 282, 498, 508, 298, 279, 25005, 582, 717, 741, 25005, 275, 942, 717, 367, 17987, 315, 282, 637, 26, 1169, 19807, 275, 298, 3910, 2, 1169, 340, 298, 564, 2, 315, 17987, 26, 1816, 340, 17987, 905, 564, 6229, 2511, 19807, 275, 298, 2052, 2, 1816, 587, 26, 2511, 19807, 275, 298, 3910, 2, 1169, 340, 19807, 508, 19807, 1541, 26, 1816, 741, 25005, 14, 740, 8, 14160, 9, 717, 340, 440, 822, 8, 279, 25005, 304, 1169, 1980, 717, 587, 26, 1169, 340, 440, 307, 498, 315, 13684, 26, 1816, 13684, 59, 84, 498, 61, 275, 1052, 1169, 13684, 59, 84, 498, 1527, 65, 498, 61, 275, 741, 25005, 490, 587, 26, 717, 340, 440, 307, 498, 315, 13684, 26, 1169, 13684, 59, 84, 498, 61, 275, 1052, 717, 13684, 59, 84, 498, 1527, 65, 498, 61, 275, 282, 637, 267, 871, 2186, 465, 444, 26, 288, 1978, 275, 298, 1726, 469, 16, 93, 315, 399, 432, 2581, 6499, 14, 7628, 3427, 78, 91, 17, 1, 82, 7063, 288, 15634, 643, 275, 1978, 14, 908, 8, 466, 8, 476, 2843, 354, 3108, 444, 14, 589, 9, 288, 291, 423, 2921, 14, 705, 3647, 83, 520, 5190, 450, 83, 2, 450, 971, 2892, 334, 17091, 643, 12, 5190, 14, 908, 63, 2804, 4059, 267, 372, 9081, 12, 13684, 339, 347, 485, 1065, 8, 277, 304, 267, 367, 1565, 3701, 315, 291, 423, 81, 26, 288, 6193, 275, 1565, 3701, 459, 576, 418, 288, 340, 1565, 3701, 459, 1430, 418, 508, 283, 3584, 356, 355, 327, 2813, 1006, 2883, 402, 642, 6484, 355, 1777, 889, 275, 6193, 459, 5312, 418, 355, 367, 790, 315, 291, 423, 2064, 1612, 59, 2064, 889, 2189, 490, 18753, 498, 275, 790, 14, 1294, 480, 6783, 17, 2788, 17, 61, 490, 1817, 275, 790, 14, 1294, 480, 6783, 17, 2788, 16, 61, 490, 2150, 291, 423, 85, 1354, 66, 59, 1224, 1527, 14890, 498, 61, 490, 291, 423, 2064, 1612, 59, 2064, 889, 1055, 2168, 3647, 83, 2689, 83, 2, 450, 971, 717, 334, 1224, 12, 18753, 498, 430, 953, 916, 1565, 3701, 459, 1430, 418, 508, 283, 5186, 7, 503, 1565, 3701, 459, 1430, 418, 508, 283, 873, 356, 355, 1777, 889, 275, 6193, 459, 5312, 418, 355, 291, 423, 2064, 1612, 59, 2064, 889 ]
[ 2647, 15, 1393, 15, 1548, 199, 199, 504, 23386, 492, 14198, 199, 20372, 14, 2068, 63, 452, 342, 199, 646, 2050, 199, 646, 23386, 199, 504, 23386, 14, 989, 736, 492, 5088, 4585, 26574, 199, 504, 29576, 492, 1804, 15294, 3041, 12, 2606, 379, 15532, 12, 5870, 18186, 12, 2863, 199, 504, 399, 432, 1000, 492, 738, 54, 654, 23685, 199, 646, 747, 199, 646, 2022, 199, 646, 1331, 199, 646, 5190, 199, 646, 5377, 199, 646, 2702, 199, 646, 2838, 199, 646, 13172, 1258, 14, 1258, 465, 1890, 221, 199, 504, 28698, 271, 609, 63, 2330, 14, 86, 561, 14, 5559, 492, 12112, 12482, 63, 30407, 63, 10486, 63, 2339, 199, 504, 10382, 290, 271, 609, 14, 1974, 492, 738, 52, 1028, 1036, 2359, 53, 3321, 199, 646, 3504, 199, 646, 16967, 199, 504, 5055, 492, 12863, 199, 199, 8416, 2354, 275, 12863, 480, 8416, 2354, 401, 905, 711, 63, 1562, 2266, 842, 63, 344, 2266, 645, 81, 63, 521, 2266, 719, 3135, 199, 199, 318, 308, 261, 63, 1389, 8, 68, 304, 272, 408, 2305, 666, 315, 428, 899, 1475, 624, 272, 3335, 275, 2125, 272, 367, 1022, 315, 788, 1430, 1673, 576, 2565, 267, 340, 1022, 315, 366, 14, 1612, 837, 288, 3335, 847, 1543, 83, 26, 450, 83, 60, 78, 7, 450, 334, 75, 12, 366, 59, 75, 566, 272, 372, 3335, 435, 1557, 78, 7, 199, 199, 533, 738, 432, 4437, 10438, 8, 303, 782, 14, 19456, 2723, 304, 272, 347, 636, 826, 721, 277, 12, 2512, 12, 1894, 12, 16394, 304, 267, 23386, 14, 19456, 2723, 855, 826, 721, 277, 9, 267, 291, 423, 2921, 275, 2512, 267, 291, 423, 81, 275, 1894, 267, 291, 423, 2064, 1612, 275, 1052, 267, 367, 1777, 889, 315, 1425, 8, 16, 12, 12553, 304, 288, 291, 423, 2064, 1612, 59, 2064, 889, 61, 275, 663, 342, 267, 291, 423, 85, 1354, 66, 275, 1052, 18407, 347, 664, 63, 85, 432, 8, 277, 12, 790, 12, 4766, 29, 403, 12, 365, 63, 14160, 29, 797, 304, 267, 9081, 275, 756, 267, 13684, 275, 1052, 267, 862, 26, 288, 4766, 275, 4766, 503, 1052, 288, 307, 1541, 275, 4766, 14, 362, 360, 67, 18872, 358, 288, 19807, 1541, 275, 4766, 14, 362, 360, 564, 18872, 358, 288, 340, 365, 63, 14160, 26, 355, 307, 1541, 275, 307, 1541, 503, 1052, 355, 327, 3979, 8152, 1454, 741, 25005, 12, 3686, 2222, 13, 14160, 286, 18872, 355, 367, 1022, 315, 307, 1541, 14, 1612, 837, 490, 340, 1022, 1137, 298, 53, 2524, 2439, 25005, 582, 717, 2150, 307, 1541, 59, 75, 61, 355, 340, 822, 8, 84, 1541, 9, 508, 378, 26, 490, 307, 1541, 905, 53, 2524, 2439, 25005, 937, 275, 663, 5234, 279, 25005, 3135, 288, 18753, 498, 275, 790, 14, 1294, 480, 6783, 17, 2788, 17, 61, 288, 1817, 275, 790, 14, 1294, 480, 6783, 17, 2788, 16, 61, 1598, 288, 340, 1817, 440, 315, 291, 423, 85, 1354, 66, 26, 355, 372, 9081, 12, 13684, 288, 340, 18753, 498, 440, 315, 291, 423, 85, 1354, 66, 59, 1224, 2189, 355, 372, 9081, 12, 13684, 7846, 367, 307, 498, 12, 84, 637, 315, 291, 423, 85, 1354, 66, 59, 1224, 1527, 14890, 498, 1055, 4611, 837, 355, 282, 1541, 63, 513, 275, 663, 342, 355, 340, 307, 1541, 365, 440, 488, 26, 490, 340, 307, 498, 440, 315, 307, 1541, 26, 717, 1980, 490, 587, 26, 717, 282, 1541, 63, 513, 275, 307, 1541, 59, 84, 498, 61, 355, 340, 440, 307, 637, 26, 490, 1980, 2234, 367, 282, 498, 12, 282, 637, 315, 307, 637, 14, 4611, 837, 490, 340, 822, 8, 65, 1541, 63, 513, 304, 717, 340, 282, 498, 440, 315, 282, 1541, 63, 513, 26, 1169, 1980, 490, 340, 19807, 1541, 365, 440, 488, 436, 971, 1169, 307, 498, 508, 298, 53, 2524, 2439, 25005, 2, 436, 282, 498, 508, 298, 279, 25005, 582, 717, 741, 25005, 275, 942, 717, 367, 17987, 315, 282, 637, 26, 1169, 19807, 275, 298, 3910, 2, 1169, 340, 298, 564, 2, 315, 17987, 26, 1816, 340, 17987, 905, 564, 6229, 2511, 19807, 275, 298, 2052, 2, 1816, 587, 26, 2511, 19807, 275, 298, 3910, 2, 1169, 340, 19807, 508, 19807, 1541, 26, 1816, 741, 25005, 14, 740, 8, 14160, 9, 717, 340, 440, 822, 8, 279, 25005, 304, 1169, 1980, 717, 587, 26, 1169, 340, 440, 307, 498, 315, 13684, 26, 1816, 13684, 59, 84, 498, 61, 275, 1052, 1169, 13684, 59, 84, 498, 1527, 65, 498, 61, 275, 741, 25005, 490, 587, 26, 717, 340, 440, 307, 498, 315, 13684, 26, 1169, 13684, 59, 84, 498, 61, 275, 1052, 717, 13684, 59, 84, 498, 1527, 65, 498, 61, 275, 282, 637, 267, 871, 2186, 465, 444, 26, 288, 1978, 275, 298, 1726, 469, 16, 93, 315, 399, 432, 2581, 6499, 14, 7628, 3427, 78, 91, 17, 1, 82, 7063, 288, 15634, 643, 275, 1978, 14, 908, 8, 466, 8, 476, 2843, 354, 3108, 444, 14, 589, 9, 288, 291, 423, 2921, 14, 705, 3647, 83, 520, 5190, 450, 83, 2, 450, 971, 2892, 334, 17091, 643, 12, 5190, 14, 908, 63, 2804, 4059, 267, 372, 9081, 12, 13684, 339, 347, 485, 1065, 8, 277, 304, 267, 367, 1565, 3701, 315, 291, 423, 81, 26, 288, 6193, 275, 1565, 3701, 459, 576, 418, 288, 340, 1565, 3701, 459, 1430, 418, 508, 283, 3584, 356, 355, 327, 2813, 1006, 2883, 402, 642, 6484, 355, 1777, 889, 275, 6193, 459, 5312, 418, 355, 367, 790, 315, 291, 423, 2064, 1612, 59, 2064, 889, 2189, 490, 18753, 498, 275, 790, 14, 1294, 480, 6783, 17, 2788, 17, 61, 490, 1817, 275, 790, 14, 1294, 480, 6783, 17, 2788, 16, 61, 490, 2150, 291, 423, 85, 1354, 66, 59, 1224, 1527, 14890, 498, 61, 490, 291, 423, 2064, 1612, 59, 2064, 889, 1055, 2168, 3647, 83, 2689, 83, 2, 450, 971, 717, 334, 1224, 12, 18753, 498, 430, 953, 916, 1565, 3701, 459, 1430, 418, 508, 283, 5186, 7, 503, 1565, 3701, 459, 1430, 418, 508, 283, 873, 356, 355, 1777, 889, 275, 6193, 459, 5312, 418, 355, 291, 423, 2064, 1612, 59, 2064, 889, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
edesky/text_validator
lib/validate.py
1
1509
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import unicode_literals import argparse import json import math parser = argparse.ArgumentParser() parser.add_argument("--text", required=True, help="Input text") parser.add_argument("--short", action='store_true') args = parser.parse_args() input_text = args.text.decode('utf8') VALID_CHARS = u'qwertzuiopasdfghjklyxcvbnm1234567890QWERTZUIOPASDFGHJKLYXCVBNM ?:.,;-=/+ěščřžýáíéĚŠČŘŽÝÁÍÉůúŇ' def chars_score(text): known_cnt = 0 for char in text: if char in VALID_CHARS: known_cnt += 1 return float(known_cnt)/max(len(text), 1) def length_score(text): cnt = 0 for char in text: if char in VALID_CHARS: cnt += 1 return min(math.log(max(cnt, 1), 1000), 1.0) # TODO: add another functions here # def xyz_score(text): # text magic here # return 0.5 def compute(scores): total = 0 cnt = 0 for score in scores: cnt += 1 total = (total * (cnt-1) + score['value']) / cnt; return {'score': total, 'parts': scores} scores = [] scores.append({'name': 'chars_score', 'value': chars_score(input_text)}) scores.append({'name': 'length_score', 'value': length_score(input_text)}) # TODO: add another functions here # scores.append({'name': 'xyz_score', 'value': xyz_score(args.text)}) total_score = compute(scores) if args.short: print(total_score['score']) else: print(json.dumps(total_score, sort_keys=True, indent=4))
mit
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 646, 7534, 199, 646, 2022, 199, 646, 3473, 199, 199, 2087, 275, 7534, 14, 10730, 342, 199, 2087, 14, 525, 63, 2094, 6739, 505, 401, 1415, 29, 549, 12, 1720, 628, 3205, 1318, 531, 199, 2087, 14, 525, 63, 2094, 6739, 3612, 401, 1595, 534, 1617, 63, 2052, 358, 199, 589, 275, 1798, 14, 1122, 63, 589, 342, 199, 199, 1210, 63, 505, 275, 1249, 14, 505, 14, 2708, 360, 1624, 24, 358, 199, 199, 5600, 63, 16326, 275, 399, 7, 81, 2135, 3903, 1907, 411, 18196, 3561, 17421, 590, 1812, 86, 10472, 77, 21515, 49, 55, 5397, 58, 6379, 1938, 1179, 3888, 39, 22313, 43, 6084, 56, 12847, 18273, 45, 5805, 26, 2020, 19901, 13043, 11, 129, 250, 27273, 31493, 130, 248, 29529, 128, 122, 11302, 13676, 5741, 129, 249, 130, 255, 129, 235, 130, 247, 130, 122, 128, 252, 128, 224, 128, 236, 128, 232, 130, 108, 24602, 130, 230, 7, 199, 199, 318, 8365, 63, 3397, 8, 505, 304, 272, 6040, 63, 6507, 275, 378, 272, 367, 1495, 315, 1318, 26, 267, 340, 1495, 315, 22049, 63, 16326, 26, 288, 6040, 63, 6507, 847, 413, 272, 372, 2069, 8, 3159, 63, 6507, 2447, 988, 8, 552, 8, 505, 395, 413, 9, 199, 199, 318, 2582, 63, 3397, 8, 505, 304, 272, 12703, 275, 378, 272, 367, 1495, 315, 1318, 26, 267, 340, 1495, 315, 22049, 63, 16326, 26, 288, 12703, 847, 413, 272, 372, 1748, 8, 3442, 14, 793, 8, 988, 8, 6507, 12, 413, 395, 5198, 395, 413, 14, 16, 9, 199, 199, 3, 3254, 26, 1050, 4573, 3423, 2348, 199, 3, 347, 24122, 63, 3397, 8, 505, 304, 199, 3, 259, 1318, 10628, 2348, 199, 3, 259, 372, 378, 14, 21, 199, 199, 318, 4526, 8, 7107, 304, 272, 3141, 275, 378, 272, 12703, 275, 378, 272, 367, 5396, 315, 9342, 26, 267, 12703, 847, 413, 267, 3141, 275, 334, 2923, 627, 334, 6507, 13, 17, 9, 435, 5396, 459, 585, 1105, 1182, 12703, 27, 272, 372, 791, 3397, 356, 3141, 12, 283, 4181, 356, 9342, 93, 199, 199, 7107, 275, 942, 199, 7107, 14, 740, 3252, 354, 356, 283, 6574, 63, 3397, 297, 283, 585, 356, 8365, 63, 3397, 8, 1210, 63, 505, 11466, 199, 7107, 14, 740, 3252, 354, 356, 283, 1267, 63, 3397, 297, 283, 585, 356, 2582, 63, 3397, 8, 1210, 63, 505, 11466, 199, 3, 3254, 26, 1050, 4573, 3423, 2348, 199, 3, 9342, 14, 740, 3252, 354, 356, 283, 8568, 63, 3397, 297, 283, 585, 356, 24122, 63, 3397, 8, 589, 14, 505, 11466, 199, 199, 2923, 63, 3397, 275, 4526, 8, 7107, 9, 199, 199, 692, 1249, 14, 3612, 26, 272, 870, 8, 2923, 63, 3397, 459, 3397, 1105, 199, 2836, 26, 272, 870, 8, 1001, 14, 4180, 8, 2923, 63, 3397, 12, 4069, 63, 1612, 29, 549, 12, 4363, 29, 20, 430, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 646, 7534, 199, 646, 2022, 199, 646, 3473, 199, 199, 2087, 275, 7534, 14, 10730, 342, 199, 2087, 14, 525, 63, 2094, 6739, 505, 401, 1415, 29, 549, 12, 1720, 628, 3205, 1318, 531, 199, 2087, 14, 525, 63, 2094, 6739, 3612, 401, 1595, 534, 1617, 63, 2052, 358, 199, 589, 275, 1798, 14, 1122, 63, 589, 342, 199, 199, 1210, 63, 505, 275, 1249, 14, 505, 14, 2708, 360, 1624, 24, 358, 199, 199, 5600, 63, 16326, 275, 399, 7, 81, 2135, 3903, 1907, 411, 18196, 3561, 17421, 590, 1812, 86, 10472, 77, 21515, 49, 55, 5397, 58, 6379, 1938, 1179, 3888, 39, 22313, 43, 6084, 56, 12847, 18273, 45, 5805, 26, 2020, 19901, 13043, 11, 129, 250, 27273, 31493, 130, 248, 29529, 128, 122, 11302, 13676, 5741, 129, 249, 130, 255, 129, 235, 130, 247, 130, 122, 128, 252, 128, 224, 128, 236, 128, 232, 130, 108, 24602, 130, 230, 7, 199, 199, 318, 8365, 63, 3397, 8, 505, 304, 272, 6040, 63, 6507, 275, 378, 272, 367, 1495, 315, 1318, 26, 267, 340, 1495, 315, 22049, 63, 16326, 26, 288, 6040, 63, 6507, 847, 413, 272, 372, 2069, 8, 3159, 63, 6507, 2447, 988, 8, 552, 8, 505, 395, 413, 9, 199, 199, 318, 2582, 63, 3397, 8, 505, 304, 272, 12703, 275, 378, 272, 367, 1495, 315, 1318, 26, 267, 340, 1495, 315, 22049, 63, 16326, 26, 288, 12703, 847, 413, 272, 372, 1748, 8, 3442, 14, 793, 8, 988, 8, 6507, 12, 413, 395, 5198, 395, 413, 14, 16, 9, 199, 199, 3, 3254, 26, 1050, 4573, 3423, 2348, 199, 3, 347, 24122, 63, 3397, 8, 505, 304, 199, 3, 259, 1318, 10628, 2348, 199, 3, 259, 372, 378, 14, 21, 199, 199, 318, 4526, 8, 7107, 304, 272, 3141, 275, 378, 272, 12703, 275, 378, 272, 367, 5396, 315, 9342, 26, 267, 12703, 847, 413, 267, 3141, 275, 334, 2923, 627, 334, 6507, 13, 17, 9, 435, 5396, 459, 585, 1105, 1182, 12703, 27, 272, 372, 791, 3397, 356, 3141, 12, 283, 4181, 356, 9342, 93, 199, 199, 7107, 275, 942, 199, 7107, 14, 740, 3252, 354, 356, 283, 6574, 63, 3397, 297, 283, 585, 356, 8365, 63, 3397, 8, 1210, 63, 505, 11466, 199, 7107, 14, 740, 3252, 354, 356, 283, 1267, 63, 3397, 297, 283, 585, 356, 2582, 63, 3397, 8, 1210, 63, 505, 11466, 199, 3, 3254, 26, 1050, 4573, 3423, 2348, 199, 3, 9342, 14, 740, 3252, 354, 356, 283, 8568, 63, 3397, 297, 283, 585, 356, 24122, 63, 3397, 8, 589, 14, 505, 11466, 199, 199, 2923, 63, 3397, 275, 4526, 8, 7107, 9, 199, 199, 692, 1249, 14, 3612, 26, 272, 870, 8, 2923, 63, 3397, 459, 3397, 1105, 199, 2836, 26, 272, 870, 8, 1001, 14, 4180, 8, 2923, 63, 3397, 12, 4069, 63, 1612, 29, 549, 12, 4363, 29, 20, 430, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
veger/ansible
test/units/modules/net_tools/nios/test_nios_a_record.py
59
5731
# This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # Make coding more python3-ish from __future__ import (absolute_import, division, print_function) __metaclass__ = type from ansible.modules.net_tools.nios import nios_a_record from ansible.module_utils.net_tools.nios import api from units.compat.mock import patch, MagicMock, Mock from .test_nios_module import TestNiosModule, load_fixture class TestNiosARecordModule(TestNiosModule): module = nios_a_record def setUp(self): super(TestNiosARecordModule, self).setUp() self.module = MagicMock(name='ansible.modules.net_tools.nios.nios_a_record.WapiModule') self.module.check_mode = False self.module.params = {'provider': None} self.mock_wapi = patch('ansible.modules.net_tools.nios.nios_a_record.WapiModule') self.exec_command = self.mock_wapi.start() self.mock_wapi_run = patch('ansible.modules.net_tools.nios.nios_a_record.WapiModule.run') self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() def tearDown(self): super(TestNiosARecordModule, self).tearDown() self.mock_wapi.stop() self.mock_wapi_run.stop() def _get_wapi(self, test_object): wapi = api.WapiModule(self.module) wapi.get_object = Mock(name='get_object', return_value=test_object) wapi.create_object = Mock(name='create_object') wapi.update_object = Mock(name='update_object') wapi.delete_object = Mock(name='delete_object') return wapi def load_fixtures(self, commands=None): self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) self.load_config.return_value = dict(diff=None, session='session') def test_nios_a_record_create(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'a.ansible.com', 'ipv4': '192.168.10.1', 'comment': None, 'extattrs': None} test_object = None test_spec = { "name": {"ib_req": True}, "ipv4": {"ib_req": True}, "comment": {}, "extattrs": {} } wapi = self._get_wapi(test_object) print("WAPI: ", wapi.__dict__) res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) wapi.create_object.assert_called_once_with('testobject', {'name': self.module._check_type_dict().__getitem__(), 'ipv4': '192.168.10.1'}) def test_nios_a_record_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'a.ansible.com', 'ipv4': '192.168.10.1', 'comment': 'updated comment', 'extattrs': None} test_object = [ { "comment": "test comment", "_ref": "arecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", "name": "a.ansible.com", "ipv4": "192.168.10.1", "extattrs": {} } ] test_spec = { "name": {"ib_req": True}, "ipv4": {"ib_req": True}, "comment": {}, "extattrs": {} } wapi = self._get_wapi(test_object) res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) def test_nios_a_record_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'a.ansible.com', 'ipv4': '192.168.10.1', 'comment': None, 'extattrs': None} ref = "arecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" test_object = [{ "comment": "test comment", "_ref": ref, "name": "a.ansible.com", "ipv4": "192.168.10.1", "extattrs": {'Site': {'value': 'test'}} }] test_spec = { "name": {"ib_req": True}, "ipv4": {"ib_req": True}, "comment": {}, "extattrs": {} } wapi = self._get_wapi(test_object) res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) wapi.delete_object.assert_called_once_with(ref) def test_nios_a_record_update_record_name(self): self.module.params = {'provider': None, 'state': 'present', 'name': {'new_name': 'a_new.ansible.com', 'old_name': 'a.ansible.com'}, 'comment': 'comment', 'extattrs': None} test_object = [ { "comment": "test comment", "_ref": "arecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", "name": "a_new.ansible.com", "old_name": "a.ansible.com", "extattrs": {} } ] test_spec = { "name": {"ib_req": True}, "comment": {}, "extattrs": {} } wapi = self._get_wapi(test_object) res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) wapi.update_object.called_once_with(test_object)
gpl-3.0
[ 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 3, 4155, 2803, 1655, 2366, 19, 13, 2453, 421, 199, 504, 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 9, 199, 363, 6577, 363, 275, 730, 421, 199, 504, 3242, 14, 3112, 14, 846, 63, 2537, 14, 8445, 736, 492, 302, 9207, 63, 65, 63, 3059, 199, 504, 3242, 14, 578, 63, 1208, 14, 846, 63, 2537, 14, 8445, 736, 492, 2986, 199, 504, 6204, 14, 5819, 14, 1805, 492, 3371, 12, 10079, 12, 4420, 199, 504, 1275, 396, 63, 8445, 736, 63, 578, 492, 1379, 46, 9207, 2377, 12, 2248, 63, 5997, 421, 199, 533, 1379, 46, 9207, 33, 5433, 2377, 8, 774, 46, 9207, 2377, 304, 339, 859, 275, 302, 9207, 63, 65, 63, 3059, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 774, 46, 9207, 33, 5433, 2377, 12, 291, 680, 5996, 342, 267, 291, 14, 578, 275, 10079, 8, 354, 534, 4853, 14, 3112, 14, 846, 63, 2537, 14, 8445, 736, 14, 8445, 736, 63, 65, 63, 3059, 14, 55, 1246, 2377, 358, 267, 291, 14, 578, 14, 1074, 63, 632, 275, 756, 267, 291, 14, 578, 14, 1162, 275, 791, 3780, 356, 488, 93, 267, 291, 14, 1805, 63, 87, 1246, 275, 3371, 360, 4853, 14, 3112, 14, 846, 63, 2537, 14, 8445, 736, 14, 8445, 736, 63, 65, 63, 3059, 14, 55, 1246, 2377, 358, 267, 291, 14, 1628, 63, 1531, 275, 291, 14, 1805, 63, 87, 1246, 14, 928, 342, 267, 291, 14, 1805, 63, 87, 1246, 63, 1065, 275, 3371, 360, 4853, 14, 3112, 14, 846, 63, 2537, 14, 8445, 736, 14, 8445, 736, 63, 65, 63, 3059, 14, 55, 1246, 2377, 14, 1065, 358, 267, 291, 14, 1805, 63, 87, 1246, 63, 1065, 14, 928, 342, 267, 291, 14, 912, 63, 888, 275, 291, 14, 1805, 63, 87, 1246, 63, 1065, 14, 928, 342, 339, 347, 6766, 8, 277, 304, 267, 1613, 8, 774, 46, 9207, 33, 5433, 2377, 12, 291, 680, 12336, 342, 267, 291, 14, 1805, 63, 87, 1246, 14, 2379, 342, 267, 291, 14, 1805, 63, 87, 1246, 63, 1065, 14, 2379, 342, 339, 347, 485, 362, 63, 87, 1246, 8, 277, 12, 511, 63, 785, 304, 267, 336, 1246, 275, 2986, 14, 55, 1246, 2377, 8, 277, 14, 578, 9, 267, 336, 1246, 14, 362, 63, 785, 275, 4420, 8, 354, 534, 362, 63, 785, 297, 372, 63, 585, 29, 396, 63, 785, 9, 267, 336, 1246, 14, 981, 63, 785, 275, 4420, 8, 354, 534, 981, 63, 785, 358, 267, 336, 1246, 14, 873, 63, 785, 275, 4420, 8, 354, 534, 873, 63, 785, 358, 267, 336, 1246, 14, 1807, 63, 785, 275, 4420, 8, 354, 534, 1807, 63, 785, 358, 267, 372, 336, 1246, 339, 347, 2248, 63, 8769, 8, 277, 12, 3718, 29, 403, 304, 267, 291, 14, 1628, 63, 1531, 14, 1107, 63, 585, 275, 334, 16, 12, 2248, 63, 5997, 360, 8445, 736, 63, 1099, 14, 2424, 1959, 1913, 1062, 488, 9, 267, 291, 14, 912, 63, 888, 14, 1107, 63, 585, 275, 1211, 8, 3028, 29, 403, 12, 2351, 534, 1730, 358, 339, 347, 511, 63, 8445, 736, 63, 65, 63, 3059, 63, 981, 8, 277, 304, 267, 291, 14, 578, 14, 1162, 275, 791, 3780, 356, 488, 12, 283, 929, 356, 283, 1881, 297, 283, 354, 356, 283, 65, 14, 4853, 14, 957, 297, 2892, 283, 4774, 20, 356, 283, 5756, 14, 6568, 14, 709, 14, 17, 297, 283, 3349, 356, 488, 12, 283, 832, 3288, 356, 488, 93, 398, 511, 63, 785, 275, 488, 398, 511, 63, 1650, 275, 469, 288, 298, 354, 582, 2420, 1892, 63, 2103, 582, 715, 1386, 288, 298, 4774, 20, 582, 2420, 1892, 63, 2103, 582, 715, 1386, 288, 298, 3349, 582, 5479, 288, 298, 832, 3288, 582, 1052, 267, 789, 398, 336, 1246, 275, 291, 423, 362, 63, 87, 1246, 8, 396, 63, 785, 9, 267, 870, 480, 55, 3735, 26, 3872, 336, 1246, 855, 807, 3368, 267, 522, 275, 336, 1246, 14, 1065, 360, 396, 785, 297, 511, 63, 1650, 9, 398, 291, 14, 1815, 8, 470, 459, 2489, 1105, 267, 336, 1246, 14, 981, 63, 785, 14, 479, 63, 3527, 63, 5089, 63, 1045, 360, 396, 785, 297, 791, 354, 356, 291, 14, 578, 423, 1074, 63, 466, 63, 807, 11027, 6095, 29709, 25404, 283, 4774, 20, 356, 283, 5756, 14, 6568, 14, 709, 14, 17, 3071, 339, 347, 511, 63, 8445, 736, 63, 65, 63, 3059, 63, 873, 63, 3349, 8, 277, 304, 267, 291, 14, 578, 14, 1162, 275, 791, 3780, 356, 488, 12, 283, 929, 356, 283, 1881, 297, 283, 354, 356, 283, 65, 14, 4853, 14, 957, 297, 283, 4774, 20, 356, 283, 5756, 14, 6568, 14, 709, 14, 17, 297, 2892, 283, 3349, 356, 283, 5334, 3721, 297, 283, 832, 3288, 356, 488, 93, 398, 511, 63, 785, 275, 359, 288, 469, 355, 298, 3349, 582, 298, 396, 3721, 401, 355, 2668, 1121, 582, 298, 1530, 1577, 15, 26074, 21, 90, 23041, 21, 1447, 40, 68, 6737, 2037, 2592, 757, 1447, 89, 49, 87, 26, 885, 15, 2052, 401, 355, 298, 354, 582, 298, 65, 14, 4853, 14, 957, 401, 355, 298, 4774, 20, 582, 298 ]
[ 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 3, 4155, 2803, 1655, 2366, 19, 13, 2453, 421, 199, 504, 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 9, 199, 363, 6577, 363, 275, 730, 421, 199, 504, 3242, 14, 3112, 14, 846, 63, 2537, 14, 8445, 736, 492, 302, 9207, 63, 65, 63, 3059, 199, 504, 3242, 14, 578, 63, 1208, 14, 846, 63, 2537, 14, 8445, 736, 492, 2986, 199, 504, 6204, 14, 5819, 14, 1805, 492, 3371, 12, 10079, 12, 4420, 199, 504, 1275, 396, 63, 8445, 736, 63, 578, 492, 1379, 46, 9207, 2377, 12, 2248, 63, 5997, 421, 199, 533, 1379, 46, 9207, 33, 5433, 2377, 8, 774, 46, 9207, 2377, 304, 339, 859, 275, 302, 9207, 63, 65, 63, 3059, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 774, 46, 9207, 33, 5433, 2377, 12, 291, 680, 5996, 342, 267, 291, 14, 578, 275, 10079, 8, 354, 534, 4853, 14, 3112, 14, 846, 63, 2537, 14, 8445, 736, 14, 8445, 736, 63, 65, 63, 3059, 14, 55, 1246, 2377, 358, 267, 291, 14, 578, 14, 1074, 63, 632, 275, 756, 267, 291, 14, 578, 14, 1162, 275, 791, 3780, 356, 488, 93, 267, 291, 14, 1805, 63, 87, 1246, 275, 3371, 360, 4853, 14, 3112, 14, 846, 63, 2537, 14, 8445, 736, 14, 8445, 736, 63, 65, 63, 3059, 14, 55, 1246, 2377, 358, 267, 291, 14, 1628, 63, 1531, 275, 291, 14, 1805, 63, 87, 1246, 14, 928, 342, 267, 291, 14, 1805, 63, 87, 1246, 63, 1065, 275, 3371, 360, 4853, 14, 3112, 14, 846, 63, 2537, 14, 8445, 736, 14, 8445, 736, 63, 65, 63, 3059, 14, 55, 1246, 2377, 14, 1065, 358, 267, 291, 14, 1805, 63, 87, 1246, 63, 1065, 14, 928, 342, 267, 291, 14, 912, 63, 888, 275, 291, 14, 1805, 63, 87, 1246, 63, 1065, 14, 928, 342, 339, 347, 6766, 8, 277, 304, 267, 1613, 8, 774, 46, 9207, 33, 5433, 2377, 12, 291, 680, 12336, 342, 267, 291, 14, 1805, 63, 87, 1246, 14, 2379, 342, 267, 291, 14, 1805, 63, 87, 1246, 63, 1065, 14, 2379, 342, 339, 347, 485, 362, 63, 87, 1246, 8, 277, 12, 511, 63, 785, 304, 267, 336, 1246, 275, 2986, 14, 55, 1246, 2377, 8, 277, 14, 578, 9, 267, 336, 1246, 14, 362, 63, 785, 275, 4420, 8, 354, 534, 362, 63, 785, 297, 372, 63, 585, 29, 396, 63, 785, 9, 267, 336, 1246, 14, 981, 63, 785, 275, 4420, 8, 354, 534, 981, 63, 785, 358, 267, 336, 1246, 14, 873, 63, 785, 275, 4420, 8, 354, 534, 873, 63, 785, 358, 267, 336, 1246, 14, 1807, 63, 785, 275, 4420, 8, 354, 534, 1807, 63, 785, 358, 267, 372, 336, 1246, 339, 347, 2248, 63, 8769, 8, 277, 12, 3718, 29, 403, 304, 267, 291, 14, 1628, 63, 1531, 14, 1107, 63, 585, 275, 334, 16, 12, 2248, 63, 5997, 360, 8445, 736, 63, 1099, 14, 2424, 1959, 1913, 1062, 488, 9, 267, 291, 14, 912, 63, 888, 14, 1107, 63, 585, 275, 1211, 8, 3028, 29, 403, 12, 2351, 534, 1730, 358, 339, 347, 511, 63, 8445, 736, 63, 65, 63, 3059, 63, 981, 8, 277, 304, 267, 291, 14, 578, 14, 1162, 275, 791, 3780, 356, 488, 12, 283, 929, 356, 283, 1881, 297, 283, 354, 356, 283, 65, 14, 4853, 14, 957, 297, 2892, 283, 4774, 20, 356, 283, 5756, 14, 6568, 14, 709, 14, 17, 297, 283, 3349, 356, 488, 12, 283, 832, 3288, 356, 488, 93, 398, 511, 63, 785, 275, 488, 398, 511, 63, 1650, 275, 469, 288, 298, 354, 582, 2420, 1892, 63, 2103, 582, 715, 1386, 288, 298, 4774, 20, 582, 2420, 1892, 63, 2103, 582, 715, 1386, 288, 298, 3349, 582, 5479, 288, 298, 832, 3288, 582, 1052, 267, 789, 398, 336, 1246, 275, 291, 423, 362, 63, 87, 1246, 8, 396, 63, 785, 9, 267, 870, 480, 55, 3735, 26, 3872, 336, 1246, 855, 807, 3368, 267, 522, 275, 336, 1246, 14, 1065, 360, 396, 785, 297, 511, 63, 1650, 9, 398, 291, 14, 1815, 8, 470, 459, 2489, 1105, 267, 336, 1246, 14, 981, 63, 785, 14, 479, 63, 3527, 63, 5089, 63, 1045, 360, 396, 785, 297, 791, 354, 356, 291, 14, 578, 423, 1074, 63, 466, 63, 807, 11027, 6095, 29709, 25404, 283, 4774, 20, 356, 283, 5756, 14, 6568, 14, 709, 14, 17, 3071, 339, 347, 511, 63, 8445, 736, 63, 65, 63, 3059, 63, 873, 63, 3349, 8, 277, 304, 267, 291, 14, 578, 14, 1162, 275, 791, 3780, 356, 488, 12, 283, 929, 356, 283, 1881, 297, 283, 354, 356, 283, 65, 14, 4853, 14, 957, 297, 283, 4774, 20, 356, 283, 5756, 14, 6568, 14, 709, 14, 17, 297, 2892, 283, 3349, 356, 283, 5334, 3721, 297, 283, 832, 3288, 356, 488, 93, 398, 511, 63, 785, 275, 359, 288, 469, 355, 298, 3349, 582, 298, 396, 3721, 401, 355, 2668, 1121, 582, 298, 1530, 1577, 15, 26074, 21, 90, 23041, 21, 1447, 40, 68, 6737, 2037, 2592, 757, 1447, 89, 49, 87, 26, 885, 15, 2052, 401, 355, 298, 354, 582, 298, 65, 14, 4853, 14, 957, 401, 355, 298, 4774, 20, 582, 298, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
cmotc/schs738c-external_chromium
testing/gmock/test/gmock_test_utils.py
222
3579
#!/usr/bin/env python # # Copyright 2006, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following disclaimer # in the documentation and/or other materials provided with the # distribution. # * Neither the name of Google Inc. nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """Unit test utilities for Google C++ Mocking Framework.""" __author__ = 'wan@google.com (Zhanyong Wan)' import os import sys # Determines path to gtest_test_utils and imports it. SCRIPT_DIR = os.path.dirname(__file__) or '.' # isdir resolves symbolic links. gtest_tests_util_dir = os.path.join(SCRIPT_DIR, '../gtest/test') if os.path.isdir(gtest_tests_util_dir): GTEST_TESTS_UTIL_DIR = gtest_tests_util_dir else: GTEST_TESTS_UTIL_DIR = os.path.join(SCRIPT_DIR, '../../gtest/test') sys.path.append(GTEST_TESTS_UTIL_DIR) import gtest_test_utils # pylint: disable-msg=C6204 def GetSourceDir(): """Returns the absolute path of the directory where the .py files are.""" return gtest_test_utils.GetSourceDir() def GetTestExecutablePath(executable_name): """Returns the absolute path of the test binary given its name. The function will print a message and abort the program if the resulting file doesn't exist. Args: executable_name: name of the test binary that the test script runs. Returns: The absolute path of the test binary. """ return gtest_test_utils.GetTestExecutablePath(executable_name) def GetExitStatus(exit_code): """Returns the argument to exit(), or -1 if exit() wasn't called. Args: exit_code: the result value of os.system(command). """ if os.name == 'nt': # On Windows, os.WEXITSTATUS() doesn't work and os.system() returns # the argument to exit() directly. return exit_code else: # On Unix, os.WEXITSTATUS() must be used to extract the exit status # from the result of os.system(). if os.WIFEXITED(exit_code): return os.WEXITSTATUS(exit_code) else: return -1 # Suppresses the "Invalid const name" lint complaint # pylint: disable-msg=C6409 # Exposes Subprocess from gtest_test_utils. Subprocess = gtest_test_utils.Subprocess # Exposes TestCase from gtest_test_utils. TestCase = gtest_test_utils.TestCase # pylint: enable-msg=C6409 def Main(): """Runs the unit test.""" gtest_test_utils.Main()
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 8315, 12, 4475, 3277, 14, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 258, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 258, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 199, 3, 4248, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 199, 3, 315, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 4084, 14, 199, 3, 258, 627, 11443, 314, 536, 402, 4475, 3277, 14, 6590, 314, 1561, 402, 2399, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 199, 3, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 199, 3, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 199, 3, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 199, 3, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 199, 3, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 624, 5072, 511, 15841, 367, 4475, 445, 4176, 4420, 316, 22545, 1041, 199, 199, 363, 2502, 363, 275, 283, 20444, 32, 3098, 14, 957, 334, 12674, 1629, 951, 644, 290, 3171, 199, 199, 646, 747, 199, 646, 984, 421, 199, 3, 22391, 931, 370, 9088, 63, 396, 63, 1208, 436, 8925, 652, 14, 199, 10484, 63, 3022, 275, 747, 14, 515, 14, 3475, 3460, 493, 3368, 503, 7815, 199, 199, 3, 26004, 32253, 13673, 6220, 14, 199, 8385, 63, 2219, 63, 1974, 63, 694, 275, 747, 14, 515, 14, 904, 8, 10484, 63, 3022, 12, 20644, 8385, 15, 396, 358, 199, 692, 747, 14, 515, 14, 6027, 8, 8385, 63, 2219, 63, 1974, 63, 694, 304, 523, 18652, 63, 7569, 63, 29076, 63, 3022, 275, 9088, 63, 2219, 63, 1974, 63, 694, 199, 2836, 26, 523, 18652, 63, 7569, 63, 29076, 63, 3022, 275, 747, 14, 515, 14, 904, 8, 10484, 63, 3022, 12, 283, 9707, 8385, 15, 396, 358, 199, 199, 1274, 14, 515, 14, 740, 8, 16151, 63, 7569, 63, 29076, 63, 3022, 9, 199, 646, 9088, 63, 396, 63, 1208, 221, 327, 4287, 26, 3507, 13, 1328, 29, 35, 2789, 966, 421, 199, 318, 2372, 2980, 3567, 837, 523, 408, 3407, 314, 3679, 931, 402, 314, 2082, 2382, 314, 1275, 647, 1584, 787, 1041, 819, 372, 9088, 63, 396, 63, 1208, 14, 1002, 2980, 3567, 342, 421, 199, 318, 2372, 774, 27602, 8, 5904, 63, 354, 304, 523, 408, 3407, 314, 3679, 931, 402, 314, 511, 3366, 1627, 2399, 536, 14, 819, 710, 805, 911, 870, 282, 1245, 436, 12004, 314, 2240, 340, 314, 9183, 570, 523, 3181, 1133, 2187, 14, 819, 3033, 26, 272, 7286, 63, 354, 26, 536, 402, 314, 511, 3366, 626, 314, 511, 2884, 7858, 14, 819, 1803, 26, 272, 710, 3679, 931, 402, 314, 511, 3366, 14, 523, 408, 819, 372, 9088, 63, 396, 63, 1208, 14, 28967, 27602, 8, 5904, 63, 354, 9, 421, 199, 318, 2372, 6699, 3694, 8, 2224, 63, 600, 304, 523, 408, 3407, 314, 1423, 370, 4458, 1062, 503, 446, 17, 340, 4458, 342, 17373, 1133, 2797, 14, 819, 3033, 26, 272, 4458, 63, 600, 26, 314, 754, 574, 402, 747, 14, 2253, 8, 1531, 680, 523, 408, 819, 340, 747, 14, 354, 508, 283, 343, 356, 272, 327, 4068, 5417, 12, 747, 14, 55, 17219, 6305, 342, 3181, 1133, 1736, 436, 747, 14, 2253, 342, 2529, 272, 327, 314, 1423, 370, 4458, 342, 5370, 14, 272, 372, 4458, 63, 600, 523, 587, 26, 272, 327, 4068, 13074, 12, 747, 14, 55, 17219, 6305, 342, 1471, 506, 1202, 370, 5536, 314, 4458, 2004, 272, 327, 687, 314, 754, 402, 747, 14, 2253, 1252, 272, 340, 747, 14, 55, 4656, 17219, 1149, 8, 2224, 63, 600, 304, 489, 372, 747, 14, 55, 17219, 6305, 8, 2224, 63, 600, 9, 272, 587, 26, 489, 372, 446, 17, 421, 199, 3, 29083, 4357, 314, 298, 3364, 950, 536, 2, 24620, 32493, 442, 199, 3, 4287, 26, 3507, 13, 1328, 29, 35, 772, 1643, 199, 199, 3, 1316, 10553, 4804, 1412, 687, 9088, 63, 396, 63, 1208, 14, 199, 22299, 275, 9088, 63, 396, 63, 1208, 14, 22299, 199, 199, 3, 1316, 10553, 7640, 687, 9088, 63, 396, 63, 1208, 14, 199, 1746, 275, 9088, 63, 396, 63, 1208, 14, 1746, 199, 199, 3, 4287, 26, 4756, 13, 1328, 29, 35, 772, 1643, 421, 199, 318, 11298, 837, 523, 408, 16291, 314, 4137, 511, 1041, 819, 9088, 63, 396, 63, 1208, 14, 6756, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 8315, 12, 4475, 3277, 14, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 258, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 258, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 199, 3, 4248, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 199, 3, 315, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 4084, 14, 199, 3, 258, 627, 11443, 314, 536, 402, 4475, 3277, 14, 6590, 314, 1561, 402, 2399, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 199, 3, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 199, 3, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 199, 3, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 199, 3, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 199, 3, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 624, 5072, 511, 15841, 367, 4475, 445, 4176, 4420, 316, 22545, 1041, 199, 199, 363, 2502, 363, 275, 283, 20444, 32, 3098, 14, 957, 334, 12674, 1629, 951, 644, 290, 3171, 199, 199, 646, 747, 199, 646, 984, 421, 199, 3, 22391, 931, 370, 9088, 63, 396, 63, 1208, 436, 8925, 652, 14, 199, 10484, 63, 3022, 275, 747, 14, 515, 14, 3475, 3460, 493, 3368, 503, 7815, 199, 199, 3, 26004, 32253, 13673, 6220, 14, 199, 8385, 63, 2219, 63, 1974, 63, 694, 275, 747, 14, 515, 14, 904, 8, 10484, 63, 3022, 12, 20644, 8385, 15, 396, 358, 199, 692, 747, 14, 515, 14, 6027, 8, 8385, 63, 2219, 63, 1974, 63, 694, 304, 523, 18652, 63, 7569, 63, 29076, 63, 3022, 275, 9088, 63, 2219, 63, 1974, 63, 694, 199, 2836, 26, 523, 18652, 63, 7569, 63, 29076, 63, 3022, 275, 747, 14, 515, 14, 904, 8, 10484, 63, 3022, 12, 283, 9707, 8385, 15, 396, 358, 199, 199, 1274, 14, 515, 14, 740, 8, 16151, 63, 7569, 63, 29076, 63, 3022, 9, 199, 646, 9088, 63, 396, 63, 1208, 221, 327, 4287, 26, 3507, 13, 1328, 29, 35, 2789, 966, 421, 199, 318, 2372, 2980, 3567, 837, 523, 408, 3407, 314, 3679, 931, 402, 314, 2082, 2382, 314, 1275, 647, 1584, 787, 1041, 819, 372, 9088, 63, 396, 63, 1208, 14, 1002, 2980, 3567, 342, 421, 199, 318, 2372, 774, 27602, 8, 5904, 63, 354, 304, 523, 408, 3407, 314, 3679, 931, 402, 314, 511, 3366, 1627, 2399, 536, 14, 819, 710, 805, 911, 870, 282, 1245, 436, 12004, 314, 2240, 340, 314, 9183, 570, 523, 3181, 1133, 2187, 14, 819, 3033, 26, 272, 7286, 63, 354, 26, 536, 402, 314, 511, 3366, 626, 314, 511, 2884, 7858, 14, 819, 1803, 26, 272, 710, 3679, 931, 402, 314, 511, 3366, 14, 523, 408, 819, 372, 9088, 63, 396, 63, 1208, 14, 28967, 27602, 8, 5904, 63, 354, 9, 421, 199, 318, 2372, 6699, 3694, 8, 2224, 63, 600, 304, 523, 408, 3407, 314, 1423, 370, 4458, 1062, 503, 446, 17, 340, 4458, 342, 17373, 1133, 2797, 14, 819, 3033, 26, 272, 4458, 63, 600, 26, 314, 754, 574, 402, 747, 14, 2253, 8, 1531, 680, 523, 408, 819, 340, 747, 14, 354, 508, 283, 343, 356, 272, 327, 4068, 5417, 12, 747, 14, 55, 17219, 6305, 342, 3181, 1133, 1736, 436, 747, 14, 2253, 342, 2529, 272, 327, 314, 1423, 370, 4458, 342, 5370, 14, 272, 372, 4458, 63, 600, 523, 587, 26, 272, 327, 4068, 13074, 12, 747, 14, 55, 17219, 6305, 342, 1471, 506, 1202, 370, 5536, 314, 4458, 2004, 272, 327, 687, 314, 754, 402, 747, 14, 2253, 1252, 272, 340, 747, 14, 55, 4656, 17219, 1149, 8, 2224, 63, 600, 304, 489, 372, 747, 14, 55, 17219, 6305, 8, 2224, 63, 600, 9, 272, 587, 26, 489, 372, 446, 17, 421, 199, 3, 29083, 4357, 314, 298, 3364, 950, 536, 2, 24620, 32493, 442, 199, 3, 4287, 26, 3507, 13, 1328, 29, 35, 772, 1643, 199, 199, 3, 1316, 10553, 4804, 1412, 687, 9088, 63, 396, 63, 1208, 14, 199, 22299, 275, 9088, 63, 396, 63, 1208, 14, 22299, 199, 199, 3, 1316, 10553, 7640, 687, 9088, 63, 396, 63, 1208, 14, 199, 1746, 275, 9088, 63, 396, 63, 1208, 14, 1746, 199, 199, 3, 4287, 26, 4756, 13, 1328, 29, 35, 772, 1643, 421, 199, 318, 11298, 837, 523, 408, 16291, 314, 4137, 511, 1041, 819, 9088, 63, 396, 63, 1208, 14, 6756, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,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, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Alberto-Beralix/Beralix
i386-squashfs-root/usr/share/system-config-printer/errordialogs.py
1
3111
#!/usr/bin/python ## system-config-printer ## Copyright (C) 2006, 2007, 2008, 2010 Red Hat, Inc. ## Authors: ## Florian Festi <ffesti@redhat.com> ## Tim Waugh <twaugh@redhat.com> ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import cups import gtk from gettext import gettext as _ def show_dialog (title, text, type, parent=None): dialog = gtk.MessageDialog (parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, type, gtk.BUTTONS_OK, title) dialog.format_secondary_text (text) dialog.run () dialog.destroy () def show_info_dialog (title, text, parent=None): return show_dialog (title, text, gtk.MESSAGE_INFO, parent=parent) def show_error_dialog (title, text, parent=None): return show_dialog (title, text, gtk.MESSAGE_ERROR, parent=parent) def show_IPP_Error(exception, message, parent=None): if exception == 0: # In this case, the user has canceled an authentication dialog. return elif exception == cups.IPP_SERVICE_UNAVAILABLE: # In this case, the user has canceled a retry dialog. return else: title = _("CUPS server error") text = (_("There was an error during the CUPS " "operation: '%s'.")) % message show_error_dialog (title, text, parent) def show_HTTP_Error(status, parent=None): if (status == cups.HTTP_UNAUTHORIZED or status == cups.HTTP_FORBIDDEN): title = _('Not authorized') text = (_('The password may be incorrect, or the ' 'server may be configured to deny ' 'remote administration.')) else: title = _('CUPS server error') if status == cups.HTTP_BAD_REQUEST: msg = _("Bad request") elif status == cups.HTTP_NOT_FOUND: msg = _("Not found") elif status == cups.HTTP_REQUEST_TIMEOUT: msg = _("Request timeout") elif status == cups.HTTP_UPGRADE_REQUIRED: msg = _("Upgrade required") elif status == cups.HTTP_SERVER_ERROR: msg = _("Server error") elif status == -1: msg = _("Not connected") else: msg = _("status %s") % status text = _("There was an HTTP error: %s.") % msg show_error_dialog (title, text, parent)
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 199, 309, 2656, 13, 888, 13, 11835, 199, 199, 309, 1898, 334, 35, 9, 8315, 12, 10219, 12, 9079, 12, 7129, 9572, 13002, 12, 3277, 14, 199, 309, 6642, 26, 199, 309, 221, 11040, 269, 5653, 481, 597, 73, 665, 556, 597, 73, 32, 17164, 14, 957, 30, 199, 309, 221, 26244, 644, 65, 3080, 665, 84, 758, 3080, 32, 17164, 14, 957, 30, 199, 199, 309, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 309, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 309, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 199, 309, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 199, 309, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 309, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 309, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 309, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 199, 309, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 309, 3180, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 309, 2752, 12, 3277, 2020, 8026, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 4828, 221, 11315, 13, 10067, 12, 8217, 14, 199, 199, 646, 286, 15203, 199, 646, 8116, 199, 504, 9796, 492, 9796, 465, 485, 199, 199, 318, 2498, 63, 7196, 334, 1213, 12, 1318, 12, 730, 12, 1676, 29, 403, 304, 272, 9592, 275, 8116, 14, 2209, 5619, 334, 1708, 12, 1816, 8116, 14, 1914, 23622, 63, 8816, 748, 1204, 1816, 8116, 14, 1914, 23622, 63, 19374, 1092, 57, 63, 9139, 63, 20562, 12, 1816, 730, 12, 1816, 8116, 14, 13272, 51, 63, 3593, 12, 1816, 2538, 9, 272, 9592, 14, 908, 63, 12371, 63, 505, 334, 505, 9, 272, 9592, 14, 1065, 6248, 272, 9592, 14, 7237, 6248, 199, 199, 318, 2498, 63, 815, 63, 7196, 334, 1213, 12, 1318, 12, 1676, 29, 403, 304, 272, 372, 2498, 63, 7196, 334, 1213, 12, 1318, 12, 8116, 14, 8272, 63, 4531, 12, 1676, 29, 1708, 9, 199, 199, 318, 2498, 63, 705, 63, 7196, 334, 1213, 12, 1318, 12, 1676, 29, 403, 304, 272, 372, 2498, 63, 7196, 334, 1213, 12, 1318, 12, 8116, 14, 8272, 63, 3170, 12, 1676, 29, 1708, 9, 199, 199, 318, 2498, 63, 1772, 48, 63, 547, 8, 1971, 12, 1245, 12, 1676, 29, 403, 304, 272, 340, 1919, 508, 378, 26, 267, 327, 1010, 642, 1930, 12, 314, 922, 965, 286, 18959, 376, 6299, 9592, 14, 267, 372, 272, 916, 1919, 508, 286, 15203, 14, 1772, 48, 63, 10486, 63, 1734, 17377, 26, 267, 327, 1010, 642, 1930, 12, 314, 922, 965, 286, 18959, 282, 7269, 9592, 14, 267, 372, 272, 587, 26, 267, 2538, 275, 3824, 35, 2160, 51, 1654, 1125, 531, 267, 1318, 275, 26542, 10924, 1990, 376, 1125, 5309, 314, 445, 2160, 51, 298, 2116, 298, 5735, 26, 1543, 83, 1370, 2237, 450, 1245, 339, 2498, 63, 705, 63, 7196, 334, 1213, 12, 1318, 12, 1676, 9, 199, 199, 318, 2498, 63, 2856, 63, 547, 8, 1205, 12, 1676, 29, 403, 304, 272, 340, 334, 1205, 508, 286, 15203, 14, 2856, 63, 1734, 25303, 1149, 503, 267, 2004, 508, 286, 15203, 14, 2856, 63, 2707, 34, 22436, 304, 267, 2538, 275, 4018, 1763, 18788, 358, 267, 1318, 275, 21790, 1918, 2505, 1443, 506, 8927, 12, 503, 314, 283, 2116, 283, 1000, 1443, 506, 7526, 370, 5376, 89, 283, 2116, 283, 3846, 4628, 4633, 12459, 272, 587, 26, 267, 2538, 275, 4018, 35, 2160, 51, 1654, 1125, 358, 267, 340, 2004, 508, 286, 15203, 14, 2856, 63, 9439, 63, 6780, 26, 288, 1499, 275, 3824, 5725, 1056, 531, 267, 916, 2004, 508, 286, 15203, 14, 2856, 63, 4609, 63, 13945, 26, 288, 1499, 275, 3824, 1763, 1911, 531, 267, 916, 2004, 508, 286, 15203, 14, 2856, 63, 6780, 63, 8899, 26, 288, 1499, 275, 3824, 2017, 2653, 531, 267, 916, 2004, 508, 286, 15203, 14, 2856, 63, 2160, 28594, 63, 12496, 26, 288, 1499, 275, 3824, 19217, 1415, 531, 267, 916, 2004, 508, 286, 15203, 14, 2856, 63, 6613, 63, 3170, 26, 288, 1499, 275, 3824, 3120, 1125, 531, 267, 916, 2004, 508, 446, 17, 26, 288, 1499, 275, 3824, 1763, 8539, 531, 267, 587, 26, 288, 1499, 275, 3824, 1205, 450, 83, 531, 450, 2004, 398, 1318, 275, 3824, 10924, 1990, 376, 3101, 1125, 26, 450, 83, 2685, 450, 1499, 339, 2498, 63, 705, 63, 7196, 334, 1213, 12, 1318, 12, 1676, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1548, 199, 199, 309, 2656, 13, 888, 13, 11835, 199, 199, 309, 1898, 334, 35, 9, 8315, 12, 10219, 12, 9079, 12, 7129, 9572, 13002, 12, 3277, 14, 199, 309, 6642, 26, 199, 309, 221, 11040, 269, 5653, 481, 597, 73, 665, 556, 597, 73, 32, 17164, 14, 957, 30, 199, 309, 221, 26244, 644, 65, 3080, 665, 84, 758, 3080, 32, 17164, 14, 957, 30, 199, 199, 309, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 309, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 309, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 199, 309, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 199, 309, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 309, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 309, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 309, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 199, 309, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 309, 3180, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 309, 2752, 12, 3277, 2020, 8026, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 4828, 221, 11315, 13, 10067, 12, 8217, 14, 199, 199, 646, 286, 15203, 199, 646, 8116, 199, 504, 9796, 492, 9796, 465, 485, 199, 199, 318, 2498, 63, 7196, 334, 1213, 12, 1318, 12, 730, 12, 1676, 29, 403, 304, 272, 9592, 275, 8116, 14, 2209, 5619, 334, 1708, 12, 1816, 8116, 14, 1914, 23622, 63, 8816, 748, 1204, 1816, 8116, 14, 1914, 23622, 63, 19374, 1092, 57, 63, 9139, 63, 20562, 12, 1816, 730, 12, 1816, 8116, 14, 13272, 51, 63, 3593, 12, 1816, 2538, 9, 272, 9592, 14, 908, 63, 12371, 63, 505, 334, 505, 9, 272, 9592, 14, 1065, 6248, 272, 9592, 14, 7237, 6248, 199, 199, 318, 2498, 63, 815, 63, 7196, 334, 1213, 12, 1318, 12, 1676, 29, 403, 304, 272, 372, 2498, 63, 7196, 334, 1213, 12, 1318, 12, 8116, 14, 8272, 63, 4531, 12, 1676, 29, 1708, 9, 199, 199, 318, 2498, 63, 705, 63, 7196, 334, 1213, 12, 1318, 12, 1676, 29, 403, 304, 272, 372, 2498, 63, 7196, 334, 1213, 12, 1318, 12, 8116, 14, 8272, 63, 3170, 12, 1676, 29, 1708, 9, 199, 199, 318, 2498, 63, 1772, 48, 63, 547, 8, 1971, 12, 1245, 12, 1676, 29, 403, 304, 272, 340, 1919, 508, 378, 26, 267, 327, 1010, 642, 1930, 12, 314, 922, 965, 286, 18959, 376, 6299, 9592, 14, 267, 372, 272, 916, 1919, 508, 286, 15203, 14, 1772, 48, 63, 10486, 63, 1734, 17377, 26, 267, 327, 1010, 642, 1930, 12, 314, 922, 965, 286, 18959, 282, 7269, 9592, 14, 267, 372, 272, 587, 26, 267, 2538, 275, 3824, 35, 2160, 51, 1654, 1125, 531, 267, 1318, 275, 26542, 10924, 1990, 376, 1125, 5309, 314, 445, 2160, 51, 298, 2116, 298, 5735, 26, 1543, 83, 1370, 2237, 450, 1245, 339, 2498, 63, 705, 63, 7196, 334, 1213, 12, 1318, 12, 1676, 9, 199, 199, 318, 2498, 63, 2856, 63, 547, 8, 1205, 12, 1676, 29, 403, 304, 272, 340, 334, 1205, 508, 286, 15203, 14, 2856, 63, 1734, 25303, 1149, 503, 267, 2004, 508, 286, 15203, 14, 2856, 63, 2707, 34, 22436, 304, 267, 2538, 275, 4018, 1763, 18788, 358, 267, 1318, 275, 21790, 1918, 2505, 1443, 506, 8927, 12, 503, 314, 283, 2116, 283, 1000, 1443, 506, 7526, 370, 5376, 89, 283, 2116, 283, 3846, 4628, 4633, 12459, 272, 587, 26, 267, 2538, 275, 4018, 35, 2160, 51, 1654, 1125, 358, 267, 340, 2004, 508, 286, 15203, 14, 2856, 63, 9439, 63, 6780, 26, 288, 1499, 275, 3824, 5725, 1056, 531, 267, 916, 2004, 508, 286, 15203, 14, 2856, 63, 4609, 63, 13945, 26, 288, 1499, 275, 3824, 1763, 1911, 531, 267, 916, 2004, 508, 286, 15203, 14, 2856, 63, 6780, 63, 8899, 26, 288, 1499, 275, 3824, 2017, 2653, 531, 267, 916, 2004, 508, 286, 15203, 14, 2856, 63, 2160, 28594, 63, 12496, 26, 288, 1499, 275, 3824, 19217, 1415, 531, 267, 916, 2004, 508, 286, 15203, 14, 2856, 63, 6613, 63, 3170, 26, 288, 1499, 275, 3824, 3120, 1125, 531, 267, 916, 2004, 508, 446, 17, 26, 288, 1499, 275, 3824, 1763, 8539, 531, 267, 587, 26, 288, 1499, 275, 3824, 1205, 450, 83, 531, 450, 2004, 398, 1318, 275, 3824, 10924, 1990, 376, 3101, 1125, 26, 450, 83, 2685, 450, 1499, 339, 2498, 63, 705, 63, 7196, 334, 1213, 12, 1318, 12, 1676, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
chouseknecht/ansible
lib/ansible/module_utils/network/ios/config/lldp_global/lldp_global.py
19
8572
# # -*- coding: utf-8 -*- # Copyright 2019 Red Hat Inc. # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) """ The ios_lldp_global class It is in this file where the current configuration (as dict) is compared to the provided configuration (as dict) and the command set necessary to bring the current configuration to its desired end-state is created """ from __future__ import absolute_import, division, print_function __metaclass__ = type from ansible.module_utils.six import iteritems from ansible.module_utils.network.common.cfg.base import ConfigBase from ansible.module_utils.network.common.utils import to_list from ansible.module_utils.network.ios.facts.facts import Facts from ansible.module_utils.network.ios.utils.utils import dict_to_set from ansible.module_utils.network.ios.utils.utils import filter_dict_having_none_value class Lldp_global(ConfigBase): """ The ios_lldp_global class """ gather_subset = [ '!all', '!min', ] gather_network_resources = [ 'lldp_global', ] tlv_select_params = {'four_wire_power_management': '4-wire-power-management', 'mac_phy_cfg': 'mac-phy-cfg', 'management_address': 'management-address', 'port_description': 'port-description', 'port_vlan': 'port-vlan', 'power_management': 'power-management', 'system_capabilities': 'system-capabilities', 'system_description': 'system-description', 'system_name': 'system-name'} def __init__(self, module): super(Lldp_global, self).__init__(module) def get_lldp_global_facts(self): """ Get the 'facts' (the current configuration) :rtype: A dictionary :returns: The current configuration as a dictionary """ facts, _warnings = Facts(self._module).get_facts(self.gather_subset, self.gather_network_resources) lldp_global_facts = facts['ansible_network_resources'].get('lldp_global') if not lldp_global_facts: return {} return lldp_global_facts def execute_module(self): """ Execute the module :rtype: A dictionary :returns: The result from moduel execution """ result = {'changed': False} commands = list() warnings = list() existing_lldp_global_facts = self.get_lldp_global_facts() commands.extend(self.set_config(existing_lldp_global_facts)) if commands: if not self._module.check_mode: self._connection.edit_config(commands) result['changed'] = True result['commands'] = commands changed_lldp_global_facts = self.get_lldp_global_facts() result['before'] = existing_lldp_global_facts if result['changed']: result['after'] = changed_lldp_global_facts result['warnings'] = warnings return result def set_config(self, existing_lldp_global_facts): """ Collect the configuration from the args passed to the module, collect the current configuration (as a dict from facts) :rtype: A list :returns: the commands necessary to migrate the current configuration to the deisred configuration """ want = self._module.params['config'] have = existing_lldp_global_facts resp = self.set_state(want, have) return to_list(resp) def set_state(self, want, have): """ Select the appropriate function based on the state provided :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :rtype: A list :returns: the commands necessary to migrate the current configuration to the deisred configuration """ commands = [] state = self._module.params['state'] if state in ('merged', 'replaced') and not want: self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(state)) if state == 'overridden': commands = self._state_overridden(want, have) elif state == 'deleted': commands = self._state_deleted(want, have) elif state == 'merged': commands = self._state_merged(want, have) elif state == 'replaced': commands = self._state_replaced(want, have) return commands def _state_replaced(self, want, have): """ The command generator when state is replaced :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :param interface_type: interface type :rtype: A list :returns: the commands necessary to migrate the current configuration to the deisred configuration """ commands = [] have_dict = filter_dict_having_none_value(want, have) commands.extend(self._clear_config(have_dict)) commands.extend(self._set_config(want, have)) return commands def _state_merged(self, want, have): """ The command generator when state is merged :param want: the additive configuration as a dictionary :param obj_in_have: the current configuration as a dictionary :rtype: A list :returns: the commands necessary to merge the provided into the current configuration """ commands = [] commands.extend(self._set_config(want, have)) return commands def _state_deleted(self, want, have): """ The command generator when state is deleted :param want: the objects from which the configuration should be removed :param obj_in_have: the current configuration as a dictionary :param interface_type: interface type :rtype: A list :returns: the commands necessary to remove the current configuration of the provided objects """ commands = [] commands.extend(self._clear_config(have)) return commands def _remove_command_from_config_list(self, cmd, commands): if cmd not in commands: commands.append('no %s' % cmd) def add_command_to_config_list(self, cmd, commands): if cmd not in commands: commands.append(cmd) def _set_config(self, want, have): # Set the interface config based on the want and have config commands = [] # Get the diff b/w want and have want_dict = dict_to_set(want) have_dict = dict_to_set(have) diff = want_dict - have_dict if diff: diff = dict(diff) holdtime = diff.get('holdtime') enabled = diff.get('enabled') timer = diff.get('timer') reinit = diff.get('reinit') tlv_select = diff.get('tlv_select') if holdtime: cmd = 'lldp holdtime {0}'.format(holdtime) self.add_command_to_config_list(cmd, commands) if enabled: cmd = 'lldp run' self.add_command_to_config_list(cmd, commands) if timer: cmd = 'lldp timer {0}'.format(timer) self.add_command_to_config_list(cmd, commands) if reinit: cmd = 'lldp reinit {0}'.format(reinit) self.add_command_to_config_list(cmd, commands) if tlv_select: tlv_selec_dict = dict(tlv_select) for k, v in iteritems(self.tlv_select_params): if k in tlv_selec_dict and tlv_selec_dict[k]: cmd = 'lldp tlv-select {0}'.format(v) self.add_command_to_config_list(cmd, commands) return commands def _clear_config(self, have): # Delete the interface config based on the want and have config commands = [] if have.get('holdtime'): cmd = 'lldp holdtime' self._remove_command_from_config_list(cmd, commands) if have.get('enabled'): cmd = 'lldp run' self._remove_command_from_config_list(cmd, commands) if have.get('timer'): cmd = 'lldp timer' self._remove_command_from_config_list(cmd, commands) if have.get('reinit'): cmd = 'lldp reinit' self._remove_command_from_config_list(cmd, commands) return commands
gpl-3.0
[ 3, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 1898, 20312, 9572, 13002, 3277, 14, 199, 3, 1664, 1696, 1684, 844, 373, 19, 14, 16, 11, 334, 3239, 9685, 503, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 11692, 13, 19, 14, 16, 14, 2424, 9, 199, 624, 199, 1918, 29516, 63, 24319, 63, 2966, 1021, 199, 7940, 365, 315, 642, 570, 2382, 314, 1453, 2897, 334, 305, 1211, 9, 199, 374, 13524, 370, 314, 2741, 2897, 334, 305, 1211, 9, 436, 314, 1414, 663, 199, 17927, 370, 330, 5985, 314, 1453, 2897, 370, 2399, 6387, 1284, 13, 929, 365, 199, 3966, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 363, 6577, 363, 275, 730, 199, 199, 504, 3242, 14, 578, 63, 1208, 14, 4174, 492, 10849, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 2330, 14, 4128, 14, 1095, 492, 4094, 1563, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 2330, 14, 1208, 492, 370, 63, 513, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 9207, 14, 5047, 14, 5047, 492, 481, 22282, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 9207, 14, 1208, 14, 1208, 492, 1211, 63, 475, 63, 409, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 9207, 14, 1208, 14, 1208, 492, 2457, 63, 807, 63, 31569, 63, 3592, 63, 585, 421, 199, 533, 491, 17288, 63, 2966, 8, 2028, 1563, 304, 272, 408, 272, 710, 29516, 63, 24319, 63, 2966, 1021, 272, 408, 339, 13082, 63, 9401, 275, 359, 267, 14597, 452, 297, 267, 14597, 827, 297, 272, 1622, 339, 13082, 63, 1200, 63, 4435, 275, 359, 267, 283, 24319, 63, 2966, 297, 272, 1622, 339, 307, 6371, 63, 2416, 63, 1162, 275, 791, 13672, 63, 11239, 63, 5652, 63, 8110, 356, 283, 20, 13, 11239, 13, 5652, 13, 8110, 297, 283, 3088, 63, 6581, 63, 4128, 356, 283, 3088, 13, 6581, 13, 4128, 297, 586, 283, 8110, 63, 1562, 356, 283, 8110, 13, 1562, 297, 283, 719, 63, 1802, 356, 283, 719, 13, 1802, 297, 586, 283, 719, 63, 7175, 356, 283, 719, 13, 7175, 297, 283, 5652, 63, 8110, 356, 283, 5652, 13, 8110, 297, 586, 283, 2253, 63, 10732, 356, 283, 2253, 13, 10732, 297, 283, 2253, 63, 1802, 356, 283, 2253, 13, 1802, 297, 586, 283, 2253, 63, 354, 356, 283, 2253, 13, 354, 936, 339, 347, 636, 826, 721, 277, 12, 859, 304, 267, 1613, 8, 44, 17288, 63, 2966, 12, 291, 2843, 826, 721, 578, 9, 339, 347, 664, 63, 24319, 63, 2966, 63, 5047, 8, 277, 304, 267, 408, 2372, 314, 283, 5047, 7, 334, 1589, 1453, 2897, 9, 398, 520, 4500, 26, 437, 2600, 267, 520, 5808, 26, 710, 1453, 2897, 465, 282, 2600, 267, 408, 267, 9036, 12, 485, 5451, 275, 481, 22282, 8, 277, 423, 578, 680, 362, 63, 5047, 8, 277, 14, 13737, 63, 9401, 12, 291, 14, 13737, 63, 1200, 63, 4435, 9, 267, 28768, 63, 2966, 63, 5047, 275, 9036, 459, 4853, 63, 1200, 63, 4435, 2278, 362, 360, 24319, 63, 2966, 358, 267, 340, 440, 28768, 63, 2966, 63, 5047, 26, 288, 372, 1052, 398, 372, 28768, 63, 2966, 63, 5047, 339, 347, 5341, 63, 578, 8, 277, 304, 267, 408, 17009, 314, 859, 398, 520, 4500, 26, 437, 2600, 267, 520, 5808, 26, 710, 754, 687, 3413, 13086, 6451, 267, 408, 267, 754, 275, 791, 2489, 356, 756, 93, 267, 3718, 275, 769, 342, 267, 3598, 275, 769, 342, 398, 3411, 63, 24319, 63, 2966, 63, 5047, 275, 291, 14, 362, 63, 24319, 63, 2966, 63, 5047, 342, 267, 3718, 14, 2880, 8, 277, 14, 409, 63, 888, 8, 5952, 63, 24319, 63, 2966, 63, 5047, 430, 398, 340, 3718, 26, 288, 340, 440, 291, 423, 578, 14, 1074, 63, 632, 26, 355, 291, 423, 2105, 14, 3773, 63, 888, 8, 4405, 9, 288, 754, 459, 2489, 418, 275, 715, 267, 754, 459, 4405, 418, 275, 3718, 398, 2896, 63, 24319, 63, 2966, 63, 5047, 275, 291, 14, 362, 63, 24319, 63, 2966, 63, 5047, 342, 398, 754, 459, 5182, 418, 275, 3411, 63, 24319, 63, 2966, 63, 5047, 267, 340, 754, 459, 2489, 2565, 288, 754, 459, 4399, 418, 275, 2896, 63, 24319, 63, 2966, 63, 5047, 267, 754, 459, 5451, 418, 275, 3598, 398, 372, 754, 339, 347, 663, 63, 888, 8, 277, 12, 3411, 63, 24319, 63, 2966, 63, 5047, 304, 267, 408, 19649, 314, 2897, 687, 314, 1249, 3032, 370, 314, 859, 12, 288, 8775, 314, 1453, 2897, 334, 305, 282, 1211, 687, 9036, 9, 398, 520, 4500, 26, 437, 769, 267, 520, 5808, 26, 314, 3718, 5784, 370, 12810, 314, 1453, 2897, 2116, 370, 314, 477, 374, 581, 2897, 267, 408, 267, 2934, 275, 291, 423, 578, 14, 1162, 459, 888, 418, 267, 1172, 275, 3411, 63, 24319, 63, 2966, 63, 5047, 267, 3085, 275, 291, 14, 409, 63, 929, 8, 7051, 12, 1172, 9, 267, 372, 370, 63, 513, 8, 4518, 9, 339, 347, 663, 63, 929, 8, 277, 12, 2934, 12, 1172, 304, 267, 408, 9496, 314, 5827, 805, 4079, 641, 314, 1174, 2741, 398, 520, 635, 2934, 26, 314, 6387, 2897, 465, 282, 2600, 267, 520, 635, 1172, 26, 314, 1453, 2897, 465, 282, 2600, 267, 520, 4500, 26, 437, 769, 267, 520, 5808, 26, 314, 3718, 5784, 370, 12810, 314, 1453, 2897, 2116, 370, 314, 477, 374, 581, 2897, 267, 408, 267, 3718, 275, 942, 267, 1174, 275, 291, 423, 578, 14, 1162, 459, 929, 418, 267, 340, 1174, 315, 661, 15269, 297, 283, 31473, 358, 436, 440, 2934, 26, 288, 291, 423, 578, 14, 1633, 63, 1001, 8, 1328, 534, 585, 402, 1101, 2725, 1471, 440, 506, 2701, 367, 1174, 469, 16, 5285, 908, 8, 929, 430, 398, 340, 1174, 508, 283, 30769, 356, 288, 3718, 275, 291, 423, 929, 63, 30769, 8, 7051, 12, 1172, 9, 267, 916, 1174, 508, 283, 6062, 356, 288, 3718, 275, 291, 423, 929, 63, 6062, 8, 7051, 12, 1172, 9, 267, 916, 1174, 508, 283, 15269, 356, 288, 3718, 275 ]
[ 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 1898, 20312, 9572, 13002, 3277, 14, 199, 3, 1664, 1696, 1684, 844, 373, 19, 14, 16, 11, 334, 3239, 9685, 503, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 11692, 13, 19, 14, 16, 14, 2424, 9, 199, 624, 199, 1918, 29516, 63, 24319, 63, 2966, 1021, 199, 7940, 365, 315, 642, 570, 2382, 314, 1453, 2897, 334, 305, 1211, 9, 199, 374, 13524, 370, 314, 2741, 2897, 334, 305, 1211, 9, 436, 314, 1414, 663, 199, 17927, 370, 330, 5985, 314, 1453, 2897, 370, 2399, 6387, 1284, 13, 929, 365, 199, 3966, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 363, 6577, 363, 275, 730, 199, 199, 504, 3242, 14, 578, 63, 1208, 14, 4174, 492, 10849, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 2330, 14, 4128, 14, 1095, 492, 4094, 1563, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 2330, 14, 1208, 492, 370, 63, 513, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 9207, 14, 5047, 14, 5047, 492, 481, 22282, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 9207, 14, 1208, 14, 1208, 492, 1211, 63, 475, 63, 409, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 9207, 14, 1208, 14, 1208, 492, 2457, 63, 807, 63, 31569, 63, 3592, 63, 585, 421, 199, 533, 491, 17288, 63, 2966, 8, 2028, 1563, 304, 272, 408, 272, 710, 29516, 63, 24319, 63, 2966, 1021, 272, 408, 339, 13082, 63, 9401, 275, 359, 267, 14597, 452, 297, 267, 14597, 827, 297, 272, 1622, 339, 13082, 63, 1200, 63, 4435, 275, 359, 267, 283, 24319, 63, 2966, 297, 272, 1622, 339, 307, 6371, 63, 2416, 63, 1162, 275, 791, 13672, 63, 11239, 63, 5652, 63, 8110, 356, 283, 20, 13, 11239, 13, 5652, 13, 8110, 297, 283, 3088, 63, 6581, 63, 4128, 356, 283, 3088, 13, 6581, 13, 4128, 297, 586, 283, 8110, 63, 1562, 356, 283, 8110, 13, 1562, 297, 283, 719, 63, 1802, 356, 283, 719, 13, 1802, 297, 586, 283, 719, 63, 7175, 356, 283, 719, 13, 7175, 297, 283, 5652, 63, 8110, 356, 283, 5652, 13, 8110, 297, 586, 283, 2253, 63, 10732, 356, 283, 2253, 13, 10732, 297, 283, 2253, 63, 1802, 356, 283, 2253, 13, 1802, 297, 586, 283, 2253, 63, 354, 356, 283, 2253, 13, 354, 936, 339, 347, 636, 826, 721, 277, 12, 859, 304, 267, 1613, 8, 44, 17288, 63, 2966, 12, 291, 2843, 826, 721, 578, 9, 339, 347, 664, 63, 24319, 63, 2966, 63, 5047, 8, 277, 304, 267, 408, 2372, 314, 283, 5047, 7, 334, 1589, 1453, 2897, 9, 398, 520, 4500, 26, 437, 2600, 267, 520, 5808, 26, 710, 1453, 2897, 465, 282, 2600, 267, 408, 267, 9036, 12, 485, 5451, 275, 481, 22282, 8, 277, 423, 578, 680, 362, 63, 5047, 8, 277, 14, 13737, 63, 9401, 12, 291, 14, 13737, 63, 1200, 63, 4435, 9, 267, 28768, 63, 2966, 63, 5047, 275, 9036, 459, 4853, 63, 1200, 63, 4435, 2278, 362, 360, 24319, 63, 2966, 358, 267, 340, 440, 28768, 63, 2966, 63, 5047, 26, 288, 372, 1052, 398, 372, 28768, 63, 2966, 63, 5047, 339, 347, 5341, 63, 578, 8, 277, 304, 267, 408, 17009, 314, 859, 398, 520, 4500, 26, 437, 2600, 267, 520, 5808, 26, 710, 754, 687, 3413, 13086, 6451, 267, 408, 267, 754, 275, 791, 2489, 356, 756, 93, 267, 3718, 275, 769, 342, 267, 3598, 275, 769, 342, 398, 3411, 63, 24319, 63, 2966, 63, 5047, 275, 291, 14, 362, 63, 24319, 63, 2966, 63, 5047, 342, 267, 3718, 14, 2880, 8, 277, 14, 409, 63, 888, 8, 5952, 63, 24319, 63, 2966, 63, 5047, 430, 398, 340, 3718, 26, 288, 340, 440, 291, 423, 578, 14, 1074, 63, 632, 26, 355, 291, 423, 2105, 14, 3773, 63, 888, 8, 4405, 9, 288, 754, 459, 2489, 418, 275, 715, 267, 754, 459, 4405, 418, 275, 3718, 398, 2896, 63, 24319, 63, 2966, 63, 5047, 275, 291, 14, 362, 63, 24319, 63, 2966, 63, 5047, 342, 398, 754, 459, 5182, 418, 275, 3411, 63, 24319, 63, 2966, 63, 5047, 267, 340, 754, 459, 2489, 2565, 288, 754, 459, 4399, 418, 275, 2896, 63, 24319, 63, 2966, 63, 5047, 267, 754, 459, 5451, 418, 275, 3598, 398, 372, 754, 339, 347, 663, 63, 888, 8, 277, 12, 3411, 63, 24319, 63, 2966, 63, 5047, 304, 267, 408, 19649, 314, 2897, 687, 314, 1249, 3032, 370, 314, 859, 12, 288, 8775, 314, 1453, 2897, 334, 305, 282, 1211, 687, 9036, 9, 398, 520, 4500, 26, 437, 769, 267, 520, 5808, 26, 314, 3718, 5784, 370, 12810, 314, 1453, 2897, 2116, 370, 314, 477, 374, 581, 2897, 267, 408, 267, 2934, 275, 291, 423, 578, 14, 1162, 459, 888, 418, 267, 1172, 275, 3411, 63, 24319, 63, 2966, 63, 5047, 267, 3085, 275, 291, 14, 409, 63, 929, 8, 7051, 12, 1172, 9, 267, 372, 370, 63, 513, 8, 4518, 9, 339, 347, 663, 63, 929, 8, 277, 12, 2934, 12, 1172, 304, 267, 408, 9496, 314, 5827, 805, 4079, 641, 314, 1174, 2741, 398, 520, 635, 2934, 26, 314, 6387, 2897, 465, 282, 2600, 267, 520, 635, 1172, 26, 314, 1453, 2897, 465, 282, 2600, 267, 520, 4500, 26, 437, 769, 267, 520, 5808, 26, 314, 3718, 5784, 370, 12810, 314, 1453, 2897, 2116, 370, 314, 477, 374, 581, 2897, 267, 408, 267, 3718, 275, 942, 267, 1174, 275, 291, 423, 578, 14, 1162, 459, 929, 418, 267, 340, 1174, 315, 661, 15269, 297, 283, 31473, 358, 436, 440, 2934, 26, 288, 291, 423, 578, 14, 1633, 63, 1001, 8, 1328, 534, 585, 402, 1101, 2725, 1471, 440, 506, 2701, 367, 1174, 469, 16, 5285, 908, 8, 929, 430, 398, 340, 1174, 508, 283, 30769, 356, 288, 3718, 275, 291, 423, 929, 63, 30769, 8, 7051, 12, 1172, 9, 267, 916, 1174, 508, 283, 6062, 356, 288, 3718, 275, 291, 423, 929, 63, 6062, 8, 7051, 12, 1172, 9, 267, 916, 1174, 508, 283, 15269, 356, 288, 3718, 275, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
Kamp9/scipy
scipy/stats/_tukeylambda_stats.py
128
6930
from __future__ import division, print_function, absolute_import import numpy as np from numpy import poly1d from scipy.special import beta # The following code was used to generate the Pade coefficients for the # Tukey Lambda variance function. Version 0.17 of mpmath was used. #--------------------------------------------------------------------------- # import mpmath as mp # # mp.mp.dps = 60 # # one = mp.mpf(1) # two = mp.mpf(2) # # def mpvar(lam): # if lam == 0: # v = mp.pi**2 / three # else: # v = (two / lam**2) * (one / (one + two*lam) - # mp.beta(lam + one, lam + one)) # return v # # t = mp.taylor(mpvar, 0, 8) # p, q = mp.pade(t, 4, 4) # print "p =", [mp.fp.mpf(c) for c in p] # print "q =", [mp.fp.mpf(c) for c in q] #--------------------------------------------------------------------------- # Pade coefficients for the Tukey Lambda variance function. _tukeylambda_var_pc = [3.289868133696453, 0.7306125098871127, -0.5370742306855439, 0.17292046290190008, -0.02371146284628187] _tukeylambda_var_qc = [1.0, 3.683605511659861, 4.184152498888124, 1.7660926747377275, 0.2643989311168465] # numpy.poly1d instances for the numerator and denominator of the # Pade approximation to the Tukey Lambda variance. _tukeylambda_var_p = poly1d(_tukeylambda_var_pc[::-1]) _tukeylambda_var_q = poly1d(_tukeylambda_var_qc[::-1]) def tukeylambda_variance(lam): """Variance of the Tukey Lambda distribution. Parameters ---------- lam : array_like The lambda values at which to compute the variance. Returns ------- v : ndarray The variance. For lam < -0.5, the variance is not defined, so np.nan is returned. For lam = 0.5, np.inf is returned. Notes ----- In an interval around lambda=0, this function uses the [4,4] Pade approximation to compute the variance. Otherwise it uses the standard formula (http://en.wikipedia.org/wiki/Tukey_lambda_distribution). The Pade approximation is used because the standard formula has a removable discontinuity at lambda = 0, and does not produce accurate numerical results near lambda = 0. """ lam = np.asarray(lam) shp = lam.shape lam = np.atleast_1d(lam).astype(np.float64) # For absolute values of lam less than threshold, use the Pade # approximation. threshold = 0.075 # Play games with masks to implement the conditional evaluation of # the distribution. # lambda < -0.5: var = nan low_mask = lam < -0.5 # lambda == -0.5: var = inf neghalf_mask = lam == -0.5 # abs(lambda) < threshold: use Pade approximation small_mask = np.abs(lam) < threshold # else the "regular" case: use the explicit formula. reg_mask = ~(low_mask | neghalf_mask | small_mask) # Get the 'lam' values for the cases where they are needed. small = lam[small_mask] reg = lam[reg_mask] # Compute the function for each case. v = np.empty_like(lam) v[low_mask] = np.nan v[neghalf_mask] = np.inf if small.size > 0: # Use the Pade approximation near lambda = 0. v[small_mask] = _tukeylambda_var_p(small) / _tukeylambda_var_q(small) if reg.size > 0: v[reg_mask] = (2.0 / reg**2) * (1.0 / (1.0 + 2 * reg) - beta(reg + 1, reg + 1)) v.shape = shp return v # The following code was used to generate the Pade coefficients for the # Tukey Lambda kurtosis function. Version 0.17 of mpmath was used. #--------------------------------------------------------------------------- # import mpmath as mp # # mp.mp.dps = 60 # # one = mp.mpf(1) # two = mp.mpf(2) # three = mp.mpf(3) # four = mp.mpf(4) # # def mpkurt(lam): # if lam == 0: # k = mp.mpf(6)/5 # else: # numer = (one/(four*lam+one) - four*mp.beta(three*lam+one, lam+one) + # three*mp.beta(two*lam+one, two*lam+one)) # denom = two*(one/(two*lam+one) - mp.beta(lam+one,lam+one))**2 # k = numer / denom - three # return k # # # There is a bug in mpmath 0.17: when we use the 'method' keyword of the # # taylor function and we request a degree 9 Taylor polynomial, we actually # # get degree 8. # t = mp.taylor(mpkurt, 0, 9, method='quad', radius=0.01) # t = [mp.chop(c, tol=1e-15) for c in t] # p, q = mp.pade(t, 4, 4) # print "p =", [mp.fp.mpf(c) for c in p] # print "q =", [mp.fp.mpf(c) for c in q] #--------------------------------------------------------------------------- # Pade coefficients for the Tukey Lambda kurtosis function. _tukeylambda_kurt_pc = [1.2, -5.853465139719495, -22.653447381131077, 0.20601184383406815, 4.59796302262789] _tukeylambda_kurt_qc = [1.0, 7.171149192233599, 12.96663094361842, 0.43075235247853005, -2.789746758009912] # numpy.poly1d instances for the numerator and denominator of the # Pade approximation to the Tukey Lambda kurtosis. _tukeylambda_kurt_p = poly1d(_tukeylambda_kurt_pc[::-1]) _tukeylambda_kurt_q = poly1d(_tukeylambda_kurt_qc[::-1]) def tukeylambda_kurtosis(lam): """Kurtosis of the Tukey Lambda distribution. Parameters ---------- lam : array_like The lambda values at which to compute the variance. Returns ------- v : ndarray The variance. For lam < -0.25, the variance is not defined, so np.nan is returned. For lam = 0.25, np.inf is returned. """ lam = np.asarray(lam) shp = lam.shape lam = np.atleast_1d(lam).astype(np.float64) # For absolute values of lam less than threshold, use the Pade # approximation. threshold = 0.055 # Use masks to implement the conditional evaluation of the kurtosis. # lambda < -0.25: kurtosis = nan low_mask = lam < -0.25 # lambda == -0.25: kurtosis = inf negqrtr_mask = lam == -0.25 # lambda near 0: use Pade approximation small_mask = np.abs(lam) < threshold # else the "regular" case: use the explicit formula. reg_mask = ~(low_mask | negqrtr_mask | small_mask) # Get the 'lam' values for the cases where they are needed. small = lam[small_mask] reg = lam[reg_mask] # Compute the function for each case. k = np.empty_like(lam) k[low_mask] = np.nan k[negqrtr_mask] = np.inf if small.size > 0: k[small_mask] = _tukeylambda_kurt_p(small) / _tukeylambda_kurt_q(small) if reg.size > 0: numer = (1.0 / (4 * reg + 1) - 4 * beta(3 * reg + 1, reg + 1) + 3 * beta(2 * reg + 1, 2 * reg + 1)) denom = 2 * (1.0/(2 * reg + 1) - beta(reg + 1, reg + 1))**2 k[reg_mask] = numer / denom - 3 # The return value will be a numpy array; resetting the shape ensures that # if `lam` was a scalar, the return value is a 0-d array. k.shape = shp return k
bsd-3-clause
[ 504, 636, 2443, 363, 492, 4629, 12, 870, 63, 1593, 12, 3679, 63, 646, 199, 199, 646, 2680, 465, 980, 199, 504, 2680, 492, 8446, 17, 68, 199, 504, 7026, 14, 6664, 492, 8201, 421, 199, 3, 710, 2569, 1233, 1990, 1202, 370, 3550, 314, 510, 9587, 12343, 367, 314, 199, 3, 377, 85, 498, 28650, 11773, 805, 14, 221, 3394, 378, 14, 1196, 402, 6118, 3442, 1990, 1202, 14, 199, 7656, 13715, 199, 3, 492, 6118, 3442, 465, 6118, 199, 3, 199, 3, 6118, 14, 311, 14, 30168, 275, 5212, 199, 3, 199, 3, 1373, 257, 275, 6118, 14, 26716, 8, 17, 9, 199, 3, 2877, 257, 275, 6118, 14, 26716, 8, 18, 9, 199, 3, 199, 3, 347, 6118, 1391, 8, 17984, 304, 199, 3, 258, 340, 25917, 508, 378, 26, 199, 3, 260, 373, 275, 6118, 14, 1038, 538, 18, 1182, 7795, 199, 3, 258, 587, 26, 199, 3, 260, 373, 275, 334, 5601, 1182, 25917, 538, 18, 9, 627, 334, 368, 1182, 334, 368, 435, 2877, 10, 17984, 9, 446, 199, 3, 17388, 6118, 14, 5683, 8, 17984, 435, 1373, 12, 25917, 435, 1373, 430, 199, 3, 258, 372, 373, 199, 3, 199, 3, 307, 275, 6118, 14, 502, 89, 25339, 8, 311, 1391, 12, 378, 12, 1695, 9, 199, 3, 299, 12, 1894, 275, 6118, 14, 387, 271, 8, 84, 12, 841, 12, 841, 9, 199, 3, 870, 298, 80, 20815, 359, 311, 14, 3997, 14, 26716, 8, 67, 9, 367, 286, 315, 299, 61, 199, 3, 870, 298, 81, 20815, 359, 311, 14, 3997, 14, 26716, 8, 67, 9, 367, 286, 315, 1894, 61, 199, 7656, 13715, 199, 199, 3, 510, 9587, 12343, 367, 314, 377, 85, 498, 28650, 11773, 805, 14, 199, 63, 10963, 498, 2734, 63, 1391, 63, 2352, 275, 359, 19, 14, 20919, 15430, 969, 11939, 772, 2481, 12, 378, 14, 23, 11363, 713, 6576, 1299, 3172, 4195, 12, 2432, 446, 16, 14, 21, 13812, 1342, 9687, 2333, 19264, 1355, 12, 378, 14, 1196, 1398, 6686, 29151, 12512, 19141, 12, 2432, 446, 16, 14, 996, 1401, 845, 2466, 10681, 22, 1651, 11775, 61, 199, 63, 10963, 498, 2734, 63, 1391, 63, 21882, 275, 359, 17, 14, 16, 12, 650, 14, 2333, 11197, 1229, 7524, 1427, 16253, 12, 841, 14, 10078, 1046, 11032, 14871, 7214, 12, 2432, 413, 14, 31251, 1643, 1479, 1342, 2898, 1138, 13643, 12, 378, 14, 9408, 1355, 14590, 845, 975, 1349, 2182, 61, 199, 199, 3, 2680, 14, 6023, 17, 68, 4454, 367, 314, 27640, 436, 21859, 402, 314, 199, 3, 510, 9587, 22772, 370, 314, 377, 85, 498, 28650, 11773, 14, 199, 63, 10963, 498, 2734, 63, 1391, 63, 80, 275, 8446, 17, 68, 1547, 10963, 498, 2734, 63, 1391, 63, 2352, 14172, 17, 566, 199, 63, 10963, 498, 2734, 63, 1391, 63, 81, 275, 8446, 17, 68, 1547, 10963, 498, 2734, 63, 1391, 63, 21882, 14172, 17, 566, 421, 199, 318, 30799, 498, 2734, 63, 6221, 8, 17984, 304, 272, 408, 31805, 402, 314, 377, 85, 498, 28650, 4084, 14, 339, 3897, 272, 4143, 272, 25917, 520, 1625, 63, 2930, 267, 710, 2400, 1338, 737, 1314, 370, 4526, 314, 11773, 14, 339, 1803, 272, 5514, 272, 373, 520, 6800, 267, 710, 11773, 14, 221, 2104, 25917, 665, 446, 16, 14, 21, 12, 314, 11773, 365, 440, 3247, 12, 880, 267, 980, 14, 4304, 365, 2138, 14, 221, 2104, 25917, 275, 378, 14, 21, 12, 980, 14, 4904, 365, 2138, 14, 339, 8144, 272, 9063, 272, 1010, 376, 6252, 6818, 2400, 29, 16, 12, 642, 805, 4440, 314, 359, 20, 12, 20, 61, 510, 9587, 272, 22772, 370, 4526, 314, 11773, 14, 221, 6630, 652, 4440, 314, 4465, 272, 15723, 334, 1014, 921, 287, 14, 13961, 14, 1308, 15, 6797, 15, 30669, 498, 63, 2734, 63, 4972, 680, 221, 710, 272, 510, 9587, 22772, 365, 1202, 2952, 314, 4465, 15723, 965, 282, 295, 14469, 461, 272, 2153, 12875, 24180, 737, 2400, 275, 378, 12, 436, 1630, 440, 7389, 23189, 15470, 272, 2058, 17429, 2400, 275, 378, 14, 272, 408, 272, 25917, 275, 980, 14, 8748, 8, 17984, 9, 272, 1033, 80, 275, 25917, 14, 1392, 272, 25917, 275, 980, 14, 22900, 63, 17, 68, 8, 17984, 680, 6041, 8, 1590, 14, 1609, 772, 9, 339, 327, 2104, 3679, 1338, 402, 25917, 6656, 2419, 8765, 12, 675, 314, 510, 9587, 272, 327, 22772, 14, 272, 8765, 275, 378, 14, 19339, 339, 327, 16527, 9219, 83, 543, 27996, 370, 5669, 314, 12303, 11735, 402, 272, 327, 314, 4084, 14, 272, 327, 2400, 665, 446, 16, 14, 21, 26, 221, 2729, 275, 12055, 272, 6465, 63, 2629, 275, 25917, 665, 446, 16, 14, 21, 272, 327, 2400, 508, 446, 16, 14, 21, 26, 2729, 275, 10739, 272, 14158, 10220, 63, 2629, 275, 25917, 508, 446, 16, 14, 21, 272, 327, 2853, 8, 2734, 9, 665, 8765, 26, 221, 675, 510, 9587, 22772, 272, 7425, 63, 2629, 275, 980, 14, 2101, 8, 17984, 9, 665, 8765, 272, 327, 587, 314, 298, 7898, 2, 1930, 26, 221, 675, 314, 5027, 15723, 14, 272, 1295, 63, 2629, 275, 6146, 8, 674, 63, 2629, 1204, 14158, 10220, 63, 2629, 1204, 7425, 63, 2629, 9, 339, 327, 2372, 314, 283, 17984, 7, 1338, 367, 314, 5560, 2382, 2985, 787, 4346, 14, 272, 7425, 275, 25917, 59, 7241, 63, 2629, 61, 272, 1295, 275, 25917, 59, 1135, 63, 2629, 61, 339, 327, 8354, 314, 805, 367, 1924, 1930, 14, 272, 373, 275, 980, 14, 1667, 63, 2930, 8, 17984, 9, 272, 373, 59, 674, 63, 2629, 61, 275, 980, 14, 4304, 272, 373, 59, 8705, 10220, 63, 2629, 61, 275, 980, 14, 4904, 272, 340, 7425, 14, 890, 690, 378, 26, 267, 327, 3645, 314, 510, 9587, 22772, 17429, 2400, 275, 378, 14, 267, 373, 59, 7241, 63, 2629, 61, 275, 485, 10963, 498, 2734, 63, 1391, 63, 80, 8, 7241, 9, 1182, 485, 10963, 498, 2734, 63, 1391, 63, 81, 8, 7241, 9, 272, 340, 1295, 14, 890, 690, 378, 26, 267, 373, 59, 1135, 63, 2629, 61, 275, 334, 18, 14, 16, 1182, 1295, 538, 18, 9, 627, 334, 17, 14, 16, 1182, 334, 17, 14, 16, 435 ]
[ 636, 2443, 363, 492, 4629, 12, 870, 63, 1593, 12, 3679, 63, 646, 199, 199, 646, 2680, 465, 980, 199, 504, 2680, 492, 8446, 17, 68, 199, 504, 7026, 14, 6664, 492, 8201, 421, 199, 3, 710, 2569, 1233, 1990, 1202, 370, 3550, 314, 510, 9587, 12343, 367, 314, 199, 3, 377, 85, 498, 28650, 11773, 805, 14, 221, 3394, 378, 14, 1196, 402, 6118, 3442, 1990, 1202, 14, 199, 7656, 13715, 199, 3, 492, 6118, 3442, 465, 6118, 199, 3, 199, 3, 6118, 14, 311, 14, 30168, 275, 5212, 199, 3, 199, 3, 1373, 257, 275, 6118, 14, 26716, 8, 17, 9, 199, 3, 2877, 257, 275, 6118, 14, 26716, 8, 18, 9, 199, 3, 199, 3, 347, 6118, 1391, 8, 17984, 304, 199, 3, 258, 340, 25917, 508, 378, 26, 199, 3, 260, 373, 275, 6118, 14, 1038, 538, 18, 1182, 7795, 199, 3, 258, 587, 26, 199, 3, 260, 373, 275, 334, 5601, 1182, 25917, 538, 18, 9, 627, 334, 368, 1182, 334, 368, 435, 2877, 10, 17984, 9, 446, 199, 3, 17388, 6118, 14, 5683, 8, 17984, 435, 1373, 12, 25917, 435, 1373, 430, 199, 3, 258, 372, 373, 199, 3, 199, 3, 307, 275, 6118, 14, 502, 89, 25339, 8, 311, 1391, 12, 378, 12, 1695, 9, 199, 3, 299, 12, 1894, 275, 6118, 14, 387, 271, 8, 84, 12, 841, 12, 841, 9, 199, 3, 870, 298, 80, 20815, 359, 311, 14, 3997, 14, 26716, 8, 67, 9, 367, 286, 315, 299, 61, 199, 3, 870, 298, 81, 20815, 359, 311, 14, 3997, 14, 26716, 8, 67, 9, 367, 286, 315, 1894, 61, 199, 7656, 13715, 199, 199, 3, 510, 9587, 12343, 367, 314, 377, 85, 498, 28650, 11773, 805, 14, 199, 63, 10963, 498, 2734, 63, 1391, 63, 2352, 275, 359, 19, 14, 20919, 15430, 969, 11939, 772, 2481, 12, 378, 14, 23, 11363, 713, 6576, 1299, 3172, 4195, 12, 2432, 446, 16, 14, 21, 13812, 1342, 9687, 2333, 19264, 1355, 12, 378, 14, 1196, 1398, 6686, 29151, 12512, 19141, 12, 2432, 446, 16, 14, 996, 1401, 845, 2466, 10681, 22, 1651, 11775, 61, 199, 63, 10963, 498, 2734, 63, 1391, 63, 21882, 275, 359, 17, 14, 16, 12, 650, 14, 2333, 11197, 1229, 7524, 1427, 16253, 12, 841, 14, 10078, 1046, 11032, 14871, 7214, 12, 2432, 413, 14, 31251, 1643, 1479, 1342, 2898, 1138, 13643, 12, 378, 14, 9408, 1355, 14590, 845, 975, 1349, 2182, 61, 199, 199, 3, 2680, 14, 6023, 17, 68, 4454, 367, 314, 27640, 436, 21859, 402, 314, 199, 3, 510, 9587, 22772, 370, 314, 377, 85, 498, 28650, 11773, 14, 199, 63, 10963, 498, 2734, 63, 1391, 63, 80, 275, 8446, 17, 68, 1547, 10963, 498, 2734, 63, 1391, 63, 2352, 14172, 17, 566, 199, 63, 10963, 498, 2734, 63, 1391, 63, 81, 275, 8446, 17, 68, 1547, 10963, 498, 2734, 63, 1391, 63, 21882, 14172, 17, 566, 421, 199, 318, 30799, 498, 2734, 63, 6221, 8, 17984, 304, 272, 408, 31805, 402, 314, 377, 85, 498, 28650, 4084, 14, 339, 3897, 272, 4143, 272, 25917, 520, 1625, 63, 2930, 267, 710, 2400, 1338, 737, 1314, 370, 4526, 314, 11773, 14, 339, 1803, 272, 5514, 272, 373, 520, 6800, 267, 710, 11773, 14, 221, 2104, 25917, 665, 446, 16, 14, 21, 12, 314, 11773, 365, 440, 3247, 12, 880, 267, 980, 14, 4304, 365, 2138, 14, 221, 2104, 25917, 275, 378, 14, 21, 12, 980, 14, 4904, 365, 2138, 14, 339, 8144, 272, 9063, 272, 1010, 376, 6252, 6818, 2400, 29, 16, 12, 642, 805, 4440, 314, 359, 20, 12, 20, 61, 510, 9587, 272, 22772, 370, 4526, 314, 11773, 14, 221, 6630, 652, 4440, 314, 4465, 272, 15723, 334, 1014, 921, 287, 14, 13961, 14, 1308, 15, 6797, 15, 30669, 498, 63, 2734, 63, 4972, 680, 221, 710, 272, 510, 9587, 22772, 365, 1202, 2952, 314, 4465, 15723, 965, 282, 295, 14469, 461, 272, 2153, 12875, 24180, 737, 2400, 275, 378, 12, 436, 1630, 440, 7389, 23189, 15470, 272, 2058, 17429, 2400, 275, 378, 14, 272, 408, 272, 25917, 275, 980, 14, 8748, 8, 17984, 9, 272, 1033, 80, 275, 25917, 14, 1392, 272, 25917, 275, 980, 14, 22900, 63, 17, 68, 8, 17984, 680, 6041, 8, 1590, 14, 1609, 772, 9, 339, 327, 2104, 3679, 1338, 402, 25917, 6656, 2419, 8765, 12, 675, 314, 510, 9587, 272, 327, 22772, 14, 272, 8765, 275, 378, 14, 19339, 339, 327, 16527, 9219, 83, 543, 27996, 370, 5669, 314, 12303, 11735, 402, 272, 327, 314, 4084, 14, 272, 327, 2400, 665, 446, 16, 14, 21, 26, 221, 2729, 275, 12055, 272, 6465, 63, 2629, 275, 25917, 665, 446, 16, 14, 21, 272, 327, 2400, 508, 446, 16, 14, 21, 26, 2729, 275, 10739, 272, 14158, 10220, 63, 2629, 275, 25917, 508, 446, 16, 14, 21, 272, 327, 2853, 8, 2734, 9, 665, 8765, 26, 221, 675, 510, 9587, 22772, 272, 7425, 63, 2629, 275, 980, 14, 2101, 8, 17984, 9, 665, 8765, 272, 327, 587, 314, 298, 7898, 2, 1930, 26, 221, 675, 314, 5027, 15723, 14, 272, 1295, 63, 2629, 275, 6146, 8, 674, 63, 2629, 1204, 14158, 10220, 63, 2629, 1204, 7425, 63, 2629, 9, 339, 327, 2372, 314, 283, 17984, 7, 1338, 367, 314, 5560, 2382, 2985, 787, 4346, 14, 272, 7425, 275, 25917, 59, 7241, 63, 2629, 61, 272, 1295, 275, 25917, 59, 1135, 63, 2629, 61, 339, 327, 8354, 314, 805, 367, 1924, 1930, 14, 272, 373, 275, 980, 14, 1667, 63, 2930, 8, 17984, 9, 272, 373, 59, 674, 63, 2629, 61, 275, 980, 14, 4304, 272, 373, 59, 8705, 10220, 63, 2629, 61, 275, 980, 14, 4904, 272, 340, 7425, 14, 890, 690, 378, 26, 267, 327, 3645, 314, 510, 9587, 22772, 17429, 2400, 275, 378, 14, 267, 373, 59, 7241, 63, 2629, 61, 275, 485, 10963, 498, 2734, 63, 1391, 63, 80, 8, 7241, 9, 1182, 485, 10963, 498, 2734, 63, 1391, 63, 81, 8, 7241, 9, 272, 340, 1295, 14, 890, 690, 378, 26, 267, 373, 59, 1135, 63, 2629, 61, 275, 334, 18, 14, 16, 1182, 1295, 538, 18, 9, 627, 334, 17, 14, 16, 1182, 334, 17, 14, 16, 435, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
allenlavoie/tensorflow
tensorflow/contrib/learn/python/learn/preprocessing/tests/categorical_vocabulary_test.py
137
2187
# encoding: utf-8 # Copyright 2016 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== """Categorical vocabulary tests.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function from tensorflow.contrib.learn.python.learn.preprocessing import categorical_vocabulary from tensorflow.python.platform import test class CategoricalVocabularyTest(test.TestCase): """Categorical vocabulary tests.""" def testIntVocabulary(self): vocab = categorical_vocabulary.CategoricalVocabulary() self.assertEqual(vocab.get(1), 1) self.assertEqual(vocab.get(3), 2) self.assertEqual(vocab.get(2), 3) self.assertEqual(vocab.get(3), 2) # This vocab doesn't handle nan specially. self.assertEqual(vocab.get(float('nan')), 4) self.assertEqual(len(vocab), 5) def testWordVocabulary(self): vocab = categorical_vocabulary.CategoricalVocabulary() self.assertEqual(vocab.get('a'), 1) self.assertEqual(vocab.get('b'), 2) self.assertEqual(vocab.get('a'), 1) self.assertEqual(vocab.get('b'), 2) def testCountsTrim(self): vocab = categorical_vocabulary.CategoricalVocabulary() vocab.get('c') vocab.add('c', 5) vocab.get('a') vocab.add('a', 10) # not in vocab yet, skips. vocab.add('b', 5) vocab.add('d', 12) vocab.trim(7, 11) vocab.freeze() self.assertEqual(vocab.get('b'), 0) self.assertEqual(vocab.get('c'), 0) self.assertEqual(len(vocab), 2) self.assertEqual(vocab.get('a'), 1) if __name__ == '__main__': test.main()
apache-2.0
[ 3, 2644, 26, 2774, 13, 24, 199, 3, 1898, 7800, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 23306, 17515, 2295, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 504, 3228, 14, 2828, 14, 4643, 14, 1548, 14, 4643, 14, 21402, 492, 22138, 63, 18681, 199, 504, 3228, 14, 1548, 14, 3246, 492, 511, 421, 199, 533, 31227, 54, 6607, 11439, 774, 8, 396, 14, 1746, 304, 523, 408, 23306, 17515, 2295, 1041, 819, 347, 511, 3241, 54, 6607, 11439, 8, 277, 304, 272, 11181, 275, 22138, 63, 18681, 14, 23306, 54, 6607, 11439, 342, 272, 291, 14, 629, 8, 9953, 14, 362, 8, 17, 395, 413, 9, 272, 291, 14, 629, 8, 9953, 14, 362, 8, 19, 395, 499, 9, 272, 291, 14, 629, 8, 9953, 14, 362, 8, 18, 395, 650, 9, 272, 291, 14, 629, 8, 9953, 14, 362, 8, 19, 395, 499, 9, 272, 327, 961, 11181, 3181, 1133, 2429, 12055, 1106, 1183, 14, 272, 291, 14, 629, 8, 9953, 14, 362, 8, 1609, 360, 4304, 3855, 841, 9, 272, 291, 14, 629, 8, 552, 8, 9953, 395, 959, 9, 819, 347, 511, 10155, 54, 6607, 11439, 8, 277, 304, 272, 11181, 275, 22138, 63, 18681, 14, 23306, 54, 6607, 11439, 342, 272, 291, 14, 629, 8, 9953, 14, 362, 360, 65, 659, 413, 9, 272, 291, 14, 629, 8, 9953, 14, 362, 360, 66, 659, 499, 9, 272, 291, 14, 629, 8, 9953, 14, 362, 360, 65, 659, 413, 9, 272, 291, 14, 629, 8, 9953, 14, 362, 360, 66, 659, 499, 9, 819, 347, 511, 23209, 31081, 8, 277, 304, 272, 11181, 275, 22138, 63, 18681, 14, 23306, 54, 6607, 11439, 342, 272, 11181, 14, 362, 360, 67, 358, 272, 11181, 14, 525, 360, 67, 297, 959, 9, 272, 11181, 14, 362, 360, 65, 358, 272, 11181, 14, 525, 360, 65, 297, 1616, 9, 272, 327, 440, 315, 11181, 5966, 12, 30505, 14, 272, 11181, 14, 525, 360, 66, 297, 959, 9, 272, 11181, 14, 525, 360, 68, 297, 3144, 9, 272, 11181, 14, 12263, 8, 23, 12, 4119, 9, 272, 11181, 14, 18459, 342, 272, 291, 14, 629, 8, 9953, 14, 362, 360, 66, 659, 378, 9, 272, 291, 14, 629, 8, 9953, 14, 362, 360, 67, 659, 378, 9, 272, 291, 14, 629, 8, 552, 8, 9953, 395, 499, 9, 272, 291, 14, 629, 8, 9953, 14, 362, 360, 65, 659, 413, 9, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 523, 511, 14, 973, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2644, 26, 2774, 13, 24, 199, 3, 1898, 7800, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 23306, 17515, 2295, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 504, 3228, 14, 2828, 14, 4643, 14, 1548, 14, 4643, 14, 21402, 492, 22138, 63, 18681, 199, 504, 3228, 14, 1548, 14, 3246, 492, 511, 421, 199, 533, 31227, 54, 6607, 11439, 774, 8, 396, 14, 1746, 304, 523, 408, 23306, 17515, 2295, 1041, 819, 347, 511, 3241, 54, 6607, 11439, 8, 277, 304, 272, 11181, 275, 22138, 63, 18681, 14, 23306, 54, 6607, 11439, 342, 272, 291, 14, 629, 8, 9953, 14, 362, 8, 17, 395, 413, 9, 272, 291, 14, 629, 8, 9953, 14, 362, 8, 19, 395, 499, 9, 272, 291, 14, 629, 8, 9953, 14, 362, 8, 18, 395, 650, 9, 272, 291, 14, 629, 8, 9953, 14, 362, 8, 19, 395, 499, 9, 272, 327, 961, 11181, 3181, 1133, 2429, 12055, 1106, 1183, 14, 272, 291, 14, 629, 8, 9953, 14, 362, 8, 1609, 360, 4304, 3855, 841, 9, 272, 291, 14, 629, 8, 552, 8, 9953, 395, 959, 9, 819, 347, 511, 10155, 54, 6607, 11439, 8, 277, 304, 272, 11181, 275, 22138, 63, 18681, 14, 23306, 54, 6607, 11439, 342, 272, 291, 14, 629, 8, 9953, 14, 362, 360, 65, 659, 413, 9, 272, 291, 14, 629, 8, 9953, 14, 362, 360, 66, 659, 499, 9, 272, 291, 14, 629, 8, 9953, 14, 362, 360, 65, 659, 413, 9, 272, 291, 14, 629, 8, 9953, 14, 362, 360, 66, 659, 499, 9, 819, 347, 511, 23209, 31081, 8, 277, 304, 272, 11181, 275, 22138, 63, 18681, 14, 23306, 54, 6607, 11439, 342, 272, 11181, 14, 362, 360, 67, 358, 272, 11181, 14, 525, 360, 67, 297, 959, 9, 272, 11181, 14, 362, 360, 65, 358, 272, 11181, 14, 525, 360, 65, 297, 1616, 9, 272, 327, 440, 315, 11181, 5966, 12, 30505, 14, 272, 11181, 14, 525, 360, 66, 297, 959, 9, 272, 11181, 14, 525, 360, 68, 297, 3144, 9, 272, 11181, 14, 12263, 8, 23, 12, 4119, 9, 272, 11181, 14, 18459, 342, 272, 291, 14, 629, 8, 9953, 14, 362, 360, 66, 659, 378, 9, 272, 291, 14, 629, 8, 9953, 14, 362, 360, 67, 659, 378, 9, 272, 291, 14, 629, 8, 552, 8, 9953, 395, 499, 9, 272, 291, 14, 629, 8, 9953, 14, 362, 360, 65, 659, 413, 9, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 523, 511, 14, 973, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1,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t-hey/QGIS-Original
python/pyplugin_installer/__init__.py
32
1499
# -*- coding: utf-8 -*- """ *************************************************************************** __init__.py --------------------- Date : May 2013 Copyright : (C) 2013 by Borys Jurgiel Email : info at borysjurgiel dot pl This module is based on former plugin_installer plugin: Copyright (C) 2007-2008 Matthew Perry Copyright (C) 2008-2013 Borys Jurgiel /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ """ __author__ = 'Borys Jurgiel' __date__ = 'May 2013' __copyright__ = '(C) 2013, Borys Jurgiel' # This will get replaced with a git SHA1 when you do a git archive __revision__ = '$Format:%H$' # import functions for easier access from . import installer from .installer import initPluginInstaller # NOQA def instance(): if not installer.pluginInstaller: installer.initPluginInstaller() return installer.pluginInstaller
gpl-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 624, 199, 17623, 272, 636, 826, 4343, 647, 272, 10652, 9858, 272, 6148, 463, 520, 10162, 6171, 272, 1898, 3322, 520, 334, 35, 9, 6171, 701, 699, 269, 588, 1603, 300, 6153, 352, 272, 11426, 4483, 520, 2256, 737, 330, 269, 588, 74, 300, 6153, 352, 6308, 1620, 339, 961, 859, 365, 4079, 641, 26610, 3589, 63, 17047, 3589, 26, 489, 1898, 334, 35, 9, 10219, 13, 9300, 18619, 29640, 3492, 651, 489, 1898, 334, 35, 9, 9079, 13, 6965, 699, 269, 588, 1603, 300, 6153, 352, 199, 199, 15, 17623, 199, 627, 17997, 627, 199, 627, 257, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 221, 627, 199, 627, 257, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 221, 627, 199, 627, 257, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 258, 627, 199, 627, 257, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 15530, 627, 199, 627, 17997, 627, 199, 1011, 14355, 15870, 199, 624, 199, 199, 363, 2502, 363, 275, 283, 34, 269, 588, 1603, 300, 6153, 352, 7, 199, 363, 602, 363, 275, 283, 15586, 6171, 7, 199, 363, 7307, 363, 275, 8189, 35, 9, 6171, 12, 699, 269, 588, 1603, 300, 6153, 352, 7, 199, 3, 961, 911, 664, 8717, 543, 282, 6135, 12002, 17, 1380, 1265, 886, 282, 6135, 6359, 199, 363, 5792, 363, 275, 4505, 3484, 2689, 40, 12913, 421, 199, 3, 492, 3423, 367, 14905, 2879, 199, 504, 1275, 492, 18535, 199, 504, 1275, 17047, 492, 4205, 5061, 27598, 221, 327, 20432, 421, 199, 318, 1256, 837, 272, 340, 440, 18535, 14, 2718, 27598, 26, 267, 18535, 14, 826, 5061, 27598, 342, 272, 372, 18535, 14, 2718, 27598, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 624, 199, 17623, 272, 636, 826, 4343, 647, 272, 10652, 9858, 272, 6148, 463, 520, 10162, 6171, 272, 1898, 3322, 520, 334, 35, 9, 6171, 701, 699, 269, 588, 1603, 300, 6153, 352, 272, 11426, 4483, 520, 2256, 737, 330, 269, 588, 74, 300, 6153, 352, 6308, 1620, 339, 961, 859, 365, 4079, 641, 26610, 3589, 63, 17047, 3589, 26, 489, 1898, 334, 35, 9, 10219, 13, 9300, 18619, 29640, 3492, 651, 489, 1898, 334, 35, 9, 9079, 13, 6965, 699, 269, 588, 1603, 300, 6153, 352, 199, 199, 15, 17623, 199, 627, 17997, 627, 199, 627, 257, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 221, 627, 199, 627, 257, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 221, 627, 199, 627, 257, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 258, 627, 199, 627, 257, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 15530, 627, 199, 627, 17997, 627, 199, 1011, 14355, 15870, 199, 624, 199, 199, 363, 2502, 363, 275, 283, 34, 269, 588, 1603, 300, 6153, 352, 7, 199, 363, 602, 363, 275, 283, 15586, 6171, 7, 199, 363, 7307, 363, 275, 8189, 35, 9, 6171, 12, 699, 269, 588, 1603, 300, 6153, 352, 7, 199, 3, 961, 911, 664, 8717, 543, 282, 6135, 12002, 17, 1380, 1265, 886, 282, 6135, 6359, 199, 363, 5792, 363, 275, 4505, 3484, 2689, 40, 12913, 421, 199, 3, 492, 3423, 367, 14905, 2879, 199, 504, 1275, 492, 18535, 199, 504, 1275, 17047, 492, 4205, 5061, 27598, 221, 327, 20432, 421, 199, 318, 1256, 837, 272, 340, 440, 18535, 14, 2718, 27598, 26, 267, 18535, 14, 826, 5061, 27598, 342, 272, 372, 18535, 14, 2718, 27598, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
aparo/django-nonrel
django/contrib/gis/db/backends/postgis/models.py
403
1970
""" The GeometryColumns and SpatialRefSys models for the PostGIS backend. """ from django.db import models from django.contrib.gis.db.backends.base import SpatialRefSysMixin class GeometryColumns(models.Model): """ The 'geometry_columns' table from the PostGIS. See the PostGIS documentation at Ch. 4.2.2. """ f_table_catalog = models.CharField(max_length=256) f_table_schema = models.CharField(max_length=256) f_table_name = models.CharField(max_length=256) f_geometry_column = models.CharField(max_length=256) coord_dimension = models.IntegerField() srid = models.IntegerField(primary_key=True) type = models.CharField(max_length=30) class Meta: db_table = 'geometry_columns' managed = False @classmethod def table_name_col(cls): """ Returns the name of the metadata column used to store the the feature table name. """ return 'f_table_name' @classmethod def geom_col_name(cls): """ Returns the name of the metadata column used to store the the feature geometry column. """ return 'f_geometry_column' def __unicode__(self): return "%s.%s - %dD %s field (SRID: %d)" % \ (self.f_table_name, self.f_geometry_column, self.coord_dimension, self.type, self.srid) class SpatialRefSys(models.Model, SpatialRefSysMixin): """ The 'spatial_ref_sys' table from PostGIS. See the PostGIS documentaiton at Ch. 4.2.1. """ srid = models.IntegerField(primary_key=True) auth_name = models.CharField(max_length=256) auth_srid = models.IntegerField() srtext = models.CharField(max_length=2048) proj4text = models.CharField(max_length=2048) class Meta: db_table = 'spatial_ref_sys' managed = False @property def wkt(self): return self.srtext @classmethod def wkt_col(cls): return 'srtext'
bsd-3-clause
[ 624, 199, 710, 10579, 15086, 436, 13423, 2891, 11319, 1709, 367, 314, 20929, 4865, 14, 199, 624, 199, 504, 1639, 14, 697, 492, 1709, 199, 504, 1639, 14, 2828, 14, 5668, 14, 697, 14, 7765, 14, 1095, 492, 13423, 2891, 11319, 4256, 199, 199, 533, 10579, 15086, 8, 992, 14, 1685, 304, 272, 408, 272, 710, 283, 7660, 63, 3406, 7, 1817, 687, 314, 20929, 14, 1666, 314, 20929, 272, 3794, 737, 2799, 14, 841, 14, 18, 14, 18, 14, 272, 408, 272, 289, 63, 1224, 63, 7959, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 3912, 9, 272, 289, 63, 1224, 63, 3629, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 3912, 9, 272, 289, 63, 1224, 63, 354, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 3912, 9, 272, 289, 63, 7660, 63, 2301, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 3912, 9, 272, 11021, 63, 7430, 275, 1709, 14, 3901, 342, 272, 15627, 275, 1709, 14, 3901, 8, 3327, 63, 498, 29, 549, 9, 272, 730, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1216, 9, 339, 1021, 6288, 26, 267, 1592, 63, 1224, 275, 283, 7660, 63, 3406, 7, 267, 12883, 275, 756, 339, 768, 3744, 272, 347, 1817, 63, 354, 63, 761, 8, 1886, 304, 267, 408, 267, 1803, 314, 536, 402, 314, 3341, 2763, 1202, 370, 3877, 314, 267, 314, 3878, 1817, 536, 14, 267, 408, 267, 372, 283, 70, 63, 1224, 63, 354, 7, 339, 768, 3744, 272, 347, 9671, 63, 761, 63, 354, 8, 1886, 304, 267, 408, 267, 1803, 314, 536, 402, 314, 3341, 2763, 1202, 370, 3877, 314, 267, 314, 3878, 3400, 2763, 14, 267, 408, 267, 372, 283, 70, 63, 7660, 63, 2301, 7, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 2071, 83, 4111, 83, 446, 450, 68, 36, 450, 83, 901, 334, 5943, 998, 26, 450, 68, 2924, 450, 971, 2049, 334, 277, 14, 70, 63, 1224, 63, 354, 12, 291, 14, 70, 63, 7660, 63, 2301, 12, 355, 291, 14, 7988, 63, 7430, 12, 291, 14, 466, 12, 291, 14, 10498, 9, 199, 199, 533, 13423, 2891, 11319, 8, 992, 14, 1685, 12, 13423, 2891, 11319, 4256, 304, 272, 408, 272, 710, 283, 11679, 63, 1121, 63, 1274, 7, 1817, 687, 20929, 14, 1666, 314, 20929, 272, 2213, 2781, 265, 737, 2799, 14, 841, 14, 18, 14, 17, 14, 272, 408, 272, 15627, 275, 1709, 14, 3901, 8, 3327, 63, 498, 29, 549, 9, 272, 1790, 63, 354, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 3912, 9, 272, 1790, 63, 10498, 275, 1709, 14, 3901, 342, 272, 11483, 505, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 18343, 9, 272, 13523, 20, 505, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 18343, 9, 339, 1021, 6288, 26, 267, 1592, 63, 1224, 275, 283, 11679, 63, 1121, 63, 1274, 7, 267, 12883, 275, 756, 339, 768, 1829, 272, 347, 21992, 8, 277, 304, 267, 372, 291, 14, 5474, 505, 339, 768, 3744, 272, 347, 21992, 63, 761, 8, 1886, 304, 267, 372, 283, 5474, 505, 7, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 199, 710, 10579, 15086, 436, 13423, 2891, 11319, 1709, 367, 314, 20929, 4865, 14, 199, 624, 199, 504, 1639, 14, 697, 492, 1709, 199, 504, 1639, 14, 2828, 14, 5668, 14, 697, 14, 7765, 14, 1095, 492, 13423, 2891, 11319, 4256, 199, 199, 533, 10579, 15086, 8, 992, 14, 1685, 304, 272, 408, 272, 710, 283, 7660, 63, 3406, 7, 1817, 687, 314, 20929, 14, 1666, 314, 20929, 272, 3794, 737, 2799, 14, 841, 14, 18, 14, 18, 14, 272, 408, 272, 289, 63, 1224, 63, 7959, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 3912, 9, 272, 289, 63, 1224, 63, 3629, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 3912, 9, 272, 289, 63, 1224, 63, 354, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 3912, 9, 272, 289, 63, 7660, 63, 2301, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 3912, 9, 272, 11021, 63, 7430, 275, 1709, 14, 3901, 342, 272, 15627, 275, 1709, 14, 3901, 8, 3327, 63, 498, 29, 549, 9, 272, 730, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1216, 9, 339, 1021, 6288, 26, 267, 1592, 63, 1224, 275, 283, 7660, 63, 3406, 7, 267, 12883, 275, 756, 339, 768, 3744, 272, 347, 1817, 63, 354, 63, 761, 8, 1886, 304, 267, 408, 267, 1803, 314, 536, 402, 314, 3341, 2763, 1202, 370, 3877, 314, 267, 314, 3878, 1817, 536, 14, 267, 408, 267, 372, 283, 70, 63, 1224, 63, 354, 7, 339, 768, 3744, 272, 347, 9671, 63, 761, 63, 354, 8, 1886, 304, 267, 408, 267, 1803, 314, 536, 402, 314, 3341, 2763, 1202, 370, 3877, 314, 267, 314, 3878, 3400, 2763, 14, 267, 408, 267, 372, 283, 70, 63, 7660, 63, 2301, 7, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 2071, 83, 4111, 83, 446, 450, 68, 36, 450, 83, 901, 334, 5943, 998, 26, 450, 68, 2924, 450, 971, 2049, 334, 277, 14, 70, 63, 1224, 63, 354, 12, 291, 14, 70, 63, 7660, 63, 2301, 12, 355, 291, 14, 7988, 63, 7430, 12, 291, 14, 466, 12, 291, 14, 10498, 9, 199, 199, 533, 13423, 2891, 11319, 8, 992, 14, 1685, 12, 13423, 2891, 11319, 4256, 304, 272, 408, 272, 710, 283, 11679, 63, 1121, 63, 1274, 7, 1817, 687, 20929, 14, 1666, 314, 20929, 272, 2213, 2781, 265, 737, 2799, 14, 841, 14, 18, 14, 17, 14, 272, 408, 272, 15627, 275, 1709, 14, 3901, 8, 3327, 63, 498, 29, 549, 9, 272, 1790, 63, 354, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 3912, 9, 272, 1790, 63, 10498, 275, 1709, 14, 3901, 342, 272, 11483, 505, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 18343, 9, 272, 13523, 20, 505, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 18343, 9, 339, 1021, 6288, 26, 267, 1592, 63, 1224, 275, 283, 11679, 63, 1121, 63, 1274, 7, 267, 12883, 275, 756, 339, 768, 1829, 272, 347, 21992, 8, 277, 304, 267, 372, 291, 14, 5474, 505, 339, 768, 3744, 272, 347, 21992, 63, 761, 8, 1886, 304, 267, 372, 283, 5474, 505, 7, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
drelu/SAGA-Hadoop
hadoop1/launcher.py
1
2591
#!/usr/bin/env python import time import saga import os, sys import subprocess import pdb import logging logging.basicConfig(level=logging.ERROR) def main(): try: # create a job service for Futuregrid's 'india' PBS cluster js = saga.job.Service("pbs+ssh://india") #js = saga.job.Service("fork://localhost") # describe our job jd = saga.job.Description() # resource requirements jd.total_cpu_count = 16 # environment, executable & arguments executable = os.path.join(os.getcwd(), "bootstrap_hadoop.py") logging.debug("Run %s"%executable) jd.executable = executable jd.arguments = [] # output options jd.output = "hadoop_job.stdout" jd.error = "hadoop_job.stderr" jd.working_directory=os.getcwd() # create the job (state: New) myjob = js.create_job(jd) print "Starting Hadoop bootstrap job...\n" # run the job (submit the job to PBS) myjob.run() jobid = myjob.get_id() print "**** Job ID : %s" % (jobid) print "**** Job State : %s" % (myjob.get_state()) while True: state = myjob.get_state() if state=="Running": if os.path.exists("work/started"): get_hadoop_config_data(str(jobid)) break time.sleep(3) except Exception, ex: print "An error occured: %s" % (str(ex)) def get_hadoop_config_data(jobid): pbs_id = jobid[jobid.find("-")+2:len(jobid)-1] nodes = subprocess.check_output(["qstat", "-f", pbs_id]) hosts = "empty" for i in nodes.split("\n"): if i.find("exec_host")>0: hosts = i[i.find("=")+1:].strip() hadoop_home=os.path.join(os.getcwd(), "work/hadoop-1.0.0") print "HADOOP installation directory: %s"%hadoop_home print "Allocated Resources for Hadoop cluster: " + hosts print "HDFS Web Interface: http://%s:50070"% hosts[:hosts.find("/")] print "\nTo use Hadoop set HADOOP_CONF_DIR: " print "export HADOOP_CONF_DIR=%s"%(os.path.join(os.getcwd(), "work", get_most_current_job(), "conf")) print "%s/bin/hadoop dfsadmin -report"%hadoop_home print "" def get_most_current_job(): dir = "work" files = os.listdir(dir) max = None for i in files: if i.startswith("hadoop-conf"): t = os.path.getctime(os.path.join(dir,i)) if max == None or t>max[0]: max = (t, i) return max[1] if __name__ == "__main__": main()
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 199, 646, 900, 199, 646, 308, 643, 65, 199, 646, 747, 12, 984, 199, 646, 3873, 199, 646, 10543, 199, 199, 646, 2050, 199, 4806, 14, 19602, 8, 1896, 29, 4806, 14, 3170, 9, 199, 199, 318, 2446, 837, 2286, 862, 26, 267, 327, 1218, 282, 3906, 2435, 367, 20799, 3825, 1159, 283, 262, 2391, 7, 510, 11087, 4350, 267, 8586, 275, 308, 643, 65, 14, 2423, 14, 3167, 480, 80, 1533, 11, 5510, 921, 262, 2391, 531, 267, 327, 3596, 275, 308, 643, 65, 14, 2423, 14, 3167, 480, 11796, 921, 5967, 531, 398, 327, 13743, 4154, 3906, 267, 1335, 68, 275, 308, 643, 65, 14, 2423, 14, 5831, 342, 267, 327, 2073, 9760, 267, 1335, 68, 14, 2923, 63, 3541, 63, 835, 275, 3193, 259, 267, 327, 3734, 12, 7286, 1253, 2368, 267, 7286, 275, 747, 14, 515, 14, 904, 8, 736, 14, 9458, 1062, 298, 11146, 63, 15449, 14, 647, 531, 267, 2050, 14, 1757, 480, 2540, 450, 83, 6808, 5904, 9, 267, 1335, 68, 14, 5904, 221, 275, 7286, 267, 1335, 68, 14, 4958, 257, 275, 942, 267, 327, 1072, 1511, 267, 1335, 68, 14, 1199, 275, 298, 15449, 63, 2423, 14, 2703, 2, 267, 1335, 68, 14, 705, 221, 275, 298, 15449, 63, 2423, 14, 3083, 2, 267, 1335, 68, 14, 9818, 63, 3619, 29, 736, 14, 9458, 342, 267, 327, 1218, 314, 3906, 334, 929, 26, 7053, 9, 267, 3002, 2423, 275, 8586, 14, 981, 63, 2423, 8, 17694, 9, 398, 870, 298, 14139, 869, 11362, 15865, 3906, 29279, 78, 2, 267, 327, 1255, 314, 3906, 334, 7275, 314, 3906, 370, 510, 11087, 9, 267, 3002, 2423, 14, 1065, 342, 267, 3906, 344, 275, 3002, 2423, 14, 362, 63, 344, 342, 267, 870, 298, 1116, 15057, 2870, 259, 520, 450, 83, 2, 450, 334, 2423, 344, 9, 267, 870, 298, 1116, 15057, 8511, 520, 450, 83, 2, 450, 334, 1662, 2423, 14, 362, 63, 929, 1012, 398, 1830, 715, 26, 288, 1174, 275, 3002, 2423, 14, 362, 63, 929, 342, 288, 340, 1174, 11800, 9602, 582, 355, 340, 747, 14, 515, 14, 2444, 480, 800, 15, 8924, 2349, 490, 664, 63, 15449, 63, 888, 63, 576, 8, 495, 8, 2423, 344, 430, 490, 2059, 288, 900, 14, 4532, 8, 19, 9, 16478, 871, 2186, 12, 444, 26, 267, 870, 298, 2493, 1125, 28408, 26, 450, 83, 2, 450, 334, 495, 8, 476, 430, 421, 199, 318, 664, 63, 15449, 63, 888, 63, 576, 8, 2423, 344, 304, 272, 299, 1533, 63, 344, 275, 3906, 344, 59, 2423, 344, 14, 1623, 6096, 531, 11, 18, 26, 552, 8, 2423, 344, 7216, 17, 61, 272, 3380, 275, 3873, 14, 1074, 63, 1199, 5234, 81, 3736, 401, 3905, 70, 401, 299, 1533, 63, 344, 566, 272, 7057, 275, 298, 1667, 2, 272, 367, 284, 315, 3380, 14, 1294, 4582, 78, 2349, 267, 340, 284, 14, 1623, 480, 1628, 63, 1102, 531, 30, 16, 26, 288, 7057, 275, 284, 59, 73, 14, 1623, 480, 23758, 11, 17, 11455, 1913, 342, 339, 29252, 63, 4219, 29, 736, 14, 515, 14, 904, 8, 736, 14, 9458, 1062, 298, 800, 15, 15449, 13, 17, 14, 16, 14, 16, 531, 272, 870, 298, 40, 1554, 47, 1938, 12096, 2082, 26, 450, 83, 6808, 15449, 63, 4219, 272, 870, 298, 2439, 13340, 26250, 367, 869, 11362, 4350, 26, 298, 435, 7057, 5591, 870, 298, 30165, 51, 6001, 14816, 26, 1455, 13827, 83, 26, 5783, 2760, 6808, 7057, 1491, 5146, 14, 1623, 4769, 11323, 259, 272, 870, 1867, 78, 1378, 675, 869, 11362, 663, 869, 1554, 47, 1938, 63, 3103, 63, 3022, 26, 298, 272, 870, 298, 3790, 869, 1554, 47, 1938, 63, 3103, 63, 3022, 2458, 83, 14007, 736, 14, 515, 14, 904, 8, 736, 14, 9458, 1062, 298, 800, 401, 664, 63, 2786, 63, 1818, 63, 2423, 1062, 298, 2190, 2237, 5591, 870, 2071, 83, 15, 1393, 15, 15449, 366, 2319, 2113, 446, 3070, 6808, 15449, 63, 4219, 272, 870, 3087, 199, 199, 318, 664, 63, 2786, 63, 1818, 63, 2423, 837, 272, 2935, 275, 298, 800, 2, 272, 1584, 275, 747, 14, 7374, 8, 694, 9, 272, 1390, 275, 488, 272, 367, 284, 315, 1584, 26, 267, 340, 284, 14, 2460, 480, 15449, 13, 2190, 2349, 288, 307, 275, 747, 14, 515, 14, 362, 20691, 8, 736, 14, 515, 14, 904, 8, 694, 12, 73, 430, 288, 340, 1390, 508, 488, 503, 307, 30, 988, 59, 16, 2189, 355, 1390, 275, 334, 84, 12, 284, 9, 272, 372, 1390, 59, 17, 61, 199, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 2446, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 199, 646, 900, 199, 646, 308, 643, 65, 199, 646, 747, 12, 984, 199, 646, 3873, 199, 646, 10543, 199, 199, 646, 2050, 199, 4806, 14, 19602, 8, 1896, 29, 4806, 14, 3170, 9, 199, 199, 318, 2446, 837, 2286, 862, 26, 267, 327, 1218, 282, 3906, 2435, 367, 20799, 3825, 1159, 283, 262, 2391, 7, 510, 11087, 4350, 267, 8586, 275, 308, 643, 65, 14, 2423, 14, 3167, 480, 80, 1533, 11, 5510, 921, 262, 2391, 531, 267, 327, 3596, 275, 308, 643, 65, 14, 2423, 14, 3167, 480, 11796, 921, 5967, 531, 398, 327, 13743, 4154, 3906, 267, 1335, 68, 275, 308, 643, 65, 14, 2423, 14, 5831, 342, 267, 327, 2073, 9760, 267, 1335, 68, 14, 2923, 63, 3541, 63, 835, 275, 3193, 259, 267, 327, 3734, 12, 7286, 1253, 2368, 267, 7286, 275, 747, 14, 515, 14, 904, 8, 736, 14, 9458, 1062, 298, 11146, 63, 15449, 14, 647, 531, 267, 2050, 14, 1757, 480, 2540, 450, 83, 6808, 5904, 9, 267, 1335, 68, 14, 5904, 221, 275, 7286, 267, 1335, 68, 14, 4958, 257, 275, 942, 267, 327, 1072, 1511, 267, 1335, 68, 14, 1199, 275, 298, 15449, 63, 2423, 14, 2703, 2, 267, 1335, 68, 14, 705, 221, 275, 298, 15449, 63, 2423, 14, 3083, 2, 267, 1335, 68, 14, 9818, 63, 3619, 29, 736, 14, 9458, 342, 267, 327, 1218, 314, 3906, 334, 929, 26, 7053, 9, 267, 3002, 2423, 275, 8586, 14, 981, 63, 2423, 8, 17694, 9, 398, 870, 298, 14139, 869, 11362, 15865, 3906, 29279, 78, 2, 267, 327, 1255, 314, 3906, 334, 7275, 314, 3906, 370, 510, 11087, 9, 267, 3002, 2423, 14, 1065, 342, 267, 3906, 344, 275, 3002, 2423, 14, 362, 63, 344, 342, 267, 870, 298, 1116, 15057, 2870, 259, 520, 450, 83, 2, 450, 334, 2423, 344, 9, 267, 870, 298, 1116, 15057, 8511, 520, 450, 83, 2, 450, 334, 1662, 2423, 14, 362, 63, 929, 1012, 398, 1830, 715, 26, 288, 1174, 275, 3002, 2423, 14, 362, 63, 929, 342, 288, 340, 1174, 11800, 9602, 582, 355, 340, 747, 14, 515, 14, 2444, 480, 800, 15, 8924, 2349, 490, 664, 63, 15449, 63, 888, 63, 576, 8, 495, 8, 2423, 344, 430, 490, 2059, 288, 900, 14, 4532, 8, 19, 9, 16478, 871, 2186, 12, 444, 26, 267, 870, 298, 2493, 1125, 28408, 26, 450, 83, 2, 450, 334, 495, 8, 476, 430, 421, 199, 318, 664, 63, 15449, 63, 888, 63, 576, 8, 2423, 344, 304, 272, 299, 1533, 63, 344, 275, 3906, 344, 59, 2423, 344, 14, 1623, 6096, 531, 11, 18, 26, 552, 8, 2423, 344, 7216, 17, 61, 272, 3380, 275, 3873, 14, 1074, 63, 1199, 5234, 81, 3736, 401, 3905, 70, 401, 299, 1533, 63, 344, 566, 272, 7057, 275, 298, 1667, 2, 272, 367, 284, 315, 3380, 14, 1294, 4582, 78, 2349, 267, 340, 284, 14, 1623, 480, 1628, 63, 1102, 531, 30, 16, 26, 288, 7057, 275, 284, 59, 73, 14, 1623, 480, 23758, 11, 17, 11455, 1913, 342, 339, 29252, 63, 4219, 29, 736, 14, 515, 14, 904, 8, 736, 14, 9458, 1062, 298, 800, 15, 15449, 13, 17, 14, 16, 14, 16, 531, 272, 870, 298, 40, 1554, 47, 1938, 12096, 2082, 26, 450, 83, 6808, 15449, 63, 4219, 272, 870, 298, 2439, 13340, 26250, 367, 869, 11362, 4350, 26, 298, 435, 7057, 5591, 870, 298, 30165, 51, 6001, 14816, 26, 1455, 13827, 83, 26, 5783, 2760, 6808, 7057, 1491, 5146, 14, 1623, 4769, 11323, 259, 272, 870, 1867, 78, 1378, 675, 869, 11362, 663, 869, 1554, 47, 1938, 63, 3103, 63, 3022, 26, 298, 272, 870, 298, 3790, 869, 1554, 47, 1938, 63, 3103, 63, 3022, 2458, 83, 14007, 736, 14, 515, 14, 904, 8, 736, 14, 9458, 1062, 298, 800, 401, 664, 63, 2786, 63, 1818, 63, 2423, 1062, 298, 2190, 2237, 5591, 870, 2071, 83, 15, 1393, 15, 15449, 366, 2319, 2113, 446, 3070, 6808, 15449, 63, 4219, 272, 870, 3087, 199, 199, 318, 664, 63, 2786, 63, 1818, 63, 2423, 837, 272, 2935, 275, 298, 800, 2, 272, 1584, 275, 747, 14, 7374, 8, 694, 9, 272, 1390, 275, 488, 272, 367, 284, 315, 1584, 26, 267, 340, 284, 14, 2460, 480, 15449, 13, 2190, 2349, 288, 307, 275, 747, 14, 515, 14, 362, 20691, 8, 736, 14, 515, 14, 904, 8, 694, 12, 73, 430, 288, 340, 1390, 508, 488, 503, 307, 30, 988, 59, 16, 2189, 355, 1390, 275, 334, 84, 12, 284, 9, 272, 372, 1390, 59, 17, 61, 199, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 2446, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
SeaFalcon/Musicool_Pr
lib/sqlalchemy/engine/interfaces.py
32
30327
# engine/interfaces.py # Copyright (C) 2005-2014 the SQLAlchemy authors and contributors # <see AUTHORS file> # # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php """Define core interfaces used by the engine system.""" from .. import util, event # backwards compat from ..sql.compiler import Compiled, TypeCompiler class Dialect(object): """Define the behavior of a specific database and DB-API combination. Any aspect of metadata definition, SQL query generation, execution, result-set handling, or anything else which varies between databases is defined under the general category of the Dialect. The Dialect acts as a factory for other database-specific object implementations including ExecutionContext, Compiled, DefaultGenerator, and TypeEngine. All Dialects implement the following attributes: name identifying name for the dialect from a DBAPI-neutral point of view (i.e. 'sqlite') driver identifying name for the dialect's DBAPI positional True if the paramstyle for this Dialect is positional. paramstyle the paramstyle to be used (some DB-APIs support multiple paramstyles). convert_unicode True if Unicode conversion should be applied to all ``str`` types. encoding type of encoding to use for unicode, usually defaults to 'utf-8'. statement_compiler a :class:`.Compiled` class used to compile SQL statements ddl_compiler a :class:`.Compiled` class used to compile DDL statements server_version_info a tuple containing a version number for the DB backend in use. This value is only available for supporting dialects, and is typically populated during the initial connection to the database. default_schema_name the name of the default schema. This value is only available for supporting dialects, and is typically populated during the initial connection to the database. execution_ctx_cls a :class:`.ExecutionContext` class used to handle statement execution execute_sequence_format either the 'tuple' or 'list' type, depending on what cursor.execute() accepts for the second argument (they vary). preparer a :class:`~sqlalchemy.sql.compiler.IdentifierPreparer` class used to quote identifiers. supports_alter ``True`` if the database supports ``ALTER TABLE``. max_identifier_length The maximum length of identifier names. supports_unicode_statements Indicate whether the DB-API can receive SQL statements as Python unicode strings supports_unicode_binds Indicate whether the DB-API can receive string bind parameters as Python unicode strings supports_sane_rowcount Indicate whether the dialect properly implements rowcount for ``UPDATE`` and ``DELETE`` statements. supports_sane_multi_rowcount Indicate whether the dialect properly implements rowcount for ``UPDATE`` and ``DELETE`` statements when executed via executemany. preexecute_autoincrement_sequences True if 'implicit' primary key functions must be executed separately in order to get their value. This is currently oriented towards Postgresql. implicit_returning use RETURNING or equivalent during INSERT execution in order to load newly generated primary keys and other column defaults in one execution, which are then available via inserted_primary_key. If an insert statement has returning() specified explicitly, the "implicit" functionality is not used and inserted_primary_key will not be available. dbapi_type_map A mapping of DB-API type objects present in this Dialect's DB-API implementation mapped to TypeEngine implementations used by the dialect. This is used to apply types to result sets based on the DB-API types present in cursor.description; it only takes effect for result sets against textual statements where no explicit typemap was present. colspecs A dictionary of TypeEngine classes from sqlalchemy.types mapped to subclasses that are specific to the dialect class. This dictionary is class-level only and is not accessed from the dialect instance itself. supports_default_values Indicates if the construct ``INSERT INTO tablename DEFAULT VALUES`` is supported supports_sequences Indicates if the dialect supports CREATE SEQUENCE or similar. sequences_optional If True, indicates if the "optional" flag on the Sequence() construct should signal to not generate a CREATE SEQUENCE. Applies only to dialects that support sequences. Currently used only to allow Postgresql SERIAL to be used on a column that specifies Sequence() for usage on other backends. supports_native_enum Indicates if the dialect supports a native ENUM construct. This will prevent types.Enum from generating a CHECK constraint when that type is used. supports_native_boolean Indicates if the dialect supports a native boolean construct. This will prevent types.Boolean from generating a CHECK constraint when that type is used. """ _has_events = False def create_connect_args(self, url): """Build DB-API compatible connection arguments. Given a :class:`~sqlalchemy.engine.url.URL` object, returns a tuple consisting of a `*args`/`**kwargs` suitable to send directly to the dbapi's connect function. """ raise NotImplementedError() @classmethod def type_descriptor(cls, typeobj): """Transform a generic type to a dialect-specific type. Dialect classes will usually use the :func:`.types.adapt_type` function in the types module to accomplish this. The returned result is cached *per dialect class* so can contain no dialect-instance state. """ raise NotImplementedError() def initialize(self, connection): """Called during strategized creation of the dialect with a connection. Allows dialects to configure options based on server version info or other properties. The connection passed here is a SQLAlchemy Connection object, with full capabilities. The initialize() method of the base dialect should be called via super(). """ pass def reflecttable( self, connection, table, include_columns, exclude_columns): """Load table description from the database. Given a :class:`.Connection` and a :class:`~sqlalchemy.schema.Table` object, reflect its columns and properties from the database. The implementation of this method is provided by :meth:`.DefaultDialect.reflecttable`, which makes use of :class:`.Inspector` to retrieve column information. Dialects should **not** seek to implement this method, and should instead implement individual schema inspection operations such as :meth:`.Dialect.get_columns`, :meth:`.Dialect.get_pk_constraint`, etc. """ raise NotImplementedError() def get_columns(self, connection, table_name, schema=None, **kw): """Return information about columns in `table_name`. Given a :class:`.Connection`, a string `table_name`, and an optional string `schema`, return column information as a list of dictionaries with these keys: name the column's name type [sqlalchemy.types#TypeEngine] nullable boolean default the column's default value autoincrement boolean sequence a dictionary of the form {'name' : str, 'start' :int, 'increment': int} Additional column attributes may be present. """ raise NotImplementedError() def get_primary_keys(self, connection, table_name, schema=None, **kw): """Return information about primary keys in `table_name`. Deprecated. This method is only called by the default implementation of :meth:`.Dialect.get_pk_constraint`. Dialects should instead implement the :meth:`.Dialect.get_pk_constraint` method directly. """ raise NotImplementedError() def get_pk_constraint(self, connection, table_name, schema=None, **kw): """Return information about the primary key constraint on table_name`. Given a :class:`.Connection`, a string `table_name`, and an optional string `schema`, return primary key information as a dictionary with these keys: constrained_columns a list of column names that make up the primary key name optional name of the primary key constraint. """ raise NotImplementedError() def get_foreign_keys(self, connection, table_name, schema=None, **kw): """Return information about foreign_keys in `table_name`. Given a :class:`.Connection`, a string `table_name`, and an optional string `schema`, return foreign key information as a list of dicts with these keys: name the constraint's name constrained_columns a list of column names that make up the foreign key referred_schema the name of the referred schema referred_table the name of the referred table referred_columns a list of column names in the referred table that correspond to constrained_columns """ raise NotImplementedError() def get_table_names(self, connection, schema=None, **kw): """Return a list of table names for `schema`.""" raise NotImplementedError def get_view_names(self, connection, schema=None, **kw): """Return a list of all view names available in the database. schema: Optional, retrieve names from a non-default schema. """ raise NotImplementedError() def get_view_definition(self, connection, view_name, schema=None, **kw): """Return view definition. Given a :class:`.Connection`, a string `view_name`, and an optional string `schema`, return the view definition. """ raise NotImplementedError() def get_indexes(self, connection, table_name, schema=None, **kw): """Return information about indexes in `table_name`. Given a :class:`.Connection`, a string `table_name` and an optional string `schema`, return index information as a list of dictionaries with these keys: name the index's name column_names list of column names in order unique boolean """ raise NotImplementedError() def get_unique_constraints( self, connection, table_name, schema=None, **kw): """Return information about unique constraints in `table_name`. Given a string `table_name` and an optional string `schema`, return unique constraint information as a list of dicts with these keys: name the unique constraint's name column_names list of column names in order \**kw other options passed to the dialect's get_unique_constraints() method. .. versionadded:: 0.9.0 """ raise NotImplementedError() def normalize_name(self, name): """convert the given name to lowercase if it is detected as case insensitive. this method is only used if the dialect defines requires_name_normalize=True. """ raise NotImplementedError() def denormalize_name(self, name): """convert the given name to a case insensitive identifier for the backend if it is an all-lowercase name. this method is only used if the dialect defines requires_name_normalize=True. """ raise NotImplementedError() def has_table(self, connection, table_name, schema=None): """Check the existence of a particular table in the database. Given a :class:`.Connection` object and a string `table_name`, return True if the given table (possibly within the specified `schema`) exists in the database, False otherwise. """ raise NotImplementedError() def has_sequence(self, connection, sequence_name, schema=None): """Check the existence of a particular sequence in the database. Given a :class:`.Connection` object and a string `sequence_name`, return True if the given sequence exists in the database, False otherwise. """ raise NotImplementedError() def _get_server_version_info(self, connection): """Retrieve the server version info from the given connection. This is used by the default implementation to populate the "server_version_info" attribute and is called exactly once upon first connect. """ raise NotImplementedError() def _get_default_schema_name(self, connection): """Return the string name of the currently selected schema from the given connection. This is used by the default implementation to populate the "default_schema_name" attribute and is called exactly once upon first connect. """ raise NotImplementedError() def do_begin(self, dbapi_connection): """Provide an implementation of ``connection.begin()``, given a DB-API connection. The DBAPI has no dedicated "begin" method and it is expected that transactions are implicit. This hook is provided for those DBAPIs that might need additional help in this area. Note that :meth:`.Dialect.do_begin` is not called unless a :class:`.Transaction` object is in use. The :meth:`.Dialect.do_autocommit` hook is provided for DBAPIs that need some extra commands emitted after a commit in order to enter the next transaction, when the SQLAlchemy :class:`.Connection` is used in its default "autocommit" mode. :param dbapi_connection: a DBAPI connection, typically proxied within a :class:`.ConnectionFairy`. """ raise NotImplementedError() def do_rollback(self, dbapi_connection): """Provide an implementation of ``connection.rollback()``, given a DB-API connection. :param dbapi_connection: a DBAPI connection, typically proxied within a :class:`.ConnectionFairy`. """ raise NotImplementedError() def do_commit(self, dbapi_connection): """Provide an implementation of ``connection.commit()``, given a DB-API connection. :param dbapi_connection: a DBAPI connection, typically proxied within a :class:`.ConnectionFairy`. """ raise NotImplementedError() def do_close(self, dbapi_connection): """Provide an implementation of ``connection.close()``, given a DBAPI connection. This hook is called by the :class:`.Pool` when a connection has been detached from the pool, or is being returned beyond the normal capacity of the pool. .. versionadded:: 0.8 """ raise NotImplementedError() def create_xid(self): """Create a two-phase transaction ID. This id will be passed to do_begin_twophase(), do_rollback_twophase(), do_commit_twophase(). Its format is unspecified. """ raise NotImplementedError() def do_savepoint(self, connection, name): """Create a savepoint with the given name. :param connection: a :class:`.Connection`. :param name: savepoint name. """ raise NotImplementedError() def do_rollback_to_savepoint(self, connection, name): """Rollback a connection to the named savepoint. :param connection: a :class:`.Connection`. :param name: savepoint name. """ raise NotImplementedError() def do_release_savepoint(self, connection, name): """Release the named savepoint on a connection. :param connection: a :class:`.Connection`. :param name: savepoint name. """ raise NotImplementedError() def do_begin_twophase(self, connection, xid): """Begin a two phase transaction on the given connection. :param connection: a :class:`.Connection`. :param xid: xid """ raise NotImplementedError() def do_prepare_twophase(self, connection, xid): """Prepare a two phase transaction on the given connection. :param connection: a :class:`.Connection`. :param xid: xid """ raise NotImplementedError() def do_rollback_twophase(self, connection, xid, is_prepared=True, recover=False): """Rollback a two phase transaction on the given connection. :param connection: a :class:`.Connection`. :param xid: xid :param is_prepared: whether or not :meth:`.TwoPhaseTransaction.prepare` was called. :param recover: if the recover flag was passed. """ raise NotImplementedError() def do_commit_twophase(self, connection, xid, is_prepared=True, recover=False): """Commit a two phase transaction on the given connection. :param connection: a :class:`.Connection`. :param xid: xid :param is_prepared: whether or not :meth:`.TwoPhaseTransaction.prepare` was called. :param recover: if the recover flag was passed. """ raise NotImplementedError() def do_recover_twophase(self, connection): """Recover list of uncommited prepared two phase transaction identifiers on the given connection. :param connection: a :class:`.Connection`. """ raise NotImplementedError() def do_executemany(self, cursor, statement, parameters, context=None): """Provide an implementation of ``cursor.executemany(statement, parameters)``.""" raise NotImplementedError() def do_execute(self, cursor, statement, parameters, context=None): """Provide an implementation of ``cursor.execute(statement, parameters)``.""" raise NotImplementedError() def do_execute_no_params(self, cursor, statement, parameters, context=None): """Provide an implementation of ``cursor.execute(statement)``. The parameter collection should not be sent. """ raise NotImplementedError() def is_disconnect(self, e, connection, cursor): """Return True if the given DB-API error indicates an invalid connection""" raise NotImplementedError() def connect(self): """return a callable which sets up a newly created DBAPI connection. The callable accepts a single argument "conn" which is the DBAPI connection itself. It has no return value. This is used to set dialect-wide per-connection options such as isolation modes, unicode modes, etc. If a callable is returned, it will be assembled into a pool listener that receives the direct DBAPI connection, with all wrappers removed. If None is returned, no listener will be generated. """ return None def reset_isolation_level(self, dbapi_conn): """Given a DBAPI connection, revert its isolation to the default.""" raise NotImplementedError() def set_isolation_level(self, dbapi_conn, level): """Given a DBAPI connection, set its isolation level.""" raise NotImplementedError() def get_isolation_level(self, dbapi_conn): """Given a DBAPI connection, return its isolation level.""" raise NotImplementedError() class ExecutionContext(object): """A messenger object for a Dialect that corresponds to a single execution. ExecutionContext should have these data members: connection Connection object which can be freely used by default value generators to execute SQL. This Connection should reference the same underlying connection/transactional resources of root_connection. root_connection Connection object which is the source of this ExecutionContext. This Connection may have close_with_result=True set, in which case it can only be used once. dialect dialect which created this ExecutionContext. cursor DB-API cursor procured from the connection, compiled if passed to constructor, sqlalchemy.engine.base.Compiled object being executed, statement string version of the statement to be executed. Is either passed to the constructor, or must be created from the sql.Compiled object by the time pre_exec() has completed. parameters bind parameters passed to the execute() method. For compiled statements, this is a dictionary or list of dictionaries. For textual statements, it should be in a format suitable for the dialect's paramstyle (i.e. dict or list of dicts for non positional, list or list of lists/tuples for positional). isinsert True if the statement is an INSERT. isupdate True if the statement is an UPDATE. should_autocommit True if the statement is a "committable" statement. prefetch_cols a list of Column objects for which a client-side default was fired off. Applies to inserts and updates. postfetch_cols a list of Column objects for which a server-side default or inline SQL expression value was fired off. Applies to inserts and updates. """ exception = None """A DBAPI-level exception that was caught when this ExecutionContext attempted to execute a statement. This attribute is meaningful only within the :meth:`.ConnectionEvents.dbapi_error` event. .. versionadded:: 0.9.7 .. seealso:: :attr:`.ExecutionContext.is_disconnect` :meth:`.ConnectionEvents.dbapi_error` """ is_disconnect = None """Boolean flag set to True or False when a DBAPI-level exception is caught when this ExecutionContext attempted to execute a statement. This attribute is meaningful only within the :meth:`.ConnectionEvents.dbapi_error` event. .. versionadded:: 0.9.7 .. seealso:: :attr:`.ExecutionContext.exception` :meth:`.ConnectionEvents.dbapi_error` """ def create_cursor(self): """Return a new cursor generated from this ExecutionContext's connection. Some dialects may wish to change the behavior of connection.cursor(), such as postgresql which may return a PG "server side" cursor. """ raise NotImplementedError() def pre_exec(self): """Called before an execution of a compiled statement. If a compiled statement was passed to this ExecutionContext, the `statement` and `parameters` datamembers must be initialized after this statement is complete. """ raise NotImplementedError() def post_exec(self): """Called after the execution of a compiled statement. If a compiled statement was passed to this ExecutionContext, the `last_insert_ids`, `last_inserted_params`, etc. datamembers should be available after this method completes. """ raise NotImplementedError() def result(self): """Return a result object corresponding to this ExecutionContext. Returns a ResultProxy. """ raise NotImplementedError() def handle_dbapi_exception(self, e): """Receive a DBAPI exception which occurred upon execute, result fetch, etc.""" raise NotImplementedError() def should_autocommit_text(self, statement): """Parse the given textual statement and return True if it refers to a "committable" statement""" raise NotImplementedError() def lastrow_has_defaults(self): """Return True if the last INSERT or UPDATE row contained inlined or database-side defaults. """ raise NotImplementedError() def get_rowcount(self): """Return the DBAPI ``cursor.rowcount`` value, or in some cases an interpreted value. See :attr:`.ResultProxy.rowcount` for details on this. """ raise NotImplementedError() class Connectable(object): """Interface for an object which supports execution of SQL constructs. The two implementations of :class:`.Connectable` are :class:`.Connection` and :class:`.Engine`. Connectable must also implement the 'dialect' member which references a :class:`.Dialect` instance. """ def connect(self, **kwargs): """Return a :class:`.Connection` object. Depending on context, this may be ``self`` if this object is already an instance of :class:`.Connection`, or a newly procured :class:`.Connection` if this object is an instance of :class:`.Engine`. """ def contextual_connect(self): """Return a :class:`.Connection` object which may be part of an ongoing context. Depending on context, this may be ``self`` if this object is already an instance of :class:`.Connection`, or a newly procured :class:`.Connection` if this object is an instance of :class:`.Engine`. """ raise NotImplementedError() @util.deprecated("0.7", "Use the create() method on the given schema " "object directly, i.e. :meth:`.Table.create`, " ":meth:`.Index.create`, :meth:`.MetaData.create_all`") def create(self, entity, **kwargs): """Emit CREATE statements for the given schema entity. """ raise NotImplementedError() @util.deprecated("0.7", "Use the drop() method on the given schema " "object directly, i.e. :meth:`.Table.drop`, " ":meth:`.Index.drop`, :meth:`.MetaData.drop_all`") def drop(self, entity, **kwargs): """Emit DROP statements for the given schema entity. """ raise NotImplementedError() def execute(self, object, *multiparams, **params): """Executes the given construct and returns a :class:`.ResultProxy`.""" raise NotImplementedError() def scalar(self, object, *multiparams, **params): """Executes and returns the first column of the first row. The underlying cursor is closed after execution. """ raise NotImplementedError() def _run_visitor(self, visitorcallable, element, **kwargs): raise NotImplementedError() def _execute_clauseelement(self, elem, multiparams=None, params=None): raise NotImplementedError() class ExceptionContext(object): """Encapsulate information about an error condition in progress. This object exists solely to be passed to the :meth:`.ConnectionEvents.handle_error` event, supporting an interface that can be extended without backwards-incompatibility. .. versionadded:: 0.9.7 """ connection = None """The :class:`.Connection` in use during the exception. This member is always present. """ cursor = None """The DBAPI cursor object. May be None. """ statement = None """String SQL statement that was emitted directly to the DBAPI. May be None. """ parameters = None """Parameter collection that was emitted directly to the DBAPI. May be None. """ original_exception = None """The exception object which was caught. This member is always present. """ sqlalchemy_exception = None """The :class:`sqlalchemy.exc.StatementError` which wraps the original, and will be raised if exception handling is not circumvented by the event. May be None, as not all exception types are wrapped by SQLAlchemy. For DBAPI-level exceptions that subclass the dbapi's Error class, this field will always be present. """ chained_exception = None """The exception that was returned by the previous handler in the exception chain, if any. If present, this exception will be the one ultimately raised by SQLAlchemy unless a subsequent handler replaces it. May be None. """ execution_context = None """The :class:`.ExecutionContext` corresponding to the execution operation in progress. This is present for statement execution operations, but not for operations such as transaction begin/end. It also is not present when the exception was raised before the :class:`.ExecutionContext` could be constructed. Note that the :attr:`.ExceptionContext.statement` and :attr:`.ExceptionContext.parameters` members may represent a different value than that of the :class:`.ExecutionContext`, potentially in the case where a :meth:`.ConnectionEvents.before_cursor_execute` event or similar modified the statement/parameters to be sent. May be None. """ is_disconnect = None """Represent whether the exception as occurred represents a "disconnect" condition. This flag will always be True or False within the scope of the :meth:`.ConnectionEvents.handle_error` handler. SQLAlchemy will defer to this flag in order to determine whether or not the connection should be invalidated subsequently. That is, by assigning to this flag, a "disconnect" event which then results in a connection and pool invalidation can be invoked or prevented by changing this flag. """
apache-2.0
[ 3, 6869, 15, 7436, 14, 647, 199, 3, 1898, 334, 35, 9, 11811, 13, 7280, 314, 14303, 11462, 436, 8417, 199, 3, 665, 3239, 10610, 570, 30, 199, 3, 199, 3, 961, 859, 365, 1777, 402, 14303, 436, 365, 14286, 1334, 199, 3, 314, 10697, 844, 26, 1455, 921, 1544, 14, 16374, 14, 1308, 15, 2383, 15, 1147, 13, 1682, 14, 8624, 199, 199, 624, 16213, 6170, 8386, 1202, 701, 314, 6869, 2656, 1041, 199, 199, 504, 2508, 492, 4884, 12, 1566, 199, 199, 3, 8552, 8434, 199, 504, 2508, 3009, 14, 5772, 492, 3599, 1672, 12, 2434, 9131, 421, 199, 533, 3757, 9062, 8, 785, 304, 272, 408, 16213, 314, 5953, 402, 282, 2488, 3050, 436, 6249, 13, 3735, 14665, 14, 339, 6184, 17435, 402, 3341, 5492, 12, 5385, 1827, 10152, 12, 272, 6451, 12, 754, 13, 409, 7252, 12, 503, 7003, 587, 1314, 373, 3433, 272, 3382, 16219, 365, 3247, 1334, 314, 8605, 4637, 402, 314, 272, 3757, 9062, 14, 221, 710, 3757, 9062, 17795, 465, 282, 6434, 367, 1163, 272, 3050, 13, 6100, 909, 12591, 5893, 272, 28573, 2998, 12, 3599, 1672, 12, 3758, 7599, 12, 436, 2434, 8524, 14, 339, 2900, 3757, 9062, 83, 5669, 314, 2569, 3004, 26, 339, 536, 489, 21119, 536, 367, 314, 10982, 687, 282, 27980, 13, 685, 29358, 2376, 402, 2455, 489, 334, 73, 14, 69, 14, 283, 10659, 358, 339, 5253, 489, 21119, 536, 367, 314, 10982, 1159, 27980, 339, 11333, 489, 715, 340, 314, 1215, 2487, 367, 642, 3757, 9062, 365, 11333, 14, 339, 1215, 2487, 489, 314, 1215, 2487, 370, 506, 1202, 334, 3972, 6249, 13, 1282, 1831, 2291, 3663, 489, 1215, 12955, 680, 339, 3957, 63, 2975, 489, 715, 340, 6140, 8603, 1077, 506, 6781, 370, 1006, 1124, 495, 1040, 489, 2943, 14, 339, 2644, 489, 730, 402, 2644, 370, 675, 367, 2649, 12, 9987, 4243, 370, 489, 283, 1624, 13, 24, 1370, 339, 5164, 63, 5772, 489, 282, 520, 533, 5026, 32521, 64, 1021, 1202, 370, 6555, 5385, 9834, 339, 366, 5030, 63, 5772, 489, 282, 520, 533, 5026, 32521, 64, 1021, 1202, 370, 6555, 32078, 9834, 339, 1654, 63, 1023, 63, 815, 489, 282, 2008, 3035, 282, 1015, 1329, 367, 314, 6249, 4865, 315, 675, 14, 489, 961, 574, 365, 1454, 2808, 367, 21038, 10982, 83, 12, 436, 365, 489, 13609, 16460, 5309, 314, 2536, 1950, 370, 314, 3050, 14, 339, 849, 63, 3629, 63, 354, 1362, 314, 536, 402, 314, 849, 4177, 14, 221, 961, 574, 365, 1454, 2808, 367, 1362, 21038, 10982, 83, 12, 436, 365, 13609, 16460, 5309, 314, 1362, 2536, 1950, 370, 314, 3050, 14, 339, 6451, 63, 3799, 63, 1886, 489, 282, 520, 533, 5026, 11310, 2998, 64, 1021, 1202, 370, 2429, 5164, 6451, 339, 5341, 63, 4041, 63, 908, 489, 1902, 314, 283, 2960, 7, 503, 283, 513, 7, 730, 12, 10298, 641, 4052, 3920, 14, 2526, 342, 489, 11479, 367, 314, 3499, 1423, 334, 29002, 17083, 680, 339, 876, 24939, 489, 282, 520, 533, 6054, 14536, 14, 3009, 14, 5772, 14, 7544, 2398, 24939, 64, 1021, 1202, 370, 489, 6313, 14154, 14, 339, 5171, 63, 11858, 489, 1124, 549, 1040, 340, 314, 3050, 5171, 1124, 19350, 9934, 4345, 339, 1390, 63, 5364, 63, 1267, 489, 710, 5696, 2582, 402, 5148, 1561, 14, 339, 5171, 63, 2975, 63, 15384, 489, 1010, 10188, 3775, 314, 6249, 13, 3735, 883, 9128, 5385, 9834, 465, 2018, 489, 2649, 3326, 339, 5171, 63, 2975, 63, 27080, 489, 1010, 10188, 3775, 314, 6249, 13, 3735, 883, 9128, 1059, 5398, 2633, 489, 465, 2018, 2649, 3326, 339, 5171, 63, 83, 5865, 63, 24007, 489, 1010, 10188, 3775, 314, 10982, 7684, 9031, 1962, 835, 367, 489, 1124, 10383, 1040, 436, 1124, 7014, 1040, 9834, 14, 339, 5171, 63, 83, 5865, 63, 3029, 63, 24007, 489, 1010, 10188, 3775, 314, 10982, 7684, 9031, 1962, 835, 367, 489, 1124, 10383, 1040, 436, 1124, 7014, 1040, 9834, 1380, 7934, 4799, 489, 2146, 25450, 14, 339, 876, 2526, 63, 27755, 63, 13436, 489, 715, 340, 283, 11886, 7, 5062, 790, 3423, 1471, 506, 7934, 18159, 489, 315, 1865, 370, 664, 3932, 574, 14, 257, 961, 365, 5544, 503, 24555, 471, 28354, 489, 7711, 7266, 1710, 14, 339, 9227, 63, 24112, 489, 675, 17409, 1230, 6024, 503, 7353, 5309, 22542, 6451, 315, 1865, 370, 2248, 489, 13903, 4046, 5062, 2883, 436, 1163, 2763, 4243, 315, 1373, 6451, 12, 489, 1314, 787, 2066, 2808, 4799, 11788, 63, 3327, 63, 498, 14, 489, 982, 376, 5518, 5164, 965, 8152, 342, 2013, 7662, 12, 489, 314, 298, 11886, 2, 9330, 365, 440, 1202, 436, 11788, 63, 3327, 63, 498, 489, 911, 440, 506, 2808, 14, 339, 29333, 63, 466, 63, 1130, 489, 437, 4412, 402, 6249, 13, 3735, 730, 2251, 3451, 315, 642, 3757, 9062, 1159, 489, 6249, 13, 3735, 4514, 9994, 370, 2434, 8524, 12591, 1202, 489, 701, 314, 10982, 14, 2541, 961, 365, 1202, 370, 4838, 2943, 370, 754, 5951, 4079, 641, 314, 6249, 13, 3735, 489, 2943, 3451, 315, 3920, 14, 1802, 27, 652, 1454, 6181, 7763, 367, 489, 754, 5951, 6169, 25884, 9834, 2382, 949, 5027, 489, 730, 1130, 1990, 3451, 14, 339, 1048, 7273, 489, 437, 2600, 402, 2434, 8524, 3992, 687, 8335, 14, 1313, 9994, 489, 370, 9180, 626, 787, 2488, 370, 314, 10982, 1021, 14, 221, 961, 489, 2600, 365, 1021, 13, 1896, 1454, 436, 365, 440, 13810, 687, 314, 489, 10982, 1256, 6337, 14, 339, 5171, 63, 885, 63, 1459, 489, 19334, 340, 314, 6982, 1124, 10258, 12872, 20283, 6186, 489, 13992, 1040, 365, 3748, 339, 5171, 63, 13436, 489, 19334, 340, 314, 10982, 5171, 16999, 31042, 503, 8545, 14, 339, 8013, 63, 4144, 489, 982, 715, 12, 9126, 340, 314, 298, 4144, 2, 3305, 641, 314, 10975, 342, 6982, 489, 1077, 4673, 370, 440, 3550, 282, 16999, 31042, 14, 4693, 6528, 1454, 370, 489, 10982, 83, 626, 2291, 8013, 14, 13550, 1202, 1454, 370, 2040, 7711, 7266, 1710, 489, 7017, 4938, 370, 506, 1202, 641, 282, 2763, 626, 9314, 10975, 342, 367, 4503, 641, 489, 1163, 14745, 14, 339, 5171, 63, 6106, 63, 4869, 489, 19334, 340, 314, 10982, 5171, 282, 5438, 662, 7125, 6982, 14, 489, 961, 911 ]
[ 6869, 15, 7436, 14, 647, 199, 3, 1898, 334, 35, 9, 11811, 13, 7280, 314, 14303, 11462, 436, 8417, 199, 3, 665, 3239, 10610, 570, 30, 199, 3, 199, 3, 961, 859, 365, 1777, 402, 14303, 436, 365, 14286, 1334, 199, 3, 314, 10697, 844, 26, 1455, 921, 1544, 14, 16374, 14, 1308, 15, 2383, 15, 1147, 13, 1682, 14, 8624, 199, 199, 624, 16213, 6170, 8386, 1202, 701, 314, 6869, 2656, 1041, 199, 199, 504, 2508, 492, 4884, 12, 1566, 199, 199, 3, 8552, 8434, 199, 504, 2508, 3009, 14, 5772, 492, 3599, 1672, 12, 2434, 9131, 421, 199, 533, 3757, 9062, 8, 785, 304, 272, 408, 16213, 314, 5953, 402, 282, 2488, 3050, 436, 6249, 13, 3735, 14665, 14, 339, 6184, 17435, 402, 3341, 5492, 12, 5385, 1827, 10152, 12, 272, 6451, 12, 754, 13, 409, 7252, 12, 503, 7003, 587, 1314, 373, 3433, 272, 3382, 16219, 365, 3247, 1334, 314, 8605, 4637, 402, 314, 272, 3757, 9062, 14, 221, 710, 3757, 9062, 17795, 465, 282, 6434, 367, 1163, 272, 3050, 13, 6100, 909, 12591, 5893, 272, 28573, 2998, 12, 3599, 1672, 12, 3758, 7599, 12, 436, 2434, 8524, 14, 339, 2900, 3757, 9062, 83, 5669, 314, 2569, 3004, 26, 339, 536, 489, 21119, 536, 367, 314, 10982, 687, 282, 27980, 13, 685, 29358, 2376, 402, 2455, 489, 334, 73, 14, 69, 14, 283, 10659, 358, 339, 5253, 489, 21119, 536, 367, 314, 10982, 1159, 27980, 339, 11333, 489, 715, 340, 314, 1215, 2487, 367, 642, 3757, 9062, 365, 11333, 14, 339, 1215, 2487, 489, 314, 1215, 2487, 370, 506, 1202, 334, 3972, 6249, 13, 1282, 1831, 2291, 3663, 489, 1215, 12955, 680, 339, 3957, 63, 2975, 489, 715, 340, 6140, 8603, 1077, 506, 6781, 370, 1006, 1124, 495, 1040, 489, 2943, 14, 339, 2644, 489, 730, 402, 2644, 370, 675, 367, 2649, 12, 9987, 4243, 370, 489, 283, 1624, 13, 24, 1370, 339, 5164, 63, 5772, 489, 282, 520, 533, 5026, 32521, 64, 1021, 1202, 370, 6555, 5385, 9834, 339, 366, 5030, 63, 5772, 489, 282, 520, 533, 5026, 32521, 64, 1021, 1202, 370, 6555, 32078, 9834, 339, 1654, 63, 1023, 63, 815, 489, 282, 2008, 3035, 282, 1015, 1329, 367, 314, 6249, 4865, 315, 675, 14, 489, 961, 574, 365, 1454, 2808, 367, 21038, 10982, 83, 12, 436, 365, 489, 13609, 16460, 5309, 314, 2536, 1950, 370, 314, 3050, 14, 339, 849, 63, 3629, 63, 354, 1362, 314, 536, 402, 314, 849, 4177, 14, 221, 961, 574, 365, 1454, 2808, 367, 1362, 21038, 10982, 83, 12, 436, 365, 13609, 16460, 5309, 314, 1362, 2536, 1950, 370, 314, 3050, 14, 339, 6451, 63, 3799, 63, 1886, 489, 282, 520, 533, 5026, 11310, 2998, 64, 1021, 1202, 370, 2429, 5164, 6451, 339, 5341, 63, 4041, 63, 908, 489, 1902, 314, 283, 2960, 7, 503, 283, 513, 7, 730, 12, 10298, 641, 4052, 3920, 14, 2526, 342, 489, 11479, 367, 314, 3499, 1423, 334, 29002, 17083, 680, 339, 876, 24939, 489, 282, 520, 533, 6054, 14536, 14, 3009, 14, 5772, 14, 7544, 2398, 24939, 64, 1021, 1202, 370, 489, 6313, 14154, 14, 339, 5171, 63, 11858, 489, 1124, 549, 1040, 340, 314, 3050, 5171, 1124, 19350, 9934, 4345, 339, 1390, 63, 5364, 63, 1267, 489, 710, 5696, 2582, 402, 5148, 1561, 14, 339, 5171, 63, 2975, 63, 15384, 489, 1010, 10188, 3775, 314, 6249, 13, 3735, 883, 9128, 5385, 9834, 465, 2018, 489, 2649, 3326, 339, 5171, 63, 2975, 63, 27080, 489, 1010, 10188, 3775, 314, 6249, 13, 3735, 883, 9128, 1059, 5398, 2633, 489, 465, 2018, 2649, 3326, 339, 5171, 63, 83, 5865, 63, 24007, 489, 1010, 10188, 3775, 314, 10982, 7684, 9031, 1962, 835, 367, 489, 1124, 10383, 1040, 436, 1124, 7014, 1040, 9834, 14, 339, 5171, 63, 83, 5865, 63, 3029, 63, 24007, 489, 1010, 10188, 3775, 314, 10982, 7684, 9031, 1962, 835, 367, 489, 1124, 10383, 1040, 436, 1124, 7014, 1040, 9834, 1380, 7934, 4799, 489, 2146, 25450, 14, 339, 876, 2526, 63, 27755, 63, 13436, 489, 715, 340, 283, 11886, 7, 5062, 790, 3423, 1471, 506, 7934, 18159, 489, 315, 1865, 370, 664, 3932, 574, 14, 257, 961, 365, 5544, 503, 24555, 471, 28354, 489, 7711, 7266, 1710, 14, 339, 9227, 63, 24112, 489, 675, 17409, 1230, 6024, 503, 7353, 5309, 22542, 6451, 315, 1865, 370, 2248, 489, 13903, 4046, 5062, 2883, 436, 1163, 2763, 4243, 315, 1373, 6451, 12, 489, 1314, 787, 2066, 2808, 4799, 11788, 63, 3327, 63, 498, 14, 489, 982, 376, 5518, 5164, 965, 8152, 342, 2013, 7662, 12, 489, 314, 298, 11886, 2, 9330, 365, 440, 1202, 436, 11788, 63, 3327, 63, 498, 489, 911, 440, 506, 2808, 14, 339, 29333, 63, 466, 63, 1130, 489, 437, 4412, 402, 6249, 13, 3735, 730, 2251, 3451, 315, 642, 3757, 9062, 1159, 489, 6249, 13, 3735, 4514, 9994, 370, 2434, 8524, 12591, 1202, 489, 701, 314, 10982, 14, 2541, 961, 365, 1202, 370, 4838, 2943, 370, 754, 5951, 4079, 641, 314, 6249, 13, 3735, 489, 2943, 3451, 315, 3920, 14, 1802, 27, 652, 1454, 6181, 7763, 367, 489, 754, 5951, 6169, 25884, 9834, 2382, 949, 5027, 489, 730, 1130, 1990, 3451, 14, 339, 1048, 7273, 489, 437, 2600, 402, 2434, 8524, 3992, 687, 8335, 14, 1313, 9994, 489, 370, 9180, 626, 787, 2488, 370, 314, 10982, 1021, 14, 221, 961, 489, 2600, 365, 1021, 13, 1896, 1454, 436, 365, 440, 13810, 687, 314, 489, 10982, 1256, 6337, 14, 339, 5171, 63, 885, 63, 1459, 489, 19334, 340, 314, 6982, 1124, 10258, 12872, 20283, 6186, 489, 13992, 1040, 365, 3748, 339, 5171, 63, 13436, 489, 19334, 340, 314, 10982, 5171, 16999, 31042, 503, 8545, 14, 339, 8013, 63, 4144, 489, 982, 715, 12, 9126, 340, 314, 298, 4144, 2, 3305, 641, 314, 10975, 342, 6982, 489, 1077, 4673, 370, 440, 3550, 282, 16999, 31042, 14, 4693, 6528, 1454, 370, 489, 10982, 83, 626, 2291, 8013, 14, 13550, 1202, 1454, 370, 2040, 7711, 7266, 1710, 489, 7017, 4938, 370, 506, 1202, 641, 282, 2763, 626, 9314, 10975, 342, 367, 4503, 641, 489, 1163, 14745, 14, 339, 5171, 63, 6106, 63, 4869, 489, 19334, 340, 314, 10982, 5171, 282, 5438, 662, 7125, 6982, 14, 489, 961, 911, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
heilaaks/snippy
tests/lib/helper.py
1
7104
# -*- coding: utf-8 -*- # # SPDX-License-Identifier: AGPL-3.0-or-later # # snippy - software development and maintenance notes manager. # Copyright 2017-2020 Heikki J. Laaksonen <laaksonen.heikki.j@gmail.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. """helper: Generic helpers testing.""" from __future__ import print_function import io import os.path import re import sys import json import pkg_resources from jsonschema import Draft7Validator, RefResolver class Helper(object): """Generic helpers testing. This class intentionally copies some of the implementation from the production code. The purpose is to avoid dependencies in this module to be able to import this module anywhere. """ EXPORT_TIME = '2018-02-02T02:02:02.000001+00:00' IMPORT_TIME = '2018-03-02T02:02:02.000001+00:00' EXPORT_TEMPLATE = '2017-10-14T19:56:31.000001+00:00' DB_SQLITE = 'sqlite' DB_POSTGRESQL = 'postgresql' DB_COCKROACHDB = 'cockroachdb' DB_IN_MEMORY = 'in-memory' STORAGES = (DB_SQLITE, DB_POSTGRESQL, DB_COCKROACHDB, DB_IN_MEMORY) COLOR_OK = '\033[32m' COLOR_END = '\033[0m' # All resource attributes that can be sent in HTTP request. REQUEST_ATTRIBUTES = ( 'data', 'brief', 'description', 'name', 'groups', 'tags', 'links', 'source', 'versions', 'languages', 'filename' ) RE_MATCH_ANSI_ESCAPE_SEQUENCES = re.compile(r''' \x1b[^m]*m # Match all ANSI escape sequences. ''', re.VERBOSE) RE_MATCH_LEADING_WHITEPSACES = re.compile(r''' \n\s+ # Match newline and all leading whitespaces after it. ''', re.VERBOSE) @classmethod def read_template(cls, filename): """Get default content template in text format. The returned template must be in the same format where external editor like vi gets the default template. This means that all the tags are removed and the group tag is replaced with 'default' group. Args: filename (str): Template filename as stored in data/templates. Returns: str: Empty template in the same format as for external editor. """ template = cls._read_resource('data/templates', filename) template = re.sub(r''' <groups> # Match groups tag. ''', 'default', template, flags=re.VERBOSE) template = re.sub(r''' [<]\S+[>] # Match any tag in the template. ''', '', template, flags=re.VERBOSE) # In case of the solution template, there is a <data> tag that leaves # empty fist line. Since all templates start from the first line, the # whitespaces can be removed from left of the string. template = template.lstrip() return template @classmethod def read_completion(cls, filename): """Get shell completion script. Args filename (str): Name of the shell completion file. """ return cls._read_resource('data/completion', filename) @staticmethod def remove_ansi(message): """Remove all ANSI escape codes from given string. Args: message (str): Message which ANSI escape codes are removed. Returns: str: Same message but without ANSI escape sequences. """ return Helper.RE_MATCH_ANSI_ESCAPE_SEQUENCES.sub('', message) @classmethod def get_schema_validator(cls): """Get JSON schema validator for REST API response. Returns: obj: Jsonschema draft7 validator. """ response_resource = json.loads(cls._read_resource('data/server/openapi/schema', 'responseresource.json')) response_collection_get = json.loads(cls._read_resource('data/server/openapi/schema', 'responsecollectionget.json')) response_collection_post = json.loads(cls._read_resource('data/server/openapi/schema', 'responsecollectionpost.json')) response_groups = json.loads(cls._read_resource('data/server/openapi/schema', 'responsegroups.json')) response_tags = json.loads(cls._read_resource('data/server/openapi/schema', 'responsetags.json')) response_errors = json.loads(cls._read_resource('data/server/openapi/schema', 'responseerrors.json')) response_hello = json.loads(cls._read_resource('data/server/openapi/schema', 'responsehello.json')) schema = { 'oneOf': [ response_collection_get, response_collection_post, response_groups, response_tags, response_errors, response_hello, response_resource ] } filepath = pkg_resources.resource_filename('snippy', 'data/server/openapi/schema/') if not os.path.isdir(filepath): print('NOK: cannot run test because server api response schema base uri is not accessible: {}'.format(filepath)) sys.exit(1) server_schema_base_uri = 'file:' + filepath Draft7Validator.check_schema(schema) resolver = RefResolver(base_uri=server_schema_base_uri, referrer=schema) validator = Draft7Validator(schema, resolver=resolver, format_checker=None) return validator @staticmethod def _read_resource(path, filename): """Read resource file. Args: path (str): Relative path under snippy project. filename (str): Resource filename. Returns: str: File read into a string. """ filename = os.path.join(pkg_resources.resource_filename('snippy', path), filename) if not os.path.isfile(filename): print('NOK: cannot run tests because snippy resource file is not accessible: {}'.format(filename)) sys.exit(1) resource_file = '' with io.open(filename, encoding='utf-8') as infile: resource_file = infile.read() return resource_file class Classproperty(object): # pylint: disable=too-few-public-methods """Implement classproperty. Implement decorator that mimics object property. See [1] for more details. [1] https://stackoverflow.com/a/3203659 """ def __init__(self, getter): self._getter = getter def __get__(self, _, owner): """Get property of a class.""" return self._getter(owner)
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 221, 6988, 19596, 13, 3761, 13, 7544, 26, 437, 12006, 13, 19, 14, 16, 13, 269, 13, 18103, 199, 3, 199, 3, 221, 6895, 711, 647, 446, 2032, 16367, 436, 21964, 12681, 5256, 14, 199, 3, 221, 1898, 9708, 13, 13934, 5311, 3258, 8810, 1603, 14, 7964, 1151, 834, 287, 221, 665, 416, 1151, 834, 287, 14, 426, 3258, 8810, 14, 74, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 221, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 221, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 3267, 199, 3, 221, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 221, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 221, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 221, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 221, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 221, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 221, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 221, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 624, 3676, 26, 8307, 10897, 5343, 1041, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 5890, 199, 646, 747, 14, 515, 199, 646, 295, 199, 646, 984, 199, 199, 646, 2022, 199, 646, 5496, 63, 4435, 199, 199, 504, 2022, 3629, 492, 28090, 23, 8640, 12, 15397, 12407, 421, 199, 533, 11642, 8, 785, 304, 272, 408, 9417, 10897, 5343, 14, 339, 961, 1021, 32005, 6866, 2005, 402, 314, 4514, 687, 314, 272, 9920, 1233, 14, 710, 12016, 365, 370, 5126, 5124, 315, 642, 859, 272, 370, 506, 7688, 370, 492, 642, 859, 26523, 14, 272, 408, 339, 3651, 3657, 63, 4961, 275, 283, 12682, 13, 996, 13, 996, 52, 996, 26, 996, 26, 996, 14, 19983, 11, 383, 26, 383, 7, 272, 5025, 2596, 63, 4961, 275, 283, 12682, 13, 1644, 13, 996, 52, 996, 26, 996, 26, 996, 14, 19983, 11, 383, 26, 383, 7, 272, 3651, 3657, 63, 7433, 275, 283, 10680, 13, 709, 13, 1079, 52, 1167, 26, 1367, 26, 2192, 14, 19983, 11, 383, 26, 383, 7, 339, 6249, 63, 4657, 4427, 275, 283, 10659, 7, 272, 6249, 63, 4030, 39, 3830, 2940, 275, 283, 15437, 7, 272, 6249, 63, 1439, 2504, 1092, 33, 1244, 2846, 275, 283, 331, 346, 293, 1225, 697, 7, 272, 6249, 63, 568, 63, 19495, 275, 283, 262, 13, 4844, 7, 272, 4384, 726, 5383, 275, 334, 2846, 63, 4657, 4427, 12, 6249, 63, 4030, 39, 3830, 2940, 12, 6249, 63, 1439, 2504, 1092, 33, 1244, 2846, 12, 6249, 63, 568, 63, 19495, 9, 339, 13513, 726, 63, 3593, 275, 1557, 8762, 59, 708, 77, 7, 272, 13513, 726, 63, 3902, 275, 1557, 8762, 59, 16, 77, 7, 339, 327, 2900, 2073, 3004, 626, 883, 506, 4847, 315, 3101, 1056, 14, 272, 31325, 63, 18166, 275, 334, 267, 283, 576, 297, 267, 283, 19127, 297, 267, 283, 1802, 297, 267, 283, 354, 297, 267, 283, 2634, 297, 267, 283, 2969, 297, 267, 283, 4614, 297, 267, 283, 1365, 297, 267, 283, 6234, 297, 267, 283, 13209, 297, 267, 283, 1501, 7, 272, 776, 339, 5363, 63, 14747, 63, 879, 2684, 63, 28879, 63, 7326, 22243, 275, 295, 14, 2014, 8, 82, 2344, 267, 971, 88, 17, 66, 4735, 77, 3672, 77, 259, 327, 9814, 1006, 25600, 4772, 8013, 14, 267, 21281, 295, 14, 16075, 9, 339, 5363, 63, 14747, 63, 906, 1554, 1206, 63, 18817, 5067, 21287, 275, 295, 14, 2014, 8, 82, 2344, 267, 971, 78, 60, 83, 11, 257, 327, 9814, 8057, 436, 1006, 9186, 704, 31926, 2410, 652, 14, 267, 21281, 295, 14, 16075, 9, 339, 768, 3744, 272, 347, 1586, 63, 1160, 8, 1886, 12, 1788, 304, 267, 408, 1002, 849, 1564, 1978, 315, 1318, 1475, 14, 398, 710, 2138, 1978, 1471, 506, 315, 314, 2011, 1475, 2382, 5957, 8823, 267, 2839, 1321, 7545, 314, 849, 1978, 14, 961, 4910, 626, 1006, 314, 3762, 787, 267, 4829, 436, 314, 1572, 1947, 365, 8717, 543, 283, 885, 7, 1572, 14, 398, 3033, 26, 288, 1788, 334, 495, 304, 5458, 1788, 465, 5489, 315, 666, 15, 5876, 14, 398, 1803, 26, 288, 620, 26, 9630, 1978, 315, 314, 2011, 1475, 465, 367, 5957, 8823, 14, 267, 408, 398, 1978, 275, 843, 423, 739, 63, 1927, 360, 576, 15, 5876, 297, 1788, 9, 267, 1978, 275, 295, 14, 954, 8, 82, 2344, 288, 665, 2634, 30, 259, 327, 9814, 4652, 1947, 14, 288, 21281, 283, 885, 297, 1978, 12, 3285, 29, 264, 14, 16075, 9, 398, 1978, 275, 295, 14, 954, 8, 82, 2344, 288, 24936, 7272, 51, 21324, 19109, 257, 327, 9814, 1263, 1947, 315, 314, 1978, 14, 288, 21281, 3260, 1978, 12, 3285, 29, 264, 14, 16075, 9, 398, 327, 1010, 1930, 402, 314, 8744, 1978, 12, 2337, 365, 282, 665, 576, 30, 1947, 626, 16733, 267, 327, 2701, 289, 631, 1004, 14, 9336, 1006, 7009, 1343, 687, 314, 1642, 1004, 12, 314, 267, 327, 704, 31926, 883, 506, 4829, 687, 3602, 402, 314, 1059, 14, 267, 1978, 275, 1978, 14, 10124, 342, 398, 372, 1978, 339, 768, 3744, 272, 347, 1586, 63, 13207, 8, 1886, 12, 1788, 304, 267, 408, 1002, 5218, 13659, 2884, 14, 398, 3033, 288, 1788, 334, 495, 304, 2812, 402, 314, 5218, 13659, 570, 14, 267, 408, 398, 372, 843, 423, 739, 63, 1927, 360, 576, 15, 13207, 297, 1788, 9, 339, 768, 4639, 272, 347, 2813, 63, 22204, 8, 1188, 304, 267, 408, 5587, 1006, 25600, 4772, 9479, 687, 1627, 1059, 14, 398, 3033, 26, 288, 1245, 334, 495, 304, 6430, 1314, 25600, 4772, 9479, 787, 4829, 14, 398, 1803, 26, 288, 620, 26, 14766, 1245, 1325, 1928, 25600, 4772, 8013, 14, 267, 408, 398 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 221, 6988, 19596, 13, 3761, 13, 7544, 26, 437, 12006, 13, 19, 14, 16, 13, 269, 13, 18103, 199, 3, 199, 3, 221, 6895, 711, 647, 446, 2032, 16367, 436, 21964, 12681, 5256, 14, 199, 3, 221, 1898, 9708, 13, 13934, 5311, 3258, 8810, 1603, 14, 7964, 1151, 834, 287, 221, 665, 416, 1151, 834, 287, 14, 426, 3258, 8810, 14, 74, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 221, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 221, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 3267, 199, 3, 221, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 221, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 221, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 221, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 221, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 221, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 221, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 221, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 624, 3676, 26, 8307, 10897, 5343, 1041, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 5890, 199, 646, 747, 14, 515, 199, 646, 295, 199, 646, 984, 199, 199, 646, 2022, 199, 646, 5496, 63, 4435, 199, 199, 504, 2022, 3629, 492, 28090, 23, 8640, 12, 15397, 12407, 421, 199, 533, 11642, 8, 785, 304, 272, 408, 9417, 10897, 5343, 14, 339, 961, 1021, 32005, 6866, 2005, 402, 314, 4514, 687, 314, 272, 9920, 1233, 14, 710, 12016, 365, 370, 5126, 5124, 315, 642, 859, 272, 370, 506, 7688, 370, 492, 642, 859, 26523, 14, 272, 408, 339, 3651, 3657, 63, 4961, 275, 283, 12682, 13, 996, 13, 996, 52, 996, 26, 996, 26, 996, 14, 19983, 11, 383, 26, 383, 7, 272, 5025, 2596, 63, 4961, 275, 283, 12682, 13, 1644, 13, 996, 52, 996, 26, 996, 26, 996, 14, 19983, 11, 383, 26, 383, 7, 272, 3651, 3657, 63, 7433, 275, 283, 10680, 13, 709, 13, 1079, 52, 1167, 26, 1367, 26, 2192, 14, 19983, 11, 383, 26, 383, 7, 339, 6249, 63, 4657, 4427, 275, 283, 10659, 7, 272, 6249, 63, 4030, 39, 3830, 2940, 275, 283, 15437, 7, 272, 6249, 63, 1439, 2504, 1092, 33, 1244, 2846, 275, 283, 331, 346, 293, 1225, 697, 7, 272, 6249, 63, 568, 63, 19495, 275, 283, 262, 13, 4844, 7, 272, 4384, 726, 5383, 275, 334, 2846, 63, 4657, 4427, 12, 6249, 63, 4030, 39, 3830, 2940, 12, 6249, 63, 1439, 2504, 1092, 33, 1244, 2846, 12, 6249, 63, 568, 63, 19495, 9, 339, 13513, 726, 63, 3593, 275, 1557, 8762, 59, 708, 77, 7, 272, 13513, 726, 63, 3902, 275, 1557, 8762, 59, 16, 77, 7, 339, 327, 2900, 2073, 3004, 626, 883, 506, 4847, 315, 3101, 1056, 14, 272, 31325, 63, 18166, 275, 334, 267, 283, 576, 297, 267, 283, 19127, 297, 267, 283, 1802, 297, 267, 283, 354, 297, 267, 283, 2634, 297, 267, 283, 2969, 297, 267, 283, 4614, 297, 267, 283, 1365, 297, 267, 283, 6234, 297, 267, 283, 13209, 297, 267, 283, 1501, 7, 272, 776, 339, 5363, 63, 14747, 63, 879, 2684, 63, 28879, 63, 7326, 22243, 275, 295, 14, 2014, 8, 82, 2344, 267, 971, 88, 17, 66, 4735, 77, 3672, 77, 259, 327, 9814, 1006, 25600, 4772, 8013, 14, 267, 21281, 295, 14, 16075, 9, 339, 5363, 63, 14747, 63, 906, 1554, 1206, 63, 18817, 5067, 21287, 275, 295, 14, 2014, 8, 82, 2344, 267, 971, 78, 60, 83, 11, 257, 327, 9814, 8057, 436, 1006, 9186, 704, 31926, 2410, 652, 14, 267, 21281, 295, 14, 16075, 9, 339, 768, 3744, 272, 347, 1586, 63, 1160, 8, 1886, 12, 1788, 304, 267, 408, 1002, 849, 1564, 1978, 315, 1318, 1475, 14, 398, 710, 2138, 1978, 1471, 506, 315, 314, 2011, 1475, 2382, 5957, 8823, 267, 2839, 1321, 7545, 314, 849, 1978, 14, 961, 4910, 626, 1006, 314, 3762, 787, 267, 4829, 436, 314, 1572, 1947, 365, 8717, 543, 283, 885, 7, 1572, 14, 398, 3033, 26, 288, 1788, 334, 495, 304, 5458, 1788, 465, 5489, 315, 666, 15, 5876, 14, 398, 1803, 26, 288, 620, 26, 9630, 1978, 315, 314, 2011, 1475, 465, 367, 5957, 8823, 14, 267, 408, 398, 1978, 275, 843, 423, 739, 63, 1927, 360, 576, 15, 5876, 297, 1788, 9, 267, 1978, 275, 295, 14, 954, 8, 82, 2344, 288, 665, 2634, 30, 259, 327, 9814, 4652, 1947, 14, 288, 21281, 283, 885, 297, 1978, 12, 3285, 29, 264, 14, 16075, 9, 398, 1978, 275, 295, 14, 954, 8, 82, 2344, 288, 24936, 7272, 51, 21324, 19109, 257, 327, 9814, 1263, 1947, 315, 314, 1978, 14, 288, 21281, 3260, 1978, 12, 3285, 29, 264, 14, 16075, 9, 398, 327, 1010, 1930, 402, 314, 8744, 1978, 12, 2337, 365, 282, 665, 576, 30, 1947, 626, 16733, 267, 327, 2701, 289, 631, 1004, 14, 9336, 1006, 7009, 1343, 687, 314, 1642, 1004, 12, 314, 267, 327, 704, 31926, 883, 506, 4829, 687, 3602, 402, 314, 1059, 14, 267, 1978, 275, 1978, 14, 10124, 342, 398, 372, 1978, 339, 768, 3744, 272, 347, 1586, 63, 13207, 8, 1886, 12, 1788, 304, 267, 408, 1002, 5218, 13659, 2884, 14, 398, 3033, 288, 1788, 334, 495, 304, 2812, 402, 314, 5218, 13659, 570, 14, 267, 408, 398, 372, 843, 423, 739, 63, 1927, 360, 576, 15, 13207, 297, 1788, 9, 339, 768, 4639, 272, 347, 2813, 63, 22204, 8, 1188, 304, 267, 408, 5587, 1006, 25600, 4772, 9479, 687, 1627, 1059, 14, 398, 3033, 26, 288, 1245, 334, 495, 304, 6430, 1314, 25600, 4772, 9479, 787, 4829, 14, 398, 1803, 26, 288, 620, 26, 14766, 1245, 1325, 1928, 25600, 4772, 8013, 14, 267, 408, 398, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
blighj/django
django/utils/dateparse.py
22
4167
"""Functions to parse datetime objects.""" # We're using regular expressions rather than time.strptime because: # - They provide both validation and parsing. # - They're more flexible for datetimes. # - The date/datetime/time constructors produce friendlier error messages. import datetime import re from django.utils.timezone import get_fixed_timezone, utc date_re = re.compile( r'(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})$' ) time_re = re.compile( r'(?P<hour>\d{1,2}):(?P<minute>\d{1,2})' r'(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?' ) datetime_re = re.compile( r'(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})' r'[T ](?P<hour>\d{1,2}):(?P<minute>\d{1,2})' r'(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?' r'(?P<tzinfo>Z|[+-]\d{2}(?::?\d{2})?)?$' ) standard_duration_re = re.compile( r'^' r'(?:(?P<days>-?\d+) (days?, )?)?' r'((?:(?P<hours>-?\d+):)(?=\d+:\d+))?' r'(?:(?P<minutes>-?\d+):)?' r'(?P<seconds>-?\d+)' r'(?:\.(?P<microseconds>\d{1,6})\d{0,6})?' r'$' ) # Support the sections of ISO 8601 date representation that are accepted by # timedelta iso8601_duration_re = re.compile( r'^(?P<sign>[-+]?)' r'P' r'(?:(?P<days>\d+(.\d+)?)D)?' r'(?:T' r'(?:(?P<hours>\d+(.\d+)?)H)?' r'(?:(?P<minutes>\d+(.\d+)?)M)?' r'(?:(?P<seconds>\d+(.\d+)?)S)?' r')?' r'$' ) def parse_date(value): """Parse a string and return a datetime.date. Raise ValueError if the input is well formatted but not a valid date. Return None if the input isn't well formatted. """ match = date_re.match(value) if match: kw = {k: int(v) for k, v in match.groupdict().items()} return datetime.date(**kw) def parse_time(value): """Parse a string and return a datetime.time. This function doesn't support time zone offsets. Raise ValueError if the input is well formatted but not a valid time. Return None if the input isn't well formatted, in particular if it contains an offset. """ match = time_re.match(value) if match: kw = match.groupdict() if kw['microsecond']: kw['microsecond'] = kw['microsecond'].ljust(6, '0') kw = {k: int(v) for k, v in kw.items() if v is not None} return datetime.time(**kw) def parse_datetime(value): """Parse a string and return a datetime.datetime. This function supports time zone offsets. When the input contains one, the output uses a timezone with a fixed offset from UTC. Raise ValueError if the input is well formatted but not a valid datetime. Return None if the input isn't well formatted. """ match = datetime_re.match(value) if match: kw = match.groupdict() if kw['microsecond']: kw['microsecond'] = kw['microsecond'].ljust(6, '0') tzinfo = kw.pop('tzinfo') if tzinfo == 'Z': tzinfo = utc elif tzinfo is not None: offset_mins = int(tzinfo[-2:]) if len(tzinfo) > 3 else 0 offset = 60 * int(tzinfo[1:3]) + offset_mins if tzinfo[0] == '-': offset = -offset tzinfo = get_fixed_timezone(offset) kw = {k: int(v) for k, v in kw.items() if v is not None} kw['tzinfo'] = tzinfo return datetime.datetime(**kw) def parse_duration(value): """Parse a duration string and return a datetime.timedelta. The preferred format for durations in Django is '%d %H:%M:%S.%f'. Also supports ISO 8601 representation. """ match = standard_duration_re.match(value) if not match: match = iso8601_duration_re.match(value) if match: kw = match.groupdict() sign = -1 if kw.pop('sign', '+') == '-' else 1 if kw.get('microseconds'): kw['microseconds'] = kw['microseconds'].ljust(6, '0') if kw.get('seconds') and kw.get('microseconds') and kw['seconds'].startswith('-'): kw['microseconds'] = '-' + kw['microseconds'] kw = {k: float(v) for k, v in kw.items() if v is not None} return sign * datetime.timedelta(**kw)
bsd-3-clause
[ 624, 13967, 370, 2198, 2197, 2251, 1041, 199, 199, 3, 2136, 3984, 1808, 5578, 8455, 7830, 2419, 900, 14, 9866, 2952, 26, 199, 3, 446, 9322, 5647, 3865, 6411, 436, 6057, 14, 199, 3, 446, 9322, 3984, 1655, 26841, 367, 29297, 14, 199, 3, 446, 710, 1434, 15, 2083, 15, 521, 31604, 7389, 32506, 5697, 1125, 3788, 14, 199, 199, 646, 2197, 199, 646, 295, 199, 199, 504, 1639, 14, 1208, 14, 7145, 492, 664, 63, 5964, 63, 7145, 12, 19314, 199, 199, 602, 63, 264, 275, 295, 14, 2014, 8, 272, 519, 10120, 48, 28, 3403, 3072, 68, 91, 20, 1552, 13, 2229, 48, 28, 4482, 3072, 68, 91, 17, 12, 18, 1552, 13, 2229, 48, 28, 2977, 3072, 68, 91, 17, 12, 18, 1552, 12913, 199, 9, 199, 199, 521, 63, 264, 275, 295, 14, 2014, 8, 272, 519, 10120, 48, 28, 5180, 3072, 68, 91, 17, 12, 18, 22558, 2229, 48, 28, 10698, 3072, 68, 91, 17, 12, 18, 29668, 272, 519, 10120, 447, 2229, 48, 28, 4375, 3072, 68, 91, 17, 12, 18, 1552, 15840, 14, 2229, 48, 28, 16627, 3072, 68, 91, 17, 12, 22, 30446, 68, 91, 16, 12, 22, 1552, 31, 5547, 7, 199, 9, 199, 199, 2083, 63, 264, 275, 295, 14, 2014, 8, 272, 519, 10120, 48, 28, 3403, 3072, 68, 91, 20, 1552, 13, 2229, 48, 28, 4482, 3072, 68, 91, 17, 12, 18, 1552, 13, 2229, 48, 28, 2977, 3072, 68, 91, 17, 12, 18, 29668, 272, 519, 3894, 52, 1622, 2229, 48, 28, 5180, 3072, 68, 91, 17, 12, 18, 22558, 2229, 48, 28, 10698, 3072, 68, 91, 17, 12, 18, 29668, 272, 519, 10120, 447, 2229, 48, 28, 4375, 3072, 68, 91, 17, 12, 18, 1552, 15840, 14, 2229, 48, 28, 16627, 3072, 68, 91, 17, 12, 22, 30446, 68, 91, 16, 12, 22, 1552, 31, 5547, 7, 272, 519, 10120, 48, 28, 9374, 30, 58, 17884, 16341, 7272, 68, 91, 18, 93, 2229, 447, 8995, 68, 91, 18, 1552, 31, 5547, 12913, 199, 9, 199, 199, 6807, 63, 5553, 63, 264, 275, 295, 14, 2014, 8, 272, 519, 4289, 7, 272, 519, 20459, 2229, 48, 28, 4899, 24860, 8995, 68, 8771, 334, 4899, 22556, 24836, 5547, 7, 272, 519, 7, 17304, 26, 2229, 48, 28, 8419, 24860, 8995, 68, 11, 304, 18168, 9529, 68, 11, 3427, 68, 11, 430, 14069, 272, 519, 20459, 2229, 48, 28, 10430, 24860, 8995, 68, 11, 304, 5547, 7, 272, 519, 10120, 48, 28, 4515, 24860, 8995, 68, 29600, 272, 519, 10120, 3427, 14, 2229, 48, 28, 18144, 3072, 68, 91, 17, 12, 22, 30446, 68, 91, 16, 12, 22, 1552, 14069, 272, 519, 7, 12913, 199, 9, 199, 199, 3, 12502, 314, 10189, 402, 9055, 10300, 614, 1434, 6025, 626, 787, 10226, 701, 199, 3, 6871, 199, 4595, 15363, 63, 5553, 63, 264, 275, 295, 14, 2014, 8, 272, 519, 24550, 48, 28, 1037, 30, 27371, 11843, 3171, 272, 519, 7, 48, 7, 272, 519, 20459, 2229, 48, 28, 4899, 3072, 68, 15622, 3134, 68, 19544, 9, 36, 5547, 7, 272, 519, 20459, 52, 7, 272, 519, 20459, 2229, 48, 28, 8419, 3072, 68, 15622, 3134, 68, 19544, 9, 40, 5547, 7, 272, 519, 20459, 2229, 48, 28, 10430, 3072, 68, 15622, 3134, 68, 19544, 9, 45, 5547, 7, 272, 519, 20459, 2229, 48, 28, 4515, 3072, 68, 15622, 3134, 68, 19544, 9, 51, 5547, 7, 272, 519, 358, 14069, 272, 519, 7, 12913, 199, 9, 421, 199, 318, 2198, 63, 602, 8, 585, 304, 272, 408, 4003, 282, 1059, 436, 372, 282, 2197, 14, 602, 14, 339, 14771, 1722, 340, 314, 1324, 365, 5521, 7871, 1325, 440, 282, 1686, 1434, 14, 272, 1432, 488, 340, 314, 1324, 5712, 1133, 5521, 7871, 14, 272, 408, 272, 1336, 275, 1434, 63, 264, 14, 1431, 8, 585, 9, 272, 340, 1336, 26, 267, 4775, 275, 469, 75, 26, 1109, 8, 86, 9, 367, 1022, 12, 373, 315, 1336, 14, 20567, 1252, 1744, 12737, 267, 372, 2197, 14, 602, 3682, 829, 9, 421, 199, 318, 2198, 63, 521, 8, 585, 304, 272, 408, 4003, 282, 1059, 436, 372, 282, 2197, 14, 521, 14, 339, 961, 805, 3181, 1133, 2291, 900, 5718, 15340, 14, 339, 14771, 1722, 340, 314, 1324, 365, 5521, 7871, 1325, 440, 282, 1686, 900, 14, 272, 1432, 488, 340, 314, 1324, 5712, 1133, 5521, 7871, 12, 315, 6770, 340, 652, 272, 3509, 376, 3268, 14, 272, 408, 272, 1336, 275, 900, 63, 264, 14, 1431, 8, 585, 9, 272, 340, 1336, 26, 267, 4775, 275, 1336, 14, 20567, 342, 267, 340, 4775, 459, 16627, 2565, 288, 4775, 459, 16627, 418, 275, 4775, 459, 16627, 2278, 19996, 8, 22, 12, 283, 16, 358, 267, 4775, 275, 469, 75, 26, 1109, 8, 86, 9, 367, 1022, 12, 373, 315, 4775, 14, 1744, 342, 340, 373, 365, 440, 488, 93, 267, 372, 2197, 14, 521, 3682, 829, 9, 421, 199, 318, 2198, 63, 2083, 8, 585, 304, 272, 408, 4003, 282, 1059, 436, 372, 282, 2197, 14, 2083, 14, 339, 961, 805, 5171, 900, 5718, 15340, 14, 3979, 314, 1324, 3509, 1373, 12, 272, 314, 1072, 4440, 282, 7137, 543, 282, 6317, 3268, 687, 12174, 14, 339, 14771, 1722, 340, 314, 1324, 365, 5521, 7871, 1325, 440, 282, 1686, 2197, 14, 272, 1432, 488, 340, 314, 1324, 5712, 1133, 5521, 7871, 14, 272, 408, 272, 1336, 275, 2197, 63, 264, 14, 1431, 8, 585, 9, 272, 340, 1336, 26, 267, 4775, 275, 1336, 14, 20567, 342, 267, 340, 4775, 459, 16627, 2565, 288, 4775, 459, 16627, 418, 275, 4775, 459, 16627, 2278, 19996, 8, 22, 12, 283, 16, 358, 267, 10313, 275, 4775, 14, 1935, 360, 9374, 358, 267, 340, 10313, 508, 283, 58, 356, 288, 10313, 275, 19314, 267, 916, 10313, 365, 440, 488, 26, 288, 3268, 63, 29361, 275, 1109, 8, 9374, 1988, 18, 5728, 340, 822, 8, 9374, 9, 690, 650, 587, 378, 288, 3268, 275, 5212, 627, 1109, 8, 9374, 59, 17, 26, 19, 566, 435, 3268, 63, 29361, 288, 340, 10313, 59, 16, 61, 508, 20905, 355, 3268, 275, 446, 2743, 288, 10313, 275, 664, 63, 5964, 63, 7145, 8, 2743, 9 ]
[ 13967, 370, 2198, 2197, 2251, 1041, 199, 199, 3, 2136, 3984, 1808, 5578, 8455, 7830, 2419, 900, 14, 9866, 2952, 26, 199, 3, 446, 9322, 5647, 3865, 6411, 436, 6057, 14, 199, 3, 446, 9322, 3984, 1655, 26841, 367, 29297, 14, 199, 3, 446, 710, 1434, 15, 2083, 15, 521, 31604, 7389, 32506, 5697, 1125, 3788, 14, 199, 199, 646, 2197, 199, 646, 295, 199, 199, 504, 1639, 14, 1208, 14, 7145, 492, 664, 63, 5964, 63, 7145, 12, 19314, 199, 199, 602, 63, 264, 275, 295, 14, 2014, 8, 272, 519, 10120, 48, 28, 3403, 3072, 68, 91, 20, 1552, 13, 2229, 48, 28, 4482, 3072, 68, 91, 17, 12, 18, 1552, 13, 2229, 48, 28, 2977, 3072, 68, 91, 17, 12, 18, 1552, 12913, 199, 9, 199, 199, 521, 63, 264, 275, 295, 14, 2014, 8, 272, 519, 10120, 48, 28, 5180, 3072, 68, 91, 17, 12, 18, 22558, 2229, 48, 28, 10698, 3072, 68, 91, 17, 12, 18, 29668, 272, 519, 10120, 447, 2229, 48, 28, 4375, 3072, 68, 91, 17, 12, 18, 1552, 15840, 14, 2229, 48, 28, 16627, 3072, 68, 91, 17, 12, 22, 30446, 68, 91, 16, 12, 22, 1552, 31, 5547, 7, 199, 9, 199, 199, 2083, 63, 264, 275, 295, 14, 2014, 8, 272, 519, 10120, 48, 28, 3403, 3072, 68, 91, 20, 1552, 13, 2229, 48, 28, 4482, 3072, 68, 91, 17, 12, 18, 1552, 13, 2229, 48, 28, 2977, 3072, 68, 91, 17, 12, 18, 29668, 272, 519, 3894, 52, 1622, 2229, 48, 28, 5180, 3072, 68, 91, 17, 12, 18, 22558, 2229, 48, 28, 10698, 3072, 68, 91, 17, 12, 18, 29668, 272, 519, 10120, 447, 2229, 48, 28, 4375, 3072, 68, 91, 17, 12, 18, 1552, 15840, 14, 2229, 48, 28, 16627, 3072, 68, 91, 17, 12, 22, 30446, 68, 91, 16, 12, 22, 1552, 31, 5547, 7, 272, 519, 10120, 48, 28, 9374, 30, 58, 17884, 16341, 7272, 68, 91, 18, 93, 2229, 447, 8995, 68, 91, 18, 1552, 31, 5547, 12913, 199, 9, 199, 199, 6807, 63, 5553, 63, 264, 275, 295, 14, 2014, 8, 272, 519, 4289, 7, 272, 519, 20459, 2229, 48, 28, 4899, 24860, 8995, 68, 8771, 334, 4899, 22556, 24836, 5547, 7, 272, 519, 7, 17304, 26, 2229, 48, 28, 8419, 24860, 8995, 68, 11, 304, 18168, 9529, 68, 11, 3427, 68, 11, 430, 14069, 272, 519, 20459, 2229, 48, 28, 10430, 24860, 8995, 68, 11, 304, 5547, 7, 272, 519, 10120, 48, 28, 4515, 24860, 8995, 68, 29600, 272, 519, 10120, 3427, 14, 2229, 48, 28, 18144, 3072, 68, 91, 17, 12, 22, 30446, 68, 91, 16, 12, 22, 1552, 14069, 272, 519, 7, 12913, 199, 9, 199, 199, 3, 12502, 314, 10189, 402, 9055, 10300, 614, 1434, 6025, 626, 787, 10226, 701, 199, 3, 6871, 199, 4595, 15363, 63, 5553, 63, 264, 275, 295, 14, 2014, 8, 272, 519, 24550, 48, 28, 1037, 30, 27371, 11843, 3171, 272, 519, 7, 48, 7, 272, 519, 20459, 2229, 48, 28, 4899, 3072, 68, 15622, 3134, 68, 19544, 9, 36, 5547, 7, 272, 519, 20459, 52, 7, 272, 519, 20459, 2229, 48, 28, 8419, 3072, 68, 15622, 3134, 68, 19544, 9, 40, 5547, 7, 272, 519, 20459, 2229, 48, 28, 10430, 3072, 68, 15622, 3134, 68, 19544, 9, 45, 5547, 7, 272, 519, 20459, 2229, 48, 28, 4515, 3072, 68, 15622, 3134, 68, 19544, 9, 51, 5547, 7, 272, 519, 358, 14069, 272, 519, 7, 12913, 199, 9, 421, 199, 318, 2198, 63, 602, 8, 585, 304, 272, 408, 4003, 282, 1059, 436, 372, 282, 2197, 14, 602, 14, 339, 14771, 1722, 340, 314, 1324, 365, 5521, 7871, 1325, 440, 282, 1686, 1434, 14, 272, 1432, 488, 340, 314, 1324, 5712, 1133, 5521, 7871, 14, 272, 408, 272, 1336, 275, 1434, 63, 264, 14, 1431, 8, 585, 9, 272, 340, 1336, 26, 267, 4775, 275, 469, 75, 26, 1109, 8, 86, 9, 367, 1022, 12, 373, 315, 1336, 14, 20567, 1252, 1744, 12737, 267, 372, 2197, 14, 602, 3682, 829, 9, 421, 199, 318, 2198, 63, 521, 8, 585, 304, 272, 408, 4003, 282, 1059, 436, 372, 282, 2197, 14, 521, 14, 339, 961, 805, 3181, 1133, 2291, 900, 5718, 15340, 14, 339, 14771, 1722, 340, 314, 1324, 365, 5521, 7871, 1325, 440, 282, 1686, 900, 14, 272, 1432, 488, 340, 314, 1324, 5712, 1133, 5521, 7871, 12, 315, 6770, 340, 652, 272, 3509, 376, 3268, 14, 272, 408, 272, 1336, 275, 900, 63, 264, 14, 1431, 8, 585, 9, 272, 340, 1336, 26, 267, 4775, 275, 1336, 14, 20567, 342, 267, 340, 4775, 459, 16627, 2565, 288, 4775, 459, 16627, 418, 275, 4775, 459, 16627, 2278, 19996, 8, 22, 12, 283, 16, 358, 267, 4775, 275, 469, 75, 26, 1109, 8, 86, 9, 367, 1022, 12, 373, 315, 4775, 14, 1744, 342, 340, 373, 365, 440, 488, 93, 267, 372, 2197, 14, 521, 3682, 829, 9, 421, 199, 318, 2198, 63, 2083, 8, 585, 304, 272, 408, 4003, 282, 1059, 436, 372, 282, 2197, 14, 2083, 14, 339, 961, 805, 5171, 900, 5718, 15340, 14, 3979, 314, 1324, 3509, 1373, 12, 272, 314, 1072, 4440, 282, 7137, 543, 282, 6317, 3268, 687, 12174, 14, 339, 14771, 1722, 340, 314, 1324, 365, 5521, 7871, 1325, 440, 282, 1686, 2197, 14, 272, 1432, 488, 340, 314, 1324, 5712, 1133, 5521, 7871, 14, 272, 408, 272, 1336, 275, 2197, 63, 264, 14, 1431, 8, 585, 9, 272, 340, 1336, 26, 267, 4775, 275, 1336, 14, 20567, 342, 267, 340, 4775, 459, 16627, 2565, 288, 4775, 459, 16627, 418, 275, 4775, 459, 16627, 2278, 19996, 8, 22, 12, 283, 16, 358, 267, 10313, 275, 4775, 14, 1935, 360, 9374, 358, 267, 340, 10313, 508, 283, 58, 356, 288, 10313, 275, 19314, 267, 916, 10313, 365, 440, 488, 26, 288, 3268, 63, 29361, 275, 1109, 8, 9374, 1988, 18, 5728, 340, 822, 8, 9374, 9, 690, 650, 587, 378, 288, 3268, 275, 5212, 627, 1109, 8, 9374, 59, 17, 26, 19, 566, 435, 3268, 63, 29361, 288, 340, 10313, 59, 16, 61, 508, 20905, 355, 3268, 275, 446, 2743, 288, 10313, 275, 664, 63, 5964, 63, 7145, 8, 2743, 9, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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bin/python2.4 -tt # Copyright 2010 Google Inc. # Licensed under the Apache License, Version 2.0 # http://www.apache.org/licenses/LICENSE-2.0 # Google's Python Class # http://code.google.com/edu/languages/google-python-class/ # Additional basic string exercises # D. verbing # Given a string, if its length is at least 3, # add 'ing' to its end. # Unless it already ends in 'ing', in which case # add 'ly' instead. # If the string length is less than 3, leave it unchanged. # Return the resulting string. def verbing(s): # +++your code here+++ # LAB(begin solution) if len(s) >= 3: if s[-3:] != 'ing': s = s + 'ing' else: s = s + 'ly' return s # LAB(replace solution) # return # LAB(end solution) # E. not_bad # Given a string, find the first appearance of the # substring 'not' and 'bad'. If the 'bad' follows # the 'not', replace the whole 'not'...'bad' substring # with 'good'. # Return the resulting string. # So 'This dinner is not that bad!' yields: # This dinner is good! def not_bad(s): # +++your code here+++ # LAB(begin solution) n = s.find('not') b = s.find('bad') if n != -1 and b != -1 and b > n: s = s[:n] + 'good' + s[b+3:] return s # LAB(replace solution) # return # LAB(end solution) # F. front_back # Consider dividing a string into two halves. # If the length is even, the front and back halves are the same length. # If the length is odd, we'll say that the extra char goes in the front half. # e.g. 'abcde', the front half is 'abc', the back half 'de'. # Given 2 strings, a and b, return a string of the form # a-front + b-front + a-back + b-back def front_back(a, b): # +++your code here+++ # LAB(begin solution) # Figure out the middle position of each string. a_middle = len(a) / 2 b_middle = len(b) / 2 if len(a) % 2 == 1: # add 1 if length is odd a_middle = a_middle + 1 if len(b) % 2 == 1: b_middle = b_middle + 1 return a[:a_middle] + b[:b_middle] + a[a_middle:] + b[b_middle:] # LAB(replace solution) # return # LAB(end solution) # Simple provided test() function used in main() to print # what each function returns vs. what it's supposed to return. def test(got, expected): if got == expected: prefix = ' OK ' else: prefix = ' X ' print '%s got: %s expected: %s' % (prefix, repr(got), repr(expected)) # main() calls the above functions with interesting inputs, # using the above test() to check if the result is correct or not. def main(): print 'verbing' test(verbing('hail'), 'hailing') test(verbing('swiming'), 'swimingly') test(verbing('do'), 'do') print print 'not_bad' test(not_bad('This movie is not so bad'), 'This movie is good') test(not_bad('This dinner is not that bad!'), 'This dinner is good!') test(not_bad('This tea is not hot'), 'This tea is not hot') test(not_bad("It's bad yet not"), "It's bad yet not") print print 'front_back' test(front_back('abcd', 'xy'), 'abxcdy') test(front_back('abcde', 'xyz'), 'abcxydez') test(front_back('Kitten', 'Donut'), 'KitDontenut') if __name__ == '__main__': main()
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1548, 18, 14, 20, 446, 6215, 199, 3, 1898, 7129, 4475, 3277, 14, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 199, 3, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 199, 3, 4475, 1159, 2018, 8089, 199, 3, 1455, 921, 600, 14, 3098, 14, 957, 15, 8654, 15, 13209, 15, 3098, 13, 1548, 13, 533, 15, 199, 199, 3, 10961, 5678, 1059, 444, 281, 559, 874, 199, 199, 3, 577, 14, 809, 10911, 199, 3, 9138, 282, 1059, 12, 340, 2399, 2582, 365, 737, 5210, 650, 12, 199, 3, 1050, 283, 316, 7, 370, 2399, 1284, 14, 199, 3, 4158, 652, 2575, 11187, 315, 283, 316, 297, 315, 1314, 1930, 199, 3, 1050, 283, 590, 7, 3140, 14, 199, 3, 982, 314, 1059, 2582, 365, 6656, 2419, 650, 12, 10137, 652, 14874, 14, 199, 3, 1432, 314, 9183, 1059, 14, 199, 318, 809, 10911, 8, 83, 304, 523, 327, 435, 4176, 12695, 1233, 2348, 4176, 11, 523, 327, 491, 1217, 8, 5037, 8744, 9, 523, 340, 822, 8, 83, 9, 2356, 650, 26, 272, 340, 308, 1988, 19, 2938, 1137, 283, 316, 356, 308, 275, 308, 435, 283, 316, 7, 272, 587, 26, 308, 275, 308, 435, 283, 590, 7, 523, 372, 308, 523, 327, 491, 1217, 8, 1814, 8744, 9, 523, 327, 372, 523, 327, 491, 1217, 8, 500, 8744, 9, 421, 199, 3, 662, 14, 440, 63, 4087, 199, 3, 9138, 282, 1059, 12, 2342, 314, 1642, 7468, 554, 402, 314, 199, 3, 20597, 283, 1397, 7, 436, 283, 4087, 1370, 982, 314, 283, 4087, 7, 11924, 199, 3, 314, 283, 1397, 297, 3350, 314, 8852, 283, 1397, 7, 13698, 4087, 7, 20597, 199, 3, 543, 283, 8302, 1370, 199, 3, 1432, 314, 9183, 1059, 14, 199, 3, 2002, 283, 2765, 366, 5216, 365, 440, 626, 4875, 11213, 14801, 26, 199, 3, 961, 366, 5216, 365, 6954, 1, 199, 318, 440, 63, 4087, 8, 83, 304, 523, 327, 435, 4176, 12695, 1233, 2348, 4176, 11, 523, 327, 491, 1217, 8, 5037, 8744, 9, 523, 302, 275, 308, 14, 1623, 360, 1397, 358, 523, 330, 275, 308, 14, 1623, 360, 4087, 358, 523, 340, 302, 1137, 446, 17, 436, 330, 1137, 446, 17, 436, 330, 690, 302, 26, 272, 308, 275, 308, 1491, 78, 61, 435, 283, 8302, 7, 435, 308, 59, 66, 11, 19, 2938, 523, 372, 308, 523, 327, 491, 1217, 8, 1814, 8744, 9, 523, 327, 372, 523, 327, 491, 1217, 8, 500, 8744, 9, 421, 199, 3, 481, 14, 13738, 63, 894, 199, 3, 24413, 487, 11604, 282, 1059, 1901, 2877, 22939, 2310, 14, 199, 3, 982, 314, 2582, 365, 2755, 12, 314, 13738, 436, 1771, 22939, 2310, 787, 314, 2011, 2582, 14, 199, 3, 982, 314, 2582, 365, 16699, 12, 781, 7171, 14722, 626, 314, 2402, 1495, 13538, 315, 314, 13738, 12995, 14, 199, 3, 325, 14, 71, 14, 283, 28109, 297, 314, 13738, 12995, 365, 283, 3175, 297, 314, 1771, 12995, 283, 271, 1370, 199, 3, 9138, 499, 3326, 12, 282, 436, 330, 12, 372, 282, 1059, 402, 314, 1824, 199, 3, 221, 282, 13, 14708, 435, 330, 13, 14708, 435, 282, 13, 894, 435, 330, 13, 894, 199, 318, 13738, 63, 894, 8, 65, 12, 330, 304, 523, 327, 435, 4176, 12695, 1233, 2348, 4176, 11, 523, 327, 491, 1217, 8, 5037, 8744, 9, 523, 327, 16266, 734, 314, 12180, 3421, 402, 1924, 1059, 14, 523, 282, 63, 14885, 275, 822, 8, 65, 9, 1182, 499, 523, 330, 63, 14885, 275, 822, 8, 66, 9, 1182, 499, 523, 340, 822, 8, 65, 9, 450, 499, 508, 413, 26, 221, 327, 1050, 413, 340, 2582, 365, 16699, 272, 282, 63, 14885, 275, 282, 63, 14885, 435, 413, 523, 340, 822, 8, 66, 9, 450, 499, 508, 413, 26, 272, 330, 63, 14885, 275, 330, 63, 14885, 435, 413, 16421, 372, 282, 1491, 65, 63, 14885, 61, 435, 330, 1491, 66, 63, 14885, 61, 435, 282, 59, 65, 63, 14885, 2938, 435, 330, 59, 66, 63, 14885, 2938, 523, 327, 491, 1217, 8, 1814, 8744, 9, 523, 327, 372, 523, 327, 491, 1217, 8, 500, 8744, 9, 421, 199, 3, 5870, 2741, 511, 342, 805, 1202, 315, 2446, 342, 370, 870, 199, 3, 4052, 1924, 805, 2529, 8118, 14, 4052, 652, 1159, 20042, 370, 372, 14, 199, 318, 511, 8, 7808, 12, 1420, 304, 523, 340, 4788, 508, 1420, 26, 272, 2403, 275, 283, 9949, 283, 523, 587, 26, 272, 2403, 275, 283, 221, 1323, 283, 523, 870, 1543, 83, 4788, 26, 450, 83, 1420, 26, 450, 83, 7, 450, 334, 1861, 12, 4700, 8, 7808, 395, 4700, 8, 2062, 430, 421, 199, 3, 2446, 342, 4882, 314, 3432, 3423, 543, 19604, 4153, 12, 199, 3, 1808, 314, 3432, 511, 342, 370, 1104, 340, 314, 754, 365, 3211, 503, 440, 14, 199, 318, 2446, 837, 523, 870, 283, 422, 10911, 7, 523, 511, 8, 422, 10911, 360, 72, 1054, 659, 283, 72, 1054, 316, 358, 523, 511, 8, 422, 10911, 360, 3519, 1017, 316, 659, 283, 3519, 1017, 316, 590, 358, 523, 511, 8, 422, 10911, 360, 1117, 659, 283, 1117, 358, 819, 870, 523, 870, 283, 1397, 63, 4087, 7, 523, 511, 8, 1397, 63, 4087, 360, 2765, 14360, 365, 440, 880, 4875, 659, 283, 2765, 14360, 365, 6954, 358, 523, 511, 8, 1397, 63, 4087, 360, 2765, 366, 5216, 365, 440, 626, 4875, 15659, 283, 2765, 366, 5216, 365, 6954, 10916, 523, 511, 8, 1397, 63, 4087, 360, 2765, 1565, 65, 365, 440, 18469, 659, 283, 2765, 1565, 65, 365, 440, 18469, 358, 523, 511, 8, 1397, 63, 4087, 480, 7940, 1159, 4875, 5966, 440, 1288, 298, 7940, 1159, 4875, 5966, 440, 531, 819, 870, 523, 870, 283, 14708, 63, 894, 7, 523, 511, 8, 14708, 63, 894, 360, 13591, 297, 283, 1702, 659, 283, 371, 1812, 8161, 358, 523, 511, 8, 14708, 63, 894, 360, 28109, 297, 283, 8568, 659, 283, 3175, 1702, 271, 90, 358, 523, 511, 8, 14708, 63, 894, 360, 14591, 724, 297, 283, 16932, 337, 659, 283, 14591, 16932, 724, 337, 358, 199 ]
[ 2647, 15, 1393, 15, 1548, 18, 14, 20, 446, 6215, 199, 3, 1898, 7129, 4475, 3277, 14, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 199, 3, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 199, 3, 4475, 1159, 2018, 8089, 199, 3, 1455, 921, 600, 14, 3098, 14, 957, 15, 8654, 15, 13209, 15, 3098, 13, 1548, 13, 533, 15, 199, 199, 3, 10961, 5678, 1059, 444, 281, 559, 874, 199, 199, 3, 577, 14, 809, 10911, 199, 3, 9138, 282, 1059, 12, 340, 2399, 2582, 365, 737, 5210, 650, 12, 199, 3, 1050, 283, 316, 7, 370, 2399, 1284, 14, 199, 3, 4158, 652, 2575, 11187, 315, 283, 316, 297, 315, 1314, 1930, 199, 3, 1050, 283, 590, 7, 3140, 14, 199, 3, 982, 314, 1059, 2582, 365, 6656, 2419, 650, 12, 10137, 652, 14874, 14, 199, 3, 1432, 314, 9183, 1059, 14, 199, 318, 809, 10911, 8, 83, 304, 523, 327, 435, 4176, 12695, 1233, 2348, 4176, 11, 523, 327, 491, 1217, 8, 5037, 8744, 9, 523, 340, 822, 8, 83, 9, 2356, 650, 26, 272, 340, 308, 1988, 19, 2938, 1137, 283, 316, 356, 308, 275, 308, 435, 283, 316, 7, 272, 587, 26, 308, 275, 308, 435, 283, 590, 7, 523, 372, 308, 523, 327, 491, 1217, 8, 1814, 8744, 9, 523, 327, 372, 523, 327, 491, 1217, 8, 500, 8744, 9, 421, 199, 3, 662, 14, 440, 63, 4087, 199, 3, 9138, 282, 1059, 12, 2342, 314, 1642, 7468, 554, 402, 314, 199, 3, 20597, 283, 1397, 7, 436, 283, 4087, 1370, 982, 314, 283, 4087, 7, 11924, 199, 3, 314, 283, 1397, 297, 3350, 314, 8852, 283, 1397, 7, 13698, 4087, 7, 20597, 199, 3, 543, 283, 8302, 1370, 199, 3, 1432, 314, 9183, 1059, 14, 199, 3, 2002, 283, 2765, 366, 5216, 365, 440, 626, 4875, 11213, 14801, 26, 199, 3, 961, 366, 5216, 365, 6954, 1, 199, 318, 440, 63, 4087, 8, 83, 304, 523, 327, 435, 4176, 12695, 1233, 2348, 4176, 11, 523, 327, 491, 1217, 8, 5037, 8744, 9, 523, 302, 275, 308, 14, 1623, 360, 1397, 358, 523, 330, 275, 308, 14, 1623, 360, 4087, 358, 523, 340, 302, 1137, 446, 17, 436, 330, 1137, 446, 17, 436, 330, 690, 302, 26, 272, 308, 275, 308, 1491, 78, 61, 435, 283, 8302, 7, 435, 308, 59, 66, 11, 19, 2938, 523, 372, 308, 523, 327, 491, 1217, 8, 1814, 8744, 9, 523, 327, 372, 523, 327, 491, 1217, 8, 500, 8744, 9, 421, 199, 3, 481, 14, 13738, 63, 894, 199, 3, 24413, 487, 11604, 282, 1059, 1901, 2877, 22939, 2310, 14, 199, 3, 982, 314, 2582, 365, 2755, 12, 314, 13738, 436, 1771, 22939, 2310, 787, 314, 2011, 2582, 14, 199, 3, 982, 314, 2582, 365, 16699, 12, 781, 7171, 14722, 626, 314, 2402, 1495, 13538, 315, 314, 13738, 12995, 14, 199, 3, 325, 14, 71, 14, 283, 28109, 297, 314, 13738, 12995, 365, 283, 3175, 297, 314, 1771, 12995, 283, 271, 1370, 199, 3, 9138, 499, 3326, 12, 282, 436, 330, 12, 372, 282, 1059, 402, 314, 1824, 199, 3, 221, 282, 13, 14708, 435, 330, 13, 14708, 435, 282, 13, 894, 435, 330, 13, 894, 199, 318, 13738, 63, 894, 8, 65, 12, 330, 304, 523, 327, 435, 4176, 12695, 1233, 2348, 4176, 11, 523, 327, 491, 1217, 8, 5037, 8744, 9, 523, 327, 16266, 734, 314, 12180, 3421, 402, 1924, 1059, 14, 523, 282, 63, 14885, 275, 822, 8, 65, 9, 1182, 499, 523, 330, 63, 14885, 275, 822, 8, 66, 9, 1182, 499, 523, 340, 822, 8, 65, 9, 450, 499, 508, 413, 26, 221, 327, 1050, 413, 340, 2582, 365, 16699, 272, 282, 63, 14885, 275, 282, 63, 14885, 435, 413, 523, 340, 822, 8, 66, 9, 450, 499, 508, 413, 26, 272, 330, 63, 14885, 275, 330, 63, 14885, 435, 413, 16421, 372, 282, 1491, 65, 63, 14885, 61, 435, 330, 1491, 66, 63, 14885, 61, 435, 282, 59, 65, 63, 14885, 2938, 435, 330, 59, 66, 63, 14885, 2938, 523, 327, 491, 1217, 8, 1814, 8744, 9, 523, 327, 372, 523, 327, 491, 1217, 8, 500, 8744, 9, 421, 199, 3, 5870, 2741, 511, 342, 805, 1202, 315, 2446, 342, 370, 870, 199, 3, 4052, 1924, 805, 2529, 8118, 14, 4052, 652, 1159, 20042, 370, 372, 14, 199, 318, 511, 8, 7808, 12, 1420, 304, 523, 340, 4788, 508, 1420, 26, 272, 2403, 275, 283, 9949, 283, 523, 587, 26, 272, 2403, 275, 283, 221, 1323, 283, 523, 870, 1543, 83, 4788, 26, 450, 83, 1420, 26, 450, 83, 7, 450, 334, 1861, 12, 4700, 8, 7808, 395, 4700, 8, 2062, 430, 421, 199, 3, 2446, 342, 4882, 314, 3432, 3423, 543, 19604, 4153, 12, 199, 3, 1808, 314, 3432, 511, 342, 370, 1104, 340, 314, 754, 365, 3211, 503, 440, 14, 199, 318, 2446, 837, 523, 870, 283, 422, 10911, 7, 523, 511, 8, 422, 10911, 360, 72, 1054, 659, 283, 72, 1054, 316, 358, 523, 511, 8, 422, 10911, 360, 3519, 1017, 316, 659, 283, 3519, 1017, 316, 590, 358, 523, 511, 8, 422, 10911, 360, 1117, 659, 283, 1117, 358, 819, 870, 523, 870, 283, 1397, 63, 4087, 7, 523, 511, 8, 1397, 63, 4087, 360, 2765, 14360, 365, 440, 880, 4875, 659, 283, 2765, 14360, 365, 6954, 358, 523, 511, 8, 1397, 63, 4087, 360, 2765, 366, 5216, 365, 440, 626, 4875, 15659, 283, 2765, 366, 5216, 365, 6954, 10916, 523, 511, 8, 1397, 63, 4087, 360, 2765, 1565, 65, 365, 440, 18469, 659, 283, 2765, 1565, 65, 365, 440, 18469, 358, 523, 511, 8, 1397, 63, 4087, 480, 7940, 1159, 4875, 5966, 440, 1288, 298, 7940, 1159, 4875, 5966, 440, 531, 819, 870, 523, 870, 283, 14708, 63, 894, 7, 523, 511, 8, 14708, 63, 894, 360, 13591, 297, 283, 1702, 659, 283, 371, 1812, 8161, 358, 523, 511, 8, 14708, 63, 894, 360, 28109, 297, 283, 8568, 659, 283, 3175, 1702, 271, 90, 358, 523, 511, 8, 14708, 63, 894, 360, 14591, 724, 297, 283, 16932, 337, 659, 283, 14591, 16932, 724, 337, 358, 199, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
leshchevds/ganeti
lib/ssh.py
1
43027
# # # Copyright (C) 2006, 2007, 2010, 2011 Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """Module encapsulating ssh functionality. """ import logging import os import shutil import tempfile from collections import namedtuple from functools import partial from ganeti import utils from ganeti import errors from ganeti import constants from ganeti import netutils from ganeti import pathutils from ganeti import vcluster from ganeti import compat from ganeti import serializer from ganeti import ssconf def GetUserFiles(user, mkdir=False, dircheck=True, kind=constants.SSHK_DSA, _homedir_fn=None): """Return the paths of a user's SSH files. @type user: string @param user: Username @type mkdir: bool @param mkdir: Whether to create ".ssh" directory if it doesn't exist @type dircheck: bool @param dircheck: Whether to check if ".ssh" directory exists @type kind: string @param kind: One of L{constants.SSHK_ALL} @rtype: tuple; (string, string, string) @return: Tuple containing three file system paths; the private SSH key file, the public SSH key file and the user's C{authorized_keys} file @raise errors.OpExecError: When home directory of the user can not be determined @raise errors.OpExecError: Regardless of the C{mkdir} parameters, this exception is raised if C{~$user/.ssh} is not a directory and C{dircheck} is set to C{True} """ if _homedir_fn is None: _homedir_fn = utils.GetHomeDir user_dir = _homedir_fn(user) if not user_dir: raise errors.OpExecError("Cannot resolve home of user '%s'" % user) if kind == constants.SSHK_DSA: suffix = "dsa" elif kind == constants.SSHK_RSA: suffix = "rsa" elif kind == constants.SSHK_ECDSA: suffix = "ecdsa" else: raise errors.ProgrammerError("Unknown SSH key kind '%s'" % kind) ssh_dir = utils.PathJoin(user_dir, ".ssh") if mkdir: utils.EnsureDirs([(ssh_dir, constants.SECURE_DIR_MODE)]) elif dircheck and not os.path.isdir(ssh_dir): raise errors.OpExecError("Path %s is not a directory" % ssh_dir) return [utils.PathJoin(ssh_dir, base) for base in ["id_%s" % suffix, "id_%s.pub" % suffix, "authorized_keys"]] def GetAllUserFiles(user, mkdir=False, dircheck=True, _homedir_fn=None): """Wrapper over L{GetUserFiles} to retrieve files for all SSH key types. See L{GetUserFiles} for details. @rtype: tuple; (string, dict with string as key, tuple of (string, string) as value) """ helper = compat.partial(GetUserFiles, user, mkdir=mkdir, dircheck=dircheck, _homedir_fn=_homedir_fn) result = [(kind, helper(kind=kind)) for kind in constants.SSHK_ALL] authorized_keys = [i for (_, (_, _, i)) in result] assert len(frozenset(authorized_keys)) == 1, \ "Different paths for authorized_keys were returned" return (authorized_keys[0], dict((kind, (privkey, pubkey)) for (kind, (privkey, pubkey, _)) in result)) def _SplitSshKey(key): """Splits a line for SSH's C{authorized_keys} file. If the line has no options (e.g. no C{command="..."}), only the significant parts, the key type and its hash, are used. Otherwise the whole line is used (split at whitespace). @type key: string @param key: Key line @rtype: tuple """ parts = key.split() if parts and parts[0] in constants.SSHAK_ALL: # If the key has no options in front of it, we only want the significant # fields return (False, parts[:2]) else: # Can't properly split the line, so use everything return (True, parts) def AddAuthorizedKeys(file_obj, keys): """Adds a list of SSH public key to an authorized_keys file. @type file_obj: str or file handle @param file_obj: path to authorized_keys file @type keys: list of str @param keys: list of strings containing keys """ key_field_list = [(key, _SplitSshKey(key)) for key in keys] if isinstance(file_obj, basestring): f = open(file_obj, "a+") else: f = file_obj try: nl = True for line in f: # Ignore whitespace changes line_key = _SplitSshKey(line) key_field_list[:] = [(key, split_key) for (key, split_key) in key_field_list if split_key != line_key] nl = line.endswith("\n") else: if not nl: f.write("\n") for (key, _) in key_field_list: f.write(key.rstrip("\r\n")) f.write("\n") f.flush() finally: f.close() def HasAuthorizedKey(file_obj, key): """Check if a particular key is in the 'authorized_keys' file. @type file_obj: str or file handle @param file_obj: path to authorized_keys file @type key: str @param key: string containing key """ key_fields = _SplitSshKey(key) if isinstance(file_obj, basestring): f = open(file_obj, "r") else: f = file_obj try: for line in f: # Ignore whitespace changes line_key = _SplitSshKey(line) if line_key == key_fields: return True finally: f.close() return False def CheckForMultipleKeys(file_obj, node_names): """Check if there is at most one key per host in 'authorized_keys' file. @type file_obj: str or file handle @param file_obj: path to authorized_keys file @type node_names: list of str @param node_names: list of names of nodes of the cluster @returns: a dictionary with hostnames which occur more than once """ if isinstance(file_obj, basestring): f = open(file_obj, "r") else: f = file_obj occurrences = {} try: index = 0 for line in f: index += 1 if line.startswith("#"): continue chunks = line.split() # find the chunk with user@hostname user_hostname = [chunk.strip() for chunk in chunks if "@" in chunk][0] if not user_hostname in occurrences: occurrences[user_hostname] = [] occurrences[user_hostname].append(index) finally: f.close() bad_occurrences = {} for user_hostname, occ in occurrences.items(): _, hostname = user_hostname.split("@") if hostname in node_names and len(occ) > 1: bad_occurrences[user_hostname] = occ return bad_occurrences def AddAuthorizedKey(file_obj, key): """Adds an SSH public key to an authorized_keys file. @type file_obj: str or file handle @param file_obj: path to authorized_keys file @type key: str @param key: string containing key """ AddAuthorizedKeys(file_obj, [key]) def RemoveAuthorizedKeys(file_name, keys): """Removes public SSH keys from an authorized_keys file. @type file_name: str @param file_name: path to authorized_keys file @type keys: list of str @param keys: list of strings containing keys """ key_field_list = [_SplitSshKey(key) for key in keys] fd, tmpname = tempfile.mkstemp(dir=os.path.dirname(file_name)) try: out = os.fdopen(fd, "w") try: f = open(file_name, "r") try: for line in f: # Ignore whitespace changes while comparing lines if _SplitSshKey(line) not in key_field_list: out.write(line) out.flush() os.rename(tmpname, file_name) finally: f.close() finally: out.close() except: utils.RemoveFile(tmpname) raise def RemoveAuthorizedKey(file_name, key): """Removes an SSH public key from an authorized_keys file. @type file_name: str @param file_name: path to authorized_keys file @type key: str @param key: string containing key """ RemoveAuthorizedKeys(file_name, [key]) def _AddPublicKeyProcessLine(new_uuid, new_key, line_uuid, line_key, found): """Processes one line of the public key file when adding a key. This is a sub function that can be called within the C{_ManipulatePublicKeyFile} function. It processes one line of the public key file, checks if this line contains the key to add already and if so, notes the occurrence in the return value. @type new_uuid: string @param new_uuid: the node UUID of the node whose key is added @type new_key: string @param new_key: the SSH key to be added @type line_uuid: the UUID of the node whose line in the public key file is processed in this function call @param line_key: the SSH key of the node whose line in the public key file is processed in this function call @type found: boolean @param found: whether or not the (UUID, key) pair of the node whose key is being added was found in the public key file already. @rtype: (boolean, string) @return: a possibly updated value of C{found} and the processed line """ if line_uuid == new_uuid and line_key == new_key: logging.debug("SSH key of node '%s' already in key file.", new_uuid) found = True return (found, "%s %s\n" % (line_uuid, line_key)) def _AddPublicKeyElse(new_uuid, new_key): """Adds a new SSH key to the key file if it did not exist already. This is an auxiliary function for C{_ManipulatePublicKeyFile} which is carried out when a new key is added to the public key file and after processing the whole file, we found out that the key does not exist in the file yet but needs to be appended at the end. @type new_uuid: string @param new_uuid: the UUID of the node whose key is added @type new_key: string @param new_key: the SSH key to be added @rtype: string @return: a new line to be added to the file """ return "%s %s\n" % (new_uuid, new_key) def _RemovePublicKeyProcessLine( target_uuid, _target_key, line_uuid, line_key, found): """Processes a line in the public key file when aiming for removing a key. This is an auxiliary function for C{_ManipulatePublicKeyFile} when we are removing a key from the public key file. This particular function only checks if the current line contains the UUID of the node in question and writes the line to the temporary file otherwise. @type target_uuid: string @param target_uuid: UUID of the node whose key is being removed @type _target_key: string @param _target_key: SSH key of the node (not used) @type line_uuid: string @param line_uuid: UUID of the node whose line is processed in this call @type line_key: string @param line_key: SSH key of the nodes whose line is processed in this call @type found: boolean @param found: whether or not the UUID was already found. @rtype: (boolean, string) @return: a tuple, indicating if the target line was found and the processed line; the line is 'None', if the original line is removed """ if line_uuid != target_uuid: return (found, "%s %s\n" % (line_uuid, line_key)) else: return (True, None) def _RemovePublicKeyElse( target_uuid, _target_key): """Logs when we tried to remove a key that does not exist. This is an auxiliary function for C{_ManipulatePublicKeyFile} which is run after we have processed the complete public key file and did not find the key to be removed. @type target_uuid: string @param target_uuid: the UUID of the node whose key was supposed to be removed @type _target_key: string @param _target_key: the key of the node which was supposed to be removed (not used) @rtype: string @return: in this case, always None """ logging.debug("Trying to remove key of node '%s' which is not in list" " of public keys.", target_uuid) return None def _ReplaceNameByUuidProcessLine( node_name, _key, line_identifier, line_key, found, node_uuid=None): """Replaces a node's name with its UUID on a matching line in the key file. This is an auxiliary function for C{_ManipulatePublicKeyFile} which processes a line of the ganeti public key file. If the line in question matches the node's name, the name will be replaced by the node's UUID. @type node_name: string @param node_name: name of the node to be replaced by the UUID @type _key: string @param _key: SSH key of the node (not used) @type line_identifier: string @param line_identifier: an identifier of a node in a line of the public key file. This can be either a node name or a node UUID, depending on if it got replaced already or not. @type line_key: string @param line_key: SSH key of the node whose line is processed @type found: boolean @param found: whether or not the line matches the node's name @type node_uuid: string @param node_uuid: the node's UUID which will replace the node name @rtype: (boolean, string) @return: a tuple indicating whether the target line was found and the processed line """ if node_name == line_identifier: return (True, "%s %s\n" % (node_uuid, line_key)) else: return (found, "%s %s\n" % (line_identifier, line_key)) def _ReplaceNameByUuidElse( node_uuid, node_name, _key): """Logs a debug message when we try to replace a key that is not there. This is an implementation of the auxiliary C{process_else_fn} function for the C{_ManipulatePubKeyFile} function when we use it to replace a line in the public key file that is indexed by the node's name instead of the node's UUID. @type node_uuid: string @param node_uuid: the node's UUID @type node_name: string @param node_name: the node's UUID @type _key: string (not used) @param _key: the node's SSH key (not used) @rtype: string @return: in this case, always None """ logging.debug("Trying to replace node name '%s' with UUID '%s', but" " no line with that name was found.", node_name, node_uuid) return None def _ParseKeyLine(line, error_fn): """Parses a line of the public key file. @type line: string @param line: line of the public key file @type error_fn: function @param error_fn: function to process error messages @rtype: tuple (string, string) @return: a tuple containing the UUID of the node and a string containing the SSH key and possible more parameters for the key """ if len(line.rstrip()) == 0: return (None, None) chunks = line.split(" ") if len(chunks) < 2: raise error_fn("Error parsing public SSH key file. Line: '%s'" % line) uuid = chunks[0] key = " ".join(chunks[1:]).rstrip() return (uuid, key) def _ManipulatePubKeyFile(target_identifier, target_key, key_file=pathutils.SSH_PUB_KEYS, error_fn=errors.ProgrammerError, process_line_fn=None, process_else_fn=None): """Manipulates the list of public SSH keys of the cluster. This is a general function to manipulate the public key file. It needs two auxiliary functions C{process_line_fn} and C{process_else_fn} to work. Generally, the public key file is processed as follows: 1) The function processes each line of the original ganeti public key file, applies the C{process_line_fn} function on it, which returns a possibly manipulated line and an indicator whether the line in question was found. If a line is returned, it is added to a list of lines for later writing to the file. 2) If all lines are processed and the 'found' variable is False, the seconds auxiliary function C{process_else_fn} is called to possibly add more lines to the list of lines. 3) Finally, the list of lines is assembled to a string and written atomically to the public key file, thereby overriding it. If the public key file does not exist, we create it. This is necessary for a smooth transition after an upgrade. @type target_identifier: str @param target_identifier: identifier of the node whose key is added; in most cases this is the node's UUID, but in some it is the node's host name @type target_key: str @param target_key: string containing a public SSH key (a complete line possibly including more parameters than just the key) @type key_file: str @param key_file: filename of the file of public node keys (optional parameter for testing) @type error_fn: function @param error_fn: Function that returns an exception, used to customize exception types depending on the calling context @type process_line_fn: function @param process_line_fn: function to process one line of the public key file @type process_else_fn: function @param process_else_fn: function to be called if no line of the key file matches the target uuid """ assert process_else_fn is not None assert process_line_fn is not None old_lines = [] f_orig = None if os.path.exists(key_file): try: f_orig = open(key_file, "r") old_lines = f_orig.readlines() finally: f_orig.close() else: try: f_orig = open(key_file, "w") f_orig.close() except IOError as e: raise errors.SshUpdateError("Cannot create public key file: %s" % e) found = False new_lines = [] for line in old_lines: (uuid, key) = _ParseKeyLine(line, error_fn) if not uuid: continue (new_found, new_line) = process_line_fn(target_identifier, target_key, uuid, key, found) if new_found: found = True if new_line is not None: new_lines.append(new_line) if not found: new_line = process_else_fn(target_identifier, target_key) if new_line is not None: new_lines.append(new_line) new_file_content = "".join(new_lines) utils.WriteFile(key_file, data=new_file_content) def AddPublicKey(new_uuid, new_key, key_file=pathutils.SSH_PUB_KEYS, error_fn=errors.ProgrammerError): """Adds a new key to the list of public keys. @see: _ManipulatePubKeyFile for parameter descriptions. """ _ManipulatePubKeyFile(new_uuid, new_key, key_file=key_file, process_line_fn=_AddPublicKeyProcessLine, process_else_fn=_AddPublicKeyElse, error_fn=error_fn) def RemovePublicKey(target_uuid, key_file=pathutils.SSH_PUB_KEYS, error_fn=errors.ProgrammerError): """Removes a key from the list of public keys. @see: _ManipulatePubKeyFile for parameter descriptions. """ _ManipulatePubKeyFile(target_uuid, None, key_file=key_file, process_line_fn=_RemovePublicKeyProcessLine, process_else_fn=_RemovePublicKeyElse, error_fn=error_fn) def ReplaceNameByUuid(node_uuid, node_name, key_file=pathutils.SSH_PUB_KEYS, error_fn=errors.ProgrammerError): """Replaces a host name with the node's corresponding UUID. When a node is added to the cluster, we don't know it's UUID yet. So first its SSH key gets added to the public key file and in a second step, the node's name gets replaced with the node's UUID as soon as we know the UUID. @type node_uuid: string @param node_uuid: the node's UUID to replace the node's name @type node_name: string @param node_name: the node's name to be replaced by the node's UUID @see: _ManipulatePubKeyFile for the other parameter descriptions. """ process_line_fn = partial(_ReplaceNameByUuidProcessLine, node_uuid=node_uuid) process_else_fn = partial(_ReplaceNameByUuidElse, node_uuid=node_uuid) _ManipulatePubKeyFile(node_name, None, key_file=key_file, process_line_fn=process_line_fn, process_else_fn=process_else_fn, error_fn=error_fn) def ClearPubKeyFile(key_file=pathutils.SSH_PUB_KEYS, mode=0600): """Resets the content of the public key file. """ utils.WriteFile(key_file, data="", mode=mode) def OverridePubKeyFile(key_map, key_file=pathutils.SSH_PUB_KEYS): """Overrides the public key file with a list of given keys. @type key_map: dict from str to list of str @param key_map: dictionary mapping uuids to lists of SSH keys """ new_lines = [] for (uuid, keys) in key_map.items(): for key in keys: new_lines.append("%s %s\n" % (uuid, key)) new_file_content = "".join(new_lines) utils.WriteFile(key_file, data=new_file_content) def QueryPubKeyFile(target_uuids, key_file=pathutils.SSH_PUB_KEYS, error_fn=errors.ProgrammerError): """Retrieves a map of keys for the requested node UUIDs. @type target_uuids: str or list of str @param target_uuids: UUID of the node to retrieve the key for or a list of UUIDs of nodes to retrieve the keys for @type key_file: str @param key_file: filename of the file of public node keys (optional parameter for testing) @type error_fn: function @param error_fn: Function that returns an exception, used to customize exception types depending on the calling context @rtype: dict mapping strings to list of strings @return: dictionary mapping node uuids to their ssh keys """ all_keys = target_uuids is None if isinstance(target_uuids, str): target_uuids = [target_uuids] result = {} f = open(key_file, "r") try: for line in f: (uuid, key) = _ParseKeyLine(line, error_fn) if not uuid: continue if all_keys or (uuid in target_uuids): if uuid not in result: result[uuid] = [] result[uuid].append(key) finally: f.close() return result def InitSSHSetup(key_type, key_bits, error_fn=errors.OpPrereqError, _homedir_fn=None, _suffix=""): """Setup the SSH configuration for the node. This generates a dsa keypair for root, adds the pub key to the permitted hosts and adds the hostkey to its own known hosts. @param key_type: the type of SSH keypair to be generated @param key_bits: the key length, in bits, to be used """ priv_key, _, auth_keys = GetUserFiles(constants.SSH_LOGIN_USER, kind=key_type, mkdir=True, _homedir_fn=_homedir_fn) new_priv_key_name = priv_key + _suffix new_pub_key_name = priv_key + _suffix + ".pub" for name in new_priv_key_name, new_pub_key_name: if os.path.exists(name): utils.CreateBackup(name) utils.RemoveFile(name) result = utils.RunCmd(["ssh-keygen", "-b", str(key_bits), "-t", key_type, "-f", new_priv_key_name, "-q", "-N", ""]) if result.failed: raise error_fn("Could not generate ssh keypair, error %s" % result.output) AddAuthorizedKey(auth_keys, utils.ReadFile(new_pub_key_name)) def InitPubKeyFile(master_uuid, key_type, key_file=pathutils.SSH_PUB_KEYS): """Creates the public key file and adds the master node's SSH key. @type master_uuid: str @param master_uuid: the master node's UUID @type key_type: one of L{constants.SSHK_ALL} @param key_type: the type of ssh key to be used @type key_file: str @param key_file: name of the file containing the public keys """ _, pub_key, _ = GetUserFiles(constants.SSH_LOGIN_USER, kind=key_type) ClearPubKeyFile(key_file=key_file) key = utils.ReadFile(pub_key) AddPublicKey(master_uuid, key, key_file=key_file) class SshRunner: """Wrapper for SSH commands. """ def __init__(self, cluster_name): """Initializes this class. @type cluster_name: str @param cluster_name: name of the cluster """ self.cluster_name = cluster_name family = ssconf.SimpleStore().GetPrimaryIPFamily() self.ipv6 = (family == netutils.IP6Address.family) def _BuildSshOptions(self, batch, ask_key, use_cluster_key, strict_host_check, private_key=None, quiet=True, port=None): """Builds a list with needed SSH options. @param batch: same as ssh's batch option @param ask_key: allows ssh to ask for key confirmation; this parameter conflicts with the batch one @param use_cluster_key: if True, use the cluster name as the HostKeyAlias name @param strict_host_check: this makes the host key checking strict @param private_key: use this private key instead of the default @param quiet: whether to enable -q to ssh @param port: the SSH port to use, or None to use the default @rtype: list @return: the list of options ready to use in L{utils.process.RunCmd} """ options = [ "-oEscapeChar=none", "-oHashKnownHosts=no", "-oGlobalKnownHostsFile=%s" % pathutils.SSH_KNOWN_HOSTS_FILE, "-oUserKnownHostsFile=/dev/null", "-oCheckHostIp=no", ] if use_cluster_key: options.append("-oHostKeyAlias=%s" % self.cluster_name) if quiet: options.append("-q") if private_key: options.append("-i%s" % private_key) if port: options.append("-oPort=%d" % port) # TODO: Too many boolean options, maybe convert them to more descriptive # constants. # Note: ask_key conflicts with batch mode if batch: if ask_key: raise errors.ProgrammerError("SSH call requested conflicting options") options.append("-oBatchMode=yes") if strict_host_check: options.append("-oStrictHostKeyChecking=yes") else: options.append("-oStrictHostKeyChecking=no") else: # non-batch mode if ask_key: options.append("-oStrictHostKeyChecking=ask") elif strict_host_check: options.append("-oStrictHostKeyChecking=yes") else: options.append("-oStrictHostKeyChecking=no") if self.ipv6: options.append("-6") else: options.append("-4") return options def BuildCmd(self, hostname, user, command, batch=True, ask_key=False, tty=False, use_cluster_key=True, strict_host_check=True, private_key=None, quiet=True, port=None): """Build an ssh command to execute a command on a remote node. @param hostname: the target host, string @param user: user to auth as @param command: the command @param batch: if true, ssh will run in batch mode with no prompting @param ask_key: if true, ssh will run with StrictHostKeyChecking=ask, so that we can connect to an unknown host (not valid in batch mode) @param use_cluster_key: whether to expect and use the cluster-global SSH key @param strict_host_check: whether to check the host's SSH key at all @param private_key: use this private key instead of the default @param quiet: whether to enable -q to ssh @param port: the SSH port on which the node's daemon is running @return: the ssh call to run 'command' on the remote host. """ argv = [constants.SSH] argv.extend(self._BuildSshOptions(batch, ask_key, use_cluster_key, strict_host_check, private_key, quiet=quiet, port=port)) if tty: argv.extend(["-t", "-t"]) argv.append("%s@%s" % (user, hostname)) # Insert variables for virtual nodes argv.extend("export %s=%s;" % (utils.ShellQuote(name), utils.ShellQuote(value)) for (name, value) in vcluster.EnvironmentForHost(hostname).items()) argv.append(command) return argv def Run(self, *args, **kwargs): """Runs a command on a remote node. This method has the same return value as `utils.RunCmd()`, which it uses to launch ssh. Args: see SshRunner.BuildCmd. @rtype: L{utils.process.RunResult} @return: the result as from L{utils.process.RunCmd()} """ return utils.RunCmd(self.BuildCmd(*args, **kwargs)) def CopyFileToNode(self, node, port, filename): """Copy a file to another node with scp. @param node: node in the cluster @param filename: absolute pathname of a local file @rtype: boolean @return: the success of the operation """ if not os.path.isabs(filename): logging.error("File %s must be an absolute path", filename) return False if not os.path.isfile(filename): logging.error("File %s does not exist", filename) return False command = [constants.SCP, "-p"] command.extend(self._BuildSshOptions(True, False, True, True, port=port)) command.append(filename) if netutils.IP6Address.IsValid(node): node = netutils.FormatAddress((node, None)) command.append("%s:%s" % (node, vcluster.ExchangeNodeRoot(node, filename))) result = utils.RunCmd(command) if result.failed: logging.error("Copy to node %s failed (%s) error '%s'," " command was '%s'", node, result.fail_reason, result.output, result.cmd) return not result.failed def VerifyNodeHostname(self, node, ssh_port): """Verify hostname consistency via SSH. This functions connects via ssh to a node and compares the hostname reported by the node to the name with have (the one that we connected to). This is used to detect problems in ssh known_hosts files (conflicting known hosts) and inconsistencies between dns/hosts entries and local machine names @param node: nodename of a host to check; can be short or full qualified hostname @param ssh_port: the port of a SSH daemon running on the node @return: (success, detail), where: - success: True/False - detail: string with details """ cmd = ("if test -z \"$GANETI_HOSTNAME\"; then" " hostname --fqdn;" "else" " echo \"$GANETI_HOSTNAME\";" "fi") retval = self.Run(node, constants.SSH_LOGIN_USER, cmd, quiet=False, port=ssh_port) if retval.failed: msg = "ssh problem" output = retval.output if output: msg += ": %s" % output else: msg += ": %s (no output)" % retval.fail_reason logging.error("Command %s failed: %s", retval.cmd, msg) return False, msg remotehostname = retval.stdout.strip() if not remotehostname or remotehostname != node: if node.startswith(remotehostname + "."): msg = "hostname not FQDN" else: msg = "hostname mismatch" return False, ("%s: expected %s but got %s" % (msg, node, remotehostname)) return True, "host matches" def WriteKnownHostsFile(cfg, file_name): """Writes the cluster-wide equally known_hosts file. """ data = "" if cfg.GetRsaHostKey(): data += "%s ssh-rsa %s\n" % (cfg.GetClusterName(), cfg.GetRsaHostKey()) if cfg.GetDsaHostKey(): data += "%s ssh-dss %s\n" % (cfg.GetClusterName(), cfg.GetDsaHostKey()) utils.WriteFile(file_name, mode=0600, data=data) def _EnsureCorrectGanetiVersion(cmd): """Ensured the correct Ganeti version before running a command via SSH. Before a command is run on a node via SSH, it makes sense in some situations to ensure that this node is indeed running the correct version of Ganeti like the rest of the cluster. @type cmd: string @param cmd: string @rtype: list of strings @return: a list of commands with the newly added ones at the beginning """ logging.debug("Ensure correct Ganeti version: %s", cmd) version = constants.DIR_VERSION all_cmds = [["test", "-d", os.path.join(pathutils.PKGLIBDIR, version)]] if constants.HAS_GNU_LN: all_cmds.extend([["ln", "-s", "-f", "-T", os.path.join(pathutils.PKGLIBDIR, version), os.path.join(pathutils.SYSCONFDIR, "ganeti/lib")], ["ln", "-s", "-f", "-T", os.path.join(pathutils.SHAREDIR, version), os.path.join(pathutils.SYSCONFDIR, "ganeti/share")]]) else: all_cmds.extend([["rm", "-f", os.path.join(pathutils.SYSCONFDIR, "ganeti/lib")], ["ln", "-s", "-f", os.path.join(pathutils.PKGLIBDIR, version), os.path.join(pathutils.SYSCONFDIR, "ganeti/lib")], ["rm", "-f", os.path.join(pathutils.SYSCONFDIR, "ganeti/share")], ["ln", "-s", "-f", os.path.join(pathutils.SHAREDIR, version), os.path.join(pathutils.SYSCONFDIR, "ganeti/share")]]) all_cmds.append(cmd) return all_cmds def RunSshCmdWithStdin(cluster_name, node, basecmd, port, data, debug=False, verbose=False, use_cluster_key=False, ask_key=False, strict_host_check=False, ensure_version=False): """Runs a command on a remote machine via SSH and provides input in stdin. @type cluster_name: string @param cluster_name: Cluster name @type node: string @param node: Node name @type basecmd: string @param basecmd: Base command (path on the remote machine) @type port: int @param port: The SSH port of the remote machine or None for the default @param data: JSON-serializable input data for script (passed to stdin) @type debug: bool @param debug: Enable debug output @type verbose: bool @param verbose: Enable verbose output @type use_cluster_key: bool @param use_cluster_key: See L{ssh.SshRunner.BuildCmd} @type ask_key: bool @param ask_key: See L{ssh.SshRunner.BuildCmd} @type strict_host_check: bool @param strict_host_check: See L{ssh.SshRunner.BuildCmd} """ cmd = [basecmd] # Pass --debug/--verbose to the external script if set on our invocation if debug: cmd.append("--debug") if verbose: cmd.append("--verbose") if ensure_version: all_cmds = _EnsureCorrectGanetiVersion(cmd) else: all_cmds = [cmd] if port is None: port = netutils.GetDaemonPort(constants.SSH) srun = SshRunner(cluster_name) scmd = srun.BuildCmd(node, constants.SSH_LOGIN_USER, utils.ShellQuoteArgs( utils.ShellCombineCommands(all_cmds)), batch=False, ask_key=ask_key, quiet=False, strict_host_check=strict_host_check, use_cluster_key=use_cluster_key, port=port) tempfh = tempfile.TemporaryFile() try: tempfh.write(serializer.DumpJson(data)) tempfh.seek(0) result = utils.RunCmd(scmd, interactive=True, input_fd=tempfh) finally: tempfh.close() if result.failed: raise errors.OpExecError("Command '%s' failed: %s" % (result.cmd, result.fail_reason)) def ReadRemoteSshPubKey(pub_key_file, node, cluster_name, port, ask_key, strict_host_check): """Fetches a public SSH key from a node via SSH. @type pub_key_file: string @param pub_key_file: a tuple consisting of the file name of the public DSA key """ ssh_runner = SshRunner(cluster_name) cmd = ["cat", pub_key_file] ssh_cmd = ssh_runner.BuildCmd(node, constants.SSH_LOGIN_USER, utils.ShellQuoteArgs(cmd), batch=False, ask_key=ask_key, quiet=False, strict_host_check=strict_host_check, use_cluster_key=False, port=port) result = utils.RunCmd(ssh_cmd) if result.failed: raise errors.OpPrereqError("Could not fetch a public SSH key (%s) from node" " '%s': ran command '%s', failure reason: '%s'." % (pub_key_file, node, cmd, result.fail_reason), errors.ECODE_INVAL) return result.stdout def GetSshKeyFilenames(key_type, suffix=""): """Get filenames of the SSH key pair of the given type. @type key_type: string @param key_type: type of SSH key, must be element of C{constants.SSHK_ALL} @type suffix: string @param suffix: optional suffix for the key filenames @rtype: tuple of (string, string) @returns: a tuple containing the name of the private key file and the public key file. """ if key_type not in constants.SSHK_ALL: raise errors.SshUpdateError("Unsupported key type '%s'. Supported key types" " are: %s." % (key_type, constants.SSHK_ALL)) (_, root_keyfiles) = \ GetAllUserFiles(constants.SSH_LOGIN_USER, mkdir=False, dircheck=False) if not key_type in root_keyfiles.keys(): raise errors.SshUpdateError("No keyfile for key type '%s' available." % key_type) key_filenames = root_keyfiles[key_type] if suffix: key_filenames = [_ComputeKeyFilePathWithSuffix(key_filename, suffix) for key_filename in key_filenames] return key_filenames def GetSshPubKeyFilename(key_type, suffix=""): """Get filename of the public SSH key of the given type. @type key_type: string @param key_type: type of SSH key, must be element of C{constants.SSHK_ALL} @type suffix: string @param suffix: optional suffix for the key filenames @rtype: string @returns: file name of the public key file """ return GetSshKeyFilenames(key_type, suffix=suffix)[1] def _ComputeKeyFilePathWithSuffix(key_filepath, suffix): """Converts the given key filename to a key filename with a suffix. @type key_filepath: string @param key_filepath: path of the key file @type suffix: string @param suffix: suffix to be appended to the basename of the file """ path = os.path.dirname(key_filepath) ext = os.path.splitext(os.path.basename(key_filepath))[1] basename = os.path.splitext(os.path.basename(key_filepath))[0] return os.path.join(path, basename + suffix + ext) def ReplaceSshKeys(src_key_type, dest_key_type, src_key_suffix="", dest_key_suffix=""): """Replaces an SSH key pair by another SSH key pair. Note that both parts, the private and the public key, are replaced. @type src_key_type: string @param src_key_type: key type of key pair that is replacing the other key pair @type dest_key_type: string @param dest_key_type: key type of the key pair that is being replaced by the source key pair @type src_key_suffix: string @param src_key_suffix: optional suffix of the key files of the source key pair @type dest_key_suffix: string @param dest_key_suffix: optional suffix of the keey files of the destination key pair """ (src_priv_filename, src_pub_filename) = GetSshKeyFilenames( src_key_type, suffix=src_key_suffix) (dest_priv_filename, dest_pub_filename) = GetSshKeyFilenames( dest_key_type, suffix=dest_key_suffix) if not (os.path.exists(src_priv_filename) and os.path.exists(src_pub_filename)): raise errors.SshUpdateError( "At least one of the source key files is missing: %s", ", ".join([src_priv_filename, src_pub_filename])) for dest_file in [dest_priv_filename, dest_pub_filename]: if os.path.exists(dest_file): utils.CreateBackup(dest_file) utils.RemoveFile(dest_file) shutil.move(src_priv_filename, dest_priv_filename) shutil.move(src_pub_filename, dest_pub_filename) def ReadLocalSshPubKeys(key_types, suffix=""): """Reads the local root user SSH key. @type key_types: list of string @param key_types: types of SSH keys. Must be subset of constants.SSHK_ALL. If 'None' or [], all available keys are returned. @type suffix: string @param suffix: optional suffix to be attached to key names when reading them. Used for temporary key files. @rtype: list of string @return: list of public keys """ fetch_key_types = [] if key_types: fetch_key_types += key_types else: fetch_key_types = constants.SSHK_ALL (_, root_keyfiles) = \ GetAllUserFiles(constants.SSH_LOGIN_USER, mkdir=False, dircheck=False) result_keys = [] for (public_key_type, (_, public_key_file)) in root_keyfiles.items(): if public_key_type not in fetch_key_types: continue public_key_dir = os.path.dirname(public_key_file) public_key_filename = "" if suffix: public_key_filename = \ os.path.splitext(os.path.basename(public_key_file))[0] \ + suffix + ".pub" else: public_key_filename = public_key_file public_key_path = os.path.join(public_key_dir, public_key_filename) if not os.path.exists(public_key_path): raise errors.SshUpdateError("Cannot find SSH public key of type '%s'." % public_key_type) else: key = utils.ReadFile(public_key_path) result_keys.append(key) return result_keys # Update gnt-cluster.rst when changing which combinations are valid. KeyBitInfo = namedtuple('KeyBitInfo', ['default', 'validation_fn']) SSH_KEY_VALID_BITS = { constants.SSHK_DSA: KeyBitInfo(1024, lambda b: b == 1024), constants.SSHK_RSA: KeyBitInfo(2048, lambda b: b >= 768), constants.SSHK_ECDSA: KeyBitInfo(384, lambda b: b in [256, 384, 521]), } def DetermineKeyBits(key_type, key_bits, old_key_type, old_key_bits): """Checks the key bits to be used for a given key type, or provides defaults. @type key_type: one of L{constants.SSHK_ALL} @param key_type: The key type to use. @type key_bits: positive int or None @param key_bits: The number of bits to use, if supplied by user. @type old_key_type: one of L{constants.SSHK_ALL} or None @param old_key_type: The previously used key type, if any. @type old_key_bits: positive int or None @param old_key_bits: The previously used number of bits, if any. @rtype: positive int @return: The number of bits to use. """ if key_bits is None: if old_key_type is not None and old_key_type == key_type: key_bits = old_key_bits else: key_bits = SSH_KEY_VALID_BITS[key_type].default if not SSH_KEY_VALID_BITS[key_type].validation_fn(key_bits): raise errors.OpPrereqError("Invalid key type and bit size combination:" " %s with %s bits" % (key_type, key_bits), errors.ECODE_INVAL) return key_bits
bsd-2-clause
[ 3, 199, 3, 199, 199, 3, 1898, 334, 35, 9, 8315, 12, 10219, 12, 7129, 12, 7760, 4475, 3277, 14, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 413, 14, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 4245, 12, 199, 3, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 199, 3, 499, 14, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 199, 3, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 298, 1179, 199, 3, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 199, 3, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 437, 3115, 199, 3, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 29785, 1549, 199, 3, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 8820, 12, 199, 3, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 5471, 2296, 12, 199, 3, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 7126, 12, 1549, 199, 3, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 9815, 1634, 199, 3, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 334, 6446, 199, 3, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 199, 3, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 421, 199, 624, 2377, 22667, 20529, 8635, 9330, 14, 199, 199, 624, 421, 199, 646, 2050, 199, 646, 747, 199, 646, 5145, 199, 646, 5549, 199, 199, 504, 5055, 492, 12863, 199, 504, 9143, 492, 7417, 199, 199, 504, 486, 5865, 280, 492, 3778, 199, 504, 486, 5865, 280, 492, 2552, 199, 504, 486, 5865, 280, 492, 5262, 199, 504, 486, 5865, 280, 492, 1851, 1208, 199, 504, 486, 5865, 280, 492, 931, 1208, 199, 504, 486, 5865, 280, 492, 373, 4201, 199, 504, 486, 5865, 280, 492, 8434, 199, 504, 486, 5865, 280, 492, 9146, 199, 504, 486, 5865, 280, 492, 10110, 2190, 421, 199, 318, 2372, 1899, 5535, 8, 751, 12, 20366, 29, 797, 12, 2935, 1074, 29, 549, 12, 4928, 29, 5559, 14, 13716, 43, 63, 23007, 12, 326, 485, 4219, 694, 63, 2324, 29, 403, 304, 523, 408, 1767, 314, 3792, 402, 282, 922, 1159, 12027, 1584, 14, 819, 768, 466, 922, 26, 1059, 523, 768, 635, 922, 26, 29739, 523, 768, 466, 20366, 26, 2155, 523, 768, 635, 20366, 26, 7480, 370, 1218, 3680, 5510, 2, 2082, 340, 652, 3181, 1133, 2187, 523, 768, 466, 2935, 1074, 26, 2155, 523, 768, 635, 2935, 1074, 26, 7480, 370, 1104, 340, 3680, 5510, 2, 2082, 3495, 523, 768, 466, 4928, 26, 1059, 523, 768, 635, 4928, 26, 7309, 402, 491, 91, 5559, 14, 13716, 43, 63, 1761, 93, 523, 768, 4500, 26, 2008, 27, 334, 875, 12, 1059, 12, 1059, 9, 523, 768, 1107, 26, 11634, 3035, 7795, 570, 2656, 3792, 27, 314, 5726, 12027, 790, 570, 12, 272, 314, 4575, 12027, 790, 570, 436, 314, 922, 1159, 445, 91, 11497, 63, 1612, 93, 570, 523, 768, 3730, 2552, 14, 4619, 4858, 547, 26, 3979, 5629, 2082, 402, 314, 922, 883, 440, 506, 272, 12037, 523, 768, 3730, 2552, 14, 4619, 4858, 547, 26, 5044, 1005, 2003, 402, 314, 445, 91, 8215, 93, 2633, 12, 642, 272, 1919, 365, 4915, 340, 445, 91, 94, 4, 751, 8083, 5510, 93, 365, 440, 282, 2082, 436, 445, 91, 694, 1074, 93, 272, 365, 663, 370, 445, 91, 549, 93, 819, 408, 523, 340, 485, 4219, 694, 63, 2324, 365, 488, 26, 272, 485, 4219, 694, 63, 2324, 275, 3778, 14, 1002, 12054, 3567, 819, 922, 63, 694, 275, 485, 4219, 694, 63, 2324, 8, 751, 9, 523, 340, 440, 922, 63, 694, 26, 272, 746, 2552, 14, 4619, 4858, 547, 480, 6612, 7512, 5629, 402, 922, 1543, 83, 4065, 450, 922, 9, 819, 340, 4928, 508, 5262, 14, 13716, 43, 63, 23007, 26, 272, 4739, 275, 298, 24760, 2, 523, 916, 4928, 508, 5262, 14, 13716, 43, 63, 12115, 26, 272, 4739, 275, 298, 13487, 2, 523, 916, 4928, 508, 5262, 14, 13716, 43, 63, 4220, 23007, 26, 272, 4739, 275, 298, 825, 24760, 2, 523, 587, 26, 272, 746, 2552, 14, 9184, 2626, 547, 480, 5912, 12027, 790, 4928, 1543, 83, 4065, 450, 4928, 9, 819, 8635, 63, 694, 275, 3778, 14, 2042, 13005, 8, 751, 63, 694, 12, 3680, 5510, 531, 523, 340, 20366, 26, 272, 3778, 14, 13913, 17051, 7694, 5510, 63, 694, 12, 5262, 14, 20696, 63, 3022, 63, 6963, 3948, 523, 916, 2935, 1074, 436, 440, 747, 14, 515, 14, 6027, 8, 5510, 63, 694, 304, 272, 746, 2552, 14, 4619, 4858, 547, 480, 2042, 450, 83, 365, 440, 282, 2082, 2, 450, 8635, 63, 694, 9, 819, 372, 359, 1208, 14, 2042, 13005, 8, 5510, 63, 694, 12, 1300, 9, 881, 367, 1300, 315, 2097, 344, 4970, 83, 2, 450, 4739, 12, 298, 344, 4970, 83, 14, 5645, 2, 450, 4739, 12, 2432, 298, 11497, 63, 1612, 15261, 421, 199, 318, 2372, 2422, 1899, 5535, 8, 751, 12, 20366, 29, 797, 12, 2935, 1074, 29, 549, 12, 485, 4219, 694, 63, 2324, 29, 403, 304, 523, 408, 4590, 1806, 491, 91, 1002, 1899, 5535, 93, 370, 8044, 1584, 367, 1006, 12027, 790, 2943, 14, 819, 1666, 491, 91, 1002, 1899, 5535, 93, 367, 2436, 14, 819, 768, 4500, 26, 2008, 27, 334, 875, 12, 1211, 543, 1059, 465, 790, 12, 2008, 402, 334, 875, 12, 1059, 9, 465, 272, 574, 9, 819, 408, 523, 5922, 275, 8434, 14, 6672, 8, 1002, 1899, 5535, 12, 922, 12, 20366, 29, 8215, 12, 2935, 1074, 29, 694, 1074, 12, 2079, 485, 4219, 694, 63, 2324, 3699, 4219, 694, 63, 2324, 9, 523, 754, 275, 3842, 5091 ]
[ 199, 3, 199, 199, 3, 1898, 334, 35, 9, 8315, 12, 10219, 12, 7129, 12, 7760, 4475, 3277, 14, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 413, 14, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 4245, 12, 199, 3, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 199, 3, 499, 14, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 199, 3, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 298, 1179, 199, 3, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 199, 3, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 437, 3115, 199, 3, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 29785, 1549, 199, 3, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 8820, 12, 199, 3, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 5471, 2296, 12, 199, 3, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 7126, 12, 1549, 199, 3, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 9815, 1634, 199, 3, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 334, 6446, 199, 3, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 199, 3, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 421, 199, 624, 2377, 22667, 20529, 8635, 9330, 14, 199, 199, 624, 421, 199, 646, 2050, 199, 646, 747, 199, 646, 5145, 199, 646, 5549, 199, 199, 504, 5055, 492, 12863, 199, 504, 9143, 492, 7417, 199, 199, 504, 486, 5865, 280, 492, 3778, 199, 504, 486, 5865, 280, 492, 2552, 199, 504, 486, 5865, 280, 492, 5262, 199, 504, 486, 5865, 280, 492, 1851, 1208, 199, 504, 486, 5865, 280, 492, 931, 1208, 199, 504, 486, 5865, 280, 492, 373, 4201, 199, 504, 486, 5865, 280, 492, 8434, 199, 504, 486, 5865, 280, 492, 9146, 199, 504, 486, 5865, 280, 492, 10110, 2190, 421, 199, 318, 2372, 1899, 5535, 8, 751, 12, 20366, 29, 797, 12, 2935, 1074, 29, 549, 12, 4928, 29, 5559, 14, 13716, 43, 63, 23007, 12, 326, 485, 4219, 694, 63, 2324, 29, 403, 304, 523, 408, 1767, 314, 3792, 402, 282, 922, 1159, 12027, 1584, 14, 819, 768, 466, 922, 26, 1059, 523, 768, 635, 922, 26, 29739, 523, 768, 466, 20366, 26, 2155, 523, 768, 635, 20366, 26, 7480, 370, 1218, 3680, 5510, 2, 2082, 340, 652, 3181, 1133, 2187, 523, 768, 466, 2935, 1074, 26, 2155, 523, 768, 635, 2935, 1074, 26, 7480, 370, 1104, 340, 3680, 5510, 2, 2082, 3495, 523, 768, 466, 4928, 26, 1059, 523, 768, 635, 4928, 26, 7309, 402, 491, 91, 5559, 14, 13716, 43, 63, 1761, 93, 523, 768, 4500, 26, 2008, 27, 334, 875, 12, 1059, 12, 1059, 9, 523, 768, 1107, 26, 11634, 3035, 7795, 570, 2656, 3792, 27, 314, 5726, 12027, 790, 570, 12, 272, 314, 4575, 12027, 790, 570, 436, 314, 922, 1159, 445, 91, 11497, 63, 1612, 93, 570, 523, 768, 3730, 2552, 14, 4619, 4858, 547, 26, 3979, 5629, 2082, 402, 314, 922, 883, 440, 506, 272, 12037, 523, 768, 3730, 2552, 14, 4619, 4858, 547, 26, 5044, 1005, 2003, 402, 314, 445, 91, 8215, 93, 2633, 12, 642, 272, 1919, 365, 4915, 340, 445, 91, 94, 4, 751, 8083, 5510, 93, 365, 440, 282, 2082, 436, 445, 91, 694, 1074, 93, 272, 365, 663, 370, 445, 91, 549, 93, 819, 408, 523, 340, 485, 4219, 694, 63, 2324, 365, 488, 26, 272, 485, 4219, 694, 63, 2324, 275, 3778, 14, 1002, 12054, 3567, 819, 922, 63, 694, 275, 485, 4219, 694, 63, 2324, 8, 751, 9, 523, 340, 440, 922, 63, 694, 26, 272, 746, 2552, 14, 4619, 4858, 547, 480, 6612, 7512, 5629, 402, 922, 1543, 83, 4065, 450, 922, 9, 819, 340, 4928, 508, 5262, 14, 13716, 43, 63, 23007, 26, 272, 4739, 275, 298, 24760, 2, 523, 916, 4928, 508, 5262, 14, 13716, 43, 63, 12115, 26, 272, 4739, 275, 298, 13487, 2, 523, 916, 4928, 508, 5262, 14, 13716, 43, 63, 4220, 23007, 26, 272, 4739, 275, 298, 825, 24760, 2, 523, 587, 26, 272, 746, 2552, 14, 9184, 2626, 547, 480, 5912, 12027, 790, 4928, 1543, 83, 4065, 450, 4928, 9, 819, 8635, 63, 694, 275, 3778, 14, 2042, 13005, 8, 751, 63, 694, 12, 3680, 5510, 531, 523, 340, 20366, 26, 272, 3778, 14, 13913, 17051, 7694, 5510, 63, 694, 12, 5262, 14, 20696, 63, 3022, 63, 6963, 3948, 523, 916, 2935, 1074, 436, 440, 747, 14, 515, 14, 6027, 8, 5510, 63, 694, 304, 272, 746, 2552, 14, 4619, 4858, 547, 480, 2042, 450, 83, 365, 440, 282, 2082, 2, 450, 8635, 63, 694, 9, 819, 372, 359, 1208, 14, 2042, 13005, 8, 5510, 63, 694, 12, 1300, 9, 881, 367, 1300, 315, 2097, 344, 4970, 83, 2, 450, 4739, 12, 298, 344, 4970, 83, 14, 5645, 2, 450, 4739, 12, 2432, 298, 11497, 63, 1612, 15261, 421, 199, 318, 2372, 2422, 1899, 5535, 8, 751, 12, 20366, 29, 797, 12, 2935, 1074, 29, 549, 12, 485, 4219, 694, 63, 2324, 29, 403, 304, 523, 408, 4590, 1806, 491, 91, 1002, 1899, 5535, 93, 370, 8044, 1584, 367, 1006, 12027, 790, 2943, 14, 819, 1666, 491, 91, 1002, 1899, 5535, 93, 367, 2436, 14, 819, 768, 4500, 26, 2008, 27, 334, 875, 12, 1211, 543, 1059, 465, 790, 12, 2008, 402, 334, 875, 12, 1059, 9, 465, 272, 574, 9, 819, 408, 523, 5922, 275, 8434, 14, 6672, 8, 1002, 1899, 5535, 12, 922, 12, 20366, 29, 8215, 12, 2935, 1074, 29, 694, 1074, 12, 2079, 485, 4219, 694, 63, 2324, 3699, 4219, 694, 63, 2324, 9, 523, 754, 275, 3842, 5091, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
littlstar/chromium.src
build/android/surface_stats.py
44
3692
#!/usr/bin/env python # # Copyright (c) 2013 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Command line tool for continuously printing Android graphics surface statistics on the console. """ import collections import optparse import sys import time from pylib.device import device_utils from pylib.perf import surface_stats_collector from pylib.utils import run_tests_helper _FIELD_FORMAT = { 'jank_count (janks)': '%d', 'max_frame_delay (vsyncs)': '%d', 'avg_surface_fps (fps)': '%.2f', 'frame_lengths (vsyncs)': '%.3f', 'refresh_period (seconds)': '%.6f', } def _MergeResults(results, fields): merged_results = collections.defaultdict(list) for result in results: if ((fields != ['all'] and not result.name in fields) or result.value is None): continue name = '%s (%s)' % (result.name, result.unit) if isinstance(result.value, list): value = result.value else: value = [result.value] merged_results[name] += value for name, values in merged_results.iteritems(): merged_results[name] = sum(values) / float(len(values)) return merged_results def _GetTerminalHeight(): try: import fcntl, termios, struct except ImportError: return 0, 0 height, _, _, _ = struct.unpack('HHHH', fcntl.ioctl(0, termios.TIOCGWINSZ, struct.pack('HHHH', 0, 0, 0, 0))) return height def _PrintColumnTitles(results): for name in results.keys(): print '%s ' % name, print for name in results.keys(): print '%s ' % ('-' * len(name)), print def _PrintResults(results): for name, value in results.iteritems(): value = _FIELD_FORMAT.get(name, '%s') % value print value.rjust(len(name)) + ' ', print def main(argv): parser = optparse.OptionParser(usage='Usage: %prog [options]', description=__doc__) parser.add_option('-v', '--verbose', dest='verbose_count', default=0, action='count', help='Verbose level (multiple times for more)') parser.add_option('--device', help='Serial number of device we should use.') parser.add_option('-f', '--fields', dest='fields', default='jank_count,max_frame_delay,avg_surface_fps,' 'frame_lengths', help='Comma separated list of fields to display or "all".') parser.add_option('-d', '--delay', dest='delay', default=1, type='float', help='Time in seconds to sleep between updates.') options, _ = parser.parse_args(argv) run_tests_helper.SetLogLevel(options.verbose_count) device = device_utils.DeviceUtils(options.device) collector = surface_stats_collector.SurfaceStatsCollector(device) collector.DisableWarningAboutEmptyData() fields = options.fields.split(',') row_count = None try: collector.Start() while True: time.sleep(options.delay) results = collector.SampleResults() results = _MergeResults(results, fields) if not results: continue terminal_height = _GetTerminalHeight() if row_count is None or (terminal_height and row_count >= terminal_height - 3): _PrintColumnTitles(results) row_count = 0 _PrintResults(results) row_count += 1 except KeyboardInterrupt: sys.exit(0) finally: collector.Stop() if __name__ == '__main__': main(sys.argv)
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 334, 67, 9, 6171, 710, 12051, 6642, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 624, 3110, 1004, 4744, 367, 19922, 590, 16116, 14694, 24348, 13195, 199, 13724, 641, 314, 8559, 14, 199, 624, 199, 199, 646, 5055, 199, 646, 8691, 199, 646, 984, 199, 646, 900, 199, 199, 504, 29219, 14, 1782, 492, 2243, 63, 1208, 199, 504, 29219, 14, 9452, 492, 13195, 63, 3200, 63, 10946, 199, 504, 29219, 14, 1208, 492, 1255, 63, 2219, 63, 3676, 421, 199, 63, 8609, 63, 4807, 275, 469, 523, 283, 74, 3580, 63, 835, 334, 74, 25088, 11862, 1543, 68, 297, 523, 283, 988, 63, 1943, 63, 5814, 334, 3122, 1236, 1259, 11862, 1543, 68, 297, 523, 283, 8595, 63, 10992, 63, 24709, 334, 24709, 11862, 22769, 18, 70, 297, 523, 283, 1943, 63, 14563, 334, 3122, 1236, 1259, 11862, 22769, 19, 70, 297, 523, 283, 6635, 63, 5191, 334, 4515, 11862, 22769, 22, 70, 297, 199, 93, 421, 199, 318, 485, 11359, 6579, 8, 2604, 12, 1504, 304, 523, 9545, 63, 2604, 275, 5055, 14, 21501, 8, 513, 9, 523, 367, 754, 315, 2058, 26, 272, 340, 3666, 955, 1137, 788, 452, 418, 436, 440, 754, 14, 354, 315, 1504, 9, 503, 267, 754, 14, 585, 365, 488, 304, 489, 1980, 272, 536, 275, 1543, 83, 4366, 83, 3171, 450, 334, 1099, 14, 354, 12, 754, 14, 3248, 9, 272, 340, 1228, 8, 1099, 14, 585, 12, 769, 304, 489, 574, 275, 754, 14, 585, 272, 587, 26, 489, 574, 275, 359, 1099, 14, 585, 61, 272, 9545, 63, 2604, 59, 354, 61, 847, 574, 523, 367, 536, 12, 1338, 315, 9545, 63, 2604, 14, 4611, 837, 272, 9545, 63, 2604, 59, 354, 61, 275, 3089, 8, 1459, 9, 1182, 2069, 8, 552, 8, 1459, 430, 523, 372, 9545, 63, 2604, 421, 199, 318, 485, 1002, 22015, 8436, 837, 523, 862, 26, 272, 492, 12871, 12, 28725, 12, 2702, 523, 871, 3545, 26, 272, 372, 378, 12, 378, 523, 4569, 12, 5501, 5501, 485, 275, 2702, 14, 5301, 360, 10213, 10213, 297, 489, 12871, 14, 2308, 8077, 8, 16, 12, 28725, 14, 52, 2090, 4064, 7941, 18101, 12, 881, 2702, 14, 1389, 360, 10213, 10213, 297, 378, 12, 378, 12, 378, 12, 378, 1724, 523, 372, 4569, 421, 199, 318, 485, 5375, 4547, 52, 390, 2978, 8, 2604, 304, 523, 367, 536, 315, 2058, 14, 1612, 837, 272, 870, 1543, 83, 283, 450, 536, 12, 523, 870, 523, 367, 536, 315, 2058, 14, 1612, 837, 272, 870, 1543, 83, 283, 450, 12291, 7, 627, 822, 8, 354, 1826, 523, 870, 421, 199, 318, 485, 5375, 6579, 8, 2604, 304, 523, 367, 536, 12, 574, 315, 2058, 14, 4611, 837, 272, 574, 275, 485, 8609, 63, 4807, 14, 362, 8, 354, 12, 1543, 83, 358, 450, 574, 272, 870, 574, 14, 24473, 8, 552, 8, 354, 430, 435, 283, 1656, 523, 870, 421, 199, 318, 2446, 8, 3020, 304, 523, 1798, 275, 8691, 14, 14553, 8, 3807, 534, 7692, 26, 450, 6595, 359, 1419, 4300, 639, 1369, 18971, 1301, 3368, 523, 1798, 14, 525, 63, 1422, 3654, 86, 297, 490, 2850, 3832, 297, 490, 2053, 534, 3832, 63, 835, 297, 490, 849, 29, 16, 12, 490, 1595, 534, 835, 297, 490, 1720, 534, 21879, 2166, 334, 6048, 5431, 367, 1655, 5942, 523, 1798, 14, 525, 63, 1422, 4517, 1782, 297, 490, 1720, 534, 3571, 1329, 402, 2243, 781, 1077, 675, 2659, 523, 1798, 14, 525, 63, 1422, 3654, 70, 297, 490, 2850, 955, 297, 490, 2053, 534, 955, 297, 490, 849, 534, 74, 3580, 63, 835, 12, 988, 63, 1943, 63, 5814, 12, 8595, 63, 10992, 63, 24709, 2584, 717, 283, 1943, 63, 14563, 297, 490, 1720, 534, 25732, 11673, 769, 402, 1504, 370, 2929, 503, 298, 452, 1674, 358, 523, 1798, 14, 525, 63, 1422, 3654, 68, 297, 490, 2850, 5814, 297, 490, 2053, 534, 5814, 297, 490, 849, 29, 17, 12, 490, 730, 534, 1609, 297, 490, 1720, 534, 1366, 315, 4696, 370, 9435, 3382, 7029, 2659, 819, 1511, 12, 485, 275, 1798, 14, 1122, 63, 589, 8, 3020, 9, 523, 1255, 63, 2219, 63, 3676, 14, 1084, 2445, 4670, 8, 1419, 14, 3832, 63, 835, 9, 819, 2243, 275, 2243, 63, 1208, 14, 2510, 7535, 8, 1419, 14, 1782, 9, 523, 14910, 275, 13195, 63, 3200, 63, 10946, 14, 16923, 8257, 12852, 8, 1782, 9, 523, 14910, 14, 13707, 3849, 18816, 4699, 1451, 342, 819, 1504, 275, 1511, 14, 955, 14, 1294, 11917, 523, 1962, 63, 835, 275, 488, 819, 862, 26, 272, 14910, 14, 3162, 342, 272, 1830, 715, 26, 489, 900, 14, 4532, 8, 1419, 14, 5814, 9, 489, 2058, 275, 14910, 14, 8176, 6579, 342, 489, 2058, 275, 485, 11359, 6579, 8, 2604, 12, 1504, 9, 2541, 340, 440, 2058, 26, 267, 1980, 2541, 11167, 63, 3333, 275, 485, 1002, 22015, 8436, 342, 489, 340, 1962, 63, 835, 365, 488, 503, 334, 12010, 63, 3333, 436, 881, 1962, 63, 835, 2356, 11167, 63, 3333, 446, 650, 304, 267, 485, 5375, 4547, 52, 390, 2978, 8, 2604, 9, 267, 1962, 63, 835, 275, 378, 2541, 485, 5375, 6579, 8, 2604, 9, 489, 1962, 63, 835, 847, 413, 523, 871, 13483, 26, 272, 984, 14, 2224, 8, 16, 9, 523, 3753, 26, 272, 14910, 14, 6293, 342, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 523, 2446, 8, 1274, 14, 3020, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 334, 67, 9, 6171, 710, 12051, 6642, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 624, 3110, 1004, 4744, 367, 19922, 590, 16116, 14694, 24348, 13195, 199, 13724, 641, 314, 8559, 14, 199, 624, 199, 199, 646, 5055, 199, 646, 8691, 199, 646, 984, 199, 646, 900, 199, 199, 504, 29219, 14, 1782, 492, 2243, 63, 1208, 199, 504, 29219, 14, 9452, 492, 13195, 63, 3200, 63, 10946, 199, 504, 29219, 14, 1208, 492, 1255, 63, 2219, 63, 3676, 421, 199, 63, 8609, 63, 4807, 275, 469, 523, 283, 74, 3580, 63, 835, 334, 74, 25088, 11862, 1543, 68, 297, 523, 283, 988, 63, 1943, 63, 5814, 334, 3122, 1236, 1259, 11862, 1543, 68, 297, 523, 283, 8595, 63, 10992, 63, 24709, 334, 24709, 11862, 22769, 18, 70, 297, 523, 283, 1943, 63, 14563, 334, 3122, 1236, 1259, 11862, 22769, 19, 70, 297, 523, 283, 6635, 63, 5191, 334, 4515, 11862, 22769, 22, 70, 297, 199, 93, 421, 199, 318, 485, 11359, 6579, 8, 2604, 12, 1504, 304, 523, 9545, 63, 2604, 275, 5055, 14, 21501, 8, 513, 9, 523, 367, 754, 315, 2058, 26, 272, 340, 3666, 955, 1137, 788, 452, 418, 436, 440, 754, 14, 354, 315, 1504, 9, 503, 267, 754, 14, 585, 365, 488, 304, 489, 1980, 272, 536, 275, 1543, 83, 4366, 83, 3171, 450, 334, 1099, 14, 354, 12, 754, 14, 3248, 9, 272, 340, 1228, 8, 1099, 14, 585, 12, 769, 304, 489, 574, 275, 754, 14, 585, 272, 587, 26, 489, 574, 275, 359, 1099, 14, 585, 61, 272, 9545, 63, 2604, 59, 354, 61, 847, 574, 523, 367, 536, 12, 1338, 315, 9545, 63, 2604, 14, 4611, 837, 272, 9545, 63, 2604, 59, 354, 61, 275, 3089, 8, 1459, 9, 1182, 2069, 8, 552, 8, 1459, 430, 523, 372, 9545, 63, 2604, 421, 199, 318, 485, 1002, 22015, 8436, 837, 523, 862, 26, 272, 492, 12871, 12, 28725, 12, 2702, 523, 871, 3545, 26, 272, 372, 378, 12, 378, 523, 4569, 12, 5501, 5501, 485, 275, 2702, 14, 5301, 360, 10213, 10213, 297, 489, 12871, 14, 2308, 8077, 8, 16, 12, 28725, 14, 52, 2090, 4064, 7941, 18101, 12, 881, 2702, 14, 1389, 360, 10213, 10213, 297, 378, 12, 378, 12, 378, 12, 378, 1724, 523, 372, 4569, 421, 199, 318, 485, 5375, 4547, 52, 390, 2978, 8, 2604, 304, 523, 367, 536, 315, 2058, 14, 1612, 837, 272, 870, 1543, 83, 283, 450, 536, 12, 523, 870, 523, 367, 536, 315, 2058, 14, 1612, 837, 272, 870, 1543, 83, 283, 450, 12291, 7, 627, 822, 8, 354, 1826, 523, 870, 421, 199, 318, 485, 5375, 6579, 8, 2604, 304, 523, 367, 536, 12, 574, 315, 2058, 14, 4611, 837, 272, 574, 275, 485, 8609, 63, 4807, 14, 362, 8, 354, 12, 1543, 83, 358, 450, 574, 272, 870, 574, 14, 24473, 8, 552, 8, 354, 430, 435, 283, 1656, 523, 870, 421, 199, 318, 2446, 8, 3020, 304, 523, 1798, 275, 8691, 14, 14553, 8, 3807, 534, 7692, 26, 450, 6595, 359, 1419, 4300, 639, 1369, 18971, 1301, 3368, 523, 1798, 14, 525, 63, 1422, 3654, 86, 297, 490, 2850, 3832, 297, 490, 2053, 534, 3832, 63, 835, 297, 490, 849, 29, 16, 12, 490, 1595, 534, 835, 297, 490, 1720, 534, 21879, 2166, 334, 6048, 5431, 367, 1655, 5942, 523, 1798, 14, 525, 63, 1422, 4517, 1782, 297, 490, 1720, 534, 3571, 1329, 402, 2243, 781, 1077, 675, 2659, 523, 1798, 14, 525, 63, 1422, 3654, 70, 297, 490, 2850, 955, 297, 490, 2053, 534, 955, 297, 490, 849, 534, 74, 3580, 63, 835, 12, 988, 63, 1943, 63, 5814, 12, 8595, 63, 10992, 63, 24709, 2584, 717, 283, 1943, 63, 14563, 297, 490, 1720, 534, 25732, 11673, 769, 402, 1504, 370, 2929, 503, 298, 452, 1674, 358, 523, 1798, 14, 525, 63, 1422, 3654, 68, 297, 490, 2850, 5814, 297, 490, 2053, 534, 5814, 297, 490, 849, 29, 17, 12, 490, 730, 534, 1609, 297, 490, 1720, 534, 1366, 315, 4696, 370, 9435, 3382, 7029, 2659, 819, 1511, 12, 485, 275, 1798, 14, 1122, 63, 589, 8, 3020, 9, 523, 1255, 63, 2219, 63, 3676, 14, 1084, 2445, 4670, 8, 1419, 14, 3832, 63, 835, 9, 819, 2243, 275, 2243, 63, 1208, 14, 2510, 7535, 8, 1419, 14, 1782, 9, 523, 14910, 275, 13195, 63, 3200, 63, 10946, 14, 16923, 8257, 12852, 8, 1782, 9, 523, 14910, 14, 13707, 3849, 18816, 4699, 1451, 342, 819, 1504, 275, 1511, 14, 955, 14, 1294, 11917, 523, 1962, 63, 835, 275, 488, 819, 862, 26, 272, 14910, 14, 3162, 342, 272, 1830, 715, 26, 489, 900, 14, 4532, 8, 1419, 14, 5814, 9, 489, 2058, 275, 14910, 14, 8176, 6579, 342, 489, 2058, 275, 485, 11359, 6579, 8, 2604, 12, 1504, 9, 2541, 340, 440, 2058, 26, 267, 1980, 2541, 11167, 63, 3333, 275, 485, 1002, 22015, 8436, 342, 489, 340, 1962, 63, 835, 365, 488, 503, 334, 12010, 63, 3333, 436, 881, 1962, 63, 835, 2356, 11167, 63, 3333, 446, 650, 304, 267, 485, 5375, 4547, 52, 390, 2978, 8, 2604, 9, 267, 1962, 63, 835, 275, 378, 2541, 485, 5375, 6579, 8, 2604, 9, 489, 1962, 63, 835, 847, 413, 523, 871, 13483, 26, 272, 984, 14, 2224, 8, 16, 9, 523, 3753, 26, 272, 14910, 14, 6293, 342, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 523, 2446, 8, 1274, 14, 3020, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Y3K/django
django/contrib/auth/hashers.py
211
17463
from __future__ import unicode_literals import base64 import binascii import hashlib import importlib from collections import OrderedDict from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.core.signals import setting_changed from django.dispatch import receiver from django.utils import lru_cache from django.utils.crypto import ( constant_time_compare, get_random_string, pbkdf2, ) from django.utils.encoding import force_bytes, force_str, force_text from django.utils.module_loading import import_string from django.utils.translation import ugettext_noop as _ UNUSABLE_PASSWORD_PREFIX = '!' # This will never be a valid encoded hash UNUSABLE_PASSWORD_SUFFIX_LENGTH = 40 # number of random chars to add after UNUSABLE_PASSWORD_PREFIX def is_password_usable(encoded): if encoded is None or encoded.startswith(UNUSABLE_PASSWORD_PREFIX): return False try: identify_hasher(encoded) except ValueError: return False return True def check_password(password, encoded, setter=None, preferred='default'): """ Returns a boolean of whether the raw password matches the three part encoded digest. If setter is specified, it'll be called when you need to regenerate the password. """ if password is None or not is_password_usable(encoded): return False preferred = get_hasher(preferred) hasher = identify_hasher(encoded) must_update = hasher.algorithm != preferred.algorithm if not must_update: must_update = preferred.must_update(encoded) is_correct = hasher.verify(password, encoded) if setter and is_correct and must_update: setter(password) return is_correct def make_password(password, salt=None, hasher='default'): """ Turn a plain-text password into a hash for database storage Same as encode() but generates a new random salt. If password is None then a concatenation of UNUSABLE_PASSWORD_PREFIX and a random string will be returned which disallows logins. Additional random string reduces chances of gaining access to staff or superuser accounts. See ticket #20079 for more info. """ if password is None: return UNUSABLE_PASSWORD_PREFIX + get_random_string(UNUSABLE_PASSWORD_SUFFIX_LENGTH) hasher = get_hasher(hasher) if not salt: salt = hasher.salt() return hasher.encode(password, salt) @lru_cache.lru_cache() def get_hashers(): hashers = [] for hasher_path in settings.PASSWORD_HASHERS: hasher_cls = import_string(hasher_path) hasher = hasher_cls() if not getattr(hasher, 'algorithm'): raise ImproperlyConfigured("hasher doesn't specify an " "algorithm name: %s" % hasher_path) hashers.append(hasher) return hashers @lru_cache.lru_cache() def get_hashers_by_algorithm(): return {hasher.algorithm: hasher for hasher in get_hashers()} @receiver(setting_changed) def reset_hashers(**kwargs): if kwargs['setting'] == 'PASSWORD_HASHERS': get_hashers.cache_clear() get_hashers_by_algorithm.cache_clear() def get_hasher(algorithm='default'): """ Returns an instance of a loaded password hasher. If algorithm is 'default', the default hasher will be returned. This function will also lazy import hashers specified in your settings file if needed. """ if hasattr(algorithm, 'algorithm'): return algorithm elif algorithm == 'default': return get_hashers()[0] else: hashers = get_hashers_by_algorithm() try: return hashers[algorithm] except KeyError: raise ValueError("Unknown password hashing algorithm '%s'. " "Did you specify it in the PASSWORD_HASHERS " "setting?" % algorithm) def identify_hasher(encoded): """ Returns an instance of a loaded password hasher. Identifies hasher algorithm by examining encoded hash, and calls get_hasher() to return hasher. Raises ValueError if algorithm cannot be identified, or if hasher is not loaded. """ # Ancient versions of Django created plain MD5 passwords and accepted # MD5 passwords with an empty salt. if ((len(encoded) == 32 and '$' not in encoded) or (len(encoded) == 37 and encoded.startswith('md5$$'))): algorithm = 'unsalted_md5' # Ancient versions of Django accepted SHA1 passwords with an empty salt. elif len(encoded) == 46 and encoded.startswith('sha1$$'): algorithm = 'unsalted_sha1' else: algorithm = encoded.split('$', 1)[0] return get_hasher(algorithm) def mask_hash(hash, show=6, char="*"): """ Returns the given hash, with only the first ``show`` number shown. The rest are masked with ``char`` for security reasons. """ masked = hash[:show] masked += char * len(hash[show:]) return masked class BasePasswordHasher(object): """ Abstract base class for password hashers When creating your own hasher, you need to override algorithm, verify(), encode() and safe_summary(). PasswordHasher objects are immutable. """ algorithm = None library = None def _load_library(self): if self.library is not None: if isinstance(self.library, (tuple, list)): name, mod_path = self.library else: mod_path = self.library try: module = importlib.import_module(mod_path) except ImportError as e: raise ValueError("Couldn't load %r algorithm library: %s" % (self.__class__.__name__, e)) return module raise ValueError("Hasher %r doesn't specify a library attribute" % self.__class__.__name__) def salt(self): """ Generates a cryptographically secure nonce salt in ASCII """ return get_random_string() def verify(self, password, encoded): """ Checks if the given password is correct """ raise NotImplementedError('subclasses of BasePasswordHasher must provide a verify() method') def encode(self, password, salt): """ Creates an encoded database value The result is normally formatted as "algorithm$salt$hash" and must be fewer than 128 characters. """ raise NotImplementedError('subclasses of BasePasswordHasher must provide an encode() method') def safe_summary(self, encoded): """ Returns a summary of safe values The result is a dictionary and will be used where the password field must be displayed to construct a safe representation of the password. """ raise NotImplementedError('subclasses of BasePasswordHasher must provide a safe_summary() method') def must_update(self, encoded): return False class PBKDF2PasswordHasher(BasePasswordHasher): """ Secure password hashing using the PBKDF2 algorithm (recommended) Configured to use PBKDF2 + HMAC + SHA256. The result is a 64 byte binary string. Iterations may be changed safely but you must rename the algorithm if you change SHA256. """ algorithm = "pbkdf2_sha256" iterations = 24000 digest = hashlib.sha256 def encode(self, password, salt, iterations=None): assert password is not None assert salt and '$' not in salt if not iterations: iterations = self.iterations hash = pbkdf2(password, salt, iterations, digest=self.digest) hash = base64.b64encode(hash).decode('ascii').strip() return "%s$%d$%s$%s" % (self.algorithm, iterations, salt, hash) def verify(self, password, encoded): algorithm, iterations, salt, hash = encoded.split('$', 3) assert algorithm == self.algorithm encoded_2 = self.encode(password, salt, int(iterations)) return constant_time_compare(encoded, encoded_2) def safe_summary(self, encoded): algorithm, iterations, salt, hash = encoded.split('$', 3) assert algorithm == self.algorithm return OrderedDict([ (_('algorithm'), algorithm), (_('iterations'), iterations), (_('salt'), mask_hash(salt)), (_('hash'), mask_hash(hash)), ]) def must_update(self, encoded): algorithm, iterations, salt, hash = encoded.split('$', 3) return int(iterations) != self.iterations class PBKDF2SHA1PasswordHasher(PBKDF2PasswordHasher): """ Alternate PBKDF2 hasher which uses SHA1, the default PRF recommended by PKCS #5. This is compatible with other implementations of PBKDF2, such as openssl's PKCS5_PBKDF2_HMAC_SHA1(). """ algorithm = "pbkdf2_sha1" digest = hashlib.sha1 class BCryptSHA256PasswordHasher(BasePasswordHasher): """ Secure password hashing using the bcrypt algorithm (recommended) This is considered by many to be the most secure algorithm but you must first install the bcrypt library. Please be warned that this library depends on native C code and might cause portability issues. """ algorithm = "bcrypt_sha256" digest = hashlib.sha256 library = ("bcrypt", "bcrypt") rounds = 12 def salt(self): bcrypt = self._load_library() return bcrypt.gensalt(rounds=self.rounds) def encode(self, password, salt): bcrypt = self._load_library() # Need to reevaluate the force_bytes call once bcrypt is supported on # Python 3 # Hash the password prior to using bcrypt to prevent password truncation # See: https://code.djangoproject.com/ticket/20138 if self.digest is not None: # We use binascii.hexlify here because Python3 decided that a hex encoded # bytestring is somehow a unicode. password = binascii.hexlify(self.digest(force_bytes(password)).digest()) else: password = force_bytes(password) data = bcrypt.hashpw(password, salt) return "%s$%s" % (self.algorithm, force_text(data)) def verify(self, password, encoded): algorithm, data = encoded.split('$', 1) assert algorithm == self.algorithm bcrypt = self._load_library() # Hash the password prior to using bcrypt to prevent password truncation # See: https://code.djangoproject.com/ticket/20138 if self.digest is not None: # We use binascii.hexlify here because Python3 decided that a hex encoded # bytestring is somehow a unicode. password = binascii.hexlify(self.digest(force_bytes(password)).digest()) else: password = force_bytes(password) # Ensure that our data is a bytestring data = force_bytes(data) # force_bytes() necessary for py-bcrypt compatibility hashpw = force_bytes(bcrypt.hashpw(password, data)) return constant_time_compare(data, hashpw) def safe_summary(self, encoded): algorithm, empty, algostr, work_factor, data = encoded.split('$', 4) assert algorithm == self.algorithm salt, checksum = data[:22], data[22:] return OrderedDict([ (_('algorithm'), algorithm), (_('work factor'), work_factor), (_('salt'), mask_hash(salt)), (_('checksum'), mask_hash(checksum)), ]) def must_update(self, encoded): algorithm, empty, algostr, rounds, data = encoded.split('$', 4) return int(rounds) != self.rounds class BCryptPasswordHasher(BCryptSHA256PasswordHasher): """ Secure password hashing using the bcrypt algorithm This is considered by many to be the most secure algorithm but you must first install the bcrypt library. Please be warned that this library depends on native C code and might cause portability issues. This hasher does not first hash the password which means it is subject to the 72 character bcrypt password truncation, most use cases should prefer the BCryptSha512PasswordHasher. See: https://code.djangoproject.com/ticket/20138 """ algorithm = "bcrypt" digest = None class SHA1PasswordHasher(BasePasswordHasher): """ The SHA1 password hashing algorithm (not recommended) """ algorithm = "sha1" def encode(self, password, salt): assert password is not None assert salt and '$' not in salt hash = hashlib.sha1(force_bytes(salt + password)).hexdigest() return "%s$%s$%s" % (self.algorithm, salt, hash) def verify(self, password, encoded): algorithm, salt, hash = encoded.split('$', 2) assert algorithm == self.algorithm encoded_2 = self.encode(password, salt) return constant_time_compare(encoded, encoded_2) def safe_summary(self, encoded): algorithm, salt, hash = encoded.split('$', 2) assert algorithm == self.algorithm return OrderedDict([ (_('algorithm'), algorithm), (_('salt'), mask_hash(salt, show=2)), (_('hash'), mask_hash(hash)), ]) class MD5PasswordHasher(BasePasswordHasher): """ The Salted MD5 password hashing algorithm (not recommended) """ algorithm = "md5" def encode(self, password, salt): assert password is not None assert salt and '$' not in salt hash = hashlib.md5(force_bytes(salt + password)).hexdigest() return "%s$%s$%s" % (self.algorithm, salt, hash) def verify(self, password, encoded): algorithm, salt, hash = encoded.split('$', 2) assert algorithm == self.algorithm encoded_2 = self.encode(password, salt) return constant_time_compare(encoded, encoded_2) def safe_summary(self, encoded): algorithm, salt, hash = encoded.split('$', 2) assert algorithm == self.algorithm return OrderedDict([ (_('algorithm'), algorithm), (_('salt'), mask_hash(salt, show=2)), (_('hash'), mask_hash(hash)), ]) class UnsaltedSHA1PasswordHasher(BasePasswordHasher): """ Very insecure algorithm that you should *never* use; stores SHA1 hashes with an empty salt. This class is implemented because Django used to accept such password hashes. Some older Django installs still have these values lingering around so we need to handle and upgrade them properly. """ algorithm = "unsalted_sha1" def salt(self): return '' def encode(self, password, salt): assert salt == '' hash = hashlib.sha1(force_bytes(password)).hexdigest() return 'sha1$$%s' % hash def verify(self, password, encoded): encoded_2 = self.encode(password, '') return constant_time_compare(encoded, encoded_2) def safe_summary(self, encoded): assert encoded.startswith('sha1$$') hash = encoded[6:] return OrderedDict([ (_('algorithm'), self.algorithm), (_('hash'), mask_hash(hash)), ]) class UnsaltedMD5PasswordHasher(BasePasswordHasher): """ Incredibly insecure algorithm that you should *never* use; stores unsalted MD5 hashes without the algorithm prefix, also accepts MD5 hashes with an empty salt. This class is implemented because Django used to store passwords this way and to accept such password hashes. Some older Django installs still have these values lingering around so we need to handle and upgrade them properly. """ algorithm = "unsalted_md5" def salt(self): return '' def encode(self, password, salt): assert salt == '' return hashlib.md5(force_bytes(password)).hexdigest() def verify(self, password, encoded): if len(encoded) == 37 and encoded.startswith('md5$$'): encoded = encoded[5:] encoded_2 = self.encode(password, '') return constant_time_compare(encoded, encoded_2) def safe_summary(self, encoded): return OrderedDict([ (_('algorithm'), self.algorithm), (_('hash'), mask_hash(encoded, show=3)), ]) class CryptPasswordHasher(BasePasswordHasher): """ Password hashing using UNIX crypt (not recommended) The crypt module is not supported on all platforms. """ algorithm = "crypt" library = "crypt" def salt(self): return get_random_string(2) def encode(self, password, salt): crypt = self._load_library() assert len(salt) == 2 data = crypt.crypt(force_str(password), salt) # we don't need to store the salt, but Django used to do this return "%s$%s$%s" % (self.algorithm, '', data) def verify(self, password, encoded): crypt = self._load_library() algorithm, salt, data = encoded.split('$', 2) assert algorithm == self.algorithm return constant_time_compare(data, crypt.crypt(force_str(password), data)) def safe_summary(self, encoded): algorithm, salt, data = encoded.split('$', 2) assert algorithm == self.algorithm return OrderedDict([ (_('algorithm'), algorithm), (_('salt'), salt), (_('hash'), mask_hash(data, show=3)), ])
bsd-3-clause
[ 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 1300, 772, 199, 646, 14755, 199, 646, 8337, 199, 646, 14802, 199, 504, 5055, 492, 8773, 199, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 1018, 14, 3924, 492, 11897, 199, 504, 1639, 14, 1018, 14, 10458, 492, 4260, 63, 2489, 199, 504, 1639, 14, 6052, 492, 13035, 199, 504, 1639, 14, 1208, 492, 634, 6558, 63, 1637, 199, 504, 1639, 14, 1208, 14, 10316, 492, 334, 272, 4413, 63, 521, 63, 5785, 12, 664, 63, 2355, 63, 875, 12, 10446, 28996, 18, 12, 199, 9, 199, 504, 1639, 14, 1208, 14, 2991, 492, 3542, 63, 2394, 12, 3542, 63, 495, 12, 3542, 63, 505, 199, 504, 1639, 14, 1208, 14, 578, 63, 8786, 492, 492, 63, 875, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 63, 12921, 465, 485, 199, 199, 53, 1440, 51, 2617, 63, 9032, 63, 6351, 275, 29376, 221, 327, 961, 911, 7078, 506, 282, 1686, 5737, 2631, 199, 53, 1440, 51, 2617, 63, 9032, 63, 12273, 63, 9127, 275, 6335, 221, 327, 1329, 402, 2196, 8365, 370, 1050, 2410, 738, 1440, 51, 2617, 63, 9032, 63, 6351, 421, 199, 318, 365, 63, 2060, 63, 14418, 8, 8167, 304, 272, 340, 5737, 365, 488, 503, 5737, 14, 2460, 8, 53, 1440, 51, 2617, 63, 9032, 63, 6351, 304, 267, 372, 756, 272, 862, 26, 267, 10405, 63, 28885, 8, 8167, 9, 272, 871, 1722, 26, 267, 372, 756, 272, 372, 715, 421, 199, 318, 1104, 63, 2060, 8, 2060, 12, 5737, 12, 18743, 29, 403, 12, 14388, 534, 885, 735, 272, 408, 272, 1803, 282, 5046, 402, 3775, 314, 3066, 2505, 4450, 314, 7795, 272, 1777, 5737, 10017, 14, 339, 982, 18743, 365, 2013, 12, 652, 7171, 506, 2797, 1380, 1265, 1929, 370, 272, 30943, 314, 2505, 14, 272, 408, 272, 340, 2505, 365, 488, 503, 440, 365, 63, 2060, 63, 14418, 8, 8167, 304, 267, 372, 756, 339, 14388, 275, 664, 63, 28885, 8, 17477, 9, 272, 19009, 275, 10405, 63, 28885, 8, 8167, 9, 339, 1471, 63, 873, 275, 19009, 14, 8833, 1137, 14388, 14, 8833, 272, 340, 440, 1471, 63, 873, 26, 267, 1471, 63, 873, 275, 14388, 14, 7790, 63, 873, 8, 8167, 9, 272, 365, 63, 4525, 275, 19009, 14, 4712, 8, 2060, 12, 5737, 9, 272, 340, 18743, 436, 365, 63, 4525, 436, 1471, 63, 873, 26, 267, 18743, 8, 2060, 9, 272, 372, 365, 63, 4525, 421, 199, 318, 1852, 63, 2060, 8, 2060, 12, 10105, 29, 403, 12, 19009, 534, 885, 735, 272, 408, 272, 16147, 282, 8971, 13, 505, 2505, 1901, 282, 2631, 367, 3050, 4887, 339, 14766, 465, 3752, 342, 1325, 12821, 282, 892, 2196, 10105, 14, 272, 982, 2505, 365, 488, 2066, 282, 28207, 402, 272, 738, 1440, 51, 2617, 63, 9032, 63, 6351, 436, 282, 2196, 1059, 911, 506, 2138, 272, 1314, 2153, 24077, 4676, 83, 14, 10961, 2196, 1059, 295, 10569, 682, 13236, 272, 402, 15334, 316, 2879, 370, 12622, 503, 32590, 12639, 14, 272, 1666, 12052, 327, 1840, 1965, 367, 1655, 2256, 14, 272, 408, 272, 340, 2505, 365, 488, 26, 267, 372, 738, 1440, 51, 2617, 63, 9032, 63, 6351, 435, 664, 63, 2355, 63, 875, 8, 53, 1440, 51, 2617, 63, 9032, 63, 12273, 63, 9127, 9, 272, 19009, 275, 664, 63, 28885, 8, 28885, 9, 339, 340, 440, 10105, 26, 267, 10105, 275, 19009, 14, 12597, 342, 339, 372, 19009, 14, 2143, 8, 2060, 12, 10105, 9, 421, 199, 32, 25003, 63, 1637, 14, 25003, 63, 1637, 342, 199, 318, 664, 63, 31342, 837, 272, 2631, 1192, 275, 942, 272, 367, 19009, 63, 515, 315, 2202, 14, 9032, 63, 13533, 31700, 26, 267, 19009, 63, 1886, 275, 492, 63, 875, 8, 28885, 63, 515, 9, 267, 19009, 275, 19009, 63, 1886, 342, 267, 340, 440, 2519, 8, 28885, 12, 283, 8833, 735, 288, 746, 11897, 480, 28885, 3181, 1133, 4165, 376, 298, 4318, 298, 8833, 536, 26, 450, 83, 2, 450, 19009, 63, 515, 9, 267, 2631, 1192, 14, 740, 8, 28885, 9, 272, 372, 2631, 1192, 421, 199, 32, 25003, 63, 1637, 14, 25003, 63, 1637, 342, 199, 318, 664, 63, 31342, 63, 991, 63, 8833, 837, 272, 372, 469, 28885, 14, 8833, 26, 19009, 367, 19009, 315, 664, 63, 31342, 12737, 421, 199, 32, 10244, 8, 6031, 63, 2489, 9, 199, 318, 5305, 63, 31342, 3682, 958, 304, 272, 340, 2074, 459, 6031, 418, 508, 283, 9032, 63, 13533, 31700, 356, 267, 664, 63, 31342, 14, 1637, 63, 3584, 342, 267, 664, 63, 31342, 63, 991, 63, 8833, 14, 1637, 63, 3584, 342, 421, 199, 318, 664, 63, 28885, 8, 8833, 534, 885, 735, 272, 408, 272, 1803, 376, 1256, 402, 282, 6511, 2505, 19009, 14, 339, 982, 5563, 365, 283, 885, 297, 314, 849, 19009, 911, 506, 2138, 14, 272, 961, 805, 911, 2597, 9617, 492, 2631, 1192, 2013, 315, 2195, 272, 2202, 570, 340, 4346, 14, 272, 408, 272, 340, 2688, 8, 8833, 12, 283, 8833, 735, 267, 372, 5563, 339, 916, 5563, 508, 283, 885, 356, 267, 372, 664, 63, 31342, 3430, 16, 61, 339, 587, 26, 267, 2631, 1192, 275, 664, 63, 31342, 63, 991, 63, 8833, 342, 267, 862, 26, 288, 372, 2631, 1192, 59, 8833, 61, 267, 871, 4067, 26, 288, 746, 1722, 480, 5912, 2505, 25223, 5563, 1543, 83, 1370, 298, 2490, 298, 17366, 1265, 4165, 652, 315, 314, 21705, 5172, 63, 13533, 31700, 298, 2490, 298, 6031, 13472, 450, 5563, 9, 421, 199, 318, 10405, 63, 28885, 8, 8167, 304, 272, 408, 272, 1803, 376, 1256, 402, 282, 6511, 2505, 19009, 14, 339, 473, 2433, 397, 19009, 5563, 701, 15735, 7969, 5737, 2631, 12, 436, 4882, 272, 664, 63, 28885, 342, 370, 372, 19009, 14, 6218, 1722, 340, 272, 5563, 3913, 506, 15836, 12, 503, 340, 19009, 365, 440, 6511, 14, 272, 408, 272, 327, 1626, 559, 484, 5459, 402, 5634, 2737, 8971, 15830, 21, 19572, 436, 10226, 272, 327, 15830, 21, 19572, 543, 376, 2701, 10105, 14, 272, 340, 3666, 552, 8, 8167, 9, 508, 4337, 436, 25271, 440, 315, 5737, 9, 503, 288, 334, 552, 8 ]
[ 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 1300, 772, 199, 646, 14755, 199, 646, 8337, 199, 646, 14802, 199, 504, 5055, 492, 8773, 199, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 1018, 14, 3924, 492, 11897, 199, 504, 1639, 14, 1018, 14, 10458, 492, 4260, 63, 2489, 199, 504, 1639, 14, 6052, 492, 13035, 199, 504, 1639, 14, 1208, 492, 634, 6558, 63, 1637, 199, 504, 1639, 14, 1208, 14, 10316, 492, 334, 272, 4413, 63, 521, 63, 5785, 12, 664, 63, 2355, 63, 875, 12, 10446, 28996, 18, 12, 199, 9, 199, 504, 1639, 14, 1208, 14, 2991, 492, 3542, 63, 2394, 12, 3542, 63, 495, 12, 3542, 63, 505, 199, 504, 1639, 14, 1208, 14, 578, 63, 8786, 492, 492, 63, 875, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 63, 12921, 465, 485, 199, 199, 53, 1440, 51, 2617, 63, 9032, 63, 6351, 275, 29376, 221, 327, 961, 911, 7078, 506, 282, 1686, 5737, 2631, 199, 53, 1440, 51, 2617, 63, 9032, 63, 12273, 63, 9127, 275, 6335, 221, 327, 1329, 402, 2196, 8365, 370, 1050, 2410, 738, 1440, 51, 2617, 63, 9032, 63, 6351, 421, 199, 318, 365, 63, 2060, 63, 14418, 8, 8167, 304, 272, 340, 5737, 365, 488, 503, 5737, 14, 2460, 8, 53, 1440, 51, 2617, 63, 9032, 63, 6351, 304, 267, 372, 756, 272, 862, 26, 267, 10405, 63, 28885, 8, 8167, 9, 272, 871, 1722, 26, 267, 372, 756, 272, 372, 715, 421, 199, 318, 1104, 63, 2060, 8, 2060, 12, 5737, 12, 18743, 29, 403, 12, 14388, 534, 885, 735, 272, 408, 272, 1803, 282, 5046, 402, 3775, 314, 3066, 2505, 4450, 314, 7795, 272, 1777, 5737, 10017, 14, 339, 982, 18743, 365, 2013, 12, 652, 7171, 506, 2797, 1380, 1265, 1929, 370, 272, 30943, 314, 2505, 14, 272, 408, 272, 340, 2505, 365, 488, 503, 440, 365, 63, 2060, 63, 14418, 8, 8167, 304, 267, 372, 756, 339, 14388, 275, 664, 63, 28885, 8, 17477, 9, 272, 19009, 275, 10405, 63, 28885, 8, 8167, 9, 339, 1471, 63, 873, 275, 19009, 14, 8833, 1137, 14388, 14, 8833, 272, 340, 440, 1471, 63, 873, 26, 267, 1471, 63, 873, 275, 14388, 14, 7790, 63, 873, 8, 8167, 9, 272, 365, 63, 4525, 275, 19009, 14, 4712, 8, 2060, 12, 5737, 9, 272, 340, 18743, 436, 365, 63, 4525, 436, 1471, 63, 873, 26, 267, 18743, 8, 2060, 9, 272, 372, 365, 63, 4525, 421, 199, 318, 1852, 63, 2060, 8, 2060, 12, 10105, 29, 403, 12, 19009, 534, 885, 735, 272, 408, 272, 16147, 282, 8971, 13, 505, 2505, 1901, 282, 2631, 367, 3050, 4887, 339, 14766, 465, 3752, 342, 1325, 12821, 282, 892, 2196, 10105, 14, 272, 982, 2505, 365, 488, 2066, 282, 28207, 402, 272, 738, 1440, 51, 2617, 63, 9032, 63, 6351, 436, 282, 2196, 1059, 911, 506, 2138, 272, 1314, 2153, 24077, 4676, 83, 14, 10961, 2196, 1059, 295, 10569, 682, 13236, 272, 402, 15334, 316, 2879, 370, 12622, 503, 32590, 12639, 14, 272, 1666, 12052, 327, 1840, 1965, 367, 1655, 2256, 14, 272, 408, 272, 340, 2505, 365, 488, 26, 267, 372, 738, 1440, 51, 2617, 63, 9032, 63, 6351, 435, 664, 63, 2355, 63, 875, 8, 53, 1440, 51, 2617, 63, 9032, 63, 12273, 63, 9127, 9, 272, 19009, 275, 664, 63, 28885, 8, 28885, 9, 339, 340, 440, 10105, 26, 267, 10105, 275, 19009, 14, 12597, 342, 339, 372, 19009, 14, 2143, 8, 2060, 12, 10105, 9, 421, 199, 32, 25003, 63, 1637, 14, 25003, 63, 1637, 342, 199, 318, 664, 63, 31342, 837, 272, 2631, 1192, 275, 942, 272, 367, 19009, 63, 515, 315, 2202, 14, 9032, 63, 13533, 31700, 26, 267, 19009, 63, 1886, 275, 492, 63, 875, 8, 28885, 63, 515, 9, 267, 19009, 275, 19009, 63, 1886, 342, 267, 340, 440, 2519, 8, 28885, 12, 283, 8833, 735, 288, 746, 11897, 480, 28885, 3181, 1133, 4165, 376, 298, 4318, 298, 8833, 536, 26, 450, 83, 2, 450, 19009, 63, 515, 9, 267, 2631, 1192, 14, 740, 8, 28885, 9, 272, 372, 2631, 1192, 421, 199, 32, 25003, 63, 1637, 14, 25003, 63, 1637, 342, 199, 318, 664, 63, 31342, 63, 991, 63, 8833, 837, 272, 372, 469, 28885, 14, 8833, 26, 19009, 367, 19009, 315, 664, 63, 31342, 12737, 421, 199, 32, 10244, 8, 6031, 63, 2489, 9, 199, 318, 5305, 63, 31342, 3682, 958, 304, 272, 340, 2074, 459, 6031, 418, 508, 283, 9032, 63, 13533, 31700, 356, 267, 664, 63, 31342, 14, 1637, 63, 3584, 342, 267, 664, 63, 31342, 63, 991, 63, 8833, 14, 1637, 63, 3584, 342, 421, 199, 318, 664, 63, 28885, 8, 8833, 534, 885, 735, 272, 408, 272, 1803, 376, 1256, 402, 282, 6511, 2505, 19009, 14, 339, 982, 5563, 365, 283, 885, 297, 314, 849, 19009, 911, 506, 2138, 14, 272, 961, 805, 911, 2597, 9617, 492, 2631, 1192, 2013, 315, 2195, 272, 2202, 570, 340, 4346, 14, 272, 408, 272, 340, 2688, 8, 8833, 12, 283, 8833, 735, 267, 372, 5563, 339, 916, 5563, 508, 283, 885, 356, 267, 372, 664, 63, 31342, 3430, 16, 61, 339, 587, 26, 267, 2631, 1192, 275, 664, 63, 31342, 63, 991, 63, 8833, 342, 267, 862, 26, 288, 372, 2631, 1192, 59, 8833, 61, 267, 871, 4067, 26, 288, 746, 1722, 480, 5912, 2505, 25223, 5563, 1543, 83, 1370, 298, 2490, 298, 17366, 1265, 4165, 652, 315, 314, 21705, 5172, 63, 13533, 31700, 298, 2490, 298, 6031, 13472, 450, 5563, 9, 421, 199, 318, 10405, 63, 28885, 8, 8167, 304, 272, 408, 272, 1803, 376, 1256, 402, 282, 6511, 2505, 19009, 14, 339, 473, 2433, 397, 19009, 5563, 701, 15735, 7969, 5737, 2631, 12, 436, 4882, 272, 664, 63, 28885, 342, 370, 372, 19009, 14, 6218, 1722, 340, 272, 5563, 3913, 506, 15836, 12, 503, 340, 19009, 365, 440, 6511, 14, 272, 408, 272, 327, 1626, 559, 484, 5459, 402, 5634, 2737, 8971, 15830, 21, 19572, 436, 10226, 272, 327, 15830, 21, 19572, 543, 376, 2701, 10105, 14, 272, 340, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
sudheerchintala/LearnEraPlatForm
lms/djangoapps/class_dashboard/tests/test_views.py
33
4214
""" Tests for class dashboard (Metrics tab in instructor dashboard) """ from mock import patch from django.test.utils import override_settings from django.test import TestCase from django.test.client import RequestFactory from xmodule.modulestore.tests.factories import CourseFactory from student.tests.factories import AdminFactory from django.utils import simplejson from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from class_dashboard import views @override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) class TestViews(ModuleStoreTestCase): """ Tests related to class_dashboard/views.py """ def setUp(self): self.request_factory = RequestFactory() self.request = self.request_factory.get('') self.request.user = None self.simple_data = {'error': 'error'} @patch('class_dashboard.views.has_instructor_access_for_class') def test_all_problem_grade_distribution_has_access(self, has_access): """ Test returns proper value when have proper access """ has_access.return_value = True response = views.all_problem_grade_distribution(self.request, 'test/test/test') self.assertEqual(simplejson.dumps(self.simple_data), response.content) @patch('class_dashboard.views.has_instructor_access_for_class') def test_all_problem_grade_distribution_no_access(self, has_access): """ Test for no access """ has_access.return_value = False response = views.all_problem_grade_distribution(self.request, 'test/test/test') self.assertEqual("{\"error\": \"Access Denied: User does not have access to this course\'s data\"}", response.content) @patch('class_dashboard.views.has_instructor_access_for_class') def test_all_sequential_open_distribution_has_access(self, has_access): """ Test returns proper value when have proper access """ has_access.return_value = True response = views.all_sequential_open_distrib(self.request, 'test/test/test') self.assertEqual(simplejson.dumps(self.simple_data), response.content) @patch('class_dashboard.views.has_instructor_access_for_class') def test_all_sequential_open_distribution_no_access(self, has_access): """ Test for no access """ has_access.return_value = False response = views.all_sequential_open_distrib(self.request, 'test/test/test') self.assertEqual("{\"error\": \"Access Denied: User does not have access to this course\'s data\"}", response.content) @patch('class_dashboard.views.has_instructor_access_for_class') def test_section_problem_grade_distribution_has_access(self, has_access): """ Test returns proper value when have proper access """ has_access.return_value = True response = views.section_problem_grade_distrib(self.request, 'test/test/test', '1') self.assertEqual(simplejson.dumps(self.simple_data), response.content) @patch('class_dashboard.views.has_instructor_access_for_class') def test_section_problem_grade_distribution_no_access(self, has_access): """ Test for no access """ has_access.return_value = False response = views.section_problem_grade_distrib(self.request, 'test/test/test', '1') self.assertEqual("{\"error\": \"Access Denied: User does not have access to this course\'s data\"}", response.content) def test_sending_deprecated_id(self): course = CourseFactory.create() instructor = AdminFactory.create() self.request.user = instructor response = views.all_sequential_open_distrib(self.request, course.id.to_deprecated_string()) self.assertEqual('[]', response.content) response = views.all_problem_grade_distribution(self.request, course.id.to_deprecated_string()) self.assertEqual('[]', response.content) response = views.section_problem_grade_distrib(self.request, course.id.to_deprecated_string(), 'no section') self.assertEqual('{"error": "error"}', response.content)
agpl-3.0
[ 624, 199, 2925, 367, 1021, 17216, 334, 17213, 5174, 315, 17724, 17216, 9, 199, 624, 199, 504, 1683, 492, 3371, 199, 504, 1639, 14, 396, 14, 1208, 492, 4278, 63, 1751, 199, 199, 504, 1639, 14, 396, 492, 7640, 199, 504, 1639, 14, 396, 14, 1258, 492, 18638, 199, 504, 9872, 14, 10012, 14, 2219, 14, 15406, 492, 17862, 199, 504, 6474, 14, 2219, 14, 15406, 492, 9516, 2927, 199, 504, 1639, 14, 1208, 492, 13804, 199, 504, 20736, 14, 2219, 14, 2219, 492, 7393, 63, 3998, 63, 45, 26477, 63, 27011, 199, 504, 9872, 14, 10012, 14, 2219, 14, 1176, 63, 1208, 492, 17996, 1746, 199, 199, 504, 1021, 63, 9743, 492, 6858, 421, 199, 32, 4415, 63, 1751, 8, 27011, 29, 2864, 63, 3998, 63, 45, 26477, 63, 27011, 9, 199, 533, 1379, 21180, 8, 27863, 304, 272, 408, 272, 6496, 4048, 370, 1021, 63, 9743, 15, 4196, 14, 647, 272, 408, 339, 347, 3613, 8, 277, 304, 398, 291, 14, 1069, 63, 3702, 275, 18638, 342, 267, 291, 14, 1069, 275, 291, 14, 1069, 63, 3702, 14, 362, 8355, 267, 291, 14, 1069, 14, 751, 275, 488, 267, 291, 14, 4129, 63, 576, 275, 791, 705, 356, 283, 705, 936, 339, 768, 2068, 360, 533, 63, 9743, 14, 4196, 14, 1989, 63, 14891, 63, 2732, 63, 509, 63, 533, 358, 272, 347, 511, 63, 452, 63, 6462, 63, 4523, 63, 4972, 63, 1989, 63, 2732, 8, 277, 12, 965, 63, 2732, 304, 267, 408, 267, 1379, 2529, 5576, 574, 1380, 1172, 5576, 2879, 267, 408, 267, 965, 63, 2732, 14, 1107, 63, 585, 275, 715, 267, 1177, 275, 6858, 14, 452, 63, 6462, 63, 4523, 63, 4972, 8, 277, 14, 1069, 12, 283, 396, 15, 396, 15, 396, 358, 398, 291, 14, 629, 8, 4129, 1001, 14, 4180, 8, 277, 14, 4129, 63, 576, 395, 1177, 14, 1317, 9, 339, 768, 2068, 360, 533, 63, 9743, 14, 4196, 14, 1989, 63, 14891, 63, 2732, 63, 509, 63, 533, 358, 272, 347, 511, 63, 452, 63, 6462, 63, 4523, 63, 4972, 63, 889, 63, 2732, 8, 277, 12, 965, 63, 2732, 304, 267, 408, 267, 1379, 367, 949, 2879, 267, 408, 267, 965, 63, 2732, 14, 1107, 63, 585, 275, 756, 267, 1177, 275, 6858, 14, 452, 63, 6462, 63, 4523, 63, 4972, 8, 277, 14, 1069, 12, 283, 396, 15, 396, 15, 396, 358, 398, 291, 14, 629, 13076, 4451, 705, 19354, 8441, 3946, 25187, 5299, 26, 2876, 1630, 440, 1172, 2879, 370, 642, 2518, 3985, 83, 666, 60, 3570, 401, 1177, 14, 1317, 9, 339, 768, 2068, 360, 533, 63, 9743, 14, 4196, 14, 1989, 63, 14891, 63, 2732, 63, 509, 63, 533, 358, 272, 347, 511, 63, 452, 63, 16211, 63, 1490, 63, 4972, 63, 1989, 63, 2732, 8, 277, 12, 965, 63, 2732, 304, 267, 408, 267, 1379, 2529, 5576, 574, 1380, 1172, 5576, 2879, 267, 408, 267, 965, 63, 2732, 14, 1107, 63, 585, 275, 715, 267, 1177, 275, 6858, 14, 452, 63, 16211, 63, 1490, 63, 20231, 8, 277, 14, 1069, 12, 283, 396, 15, 396, 15, 396, 358, 398, 291, 14, 629, 8, 4129, 1001, 14, 4180, 8, 277, 14, 4129, 63, 576, 395, 1177, 14, 1317, 9, 339, 768, 2068, 360, 533, 63, 9743, 14, 4196, 14, 1989, 63, 14891, 63, 2732, 63, 509, 63, 533, 358, 272, 347, 511, 63, 452, 63, 16211, 63, 1490, 63, 4972, 63, 889, 63, 2732, 8, 277, 12, 965, 63, 2732, 304, 267, 408, 267, 1379, 367, 949, 2879, 267, 408, 267, 965, 63, 2732, 14, 1107, 63, 585, 275, 756, 267, 1177, 275, 6858, 14, 452, 63, 16211, 63, 1490, 63, 20231, 8, 277, 14, 1069, 12, 283, 396, 15, 396, 15, 396, 358, 398, 291, 14, 629, 13076, 4451, 705, 19354, 8441, 3946, 25187, 5299, 26, 2876, 1630, 440, 1172, 2879, 370, 642, 2518, 3985, 83, 666, 60, 3570, 401, 1177, 14, 1317, 9, 339, 768, 2068, 360, 533, 63, 9743, 14, 4196, 14, 1989, 63, 14891, 63, 2732, 63, 509, 63, 533, 358, 272, 347, 511, 63, 2792, 63, 6462, 63, 4523, 63, 4972, 63, 1989, 63, 2732, 8, 277, 12, 965, 63, 2732, 304, 267, 408, 267, 1379, 2529, 5576, 574, 1380, 1172, 5576, 2879, 267, 408, 267, 965, 63, 2732, 14, 1107, 63, 585, 275, 715, 267, 1177, 275, 6858, 14, 2792, 63, 6462, 63, 4523, 63, 20231, 8, 277, 14, 1069, 12, 283, 396, 15, 396, 15, 396, 297, 283, 17, 358, 398, 291, 14, 629, 8, 4129, 1001, 14, 4180, 8, 277, 14, 4129, 63, 576, 395, 1177, 14, 1317, 9, 339, 768, 2068, 360, 533, 63, 9743, 14, 4196, 14, 1989, 63, 14891, 63, 2732, 63, 509, 63, 533, 358, 272, 347, 511, 63, 2792, 63, 6462, 63, 4523, 63, 4972, 63, 889, 63, 2732, 8, 277, 12, 965, 63, 2732, 304, 267, 408, 267, 1379, 367, 949, 2879, 267, 408, 267, 965, 63, 2732, 14, 1107, 63, 585, 275, 756, 267, 1177, 275, 6858, 14, 2792, 63, 6462, 63, 4523, 63, 20231, 8, 277, 14, 1069, 12, 283, 396, 15, 396, 15, 396, 297, 283, 17, 358, 398, 291, 14, 629, 13076, 4451, 705, 19354, 8441, 3946, 25187, 5299, 26, 2876, 1630, 440, 1172, 2879, 370, 642, 2518, 3985, 83, 666, 60, 3570, 401, 1177, 14, 1317, 9, 339, 347, 511, 63, 24450, 63, 6667, 63, 344, 8, 277, 304, 398, 2518, 275, 17862, 14, 981, 342, 267, 17724, 275, 9516, 2927, 14, 981, 342, 267, 291, 14, 1069, 14, 751, 275, 17724, 398, 1177, 275, 6858, 14, 452, 63, 16211, 63, 1490, 63, 20231, 8, 277, 14, 1069, 12, 2518, 14, 344, 14, 475, 63, 6667, 63, 875, 1012, 267, 291, 14, 629, 11894, 4300, 1177, 14, 1317, 9, 398, 1177, 275, 6858, 14, 452, 63, 6462, 63, 4523, 63, 4972, 8, 277, 14, 1069, 12, 2518, 14, 344, 14, 475, 63, 6667, 63, 875, 1012, 267, 291, 14, 629, 11894, 4300, 1177, 14, 1317, 9, 398, 1177, 275, 6858, 14, 2792, 63, 6462, 63, 4523, 63, 20231, 8, 277, 14, 1069, 12, 2518, 14, 344, 14, 475, 63, 6667, 63, 875, 1062, 283, 889, 3420, 358 ]
[ 199, 2925, 367, 1021, 17216, 334, 17213, 5174, 315, 17724, 17216, 9, 199, 624, 199, 504, 1683, 492, 3371, 199, 504, 1639, 14, 396, 14, 1208, 492, 4278, 63, 1751, 199, 199, 504, 1639, 14, 396, 492, 7640, 199, 504, 1639, 14, 396, 14, 1258, 492, 18638, 199, 504, 9872, 14, 10012, 14, 2219, 14, 15406, 492, 17862, 199, 504, 6474, 14, 2219, 14, 15406, 492, 9516, 2927, 199, 504, 1639, 14, 1208, 492, 13804, 199, 504, 20736, 14, 2219, 14, 2219, 492, 7393, 63, 3998, 63, 45, 26477, 63, 27011, 199, 504, 9872, 14, 10012, 14, 2219, 14, 1176, 63, 1208, 492, 17996, 1746, 199, 199, 504, 1021, 63, 9743, 492, 6858, 421, 199, 32, 4415, 63, 1751, 8, 27011, 29, 2864, 63, 3998, 63, 45, 26477, 63, 27011, 9, 199, 533, 1379, 21180, 8, 27863, 304, 272, 408, 272, 6496, 4048, 370, 1021, 63, 9743, 15, 4196, 14, 647, 272, 408, 339, 347, 3613, 8, 277, 304, 398, 291, 14, 1069, 63, 3702, 275, 18638, 342, 267, 291, 14, 1069, 275, 291, 14, 1069, 63, 3702, 14, 362, 8355, 267, 291, 14, 1069, 14, 751, 275, 488, 267, 291, 14, 4129, 63, 576, 275, 791, 705, 356, 283, 705, 936, 339, 768, 2068, 360, 533, 63, 9743, 14, 4196, 14, 1989, 63, 14891, 63, 2732, 63, 509, 63, 533, 358, 272, 347, 511, 63, 452, 63, 6462, 63, 4523, 63, 4972, 63, 1989, 63, 2732, 8, 277, 12, 965, 63, 2732, 304, 267, 408, 267, 1379, 2529, 5576, 574, 1380, 1172, 5576, 2879, 267, 408, 267, 965, 63, 2732, 14, 1107, 63, 585, 275, 715, 267, 1177, 275, 6858, 14, 452, 63, 6462, 63, 4523, 63, 4972, 8, 277, 14, 1069, 12, 283, 396, 15, 396, 15, 396, 358, 398, 291, 14, 629, 8, 4129, 1001, 14, 4180, 8, 277, 14, 4129, 63, 576, 395, 1177, 14, 1317, 9, 339, 768, 2068, 360, 533, 63, 9743, 14, 4196, 14, 1989, 63, 14891, 63, 2732, 63, 509, 63, 533, 358, 272, 347, 511, 63, 452, 63, 6462, 63, 4523, 63, 4972, 63, 889, 63, 2732, 8, 277, 12, 965, 63, 2732, 304, 267, 408, 267, 1379, 367, 949, 2879, 267, 408, 267, 965, 63, 2732, 14, 1107, 63, 585, 275, 756, 267, 1177, 275, 6858, 14, 452, 63, 6462, 63, 4523, 63, 4972, 8, 277, 14, 1069, 12, 283, 396, 15, 396, 15, 396, 358, 398, 291, 14, 629, 13076, 4451, 705, 19354, 8441, 3946, 25187, 5299, 26, 2876, 1630, 440, 1172, 2879, 370, 642, 2518, 3985, 83, 666, 60, 3570, 401, 1177, 14, 1317, 9, 339, 768, 2068, 360, 533, 63, 9743, 14, 4196, 14, 1989, 63, 14891, 63, 2732, 63, 509, 63, 533, 358, 272, 347, 511, 63, 452, 63, 16211, 63, 1490, 63, 4972, 63, 1989, 63, 2732, 8, 277, 12, 965, 63, 2732, 304, 267, 408, 267, 1379, 2529, 5576, 574, 1380, 1172, 5576, 2879, 267, 408, 267, 965, 63, 2732, 14, 1107, 63, 585, 275, 715, 267, 1177, 275, 6858, 14, 452, 63, 16211, 63, 1490, 63, 20231, 8, 277, 14, 1069, 12, 283, 396, 15, 396, 15, 396, 358, 398, 291, 14, 629, 8, 4129, 1001, 14, 4180, 8, 277, 14, 4129, 63, 576, 395, 1177, 14, 1317, 9, 339, 768, 2068, 360, 533, 63, 9743, 14, 4196, 14, 1989, 63, 14891, 63, 2732, 63, 509, 63, 533, 358, 272, 347, 511, 63, 452, 63, 16211, 63, 1490, 63, 4972, 63, 889, 63, 2732, 8, 277, 12, 965, 63, 2732, 304, 267, 408, 267, 1379, 367, 949, 2879, 267, 408, 267, 965, 63, 2732, 14, 1107, 63, 585, 275, 756, 267, 1177, 275, 6858, 14, 452, 63, 16211, 63, 1490, 63, 20231, 8, 277, 14, 1069, 12, 283, 396, 15, 396, 15, 396, 358, 398, 291, 14, 629, 13076, 4451, 705, 19354, 8441, 3946, 25187, 5299, 26, 2876, 1630, 440, 1172, 2879, 370, 642, 2518, 3985, 83, 666, 60, 3570, 401, 1177, 14, 1317, 9, 339, 768, 2068, 360, 533, 63, 9743, 14, 4196, 14, 1989, 63, 14891, 63, 2732, 63, 509, 63, 533, 358, 272, 347, 511, 63, 2792, 63, 6462, 63, 4523, 63, 4972, 63, 1989, 63, 2732, 8, 277, 12, 965, 63, 2732, 304, 267, 408, 267, 1379, 2529, 5576, 574, 1380, 1172, 5576, 2879, 267, 408, 267, 965, 63, 2732, 14, 1107, 63, 585, 275, 715, 267, 1177, 275, 6858, 14, 2792, 63, 6462, 63, 4523, 63, 20231, 8, 277, 14, 1069, 12, 283, 396, 15, 396, 15, 396, 297, 283, 17, 358, 398, 291, 14, 629, 8, 4129, 1001, 14, 4180, 8, 277, 14, 4129, 63, 576, 395, 1177, 14, 1317, 9, 339, 768, 2068, 360, 533, 63, 9743, 14, 4196, 14, 1989, 63, 14891, 63, 2732, 63, 509, 63, 533, 358, 272, 347, 511, 63, 2792, 63, 6462, 63, 4523, 63, 4972, 63, 889, 63, 2732, 8, 277, 12, 965, 63, 2732, 304, 267, 408, 267, 1379, 367, 949, 2879, 267, 408, 267, 965, 63, 2732, 14, 1107, 63, 585, 275, 756, 267, 1177, 275, 6858, 14, 2792, 63, 6462, 63, 4523, 63, 20231, 8, 277, 14, 1069, 12, 283, 396, 15, 396, 15, 396, 297, 283, 17, 358, 398, 291, 14, 629, 13076, 4451, 705, 19354, 8441, 3946, 25187, 5299, 26, 2876, 1630, 440, 1172, 2879, 370, 642, 2518, 3985, 83, 666, 60, 3570, 401, 1177, 14, 1317, 9, 339, 347, 511, 63, 24450, 63, 6667, 63, 344, 8, 277, 304, 398, 2518, 275, 17862, 14, 981, 342, 267, 17724, 275, 9516, 2927, 14, 981, 342, 267, 291, 14, 1069, 14, 751, 275, 17724, 398, 1177, 275, 6858, 14, 452, 63, 16211, 63, 1490, 63, 20231, 8, 277, 14, 1069, 12, 2518, 14, 344, 14, 475, 63, 6667, 63, 875, 1012, 267, 291, 14, 629, 11894, 4300, 1177, 14, 1317, 9, 398, 1177, 275, 6858, 14, 452, 63, 6462, 63, 4523, 63, 4972, 8, 277, 14, 1069, 12, 2518, 14, 344, 14, 475, 63, 6667, 63, 875, 1012, 267, 291, 14, 629, 11894, 4300, 1177, 14, 1317, 9, 398, 1177, 275, 6858, 14, 2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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
danieldanciu/schoggi
tests/functional/explorer_module.py
4
11627
# Copyright 2013 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS-IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Functional tests for modules/course_explorer/course_explorer.py.""" __author__ = 'rahulsingal@google.com (Rahul Singal)' import actions from actions import assert_contains from actions import assert_does_not_contain from actions import assert_equals from controllers import sites from models import config from models import models from models import transforms from models.models import PersonalProfile from modules.course_explorer import course_explorer from modules.course_explorer import student class BaseExplorerTest(actions.TestBase): """Base class for testing explorer pages.""" def setUp(self): # pylint: disable=g-bad-name super(BaseExplorerTest, self).setUp() config.Registry.test_overrides[ models.CAN_SHARE_STUDENT_PROFILE.name] = True config.Registry.test_overrides[ course_explorer.GCB_ENABLE_COURSE_EXPLORER_PAGE.name] = True def tearDown(self): # pylint: disable=g-bad-name config.Registry.test_overrides = {} super(BaseExplorerTest, self).tearDown() class CourseExplorerTest(BaseExplorerTest): """Tests course_explorer module.""" def test_single_uncompleted_course(self): """Tests for a single available course.""" # This call should redirect to explorer page. response = self.get('/') assert_contains('/explorer', response.location) name = 'Test student courses page' email = 'Student' actions.login(email) # Test the explorer page. response = self.get('/explorer') assert_equals(response.status_int, 200) assert_contains('Register', response.body) # Navbar should not contain profile tab. assert_does_not_contain( '<a href="/explorer/profile">Profile</a>', response.body) # Test 'my courses' page when a student is not enrolled in any course. response = self.get('/explorer/courses') assert_equals(response.status_int, 200) assert_contains('You are not currently enrolled in any course', response.body) # Test 'my courses' page when a student is enrolled in all courses. actions.register(self, name) response = self.get('/explorer/courses') assert_equals(response.status_int, 200) assert_contains('Go to course', response.body) assert_does_not_contain('You are not currently enrolled in any course', response.body) # After the student registers for a course, # profile tab should be visible in navbar. assert_contains( '<a href="/explorer/profile">Profile</a>', response.body) # Test profile page. response = self.get('/explorer/profile') assert_contains('<td>%s</td>' % email, response.body) assert_contains('<td>%s</td>' % name, response.body) assert_contains('Progress', response.body) assert_does_not_contain('View score', response.body) def test_single_completed_course(self): """Tests when a single completed course is present.""" email = 'test_assessments@google.com' name = 'Test Assessments' # Register. actions.login(email) actions.register(self, name) response = self.get('/explorer') # Before a course is not completed, # explorer page should not show 'view score' button. assert_does_not_contain('View score', response.body) # Assign a grade to the course enrolled to mark it complete. profile = PersonalProfile.get_by_key_name(email) info = {'final_grade': 'A'} course_info_dict = {'': info} profile.course_info = transforms.dumps(course_info_dict) profile.put() # Check if 'View score' text is visible on profile page. response = self.get('/explorer/profile') assert_contains('View score', response.body) # Check if 'Go to course' button is not visible on explorer page. response = self.get('/explorer') assert_does_not_contain('Go to course', response.body) # Check if 'View score' button is visible on explorer page. response = self.get('/explorer') assert_contains('View score', response.body) def test_multiple_course(self): """Tests when multiple courses are available.""" sites.setup_courses('course:/test::ns_test, course:/:/') name = 'Test completed course' email = 'Student' # Make the course available. get_environ_old = sites.ApplicationContext.get_environ def get_environ_new(self): environ = get_environ_old(self) environ['course']['now_available'] = True return environ sites.ApplicationContext.get_environ = get_environ_new actions.login(email) actions.register(self, name) response = self.get('/explorer/courses') # Assert if 'View course list' text is shown on my course page. assert_contains('View course list', response.body) # Clean up app_context. sites.ApplicationContext.get_environ = get_environ_old sites.reset_courses() class CourseExplorerDisabledTest(actions.TestBase): """Tests when course explorer is disabled.""" def get_auto_deploy(self): return False def test_anonymous_access(self): """Tests for disabled course explorer page.""" # disable the explorer config.Registry.test_overrides[ course_explorer.GCB_ENABLE_COURSE_EXPLORER_PAGE.name] = False self.assertFalse(course_explorer.GCB_ENABLE_COURSE_EXPLORER_PAGE.value) # check root URL's properly redirect to login response = self.get('/') assert_equals(response.status_int, 302) assert_contains( 'http://localhost/admin?action=welcome', response.location) response = self.get('/assets/img/your_logo_here.png') assert_equals(response.status_int, 302) assert_contains('accounts/Login', response.location) # check explorer pages are not accessible not_accessibles = [ '/explorer', '/explorer/courses', '/explorer/profile', '/explorer/assets/img/your_logo_here.png'] for not_accessible in not_accessibles: response = self.get(not_accessible, expect_errors=True) assert_equals(response.status_int, 404) # enable course explorer config.Registry.test_overrides[ course_explorer.GCB_ENABLE_COURSE_EXPLORER_PAGE.name] = True self.assertTrue(course_explorer.GCB_ENABLE_COURSE_EXPLORER_PAGE.value) # check explorer pages are accessible accessibles = [ '/explorer', '/explorer/courses', '/explorer/assets/img/your_logo_here.png'] for accessible in accessibles: response = self.get(accessible, expect_errors=True) assert_equals(response.status_int, 200) # check student pages are not accessible response = self.get('/explorer/profile') assert_equals(response.status_int, 302) self.assertEqual('http://localhost/explorer', response.location) def test_student_access(self): # enable course explorer config.Registry.test_overrides[ course_explorer.GCB_ENABLE_COURSE_EXPLORER_PAGE.name] = True self.assertTrue(course_explorer.GCB_ENABLE_COURSE_EXPLORER_PAGE.value) # check not being logged in response = self.get('/explorer') assert_contains('Explore Courses', response.body) assert_does_not_contain('My Courses', response.body) # login and check logged in student perspective config.Registry.test_overrides[ sites.GCB_COURSES_CONFIG.name] = 'course:/:/' email = 'student' actions.login(email) response = self.get('/explorer') assert_contains('Explore Courses', response.body) assert_contains('My Courses', response.body) class GlobalProfileTest(BaseExplorerTest): """Tests course_explorer module.""" def test_change_of_name(self): """Tests for a single available course.""" # This call should redirect to explorer page. response = self.get('/') assert_contains('/explorer', response.location) name = 'Test global profile page' email = 'student_global_profile@example.com' actions.login(email) # Test the explorer page. response = self.get('/explorer') assert_equals(response.status_int, 200) assert_contains('Register', response.body) # Test 'my courses' page when a student is enrolled in all courses. actions.register(self, name) # Test profile page. response = self.get('/explorer/profile') assert_contains('<td>%s</td>' % email, response.body) assert_contains('<td>%s</td>' % name, response.body) # Change the name now new_name = 'New global name' response.form.set('name', new_name) response = self.submit(response.form) assert_equals(response.status_int, 302) response = self.get('/explorer/profile') assert_contains('<td>%s</td>' % email, response.body) assert_contains('<td>%s</td>' % new_name, response.body) # Change name with bad xsrf token. response = self.get('/explorer/profile') assert_equals(response.status_int, 200) new_name = 'New Bad global name' response.form.set('name', new_name) response.form.set('xsrf_token', 'asdfsdf') response = response.form.submit(expect_errors=True) assert_equals(response.status_int, 403) # Change name with empty name shold fail. response = self.get('/explorer/profile') assert_equals(response.status_int, 200) new_name = '' response.form.set('name', new_name) response = response.form.submit(expect_errors=True) assert_equals(response.status_int, 400) # Change name with overlong name should fail for str. response = self.get('/explorer/profile') assert_equals(response.status_int, 200) # Constant is module-protected. pylint: disable=protected-access new_name = 'a' * (student._STRING_PROPERTY_MAX_BYTES + 1) response.form.set('name', new_name) response = response.form.submit(expect_errors=True) assert_equals(response.status_int, 400) # Change name with overlong name should fail for unicode. response = self.get('/explorer/profile') assert_equals(response.status_int, 200) # \u03a3 == Sigma. len == 1 for unicode; 2 for utf-8 encoded str. new_name = u'\u03a3' + ('a' * (student._STRING_PROPERTY_MAX_BYTES - 1)) response.form.set('name', new_name) response = response.form.submit(expect_errors=True) assert_equals(response.status_int, 400)
apache-2.0
[ 3, 1898, 6171, 4475, 3277, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 13, 1311, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 199, 624, 3481, 279, 2295, 367, 4621, 15, 1972, 63, 16971, 3859, 15, 1972, 63, 16971, 3859, 14, 647, 1041, 199, 199, 363, 2502, 363, 275, 283, 345, 72, 348, 1044, 279, 32, 3098, 14, 957, 334, 1537, 72, 348, 428, 316, 279, 3171, 421, 199, 646, 5445, 199, 504, 5445, 492, 702, 63, 6134, 199, 504, 5445, 492, 702, 63, 9105, 63, 1397, 63, 7747, 199, 504, 5445, 492, 702, 63, 11332, 199, 504, 27325, 492, 15424, 199, 504, 1709, 492, 1101, 199, 504, 1709, 492, 1709, 199, 504, 1709, 492, 18501, 199, 504, 1709, 14, 992, 492, 8028, 279, 5736, 199, 504, 4621, 14, 1972, 63, 16971, 3859, 492, 2518, 63, 16971, 3859, 199, 504, 4621, 14, 1972, 63, 16971, 3859, 492, 6474, 421, 199, 533, 3523, 4527, 22732, 774, 8, 3723, 14, 14440, 304, 272, 408, 1563, 1021, 367, 5343, 15868, 3859, 6497, 1041, 339, 347, 3613, 8, 277, 304, 221, 327, 4287, 26, 3507, 29, 71, 13, 4087, 13, 354, 267, 1613, 8, 1563, 4527, 22732, 774, 12, 291, 680, 5996, 342, 267, 1101, 14, 10899, 14, 396, 63, 12867, 59, 288, 1709, 14, 18988, 63, 31220, 63, 840, 29317, 63, 16632, 14, 354, 61, 275, 715, 267, 1101, 14, 10899, 14, 396, 63, 12867, 59, 288, 2518, 63, 16971, 3859, 14, 7484, 34, 63, 8898, 63, 15552, 63, 1438, 2749, 726, 540, 63, 12898, 14, 354, 61, 275, 715, 339, 347, 6766, 8, 277, 304, 221, 327, 4287, 26, 3507, 29, 71, 13, 4087, 13, 354, 267, 1101, 14, 10899, 14, 396, 63, 12867, 275, 1052, 267, 1613, 8, 1563, 4527, 22732, 774, 12, 291, 680, 12336, 342, 421, 199, 533, 5531, 4527, 22732, 774, 8, 1563, 4527, 22732, 774, 304, 272, 408, 2925, 2518, 63, 16971, 3859, 859, 1041, 339, 347, 511, 63, 4780, 63, 324, 12634, 63, 1972, 8, 277, 304, 267, 408, 2925, 367, 282, 2849, 2808, 2518, 1041, 267, 327, 961, 1240, 1077, 4660, 370, 15868, 3859, 2034, 14, 267, 1177, 275, 291, 14, 362, 7825, 267, 702, 63, 6134, 2336, 16971, 3859, 297, 1177, 14, 1985, 9, 398, 536, 275, 283, 774, 6474, 13588, 2034, 7, 267, 3031, 275, 283, 18086, 7, 398, 5445, 14, 2886, 8, 2123, 9, 398, 327, 1379, 314, 15868, 3859, 2034, 14, 267, 1177, 275, 291, 14, 362, 2336, 16971, 3859, 358, 267, 702, 63, 11332, 8, 1310, 14, 1205, 63, 442, 12, 1926, 9, 267, 702, 63, 6134, 360, 7099, 297, 1177, 14, 2030, 9, 398, 327, 653, 1214, 1700, 1077, 440, 1395, 4690, 5174, 14, 267, 702, 63, 9105, 63, 1397, 63, 7747, 8, 288, 2650, 65, 4369, 9555, 16971, 3859, 15, 2913, 1743, 5736, 1108, 65, 4206, 1177, 14, 2030, 9, 398, 327, 1379, 283, 1662, 13588, 7, 2034, 1380, 282, 6474, 365, 440, 26802, 315, 1263, 2518, 14, 267, 1177, 275, 291, 14, 362, 2336, 16971, 3859, 15, 11653, 358, 267, 702, 63, 11332, 8, 1310, 14, 1205, 63, 442, 12, 1926, 9, 267, 702, 63, 6134, 360, 5556, 787, 440, 5544, 26802, 315, 1263, 2518, 297, 717, 1177, 14, 2030, 9, 398, 327, 1379, 283, 1662, 13588, 7, 2034, 1380, 282, 6474, 365, 26802, 315, 1006, 13588, 14, 267, 5445, 14, 2683, 8, 277, 12, 536, 9, 267, 1177, 275, 291, 14, 362, 2336, 16971, 3859, 15, 11653, 358, 267, 702, 63, 11332, 8, 1310, 14, 1205, 63, 442, 12, 1926, 9, 267, 702, 63, 6134, 360, 7250, 370, 2518, 297, 1177, 14, 2030, 9, 267, 702, 63, 9105, 63, 1397, 63, 7747, 360, 5556, 787, 440, 5544, 26802, 315, 1263, 2518, 297, 1816, 1177, 14, 2030, 9, 398, 327, 12836, 314, 6474, 24493, 367, 282, 2518, 12, 267, 327, 4690, 5174, 1077, 506, 8917, 315, 16681, 1700, 14, 267, 702, 63, 6134, 8, 288, 2650, 65, 4369, 9555, 16971, 3859, 15, 2913, 1743, 5736, 1108, 65, 4206, 1177, 14, 2030, 9, 398, 327, 1379, 4690, 2034, 14, 267, 1177, 275, 291, 14, 362, 2336, 16971, 3859, 15, 2913, 358, 267, 702, 63, 6134, 4827, 2076, 6598, 83, 1108, 2076, 3524, 450, 3031, 12, 1177, 14, 2030, 9, 267, 702, 63, 6134, 4827, 2076, 6598, 83, 1108, 2076, 3524, 450, 536, 12, 1177, 14, 2030, 9, 267, 702, 63, 6134, 360, 11504, 297, 1177, 14, 2030, 9, 267, 702, 63, 9105, 63, 1397, 63, 7747, 360, 2768, 5396, 297, 1177, 14, 2030, 9, 339, 347, 511, 63, 4780, 63, 12634, 63, 1972, 8, 277, 304, 267, 408, 2925, 1380, 282, 2849, 9709, 2518, 365, 3451, 1041, 267, 3031, 275, 283, 396, 63, 305, 5480, 1470, 32, 3098, 14, 957, 7, 267, 536, 275, 283, 774, 3709, 5480, 1470, 7, 398, 327, 11828, 14, 267, 5445, 14, 2886, 8, 2123, 9, 267, 5445, 14, 2683, 8, 277, 12, 536, 9, 398, 1177, 275, 291, 14, 362, 2336, 16971, 3859, 358, 267, 327, 21467, 282, 2518, 365, 440, 9709, 12, 267, 327, 15868, 3859, 2034, 1077, 440, 2498, 283, 1345, 5396, 7, 5528, 14, 267, 702, 63, 9105, 63, 1397, 63, 7747, 360, 2768, 5396, 297, 1177, 14, 2030, 9, 398, 327, 16927, 282, 16183, 370, 314, 2518, 26802, 370, 2216, 652, 4890, 14, 267, 4690, 275, 8028, 279, 5736, 14, 362, 63, 991, 63, 498, 63, 354, 8, 2123, 9, 267, 2256, 275, 791, 5094, 63, 4523, 356, 283, 33, 936, 267 ]
[ 1898, 6171, 4475, 3277, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 13, 1311, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 199, 624, 3481, 279, 2295, 367, 4621, 15, 1972, 63, 16971, 3859, 15, 1972, 63, 16971, 3859, 14, 647, 1041, 199, 199, 363, 2502, 363, 275, 283, 345, 72, 348, 1044, 279, 32, 3098, 14, 957, 334, 1537, 72, 348, 428, 316, 279, 3171, 421, 199, 646, 5445, 199, 504, 5445, 492, 702, 63, 6134, 199, 504, 5445, 492, 702, 63, 9105, 63, 1397, 63, 7747, 199, 504, 5445, 492, 702, 63, 11332, 199, 504, 27325, 492, 15424, 199, 504, 1709, 492, 1101, 199, 504, 1709, 492, 1709, 199, 504, 1709, 492, 18501, 199, 504, 1709, 14, 992, 492, 8028, 279, 5736, 199, 504, 4621, 14, 1972, 63, 16971, 3859, 492, 2518, 63, 16971, 3859, 199, 504, 4621, 14, 1972, 63, 16971, 3859, 492, 6474, 421, 199, 533, 3523, 4527, 22732, 774, 8, 3723, 14, 14440, 304, 272, 408, 1563, 1021, 367, 5343, 15868, 3859, 6497, 1041, 339, 347, 3613, 8, 277, 304, 221, 327, 4287, 26, 3507, 29, 71, 13, 4087, 13, 354, 267, 1613, 8, 1563, 4527, 22732, 774, 12, 291, 680, 5996, 342, 267, 1101, 14, 10899, 14, 396, 63, 12867, 59, 288, 1709, 14, 18988, 63, 31220, 63, 840, 29317, 63, 16632, 14, 354, 61, 275, 715, 267, 1101, 14, 10899, 14, 396, 63, 12867, 59, 288, 2518, 63, 16971, 3859, 14, 7484, 34, 63, 8898, 63, 15552, 63, 1438, 2749, 726, 540, 63, 12898, 14, 354, 61, 275, 715, 339, 347, 6766, 8, 277, 304, 221, 327, 4287, 26, 3507, 29, 71, 13, 4087, 13, 354, 267, 1101, 14, 10899, 14, 396, 63, 12867, 275, 1052, 267, 1613, 8, 1563, 4527, 22732, 774, 12, 291, 680, 12336, 342, 421, 199, 533, 5531, 4527, 22732, 774, 8, 1563, 4527, 22732, 774, 304, 272, 408, 2925, 2518, 63, 16971, 3859, 859, 1041, 339, 347, 511, 63, 4780, 63, 324, 12634, 63, 1972, 8, 277, 304, 267, 408, 2925, 367, 282, 2849, 2808, 2518, 1041, 267, 327, 961, 1240, 1077, 4660, 370, 15868, 3859, 2034, 14, 267, 1177, 275, 291, 14, 362, 7825, 267, 702, 63, 6134, 2336, 16971, 3859, 297, 1177, 14, 1985, 9, 398, 536, 275, 283, 774, 6474, 13588, 2034, 7, 267, 3031, 275, 283, 18086, 7, 398, 5445, 14, 2886, 8, 2123, 9, 398, 327, 1379, 314, 15868, 3859, 2034, 14, 267, 1177, 275, 291, 14, 362, 2336, 16971, 3859, 358, 267, 702, 63, 11332, 8, 1310, 14, 1205, 63, 442, 12, 1926, 9, 267, 702, 63, 6134, 360, 7099, 297, 1177, 14, 2030, 9, 398, 327, 653, 1214, 1700, 1077, 440, 1395, 4690, 5174, 14, 267, 702, 63, 9105, 63, 1397, 63, 7747, 8, 288, 2650, 65, 4369, 9555, 16971, 3859, 15, 2913, 1743, 5736, 1108, 65, 4206, 1177, 14, 2030, 9, 398, 327, 1379, 283, 1662, 13588, 7, 2034, 1380, 282, 6474, 365, 440, 26802, 315, 1263, 2518, 14, 267, 1177, 275, 291, 14, 362, 2336, 16971, 3859, 15, 11653, 358, 267, 702, 63, 11332, 8, 1310, 14, 1205, 63, 442, 12, 1926, 9, 267, 702, 63, 6134, 360, 5556, 787, 440, 5544, 26802, 315, 1263, 2518, 297, 717, 1177, 14, 2030, 9, 398, 327, 1379, 283, 1662, 13588, 7, 2034, 1380, 282, 6474, 365, 26802, 315, 1006, 13588, 14, 267, 5445, 14, 2683, 8, 277, 12, 536, 9, 267, 1177, 275, 291, 14, 362, 2336, 16971, 3859, 15, 11653, 358, 267, 702, 63, 11332, 8, 1310, 14, 1205, 63, 442, 12, 1926, 9, 267, 702, 63, 6134, 360, 7250, 370, 2518, 297, 1177, 14, 2030, 9, 267, 702, 63, 9105, 63, 1397, 63, 7747, 360, 5556, 787, 440, 5544, 26802, 315, 1263, 2518, 297, 1816, 1177, 14, 2030, 9, 398, 327, 12836, 314, 6474, 24493, 367, 282, 2518, 12, 267, 327, 4690, 5174, 1077, 506, 8917, 315, 16681, 1700, 14, 267, 702, 63, 6134, 8, 288, 2650, 65, 4369, 9555, 16971, 3859, 15, 2913, 1743, 5736, 1108, 65, 4206, 1177, 14, 2030, 9, 398, 327, 1379, 4690, 2034, 14, 267, 1177, 275, 291, 14, 362, 2336, 16971, 3859, 15, 2913, 358, 267, 702, 63, 6134, 4827, 2076, 6598, 83, 1108, 2076, 3524, 450, 3031, 12, 1177, 14, 2030, 9, 267, 702, 63, 6134, 4827, 2076, 6598, 83, 1108, 2076, 3524, 450, 536, 12, 1177, 14, 2030, 9, 267, 702, 63, 6134, 360, 11504, 297, 1177, 14, 2030, 9, 267, 702, 63, 9105, 63, 1397, 63, 7747, 360, 2768, 5396, 297, 1177, 14, 2030, 9, 339, 347, 511, 63, 4780, 63, 12634, 63, 1972, 8, 277, 304, 267, 408, 2925, 1380, 282, 2849, 9709, 2518, 365, 3451, 1041, 267, 3031, 275, 283, 396, 63, 305, 5480, 1470, 32, 3098, 14, 957, 7, 267, 536, 275, 283, 774, 3709, 5480, 1470, 7, 398, 327, 11828, 14, 267, 5445, 14, 2886, 8, 2123, 9, 267, 5445, 14, 2683, 8, 277, 12, 536, 9, 398, 1177, 275, 291, 14, 362, 2336, 16971, 3859, 358, 267, 327, 21467, 282, 2518, 365, 440, 9709, 12, 267, 327, 15868, 3859, 2034, 1077, 440, 2498, 283, 1345, 5396, 7, 5528, 14, 267, 702, 63, 9105, 63, 1397, 63, 7747, 360, 2768, 5396, 297, 1177, 14, 2030, 9, 398, 327, 16927, 282, 16183, 370, 314, 2518, 26802, 370, 2216, 652, 4890, 14, 267, 4690, 275, 8028, 279, 5736, 14, 362, 63, 991, 63, 498, 63, 354, 8, 2123, 9, 267, 2256, 275, 791, 5094, 63, 4523, 356, 283, 33, 936, 267, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
Peratham/segan
script/dot_topics.py
3
4584
# Script to take plain text topics from SHLDA and turn them into dot file # (suitable for further editing in OmniGraffle) # # Author: Jordan Boyd-Graber # Date: 12. Feb 2013 from textwrap import TextWrapper import sys from math import floor from string import strip COLORS = ["FF8888", "F8888E", "F28894", "EC889A", "E588A1", "DF88A7", "D988AD", "D388B3", "CC88BA", "C688C0", "C088C6", "BA88CC", "B388D3", "AD88D9", "A788DF", "A188E5", "9A88EC", "9488F2", "8E88F8", "8888FF"] class TopicNode: """ Class to parse and display a single line of the input file. Represents a node in the topic hierarchy. """ def __init__(self, line): node_fields, line = line.split("(") count_fields, word_fields = line.split(")") self.edges = set() node_fields = map(strip, node_fields.split(":")) node_fields = ["_".join(node_fields[:(x + 1)]) for x in \ xrange(len(node_fields))] node_fields = ['"%s"' % x for x in node_fields] for ii, vv in list(enumerate(node_fields))[1:]: self.edges.add((node_fields[ii-1], vv)) self.id = node_fields[-1] count_fields = count_fields.split(";") self.words = map(strip, word_fields.split(" ")) self.response = float(count_fields[-1]) self.token_count = int(count_fields[1]) #self.doc_count = int(count_fields[1]) self.iter_created = int(count_fields[0]) #print("Node ids: %s" % str(node_fields[-1])) #print("Count: %s" % str(count_fields)) #print("Word: %s" % str(word_fields)) #print("response = %f" % self.response) #print("doc count = %d" % self.doc_count) #print("token count = %d" % self.token_count) #print("iter created = %d" % self.iter_created) def graphviz(self, color): text = "" if len(self.words) == 2: text += "root" else: for ii in range(0, 10): text += " " + self.words[ii] text += "\n(" + str(self.id).replace('\"', '') + ", " + str(self.response) + ", " + str(self.token_count) + ")" return '\t%s [color="#%s" label="%s"];' % \ (self.id, color, text) class TopicGraph: """ Class to represent the entire topic hierarchy and to keep track of statistics necessary to render it. """ def __init__(self, doc_lim): self._edges = set() self._doc_lim = doc_lim self._nodes = {} self._max_response = float("-inf") self._min_response = float("inf") def range(self): return self._min_response, self._max_response def add_node(self, line, reverse=False): node = TopicNode(line) #if node.doc_count < self._doc_lim: # return None if node.iter_created > 100: return None if reverse: node.response *= -1.0 self._nodes[node.id] = node for ii in node.edges: self._edges.add(ii) self._max_response = max(self._max_response, node.response) self._min_response = min(self._min_response, node.response) return node def color(self, response, min, max): # Add a little bit of padding so that the max value doesn't break # things width = (max - min) * 1.001 levels = len(COLORS) val = int(floor((response - min) / width * levels)) return COLORS[val] def graphviz(self): yield 'graph {' yield '\tnode [style="filled" shape=box width=2.5in height=1.5in fixedsize=true];' for nn in self._nodes: node = self._nodes[nn] color = self.color(node.response, self._min_response, self._max_response) yield node.graphviz(color) yield "" for ee in self._edges: yield '\t%s -- %s;' % ee yield '}' if __name__ == "__main__": if len(sys.argv) < 3: print("USAGE: dot_topics.py INFILE OUTFILE [DOC_LIM] [--reverse]") infile = sys.argv[1] outfile = sys.argv[2] doc_lim = 15 if len(sys.argv) > 3: doc_lim = int(sys.argv[3]) reverse = False if len(sys.argv) > 4 and sys.argv[4] == "--reverse": print("Reverse") reverse = True graph = TopicGraph(doc_lim) for ii in [x for x in open(infile) if x.strip()]: graph.add_node(ii, reverse) print("Range: %s" % str(graph.range())) o = open(outfile, 'w') for ii in graph.graphviz(): o.write("%s\n" % ii) o.close()
apache-2.0
[ 3, 14914, 370, 5452, 8971, 1318, 17398, 687, 4410, 6533, 33, 436, 7485, 3062, 1901, 6308, 570, 199, 3, 334, 83, 10020, 367, 9848, 20401, 315, 593, 77, 8445, 5761, 556, 274, 9, 199, 3, 199, 3, 6529, 26, 1603, 2181, 290, 5088, 24503, 13, 5761, 605, 199, 3, 6148, 26, 3144, 14, 21141, 6171, 199, 199, 504, 13390, 492, 4516, 4590, 199, 646, 984, 199, 504, 3473, 492, 19841, 199, 504, 1059, 492, 6202, 199, 199, 25671, 275, 2097, 1665, 14871, 401, 298, 38, 14871, 37, 401, 298, 38, 10740, 2635, 401, 298, 4220, 13976, 33, 401, 298, 37, 29043, 33, 17, 401, 298, 3888, 1299, 33, 23, 401, 489, 298, 36, 31024, 1554, 401, 298, 36, 11403, 34, 19, 401, 298, 2571, 1299, 4134, 401, 298, 35, 27697, 35, 16, 401, 298, 35, 27930, 35, 22, 401, 298, 4134, 1299, 2571, 401, 489, 298, 34, 11403, 36, 19, 401, 298, 1554, 1299, 36, 25, 401, 298, 33, 29831, 3888, 401, 298, 33, 11501, 37, 21, 401, 298, 25, 33, 1299, 4220, 401, 298, 2635, 1299, 38, 18, 401, 489, 298, 24, 37, 1299, 38, 24, 401, 298, 14871, 1665, 937, 199, 199, 533, 32166, 1716, 26, 272, 408, 272, 8089, 370, 2198, 436, 2929, 282, 2849, 1004, 402, 314, 1324, 570, 14, 221, 21591, 282, 272, 1031, 315, 314, 7482, 14446, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 1004, 304, 267, 1031, 63, 955, 12, 1004, 275, 1004, 14, 1294, 480, 480, 9, 267, 2338, 63, 955, 12, 4349, 63, 955, 275, 1004, 14, 1294, 480, 6320, 398, 291, 14, 6929, 275, 663, 342, 267, 1031, 63, 955, 275, 2341, 8, 1913, 12, 1031, 63, 955, 14, 1294, 20308, 2237, 267, 1031, 63, 955, 275, 2097, 63, 1674, 904, 8, 932, 63, 955, 1491, 8, 88, 435, 413, 3948, 367, 671, 315, 971, 2511, 4945, 8, 552, 8, 932, 63, 955, 10524, 267, 1031, 63, 955, 275, 788, 6808, 83, 4507, 450, 671, 367, 671, 315, 1031, 63, 955, 61, 398, 367, 15393, 12, 373, 86, 315, 769, 8, 26318, 8, 932, 63, 955, 11515, 17, 10688, 288, 291, 14, 6929, 14, 525, 1332, 932, 63, 955, 59, 5908, 13, 17, 467, 373, 86, 430, 267, 291, 14, 344, 275, 1031, 63, 955, 1988, 17, 61, 398, 2338, 63, 955, 275, 2338, 63, 955, 14, 1294, 480, 15027, 267, 291, 14, 3148, 275, 2341, 8, 1913, 12, 4349, 63, 955, 14, 1294, 480, 26725, 267, 291, 14, 1310, 275, 2069, 8, 835, 63, 955, 1988, 17, 566, 267, 291, 14, 1418, 63, 835, 275, 1109, 8, 835, 63, 955, 59, 17, 566, 267, 327, 277, 14, 1301, 63, 835, 275, 1109, 8, 835, 63, 955, 59, 17, 566, 267, 291, 14, 1661, 63, 3966, 275, 1109, 8, 835, 63, 955, 59, 16, 566, 13857, 327, 1361, 480, 1716, 2762, 26, 450, 83, 2, 450, 620, 8, 932, 63, 955, 1988, 17, 2459, 267, 327, 1361, 480, 2353, 26, 450, 83, 2, 450, 620, 8, 835, 63, 955, 430, 199, 198, 3, 1361, 480, 10155, 26, 450, 83, 2, 450, 620, 8, 1027, 63, 955, 430, 199, 198, 3, 1361, 480, 1310, 275, 450, 70, 2, 450, 291, 14, 1310, 9, 199, 198, 3, 1361, 480, 1301, 2338, 275, 450, 68, 2, 450, 291, 14, 1301, 63, 835, 9, 199, 198, 3, 1361, 480, 1418, 2338, 275, 450, 68, 2, 450, 291, 14, 1418, 63, 835, 9, 199, 198, 3, 1361, 480, 1661, 2737, 275, 450, 68, 2, 450, 291, 14, 1661, 63, 3966, 9, 339, 347, 3343, 17249, 8, 277, 12, 3164, 304, 267, 1318, 275, 3087, 267, 340, 822, 8, 277, 14, 3148, 9, 508, 499, 26, 288, 1318, 847, 298, 1231, 2, 267, 587, 26, 288, 367, 15393, 315, 1425, 8, 16, 12, 1616, 304, 355, 1318, 847, 298, 298, 435, 291, 14, 3148, 59, 5908, 61, 267, 1318, 847, 1867, 78, 480, 435, 620, 8, 277, 14, 344, 680, 1814, 2258, 6949, 4074, 435, 3872, 298, 435, 620, 8, 277, 14, 1310, 9, 435, 3872, 298, 435, 620, 8, 277, 14, 1418, 63, 835, 9, 435, 19607, 267, 372, 1557, 84, 5, 83, 359, 2326, 13476, 5, 83, 2, 1768, 5961, 83, 937, 8942, 450, 971, 288, 334, 277, 14, 344, 12, 3164, 12, 1318, 9, 421, 199, 533, 32166, 4578, 26, 272, 408, 272, 8089, 370, 2954, 314, 8039, 7482, 14446, 436, 370, 4215, 4426, 402, 272, 11076, 5784, 370, 3795, 652, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 1382, 63, 4175, 304, 267, 291, 423, 6929, 275, 663, 342, 267, 291, 423, 1301, 63, 4175, 275, 1382, 63, 4175, 267, 291, 423, 2415, 275, 1052, 267, 291, 423, 988, 63, 1310, 275, 2069, 6096, 4904, 531, 267, 291, 423, 827, 63, 1310, 275, 2069, 480, 4904, 531, 339, 347, 1425, 8, 277, 304, 267, 372, 291, 423, 827, 63, 1310, 12, 291, 423, 988, 63, 1310, 339, 347, 1050, 63, 932, 8, 277, 12, 1004, 12, 3837, 29, 797, 304, 267, 1031, 275, 32166, 1716, 8, 604, 9, 398, 327, 692, 1031, 14, 1301, 63, 835, 665, 291, 423, 1301, 63, 4175, 26, 267, 327, 259, 372, 488, 2728, 340, 1031, 14, 1661, 63, 3966, 690, 2948, 26, 288, 372, 488, 398, 340, 3837, 26, 288, 1031, 14, 1310, 9000, 446, 17, 14, 16, 398, 291, 423, 2415, 59, 932, 14, 344, 61, 275, 1031, 267, 367, 15393, 315, 1031, 14, 6929, 26, 288, 291, 423, 6929, 14, 525, 8, 5908, 9, 398, 291, 423, 988, 63, 1310, 275, 1390, 8, 277, 423, 988, 63, 1310, 12, 1031, 14, 1310, 9, 267, 291, 423, 827, 63, 1310, 275, 1748, 8, 277, 423, 827, 63, 1310, 12, 1031, 14, 1310, 9, 398, 372, 1031, 339, 347, 3164, 8, 277, 12, 1177, 12, 1748, 12, 1390, 304, 267, 327, 2654, 282, 12050, 4546, 402, 6273, 880, 626, 314, 1390, 574, 3181, 1133, 2059, 267, 327, 7645, 267, 3462, 275, 334, 988, 446, 1748, 9, 627, 413, 14, 4587, 398, 11106, 275, 822, 8, 25671, 9, 398, 1139, 275, 1109, 8, 11289, 1332, 1310, 446, 1748, 9, 1182, 3462, 627, 11106, 430, 398, 372 ]
[ 14914, 370, 5452, 8971, 1318, 17398, 687, 4410, 6533, 33, 436, 7485, 3062, 1901, 6308, 570, 199, 3, 334, 83, 10020, 367, 9848, 20401, 315, 593, 77, 8445, 5761, 556, 274, 9, 199, 3, 199, 3, 6529, 26, 1603, 2181, 290, 5088, 24503, 13, 5761, 605, 199, 3, 6148, 26, 3144, 14, 21141, 6171, 199, 199, 504, 13390, 492, 4516, 4590, 199, 646, 984, 199, 504, 3473, 492, 19841, 199, 504, 1059, 492, 6202, 199, 199, 25671, 275, 2097, 1665, 14871, 401, 298, 38, 14871, 37, 401, 298, 38, 10740, 2635, 401, 298, 4220, 13976, 33, 401, 298, 37, 29043, 33, 17, 401, 298, 3888, 1299, 33, 23, 401, 489, 298, 36, 31024, 1554, 401, 298, 36, 11403, 34, 19, 401, 298, 2571, 1299, 4134, 401, 298, 35, 27697, 35, 16, 401, 298, 35, 27930, 35, 22, 401, 298, 4134, 1299, 2571, 401, 489, 298, 34, 11403, 36, 19, 401, 298, 1554, 1299, 36, 25, 401, 298, 33, 29831, 3888, 401, 298, 33, 11501, 37, 21, 401, 298, 25, 33, 1299, 4220, 401, 298, 2635, 1299, 38, 18, 401, 489, 298, 24, 37, 1299, 38, 24, 401, 298, 14871, 1665, 937, 199, 199, 533, 32166, 1716, 26, 272, 408, 272, 8089, 370, 2198, 436, 2929, 282, 2849, 1004, 402, 314, 1324, 570, 14, 221, 21591, 282, 272, 1031, 315, 314, 7482, 14446, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 1004, 304, 267, 1031, 63, 955, 12, 1004, 275, 1004, 14, 1294, 480, 480, 9, 267, 2338, 63, 955, 12, 4349, 63, 955, 275, 1004, 14, 1294, 480, 6320, 398, 291, 14, 6929, 275, 663, 342, 267, 1031, 63, 955, 275, 2341, 8, 1913, 12, 1031, 63, 955, 14, 1294, 20308, 2237, 267, 1031, 63, 955, 275, 2097, 63, 1674, 904, 8, 932, 63, 955, 1491, 8, 88, 435, 413, 3948, 367, 671, 315, 971, 2511, 4945, 8, 552, 8, 932, 63, 955, 10524, 267, 1031, 63, 955, 275, 788, 6808, 83, 4507, 450, 671, 367, 671, 315, 1031, 63, 955, 61, 398, 367, 15393, 12, 373, 86, 315, 769, 8, 26318, 8, 932, 63, 955, 11515, 17, 10688, 288, 291, 14, 6929, 14, 525, 1332, 932, 63, 955, 59, 5908, 13, 17, 467, 373, 86, 430, 267, 291, 14, 344, 275, 1031, 63, 955, 1988, 17, 61, 398, 2338, 63, 955, 275, 2338, 63, 955, 14, 1294, 480, 15027, 267, 291, 14, 3148, 275, 2341, 8, 1913, 12, 4349, 63, 955, 14, 1294, 480, 26725, 267, 291, 14, 1310, 275, 2069, 8, 835, 63, 955, 1988, 17, 566, 267, 291, 14, 1418, 63, 835, 275, 1109, 8, 835, 63, 955, 59, 17, 566, 267, 327, 277, 14, 1301, 63, 835, 275, 1109, 8, 835, 63, 955, 59, 17, 566, 267, 291, 14, 1661, 63, 3966, 275, 1109, 8, 835, 63, 955, 59, 16, 566, 13857, 327, 1361, 480, 1716, 2762, 26, 450, 83, 2, 450, 620, 8, 932, 63, 955, 1988, 17, 2459, 267, 327, 1361, 480, 2353, 26, 450, 83, 2, 450, 620, 8, 835, 63, 955, 430, 199, 198, 3, 1361, 480, 10155, 26, 450, 83, 2, 450, 620, 8, 1027, 63, 955, 430, 199, 198, 3, 1361, 480, 1310, 275, 450, 70, 2, 450, 291, 14, 1310, 9, 199, 198, 3, 1361, 480, 1301, 2338, 275, 450, 68, 2, 450, 291, 14, 1301, 63, 835, 9, 199, 198, 3, 1361, 480, 1418, 2338, 275, 450, 68, 2, 450, 291, 14, 1418, 63, 835, 9, 199, 198, 3, 1361, 480, 1661, 2737, 275, 450, 68, 2, 450, 291, 14, 1661, 63, 3966, 9, 339, 347, 3343, 17249, 8, 277, 12, 3164, 304, 267, 1318, 275, 3087, 267, 340, 822, 8, 277, 14, 3148, 9, 508, 499, 26, 288, 1318, 847, 298, 1231, 2, 267, 587, 26, 288, 367, 15393, 315, 1425, 8, 16, 12, 1616, 304, 355, 1318, 847, 298, 298, 435, 291, 14, 3148, 59, 5908, 61, 267, 1318, 847, 1867, 78, 480, 435, 620, 8, 277, 14, 344, 680, 1814, 2258, 6949, 4074, 435, 3872, 298, 435, 620, 8, 277, 14, 1310, 9, 435, 3872, 298, 435, 620, 8, 277, 14, 1418, 63, 835, 9, 435, 19607, 267, 372, 1557, 84, 5, 83, 359, 2326, 13476, 5, 83, 2, 1768, 5961, 83, 937, 8942, 450, 971, 288, 334, 277, 14, 344, 12, 3164, 12, 1318, 9, 421, 199, 533, 32166, 4578, 26, 272, 408, 272, 8089, 370, 2954, 314, 8039, 7482, 14446, 436, 370, 4215, 4426, 402, 272, 11076, 5784, 370, 3795, 652, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 1382, 63, 4175, 304, 267, 291, 423, 6929, 275, 663, 342, 267, 291, 423, 1301, 63, 4175, 275, 1382, 63, 4175, 267, 291, 423, 2415, 275, 1052, 267, 291, 423, 988, 63, 1310, 275, 2069, 6096, 4904, 531, 267, 291, 423, 827, 63, 1310, 275, 2069, 480, 4904, 531, 339, 347, 1425, 8, 277, 304, 267, 372, 291, 423, 827, 63, 1310, 12, 291, 423, 988, 63, 1310, 339, 347, 1050, 63, 932, 8, 277, 12, 1004, 12, 3837, 29, 797, 304, 267, 1031, 275, 32166, 1716, 8, 604, 9, 398, 327, 692, 1031, 14, 1301, 63, 835, 665, 291, 423, 1301, 63, 4175, 26, 267, 327, 259, 372, 488, 2728, 340, 1031, 14, 1661, 63, 3966, 690, 2948, 26, 288, 372, 488, 398, 340, 3837, 26, 288, 1031, 14, 1310, 9000, 446, 17, 14, 16, 398, 291, 423, 2415, 59, 932, 14, 344, 61, 275, 1031, 267, 367, 15393, 315, 1031, 14, 6929, 26, 288, 291, 423, 6929, 14, 525, 8, 5908, 9, 398, 291, 423, 988, 63, 1310, 275, 1390, 8, 277, 423, 988, 63, 1310, 12, 1031, 14, 1310, 9, 267, 291, 423, 827, 63, 1310, 275, 1748, 8, 277, 423, 827, 63, 1310, 12, 1031, 14, 1310, 9, 398, 372, 1031, 339, 347, 3164, 8, 277, 12, 1177, 12, 1748, 12, 1390, 304, 267, 327, 2654, 282, 12050, 4546, 402, 6273, 880, 626, 314, 1390, 574, 3181, 1133, 2059, 267, 327, 7645, 267, 3462, 275, 334, 988, 446, 1748, 9, 627, 413, 14, 4587, 398, 11106, 275, 822, 8, 25671, 9, 398, 1139, 275, 1109, 8, 11289, 1332, 1310, 446, 1748, 9, 1182, 3462, 627, 11106, 430, 398, 372, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
nevir/plexability
extern/depot_tools/third_party/gsutil/gslib/addlhelp/acls.py
51
9472
# Copyright 2012 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from gslib.help_provider import HELP_NAME from gslib.help_provider import HELP_NAME_ALIASES from gslib.help_provider import HELP_ONE_LINE_SUMMARY from gslib.help_provider import HelpProvider from gslib.help_provider import HELP_TEXT from gslib.help_provider import HelpType from gslib.help_provider import HELP_TYPE _detailed_help_text = (""" <B>OVERVIEW</B> Access Control Lists (ACLs) allow you to control who can read and write your data, and who can read and write the ACLs themselves. If not specified at the time an object is uploaded (e.g., via the gsutil cp -a option), objects will be created with a default object ACL set on the bucket (see "gsutil help setdefacl"). You can replace the ACL on an object or bucket using the gsutil setacl command (see "gsutil help setacl"), or modify the existing ACL using the gsutil chacl command (see "gsutil help chacl"). <B>BUCKET VS OBJECT ACLS</B> In Google Cloud Storage, the bucket ACL works as follows: - Users granted READ access are allowed to list the bucket contents. - Users granted WRITE access are allowed READ access and also are allowed to write and delete objects in that bucket -- including overwriting previously written objects. - Users granted FULL_CONTROL access are allowed WRITE access and also are allowed to read and write the bucket's ACL. The object ACL works as follows: - Users granted READ access are allowed to read the object's data and metadata. - Users granted FULL_CONTROL access are allowed READ access and also are allowed to read and write the object's ACL. A couple of points are worth noting, that sometimes surprise users: 1. There is no WRITE access for objects; attempting to set an ACL with WRITE permission for an object will result in an error. 2. The bucket ACL plays no role in determining who can read objects; only the object ACL matters for that purpose. This is different from how things work in Linux file systems, where both the file and directory permission control file read access. It also means, for example, that someone with FULL_CONTROL over the bucket may not have read access to objects in the bucket. This is by design, and supports useful cases. For example, you might want to set up bucket ownership so that a small group of administrators have FULL_CONTROL on the bucket (with the ability to delete data to control storage costs), but not grant those users read access to the object data (which might be sensitive data that should only be accessed by a different specific group of users). <B>CANNED ACLS</B> The simplest way to set an ACL on a bucket or object is using a "canned ACL". The available canned ACLs are: project-private Gives permission to the project team based on their roles. Anyone who is part of the team has READ permission, and project owners and project editors have FULL_CONTROL permission. This is the default ACL for newly created buckets. This is also the default ACL for newly created objects unless the default object ACL for that bucket has been changed. For more details see "gsutil help projects". private Gives the requester (and only the requester) FULL_CONTROL permission for a bucket or object. public-read Gives the requester FULL_CONTROL permission and gives all users READ permission. When you apply this to an object, anyone on the Internet can read the object without authenticating. public-read-write Gives the requester FULL_CONTROL permission and gives all users READ and WRITE permission. This ACL applies only to buckets. authenticated-read Gives the requester FULL_CONTROL permission and gives all authenticated Google account holders READ permission. bucket-owner-read Gives the requester FULL_CONTROL permission and gives the bucket owner READ permission. This is used only with objects. bucket-owner-full-control Gives the requester FULL_CONTROL permission and gives the bucket owner FULL_CONTROL permission. This is used only with objects. <B>ACL XML</B> When you use a canned ACL, it is translated into an XML representation that can later be retrieved and edited to specify more fine-grained detail about who can read and write buckets and objects. By running the gsutil getacl command you can retrieve the ACL XML, and edit it to customize the permissions. As an example, if you create an object in a bucket that has no default object ACL set and then retrieve the ACL on the object, it will look something like this: <AccessControlList> <Owner> <ID> 00b4903a9740e42c29800f53bd5a9a62a2f96eb3f64a4313a115df3f3a776bf7 </ID> </Owner> <Entries> <Entry> <Scope type="GroupById"> <ID> 00b4903a9740e42c29800f53bd5a9a62a2f96eb3f64a4313a115df3f3a776bf7 </ID> </Scope> <Permission> FULL_CONTROL </Permission> </Entry> <Entry> <Scope type="GroupById"> <ID> 00b4903a977fd817e9da167bc81306489181a110456bb635f466d71cf90a0d51 </ID> </Scope> <Permission> FULL_CONTROL </Permission> </Entry> <Entry> <Scope type="GroupById"> <ID> 00b4903a974898cc8fc309f2f2835308ba3d3df1b889d3fc7e33e187d52d8e71 </ID> </Scope> <Permission> READ </Permission> </Entry> </Entries> </AccessControlList> The ACL consists of an Owner element and a collection of Entry elements, each of which specifies a Scope and a Permission. Scopes are the way you specify an individual or group of individuals, and Permissions specify what access they're permitted. This particular ACL grants FULL_CONTROL to two groups (which means members of those groups are allowed to read the object and read and write the ACL), and READ permission to a third group. The project groups are (in order) the owners group, editors group, and viewers group. The 64 digit hex identifiers used in this ACL are called canonical IDs, and are used to identify predefined groups associated with the project that owns the bucket. For more information about project groups, see "gsutil help projects". Here's an example of an ACL specified using the GroupByEmail and GroupByDomain scopes: <AccessControlList> <Entries> <Entry> <Permission> FULL_CONTROL </Permission> <Scope type="GroupByEmail"> <EmailAddress>travel-companion-owners@googlegroups.com</EmailAddress> </Scope> </Entry> <Entry> <Permission> READ </Permission> <Scope type="GroupByDomain"> <Domain>example.com</Domain> </Scope> </Entry> </Entries> </AccessControlList> This ACL grants members of an email group FULL_CONTROL, and grants READ access to any user in a domain (which must be a Google Apps for Business domain). By applying email group grants to a collection of objects you can edit access control for large numbers of objects at once via http://groups.google.com. That way, for example, you can easily and quickly change access to a group of company objects when employees join and leave your company (i.e., without having to individually change ACLs across potentially millions of objects). <B>SHARING SCENARIOS</B> For more detailed examples how to achieve various useful sharing use cases see https://developers.google.com/storage/docs/collaboration """) class CommandOptions(HelpProvider): """Additional help about Access Control Lists.""" help_spec = { # Name of command or auxiliary help info for which this help applies. HELP_NAME : 'acls', # List of help name aliases. HELP_NAME_ALIASES : ['acl', 'ACL', 'access control', 'access control list', 'authorization', 'canned', 'canned acl'], # Type of help: HELP_TYPE : HelpType.ADDITIONAL_HELP, # One line summary of this help. HELP_ONE_LINE_SUMMARY : 'Working with Access Control Lists', # The full help text. HELP_TEXT : _detailed_help_text, }
gpl-2.0
[ 3, 1898, 6029, 4475, 3277, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 199, 504, 29563, 14, 3437, 63, 3780, 492, 29269, 63, 2339, 199, 504, 29563, 14, 3437, 63, 3780, 492, 29269, 63, 2339, 63, 12644, 654, 199, 504, 29563, 14, 3437, 63, 3780, 492, 29269, 63, 4817, 63, 6174, 63, 29508, 199, 504, 29563, 14, 3437, 63, 3780, 492, 15456, 6663, 199, 504, 29563, 14, 3437, 63, 3780, 492, 29269, 63, 3876, 199, 504, 29563, 14, 3437, 63, 3780, 492, 15456, 804, 199, 504, 29563, 14, 3437, 63, 3780, 492, 29269, 63, 2711, 199, 199, 63, 19170, 63, 3437, 63, 505, 275, 334, 624, 199, 28, 34, 30, 14336, 12058, 1108, 34, 30, 523, 11003, 8612, 31289, 334, 18765, 83, 9, 2040, 1265, 370, 3304, 3963, 883, 1586, 436, 2218, 523, 2195, 666, 12, 436, 3963, 883, 1586, 436, 2218, 314, 16543, 83, 17279, 14, 819, 982, 440, 2013, 737, 314, 900, 376, 909, 365, 14238, 334, 69, 14, 71, 2020, 4799, 314, 24986, 7667, 523, 446, 65, 945, 395, 2251, 911, 506, 2737, 543, 282, 849, 909, 16543, 663, 641, 314, 523, 5315, 334, 3239, 298, 458, 1974, 1720, 663, 318, 5853, 3471, 2047, 883, 3350, 314, 16543, 641, 376, 909, 523, 503, 5315, 1808, 314, 24986, 663, 5853, 1414, 334, 3239, 298, 458, 1974, 1720, 663, 5853, 1288, 503, 523, 2811, 314, 3411, 16543, 1808, 314, 24986, 682, 5853, 1414, 334, 3239, 298, 458, 1974, 1720, 523, 682, 5853, 3471, 421, 199, 28, 34, 30, 20156, 21685, 28652, 5550, 16543, 51, 1108, 34, 30, 523, 1010, 4475, 8142, 10533, 12, 314, 5315, 16543, 5419, 465, 11924, 26, 339, 446, 20123, 10009, 16767, 2879, 787, 4370, 370, 769, 314, 5315, 4072, 14, 339, 446, 20123, 10009, 32280, 2879, 787, 4370, 16767, 2879, 436, 2597, 787, 489, 4370, 370, 2218, 436, 3145, 2251, 315, 626, 5315, 1553, 5893, 489, 32592, 10889, 5313, 2251, 14, 339, 446, 20123, 10009, 18530, 63, 13060, 2879, 787, 4370, 32280, 2879, 436, 2597, 489, 787, 4370, 370, 1586, 436, 2218, 314, 5315, 1159, 16543, 14, 819, 710, 909, 16543, 5419, 465, 11924, 26, 339, 446, 20123, 10009, 16767, 2879, 787, 4370, 370, 1586, 314, 909, 1159, 666, 436, 489, 3341, 14, 339, 446, 20123, 10009, 18530, 63, 13060, 2879, 787, 4370, 16767, 2879, 436, 2597, 489, 787, 4370, 370, 1586, 436, 2218, 314, 909, 1159, 16543, 14, 819, 437, 17535, 402, 4501, 787, 25235, 440, 316, 12, 626, 15026, 6296, 13219, 4390, 26, 819, 413, 14, 6006, 365, 949, 32280, 2879, 367, 2251, 27, 19595, 370, 663, 376, 16543, 543, 32280, 1362, 4983, 367, 376, 909, 911, 754, 315, 376, 1125, 14, 819, 499, 14, 710, 5315, 16543, 299, 9316, 949, 4719, 315, 26638, 3963, 883, 1586, 2251, 27, 1454, 314, 1362, 909, 16543, 2530, 878, 367, 626, 12016, 14, 961, 365, 3365, 687, 4212, 7645, 1362, 1736, 315, 10130, 570, 10460, 12, 2382, 3865, 314, 570, 436, 2082, 4983, 1362, 3304, 570, 1586, 2879, 14, 2779, 2597, 4910, 12, 367, 2893, 12, 626, 17122, 543, 1362, 18530, 63, 13060, 1806, 314, 5315, 1443, 440, 1172, 1586, 2879, 370, 2251, 315, 1362, 314, 5315, 14, 221, 961, 365, 701, 12899, 12, 436, 5171, 2997, 5560, 14, 2104, 2893, 12, 1362, 1265, 5594, 2934, 370, 663, 1536, 5315, 12715, 880, 626, 282, 7425, 1572, 402, 1362, 4628, 3075, 2750, 1172, 18530, 63, 13060, 641, 314, 5315, 334, 1045, 314, 21255, 370, 1362, 3145, 666, 370, 3304, 4887, 26819, 395, 1325, 440, 16085, 5204, 4390, 1586, 1362, 2879, 370, 314, 909, 666, 334, 6777, 5594, 506, 18423, 666, 626, 1077, 1362, 1454, 506, 13810, 701, 282, 3365, 2488, 1572, 402, 4390, 680, 421, 199, 28, 34, 30, 18988, 46, 1149, 16543, 51, 1108, 34, 30, 523, 710, 3486, 270, 4340, 370, 663, 376, 16543, 641, 282, 5315, 503, 909, 365, 1808, 282, 298, 31126, 523, 16543, 1674, 710, 2808, 883, 7439, 16543, 83, 787, 26, 819, 2199, 13, 4239, 3322, 598, 7602, 4983, 370, 314, 2199, 8099, 4079, 641, 3932, 2490, 11689, 14, 6184, 368, 3963, 365, 1777, 402, 314, 8099, 965, 16767, 2490, 4983, 12, 436, 2199, 31867, 436, 2199, 5283, 1384, 2490, 1172, 18530, 63, 13060, 4983, 14, 961, 365, 314, 849, 2490, 16543, 367, 13903, 2737, 18655, 14, 961, 365, 2597, 314, 2490, 849, 16543, 367, 13903, 2737, 2251, 7444, 314, 2490, 849, 909, 16543, 367, 626, 5315, 965, 2757, 2490, 2896, 14, 2104, 1655, 2436, 1937, 2490, 298, 458, 1974, 1720, 11336, 1674, 819, 5726, 8540, 598, 7602, 314, 295, 18246, 334, 460, 1454, 314, 295, 18246, 9, 2490, 18530, 63, 13060, 4983, 367, 282, 5315, 503, 909, 14, 819, 4575, 13, 739, 4483, 598, 7602, 314, 295, 18246, 18530, 63, 13060, 4983, 436, 2490, 10557, 1006, 4390, 16767, 4983, 14, 3979, 1265, 4838, 2490, 642, 370, 376, 909, 12, 29165, 641, 314, 22026, 883, 2490, 1586, 314, 909, 1928, 28532, 1958, 14, 819, 4575, 13, 739, 13, 952, 3515, 598, 7602, 314, 295, 18246, 18530, 63, 13060, 4983, 436, 2490, 10557, 1006, 4390, 16767, 436, 32280, 4983, 14, 961, 2490, 16543, 12966, 1454, 370, 18655, 14, 819, 15082, 13, 739, 260, 598, 7602, 314, 295, 18246, 18530, 63, 13060, 4983, 436, 2490, 10557, 1006, 15082, 4475, 2933, 31976, 2490, 16767, 4983, 14, 819, 5315, 13, 4597, 13, 739, 3515, 598, 7602, 314, 295, 18246, 18530, 63, 13060, 4983, 436, 2490, 10557, 314, 5315, 5771, 16767 ]
[ 1898, 6029, 4475, 3277, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 199, 504, 29563, 14, 3437, 63, 3780, 492, 29269, 63, 2339, 199, 504, 29563, 14, 3437, 63, 3780, 492, 29269, 63, 2339, 63, 12644, 654, 199, 504, 29563, 14, 3437, 63, 3780, 492, 29269, 63, 4817, 63, 6174, 63, 29508, 199, 504, 29563, 14, 3437, 63, 3780, 492, 15456, 6663, 199, 504, 29563, 14, 3437, 63, 3780, 492, 29269, 63, 3876, 199, 504, 29563, 14, 3437, 63, 3780, 492, 15456, 804, 199, 504, 29563, 14, 3437, 63, 3780, 492, 29269, 63, 2711, 199, 199, 63, 19170, 63, 3437, 63, 505, 275, 334, 624, 199, 28, 34, 30, 14336, 12058, 1108, 34, 30, 523, 11003, 8612, 31289, 334, 18765, 83, 9, 2040, 1265, 370, 3304, 3963, 883, 1586, 436, 2218, 523, 2195, 666, 12, 436, 3963, 883, 1586, 436, 2218, 314, 16543, 83, 17279, 14, 819, 982, 440, 2013, 737, 314, 900, 376, 909, 365, 14238, 334, 69, 14, 71, 2020, 4799, 314, 24986, 7667, 523, 446, 65, 945, 395, 2251, 911, 506, 2737, 543, 282, 849, 909, 16543, 663, 641, 314, 523, 5315, 334, 3239, 298, 458, 1974, 1720, 663, 318, 5853, 3471, 2047, 883, 3350, 314, 16543, 641, 376, 909, 523, 503, 5315, 1808, 314, 24986, 663, 5853, 1414, 334, 3239, 298, 458, 1974, 1720, 663, 5853, 1288, 503, 523, 2811, 314, 3411, 16543, 1808, 314, 24986, 682, 5853, 1414, 334, 3239, 298, 458, 1974, 1720, 523, 682, 5853, 3471, 421, 199, 28, 34, 30, 20156, 21685, 28652, 5550, 16543, 51, 1108, 34, 30, 523, 1010, 4475, 8142, 10533, 12, 314, 5315, 16543, 5419, 465, 11924, 26, 339, 446, 20123, 10009, 16767, 2879, 787, 4370, 370, 769, 314, 5315, 4072, 14, 339, 446, 20123, 10009, 32280, 2879, 787, 4370, 16767, 2879, 436, 2597, 787, 489, 4370, 370, 2218, 436, 3145, 2251, 315, 626, 5315, 1553, 5893, 489, 32592, 10889, 5313, 2251, 14, 339, 446, 20123, 10009, 18530, 63, 13060, 2879, 787, 4370, 32280, 2879, 436, 2597, 489, 787, 4370, 370, 1586, 436, 2218, 314, 5315, 1159, 16543, 14, 819, 710, 909, 16543, 5419, 465, 11924, 26, 339, 446, 20123, 10009, 16767, 2879, 787, 4370, 370, 1586, 314, 909, 1159, 666, 436, 489, 3341, 14, 339, 446, 20123, 10009, 18530, 63, 13060, 2879, 787, 4370, 16767, 2879, 436, 2597, 489, 787, 4370, 370, 1586, 436, 2218, 314, 909, 1159, 16543, 14, 819, 437, 17535, 402, 4501, 787, 25235, 440, 316, 12, 626, 15026, 6296, 13219, 4390, 26, 819, 413, 14, 6006, 365, 949, 32280, 2879, 367, 2251, 27, 19595, 370, 663, 376, 16543, 543, 32280, 1362, 4983, 367, 376, 909, 911, 754, 315, 376, 1125, 14, 819, 499, 14, 710, 5315, 16543, 299, 9316, 949, 4719, 315, 26638, 3963, 883, 1586, 2251, 27, 1454, 314, 1362, 909, 16543, 2530, 878, 367, 626, 12016, 14, 961, 365, 3365, 687, 4212, 7645, 1362, 1736, 315, 10130, 570, 10460, 12, 2382, 3865, 314, 570, 436, 2082, 4983, 1362, 3304, 570, 1586, 2879, 14, 2779, 2597, 4910, 12, 367, 2893, 12, 626, 17122, 543, 1362, 18530, 63, 13060, 1806, 314, 5315, 1443, 440, 1172, 1586, 2879, 370, 2251, 315, 1362, 314, 5315, 14, 221, 961, 365, 701, 12899, 12, 436, 5171, 2997, 5560, 14, 2104, 2893, 12, 1362, 1265, 5594, 2934, 370, 663, 1536, 5315, 12715, 880, 626, 282, 7425, 1572, 402, 1362, 4628, 3075, 2750, 1172, 18530, 63, 13060, 641, 314, 5315, 334, 1045, 314, 21255, 370, 1362, 3145, 666, 370, 3304, 4887, 26819, 395, 1325, 440, 16085, 5204, 4390, 1586, 1362, 2879, 370, 314, 909, 666, 334, 6777, 5594, 506, 18423, 666, 626, 1077, 1362, 1454, 506, 13810, 701, 282, 3365, 2488, 1572, 402, 4390, 680, 421, 199, 28, 34, 30, 18988, 46, 1149, 16543, 51, 1108, 34, 30, 523, 710, 3486, 270, 4340, 370, 663, 376, 16543, 641, 282, 5315, 503, 909, 365, 1808, 282, 298, 31126, 523, 16543, 1674, 710, 2808, 883, 7439, 16543, 83, 787, 26, 819, 2199, 13, 4239, 3322, 598, 7602, 4983, 370, 314, 2199, 8099, 4079, 641, 3932, 2490, 11689, 14, 6184, 368, 3963, 365, 1777, 402, 314, 8099, 965, 16767, 2490, 4983, 12, 436, 2199, 31867, 436, 2199, 5283, 1384, 2490, 1172, 18530, 63, 13060, 4983, 14, 961, 365, 314, 849, 2490, 16543, 367, 13903, 2737, 18655, 14, 961, 365, 2597, 314, 2490, 849, 16543, 367, 13903, 2737, 2251, 7444, 314, 2490, 849, 909, 16543, 367, 626, 5315, 965, 2757, 2490, 2896, 14, 2104, 1655, 2436, 1937, 2490, 298, 458, 1974, 1720, 11336, 1674, 819, 5726, 8540, 598, 7602, 314, 295, 18246, 334, 460, 1454, 314, 295, 18246, 9, 2490, 18530, 63, 13060, 4983, 367, 282, 5315, 503, 909, 14, 819, 4575, 13, 739, 4483, 598, 7602, 314, 295, 18246, 18530, 63, 13060, 4983, 436, 2490, 10557, 1006, 4390, 16767, 4983, 14, 3979, 1265, 4838, 2490, 642, 370, 376, 909, 12, 29165, 641, 314, 22026, 883, 2490, 1586, 314, 909, 1928, 28532, 1958, 14, 819, 4575, 13, 739, 13, 952, 3515, 598, 7602, 314, 295, 18246, 18530, 63, 13060, 4983, 436, 2490, 10557, 1006, 4390, 16767, 436, 32280, 4983, 14, 961, 2490, 16543, 12966, 1454, 370, 18655, 14, 819, 15082, 13, 739, 260, 598, 7602, 314, 295, 18246, 18530, 63, 13060, 4983, 436, 2490, 10557, 1006, 15082, 4475, 2933, 31976, 2490, 16767, 4983, 14, 819, 5315, 13, 4597, 13, 739, 3515, 598, 7602, 314, 295, 18246, 18530, 63, 13060, 4983, 436, 2490, 10557, 314, 5315, 5771, 16767, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
clever-crow-consulting/otm-core
opentreemap/exporter/views.py
6
3612
# -*- coding: utf-8 -*- from __future__ import print_function from __future__ import unicode_literals from __future__ import division from django.http import Http404 from django.shortcuts import get_object_or_404 from tasks import async_csv_export, async_users_export from django_tinsel.utils import decorate as do from django_tinsel.decorators import json_api_call from treemap.util import get_csv_response, get_json_response from treemap.decorators import instance_request, requires_feature from exporter import EXPORTS_NOT_ENABLED_CONTEXT from exporter.lib import export_enabled_for from exporter.models import ExportJob from exporter.user import write_users ############################################ # synchronous exports ############################################ # # these are legacy views that are used by the API to provide # this data to external services. they are not used by the web # client (js) or the android app. generally, they should not # be used, because synchronous exports are a costly burden # on the request/response cycle. # # TODO: convert the API to provide asynchronous exporting. # def _get_user_extra_args(request): return [request.REQUEST.get("minJoinDate"), request.REQUEST.get("minEditDate")] def users_csv(request, instance): "Return a user csv synchronously" response = get_csv_response('users.csv') extra = _get_user_extra_args(request) write_users('csv', response, instance, *extra) return response def users_json(request, instance): response = get_json_response('user_export.json') extra = _get_user_extra_args(request) write_users('json', response, instance, *extra) return response ############################################ # async exports ############################################ def begin_export_users(request, instance, data_format): if not request.user.is_authenticated(): raise Http404() if not export_enabled_for(instance, request.user): return EXPORTS_NOT_ENABLED_CONTEXT job = ExportJob.objects.create( instance=instance, user=request.user, description='user export with %s format' % data_format) async_users_export.delay(job.pk, data_format) return {'start_status': 'OK', 'job_id': job.pk} def begin_export(request, instance, model): if not export_enabled_for(instance, request.user): return EXPORTS_NOT_ENABLED_CONTEXT query = request.GET.get('q', None) display_filters = request.GET.get('show', None) job = ExportJob(instance=instance, description='csv export of %s' % model) if request.user.is_authenticated(): job.user = request.user job.save() async_csv_export.delay(job.pk, model, query, display_filters) return {'start_status': 'OK', 'job_id': job.pk} def check_export(request, instance, job_id): job = get_object_or_404(ExportJob, pk=job_id) # if a job has a user, it means the user must # be authenticated so only the job user can # retrieve the export if job.user and job.user != request.user: return {'status': 'ERROR', 'message': 'Job not initiated by user', 'url': None} else: return {'status': ExportJob.STATUS_STRINGS[job.status], 'message': ExportJob.STATUS_CHOICES[job.status], 'url': job.get_url_if_ready()} begin_export_endpoint = do( json_api_call, instance_request, requires_feature('exports'), begin_export) check_export_endpoint = do( json_api_call, instance_request, check_export)
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 504, 636, 2443, 363, 492, 4629, 199, 199, 504, 1639, 14, 1014, 492, 4760, 5188, 199, 504, 1639, 14, 17469, 492, 664, 63, 785, 63, 269, 63, 5188, 199, 199, 504, 6527, 492, 5316, 63, 4737, 63, 3790, 12, 5316, 63, 3707, 63, 3790, 199, 199, 504, 1639, 63, 1346, 5891, 14, 1208, 492, 24774, 465, 886, 199, 504, 1639, 63, 1346, 5891, 14, 11582, 492, 2022, 63, 1246, 63, 1250, 199, 199, 504, 3123, 1130, 14, 1974, 492, 664, 63, 4737, 63, 1310, 12, 664, 63, 1001, 63, 1310, 199, 504, 3123, 1130, 14, 11582, 492, 1256, 63, 1069, 12, 5074, 63, 4445, 199, 199, 504, 1437, 3968, 492, 3651, 3657, 51, 63, 4609, 63, 15704, 63, 9059, 199, 504, 1437, 3968, 14, 773, 492, 4843, 63, 3827, 63, 509, 199, 504, 1437, 3968, 14, 992, 492, 20220, 6694, 199, 504, 1437, 3968, 14, 751, 492, 2218, 63, 3707, 199, 199, 26634, 381, 199, 3, 24248, 22609, 199, 26634, 381, 199, 3, 199, 3, 3520, 787, 12139, 6858, 626, 787, 1202, 701, 314, 3261, 370, 5647, 199, 3, 642, 666, 370, 5957, 8500, 14, 2985, 787, 440, 1202, 701, 314, 3330, 199, 3, 1890, 334, 3596, 9, 503, 314, 15516, 1145, 14, 16711, 12, 2985, 1077, 440, 199, 3, 506, 1202, 12, 2952, 24248, 22609, 787, 282, 7918, 590, 330, 300, 848, 199, 3, 641, 314, 1056, 15, 1310, 8643, 14, 199, 3, 199, 3, 3254, 26, 3957, 314, 3261, 370, 5647, 15608, 4843, 316, 14, 199, 3, 421, 199, 318, 485, 362, 63, 751, 63, 2911, 63, 589, 8, 1069, 304, 272, 372, 359, 1069, 14, 6780, 14, 362, 480, 827, 13005, 2506, 1288, 288, 1056, 14, 6780, 14, 362, 480, 827, 4685, 2506, 11323, 421, 199, 318, 4390, 63, 4737, 8, 1069, 12, 1256, 304, 272, 298, 1767, 282, 922, 7392, 24248, 590, 2, 272, 1177, 275, 664, 63, 4737, 63, 1310, 360, 3707, 14, 4737, 358, 272, 2402, 275, 485, 362, 63, 751, 63, 2911, 63, 589, 8, 1069, 9, 272, 2218, 63, 3707, 360, 4737, 297, 1177, 12, 1256, 12, 627, 2911, 9, 272, 372, 1177, 421, 199, 318, 4390, 63, 1001, 8, 1069, 12, 1256, 304, 272, 1177, 275, 664, 63, 1001, 63, 1310, 360, 751, 63, 3790, 14, 1001, 358, 272, 2402, 275, 485, 362, 63, 751, 63, 2911, 63, 589, 8, 1069, 9, 272, 2218, 63, 3707, 360, 1001, 297, 1177, 12, 1256, 12, 627, 2911, 9, 272, 372, 1177, 421, 199, 26634, 381, 199, 3, 5316, 22609, 199, 26634, 381, 199, 199, 318, 5386, 63, 3790, 63, 3707, 8, 1069, 12, 1256, 12, 666, 63, 908, 304, 272, 340, 440, 1056, 14, 751, 14, 374, 63, 12177, 837, 267, 746, 4760, 5188, 342, 339, 340, 440, 4843, 63, 3827, 63, 509, 8, 842, 12, 1056, 14, 751, 304, 267, 372, 3651, 3657, 51, 63, 4609, 63, 15704, 63, 9059, 339, 3906, 275, 20220, 6694, 14, 1462, 14, 981, 8, 267, 1256, 29, 842, 12, 267, 922, 29, 1069, 14, 751, 12, 267, 1369, 534, 751, 4843, 543, 450, 83, 1475, 7, 450, 666, 63, 908, 9, 339, 5316, 63, 3707, 63, 3790, 14, 5814, 8, 2423, 14, 2051, 12, 666, 63, 908, 9, 339, 372, 791, 928, 63, 1205, 356, 283, 3593, 297, 283, 2423, 63, 344, 356, 3906, 14, 2051, 93, 421, 199, 318, 5386, 63, 3790, 8, 1069, 12, 1256, 12, 1402, 304, 272, 340, 440, 4843, 63, 3827, 63, 509, 8, 842, 12, 1056, 14, 751, 304, 267, 372, 3651, 3657, 51, 63, 4609, 63, 15704, 63, 9059, 339, 1827, 275, 1056, 14, 2970, 14, 362, 360, 81, 297, 488, 9, 272, 2929, 63, 4273, 275, 1056, 14, 2970, 14, 362, 360, 2384, 297, 488, 9, 339, 3906, 275, 20220, 6694, 8, 842, 29, 842, 12, 490, 1369, 534, 4737, 4843, 402, 450, 83, 7, 450, 1402, 9, 339, 340, 1056, 14, 751, 14, 374, 63, 12177, 837, 267, 3906, 14, 751, 275, 1056, 14, 751, 272, 3906, 14, 2117, 342, 339, 5316, 63, 4737, 63, 3790, 14, 5814, 8, 2423, 14, 2051, 12, 1402, 12, 1827, 12, 2929, 63, 4273, 9, 339, 372, 791, 928, 63, 1205, 356, 283, 3593, 297, 283, 2423, 63, 344, 356, 3906, 14, 2051, 93, 421, 199, 318, 1104, 63, 3790, 8, 1069, 12, 1256, 12, 3906, 63, 344, 304, 339, 3906, 275, 664, 63, 785, 63, 269, 63, 5188, 8, 11399, 6694, 12, 3803, 29, 2423, 63, 344, 9, 339, 327, 340, 282, 3906, 965, 282, 922, 12, 652, 4910, 314, 922, 1471, 272, 327, 506, 15082, 880, 1454, 314, 3906, 922, 883, 272, 327, 8044, 314, 4843, 272, 340, 3906, 14, 751, 436, 3906, 14, 751, 1137, 1056, 14, 751, 26, 267, 372, 791, 1205, 356, 283, 3170, 297, 355, 283, 1188, 356, 283, 6694, 440, 11023, 972, 701, 922, 297, 355, 283, 633, 356, 488, 93, 339, 587, 26, 267, 372, 791, 1205, 356, 20220, 6694, 14, 6305, 63, 31271, 59, 2423, 14, 1205, 467, 355, 283, 1188, 356, 20220, 6694, 14, 6305, 63, 16236, 59, 2423, 14, 1205, 467, 355, 283, 633, 356, 3906, 14, 362, 63, 633, 63, 692, 63, 2179, 12737, 421, 199, 5037, 63, 3790, 63, 6520, 275, 886, 8, 272, 2022, 63, 1246, 63, 1250, 12, 272, 1256, 63, 1069, 12, 272, 5074, 63, 4445, 360, 20775, 659, 272, 5386, 63, 3790, 9, 199, 199, 1074, 63, 3790, 63, 6520, 275, 886, 8, 272, 2022, 63, 1246, 63, 1250, 12, 272, 1256, 63, 1069, 12, 272, 1104, 63, 3790, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 504, 636, 2443, 363, 492, 4629, 199, 199, 504, 1639, 14, 1014, 492, 4760, 5188, 199, 504, 1639, 14, 17469, 492, 664, 63, 785, 63, 269, 63, 5188, 199, 199, 504, 6527, 492, 5316, 63, 4737, 63, 3790, 12, 5316, 63, 3707, 63, 3790, 199, 199, 504, 1639, 63, 1346, 5891, 14, 1208, 492, 24774, 465, 886, 199, 504, 1639, 63, 1346, 5891, 14, 11582, 492, 2022, 63, 1246, 63, 1250, 199, 199, 504, 3123, 1130, 14, 1974, 492, 664, 63, 4737, 63, 1310, 12, 664, 63, 1001, 63, 1310, 199, 504, 3123, 1130, 14, 11582, 492, 1256, 63, 1069, 12, 5074, 63, 4445, 199, 199, 504, 1437, 3968, 492, 3651, 3657, 51, 63, 4609, 63, 15704, 63, 9059, 199, 504, 1437, 3968, 14, 773, 492, 4843, 63, 3827, 63, 509, 199, 504, 1437, 3968, 14, 992, 492, 20220, 6694, 199, 504, 1437, 3968, 14, 751, 492, 2218, 63, 3707, 199, 199, 26634, 381, 199, 3, 24248, 22609, 199, 26634, 381, 199, 3, 199, 3, 3520, 787, 12139, 6858, 626, 787, 1202, 701, 314, 3261, 370, 5647, 199, 3, 642, 666, 370, 5957, 8500, 14, 2985, 787, 440, 1202, 701, 314, 3330, 199, 3, 1890, 334, 3596, 9, 503, 314, 15516, 1145, 14, 16711, 12, 2985, 1077, 440, 199, 3, 506, 1202, 12, 2952, 24248, 22609, 787, 282, 7918, 590, 330, 300, 848, 199, 3, 641, 314, 1056, 15, 1310, 8643, 14, 199, 3, 199, 3, 3254, 26, 3957, 314, 3261, 370, 5647, 15608, 4843, 316, 14, 199, 3, 421, 199, 318, 485, 362, 63, 751, 63, 2911, 63, 589, 8, 1069, 304, 272, 372, 359, 1069, 14, 6780, 14, 362, 480, 827, 13005, 2506, 1288, 288, 1056, 14, 6780, 14, 362, 480, 827, 4685, 2506, 11323, 421, 199, 318, 4390, 63, 4737, 8, 1069, 12, 1256, 304, 272, 298, 1767, 282, 922, 7392, 24248, 590, 2, 272, 1177, 275, 664, 63, 4737, 63, 1310, 360, 3707, 14, 4737, 358, 272, 2402, 275, 485, 362, 63, 751, 63, 2911, 63, 589, 8, 1069, 9, 272, 2218, 63, 3707, 360, 4737, 297, 1177, 12, 1256, 12, 627, 2911, 9, 272, 372, 1177, 421, 199, 318, 4390, 63, 1001, 8, 1069, 12, 1256, 304, 272, 1177, 275, 664, 63, 1001, 63, 1310, 360, 751, 63, 3790, 14, 1001, 358, 272, 2402, 275, 485, 362, 63, 751, 63, 2911, 63, 589, 8, 1069, 9, 272, 2218, 63, 3707, 360, 1001, 297, 1177, 12, 1256, 12, 627, 2911, 9, 272, 372, 1177, 421, 199, 26634, 381, 199, 3, 5316, 22609, 199, 26634, 381, 199, 199, 318, 5386, 63, 3790, 63, 3707, 8, 1069, 12, 1256, 12, 666, 63, 908, 304, 272, 340, 440, 1056, 14, 751, 14, 374, 63, 12177, 837, 267, 746, 4760, 5188, 342, 339, 340, 440, 4843, 63, 3827, 63, 509, 8, 842, 12, 1056, 14, 751, 304, 267, 372, 3651, 3657, 51, 63, 4609, 63, 15704, 63, 9059, 339, 3906, 275, 20220, 6694, 14, 1462, 14, 981, 8, 267, 1256, 29, 842, 12, 267, 922, 29, 1069, 14, 751, 12, 267, 1369, 534, 751, 4843, 543, 450, 83, 1475, 7, 450, 666, 63, 908, 9, 339, 5316, 63, 3707, 63, 3790, 14, 5814, 8, 2423, 14, 2051, 12, 666, 63, 908, 9, 339, 372, 791, 928, 63, 1205, 356, 283, 3593, 297, 283, 2423, 63, 344, 356, 3906, 14, 2051, 93, 421, 199, 318, 5386, 63, 3790, 8, 1069, 12, 1256, 12, 1402, 304, 272, 340, 440, 4843, 63, 3827, 63, 509, 8, 842, 12, 1056, 14, 751, 304, 267, 372, 3651, 3657, 51, 63, 4609, 63, 15704, 63, 9059, 339, 1827, 275, 1056, 14, 2970, 14, 362, 360, 81, 297, 488, 9, 272, 2929, 63, 4273, 275, 1056, 14, 2970, 14, 362, 360, 2384, 297, 488, 9, 339, 3906, 275, 20220, 6694, 8, 842, 29, 842, 12, 490, 1369, 534, 4737, 4843, 402, 450, 83, 7, 450, 1402, 9, 339, 340, 1056, 14, 751, 14, 374, 63, 12177, 837, 267, 3906, 14, 751, 275, 1056, 14, 751, 272, 3906, 14, 2117, 342, 339, 5316, 63, 4737, 63, 3790, 14, 5814, 8, 2423, 14, 2051, 12, 1402, 12, 1827, 12, 2929, 63, 4273, 9, 339, 372, 791, 928, 63, 1205, 356, 283, 3593, 297, 283, 2423, 63, 344, 356, 3906, 14, 2051, 93, 421, 199, 318, 1104, 63, 3790, 8, 1069, 12, 1256, 12, 3906, 63, 344, 304, 339, 3906, 275, 664, 63, 785, 63, 269, 63, 5188, 8, 11399, 6694, 12, 3803, 29, 2423, 63, 344, 9, 339, 327, 340, 282, 3906, 965, 282, 922, 12, 652, 4910, 314, 922, 1471, 272, 327, 506, 15082, 880, 1454, 314, 3906, 922, 883, 272, 327, 8044, 314, 4843, 272, 340, 3906, 14, 751, 436, 3906, 14, 751, 1137, 1056, 14, 751, 26, 267, 372, 791, 1205, 356, 283, 3170, 297, 355, 283, 1188, 356, 283, 6694, 440, 11023, 972, 701, 922, 297, 355, 283, 633, 356, 488, 93, 339, 587, 26, 267, 372, 791, 1205, 356, 20220, 6694, 14, 6305, 63, 31271, 59, 2423, 14, 1205, 467, 355, 283, 1188, 356, 20220, 6694, 14, 6305, 63, 16236, 59, 2423, 14, 1205, 467, 355, 283, 633, 356, 3906, 14, 362, 63, 633, 63, 692, 63, 2179, 12737, 421, 199, 5037, 63, 3790, 63, 6520, 275, 886, 8, 272, 2022, 63, 1246, 63, 1250, 12, 272, 1256, 63, 1069, 12, 272, 5074, 63, 4445, 360, 20775, 659, 272, 5386, 63, 3790, 9, 199, 199, 1074, 63, 3790, 63, 6520, 275, 886, 8, 272, 2022, 63, 1246, 63, 1250, 12, 272, 1256, 63, 1069, 12, 272, 1104, 63, 3790, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
vwflow/raws-python
raws_json/__init__.py
1
28752
#!/usr/bin/python # -*- coding: utf-8 -*- # # This is a modified version of '__init__.py' (version 1.1.1), part of the 'atom' module # from the gdata-python-client project (http://code.google.com/p/gdata-python-client/) by Google Inc. # Copyright (C) 2006, 2007, 2008 Google Inc. # # It has been modified to support json formatted data instead of atom. # Copyright (C) 2012 rambla.eu # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.import os __author__ = 'api.jscudder (Jeffrey Scudder)' """JsonService provides CRUD ops. in line with the Atom Publishing Protocol. JsonService: Encapsulates the ability to perform insert, update and delete operations with the Atom Publishing Protocol on which GData is based. An instance can perform query, insertion, deletion, and update. HttpRequest: Function that performs a GET, POST, PUT, or DELETE HTTP request to the specified end point. An JsonService object or a subclass can be used to specify information about the request. """ import os import httplib import urllib import re import base64 import socket URL_REGEX = re.compile('http(s)?\://([\w\.-]*)(\:(\d+))?(/.*)?') class JsonService(object): """Performs Atom Publishing Protocol CRUD operations. The JsonService contains methods to perform HTTP CRUD operations. """ # Default values for members -> disabled, also works without them # port = 80 # ssl = False # If debug is True, the HTTPConnection will display debug information debug = False def __init__(self, server=None, additional_headers=None): """Creates a new JsonService client. Args: server: string (optional) The start of a URL for the server to which all operations should be directed. Example: 'www.google.com' additional_headers: dict (optional) Any additional HTTP headers which should be included with CRUD operations. """ self.server = server self.additional_headers = additional_headers or {} self.additional_headers['User-Agent'] = 'Python Google Data Client Lib' def _ProcessUrl(self, url, for_proxy=False): """Processes a passed URL. If the URL does not begin with https?, then the default value for self.server is used""" return ProcessUrl(self, url, for_proxy=for_proxy) def UseBasicAuth(self, username, password, for_proxy=False): """Sets an Authenticaiton: Basic HTTP header containing plaintext. The username and password are base64 encoded and added to an HTTP header which will be included in each request. Note that your username and password are sent in plaintext. Args: username: str password: str """ UseBasicAuth(self, username, password, for_proxy=for_proxy) def PrepareConnection(self, full_uri): """Opens a connection to the server based on the full URI. Examines the target URI and the proxy settings, which are set as environment variables, to open a connection with the server. This connection is used to make an HTTP request. Args: full_uri: str Which is the target relative (lacks protocol and host) or absolute URL to be opened. Example: 'https://www.google.com/accounts/ClientLogin' or 'base/feeds/snippets' where the server is set to www.google.com. Returns: A tuple containing the httplib.HTTPConnection and the full_uri for the request. """ return PrepareConnection(self, full_uri) # Alias the old name for the above method to preserve backwards # compatibility. _PrepareConnection = PrepareConnection # CRUD operations def Get(self, uri, extra_headers=None, url_params=None, escape_params=True): """Query the APP server with the given URI The uri is the portion of the URI after the server value (server example: 'www.google.com'). Example use: To perform a query against Google Base, set the server to 'base.google.com' and set the uri to '/base/feeds/...', where ... is your query. For example, to find snippets for all digital cameras uri should be set to: '/base/feeds/snippets?bq=digital+camera' Args: uri: string The query in the form of a URI. Example: '/base/feeds/snippets?bq=digital+camera'. extra_headers: dicty (optional) Extra HTTP headers to be included in the GET request. These headers are in addition to those stored in the client's additional_headers property. The client automatically sets the Content-Type and Authorization headers. url_params: dict (optional) Additional URL parameters to be included in the query. These are translated into query arguments in the form '&dict_key=value&...'. Example: {'max-results': '250'} becomes &max-results=250 escape_params: boolean (optional) If false, the calling code has already ensured that the query will form a valid URL (all reserved characters have been escaped). If true, this method will escape the query and any URL parameters provided. Returns: httplib.HTTPResponse The server's response to the GET request. """ extra_headers.update({'Accept': 'application/json', 'Content-Type': 'application/json'}) return HttpRequest(self, 'GET', None, uri, extra_headers=extra_headers, url_params=url_params, escape_params=escape_params) def Post(self, data, uri, extra_headers=None, url_params=None, escape_params=True, content_type='application/atom+xml'): """Insert data into an APP server at the given URI. Args: data: string, ElementTree._Element, or something with a __str__ method The XML to be sent to the uri. uri: string The location (feed) to which the data should be inserted. Example: '/base/feeds/items'. extra_headers: dict (optional) HTTP headers which are to be included. The client automatically sets the Content-Type, Authorization, and Content-Length headers. url_params: dict (optional) Additional URL parameters to be included in the URI. These are translated into query arguments in the form '&dict_key=value&...'. Example: {'max-results': '250'} becomes &max-results=250 escape_params: boolean (optional) If false, the calling code has already ensured that the query will form a valid URL (all reserved characters have been escaped). If true, this method will escape the query and any URL parameters provided. Returns: httplib.HTTPResponse Server's response to the POST request. """ extra_headers.update({'Accept': 'application/json'}) return HttpRequest(self, 'POST', data, uri, extra_headers=extra_headers, url_params=url_params, escape_params=escape_params, content_type=content_type) def Put(self, data, uri, extra_headers=None, url_params=None, escape_params=True, content_type='application/atom+xml'): """Updates an entry at the given URI. Args: data: string, ElementTree._Element, or xml_wrapper.ElementWrapper The XML containing the updated data. uri: string A URI indicating entry to which the update will be applied. Example: '/base/feeds/items/ITEM-ID' extra_headers: dict (optional) HTTP headers which are to be included. The client automatically sets the Content-Type, Authorization, and Content-Length headers. url_params: dict (optional) Additional URL parameters to be included in the URI. These are translated into query arguments in the form '&dict_key=value&...'. Example: {'max-results': '250'} becomes &max-results=250 escape_params: boolean (optional) If false, the calling code has already ensured that the query will form a valid URL (all reserved characters have been escaped). If true, this method will escape the query and any URL parameters provided. Returns: httplib.HTTPResponse Server's response to the PUT request. """ extra_headers.update({'Accept': 'application/json'}) return HttpRequest(self, 'PUT', data, uri, extra_headers=extra_headers, url_params=url_params, escape_params=escape_params, content_type=content_type) def Delete(self, uri, extra_headers=None, url_params=None, escape_params=True): """Deletes the entry at the given URI. Args: uri: string The URI of the entry to be deleted. Example: '/base/feeds/items/ITEM-ID' extra_headers: dict (optional) HTTP headers which are to be included. The client automatically sets the Content-Type and Authorization headers. url_params: dict (optional) Additional URL parameters to be included in the URI. These are translated into query arguments in the form '&dict_key=value&...'. Example: {'max-results': '250'} becomes &max-results=250 escape_params: boolean (optional) If false, the calling code has already ensured that the query will form a valid URL (all reserved characters have been escaped). If true, this method will escape the query and any URL parameters provided. Returns: httplib.HTTPResponse Server's response to the DELETE request. """ return HttpRequest(self, 'DELETE', None, uri, extra_headers=extra_headers, url_params=url_params, escape_params=escape_params) def Head(self, uri, extra_headers=None, url_params=None, escape_params=True): """Send a HEAD request to the APP server with the given URI The uri is the portion of the URI after the server value (server example: 'www.google.com'). Example use: To perform a query against Google Base, set the server to 'base.google.com' and set the uri to '/base/feeds/...', where ... is your query. For example, to find snippets for all digital cameras uri should be set to: '/base/feeds/snippets?bq=digital+camera' Args: uri: string The query in the form of a URI. Example: '/base/feeds/snippets?bq=digital+camera'. extra_headers: dicty (optional) Extra HTTP headers to be included in the GET request. These headers are in addition to those stored in the client's additional_headers property. The client automatically sets the Content-Type and Authorization headers. url_params: dict (optional) Additional URL parameters to be included in the query. These are translated into query arguments in the form '&dict_key=value&...'. Example: {'max-results': '250'} becomes &max-results=250 escape_params: boolean (optional) If false, the calling code has already ensured that the query will form a valid URL (all reserved characters have been escaped). If true, this method will escape the query and any URL parameters provided. Returns: httplib.HTTPResponse The server's response to the GET request. """ return HttpRequest(self, 'HEAD', None, uri, extra_headers=extra_headers, url_params=url_params, escape_params=escape_params) def HttpRequest(service, operation, data, uri, extra_headers=None, url_params=None, escape_params=True, content_type='application/atom+xml'): """Performs an HTTP call to the server, supports GET, POST, PUT, and DELETE. Usage example, perform and HTTP GET on http://www.google.com/: import atom.service client = atom.service.JsonService() http_response = client.Get('http://www.google.com/') or you could set the client.server to 'www.google.com' and use the following: client.server = 'www.google.com' http_response = client.Get('/') Args: service: atom.JsonService object which contains some of the parameters needed to make the request. The following members are used to construct the HTTP call: server (str), additional_headers (dict), port (int), and ssl (bool). operation: str The HTTP operation to be performed. This is usually one of 'GET', 'POST', 'PUT', or 'DELETE' data: ElementTree, filestream, list of parts, or other object which can be converted to a string. Should be set to None when performing a GET or PUT. If data is a file-like object which can be read, this method will read a chunk of 100K bytes at a time and send them. If the data is a list of parts to be sent, each part will be evaluated and sent. uri: The beginning of the URL to which the request should be sent. Examples: '/', '/base/feeds/snippets', '/m8/feeds/contacts/default/base' extra_headers: dict of strings. HTTP headers which should be sent in the request. These headers are in addition to those stored in service.additional_headers. url_params: dict of strings. Key value pairs to be added to the URL as URL parameters. For example {'foo':'bar', 'test':'param'} will become ?foo=bar&test=param. escape_params: bool default True. If true, the keys and values in url_params will be URL escaped when the form is constructed (Special characters converted to %XX form.) content_type: str The MIME type for the data being sent. Defaults to 'application/atom+xml', this is only used if data is set. """ full_uri = BuildUri(uri, url_params, escape_params) (connection, full_uri) = PrepareConnection(service, full_uri) if extra_headers is None: extra_headers = {} # Turn on debug mode if the debug member is set. if service.debug: connection.debuglevel = 1 connection.putrequest(operation, full_uri) # If the list of headers does not include a Content-Length, attempt to # calculate it based on the data object. if (data and not service.additional_headers.has_key('Content-Length') and not extra_headers.has_key('Content-Length')): content_length = __CalculateDataLength(data) if content_length: extra_headers['Content-Length'] = str(content_length) else: extra_headers['Content-Length'] = "0" if content_type: extra_headers['Content-Type'] = content_type # Send the HTTP headers. if isinstance(service.additional_headers, dict): for header in service.additional_headers: connection.putheader(header, service.additional_headers[header]) if isinstance(extra_headers, dict): for header in extra_headers: connection.putheader(header, extra_headers[header]) connection.endheaders() # If there is data, send it in the request. if data: if isinstance(data, list): for data_part in data: __SendDataPart(data_part, connection) else: __SendDataPart(data, connection) # Return the HTTP Response from the server. return connection.getresponse() def __SendDataPart(data, connection): if isinstance(data, str): connection.send(data) return elif isinstance(data, unicode): # unicode string must be converted into 8-bit string version (otherwise httplib will raise UnicodeDecodeError) connection.send(data.encode('utf-8')) return # NEXT SECTION COMMENTED OUT, replace by json.decode() if desired # elif ElementTree.iselement(data): # connection.send(ElementTree.tostring(data)) # return # Check to see if data is a file-like object that has a read method. elif hasattr(data, 'read'): # Read the file and send it a chunk at a time. while 1: binarydata = data.read(100000) if binarydata == '': break connection.send(binarydata) return else: # The data object was not a file. # Try to convert to a string and send the data. connection.send(str(data)) return def __CalculateDataLength(data): """Attempts to determine the length of the data to send. This method will respond with a length only if the data is a string or and ElementTree element. Args: data: object If this is not a string or ElementTree element this funtion will return None. """ if isinstance(data, str): return len(data) elif isinstance(data, unicode): return len(data.decode('utf-8')) elif isinstance(data, list): return None # elif ElementTree.iselement(data): # return len(ElementTree.tostring(data)) elif hasattr(data, 'read'): # If this is a file-like object, don't try to guess the length. return None else: return len(str(data)) def PrepareConnection(service, full_uri): """Opens a connection to the server based on the full URI. Examines the target URI and the proxy settings, which are set as environment variables, to open a connection with the server. This connection is used to make an HTTP request. Args: service: atom.JsonService or a subclass. It must have a server string which represents the server host to which the request should be made. It may also have a dictionary of additional_headers to send in the HTTP request. full_uri: str Which is the target relative (lacks protocol and host) or absolute URL to be opened. Example: 'https://www.google.com/accounts/ClientLogin' or 'base/feeds/snippets' where the server is set to www.google.com. Returns: A tuple containing the httplib.HTTPConnection and the full_uri for the request. """ (server, port, ssl, partial_uri) = ProcessUrl(service, full_uri) if ssl: # destination is https proxy = os.environ.get('https_proxy') if proxy: (p_server, p_port, p_ssl, p_uri) = ProcessUrl(service, proxy, True) proxy_username = os.environ.get('proxy-username') if not proxy_username: proxy_username = os.environ.get('proxy_username') proxy_password = os.environ.get('proxy-password') if not proxy_password: proxy_password = os.environ.get('proxy_password') if proxy_username: user_auth = base64.encodestring('%s:%s' % (proxy_username, proxy_password)) proxy_authorization = ('Proxy-authorization: Basic %s\r\n' % ( user_auth.strip())) else: proxy_authorization = '' proxy_connect = 'CONNECT %s:%s HTTP/1.0\r\n' % (server, port) user_agent = 'User-Agent: %s\r\n' % ( service.additional_headers['User-Agent']) proxy_pieces = (proxy_connect + proxy_authorization + user_agent + '\r\n') #now connect, very simple recv and error checking p_sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) p_sock.connect((p_server,p_port)) p_sock.sendall(proxy_pieces) response = '' # Wait for the full response. while response.find("\r\n\r\n") == -1: response += p_sock.recv(8192) p_status=response.split()[1] if p_status!=str(200): raise 'Error status=',str(p_status) # Trivial setup for ssl socket. ssl = socket.ssl(p_sock, None, None) fake_sock = httplib.FakeSocket(p_sock, ssl) # Initalize httplib and replace with the proxy socket. connection = httplib.HTTPConnection(server) connection.sock=fake_sock full_uri = partial_uri else: connection = httplib.HTTPSConnection(server, port) full_uri = partial_uri else: # destination is http proxy = os.environ.get('http_proxy') if proxy: (p_server, p_port, p_ssl, p_uri) = ProcessUrl(service.server, proxy, True) proxy_username = os.environ.get('proxy-username') if not proxy_username: proxy_username = os.environ.get('proxy_username') proxy_password = os.environ.get('proxy-password') if not proxy_password: proxy_password = os.environ.get('proxy_password') if proxy_username: UseBasicAuth(service, proxy_username, proxy_password, True) connection = httplib.HTTPConnection(p_server, p_port) if not full_uri.startswith("http://"): if full_uri.startswith("/"): full_uri = "http://%s%s" % (service.server, full_uri) else: full_uri = "http://%s/%s" % (service.server, full_uri) else: connection = httplib.HTTPConnection(server, port) full_uri = partial_uri return (connection, full_uri) def UseBasicAuth(service, username, password, for_proxy=False): """Sets an Authenticaiton: Basic HTTP header containing plaintext. The username and password are base64 encoded and added to an HTTP header which will be included in each request. Note that your username and password are sent in plaintext. The auth header is added to the additional_headers dictionary in the service object. Args: service: atom.JsonService or a subclass which has an additional_headers dict as a member. username: str password: str """ base_64_string = base64.encodestring('%s:%s' % (username, password)) base_64_string = base_64_string.strip() if for_proxy: header_name = 'Proxy-Authorization' else: header_name = 'Authorization' service.additional_headers[header_name] = 'Basic %s' % (base_64_string,) def ProcessUrl(service, url, for_proxy=False): """Processes a passed URL. If the URL does not begin with https?, then the default value for server is used""" server = None port = 80 ssl = False if hasattr(service, 'server'): server = service.server else: server = service if not for_proxy: if hasattr(service, 'port'): port = service.port if hasattr(service, 'ssl'): ssl = service.ssl uri = url m = URL_REGEX.match(url) if m is None: return (server, port, ssl, uri) else: if m.group(1) is not None: port = 443 ssl = True if m.group(3) is None: server = m.group(2) else: server = m.group(2) port = int(m.group(4)) if m.group(5) is not None: uri = m.group(5) else: uri = '/' return (server, port, ssl, uri) def DictionaryToParamList(url_parameters, escape_params=True): """Convert a dictionary of URL arguments into a URL parameter string. Args: url_parameters: The dictionaty of key-value pairs which will be converted into URL parameters. For example, {'dry-run': 'true', 'foo': 'bar'} will become ['dry-run=true', 'foo=bar']. Returns: A list which contains a string for each key-value pair. The strings are ready to be incorporated into a URL by using '&'.join([] + parameter_list) """ # Choose which function to use when modifying the query and parameters. # Use quote_plus when escape_params is true. transform_op = [str, urllib.quote_plus][bool(escape_params)] # Create a list of tuples containing the escaped version of the # parameter-value pairs. parameter_tuples = [(transform_op(param), transform_op(value)) for param, value in (url_parameters or {}).items()] # Turn parameter-value tuples into a list of strings in the form # 'PARAMETER=VALUE'. return ['='.join(x) for x in parameter_tuples] def BuildUri(uri, url_params=None, escape_params=True): """Converts a uri string and a collection of parameters into a URI. Args: uri: string url_params: dict (optional) escape_params: boolean (optional) uri: string The start of the desired URI. This string can alrady contain URL parameters. Examples: '/base/feeds/snippets', '/base/feeds/snippets?bq=digital+camera' url_parameters: dict (optional) Additional URL parameters to be included in the query. These are translated into query arguments in the form '&dict_key=value&...'. Example: {'max-results': '250'} becomes &max-results=250 escape_params: boolean (optional) If false, the calling code has already ensured that the query will form a valid URL (all reserved characters have been escaped). If true, this method will escape the query and any URL parameters provided. Returns: string The URI consisting of the escaped URL parameters appended to the initial uri string. """ # Prepare URL parameters for inclusion into the GET request. parameter_list = DictionaryToParamList(url_params, escape_params) # Append the URL parameters to the URL. if parameter_list: if uri.find('?') != -1: # If there are already URL parameters in the uri string, add the # parameters after a new & character. full_uri = '&'.join([uri] + parameter_list) else: # The uri string did not have any URL parameters (no ? character) # so put a ? between the uri and URL parameters. full_uri = '%s%s' % (uri, '?%s' % ('&'.join([] + parameter_list))) else: full_uri = uri return full_uri class MediaSource(object): """Raws Entries can refer to media sources, so this class provides a place to store references to these objects along with some metadata. """ def __init__(self, file_handle=None, content_type=None, content_length=None, file_path=None, file_name=None, svr_filename = None): """Creates an object of type MediaSource. Args: file_handle: A file handle pointing to the file to be encapsulated in the MediaSource content_type: string The MIME type of the file. Required if a file_handle is given. content_length: int The size of the file. Required if a file_handle is given. file_path: string (optional) A full path name to the file. Used in place of a file_handle. file_name: string The name of the file without any path information. Required if a file_handle is given. """ self.file_handle = file_handle self.content_type = content_type self.content_length = content_length self.file_name = file_name self.svr_filename = svr_filename self.file_path = file_path if (file_handle is None and file_path is not None): self.setFile(file_path, content_type) if not self.svr_filename: self.svr_filename = self.file_name def setFile(self, file_name, content_type): """A helper function which can create a file handle from a given filename and set the content type and length all at once. Args: file_name: string The path and file name to the file containing the media content_type: string A MIME type representing the type of the media """ self.file_handle = open(file_name, 'rb') self.content_type = content_type self.content_length = os.path.getsize(file_name) self.file_name = os.path.basename(file_name) def writeFile(self, file_path): # can not write if no path and handle if not file_path or not self.file_handle: return False self.file_path = file_path fd = open(file_path, 'wb') fd.write(self.file_handle.read()) fd.close() return True
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 961, 365, 282, 6042, 1015, 402, 2560, 826, 4343, 647, 7, 334, 1023, 413, 14, 17, 14, 17, 395, 1777, 402, 314, 283, 4188, 7, 859, 199, 3, 221, 687, 314, 11006, 13, 1548, 13, 1258, 2199, 334, 1014, 921, 600, 14, 3098, 14, 957, 15, 80, 15, 15275, 13, 1548, 13, 1258, 24793, 701, 4475, 3277, 14, 199, 3, 1898, 334, 35, 9, 8315, 12, 10219, 12, 9079, 4475, 3277, 14, 199, 3, 199, 3, 2779, 965, 2757, 6042, 370, 2291, 2022, 7871, 666, 3140, 402, 6222, 14, 199, 3, 1898, 334, 35, 9, 6029, 660, 887, 416, 14, 16913, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 646, 747, 199, 363, 2502, 363, 275, 283, 1246, 14, 74, 551, 1181, 424, 334, 42, 3609, 17885, 13916, 1181, 424, 3171, 199, 199, 624, 9653, 3167, 6571, 17101, 3383, 4156, 14, 315, 1004, 543, 314, 18840, 19952, 316, 11557, 14, 819, 14587, 3167, 26, 3447, 12029, 15409, 314, 21255, 370, 5147, 5518, 12, 1678, 436, 3145, 2049, 5331, 543, 314, 18840, 19952, 316, 11557, 641, 1314, 598, 1451, 365, 2049, 4079, 14, 1626, 1256, 883, 5147, 1827, 12, 22470, 12, 14068, 12, 436, 2049, 1678, 14, 819, 20730, 26, 6801, 626, 18628, 282, 9576, 12, 8761, 12, 18337, 12, 503, 15137, 3101, 1056, 2126, 370, 314, 2013, 1284, 2376, 14, 1626, 14587, 3167, 909, 503, 282, 5516, 883, 506, 2126, 1202, 370, 4165, 2556, 3595, 314, 1056, 14, 199, 624, 199, 646, 747, 199, 646, 8809, 199, 646, 4011, 199, 646, 295, 199, 646, 1300, 772, 199, 646, 2838, 199, 199, 2632, 63, 10710, 275, 295, 14, 2014, 360, 1014, 8, 83, 5547, 60, 921, 16510, 87, 4537, 13, 3672, 10127, 26, 2961, 68, 11, 22119, 29478, 2795, 5547, 358, 199, 199, 533, 14587, 3167, 8, 785, 304, 523, 408, 2623, 3351, 18840, 19952, 316, 11557, 17101, 3383, 5331, 14, 12244, 710, 14587, 3167, 3509, 3102, 370, 5147, 3101, 17101, 3383, 5331, 14, 16421, 408, 819, 327, 3758, 1338, 367, 7556, 1035, 6980, 12, 2597, 5419, 1928, 3062, 523, 327, 1844, 275, 5939, 523, 327, 6149, 275, 756, 12244, 327, 982, 3105, 365, 715, 12, 314, 3101, 3225, 911, 2929, 3105, 2556, 523, 3105, 275, 756, 819, 347, 636, 826, 721, 277, 12, 1654, 29, 403, 12, 4722, 63, 2139, 29, 403, 304, 272, 408, 10607, 282, 892, 14587, 3167, 1890, 14, 2286, 3033, 26, 489, 1654, 26, 1059, 334, 4144, 9, 710, 1343, 402, 282, 2851, 367, 314, 1654, 1598, 370, 1314, 1006, 5331, 1077, 506, 23667, 14, 5679, 26, 221, 1598, 283, 1544, 14, 3098, 14, 957, 7, 489, 4722, 63, 2139, 26, 1211, 334, 4144, 9, 6184, 4722, 3101, 2323, 1314, 2079, 1077, 506, 5120, 543, 17101, 3383, 5331, 14, 272, 408, 339, 291, 14, 1000, 275, 1654, 272, 291, 14, 8460, 63, 2139, 275, 4722, 63, 2139, 503, 1052, 339, 291, 14, 8460, 63, 2139, 459, 1899, 13, 7788, 418, 275, 283, 4718, 4475, 3918, 6810, 8003, 7, 819, 347, 485, 3498, 6417, 8, 277, 12, 1166, 12, 367, 63, 3280, 29, 797, 304, 272, 408, 25857, 282, 3032, 2851, 14, 221, 982, 314, 2851, 1630, 440, 5386, 543, 4178, 22556, 2066, 272, 314, 849, 574, 367, 291, 14, 1000, 365, 1202, 624, 272, 372, 7132, 6417, 8, 277, 12, 1166, 12, 367, 63, 3280, 29, 509, 63, 3280, 9, 819, 347, 3645, 6845, 2817, 8, 277, 12, 3434, 12, 2505, 12, 367, 63, 3280, 29, 797, 304, 272, 408, 9899, 376, 3590, 287, 15922, 390, 265, 26, 10082, 3101, 1406, 3035, 18577, 14, 2286, 710, 3434, 436, 2505, 787, 1300, 772, 5737, 436, 3483, 370, 376, 3101, 1406, 272, 1314, 911, 506, 5120, 315, 1924, 1056, 14, 3390, 626, 2195, 3434, 436, 5591, 2505, 787, 4847, 315, 18577, 14, 339, 3033, 26, 489, 3434, 26, 620, 489, 2505, 26, 620, 272, 408, 272, 3645, 6845, 2817, 8, 277, 12, 3434, 12, 2505, 12, 367, 63, 3280, 29, 509, 63, 3280, 9, 819, 347, 17008, 3225, 8, 277, 12, 2615, 63, 2302, 304, 272, 408, 4299, 83, 282, 1950, 370, 314, 1654, 4079, 641, 314, 2615, 9022, 14, 339, 1316, 455, 3746, 314, 1347, 9022, 436, 314, 4566, 2202, 12, 1314, 787, 663, 465, 5591, 3734, 2860, 12, 370, 1551, 282, 1950, 543, 314, 1654, 14, 961, 5591, 1950, 365, 1202, 370, 1852, 376, 3101, 1056, 14, 339, 3033, 26, 489, 2615, 63, 2302, 26, 620, 26058, 365, 314, 1347, 3847, 334, 5143, 83, 4113, 436, 1591, 9, 503, 489, 3679, 2851, 370, 506, 12123, 14, 5679, 26, 489, 283, 2859, 921, 1544, 14, 3098, 14, 957, 15, 8370, 15, 3041, 8880, 7, 503, 489, 283, 1095, 15, 11522, 15, 32566, 7, 2382, 314, 1654, 365, 663, 370, 20732, 14, 3098, 14, 957, 14, 339, 1803, 26, 489, 437, 2008, 3035, 314, 8809, 14, 19114, 436, 314, 2615, 63, 2302, 367, 314, 489, 1056, 14, 272, 408, 272, 372, 17008, 3225, 8, 277, 12, 2615, 63, 2302, 9, 259, 819, 327, 24777, 314, 2269, 536, 367, 314, 3432, 1083, 370, 11211, 8552, 16421, 327, 7163, 14, 523, 485, 22281, 3225, 275, 17008, 3225, 523, 523, 327, 17101, 3383, 5331, 523, 347, 2372, 8, 277, 12, 5108, 12, 2402, 63, 2139, 29, 403, 12, 1166, 63, 1162, 29, 403, 12, 4772, 63, 1162, 29, 549, 304, 272, 408, 3227 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 961, 365, 282, 6042, 1015, 402, 2560, 826, 4343, 647, 7, 334, 1023, 413, 14, 17, 14, 17, 395, 1777, 402, 314, 283, 4188, 7, 859, 199, 3, 221, 687, 314, 11006, 13, 1548, 13, 1258, 2199, 334, 1014, 921, 600, 14, 3098, 14, 957, 15, 80, 15, 15275, 13, 1548, 13, 1258, 24793, 701, 4475, 3277, 14, 199, 3, 1898, 334, 35, 9, 8315, 12, 10219, 12, 9079, 4475, 3277, 14, 199, 3, 199, 3, 2779, 965, 2757, 6042, 370, 2291, 2022, 7871, 666, 3140, 402, 6222, 14, 199, 3, 1898, 334, 35, 9, 6029, 660, 887, 416, 14, 16913, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 646, 747, 199, 363, 2502, 363, 275, 283, 1246, 14, 74, 551, 1181, 424, 334, 42, 3609, 17885, 13916, 1181, 424, 3171, 199, 199, 624, 9653, 3167, 6571, 17101, 3383, 4156, 14, 315, 1004, 543, 314, 18840, 19952, 316, 11557, 14, 819, 14587, 3167, 26, 3447, 12029, 15409, 314, 21255, 370, 5147, 5518, 12, 1678, 436, 3145, 2049, 5331, 543, 314, 18840, 19952, 316, 11557, 641, 1314, 598, 1451, 365, 2049, 4079, 14, 1626, 1256, 883, 5147, 1827, 12, 22470, 12, 14068, 12, 436, 2049, 1678, 14, 819, 20730, 26, 6801, 626, 18628, 282, 9576, 12, 8761, 12, 18337, 12, 503, 15137, 3101, 1056, 2126, 370, 314, 2013, 1284, 2376, 14, 1626, 14587, 3167, 909, 503, 282, 5516, 883, 506, 2126, 1202, 370, 4165, 2556, 3595, 314, 1056, 14, 199, 624, 199, 646, 747, 199, 646, 8809, 199, 646, 4011, 199, 646, 295, 199, 646, 1300, 772, 199, 646, 2838, 199, 199, 2632, 63, 10710, 275, 295, 14, 2014, 360, 1014, 8, 83, 5547, 60, 921, 16510, 87, 4537, 13, 3672, 10127, 26, 2961, 68, 11, 22119, 29478, 2795, 5547, 358, 199, 199, 533, 14587, 3167, 8, 785, 304, 523, 408, 2623, 3351, 18840, 19952, 316, 11557, 17101, 3383, 5331, 14, 12244, 710, 14587, 3167, 3509, 3102, 370, 5147, 3101, 17101, 3383, 5331, 14, 16421, 408, 819, 327, 3758, 1338, 367, 7556, 1035, 6980, 12, 2597, 5419, 1928, 3062, 523, 327, 1844, 275, 5939, 523, 327, 6149, 275, 756, 12244, 327, 982, 3105, 365, 715, 12, 314, 3101, 3225, 911, 2929, 3105, 2556, 523, 3105, 275, 756, 819, 347, 636, 826, 721, 277, 12, 1654, 29, 403, 12, 4722, 63, 2139, 29, 403, 304, 272, 408, 10607, 282, 892, 14587, 3167, 1890, 14, 2286, 3033, 26, 489, 1654, 26, 1059, 334, 4144, 9, 710, 1343, 402, 282, 2851, 367, 314, 1654, 1598, 370, 1314, 1006, 5331, 1077, 506, 23667, 14, 5679, 26, 221, 1598, 283, 1544, 14, 3098, 14, 957, 7, 489, 4722, 63, 2139, 26, 1211, 334, 4144, 9, 6184, 4722, 3101, 2323, 1314, 2079, 1077, 506, 5120, 543, 17101, 3383, 5331, 14, 272, 408, 339, 291, 14, 1000, 275, 1654, 272, 291, 14, 8460, 63, 2139, 275, 4722, 63, 2139, 503, 1052, 339, 291, 14, 8460, 63, 2139, 459, 1899, 13, 7788, 418, 275, 283, 4718, 4475, 3918, 6810, 8003, 7, 819, 347, 485, 3498, 6417, 8, 277, 12, 1166, 12, 367, 63, 3280, 29, 797, 304, 272, 408, 25857, 282, 3032, 2851, 14, 221, 982, 314, 2851, 1630, 440, 5386, 543, 4178, 22556, 2066, 272, 314, 849, 574, 367, 291, 14, 1000, 365, 1202, 624, 272, 372, 7132, 6417, 8, 277, 12, 1166, 12, 367, 63, 3280, 29, 509, 63, 3280, 9, 819, 347, 3645, 6845, 2817, 8, 277, 12, 3434, 12, 2505, 12, 367, 63, 3280, 29, 797, 304, 272, 408, 9899, 376, 3590, 287, 15922, 390, 265, 26, 10082, 3101, 1406, 3035, 18577, 14, 2286, 710, 3434, 436, 2505, 787, 1300, 772, 5737, 436, 3483, 370, 376, 3101, 1406, 272, 1314, 911, 506, 5120, 315, 1924, 1056, 14, 3390, 626, 2195, 3434, 436, 5591, 2505, 787, 4847, 315, 18577, 14, 339, 3033, 26, 489, 3434, 26, 620, 489, 2505, 26, 620, 272, 408, 272, 3645, 6845, 2817, 8, 277, 12, 3434, 12, 2505, 12, 367, 63, 3280, 29, 509, 63, 3280, 9, 819, 347, 17008, 3225, 8, 277, 12, 2615, 63, 2302, 304, 272, 408, 4299, 83, 282, 1950, 370, 314, 1654, 4079, 641, 314, 2615, 9022, 14, 339, 1316, 455, 3746, 314, 1347, 9022, 436, 314, 4566, 2202, 12, 1314, 787, 663, 465, 5591, 3734, 2860, 12, 370, 1551, 282, 1950, 543, 314, 1654, 14, 961, 5591, 1950, 365, 1202, 370, 1852, 376, 3101, 1056, 14, 339, 3033, 26, 489, 2615, 63, 2302, 26, 620, 26058, 365, 314, 1347, 3847, 334, 5143, 83, 4113, 436, 1591, 9, 503, 489, 3679, 2851, 370, 506, 12123, 14, 5679, 26, 489, 283, 2859, 921, 1544, 14, 3098, 14, 957, 15, 8370, 15, 3041, 8880, 7, 503, 489, 283, 1095, 15, 11522, 15, 32566, 7, 2382, 314, 1654, 365, 663, 370, 20732, 14, 3098, 14, 957, 14, 339, 1803, 26, 489, 437, 2008, 3035, 314, 8809, 14, 19114, 436, 314, 2615, 63, 2302, 367, 314, 489, 1056, 14, 272, 408, 272, 372, 17008, 3225, 8, 277, 12, 2615, 63, 2302, 9, 259, 819, 327, 24777, 314, 2269, 536, 367, 314, 3432, 1083, 370, 11211, 8552, 16421, 327, 7163, 14, 523, 485, 22281, 3225, 275, 17008, 3225, 523, 523, 327, 17101, 3383, 5331, 523, 347, 2372, 8, 277, 12, 5108, 12, 2402, 63, 2139, 29, 403, 12, 1166, 63, 1162, 29, 403, 12, 4772, 63, 1162, 29, 549, 304, 272, 408, 3227, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
quaquel/EMAworkbench
test/test_em_framework/test_outcomes.py
1
5451
''' Created on Jul 28, 2015 .. codeauthor:: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl> ''' from __future__ import (division, print_function, absolute_import, unicode_literals) import unittest import unittest.mock as mock from ema_workbench.em_framework.outcomes import ScalarOutcome,\ TimeSeriesOutcome class TestScalarOutcome(unittest.TestCase): outcome_class = ScalarOutcome outcome_klass = "ScalarOutcome" def test_outcome(self): name = 'test' outcome = self.outcome_class(name) self.assertEqual(outcome.name, name) self.assertEqual(outcome.variable_name, [name]) self.assertIsNone(outcome.function) self.assertEqual(repr(outcome), self.outcome_klass+'(\'test\')') name = 'test' var_name = 'something else' outcome = self.outcome_class(name, variable_name=var_name) self.assertEqual(outcome.name, name) self.assertEqual(outcome.variable_name, [var_name]) self.assertIsNone(outcome.function) name = 'test' var_name = 'something else' function = mock.Mock() outcome = self.outcome_class(name, variable_name=var_name, function=function) self.assertEqual(outcome.name, name) self.assertEqual(outcome.variable_name, [var_name]) self.assertIsNotNone(outcome.function) with self.assertRaises(ValueError): name = 'test' var_name = 'something else' function = 'not a function' outcome = self.outcome_class(name, variable_name=var_name, function=function) with self.assertRaises(ValueError): name = 'test' var_name = 1 outcome = self.outcome_class(name, variable_name=var_name, function=function) with self.assertRaises(ValueError): name = 'test' var_name = ['a variable', 1] outcome = self.outcome_class(name, variable_name=var_name, function=function) name = 'test' var_name = 'something else' function = lambda x: x outcome1 = self.outcome_class(name, variable_name=var_name, function=function) outcome2 = self.outcome_class(name, variable_name=var_name, function=function) self.assertEqual(outcome1, outcome2) def test_process(self): name = 'test' outcome = self.outcome_class(name) outputs = [1] self.assertEqual(outcome.process(outputs), outputs[0]) name = 'test' function = mock.Mock() function.return_value = 2 outcome = self.outcome_class(name, function=function) outputs = [1] self.assertEqual(outcome.process(outputs), 2) function.assert_called_once() name = 'test' function = mock.Mock() function.return_value = 2 variable_name = ['a', 'b'] outcome = self.outcome_class(name, function=function, variable_name=variable_name) outputs = [1, 2] self.assertEqual(outcome.process(outputs), 2) function.assert_called_once() function.assert_called_with(1, 2) with self.assertRaises(ValueError): name = 'test' function = mock.Mock() function.return_value = 2 variable_name = ['a', 'b'] outcome = self.outcome_class(name, function=function, variable_name=variable_name) outcome.process([1]) class TestTimeSeriesOutcome(TestScalarOutcome): outcome_class = TimeSeriesOutcome outcome_klass = "TimeSeriesOutcome" def test_process(self): name = 'test' outcome = self.outcome_class(name) outputs = [[1]] self.assertEqual(outcome.process(outputs), outputs[0]) name = 'test' function = mock.Mock() function.return_value = [2] outcome = self.outcome_class(name, function=function) outputs = [1] self.assertEqual(outcome.process(outputs), [2]) function.assert_called_once() name = 'test' function = mock.Mock() function.return_value = [2] variable_name = ['a', 'b'] outcome = self.outcome_class(name, function=function, variable_name=variable_name) outputs = [1, 2] self.assertEqual(outcome.process(outputs), [2]) function.assert_called_once() function.assert_called_with(1, 2) with self.assertRaises(ValueError): name = 'test' function = mock.Mock() function.return_value = [2] variable_name = ['a', 'b'] outcome = self.outcome_class(name, function=function, variable_name=variable_name) outcome.process([1]) if __name__ == "__main__": unittest.main()
bsd-3-clause
[ 2344, 199, 10502, 641, 1603, 348, 7294, 12, 6900, 199, 199, 703, 1233, 2502, 447, 1335, 21557, 758, 16247, 352, 665, 74, 14, 72, 14, 75, 758, 16247, 352, 334, 292, 9, 307, 3786, 32462, 334, 3287, 9, 12992, 30, 199, 2344, 199, 504, 636, 2443, 363, 492, 334, 25035, 12, 870, 63, 1593, 12, 3679, 63, 646, 12, 717, 2649, 63, 5955, 9, 199, 199, 646, 2882, 199, 646, 2882, 14, 1805, 465, 1683, 199, 199, 504, 325, 391, 63, 800, 16571, 14, 5633, 63, 4857, 14, 17502, 83, 492, 24289, 2204, 4352, 4202, 272, 4703, 9641, 2204, 4352, 199, 199, 533, 1379, 13090, 2204, 4352, 8, 2796, 14, 1746, 304, 272, 15955, 63, 533, 275, 24289, 2204, 4352, 272, 15955, 63, 11645, 275, 298, 13090, 2204, 4352, 2, 2286, 347, 511, 63, 17502, 8, 277, 304, 267, 536, 275, 283, 396, 7, 267, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 9, 2728, 291, 14, 629, 8, 17502, 14, 354, 12, 536, 9, 267, 291, 14, 629, 8, 17502, 14, 1975, 63, 354, 12, 359, 354, 566, 267, 291, 14, 7702, 8, 17502, 14, 1593, 9, 267, 291, 14, 629, 8, 2722, 8, 17502, 395, 291, 14, 17502, 63, 11645, 4786, 30338, 396, 60, 358, 358, 398, 536, 275, 283, 396, 7, 267, 2729, 63, 354, 275, 283, 10297, 587, 7, 267, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 1750, 63, 354, 29, 1391, 63, 354, 9, 2728, 291, 14, 629, 8, 17502, 14, 354, 12, 536, 9, 267, 291, 14, 629, 8, 17502, 14, 1975, 63, 354, 12, 359, 1391, 63, 354, 566, 267, 291, 14, 7702, 8, 17502, 14, 1593, 9, 398, 536, 275, 283, 396, 7, 267, 2729, 63, 354, 275, 283, 10297, 587, 7, 267, 805, 275, 1683, 14, 3346, 342, 267, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 1750, 63, 354, 29, 1391, 63, 354, 12, 221, 1816, 805, 29, 1593, 9, 2728, 291, 14, 629, 8, 17502, 14, 354, 12, 536, 9, 267, 291, 14, 629, 8, 17502, 14, 1975, 63, 354, 12, 359, 1391, 63, 354, 566, 267, 291, 14, 10389, 8, 17502, 14, 1593, 9, 2728, 543, 291, 14, 1855, 8, 3393, 304, 288, 536, 275, 283, 396, 7, 288, 2729, 63, 354, 275, 283, 10297, 587, 7, 288, 805, 275, 283, 1397, 282, 805, 7, 288, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 1750, 63, 354, 29, 1391, 63, 354, 12, 221, 2511, 805, 29, 1593, 9, 2728, 543, 291, 14, 1855, 8, 3393, 304, 288, 536, 275, 283, 396, 7, 288, 2729, 63, 354, 275, 413, 288, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 1750, 63, 354, 29, 1391, 63, 354, 12, 221, 2511, 805, 29, 1593, 9, 2728, 543, 291, 14, 1855, 8, 3393, 304, 288, 536, 275, 283, 396, 7, 288, 2729, 63, 354, 275, 788, 65, 1750, 297, 413, 61, 288, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 1750, 63, 354, 29, 1391, 63, 354, 12, 221, 2511, 805, 29, 1593, 9, 2728, 536, 275, 283, 396, 7, 267, 2729, 63, 354, 275, 283, 10297, 587, 7, 267, 805, 275, 2400, 671, 26, 671, 267, 15955, 17, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 1750, 63, 354, 29, 1391, 63, 354, 12, 221, 1816, 805, 29, 1593, 9, 398, 15955, 18, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 1750, 63, 354, 29, 1391, 63, 354, 12, 221, 1816, 805, 29, 1593, 9, 2728, 291, 14, 629, 8, 17502, 17, 12, 15955, 18, 9, 2378, 347, 511, 63, 1412, 8, 277, 304, 267, 536, 275, 283, 396, 7, 267, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 9, 2728, 4704, 275, 359, 17, 61, 267, 291, 14, 629, 8, 17502, 14, 1412, 8, 4467, 395, 4704, 59, 16, 566, 398, 536, 275, 283, 396, 7, 267, 805, 275, 1683, 14, 3346, 342, 267, 805, 14, 1107, 63, 585, 275, 499, 267, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 805, 29, 1593, 9, 2728, 4704, 275, 359, 17, 61, 267, 291, 14, 629, 8, 17502, 14, 1412, 8, 4467, 395, 499, 9, 267, 805, 14, 479, 63, 3527, 63, 5089, 342, 7318, 536, 275, 283, 396, 7, 267, 805, 275, 1683, 14, 3346, 342, 267, 805, 14, 1107, 63, 585, 275, 499, 267, 1750, 63, 354, 275, 788, 65, 297, 283, 66, 418, 2728, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 805, 29, 1593, 12, 221, 1816, 1750, 63, 354, 29, 1975, 63, 354, 9, 2728, 4704, 275, 359, 17, 12, 499, 61, 267, 291, 14, 629, 8, 17502, 14, 1412, 8, 4467, 395, 499, 9, 267, 805, 14, 479, 63, 3527, 63, 5089, 342, 267, 805, 14, 479, 63, 3527, 63, 1045, 8, 17, 12, 499, 9, 398, 543, 291, 14, 1855, 8, 3393, 304, 288, 536, 275, 283, 396, 7, 288, 805, 275, 1683, 14, 3346, 342, 288, 805, 14, 1107, 63, 585, 275, 499, 288, 1750, 63, 354, 275, 788, 65, 297, 283, 66, 418, 7846, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 805, 29, 1593, 12, 221, 2511, 1750, 63, 354, 29, 1975, 63, 354, 9, 7846, 15955, 14, 1412, 779, 17, 566, 199, 199, 533, 1379, 30887, 2204, 4352, 8, 774, 13090, 2204, 4352, 304, 272, 15955, 63, 533, 275, 4703, 9641, 2204, 4352, 272, 15955, 63, 11645, 275, 298, 30887, 2204, 4352, 2, 339, 347, 511, 63, 1412, 8, 277, 304, 288, 536, 275, 283, 396, 7, 288, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 9, 7846, 4704, 275, 3474, 17, 2677, 288, 291, 14, 629, 8, 17502, 14, 1412, 8, 4467, 395, 4704, 59, 16, 566, 1362, 288, 536, 275, 283, 396, 7, 288, 805, 275, 1683, 14, 3346, 342, 288, 805, 14, 1107, 63, 585, 275, 359, 18, 61, 288, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 805, 29, 1593, 9, 7846, 4704, 275, 359, 17, 61, 288, 291, 14, 629, 8, 17502, 14, 1412, 8, 4467, 395, 359, 18, 566, 288, 805, 14, 479, 63, 3527, 63 ]
[ 199, 10502, 641, 1603, 348, 7294, 12, 6900, 199, 199, 703, 1233, 2502, 447, 1335, 21557, 758, 16247, 352, 665, 74, 14, 72, 14, 75, 758, 16247, 352, 334, 292, 9, 307, 3786, 32462, 334, 3287, 9, 12992, 30, 199, 2344, 199, 504, 636, 2443, 363, 492, 334, 25035, 12, 870, 63, 1593, 12, 3679, 63, 646, 12, 717, 2649, 63, 5955, 9, 199, 199, 646, 2882, 199, 646, 2882, 14, 1805, 465, 1683, 199, 199, 504, 325, 391, 63, 800, 16571, 14, 5633, 63, 4857, 14, 17502, 83, 492, 24289, 2204, 4352, 4202, 272, 4703, 9641, 2204, 4352, 199, 199, 533, 1379, 13090, 2204, 4352, 8, 2796, 14, 1746, 304, 272, 15955, 63, 533, 275, 24289, 2204, 4352, 272, 15955, 63, 11645, 275, 298, 13090, 2204, 4352, 2, 2286, 347, 511, 63, 17502, 8, 277, 304, 267, 536, 275, 283, 396, 7, 267, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 9, 2728, 291, 14, 629, 8, 17502, 14, 354, 12, 536, 9, 267, 291, 14, 629, 8, 17502, 14, 1975, 63, 354, 12, 359, 354, 566, 267, 291, 14, 7702, 8, 17502, 14, 1593, 9, 267, 291, 14, 629, 8, 2722, 8, 17502, 395, 291, 14, 17502, 63, 11645, 4786, 30338, 396, 60, 358, 358, 398, 536, 275, 283, 396, 7, 267, 2729, 63, 354, 275, 283, 10297, 587, 7, 267, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 1750, 63, 354, 29, 1391, 63, 354, 9, 2728, 291, 14, 629, 8, 17502, 14, 354, 12, 536, 9, 267, 291, 14, 629, 8, 17502, 14, 1975, 63, 354, 12, 359, 1391, 63, 354, 566, 267, 291, 14, 7702, 8, 17502, 14, 1593, 9, 398, 536, 275, 283, 396, 7, 267, 2729, 63, 354, 275, 283, 10297, 587, 7, 267, 805, 275, 1683, 14, 3346, 342, 267, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 1750, 63, 354, 29, 1391, 63, 354, 12, 221, 1816, 805, 29, 1593, 9, 2728, 291, 14, 629, 8, 17502, 14, 354, 12, 536, 9, 267, 291, 14, 629, 8, 17502, 14, 1975, 63, 354, 12, 359, 1391, 63, 354, 566, 267, 291, 14, 10389, 8, 17502, 14, 1593, 9, 2728, 543, 291, 14, 1855, 8, 3393, 304, 288, 536, 275, 283, 396, 7, 288, 2729, 63, 354, 275, 283, 10297, 587, 7, 288, 805, 275, 283, 1397, 282, 805, 7, 288, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 1750, 63, 354, 29, 1391, 63, 354, 12, 221, 2511, 805, 29, 1593, 9, 2728, 543, 291, 14, 1855, 8, 3393, 304, 288, 536, 275, 283, 396, 7, 288, 2729, 63, 354, 275, 413, 288, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 1750, 63, 354, 29, 1391, 63, 354, 12, 221, 2511, 805, 29, 1593, 9, 2728, 543, 291, 14, 1855, 8, 3393, 304, 288, 536, 275, 283, 396, 7, 288, 2729, 63, 354, 275, 788, 65, 1750, 297, 413, 61, 288, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 1750, 63, 354, 29, 1391, 63, 354, 12, 221, 2511, 805, 29, 1593, 9, 2728, 536, 275, 283, 396, 7, 267, 2729, 63, 354, 275, 283, 10297, 587, 7, 267, 805, 275, 2400, 671, 26, 671, 267, 15955, 17, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 1750, 63, 354, 29, 1391, 63, 354, 12, 221, 1816, 805, 29, 1593, 9, 398, 15955, 18, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 1750, 63, 354, 29, 1391, 63, 354, 12, 221, 1816, 805, 29, 1593, 9, 2728, 291, 14, 629, 8, 17502, 17, 12, 15955, 18, 9, 2378, 347, 511, 63, 1412, 8, 277, 304, 267, 536, 275, 283, 396, 7, 267, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 9, 2728, 4704, 275, 359, 17, 61, 267, 291, 14, 629, 8, 17502, 14, 1412, 8, 4467, 395, 4704, 59, 16, 566, 398, 536, 275, 283, 396, 7, 267, 805, 275, 1683, 14, 3346, 342, 267, 805, 14, 1107, 63, 585, 275, 499, 267, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 805, 29, 1593, 9, 2728, 4704, 275, 359, 17, 61, 267, 291, 14, 629, 8, 17502, 14, 1412, 8, 4467, 395, 499, 9, 267, 805, 14, 479, 63, 3527, 63, 5089, 342, 7318, 536, 275, 283, 396, 7, 267, 805, 275, 1683, 14, 3346, 342, 267, 805, 14, 1107, 63, 585, 275, 499, 267, 1750, 63, 354, 275, 788, 65, 297, 283, 66, 418, 2728, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 805, 29, 1593, 12, 221, 1816, 1750, 63, 354, 29, 1975, 63, 354, 9, 2728, 4704, 275, 359, 17, 12, 499, 61, 267, 291, 14, 629, 8, 17502, 14, 1412, 8, 4467, 395, 499, 9, 267, 805, 14, 479, 63, 3527, 63, 5089, 342, 267, 805, 14, 479, 63, 3527, 63, 1045, 8, 17, 12, 499, 9, 398, 543, 291, 14, 1855, 8, 3393, 304, 288, 536, 275, 283, 396, 7, 288, 805, 275, 1683, 14, 3346, 342, 288, 805, 14, 1107, 63, 585, 275, 499, 288, 1750, 63, 354, 275, 788, 65, 297, 283, 66, 418, 7846, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 805, 29, 1593, 12, 221, 2511, 1750, 63, 354, 29, 1975, 63, 354, 9, 7846, 15955, 14, 1412, 779, 17, 566, 199, 199, 533, 1379, 30887, 2204, 4352, 8, 774, 13090, 2204, 4352, 304, 272, 15955, 63, 533, 275, 4703, 9641, 2204, 4352, 272, 15955, 63, 11645, 275, 298, 30887, 2204, 4352, 2, 339, 347, 511, 63, 1412, 8, 277, 304, 288, 536, 275, 283, 396, 7, 288, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 9, 7846, 4704, 275, 3474, 17, 2677, 288, 291, 14, 629, 8, 17502, 14, 1412, 8, 4467, 395, 4704, 59, 16, 566, 1362, 288, 536, 275, 283, 396, 7, 288, 805, 275, 1683, 14, 3346, 342, 288, 805, 14, 1107, 63, 585, 275, 359, 18, 61, 288, 15955, 275, 291, 14, 17502, 63, 533, 8, 354, 12, 805, 29, 1593, 9, 7846, 4704, 275, 359, 17, 61, 288, 291, 14, 629, 8, 17502, 14, 1412, 8, 4467, 395, 359, 18, 566, 288, 805, 14, 479, 63, 3527, 63, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
tokenly/counterparty-lib
counterpartylib/lib/messages/versions/send2.py
3
3560
#! /usr/bin/python3 """Create and parse ‘send’-type messages.""" import struct from counterpartylib.lib import util from counterpartylib.lib import config from counterpartylib.lib.script import AddressError from counterpartylib.lib.exceptions import ValidateError from counterpartylib.lib.exceptions import UnpackError from counterpartylib.lib.exceptions import AssetError from counterpartylib.lib.exceptions import AssetNameError from counterpartylib.lib.exceptions import BalanceError FORMAT = '>QQ' LENGTH = 8 + 8 ID = 1 def pack(asset, quantity): data = struct.pack(config.TXTYPE_FORMAT, ID) data += struct.pack(FORMAT, util.asset_id(asset), quantity) return data def unpack(db, message, block_index): try: asset_id, quantity = struct.unpack(FORMAT, message) asset = util.get_asset_name(db, asset_id, block_index) except struct.error: raise UnpackError('could not unpack') except AssetNameError: raise UnpackError('asset id invalid') unpacked = { 'asset': asset, 'quantity': quantity } return unpacked def validate(db, source, destination, asset, quantity, block_index): try: util.get_asset_id(db, asset, block_index) except AssetError: raise ValidateError('asset invalid') try: script.validate(source) except AddressError: raise ValidateError('source address invalid') try: script.validate(destination) except AddressError: raise ValidateError('destination address invalid') if asset == config.BTC: raise ValidateError('cannot send {}'.format(config.BTC)) if type(quantity) != int: raise ValidateError('quantity not integer') if quantity > config.MAX_INT: raise ValidateError('quantity too large') if quantity <= 0: raise ValidateError('quantity non‐positive') if util.get_balance(db, source, asset) < quantity: raise BalanceError('balance insufficient') def compose(db, source, destination, asset, quantity): if asset == config.BTC: return (source, [(destination, quantity)], None) validate(db, source, destination, asset, quantity, util.CURRENT_BLOCK_INDEX) data = pack(asset, quantity) return (source, [(destination, None)], data) def parse(db, tx, message): status = 'valid' try: unpacked = unpack(message) asset, quantity = unpacked['asset'], unpacked['quantity'] validate(db, tx['source'], tx['destination'], asset, quantity, tx['block_index']) util.transfer(db, tx['source'], tx['destination'], asset, quantity, 'send', tx['tx_hash']) except UnpackError as e: asset, quantity = None, None status = 'invalid: ' + ''.join(e.args) except (ValidateError, BalanceError) as e: status = 'invalid: ' + ''.join(e.args) finally: bindings = { 'tx_index': tx['tx_index'], 'tx_hash': tx['tx_hash'], 'block_index': tx['block_index'], 'source': tx['source'], 'destination': tx['destination'], 'asset': asset, 'quantity': quantity, 'status': status, } sql = 'insert into sends values(:tx_index, :tx_hash, :block_index, :source, :destination, :asset, :quantity, :status)' cursor = db.cursor() cursor.execute(sql, bindings) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
mit
[ 3168, 1182, 2647, 15, 1393, 15, 1548, 19, 199, 199, 624, 2499, 436, 2198, 27430, 247, 2254, 21045, 13, 466, 3788, 1041, 199, 199, 646, 2702, 199, 199, 504, 7055, 7522, 773, 14, 773, 492, 4884, 199, 504, 7055, 7522, 773, 14, 773, 492, 1101, 199, 504, 7055, 7522, 773, 14, 773, 14, 1579, 492, 9906, 547, 199, 504, 7055, 7522, 773, 14, 773, 14, 3924, 492, 12134, 547, 199, 504, 7055, 7522, 773, 14, 773, 14, 3924, 492, 31017, 547, 199, 504, 7055, 7522, 773, 14, 773, 14, 3924, 492, 25670, 547, 199, 504, 7055, 7522, 773, 14, 773, 14, 3924, 492, 3709, 18347, 547, 199, 504, 7055, 7522, 773, 14, 773, 14, 3924, 492, 23928, 554, 547, 199, 199, 4807, 275, 12696, 12917, 7, 199, 9127, 275, 1695, 435, 1695, 199, 998, 275, 413, 199, 199, 318, 1706, 8, 6562, 12, 12524, 304, 272, 666, 275, 2702, 14, 1389, 8, 888, 14, 10051, 2711, 63, 4807, 12, 2870, 9, 272, 666, 847, 2702, 14, 1389, 8, 4807, 12, 4884, 14, 6562, 63, 344, 8, 6562, 395, 12524, 9, 272, 372, 666, 199, 199, 318, 7787, 8, 697, 12, 1245, 12, 1853, 63, 1080, 304, 272, 862, 26, 267, 8977, 63, 344, 12, 12524, 275, 2702, 14, 5301, 8, 4807, 12, 1245, 9, 267, 8977, 275, 4884, 14, 362, 63, 6562, 63, 354, 8, 697, 12, 8977, 63, 344, 12, 1853, 63, 1080, 9, 339, 871, 2702, 14, 705, 26, 267, 746, 31017, 547, 360, 15153, 440, 7787, 358, 339, 871, 3709, 18347, 547, 26, 267, 746, 31017, 547, 360, 6562, 1305, 3866, 358, 339, 23389, 275, 469, 355, 283, 6562, 356, 8977, 12, 355, 283, 10577, 356, 12524, 2049, 789, 272, 372, 23389, 199, 199, 318, 4107, 8, 697, 12, 1350, 12, 5724, 12, 8977, 12, 12524, 12, 1853, 63, 1080, 304, 339, 862, 26, 267, 4884, 14, 362, 63, 6562, 63, 344, 8, 697, 12, 8977, 12, 1853, 63, 1080, 9, 272, 871, 25670, 547, 26, 267, 746, 12134, 547, 360, 6562, 3866, 358, 339, 862, 26, 267, 2884, 14, 3502, 8, 1365, 9, 272, 871, 9906, 547, 26, 267, 746, 12134, 547, 360, 1365, 2287, 3866, 358, 339, 862, 26, 267, 2884, 14, 3502, 8, 6881, 9, 272, 871, 9906, 547, 26, 267, 746, 12134, 547, 360, 6881, 2287, 3866, 358, 339, 340, 8977, 508, 1101, 14, 34, 5708, 26, 267, 746, 12134, 547, 360, 11250, 3222, 9499, 908, 8, 888, 14, 34, 5708, 430, 339, 340, 730, 8, 10577, 9, 1137, 1109, 26, 267, 746, 12134, 547, 360, 10577, 440, 3000, 358, 339, 340, 12524, 690, 1101, 14, 4283, 63, 2919, 26, 267, 746, 12134, 547, 360, 10577, 4634, 7031, 358, 339, 340, 12524, 2695, 378, 26, 267, 746, 12134, 547, 360, 10577, 2222, 8477, 239, 8965, 358, 339, 340, 4884, 14, 362, 63, 7358, 8, 697, 12, 1350, 12, 8977, 9, 665, 12524, 26, 267, 746, 23928, 554, 547, 360, 7358, 5261, 12983, 358, 199, 199, 318, 23366, 8, 697, 12, 1350, 12, 5724, 12, 8977, 12, 12524, 304, 339, 340, 8977, 508, 1101, 14, 34, 5708, 26, 267, 372, 334, 1365, 12, 3842, 6881, 12, 12524, 4360, 488, 9, 339, 4107, 8, 697, 12, 1350, 12, 5724, 12, 8977, 12, 12524, 12, 4884, 14, 14211, 63, 8475, 63, 10215, 9, 272, 666, 275, 1706, 8, 6562, 12, 12524, 9, 339, 372, 334, 1365, 12, 3842, 6881, 12, 488, 4360, 666, 9, 199, 199, 318, 2198, 8, 697, 12, 4773, 12, 1245, 304, 272, 2004, 275, 283, 1078, 7, 339, 862, 26, 267, 23389, 275, 7787, 8, 1188, 9, 267, 8977, 12, 12524, 275, 23389, 459, 6562, 995, 23389, 459, 10577, 418, 267, 4107, 8, 697, 12, 4773, 459, 1365, 995, 4773, 459, 6881, 995, 8977, 12, 12524, 12, 4773, 459, 1457, 63, 1080, 1105, 267, 4884, 14, 9609, 8, 697, 12, 4773, 459, 1365, 995, 4773, 459, 6881, 995, 8977, 12, 12524, 12, 283, 2254, 297, 4773, 459, 2347, 63, 2227, 1105, 339, 871, 31017, 547, 465, 325, 26, 267, 8977, 12, 12524, 275, 488, 12, 488, 267, 2004, 275, 283, 3197, 26, 283, 435, 6522, 904, 8, 69, 14, 589, 9, 339, 871, 334, 12584, 547, 12, 23928, 554, 547, 9, 465, 325, 26, 267, 2004, 275, 283, 3197, 26, 283, 435, 6522, 904, 8, 69, 14, 589, 9, 339, 3753, 26, 267, 17792, 275, 469, 490, 283, 2347, 63, 1080, 356, 4773, 459, 2347, 63, 1080, 995, 490, 283, 2347, 63, 2227, 356, 4773, 459, 2347, 63, 2227, 995, 490, 283, 1457, 63, 1080, 356, 4773, 459, 1457, 63, 1080, 995, 490, 283, 1365, 356, 4773, 459, 1365, 995, 490, 283, 6881, 356, 4773, 459, 6881, 995, 490, 283, 6562, 356, 8977, 12, 490, 283, 10577, 356, 12524, 12, 490, 283, 1205, 356, 2004, 12, 673, 789, 267, 3875, 275, 283, 3176, 1901, 16178, 1338, 8, 26, 2347, 63, 1080, 12, 520, 2347, 63, 2227, 12, 520, 1457, 63, 1080, 12, 520, 1365, 12, 520, 6881, 12, 520, 6562, 12, 520, 10577, 12, 520, 1205, 3171, 267, 3920, 275, 1592, 14, 3937, 342, 267, 3920, 14, 2526, 8, 3009, 12, 17792, 9, 199, 199, 3, 6695, 26, 20849, 29, 24, 26414, 20105, 29, 20, 25966, 29, 20, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1182, 2647, 15, 1393, 15, 1548, 19, 199, 199, 624, 2499, 436, 2198, 27430, 247, 2254, 21045, 13, 466, 3788, 1041, 199, 199, 646, 2702, 199, 199, 504, 7055, 7522, 773, 14, 773, 492, 4884, 199, 504, 7055, 7522, 773, 14, 773, 492, 1101, 199, 504, 7055, 7522, 773, 14, 773, 14, 1579, 492, 9906, 547, 199, 504, 7055, 7522, 773, 14, 773, 14, 3924, 492, 12134, 547, 199, 504, 7055, 7522, 773, 14, 773, 14, 3924, 492, 31017, 547, 199, 504, 7055, 7522, 773, 14, 773, 14, 3924, 492, 25670, 547, 199, 504, 7055, 7522, 773, 14, 773, 14, 3924, 492, 3709, 18347, 547, 199, 504, 7055, 7522, 773, 14, 773, 14, 3924, 492, 23928, 554, 547, 199, 199, 4807, 275, 12696, 12917, 7, 199, 9127, 275, 1695, 435, 1695, 199, 998, 275, 413, 199, 199, 318, 1706, 8, 6562, 12, 12524, 304, 272, 666, 275, 2702, 14, 1389, 8, 888, 14, 10051, 2711, 63, 4807, 12, 2870, 9, 272, 666, 847, 2702, 14, 1389, 8, 4807, 12, 4884, 14, 6562, 63, 344, 8, 6562, 395, 12524, 9, 272, 372, 666, 199, 199, 318, 7787, 8, 697, 12, 1245, 12, 1853, 63, 1080, 304, 272, 862, 26, 267, 8977, 63, 344, 12, 12524, 275, 2702, 14, 5301, 8, 4807, 12, 1245, 9, 267, 8977, 275, 4884, 14, 362, 63, 6562, 63, 354, 8, 697, 12, 8977, 63, 344, 12, 1853, 63, 1080, 9, 339, 871, 2702, 14, 705, 26, 267, 746, 31017, 547, 360, 15153, 440, 7787, 358, 339, 871, 3709, 18347, 547, 26, 267, 746, 31017, 547, 360, 6562, 1305, 3866, 358, 339, 23389, 275, 469, 355, 283, 6562, 356, 8977, 12, 355, 283, 10577, 356, 12524, 2049, 789, 272, 372, 23389, 199, 199, 318, 4107, 8, 697, 12, 1350, 12, 5724, 12, 8977, 12, 12524, 12, 1853, 63, 1080, 304, 339, 862, 26, 267, 4884, 14, 362, 63, 6562, 63, 344, 8, 697, 12, 8977, 12, 1853, 63, 1080, 9, 272, 871, 25670, 547, 26, 267, 746, 12134, 547, 360, 6562, 3866, 358, 339, 862, 26, 267, 2884, 14, 3502, 8, 1365, 9, 272, 871, 9906, 547, 26, 267, 746, 12134, 547, 360, 1365, 2287, 3866, 358, 339, 862, 26, 267, 2884, 14, 3502, 8, 6881, 9, 272, 871, 9906, 547, 26, 267, 746, 12134, 547, 360, 6881, 2287, 3866, 358, 339, 340, 8977, 508, 1101, 14, 34, 5708, 26, 267, 746, 12134, 547, 360, 11250, 3222, 9499, 908, 8, 888, 14, 34, 5708, 430, 339, 340, 730, 8, 10577, 9, 1137, 1109, 26, 267, 746, 12134, 547, 360, 10577, 440, 3000, 358, 339, 340, 12524, 690, 1101, 14, 4283, 63, 2919, 26, 267, 746, 12134, 547, 360, 10577, 4634, 7031, 358, 339, 340, 12524, 2695, 378, 26, 267, 746, 12134, 547, 360, 10577, 2222, 8477, 239, 8965, 358, 339, 340, 4884, 14, 362, 63, 7358, 8, 697, 12, 1350, 12, 8977, 9, 665, 12524, 26, 267, 746, 23928, 554, 547, 360, 7358, 5261, 12983, 358, 199, 199, 318, 23366, 8, 697, 12, 1350, 12, 5724, 12, 8977, 12, 12524, 304, 339, 340, 8977, 508, 1101, 14, 34, 5708, 26, 267, 372, 334, 1365, 12, 3842, 6881, 12, 12524, 4360, 488, 9, 339, 4107, 8, 697, 12, 1350, 12, 5724, 12, 8977, 12, 12524, 12, 4884, 14, 14211, 63, 8475, 63, 10215, 9, 272, 666, 275, 1706, 8, 6562, 12, 12524, 9, 339, 372, 334, 1365, 12, 3842, 6881, 12, 488, 4360, 666, 9, 199, 199, 318, 2198, 8, 697, 12, 4773, 12, 1245, 304, 272, 2004, 275, 283, 1078, 7, 339, 862, 26, 267, 23389, 275, 7787, 8, 1188, 9, 267, 8977, 12, 12524, 275, 23389, 459, 6562, 995, 23389, 459, 10577, 418, 267, 4107, 8, 697, 12, 4773, 459, 1365, 995, 4773, 459, 6881, 995, 8977, 12, 12524, 12, 4773, 459, 1457, 63, 1080, 1105, 267, 4884, 14, 9609, 8, 697, 12, 4773, 459, 1365, 995, 4773, 459, 6881, 995, 8977, 12, 12524, 12, 283, 2254, 297, 4773, 459, 2347, 63, 2227, 1105, 339, 871, 31017, 547, 465, 325, 26, 267, 8977, 12, 12524, 275, 488, 12, 488, 267, 2004, 275, 283, 3197, 26, 283, 435, 6522, 904, 8, 69, 14, 589, 9, 339, 871, 334, 12584, 547, 12, 23928, 554, 547, 9, 465, 325, 26, 267, 2004, 275, 283, 3197, 26, 283, 435, 6522, 904, 8, 69, 14, 589, 9, 339, 3753, 26, 267, 17792, 275, 469, 490, 283, 2347, 63, 1080, 356, 4773, 459, 2347, 63, 1080, 995, 490, 283, 2347, 63, 2227, 356, 4773, 459, 2347, 63, 2227, 995, 490, 283, 1457, 63, 1080, 356, 4773, 459, 1457, 63, 1080, 995, 490, 283, 1365, 356, 4773, 459, 1365, 995, 490, 283, 6881, 356, 4773, 459, 6881, 995, 490, 283, 6562, 356, 8977, 12, 490, 283, 10577, 356, 12524, 12, 490, 283, 1205, 356, 2004, 12, 673, 789, 267, 3875, 275, 283, 3176, 1901, 16178, 1338, 8, 26, 2347, 63, 1080, 12, 520, 2347, 63, 2227, 12, 520, 1457, 63, 1080, 12, 520, 1365, 12, 520, 6881, 12, 520, 6562, 12, 520, 10577, 12, 520, 1205, 3171, 267, 3920, 275, 1592, 14, 3937, 342, 267, 3920, 14, 2526, 8, 3009, 12, 17792, 9, 199, 199, 3, 6695, 26, 20849, 29, 24, 26414, 20105, 29, 20, 25966, 29, 20, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
doot/CouchPotatoServer
libs/guessit/patterns.py
94
10301
#!/usr/bin/env python # -*- coding: utf-8 -*- # # GuessIt - A library for guessing information from filenames # Copyright (c) 2011 Nicolas Wack <wackou@gmail.com> # Copyright (c) 2011 Ricard Marxer <ricardmp@gmail.com> # # GuessIt is free software; you can redistribute it and/or modify it under # the terms of the Lesser GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # GuessIt is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # Lesser GNU General Public License for more details. # # You should have received a copy of the Lesser GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # from __future__ import unicode_literals import re subtitle_exts = [ 'srt', 'idx', 'sub', 'ssa' ] info_exts = [ 'nfo' ] video_exts = ['3g2', '3gp', '3gp2', 'asf', 'avi', 'divx', 'flv', 'm4v', 'mk2', 'mka', 'mkv', 'mov', 'mp4', 'mp4a', 'mpeg', 'mpg', 'ogg', 'ogm', 'ogv', 'qt', 'ra', 'ram', 'rm', 'ts', 'wav', 'webm', 'wma', 'wmv'] group_delimiters = [ '()', '[]', '{}' ] # separator character regexp sep = r'[][,)(}{+ /\._-]' # regexp art, hehe :D # character used to represent a deleted char (when matching groups) deleted = '_' # format: [ (regexp, confidence, span_adjust) ] episode_rexps = [ # ... Season 2 ... (r'season (?P<season>[0-9]+)', 1.0, (0, 0)), (r'saison (?P<season>[0-9]+)', 1.0, (0, 0)), # ... s02e13 ... (r'[Ss](?P<season>[0-9]{1,3})[^0-9]?(?P<episodeNumber>(?:-?[eE-][0-9]{1,3})+)[^0-9]', 1.0, (0, -1)), # ... s03-x02 ... # FIXME: redundant? remove it? #(r'[Ss](?P<season>[0-9]{1,3})[^0-9]?(?P<bonusNumber>(?:-?[xX-][0-9]{1,3})+)[^0-9]', 1.0, (0, -1)), # ... 2x13 ... (r'[^0-9](?P<season>[0-9]{1,2})[^0-9 .-]?(?P<episodeNumber>(?:-?[xX][0-9]{1,3})+)[^0-9]', 1.0, (1, -1)), # ... s02 ... #(sep + r's(?P<season>[0-9]{1,2})' + sep, 0.6, (1, -1)), (r's(?P<season>[0-9]{1,2})[^0-9]', 0.6, (0, -1)), # v2 or v3 for some mangas which have multiples rips (r'(?P<episodeNumber>[0-9]{1,3})v[23]' + sep, 0.6, (0, 0)), # ... ep 23 ... ('ep' + sep + r'(?P<episodeNumber>[0-9]{1,2})[^0-9]', 0.7, (0, -1)), # ... e13 ... for a mini-series without a season number (sep + r'e(?P<episodeNumber>[0-9]{1,2})' + sep, 0.6, (1, -1)) ] weak_episode_rexps = [ # ... 213 or 0106 ... (sep + r'(?P<episodeNumber>[0-9]{2,4})' + sep, (1, -1)) ] non_episode_title = [ 'extras', 'rip' ] video_rexps = [ # cd number (r'cd ?(?P<cdNumber>[0-9])( ?of ?(?P<cdNumberTotal>[0-9]))?', 1.0, (0, 0)), (r'(?P<cdNumberTotal>[1-9]) cds?', 0.9, (0, 0)), # special editions (r'edition' + sep + r'(?P<edition>collector)', 1.0, (0, 0)), (r'(?P<edition>collector)' + sep + 'edition', 1.0, (0, 0)), (r'(?P<edition>special)' + sep + 'edition', 1.0, (0, 0)), (r'(?P<edition>criterion)' + sep + 'edition', 1.0, (0, 0)), # director's cut (r"(?P<edition>director'?s?" + sep + "cut)", 1.0, (0, 0)), # video size (r'(?P<width>[0-9]{3,4})x(?P<height>[0-9]{3,4})', 0.9, (0, 0)), # website (r'(?P<website>www(\.[a-zA-Z0-9]+){2,3})', 0.8, (0, 0)), # bonusNumber: ... x01 ... (r'x(?P<bonusNumber>[0-9]{1,2})', 1.0, (0, 0)), # filmNumber: ... f01 ... (r'f(?P<filmNumber>[0-9]{1,2})', 1.0, (0, 0)) ] websites = [ 'tvu.org.ru', 'emule-island.com', 'UsaBit.com', 'www.divx-overnet.com', 'sharethefiles.com' ] unlikely_series = [ 'series' ] # prop_multi is a dict of { property_name: { canonical_form: [ pattern ] } } # pattern is a string considered as a regexp, with the addition that dashes are # replaced with '([ \.-_])?' which matches more types of separators (or none) # note: simpler patterns need to be at the end of the list to not shadow more # complete ones, eg: 'AAC' needs to come after 'He-AAC' # ie: from most specific to less specific prop_multi = { 'format': { 'DVD': [ 'DVD', 'DVD-Rip', 'VIDEO-TS', 'DVDivX' ], 'HD-DVD': [ 'HD-(?:DVD)?-Rip', 'HD-DVD' ], 'BluRay': [ 'Blu-ray', 'B[DR]Rip' ], 'HDTV': [ 'HD-TV' ], 'DVB': [ 'DVB-Rip', 'DVB', 'PD-TV' ], 'WEBRip': [ 'WEB-Rip' ], 'Screener': [ 'DVD-SCR', 'Screener' ], 'VHS': [ 'VHS' ], 'WEB-DL': [ 'WEB-DL' ] }, 'is3D': { True: [ '3D' ] }, 'screenSize': { '480p': [ '480[pi]?' ], '720p': [ '720[pi]?' ], '1080i': [ '1080i' ], '1080p': [ '1080p', '1080[^i]' ] }, 'videoCodec': { 'XviD': [ 'Xvid' ], 'DivX': [ 'DVDivX', 'DivX' ], 'h264': [ '[hx]-264' ], 'Rv10': [ 'Rv10' ], 'Mpeg2': [ 'Mpeg2' ] }, # has nothing to do here (or on filenames for that matter), but some # releases use it and it helps to identify release groups, so we adapt 'videoApi': { 'DXVA': [ 'DXVA' ] }, 'audioCodec': { 'AC3': [ 'AC3' ], 'DTS': [ 'DTS' ], 'AAC': [ 'He-AAC', 'AAC-He', 'AAC' ] }, 'audioChannels': { '5.1': [ r'5\.1', 'DD5[._ ]1', '5ch' ] }, 'episodeFormat': { 'Minisode': [ 'Minisodes?' ] } } # prop_single dict of { property_name: [ canonical_form ] } prop_single = { 'releaseGroup': [ 'ESiR', 'WAF', 'SEPTiC', r'\[XCT\]', 'iNT', 'PUKKA', 'CHD', 'ViTE', 'TLF', 'FLAiTE', 'MDX', 'GM4F', 'DVL', 'SVD', 'iLUMiNADOS', 'aXXo', 'KLAXXON', 'NoTV', 'ZeaL', 'LOL', 'CtrlHD', 'POD', 'WiKi','IMMERSE', 'FQM', '2HD', 'CTU', 'HALCYON', 'EbP', 'SiTV', 'HDBRiSe', 'AlFleNi-TeaM', 'EVOLVE', '0TV', 'TLA', 'NTB', 'ASAP', 'MOMENTUM', 'FoV', 'D-Z0N3', 'TrollHD', 'ECI' ], # potentially confusing release group names (they are words) 'weakReleaseGroup': [ 'DEiTY', 'FiNaLe', 'UnSeeN', 'KiNGS', 'CLUE', 'DIMENSION', 'SAiNTS', 'ARROW', 'EuReKA', 'SiNNERS', 'DiRTY', 'REWARD', 'REPTiLE', ], 'other': [ 'PROPER', 'REPACK', 'LIMITED', 'DualAudio', 'Audiofixed', 'R5', 'complete', 'classic', # not so sure about these ones, could appear in a title 'ws' ] # widescreen } _dash = '-' _psep = '[-. _]?' def _to_rexp(prop): return re.compile(prop.replace(_dash, _psep), re.IGNORECASE) # properties_rexps dict of { property_name: { canonical_form: [ rexp ] } } # containing the rexps compiled from both prop_multi and prop_single properties_rexps = dict((type, dict((canonical_form, [ _to_rexp(pattern) for pattern in patterns ]) for canonical_form, patterns in props.items())) for type, props in prop_multi.items()) properties_rexps.update(dict((type, dict((canonical_form, [ _to_rexp(canonical_form) ]) for canonical_form in props)) for type, props in prop_single.items())) def find_properties(string): result = [] for property_name, props in properties_rexps.items(): # FIXME: this should be done in a more flexible way... if property_name in ['weakReleaseGroup']: continue for canonical_form, rexps in props.items(): for value_rexp in rexps: match = value_rexp.search(string) if match: start, end = match.span() # make sure our word is always surrounded by separators # note: sep is a regexp, but in this case using it as # a char sequence achieves the same goal if ((start > 0 and string[start-1] not in sep) or (end < len(string) and string[end] not in sep)): continue result.append((property_name, canonical_form, start, end)) return result property_synonyms = { 'Special Edition': [ 'Special' ], 'Collector Edition': [ 'Collector' ], 'Criterion Edition': [ 'Criterion' ] } def revert_synonyms(): reverse = {} for canonical, synonyms in property_synonyms.items(): for synonym in synonyms: reverse[synonym.lower()] = canonical return reverse reverse_synonyms = revert_synonyms() def canonical_form(string): return reverse_synonyms.get(string.lower(), string) def compute_canonical_form(property_name, value): """Return the canonical form of a property given its type if it is a valid one, None otherwise.""" if isinstance(value, basestring): for canonical_form, rexps in properties_rexps[property_name].items(): for rexp in rexps: if rexp.match(value): return canonical_form return None
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 24570, 7940, 446, 437, 3555, 367, 9519, 316, 2556, 687, 6203, 199, 3, 1898, 334, 67, 9, 7760, 30650, 761, 305, 644, 564, 665, 87, 564, 810, 32, 6799, 14, 957, 30, 199, 3, 1898, 334, 67, 9, 7760, 820, 530, 1005, 16794, 32200, 665, 1567, 1005, 311, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 24570, 7940, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 652, 1334, 199, 3, 314, 2895, 402, 314, 6401, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 27, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 24570, 7940, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 6401, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 6401, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 646, 295, 421, 199, 14348, 63, 25752, 275, 359, 283, 24336, 297, 283, 2996, 297, 283, 954, 297, 283, 28023, 7, 1622, 199, 199, 815, 63, 25752, 275, 359, 283, 78, 545, 7, 1622, 199, 199, 3722, 63, 25752, 275, 788, 19, 71, 18, 297, 283, 19, 4927, 297, 283, 19, 4927, 18, 297, 283, 29551, 297, 283, 7194, 297, 283, 3015, 88, 297, 283, 22753, 297, 283, 77, 20, 86, 297, 283, 3880, 18, 297, 1598, 283, 3880, 65, 297, 283, 30420, 297, 283, 14469, 297, 283, 311, 20, 297, 283, 311, 20, 65, 297, 283, 16801, 297, 283, 311, 71, 297, 283, 24798, 297, 283, 974, 77, 297, 1598, 283, 974, 86, 297, 283, 8440, 297, 283, 345, 297, 283, 5975, 297, 283, 5682, 297, 283, 1086, 297, 283, 19118, 297, 283, 30504, 297, 283, 87, 391, 297, 283, 87, 12393, 418, 199, 199, 923, 63, 6933, 20378, 275, 359, 283, 19633, 6730, 4300, 19574, 1622, 199, 199, 3, 9432, 4528, 13156, 199, 4127, 275, 519, 3894, 1527, 4258, 8, 8847, 11, 1182, 60, 423, 13, 6616, 327, 13156, 24701, 12, 946, 426, 520, 36, 199, 199, 3, 4528, 1202, 370, 2954, 282, 5463, 1495, 334, 6526, 4877, 4652, 9, 199, 6062, 275, 14135, 199, 199, 3, 1475, 26, 359, 334, 11191, 12, 15197, 12, 13598, 63, 10917, 9, 1622, 199, 9544, 63, 15063, 1190, 275, 359, 327, 2263, 3240, 2660, 499, 2263, 2116, 334, 82, 1159, 69, 2660, 7558, 48, 28, 12605, 9514, 16, 13, 25, 28798, 413, 14, 16, 12, 334, 16, 12, 378, 1826, 2116, 334, 82, 1159, 65, 28287, 7558, 48, 28, 12605, 9514, 16, 13, 25, 28798, 413, 14, 16, 12, 334, 16, 12, 378, 1826, 199, 2116, 327, 2263, 308, 996, 69, 969, 2263, 2116, 334, 82, 3894, 32307, 61, 2229, 48, 28, 12605, 9514, 16, 13, 25, 8194, 17, 12, 19, 1552, 4735, 16, 13, 25, 11843, 2229, 48, 28, 9544, 3259, 30, 5169, 13, 26736, 20565, 13, 1527, 16, 13, 25, 8194, 17, 12, 19, 1552, 11, 2788, 62, 16, 13, 25, 4300, 413, 14, 16, 12, 334, 16, 12, 446, 17, 1826, 199, 2116, 327, 2263, 308, 1644, 13, 88, 996, 2263, 327, 7600, 26, 22649, 31, 2813, 652, 31, 2116, 21571, 82, 3894, 32307, 61, 2229, 48, 28, 12605, 9514, 16, 13, 25, 8194, 17, 12, 19, 1552, 4735, 16, 13, 25, 11843, 2229, 48, 28, 13520, 527, 3259, 30, 5169, 13, 26736, 24110, 13, 1527, 16, 13, 25, 8194, 17, 12, 19, 1552, 11, 2788, 62, 16, 13, 25, 4300, 413, 14, 16, 12, 334, 16, 12, 446, 17, 1826, 199, 2116, 327, 2263, 499, 88, 969, 2263, 2116, 334, 82, 16122, 16, 13, 25, 61, 2229, 48, 28, 12605, 9514, 16, 13, 25, 8194, 17, 12, 18, 1552, 4735, 16, 13, 25, 1275, 13, 11843, 2229, 48, 28, 9544, 3259, 30, 5169, 13, 26736, 24110, 1527, 16, 13, 25, 8194, 17, 12, 19, 1552, 11, 2788, 62, 16, 13, 25, 4300, 413, 14, 16, 12, 334, 17, 12, 446, 17, 1826, 199, 2116, 327, 2263, 308, 996, 2263, 2116, 21571, 4127, 435, 519, 1159, 2229, 48, 28, 12605, 9514, 16, 13, 25, 8194, 17, 12, 18, 29668, 435, 7375, 12, 378, 14, 22, 12, 334, 17, 12, 446, 17, 1826, 2116, 334, 82, 1159, 2229, 48, 28, 12605, 9514, 16, 13, 25, 8194, 17, 12, 18, 1552, 4735, 16, 13, 25, 4300, 378, 14, 22, 12, 334, 16, 12, 446, 17, 1826, 199, 2116, 327, 373, 18, 503, 373, 19, 367, 2005, 333, 621, 305, 1314, 1172, 3663, 83, 8012, 1190, 2116, 334, 82, 10120, 48, 28, 9544, 3259, 9514, 16, 13, 25, 8194, 17, 12, 19, 1552, 86, 59, 1789, 6616, 435, 7375, 12, 378, 14, 22, 12, 334, 16, 12, 378, 1826, 199, 2116, 327, 2263, 5442, 6546, 2263, 2116, 661, 1545, 7, 435, 7375, 435, 519, 10120, 48, 28, 9544, 3259, 9514, 16, 13, 25, 8194, 17, 12, 18, 1552, 4735, 16, 13, 25, 4300, 378, 14, 23, 12, 334, 16, 12, 446, 17, 1826, 199, 2116, 327, 2263, 325, 969, 2263, 367, 282, 20536, 13, 5602, 1928, 282, 14718, 1329, 2116, 334, 4127, 435, 519, 7, 69, 2229, 48, 28, 9544, 3259, 9514, 16, 13, 25, 8194, 17, 12, 18, 29668, 435, 7375, 12, 378, 14, 22, 12, 334, 17, 12, 446, 17, 430, 199, 2116, 1622, 421, 199, 10350, 63, 9544, 63, 15063, 1190, 275, 359, 327, 2263, 499, 969, 503, 378, 7357, 2263, 2432, 334, 4127, 435, 519, 10120, 48, 28, 9544, 3259, 9514, 16, 13, 25, 8194, 18, 12, 20, 29668, 435, 7375, 12, 334, 17, 12, 446, 17, 430, 2432, 1622, 199, 199, 2865, 63, 9544, 63, 1213, 275, 359, 283, 9975 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 24570, 7940, 446, 437, 3555, 367, 9519, 316, 2556, 687, 6203, 199, 3, 1898, 334, 67, 9, 7760, 30650, 761, 305, 644, 564, 665, 87, 564, 810, 32, 6799, 14, 957, 30, 199, 3, 1898, 334, 67, 9, 7760, 820, 530, 1005, 16794, 32200, 665, 1567, 1005, 311, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 24570, 7940, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 652, 1334, 199, 3, 314, 2895, 402, 314, 6401, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 27, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 24570, 7940, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 6401, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 6401, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 646, 295, 421, 199, 14348, 63, 25752, 275, 359, 283, 24336, 297, 283, 2996, 297, 283, 954, 297, 283, 28023, 7, 1622, 199, 199, 815, 63, 25752, 275, 359, 283, 78, 545, 7, 1622, 199, 199, 3722, 63, 25752, 275, 788, 19, 71, 18, 297, 283, 19, 4927, 297, 283, 19, 4927, 18, 297, 283, 29551, 297, 283, 7194, 297, 283, 3015, 88, 297, 283, 22753, 297, 283, 77, 20, 86, 297, 283, 3880, 18, 297, 1598, 283, 3880, 65, 297, 283, 30420, 297, 283, 14469, 297, 283, 311, 20, 297, 283, 311, 20, 65, 297, 283, 16801, 297, 283, 311, 71, 297, 283, 24798, 297, 283, 974, 77, 297, 1598, 283, 974, 86, 297, 283, 8440, 297, 283, 345, 297, 283, 5975, 297, 283, 5682, 297, 283, 1086, 297, 283, 19118, 297, 283, 30504, 297, 283, 87, 391, 297, 283, 87, 12393, 418, 199, 199, 923, 63, 6933, 20378, 275, 359, 283, 19633, 6730, 4300, 19574, 1622, 199, 199, 3, 9432, 4528, 13156, 199, 4127, 275, 519, 3894, 1527, 4258, 8, 8847, 11, 1182, 60, 423, 13, 6616, 327, 13156, 24701, 12, 946, 426, 520, 36, 199, 199, 3, 4528, 1202, 370, 2954, 282, 5463, 1495, 334, 6526, 4877, 4652, 9, 199, 6062, 275, 14135, 199, 199, 3, 1475, 26, 359, 334, 11191, 12, 15197, 12, 13598, 63, 10917, 9, 1622, 199, 9544, 63, 15063, 1190, 275, 359, 327, 2263, 3240, 2660, 499, 2263, 2116, 334, 82, 1159, 69, 2660, 7558, 48, 28, 12605, 9514, 16, 13, 25, 28798, 413, 14, 16, 12, 334, 16, 12, 378, 1826, 2116, 334, 82, 1159, 65, 28287, 7558, 48, 28, 12605, 9514, 16, 13, 25, 28798, 413, 14, 16, 12, 334, 16, 12, 378, 1826, 199, 2116, 327, 2263, 308, 996, 69, 969, 2263, 2116, 334, 82, 3894, 32307, 61, 2229, 48, 28, 12605, 9514, 16, 13, 25, 8194, 17, 12, 19, 1552, 4735, 16, 13, 25, 11843, 2229, 48, 28, 9544, 3259, 30, 5169, 13, 26736, 20565, 13, 1527, 16, 13, 25, 8194, 17, 12, 19, 1552, 11, 2788, 62, 16, 13, 25, 4300, 413, 14, 16, 12, 334, 16, 12, 446, 17, 1826, 199, 2116, 327, 2263, 308, 1644, 13, 88, 996, 2263, 327, 7600, 26, 22649, 31, 2813, 652, 31, 2116, 21571, 82, 3894, 32307, 61, 2229, 48, 28, 12605, 9514, 16, 13, 25, 8194, 17, 12, 19, 1552, 4735, 16, 13, 25, 11843, 2229, 48, 28, 13520, 527, 3259, 30, 5169, 13, 26736, 24110, 13, 1527, 16, 13, 25, 8194, 17, 12, 19, 1552, 11, 2788, 62, 16, 13, 25, 4300, 413, 14, 16, 12, 334, 16, 12, 446, 17, 1826, 199, 2116, 327, 2263, 499, 88, 969, 2263, 2116, 334, 82, 16122, 16, 13, 25, 61, 2229, 48, 28, 12605, 9514, 16, 13, 25, 8194, 17, 12, 18, 1552, 4735, 16, 13, 25, 1275, 13, 11843, 2229, 48, 28, 9544, 3259, 30, 5169, 13, 26736, 24110, 1527, 16, 13, 25, 8194, 17, 12, 19, 1552, 11, 2788, 62, 16, 13, 25, 4300, 413, 14, 16, 12, 334, 17, 12, 446, 17, 1826, 199, 2116, 327, 2263, 308, 996, 2263, 2116, 21571, 4127, 435, 519, 1159, 2229, 48, 28, 12605, 9514, 16, 13, 25, 8194, 17, 12, 18, 29668, 435, 7375, 12, 378, 14, 22, 12, 334, 17, 12, 446, 17, 1826, 2116, 334, 82, 1159, 2229, 48, 28, 12605, 9514, 16, 13, 25, 8194, 17, 12, 18, 1552, 4735, 16, 13, 25, 4300, 378, 14, 22, 12, 334, 16, 12, 446, 17, 1826, 199, 2116, 327, 373, 18, 503, 373, 19, 367, 2005, 333, 621, 305, 1314, 1172, 3663, 83, 8012, 1190, 2116, 334, 82, 10120, 48, 28, 9544, 3259, 9514, 16, 13, 25, 8194, 17, 12, 19, 1552, 86, 59, 1789, 6616, 435, 7375, 12, 378, 14, 22, 12, 334, 16, 12, 378, 1826, 199, 2116, 327, 2263, 5442, 6546, 2263, 2116, 661, 1545, 7, 435, 7375, 435, 519, 10120, 48, 28, 9544, 3259, 9514, 16, 13, 25, 8194, 17, 12, 18, 1552, 4735, 16, 13, 25, 4300, 378, 14, 23, 12, 334, 16, 12, 446, 17, 1826, 199, 2116, 327, 2263, 325, 969, 2263, 367, 282, 20536, 13, 5602, 1928, 282, 14718, 1329, 2116, 334, 4127, 435, 519, 7, 69, 2229, 48, 28, 9544, 3259, 9514, 16, 13, 25, 8194, 17, 12, 18, 29668, 435, 7375, 12, 378, 14, 22, 12, 334, 17, 12, 446, 17, 430, 199, 2116, 1622, 421, 199, 10350, 63, 9544, 63, 15063, 1190, 275, 359, 327, 2263, 499, 969, 503, 378, 7357, 2263, 2432, 334, 4127, 435, 519, 10120, 48, 28, 9544, 3259, 9514, 16, 13, 25, 8194, 18, 12, 20, 29668, 435, 7375, 12, 334, 17, 12, 446, 17, 430, 2432, 1622, 199, 199, 2865, 63, 9544, 63, 1213, 275, 359, 283, 9975, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
google/google-ctf
2019/finals/web-gphotos-finals/app/gallery/middleware.py
1
1230
# Copyright 2019 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from django.utils.text import slugify import hashlib import os class UserMiddleware: def __init__(self, get_response): self.get_response = get_response def __call__(self, request): user_id = request.COOKIES.get('user') if not user_id: user_id = hashlib.md5(os.urandom(16)).hexdigest() else: user_id = slugify(user_id) user_dir = os.path.join('media', user_id) if not os.path.exists(user_dir): os.makedirs(user_dir) os.makedirs(os.path.join(user_dir, 'thumbs')) request.user_id = user_id response = self.get_response(request) response.set_cookie('user', user_id) return response
apache-2.0
[ 3, 1898, 20312, 4475, 20376, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 4178, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 199, 504, 1639, 14, 1208, 14, 505, 492, 29864, 199, 646, 8337, 199, 646, 747, 421, 199, 533, 2876, 6608, 26, 523, 347, 636, 826, 721, 277, 12, 664, 63, 1310, 304, 272, 291, 14, 362, 63, 1310, 275, 664, 63, 1310, 819, 347, 636, 1250, 721, 277, 12, 1056, 304, 272, 922, 63, 344, 275, 1056, 14, 12189, 2563, 14, 362, 360, 751, 358, 272, 340, 440, 922, 63, 344, 26, 489, 922, 63, 344, 275, 8337, 14, 1064, 21, 8, 736, 14, 22776, 8, 975, 4992, 11453, 342, 272, 587, 26, 489, 922, 63, 344, 275, 29864, 8, 751, 63, 344, 9, 339, 922, 63, 694, 275, 747, 14, 515, 14, 904, 360, 4603, 297, 922, 63, 344, 9, 339, 340, 440, 747, 14, 515, 14, 2444, 8, 751, 63, 694, 304, 489, 747, 14, 8347, 8, 751, 63, 694, 9, 489, 747, 14, 8347, 8, 736, 14, 515, 14, 904, 8, 751, 63, 694, 12, 283, 273, 23135, 1333, 339, 1056, 14, 751, 63, 344, 275, 922, 63, 344, 339, 1177, 275, 291, 14, 362, 63, 1310, 8, 1069, 9, 272, 1177, 14, 409, 63, 5306, 360, 751, 297, 922, 63, 344, 9, 339, 372, 1177, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1898, 20312, 4475, 20376, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 4178, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 199, 504, 1639, 14, 1208, 14, 505, 492, 29864, 199, 646, 8337, 199, 646, 747, 421, 199, 533, 2876, 6608, 26, 523, 347, 636, 826, 721, 277, 12, 664, 63, 1310, 304, 272, 291, 14, 362, 63, 1310, 275, 664, 63, 1310, 819, 347, 636, 1250, 721, 277, 12, 1056, 304, 272, 922, 63, 344, 275, 1056, 14, 12189, 2563, 14, 362, 360, 751, 358, 272, 340, 440, 922, 63, 344, 26, 489, 922, 63, 344, 275, 8337, 14, 1064, 21, 8, 736, 14, 22776, 8, 975, 4992, 11453, 342, 272, 587, 26, 489, 922, 63, 344, 275, 29864, 8, 751, 63, 344, 9, 339, 922, 63, 694, 275, 747, 14, 515, 14, 904, 360, 4603, 297, 922, 63, 344, 9, 339, 340, 440, 747, 14, 515, 14, 2444, 8, 751, 63, 694, 304, 489, 747, 14, 8347, 8, 751, 63, 694, 9, 489, 747, 14, 8347, 8, 736, 14, 515, 14, 904, 8, 751, 63, 694, 12, 283, 273, 23135, 1333, 339, 1056, 14, 751, 63, 344, 275, 922, 63, 344, 339, 1177, 275, 291, 14, 362, 63, 1310, 8, 1069, 9, 272, 1177, 14, 409, 63, 5306, 360, 751, 297, 922, 63, 344, 9, 339, 372, 1177, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
atosatto/ansible
lib/ansible/modules/storage/netapp/na_cdot_license.py
67
9643
#!/usr/bin/python # (c) 2017, NetApp, Inc # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} DOCUMENTATION = ''' module: na_cdot_license short_description: Manage NetApp cDOT protocol and feature licenses extends_documentation_fragment: - netapp.ontap version_added: '2.3' author: Sumit Kumar (sumit4@netapp.com) description: - Add or remove licenses on NetApp ONTAP. options: remove_unused: description: - Remove licenses that have no controller affiliation in the cluster. choices: ['true', 'false'] remove_expired: description: - Remove licenses that have expired in the cluster. choices: ['true', 'false'] serial_number: description: - Serial number of the node associated with the license. - This parameter is used primarily when removing license for a specific service. - If this parameter is not provided, the cluster serial number is used by default. default: None licenses: description: - List of licenses to add or remove. - Please note that trying to remove a non-existent license will throw an error. suboptions: base: description: - Cluster Base License nfs: description: - NFS License cifs: description: - CIFS License iscsi: description: - iSCSI License fcp: description: - FCP License cdmi: description: - CDMI License snaprestore: description: - SnapRestore License snapmirror: description: - SnapMirror License flexclone: description: - FlexClone License snapvault: description: - SnapVault License snaplock: description: - SnapLock License snapmanagersuite: description: - SnapManagerSuite License snapprotectapps: description: - SnapProtectApp License v_storageattach: description: - Virtual Attached Storage License ''' EXAMPLES = """ - name: Add licenses na_cdot_license: hostname: "{{ netapp_hostname }}" username: "{{ netapp_username }}" password: "{{ netapp_password }}" serial_number: ################# licenses: nfs: ################# cifs: ################# iscsi: ################# fcp: ################# snaprestore: ################# flexclone: ################# - name: Remove licenses na_cdot_license: hostname: "{{ netapp_hostname }}" username: "{{ netapp_username }}" password: "{{ netapp_password }}" remove_unused: false remove_expired: true serial_number: ################# licenses: nfs: remove """ RETURN = """ """ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.pycompat24 import get_exception import ansible.module_utils.netapp as netapp_utils HAS_NETAPP_LIB = netapp_utils.has_netapp_lib() class NetAppCDOTLicense(object): def __init__(self): self.argument_spec = netapp_utils.ontap_sf_host_argument_spec() self.argument_spec.update(dict( serial_number=dict(required=False, type='str', default=None), remove_unused=dict(default=False, type='bool'), remove_expired=dict(default=False, type='bool'), licenses=dict(default=False, type='dict'), )) self.module = AnsibleModule( argument_spec=self.argument_spec, supports_check_mode=False ) p = self.module.params # set up state variables self.serial_number = p['serial_number'] self.remove_unused = p['remove_unused'] self.remove_expired = p['remove_expired'] self.licenses = p['licenses'] if HAS_NETAPP_LIB is False: self.module.fail_json(msg="the python NetApp-Lib module is required") else: self.server = netapp_utils.setup_ontap_zapi(module=self.module) def get_licensing_status(self): """ Check licensing status :return: package (key) and licensing status (value) :rtype: dict """ license_status = netapp_utils.zapi.NaElement('license-v2-status-list-info') result = None try: result = self.server.invoke_successfully(license_status, enable_tunneling=False) except netapp_utils.zapi.NaApiError: err = get_exception() self.module.fail_json(msg="Error checking license status", exception=str(err)) return_dictionary = {} license_v2_status = result.get_child_by_name('license-v2-status') if license_v2_status: for license_v2_status_info in license_v2_status.get_children(): package = license_v2_status_info.get_child_content('package') status = license_v2_status_info.get_child_content('method') return_dictionary[package] = status return return_dictionary def remove_licenses(self, remove_list): """ Remove requested licenses :param: remove_list : List of packages to remove """ license_delete = netapp_utils.zapi.NaElement('license-v2-delete') for package in remove_list: license_delete.add_new_child('package', package) if self.serial_number is not None: license_delete.add_new_child('serial-number', self.serial_number) try: self.server.invoke_successfully(license_delete, enable_tunneling=False) except netapp_utils.zapi.NaApiError: err = get_exception() self.module.fail_json(msg="Error removing license", exception=str(err)) def remove_unused_licenses(self): """ Remove unused licenses """ remove_unused = netapp_utils.zapi.NaElement('license-v2-delete-unused') try: self.server.invoke_successfully(remove_unused, enable_tunneling=False) except netapp_utils.zapi.NaApiError: err = get_exception() self.module.fail_json(msg="Error removing unused licenses", exception=str(err)) def remove_expired_licenses(self): """ Remove expired licenses """ remove_expired = netapp_utils.zapi.NaElement('license-v2-delete-expired') try: self.server.invoke_successfully(remove_expired, enable_tunneling=False) except netapp_utils.zapi.NaApiError: err = get_exception() self.module.fail_json(msg="Error removing expired licenses", exception=str(err)) def update_licenses(self): """ Update licenses """ # Remove unused and expired licenses, if requested. if self.remove_unused: self.remove_unused_licenses() if self.remove_expired: self.remove_expired_licenses() # Next, add/remove specific requested licenses. license_add = netapp_utils.zapi.NaElement('license-v2-add') codes = netapp_utils.zapi.NaElement('codes') remove_list = [] for key, value in self.licenses.items(): str_value = str(value) # Make sure license is not an empty string. if str_value and str_value.strip(): if str_value.lower() == 'remove': remove_list.append(str(key).lower()) else: codes.add_new_child('license-code-v2', str_value) # Remove requested licenses. if not len(remove_list) == 0: self.remove_licenses(remove_list) # Add requested licenses if not len(codes.get_children()) == 0: license_add.add_child_elem(codes) try: self.server.invoke_successfully(license_add, enable_tunneling=False) except netapp_utils.zapi.NaApiError: err = get_exception() self.module.fail_json(msg="Error adding licenses", exception=str(err)) def apply(self): changed = False # Add / Update licenses. license_status = self.get_licensing_status() self.update_licenses() new_license_status = self.get_licensing_status() if not license_status == new_license_status: changed = True self.module.exit_json(changed=changed) def main(): v = NetAppCDOTLicense() v.apply() if __name__ == '__main__': main()
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 199, 3, 334, 67, 9, 9708, 12, 28076, 12, 3277, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 16, 297, 490, 283, 1205, 356, 788, 7780, 995, 490, 283, 4946, 63, 991, 356, 283, 9387, 936, 421, 199, 8948, 275, 1449, 199, 199, 578, 26, 11802, 63, 2866, 357, 63, 1682, 199, 199, 3612, 63, 1802, 26, 14944, 28076, 286, 13203, 4113, 436, 3878, 12378, 199, 11036, 63, 9970, 63, 7677, 26, 272, 446, 15742, 14, 1888, 439, 199, 1023, 63, 3270, 26, 283, 18, 14, 19, 7, 199, 2502, 26, 12094, 390, 1804, 453, 285, 334, 1838, 390, 20, 32, 25830, 14, 957, 9, 199, 199, 1802, 26, 199, 13, 2654, 503, 2813, 12378, 641, 28076, 5258, 52, 1282, 14, 199, 199, 1419, 26, 819, 2813, 63, 8618, 26, 272, 1369, 26, 272, 446, 5852, 12378, 626, 1172, 949, 7614, 23528, 18835, 315, 314, 4350, 14, 272, 3415, 26, 788, 2052, 297, 283, 3910, 418, 819, 2813, 63, 16340, 26, 272, 1369, 26, 272, 446, 5852, 12378, 626, 1172, 14721, 315, 314, 4350, 14, 272, 3415, 26, 788, 2052, 297, 283, 3910, 418, 819, 3012, 63, 1955, 26, 272, 1369, 26, 272, 446, 11973, 1329, 402, 314, 1031, 4568, 543, 314, 4190, 14, 272, 446, 961, 2725, 365, 1202, 1979, 30468, 1380, 12881, 4190, 367, 282, 2488, 2435, 14, 272, 446, 982, 642, 2725, 365, 440, 2741, 12, 314, 4350, 3012, 1329, 365, 1202, 701, 849, 14, 272, 849, 26, 488, 819, 12378, 26, 272, 1369, 26, 272, 446, 3820, 402, 12378, 370, 1050, 503, 2813, 14, 272, 446, 7754, 5317, 626, 9936, 370, 2813, 282, 2222, 13, 15025, 4190, 911, 7978, 376, 1125, 14, 272, 26265, 26, 489, 1300, 26, 267, 1369, 26, 881, 446, 16454, 3523, 844, 489, 31307, 26, 267, 1369, 26, 881, 446, 653, 7079, 844, 489, 286, 20985, 26, 267, 1369, 26, 881, 446, 445, 4656, 51, 844, 489, 22144, 26, 267, 1369, 26, 881, 446, 284, 16958, 844, 489, 289, 1850, 26, 267, 1369, 26, 881, 446, 481, 2890, 844, 489, 12829, 2664, 26, 267, 1369, 26, 881, 446, 445, 36, 10709, 844, 489, 13639, 8011, 26, 267, 1369, 26, 881, 446, 428, 2542, 21012, 844, 489, 13639, 12324, 26, 267, 1369, 26, 881, 446, 428, 2542, 28034, 844, 489, 20758, 6311, 26, 267, 1369, 26, 881, 446, 481, 3113, 21222, 844, 489, 13639, 10077, 26, 267, 1369, 26, 881, 446, 428, 2542, 20229, 844, 489, 13639, 831, 26, 267, 1369, 26, 881, 446, 428, 2542, 6432, 844, 489, 13639, 16259, 2577, 26, 267, 1369, 26, 881, 446, 428, 2542, 2988, 6207, 844, 489, 13639, 18292, 5181, 26, 267, 1369, 26, 881, 446, 428, 2542, 919, 5302, 2640, 844, 489, 373, 63, 3494, 5040, 26, 267, 1369, 26, 881, 446, 13311, 2854, 7159, 10533, 844, 199, 199, 2344, 421, 199, 8918, 275, 408, 199, 13, 536, 26, 2654, 12378, 523, 11802, 63, 2866, 357, 63, 1682, 26, 272, 6246, 26, 7370, 15742, 63, 4269, 7820, 272, 3434, 26, 7370, 15742, 63, 2473, 7820, 272, 2505, 26, 7370, 15742, 63, 2060, 7820, 272, 3012, 63, 1955, 26, 21905, 3, 272, 12378, 26, 489, 31307, 26, 21905, 3, 489, 286, 20985, 26, 21905, 3, 489, 22144, 26, 21905, 3, 489, 289, 1850, 26, 21905, 3, 489, 13639, 8011, 26, 21905, 3, 489, 20758, 6311, 26, 21905, 3, 199, 199, 13, 536, 26, 5852, 12378, 523, 11802, 63, 2866, 357, 63, 1682, 26, 272, 6246, 26, 7370, 15742, 63, 4269, 7820, 272, 3434, 26, 7370, 15742, 63, 2473, 7820, 272, 2505, 26, 7370, 15742, 63, 2060, 7820, 272, 2813, 63, 8618, 26, 3055, 272, 2813, 63, 16340, 26, 2549, 272, 3012, 63, 1955, 26, 21905, 3, 272, 12378, 26, 489, 31307, 26, 2813, 199, 624, 199, 199, 9677, 275, 408, 199, 199, 624, 199, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 6953, 199, 504, 3242, 14, 578, 63, 1208, 14, 647, 5819, 1194, 492, 664, 63, 1971, 199, 646, 3242, 14, 578, 63, 1208, 14, 25830, 465, 15742, 63, 1208, 199, 199, 13533, 63, 7278, 7121, 63, 5617, 275, 15742, 63, 1208, 14, 1989, 63, 25830, 63, 773, 342, 421, 199, 533, 28076, 7695, 1387, 3761, 8, 785, 304, 339, 347, 636, 826, 721, 277, 304, 267, 291, 14, 2094, 63, 1650, 275, 15742, 63, 1208, 14, 1888, 439, 63, 7646, 63, 1102, 63, 2094, 63, 1650, 342, 267, 291, 14, 2094, 63, 1650, 14, 873, 8, 807, 8, 288, 3012, 63, 1955, 29, 807, 8, 2427, 29, 797, 12, 730, 534, 495, 297, 849, 29, 403, 395, 288, 2813, 63, 8618, 29, 807, 8, 885, 29, 797, 12, 730, 534, 2245, 659, 288, 2813, 63, 16340, 29, 807, 8, 885, 29, 797, 12, 730, 534, 2245, 659, 288, 12378, 29, 807, 8, 885, 29, 797, 12, 730, 534, 807, 659, 267, 5082, 398, 291, 14, 578, 275, 6953, 8, 288, 1423, 63, 1650, 29, 277, 14, 2094, 63, 1650, 12, 288, 5171, 63, 1074, 63, 632, 29, 797, 267, 776, 398, 299, 275, 291, 14, 578, 14, 1162, 398, 327, 663, 1536, 1174, 2860, 267, 291, 14, 2171, 63, 1955, 275, 299, 459, 2171 ]
[ 2647, 15, 1393, 15, 1548, 199, 199, 3, 334, 67, 9, 9708, 12, 28076, 12, 3277, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 16, 297, 490, 283, 1205, 356, 788, 7780, 995, 490, 283, 4946, 63, 991, 356, 283, 9387, 936, 421, 199, 8948, 275, 1449, 199, 199, 578, 26, 11802, 63, 2866, 357, 63, 1682, 199, 199, 3612, 63, 1802, 26, 14944, 28076, 286, 13203, 4113, 436, 3878, 12378, 199, 11036, 63, 9970, 63, 7677, 26, 272, 446, 15742, 14, 1888, 439, 199, 1023, 63, 3270, 26, 283, 18, 14, 19, 7, 199, 2502, 26, 12094, 390, 1804, 453, 285, 334, 1838, 390, 20, 32, 25830, 14, 957, 9, 199, 199, 1802, 26, 199, 13, 2654, 503, 2813, 12378, 641, 28076, 5258, 52, 1282, 14, 199, 199, 1419, 26, 819, 2813, 63, 8618, 26, 272, 1369, 26, 272, 446, 5852, 12378, 626, 1172, 949, 7614, 23528, 18835, 315, 314, 4350, 14, 272, 3415, 26, 788, 2052, 297, 283, 3910, 418, 819, 2813, 63, 16340, 26, 272, 1369, 26, 272, 446, 5852, 12378, 626, 1172, 14721, 315, 314, 4350, 14, 272, 3415, 26, 788, 2052, 297, 283, 3910, 418, 819, 3012, 63, 1955, 26, 272, 1369, 26, 272, 446, 11973, 1329, 402, 314, 1031, 4568, 543, 314, 4190, 14, 272, 446, 961, 2725, 365, 1202, 1979, 30468, 1380, 12881, 4190, 367, 282, 2488, 2435, 14, 272, 446, 982, 642, 2725, 365, 440, 2741, 12, 314, 4350, 3012, 1329, 365, 1202, 701, 849, 14, 272, 849, 26, 488, 819, 12378, 26, 272, 1369, 26, 272, 446, 3820, 402, 12378, 370, 1050, 503, 2813, 14, 272, 446, 7754, 5317, 626, 9936, 370, 2813, 282, 2222, 13, 15025, 4190, 911, 7978, 376, 1125, 14, 272, 26265, 26, 489, 1300, 26, 267, 1369, 26, 881, 446, 16454, 3523, 844, 489, 31307, 26, 267, 1369, 26, 881, 446, 653, 7079, 844, 489, 286, 20985, 26, 267, 1369, 26, 881, 446, 445, 4656, 51, 844, 489, 22144, 26, 267, 1369, 26, 881, 446, 284, 16958, 844, 489, 289, 1850, 26, 267, 1369, 26, 881, 446, 481, 2890, 844, 489, 12829, 2664, 26, 267, 1369, 26, 881, 446, 445, 36, 10709, 844, 489, 13639, 8011, 26, 267, 1369, 26, 881, 446, 428, 2542, 21012, 844, 489, 13639, 12324, 26, 267, 1369, 26, 881, 446, 428, 2542, 28034, 844, 489, 20758, 6311, 26, 267, 1369, 26, 881, 446, 481, 3113, 21222, 844, 489, 13639, 10077, 26, 267, 1369, 26, 881, 446, 428, 2542, 20229, 844, 489, 13639, 831, 26, 267, 1369, 26, 881, 446, 428, 2542, 6432, 844, 489, 13639, 16259, 2577, 26, 267, 1369, 26, 881, 446, 428, 2542, 2988, 6207, 844, 489, 13639, 18292, 5181, 26, 267, 1369, 26, 881, 446, 428, 2542, 919, 5302, 2640, 844, 489, 373, 63, 3494, 5040, 26, 267, 1369, 26, 881, 446, 13311, 2854, 7159, 10533, 844, 199, 199, 2344, 421, 199, 8918, 275, 408, 199, 13, 536, 26, 2654, 12378, 523, 11802, 63, 2866, 357, 63, 1682, 26, 272, 6246, 26, 7370, 15742, 63, 4269, 7820, 272, 3434, 26, 7370, 15742, 63, 2473, 7820, 272, 2505, 26, 7370, 15742, 63, 2060, 7820, 272, 3012, 63, 1955, 26, 21905, 3, 272, 12378, 26, 489, 31307, 26, 21905, 3, 489, 286, 20985, 26, 21905, 3, 489, 22144, 26, 21905, 3, 489, 289, 1850, 26, 21905, 3, 489, 13639, 8011, 26, 21905, 3, 489, 20758, 6311, 26, 21905, 3, 199, 199, 13, 536, 26, 5852, 12378, 523, 11802, 63, 2866, 357, 63, 1682, 26, 272, 6246, 26, 7370, 15742, 63, 4269, 7820, 272, 3434, 26, 7370, 15742, 63, 2473, 7820, 272, 2505, 26, 7370, 15742, 63, 2060, 7820, 272, 2813, 63, 8618, 26, 3055, 272, 2813, 63, 16340, 26, 2549, 272, 3012, 63, 1955, 26, 21905, 3, 272, 12378, 26, 489, 31307, 26, 2813, 199, 624, 199, 199, 9677, 275, 408, 199, 199, 624, 199, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 6953, 199, 504, 3242, 14, 578, 63, 1208, 14, 647, 5819, 1194, 492, 664, 63, 1971, 199, 646, 3242, 14, 578, 63, 1208, 14, 25830, 465, 15742, 63, 1208, 199, 199, 13533, 63, 7278, 7121, 63, 5617, 275, 15742, 63, 1208, 14, 1989, 63, 25830, 63, 773, 342, 421, 199, 533, 28076, 7695, 1387, 3761, 8, 785, 304, 339, 347, 636, 826, 721, 277, 304, 267, 291, 14, 2094, 63, 1650, 275, 15742, 63, 1208, 14, 1888, 439, 63, 7646, 63, 1102, 63, 2094, 63, 1650, 342, 267, 291, 14, 2094, 63, 1650, 14, 873, 8, 807, 8, 288, 3012, 63, 1955, 29, 807, 8, 2427, 29, 797, 12, 730, 534, 495, 297, 849, 29, 403, 395, 288, 2813, 63, 8618, 29, 807, 8, 885, 29, 797, 12, 730, 534, 2245, 659, 288, 2813, 63, 16340, 29, 807, 8, 885, 29, 797, 12, 730, 534, 2245, 659, 288, 12378, 29, 807, 8, 885, 29, 797, 12, 730, 534, 807, 659, 267, 5082, 398, 291, 14, 578, 275, 6953, 8, 288, 1423, 63, 1650, 29, 277, 14, 2094, 63, 1650, 12, 288, 5171, 63, 1074, 63, 632, 29, 797, 267, 776, 398, 299, 275, 291, 14, 578, 14, 1162, 398, 327, 663, 1536, 1174, 2860, 267, 291, 14, 2171, 63, 1955, 275, 299, 459, 2171, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
JioEducation/edx-platform
pavelib/utils/envs.py
9
7028
""" Helper functions for loading environment settings. """ from __future__ import print_function import os import sys import json from lazy import lazy from path import Path as path import memcache class Env(object): """ Load information about the execution environment. """ # Root of the git repository (edx-platform) REPO_ROOT = path(__file__).abspath().parent.parent.parent # Reports Directory REPORT_DIR = REPO_ROOT / 'reports' METRICS_DIR = REPORT_DIR / 'metrics' # Python unittest dirs PYTHON_COVERAGERC = REPO_ROOT / ".coveragerc" # Bok_choy dirs BOK_CHOY_DIR = REPO_ROOT / "common" / "test" / "acceptance" BOK_CHOY_LOG_DIR = REPO_ROOT / "test_root" / "log" BOK_CHOY_REPORT_DIR = REPORT_DIR / "bok_choy" BOK_CHOY_A11Y_REPORT_DIR = REPORT_DIR / "a11y" BOK_CHOY_COVERAGERC = BOK_CHOY_DIR / ".coveragerc" BOK_CHOY_A11Y_COVERAGERC = BOK_CHOY_DIR / ".a11ycoveragerc" BOK_CHOY_A11Y_CUSTOM_RULES_FILE = ( REPO_ROOT / "node_modules" / "edx-custom-a11y-rules" / "lib" / "custom_a11y_rules.js" ) PA11YCRAWLER_REPORT_DIR = REPORT_DIR / "pa11ycrawler" PA11YCRAWLER_COVERAGERC = BOK_CHOY_DIR / ".pa11ycrawlercoveragerc" # If set, put reports for run in "unique" directories. # The main purpose of this is to ensure that the reports can be 'slurped' # in the main jenkins flow job without overwriting the reports from other # build steps. For local development/testing, this shouldn't be needed. if os.environ.get("SHARD", None): shard_str = "shard_{}".format(os.environ.get("SHARD")) BOK_CHOY_REPORT_DIR = BOK_CHOY_REPORT_DIR / shard_str BOK_CHOY_LOG_DIR = BOK_CHOY_LOG_DIR / shard_str # For the time being, stubs are used by both the bok-choy and lettuce acceptance tests # For this reason, the stubs package is currently located in the Django app called "terrain" # where other lettuce configuration is stored. BOK_CHOY_STUB_DIR = REPO_ROOT / "common" / "djangoapps" / "terrain" # Directory that videos are served from VIDEO_SOURCE_DIR = REPO_ROOT / "test_root" / "data" / "video" BOK_CHOY_SERVERS = { 'lms': { 'port': 8003, 'log': BOK_CHOY_LOG_DIR / "bok_choy_lms.log" }, 'cms': { 'port': 8031, 'log': BOK_CHOY_LOG_DIR / "bok_choy_studio.log" } } BOK_CHOY_STUBS = { 'xqueue': { 'port': 8040, 'log': BOK_CHOY_LOG_DIR / "bok_choy_xqueue.log", 'config': 'register_submission_url=http://0.0.0.0:8041/test/register_submission', }, 'ora': { 'port': 8041, 'log': BOK_CHOY_LOG_DIR / "bok_choy_ora.log", 'config': '', }, 'comments': { 'port': 4567, 'log': BOK_CHOY_LOG_DIR / "bok_choy_comments.log", }, 'video': { 'port': 8777, 'log': BOK_CHOY_LOG_DIR / "bok_choy_video_sources.log", 'config': "root_dir={}".format(VIDEO_SOURCE_DIR), }, 'youtube': { 'port': 9080, 'log': BOK_CHOY_LOG_DIR / "bok_choy_youtube.log", }, 'edxnotes': { 'port': 8042, 'log': BOK_CHOY_LOG_DIR / "bok_choy_edxnotes.log", }, 'programs': { 'port': 8090, 'log': BOK_CHOY_LOG_DIR / "bok_choy_programs.log", }, 'ecommerce': { 'port': 8043, 'log': BOK_CHOY_LOG_DIR / "bok_choy_ecommerce.log", } } # Mongo databases that will be dropped before/after the tests run BOK_CHOY_MONGO_DATABASE = "test" BOK_CHOY_CACHE = memcache.Client(['0.0.0.0:11211'], debug=0) # Test Ids Directory TEST_DIR = REPO_ROOT / ".testids" # Files used to run each of the js test suites # TODO: Store this as a dict. Order seems to matter for some # reason. See issue TE-415. KARMA_CONFIG_FILES = [ REPO_ROOT / 'cms/static/karma_cms.conf.js', REPO_ROOT / 'cms/static/karma_cms_squire.conf.js', REPO_ROOT / 'lms/static/karma_lms.conf.js', REPO_ROOT / 'lms/static/karma_lms_coffee.conf.js', REPO_ROOT / 'common/lib/xmodule/xmodule/js/karma_xmodule.conf.js', REPO_ROOT / 'common/static/karma_common.conf.js', REPO_ROOT / 'common/static/karma_common_requirejs.conf.js', ] JS_TEST_ID_KEYS = [ 'cms', 'cms-squire', 'lms', 'lms-coffee', 'xmodule', 'common', 'common-requirejs' ] JS_REPORT_DIR = REPORT_DIR / 'javascript' # Directories used for common/lib/ tests LIB_TEST_DIRS = [] for item in (REPO_ROOT / "common/lib").listdir(): if (REPO_ROOT / 'common/lib' / item).isdir(): LIB_TEST_DIRS.append(path("common/lib") / item.basename()) LIB_TEST_DIRS.append(path("pavelib/paver_tests")) # Directory for i18n test reports I18N_REPORT_DIR = REPORT_DIR / 'i18n' # Service variant (lms, cms, etc.) configured with an environment variable # We use this to determine which envs.json file to load. SERVICE_VARIANT = os.environ.get('SERVICE_VARIANT', None) # If service variant not configured in env, then pass the correct # environment for lms / cms if not SERVICE_VARIANT: # this will intentionally catch ""; if any(i in sys.argv[1:] for i in ('cms', 'studio')): SERVICE_VARIANT = 'cms' else: SERVICE_VARIANT = 'lms' @lazy def env_tokens(self): """ Return a dict of environment settings. If we couldn't find the JSON file, issue a warning and return an empty dict. """ # Find the env JSON file if self.SERVICE_VARIANT: env_path = self.REPO_ROOT.parent / "{service}.env.json".format(service=self.SERVICE_VARIANT) else: env_path = path("env.json").abspath() # If the file does not exist, here or one level up, # issue a warning and return an empty dict if not env_path.isfile(): env_path = env_path.parent.parent / env_path.basename() if not env_path.isfile(): print( "Warning: could not find environment JSON file " "at '{path}'".format(path=env_path), file=sys.stderr, ) return dict() # Otherwise, load the file as JSON and return the resulting dict try: with open(env_path) as env_file: return json.load(env_file) except ValueError: print( "Error: Could not parse JSON " "in {path}".format(path=env_path), file=sys.stderr, ) sys.exit(1) @lazy def feature_flags(self): """ Return a dictionary of feature flags configured by the environment. """ return self.env_tokens.get('FEATURES', dict())
agpl-3.0
[ 624, 199, 4433, 3423, 367, 8697, 3734, 2202, 14, 199, 624, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 646, 747, 199, 646, 984, 199, 646, 2022, 199, 504, 9617, 492, 9617, 199, 504, 931, 492, 6912, 465, 931, 199, 646, 21598, 421, 199, 533, 31543, 8, 785, 304, 272, 408, 272, 7190, 2556, 3595, 314, 6451, 3734, 14, 272, 408, 339, 327, 12826, 402, 314, 6135, 7611, 334, 8268, 13, 3246, 9, 272, 5363, 1512, 63, 5441, 275, 931, 3460, 493, 28634, 4832, 1252, 1708, 14, 1708, 14, 1708, 339, 327, 799, 5203, 15191, 272, 27357, 63, 3022, 275, 5363, 1512, 63, 5441, 1182, 283, 15629, 7, 272, 19357, 14673, 51, 63, 3022, 275, 27357, 63, 3022, 1182, 283, 6759, 7, 339, 327, 2018, 2882, 7606, 272, 18280, 63, 19052, 1254, 540, 35, 275, 5363, 1512, 63, 5441, 1182, 3680, 5899, 1456, 67, 2, 339, 327, 699, 745, 63, 2239, 89, 7606, 272, 699, 3593, 63, 10465, 57, 63, 3022, 275, 5363, 1512, 63, 5441, 1182, 298, 2330, 2, 1182, 298, 396, 2, 1182, 298, 28519, 2, 272, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 275, 5363, 1512, 63, 5441, 1182, 298, 396, 63, 1231, 2, 1182, 298, 793, 2, 272, 699, 3593, 63, 10465, 57, 63, 17356, 63, 3022, 275, 27357, 63, 3022, 1182, 298, 656, 75, 63, 2239, 89, 2, 272, 699, 3593, 63, 10465, 57, 63, 33, 845, 57, 63, 17356, 63, 3022, 275, 27357, 63, 3022, 1182, 298, 65, 845, 89, 2, 272, 699, 3593, 63, 10465, 57, 63, 19052, 1254, 540, 35, 275, 699, 3593, 63, 10465, 57, 63, 3022, 1182, 3680, 5899, 1456, 67, 2, 272, 699, 3593, 63, 10465, 57, 63, 33, 845, 57, 63, 19052, 1254, 540, 35, 275, 699, 3593, 63, 10465, 57, 63, 3022, 1182, 3680, 65, 845, 89, 5899, 1456, 67, 2, 272, 699, 3593, 63, 10465, 57, 63, 33, 845, 57, 63, 20519, 63, 31490, 63, 3817, 275, 334, 267, 5363, 1512, 63, 5441, 1182, 298, 932, 63, 3112, 2, 1182, 298, 8268, 13, 4229, 13, 65, 845, 89, 13, 4423, 2, 1182, 267, 298, 773, 2, 1182, 298, 4229, 63, 65, 845, 89, 63, 4423, 14, 3596, 2, 272, 776, 339, 510, 33, 845, 57, 35, 4307, 19650, 63, 17356, 63, 3022, 275, 27357, 63, 3022, 1182, 298, 387, 845, 89, 23972, 2, 272, 510, 33, 845, 57, 35, 4307, 19650, 63, 19052, 1254, 540, 35, 275, 699, 3593, 63, 10465, 57, 63, 3022, 1182, 3680, 387, 845, 89, 23972, 5899, 1456, 67, 2, 339, 327, 982, 663, 12, 5324, 13924, 367, 1255, 315, 298, 3235, 2, 6602, 14, 272, 327, 710, 2446, 12016, 402, 642, 365, 370, 4868, 626, 314, 13924, 883, 506, 283, 2482, 300, 1915, 7, 272, 327, 315, 314, 2446, 29537, 6369, 3906, 1928, 32592, 314, 13924, 687, 1163, 272, 327, 1900, 7124, 14, 2104, 2257, 16367, 15, 4776, 12, 642, 9296, 1133, 506, 4346, 14, 272, 340, 747, 14, 2314, 14, 362, 480, 3234, 7816, 401, 488, 304, 267, 11814, 63, 495, 275, 298, 10810, 63, 13536, 908, 8, 736, 14, 2314, 14, 362, 480, 3234, 7816, 2237, 267, 699, 3593, 63, 10465, 57, 63, 17356, 63, 3022, 275, 699, 3593, 63, 10465, 57, 63, 17356, 63, 3022, 1182, 11814, 63, 495, 267, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 275, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 1182, 11814, 63, 495, 339, 327, 2104, 314, 900, 3769, 12, 22312, 787, 1202, 701, 3865, 314, 330, 745, 13, 2239, 89, 436, 4691, 84, 3683, 4729, 554, 2295, 272, 327, 2104, 642, 4499, 12, 314, 22312, 2559, 365, 5544, 16180, 315, 314, 5634, 1145, 2797, 298, 351, 6322, 2, 272, 327, 2382, 1163, 4691, 84, 3683, 2897, 365, 5489, 14, 272, 699, 3593, 63, 10465, 57, 63, 840, 2533, 63, 3022, 275, 5363, 1512, 63, 5441, 1182, 298, 2330, 2, 1182, 298, 16432, 2, 1182, 298, 351, 6322, 2, 339, 327, 15191, 626, 22010, 787, 19733, 687, 272, 812, 11259, 47, 63, 10187, 63, 3022, 275, 5363, 1512, 63, 5441, 1182, 298, 396, 63, 1231, 2, 1182, 298, 576, 2, 1182, 298, 3722, 2, 339, 699, 3593, 63, 10465, 57, 63, 6613, 51, 275, 469, 267, 283, 15807, 356, 469, 288, 283, 719, 356, 1695, 8262, 12, 288, 283, 793, 356, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 1182, 298, 656, 75, 63, 2239, 89, 63, 15807, 14, 793, 2, 267, 1660, 267, 283, 10781, 356, 469, 288, 283, 719, 356, 5939, 2192, 12, 288, 283, 793, 356, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 1182, 298, 656, 75, 63, 2239, 89, 63, 19806, 14, 793, 2, 267, 789, 272, 789, 339, 699, 3593, 63, 10465, 57, 63, 840, 2533, 51, 275, 469, 398, 283, 88, 1825, 356, 469, 288, 283, 719, 356, 1695, 11189, 12, 288, 283, 793, 356, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 1182, 298, 656, 75, 63, 2239, 89, 63, 88, 1825, 14, 793, 401, 288, 283, 888, 356, 283, 2683, 63, 12542, 63, 633, 29, 1014, 921, 16, 14, 16, 14, 16, 14, 16, 26, 24, 10531, 15, 396, 15, 2683, 63, 12542, 297, 267, 1660, 398, 283, 11131, 356, 469, 288, 283, 719, 356, 1695, 10531, 12, 288, 283, 793, 356, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 1182, 298, 656, 75, 63, 2239, 89, 63, 11131, 14, 793, 401, 288, 283, 888, 356, 3260, 267, 1660, 398, 283, 6223, 356, 469, 288, 283, 719, 356, 841, 5308, 12, 288, 283, 793, 356, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 1182, 298, 656, 75, 63, 2239, 89, 63, 6223, 14, 793, 401, 267, 1660, 398, 283, 3722, 356, 469, 288, 283, 719, 356, 1695, 11956, 12, 288, 283, 793, 356, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 1182, 298, 656, 75, 63, 2239, 89, 63, 3722, 63, 4553, 14, 793, 401, 288, 283, 888, 356, 298, 1231, 63, 694, 7622, 1674, 908, 8, 20142, 63, 10187, 63, 3022, 395, 267, 1660, 398, 283, 9788, 356, 469, 288, 283, 719, 356, 9137, 1257, 12, 288, 283, 793, 356, 699, 3593 ]
[ 199, 4433, 3423, 367, 8697, 3734, 2202, 14, 199, 624, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 646, 747, 199, 646, 984, 199, 646, 2022, 199, 504, 9617, 492, 9617, 199, 504, 931, 492, 6912, 465, 931, 199, 646, 21598, 421, 199, 533, 31543, 8, 785, 304, 272, 408, 272, 7190, 2556, 3595, 314, 6451, 3734, 14, 272, 408, 339, 327, 12826, 402, 314, 6135, 7611, 334, 8268, 13, 3246, 9, 272, 5363, 1512, 63, 5441, 275, 931, 3460, 493, 28634, 4832, 1252, 1708, 14, 1708, 14, 1708, 339, 327, 799, 5203, 15191, 272, 27357, 63, 3022, 275, 5363, 1512, 63, 5441, 1182, 283, 15629, 7, 272, 19357, 14673, 51, 63, 3022, 275, 27357, 63, 3022, 1182, 283, 6759, 7, 339, 327, 2018, 2882, 7606, 272, 18280, 63, 19052, 1254, 540, 35, 275, 5363, 1512, 63, 5441, 1182, 3680, 5899, 1456, 67, 2, 339, 327, 699, 745, 63, 2239, 89, 7606, 272, 699, 3593, 63, 10465, 57, 63, 3022, 275, 5363, 1512, 63, 5441, 1182, 298, 2330, 2, 1182, 298, 396, 2, 1182, 298, 28519, 2, 272, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 275, 5363, 1512, 63, 5441, 1182, 298, 396, 63, 1231, 2, 1182, 298, 793, 2, 272, 699, 3593, 63, 10465, 57, 63, 17356, 63, 3022, 275, 27357, 63, 3022, 1182, 298, 656, 75, 63, 2239, 89, 2, 272, 699, 3593, 63, 10465, 57, 63, 33, 845, 57, 63, 17356, 63, 3022, 275, 27357, 63, 3022, 1182, 298, 65, 845, 89, 2, 272, 699, 3593, 63, 10465, 57, 63, 19052, 1254, 540, 35, 275, 699, 3593, 63, 10465, 57, 63, 3022, 1182, 3680, 5899, 1456, 67, 2, 272, 699, 3593, 63, 10465, 57, 63, 33, 845, 57, 63, 19052, 1254, 540, 35, 275, 699, 3593, 63, 10465, 57, 63, 3022, 1182, 3680, 65, 845, 89, 5899, 1456, 67, 2, 272, 699, 3593, 63, 10465, 57, 63, 33, 845, 57, 63, 20519, 63, 31490, 63, 3817, 275, 334, 267, 5363, 1512, 63, 5441, 1182, 298, 932, 63, 3112, 2, 1182, 298, 8268, 13, 4229, 13, 65, 845, 89, 13, 4423, 2, 1182, 267, 298, 773, 2, 1182, 298, 4229, 63, 65, 845, 89, 63, 4423, 14, 3596, 2, 272, 776, 339, 510, 33, 845, 57, 35, 4307, 19650, 63, 17356, 63, 3022, 275, 27357, 63, 3022, 1182, 298, 387, 845, 89, 23972, 2, 272, 510, 33, 845, 57, 35, 4307, 19650, 63, 19052, 1254, 540, 35, 275, 699, 3593, 63, 10465, 57, 63, 3022, 1182, 3680, 387, 845, 89, 23972, 5899, 1456, 67, 2, 339, 327, 982, 663, 12, 5324, 13924, 367, 1255, 315, 298, 3235, 2, 6602, 14, 272, 327, 710, 2446, 12016, 402, 642, 365, 370, 4868, 626, 314, 13924, 883, 506, 283, 2482, 300, 1915, 7, 272, 327, 315, 314, 2446, 29537, 6369, 3906, 1928, 32592, 314, 13924, 687, 1163, 272, 327, 1900, 7124, 14, 2104, 2257, 16367, 15, 4776, 12, 642, 9296, 1133, 506, 4346, 14, 272, 340, 747, 14, 2314, 14, 362, 480, 3234, 7816, 401, 488, 304, 267, 11814, 63, 495, 275, 298, 10810, 63, 13536, 908, 8, 736, 14, 2314, 14, 362, 480, 3234, 7816, 2237, 267, 699, 3593, 63, 10465, 57, 63, 17356, 63, 3022, 275, 699, 3593, 63, 10465, 57, 63, 17356, 63, 3022, 1182, 11814, 63, 495, 267, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 275, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 1182, 11814, 63, 495, 339, 327, 2104, 314, 900, 3769, 12, 22312, 787, 1202, 701, 3865, 314, 330, 745, 13, 2239, 89, 436, 4691, 84, 3683, 4729, 554, 2295, 272, 327, 2104, 642, 4499, 12, 314, 22312, 2559, 365, 5544, 16180, 315, 314, 5634, 1145, 2797, 298, 351, 6322, 2, 272, 327, 2382, 1163, 4691, 84, 3683, 2897, 365, 5489, 14, 272, 699, 3593, 63, 10465, 57, 63, 840, 2533, 63, 3022, 275, 5363, 1512, 63, 5441, 1182, 298, 2330, 2, 1182, 298, 16432, 2, 1182, 298, 351, 6322, 2, 339, 327, 15191, 626, 22010, 787, 19733, 687, 272, 812, 11259, 47, 63, 10187, 63, 3022, 275, 5363, 1512, 63, 5441, 1182, 298, 396, 63, 1231, 2, 1182, 298, 576, 2, 1182, 298, 3722, 2, 339, 699, 3593, 63, 10465, 57, 63, 6613, 51, 275, 469, 267, 283, 15807, 356, 469, 288, 283, 719, 356, 1695, 8262, 12, 288, 283, 793, 356, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 1182, 298, 656, 75, 63, 2239, 89, 63, 15807, 14, 793, 2, 267, 1660, 267, 283, 10781, 356, 469, 288, 283, 719, 356, 5939, 2192, 12, 288, 283, 793, 356, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 1182, 298, 656, 75, 63, 2239, 89, 63, 19806, 14, 793, 2, 267, 789, 272, 789, 339, 699, 3593, 63, 10465, 57, 63, 840, 2533, 51, 275, 469, 398, 283, 88, 1825, 356, 469, 288, 283, 719, 356, 1695, 11189, 12, 288, 283, 793, 356, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 1182, 298, 656, 75, 63, 2239, 89, 63, 88, 1825, 14, 793, 401, 288, 283, 888, 356, 283, 2683, 63, 12542, 63, 633, 29, 1014, 921, 16, 14, 16, 14, 16, 14, 16, 26, 24, 10531, 15, 396, 15, 2683, 63, 12542, 297, 267, 1660, 398, 283, 11131, 356, 469, 288, 283, 719, 356, 1695, 10531, 12, 288, 283, 793, 356, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 1182, 298, 656, 75, 63, 2239, 89, 63, 11131, 14, 793, 401, 288, 283, 888, 356, 3260, 267, 1660, 398, 283, 6223, 356, 469, 288, 283, 719, 356, 841, 5308, 12, 288, 283, 793, 356, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 1182, 298, 656, 75, 63, 2239, 89, 63, 6223, 14, 793, 401, 267, 1660, 398, 283, 3722, 356, 469, 288, 283, 719, 356, 1695, 11956, 12, 288, 283, 793, 356, 699, 3593, 63, 10465, 57, 63, 4947, 63, 3022, 1182, 298, 656, 75, 63, 2239, 89, 63, 3722, 63, 4553, 14, 793, 401, 288, 283, 888, 356, 298, 1231, 63, 694, 7622, 1674, 908, 8, 20142, 63, 10187, 63, 3022, 395, 267, 1660, 398, 283, 9788, 356, 469, 288, 283, 719, 356, 9137, 1257, 12, 288, 283, 793, 356, 699, 3593, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
smanolloff/SublimeLinter3
docs/conf.py
4
8489
# -*- coding: utf-8 -*- """SublimeLinter documentation build configuration file. Created by sphinx-quickstart on Sun Dec 29 11:05:37 2013. This file is execfile()d with the current directory set to its containing dir. Note that not all possible configuration values are present in this autogenerated file. All configuration values have a default; values that are commented out serve to show the default. """ import os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. #sys.path.insert(0, os.path.abspath('.')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = u'SublimeLinter' copyright = u'2015, Blake Grotewold' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = '3.4.24' # The full version, including alpha/beta/rc tags. release = '3.4.24' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ["_build"] # The reST default role (used for this markup: `text`) to use for all # documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. #keep_warnings = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. on_rtd = os.environ.get('READTHEDOCS', None) == 'True' if not on_rtd: # only import and set the theme if we're building docs locally import sphinx_rtd_theme html_theme = 'sphinx_rtd_theme' html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] else: html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = None # The name for this set of Sphinx documents. If None, it defaults to # "<project> v<release> documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. #html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. #html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. #html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a <link> tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'SublimeLinterdoc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ ('index', 'SublimeLinter.tex', u'SublimeLinter Documentation', u'Blake Grotewold', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'sublimelinter', u'SublimeLinter Documentation', [u'Blake Grotewold'], 1) ] # If true, show URL addresses after external links. #man_show_urls = False # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ ('index', 'SublimeLinter', u'SublimeLinter Documentation', u'Blake Grotewold', 'SublimeLinter', 'Interactive code linting framework for Sublime Text 3.', 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. #texinfo_no_detailmenu = False
mit
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 2610, 18687, 44, 1058, 3794, 1900, 2897, 570, 14, 199, 199, 10502, 701, 15882, 13, 28957, 641, 25625, 13966, 7349, 4119, 26, 1717, 26, 1401, 6171, 14, 199, 199, 2765, 570, 365, 22711, 342, 68, 543, 314, 1453, 2082, 663, 370, 2399, 199, 16133, 2935, 14, 199, 199, 7443, 626, 440, 1006, 3962, 2897, 1338, 787, 3451, 315, 642, 199, 6898, 16741, 570, 14, 199, 199, 2422, 2897, 1338, 1172, 282, 849, 27, 1338, 626, 787, 21804, 734, 199, 4909, 370, 2498, 314, 849, 14, 199, 624, 199, 199, 646, 747, 199, 199, 3, 982, 5478, 334, 269, 4621, 370, 2213, 543, 29973, 9, 787, 315, 4573, 2082, 12, 199, 3, 1050, 3520, 6602, 370, 984, 14, 515, 2348, 14, 982, 314, 2082, 365, 3847, 370, 314, 199, 3, 3794, 1738, 12, 675, 747, 14, 515, 14, 4832, 370, 1852, 652, 3679, 12, 2839, 9164, 2348, 14, 199, 3, 1274, 14, 515, 14, 3176, 8, 16, 12, 747, 14, 515, 14, 4832, 24535, 199, 199, 3, 1553, 1696, 2897, 9527, 199, 199, 3, 982, 2195, 3794, 4839, 282, 13460, 10229, 1015, 12, 1174, 652, 2348, 14, 199, 3, 10065, 63, 8008, 275, 283, 17, 14, 16, 7, 199, 199, 3, 2654, 1263, 10229, 3329, 859, 1561, 2348, 12, 465, 3326, 14, 9322, 883, 506, 199, 3, 5478, 17262, 543, 10229, 334, 4579, 283, 8008, 14, 832, 24915, 503, 2195, 3537, 199, 3, 7869, 14, 199, 5359, 275, 942, 199, 199, 3, 2654, 1263, 3792, 626, 1395, 7009, 2348, 12, 3847, 370, 642, 2082, 14, 199, 5876, 63, 515, 275, 4044, 5876, 418, 199, 199, 3, 710, 4739, 402, 1350, 6203, 14, 199, 1365, 63, 4511, 275, 1987, 8332, 7, 199, 199, 3, 710, 2644, 402, 1350, 1584, 14, 199, 3, 1365, 63, 2991, 275, 283, 1624, 13, 24, 13, 4093, 7, 199, 199, 3, 710, 5288, 28310, 2213, 14, 199, 4133, 63, 1301, 275, 283, 1080, 7, 199, 199, 3, 1696, 2556, 3595, 314, 2199, 14, 199, 1715, 275, 399, 7, 2610, 18687, 44, 1058, 7, 199, 7307, 275, 399, 7, 7806, 12, 699, 416, 415, 598, 22665, 87, 1753, 7, 199, 199, 3, 710, 1015, 2256, 367, 314, 2199, 1265, 3984, 29904, 12, 17795, 465, 8343, 367, 199, 3, 1204, 1023, 92, 436, 1204, 3221, 18712, 2597, 1202, 315, 7750, 1163, 9825, 23088, 314, 199, 3, 6137, 8247, 14, 199, 3, 199, 3, 710, 3974, 1323, 14, 57, 1015, 14, 199, 1023, 275, 283, 19, 14, 20, 14, 1194, 7, 199, 3, 710, 2615, 1015, 12, 5893, 5131, 15, 5683, 15, 1195, 3762, 14, 199, 3221, 275, 283, 19, 14, 20, 14, 1194, 7, 199, 199, 3, 710, 2637, 367, 1564, 18392, 701, 10229, 14, 21751, 370, 3794, 199, 3, 367, 282, 769, 402, 3748, 10815, 14, 199, 3, 3671, 275, 488, 199, 199, 3, 6006, 787, 2877, 1511, 367, 15810, 1204, 8136, 25004, 1902, 12, 1265, 663, 11168, 370, 2005, 199, 3, 2222, 13, 3910, 574, 12, 2066, 652, 365, 1202, 26, 199, 3, 8136, 275, 2125, 199, 3, 19524, 12, 11168, 63, 5045, 365, 1202, 465, 314, 1475, 367, 282, 14053, 1240, 14, 199, 3, 8136, 63, 5045, 275, 1543, 34, 450, 68, 12, 450, 57, 7, 199, 199, 3, 3820, 402, 7970, 12, 3847, 370, 1350, 2082, 12, 626, 1336, 1584, 436, 199, 3, 6602, 370, 3686, 1380, 10023, 367, 1350, 1584, 14, 199, 5473, 63, 7435, 275, 2097, 63, 1506, 937, 199, 199, 3, 710, 20883, 849, 4719, 334, 2972, 367, 642, 9189, 26, 658, 505, 10522, 370, 675, 367, 1006, 199, 3, 8247, 14, 199, 3, 885, 63, 3756, 275, 488, 199, 199, 3, 982, 2549, 12, 26380, 911, 506, 11544, 370, 520, 1532, 26, 5423, 14, 8059, 13, 4443, 1318, 14, 199, 3, 525, 63, 1593, 63, 25510, 275, 715, 199, 199, 3, 982, 2549, 12, 314, 1453, 859, 536, 911, 506, 20247, 370, 1006, 1369, 199, 3, 4137, 16194, 334, 10180, 465, 2508, 805, 32469, 199, 3, 525, 63, 578, 63, 1247, 275, 715, 199, 199, 3, 982, 2549, 12, 3420, 2502, 436, 28966, 13502, 911, 506, 9164, 315, 314, 199, 3, 1072, 14, 9322, 787, 5525, 701, 849, 14, 199, 3, 2384, 63, 8149, 275, 756, 199, 199, 3, 710, 536, 402, 314, 14493, 334, 7093, 22437, 9, 3449, 370, 675, 14, 199, 12173, 63, 2487, 275, 283, 8008, 7, 199, 199, 3, 437, 769, 402, 5525, 13158, 367, 859, 1478, 13351, 14, 199, 3, 27555, 63, 2330, 63, 1861, 275, 942, 199, 199, 3, 982, 2549, 12, 4215, 3598, 465, 298, 2253, 1245, 2, 26603, 315, 314, 6137, 8247, 14, 199, 3, 3250, 63, 5451, 275, 756, 421, 199, 3, 1553, 8394, 367, 4163, 1072, 11016, 10965, 199, 199, 3, 710, 8879, 370, 675, 367, 4163, 436, 4163, 15456, 6497, 14, 221, 1666, 314, 3794, 367, 199, 3, 282, 769, 402, 6762, 17915, 14, 199, 265, 63, 29048, 275, 747, 14, 2314, 14, 362, 360, 5670, 2080, 1149, 47, 3298, 297, 488, 9, 508, 283, 549, 7, 199, 199, 692, 440, 641, 63, 29048, 26, 221, 327, 1454, 492, 436, 663, 314, 8879, 340, 781, 3984, 10015, 9149, 17738, 272, 492, 15882, 63, 29048, 63, 7915, 272, 3517, 63, 7915, 275, 283, 8008, 63, 29048, 63, 7915, 7, 272, 3517, 63, 7915, 63, 515, 275, 359, 8008, 63, 29048, 63, 7915, 14, 362, 63, 1360, 63, 7915, 63, 515, 5106, 199, 2836, 26, 272, 3517, 63, 7915, 275, 283, 885, 7, 199, 199, 3, 23978, 1511, 787, 8879, 13, 6100, 436, 17551, 314, 3648, 436, 23109, 402, 282, 8879, 199, 3, 9848, 14, 221, 2104, 282, 769, 402, 1511, 2808, 367, 1924, 8879, 12, 1937, 314, 199, 3, 3794, 14, 199, 3, 1360, 63, 7915, 63, 1419, 275, 1052, 199, 199, 3, 2654, 1263, 3792, 626, 1395, 3537, 17915, 2348, 12, 3847, 370, 642, 2082, 14, 199, 3, 1360, 63, 7915, 63, 515, 275, 488, 199, 199, 3, 710, 536, 367, 642, 663, 402, 10229, 8247, 14, 221, 982, 488, 12, 652, 4243, 370, 199, 3, 3886, 1715, 30, 373, 28, 3221, 30, 3794, 1674, 199, 3, 1360, 63, 1213, 275, 488, 199, 199 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 2610, 18687, 44, 1058, 3794, 1900, 2897, 570, 14, 199, 199, 10502, 701, 15882, 13, 28957, 641, 25625, 13966, 7349, 4119, 26, 1717, 26, 1401, 6171, 14, 199, 199, 2765, 570, 365, 22711, 342, 68, 543, 314, 1453, 2082, 663, 370, 2399, 199, 16133, 2935, 14, 199, 199, 7443, 626, 440, 1006, 3962, 2897, 1338, 787, 3451, 315, 642, 199, 6898, 16741, 570, 14, 199, 199, 2422, 2897, 1338, 1172, 282, 849, 27, 1338, 626, 787, 21804, 734, 199, 4909, 370, 2498, 314, 849, 14, 199, 624, 199, 199, 646, 747, 199, 199, 3, 982, 5478, 334, 269, 4621, 370, 2213, 543, 29973, 9, 787, 315, 4573, 2082, 12, 199, 3, 1050, 3520, 6602, 370, 984, 14, 515, 2348, 14, 982, 314, 2082, 365, 3847, 370, 314, 199, 3, 3794, 1738, 12, 675, 747, 14, 515, 14, 4832, 370, 1852, 652, 3679, 12, 2839, 9164, 2348, 14, 199, 3, 1274, 14, 515, 14, 3176, 8, 16, 12, 747, 14, 515, 14, 4832, 24535, 199, 199, 3, 1553, 1696, 2897, 9527, 199, 199, 3, 982, 2195, 3794, 4839, 282, 13460, 10229, 1015, 12, 1174, 652, 2348, 14, 199, 3, 10065, 63, 8008, 275, 283, 17, 14, 16, 7, 199, 199, 3, 2654, 1263, 10229, 3329, 859, 1561, 2348, 12, 465, 3326, 14, 9322, 883, 506, 199, 3, 5478, 17262, 543, 10229, 334, 4579, 283, 8008, 14, 832, 24915, 503, 2195, 3537, 199, 3, 7869, 14, 199, 5359, 275, 942, 199, 199, 3, 2654, 1263, 3792, 626, 1395, 7009, 2348, 12, 3847, 370, 642, 2082, 14, 199, 5876, 63, 515, 275, 4044, 5876, 418, 199, 199, 3, 710, 4739, 402, 1350, 6203, 14, 199, 1365, 63, 4511, 275, 1987, 8332, 7, 199, 199, 3, 710, 2644, 402, 1350, 1584, 14, 199, 3, 1365, 63, 2991, 275, 283, 1624, 13, 24, 13, 4093, 7, 199, 199, 3, 710, 5288, 28310, 2213, 14, 199, 4133, 63, 1301, 275, 283, 1080, 7, 199, 199, 3, 1696, 2556, 3595, 314, 2199, 14, 199, 1715, 275, 399, 7, 2610, 18687, 44, 1058, 7, 199, 7307, 275, 399, 7, 7806, 12, 699, 416, 415, 598, 22665, 87, 1753, 7, 199, 199, 3, 710, 1015, 2256, 367, 314, 2199, 1265, 3984, 29904, 12, 17795, 465, 8343, 367, 199, 3, 1204, 1023, 92, 436, 1204, 3221, 18712, 2597, 1202, 315, 7750, 1163, 9825, 23088, 314, 199, 3, 6137, 8247, 14, 199, 3, 199, 3, 710, 3974, 1323, 14, 57, 1015, 14, 199, 1023, 275, 283, 19, 14, 20, 14, 1194, 7, 199, 3, 710, 2615, 1015, 12, 5893, 5131, 15, 5683, 15, 1195, 3762, 14, 199, 3221, 275, 283, 19, 14, 20, 14, 1194, 7, 199, 199, 3, 710, 2637, 367, 1564, 18392, 701, 10229, 14, 21751, 370, 3794, 199, 3, 367, 282, 769, 402, 3748, 10815, 14, 199, 3, 3671, 275, 488, 199, 199, 3, 6006, 787, 2877, 1511, 367, 15810, 1204, 8136, 25004, 1902, 12, 1265, 663, 11168, 370, 2005, 199, 3, 2222, 13, 3910, 574, 12, 2066, 652, 365, 1202, 26, 199, 3, 8136, 275, 2125, 199, 3, 19524, 12, 11168, 63, 5045, 365, 1202, 465, 314, 1475, 367, 282, 14053, 1240, 14, 199, 3, 8136, 63, 5045, 275, 1543, 34, 450, 68, 12, 450, 57, 7, 199, 199, 3, 3820, 402, 7970, 12, 3847, 370, 1350, 2082, 12, 626, 1336, 1584, 436, 199, 3, 6602, 370, 3686, 1380, 10023, 367, 1350, 1584, 14, 199, 5473, 63, 7435, 275, 2097, 63, 1506, 937, 199, 199, 3, 710, 20883, 849, 4719, 334, 2972, 367, 642, 9189, 26, 658, 505, 10522, 370, 675, 367, 1006, 199, 3, 8247, 14, 199, 3, 885, 63, 3756, 275, 488, 199, 199, 3, 982, 2549, 12, 26380, 911, 506, 11544, 370, 520, 1532, 26, 5423, 14, 8059, 13, 4443, 1318, 14, 199, 3, 525, 63, 1593, 63, 25510, 275, 715, 199, 199, 3, 982, 2549, 12, 314, 1453, 859, 536, 911, 506, 20247, 370, 1006, 1369, 199, 3, 4137, 16194, 334, 10180, 465, 2508, 805, 32469, 199, 3, 525, 63, 578, 63, 1247, 275, 715, 199, 199, 3, 982, 2549, 12, 3420, 2502, 436, 28966, 13502, 911, 506, 9164, 315, 314, 199, 3, 1072, 14, 9322, 787, 5525, 701, 849, 14, 199, 3, 2384, 63, 8149, 275, 756, 199, 199, 3, 710, 536, 402, 314, 14493, 334, 7093, 22437, 9, 3449, 370, 675, 14, 199, 12173, 63, 2487, 275, 283, 8008, 7, 199, 199, 3, 437, 769, 402, 5525, 13158, 367, 859, 1478, 13351, 14, 199, 3, 27555, 63, 2330, 63, 1861, 275, 942, 199, 199, 3, 982, 2549, 12, 4215, 3598, 465, 298, 2253, 1245, 2, 26603, 315, 314, 6137, 8247, 14, 199, 3, 3250, 63, 5451, 275, 756, 421, 199, 3, 1553, 8394, 367, 4163, 1072, 11016, 10965, 199, 199, 3, 710, 8879, 370, 675, 367, 4163, 436, 4163, 15456, 6497, 14, 221, 1666, 314, 3794, 367, 199, 3, 282, 769, 402, 6762, 17915, 14, 199, 265, 63, 29048, 275, 747, 14, 2314, 14, 362, 360, 5670, 2080, 1149, 47, 3298, 297, 488, 9, 508, 283, 549, 7, 199, 199, 692, 440, 641, 63, 29048, 26, 221, 327, 1454, 492, 436, 663, 314, 8879, 340, 781, 3984, 10015, 9149, 17738, 272, 492, 15882, 63, 29048, 63, 7915, 272, 3517, 63, 7915, 275, 283, 8008, 63, 29048, 63, 7915, 7, 272, 3517, 63, 7915, 63, 515, 275, 359, 8008, 63, 29048, 63, 7915, 14, 362, 63, 1360, 63, 7915, 63, 515, 5106, 199, 2836, 26, 272, 3517, 63, 7915, 275, 283, 885, 7, 199, 199, 3, 23978, 1511, 787, 8879, 13, 6100, 436, 17551, 314, 3648, 436, 23109, 402, 282, 8879, 199, 3, 9848, 14, 221, 2104, 282, 769, 402, 1511, 2808, 367, 1924, 8879, 12, 1937, 314, 199, 3, 3794, 14, 199, 3, 1360, 63, 7915, 63, 1419, 275, 1052, 199, 199, 3, 2654, 1263, 3792, 626, 1395, 3537, 17915, 2348, 12, 3847, 370, 642, 2082, 14, 199, 3, 1360, 63, 7915, 63, 515, 275, 488, 199, 199, 3, 710, 536, 367, 642, 663, 402, 10229, 8247, 14, 221, 982, 488, 12, 652, 4243, 370, 199, 3, 3886, 1715, 30, 373, 28, 3221, 30, 3794, 1674, 199, 3, 1360, 63, 1213, 275, 488, 199, 199, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
diegoingaramo/img-search-al
node_modules/googleapis/node_modules/google-auth-library/node_modules/gtoken/node_modules/google-p12-pem/node_modules/node-forge/tests/server.py
171
5756
#!/usr/bin/env python """ SSL server for Forge tests. - The server changes to the directory of the server script. - SSL uses "server.key" and "server.crt". - Sever performs basic static file serving. - Starts Flash cross domain policy file server. - Defaults to HTTP/HTTPS port 19400. - Defaults to Flash socket policy port 19945. $ ./server.py [options] If you just need a simple HTTP server, also consider: $ python -m SimpleHTTPServer 19400 """ from multiprocessing import Process from optparse import OptionParser import SimpleHTTPServer import SocketServer import os import sys import time # Try to import special Forge SSL module with session cache support # Using the built directory directly python_version = "python" + sys.version[:3] sys.path.insert(0, os.path.join( os.path.dirname(os.path.realpath(__file__)), "..", "dist", "forge_ssl", "lib", python_version, "site-packages")) try: from forge import ssl have_ssl_sessions = True have_ssl = True except ImportError: have_ssl_sessions = False try: import ssl have_ssl = True except ImportError: have_ssl = False # Set address reuse for all TCPServers SocketServer.TCPServer.allow_reuse_address = True # The policy file # NOTE: This format is very strict. Edit with care. policy_file = """\ <?xml version="1.0"?>\ <!DOCTYPE cross-domain-policy\ SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">\ <cross-domain-policy>\ <allow-access-from domain="*" to-ports="*"/>\ </cross-domain-policy>\0""" class PolicyHandler(SocketServer.BaseRequestHandler): """ The RequestHandler class for our server. Returns a policy file when requested. """ def handle(self): # get some data # TODO: make this more robust (while loop, etc) self.data = self.request.recv(1024).rstrip('\0') #print "%s wrote:" % self.client_address[0] #print repr(self.data) # if policy file request, send the file. if self.data == "<policy-file-request/>": print "Policy server request from %s." % (self.client_address[0]) self.request.send(policy_file) else: print "Policy server received junk from %s: \"%s\"" % \ (self.client_address[0], repr(self.data)) def create_policy_server(options): """Start a policy server""" print "Policy serving from %d." % (options.policy_port) policyd = SocketServer.TCPServer((options.host, options.policy_port), PolicyHandler) return policyd class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): pass def create_http_server(options, script_dir): """Start a static file server""" # use UTF-8 encoding for javascript files m = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map m['.js'] = 'application/javascript;charset=UTF-8' Handler = SimpleHTTPServer.SimpleHTTPRequestHandler # httpd = SocketServer.TCPServer((options.host, options.port), Handler) httpd = ThreadedTCPServer((options.host, options.port), Handler) if options.tls: if not have_ssl: raise Exception("SSL support from Python 2.7 or later is required.") # setup session args if we session support sess_args = {} if have_ssl_sessions: sess_args["sess_id_ctx"] = "forgetest" else: print "Forge SSL with session cache not available, using standard version." httpd.socket = ssl.wrap_socket( httpd.socket, keyfile="server.key", certfile="server.crt", server_side=True, **sess_args) print "Serving from \"%s\"." % (script_dir) print "%s://%s:%d/" % \ (("https" if options.tls else "http"), httpd.server_address[0], options.port) return httpd def serve_forever(server): """Serve until shutdown or keyboard interrupt.""" try: server.serve_forever() except KeyboardInterrupt: return def main(): """Start static file and policy servers""" usage = "Usage: %prog [options]" parser = OptionParser(usage=usage) parser.add_option("", "--host", dest="host", metavar="HOST", default="localhost", help="bind to HOST") parser.add_option("-p", "--port", dest="port", type="int", help="serve on PORT", metavar="PORT", default=19400) parser.add_option("-P", "--policy-port", dest="policy_port", type="int", help="serve policy file on PORT", metavar="PORT", default=19945) parser.add_option("", "--tls", dest="tls", action="store_true", help="serve HTTPS", default=False) (options, args) = parser.parse_args() # Change to script dir so SSL and test files are in current dir. script_dir = os.path.dirname(os.path.realpath(__file__)) os.chdir(script_dir) print "Forge Test Server. Use ctrl-c to exit." # create policy and http servers httpd = create_http_server(options, script_dir) policyd = create_policy_server(options) # start servers server_p = Process(target=serve_forever, args=(httpd,)) policy_p = Process(target=serve_forever, args=(policyd,)) server_p.start() policy_p.start() processes = [server_p, policy_p] while len(processes) > 0: try: for p in processes: if p.is_alive(): p.join(1) else: processes.remove(p) except KeyboardInterrupt: print "\nStopping test server..." # processes each receive interrupt # so no need to shutdown #httpd.shutdown(); #policyd.shutdown(); if __name__ == "__main__": main()
mit
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 199, 624, 199, 5413, 1654, 367, 2104, 303, 2295, 14, 199, 199, 13, 710, 1654, 4493, 370, 314, 2082, 402, 314, 1654, 2884, 14, 199, 13, 7799, 4440, 298, 1000, 14, 498, 2, 436, 298, 1000, 14, 16617, 1674, 199, 13, 3240, 422, 18628, 5678, 2955, 570, 22701, 14, 199, 13, 7707, 83, 11040, 1119, 8059, 2881, 4592, 570, 1654, 14, 199, 13, 7827, 370, 3101, 15, 14921, 1844, 413, 2635, 383, 14, 199, 13, 7827, 370, 11040, 1119, 2838, 4592, 1844, 9013, 2322, 14, 819, 2672, 16605, 1000, 14, 647, 359, 1419, 61, 199, 199, 3917, 1265, 2951, 1929, 282, 3486, 3101, 1654, 12, 2597, 11201, 26, 523, 2672, 2366, 446, 77, 5870, 14938, 413, 2635, 383, 199, 624, 199, 199, 504, 12866, 492, 7132, 199, 504, 8691, 492, 13491, 199, 646, 5870, 14938, 199, 646, 17766, 3120, 199, 646, 747, 199, 646, 984, 199, 646, 900, 199, 199, 3, 7649, 370, 492, 4539, 2104, 303, 7799, 859, 543, 2351, 2581, 2291, 199, 3, 11719, 314, 6137, 2082, 5370, 199, 1548, 63, 1023, 275, 298, 1548, 2, 435, 984, 14, 1023, 1491, 19, 61, 199, 1274, 14, 515, 14, 3176, 8, 16, 12, 747, 14, 515, 14, 904, 8, 272, 747, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 11091, 3460, 493, 22159, 272, 21777, 401, 298, 2686, 401, 298, 16677, 63, 4266, 401, 298, 773, 401, 2366, 63, 1023, 12, 298, 2124, 13, 5154, 2237, 199, 893, 26, 272, 687, 367, 303, 492, 6149, 272, 1172, 63, 4266, 63, 11676, 275, 715, 272, 1172, 63, 4266, 275, 715, 199, 2590, 3545, 26, 272, 1172, 63, 4266, 63, 11676, 275, 756, 272, 862, 26, 267, 492, 6149, 267, 1172, 63, 4266, 275, 715, 272, 871, 3545, 26, 267, 1172, 63, 4266, 275, 756, 199, 199, 3, 2494, 2287, 12598, 367, 1006, 13488, 23637, 199, 3869, 3120, 14, 9735, 3120, 14, 3306, 63, 15712, 63, 1562, 275, 715, 199, 199, 3, 710, 4592, 570, 199, 3, 6944, 26, 961, 1475, 365, 7437, 7478, 14, 16407, 543, 10296, 14, 199, 3185, 63, 493, 275, 9638, 199, 28, 31, 1652, 1015, 628, 17, 14, 16, 14863, 3072, 199, 11230, 16556, 8059, 13, 2261, 13, 3185, 60, 199, 20859, 298, 1014, 921, 1544, 14, 5129, 1235, 14, 957, 15, 1652, 15, 3583, 795, 15, 7925, 13, 2261, 13, 3185, 14, 15662, 14559, 199, 28, 7925, 13, 2261, 13, 3185, 3072, 199, 28, 3306, 13, 2732, 13, 504, 2881, 21437, 370, 13, 5203, 21437, 15, 3072, 199, 1108, 7925, 13, 2261, 13, 3185, 3072, 16, 624, 421, 199, 533, 18141, 2461, 8, 3869, 3120, 14, 1563, 11149, 304, 272, 408, 272, 710, 4784, 2461, 1021, 367, 4154, 1654, 14, 339, 1803, 282, 4592, 570, 1380, 5839, 14, 272, 408, 339, 347, 2429, 8, 277, 304, 267, 327, 664, 2005, 666, 267, 327, 3254, 26, 1852, 642, 1655, 23399, 334, 6710, 4438, 12, 5423, 9, 267, 291, 14, 576, 275, 291, 14, 1069, 14, 7637, 8, 7727, 680, 6735, 2258, 16, 358, 267, 327, 1361, 2071, 83, 336, 22665, 5424, 450, 291, 14, 1258, 63, 1562, 59, 16, 61, 267, 327, 1361, 4700, 8, 277, 14, 576, 9, 267, 327, 340, 4592, 570, 1056, 12, 3222, 314, 570, 14, 267, 340, 291, 14, 576, 508, 3886, 3185, 13, 493, 13, 1069, 3133, 582, 288, 870, 298, 4845, 1654, 1056, 687, 450, 83, 2122, 450, 334, 277, 14, 1258, 63, 1562, 59, 16, 566, 288, 291, 14, 1069, 14, 2254, 8, 3185, 63, 493, 9, 267, 587, 26, 288, 870, 298, 4845, 1654, 3086, 24605, 687, 450, 83, 26, 18321, 83, 18781, 450, 971, 490, 334, 277, 14, 1258, 63, 1562, 59, 16, 467, 4700, 8, 277, 14, 576, 430, 421, 199, 318, 1218, 63, 3185, 63, 1000, 8, 1419, 304, 272, 408, 3162, 282, 4592, 1654, 624, 272, 870, 298, 4845, 22701, 687, 450, 68, 2122, 450, 334, 1419, 14, 3185, 63, 719, 9, 272, 4592, 68, 275, 17766, 3120, 14, 9735, 3120, 1332, 1419, 14, 1102, 12, 1511, 14, 3185, 63, 719, 395, 18141, 2461, 9, 272, 372, 4592, 68, 421, 199, 533, 3868, 11698, 9735, 3120, 8, 3869, 3120, 14, 4436, 316, 26527, 12, 17766, 3120, 14, 9735, 3120, 304, 272, 986, 421, 199, 318, 1218, 63, 1014, 63, 1000, 8, 1419, 12, 2884, 63, 694, 304, 272, 408, 3162, 282, 2955, 570, 1654, 624, 272, 327, 675, 9094, 13, 24, 2644, 367, 18910, 1584, 272, 333, 275, 5870, 14938, 14, 3184, 23518, 14, 5359, 63, 1130, 272, 333, 459, 14, 3596, 418, 275, 283, 3578, 15, 9554, 27, 6043, 29, 6610, 13, 24, 7, 339, 18599, 275, 5870, 14938, 14, 3184, 23518, 199, 3, 259, 23913, 275, 17766, 3120, 14, 9735, 3120, 1332, 1419, 14, 1102, 12, 1511, 14, 719, 395, 18599, 9, 272, 23913, 275, 3868, 11698, 9735, 3120, 1332, 1419, 14, 1102, 12, 1511, 14, 719, 395, 18599, 9, 272, 340, 1511, 14, 9945, 26, 267, 340, 440, 1172, 63, 4266, 26, 288, 746, 2186, 480, 5413, 2291, 687, 2018, 499, 14, 23, 503, 2945, 365, 1415, 2685, 398, 327, 3272, 2351, 1249, 340, 781, 2351, 2291, 267, 4043, 63, 589, 275, 1052, 267, 340, 1172, 63, 4266, 63, 11676, 26, 288, 4043, 63, 589, 905, 5480, 63, 344, 63, 3799, 937, 275, 298, 16677, 396, 2, 267, 587, 26, 288, 870, 298, 1858, 303, 7799, 543, 2351, 2581, 440, 2808, 12, 1808, 4465, 1015, 2122, 398, 23913, 14, 3450, 275, 6149, 14, 3823, 63, 3450, 8, 288, 23913, 14, 3450, 12, 288, 25776, 628, 1000, 14, 498, 401, 288, 27660, 628, 1000, 14, 16617, 401, 288, 1654, 63, 2441, 29, 549, 12, 288, 1011, 5480, 63, 589, 9, 339, 870, 298, 1505, 4007, 687, 18321, 83, 60, 21176, 450, 334, 1579, 63, 694, 9, 272, 870, 2071, 83, 13827, 83, 2689, 68, 6687, 450, 971, 288, 19110, 2859, 2, 340, 1511, 14, 9945, 587, 298, 1014, 1288, 288, 23913, 14, 1000, 63, 1562, 59, 16, 467, 288, 1511, 14, 719, 9, 272, 372, 23913, 421, 199, 318, 14062, 63, 21327, 8, 1000, 304, 272, 408, 1505, 432, 5133, 12842, 503, 18716, 26791, 1041, 272 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 199, 624, 199, 5413, 1654, 367, 2104, 303, 2295, 14, 199, 199, 13, 710, 1654, 4493, 370, 314, 2082, 402, 314, 1654, 2884, 14, 199, 13, 7799, 4440, 298, 1000, 14, 498, 2, 436, 298, 1000, 14, 16617, 1674, 199, 13, 3240, 422, 18628, 5678, 2955, 570, 22701, 14, 199, 13, 7707, 83, 11040, 1119, 8059, 2881, 4592, 570, 1654, 14, 199, 13, 7827, 370, 3101, 15, 14921, 1844, 413, 2635, 383, 14, 199, 13, 7827, 370, 11040, 1119, 2838, 4592, 1844, 9013, 2322, 14, 819, 2672, 16605, 1000, 14, 647, 359, 1419, 61, 199, 199, 3917, 1265, 2951, 1929, 282, 3486, 3101, 1654, 12, 2597, 11201, 26, 523, 2672, 2366, 446, 77, 5870, 14938, 413, 2635, 383, 199, 624, 199, 199, 504, 12866, 492, 7132, 199, 504, 8691, 492, 13491, 199, 646, 5870, 14938, 199, 646, 17766, 3120, 199, 646, 747, 199, 646, 984, 199, 646, 900, 199, 199, 3, 7649, 370, 492, 4539, 2104, 303, 7799, 859, 543, 2351, 2581, 2291, 199, 3, 11719, 314, 6137, 2082, 5370, 199, 1548, 63, 1023, 275, 298, 1548, 2, 435, 984, 14, 1023, 1491, 19, 61, 199, 1274, 14, 515, 14, 3176, 8, 16, 12, 747, 14, 515, 14, 904, 8, 272, 747, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 11091, 3460, 493, 22159, 272, 21777, 401, 298, 2686, 401, 298, 16677, 63, 4266, 401, 298, 773, 401, 2366, 63, 1023, 12, 298, 2124, 13, 5154, 2237, 199, 893, 26, 272, 687, 367, 303, 492, 6149, 272, 1172, 63, 4266, 63, 11676, 275, 715, 272, 1172, 63, 4266, 275, 715, 199, 2590, 3545, 26, 272, 1172, 63, 4266, 63, 11676, 275, 756, 272, 862, 26, 267, 492, 6149, 267, 1172, 63, 4266, 275, 715, 272, 871, 3545, 26, 267, 1172, 63, 4266, 275, 756, 199, 199, 3, 2494, 2287, 12598, 367, 1006, 13488, 23637, 199, 3869, 3120, 14, 9735, 3120, 14, 3306, 63, 15712, 63, 1562, 275, 715, 199, 199, 3, 710, 4592, 570, 199, 3, 6944, 26, 961, 1475, 365, 7437, 7478, 14, 16407, 543, 10296, 14, 199, 3185, 63, 493, 275, 9638, 199, 28, 31, 1652, 1015, 628, 17, 14, 16, 14863, 3072, 199, 11230, 16556, 8059, 13, 2261, 13, 3185, 60, 199, 20859, 298, 1014, 921, 1544, 14, 5129, 1235, 14, 957, 15, 1652, 15, 3583, 795, 15, 7925, 13, 2261, 13, 3185, 14, 15662, 14559, 199, 28, 7925, 13, 2261, 13, 3185, 3072, 199, 28, 3306, 13, 2732, 13, 504, 2881, 21437, 370, 13, 5203, 21437, 15, 3072, 199, 1108, 7925, 13, 2261, 13, 3185, 3072, 16, 624, 421, 199, 533, 18141, 2461, 8, 3869, 3120, 14, 1563, 11149, 304, 272, 408, 272, 710, 4784, 2461, 1021, 367, 4154, 1654, 14, 339, 1803, 282, 4592, 570, 1380, 5839, 14, 272, 408, 339, 347, 2429, 8, 277, 304, 267, 327, 664, 2005, 666, 267, 327, 3254, 26, 1852, 642, 1655, 23399, 334, 6710, 4438, 12, 5423, 9, 267, 291, 14, 576, 275, 291, 14, 1069, 14, 7637, 8, 7727, 680, 6735, 2258, 16, 358, 267, 327, 1361, 2071, 83, 336, 22665, 5424, 450, 291, 14, 1258, 63, 1562, 59, 16, 61, 267, 327, 1361, 4700, 8, 277, 14, 576, 9, 267, 327, 340, 4592, 570, 1056, 12, 3222, 314, 570, 14, 267, 340, 291, 14, 576, 508, 3886, 3185, 13, 493, 13, 1069, 3133, 582, 288, 870, 298, 4845, 1654, 1056, 687, 450, 83, 2122, 450, 334, 277, 14, 1258, 63, 1562, 59, 16, 566, 288, 291, 14, 1069, 14, 2254, 8, 3185, 63, 493, 9, 267, 587, 26, 288, 870, 298, 4845, 1654, 3086, 24605, 687, 450, 83, 26, 18321, 83, 18781, 450, 971, 490, 334, 277, 14, 1258, 63, 1562, 59, 16, 467, 4700, 8, 277, 14, 576, 430, 421, 199, 318, 1218, 63, 3185, 63, 1000, 8, 1419, 304, 272, 408, 3162, 282, 4592, 1654, 624, 272, 870, 298, 4845, 22701, 687, 450, 68, 2122, 450, 334, 1419, 14, 3185, 63, 719, 9, 272, 4592, 68, 275, 17766, 3120, 14, 9735, 3120, 1332, 1419, 14, 1102, 12, 1511, 14, 3185, 63, 719, 395, 18141, 2461, 9, 272, 372, 4592, 68, 421, 199, 533, 3868, 11698, 9735, 3120, 8, 3869, 3120, 14, 4436, 316, 26527, 12, 17766, 3120, 14, 9735, 3120, 304, 272, 986, 421, 199, 318, 1218, 63, 1014, 63, 1000, 8, 1419, 12, 2884, 63, 694, 304, 272, 408, 3162, 282, 2955, 570, 1654, 624, 272, 327, 675, 9094, 13, 24, 2644, 367, 18910, 1584, 272, 333, 275, 5870, 14938, 14, 3184, 23518, 14, 5359, 63, 1130, 272, 333, 459, 14, 3596, 418, 275, 283, 3578, 15, 9554, 27, 6043, 29, 6610, 13, 24, 7, 339, 18599, 275, 5870, 14938, 14, 3184, 23518, 199, 3, 259, 23913, 275, 17766, 3120, 14, 9735, 3120, 1332, 1419, 14, 1102, 12, 1511, 14, 719, 395, 18599, 9, 272, 23913, 275, 3868, 11698, 9735, 3120, 1332, 1419, 14, 1102, 12, 1511, 14, 719, 395, 18599, 9, 272, 340, 1511, 14, 9945, 26, 267, 340, 440, 1172, 63, 4266, 26, 288, 746, 2186, 480, 5413, 2291, 687, 2018, 499, 14, 23, 503, 2945, 365, 1415, 2685, 398, 327, 3272, 2351, 1249, 340, 781, 2351, 2291, 267, 4043, 63, 589, 275, 1052, 267, 340, 1172, 63, 4266, 63, 11676, 26, 288, 4043, 63, 589, 905, 5480, 63, 344, 63, 3799, 937, 275, 298, 16677, 396, 2, 267, 587, 26, 288, 870, 298, 1858, 303, 7799, 543, 2351, 2581, 440, 2808, 12, 1808, 4465, 1015, 2122, 398, 23913, 14, 3450, 275, 6149, 14, 3823, 63, 3450, 8, 288, 23913, 14, 3450, 12, 288, 25776, 628, 1000, 14, 498, 401, 288, 27660, 628, 1000, 14, 16617, 401, 288, 1654, 63, 2441, 29, 549, 12, 288, 1011, 5480, 63, 589, 9, 339, 870, 298, 1505, 4007, 687, 18321, 83, 60, 21176, 450, 334, 1579, 63, 694, 9, 272, 870, 2071, 83, 13827, 83, 2689, 68, 6687, 450, 971, 288, 19110, 2859, 2, 340, 1511, 14, 9945, 587, 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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
EggieCode/ansible-role-ufw
test/test.py
1
2161
#!/usr/bin/env python3 import imp import os import unittest from pprint import pprint imp.load_source('ufw_forward', os.path.join(os.path.dirname(__file__), os.path.pardir, 'library', 'ufw_forward.py')) from ufw_forward import UFWForwards class TestBase(unittest.TestCase): def test_do_magic(self): test = { "incomming_dev": "eth0", "outgoing_dev": "lxdbr0", "outgoing_network": "10.20.10.0/24", "masquerading": True, "conntrack_state": "RELATED,ESTABLISHED", "reroute": [], "forwards": [ { "container": "mumble.baviaan.eggie.zone", "destination_ip": "10.20.10.11", "destination_port": [ 64738 ], "incomming_ip": "88.99.152.112", "incomming_port": [ 64738 ], "protocol": [ "tcp", "udp" ] }, { "container": "brandon-minecraft.baviaan.eggie.zone", "destination_ip": "10.20.10.12", "destination_port": [ 25565 ], "incomming_ip": "88.99.152.112", "incomming_port": [ 25565 ], "protocol": [ "tcp" ] } ] } response = { 'nat_rules' : [], 'filter_rules' : [] } ufw_forwards = UFWForwards(test, False) ufw_forwards.nat_rules = response['nat_rules'] ufw_forwards.filter_rules = response['filter_rules'] ufw_forwards.generate() for rule in response['nat_rules']: print(" ".join(rule)) pprint(response['filter_rules'])) for rule in response['filter_rules']: print(" ".join(rule)) if __name__ == '__main__': unittest.main()
mit
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 19, 199, 199, 646, 1742, 199, 646, 747, 199, 646, 2882, 199, 504, 10933, 492, 10933, 199, 3236, 14, 912, 63, 1365, 360, 1286, 87, 63, 6688, 297, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 747, 14, 515, 14, 21386, 12, 283, 4342, 297, 283, 1286, 87, 63, 6688, 14, 647, 1333, 199, 504, 399, 8835, 63, 6688, 492, 738, 19445, 1858, 4751, 6905, 199, 533, 1379, 1563, 8, 2796, 14, 1746, 304, 523, 347, 511, 63, 1117, 63, 11523, 8, 277, 304, 339, 511, 275, 469, 221, 298, 262, 1404, 316, 63, 2374, 582, 298, 12391, 16, 401, 1598, 298, 19388, 63, 2374, 582, 298, 76, 10719, 82, 16, 401, 1598, 298, 19388, 63, 1200, 582, 298, 709, 14, 1165, 14, 709, 14, 16, 15, 1194, 401, 1598, 298, 5892, 16891, 5384, 582, 715, 12, 1598, 298, 388, 343, 8085, 63, 929, 582, 298, 13604, 6989, 12, 1719, 1217, 44, 20450, 401, 1598, 298, 264, 4449, 582, 990, 1598, 298, 19159, 582, 359, 2116, 469, 1993, 298, 3600, 582, 298, 77, 453, 830, 14, 2470, 12897, 290, 14, 5799, 1873, 14, 2619, 401, 1993, 298, 6881, 63, 711, 582, 298, 709, 14, 1165, 14, 709, 14, 845, 401, 1993, 298, 6881, 63, 719, 582, 359, 2079, 5049, 23, 1703, 1993, 2156, 1993, 298, 262, 1404, 316, 63, 711, 582, 298, 1299, 14, 1020, 14, 11024, 14, 6094, 401, 1993, 298, 262, 1404, 316, 63, 719, 582, 359, 2079, 5049, 23, 1703, 1993, 2156, 1993, 298, 3922, 582, 359, 2079, 298, 8815, 401, 2079, 298, 15036, 2, 1993, 1622, 2116, 1660, 2116, 469, 1993, 298, 3600, 582, 298, 19026, 265, 13, 827, 825, 4800, 14, 2470, 12897, 290, 14, 5799, 1873, 14, 2619, 401, 1993, 298, 6881, 63, 711, 582, 298, 709, 14, 1165, 14, 709, 14, 713, 401, 1993, 298, 6881, 63, 719, 582, 359, 2079, 5450, 2182, 1993, 2156, 1993, 298, 262, 1404, 316, 63, 711, 582, 298, 1299, 14, 1020, 14, 11024, 14, 6094, 401, 1993, 298, 262, 1404, 316, 63, 719, 582, 359, 2079, 5450, 2182, 1993, 2156, 1993, 298, 3922, 582, 359, 2079, 298, 8815, 2, 1993, 1622, 2116, 789, 1598, 1622, 1779, 789, 339, 1177, 275, 469, 267, 283, 9468, 63, 4423, 7, 520, 990, 267, 283, 1541, 63, 4423, 7, 520, 942, 272, 789, 339, 399, 8835, 63, 19159, 275, 738, 19445, 1858, 4751, 8, 396, 12, 756, 9, 272, 399, 8835, 63, 19159, 14, 9468, 63, 4423, 275, 1177, 459, 9468, 63, 4423, 418, 272, 399, 8835, 63, 19159, 14, 1541, 63, 4423, 275, 1177, 459, 1541, 63, 4423, 418, 339, 399, 8835, 63, 19159, 14, 4208, 342, 339, 367, 2332, 315, 1177, 459, 9468, 63, 4423, 2565, 267, 870, 480, 3680, 904, 8, 2200, 430, 272, 10933, 8, 1310, 459, 1541, 63, 4423, 5156, 272, 367, 2332, 315, 1177, 459, 1541, 63, 4423, 2565, 267, 870, 480, 3680, 904, 8, 2200, 430, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 2882, 14, 973, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1813, 2366, 19, 199, 199, 646, 1742, 199, 646, 747, 199, 646, 2882, 199, 504, 10933, 492, 10933, 199, 3236, 14, 912, 63, 1365, 360, 1286, 87, 63, 6688, 297, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 747, 14, 515, 14, 21386, 12, 283, 4342, 297, 283, 1286, 87, 63, 6688, 14, 647, 1333, 199, 504, 399, 8835, 63, 6688, 492, 738, 19445, 1858, 4751, 6905, 199, 533, 1379, 1563, 8, 2796, 14, 1746, 304, 523, 347, 511, 63, 1117, 63, 11523, 8, 277, 304, 339, 511, 275, 469, 221, 298, 262, 1404, 316, 63, 2374, 582, 298, 12391, 16, 401, 1598, 298, 19388, 63, 2374, 582, 298, 76, 10719, 82, 16, 401, 1598, 298, 19388, 63, 1200, 582, 298, 709, 14, 1165, 14, 709, 14, 16, 15, 1194, 401, 1598, 298, 5892, 16891, 5384, 582, 715, 12, 1598, 298, 388, 343, 8085, 63, 929, 582, 298, 13604, 6989, 12, 1719, 1217, 44, 20450, 401, 1598, 298, 264, 4449, 582, 990, 1598, 298, 19159, 582, 359, 2116, 469, 1993, 298, 3600, 582, 298, 77, 453, 830, 14, 2470, 12897, 290, 14, 5799, 1873, 14, 2619, 401, 1993, 298, 6881, 63, 711, 582, 298, 709, 14, 1165, 14, 709, 14, 845, 401, 1993, 298, 6881, 63, 719, 582, 359, 2079, 5049, 23, 1703, 1993, 2156, 1993, 298, 262, 1404, 316, 63, 711, 582, 298, 1299, 14, 1020, 14, 11024, 14, 6094, 401, 1993, 298, 262, 1404, 316, 63, 719, 582, 359, 2079, 5049, 23, 1703, 1993, 2156, 1993, 298, 3922, 582, 359, 2079, 298, 8815, 401, 2079, 298, 15036, 2, 1993, 1622, 2116, 1660, 2116, 469, 1993, 298, 3600, 582, 298, 19026, 265, 13, 827, 825, 4800, 14, 2470, 12897, 290, 14, 5799, 1873, 14, 2619, 401, 1993, 298, 6881, 63, 711, 582, 298, 709, 14, 1165, 14, 709, 14, 713, 401, 1993, 298, 6881, 63, 719, 582, 359, 2079, 5450, 2182, 1993, 2156, 1993, 298, 262, 1404, 316, 63, 711, 582, 298, 1299, 14, 1020, 14, 11024, 14, 6094, 401, 1993, 298, 262, 1404, 316, 63, 719, 582, 359, 2079, 5450, 2182, 1993, 2156, 1993, 298, 3922, 582, 359, 2079, 298, 8815, 2, 1993, 1622, 2116, 789, 1598, 1622, 1779, 789, 339, 1177, 275, 469, 267, 283, 9468, 63, 4423, 7, 520, 990, 267, 283, 1541, 63, 4423, 7, 520, 942, 272, 789, 339, 399, 8835, 63, 19159, 275, 738, 19445, 1858, 4751, 8, 396, 12, 756, 9, 272, 399, 8835, 63, 19159, 14, 9468, 63, 4423, 275, 1177, 459, 9468, 63, 4423, 418, 272, 399, 8835, 63, 19159, 14, 1541, 63, 4423, 275, 1177, 459, 1541, 63, 4423, 418, 339, 399, 8835, 63, 19159, 14, 4208, 342, 339, 367, 2332, 315, 1177, 459, 9468, 63, 4423, 2565, 267, 870, 480, 3680, 904, 8, 2200, 430, 272, 10933, 8, 1310, 459, 1541, 63, 4423, 5156, 272, 367, 2332, 315, 1177, 459, 1541, 63, 4423, 2565, 267, 870, 480, 3680, 904, 8, 2200, 430, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 2882, 14, 973, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
mcalmer/spacewalk
client/tools/rhncfg/config_common/rhn_log.py
10
3785
# # Copyright (c) 2008--2016 Red Hat, Inc. # # This software is licensed to you under the GNU General Public License, # version 2 (GPLv2). There is NO WARRANTY for this software, express or # implied, including the implied warranties of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 # along with this software; if not, see # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. # # Red Hat trademarks are not licensed under GPLv2. No permission is # granted to use or replicate Red Hat trademarks that are incorporated # in this software or its documentation. # import os import stat import sys import time import traceback class Logger: debug_level = 1 logfile = None def log_debug(self, debug_level, *args): if debug_level <= self.debug_level: outstr = "%s %s: %s\n" % ( time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())), self.get_caller(), " ".join([str(it) for it in args])) sys.stdout.write(outstr) if not self.logfile is None: self.write_to_logfile(outstr) def log_to_file(self, debug_level, *args): if debug_level <= self.debug_level: outstr = "%s %s: %s\n" % ( time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())), self.get_caller(), " ".join([str(it) for it in args])) if not self.logfile is None: self.write_to_logfile(outstr) def write_to_logfile(self, logstr): if os.access(self.logfile, os.F_OK|os.R_OK|os.W_OK): logname = open(self.logfile, "a") logname.write(logstr) logname.close() else: #pkilambi: bug#179367: check permissions before writing. #non-root users will not have permissions to create the file # Set to root-RW-only if we have to create the file mode = stat.S_IRUSR | stat.S_IWUSR # octal 0o600 try: # Need to use os.open to insure initial permissions fd = os.open(self.logfile, os.O_WRONLY | os.O_CREAT, mode) logname = os.fdopen(fd, 'w') logname.write(logstr) logname.close() except: print("does not have permissions to create file %s" % (self.logfile)) sys.exit(1) def set_logfile(self, filename): Logger.logfile = filename def set_debug_level(self, debug_level): Logger.debug_level = debug_level def get_debug_level(self): return Logger.debug_level def get_caller(self, caller_offset=4): tbStack = traceback.extract_stack() callid = len(tbStack) - caller_offset module = tbStack[callid] module_file = os.path.basename(module[0]) module_file = module_file.split('.', 1)[0] return "%s.%s" % (module_file, module[2]) def log_error(self, *args): outstr = " ".join([str(it) for it in args]) sys.stderr.write(outstr) sys.stderr.write("\n") if not self.logfile is None: self.write_to_logfile(outstr) def die(self, error_code, *args): self.log_error(args) sys.exit(error_code) def set_debug_level(*args): return Logger().set_debug_level(*args) def get_debug_level(*args): return Logger().get_debug_level(*args) def set_logfile(*args): return Logger().set_logfile(*args) def log_debug(*args): return Logger().log_debug(*args) def log_to_file(*args): return Logger().log_to_file(*args) def log_error(*args): return Logger().log_error(*args) def die(error_code, *args): Logger().log_error(*args) sys.exit(error_code)
gpl-2.0
[ 3, 199, 3, 1898, 334, 67, 9, 9079, 306, 9261, 9572, 13002, 12, 3277, 14, 199, 3, 199, 3, 961, 2032, 365, 18233, 370, 1265, 1334, 314, 1664, 1696, 1684, 844, 12, 199, 3, 1015, 499, 334, 28863, 18, 680, 6006, 365, 4825, 3408, 367, 642, 2032, 12, 4056, 503, 199, 3, 2478, 12, 5893, 314, 2478, 3712, 1417, 402, 3169, 503, 3092, 199, 3, 2381, 437, 3115, 3104, 14, 2047, 1077, 1172, 3086, 282, 1331, 402, 14629, 86, 18, 199, 3, 3180, 543, 642, 2032, 27, 340, 440, 12, 1937, 199, 3, 1455, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 1753, 13, 2383, 15, 11692, 13, 18, 14, 16, 14, 2424, 14, 199, 3, 199, 3, 9572, 13002, 21032, 10375, 787, 440, 18233, 1334, 14629, 86, 18, 14, 3091, 4983, 365, 199, 3, 10009, 370, 675, 503, 29738, 9572, 13002, 21032, 10375, 626, 787, 30147, 972, 199, 3, 315, 642, 2032, 503, 2399, 3794, 14, 199, 3, 199, 199, 646, 747, 199, 646, 5672, 199, 646, 984, 199, 646, 900, 199, 646, 5190, 199, 199, 533, 15996, 26, 272, 3105, 63, 1896, 275, 413, 272, 17251, 275, 488, 339, 347, 943, 63, 1757, 8, 277, 12, 3105, 63, 1896, 12, 627, 589, 304, 267, 340, 3105, 63, 1896, 2695, 291, 14, 1757, 63, 1896, 26, 288, 24632, 275, 2071, 83, 450, 83, 26, 450, 83, 60, 78, 2, 450, 334, 355, 900, 14, 6205, 3647, 57, 3295, 77, 3295, 68, 450, 40, 2689, 45, 2689, 51, 401, 900, 14, 15198, 8, 521, 14, 521, 22606, 355, 291, 14, 362, 63, 11219, 1062, 355, 298, 3680, 904, 779, 495, 8, 390, 9, 367, 652, 315, 1249, 2459, 288, 984, 14, 2703, 14, 952, 8, 548, 495, 9, 953, 340, 440, 291, 14, 12804, 365, 488, 26, 355, 291, 14, 952, 63, 475, 63, 12804, 8, 548, 495, 9, 339, 347, 943, 63, 475, 63, 493, 8, 277, 12, 3105, 63, 1896, 12, 627, 589, 304, 267, 340, 3105, 63, 1896, 2695, 291, 14, 1757, 63, 1896, 26, 288, 24632, 275, 2071, 83, 450, 83, 26, 450, 83, 60, 78, 2, 450, 334, 355, 900, 14, 6205, 3647, 57, 3295, 77, 3295, 68, 450, 40, 2689, 45, 2689, 51, 401, 900, 14, 15198, 8, 521, 14, 521, 22606, 355, 291, 14, 362, 63, 11219, 1062, 355, 298, 3680, 904, 779, 495, 8, 390, 9, 367, 652, 315, 1249, 2459, 288, 340, 440, 291, 14, 12804, 365, 488, 26, 355, 291, 14, 952, 63, 475, 63, 12804, 8, 548, 495, 9, 2378, 347, 2218, 63, 475, 63, 12804, 8, 277, 12, 943, 495, 304, 267, 340, 747, 14, 2732, 8, 277, 14, 12804, 12, 747, 14, 38, 63, 3593, 92, 736, 14, 50, 63, 3593, 92, 736, 14, 55, 63, 3593, 304, 288, 943, 354, 275, 1551, 8, 277, 14, 12804, 12, 298, 65, 531, 288, 943, 354, 14, 952, 8, 793, 495, 9, 288, 943, 354, 14, 1600, 342, 267, 587, 26, 288, 327, 2051, 382, 455, 4492, 26, 6519, 3, 10699, 12684, 26, 1104, 3443, 2544, 3575, 14, 288, 327, 2865, 13, 1231, 4390, 911, 440, 1172, 3443, 370, 1218, 314, 570, 953, 327, 2494, 370, 1738, 13, 25438, 13, 2118, 340, 781, 1172, 370, 1218, 314, 570, 288, 818, 275, 5672, 14, 51, 63, 3927, 22592, 1204, 5672, 14, 51, 63, 22275, 22592, 221, 327, 30100, 378, 79, 6683, 288, 862, 26, 355, 327, 14012, 370, 675, 747, 14, 1490, 370, 315, 3253, 2536, 3443, 355, 6111, 275, 747, 14, 1490, 8, 277, 14, 12804, 12, 747, 14, 47, 63, 6524, 10452, 1204, 747, 14, 47, 63, 32120, 12, 818, 9, 355, 943, 354, 275, 747, 14, 23140, 8, 2592, 12, 283, 87, 358, 355, 943, 354, 14, 952, 8, 793, 495, 9, 355, 943, 354, 14, 1600, 342, 288, 871, 26, 355, 870, 480, 9105, 440, 1172, 3443, 370, 1218, 570, 221, 450, 83, 2, 450, 334, 277, 14, 12804, 430, 355, 984, 14, 2224, 8, 17, 9, 339, 347, 663, 63, 12804, 8, 277, 12, 1788, 304, 267, 15996, 14, 12804, 275, 1788, 339, 347, 663, 63, 1757, 63, 1896, 8, 277, 12, 3105, 63, 1896, 304, 267, 15996, 14, 1757, 63, 1896, 275, 3105, 63, 1896, 339, 347, 664, 63, 1757, 63, 1896, 8, 277, 304, 267, 372, 15996, 14, 1757, 63, 1896, 339, 347, 664, 63, 11219, 8, 277, 12, 8025, 63, 2743, 29, 20, 304, 267, 7070, 4851, 275, 5190, 14, 5005, 63, 2340, 342, 267, 3213, 7401, 275, 822, 8, 5842, 4851, 9, 446, 8025, 63, 2743, 267, 859, 275, 7070, 4851, 59, 915, 7401, 61, 267, 859, 63, 493, 275, 747, 14, 515, 14, 4846, 8, 578, 59, 16, 566, 267, 859, 63, 493, 275, 859, 63, 493, 14, 1294, 14078, 413, 2788, 16, 61, 267, 372, 2071, 83, 4111, 83, 2, 450, 334, 578, 63, 493, 12, 859, 59, 18, 566, 339, 347, 943, 63, 705, 8, 277, 12, 627, 589, 304, 267, 24632, 275, 298, 3680, 904, 779, 495, 8, 390, 9, 367, 652, 315, 1249, 566, 267, 984, 14, 3083, 14, 952, 8, 548, 495, 9, 267, 984, 14, 3083, 14, 952, 4582, 78, 531, 267, 340, 440, 291, 14, 12804, 365, 488, 26, 288, 291, 14, 952, 63, 475, 63, 12804, 8, 548, 495, 9, 339, 347, 18833, 8, 277, 12, 1125, 63, 600, 12, 627, 589, 304, 267, 291, 14, 793, 63, 705, 8, 589, 9, 267, 984, 14, 2224, 8, 705, 63, 600, 9, 199, 199, 318, 663, 63, 1757, 63, 1896, 2031, 589, 304, 272, 372, 15996, 1252, 409, 63, 1757, 63, 1896, 2031, 589, 9, 199, 199, 318, 664, 63, 1757, 63, 1896, 2031, 589, 304, 272, 372, 15996, 1252, 362, 63, 1757, 63, 1896, 2031, 589, 9, 199, 199, 318, 663, 63, 12804, 2031, 589, 304, 272, 372, 15996, 1252, 409, 63, 12804, 2031, 589, 9, 199, 199, 318, 943, 63, 1757, 2031, 589, 304, 272, 372, 15996, 1252, 793, 63, 1757, 2031, 589, 9, 199, 199, 318, 943, 63, 475, 63, 493, 2031, 589, 304, 272, 372, 15996, 1252, 793, 63, 475, 63, 493, 2031, 589, 9, 199, 199, 318, 943, 63, 705, 2031 ]
[ 199, 3, 1898, 334, 67, 9, 9079, 306, 9261, 9572, 13002, 12, 3277, 14, 199, 3, 199, 3, 961, 2032, 365, 18233, 370, 1265, 1334, 314, 1664, 1696, 1684, 844, 12, 199, 3, 1015, 499, 334, 28863, 18, 680, 6006, 365, 4825, 3408, 367, 642, 2032, 12, 4056, 503, 199, 3, 2478, 12, 5893, 314, 2478, 3712, 1417, 402, 3169, 503, 3092, 199, 3, 2381, 437, 3115, 3104, 14, 2047, 1077, 1172, 3086, 282, 1331, 402, 14629, 86, 18, 199, 3, 3180, 543, 642, 2032, 27, 340, 440, 12, 1937, 199, 3, 1455, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 1753, 13, 2383, 15, 11692, 13, 18, 14, 16, 14, 2424, 14, 199, 3, 199, 3, 9572, 13002, 21032, 10375, 787, 440, 18233, 1334, 14629, 86, 18, 14, 3091, 4983, 365, 199, 3, 10009, 370, 675, 503, 29738, 9572, 13002, 21032, 10375, 626, 787, 30147, 972, 199, 3, 315, 642, 2032, 503, 2399, 3794, 14, 199, 3, 199, 199, 646, 747, 199, 646, 5672, 199, 646, 984, 199, 646, 900, 199, 646, 5190, 199, 199, 533, 15996, 26, 272, 3105, 63, 1896, 275, 413, 272, 17251, 275, 488, 339, 347, 943, 63, 1757, 8, 277, 12, 3105, 63, 1896, 12, 627, 589, 304, 267, 340, 3105, 63, 1896, 2695, 291, 14, 1757, 63, 1896, 26, 288, 24632, 275, 2071, 83, 450, 83, 26, 450, 83, 60, 78, 2, 450, 334, 355, 900, 14, 6205, 3647, 57, 3295, 77, 3295, 68, 450, 40, 2689, 45, 2689, 51, 401, 900, 14, 15198, 8, 521, 14, 521, 22606, 355, 291, 14, 362, 63, 11219, 1062, 355, 298, 3680, 904, 779, 495, 8, 390, 9, 367, 652, 315, 1249, 2459, 288, 984, 14, 2703, 14, 952, 8, 548, 495, 9, 953, 340, 440, 291, 14, 12804, 365, 488, 26, 355, 291, 14, 952, 63, 475, 63, 12804, 8, 548, 495, 9, 339, 347, 943, 63, 475, 63, 493, 8, 277, 12, 3105, 63, 1896, 12, 627, 589, 304, 267, 340, 3105, 63, 1896, 2695, 291, 14, 1757, 63, 1896, 26, 288, 24632, 275, 2071, 83, 450, 83, 26, 450, 83, 60, 78, 2, 450, 334, 355, 900, 14, 6205, 3647, 57, 3295, 77, 3295, 68, 450, 40, 2689, 45, 2689, 51, 401, 900, 14, 15198, 8, 521, 14, 521, 22606, 355, 291, 14, 362, 63, 11219, 1062, 355, 298, 3680, 904, 779, 495, 8, 390, 9, 367, 652, 315, 1249, 2459, 288, 340, 440, 291, 14, 12804, 365, 488, 26, 355, 291, 14, 952, 63, 475, 63, 12804, 8, 548, 495, 9, 2378, 347, 2218, 63, 475, 63, 12804, 8, 277, 12, 943, 495, 304, 267, 340, 747, 14, 2732, 8, 277, 14, 12804, 12, 747, 14, 38, 63, 3593, 92, 736, 14, 50, 63, 3593, 92, 736, 14, 55, 63, 3593, 304, 288, 943, 354, 275, 1551, 8, 277, 14, 12804, 12, 298, 65, 531, 288, 943, 354, 14, 952, 8, 793, 495, 9, 288, 943, 354, 14, 1600, 342, 267, 587, 26, 288, 327, 2051, 382, 455, 4492, 26, 6519, 3, 10699, 12684, 26, 1104, 3443, 2544, 3575, 14, 288, 327, 2865, 13, 1231, 4390, 911, 440, 1172, 3443, 370, 1218, 314, 570, 953, 327, 2494, 370, 1738, 13, 25438, 13, 2118, 340, 781, 1172, 370, 1218, 314, 570, 288, 818, 275, 5672, 14, 51, 63, 3927, 22592, 1204, 5672, 14, 51, 63, 22275, 22592, 221, 327, 30100, 378, 79, 6683, 288, 862, 26, 355, 327, 14012, 370, 675, 747, 14, 1490, 370, 315, 3253, 2536, 3443, 355, 6111, 275, 747, 14, 1490, 8, 277, 14, 12804, 12, 747, 14, 47, 63, 6524, 10452, 1204, 747, 14, 47, 63, 32120, 12, 818, 9, 355, 943, 354, 275, 747, 14, 23140, 8, 2592, 12, 283, 87, 358, 355, 943, 354, 14, 952, 8, 793, 495, 9, 355, 943, 354, 14, 1600, 342, 288, 871, 26, 355, 870, 480, 9105, 440, 1172, 3443, 370, 1218, 570, 221, 450, 83, 2, 450, 334, 277, 14, 12804, 430, 355, 984, 14, 2224, 8, 17, 9, 339, 347, 663, 63, 12804, 8, 277, 12, 1788, 304, 267, 15996, 14, 12804, 275, 1788, 339, 347, 663, 63, 1757, 63, 1896, 8, 277, 12, 3105, 63, 1896, 304, 267, 15996, 14, 1757, 63, 1896, 275, 3105, 63, 1896, 339, 347, 664, 63, 1757, 63, 1896, 8, 277, 304, 267, 372, 15996, 14, 1757, 63, 1896, 339, 347, 664, 63, 11219, 8, 277, 12, 8025, 63, 2743, 29, 20, 304, 267, 7070, 4851, 275, 5190, 14, 5005, 63, 2340, 342, 267, 3213, 7401, 275, 822, 8, 5842, 4851, 9, 446, 8025, 63, 2743, 267, 859, 275, 7070, 4851, 59, 915, 7401, 61, 267, 859, 63, 493, 275, 747, 14, 515, 14, 4846, 8, 578, 59, 16, 566, 267, 859, 63, 493, 275, 859, 63, 493, 14, 1294, 14078, 413, 2788, 16, 61, 267, 372, 2071, 83, 4111, 83, 2, 450, 334, 578, 63, 493, 12, 859, 59, 18, 566, 339, 347, 943, 63, 705, 8, 277, 12, 627, 589, 304, 267, 24632, 275, 298, 3680, 904, 779, 495, 8, 390, 9, 367, 652, 315, 1249, 566, 267, 984, 14, 3083, 14, 952, 8, 548, 495, 9, 267, 984, 14, 3083, 14, 952, 4582, 78, 531, 267, 340, 440, 291, 14, 12804, 365, 488, 26, 288, 291, 14, 952, 63, 475, 63, 12804, 8, 548, 495, 9, 339, 347, 18833, 8, 277, 12, 1125, 63, 600, 12, 627, 589, 304, 267, 291, 14, 793, 63, 705, 8, 589, 9, 267, 984, 14, 2224, 8, 705, 63, 600, 9, 199, 199, 318, 663, 63, 1757, 63, 1896, 2031, 589, 304, 272, 372, 15996, 1252, 409, 63, 1757, 63, 1896, 2031, 589, 9, 199, 199, 318, 664, 63, 1757, 63, 1896, 2031, 589, 304, 272, 372, 15996, 1252, 362, 63, 1757, 63, 1896, 2031, 589, 9, 199, 199, 318, 663, 63, 12804, 2031, 589, 304, 272, 372, 15996, 1252, 409, 63, 12804, 2031, 589, 9, 199, 199, 318, 943, 63, 1757, 2031, 589, 304, 272, 372, 15996, 1252, 793, 63, 1757, 2031, 589, 9, 199, 199, 318, 943, 63, 475, 63, 493, 2031, 589, 304, 272, 372, 15996, 1252, 793, 63, 475, 63, 493, 2031, 589, 9, 199, 199, 318, 943, 63, 705, 2031, 0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 1, 1 ]
rklabs/scrapy
scrapy/spidermiddlewares/offsite.py
85
2120
""" Offsite Spider Middleware See documentation in docs/topics/spider-middleware.rst """ import re import logging from scrapy import signals from scrapy.http import Request from scrapy.utils.httpobj import urlparse_cached logger = logging.getLogger(__name__) class OffsiteMiddleware(object): def __init__(self, stats): self.stats = stats @classmethod def from_crawler(cls, crawler): o = cls(crawler.stats) crawler.signals.connect(o.spider_opened, signal=signals.spider_opened) return o def process_spider_output(self, response, result, spider): for x in result: if isinstance(x, Request): if x.dont_filter or self.should_follow(x, spider): yield x else: domain = urlparse_cached(x).hostname if domain and domain not in self.domains_seen: self.domains_seen.add(domain) logger.debug("Filtered offsite request to %(domain)r: %(request)s", {'domain': domain, 'request': x}, extra={'spider': spider}) self.stats.inc_value('offsite/domains', spider=spider) self.stats.inc_value('offsite/filtered', spider=spider) else: yield x def should_follow(self, request, spider): regex = self.host_regex # hostname can be None for wrong urls (like javascript links) host = urlparse_cached(request).hostname or '' return bool(regex.search(host)) def get_host_regex(self, spider): """Override this method to implement a different offsite policy""" allowed_domains = getattr(spider, 'allowed_domains', None) if not allowed_domains: return re.compile('') # allow all by default regex = r'^(.*\.)?(%s)$' % '|'.join(re.escape(d) for d in allowed_domains if d is not None) return re.compile(regex) def spider_opened(self, spider): self.host_regex = self.get_host_regex(spider) self.domains_seen = set()
bsd-3-clause
[ 624, 199, 5195, 2124, 428, 12508, 603, 3551, 199, 199, 9295, 3794, 315, 9149, 15, 11299, 15, 12856, 13, 5754, 14, 8332, 199, 624, 199, 199, 646, 295, 199, 646, 2050, 199, 199, 504, 18918, 492, 10166, 199, 504, 18918, 14, 1014, 492, 4784, 199, 504, 18918, 14, 1208, 14, 16916, 555, 468, 492, 7097, 63, 5245, 199, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 421, 199, 533, 28856, 2124, 6608, 8, 785, 304, 339, 347, 636, 826, 721, 277, 12, 5020, 304, 267, 291, 14, 3200, 275, 5020, 339, 768, 3744, 272, 347, 687, 63, 23972, 8, 1886, 12, 29550, 304, 267, 312, 275, 843, 8, 23972, 14, 3200, 9, 267, 29550, 14, 10458, 14, 2242, 8, 79, 14, 12856, 63, 19234, 12, 4673, 29, 10458, 14, 12856, 63, 19234, 9, 267, 372, 312, 339, 347, 2112, 63, 12856, 63, 1199, 8, 277, 12, 1177, 12, 754, 12, 18094, 304, 267, 367, 671, 315, 754, 26, 288, 340, 1228, 8, 88, 12, 4784, 304, 355, 340, 671, 14, 18671, 63, 1541, 503, 291, 14, 5626, 63, 7207, 8, 88, 12, 18094, 304, 490, 1995, 671, 355, 587, 26, 490, 2881, 275, 7097, 63, 5245, 8, 88, 680, 4269, 490, 340, 2881, 436, 2881, 440, 315, 291, 14, 9756, 63, 8606, 26, 717, 291, 14, 9756, 63, 8606, 14, 525, 8, 2261, 9, 717, 2512, 14, 1757, 480, 13079, 3014, 2331, 2124, 1056, 370, 2818, 2261, 9, 82, 26, 2818, 1069, 9, 83, 401, 3660, 791, 2261, 356, 2881, 12, 283, 1069, 356, 671, 1386, 2402, 3713, 12856, 356, 18094, 1552, 717, 291, 14, 3200, 14, 6559, 63, 585, 360, 1997, 2124, 15, 9756, 297, 18094, 29, 12856, 9, 490, 291, 14, 3200, 14, 6559, 63, 585, 360, 1997, 2124, 15, 11142, 297, 18094, 29, 12856, 9, 288, 587, 26, 355, 1995, 671, 339, 347, 1077, 63, 7207, 8, 277, 12, 1056, 12, 18094, 304, 267, 5163, 275, 291, 14, 1102, 63, 3821, 267, 327, 6246, 883, 506, 488, 367, 6835, 8187, 334, 2930, 18910, 6220, 9, 267, 1591, 275, 7097, 63, 5245, 8, 1069, 680, 4269, 503, 2125, 267, 372, 2155, 8, 3821, 14, 1733, 8, 1102, 430, 339, 347, 664, 63, 1102, 63, 3821, 8, 277, 12, 18094, 304, 267, 408, 11954, 642, 1083, 370, 5669, 282, 3365, 2331, 2124, 4592, 624, 267, 4370, 63, 9756, 275, 2519, 8, 12856, 12, 283, 6541, 63, 9756, 297, 488, 9, 267, 340, 440, 4370, 63, 9756, 26, 288, 372, 295, 14, 2014, 8355, 327, 2040, 1006, 701, 849, 267, 5163, 275, 519, 4289, 19276, 20316, 4042, 83, 9, 12913, 450, 21590, 904, 8, 264, 14, 3765, 8, 68, 9, 367, 366, 315, 4370, 63, 9756, 340, 366, 365, 440, 488, 9, 267, 372, 295, 14, 2014, 8, 3821, 9, 339, 347, 18094, 63, 19234, 8, 277, 12, 18094, 304, 267, 291, 14, 1102, 63, 3821, 275, 291, 14, 362, 63, 1102, 63, 3821, 8, 12856, 9, 267, 291, 14, 9756, 63, 8606, 275, 663, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 199, 5195, 2124, 428, 12508, 603, 3551, 199, 199, 9295, 3794, 315, 9149, 15, 11299, 15, 12856, 13, 5754, 14, 8332, 199, 624, 199, 199, 646, 295, 199, 646, 2050, 199, 199, 504, 18918, 492, 10166, 199, 504, 18918, 14, 1014, 492, 4784, 199, 504, 18918, 14, 1208, 14, 16916, 555, 468, 492, 7097, 63, 5245, 199, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 421, 199, 533, 28856, 2124, 6608, 8, 785, 304, 339, 347, 636, 826, 721, 277, 12, 5020, 304, 267, 291, 14, 3200, 275, 5020, 339, 768, 3744, 272, 347, 687, 63, 23972, 8, 1886, 12, 29550, 304, 267, 312, 275, 843, 8, 23972, 14, 3200, 9, 267, 29550, 14, 10458, 14, 2242, 8, 79, 14, 12856, 63, 19234, 12, 4673, 29, 10458, 14, 12856, 63, 19234, 9, 267, 372, 312, 339, 347, 2112, 63, 12856, 63, 1199, 8, 277, 12, 1177, 12, 754, 12, 18094, 304, 267, 367, 671, 315, 754, 26, 288, 340, 1228, 8, 88, 12, 4784, 304, 355, 340, 671, 14, 18671, 63, 1541, 503, 291, 14, 5626, 63, 7207, 8, 88, 12, 18094, 304, 490, 1995, 671, 355, 587, 26, 490, 2881, 275, 7097, 63, 5245, 8, 88, 680, 4269, 490, 340, 2881, 436, 2881, 440, 315, 291, 14, 9756, 63, 8606, 26, 717, 291, 14, 9756, 63, 8606, 14, 525, 8, 2261, 9, 717, 2512, 14, 1757, 480, 13079, 3014, 2331, 2124, 1056, 370, 2818, 2261, 9, 82, 26, 2818, 1069, 9, 83, 401, 3660, 791, 2261, 356, 2881, 12, 283, 1069, 356, 671, 1386, 2402, 3713, 12856, 356, 18094, 1552, 717, 291, 14, 3200, 14, 6559, 63, 585, 360, 1997, 2124, 15, 9756, 297, 18094, 29, 12856, 9, 490, 291, 14, 3200, 14, 6559, 63, 585, 360, 1997, 2124, 15, 11142, 297, 18094, 29, 12856, 9, 288, 587, 26, 355, 1995, 671, 339, 347, 1077, 63, 7207, 8, 277, 12, 1056, 12, 18094, 304, 267, 5163, 275, 291, 14, 1102, 63, 3821, 267, 327, 6246, 883, 506, 488, 367, 6835, 8187, 334, 2930, 18910, 6220, 9, 267, 1591, 275, 7097, 63, 5245, 8, 1069, 680, 4269, 503, 2125, 267, 372, 2155, 8, 3821, 14, 1733, 8, 1102, 430, 339, 347, 664, 63, 1102, 63, 3821, 8, 277, 12, 18094, 304, 267, 408, 11954, 642, 1083, 370, 5669, 282, 3365, 2331, 2124, 4592, 624, 267, 4370, 63, 9756, 275, 2519, 8, 12856, 12, 283, 6541, 63, 9756, 297, 488, 9, 267, 340, 440, 4370, 63, 9756, 26, 288, 372, 295, 14, 2014, 8355, 327, 2040, 1006, 701, 849, 267, 5163, 275, 519, 4289, 19276, 20316, 4042, 83, 9, 12913, 450, 21590, 904, 8, 264, 14, 3765, 8, 68, 9, 367, 366, 315, 4370, 63, 9756, 340, 366, 365, 440, 488, 9, 267, 372, 295, 14, 2014, 8, 3821, 9, 339, 347, 18094, 63, 19234, 8, 277, 12, 18094, 304, 267, 291, 14, 1102, 63, 3821, 275, 291, 14, 362, 63, 1102, 63, 3821, 8, 12856, 9, 267, 291, 14, 9756, 63, 8606, 275, 663, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
UKPLab/emnlp2017-claim-identification
src/main/python/process_data_se_WithDevel.py
1
4976
import cPickle import numpy as np import pandas as pd import re import sys from collections import defaultdict def build_data_cv(data_folder, cv=10, clean_string=True): """ Loads data. """ revs = [] pos_file = data_folder[0] # train file neg_file = data_folder[1] # test file devel_file = data_folder[2] vocab = defaultdict(float) for (mysplit,myfile) in [(0,pos_file),(1,neg_file),(2,devel_file)]: with open(myfile, "rb") as f: for line in f: rev = [] strippedLine = line.strip() try: lline,label = strippedLine.split("\t") except ValueError: lline = "" label = strippedLine rev.append(lline.strip()) if clean_string: orig_rev = clean_str(" ".join(rev)) else: orig_rev = " ".join(rev).lower() words = set(orig_rev.split()) for word in words: vocab[word] += 1 datum = {"y":int(label), "text": orig_rev, "num_words": len(orig_rev.split()), "split": mysplit} revs.append(datum) #print revs return revs, vocab def get_W(word_vecs, k=300): """ Get word matrix. W[i] is the vector for word indexed by i """ vocab_size = len(word_vecs) word_idx_map = dict() W = np.zeros(shape=(vocab_size+1, k), dtype='float32') W[0] = np.zeros(k, dtype='float32') i = 1 for word in word_vecs: W[i] = word_vecs[word] word_idx_map[word] = i i += 1 return W, word_idx_map def load_bin_vec(fname, vocab): """ Loads 300x1 word vecs from Google (Mikolov) word2vec """ word_vecs = {} with open(fname, "rb") as f: header = f.readline() vocab_size, layer1_size = map(int, header.split()) binary_len = np.dtype('float32').itemsize * layer1_size for line in xrange(vocab_size): word = [] while True: ch = f.read(1) if ch == ' ': word = ''.join(word) break if ch != '\n': word.append(ch) if word in vocab: word_vecs[word] = np.fromstring(f.read(binary_len), dtype='float32') else: f.read(binary_len) return word_vecs def add_unknown_words(word_vecs, vocab, min_df=1, k=300): """ For words that occur in at least min_df documents, create a separate word vector. 0.25 is chosen so the unknown vectors have (approximately) same variance as pre-trained ones """ for word in vocab: if word not in word_vecs and vocab[word] >= min_df: word_vecs[word] = np.random.uniform(-0.25,0.25,k) def clean_str(string, TREC=False): """ Tokenization/string cleaning for all datasets except for SST. Every dataset is lower cased except for TREC """ string = re.sub(r"[^A-Za-z0-9(),!?\'\`]", " ", string) string = re.sub(r"\'s", " \'s", string) string = re.sub(r"\'ve", " \'ve", string) string = re.sub(r"n\'t", " n\'t", string) string = re.sub(r"\'re", " \'re", string) string = re.sub(r"\'d", " \'d", string) string = re.sub(r"\'ll", " \'ll", string) string = re.sub(r",", " , ", string) string = re.sub(r"!", " ! ", string) string = re.sub(r"\(", " \( ", string) string = re.sub(r"\)", " \) ", string) string = re.sub(r"\?", " \? ", string) string = re.sub(r"\s{2,}", " ", string) return string.strip() if TREC else string.strip().lower() def clean_str_sst(string): """ Tokenization/string cleaning for the SST dataset """ string = re.sub(r"[^A-Za-z0-9(),!?\'\`]", " ", string) string = re.sub(r"\s{2,}", " ", string) return string.strip().lower() if __name__=="__main__": w2v_file = sys.argv[1] trainFile = sys.argv[2] testFile = sys.argv[3] develFile = sys.argv[4] saveFile = sys.argv[5] data_folder = [trainFile,testFile,develFile] print "loading data...", revs, vocab = build_data_cv(data_folder, cv=10, clean_string=True) max_l = np.max(pd.DataFrame(revs)["num_words"]) print "data loaded!" print "number of sentences: " + str(len(revs)) print "vocab size: " + str(len(vocab)) print "max sentence length: " + str(max_l) print "loading word2vec vectors...", sys.stdout.flush() w2v = load_bin_vec(w2v_file, vocab) print "word2vec loaded!" print "num words already in word2vec: " + str(len(w2v)) add_unknown_words(w2v, vocab) W, word_idx_map = get_W(w2v) rand_vecs = {} add_unknown_words(rand_vecs, vocab) W2, _ = get_W(rand_vecs) cPickle.dump([revs, W, W2, word_idx_map, vocab], open(saveFile, "wb")) print "dataset created!" #sys.exit(1) # SE
apache-2.0
[ 646, 17572, 199, 646, 2680, 465, 980, 199, 646, 10634, 465, 6454, 199, 646, 295, 199, 646, 984, 199, 504, 5055, 492, 10018, 421, 199, 318, 1900, 63, 576, 63, 5107, 8, 576, 63, 3741, 12, 6277, 29, 709, 12, 3633, 63, 875, 29, 549, 304, 272, 408, 272, 30367, 666, 14, 272, 408, 272, 27330, 275, 942, 272, 2086, 63, 493, 275, 666, 63, 3741, 59, 16, 61, 327, 3560, 570, 272, 14158, 63, 493, 275, 666, 63, 3741, 59, 17, 61, 327, 511, 570, 272, 477, 1090, 63, 493, 275, 666, 63, 3741, 59, 18, 61, 272, 11181, 275, 10018, 8, 1609, 9, 272, 367, 334, 23726, 16381, 12, 29384, 9, 315, 3842, 16, 12, 1712, 63, 493, 11865, 17, 12, 8705, 63, 493, 11865, 18, 12, 27870, 63, 493, 19532, 489, 543, 1551, 8, 29384, 12, 298, 4848, 531, 465, 289, 26, 267, 367, 1004, 315, 289, 26, 263, 288, 6822, 275, 942, 288, 14489, 3049, 275, 1004, 14, 1913, 342, 6722, 862, 26, 1598, 634, 604, 12, 1302, 275, 14489, 3049, 14, 1294, 4582, 84, 531, 6722, 871, 1722, 26, 507, 420, 634, 604, 275, 3087, 507, 420, 1768, 275, 14489, 3049, 288, 6822, 14, 740, 8, 76, 604, 14, 1913, 1012, 288, 340, 3633, 63, 875, 26, 355, 2306, 63, 4964, 275, 3633, 63, 495, 480, 3680, 904, 8, 4964, 430, 288, 587, 26, 355, 2306, 63, 4964, 275, 298, 3680, 904, 8, 4964, 680, 2325, 342, 288, 5932, 275, 663, 8, 2981, 63, 4964, 14, 1294, 1012, 288, 367, 4349, 315, 5932, 26, 355, 11181, 59, 1027, 61, 847, 413, 288, 18908, 221, 275, 2420, 89, 582, 442, 8, 1302, 395, 221, 1993, 298, 505, 582, 2306, 63, 4964, 12, 19242, 1993, 298, 1507, 63, 3148, 582, 822, 8, 2981, 63, 4964, 14, 1294, 4000, 1993, 298, 1294, 582, 333, 588, 16381, 93, 288, 27330, 14, 740, 8, 18945, 9, 272, 327, 1361, 27330, 272, 372, 27330, 12, 11181, 421, 199, 318, 664, 63, 55, 8, 1027, 63, 25130, 12, 1022, 29, 5863, 304, 272, 408, 272, 2372, 4349, 3634, 14, 644, 59, 73, 61, 365, 314, 5477, 367, 4349, 15235, 701, 284, 272, 408, 272, 11181, 63, 890, 275, 822, 8, 1027, 63, 25130, 9, 272, 4349, 63, 2996, 63, 1130, 275, 1211, 342, 272, 644, 275, 980, 14, 4250, 8, 1392, 2687, 9953, 63, 890, 11, 17, 12, 1022, 395, 2152, 534, 1609, 708, 358, 3777, 272, 644, 59, 16, 61, 275, 980, 14, 4250, 8, 75, 12, 2152, 534, 1609, 708, 358, 272, 284, 275, 413, 272, 367, 4349, 315, 4349, 63, 25130, 26, 267, 644, 59, 73, 61, 275, 4349, 63, 25130, 59, 1027, 61, 267, 4349, 63, 2996, 63, 1130, 59, 1027, 61, 275, 284, 267, 284, 847, 413, 272, 372, 644, 12, 4349, 63, 2996, 63, 1130, 199, 199, 318, 2248, 63, 1393, 63, 6046, 8, 5252, 12, 11181, 304, 272, 408, 272, 30367, 9601, 88, 17, 4349, 10782, 83, 687, 4475, 334, 45, 16625, 32555, 9, 4349, 18, 6046, 272, 408, 272, 4349, 63, 25130, 275, 1052, 272, 543, 1551, 8, 5252, 12, 298, 4848, 531, 465, 289, 26, 267, 1406, 275, 289, 14, 6407, 342, 267, 11181, 63, 890, 12, 4045, 17, 63, 890, 275, 2341, 8, 442, 12, 1406, 14, 1294, 1012, 267, 3366, 63, 552, 275, 980, 14, 2271, 360, 1609, 708, 1959, 21210, 627, 4045, 17, 63, 890, 267, 367, 1004, 315, 4945, 8, 9953, 63, 890, 304, 288, 4349, 275, 942, 288, 1830, 715, 26, 355, 682, 275, 289, 14, 739, 8, 17, 9, 355, 340, 682, 508, 283, 7596, 490, 4349, 275, 6522, 904, 8, 1027, 9, 490, 2059, 355, 340, 682, 1137, 1557, 78, 356, 490, 4349, 14, 740, 8, 335, 9, 259, 288, 340, 4349, 315, 11181, 26, 2049, 4349, 63, 25130, 59, 1027, 61, 275, 980, 14, 13521, 8, 70, 14, 739, 8, 3008, 63, 552, 395, 2152, 534, 1609, 708, 358, 257, 288, 587, 26, 355, 289, 14, 739, 8, 3008, 63, 552, 9, 272, 372, 4349, 63, 25130, 199, 199, 318, 1050, 63, 5187, 63, 3148, 8, 1027, 63, 25130, 12, 11181, 12, 1748, 63, 1587, 29, 17, 12, 1022, 29, 5863, 304, 272, 408, 272, 2104, 5932, 626, 4781, 315, 737, 5210, 1748, 63, 1587, 8247, 12, 1218, 282, 7396, 4349, 5477, 14, 14821, 378, 14, 821, 365, 12414, 880, 314, 5809, 11102, 1172, 334, 16815, 6897, 590, 9, 2011, 11773, 465, 876, 13, 23782, 7869, 272, 408, 272, 367, 4349, 315, 11181, 26, 267, 340, 4349, 440, 315, 4349, 63, 25130, 436, 11181, 59, 1027, 61, 2356, 1748, 63, 1587, 26, 288, 4349, 63, 25130, 59, 1027, 61, 275, 980, 14, 2355, 14, 8830, 2801, 16, 14, 821, 12, 16, 14, 821, 12, 75, 9, 257, 199, 199, 318, 3633, 63, 495, 8, 875, 12, 377, 9481, 29, 797, 304, 272, 408, 272, 8767, 2072, 15, 875, 29579, 367, 1006, 13148, 871, 367, 428, 840, 14, 272, 18414, 4789, 365, 5117, 1930, 68, 871, 367, 377, 9481, 272, 408, 272, 1059, 275, 295, 14, 954, 8, 82, 2, 4735, 33, 13, 13163, 13, 90, 16, 13, 25, 1062, 1, 8995, 1154, 64, 11472, 298, 3872, 1059, 9, 420, 272, 1059, 275, 295, 14, 954, 8, 82, 3212, 7, 83, 401, 298, 8891, 83, 401, 1059, 9, 5591, 1059, 275, 295, 14, 954, 8, 82, 3212, 7, 432, 401, 298, 8891, 432, 401, 1059, 9, 5591, 1059, 275, 295, 14, 954, 8, 82, 2, 78, 3985, 84, 401, 298, 302, 3985, 84, 401, 1059, 9, 5591, 1059, 275, 295, 14, 954, 8, 82, 3212, 7, 264, 401, 298, 8891, 264, 401, 1059, 9, 5591, 1059, 275, 295, 14, 954, 8, 82, 3212, 7, 68, 401, 298, 8891, 68, 401, 1059, 9, 5591, 1059, 275, 295, 14, 954, 8, 82, 3212, 7, 914, 401, 298, 8891, 914, 401, 1059, 9, 5591, 1059, 275, 295, 14, 954, 8, 82, 401, 401, 298, 2360, 3872, 1059, 9, 5591, 1059, 275, 295, 14, 954, 8, 82, 2, 17716, 298, 8546, 3872, 1059, 9, 5591, 1059, 275, 295, 14, 954, 8, 82, 3212, 11854, 298, 25445, 3872, 1059, 9, 5591, 1059, 275, 295, 14 ]
[ 17572, 199, 646, 2680, 465, 980, 199, 646, 10634, 465, 6454, 199, 646, 295, 199, 646, 984, 199, 504, 5055, 492, 10018, 421, 199, 318, 1900, 63, 576, 63, 5107, 8, 576, 63, 3741, 12, 6277, 29, 709, 12, 3633, 63, 875, 29, 549, 304, 272, 408, 272, 30367, 666, 14, 272, 408, 272, 27330, 275, 942, 272, 2086, 63, 493, 275, 666, 63, 3741, 59, 16, 61, 327, 3560, 570, 272, 14158, 63, 493, 275, 666, 63, 3741, 59, 17, 61, 327, 511, 570, 272, 477, 1090, 63, 493, 275, 666, 63, 3741, 59, 18, 61, 272, 11181, 275, 10018, 8, 1609, 9, 272, 367, 334, 23726, 16381, 12, 29384, 9, 315, 3842, 16, 12, 1712, 63, 493, 11865, 17, 12, 8705, 63, 493, 11865, 18, 12, 27870, 63, 493, 19532, 489, 543, 1551, 8, 29384, 12, 298, 4848, 531, 465, 289, 26, 267, 367, 1004, 315, 289, 26, 263, 288, 6822, 275, 942, 288, 14489, 3049, 275, 1004, 14, 1913, 342, 6722, 862, 26, 1598, 634, 604, 12, 1302, 275, 14489, 3049, 14, 1294, 4582, 84, 531, 6722, 871, 1722, 26, 507, 420, 634, 604, 275, 3087, 507, 420, 1768, 275, 14489, 3049, 288, 6822, 14, 740, 8, 76, 604, 14, 1913, 1012, 288, 340, 3633, 63, 875, 26, 355, 2306, 63, 4964, 275, 3633, 63, 495, 480, 3680, 904, 8, 4964, 430, 288, 587, 26, 355, 2306, 63, 4964, 275, 298, 3680, 904, 8, 4964, 680, 2325, 342, 288, 5932, 275, 663, 8, 2981, 63, 4964, 14, 1294, 1012, 288, 367, 4349, 315, 5932, 26, 355, 11181, 59, 1027, 61, 847, 413, 288, 18908, 221, 275, 2420, 89, 582, 442, 8, 1302, 395, 221, 1993, 298, 505, 582, 2306, 63, 4964, 12, 19242, 1993, 298, 1507, 63, 3148, 582, 822, 8, 2981, 63, 4964, 14, 1294, 4000, 1993, 298, 1294, 582, 333, 588, 16381, 93, 288, 27330, 14, 740, 8, 18945, 9, 272, 327, 1361, 27330, 272, 372, 27330, 12, 11181, 421, 199, 318, 664, 63, 55, 8, 1027, 63, 25130, 12, 1022, 29, 5863, 304, 272, 408, 272, 2372, 4349, 3634, 14, 644, 59, 73, 61, 365, 314, 5477, 367, 4349, 15235, 701, 284, 272, 408, 272, 11181, 63, 890, 275, 822, 8, 1027, 63, 25130, 9, 272, 4349, 63, 2996, 63, 1130, 275, 1211, 342, 272, 644, 275, 980, 14, 4250, 8, 1392, 2687, 9953, 63, 890, 11, 17, 12, 1022, 395, 2152, 534, 1609, 708, 358, 3777, 272, 644, 59, 16, 61, 275, 980, 14, 4250, 8, 75, 12, 2152, 534, 1609, 708, 358, 272, 284, 275, 413, 272, 367, 4349, 315, 4349, 63, 25130, 26, 267, 644, 59, 73, 61, 275, 4349, 63, 25130, 59, 1027, 61, 267, 4349, 63, 2996, 63, 1130, 59, 1027, 61, 275, 284, 267, 284, 847, 413, 272, 372, 644, 12, 4349, 63, 2996, 63, 1130, 199, 199, 318, 2248, 63, 1393, 63, 6046, 8, 5252, 12, 11181, 304, 272, 408, 272, 30367, 9601, 88, 17, 4349, 10782, 83, 687, 4475, 334, 45, 16625, 32555, 9, 4349, 18, 6046, 272, 408, 272, 4349, 63, 25130, 275, 1052, 272, 543, 1551, 8, 5252, 12, 298, 4848, 531, 465, 289, 26, 267, 1406, 275, 289, 14, 6407, 342, 267, 11181, 63, 890, 12, 4045, 17, 63, 890, 275, 2341, 8, 442, 12, 1406, 14, 1294, 1012, 267, 3366, 63, 552, 275, 980, 14, 2271, 360, 1609, 708, 1959, 21210, 627, 4045, 17, 63, 890, 267, 367, 1004, 315, 4945, 8, 9953, 63, 890, 304, 288, 4349, 275, 942, 288, 1830, 715, 26, 355, 682, 275, 289, 14, 739, 8, 17, 9, 355, 340, 682, 508, 283, 7596, 490, 4349, 275, 6522, 904, 8, 1027, 9, 490, 2059, 355, 340, 682, 1137, 1557, 78, 356, 490, 4349, 14, 740, 8, 335, 9, 259, 288, 340, 4349, 315, 11181, 26, 2049, 4349, 63, 25130, 59, 1027, 61, 275, 980, 14, 13521, 8, 70, 14, 739, 8, 3008, 63, 552, 395, 2152, 534, 1609, 708, 358, 257, 288, 587, 26, 355, 289, 14, 739, 8, 3008, 63, 552, 9, 272, 372, 4349, 63, 25130, 199, 199, 318, 1050, 63, 5187, 63, 3148, 8, 1027, 63, 25130, 12, 11181, 12, 1748, 63, 1587, 29, 17, 12, 1022, 29, 5863, 304, 272, 408, 272, 2104, 5932, 626, 4781, 315, 737, 5210, 1748, 63, 1587, 8247, 12, 1218, 282, 7396, 4349, 5477, 14, 14821, 378, 14, 821, 365, 12414, 880, 314, 5809, 11102, 1172, 334, 16815, 6897, 590, 9, 2011, 11773, 465, 876, 13, 23782, 7869, 272, 408, 272, 367, 4349, 315, 11181, 26, 267, 340, 4349, 440, 315, 4349, 63, 25130, 436, 11181, 59, 1027, 61, 2356, 1748, 63, 1587, 26, 288, 4349, 63, 25130, 59, 1027, 61, 275, 980, 14, 2355, 14, 8830, 2801, 16, 14, 821, 12, 16, 14, 821, 12, 75, 9, 257, 199, 199, 318, 3633, 63, 495, 8, 875, 12, 377, 9481, 29, 797, 304, 272, 408, 272, 8767, 2072, 15, 875, 29579, 367, 1006, 13148, 871, 367, 428, 840, 14, 272, 18414, 4789, 365, 5117, 1930, 68, 871, 367, 377, 9481, 272, 408, 272, 1059, 275, 295, 14, 954, 8, 82, 2, 4735, 33, 13, 13163, 13, 90, 16, 13, 25, 1062, 1, 8995, 1154, 64, 11472, 298, 3872, 1059, 9, 420, 272, 1059, 275, 295, 14, 954, 8, 82, 3212, 7, 83, 401, 298, 8891, 83, 401, 1059, 9, 5591, 1059, 275, 295, 14, 954, 8, 82, 3212, 7, 432, 401, 298, 8891, 432, 401, 1059, 9, 5591, 1059, 275, 295, 14, 954, 8, 82, 2, 78, 3985, 84, 401, 298, 302, 3985, 84, 401, 1059, 9, 5591, 1059, 275, 295, 14, 954, 8, 82, 3212, 7, 264, 401, 298, 8891, 264, 401, 1059, 9, 5591, 1059, 275, 295, 14, 954, 8, 82, 3212, 7, 68, 401, 298, 8891, 68, 401, 1059, 9, 5591, 1059, 275, 295, 14, 954, 8, 82, 3212, 7, 914, 401, 298, 8891, 914, 401, 1059, 9, 5591, 1059, 275, 295, 14, 954, 8, 82, 401, 401, 298, 2360, 3872, 1059, 9, 5591, 1059, 275, 295, 14, 954, 8, 82, 2, 17716, 298, 8546, 3872, 1059, 9, 5591, 1059, 275, 295, 14, 954, 8, 82, 3212, 11854, 298, 25445, 3872, 1059, 9, 5591, 1059, 275, 295, 14, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
houzhenggang/hiwifi-openwrt-HC5661-HC5761
staging_dir/target-mipsel_r2_uClibc-0.9.33.2/usr/lib/python2.7/ctypes/test/test_callbacks.py
59
8177
import unittest from ctypes import * import _ctypes_test class Callbacks(unittest.TestCase): functype = CFUNCTYPE ## def tearDown(self): ## import gc ## gc.collect() def callback(self, *args): self.got_args = args return args[-1] def check_type(self, typ, arg): PROTO = self.functype.im_func(typ, typ) result = PROTO(self.callback)(arg) if typ == c_float: self.assertAlmostEqual(result, arg, places=5) else: self.assertEqual(self.got_args, (arg,)) self.assertEqual(result, arg) PROTO = self.functype.im_func(typ, c_byte, typ) result = PROTO(self.callback)(-3, arg) if typ == c_float: self.assertAlmostEqual(result, arg, places=5) else: self.assertEqual(self.got_args, (-3, arg)) self.assertEqual(result, arg) ################ def test_byte(self): self.check_type(c_byte, 42) self.check_type(c_byte, -42) def test_ubyte(self): self.check_type(c_ubyte, 42) def test_short(self): self.check_type(c_short, 42) self.check_type(c_short, -42) def test_ushort(self): self.check_type(c_ushort, 42) def test_int(self): self.check_type(c_int, 42) self.check_type(c_int, -42) def test_uint(self): self.check_type(c_uint, 42) def test_long(self): self.check_type(c_long, 42) self.check_type(c_long, -42) def test_ulong(self): self.check_type(c_ulong, 42) def test_longlong(self): # test some 64-bit values, positive and negative self.check_type(c_longlong, 5948291757245277467) self.check_type(c_longlong, -5229388909784190580) self.check_type(c_longlong, 42) self.check_type(c_longlong, -42) def test_ulonglong(self): # test some 64-bit values, with and without msb set. self.check_type(c_ulonglong, 10955412242170339782) self.check_type(c_ulonglong, 3665885499841167458) self.check_type(c_ulonglong, 42) def test_float(self): # only almost equal: double -> float -> double import math self.check_type(c_float, math.e) self.check_type(c_float, -math.e) def test_double(self): self.check_type(c_double, 3.14) self.check_type(c_double, -3.14) def test_longdouble(self): self.check_type(c_longdouble, 3.14) self.check_type(c_longdouble, -3.14) def test_char(self): self.check_type(c_char, "x") self.check_type(c_char, "a") # disabled: would now (correctly) raise a RuntimeWarning about # a memory leak. A callback function cannot return a non-integral # C type without causing a memory leak. ## def test_char_p(self): ## self.check_type(c_char_p, "abc") ## self.check_type(c_char_p, "def") def test_pyobject(self): o = () from sys import getrefcount as grc for o in (), [], object(): initial = grc(o) # This call leaks a reference to 'o'... self.check_type(py_object, o) before = grc(o) # ...but this call doesn't leak any more. Where is the refcount? self.check_type(py_object, o) after = grc(o) self.assertEqual((after, o), (before, o)) def test_unsupported_restype_1(self): # Only "fundamental" result types are supported for callback # functions, the type must have a non-NULL stgdict->setfunc. # POINTER(c_double), for example, is not supported. prototype = self.functype.im_func(POINTER(c_double)) # The type is checked when the prototype is called self.assertRaises(TypeError, prototype, lambda: None) def test_unsupported_restype_2(self): prototype = self.functype.im_func(object) self.assertRaises(TypeError, prototype, lambda: None) def test_issue_7959(self): proto = self.functype.im_func(None) class X(object): def func(self): pass def __init__(self): self.v = proto(self.func) import gc for i in range(32): X() gc.collect() live = [x for x in gc.get_objects() if isinstance(x, X)] self.assertEqual(len(live), 0) def test_issue12483(self): import gc class Nasty: def __del__(self): gc.collect() CFUNCTYPE(None)(lambda x=Nasty(): None) try: WINFUNCTYPE except NameError: pass else: class StdcallCallbacks(Callbacks): functype = WINFUNCTYPE ################################################################ class SampleCallbacksTestCase(unittest.TestCase): def test_integrate(self): # Derived from some then non-working code, posted by David Foster dll = CDLL(_ctypes_test.__file__) # The function prototype called by 'integrate': double func(double); CALLBACK = CFUNCTYPE(c_double, c_double) # The integrate function itself, exposed from the _ctypes_test dll integrate = dll.integrate integrate.argtypes = (c_double, c_double, CALLBACK, c_long) integrate.restype = c_double def func(x): return x**2 result = integrate(0.0, 1.0, CALLBACK(func), 10) diff = abs(result - 1./3.) self.assertLess(diff, 0.01, "%s not less than 0.01" % diff) def test_issue_8959_a(self): from ctypes.util import find_library libc_path = find_library("c") if not libc_path: return # cannot test libc = CDLL(libc_path) @CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int)) def cmp_func(a, b): return a[0] - b[0] array = (c_int * 5)(5, 1, 99, 7, 33) libc.qsort(array, len(array), sizeof(c_int), cmp_func) self.assertEqual(array[:], [1, 5, 7, 33, 99]) try: WINFUNCTYPE except NameError: pass else: def test_issue_8959_b(self): from ctypes.wintypes import BOOL, HWND, LPARAM global windowCount windowCount = 0 @WINFUNCTYPE(BOOL, HWND, LPARAM) def EnumWindowsCallbackFunc(hwnd, lParam): global windowCount windowCount += 1 return True #Allow windows to keep enumerating windll.user32.EnumWindows(EnumWindowsCallbackFunc, 0) def test_callback_register_int(self): # Issue #8275: buggy handling of callback args under Win64 # NOTE: should be run on release builds as well dll = CDLL(_ctypes_test.__file__) CALLBACK = CFUNCTYPE(c_int, c_int, c_int, c_int, c_int, c_int) # All this function does is call the callback with its args squared func = dll._testfunc_cbk_reg_int func.argtypes = (c_int, c_int, c_int, c_int, c_int, CALLBACK) func.restype = c_int def callback(a, b, c, d, e): return a + b + c + d + e result = func(2, 3, 4, 5, 6, CALLBACK(callback)) self.assertEqual(result, callback(2*2, 3*3, 4*4, 5*5, 6*6)) def test_callback_register_double(self): # Issue #8275: buggy handling of callback args under Win64 # NOTE: should be run on release builds as well dll = CDLL(_ctypes_test.__file__) CALLBACK = CFUNCTYPE(c_double, c_double, c_double, c_double, c_double, c_double) # All this function does is call the callback with its args squared func = dll._testfunc_cbk_reg_double func.argtypes = (c_double, c_double, c_double, c_double, c_double, CALLBACK) func.restype = c_double def callback(a, b, c, d, e): return a + b + c + d + e result = func(1.1, 2.2, 3.3, 4.4, 5.5, CALLBACK(callback)) self.assertEqual(result, callback(1.1*1.1, 2.2*2.2, 3.3*3.3, 4.4*4.4, 5.5*5.5)) ################################################################ if __name__ == '__main__': unittest.main()
gpl-2.0
[ 646, 2882, 199, 504, 5577, 492, 627, 199, 646, 485, 9798, 63, 396, 199, 199, 533, 17555, 83, 8, 2796, 14, 1746, 304, 272, 9627, 3667, 275, 11093, 199, 199, 309, 259, 347, 6766, 8, 277, 304, 199, 309, 263, 492, 9486, 199, 309, 263, 9486, 14, 7112, 342, 339, 347, 3233, 8, 277, 12, 627, 589, 304, 267, 291, 14, 7808, 63, 589, 275, 1249, 267, 372, 1249, 1988, 17, 61, 339, 347, 1104, 63, 466, 8, 277, 12, 6211, 12, 1680, 304, 267, 3611, 2566, 275, 291, 14, 7036, 3667, 14, 1017, 63, 1532, 8, 9749, 12, 6211, 9, 267, 754, 275, 3611, 2566, 8, 277, 14, 3058, 5130, 1273, 9, 267, 340, 6211, 508, 286, 63, 1609, 26, 288, 291, 14, 7904, 8, 1099, 12, 1680, 12, 9825, 29, 21, 9, 267, 587, 26, 288, 291, 14, 629, 8, 277, 14, 7808, 63, 589, 12, 334, 1273, 4641, 288, 291, 14, 629, 8, 1099, 12, 1680, 9, 398, 3611, 2566, 275, 291, 14, 7036, 3667, 14, 1017, 63, 1532, 8, 9749, 12, 286, 63, 4414, 12, 6211, 9, 267, 754, 275, 3611, 2566, 8, 277, 14, 3058, 9, 2801, 19, 12, 1680, 9, 267, 340, 6211, 508, 286, 63, 1609, 26, 288, 291, 14, 7904, 8, 1099, 12, 1680, 12, 9825, 29, 21, 9, 267, 587, 26, 288, 291, 14, 629, 8, 277, 14, 7808, 63, 589, 12, 5868, 19, 12, 1680, 430, 288, 291, 14, 629, 8, 1099, 12, 1680, 9, 339, 21905, 339, 347, 511, 63, 4414, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 4414, 12, 5685, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 4414, 12, 446, 2260, 9, 339, 347, 511, 63, 20790, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 20790, 12, 5685, 9, 339, 347, 511, 63, 3612, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 3612, 12, 5685, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 3612, 12, 446, 2260, 9, 339, 347, 511, 63, 27170, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 27170, 12, 5685, 9, 339, 347, 511, 63, 442, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 442, 12, 5685, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 442, 12, 446, 2260, 9, 339, 347, 511, 63, 1635, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 1635, 12, 5685, 9, 339, 347, 511, 63, 2809, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 2809, 12, 5685, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 2809, 12, 446, 2260, 9, 339, 347, 511, 63, 15688, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 15688, 12, 5685, 9, 339, 347, 511, 63, 2809, 2809, 8, 277, 304, 267, 327, 511, 2005, 5049, 13, 2075, 1338, 12, 7317, 436, 6946, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 2809, 2809, 12, 8155, 2006, 1398, 1196, 1641, 1194, 2528, 15464, 1822, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 2809, 2809, 12, 446, 29915, 3129, 13976, 17790, 1349, 1167, 1717, 1257, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 2809, 2809, 12, 5685, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 2809, 2809, 12, 446, 2260, 9, 339, 347, 511, 63, 32020, 8, 277, 304, 267, 327, 511, 2005, 5049, 13, 2075, 1338, 12, 543, 436, 1928, 6605, 66, 663, 14, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 32020, 12, 24058, 19264, 713, 1194, 9335, 8762, 25, 23199, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 32020, 12, 650, 16373, 1299, 1477, 1020, 1349, 7524, 1342, 2010, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 32020, 12, 5685, 9, 339, 347, 511, 63, 1609, 8, 277, 304, 267, 327, 1454, 18871, 4472, 26, 4270, 1035, 2069, 1035, 4270, 267, 492, 3473, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 1609, 12, 3473, 14, 69, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 1609, 12, 446, 3442, 14, 69, 9, 339, 347, 511, 63, 3157, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 3157, 12, 650, 14, 1079, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 3157, 12, 446, 19, 14, 1079, 9, 339, 347, 511, 63, 2809, 3157, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 2809, 3157, 12, 650, 14, 1079, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 2809, 3157, 12, 446, 19, 14, 1079, 9, 339, 347, 511, 63, 1560, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 1560, 12, 298, 88, 531, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 1560, 12, 298, 65, 531, 339, 327, 6980, 26, 3955, 3063, 334, 4525, 590, 9, 746, 282, 25178, 3595, 272, 327, 282, 4402, 25831, 14, 221, 437, 3233, 805, 3913, 372, 282, 2222, 13, 24705, 272, 327, 445, 730, 1928, 25498, 282, 4402, 25831, 14, 199, 309, 259, 347, 511, 63, 1560, 63, 80, 8, 277, 304, 199, 309, 263, 291, 14, 1074, 63, 466, 8, 67, 63, 1560, 63, 80, 12, 298, 3175, 531, 199, 309, 263, 291, 14, 1074, 63, 466, 8, 67, 63, 1560, 63, 80, 12, 298, 318, 531, 339, 347, 511, 63, 31614, 8, 277, 304, 267, 312, 275, 6248, 267, 687, 984, 492, 664, 16497, 465, 486, 1195, 267, 367, 312, 315, 11969, 990, 909, 837, 288, 2536, 275, 486, 1195, 8, 79, 9, 288, 327, 961, 1240, 1026, 14631, 282, 3659, 370, 283, 79, 7, 1396, 288, 291, 14, 1074, 63, 466, 8, 647, 63, 785, 12, 312, 9, 288, 2544, 275, 486, 1195, 8, 79, 9, 288, 327, 2263, 7911, 642, 1240, 3181, 1133, 25831, 1263, 1655, 14, 221, 17685, 365, 314, 2984, 835, 31, 288, 291, 14, 1074, 63, 466, 8, 647, 63, 785, 12, 312, 9, 288, 2410, 275, 486, 1195, 8, 79, 9, 288, 291, 14, 629, 1332, 4399, 12, 312, 395, 334, 5182, 12 ]
[ 2882, 199, 504, 5577, 492, 627, 199, 646, 485, 9798, 63, 396, 199, 199, 533, 17555, 83, 8, 2796, 14, 1746, 304, 272, 9627, 3667, 275, 11093, 199, 199, 309, 259, 347, 6766, 8, 277, 304, 199, 309, 263, 492, 9486, 199, 309, 263, 9486, 14, 7112, 342, 339, 347, 3233, 8, 277, 12, 627, 589, 304, 267, 291, 14, 7808, 63, 589, 275, 1249, 267, 372, 1249, 1988, 17, 61, 339, 347, 1104, 63, 466, 8, 277, 12, 6211, 12, 1680, 304, 267, 3611, 2566, 275, 291, 14, 7036, 3667, 14, 1017, 63, 1532, 8, 9749, 12, 6211, 9, 267, 754, 275, 3611, 2566, 8, 277, 14, 3058, 5130, 1273, 9, 267, 340, 6211, 508, 286, 63, 1609, 26, 288, 291, 14, 7904, 8, 1099, 12, 1680, 12, 9825, 29, 21, 9, 267, 587, 26, 288, 291, 14, 629, 8, 277, 14, 7808, 63, 589, 12, 334, 1273, 4641, 288, 291, 14, 629, 8, 1099, 12, 1680, 9, 398, 3611, 2566, 275, 291, 14, 7036, 3667, 14, 1017, 63, 1532, 8, 9749, 12, 286, 63, 4414, 12, 6211, 9, 267, 754, 275, 3611, 2566, 8, 277, 14, 3058, 9, 2801, 19, 12, 1680, 9, 267, 340, 6211, 508, 286, 63, 1609, 26, 288, 291, 14, 7904, 8, 1099, 12, 1680, 12, 9825, 29, 21, 9, 267, 587, 26, 288, 291, 14, 629, 8, 277, 14, 7808, 63, 589, 12, 5868, 19, 12, 1680, 430, 288, 291, 14, 629, 8, 1099, 12, 1680, 9, 339, 21905, 339, 347, 511, 63, 4414, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 4414, 12, 5685, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 4414, 12, 446, 2260, 9, 339, 347, 511, 63, 20790, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 20790, 12, 5685, 9, 339, 347, 511, 63, 3612, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 3612, 12, 5685, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 3612, 12, 446, 2260, 9, 339, 347, 511, 63, 27170, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 27170, 12, 5685, 9, 339, 347, 511, 63, 442, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 442, 12, 5685, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 442, 12, 446, 2260, 9, 339, 347, 511, 63, 1635, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 1635, 12, 5685, 9, 339, 347, 511, 63, 2809, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 2809, 12, 5685, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 2809, 12, 446, 2260, 9, 339, 347, 511, 63, 15688, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 15688, 12, 5685, 9, 339, 347, 511, 63, 2809, 2809, 8, 277, 304, 267, 327, 511, 2005, 5049, 13, 2075, 1338, 12, 7317, 436, 6946, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 2809, 2809, 12, 8155, 2006, 1398, 1196, 1641, 1194, 2528, 15464, 1822, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 2809, 2809, 12, 446, 29915, 3129, 13976, 17790, 1349, 1167, 1717, 1257, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 2809, 2809, 12, 5685, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 2809, 2809, 12, 446, 2260, 9, 339, 347, 511, 63, 32020, 8, 277, 304, 267, 327, 511, 2005, 5049, 13, 2075, 1338, 12, 543, 436, 1928, 6605, 66, 663, 14, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 32020, 12, 24058, 19264, 713, 1194, 9335, 8762, 25, 23199, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 32020, 12, 650, 16373, 1299, 1477, 1020, 1349, 7524, 1342, 2010, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 32020, 12, 5685, 9, 339, 347, 511, 63, 1609, 8, 277, 304, 267, 327, 1454, 18871, 4472, 26, 4270, 1035, 2069, 1035, 4270, 267, 492, 3473, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 1609, 12, 3473, 14, 69, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 1609, 12, 446, 3442, 14, 69, 9, 339, 347, 511, 63, 3157, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 3157, 12, 650, 14, 1079, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 3157, 12, 446, 19, 14, 1079, 9, 339, 347, 511, 63, 2809, 3157, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 2809, 3157, 12, 650, 14, 1079, 9, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 2809, 3157, 12, 446, 19, 14, 1079, 9, 339, 347, 511, 63, 1560, 8, 277, 304, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 1560, 12, 298, 88, 531, 267, 291, 14, 1074, 63, 466, 8, 67, 63, 1560, 12, 298, 65, 531, 339, 327, 6980, 26, 3955, 3063, 334, 4525, 590, 9, 746, 282, 25178, 3595, 272, 327, 282, 4402, 25831, 14, 221, 437, 3233, 805, 3913, 372, 282, 2222, 13, 24705, 272, 327, 445, 730, 1928, 25498, 282, 4402, 25831, 14, 199, 309, 259, 347, 511, 63, 1560, 63, 80, 8, 277, 304, 199, 309, 263, 291, 14, 1074, 63, 466, 8, 67, 63, 1560, 63, 80, 12, 298, 3175, 531, 199, 309, 263, 291, 14, 1074, 63, 466, 8, 67, 63, 1560, 63, 80, 12, 298, 318, 531, 339, 347, 511, 63, 31614, 8, 277, 304, 267, 312, 275, 6248, 267, 687, 984, 492, 664, 16497, 465, 486, 1195, 267, 367, 312, 315, 11969, 990, 909, 837, 288, 2536, 275, 486, 1195, 8, 79, 9, 288, 327, 961, 1240, 1026, 14631, 282, 3659, 370, 283, 79, 7, 1396, 288, 291, 14, 1074, 63, 466, 8, 647, 63, 785, 12, 312, 9, 288, 2544, 275, 486, 1195, 8, 79, 9, 288, 327, 2263, 7911, 642, 1240, 3181, 1133, 25831, 1263, 1655, 14, 221, 17685, 365, 314, 2984, 835, 31, 288, 291, 14, 1074, 63, 466, 8, 647, 63, 785, 12, 312, 9, 288, 2410, 275, 486, 1195, 8, 79, 9, 288, 291, 14, 629, 1332, 4399, 12, 312, 395, 334, 5182, 12, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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BarReader, OpenPrice, add_security_data, all_pairs_matching_predicate, all_subindices, assert_single_position, assert_timestamp_equal, check_allclose, check_arrays, chrange, create_daily_df_for_asset, create_data_portal, create_data_portal_from_trade_history, create_empty_splits_mergers_frame, create_minute_bar_data, create_minute_df_for_asset, drain_zipline, empty_asset_finder, empty_assets_db, empty_trading_env, make_alternating_boolean_array, make_cascading_boolean_array, make_test_handler, make_trade_data_for_asset_info, parameter_space, patch_os_environment, patch_read_csv, permute_rows, powerset, product_upper_triangle, read_compressed, seconds_to_timestamp, security_list_copy, str_to_seconds, subtest, temp_pipeline_engine, test_resource_path, tmp_asset_finder, tmp_assets_db, tmp_bcolz_equity_minute_bar_reader, tmp_dir, tmp_trading_env, to_series, to_utc, trades_by_sid_to_dfs, write_bcolz_minute_data, write_compressed, ) from .fixtures import ZiplineTestCase # noqa
apache-2.0
[ 504, 1275, 1018, 492, 334, 221, 327, 8151, 272, 25670, 998, 12, 272, 25670, 998, 25800, 12631, 12, 272, 662, 1512, 1244, 12, 272, 7910, 320, 1098, 1692, 12, 272, 7777, 1451, 26708, 12, 272, 16347, 281, 1451, 26708, 12, 272, 4420, 36, 17550, 5281, 5929, 12, 272, 3232, 11826, 12, 272, 1050, 63, 4416, 63, 576, 12, 272, 1006, 63, 7322, 63, 9467, 63, 14463, 12, 272, 1006, 63, 954, 4108, 12, 272, 702, 63, 4780, 63, 3124, 12, 272, 702, 63, 3954, 63, 1452, 12, 272, 1104, 63, 7520, 12, 272, 1104, 63, 10095, 12, 272, 682, 1842, 12, 272, 1218, 63, 18621, 63, 1587, 63, 509, 63, 6562, 12, 272, 1218, 63, 576, 63, 8707, 12, 272, 1218, 63, 576, 63, 8707, 63, 504, 63, 21697, 63, 5570, 12, 272, 1218, 63, 1667, 63, 16508, 63, 2626, 31988, 63, 1943, 12, 272, 1218, 63, 10698, 63, 1700, 63, 576, 12, 272, 1218, 63, 10698, 63, 1587, 63, 509, 63, 6562, 12, 272, 366, 6322, 63, 3065, 604, 12, 272, 2701, 63, 6562, 63, 11681, 12, 272, 2701, 63, 12186, 63, 697, 12, 272, 2701, 63, 1239, 1098, 63, 1813, 12, 272, 1852, 63, 10280, 1958, 63, 4871, 63, 1144, 12, 272, 1852, 63, 9765, 67, 5384, 63, 4871, 63, 1144, 12, 272, 1852, 63, 396, 63, 2232, 12, 272, 1852, 63, 21697, 63, 576, 63, 509, 63, 6562, 63, 815, 12, 272, 2725, 63, 2638, 12, 272, 3371, 63, 736, 63, 5418, 12, 272, 3371, 63, 739, 63, 4737, 12, 272, 10869, 938, 63, 3838, 12, 272, 7074, 409, 12, 272, 3336, 63, 4142, 63, 21584, 12, 272, 1586, 63, 10895, 12, 272, 4696, 63, 475, 63, 3954, 12, 272, 6391, 63, 513, 63, 1574, 12, 272, 620, 63, 475, 63, 4515, 12, 272, 1007, 396, 12, 272, 2388, 63, 7379, 63, 3908, 12, 272, 511, 63, 1927, 63, 515, 12, 272, 3529, 63, 6562, 63, 11681, 12, 272, 3529, 63, 12186, 63, 697, 12, 272, 3529, 63, 66, 761, 90, 63, 69, 783, 369, 63, 10698, 63, 1700, 63, 5503, 12, 272, 3529, 63, 694, 12, 272, 3529, 63, 1239, 1098, 63, 1813, 12, 272, 370, 63, 5602, 12, 272, 370, 63, 5834, 12, 272, 1468, 3424, 63, 991, 63, 4148, 63, 475, 63, 10434, 12, 272, 2218, 63, 66, 761, 90, 63, 10698, 63, 576, 12, 272, 2218, 63, 10895, 12, 199, 9, 199, 504, 1275, 8769, 492, 16688, 604, 1746, 221, 327, 8151, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1275, 1018, 492, 334, 221, 327, 8151, 272, 25670, 998, 12, 272, 25670, 998, 25800, 12631, 12, 272, 662, 1512, 1244, 12, 272, 7910, 320, 1098, 1692, 12, 272, 7777, 1451, 26708, 12, 272, 16347, 281, 1451, 26708, 12, 272, 4420, 36, 17550, 5281, 5929, 12, 272, 3232, 11826, 12, 272, 1050, 63, 4416, 63, 576, 12, 272, 1006, 63, 7322, 63, 9467, 63, 14463, 12, 272, 1006, 63, 954, 4108, 12, 272, 702, 63, 4780, 63, 3124, 12, 272, 702, 63, 3954, 63, 1452, 12, 272, 1104, 63, 7520, 12, 272, 1104, 63, 10095, 12, 272, 682, 1842, 12, 272, 1218, 63, 18621, 63, 1587, 63, 509, 63, 6562, 12, 272, 1218, 63, 576, 63, 8707, 12, 272, 1218, 63, 576, 63, 8707, 63, 504, 63, 21697, 63, 5570, 12, 272, 1218, 63, 1667, 63, 16508, 63, 2626, 31988, 63, 1943, 12, 272, 1218, 63, 10698, 63, 1700, 63, 576, 12, 272, 1218, 63, 10698, 63, 1587, 63, 509, 63, 6562, 12, 272, 366, 6322, 63, 3065, 604, 12, 272, 2701, 63, 6562, 63, 11681, 12, 272, 2701, 63, 12186, 63, 697, 12, 272, 2701, 63, 1239, 1098, 63, 1813, 12, 272, 1852, 63, 10280, 1958, 63, 4871, 63, 1144, 12, 272, 1852, 63, 9765, 67, 5384, 63, 4871, 63, 1144, 12, 272, 1852, 63, 396, 63, 2232, 12, 272, 1852, 63, 21697, 63, 576, 63, 509, 63, 6562, 63, 815, 12, 272, 2725, 63, 2638, 12, 272, 3371, 63, 736, 63, 5418, 12, 272, 3371, 63, 739, 63, 4737, 12, 272, 10869, 938, 63, 3838, 12, 272, 7074, 409, 12, 272, 3336, 63, 4142, 63, 21584, 12, 272, 1586, 63, 10895, 12, 272, 4696, 63, 475, 63, 3954, 12, 272, 6391, 63, 513, 63, 1574, 12, 272, 620, 63, 475, 63, 4515, 12, 272, 1007, 396, 12, 272, 2388, 63, 7379, 63, 3908, 12, 272, 511, 63, 1927, 63, 515, 12, 272, 3529, 63, 6562, 63, 11681, 12, 272, 3529, 63, 12186, 63, 697, 12, 272, 3529, 63, 66, 761, 90, 63, 69, 783, 369, 63, 10698, 63, 1700, 63, 5503, 12, 272, 3529, 63, 694, 12, 272, 3529, 63, 1239, 1098, 63, 1813, 12, 272, 370, 63, 5602, 12, 272, 370, 63, 5834, 12, 272, 1468, 3424, 63, 991, 63, 4148, 63, 475, 63, 10434, 12, 272, 2218, 63, 66, 761, 90, 63, 10698, 63, 576, 12, 272, 2218, 63, 10895, 12, 199, 9, 199, 504, 1275, 8769, 492, 16688, 604, 1746, 221, 327, 8151, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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ergionery@gmail.com> # All rights reserved. # BSD license. import networkx as nx __author__ = """\n""".join(['Sérgio Nery Simões <sergionery@gmail.com>', 'Aric Hagberg <aric.hagberg@gmail.com>']) __all__ = ['all_simple_paths'] def all_simple_paths(G, source, target, cutoff=None): """Generate all simple paths in the graph G from source to target. A simple path is a path with no repeated nodes. Parameters ---------- G : NetworkX graph source : node Starting node for path target : node Ending node for path cutoff : integer, optional Depth to stop the search. Only paths of length <= cutoff are returned. Returns ------- path_generator: generator A generator that produces lists of simple paths. If there are no paths between the source and target within the given cutoff the generator produces no output. Examples -------- >>> G = nx.complete_graph(4) >>> for path in nx.all_simple_paths(G, source=0, target=3): ... print(path) ... [0, 1, 2, 3] [0, 1, 3] [0, 2, 1, 3] [0, 2, 3] [0, 3] >>> paths = nx.all_simple_paths(G, source=0, target=3, cutoff=2) >>> print(list(paths)) [[0, 1, 3], [0, 2, 3], [0, 3]] Notes ----- This algorithm uses a modified depth-first search to generate the paths [1]_. A single path can be found in `O(V+E)` time but the number of simple paths in a graph can be very large, e.g. `O(n!)` in the complete graph of order n. References ---------- .. [1] R. Sedgewick, "Algorithms in C, Part 5: Graph Algorithms", Addison Wesley Professional, 3rd ed., 2001. See Also -------- all_shortest_paths, shortest_path """ if source not in G: raise nx.NetworkXError('source node %s not in graph'%source) if target not in G: raise nx.NetworkXError('target node %s not in graph'%target) if cutoff is None: cutoff = len(G)-1 if G.is_multigraph(): return _all_simple_paths_multigraph(G, source, target, cutoff=cutoff) else: return _all_simple_paths_graph(G, source, target, cutoff=cutoff) def _all_simple_paths_graph(G, source, target, cutoff=None): if cutoff < 1: return visited = [source] stack = [iter(G[source])] while stack: children = stack[-1] child = next(children, None) if child is None: stack.pop() visited.pop() elif len(visited) < cutoff: if child == target: yield visited + [target] elif child not in visited: visited.append(child) stack.append(iter(G[child])) else: #len(visited) == cutoff: if child == target or target in children: yield visited + [target] stack.pop() visited.pop() def _all_simple_paths_multigraph(G, source, target, cutoff=None): if cutoff < 1: return visited = [source] stack = [(v for u,v in G.edges(source))] while stack: children = stack[-1] child = next(children, None) if child is None: stack.pop() visited.pop() elif len(visited) < cutoff: if child == target: yield visited + [target] elif child not in visited: visited.append(child) stack.append((v for u,v in G.edges(child))) else: #len(visited) == cutoff: count = ([child]+list(children)).count(target) for i in range(count): yield visited + [target] stack.pop() visited.pop()
bsd-3-clause
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 259, 1898, 334, 35, 9, 6029, 701, 199, 3, 259, 3739, 71, 2308, 653, 994, 428, 73, 573, 397, 665, 332, 71, 1636, 994, 32, 6799, 14, 957, 30, 199, 3, 259, 2900, 4481, 4644, 14, 199, 3, 259, 6289, 4190, 14, 199, 646, 24313, 465, 8484, 199, 363, 2502, 363, 275, 9638, 78, 23045, 904, 2941, 51, 5741, 12430, 2308, 653, 994, 10751, 128, 114, 397, 665, 332, 71, 1636, 994, 32, 6799, 14, 957, 4206, 1169, 283, 33, 1567, 869, 643, 14630, 665, 285, 530, 14, 72, 643, 14630, 32, 6799, 14, 957, 24782, 199, 363, 452, 363, 275, 788, 452, 63, 4129, 63, 3771, 418, 199, 199, 318, 1006, 63, 4129, 63, 3771, 8, 39, 12, 1350, 12, 1347, 12, 17875, 29, 403, 304, 272, 408, 6864, 1006, 3486, 3792, 315, 314, 3343, 598, 687, 1350, 370, 1347, 14, 339, 437, 3486, 931, 365, 282, 931, 543, 949, 10877, 3380, 14, 339, 3897, 272, 4143, 272, 598, 520, 7220, 56, 3343, 339, 1350, 520, 1031, 2126, 24175, 1031, 367, 931, 339, 1347, 520, 1031, 2126, 9599, 316, 1031, 367, 931, 339, 17875, 520, 3000, 12, 2716, 267, 1487, 13316, 370, 3631, 314, 2754, 14, 5972, 3792, 402, 2582, 2695, 17875, 787, 2138, 14, 339, 1803, 272, 5514, 272, 931, 63, 4679, 26, 4306, 2126, 437, 4306, 626, 16904, 5548, 402, 3486, 3792, 14, 221, 982, 2337, 787, 949, 3792, 2126, 3382, 314, 1350, 436, 1347, 4453, 314, 1627, 17875, 314, 4306, 2126, 16904, 949, 1072, 14, 339, 6058, 272, 3001, 272, 1306, 598, 275, 8484, 14, 4883, 63, 2180, 8, 20, 9, 272, 1306, 367, 931, 315, 8484, 14, 452, 63, 4129, 63, 3771, 8, 39, 12, 1350, 29, 16, 12, 1347, 29, 19, 304, 272, 2263, 258, 870, 8, 515, 9, 272, 2263, 272, 359, 16, 12, 413, 12, 499, 12, 650, 61, 272, 359, 16, 12, 413, 12, 650, 61, 272, 359, 16, 12, 499, 12, 413, 12, 650, 61, 272, 359, 16, 12, 499, 12, 650, 61, 272, 359, 16, 12, 650, 61, 272, 1306, 3792, 275, 8484, 14, 452, 63, 4129, 63, 3771, 8, 39, 12, 1350, 29, 16, 12, 1347, 29, 19, 12, 17875, 29, 18, 9, 272, 1306, 870, 8, 513, 8, 3771, 430, 272, 3474, 16, 12, 413, 12, 650, 467, 359, 16, 12, 499, 12, 650, 467, 359, 16, 12, 650, 2677, 339, 8144, 272, 9063, 272, 961, 5563, 4440, 282, 6042, 5818, 13, 2246, 2754, 370, 3550, 314, 272, 3792, 359, 17, 61, 3754, 221, 437, 2849, 931, 883, 506, 1911, 315, 658, 47, 8, 54, 11, 37, 12544, 900, 1325, 314, 272, 1329, 402, 3486, 3792, 315, 282, 3343, 883, 506, 7437, 7031, 12, 325, 14, 71, 14, 658, 47, 8, 78, 1, 12544, 315, 272, 314, 4890, 3343, 402, 1865, 302, 14, 339, 14504, 272, 4143, 272, 2508, 359, 17, 61, 820, 14, 428, 5173, 87, 2000, 12, 298, 2439, 12719, 315, 445, 12, 14320, 959, 26, 11513, 4580, 12719, 401, 2126, 4431, 328, 834, 644, 397, 15515, 2165, 70, 28661, 12, 650, 6883, 3988, 2020, 12521, 14, 339, 1666, 6121, 272, 3001, 272, 1006, 63, 20695, 396, 63, 3771, 12, 26564, 63, 515, 272, 408, 272, 340, 1350, 440, 315, 598, 26, 267, 746, 8484, 14, 4491, 29356, 360, 1365, 1031, 450, 83, 440, 315, 3343, 5956, 1365, 9, 272, 340, 1347, 440, 315, 598, 26, 267, 746, 8484, 14, 4491, 29356, 360, 1375, 1031, 450, 83, 440, 315, 3343, 5956, 1375, 9, 272, 340, 17875, 365, 488, 26, 267, 17875, 275, 822, 8, 39, 7216, 17, 272, 340, 598, 14, 374, 63, 3029, 2180, 837, 267, 372, 485, 452, 63, 4129, 63, 3771, 63, 3029, 2180, 8, 39, 12, 1350, 12, 1347, 12, 17875, 29, 17708, 9, 272, 587, 26, 267, 372, 485, 452, 63, 4129, 63, 3771, 63, 2180, 8, 39, 12, 1350, 12, 1347, 12, 17875, 29, 17708, 9, 199, 199, 318, 485, 452, 63, 4129, 63, 3771, 63, 2180, 8, 39, 12, 1350, 12, 1347, 12, 17875, 29, 403, 304, 272, 340, 17875, 665, 413, 26, 267, 372, 272, 15867, 275, 359, 1365, 61, 272, 3464, 275, 359, 1661, 8, 39, 59, 1365, 12457, 272, 1830, 3464, 26, 267, 4978, 275, 3464, 1988, 17, 61, 267, 1982, 275, 2163, 8, 3223, 12, 488, 9, 267, 340, 1982, 365, 488, 26, 288, 3464, 14, 1935, 342, 288, 15867, 14, 1935, 342, 267, 916, 822, 8, 21736, 9, 665, 17875, 26, 288, 340, 1982, 508, 1347, 26, 355, 1995, 15867, 435, 359, 1375, 61, 288, 916, 1982, 440, 315, 15867, 26, 355, 15867, 14, 740, 8, 1739, 9, 355, 3464, 14, 740, 8, 1661, 8, 39, 59, 1739, 2459, 267, 587, 26, 327, 552, 8, 21736, 9, 508, 17875, 26, 288, 340, 1982, 508, 1347, 503, 1347, 315, 4978, 26, 355, 1995, 15867, 435, 359, 1375, 61, 288, 3464, 14, 1935, 342, 288, 15867, 14, 1935, 342, 421, 199, 318, 485, 452, 63, 4129, 63, 3771, 63, 3029, 2180, 8, 39, 12, 1350, 12, 1347, 12, 17875, 29, 403, 304, 272, 340, 17875, 665, 413, 26, 267, 372, 272, 15867, 275, 359, 1365, 61, 272, 3464, 275, 3842, 86, 367, 399, 12, 86, 315, 598, 14, 6929, 8, 1365, 10524, 272, 1830, 3464, 26, 267, 4978, 275, 3464, 1988, 17, 61, 267, 1982, 275, 2163, 8, 3223, 12, 488, 9, 267, 340, 1982, 365, 488, 26, 288, 3464, 14, 1935, 342, 288, 15867, 14, 1935, 342, 267, 916, 822, 8, 21736, 9, 665, 17875, 26, 288, 340, 1982, 508, 1347, 26, 355, 1995, 15867, 435, 359, 1375, 61, 288, 916, 1982, 440, 315, 15867, 26, 355, 15867, 14, 740, 8, 1739, 9, 355, 3464, 14, 740, 1332, 86, 367, 399, 12, 86, 315, 598, 14, 6929, 8, 1739, 1724, 267, 587, 26, 327, 552, 8, 21736, 9, 508, 17875, 26, 288, 2338, 275, 7287, 1739, 2807, 513, 8, 3223, 4992, 835, 8, 1375, 9, 288, 367, 284, 315, 1425, 8, 835, 304, 355, 1995, 15867, 435, 359, 1375, 61, 288, 3464, 14, 1935, 342, 288, 15867, 14, 1935, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 259, 1898, 334, 35, 9, 6029, 701, 199, 3, 259, 3739, 71, 2308, 653, 994, 428, 73, 573, 397, 665, 332, 71, 1636, 994, 32, 6799, 14, 957, 30, 199, 3, 259, 2900, 4481, 4644, 14, 199, 3, 259, 6289, 4190, 14, 199, 646, 24313, 465, 8484, 199, 363, 2502, 363, 275, 9638, 78, 23045, 904, 2941, 51, 5741, 12430, 2308, 653, 994, 10751, 128, 114, 397, 665, 332, 71, 1636, 994, 32, 6799, 14, 957, 4206, 1169, 283, 33, 1567, 869, 643, 14630, 665, 285, 530, 14, 72, 643, 14630, 32, 6799, 14, 957, 24782, 199, 363, 452, 363, 275, 788, 452, 63, 4129, 63, 3771, 418, 199, 199, 318, 1006, 63, 4129, 63, 3771, 8, 39, 12, 1350, 12, 1347, 12, 17875, 29, 403, 304, 272, 408, 6864, 1006, 3486, 3792, 315, 314, 3343, 598, 687, 1350, 370, 1347, 14, 339, 437, 3486, 931, 365, 282, 931, 543, 949, 10877, 3380, 14, 339, 3897, 272, 4143, 272, 598, 520, 7220, 56, 3343, 339, 1350, 520, 1031, 2126, 24175, 1031, 367, 931, 339, 1347, 520, 1031, 2126, 9599, 316, 1031, 367, 931, 339, 17875, 520, 3000, 12, 2716, 267, 1487, 13316, 370, 3631, 314, 2754, 14, 5972, 3792, 402, 2582, 2695, 17875, 787, 2138, 14, 339, 1803, 272, 5514, 272, 931, 63, 4679, 26, 4306, 2126, 437, 4306, 626, 16904, 5548, 402, 3486, 3792, 14, 221, 982, 2337, 787, 949, 3792, 2126, 3382, 314, 1350, 436, 1347, 4453, 314, 1627, 17875, 314, 4306, 2126, 16904, 949, 1072, 14, 339, 6058, 272, 3001, 272, 1306, 598, 275, 8484, 14, 4883, 63, 2180, 8, 20, 9, 272, 1306, 367, 931, 315, 8484, 14, 452, 63, 4129, 63, 3771, 8, 39, 12, 1350, 29, 16, 12, 1347, 29, 19, 304, 272, 2263, 258, 870, 8, 515, 9, 272, 2263, 272, 359, 16, 12, 413, 12, 499, 12, 650, 61, 272, 359, 16, 12, 413, 12, 650, 61, 272, 359, 16, 12, 499, 12, 413, 12, 650, 61, 272, 359, 16, 12, 499, 12, 650, 61, 272, 359, 16, 12, 650, 61, 272, 1306, 3792, 275, 8484, 14, 452, 63, 4129, 63, 3771, 8, 39, 12, 1350, 29, 16, 12, 1347, 29, 19, 12, 17875, 29, 18, 9, 272, 1306, 870, 8, 513, 8, 3771, 430, 272, 3474, 16, 12, 413, 12, 650, 467, 359, 16, 12, 499, 12, 650, 467, 359, 16, 12, 650, 2677, 339, 8144, 272, 9063, 272, 961, 5563, 4440, 282, 6042, 5818, 13, 2246, 2754, 370, 3550, 314, 272, 3792, 359, 17, 61, 3754, 221, 437, 2849, 931, 883, 506, 1911, 315, 658, 47, 8, 54, 11, 37, 12544, 900, 1325, 314, 272, 1329, 402, 3486, 3792, 315, 282, 3343, 883, 506, 7437, 7031, 12, 325, 14, 71, 14, 658, 47, 8, 78, 1, 12544, 315, 272, 314, 4890, 3343, 402, 1865, 302, 14, 339, 14504, 272, 4143, 272, 2508, 359, 17, 61, 820, 14, 428, 5173, 87, 2000, 12, 298, 2439, 12719, 315, 445, 12, 14320, 959, 26, 11513, 4580, 12719, 401, 2126, 4431, 328, 834, 644, 397, 15515, 2165, 70, 28661, 12, 650, 6883, 3988, 2020, 12521, 14, 339, 1666, 6121, 272, 3001, 272, 1006, 63, 20695, 396, 63, 3771, 12, 26564, 63, 515, 272, 408, 272, 340, 1350, 440, 315, 598, 26, 267, 746, 8484, 14, 4491, 29356, 360, 1365, 1031, 450, 83, 440, 315, 3343, 5956, 1365, 9, 272, 340, 1347, 440, 315, 598, 26, 267, 746, 8484, 14, 4491, 29356, 360, 1375, 1031, 450, 83, 440, 315, 3343, 5956, 1375, 9, 272, 340, 17875, 365, 488, 26, 267, 17875, 275, 822, 8, 39, 7216, 17, 272, 340, 598, 14, 374, 63, 3029, 2180, 837, 267, 372, 485, 452, 63, 4129, 63, 3771, 63, 3029, 2180, 8, 39, 12, 1350, 12, 1347, 12, 17875, 29, 17708, 9, 272, 587, 26, 267, 372, 485, 452, 63, 4129, 63, 3771, 63, 2180, 8, 39, 12, 1350, 12, 1347, 12, 17875, 29, 17708, 9, 199, 199, 318, 485, 452, 63, 4129, 63, 3771, 63, 2180, 8, 39, 12, 1350, 12, 1347, 12, 17875, 29, 403, 304, 272, 340, 17875, 665, 413, 26, 267, 372, 272, 15867, 275, 359, 1365, 61, 272, 3464, 275, 359, 1661, 8, 39, 59, 1365, 12457, 272, 1830, 3464, 26, 267, 4978, 275, 3464, 1988, 17, 61, 267, 1982, 275, 2163, 8, 3223, 12, 488, 9, 267, 340, 1982, 365, 488, 26, 288, 3464, 14, 1935, 342, 288, 15867, 14, 1935, 342, 267, 916, 822, 8, 21736, 9, 665, 17875, 26, 288, 340, 1982, 508, 1347, 26, 355, 1995, 15867, 435, 359, 1375, 61, 288, 916, 1982, 440, 315, 15867, 26, 355, 15867, 14, 740, 8, 1739, 9, 355, 3464, 14, 740, 8, 1661, 8, 39, 59, 1739, 2459, 267, 587, 26, 327, 552, 8, 21736, 9, 508, 17875, 26, 288, 340, 1982, 508, 1347, 503, 1347, 315, 4978, 26, 355, 1995, 15867, 435, 359, 1375, 61, 288, 3464, 14, 1935, 342, 288, 15867, 14, 1935, 342, 421, 199, 318, 485, 452, 63, 4129, 63, 3771, 63, 3029, 2180, 8, 39, 12, 1350, 12, 1347, 12, 17875, 29, 403, 304, 272, 340, 17875, 665, 413, 26, 267, 372, 272, 15867, 275, 359, 1365, 61, 272, 3464, 275, 3842, 86, 367, 399, 12, 86, 315, 598, 14, 6929, 8, 1365, 10524, 272, 1830, 3464, 26, 267, 4978, 275, 3464, 1988, 17, 61, 267, 1982, 275, 2163, 8, 3223, 12, 488, 9, 267, 340, 1982, 365, 488, 26, 288, 3464, 14, 1935, 342, 288, 15867, 14, 1935, 342, 267, 916, 822, 8, 21736, 9, 665, 17875, 26, 288, 340, 1982, 508, 1347, 26, 355, 1995, 15867, 435, 359, 1375, 61, 288, 916, 1982, 440, 315, 15867, 26, 355, 15867, 14, 740, 8, 1739, 9, 355, 3464, 14, 740, 1332, 86, 367, 399, 12, 86, 315, 598, 14, 6929, 8, 1739, 1724, 267, 587, 26, 327, 552, 8, 21736, 9, 508, 17875, 26, 288, 2338, 275, 7287, 1739, 2807, 513, 8, 3223, 4992, 835, 8, 1375, 9, 288, 367, 284, 315, 1425, 8, 835, 304, 355, 1995, 15867, 435, 359, 1375, 61, 288, 3464, 14, 1935, 342, 288, 15867, 14, 1935, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 ]
yuewko/neutron
neutron/plugins/midonet/plugin.py
43
1975
# Copyright (C) 2012 Midokura Japan K.K. # Copyright (C) 2013 Midokura PTE LTD # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from oslo_config import cfg from midonet.neutron import plugin midonet_opts = [ cfg.StrOpt('midonet_uri', default='http://localhost:8080/midonet-api', help=_('MidoNet API server URI.')), cfg.StrOpt('username', default='admin', help=_('MidoNet admin username.')), cfg.StrOpt('password', default='passw0rd', secret=True, help=_('MidoNet admin password.')), cfg.StrOpt('project_id', default='77777777-7777-7777-7777-777777777777', help=_('ID of the project that MidoNet admin user ' 'belongs to.')) ] cfg.CONF.register_opts(midonet_opts, "MIDONET") # Derives from `object` (via at least NeutronDbPluginV2), but pylint # can't see that without having the midonet libraries available. # pylint: disable=super-on-old-class class MidonetPluginV2(plugin.MidonetMixin): vendor_extensions = plugin.MidonetMixin.supported_extension_aliases supported_extension_aliases = ['external-net', 'router', 'security-group', 'agent', 'dhcp_agent_scheduler', 'binding', 'quotas'] + vendor_extensions __native_bulk_support = True def __init__(self): super(MidonetPluginV2, self).__init__()
apache-2.0
[ 3, 1898, 334, 35, 9, 6029, 603, 344, 745, 12417, 1603, 439, 290, 1804, 14, 43, 14, 199, 3, 1898, 334, 35, 9, 6171, 603, 344, 745, 12417, 510, 3727, 24368, 199, 3, 2900, 5924, 5702, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 504, 11258, 63, 888, 492, 4810, 199, 199, 504, 10887, 25759, 14, 10271, 492, 3589, 199, 199, 8523, 25759, 63, 3291, 275, 359, 272, 4810, 14, 19340, 360, 8523, 25759, 63, 2302, 297, 849, 534, 1014, 921, 5967, 26, 15844, 15, 8523, 25759, 13, 1246, 297, 2049, 1720, 12397, 28735, 79, 2480, 3261, 1654, 9022, 2659, 395, 272, 4810, 14, 19340, 360, 2473, 297, 849, 534, 2113, 297, 2049, 1720, 12397, 28735, 79, 2480, 4628, 3434, 2659, 395, 272, 4810, 14, 19340, 360, 2060, 297, 849, 534, 1529, 87, 16, 6883, 297, 2049, 7565, 29, 549, 12, 2049, 1720, 12397, 28735, 79, 2480, 4628, 2505, 2659, 395, 272, 4810, 14, 19340, 360, 1715, 63, 344, 297, 2049, 849, 534, 16713, 16713, 13, 16713, 13, 16713, 13, 16713, 13, 16713, 16713, 16713, 297, 2049, 1720, 12397, 998, 402, 314, 2199, 626, 603, 31090, 2480, 4628, 922, 283, 1993, 283, 20621, 12358, 370, 12459, 199, 61, 421, 199, 4128, 14, 3103, 14, 2683, 63, 3291, 8, 8523, 25759, 63, 3291, 12, 298, 45, 998, 615, 775, 531, 421, 199, 3, 18674, 7602, 687, 658, 785, 64, 334, 12897, 737, 5210, 30422, 8882, 5061, 54, 18, 395, 1325, 4287, 199, 3, 883, 1133, 1937, 626, 1928, 9445, 314, 10887, 25759, 8363, 2808, 14, 199, 3, 4287, 26, 3507, 29, 4792, 13, 265, 13, 1753, 13, 533, 199, 533, 603, 344, 25759, 5061, 54, 18, 8, 2718, 14, 28735, 25759, 4256, 304, 339, 20868, 63, 5359, 275, 3589, 14, 28735, 25759, 4256, 14, 4946, 63, 3435, 63, 8602, 272, 3748, 63, 3435, 63, 8602, 275, 788, 5159, 13, 846, 297, 283, 4995, 297, 283, 4416, 13, 923, 297, 3521, 283, 4054, 297, 283, 10801, 63, 4054, 63, 8874, 297, 283, 9140, 297, 3521, 283, 17056, 418, 435, 20868, 63, 5359, 339, 636, 6106, 63, 9377, 63, 4058, 275, 715, 339, 347, 636, 826, 721, 277, 304, 267, 1613, 8, 28735, 25759, 5061, 54, 18, 12, 291, 2843, 826, 4533, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1898, 334, 35, 9, 6029, 603, 344, 745, 12417, 1603, 439, 290, 1804, 14, 43, 14, 199, 3, 1898, 334, 35, 9, 6171, 603, 344, 745, 12417, 510, 3727, 24368, 199, 3, 2900, 5924, 5702, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 504, 11258, 63, 888, 492, 4810, 199, 199, 504, 10887, 25759, 14, 10271, 492, 3589, 199, 199, 8523, 25759, 63, 3291, 275, 359, 272, 4810, 14, 19340, 360, 8523, 25759, 63, 2302, 297, 849, 534, 1014, 921, 5967, 26, 15844, 15, 8523, 25759, 13, 1246, 297, 2049, 1720, 12397, 28735, 79, 2480, 3261, 1654, 9022, 2659, 395, 272, 4810, 14, 19340, 360, 2473, 297, 849, 534, 2113, 297, 2049, 1720, 12397, 28735, 79, 2480, 4628, 3434, 2659, 395, 272, 4810, 14, 19340, 360, 2060, 297, 849, 534, 1529, 87, 16, 6883, 297, 2049, 7565, 29, 549, 12, 2049, 1720, 12397, 28735, 79, 2480, 4628, 2505, 2659, 395, 272, 4810, 14, 19340, 360, 1715, 63, 344, 297, 2049, 849, 534, 16713, 16713, 13, 16713, 13, 16713, 13, 16713, 13, 16713, 16713, 16713, 297, 2049, 1720, 12397, 998, 402, 314, 2199, 626, 603, 31090, 2480, 4628, 922, 283, 1993, 283, 20621, 12358, 370, 12459, 199, 61, 421, 199, 4128, 14, 3103, 14, 2683, 63, 3291, 8, 8523, 25759, 63, 3291, 12, 298, 45, 998, 615, 775, 531, 421, 199, 3, 18674, 7602, 687, 658, 785, 64, 334, 12897, 737, 5210, 30422, 8882, 5061, 54, 18, 395, 1325, 4287, 199, 3, 883, 1133, 1937, 626, 1928, 9445, 314, 10887, 25759, 8363, 2808, 14, 199, 3, 4287, 26, 3507, 29, 4792, 13, 265, 13, 1753, 13, 533, 199, 533, 603, 344, 25759, 5061, 54, 18, 8, 2718, 14, 28735, 25759, 4256, 304, 339, 20868, 63, 5359, 275, 3589, 14, 28735, 25759, 4256, 14, 4946, 63, 3435, 63, 8602, 272, 3748, 63, 3435, 63, 8602, 275, 788, 5159, 13, 846, 297, 283, 4995, 297, 283, 4416, 13, 923, 297, 3521, 283, 4054, 297, 283, 10801, 63, 4054, 63, 8874, 297, 283, 9140, 297, 3521, 283, 17056, 418, 435, 20868, 63, 5359, 339, 636, 6106, 63, 9377, 63, 4058, 275, 715, 339, 347, 636, 826, 721, 277, 304, 267, 1613, 8, 28735, 25759, 5061, 54, 18, 12, 291, 2843, 826, 4533, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,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, 0, 0, 0, 0, 0 ]
aljscott/phantomjs
src/breakpad/src/third_party/protobuf/protobuf/examples/add_person.py
432
1656
#! /usr/bin/python # See README.txt for information and build instructions. import addressbook_pb2 import sys # This function fills in a Person message based on user input. def PromptForAddress(person): person.id = int(raw_input("Enter person ID number: ")) person.name = raw_input("Enter name: ") email = raw_input("Enter email address (blank for none): ") if email != "": person.email = email while True: number = raw_input("Enter a phone number (or leave blank to finish): ") if number == "": break phone_number = person.phone.add() phone_number.number = number type = raw_input("Is this a mobile, home, or work phone? ") if type == "mobile": phone_number.type = addressbook_pb2.Person.MOBILE elif type == "home": phone_number.type = addressbook_pb2.Person.HOME elif type == "work": phone_number.type = addressbook_pb2.Person.WORK else: print "Unknown phone type; leaving as default value." # Main procedure: Reads the entire address book from a file, # adds one person based on user input, then writes it back out to the same # file. if len(sys.argv) != 2: print "Usage:", sys.argv[0], "ADDRESS_BOOK_FILE" sys.exit(-1) address_book = addressbook_pb2.AddressBook() # Read the existing address book. try: f = open(sys.argv[1], "rb") address_book.ParseFromString(f.read()) f.close() except IOError: print sys.argv[1] + ": File not found. Creating a new file." # Add an address. PromptForAddress(address_book.person.add()) # Write the new address book back to disk. f = open(sys.argv[1], "wb") f.write(address_book.SerializeToString()) f.close()
bsd-3-clause
[ 3168, 1182, 2647, 15, 1393, 15, 1548, 199, 199, 3, 1666, 27781, 14, 2424, 367, 2556, 436, 1900, 15794, 14, 199, 199, 646, 2287, 2706, 63, 3317, 18, 199, 646, 984, 199, 199, 3, 961, 805, 1794, 478, 315, 282, 8028, 1245, 4079, 641, 922, 1324, 14, 199, 318, 2165, 4787, 1858, 1476, 8, 5484, 304, 523, 4954, 14, 344, 275, 1109, 8, 1773, 63, 1210, 480, 8468, 4954, 2870, 1329, 26, 26725, 523, 4954, 14, 354, 275, 3066, 63, 1210, 480, 8468, 536, 26, 6099, 819, 3031, 275, 3066, 63, 1210, 480, 8468, 3031, 2287, 334, 2500, 367, 7179, 304, 6099, 523, 340, 3031, 1137, 10812, 272, 4954, 14, 2123, 275, 3031, 819, 1830, 715, 26, 272, 1329, 275, 3066, 63, 1210, 480, 8468, 282, 14617, 1329, 334, 269, 10137, 4596, 370, 9578, 304, 6099, 272, 340, 1329, 508, 10812, 489, 2059, 339, 14617, 63, 1955, 275, 4954, 14, 9339, 14, 525, 342, 272, 14617, 63, 1955, 14, 1955, 275, 1329, 339, 730, 275, 3066, 63, 1210, 480, 1831, 642, 282, 21305, 12, 5629, 12, 503, 1736, 14617, 31, 6099, 272, 340, 730, 508, 298, 11375, 582, 489, 14617, 63, 1955, 14, 466, 275, 2287, 2706, 63, 3317, 18, 14, 7344, 14, 2679, 34, 8453, 272, 916, 730, 508, 298, 4219, 582, 489, 14617, 63, 1955, 14, 466, 275, 2287, 2706, 63, 3317, 18, 14, 7344, 14, 9524, 272, 916, 730, 508, 298, 800, 582, 489, 14617, 63, 1955, 14, 466, 275, 2287, 2706, 63, 3317, 18, 14, 7344, 14, 8406, 272, 587, 26, 489, 870, 298, 5912, 14617, 730, 27, 23188, 465, 849, 574, 2122, 199, 199, 3, 11298, 17782, 26, 221, 26129, 314, 8039, 2287, 6719, 687, 282, 570, 12, 199, 3, 257, 9584, 1373, 4954, 4079, 641, 922, 1324, 12, 2066, 14511, 652, 1771, 734, 370, 314, 2011, 199, 3, 257, 570, 14, 199, 692, 822, 8, 1274, 14, 3020, 9, 1137, 499, 26, 523, 870, 298, 7692, 6783, 984, 14, 3020, 59, 16, 467, 298, 12368, 63, 21155, 63, 3817, 2, 523, 984, 14, 2224, 2801, 17, 9, 199, 199, 1562, 63, 2706, 275, 2287, 2706, 63, 3317, 18, 14, 1476, 8696, 342, 199, 199, 3, 5574, 314, 3411, 2287, 6719, 14, 199, 893, 26, 523, 289, 275, 1551, 8, 1274, 14, 3020, 59, 17, 467, 298, 4848, 531, 523, 2287, 63, 2706, 14, 28685, 8, 70, 14, 739, 1012, 523, 289, 14, 1600, 342, 199, 2590, 5925, 26, 523, 870, 984, 14, 3020, 59, 17, 61, 435, 7244, 3814, 440, 1911, 14, 221, 20507, 282, 892, 570, 2122, 199, 199, 3, 2654, 376, 2287, 14, 199, 20430, 1858, 1476, 8, 1562, 63, 2706, 14, 5484, 14, 525, 1012, 199, 199, 3, 6990, 314, 892, 2287, 6719, 1771, 370, 4543, 14, 199, 70, 275, 1551, 8, 1274, 14, 3020, 59, 17, 467, 298, 6603, 531, 199, 70, 14, 952, 8, 1562, 63, 2706, 14, 9436, 1012, 199, 70, 14, 1600, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1182, 2647, 15, 1393, 15, 1548, 199, 199, 3, 1666, 27781, 14, 2424, 367, 2556, 436, 1900, 15794, 14, 199, 199, 646, 2287, 2706, 63, 3317, 18, 199, 646, 984, 199, 199, 3, 961, 805, 1794, 478, 315, 282, 8028, 1245, 4079, 641, 922, 1324, 14, 199, 318, 2165, 4787, 1858, 1476, 8, 5484, 304, 523, 4954, 14, 344, 275, 1109, 8, 1773, 63, 1210, 480, 8468, 4954, 2870, 1329, 26, 26725, 523, 4954, 14, 354, 275, 3066, 63, 1210, 480, 8468, 536, 26, 6099, 819, 3031, 275, 3066, 63, 1210, 480, 8468, 3031, 2287, 334, 2500, 367, 7179, 304, 6099, 523, 340, 3031, 1137, 10812, 272, 4954, 14, 2123, 275, 3031, 819, 1830, 715, 26, 272, 1329, 275, 3066, 63, 1210, 480, 8468, 282, 14617, 1329, 334, 269, 10137, 4596, 370, 9578, 304, 6099, 272, 340, 1329, 508, 10812, 489, 2059, 339, 14617, 63, 1955, 275, 4954, 14, 9339, 14, 525, 342, 272, 14617, 63, 1955, 14, 1955, 275, 1329, 339, 730, 275, 3066, 63, 1210, 480, 1831, 642, 282, 21305, 12, 5629, 12, 503, 1736, 14617, 31, 6099, 272, 340, 730, 508, 298, 11375, 582, 489, 14617, 63, 1955, 14, 466, 275, 2287, 2706, 63, 3317, 18, 14, 7344, 14, 2679, 34, 8453, 272, 916, 730, 508, 298, 4219, 582, 489, 14617, 63, 1955, 14, 466, 275, 2287, 2706, 63, 3317, 18, 14, 7344, 14, 9524, 272, 916, 730, 508, 298, 800, 582, 489, 14617, 63, 1955, 14, 466, 275, 2287, 2706, 63, 3317, 18, 14, 7344, 14, 8406, 272, 587, 26, 489, 870, 298, 5912, 14617, 730, 27, 23188, 465, 849, 574, 2122, 199, 199, 3, 11298, 17782, 26, 221, 26129, 314, 8039, 2287, 6719, 687, 282, 570, 12, 199, 3, 257, 9584, 1373, 4954, 4079, 641, 922, 1324, 12, 2066, 14511, 652, 1771, 734, 370, 314, 2011, 199, 3, 257, 570, 14, 199, 692, 822, 8, 1274, 14, 3020, 9, 1137, 499, 26, 523, 870, 298, 7692, 6783, 984, 14, 3020, 59, 16, 467, 298, 12368, 63, 21155, 63, 3817, 2, 523, 984, 14, 2224, 2801, 17, 9, 199, 199, 1562, 63, 2706, 275, 2287, 2706, 63, 3317, 18, 14, 1476, 8696, 342, 199, 199, 3, 5574, 314, 3411, 2287, 6719, 14, 199, 893, 26, 523, 289, 275, 1551, 8, 1274, 14, 3020, 59, 17, 467, 298, 4848, 531, 523, 2287, 63, 2706, 14, 28685, 8, 70, 14, 739, 1012, 523, 289, 14, 1600, 342, 199, 2590, 5925, 26, 523, 870, 984, 14, 3020, 59, 17, 61, 435, 7244, 3814, 440, 1911, 14, 221, 20507, 282, 892, 570, 2122, 199, 199, 3, 2654, 376, 2287, 14, 199, 20430, 1858, 1476, 8, 1562, 63, 2706, 14, 5484, 14, 525, 1012, 199, 199, 3, 6990, 314, 892, 2287, 6719, 1771, 370, 4543, 14, 199, 70, 275, 1551, 8, 1274, 14, 3020, 59, 17, 467, 298, 6603, 531, 199, 70, 14, 952, 8, 1562, 63, 2706, 14, 9436, 1012, 199, 70, 14, 1600, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
alephu5/Soundbyte
environment/lib/python3.3/site-packages/IPython/nbconvert/preprocessors/tests/test_extractoutput.py
8
2601
""" Module with tests for the extractoutput preprocessor """ #----------------------------------------------------------------------------- # Copyright (c) 2013, the IPython Development Team. # # Distributed under the terms of the Modified BSD License. # # The full license is in the file COPYING.txt, distributed with this software. #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- # Imports #----------------------------------------------------------------------------- from .base import PreprocessorTestsBase from ..extractoutput import ExtractOutputPreprocessor #----------------------------------------------------------------------------- # Class #----------------------------------------------------------------------------- class TestExtractOutput(PreprocessorTestsBase): """Contains test functions for extractoutput.py""" def build_preprocessor(self): """Make an instance of a preprocessor""" preprocessor = ExtractOutputPreprocessor() preprocessor.extract_output_types = {'text', 'png', 'application/pdf'} preprocessor.enabled = True return preprocessor def test_constructor(self): """Can a ExtractOutputPreprocessor be constructed?""" self.build_preprocessor() def test_output(self): """Test the output of the ExtractOutputPreprocessor""" nb = self.build_notebook() res = self.build_resources() preprocessor = self.build_preprocessor() nb, res = preprocessor(nb, res) # Check if text was extracted. output = nb.worksheets[0].cells[0].outputs[1] assert 'text_filename' in output text_filename = output['text_filename'] # Check if png was extracted. output = nb.worksheets[0].cells[0].outputs[6] assert 'png_filename' in output png_filename = output['png_filename'] # Check that pdf was extracted output = nb.worksheets[0].cells[0].outputs[7] assert 'application/pdf_filename' in output pdf_filename = output['application/pdf_filename'] # Verify text output assert text_filename in res['outputs'] self.assertEqual(res['outputs'][text_filename], b'b') # Verify png output assert png_filename in res['outputs'] self.assertEqual(res['outputs'][png_filename], b'g') # Verify pdf output assert pdf_filename in res['outputs'] self.assertEqual(res['outputs'][pdf_filename], b'h')
gpl-3.0
[ 624, 199, 2377, 543, 2295, 367, 314, 5536, 1199, 22335, 199, 624, 199, 199, 18045, 199, 3, 1898, 334, 67, 9, 6171, 12, 314, 16243, 15290, 11682, 14, 199, 3, 199, 3, 17484, 1334, 314, 2895, 402, 314, 22016, 6289, 844, 14, 199, 3, 199, 3, 710, 2615, 4190, 365, 315, 314, 570, 9685, 14, 2424, 12, 1854, 543, 642, 2032, 14, 199, 18045, 199, 199, 18045, 199, 3, 24339, 199, 18045, 199, 199, 504, 1275, 1095, 492, 5543, 6459, 2925, 1563, 199, 504, 2508, 5005, 1199, 492, 12892, 2959, 16482, 421, 199, 18045, 199, 3, 8089, 199, 18045, 199, 199, 533, 1379, 12147, 2959, 8, 16482, 2925, 1563, 304, 272, 408, 6906, 511, 3423, 367, 5536, 1199, 14, 647, 624, 2378, 347, 1900, 63, 657, 6459, 8, 277, 304, 267, 408, 5483, 376, 1256, 402, 282, 22335, 624, 267, 22335, 275, 12892, 2959, 16482, 342, 267, 22335, 14, 5005, 63, 1199, 63, 1313, 275, 791, 505, 297, 283, 4524, 297, 283, 3578, 15, 5607, 936, 267, 22335, 14, 3827, 275, 715, 267, 372, 22335, 2378, 347, 511, 63, 1880, 8, 277, 304, 267, 408, 6049, 282, 12892, 2959, 16482, 506, 14701, 30196, 267, 291, 14, 1506, 63, 657, 6459, 342, 1362, 339, 347, 511, 63, 1199, 8, 277, 304, 267, 408, 774, 314, 1072, 402, 314, 12892, 2959, 16482, 624, 267, 8526, 275, 291, 14, 1506, 63, 19174, 342, 267, 522, 275, 291, 14, 1506, 63, 4435, 342, 267, 22335, 275, 291, 14, 1506, 63, 657, 6459, 342, 267, 8526, 12, 522, 275, 22335, 8, 4994, 12, 522, 9, 398, 327, 2670, 340, 1318, 1990, 12509, 14, 267, 1072, 275, 8526, 14, 800, 24376, 59, 16, 1055, 9041, 59, 16, 1055, 4467, 59, 17, 61, 267, 702, 283, 505, 63, 1501, 7, 315, 1072, 267, 1318, 63, 1501, 275, 1072, 459, 505, 63, 1501, 418, 398, 327, 2670, 340, 25296, 1990, 12509, 14, 267, 1072, 275, 8526, 14, 800, 24376, 59, 16, 1055, 9041, 59, 16, 1055, 4467, 59, 22, 61, 267, 702, 283, 4524, 63, 1501, 7, 315, 1072, 267, 25296, 63, 1501, 275, 1072, 459, 4524, 63, 1501, 418, 2728, 327, 2670, 626, 11249, 1990, 12509, 267, 1072, 275, 8526, 14, 800, 24376, 59, 16, 1055, 9041, 59, 16, 1055, 4467, 59, 23, 61, 267, 702, 283, 3578, 15, 5607, 63, 1501, 7, 315, 1072, 267, 11249, 63, 1501, 275, 1072, 459, 3578, 15, 5607, 63, 1501, 418, 398, 327, 7635, 1318, 1072, 267, 702, 1318, 63, 1501, 315, 522, 459, 4467, 418, 267, 291, 14, 629, 8, 470, 459, 4467, 3488, 505, 63, 1501, 467, 330, 7, 66, 358, 398, 327, 7635, 25296, 1072, 267, 702, 25296, 63, 1501, 315, 522, 459, 4467, 418, 267, 291, 14, 629, 8, 470, 459, 4467, 3488, 4524, 63, 1501, 467, 330, 7, 71, 358, 398, 327, 7635, 11249, 1072, 267, 702, 11249, 63, 1501, 315, 522, 459, 4467, 418, 267, 291, 14, 629, 8, 470, 459, 4467, 3488, 5607, 63, 1501, 467, 330, 7, 72, 358, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 199, 2377, 543, 2295, 367, 314, 5536, 1199, 22335, 199, 624, 199, 199, 18045, 199, 3, 1898, 334, 67, 9, 6171, 12, 314, 16243, 15290, 11682, 14, 199, 3, 199, 3, 17484, 1334, 314, 2895, 402, 314, 22016, 6289, 844, 14, 199, 3, 199, 3, 710, 2615, 4190, 365, 315, 314, 570, 9685, 14, 2424, 12, 1854, 543, 642, 2032, 14, 199, 18045, 199, 199, 18045, 199, 3, 24339, 199, 18045, 199, 199, 504, 1275, 1095, 492, 5543, 6459, 2925, 1563, 199, 504, 2508, 5005, 1199, 492, 12892, 2959, 16482, 421, 199, 18045, 199, 3, 8089, 199, 18045, 199, 199, 533, 1379, 12147, 2959, 8, 16482, 2925, 1563, 304, 272, 408, 6906, 511, 3423, 367, 5536, 1199, 14, 647, 624, 2378, 347, 1900, 63, 657, 6459, 8, 277, 304, 267, 408, 5483, 376, 1256, 402, 282, 22335, 624, 267, 22335, 275, 12892, 2959, 16482, 342, 267, 22335, 14, 5005, 63, 1199, 63, 1313, 275, 791, 505, 297, 283, 4524, 297, 283, 3578, 15, 5607, 936, 267, 22335, 14, 3827, 275, 715, 267, 372, 22335, 2378, 347, 511, 63, 1880, 8, 277, 304, 267, 408, 6049, 282, 12892, 2959, 16482, 506, 14701, 30196, 267, 291, 14, 1506, 63, 657, 6459, 342, 1362, 339, 347, 511, 63, 1199, 8, 277, 304, 267, 408, 774, 314, 1072, 402, 314, 12892, 2959, 16482, 624, 267, 8526, 275, 291, 14, 1506, 63, 19174, 342, 267, 522, 275, 291, 14, 1506, 63, 4435, 342, 267, 22335, 275, 291, 14, 1506, 63, 657, 6459, 342, 267, 8526, 12, 522, 275, 22335, 8, 4994, 12, 522, 9, 398, 327, 2670, 340, 1318, 1990, 12509, 14, 267, 1072, 275, 8526, 14, 800, 24376, 59, 16, 1055, 9041, 59, 16, 1055, 4467, 59, 17, 61, 267, 702, 283, 505, 63, 1501, 7, 315, 1072, 267, 1318, 63, 1501, 275, 1072, 459, 505, 63, 1501, 418, 398, 327, 2670, 340, 25296, 1990, 12509, 14, 267, 1072, 275, 8526, 14, 800, 24376, 59, 16, 1055, 9041, 59, 16, 1055, 4467, 59, 22, 61, 267, 702, 283, 4524, 63, 1501, 7, 315, 1072, 267, 25296, 63, 1501, 275, 1072, 459, 4524, 63, 1501, 418, 2728, 327, 2670, 626, 11249, 1990, 12509, 267, 1072, 275, 8526, 14, 800, 24376, 59, 16, 1055, 9041, 59, 16, 1055, 4467, 59, 23, 61, 267, 702, 283, 3578, 15, 5607, 63, 1501, 7, 315, 1072, 267, 11249, 63, 1501, 275, 1072, 459, 3578, 15, 5607, 63, 1501, 418, 398, 327, 7635, 1318, 1072, 267, 702, 1318, 63, 1501, 315, 522, 459, 4467, 418, 267, 291, 14, 629, 8, 470, 459, 4467, 3488, 505, 63, 1501, 467, 330, 7, 66, 358, 398, 327, 7635, 25296, 1072, 267, 702, 25296, 63, 1501, 315, 522, 459, 4467, 418, 267, 291, 14, 629, 8, 470, 459, 4467, 3488, 4524, 63, 1501, 467, 330, 7, 71, 358, 398, 327, 7635, 11249, 1072, 267, 702, 11249, 63, 1501, 315, 522, 459, 4467, 418, 267, 291, 14, 629, 8, 470, 459, 4467, 3488, 5607, 63, 1501, 467, 330, 7, 72, 358, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
huntxu/neutron
neutron/agent/linux/daemon.py
3
7987
# Copyright 2012 New Dream Network, LLC (DreamHost) # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import atexit import fcntl import grp import logging as std_logging from logging import handlers import os import pwd import signal import sys from oslo_log import log as logging from neutron._i18n import _ from neutron.common import exceptions LOG = logging.getLogger(__name__) DEVNULL = object() # Note: We can't use sys.std*.fileno() here. sys.std* objects may be # random file-like objects that may not match the true system std* fds # - and indeed may not even have a file descriptor at all (eg: test # fixtures that monkey patch fixtures.StringStream onto sys.stdout). # Below we always want the _real_ well-known 0,1,2 Unix fds during # os.dup2 manipulation. STDIN_FILENO = 0 STDOUT_FILENO = 1 STDERR_FILENO = 2 def setuid(user_id_or_name): try: new_uid = int(user_id_or_name) except (TypeError, ValueError): new_uid = pwd.getpwnam(user_id_or_name).pw_uid if new_uid != 0: try: os.setuid(new_uid) except OSError: msg = _('Failed to set uid %s') % new_uid LOG.critical(msg) raise exceptions.FailToDropPrivilegesExit(msg) def setgid(group_id_or_name): try: new_gid = int(group_id_or_name) except (TypeError, ValueError): new_gid = grp.getgrnam(group_id_or_name).gr_gid if new_gid != 0: try: os.setgid(new_gid) except OSError: msg = _('Failed to set gid %s') % new_gid LOG.critical(msg) raise exceptions.FailToDropPrivilegesExit(msg) def unwatch_log(): """Replace WatchedFileHandler handlers by FileHandler ones. Neutron logging uses WatchedFileHandler handlers but they do not support privileges drop, this method replaces them by FileHandler handlers supporting privileges drop. """ log_root = logging.getLogger(None).logger to_replace = [h for h in log_root.handlers if isinstance(h, handlers.WatchedFileHandler)] for handler in to_replace: # NOTE(cbrandily): we use default delay(=False) to ensure the log file # is opened before privileges drop. new_handler = std_logging.FileHandler(handler.baseFilename, mode=handler.mode, encoding=handler.encoding) log_root.removeHandler(handler) log_root.addHandler(new_handler) def drop_privileges(user=None, group=None): """Drop privileges to user/group privileges.""" if user is None and group is None: return if os.geteuid() != 0: msg = _('Root permissions are required to drop privileges.') LOG.critical(msg) raise exceptions.FailToDropPrivilegesExit(msg) if group is not None: try: os.setgroups([]) except OSError: msg = _('Failed to remove supplemental groups') LOG.critical(msg) raise exceptions.FailToDropPrivilegesExit(msg) setgid(group) if user is not None: setuid(user) LOG.info("Process runs with uid/gid: %(uid)s/%(gid)s", {'uid': os.getuid(), 'gid': os.getgid()}) class Pidfile(object): def __init__(self, pidfile, procname, uuid=None): self.pidfile = pidfile self.procname = procname self.uuid = uuid try: self.fd = os.open(pidfile, os.O_CREAT | os.O_RDWR) fcntl.flock(self.fd, fcntl.LOCK_EX | fcntl.LOCK_NB) except IOError: LOG.exception("Error while handling pidfile: %s", pidfile) sys.exit(1) def __str__(self): return self.pidfile def unlock(self): fcntl.flock(self.fd, fcntl.LOCK_UN) def write(self, pid): os.ftruncate(self.fd, 0) os.write(self.fd, b"%d" % pid) os.fsync(self.fd) def read(self): try: pid = int(os.read(self.fd, 128)) os.lseek(self.fd, 0, os.SEEK_SET) return pid except ValueError: return def is_running(self): pid = self.read() if not pid: return False cmdline = '/proc/%s/cmdline' % pid try: with open(cmdline, "r") as f: exec_out = f.readline() return self.procname in exec_out and (not self.uuid or self.uuid in exec_out) except IOError: return False class Daemon(object): """A generic daemon class. Usage: subclass the Daemon class and override the run() method """ def __init__(self, pidfile, stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL, procname='python', uuid=None, user=None, group=None): """Note: pidfile may be None.""" self.stdin = stdin self.stdout = stdout self.stderr = stderr self.procname = procname self.pidfile = (Pidfile(pidfile, procname, uuid) if pidfile is not None else None) self.user = user self.group = group def _fork(self): try: pid = os.fork() if pid > 0: os._exit(0) except OSError: LOG.exception('Fork failed') sys.exit(1) def daemonize(self): """Daemonize process by doing Stevens double fork.""" # flush any buffered data before fork/dup2. if self.stdout is not DEVNULL: self.stdout.flush() if self.stderr is not DEVNULL: self.stderr.flush() # sys.std* may not match STD{OUT,ERR}_FILENO. Tough. for f in (sys.stdout, sys.stderr): f.flush() # fork first time self._fork() # decouple from parent environment os.chdir("/") os.setsid() os.umask(0) # fork second time self._fork() # redirect standard file descriptors with open(os.devnull, 'w+') as devnull: stdin = devnull if self.stdin is DEVNULL else self.stdin stdout = devnull if self.stdout is DEVNULL else self.stdout stderr = devnull if self.stderr is DEVNULL else self.stderr os.dup2(stdin.fileno(), STDIN_FILENO) os.dup2(stdout.fileno(), STDOUT_FILENO) os.dup2(stderr.fileno(), STDERR_FILENO) if self.pidfile is not None: # write pidfile atexit.register(self.delete_pid) signal.signal(signal.SIGTERM, self.handle_sigterm) self.pidfile.write(os.getpid()) def delete_pid(self): if self.pidfile is not None: os.remove(str(self.pidfile)) def handle_sigterm(self, signum, frame): sys.exit(0) def start(self): """Start the daemon.""" if self.pidfile is not None and self.pidfile.is_running(): self.pidfile.unlock() LOG.error('Pidfile %s already exist. Daemon already ' 'running?', self.pidfile) sys.exit(1) # Start the daemon self.daemonize() self.run() def run(self): """Override this method and call super().run when subclassing Daemon. start() will call this method after the process has daemonized. """ unwatch_log() drop_privileges(self.user, self.group)
apache-2.0
[ 3, 1898, 6029, 7053, 577, 1091, 7220, 12, 20376, 334, 36, 1091, 4965, 9, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 646, 19840, 199, 646, 12871, 199, 646, 18598, 199, 646, 2050, 465, 2418, 63, 4806, 199, 504, 2050, 492, 8297, 199, 646, 747, 199, 646, 14374, 199, 646, 4673, 199, 646, 984, 199, 199, 504, 11258, 63, 793, 492, 943, 465, 2050, 199, 199, 504, 8224, 423, 73, 1085, 78, 492, 485, 199, 504, 8224, 14, 2330, 492, 4967, 199, 199, 4947, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 13260, 8084, 275, 909, 342, 199, 199, 3, 3390, 26, 2136, 883, 1133, 675, 984, 14, 1516, 4856, 9843, 342, 2348, 14, 221, 984, 14, 1516, 10, 2251, 1443, 506, 199, 3, 2196, 570, 13, 2930, 2251, 626, 1443, 440, 1336, 314, 2549, 2656, 2418, 10, 289, 795, 199, 3, 446, 436, 31043, 379, 1443, 440, 2755, 1172, 282, 570, 5872, 737, 1006, 334, 5902, 26, 511, 199, 3, 15188, 626, 14198, 3371, 15188, 14, 1558, 3296, 14602, 984, 14, 2703, 680, 199, 3, 6423, 674, 781, 3544, 2934, 314, 485, 3093, 63, 5521, 13, 3159, 378, 12, 17, 12, 18, 13074, 289, 795, 5309, 199, 3, 747, 14, 11048, 18, 26212, 14, 199, 18472, 568, 63, 5110, 15577, 275, 378, 199, 13850, 63, 5110, 15577, 275, 413, 199, 18472, 2666, 63, 5110, 15577, 275, 499, 421, 199, 318, 663, 1535, 8, 751, 63, 344, 63, 269, 63, 354, 304, 272, 862, 26, 267, 892, 63, 1535, 275, 1109, 8, 751, 63, 344, 63, 269, 63, 354, 9, 272, 871, 334, 4333, 12, 1722, 304, 267, 892, 63, 1535, 275, 14374, 14, 362, 80, 3501, 455, 8, 751, 63, 344, 63, 269, 63, 354, 680, 8796, 63, 1535, 272, 340, 892, 63, 1535, 1137, 378, 26, 267, 862, 26, 288, 747, 14, 409, 1535, 8, 1222, 63, 1535, 9, 267, 871, 6440, 26, 288, 1499, 275, 4018, 4276, 370, 663, 1747, 450, 83, 358, 450, 892, 63, 1535, 288, 5051, 14, 13138, 8, 1328, 9, 288, 746, 4967, 14, 4874, 1378, 11070, 4562, 13886, 6699, 8, 1328, 9, 421, 199, 318, 663, 8787, 8, 923, 63, 344, 63, 269, 63, 354, 304, 272, 862, 26, 267, 892, 63, 8787, 275, 1109, 8, 923, 63, 344, 63, 269, 63, 354, 9, 272, 871, 334, 4333, 12, 1722, 304, 267, 892, 63, 8787, 275, 18598, 14, 362, 2587, 17811, 8, 923, 63, 344, 63, 269, 63, 354, 680, 2587, 63, 8787, 272, 340, 892, 63, 8787, 1137, 378, 26, 267, 862, 26, 288, 747, 14, 409, 8787, 8, 1222, 63, 8787, 9, 267, 871, 6440, 26, 288, 1499, 275, 4018, 4276, 370, 663, 15122, 450, 83, 358, 450, 892, 63, 8787, 288, 5051, 14, 13138, 8, 1328, 9, 288, 746, 4967, 14, 4874, 1378, 11070, 4562, 13886, 6699, 8, 1328, 9, 421, 199, 318, 625, 6821, 63, 793, 837, 272, 408, 11328, 29075, 379, 21982, 8297, 701, 3814, 2461, 7869, 14, 339, 30422, 2050, 4440, 29075, 379, 21982, 8297, 1325, 2985, 886, 440, 272, 2291, 20001, 5978, 12, 642, 1083, 19058, 3062, 701, 3814, 2461, 272, 8297, 21038, 20001, 5978, 14, 272, 408, 272, 943, 63, 1231, 275, 2050, 14, 5572, 8, 403, 680, 2921, 272, 370, 63, 1814, 275, 359, 72, 367, 394, 315, 943, 63, 1231, 14, 5586, 2116, 340, 1228, 8, 72, 12, 8297, 14, 13978, 379, 21982, 1874, 272, 367, 3016, 315, 370, 63, 1814, 26, 267, 327, 6944, 8, 2894, 1312, 328, 590, 304, 781, 675, 849, 7339, 8, 29, 797, 9, 370, 4868, 314, 943, 570, 267, 327, 365, 12123, 2544, 20001, 5978, 14, 267, 892, 63, 2232, 275, 2418, 63, 4806, 14, 21982, 8, 2232, 14, 1095, 8117, 12, 6343, 818, 29, 2232, 14, 632, 12, 6343, 2644, 29, 2232, 14, 2991, 9, 267, 943, 63, 1231, 14, 2168, 2461, 8, 2232, 9, 267, 943, 63, 1231, 14, 18826, 8, 1222, 63, 2232, 9, 421, 199, 318, 5978, 63, 27852, 8, 751, 29, 403, 12, 1572, 29, 403, 304, 272, 408, 11070, 20001, 370, 922, 15, 923, 20001, 1041, 272, 340, 922, 365, 488, 436, 1572, 365, 488, 26, 267, 372, 339, 340, 747, 14, 31508, 1535, 342, 1137, 378, 26, 267, 1499, 275, 4018, 6405, 3443, 787, 1415, 370, 5978, 20001, 2659, 267, 5051, 14, 13138, 8, 1328, 9, 267, 746, 4967, 14, 4874, 1378, 11070, 4562, 13886, 6699, 8, 1328, 9, 339, 340, 1572, 365, 440, 488, 26, 267, 862, 26, 288, 747, 14, 409, 2634, 4157, 267, 871, 6440, 26, 288, 1499, 275, 4018, 4276, 370, 2813, 4973, 968, 279, 4652, 358, 288, 5051, 14, 13138, 8, 1328, 9, 288, 746, 4967, 14, 4874, 1378, 11070, 4562, 13886, 6699, 8, 1328, 9, 267, 663, 8787, 8, 923, 9, 339, 340, 922, 365, 440, 488, 26, 267, 663, 1535, 8, 751, 9, 339, 5051, 14, 815, 480, 3498, 7858, 543, 1747, 15, 8787, 26, 2818, 1535, 9, 83, 21275, 8787, 9, 83, 401, 1467, 791, 1535, 356, 747, 14, 362, 1535, 1062, 283, 8787, 356, 747, 14, 362, 8787, 22804, 421, 199, 533, 510, 344, 493, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 32739, 12, 6499, 354, 12, 5377, 29, 403, 304, 267, 291, 14, 21957, 275, 32739, 267, 291, 14, 4687, 354, 275, 6499, 354, 267, 291, 14, 2580, 275, 5377, 267, 862, 26, 288, 291, 14 ]
[ 1898, 6029, 7053, 577, 1091, 7220, 12, 20376, 334, 36, 1091, 4965, 9, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 646, 19840, 199, 646, 12871, 199, 646, 18598, 199, 646, 2050, 465, 2418, 63, 4806, 199, 504, 2050, 492, 8297, 199, 646, 747, 199, 646, 14374, 199, 646, 4673, 199, 646, 984, 199, 199, 504, 11258, 63, 793, 492, 943, 465, 2050, 199, 199, 504, 8224, 423, 73, 1085, 78, 492, 485, 199, 504, 8224, 14, 2330, 492, 4967, 199, 199, 4947, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 13260, 8084, 275, 909, 342, 199, 199, 3, 3390, 26, 2136, 883, 1133, 675, 984, 14, 1516, 4856, 9843, 342, 2348, 14, 221, 984, 14, 1516, 10, 2251, 1443, 506, 199, 3, 2196, 570, 13, 2930, 2251, 626, 1443, 440, 1336, 314, 2549, 2656, 2418, 10, 289, 795, 199, 3, 446, 436, 31043, 379, 1443, 440, 2755, 1172, 282, 570, 5872, 737, 1006, 334, 5902, 26, 511, 199, 3, 15188, 626, 14198, 3371, 15188, 14, 1558, 3296, 14602, 984, 14, 2703, 680, 199, 3, 6423, 674, 781, 3544, 2934, 314, 485, 3093, 63, 5521, 13, 3159, 378, 12, 17, 12, 18, 13074, 289, 795, 5309, 199, 3, 747, 14, 11048, 18, 26212, 14, 199, 18472, 568, 63, 5110, 15577, 275, 378, 199, 13850, 63, 5110, 15577, 275, 413, 199, 18472, 2666, 63, 5110, 15577, 275, 499, 421, 199, 318, 663, 1535, 8, 751, 63, 344, 63, 269, 63, 354, 304, 272, 862, 26, 267, 892, 63, 1535, 275, 1109, 8, 751, 63, 344, 63, 269, 63, 354, 9, 272, 871, 334, 4333, 12, 1722, 304, 267, 892, 63, 1535, 275, 14374, 14, 362, 80, 3501, 455, 8, 751, 63, 344, 63, 269, 63, 354, 680, 8796, 63, 1535, 272, 340, 892, 63, 1535, 1137, 378, 26, 267, 862, 26, 288, 747, 14, 409, 1535, 8, 1222, 63, 1535, 9, 267, 871, 6440, 26, 288, 1499, 275, 4018, 4276, 370, 663, 1747, 450, 83, 358, 450, 892, 63, 1535, 288, 5051, 14, 13138, 8, 1328, 9, 288, 746, 4967, 14, 4874, 1378, 11070, 4562, 13886, 6699, 8, 1328, 9, 421, 199, 318, 663, 8787, 8, 923, 63, 344, 63, 269, 63, 354, 304, 272, 862, 26, 267, 892, 63, 8787, 275, 1109, 8, 923, 63, 344, 63, 269, 63, 354, 9, 272, 871, 334, 4333, 12, 1722, 304, 267, 892, 63, 8787, 275, 18598, 14, 362, 2587, 17811, 8, 923, 63, 344, 63, 269, 63, 354, 680, 2587, 63, 8787, 272, 340, 892, 63, 8787, 1137, 378, 26, 267, 862, 26, 288, 747, 14, 409, 8787, 8, 1222, 63, 8787, 9, 267, 871, 6440, 26, 288, 1499, 275, 4018, 4276, 370, 663, 15122, 450, 83, 358, 450, 892, 63, 8787, 288, 5051, 14, 13138, 8, 1328, 9, 288, 746, 4967, 14, 4874, 1378, 11070, 4562, 13886, 6699, 8, 1328, 9, 421, 199, 318, 625, 6821, 63, 793, 837, 272, 408, 11328, 29075, 379, 21982, 8297, 701, 3814, 2461, 7869, 14, 339, 30422, 2050, 4440, 29075, 379, 21982, 8297, 1325, 2985, 886, 440, 272, 2291, 20001, 5978, 12, 642, 1083, 19058, 3062, 701, 3814, 2461, 272, 8297, 21038, 20001, 5978, 14, 272, 408, 272, 943, 63, 1231, 275, 2050, 14, 5572, 8, 403, 680, 2921, 272, 370, 63, 1814, 275, 359, 72, 367, 394, 315, 943, 63, 1231, 14, 5586, 2116, 340, 1228, 8, 72, 12, 8297, 14, 13978, 379, 21982, 1874, 272, 367, 3016, 315, 370, 63, 1814, 26, 267, 327, 6944, 8, 2894, 1312, 328, 590, 304, 781, 675, 849, 7339, 8, 29, 797, 9, 370, 4868, 314, 943, 570, 267, 327, 365, 12123, 2544, 20001, 5978, 14, 267, 892, 63, 2232, 275, 2418, 63, 4806, 14, 21982, 8, 2232, 14, 1095, 8117, 12, 6343, 818, 29, 2232, 14, 632, 12, 6343, 2644, 29, 2232, 14, 2991, 9, 267, 943, 63, 1231, 14, 2168, 2461, 8, 2232, 9, 267, 943, 63, 1231, 14, 18826, 8, 1222, 63, 2232, 9, 421, 199, 318, 5978, 63, 27852, 8, 751, 29, 403, 12, 1572, 29, 403, 304, 272, 408, 11070, 20001, 370, 922, 15, 923, 20001, 1041, 272, 340, 922, 365, 488, 436, 1572, 365, 488, 26, 267, 372, 339, 340, 747, 14, 31508, 1535, 342, 1137, 378, 26, 267, 1499, 275, 4018, 6405, 3443, 787, 1415, 370, 5978, 20001, 2659, 267, 5051, 14, 13138, 8, 1328, 9, 267, 746, 4967, 14, 4874, 1378, 11070, 4562, 13886, 6699, 8, 1328, 9, 339, 340, 1572, 365, 440, 488, 26, 267, 862, 26, 288, 747, 14, 409, 2634, 4157, 267, 871, 6440, 26, 288, 1499, 275, 4018, 4276, 370, 2813, 4973, 968, 279, 4652, 358, 288, 5051, 14, 13138, 8, 1328, 9, 288, 746, 4967, 14, 4874, 1378, 11070, 4562, 13886, 6699, 8, 1328, 9, 267, 663, 8787, 8, 923, 9, 339, 340, 922, 365, 440, 488, 26, 267, 663, 1535, 8, 751, 9, 339, 5051, 14, 815, 480, 3498, 7858, 543, 1747, 15, 8787, 26, 2818, 1535, 9, 83, 21275, 8787, 9, 83, 401, 1467, 791, 1535, 356, 747, 14, 362, 1535, 1062, 283, 8787, 356, 747, 14, 362, 8787, 22804, 421, 199, 533, 510, 344, 493, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 32739, 12, 6499, 354, 12, 5377, 29, 403, 304, 267, 291, 14, 21957, 275, 32739, 267, 291, 14, 4687, 354, 275, 6499, 354, 267, 291, 14, 2580, 275, 5377, 267, 862, 26, 288, 291, 14, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
themurph/openshift-tools
ansible/roles/lib_openshift_3.2/build/generate.py
12
8336
#!/usr/bin/env python ''' Generate the openshift-tools/ansible/roles/lib_openshift_cli/library/ modules. ''' import os # pylint: disable=anomalous-backslash-in-string GEN_STR = "#!/usr/bin/env python # pylint: disable=too-many-lines\n" + \ "# ___ ___ _ _ ___ ___ _ _____ ___ ___\n" + \ "# / __| __| \| | __| _ \ /_\_ _| __| \\\n" + \ "# | (_ | _|| .` | _|| / / _ \| | | _|| |) |\n" + \ "# \___|___|_|\_|___|_|_\/_/_\_\_|_|___|___/_ _____\n" + \ "# | \ / _ \ | \| |/ _ \_ _| | __| \_ _|_ _|\n" + \ "# | |) | (_) | | .` | (_) || | | _|| |) | | | |\n" + \ "# |___/ \___/ |_|\_|\___/ |_| |___|___/___| |_|\n" OPENSHIFT_ANSIBLE_PATH = os.path.dirname(os.path.realpath(__file__)) FILES = {'oc_obj.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'src/oc_obj.py', 'ansible/oc_obj.py', ], 'oc_version.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'src/oc_version.py', 'ansible/oc_version.py', ], 'oc_secret_add.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'src/oc_secret_add.py', 'lib/serviceaccount.py', 'ansible/oc_secret_add.py', ], 'oc_secret.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'src/oc_secret.py', 'ansible/oc_secret.py', ], 'oc_service.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'lib/service.py', 'src/oc_service.py', 'ansible/oc_service.py', ], 'oc_volume.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'lib/volume.py', 'lib/deploymentconfig.py', 'src/oc_volume.py', 'ansible/oc_volume.py', ], 'oc_scale.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'lib/deploymentconfig.py', 'lib/replicationcontroller.py', 'src/oc_scale.py', 'ansible/oc_scale.py', ], 'oc_edit.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'src/oc_edit.py', 'ansible/oc_edit.py', ], 'oc_env.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'lib/deploymentconfig.py', 'src/oc_env.py', 'ansible/oc_env.py', ], 'oadm_router.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'lib/service.py', 'lib/deploymentconfig.py', 'lib/secret.py', 'lib/serviceaccount.py', 'lib/rolebinding.py', 'src/oadm_router.py', 'ansible/oadm_router.py', ], 'oadm_registry.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'lib/volume.py', 'lib/service.py', 'lib/deploymentconfig.py', 'src/oc_version.py', 'src/oadm_registry.py', 'ansible/oadm_registry.py', ], 'oadm_ca.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'src/oadm_certificate_authority.py', 'ansible/oadm_certificate_authority.py', ], 'oadm_project.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'lib/project.py', 'src/oadm_project.py', 'ansible/oadm_project.py', ], 'oadm_manage_node.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'src/oadm_manage_node.py', 'ansible/oadm_manage_node.py', ], 'oc_route.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'lib/route.py', 'src/oc_route.py', 'ansible/oc_route.py', ], 'oc_serviceaccount.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'lib/serviceaccount.py', 'src/oc_serviceaccount.py', 'ansible/oc_serviceaccount.py', ], 'oc_label.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'src/oc_label.py', 'ansible/oc_label.py', ], 'oc_user.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'lib/user.py', 'src/oc_user.py', 'ansible/oc_user.py', ], 'oc_group.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'lib/group.py', 'src/oc_group.py', 'ansible/oc_group.py', ], 'oadm_policy_user.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'lib/role.py', 'lib/rolebinding.py', 'lib/scc.py', 'src/oadm_policy_user.py', 'ansible/oadm_policy_user.py', ], 'oc_process.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'src/oc_process.py', 'ansible/oc_process.py', ], 'oc_pvc.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'lib/pvc.py', 'src/oc_pvc.py', 'ansible/oc_pvc.py', ], 'oc_image.py': ['lib/base.py', '../../lib_yaml_editor/build/src/yedit.py', 'src/oc_image.py', 'ansible/oc_image.py', ], } def main(): ''' combine the necessary files to create the ansible module ''' library = os.path.join(OPENSHIFT_ANSIBLE_PATH, '..', 'library/') for fname, parts in FILES.items(): with open(os.path.join(library, fname), 'w') as afd: afd.seek(0) afd.write(GEN_STR) for fpart in parts: with open(os.path.join(OPENSHIFT_ANSIBLE_PATH, fpart)) as pfd: # first line is pylint disable so skip it for idx, line in enumerate(pfd): if idx == 0 and 'skip-file' in line: continue afd.write(line) if __name__ == '__main__': main()
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 2344, 523, 7958, 314, 1551, 4723, 13, 2537, 15, 4853, 15, 8050, 15, 773, 63, 22858, 63, 2764, 15, 4342, 15, 4621, 14, 199, 2344, 199, 199, 646, 747, 199, 199, 3, 4287, 26, 3507, 29, 290, 676, 279, 1785, 13, 21509, 13, 262, 13, 875, 199, 9289, 63, 3027, 275, 298, 3381, 2647, 15, 1393, 15, 1813, 2366, 327, 4287, 26, 3507, 29, 7354, 13, 3479, 13, 1278, 60, 78, 2, 435, 971, 881, 5426, 258, 31111, 31111, 485, 221, 485, 31111, 31111, 259, 485, 636, 8989, 31111, 636, 18005, 78, 2, 3515, 435, 971, 881, 5426, 259, 1182, 636, 92, 636, 92, 971, 92, 1204, 636, 92, 485, 971, 221, 1182, 18005, 63, 257, 485, 92, 636, 92, 257, 32432, 78, 2, 263, 435, 971, 881, 5426, 257, 1204, 6110, 1204, 485, 10644, 1275, 64, 1204, 485, 10644, 257, 1182, 1182, 485, 971, 92, 1204, 1204, 485, 10644, 1204, 9, 12196, 78, 2, 263, 435, 971, 881, 5426, 259, 971, 8989, 92, 8989, 30007, 6113, 63, 92, 8989, 30007, 92, 18005, 15607, 15607, 60, 18005, 63, 30007, 92, 8989, 92, 8989, 15607, 636, 8989, 60, 78, 2, 221, 435, 971, 881, 5426, 257, 1204, 257, 971, 1182, 485, 971, 221, 1204, 971, 92, 1204, 15, 485, 971, 63, 257, 485, 92, 1204, 636, 92, 257, 971, 63, 485, 30007, 257, 485, 6113, 78, 2, 435, 971, 881, 5426, 257, 1204, 1204, 9, 1204, 334, 4602, 1204, 1204, 1275, 64, 1204, 334, 4602, 12208, 1204, 257, 1204, 485, 10644, 1204, 9, 1204, 1204, 221, 1204, 12196, 78, 2, 257, 435, 971, 881, 5426, 257, 1204, 8989, 15, 971, 8989, 15, 221, 1204, 63, 6113, 63, 6113, 8989, 15, 1204, 63, 92, 257, 1204, 8989, 92, 8989, 15, 8989, 92, 1204, 63, 6113, 78, 2, 199, 199, 9935, 18013, 63, 8490, 63, 3243, 275, 747, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 11091, 3460, 493, 8964, 421, 199, 9472, 275, 791, 679, 63, 1113, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 2432, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 2432, 283, 2164, 15, 679, 63, 1113, 14, 647, 297, 2432, 283, 4853, 15, 679, 63, 1113, 14, 647, 297, 1993, 2156, 268, 283, 679, 63, 1023, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 2574, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 2574, 283, 2164, 15, 679, 63, 1023, 14, 647, 297, 2574, 283, 4853, 15, 679, 63, 1023, 14, 647, 297, 2079, 2156, 268, 283, 679, 63, 4731, 63, 525, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 2892, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 2892, 283, 2164, 15, 679, 63, 4731, 63, 525, 14, 647, 297, 2892, 283, 773, 15, 1364, 2048, 14, 647, 297, 2892, 283, 4853, 15, 679, 63, 4731, 63, 525, 14, 647, 297, 2490, 2156, 268, 283, 679, 63, 4731, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 2079, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 2079, 283, 2164, 15, 679, 63, 4731, 14, 647, 297, 2079, 283, 4853, 15, 679, 63, 4731, 14, 647, 297, 586, 2156, 268, 283, 679, 63, 1364, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 2574, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 2574, 283, 773, 15, 1364, 14, 647, 297, 2574, 283, 2164, 15, 679, 63, 1364, 14, 647, 297, 2574, 283, 4853, 15, 679, 63, 1364, 14, 647, 297, 2079, 2156, 268, 283, 679, 63, 2405, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 2079, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 2079, 283, 773, 15, 2405, 14, 647, 297, 2079, 283, 773, 15, 13605, 888, 14, 647, 297, 2079, 283, 2164, 15, 679, 63, 2405, 14, 647, 297, 2079, 283, 4853, 15, 679, 63, 2405, 14, 647, 297, 586, 2156, 268, 283, 679, 63, 3467, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 586, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 586, 283, 773, 15, 13605, 888, 14, 647, 297, 586, 283, 773, 15, 17144, 5538, 14, 647, 297, 586, 283, 2164, 15, 679, 63, 3467, 14, 647, 297, 586, 283, 4853, 15, 679, 63, 3467, 14, 647, 297, 717, 2156, 268, 283, 679, 63, 3773, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 717, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 717, 283, 2164, 15, 679, 63, 3773, 14, 647, 297, 717, 283, 4853, 15, 679, 63, 3773, 14, 647, 297, 2432, 2156, 268, 283, 679, 63, 1813, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 2432, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 2432, 283, 773, 15, 13605, 888, 14, 647, 297, 2432, 283, 2164, 15, 679, 63, 1813, 14, 647, 297, 2432, 283, 4853, 15, 679, 63, 1813, 14, 647, 297, 1993, 2156, 268, 283, 79, 14464, 63, 4995, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 1169, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 1169, 283, 773, 15, 1364, 14, 647, 297, 1169, 283, 773, 15, 13605, 888, 14, 647, 297, 1169, 283, 773, 15, 4731, 14, 647, 297, 1169, 283, 773, 15, 1364, 2048, 14, 647, 297, 1169, 283, 773, 15, 3756, 9140, 14, 647, 297, 1169, 283, 2164, 15, 79, 14464, 63, 4995, 14, 647, 297, 1169, 283, 4853, 15, 79, 14464, 63, 4995, 14, 647, 297, 2574, 2156, 268, 283, 79, 14464, 63, 5189, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 2892, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 2344, 523, 7958, 314, 1551, 4723, 13, 2537, 15, 4853, 15, 8050, 15, 773, 63, 22858, 63, 2764, 15, 4342, 15, 4621, 14, 199, 2344, 199, 199, 646, 747, 199, 199, 3, 4287, 26, 3507, 29, 290, 676, 279, 1785, 13, 21509, 13, 262, 13, 875, 199, 9289, 63, 3027, 275, 298, 3381, 2647, 15, 1393, 15, 1813, 2366, 327, 4287, 26, 3507, 29, 7354, 13, 3479, 13, 1278, 60, 78, 2, 435, 971, 881, 5426, 258, 31111, 31111, 485, 221, 485, 31111, 31111, 259, 485, 636, 8989, 31111, 636, 18005, 78, 2, 3515, 435, 971, 881, 5426, 259, 1182, 636, 92, 636, 92, 971, 92, 1204, 636, 92, 485, 971, 221, 1182, 18005, 63, 257, 485, 92, 636, 92, 257, 32432, 78, 2, 263, 435, 971, 881, 5426, 257, 1204, 6110, 1204, 485, 10644, 1275, 64, 1204, 485, 10644, 257, 1182, 1182, 485, 971, 92, 1204, 1204, 485, 10644, 1204, 9, 12196, 78, 2, 263, 435, 971, 881, 5426, 259, 971, 8989, 92, 8989, 30007, 6113, 63, 92, 8989, 30007, 92, 18005, 15607, 15607, 60, 18005, 63, 30007, 92, 8989, 92, 8989, 15607, 636, 8989, 60, 78, 2, 221, 435, 971, 881, 5426, 257, 1204, 257, 971, 1182, 485, 971, 221, 1204, 971, 92, 1204, 15, 485, 971, 63, 257, 485, 92, 1204, 636, 92, 257, 971, 63, 485, 30007, 257, 485, 6113, 78, 2, 435, 971, 881, 5426, 257, 1204, 1204, 9, 1204, 334, 4602, 1204, 1204, 1275, 64, 1204, 334, 4602, 12208, 1204, 257, 1204, 485, 10644, 1204, 9, 1204, 1204, 221, 1204, 12196, 78, 2, 257, 435, 971, 881, 5426, 257, 1204, 8989, 15, 971, 8989, 15, 221, 1204, 63, 6113, 63, 6113, 8989, 15, 1204, 63, 92, 257, 1204, 8989, 92, 8989, 15, 8989, 92, 1204, 63, 6113, 78, 2, 199, 199, 9935, 18013, 63, 8490, 63, 3243, 275, 747, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 11091, 3460, 493, 8964, 421, 199, 9472, 275, 791, 679, 63, 1113, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 2432, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 2432, 283, 2164, 15, 679, 63, 1113, 14, 647, 297, 2432, 283, 4853, 15, 679, 63, 1113, 14, 647, 297, 1993, 2156, 268, 283, 679, 63, 1023, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 2574, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 2574, 283, 2164, 15, 679, 63, 1023, 14, 647, 297, 2574, 283, 4853, 15, 679, 63, 1023, 14, 647, 297, 2079, 2156, 268, 283, 679, 63, 4731, 63, 525, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 2892, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 2892, 283, 2164, 15, 679, 63, 4731, 63, 525, 14, 647, 297, 2892, 283, 773, 15, 1364, 2048, 14, 647, 297, 2892, 283, 4853, 15, 679, 63, 4731, 63, 525, 14, 647, 297, 2490, 2156, 268, 283, 679, 63, 4731, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 2079, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 2079, 283, 2164, 15, 679, 63, 4731, 14, 647, 297, 2079, 283, 4853, 15, 679, 63, 4731, 14, 647, 297, 586, 2156, 268, 283, 679, 63, 1364, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 2574, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 2574, 283, 773, 15, 1364, 14, 647, 297, 2574, 283, 2164, 15, 679, 63, 1364, 14, 647, 297, 2574, 283, 4853, 15, 679, 63, 1364, 14, 647, 297, 2079, 2156, 268, 283, 679, 63, 2405, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 2079, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 2079, 283, 773, 15, 2405, 14, 647, 297, 2079, 283, 773, 15, 13605, 888, 14, 647, 297, 2079, 283, 2164, 15, 679, 63, 2405, 14, 647, 297, 2079, 283, 4853, 15, 679, 63, 2405, 14, 647, 297, 586, 2156, 268, 283, 679, 63, 3467, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 586, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 586, 283, 773, 15, 13605, 888, 14, 647, 297, 586, 283, 773, 15, 17144, 5538, 14, 647, 297, 586, 283, 2164, 15, 679, 63, 3467, 14, 647, 297, 586, 283, 4853, 15, 679, 63, 3467, 14, 647, 297, 717, 2156, 268, 283, 679, 63, 3773, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 717, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 717, 283, 2164, 15, 679, 63, 3773, 14, 647, 297, 717, 283, 4853, 15, 679, 63, 3773, 14, 647, 297, 2432, 2156, 268, 283, 679, 63, 1813, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 2432, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 2432, 283, 773, 15, 13605, 888, 14, 647, 297, 2432, 283, 2164, 15, 679, 63, 1813, 14, 647, 297, 2432, 283, 4853, 15, 679, 63, 1813, 14, 647, 297, 1993, 2156, 268, 283, 79, 14464, 63, 4995, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 1169, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 647, 297, 1169, 283, 773, 15, 1364, 14, 647, 297, 1169, 283, 773, 15, 13605, 888, 14, 647, 297, 1169, 283, 773, 15, 4731, 14, 647, 297, 1169, 283, 773, 15, 1364, 2048, 14, 647, 297, 1169, 283, 773, 15, 3756, 9140, 14, 647, 297, 1169, 283, 2164, 15, 79, 14464, 63, 4995, 14, 647, 297, 1169, 283, 4853, 15, 79, 14464, 63, 4995, 14, 647, 297, 2574, 2156, 268, 283, 79, 14464, 63, 5189, 14, 647, 356, 788, 773, 15, 1095, 14, 647, 297, 2892, 283, 9707, 773, 63, 5963, 63, 7515, 15, 1506, 15, 2164, 15, 89, 3773, 14, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
ktan2020/legacy-automation
win/Lib/bsddb/dbrecio.py
19
5498
""" File-like objects that read from or write to a bsddb record. This implements (nearly) all stdio methods. f = DBRecIO(db, key, txn=None) f.close() # explicitly release resources held flag = f.isatty() # always false pos = f.tell() # get current position f.seek(pos) # set current position f.seek(pos, mode) # mode 0: absolute; 1: relative; 2: relative to EOF buf = f.read() # read until EOF buf = f.read(n) # read up to n bytes f.truncate([size]) # truncate file at to at most size (default: current pos) f.write(buf) # write at current position f.writelines(list) # for line in list: f.write(line) Notes: - fileno() is left unimplemented so that code which uses it triggers an exception early. - There's a simple test set (see end of this file) - not yet updated for DBRecIO. - readline() is not implemented yet. From: Itamar Shtull-Trauring <itamar@maxnm.com> """ import errno import string class DBRecIO: def __init__(self, db, key, txn=None): self.db = db self.key = key self.txn = txn self.len = None self.pos = 0 self.closed = 0 self.softspace = 0 def close(self): if not self.closed: self.closed = 1 del self.db, self.txn def isatty(self): if self.closed: raise ValueError, "I/O operation on closed file" return 0 def seek(self, pos, mode = 0): if self.closed: raise ValueError, "I/O operation on closed file" if mode == 1: pos = pos + self.pos elif mode == 2: pos = pos + self.len self.pos = max(0, pos) def tell(self): if self.closed: raise ValueError, "I/O operation on closed file" return self.pos def read(self, n = -1): if self.closed: raise ValueError, "I/O operation on closed file" if n < 0: newpos = self.len else: newpos = min(self.pos+n, self.len) dlen = newpos - self.pos r = self.db.get(self.key, txn=self.txn, dlen=dlen, doff=self.pos) self.pos = newpos return r __fixme = """ def readline(self, length=None): if self.closed: raise ValueError, "I/O operation on closed file" if self.buflist: self.buf = self.buf + string.joinfields(self.buflist, '') self.buflist = [] i = string.find(self.buf, '\n', self.pos) if i < 0: newpos = self.len else: newpos = i+1 if length is not None: if self.pos + length < newpos: newpos = self.pos + length r = self.buf[self.pos:newpos] self.pos = newpos return r def readlines(self, sizehint = 0): total = 0 lines = [] line = self.readline() while line: lines.append(line) total += len(line) if 0 < sizehint <= total: break line = self.readline() return lines """ def truncate(self, size=None): if self.closed: raise ValueError, "I/O operation on closed file" if size is None: size = self.pos elif size < 0: raise IOError(errno.EINVAL, "Negative size not allowed") elif size < self.pos: self.pos = size self.db.put(self.key, "", txn=self.txn, dlen=self.len-size, doff=size) def write(self, s): if self.closed: raise ValueError, "I/O operation on closed file" if not s: return if self.pos > self.len: self.buflist.append('\0'*(self.pos - self.len)) self.len = self.pos newpos = self.pos + len(s) self.db.put(self.key, s, txn=self.txn, dlen=len(s), doff=self.pos) self.pos = newpos def writelines(self, list): self.write(string.joinfields(list, '')) def flush(self): if self.closed: raise ValueError, "I/O operation on closed file" """ # A little test suite def _test(): import sys if sys.argv[1:]: file = sys.argv[1] else: file = '/etc/passwd' lines = open(file, 'r').readlines() text = open(file, 'r').read() f = StringIO() for line in lines[:-2]: f.write(line) f.writelines(lines[-2:]) if f.getvalue() != text: raise RuntimeError, 'write failed' length = f.tell() print 'File length =', length f.seek(len(lines[0])) f.write(lines[1]) f.seek(0) print 'First line =', repr(f.readline()) here = f.tell() line = f.readline() print 'Second line =', repr(line) f.seek(-len(line), 1) line2 = f.read(len(line)) if line != line2: raise RuntimeError, 'bad result after seek back' f.seek(len(line2), 1) list = f.readlines() line = list[-1] f.seek(f.tell() - len(line)) line2 = f.read() if line != line2: raise RuntimeError, 'bad result after seek back from EOF' print 'Read', len(list), 'more lines' print 'File length =', f.tell() if f.tell() != length: raise RuntimeError, 'bad length' f.close() if __name__ == '__main__': _test() """
mit
[ 202, 199, 624, 202, 199, 1173, 13, 2930, 2251, 626, 1586, 687, 503, 2218, 370, 282, 9922, 23217, 2777, 14, 2999, 199, 2765, 9031, 334, 21078, 590, 9, 1006, 410, 3006, 3102, 14, 2999, 199, 70, 275, 6249, 21561, 2090, 8, 697, 12, 790, 12, 23883, 29, 403, 9, 202, 199, 70, 14, 1600, 342, 3698, 327, 7662, 4683, 5944, 23608, 202, 199, 4173, 275, 289, 14, 21122, 342, 257, 327, 3544, 3055, 202, 199, 1712, 275, 289, 14, 9974, 342, 420, 327, 664, 1453, 3421, 202, 199, 70, 14, 5507, 8, 1712, 9, 260, 327, 663, 1453, 3421, 202, 199, 70, 14, 5507, 8, 1712, 12, 818, 9, 257, 327, 818, 378, 26, 3679, 27, 413, 26, 3847, 27, 499, 26, 3847, 370, 9027, 202, 199, 1436, 275, 289, 14, 739, 342, 420, 327, 1586, 5133, 9027, 202, 199, 1436, 275, 289, 14, 739, 8, 78, 9, 258, 327, 1586, 1536, 370, 302, 2783, 202, 199, 70, 14, 12517, 779, 890, 566, 221, 327, 14547, 570, 737, 370, 737, 4750, 1568, 334, 885, 26, 1453, 2086, 9, 202, 199, 70, 14, 952, 8, 1436, 9, 263, 327, 2218, 737, 1453, 3421, 202, 199, 70, 14, 23277, 8, 513, 9, 221, 327, 367, 1004, 315, 769, 26, 289, 14, 952, 8, 604, 9, 2999, 199, 18685, 26, 202, 199, 13, 25255, 342, 365, 3602, 625, 13825, 880, 626, 1233, 1314, 4440, 652, 18899, 10292, 376, 1919, 14670, 14, 202, 199, 13, 6006, 1159, 282, 3486, 511, 663, 334, 3239, 1284, 402, 642, 570, 9, 446, 440, 5966, 4588, 10292, 367, 6249, 21561, 2090, 14, 202, 199, 13, 14441, 342, 365, 440, 6366, 5966, 14, 8065, 199, 2532, 26, 1128, 2779, 455, 285, 428, 517, 979, 13, 2437, 4039, 665, 390, 455, 285, 32, 988, 10756, 14, 957, 30, 202, 199, 624, 2999, 199, 646, 7554, 202, 199, 646, 1059, 2999, 199, 533, 6249, 21561, 2090, 26, 1128, 347, 636, 826, 721, 277, 12, 1592, 12, 790, 12, 23883, 29, 403, 304, 1039, 291, 14, 697, 275, 1592, 1039, 291, 14, 498, 275, 790, 1039, 291, 14, 18174, 275, 23883, 1039, 291, 14, 552, 275, 488, 1039, 291, 14, 1712, 275, 378, 1039, 291, 14, 5938, 275, 378, 1039, 291, 14, 4617, 2638, 275, 378, 2958, 347, 4002, 8, 277, 304, 1039, 340, 440, 291, 14, 5938, 26, 1675, 291, 14, 5938, 275, 413, 1675, 2150, 291, 14, 697, 12, 291, 14, 18174, 2958, 347, 365, 16623, 8, 277, 304, 1039, 340, 291, 14, 5938, 26, 1675, 746, 1722, 12, 298, 41, 15, 47, 3439, 641, 6876, 570, 2, 1039, 372, 378, 2958, 347, 12005, 8, 277, 12, 2086, 12, 818, 275, 378, 304, 1039, 340, 291, 14, 5938, 26, 1675, 746, 1722, 12, 298, 41, 15, 47, 3439, 641, 6876, 570, 2, 1039, 340, 818, 508, 413, 26, 1675, 2086, 275, 2086, 435, 291, 14, 1712, 1039, 916, 818, 508, 499, 26, 1675, 2086, 275, 2086, 435, 291, 14, 552, 1039, 291, 14, 1712, 275, 1390, 8, 16, 12, 2086, 9, 2958, 347, 11480, 8, 277, 304, 1039, 340, 291, 14, 5938, 26, 1675, 746, 1722, 12, 298, 41, 15, 47, 3439, 641, 6876, 570, 2, 1039, 372, 291, 14, 1712, 2958, 347, 1586, 8, 277, 12, 302, 275, 446, 17, 304, 1039, 340, 291, 14, 5938, 26, 1675, 746, 1722, 12, 298, 41, 15, 47, 3439, 641, 6876, 570, 2, 1039, 340, 302, 665, 378, 26, 1675, 892, 1712, 275, 291, 14, 552, 1039, 587, 26, 1675, 892, 1712, 275, 1748, 8, 277, 14, 1712, 11, 78, 12, 291, 14, 552, 9, 4341, 366, 552, 275, 892, 1712, 446, 291, 14, 1712, 4341, 519, 275, 291, 14, 697, 14, 362, 8, 277, 14, 498, 12, 23883, 29, 277, 14, 18174, 12, 366, 552, 29, 68, 552, 12, 886, 556, 29, 277, 14, 1712, 9, 1039, 291, 14, 1712, 275, 892, 1712, 1039, 372, 519, 2958, 636, 970, 278, 275, 408, 1128, 347, 14441, 8, 277, 12, 2582, 29, 403, 304, 1039, 340, 291, 14, 5938, 26, 1675, 746, 1722, 12, 298, 41, 15, 47, 3439, 641, 6876, 570, 2, 1039, 340, 291, 14, 1436, 513, 26, 1675, 291, 14, 1436, 275, 291, 14, 1436, 435, 1059, 14, 904, 955, 8, 277, 14, 1436, 513, 12, 4074, 1675, 291, 14, 1436, 513, 275, 942, 1039, 284, 275, 1059, 14, 1623, 8, 277, 14, 1436, 12, 1557, 78, 297, 291, 14, 1712, 9, 1039, 340, 284, 665, 378, 26, 1675, 892, 1712, 275, 291, 14, 552, 1039, 587, 26, 1675, 892, 1712, 275, 284, 11, 17, 1039, 340, 2582, 365, 440, 488, 26, 1675, 340, 291, 14, 1712, 435, 2582, 665, 892, 1712, 26, 2628, 892, 1712, 275, 291, 14, 1712, 435, 2582, 1039, 519, 275, 291, 14, 1436, 59, 277, 14, 1712, 26, 1222, 1712, 61, 1039, 291, 14, 1712, 275, 892, 1712, 1039, 372, 519, 2958, 347, 1586, 1278, 8, 277, 12, 1568, 6479, 275, 378, 304, 1039, 3141, 275, 378, 1039, 2385, 275, 942, 1039, 1004, 275, 291, 14, 6407, 342, 1039, 1830, 1004, 26, 1675, 2385, 14, 740, 8, 604, 9, 1675, 3141, 847, 822, 8, 604, 9, 1675, 340, 378, 665, 1568, 6479, 2695, 3141, 26, 2628, 2059, 1675, 1004, 275, 291, 14, 6407, 342, 1039, 372, 2385, 1128, 408, 2958, 347, 14547, 8, 277, 12, 1568, 29, 403, 304, 1039, 340, 291, 14, 5938, 26, 1675, 746, 1722, 12, 298, 41, 15, 47, 3439, 641, 6876, 570, 2, 1039, 340, 1568, 365, 488, 26, 1675, 1568, 275, 291, 14, 1712, 1039, 916, 1568, 665, 378, 26, 1675, 746, 5925, 8, 7931, 14, 29510, 12, 202, 4228, 298, 15562, 1568, 440, 4370, 531, 1039, 916, 1568, 665, 291, 14, 1712, 26, 1675, 291, 14, 1712, 275, 1568, 1039, 291, 14, 697, 14, 524, 8, 277, 14, 498, 12, 4873, 23883, 29, 277, 14, 18174, 12, 366, 552, 29, 277, 14, 552, 13, 890, 12, 886, 556, 29, 890, 9, 2958, 347, 2218, 8, 277, 12, 308, 304, 1039, 340, 291, 14, 5938, 26, 1675, 746, 1722, 12, 298, 41, 15, 47, 3439, 641, 6876, 570, 2, 1039, 340, 440, 308, 26, 372, 1039, 340, 291, 14, 1712, 690, 291, 14 ]
[ 199, 624, 202, 199, 1173, 13, 2930, 2251, 626, 1586, 687, 503, 2218, 370, 282, 9922, 23217, 2777, 14, 2999, 199, 2765, 9031, 334, 21078, 590, 9, 1006, 410, 3006, 3102, 14, 2999, 199, 70, 275, 6249, 21561, 2090, 8, 697, 12, 790, 12, 23883, 29, 403, 9, 202, 199, 70, 14, 1600, 342, 3698, 327, 7662, 4683, 5944, 23608, 202, 199, 4173, 275, 289, 14, 21122, 342, 257, 327, 3544, 3055, 202, 199, 1712, 275, 289, 14, 9974, 342, 420, 327, 664, 1453, 3421, 202, 199, 70, 14, 5507, 8, 1712, 9, 260, 327, 663, 1453, 3421, 202, 199, 70, 14, 5507, 8, 1712, 12, 818, 9, 257, 327, 818, 378, 26, 3679, 27, 413, 26, 3847, 27, 499, 26, 3847, 370, 9027, 202, 199, 1436, 275, 289, 14, 739, 342, 420, 327, 1586, 5133, 9027, 202, 199, 1436, 275, 289, 14, 739, 8, 78, 9, 258, 327, 1586, 1536, 370, 302, 2783, 202, 199, 70, 14, 12517, 779, 890, 566, 221, 327, 14547, 570, 737, 370, 737, 4750, 1568, 334, 885, 26, 1453, 2086, 9, 202, 199, 70, 14, 952, 8, 1436, 9, 263, 327, 2218, 737, 1453, 3421, 202, 199, 70, 14, 23277, 8, 513, 9, 221, 327, 367, 1004, 315, 769, 26, 289, 14, 952, 8, 604, 9, 2999, 199, 18685, 26, 202, 199, 13, 25255, 342, 365, 3602, 625, 13825, 880, 626, 1233, 1314, 4440, 652, 18899, 10292, 376, 1919, 14670, 14, 202, 199, 13, 6006, 1159, 282, 3486, 511, 663, 334, 3239, 1284, 402, 642, 570, 9, 446, 440, 5966, 4588, 10292, 367, 6249, 21561, 2090, 14, 202, 199, 13, 14441, 342, 365, 440, 6366, 5966, 14, 8065, 199, 2532, 26, 1128, 2779, 455, 285, 428, 517, 979, 13, 2437, 4039, 665, 390, 455, 285, 32, 988, 10756, 14, 957, 30, 202, 199, 624, 2999, 199, 646, 7554, 202, 199, 646, 1059, 2999, 199, 533, 6249, 21561, 2090, 26, 1128, 347, 636, 826, 721, 277, 12, 1592, 12, 790, 12, 23883, 29, 403, 304, 1039, 291, 14, 697, 275, 1592, 1039, 291, 14, 498, 275, 790, 1039, 291, 14, 18174, 275, 23883, 1039, 291, 14, 552, 275, 488, 1039, 291, 14, 1712, 275, 378, 1039, 291, 14, 5938, 275, 378, 1039, 291, 14, 4617, 2638, 275, 378, 2958, 347, 4002, 8, 277, 304, 1039, 340, 440, 291, 14, 5938, 26, 1675, 291, 14, 5938, 275, 413, 1675, 2150, 291, 14, 697, 12, 291, 14, 18174, 2958, 347, 365, 16623, 8, 277, 304, 1039, 340, 291, 14, 5938, 26, 1675, 746, 1722, 12, 298, 41, 15, 47, 3439, 641, 6876, 570, 2, 1039, 372, 378, 2958, 347, 12005, 8, 277, 12, 2086, 12, 818, 275, 378, 304, 1039, 340, 291, 14, 5938, 26, 1675, 746, 1722, 12, 298, 41, 15, 47, 3439, 641, 6876, 570, 2, 1039, 340, 818, 508, 413, 26, 1675, 2086, 275, 2086, 435, 291, 14, 1712, 1039, 916, 818, 508, 499, 26, 1675, 2086, 275, 2086, 435, 291, 14, 552, 1039, 291, 14, 1712, 275, 1390, 8, 16, 12, 2086, 9, 2958, 347, 11480, 8, 277, 304, 1039, 340, 291, 14, 5938, 26, 1675, 746, 1722, 12, 298, 41, 15, 47, 3439, 641, 6876, 570, 2, 1039, 372, 291, 14, 1712, 2958, 347, 1586, 8, 277, 12, 302, 275, 446, 17, 304, 1039, 340, 291, 14, 5938, 26, 1675, 746, 1722, 12, 298, 41, 15, 47, 3439, 641, 6876, 570, 2, 1039, 340, 302, 665, 378, 26, 1675, 892, 1712, 275, 291, 14, 552, 1039, 587, 26, 1675, 892, 1712, 275, 1748, 8, 277, 14, 1712, 11, 78, 12, 291, 14, 552, 9, 4341, 366, 552, 275, 892, 1712, 446, 291, 14, 1712, 4341, 519, 275, 291, 14, 697, 14, 362, 8, 277, 14, 498, 12, 23883, 29, 277, 14, 18174, 12, 366, 552, 29, 68, 552, 12, 886, 556, 29, 277, 14, 1712, 9, 1039, 291, 14, 1712, 275, 892, 1712, 1039, 372, 519, 2958, 636, 970, 278, 275, 408, 1128, 347, 14441, 8, 277, 12, 2582, 29, 403, 304, 1039, 340, 291, 14, 5938, 26, 1675, 746, 1722, 12, 298, 41, 15, 47, 3439, 641, 6876, 570, 2, 1039, 340, 291, 14, 1436, 513, 26, 1675, 291, 14, 1436, 275, 291, 14, 1436, 435, 1059, 14, 904, 955, 8, 277, 14, 1436, 513, 12, 4074, 1675, 291, 14, 1436, 513, 275, 942, 1039, 284, 275, 1059, 14, 1623, 8, 277, 14, 1436, 12, 1557, 78, 297, 291, 14, 1712, 9, 1039, 340, 284, 665, 378, 26, 1675, 892, 1712, 275, 291, 14, 552, 1039, 587, 26, 1675, 892, 1712, 275, 284, 11, 17, 1039, 340, 2582, 365, 440, 488, 26, 1675, 340, 291, 14, 1712, 435, 2582, 665, 892, 1712, 26, 2628, 892, 1712, 275, 291, 14, 1712, 435, 2582, 1039, 519, 275, 291, 14, 1436, 59, 277, 14, 1712, 26, 1222, 1712, 61, 1039, 291, 14, 1712, 275, 892, 1712, 1039, 372, 519, 2958, 347, 1586, 1278, 8, 277, 12, 1568, 6479, 275, 378, 304, 1039, 3141, 275, 378, 1039, 2385, 275, 942, 1039, 1004, 275, 291, 14, 6407, 342, 1039, 1830, 1004, 26, 1675, 2385, 14, 740, 8, 604, 9, 1675, 3141, 847, 822, 8, 604, 9, 1675, 340, 378, 665, 1568, 6479, 2695, 3141, 26, 2628, 2059, 1675, 1004, 275, 291, 14, 6407, 342, 1039, 372, 2385, 1128, 408, 2958, 347, 14547, 8, 277, 12, 1568, 29, 403, 304, 1039, 340, 291, 14, 5938, 26, 1675, 746, 1722, 12, 298, 41, 15, 47, 3439, 641, 6876, 570, 2, 1039, 340, 1568, 365, 488, 26, 1675, 1568, 275, 291, 14, 1712, 1039, 916, 1568, 665, 378, 26, 1675, 746, 5925, 8, 7931, 14, 29510, 12, 202, 4228, 298, 15562, 1568, 440, 4370, 531, 1039, 916, 1568, 665, 291, 14, 1712, 26, 1675, 291, 14, 1712, 275, 1568, 1039, 291, 14, 697, 14, 524, 8, 277, 14, 498, 12, 4873, 23883, 29, 277, 14, 18174, 12, 366, 552, 29, 277, 14, 552, 13, 890, 12, 886, 556, 29, 890, 9, 2958, 347, 2218, 8, 277, 12, 308, 304, 1039, 340, 291, 14, 5938, 26, 1675, 746, 1722, 12, 298, 41, 15, 47, 3439, 641, 6876, 570, 2, 1039, 340, 440, 308, 26, 372, 1039, 340, 291, 14, 1712, 690, 291, 14, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
damonkohler/sl4a
python/src/Lib/lib2to3/patcomp.py
52
6524
# Copyright 2006 Google, Inc. All Rights Reserved. # Licensed to PSF under a Contributor Agreement. """Pattern compiler. The grammer is taken from PatternGrammar.txt. The compiler compiles a pattern to a pytree.*Pattern instance. """ __author__ = "Guido van Rossum <guido@python.org>" # Python imports import os # Fairly local imports from .pgen2 import driver from .pgen2 import literals from .pgen2 import token from .pgen2 import tokenize # Really local imports from . import pytree from . import pygram # The pattern grammar file _PATTERN_GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), "PatternGrammar.txt") def tokenize_wrapper(input): """Tokenizes a string suppressing significant whitespace.""" skip = (token.NEWLINE, token.INDENT, token.DEDENT) tokens = tokenize.generate_tokens(driver.generate_lines(input).next) for quintuple in tokens: type, value, start, end, line_text = quintuple if type not in skip: yield quintuple class PatternCompiler(object): def __init__(self, grammar_file=_PATTERN_GRAMMAR_FILE): """Initializer. Takes an optional alternative filename for the pattern grammar. """ self.grammar = driver.load_grammar(grammar_file) self.syms = pygram.Symbols(self.grammar) self.pygrammar = pygram.python_grammar self.pysyms = pygram.python_symbols self.driver = driver.Driver(self.grammar, convert=pattern_convert) def compile_pattern(self, input, debug=False): """Compiles a pattern string to a nested pytree.*Pattern object.""" tokens = tokenize_wrapper(input) root = self.driver.parse_tokens(tokens, debug=debug) return self.compile_node(root) def compile_node(self, node): """Compiles a node, recursively. This is one big switch on the node type. """ # XXX Optimize certain Wildcard-containing-Wildcard patterns # that can be merged if node.type == self.syms.Matcher: node = node.children[0] # Avoid unneeded recursion if node.type == self.syms.Alternatives: # Skip the odd children since they are just '|' tokens alts = [self.compile_node(ch) for ch in node.children[::2]] if len(alts) == 1: return alts[0] p = pytree.WildcardPattern([[a] for a in alts], min=1, max=1) return p.optimize() if node.type == self.syms.Alternative: units = [self.compile_node(ch) for ch in node.children] if len(units) == 1: return units[0] p = pytree.WildcardPattern([units], min=1, max=1) return p.optimize() if node.type == self.syms.NegatedUnit: pattern = self.compile_basic(node.children[1:]) p = pytree.NegatedPattern(pattern) return p.optimize() assert node.type == self.syms.Unit name = None nodes = node.children if len(nodes) >= 3 and nodes[1].type == token.EQUAL: name = nodes[0].value nodes = nodes[2:] repeat = None if len(nodes) >= 2 and nodes[-1].type == self.syms.Repeater: repeat = nodes[-1] nodes = nodes[:-1] # Now we've reduced it to: STRING | NAME [Details] | (...) | [...] pattern = self.compile_basic(nodes, repeat) if repeat is not None: assert repeat.type == self.syms.Repeater children = repeat.children child = children[0] if child.type == token.STAR: min = 0 max = pytree.HUGE elif child.type == token.PLUS: min = 1 max = pytree.HUGE elif child.type == token.LBRACE: assert children[-1].type == token.RBRACE assert len(children) in (3, 5) min = max = self.get_int(children[1]) if len(children) == 5: max = self.get_int(children[3]) else: assert False if min != 1 or max != 1: pattern = pattern.optimize() pattern = pytree.WildcardPattern([[pattern]], min=min, max=max) if name is not None: pattern.name = name return pattern.optimize() def compile_basic(self, nodes, repeat=None): # Compile STRING | NAME [Details] | (...) | [...] assert len(nodes) >= 1 node = nodes[0] if node.type == token.STRING: value = literals.evalString(node.value) return pytree.LeafPattern(content=value) elif node.type == token.NAME: value = node.value if value.isupper(): if value not in TOKEN_MAP: raise SyntaxError("Invalid token: %r" % value) return pytree.LeafPattern(TOKEN_MAP[value]) else: if value == "any": type = None elif not value.startswith("_"): type = getattr(self.pysyms, value, None) if type is None: raise SyntaxError("Invalid symbol: %r" % value) if nodes[1:]: # Details present content = [self.compile_node(nodes[1].children[1])] else: content = None return pytree.NodePattern(type, content) elif node.value == "(": return self.compile_node(nodes[1]) elif node.value == "[": assert repeat is None subpattern = self.compile_node(nodes[1]) return pytree.WildcardPattern([[subpattern]], min=0, max=1) assert False, node def get_int(self, node): assert node.type == token.NUMBER return int(node.value) # Map named tokens to the type value for a LeafPattern TOKEN_MAP = {"NAME": token.NAME, "STRING": token.STRING, "NUMBER": token.NUMBER, "TOKEN": None} def pattern_convert(grammar, raw_node_info): """Converts raw node information to a Node or Leaf instance.""" type, value, context, children = raw_node_info if children or type in grammar.number2symbol: return pytree.Node(type, children, context=context) else: return pytree.Leaf(type, value, context=context) def compile_pattern(pattern): return PatternCompiler().compile_pattern(pattern)
apache-2.0
[ 3, 1898, 8315, 4475, 12, 3277, 14, 2900, 5924, 5702, 14, 199, 3, 3909, 370, 29770, 1334, 282, 17636, 28629, 14, 199, 199, 624, 9959, 6365, 14, 199, 199, 1918, 1999, 77, 2626, 365, 9394, 687, 27019, 27119, 14, 2424, 14, 199, 199, 1918, 6365, 6555, 83, 282, 3851, 370, 282, 23353, 2795, 9959, 1256, 14, 199, 624, 199, 199, 363, 2502, 363, 275, 298, 18834, 79, 20744, 6848, 385, 453, 665, 9473, 79, 32, 1548, 14, 1308, 4335, 199, 199, 3, 2018, 8925, 199, 646, 747, 199, 199, 3, 481, 8387, 590, 2257, 8925, 199, 504, 1275, 80, 2268, 18, 492, 5253, 199, 504, 1275, 80, 2268, 18, 492, 18041, 199, 504, 1275, 80, 2268, 18, 492, 1526, 199, 504, 1275, 80, 2268, 18, 492, 13343, 199, 199, 3, 799, 1183, 2257, 8925, 199, 504, 1275, 492, 23353, 199, 504, 1275, 492, 1134, 1679, 199, 199, 3, 710, 3851, 12528, 570, 199, 63, 10764, 63, 10896, 45, 689, 63, 3817, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 3660, 298, 9959, 27119, 14, 2424, 531, 421, 199, 318, 13343, 63, 5029, 8, 1210, 304, 272, 408, 3264, 6491, 282, 1059, 15678, 316, 16474, 8139, 1041, 272, 3372, 275, 334, 1418, 14, 28758, 12, 1526, 14, 29080, 12, 1526, 14, 8280, 1309, 9, 272, 4645, 275, 13343, 14, 4208, 63, 4504, 8, 3090, 14, 4208, 63, 1278, 8, 1210, 680, 2184, 9, 272, 367, 2173, 442, 1363, 315, 4645, 26, 267, 730, 12, 574, 12, 1343, 12, 1284, 12, 1004, 63, 505, 275, 2173, 442, 1363, 267, 340, 730, 440, 315, 3372, 26, 288, 1995, 2173, 442, 1363, 421, 199, 533, 27019, 9131, 8, 785, 304, 339, 347, 636, 826, 721, 277, 12, 12528, 63, 493, 3699, 10764, 63, 10896, 45, 689, 63, 3817, 304, 267, 408, 27742, 14, 398, 17415, 376, 2716, 13943, 1788, 367, 314, 3851, 12528, 14, 267, 408, 267, 291, 14, 15239, 275, 5253, 14, 912, 63, 15239, 8, 15239, 63, 493, 9, 267, 291, 14, 13807, 275, 1134, 1679, 14, 20574, 8, 277, 14, 15239, 9, 267, 291, 14, 647, 15239, 275, 1134, 1679, 14, 1548, 63, 15239, 267, 291, 14, 15983, 89, 706, 275, 1134, 1679, 14, 1548, 63, 7450, 267, 291, 14, 3090, 275, 5253, 14, 6158, 8, 277, 14, 15239, 12, 3957, 29, 3401, 63, 3916, 9, 339, 347, 6555, 63, 3401, 8, 277, 12, 1324, 12, 3105, 29, 797, 304, 267, 408, 12626, 83, 282, 3851, 1059, 370, 282, 6032, 23353, 2795, 9959, 909, 1041, 267, 4645, 275, 13343, 63, 5029, 8, 1210, 9, 267, 1738, 275, 291, 14, 3090, 14, 1122, 63, 4504, 8, 4504, 12, 3105, 29, 1757, 9, 267, 372, 291, 14, 2014, 63, 932, 8, 1231, 9, 339, 347, 6555, 63, 932, 8, 277, 12, 1031, 304, 267, 408, 12626, 83, 282, 1031, 12, 15035, 14, 398, 961, 365, 1373, 7282, 6258, 641, 314, 1031, 730, 14, 267, 408, 267, 327, 5787, 19246, 794, 9842, 644, 10210, 13, 16133, 13, 55, 10210, 7970, 267, 327, 626, 883, 506, 9545, 267, 340, 1031, 14, 466, 508, 291, 14, 13807, 14, 16073, 26, 288, 1031, 275, 1031, 14, 3223, 59, 16, 61, 327, 19503, 625, 11368, 16189, 398, 340, 1031, 14, 466, 508, 291, 14, 13807, 14, 19978, 10661, 26, 288, 327, 8232, 314, 16699, 4978, 3967, 2985, 787, 2951, 24628, 4645, 288, 741, 1086, 275, 359, 277, 14, 2014, 63, 932, 8, 335, 9, 367, 682, 315, 1031, 14, 3223, 10345, 18, 2677, 288, 340, 822, 8, 279, 1086, 9, 508, 413, 26, 355, 372, 741, 1086, 59, 16, 61, 288, 299, 275, 23353, 14, 55, 10210, 9959, 4038, 65, 61, 367, 282, 315, 741, 1086, 467, 1748, 29, 17, 12, 1390, 29, 17, 9, 288, 372, 299, 14, 13416, 342, 398, 340, 1031, 14, 466, 508, 291, 14, 13807, 14, 19978, 1905, 26, 288, 6204, 275, 359, 277, 14, 2014, 63, 932, 8, 335, 9, 367, 682, 315, 1031, 14, 3223, 61, 288, 340, 822, 8, 5260, 9, 508, 413, 26, 355, 372, 6204, 59, 16, 61, 288, 299, 275, 23353, 14, 55, 10210, 9959, 779, 5260, 467, 1748, 29, 17, 12, 1390, 29, 17, 9, 288, 372, 299, 14, 13416, 342, 398, 340, 1031, 14, 466, 508, 291, 14, 13807, 14, 27814, 972, 5072, 26, 288, 3851, 275, 291, 14, 2014, 63, 4316, 8, 932, 14, 3223, 59, 17, 5728, 288, 299, 275, 23353, 14, 27814, 972, 9959, 8, 3401, 9, 288, 372, 299, 14, 13416, 342, 398, 702, 1031, 14, 466, 508, 291, 14, 13807, 14, 5072, 398, 536, 275, 488, 267, 3380, 275, 1031, 14, 3223, 267, 340, 822, 8, 2415, 9, 2356, 650, 436, 3380, 59, 17, 1055, 466, 508, 1526, 14, 16352, 26, 288, 536, 275, 3380, 59, 16, 1055, 585, 288, 3380, 275, 3380, 59, 18, 2938, 267, 11982, 275, 488, 267, 340, 822, 8, 2415, 9, 2356, 499, 436, 3380, 1988, 17, 1055, 466, 508, 291, 14, 13807, 14, 12945, 6618, 26, 288, 11982, 275, 3380, 1988, 17, 61, 288, 3380, 275, 3380, 4439, 17, 61, 398, 327, 7356, 781, 9064, 14953, 652, 370, 26, 18661, 1204, 13637, 359, 11347, 61, 1204, 30934, 1204, 359, 18737, 267, 3851, 275, 291, 14, 2014, 63, 4316, 8, 2415, 12, 11982, 9, 398, 340, 11982, 365, 440, 488, 26, 288, 702, 11982, 14, 466, 508, 291, 14, 13807, 14, 12945, 6618, 288, 4978, 275, 11982, 14, 3223, 288, 1982, 275, 4978, 59, 16, 61, 288, 340, 1982, 14, 466, 508, 1526, 14, 30302, 26, 355, 1748, 275, 378, 355, 1390, 275, 23353, 14, 28327, 4962, 288, 916, 1982, 14, 466, 508, 1526, 14, 27280, 26, 355, 1748, 275, 413, 355, 1390, 275, 23353, 14, 28327, 4962, 288, 916, 1982, 14, 466, 508, 1526, 14, 44, 29246, 26, 355, 702, 4978, 1988, 17, 1055, 466, 508, 1526, 14, 50, 29246, 355, 702, 221, 822, 8, 3223, 9, 315, 334, 19, 12, 959, 9, 355, 1748, 275, 1390, 275, 291, 14, 362, 63, 442, 8, 3223, 59, 17, 566, 355, 340, 822, 8, 3223, 9, 508, 959, 26, 490, 1390, 275, 291, 14, 362, 63, 442, 8, 3223, 59, 19, 566, 288 ]
[ 1898, 8315, 4475, 12, 3277, 14, 2900, 5924, 5702, 14, 199, 3, 3909, 370, 29770, 1334, 282, 17636, 28629, 14, 199, 199, 624, 9959, 6365, 14, 199, 199, 1918, 1999, 77, 2626, 365, 9394, 687, 27019, 27119, 14, 2424, 14, 199, 199, 1918, 6365, 6555, 83, 282, 3851, 370, 282, 23353, 2795, 9959, 1256, 14, 199, 624, 199, 199, 363, 2502, 363, 275, 298, 18834, 79, 20744, 6848, 385, 453, 665, 9473, 79, 32, 1548, 14, 1308, 4335, 199, 199, 3, 2018, 8925, 199, 646, 747, 199, 199, 3, 481, 8387, 590, 2257, 8925, 199, 504, 1275, 80, 2268, 18, 492, 5253, 199, 504, 1275, 80, 2268, 18, 492, 18041, 199, 504, 1275, 80, 2268, 18, 492, 1526, 199, 504, 1275, 80, 2268, 18, 492, 13343, 199, 199, 3, 799, 1183, 2257, 8925, 199, 504, 1275, 492, 23353, 199, 504, 1275, 492, 1134, 1679, 199, 199, 3, 710, 3851, 12528, 570, 199, 63, 10764, 63, 10896, 45, 689, 63, 3817, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 3660, 298, 9959, 27119, 14, 2424, 531, 421, 199, 318, 13343, 63, 5029, 8, 1210, 304, 272, 408, 3264, 6491, 282, 1059, 15678, 316, 16474, 8139, 1041, 272, 3372, 275, 334, 1418, 14, 28758, 12, 1526, 14, 29080, 12, 1526, 14, 8280, 1309, 9, 272, 4645, 275, 13343, 14, 4208, 63, 4504, 8, 3090, 14, 4208, 63, 1278, 8, 1210, 680, 2184, 9, 272, 367, 2173, 442, 1363, 315, 4645, 26, 267, 730, 12, 574, 12, 1343, 12, 1284, 12, 1004, 63, 505, 275, 2173, 442, 1363, 267, 340, 730, 440, 315, 3372, 26, 288, 1995, 2173, 442, 1363, 421, 199, 533, 27019, 9131, 8, 785, 304, 339, 347, 636, 826, 721, 277, 12, 12528, 63, 493, 3699, 10764, 63, 10896, 45, 689, 63, 3817, 304, 267, 408, 27742, 14, 398, 17415, 376, 2716, 13943, 1788, 367, 314, 3851, 12528, 14, 267, 408, 267, 291, 14, 15239, 275, 5253, 14, 912, 63, 15239, 8, 15239, 63, 493, 9, 267, 291, 14, 13807, 275, 1134, 1679, 14, 20574, 8, 277, 14, 15239, 9, 267, 291, 14, 647, 15239, 275, 1134, 1679, 14, 1548, 63, 15239, 267, 291, 14, 15983, 89, 706, 275, 1134, 1679, 14, 1548, 63, 7450, 267, 291, 14, 3090, 275, 5253, 14, 6158, 8, 277, 14, 15239, 12, 3957, 29, 3401, 63, 3916, 9, 339, 347, 6555, 63, 3401, 8, 277, 12, 1324, 12, 3105, 29, 797, 304, 267, 408, 12626, 83, 282, 3851, 1059, 370, 282, 6032, 23353, 2795, 9959, 909, 1041, 267, 4645, 275, 13343, 63, 5029, 8, 1210, 9, 267, 1738, 275, 291, 14, 3090, 14, 1122, 63, 4504, 8, 4504, 12, 3105, 29, 1757, 9, 267, 372, 291, 14, 2014, 63, 932, 8, 1231, 9, 339, 347, 6555, 63, 932, 8, 277, 12, 1031, 304, 267, 408, 12626, 83, 282, 1031, 12, 15035, 14, 398, 961, 365, 1373, 7282, 6258, 641, 314, 1031, 730, 14, 267, 408, 267, 327, 5787, 19246, 794, 9842, 644, 10210, 13, 16133, 13, 55, 10210, 7970, 267, 327, 626, 883, 506, 9545, 267, 340, 1031, 14, 466, 508, 291, 14, 13807, 14, 16073, 26, 288, 1031, 275, 1031, 14, 3223, 59, 16, 61, 327, 19503, 625, 11368, 16189, 398, 340, 1031, 14, 466, 508, 291, 14, 13807, 14, 19978, 10661, 26, 288, 327, 8232, 314, 16699, 4978, 3967, 2985, 787, 2951, 24628, 4645, 288, 741, 1086, 275, 359, 277, 14, 2014, 63, 932, 8, 335, 9, 367, 682, 315, 1031, 14, 3223, 10345, 18, 2677, 288, 340, 822, 8, 279, 1086, 9, 508, 413, 26, 355, 372, 741, 1086, 59, 16, 61, 288, 299, 275, 23353, 14, 55, 10210, 9959, 4038, 65, 61, 367, 282, 315, 741, 1086, 467, 1748, 29, 17, 12, 1390, 29, 17, 9, 288, 372, 299, 14, 13416, 342, 398, 340, 1031, 14, 466, 508, 291, 14, 13807, 14, 19978, 1905, 26, 288, 6204, 275, 359, 277, 14, 2014, 63, 932, 8, 335, 9, 367, 682, 315, 1031, 14, 3223, 61, 288, 340, 822, 8, 5260, 9, 508, 413, 26, 355, 372, 6204, 59, 16, 61, 288, 299, 275, 23353, 14, 55, 10210, 9959, 779, 5260, 467, 1748, 29, 17, 12, 1390, 29, 17, 9, 288, 372, 299, 14, 13416, 342, 398, 340, 1031, 14, 466, 508, 291, 14, 13807, 14, 27814, 972, 5072, 26, 288, 3851, 275, 291, 14, 2014, 63, 4316, 8, 932, 14, 3223, 59, 17, 5728, 288, 299, 275, 23353, 14, 27814, 972, 9959, 8, 3401, 9, 288, 372, 299, 14, 13416, 342, 398, 702, 1031, 14, 466, 508, 291, 14, 13807, 14, 5072, 398, 536, 275, 488, 267, 3380, 275, 1031, 14, 3223, 267, 340, 822, 8, 2415, 9, 2356, 650, 436, 3380, 59, 17, 1055, 466, 508, 1526, 14, 16352, 26, 288, 536, 275, 3380, 59, 16, 1055, 585, 288, 3380, 275, 3380, 59, 18, 2938, 267, 11982, 275, 488, 267, 340, 822, 8, 2415, 9, 2356, 499, 436, 3380, 1988, 17, 1055, 466, 508, 291, 14, 13807, 14, 12945, 6618, 26, 288, 11982, 275, 3380, 1988, 17, 61, 288, 3380, 275, 3380, 4439, 17, 61, 398, 327, 7356, 781, 9064, 14953, 652, 370, 26, 18661, 1204, 13637, 359, 11347, 61, 1204, 30934, 1204, 359, 18737, 267, 3851, 275, 291, 14, 2014, 63, 4316, 8, 2415, 12, 11982, 9, 398, 340, 11982, 365, 440, 488, 26, 288, 702, 11982, 14, 466, 508, 291, 14, 13807, 14, 12945, 6618, 288, 4978, 275, 11982, 14, 3223, 288, 1982, 275, 4978, 59, 16, 61, 288, 340, 1982, 14, 466, 508, 1526, 14, 30302, 26, 355, 1748, 275, 378, 355, 1390, 275, 23353, 14, 28327, 4962, 288, 916, 1982, 14, 466, 508, 1526, 14, 27280, 26, 355, 1748, 275, 413, 355, 1390, 275, 23353, 14, 28327, 4962, 288, 916, 1982, 14, 466, 508, 1526, 14, 44, 29246, 26, 355, 702, 4978, 1988, 17, 1055, 466, 508, 1526, 14, 50, 29246, 355, 702, 221, 822, 8, 3223, 9, 315, 334, 19, 12, 959, 9, 355, 1748, 275, 1390, 275, 291, 14, 362, 63, 442, 8, 3223, 59, 17, 566, 355, 340, 822, 8, 3223, 9, 508, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
bcgov/gwells
app/backend/gwells/views/bulk.py
1
18358
""" Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ import math import logging from decimal import Decimal from rest_framework.views import APIView from rest_framework import status from rest_framework.response import Response from drf_yasg.utils import swagger_auto_schema from django.db import transaction from django.utils import timezone from django.contrib.gis.geos import Point from aquifers.constants import AQUIFER_ID_FOR_UNCORRELATED_WELLS from aquifers.models import Aquifer, VerticalAquiferExtent, VerticalAquiferExtentsHistory from wells.models import Well from gwells.models.bulk import BulkWellAquiferCorrelationHistory from gwells.permissions import ( HasBulkWellAquiferCorrelationUploadRole, HasBulkVerticalAquiferExtentsUploadRole ) logger = logging.getLogger(__name__) class BulkWellAquiferCorrelation(APIView): """ Changes multiple aquifers well correlations all at once """ permission_classes = (HasBulkWellAquiferCorrelationUploadRole, ) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.change_log = [] self.create_date = timezone.now() self.unknown_well_tag_numbers = set() self.unknown_aquifer_ids = set() self.wells_outside_aquifer = dict() self.no_geom_aquifers = set() self.retired_aquifers = set() self.unpublished_aquifers = set() self.unpublished_wells = set() @swagger_auto_schema(auto_schema=None) @transaction.atomic def post(self, request, **kwargs): aquifers = request.data changes = {} wells_to_update = [] # check for a ?commit querystring parameter for this /bulk API # this flag will actually perform the bulk_update() on the DB # without it will just check for errors and return the changes # that would have been made update_db = 'commit' in request.GET incoming_well_tag_numbers = {wtn for aquifer in aquifers for wtn in aquifer['wellTagNumbers']} incoming_aquifer_ids = {aquifer['aquiferId'] for aquifer in aquifers} existing_wells = self.lookup_existing_wells(incoming_well_tag_numbers) existing_aquifers = self.lookup_existing_aquifers(incoming_aquifer_ids) if self.has_errors(): return self.return_errors({}) for aquifer in aquifers: aquifer_id = int(aquifer['aquiferId']) well_tag_numbers = aquifer['wellTagNumbers'] # capture errors about any unknown aquifers aquifer = existing_aquifers[aquifer_id] wells = [well for wtn, well in existing_wells.items() if wtn in well_tag_numbers] # now figure out what has changed for each well for well in wells: well_tag_number = well.well_tag_number existing_aquifer_id = well.aquifer_id if well.aquifer_id else None # We need to skip aquifer 1143 as it is the aquifer without geom that wells are # assigned to when they are not correlated at the time of interpretation. if aquifer_id != AQUIFER_ID_FOR_UNCORRELATED_WELLS: # If the correlation is changing — check if the well is inside the aquifer self.check_well_in_aquifer(well, aquifer) if existing_aquifer_id == aquifer_id: # this well correlation is unchanged change = { 'action': 'same' } else: if existing_aquifer_id is None: # No existing aquifer for this well? Must be a new correlation self.append_to_change_log(well_tag_number, aquifer_id, None) change = { 'action': 'new', 'aquiferId': aquifer_id } wells_to_update.append(well) elif existing_aquifer_id != aquifer_id: # existing ids don't match - must be a change self.append_to_change_log(well_tag_number, aquifer_id, existing_aquifer_id) change = { 'action': 'update', 'existingAquiferId': existing_aquifer_id, 'newAquiferId': aquifer_id } wells_to_update.append(well) if change: changes[well_tag_number] = change if update_db: # change all well's to point to the new aquifer for well in wells: well.aquifer = aquifer if update_db: # no errors then updated the DB (if ?commit is passed in) self.update_wells(wells_to_update) elif self.has_warnings(): return self.return_errors(changes) # no errors then we return the changes that were (or could be) performed http_status = status.HTTP_200_OK if update_db else status.HTTP_202_ACCEPTED return Response(changes, status=http_status) def has_errors(self): has_errors = ( len(self.unknown_well_tag_numbers) > 0 or len(self.unknown_aquifer_ids) > 0 ) return has_errors def has_warnings(self): has_warnings = ( len(self.wells_outside_aquifer) > 0 or len(self.no_geom_aquifers) > 0 or len(self.unpublished_wells) > 0 or len(self.unpublished_aquifers) > 0 or len(self.retired_aquifers) > 0 ) return has_warnings def lookup_existing_wells(self, well_tag_numbers): wells = Well.objects.filter(pk__in=well_tag_numbers) keyed_wells = {well.well_tag_number: well for well in wells} known_well_tag_numbers = set(keyed_wells.keys()) self.unknown_well_tag_numbers = well_tag_numbers - known_well_tag_numbers self.unpublished_wells = [well.well_tag_number for well in wells if well.well_publication_status_id != 'Published'] return keyed_wells def lookup_existing_aquifers(self, aquifer_ids): aquifers = Aquifer.objects.filter(pk__in=aquifer_ids).defer('geom') # we are not using geom keyed_aquifers = {aquifer.aquifer_id: aquifer for aquifer in aquifers} known_aquifer_ids = set(keyed_aquifers.keys()) self.unknown_aquifer_ids = aquifer_ids - known_aquifer_ids self.retired_aquifers = [a.aquifer_id for a in aquifers if a.status_retired] self.unpublished_aquifers = [a.aquifer_id for a in aquifers if not a.status_published] return keyed_aquifers def check_well_in_aquifer(self, well, aquifer): if aquifer.geom is None: self.no_geom_aquifers.add(aquifer.aquifer_id) return None if aquifer.geom_simplified is None: raise Exception(f"Aquifer {aquifer.aquifer_id} has no geom_simplified") # Expand simplified polygon by ~1000m in WGS-84 (srid 4326) aquifer_geom = aquifer.geom_simplified.buffer(0.01) if not aquifer_geom.contains(well.geom): well_3005_geom = well.geom.transform(3005, clone=True) distance = aquifer.geom.distance(well_3005_geom) # NOTE: 3005 projection's `.distance()` returns almost-meters self.wells_outside_aquifer[well.well_tag_number] = {'distance': distance, 'units': 'meters'} return False return True def return_errors(self, changes): # roll back the transaction as the bulk_update could have run for one # aquifer but errored on another. Best to abort the whole thing and warn the user transaction.set_rollback(True) errors = { 'unknownAquifers': self.unknown_aquifer_ids, 'unknownWells': self.unknown_well_tag_numbers, 'wellsNotInAquifer': self.wells_outside_aquifer, 'aquiferHasNoGeom': self.no_geom_aquifers, 'retiredAquifers': self.retired_aquifers, 'unpublishedAquifers': self.unpublished_aquifers, 'unpublishedWells': self.unpublished_wells, 'changes': changes # always return the list of changes even if there are unknowns } return Response(errors, status=status.HTTP_400_BAD_REQUEST) def update_wells(self, wells): logger.info("Bulk updating %d wells", len(wells)) # bulk update using efficient SQL for any well aquifer correlations that have changed Well.objects.bulk_update(wells, ['aquifer']) # save the BulkWellAquiferCorrelation records BulkWellAquiferCorrelationHistory.objects.bulk_create(self.change_log) def append_to_change_log(self, well_tag_number, to_aquifer_id, from_aquifer_id): bulk_history_item = BulkWellAquiferCorrelationHistory( well_id=well_tag_number, update_to_aquifer_id=to_aquifer_id, update_from_aquifer_id=from_aquifer_id, create_user=self.request.user.profile.username, create_date=self.create_date ) self.change_log.append(bulk_history_item) class BulkVerticalAquiferExtents(APIView): """ Changes multiple vertical aquifer extents all at once """ permission_classes = (HasBulkVerticalAquiferExtentsUploadRole, ) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.conflicts = [] self.change_log = [] self.create_date = timezone.now() self.unknown_well_tag_numbers = set() self.unknown_aquifer_ids = set() @swagger_auto_schema(auto_schema=None) @transaction.atomic def post(self, request, **kwargs): vertical_aquifer_extents = request.data new_vae_models = [] # check for a ?commit querystring parameter for this /bulk API # this flag will actually perform the bulk_update() on the DB # without it will just check for errors and return the changes # that would have been made update_db = 'commit' in request.GET # create a dict of the extents keyed by well_tag_number incoming_vae_data = self.as_wells(vertical_aquifer_extents) incoming_well_tag_numbers = incoming_vae_data.keys() existing_wells = self.lookup_existing_wells(incoming_well_tag_numbers) incoming_aquifer_ids = set(row['aquiferId'] for row in vertical_aquifer_extents) existing_aquifers = self.lookup_existing_aquifers(incoming_aquifer_ids) if len(self.unknown_well_tag_numbers) > 0 or len(self.unknown_aquifer_ids) > 0: return self.return_errors() # loop through every well in this bulk update for well_tag_number, data in incoming_vae_data.items(): well = existing_wells[well_tag_number] existing_data = VerticalAquiferExtent.objects \ .filter(well_id=well_tag_number) \ .order_by('start')[:] existing_aquifer_ids = [item.aquifer_id for item in existing_data] extents = [{'start': item.start, 'end': item.end} for item in existing_data] # record the current extents at this well so we know the complete state at this time for existing_vae in existing_data: self.append_to_history_log(existing_vae) # loop through all incoming extents and see if they overlap with any existing or new extents max_depth = float('-inf') data.sort(key=lambda item: item['fromDepth']) for vae in data: aquifer_id = vae['aquiferId'] from_depth = Decimal(format(vae['fromDepth'], '.2f')) if vae['fromDepth'] is not None else None to_depth = Decimal(format(vae['toDepth'], '.2f')) if vae['toDepth'] is not None else Decimal('Infinity') if aquifer_id in existing_aquifer_ids: self.add_conflict(vae, 'Aquifer %s already defined for well' % aquifer_id) continue if from_depth < 0: self.add_conflict(vae, 'From depth can not be less then zero') continue if to_depth < 0: self.add_conflict(vae, 'To depth can not be less then zero') continue if to_depth < from_depth: self.add_conflict(vae, 'From depth must be below to depth') continue aquifer = existing_aquifers[aquifer_id] if self.check_extent_overlaps(from_depth, to_depth, extents): self.add_conflict(vae, 'Overlaps with an existing vertical aquifer extent') continue if from_depth < max_depth: self.add_conflict(vae, 'Overlaps with another vertical aquifer extent in the CSV') continue max_depth = to_depth if update_db: vae_model = self.build_vertical_aquifer_extent_model(well, aquifer, from_depth, to_depth) new_vae_models.append(vae_model) self.append_to_history_log(vae_model) # if there are any unknown aquifers or wells then we want to return errors if len(self.conflicts) > 0: return self.return_errors() if update_db: # no errors then updated the DB (if ?commit is passed in) self.create_vertical_aquifer_extents(new_vae_models) # no errors then we return the changes that were (or could be) performed http_status = status.HTTP_200_OK if update_db else status.HTTP_202_ACCEPTED return Response({}, status=http_status) def as_wells(self, vertical_aquifer_extents): """ Returns extents as a dict keyed by well_tag_number """ wells = {} for record in vertical_aquifer_extents: wells.setdefault(record['wellTagNumber'], []).append(record) return wells def lookup_existing_wells(self, well_tag_numbers): """ Returns a dict keyed by well_tag_number of existing wells """ wells = Well.objects.filter(pk__in=well_tag_numbers) keyed_wells = {well.well_tag_number: well for well in wells} known_well_tag_numbers = set(keyed_wells.keys()) self.unknown_well_tag_numbers = well_tag_numbers - known_well_tag_numbers return keyed_wells def lookup_existing_aquifers(self, aquifer_ids): """ Returns a dict keyed by aquifer_id of existing aquifers """ aquifers = Aquifer.objects.filter(pk__in=aquifer_ids) keyed_aquifers = {aquifer.aquifer_id: aquifer for aquifer in aquifers} known_aquifer_ids = set(keyed_aquifers.keys()) self.unknown_aquifer_ids = aquifer_ids - known_aquifer_ids return keyed_aquifers def add_conflict(self, data, msg): """ Logs a conflict to be returned as a list of conflicts """ self.conflicts.append({ **data, 'message': msg, }) def build_vertical_aquifer_extent_model(self, well, aquifer, from_depth, to_depth): """ A new VerticalAquiferExtentModel which uses the well's geom """ if well.geom: longitude = well.geom.x latitude = well.geom.y point = Point(-abs(float(longitude)), float(latitude), srid=4326) return VerticalAquiferExtent( well=well, aquifer=aquifer, geom=point, start=from_depth, end=None if math.isinf(to_depth) else to_depth, create_user=self.request.user.profile.username, create_date=self.create_date ) def check_extent_overlaps(self, from_depth, to_depth, existing_extents): """ Checks an extent against a list of existing extents """ if len(existing_extents) == 0: return False max_depth = float('-inf') for extent in existing_extents: start = extent['start'] end = extent['end'] if extent['end'] is not None else Decimal('Infinity') if from_depth >= max_depth and to_depth <= start: return False max_depth = end return from_depth < max_depth # check the bottom of all extents def return_errors(self): # roll back the transaction as the bulk_update could have run for one # aquifer but errored on another. Best to abort the whole thing and warn the user transaction.set_rollback(True) errors = { 'unknownAquifers': self.unknown_aquifer_ids, 'unknownWells': self.unknown_well_tag_numbers, 'conflicts': self.conflicts } return Response(errors, status=status.HTTP_400_BAD_REQUEST) def create_vertical_aquifer_extents(self, models): """ Creates all the vertical aquifer extents and history log items all at once """ logger.info("Bulk updating %d VerticalAquiferExtents", len(models)) # bulk update using efficient SQL for any well aquifer correlations that have changed VerticalAquiferExtent.objects.bulk_create(models) # save the BulkWellAquiferCorrelation records VerticalAquiferExtentsHistory.objects.bulk_create(self.change_log) def append_to_history_log(self, model): """ Adds a vertical aquifer extent's data to the history log """ bulk_history_item = VerticalAquiferExtentsHistory( well_tag_number=model.well_id, aquifer_id=model.aquifer_id, geom=model.geom, start=model.start, end=model.end, create_user=self.request.user.profile.username, create_date=self.create_date ) self.change_log.append(bulk_history_item)
apache-2.0
[ 624, 272, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 272, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 272, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 398, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 339, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 272, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 272, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 272, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 272, 4204, 1334, 314, 844, 14, 199, 624, 199, 646, 3473, 199, 646, 2050, 199, 504, 6107, 492, 6345, 199, 199, 504, 4618, 63, 4857, 14, 4196, 492, 3261, 2768, 199, 504, 4618, 63, 4857, 492, 2004, 199, 504, 4618, 63, 4857, 14, 1310, 492, 7232, 199, 504, 366, 3941, 63, 89, 305, 71, 14, 1208, 492, 5584, 16267, 63, 2495, 63, 3629, 199, 504, 1639, 14, 697, 492, 6008, 199, 504, 1639, 14, 1208, 492, 7137, 199, 504, 1639, 14, 2828, 14, 5668, 14, 12151, 492, 7584, 199, 199, 504, 282, 392, 692, 1192, 14, 5559, 492, 437, 2328, 4656, 540, 63, 998, 63, 2707, 63, 17192, 726, 13604, 6989, 63, 55, 2901, 5296, 199, 504, 282, 392, 692, 1192, 14, 992, 492, 437, 392, 692, 281, 12, 5444, 3294, 33, 392, 692, 281, 19808, 12, 5444, 3294, 33, 392, 692, 281, 19808, 83, 12114, 199, 504, 336, 6840, 14, 992, 492, 644, 1697, 199, 504, 22192, 6840, 14, 992, 14, 9377, 492, 699, 6368, 55, 1697, 33, 392, 692, 281, 8380, 5690, 12114, 199, 504, 22192, 6840, 14, 6060, 492, 334, 272, 13481, 26033, 55, 1697, 33, 392, 692, 281, 8380, 5690, 10301, 7422, 12, 272, 13481, 26033, 19462, 33, 392, 692, 281, 19808, 83, 10301, 7422, 199, 9, 421, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 421, 199, 533, 699, 6368, 55, 1697, 33, 392, 692, 281, 8380, 5690, 8, 25778, 304, 272, 408, 272, 18784, 3663, 282, 392, 692, 1192, 5521, 1970, 15741, 1006, 737, 5403, 272, 408, 272, 4983, 63, 2888, 275, 334, 6362, 26033, 55, 1697, 33, 392, 692, 281, 8380, 5690, 10301, 7422, 12, 776, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 11027, 826, 9308, 589, 12, 1011, 958, 9, 267, 291, 14, 1461, 63, 793, 275, 942, 267, 291, 14, 981, 63, 602, 275, 7137, 14, 2131, 342, 267, 291, 14, 5187, 63, 20501, 63, 1450, 63, 10548, 275, 663, 342, 267, 291, 14, 5187, 63, 65, 392, 692, 281, 63, 1580, 275, 663, 342, 267, 291, 14, 87, 6840, 63, 22431, 63, 65, 392, 692, 281, 275, 1211, 342, 267, 291, 14, 889, 63, 6481, 63, 65, 392, 692, 1192, 275, 663, 342, 267, 291, 14, 264, 280, 581, 63, 65, 392, 692, 1192, 275, 663, 342, 267, 291, 14, 324, 8987, 63, 65, 392, 692, 1192, 275, 663, 342, 267, 291, 14, 324, 8987, 63, 87, 6840, 275, 663, 342, 339, 768, 29940, 63, 2495, 63, 3629, 8, 2495, 63, 3629, 29, 403, 9, 272, 768, 5945, 14, 10910, 272, 347, 2963, 8, 277, 12, 1056, 12, 1011, 958, 304, 267, 282, 392, 692, 1192, 275, 1056, 14, 576, 267, 4493, 275, 1052, 267, 336, 6840, 63, 475, 63, 873, 275, 942, 398, 327, 1104, 367, 282, 5805, 3543, 1827, 875, 2725, 367, 642, 1182, 9377, 3261, 267, 327, 642, 3305, 911, 5965, 5147, 314, 13137, 63, 873, 342, 641, 314, 6249, 267, 327, 1928, 652, 911, 2951, 1104, 367, 2552, 436, 372, 314, 4493, 267, 327, 626, 3955, 1172, 2757, 6326, 267, 1678, 63, 697, 275, 283, 3543, 7, 315, 1056, 14, 2970, 398, 12467, 63, 20501, 63, 1450, 63, 10548, 275, 469, 87, 5889, 367, 282, 392, 692, 281, 315, 282, 392, 692, 1192, 367, 336, 5889, 315, 282, 392, 692, 281, 459, 20501, 1931, 22951, 12074, 267, 12467, 63, 65, 392, 692, 281, 63, 1580, 275, 469, 65, 392, 692, 281, 459, 65, 392, 692, 281, 1304, 418, 367, 282, 392, 692, 281, 315, 282, 392, 692, 1192, 93, 398, 3411, 63, 87, 6840, 275, 291, 14, 3892, 63, 5952, 63, 87, 6840, 8, 15994, 63, 20501, 63, 1450, 63, 10548, 9, 267, 3411, 63, 65, 392, 692, 1192, 275, 291, 14, 3892, 63, 5952, 63, 65, 392, 692, 1192, 8, 15994, 63, 65, 392, 692, 281, 63, 1580, 9, 398, 340, 291, 14, 1989, 63, 2550, 837, 288, 372, 291, 14, 1107, 63, 2550, 14079, 398, 367, 282, 392, 692, 281, 315, 282, 392, 692, 1192, 26, 288, 282, 392, 692, 281, 63, 344, 275, 1109, 8, 65, 392, 692, 281, 459, 65, 392, 692, 281, 1304, 1105, 288, 5521, 63, 1450, 63, 10548, 275, 282, 392, 692, 281, 459, 20501, 1931, 22951, 418, 953, 327, 12296, 2552, 3595, 1263, 5809, 282, 392, 692, 1192, 288, 282, 392, 692, 281, 275, 3411, 63, 65, 392, 692, 1192, 59, 65, 392, 692, 281, 63, 344, 61, 953, 336, 6840, 275, 359, 20501, 367, 336, 5889, 12, 5521, 315, 3411, 63, 87, 6840, 14, 1744, 342, 340, 336, 5889, 315, 5521, 63, 1450, 63, 10548, 61, 953, 327, 3063, 9658, 734, 4052, 965, 2896, 367, 1924, 5521, 288, 367, 5521, 315, 336, 6840, 26, 355, 5521, 63, 1450, 63, 1955, 275, 5521, 14, 20501, 63, 1450, 63, 1955, 355, 3411, 63, 65, 392, 692, 281, 63, 344, 275, 5521, 14, 65, 392, 692, 281, 63, 344, 340, 5521, 14, 65, 392, 692, 281, 63, 344, 587, 488, 2234, 327, 2136, 1929, 370, 3372, 282, 392, 692, 281, 413, 12289, 465, 652, 365, 314, 282, 392, 692, 281, 1928, 9671, 626, 336, 6840, 787, 355, 327, 7943, 370, 1380, 2985, 787, 440, 1970, 2407, 737, 314, 900, 402, 28426, 14, 355, 340, 282, 392, 692, 281, 63, 344, 1137, 437, 2328, 4656, 540, 63, 998, 63, 2707, 63, 17192, 726, 13604, 6989, 63, 55, 2901, 5296, 26, 490, 327, 982, 314, 21280, 365, 13729, 221, 20292, 1104, 340, 314, 5521, 365, 6272, 314 ]
[ 272, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 272, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 272, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 398, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 339, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 272, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 272, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 272, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 272, 4204, 1334, 314, 844, 14, 199, 624, 199, 646, 3473, 199, 646, 2050, 199, 504, 6107, 492, 6345, 199, 199, 504, 4618, 63, 4857, 14, 4196, 492, 3261, 2768, 199, 504, 4618, 63, 4857, 492, 2004, 199, 504, 4618, 63, 4857, 14, 1310, 492, 7232, 199, 504, 366, 3941, 63, 89, 305, 71, 14, 1208, 492, 5584, 16267, 63, 2495, 63, 3629, 199, 504, 1639, 14, 697, 492, 6008, 199, 504, 1639, 14, 1208, 492, 7137, 199, 504, 1639, 14, 2828, 14, 5668, 14, 12151, 492, 7584, 199, 199, 504, 282, 392, 692, 1192, 14, 5559, 492, 437, 2328, 4656, 540, 63, 998, 63, 2707, 63, 17192, 726, 13604, 6989, 63, 55, 2901, 5296, 199, 504, 282, 392, 692, 1192, 14, 992, 492, 437, 392, 692, 281, 12, 5444, 3294, 33, 392, 692, 281, 19808, 12, 5444, 3294, 33, 392, 692, 281, 19808, 83, 12114, 199, 504, 336, 6840, 14, 992, 492, 644, 1697, 199, 504, 22192, 6840, 14, 992, 14, 9377, 492, 699, 6368, 55, 1697, 33, 392, 692, 281, 8380, 5690, 12114, 199, 504, 22192, 6840, 14, 6060, 492, 334, 272, 13481, 26033, 55, 1697, 33, 392, 692, 281, 8380, 5690, 10301, 7422, 12, 272, 13481, 26033, 19462, 33, 392, 692, 281, 19808, 83, 10301, 7422, 199, 9, 421, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 421, 199, 533, 699, 6368, 55, 1697, 33, 392, 692, 281, 8380, 5690, 8, 25778, 304, 272, 408, 272, 18784, 3663, 282, 392, 692, 1192, 5521, 1970, 15741, 1006, 737, 5403, 272, 408, 272, 4983, 63, 2888, 275, 334, 6362, 26033, 55, 1697, 33, 392, 692, 281, 8380, 5690, 10301, 7422, 12, 776, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 11027, 826, 9308, 589, 12, 1011, 958, 9, 267, 291, 14, 1461, 63, 793, 275, 942, 267, 291, 14, 981, 63, 602, 275, 7137, 14, 2131, 342, 267, 291, 14, 5187, 63, 20501, 63, 1450, 63, 10548, 275, 663, 342, 267, 291, 14, 5187, 63, 65, 392, 692, 281, 63, 1580, 275, 663, 342, 267, 291, 14, 87, 6840, 63, 22431, 63, 65, 392, 692, 281, 275, 1211, 342, 267, 291, 14, 889, 63, 6481, 63, 65, 392, 692, 1192, 275, 663, 342, 267, 291, 14, 264, 280, 581, 63, 65, 392, 692, 1192, 275, 663, 342, 267, 291, 14, 324, 8987, 63, 65, 392, 692, 1192, 275, 663, 342, 267, 291, 14, 324, 8987, 63, 87, 6840, 275, 663, 342, 339, 768, 29940, 63, 2495, 63, 3629, 8, 2495, 63, 3629, 29, 403, 9, 272, 768, 5945, 14, 10910, 272, 347, 2963, 8, 277, 12, 1056, 12, 1011, 958, 304, 267, 282, 392, 692, 1192, 275, 1056, 14, 576, 267, 4493, 275, 1052, 267, 336, 6840, 63, 475, 63, 873, 275, 942, 398, 327, 1104, 367, 282, 5805, 3543, 1827, 875, 2725, 367, 642, 1182, 9377, 3261, 267, 327, 642, 3305, 911, 5965, 5147, 314, 13137, 63, 873, 342, 641, 314, 6249, 267, 327, 1928, 652, 911, 2951, 1104, 367, 2552, 436, 372, 314, 4493, 267, 327, 626, 3955, 1172, 2757, 6326, 267, 1678, 63, 697, 275, 283, 3543, 7, 315, 1056, 14, 2970, 398, 12467, 63, 20501, 63, 1450, 63, 10548, 275, 469, 87, 5889, 367, 282, 392, 692, 281, 315, 282, 392, 692, 1192, 367, 336, 5889, 315, 282, 392, 692, 281, 459, 20501, 1931, 22951, 12074, 267, 12467, 63, 65, 392, 692, 281, 63, 1580, 275, 469, 65, 392, 692, 281, 459, 65, 392, 692, 281, 1304, 418, 367, 282, 392, 692, 281, 315, 282, 392, 692, 1192, 93, 398, 3411, 63, 87, 6840, 275, 291, 14, 3892, 63, 5952, 63, 87, 6840, 8, 15994, 63, 20501, 63, 1450, 63, 10548, 9, 267, 3411, 63, 65, 392, 692, 1192, 275, 291, 14, 3892, 63, 5952, 63, 65, 392, 692, 1192, 8, 15994, 63, 65, 392, 692, 281, 63, 1580, 9, 398, 340, 291, 14, 1989, 63, 2550, 837, 288, 372, 291, 14, 1107, 63, 2550, 14079, 398, 367, 282, 392, 692, 281, 315, 282, 392, 692, 1192, 26, 288, 282, 392, 692, 281, 63, 344, 275, 1109, 8, 65, 392, 692, 281, 459, 65, 392, 692, 281, 1304, 1105, 288, 5521, 63, 1450, 63, 10548, 275, 282, 392, 692, 281, 459, 20501, 1931, 22951, 418, 953, 327, 12296, 2552, 3595, 1263, 5809, 282, 392, 692, 1192, 288, 282, 392, 692, 281, 275, 3411, 63, 65, 392, 692, 1192, 59, 65, 392, 692, 281, 63, 344, 61, 953, 336, 6840, 275, 359, 20501, 367, 336, 5889, 12, 5521, 315, 3411, 63, 87, 6840, 14, 1744, 342, 340, 336, 5889, 315, 5521, 63, 1450, 63, 10548, 61, 953, 327, 3063, 9658, 734, 4052, 965, 2896, 367, 1924, 5521, 288, 367, 5521, 315, 336, 6840, 26, 355, 5521, 63, 1450, 63, 1955, 275, 5521, 14, 20501, 63, 1450, 63, 1955, 355, 3411, 63, 65, 392, 692, 281, 63, 344, 275, 5521, 14, 65, 392, 692, 281, 63, 344, 340, 5521, 14, 65, 392, 692, 281, 63, 344, 587, 488, 2234, 327, 2136, 1929, 370, 3372, 282, 392, 692, 281, 413, 12289, 465, 652, 365, 314, 282, 392, 692, 281, 1928, 9671, 626, 336, 6840, 787, 355, 327, 7943, 370, 1380, 2985, 787, 440, 1970, 2407, 737, 314, 900, 402, 28426, 14, 355, 340, 282, 392, 692, 281, 63, 344, 1137, 437, 2328, 4656, 540, 63, 998, 63, 2707, 63, 17192, 726, 13604, 6989, 63, 55, 2901, 5296, 26, 490, 327, 982, 314, 21280, 365, 13729, 221, 20292, 1104, 340, 314, 5521, 365, 6272, 314, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
live-clones/dolfin-adjoint
tests_dolfin/optimization_scalar/optimization_scalar.py
1
1880
from __future__ import print_function from dolfin import * from dolfin_adjoint import * import sys dolfin.set_log_level(ERROR) n = 10 mesh = UnitIntervalMesh(n) V = FunctionSpace(mesh, "CG", 2) ic = project(Expression("sin(2*pi*x[0])", degree=1), V) u = ic.copy(deepcopy=True) def main(nu): u_next = Function(V) v = TestFunction(V) timestep = Constant(1.0/n, name="Timestep") F = ((u_next - u)/timestep*v + u_next*u_next.dx(0)*v + nu*u_next.dx(0)*v.dx(0))*dx bc = DirichletBC(V, 0.0, "on_boundary") t = 0.0 end = 0.1 while (t <= end): solve(F == 0, u_next, bc) u.assign(u_next) t += float(timestep) adj_inc_timestep() def eval_cb(j, m): print("j = %f, m = %f." % (j, float(m))) def derivative_cb(j, dj, m): print("j = %f, dj = %f, m = %f." % (j, dj, float(m))) def replay_cb(var, data, m): #print "Got data for variable %s at m = %f." % (var, float(m)) pass if __name__ == "__main__": nu = Constant(0.0001, name="Nu") # Run the forward model once to have the annotation main(nu) J = Functional(inner(u, u)*dx*dt[FINISH_TIME]) # Run the optimisation reduced_functional = ReducedFunctional(J, ConstantControl("Nu"), eval_cb_post= eval_cb, derivative_cb_post=derivative_cb, replay_cb=replay_cb, scale=2.0) try: nu_opt = minimize(reduced_functional, 'SLSQP') tol = 1e-4 if reduced_functional(nu_opt) > tol: print('Test failed: Optimised functional value exceeds tolerance: ', reduced_functional(nu_opt), ' > ', tol, '.') sys.exit(1) except ImportError: info_red("No suitable scipy version found. Aborting test.")
lgpl-3.0
[ 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 504, 886, 276, 262, 492, 627, 199, 504, 886, 276, 262, 63, 26055, 492, 627, 199, 646, 984, 199, 199, 1117, 276, 262, 14, 409, 63, 793, 63, 1896, 8, 3170, 9, 199, 199, 78, 275, 1616, 199, 6480, 275, 12008, 8227, 12241, 8, 78, 9, 199, 54, 275, 6801, 7643, 8, 6480, 12, 298, 4064, 401, 499, 9, 199, 199, 530, 275, 2199, 8, 9093, 480, 5911, 8, 18, 10, 1038, 10, 88, 59, 16, 566, 401, 13666, 29, 17, 395, 221, 812, 9, 199, 85, 275, 284, 67, 14, 1574, 8, 8293, 29, 549, 9, 199, 199, 318, 2446, 8, 4850, 304, 272, 399, 63, 2184, 275, 6801, 8, 54, 9, 272, 373, 275, 1379, 3481, 8, 54, 9, 339, 900, 2926, 275, 19991, 8, 17, 14, 16, 15, 78, 12, 536, 628, 1366, 2926, 531, 339, 481, 275, 3666, 85, 63, 2184, 446, 399, 2447, 521, 2926, 10, 86, 267, 435, 399, 63, 2184, 10, 85, 63, 2184, 14, 8373, 8, 16, 3342, 86, 267, 435, 15699, 10, 85, 63, 2184, 14, 8373, 8, 16, 3342, 86, 14, 8373, 8, 16, 19198, 8373, 272, 16604, 275, 3757, 19683, 6265, 8, 54, 12, 378, 14, 16, 12, 298, 265, 63, 9891, 531, 339, 307, 275, 378, 14, 16, 272, 1284, 275, 378, 14, 17, 272, 1830, 334, 84, 2695, 1284, 304, 267, 14241, 8, 38, 508, 378, 12, 399, 63, 2184, 12, 16604, 9, 267, 399, 14, 5038, 8, 85, 63, 2184, 9, 267, 307, 847, 2069, 8, 521, 2926, 9, 267, 14510, 63, 6559, 63, 521, 2926, 342, 199, 199, 318, 3468, 63, 2894, 8, 74, 12, 333, 304, 272, 870, 480, 74, 275, 450, 70, 12, 333, 275, 450, 70, 2122, 450, 334, 74, 12, 2069, 8, 77, 1724, 199, 199, 318, 18883, 63, 2894, 8, 74, 12, 366, 74, 12, 333, 304, 272, 870, 480, 74, 275, 450, 70, 12, 366, 74, 275, 450, 70, 12, 333, 275, 450, 70, 2122, 450, 334, 74, 12, 366, 74, 12, 2069, 8, 77, 1724, 199, 199, 318, 24331, 63, 2894, 8, 1391, 12, 666, 12, 333, 304, 272, 327, 1361, 298, 13662, 666, 367, 1750, 450, 83, 737, 333, 275, 450, 70, 2122, 450, 334, 1391, 12, 2069, 8, 77, 430, 272, 986, 199, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 15699, 275, 19991, 8, 16, 14, 4183, 12, 536, 628, 21988, 531, 272, 327, 3378, 314, 7568, 1402, 5403, 370, 1172, 314, 11262, 272, 2446, 8, 4850, 9, 339, 1603, 275, 6801, 279, 8, 5216, 8, 85, 12, 399, 3342, 8373, 10, 3583, 59, 17383, 13898, 63, 4961, 566, 339, 327, 3378, 314, 1687, 280, 1292, 425, 272, 14953, 63, 15481, 275, 30778, 68, 3481, 279, 8, 42, 12, 19991, 3717, 480, 21988, 1288, 5644, 3468, 63, 2894, 63, 1932, 29, 3468, 63, 2894, 12, 5644, 18883, 63, 2894, 63, 1932, 29, 26851, 63, 2894, 12, 5644, 24331, 63, 2894, 29, 19540, 63, 2894, 12, 5644, 4666, 29, 18, 14, 16, 9, 272, 862, 26, 267, 15699, 63, 2992, 275, 24720, 8, 19523, 63, 15481, 12, 283, 4929, 18445, 48, 358, 398, 9561, 275, 413, 69, 13, 20, 267, 340, 14953, 63, 15481, 8, 4850, 63, 2992, 9, 690, 9561, 26, 288, 870, 360, 774, 3405, 26, 19246, 9096, 22380, 574, 22338, 13464, 26, 1656, 14953, 63, 15481, 8, 4850, 63, 2992, 395, 283, 690, 1656, 9561, 12, 20093, 288, 984, 14, 2224, 8, 17, 9, 272, 871, 3545, 26, 267, 2256, 63, 581, 480, 1944, 11233, 7026, 1015, 1911, 14, 31455, 316, 511, 2685, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 636, 2443, 363, 492, 870, 63, 1593, 199, 504, 886, 276, 262, 492, 627, 199, 504, 886, 276, 262, 63, 26055, 492, 627, 199, 646, 984, 199, 199, 1117, 276, 262, 14, 409, 63, 793, 63, 1896, 8, 3170, 9, 199, 199, 78, 275, 1616, 199, 6480, 275, 12008, 8227, 12241, 8, 78, 9, 199, 54, 275, 6801, 7643, 8, 6480, 12, 298, 4064, 401, 499, 9, 199, 199, 530, 275, 2199, 8, 9093, 480, 5911, 8, 18, 10, 1038, 10, 88, 59, 16, 566, 401, 13666, 29, 17, 395, 221, 812, 9, 199, 85, 275, 284, 67, 14, 1574, 8, 8293, 29, 549, 9, 199, 199, 318, 2446, 8, 4850, 304, 272, 399, 63, 2184, 275, 6801, 8, 54, 9, 272, 373, 275, 1379, 3481, 8, 54, 9, 339, 900, 2926, 275, 19991, 8, 17, 14, 16, 15, 78, 12, 536, 628, 1366, 2926, 531, 339, 481, 275, 3666, 85, 63, 2184, 446, 399, 2447, 521, 2926, 10, 86, 267, 435, 399, 63, 2184, 10, 85, 63, 2184, 14, 8373, 8, 16, 3342, 86, 267, 435, 15699, 10, 85, 63, 2184, 14, 8373, 8, 16, 3342, 86, 14, 8373, 8, 16, 19198, 8373, 272, 16604, 275, 3757, 19683, 6265, 8, 54, 12, 378, 14, 16, 12, 298, 265, 63, 9891, 531, 339, 307, 275, 378, 14, 16, 272, 1284, 275, 378, 14, 17, 272, 1830, 334, 84, 2695, 1284, 304, 267, 14241, 8, 38, 508, 378, 12, 399, 63, 2184, 12, 16604, 9, 267, 399, 14, 5038, 8, 85, 63, 2184, 9, 267, 307, 847, 2069, 8, 521, 2926, 9, 267, 14510, 63, 6559, 63, 521, 2926, 342, 199, 199, 318, 3468, 63, 2894, 8, 74, 12, 333, 304, 272, 870, 480, 74, 275, 450, 70, 12, 333, 275, 450, 70, 2122, 450, 334, 74, 12, 2069, 8, 77, 1724, 199, 199, 318, 18883, 63, 2894, 8, 74, 12, 366, 74, 12, 333, 304, 272, 870, 480, 74, 275, 450, 70, 12, 366, 74, 275, 450, 70, 12, 333, 275, 450, 70, 2122, 450, 334, 74, 12, 366, 74, 12, 2069, 8, 77, 1724, 199, 199, 318, 24331, 63, 2894, 8, 1391, 12, 666, 12, 333, 304, 272, 327, 1361, 298, 13662, 666, 367, 1750, 450, 83, 737, 333, 275, 450, 70, 2122, 450, 334, 1391, 12, 2069, 8, 77, 430, 272, 986, 199, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 15699, 275, 19991, 8, 16, 14, 4183, 12, 536, 628, 21988, 531, 272, 327, 3378, 314, 7568, 1402, 5403, 370, 1172, 314, 11262, 272, 2446, 8, 4850, 9, 339, 1603, 275, 6801, 279, 8, 5216, 8, 85, 12, 399, 3342, 8373, 10, 3583, 59, 17383, 13898, 63, 4961, 566, 339, 327, 3378, 314, 1687, 280, 1292, 425, 272, 14953, 63, 15481, 275, 30778, 68, 3481, 279, 8, 42, 12, 19991, 3717, 480, 21988, 1288, 5644, 3468, 63, 2894, 63, 1932, 29, 3468, 63, 2894, 12, 5644, 18883, 63, 2894, 63, 1932, 29, 26851, 63, 2894, 12, 5644, 24331, 63, 2894, 29, 19540, 63, 2894, 12, 5644, 4666, 29, 18, 14, 16, 9, 272, 862, 26, 267, 15699, 63, 2992, 275, 24720, 8, 19523, 63, 15481, 12, 283, 4929, 18445, 48, 358, 398, 9561, 275, 413, 69, 13, 20, 267, 340, 14953, 63, 15481, 8, 4850, 63, 2992, 9, 690, 9561, 26, 288, 870, 360, 774, 3405, 26, 19246, 9096, 22380, 574, 22338, 13464, 26, 1656, 14953, 63, 15481, 8, 4850, 63, 2992, 395, 283, 690, 1656, 9561, 12, 20093, 288, 984, 14, 2224, 8, 17, 9, 272, 871, 3545, 26, 267, 2256, 63, 581, 480, 1944, 11233, 7026, 1015, 1911, 14, 31455, 316, 511, 2685, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
haoxli/crosswalk-test-suite
webapi/tct-csp-w3c-tests/csp-py/csp_ro_img-src_self_allowed_ext-manual.py
30
2545
def main(request, response): import simplejson as json f = file('config.json') source = f.read() s = json.JSONDecoder().decode(source) url1 = "http://" + s['host'] + ":" + str(s['ports']['http'][1]) url2 = "http://" + s['host'] + ":" + str(s['ports']['http'][0]) _CSP = "img-src 'self'" response.headers.set("Content-Security-Policy-Report-Only", _CSP) response.headers.set("X-Content-Security-Policy-Report-Only", _CSP) response.headers.set("X-WebKit-CSP-Report-Only", _CSP) return """<!DOCTYPE html> <!-- Copyright (c) 2013 Intel Corporation. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of works must retain the original copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the original copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Intel Corporation nor the names of its contributors may be used to endorse or promote products derived from this work without specific prior written permission. THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Authors: Hao, Yunfei <yunfeix.hao@intel.com> --> <html> <head> <title>CSP Test: csp_ro_img-src_self_allowed_ext</title> <link rel="author" title="Intel" href="http://www.intel.com"/> <link rel="help" href="http://www.w3.org/TR/2012/CR-CSP-20121115/#img-src"/> <meta name="flags" content=""/> <meta name="assert" content="img-src 'self'"/> <meta charset="utf-8"/> </head> <body> <p>Test passes if there is a filled green square.</p> <img src='""" + url1 + """/tests/csp/support/green-100x100.png'/> </body> </html> """
bsd-3-clause
[ 318, 2446, 8, 1069, 12, 1177, 304, 272, 492, 13804, 465, 2022, 272, 289, 275, 570, 360, 888, 14, 1001, 358, 272, 1350, 275, 289, 14, 739, 342, 272, 308, 275, 2022, 14, 6243, 8326, 1252, 2708, 8, 1365, 9, 272, 1166, 17, 275, 298, 1014, 30443, 435, 308, 459, 1102, 418, 435, 14725, 435, 620, 8, 83, 459, 5203, 2545, 1014, 3488, 17, 566, 272, 1166, 18, 275, 298, 1014, 30443, 435, 308, 459, 1102, 418, 435, 14725, 435, 620, 8, 83, 459, 5203, 2545, 1014, 3488, 16, 566, 272, 485, 30635, 275, 298, 4060, 13, 2164, 283, 277, 4065, 272, 1177, 14, 2139, 14, 409, 480, 2714, 13, 7676, 13, 4845, 13, 7457, 13, 5903, 401, 485, 30635, 9, 272, 1177, 14, 2139, 14, 409, 480, 56, 13, 2714, 13, 7676, 13, 4845, 13, 7457, 13, 5903, 401, 485, 30635, 9, 272, 1177, 14, 2139, 14, 409, 480, 56, 13, 21666, 13, 30635, 13, 7457, 13, 5903, 401, 485, 30635, 9, 272, 372, 8894, 1, 16556, 3517, 30, 199, 25273, 199, 7384, 334, 67, 9, 6171, 20619, 11098, 14, 199, 199, 497, 4972, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 7100, 12, 199, 1530, 8211, 2741, 626, 314, 2569, 3704, 787, 7647, 26, 199, 199, 10, 6823, 402, 5419, 1471, 8074, 314, 3379, 4248, 4245, 12, 642, 769, 523, 402, 3704, 436, 314, 2569, 6450, 14, 199, 10, 6823, 315, 3366, 1824, 1471, 9172, 314, 3379, 4248, 4245, 12, 523, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 3794, 523, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 199, 10, 11443, 314, 536, 402, 20619, 11098, 6590, 314, 1561, 402, 2399, 8417, 523, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 642, 1736, 1928, 523, 2488, 6791, 5313, 4983, 14, 199, 199, 24571, 4141, 2281, 7049, 6515, 16429, 2901, 27072, 298, 1179, 2281, 2, 199, 3649, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 2296, 12, 2334, 199, 8947, 5177, 2990, 1634, 3169, 2401, 3092, 2381, 437, 3115, 3104, 199, 8693, 9706, 14, 1621, 4825, 6461, 7000, 16429, 2901, 27072, 6262, 7024, 2381, 1821, 8703, 12, 199, 568, 6098, 12, 9716, 12, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 199, 12728, 2845, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3998, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 9815, 199, 3359, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 334, 6446, 199, 6388, 9179, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 4141, 12, 199, 37, 8253, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 2817, 1384, 26, 267, 869, 8035, 12, 1488, 324, 771, 73, 665, 89, 324, 771, 1148, 14, 2411, 79, 32, 22264, 14, 957, 30, 199, 199, 31647, 199, 199, 28, 1360, 30, 523, 665, 2993, 30, 272, 665, 1213, 30, 30635, 1379, 26, 286, 681, 63, 293, 63, 4060, 13, 2164, 63, 277, 63, 6541, 63, 832, 1108, 1213, 30, 272, 665, 1073, 4668, 628, 2502, 2, 2538, 628, 27528, 2, 4369, 628, 1014, 921, 1544, 14, 22264, 14, 957, 7897, 272, 665, 1073, 4668, 628, 3437, 2, 4369, 628, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 1766, 15, 7409, 15, 2944, 13, 30635, 13, 7409, 845, 1046, 12645, 4060, 13, 2164, 7897, 272, 665, 2024, 536, 628, 2469, 2, 1564, 9287, 3133, 272, 665, 2024, 536, 628, 479, 2, 1564, 628, 4060, 13, 2164, 283, 277, 4065, 3133, 272, 665, 2024, 5960, 628, 1624, 13, 24, 7897, 523, 3068, 2993, 30, 523, 665, 2030, 30, 272, 665, 80, 30, 774, 14933, 340, 2337, 365, 282, 13457, 12431, 12386, 9758, 80, 30, 272, 665, 4060, 2928, 534, 624, 435, 1166, 17, 435, 408, 15, 2219, 15, 30608, 15, 4058, 15, 7731, 13, 1960, 88, 1960, 14, 4524, 22619, 523, 3068, 2030, 30, 199, 1108, 1360, 30, 408, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2446, 8, 1069, 12, 1177, 304, 272, 492, 13804, 465, 2022, 272, 289, 275, 570, 360, 888, 14, 1001, 358, 272, 1350, 275, 289, 14, 739, 342, 272, 308, 275, 2022, 14, 6243, 8326, 1252, 2708, 8, 1365, 9, 272, 1166, 17, 275, 298, 1014, 30443, 435, 308, 459, 1102, 418, 435, 14725, 435, 620, 8, 83, 459, 5203, 2545, 1014, 3488, 17, 566, 272, 1166, 18, 275, 298, 1014, 30443, 435, 308, 459, 1102, 418, 435, 14725, 435, 620, 8, 83, 459, 5203, 2545, 1014, 3488, 16, 566, 272, 485, 30635, 275, 298, 4060, 13, 2164, 283, 277, 4065, 272, 1177, 14, 2139, 14, 409, 480, 2714, 13, 7676, 13, 4845, 13, 7457, 13, 5903, 401, 485, 30635, 9, 272, 1177, 14, 2139, 14, 409, 480, 56, 13, 2714, 13, 7676, 13, 4845, 13, 7457, 13, 5903, 401, 485, 30635, 9, 272, 1177, 14, 2139, 14, 409, 480, 56, 13, 21666, 13, 30635, 13, 7457, 13, 5903, 401, 485, 30635, 9, 272, 372, 8894, 1, 16556, 3517, 30, 199, 25273, 199, 7384, 334, 67, 9, 6171, 20619, 11098, 14, 199, 199, 497, 4972, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 7100, 12, 199, 1530, 8211, 2741, 626, 314, 2569, 3704, 787, 7647, 26, 199, 199, 10, 6823, 402, 5419, 1471, 8074, 314, 3379, 4248, 4245, 12, 642, 769, 523, 402, 3704, 436, 314, 2569, 6450, 14, 199, 10, 6823, 315, 3366, 1824, 1471, 9172, 314, 3379, 4248, 4245, 12, 523, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 3794, 523, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 199, 10, 11443, 314, 536, 402, 20619, 11098, 6590, 314, 1561, 402, 2399, 8417, 523, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 642, 1736, 1928, 523, 2488, 6791, 5313, 4983, 14, 199, 199, 24571, 4141, 2281, 7049, 6515, 16429, 2901, 27072, 298, 1179, 2281, 2, 199, 3649, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 2296, 12, 2334, 199, 8947, 5177, 2990, 1634, 3169, 2401, 3092, 2381, 437, 3115, 3104, 199, 8693, 9706, 14, 1621, 4825, 6461, 7000, 16429, 2901, 27072, 6262, 7024, 2381, 1821, 8703, 12, 199, 568, 6098, 12, 9716, 12, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 199, 12728, 2845, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3998, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 9815, 199, 3359, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 334, 6446, 199, 6388, 9179, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 4141, 12, 199, 37, 8253, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 2817, 1384, 26, 267, 869, 8035, 12, 1488, 324, 771, 73, 665, 89, 324, 771, 1148, 14, 2411, 79, 32, 22264, 14, 957, 30, 199, 199, 31647, 199, 199, 28, 1360, 30, 523, 665, 2993, 30, 272, 665, 1213, 30, 30635, 1379, 26, 286, 681, 63, 293, 63, 4060, 13, 2164, 63, 277, 63, 6541, 63, 832, 1108, 1213, 30, 272, 665, 1073, 4668, 628, 2502, 2, 2538, 628, 27528, 2, 4369, 628, 1014, 921, 1544, 14, 22264, 14, 957, 7897, 272, 665, 1073, 4668, 628, 3437, 2, 4369, 628, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 1766, 15, 7409, 15, 2944, 13, 30635, 13, 7409, 845, 1046, 12645, 4060, 13, 2164, 7897, 272, 665, 2024, 536, 628, 2469, 2, 1564, 9287, 3133, 272, 665, 2024, 536, 628, 479, 2, 1564, 628, 4060, 13, 2164, 283, 277, 4065, 3133, 272, 665, 2024, 5960, 628, 1624, 13, 24, 7897, 523, 3068, 2993, 30, 523, 665, 2030, 30, 272, 665, 80, 30, 774, 14933, 340, 2337, 365, 282, 13457, 12431, 12386, 9758, 80, 30, 272, 665, 4060, 2928, 534, 624, 435, 1166, 17, 435, 408, 15, 2219, 15, 30608, 15, 4058, 15, 7731, 13, 1960, 88, 1960, 14, 4524, 22619, 523, 3068, 2030, 30, 199, 1108, 1360, 30, 408, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Eternali/synk
synk-pre/synk-pre.py
1
5279
''' Synk - Sublime Text Plugin ''' import os import socket import sublime import sublime_plugin from threading import Thread, Timer # variables for storing user defined settings settings_filename = "synk_pre.sublime-settings" enabled_field = "enabled" server_ips_field = "project_server_ips" # NOTE: add feature to have more than one server later uplink_ports_field = "uplink_ports" downlink_ports_field = "downlink_ports" all_files_field = "synk_all_files" current_file_field = "synk_current_file" delay_field = "delay_in_seconds" # Object for connecting to the server class ServerConnection(object): def __init__(self, attempts=5): self.settings = sublime.load_settings(settings_filename) self.delay = self.settings.get(delay_field) self.server = self.settings.get(server_ips_field) self.up_port = self.settings.get(uplink_ports_field) self.down_port = self.settings.get(downlink_ports_field) self.current_file = self.settings.get(current_file_field) self.upsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.downsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.file_locked = False for a in range(attempts): try: self.upsock.connect((self.server, self.up_port)) self.downsock.connect((self.server, self.down_port)) return except: continue sublime.status_message("An error occured while attempting to connect to the server.") def recv_data(conn): received = "" while True: data = conn.recv(4096) received += data.decode("utf-8") if len(data) <= 4096: break return received def write_file(fname, data, mode="w"): with open(fname, mode) as f: for line in data: f.write(line + '\n') def push_changes(self, filename=self.current_file, attempts=30): for a in attempts: if not self.file_locked: self.file_locked = True data = self.current_file + '\n' + view.substr(sublime.Region(0, view.size())) self.upsock.send(data.encode("utf-8")) self.file_locked = False break def get_changes(self): #change_thread = Thread(target=self.get_changes_thread) #change_thread.start() Timer(self.delay, self.get_changes_thread).start() def get_changes_thread(self): while True: self.recved_data = self.recv_data(self.downsock) if len(self.recv_data) and not self.file_locked and not view.is_loading(): self.file_locked = True self.write_file(self.current_file, self.recved_data) self.file_locked = False class SynkPreListener(sublime_plugin.EventListener): save_queue = [] @staticmethod def generate_backup_filename(filename): dirname, basename = [os.path.dirname(filename), os.path.basename(filename).split('.')] if len(basename) > 1: basename.insert(-1, 'bak') else: basename.append('bak') return dirname + '/' + '.'.join(basename) def on_modified(self, view): settings = sublime.load_settings(settings_filename) if not (view.file_name() and view.is_dirty()): return delay = settings.get(delay_field) all_files = settings.get(all_files_field) current_file = settings.get(current_file_field) if not all_files and current_file != view.file_name(): return def callback(): settings = sublime.load_settings(settings_filename) current_file = settings.get(current_file_field) if view.is_dirty() and not view.is_loading(): view.run_command("save") serv_conn.push_changes(filename=current_file) else: content = view.substr(sublime.Region(0, view.size())) try: with open(SynkPreListener.generate_backup_filename(view.filename()), 'w', encoding="utf-8") as f: f.write(content) except Exception as e: sublime.status_message(str(e)) raise e class SynkPreCommand(sublime_plugin.TextCommand): def run(self, **kwargs): enable = kwargs.get("enable", None) all_files = kwargs.get("all_files", False) settings = sublime.load_settings(settings_filename) if enable is None: enable = not settings.get(enabled_field) if not enable: message = "Autosynk is turned off." filename = settings.get(current_file_field) settings.set(enabled_field, enable) settings.set(all_files_field, all_files) filename = sublime.Window.active_view(sublime.active_window()).file_name() settings.set(current_file_field, filename) if enable: message = "Autosynk is turned on." if not all_files: message += " for: " + os.path.basename(filename) serv_conn = ServerConnection() global serv_conn serv_conn.get_changes() sublime.status_message(message)
gpl-3.0
[ 2344, 199, 17746, 75, 446, 4804, 18687, 4516, 11349, 199, 199, 2344, 199, 199, 646, 747, 199, 646, 2838, 199, 646, 1007, 18687, 199, 646, 1007, 18687, 63, 2718, 199, 504, 5796, 492, 11086, 12, 22287, 199, 199, 3, 2860, 367, 16915, 922, 3247, 2202, 199, 1751, 63, 1501, 275, 298, 9466, 75, 63, 657, 14, 954, 18687, 13, 1751, 2, 199, 199, 3827, 63, 698, 275, 298, 3827, 2, 199, 1000, 63, 6142, 63, 698, 275, 298, 1715, 63, 1000, 63, 6142, 2, 258, 327, 6944, 26, 1050, 3878, 370, 1172, 1655, 2419, 1373, 1654, 2945, 199, 28816, 63, 5203, 63, 698, 275, 298, 28816, 63, 5203, 2, 199, 2110, 1073, 63, 5203, 63, 698, 275, 298, 2110, 1073, 63, 5203, 2, 199, 452, 63, 1725, 63, 698, 275, 298, 9466, 75, 63, 452, 63, 1725, 2, 199, 1818, 63, 493, 63, 698, 275, 298, 9466, 75, 63, 1818, 63, 493, 2, 199, 5814, 63, 698, 275, 298, 5814, 63, 262, 63, 4515, 2, 421, 199, 3, 6935, 367, 18170, 370, 314, 1654, 199, 533, 7146, 3225, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 12454, 29, 21, 304, 267, 291, 14, 1751, 275, 1007, 18687, 14, 912, 63, 1751, 8, 1751, 63, 1501, 9, 267, 291, 14, 5814, 275, 291, 14, 1751, 14, 362, 8, 5814, 63, 698, 9, 267, 291, 14, 1000, 275, 291, 14, 1751, 14, 362, 8, 1000, 63, 6142, 63, 698, 9, 267, 291, 14, 384, 63, 719, 275, 291, 14, 1751, 14, 362, 8, 28816, 63, 5203, 63, 698, 9, 267, 291, 14, 2110, 63, 719, 275, 291, 14, 1751, 14, 362, 8, 2110, 1073, 63, 5203, 63, 698, 9, 267, 291, 14, 1818, 63, 493, 275, 291, 14, 1751, 14, 362, 8, 1818, 63, 493, 63, 698, 9, 267, 291, 14, 384, 5096, 275, 2838, 14, 3450, 8, 3450, 14, 5699, 63, 11367, 12, 2838, 14, 9469, 63, 9484, 9, 267, 291, 14, 68, 23311, 766, 275, 2838, 14, 3450, 8, 3450, 14, 5699, 63, 11367, 12, 2838, 14, 9469, 63, 9484, 9, 267, 291, 14, 493, 63, 9325, 275, 756, 267, 367, 282, 315, 1425, 8, 13143, 304, 288, 862, 26, 355, 291, 14, 384, 5096, 14, 2242, 1332, 277, 14, 1000, 12, 291, 14, 384, 63, 719, 430, 355, 291, 14, 68, 23311, 766, 14, 2242, 1332, 277, 14, 1000, 12, 291, 14, 2110, 63, 719, 430, 355, 372, 288, 871, 26, 355, 1980, 267, 1007, 18687, 14, 1205, 63, 1188, 480, 2493, 1125, 28408, 1830, 19595, 370, 4907, 370, 314, 1654, 2685, 339, 347, 11904, 63, 576, 8, 1631, 304, 267, 3086, 275, 3087, 267, 1830, 715, 26, 288, 666, 275, 2557, 14, 7637, 8, 20579, 9, 288, 3086, 847, 666, 14, 2708, 480, 1624, 13, 24, 531, 288, 340, 822, 8, 576, 9, 2695, 17125, 26, 355, 2059, 398, 372, 3086, 339, 347, 2218, 63, 493, 8, 5252, 12, 666, 12, 818, 628, 87, 2349, 267, 543, 1551, 8, 5252, 12, 818, 9, 465, 289, 26, 288, 367, 1004, 315, 666, 26, 355, 289, 14, 952, 8, 604, 435, 1557, 78, 358, 339, 347, 6675, 63, 6627, 8, 277, 12, 1788, 29, 277, 14, 1818, 63, 493, 12, 12454, 29, 1216, 304, 267, 367, 282, 315, 12454, 26, 288, 340, 440, 291, 14, 493, 63, 9325, 26, 355, 291, 14, 493, 63, 9325, 275, 715, 355, 666, 275, 291, 14, 1818, 63, 493, 435, 1557, 78, 7, 435, 2455, 14, 22668, 8, 954, 18687, 14, 10708, 8, 16, 12, 2455, 14, 890, 4059, 355, 291, 14, 384, 5096, 14, 2254, 8, 576, 14, 2143, 480, 1624, 13, 24, 2237, 355, 291, 14, 493, 63, 9325, 275, 756, 355, 2059, 339, 347, 664, 63, 6627, 8, 277, 304, 267, 327, 1461, 63, 2671, 275, 11086, 8, 1375, 29, 277, 14, 362, 63, 6627, 63, 2671, 9, 267, 327, 1461, 63, 2671, 14, 928, 342, 267, 22287, 8, 277, 14, 5814, 12, 291, 14, 362, 63, 6627, 63, 2671, 680, 928, 342, 339, 347, 664, 63, 6627, 63, 2671, 8, 277, 304, 267, 1830, 715, 26, 288, 291, 14, 2761, 1354, 63, 576, 275, 291, 14, 7637, 63, 576, 8, 277, 14, 68, 23311, 766, 9, 288, 340, 822, 8, 277, 14, 7637, 63, 576, 9, 436, 440, 291, 14, 493, 63, 9325, 436, 440, 2455, 14, 374, 63, 8786, 837, 355, 291, 14, 493, 63, 9325, 275, 715, 355, 291, 14, 952, 63, 493, 8, 277, 14, 1818, 63, 493, 12, 291, 14, 2761, 1354, 63, 576, 9, 355, 291, 14, 493, 63, 9325, 275, 756, 421, 199, 533, 29988, 75, 2398, 10464, 8, 954, 18687, 63, 2718, 14, 2390, 10464, 304, 272, 3354, 63, 1825, 275, 942, 339, 768, 4639, 272, 347, 3550, 63, 5751, 63, 1501, 8, 1501, 304, 267, 9017, 12, 9593, 275, 359, 736, 14, 515, 14, 3475, 8, 1501, 395, 747, 14, 515, 14, 4846, 8, 1501, 680, 1294, 7563, 61, 267, 340, 822, 8, 4846, 9, 690, 413, 26, 288, 9593, 14, 3176, 2801, 17, 12, 283, 27162, 358, 267, 587, 26, 288, 9593, 14, 740, 360, 27162, 358, 398, 372, 9017, 435, 7324, 435, 15671, 904, 8, 4846, 9, 339, 347, 641, 63, 5540, 8, 277, 12, 2455, 304, 267, 2202, 275, 1007, 18687, 14, 912, 63, 1751, 8, 1751, 63, 1501, 9, 267, 340, 440, 334, 1345, 14, 493, 63, 354, 342, 436, 2455, 14, 374, 63, 8799, 5109, 288, 372, 398, 7339, 275, 2202, 14, 362, 8, 5814, 63, 698, 9, 267, 1006, 63, 1725, 275, 2202, 14, 362, 8, 452, 63, 1725, 63, 698, 9, 267, 1453, 63, 493, 275, 2202, 14, 362, 8, 1818, 63, 493, 63, 698, 9, 398, 340, 440, 1006, 63, 1725, 436, 1453, 63, 493, 1137, 2455, 14, 493, 63, 354, 837, 288, 372, 339, 347, 3233, 837, 267, 2202, 275, 1007, 18687, 14, 912, 63, 1751, 8, 1751, 63, 1501, 9, 267, 1453, 63, 493, 275, 2202, 14, 362, 8, 1818, 63, 493, 63, 698, 9, 267, 340, 2455, 14, 374, 63, 8799, 342, 436, 440, 2455, 14, 374, 63, 8786, 837, 288, 2455, 14, 1065, 63, 1531, 480, 2117, 531, 288, 27415, 63, 1631 ]
[ 199, 17746, 75, 446, 4804, 18687, 4516, 11349, 199, 199, 2344, 199, 199, 646, 747, 199, 646, 2838, 199, 646, 1007, 18687, 199, 646, 1007, 18687, 63, 2718, 199, 504, 5796, 492, 11086, 12, 22287, 199, 199, 3, 2860, 367, 16915, 922, 3247, 2202, 199, 1751, 63, 1501, 275, 298, 9466, 75, 63, 657, 14, 954, 18687, 13, 1751, 2, 199, 199, 3827, 63, 698, 275, 298, 3827, 2, 199, 1000, 63, 6142, 63, 698, 275, 298, 1715, 63, 1000, 63, 6142, 2, 258, 327, 6944, 26, 1050, 3878, 370, 1172, 1655, 2419, 1373, 1654, 2945, 199, 28816, 63, 5203, 63, 698, 275, 298, 28816, 63, 5203, 2, 199, 2110, 1073, 63, 5203, 63, 698, 275, 298, 2110, 1073, 63, 5203, 2, 199, 452, 63, 1725, 63, 698, 275, 298, 9466, 75, 63, 452, 63, 1725, 2, 199, 1818, 63, 493, 63, 698, 275, 298, 9466, 75, 63, 1818, 63, 493, 2, 199, 5814, 63, 698, 275, 298, 5814, 63, 262, 63, 4515, 2, 421, 199, 3, 6935, 367, 18170, 370, 314, 1654, 199, 533, 7146, 3225, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 12454, 29, 21, 304, 267, 291, 14, 1751, 275, 1007, 18687, 14, 912, 63, 1751, 8, 1751, 63, 1501, 9, 267, 291, 14, 5814, 275, 291, 14, 1751, 14, 362, 8, 5814, 63, 698, 9, 267, 291, 14, 1000, 275, 291, 14, 1751, 14, 362, 8, 1000, 63, 6142, 63, 698, 9, 267, 291, 14, 384, 63, 719, 275, 291, 14, 1751, 14, 362, 8, 28816, 63, 5203, 63, 698, 9, 267, 291, 14, 2110, 63, 719, 275, 291, 14, 1751, 14, 362, 8, 2110, 1073, 63, 5203, 63, 698, 9, 267, 291, 14, 1818, 63, 493, 275, 291, 14, 1751, 14, 362, 8, 1818, 63, 493, 63, 698, 9, 267, 291, 14, 384, 5096, 275, 2838, 14, 3450, 8, 3450, 14, 5699, 63, 11367, 12, 2838, 14, 9469, 63, 9484, 9, 267, 291, 14, 68, 23311, 766, 275, 2838, 14, 3450, 8, 3450, 14, 5699, 63, 11367, 12, 2838, 14, 9469, 63, 9484, 9, 267, 291, 14, 493, 63, 9325, 275, 756, 267, 367, 282, 315, 1425, 8, 13143, 304, 288, 862, 26, 355, 291, 14, 384, 5096, 14, 2242, 1332, 277, 14, 1000, 12, 291, 14, 384, 63, 719, 430, 355, 291, 14, 68, 23311, 766, 14, 2242, 1332, 277, 14, 1000, 12, 291, 14, 2110, 63, 719, 430, 355, 372, 288, 871, 26, 355, 1980, 267, 1007, 18687, 14, 1205, 63, 1188, 480, 2493, 1125, 28408, 1830, 19595, 370, 4907, 370, 314, 1654, 2685, 339, 347, 11904, 63, 576, 8, 1631, 304, 267, 3086, 275, 3087, 267, 1830, 715, 26, 288, 666, 275, 2557, 14, 7637, 8, 20579, 9, 288, 3086, 847, 666, 14, 2708, 480, 1624, 13, 24, 531, 288, 340, 822, 8, 576, 9, 2695, 17125, 26, 355, 2059, 398, 372, 3086, 339, 347, 2218, 63, 493, 8, 5252, 12, 666, 12, 818, 628, 87, 2349, 267, 543, 1551, 8, 5252, 12, 818, 9, 465, 289, 26, 288, 367, 1004, 315, 666, 26, 355, 289, 14, 952, 8, 604, 435, 1557, 78, 358, 339, 347, 6675, 63, 6627, 8, 277, 12, 1788, 29, 277, 14, 1818, 63, 493, 12, 12454, 29, 1216, 304, 267, 367, 282, 315, 12454, 26, 288, 340, 440, 291, 14, 493, 63, 9325, 26, 355, 291, 14, 493, 63, 9325, 275, 715, 355, 666, 275, 291, 14, 1818, 63, 493, 435, 1557, 78, 7, 435, 2455, 14, 22668, 8, 954, 18687, 14, 10708, 8, 16, 12, 2455, 14, 890, 4059, 355, 291, 14, 384, 5096, 14, 2254, 8, 576, 14, 2143, 480, 1624, 13, 24, 2237, 355, 291, 14, 493, 63, 9325, 275, 756, 355, 2059, 339, 347, 664, 63, 6627, 8, 277, 304, 267, 327, 1461, 63, 2671, 275, 11086, 8, 1375, 29, 277, 14, 362, 63, 6627, 63, 2671, 9, 267, 327, 1461, 63, 2671, 14, 928, 342, 267, 22287, 8, 277, 14, 5814, 12, 291, 14, 362, 63, 6627, 63, 2671, 680, 928, 342, 339, 347, 664, 63, 6627, 63, 2671, 8, 277, 304, 267, 1830, 715, 26, 288, 291, 14, 2761, 1354, 63, 576, 275, 291, 14, 7637, 63, 576, 8, 277, 14, 68, 23311, 766, 9, 288, 340, 822, 8, 277, 14, 7637, 63, 576, 9, 436, 440, 291, 14, 493, 63, 9325, 436, 440, 2455, 14, 374, 63, 8786, 837, 355, 291, 14, 493, 63, 9325, 275, 715, 355, 291, 14, 952, 63, 493, 8, 277, 14, 1818, 63, 493, 12, 291, 14, 2761, 1354, 63, 576, 9, 355, 291, 14, 493, 63, 9325, 275, 756, 421, 199, 533, 29988, 75, 2398, 10464, 8, 954, 18687, 63, 2718, 14, 2390, 10464, 304, 272, 3354, 63, 1825, 275, 942, 339, 768, 4639, 272, 347, 3550, 63, 5751, 63, 1501, 8, 1501, 304, 267, 9017, 12, 9593, 275, 359, 736, 14, 515, 14, 3475, 8, 1501, 395, 747, 14, 515, 14, 4846, 8, 1501, 680, 1294, 7563, 61, 267, 340, 822, 8, 4846, 9, 690, 413, 26, 288, 9593, 14, 3176, 2801, 17, 12, 283, 27162, 358, 267, 587, 26, 288, 9593, 14, 740, 360, 27162, 358, 398, 372, 9017, 435, 7324, 435, 15671, 904, 8, 4846, 9, 339, 347, 641, 63, 5540, 8, 277, 12, 2455, 304, 267, 2202, 275, 1007, 18687, 14, 912, 63, 1751, 8, 1751, 63, 1501, 9, 267, 340, 440, 334, 1345, 14, 493, 63, 354, 342, 436, 2455, 14, 374, 63, 8799, 5109, 288, 372, 398, 7339, 275, 2202, 14, 362, 8, 5814, 63, 698, 9, 267, 1006, 63, 1725, 275, 2202, 14, 362, 8, 452, 63, 1725, 63, 698, 9, 267, 1453, 63, 493, 275, 2202, 14, 362, 8, 1818, 63, 493, 63, 698, 9, 398, 340, 440, 1006, 63, 1725, 436, 1453, 63, 493, 1137, 2455, 14, 493, 63, 354, 837, 288, 372, 339, 347, 3233, 837, 267, 2202, 275, 1007, 18687, 14, 912, 63, 1751, 8, 1751, 63, 1501, 9, 267, 1453, 63, 493, 275, 2202, 14, 362, 8, 1818, 63, 493, 63, 698, 9, 267, 340, 2455, 14, 374, 63, 8799, 342, 436, 440, 2455, 14, 374, 63, 8786, 837, 288, 2455, 14, 1065, 63, 1531, 480, 2117, 531, 288, 27415, 63, 1631, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
ChristianKniep/QNIB
serverfiles/usr/local/lib/networkx-1.6/networkx/exception.py
5
1540
# -*- coding: utf-8 -*- """ ********** Exceptions ********** Base exceptions and errors for NetworkX. """ __author__ = """Aric Hagberg (hagberg@lanl.gov)\nPieter Swart (swart@lanl.gov)\nDan Schult(dschult@colgate.edu)\nLoïc Séguin-C. <loicseguin@gmail.com>""" # Copyright (C) 2004-2008 by # Aric Hagberg <hagberg@lanl.gov> # Dan Schult <dschult@colgate.edu> # Pieter Swart <swart@lanl.gov> # All rights reserved. # BSD license. # # Exception handling # the root of all Exceptions class NetworkXException(Exception): """Base class for exceptions in NetworkX.""" class NetworkXError(NetworkXException): """Exception for a serious error in NetworkX""" class NetworkXPointlessConcept(NetworkXException): """Harary, F. and Read, R. "Is the Null Graph a Pointless Concept?" In Graphs and Combinatorics Conference, George Washington University. New York: Springer-Verlag, 1973. """ class NetworkXAlgorithmError(NetworkXException): """Exception for unexpected termination of algorithms.""" class NetworkXUnfeasible(NetworkXAlgorithmError): """Exception raised by algorithms trying to solve a problem instance that has no feasible solution.""" class NetworkXNoPath(NetworkXUnfeasible): """Exception for algorithms that should return a path when running on graphs where such a path does not exist.""" class NetworkXUnbounded(NetworkXAlgorithmError): """Exception raised by algorithms trying to solve a maximization or a minimization problem instance that is unbounded."""
gpl-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 199, 1801, 538, 199, 16836, 199, 1801, 538, 199, 199, 1563, 4967, 436, 2552, 367, 7220, 56, 14, 1362, 199, 624, 199, 363, 2502, 363, 275, 408, 33, 1567, 869, 643, 14630, 334, 72, 643, 14630, 32, 1502, 76, 14, 16294, 2862, 30035, 1873, 351, 16666, 580, 334, 3519, 580, 32, 1502, 76, 14, 16294, 2862, 78, 29336, 22985, 427, 8, 795, 335, 427, 32, 761, 3237, 14, 8654, 2862, 78, 2041, 128, 108, 67, 428, 5741, 6051, 262, 13, 35, 14, 665, 320, 530, 261, 6051, 262, 32, 6799, 14, 957, 11193, 199, 3, 259, 1898, 334, 35, 9, 8353, 13, 9300, 701, 221, 199, 3, 259, 437, 1567, 869, 643, 14630, 665, 72, 643, 14630, 32, 1502, 76, 14, 16294, 30, 199, 3, 259, 24747, 22985, 427, 665, 795, 335, 427, 32, 761, 3237, 14, 8654, 30, 199, 3, 259, 510, 1873, 351, 16666, 580, 665, 3519, 580, 32, 1502, 76, 14, 16294, 30, 199, 3, 259, 2900, 4481, 4644, 14, 199, 3, 259, 6289, 4190, 14, 199, 3, 199, 199, 3, 2186, 7252, 199, 199, 3, 314, 1738, 402, 1006, 24873, 199, 533, 7220, 56, 1726, 8, 1726, 304, 272, 408, 1563, 1021, 367, 4967, 315, 7220, 56, 1041, 199, 199, 533, 7220, 29356, 8, 4491, 56, 1726, 304, 272, 408, 1726, 367, 282, 542, 322, 1785, 1125, 315, 7220, 56, 624, 199, 199, 533, 7220, 56, 3428, 2003, 32209, 8, 4491, 56, 1726, 304, 272, 408, 18248, 695, 12, 481, 14, 436, 5574, 12, 820, 14, 298, 1831, 314, 12119, 11513, 282, 7584, 2003, 1448, 716, 13472, 221, 199, 607, 11513, 83, 436, 22170, 707, 2932, 1448, 1769, 12, 5346, 24591, 644, 1119, 31673, 15904, 14, 199, 4665, 1488, 4708, 26, 428, 2700, 7886, 13, 3673, 1823, 12, 413, 26706, 14, 199, 624, 199, 199, 533, 7220, 56, 11570, 547, 8, 4491, 56, 1726, 304, 272, 408, 1726, 367, 10537, 23868, 402, 18036, 1041, 199, 199, 533, 7220, 56, 1358, 771, 305, 7247, 8, 4491, 56, 11570, 547, 304, 272, 408, 1726, 4915, 701, 18036, 9936, 370, 14241, 282, 5160, 272, 1256, 626, 965, 949, 1964, 305, 7247, 8744, 1041, 199, 199, 533, 7220, 56, 1944, 2042, 8, 4491, 56, 1358, 771, 305, 7247, 304, 272, 408, 1726, 367, 18036, 626, 1077, 372, 282, 931, 1380, 3879, 272, 641, 18312, 2382, 4066, 282, 931, 1630, 440, 2187, 1041, 199, 199, 533, 7220, 56, 1358, 7547, 8, 4491, 56, 11570, 547, 304, 272, 408, 1726, 4915, 701, 18036, 9936, 370, 14241, 282, 1390, 1017, 2072, 272, 503, 282, 18790, 2072, 5160, 1256, 626, 365, 625, 7547, 1041, 4388, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 199, 1801, 538, 199, 16836, 199, 1801, 538, 199, 199, 1563, 4967, 436, 2552, 367, 7220, 56, 14, 1362, 199, 624, 199, 363, 2502, 363, 275, 408, 33, 1567, 869, 643, 14630, 334, 72, 643, 14630, 32, 1502, 76, 14, 16294, 2862, 30035, 1873, 351, 16666, 580, 334, 3519, 580, 32, 1502, 76, 14, 16294, 2862, 78, 29336, 22985, 427, 8, 795, 335, 427, 32, 761, 3237, 14, 8654, 2862, 78, 2041, 128, 108, 67, 428, 5741, 6051, 262, 13, 35, 14, 665, 320, 530, 261, 6051, 262, 32, 6799, 14, 957, 11193, 199, 3, 259, 1898, 334, 35, 9, 8353, 13, 9300, 701, 221, 199, 3, 259, 437, 1567, 869, 643, 14630, 665, 72, 643, 14630, 32, 1502, 76, 14, 16294, 30, 199, 3, 259, 24747, 22985, 427, 665, 795, 335, 427, 32, 761, 3237, 14, 8654, 30, 199, 3, 259, 510, 1873, 351, 16666, 580, 665, 3519, 580, 32, 1502, 76, 14, 16294, 30, 199, 3, 259, 2900, 4481, 4644, 14, 199, 3, 259, 6289, 4190, 14, 199, 3, 199, 199, 3, 2186, 7252, 199, 199, 3, 314, 1738, 402, 1006, 24873, 199, 533, 7220, 56, 1726, 8, 1726, 304, 272, 408, 1563, 1021, 367, 4967, 315, 7220, 56, 1041, 199, 199, 533, 7220, 29356, 8, 4491, 56, 1726, 304, 272, 408, 1726, 367, 282, 542, 322, 1785, 1125, 315, 7220, 56, 624, 199, 199, 533, 7220, 56, 3428, 2003, 32209, 8, 4491, 56, 1726, 304, 272, 408, 18248, 695, 12, 481, 14, 436, 5574, 12, 820, 14, 298, 1831, 314, 12119, 11513, 282, 7584, 2003, 1448, 716, 13472, 221, 199, 607, 11513, 83, 436, 22170, 707, 2932, 1448, 1769, 12, 5346, 24591, 644, 1119, 31673, 15904, 14, 199, 4665, 1488, 4708, 26, 428, 2700, 7886, 13, 3673, 1823, 12, 413, 26706, 14, 199, 624, 199, 199, 533, 7220, 56, 11570, 547, 8, 4491, 56, 1726, 304, 272, 408, 1726, 367, 10537, 23868, 402, 18036, 1041, 199, 199, 533, 7220, 56, 1358, 771, 305, 7247, 8, 4491, 56, 11570, 547, 304, 272, 408, 1726, 4915, 701, 18036, 9936, 370, 14241, 282, 5160, 272, 1256, 626, 965, 949, 1964, 305, 7247, 8744, 1041, 199, 199, 533, 7220, 56, 1944, 2042, 8, 4491, 56, 1358, 771, 305, 7247, 304, 272, 408, 1726, 367, 18036, 626, 1077, 372, 282, 931, 1380, 3879, 272, 641, 18312, 2382, 4066, 282, 931, 1630, 440, 2187, 1041, 199, 199, 533, 7220, 56, 1358, 7547, 8, 4491, 56, 11570, 547, 304, 272, 408, 1726, 4915, 701, 18036, 9936, 370, 14241, 282, 1390, 1017, 2072, 272, 503, 282, 18790, 2072, 5160, 1256, 626, 365, 625, 7547, 1041, 4388, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
MalloyPower/parsing-python
front-end/testsuite-python-lib/Python-3.6.0/Lib/selectors.py
4
19168
"""Selectors module. This module allows high-level and efficient I/O multiplexing, built upon the `select` module primitives. """ from abc import ABCMeta, abstractmethod from collections import namedtuple, Mapping import math import select import sys # generic events, that must be mapped to implementation-specific ones EVENT_READ = (1 << 0) EVENT_WRITE = (1 << 1) def _fileobj_to_fd(fileobj): """Return a file descriptor from a file object. Parameters: fileobj -- file object or file descriptor Returns: corresponding file descriptor Raises: ValueError if the object is invalid """ if isinstance(fileobj, int): fd = fileobj else: try: fd = int(fileobj.fileno()) except (AttributeError, TypeError, ValueError): raise ValueError("Invalid file object: " "{!r}".format(fileobj)) from None if fd < 0: raise ValueError("Invalid file descriptor: {}".format(fd)) return fd SelectorKey = namedtuple('SelectorKey', ['fileobj', 'fd', 'events', 'data']) SelectorKey.__doc__ = """SelectorKey(fileobj, fd, events, data) Object used to associate a file object to its backing file descriptor, selected event mask, and attached data. """ if sys.version_info >= (3, 5): SelectorKey.fileobj.__doc__ = 'File object registered.' SelectorKey.fd.__doc__ = 'Underlying file descriptor.' SelectorKey.events.__doc__ = 'Events that must be waited for on this file object.' SelectorKey.data.__doc__ = ('''Optional opaque data associated to this file object. For example, this could be used to store a per-client session ID.''') class _SelectorMapping(Mapping): """Mapping of file objects to selector keys.""" def __init__(self, selector): self._selector = selector def __len__(self): return len(self._selector._fd_to_key) def __getitem__(self, fileobj): try: fd = self._selector._fileobj_lookup(fileobj) return self._selector._fd_to_key[fd] except KeyError: raise KeyError("{!r} is not registered".format(fileobj)) from None def __iter__(self): return iter(self._selector._fd_to_key) class BaseSelector(metaclass=ABCMeta): """Selector abstract base class. A selector supports registering file objects to be monitored for specific I/O events. A file object is a file descriptor or any object with a `fileno()` method. An arbitrary object can be attached to the file object, which can be used for example to store context information, a callback, etc. A selector can use various implementations (select(), poll(), epoll()...) depending on the platform. The default `Selector` class uses the most efficient implementation on the current platform. """ @abstractmethod def register(self, fileobj, events, data=None): """Register a file object. Parameters: fileobj -- file object or file descriptor events -- events to monitor (bitwise mask of EVENT_READ|EVENT_WRITE) data -- attached data Returns: SelectorKey instance Raises: ValueError if events is invalid KeyError if fileobj is already registered OSError if fileobj is closed or otherwise is unacceptable to the underlying system call (if a system call is made) Note: OSError may or may not be raised """ raise NotImplementedError @abstractmethod def unregister(self, fileobj): """Unregister a file object. Parameters: fileobj -- file object or file descriptor Returns: SelectorKey instance Raises: KeyError if fileobj is not registered Note: If fileobj is registered but has since been closed this does *not* raise OSError (even if the wrapped syscall does) """ raise NotImplementedError def modify(self, fileobj, events, data=None): """Change a registered file object monitored events or attached data. Parameters: fileobj -- file object or file descriptor events -- events to monitor (bitwise mask of EVENT_READ|EVENT_WRITE) data -- attached data Returns: SelectorKey instance Raises: Anything that unregister() or register() raises """ self.unregister(fileobj) return self.register(fileobj, events, data) @abstractmethod def select(self, timeout=None): """Perform the actual selection, until some monitored file objects are ready or a timeout expires. Parameters: timeout -- if timeout > 0, this specifies the maximum wait time, in seconds if timeout <= 0, the select() call won't block, and will report the currently ready file objects if timeout is None, select() will block until a monitored file object becomes ready Returns: list of (key, events) for ready file objects `events` is a bitwise mask of EVENT_READ|EVENT_WRITE """ raise NotImplementedError def close(self): """Close the selector. This must be called to make sure that any underlying resource is freed. """ pass def get_key(self, fileobj): """Return the key associated to a registered file object. Returns: SelectorKey for this file object """ mapping = self.get_map() if mapping is None: raise RuntimeError('Selector is closed') try: return mapping[fileobj] except KeyError: raise KeyError("{!r} is not registered".format(fileobj)) from None @abstractmethod def get_map(self): """Return a mapping of file objects to selector keys.""" raise NotImplementedError def __enter__(self): return self def __exit__(self, *args): self.close() class _BaseSelectorImpl(BaseSelector): """Base selector implementation.""" def __init__(self): # this maps file descriptors to keys self._fd_to_key = {} # read-only mapping returned by get_map() self._map = _SelectorMapping(self) def _fileobj_lookup(self, fileobj): """Return a file descriptor from a file object. This wraps _fileobj_to_fd() to do an exhaustive search in case the object is invalid but we still have it in our map. This is used by unregister() so we can unregister an object that was previously registered even if it is closed. It is also used by _SelectorMapping. """ try: return _fileobj_to_fd(fileobj) except ValueError: # Do an exhaustive search. for key in self._fd_to_key.values(): if key.fileobj is fileobj: return key.fd # Raise ValueError after all. raise def register(self, fileobj, events, data=None): if (not events) or (events & ~(EVENT_READ | EVENT_WRITE)): raise ValueError("Invalid events: {!r}".format(events)) key = SelectorKey(fileobj, self._fileobj_lookup(fileobj), events, data) if key.fd in self._fd_to_key: raise KeyError("{!r} (FD {}) is already registered" .format(fileobj, key.fd)) self._fd_to_key[key.fd] = key return key def unregister(self, fileobj): try: key = self._fd_to_key.pop(self._fileobj_lookup(fileobj)) except KeyError: raise KeyError("{!r} is not registered".format(fileobj)) from None return key def modify(self, fileobj, events, data=None): # TODO: Subclasses can probably optimize this even further. try: key = self._fd_to_key[self._fileobj_lookup(fileobj)] except KeyError: raise KeyError("{!r} is not registered".format(fileobj)) from None if events != key.events: self.unregister(fileobj) key = self.register(fileobj, events, data) elif data != key.data: # Use a shortcut to update the data. key = key._replace(data=data) self._fd_to_key[key.fd] = key return key def close(self): self._fd_to_key.clear() self._map = None def get_map(self): return self._map def _key_from_fd(self, fd): """Return the key associated to a given file descriptor. Parameters: fd -- file descriptor Returns: corresponding key, or None if not found """ try: return self._fd_to_key[fd] except KeyError: return None class SelectSelector(_BaseSelectorImpl): """Select-based selector.""" def __init__(self): super().__init__() self._readers = set() self._writers = set() def register(self, fileobj, events, data=None): key = super().register(fileobj, events, data) if events & EVENT_READ: self._readers.add(key.fd) if events & EVENT_WRITE: self._writers.add(key.fd) return key def unregister(self, fileobj): key = super().unregister(fileobj) self._readers.discard(key.fd) self._writers.discard(key.fd) return key if sys.platform == 'win32': def _select(self, r, w, _, timeout=None): r, w, x = select.select(r, w, w, timeout) return r, w + x, [] else: _select = select.select def select(self, timeout=None): timeout = None if timeout is None else max(timeout, 0) ready = [] try: r, w, _ = self._select(self._readers, self._writers, [], timeout) except InterruptedError: return ready r = set(r) w = set(w) for fd in r | w: events = 0 if fd in r: events |= EVENT_READ if fd in w: events |= EVENT_WRITE key = self._key_from_fd(fd) if key: ready.append((key, events & key.events)) return ready if hasattr(select, 'poll'): class PollSelector(_BaseSelectorImpl): """Poll-based selector.""" def __init__(self): super().__init__() self._poll = select.poll() def register(self, fileobj, events, data=None): key = super().register(fileobj, events, data) poll_events = 0 if events & EVENT_READ: poll_events |= select.POLLIN if events & EVENT_WRITE: poll_events |= select.POLLOUT self._poll.register(key.fd, poll_events) return key def unregister(self, fileobj): key = super().unregister(fileobj) self._poll.unregister(key.fd) return key def select(self, timeout=None): if timeout is None: timeout = None elif timeout <= 0: timeout = 0 else: # poll() has a resolution of 1 millisecond, round away from # zero to wait *at least* timeout seconds. timeout = math.ceil(timeout * 1e3) ready = [] try: fd_event_list = self._poll.poll(timeout) except InterruptedError: return ready for fd, event in fd_event_list: events = 0 if event & ~select.POLLIN: events |= EVENT_WRITE if event & ~select.POLLOUT: events |= EVENT_READ key = self._key_from_fd(fd) if key: ready.append((key, events & key.events)) return ready if hasattr(select, 'epoll'): class EpollSelector(_BaseSelectorImpl): """Epoll-based selector.""" def __init__(self): super().__init__() self._epoll = select.epoll() def fileno(self): return self._epoll.fileno() def register(self, fileobj, events, data=None): key = super().register(fileobj, events, data) epoll_events = 0 if events & EVENT_READ: epoll_events |= select.EPOLLIN if events & EVENT_WRITE: epoll_events |= select.EPOLLOUT self._epoll.register(key.fd, epoll_events) return key def unregister(self, fileobj): key = super().unregister(fileobj) try: self._epoll.unregister(key.fd) except OSError: # This can happen if the FD was closed since it # was registered. pass return key def select(self, timeout=None): if timeout is None: timeout = -1 elif timeout <= 0: timeout = 0 else: # epoll_wait() has a resolution of 1 millisecond, round away # from zero to wait *at least* timeout seconds. timeout = math.ceil(timeout * 1e3) * 1e-3 # epoll_wait() expects `maxevents` to be greater than zero; # we want to make sure that `select()` can be called when no # FD is registered. max_ev = max(len(self._fd_to_key), 1) ready = [] try: fd_event_list = self._epoll.poll(timeout, max_ev) except InterruptedError: return ready for fd, event in fd_event_list: events = 0 if event & ~select.EPOLLIN: events |= EVENT_WRITE if event & ~select.EPOLLOUT: events |= EVENT_READ key = self._key_from_fd(fd) if key: ready.append((key, events & key.events)) return ready def close(self): self._epoll.close() super().close() if hasattr(select, 'devpoll'): class DevpollSelector(_BaseSelectorImpl): """Solaris /dev/poll selector.""" def __init__(self): super().__init__() self._devpoll = select.devpoll() def fileno(self): return self._devpoll.fileno() def register(self, fileobj, events, data=None): key = super().register(fileobj, events, data) poll_events = 0 if events & EVENT_READ: poll_events |= select.POLLIN if events & EVENT_WRITE: poll_events |= select.POLLOUT self._devpoll.register(key.fd, poll_events) return key def unregister(self, fileobj): key = super().unregister(fileobj) self._devpoll.unregister(key.fd) return key def select(self, timeout=None): if timeout is None: timeout = None elif timeout <= 0: timeout = 0 else: # devpoll() has a resolution of 1 millisecond, round away from # zero to wait *at least* timeout seconds. timeout = math.ceil(timeout * 1e3) ready = [] try: fd_event_list = self._devpoll.poll(timeout) except InterruptedError: return ready for fd, event in fd_event_list: events = 0 if event & ~select.POLLIN: events |= EVENT_WRITE if event & ~select.POLLOUT: events |= EVENT_READ key = self._key_from_fd(fd) if key: ready.append((key, events & key.events)) return ready def close(self): self._devpoll.close() super().close() if hasattr(select, 'kqueue'): class KqueueSelector(_BaseSelectorImpl): """Kqueue-based selector.""" def __init__(self): super().__init__() self._kqueue = select.kqueue() def fileno(self): return self._kqueue.fileno() def register(self, fileobj, events, data=None): key = super().register(fileobj, events, data) if events & EVENT_READ: kev = select.kevent(key.fd, select.KQ_FILTER_READ, select.KQ_EV_ADD) self._kqueue.control([kev], 0, 0) if events & EVENT_WRITE: kev = select.kevent(key.fd, select.KQ_FILTER_WRITE, select.KQ_EV_ADD) self._kqueue.control([kev], 0, 0) return key def unregister(self, fileobj): key = super().unregister(fileobj) if key.events & EVENT_READ: kev = select.kevent(key.fd, select.KQ_FILTER_READ, select.KQ_EV_DELETE) try: self._kqueue.control([kev], 0, 0) except OSError: # This can happen if the FD was closed since it # was registered. pass if key.events & EVENT_WRITE: kev = select.kevent(key.fd, select.KQ_FILTER_WRITE, select.KQ_EV_DELETE) try: self._kqueue.control([kev], 0, 0) except OSError: # See comment above. pass return key def select(self, timeout=None): timeout = None if timeout is None else max(timeout, 0) max_ev = len(self._fd_to_key) ready = [] try: kev_list = self._kqueue.control(None, max_ev, timeout) except InterruptedError: return ready for kev in kev_list: fd = kev.ident flag = kev.filter events = 0 if flag == select.KQ_FILTER_READ: events |= EVENT_READ if flag == select.KQ_FILTER_WRITE: events |= EVENT_WRITE key = self._key_from_fd(fd) if key: ready.append((key, events & key.events)) return ready def close(self): self._kqueue.close() super().close() # Choose the best implementation, roughly: # epoll|kqueue|devpoll > poll > select. # select() also can't accept a FD > FD_SETSIZE (usually around 1024) if 'KqueueSelector' in globals(): DefaultSelector = KqueueSelector elif 'EpollSelector' in globals(): DefaultSelector = EpollSelector elif 'DevpollSelector' in globals(): DefaultSelector = DevpollSelector elif 'PollSelector' in globals(): DefaultSelector = PollSelector else: DefaultSelector = SelectSelector
mit
[ 624, 11212, 83, 859, 14, 199, 199, 2765, 859, 6127, 4721, 13, 1896, 436, 13402, 473, 15, 47, 3663, 88, 316, 12, 6137, 12188, 314, 199, 64, 2416, 64, 859, 1979, 22337, 14, 199, 624, 421, 199, 504, 13022, 492, 29565, 12, 9006, 765, 199, 504, 5055, 492, 12863, 12, 12340, 199, 646, 3473, 199, 646, 3504, 199, 646, 984, 421, 199, 3, 7809, 4474, 12, 626, 1471, 506, 9994, 370, 4514, 13, 6100, 7869, 199, 8193, 63, 5670, 275, 334, 17, 5213, 378, 9, 199, 8193, 63, 10387, 275, 334, 17, 5213, 413, 9, 421, 199, 318, 485, 9234, 63, 475, 63, 2592, 8, 9234, 304, 272, 408, 1767, 282, 570, 5872, 687, 282, 570, 909, 14, 339, 3897, 26, 272, 11099, 1553, 570, 909, 503, 570, 5872, 339, 1803, 26, 272, 5226, 570, 5872, 339, 6218, 26, 272, 1722, 340, 314, 909, 365, 3866, 272, 408, 272, 340, 1228, 8, 9234, 12, 1109, 304, 267, 6111, 275, 11099, 272, 587, 26, 267, 862, 26, 288, 6111, 275, 1109, 8, 9234, 14, 9843, 1012, 267, 871, 334, 10227, 12, 3146, 12, 1722, 304, 288, 746, 1722, 480, 3364, 570, 909, 26, 298, 2490, 5310, 1, 82, 5469, 908, 8, 9234, 430, 687, 488, 272, 340, 6111, 665, 378, 26, 267, 746, 1722, 480, 3364, 570, 5872, 26, 8352, 908, 8, 2592, 430, 272, 372, 6111, 421, 199, 11212, 1197, 275, 12863, 360, 11212, 1197, 297, 788, 9234, 297, 283, 2592, 297, 283, 4368, 297, 283, 576, 1105, 199, 199, 11212, 1197, 855, 1301, 363, 275, 408, 11212, 1197, 8, 9234, 12, 6111, 12, 4474, 12, 666, 9, 339, 6935, 1202, 370, 20133, 282, 570, 909, 370, 2399, 21094, 272, 570, 5872, 12, 4895, 1566, 3656, 12, 436, 10102, 666, 14, 199, 624, 199, 692, 984, 14, 1023, 63, 815, 2356, 334, 19, 12, 959, 304, 272, 3240, 3283, 1197, 14, 9234, 855, 1301, 363, 275, 283, 1173, 909, 7264, 3530, 272, 3240, 3283, 1197, 14, 2592, 855, 1301, 363, 275, 283, 26104, 570, 5872, 3530, 272, 3240, 3283, 1197, 14, 4368, 855, 1301, 363, 275, 283, 11770, 626, 1471, 506, 14442, 5703, 367, 641, 642, 570, 909, 3530, 272, 3240, 3283, 1197, 14, 576, 855, 1301, 363, 275, 661, 891, 7012, 15058, 666, 4568, 370, 642, 570, 909, 14, 272, 2104, 2893, 12, 642, 4293, 506, 1202, 370, 3877, 282, 1126, 13, 1258, 2351, 2870, 14, 12310, 199, 199, 533, 485, 11212, 7674, 8, 7674, 304, 272, 408, 7674, 402, 570, 2251, 370, 9759, 2883, 1041, 339, 347, 636, 826, 721, 277, 12, 9759, 304, 267, 291, 423, 6662, 275, 9759, 339, 347, 636, 552, 721, 277, 304, 267, 372, 822, 8, 277, 423, 6662, 423, 2592, 63, 475, 63, 498, 9, 339, 347, 636, 6095, 721, 277, 12, 11099, 304, 267, 862, 26, 288, 6111, 275, 291, 423, 6662, 423, 9234, 63, 3892, 8, 9234, 9, 288, 372, 291, 423, 6662, 423, 2592, 63, 475, 63, 498, 59, 2592, 61, 267, 871, 4067, 26, 288, 746, 4067, 13076, 1, 82, 93, 365, 440, 7264, 1674, 908, 8, 9234, 430, 687, 488, 339, 347, 636, 1661, 721, 277, 304, 267, 372, 2740, 8, 277, 423, 6662, 423, 2592, 63, 475, 63, 498, 9, 421, 199, 533, 3523, 11212, 8, 6577, 29, 22254, 304, 272, 408, 11212, 9006, 1300, 1021, 14, 339, 437, 9759, 5171, 2274, 316, 570, 2251, 370, 506, 23821, 367, 2488, 272, 473, 15, 47, 4474, 14, 339, 437, 570, 909, 365, 282, 570, 5872, 503, 1263, 909, 543, 282, 658, 9843, 11995, 1083, 14, 272, 1626, 9697, 909, 883, 506, 10102, 370, 314, 570, 909, 12, 1314, 883, 506, 1202, 272, 367, 2893, 370, 3877, 1067, 2556, 12, 282, 3233, 12, 5423, 14, 339, 437, 9759, 883, 675, 7750, 12591, 334, 2416, 1062, 11271, 1062, 325, 6843, 342, 11965, 272, 10298, 641, 314, 4298, 14, 710, 849, 658, 11212, 64, 1021, 4440, 314, 4750, 272, 13402, 4514, 641, 314, 1453, 4298, 14, 272, 408, 339, 768, 10315, 272, 347, 2274, 8, 277, 12, 11099, 12, 4474, 12, 666, 29, 403, 304, 267, 408, 7099, 282, 570, 909, 14, 398, 3897, 26, 267, 11099, 1553, 570, 909, 503, 570, 5872, 267, 4474, 221, 1553, 4474, 370, 8372, 334, 28831, 3656, 402, 6461, 63, 5670, 92, 8193, 63, 10387, 9, 267, 666, 259, 1553, 10102, 666, 398, 1803, 26, 267, 3240, 3283, 1197, 1256, 398, 6218, 26, 267, 1722, 340, 4474, 365, 3866, 267, 4067, 340, 11099, 365, 2575, 7264, 267, 6440, 340, 11099, 365, 6876, 503, 4257, 365, 625, 28751, 370, 355, 314, 8793, 2656, 1240, 334, 692, 282, 2656, 1240, 365, 6326, 9, 398, 3390, 26, 267, 6440, 1443, 503, 1443, 440, 506, 4915, 267, 408, 267, 746, 4279, 339, 768, 10315, 272, 347, 24369, 8, 277, 12, 11099, 304, 267, 408, 27419, 282, 570, 909, 14, 398, 3897, 26, 267, 11099, 1553, 570, 909, 503, 570, 5872, 398, 1803, 26, 267, 3240, 3283, 1197, 1256, 398, 6218, 26, 267, 4067, 340, 11099, 365, 440, 7264, 398, 3390, 26, 267, 982, 11099, 365, 7264, 1325, 965, 3967, 2757, 6876, 642, 1630, 267, 627, 1397, 10, 746, 6440, 334, 12056, 340, 314, 8072, 18901, 1630, 9, 267, 408, 267, 746, 4279, 339, 347, 2811, 8, 277, 12, 11099, 12, 4474, 12, 666, 29, 403, 304, 267, 408, 4001, 282, 7264, 570, 909, 23821, 4474, 503, 10102, 666, 14, 398, 3897, 26, 267, 11099, 1553, 570, 909, 503, 570, 5872, 267, 4474, 221, 1553, 4474, 370, 8372, 334, 28831, 3656, 402, 6461, 63, 5670, 92, 8193, 63, 10387, 9, 267, 666, 259, 1553, 10102, 666, 398, 1803, 26, 267, 3240, 3283, 1197, 1256, 398, 6218, 26, 267, 6184, 2127, 626, 24369, 342, 503, 2274, 342, 6534, 267, 408, 267, 291, 14, 18408, 8, 9234, 9, 267, 372, 291, 14, 2683, 8, 9234, 12, 4474, 12, 666, 9, 339, 768, 10315, 272, 347, 3504, 8, 277, 12, 2653, 29, 403, 304, 267, 408, 20906, 314, 3503, 7267, 12, 5133, 2005, 23821, 570, 2251, 787, 267, 10144, 503, 282, 2653, 12261, 14, 398, 3897, 26, 267, 2653, 1553, 340, 2653, 690, 378, 12, 642, 9314, 314, 5696, 3618, 900, 12, 315, 673, 4696, 673 ]
[ 11212, 83, 859, 14, 199, 199, 2765, 859, 6127, 4721, 13, 1896, 436, 13402, 473, 15, 47, 3663, 88, 316, 12, 6137, 12188, 314, 199, 64, 2416, 64, 859, 1979, 22337, 14, 199, 624, 421, 199, 504, 13022, 492, 29565, 12, 9006, 765, 199, 504, 5055, 492, 12863, 12, 12340, 199, 646, 3473, 199, 646, 3504, 199, 646, 984, 421, 199, 3, 7809, 4474, 12, 626, 1471, 506, 9994, 370, 4514, 13, 6100, 7869, 199, 8193, 63, 5670, 275, 334, 17, 5213, 378, 9, 199, 8193, 63, 10387, 275, 334, 17, 5213, 413, 9, 421, 199, 318, 485, 9234, 63, 475, 63, 2592, 8, 9234, 304, 272, 408, 1767, 282, 570, 5872, 687, 282, 570, 909, 14, 339, 3897, 26, 272, 11099, 1553, 570, 909, 503, 570, 5872, 339, 1803, 26, 272, 5226, 570, 5872, 339, 6218, 26, 272, 1722, 340, 314, 909, 365, 3866, 272, 408, 272, 340, 1228, 8, 9234, 12, 1109, 304, 267, 6111, 275, 11099, 272, 587, 26, 267, 862, 26, 288, 6111, 275, 1109, 8, 9234, 14, 9843, 1012, 267, 871, 334, 10227, 12, 3146, 12, 1722, 304, 288, 746, 1722, 480, 3364, 570, 909, 26, 298, 2490, 5310, 1, 82, 5469, 908, 8, 9234, 430, 687, 488, 272, 340, 6111, 665, 378, 26, 267, 746, 1722, 480, 3364, 570, 5872, 26, 8352, 908, 8, 2592, 430, 272, 372, 6111, 421, 199, 11212, 1197, 275, 12863, 360, 11212, 1197, 297, 788, 9234, 297, 283, 2592, 297, 283, 4368, 297, 283, 576, 1105, 199, 199, 11212, 1197, 855, 1301, 363, 275, 408, 11212, 1197, 8, 9234, 12, 6111, 12, 4474, 12, 666, 9, 339, 6935, 1202, 370, 20133, 282, 570, 909, 370, 2399, 21094, 272, 570, 5872, 12, 4895, 1566, 3656, 12, 436, 10102, 666, 14, 199, 624, 199, 692, 984, 14, 1023, 63, 815, 2356, 334, 19, 12, 959, 304, 272, 3240, 3283, 1197, 14, 9234, 855, 1301, 363, 275, 283, 1173, 909, 7264, 3530, 272, 3240, 3283, 1197, 14, 2592, 855, 1301, 363, 275, 283, 26104, 570, 5872, 3530, 272, 3240, 3283, 1197, 14, 4368, 855, 1301, 363, 275, 283, 11770, 626, 1471, 506, 14442, 5703, 367, 641, 642, 570, 909, 3530, 272, 3240, 3283, 1197, 14, 576, 855, 1301, 363, 275, 661, 891, 7012, 15058, 666, 4568, 370, 642, 570, 909, 14, 272, 2104, 2893, 12, 642, 4293, 506, 1202, 370, 3877, 282, 1126, 13, 1258, 2351, 2870, 14, 12310, 199, 199, 533, 485, 11212, 7674, 8, 7674, 304, 272, 408, 7674, 402, 570, 2251, 370, 9759, 2883, 1041, 339, 347, 636, 826, 721, 277, 12, 9759, 304, 267, 291, 423, 6662, 275, 9759, 339, 347, 636, 552, 721, 277, 304, 267, 372, 822, 8, 277, 423, 6662, 423, 2592, 63, 475, 63, 498, 9, 339, 347, 636, 6095, 721, 277, 12, 11099, 304, 267, 862, 26, 288, 6111, 275, 291, 423, 6662, 423, 9234, 63, 3892, 8, 9234, 9, 288, 372, 291, 423, 6662, 423, 2592, 63, 475, 63, 498, 59, 2592, 61, 267, 871, 4067, 26, 288, 746, 4067, 13076, 1, 82, 93, 365, 440, 7264, 1674, 908, 8, 9234, 430, 687, 488, 339, 347, 636, 1661, 721, 277, 304, 267, 372, 2740, 8, 277, 423, 6662, 423, 2592, 63, 475, 63, 498, 9, 421, 199, 533, 3523, 11212, 8, 6577, 29, 22254, 304, 272, 408, 11212, 9006, 1300, 1021, 14, 339, 437, 9759, 5171, 2274, 316, 570, 2251, 370, 506, 23821, 367, 2488, 272, 473, 15, 47, 4474, 14, 339, 437, 570, 909, 365, 282, 570, 5872, 503, 1263, 909, 543, 282, 658, 9843, 11995, 1083, 14, 272, 1626, 9697, 909, 883, 506, 10102, 370, 314, 570, 909, 12, 1314, 883, 506, 1202, 272, 367, 2893, 370, 3877, 1067, 2556, 12, 282, 3233, 12, 5423, 14, 339, 437, 9759, 883, 675, 7750, 12591, 334, 2416, 1062, 11271, 1062, 325, 6843, 342, 11965, 272, 10298, 641, 314, 4298, 14, 710, 849, 658, 11212, 64, 1021, 4440, 314, 4750, 272, 13402, 4514, 641, 314, 1453, 4298, 14, 272, 408, 339, 768, 10315, 272, 347, 2274, 8, 277, 12, 11099, 12, 4474, 12, 666, 29, 403, 304, 267, 408, 7099, 282, 570, 909, 14, 398, 3897, 26, 267, 11099, 1553, 570, 909, 503, 570, 5872, 267, 4474, 221, 1553, 4474, 370, 8372, 334, 28831, 3656, 402, 6461, 63, 5670, 92, 8193, 63, 10387, 9, 267, 666, 259, 1553, 10102, 666, 398, 1803, 26, 267, 3240, 3283, 1197, 1256, 398, 6218, 26, 267, 1722, 340, 4474, 365, 3866, 267, 4067, 340, 11099, 365, 2575, 7264, 267, 6440, 340, 11099, 365, 6876, 503, 4257, 365, 625, 28751, 370, 355, 314, 8793, 2656, 1240, 334, 692, 282, 2656, 1240, 365, 6326, 9, 398, 3390, 26, 267, 6440, 1443, 503, 1443, 440, 506, 4915, 267, 408, 267, 746, 4279, 339, 768, 10315, 272, 347, 24369, 8, 277, 12, 11099, 304, 267, 408, 27419, 282, 570, 909, 14, 398, 3897, 26, 267, 11099, 1553, 570, 909, 503, 570, 5872, 398, 1803, 26, 267, 3240, 3283, 1197, 1256, 398, 6218, 26, 267, 4067, 340, 11099, 365, 440, 7264, 398, 3390, 26, 267, 982, 11099, 365, 7264, 1325, 965, 3967, 2757, 6876, 642, 1630, 267, 627, 1397, 10, 746, 6440, 334, 12056, 340, 314, 8072, 18901, 1630, 9, 267, 408, 267, 746, 4279, 339, 347, 2811, 8, 277, 12, 11099, 12, 4474, 12, 666, 29, 403, 304, 267, 408, 4001, 282, 7264, 570, 909, 23821, 4474, 503, 10102, 666, 14, 398, 3897, 26, 267, 11099, 1553, 570, 909, 503, 570, 5872, 267, 4474, 221, 1553, 4474, 370, 8372, 334, 28831, 3656, 402, 6461, 63, 5670, 92, 8193, 63, 10387, 9, 267, 666, 259, 1553, 10102, 666, 398, 1803, 26, 267, 3240, 3283, 1197, 1256, 398, 6218, 26, 267, 6184, 2127, 626, 24369, 342, 503, 2274, 342, 6534, 267, 408, 267, 291, 14, 18408, 8, 9234, 9, 267, 372, 291, 14, 2683, 8, 9234, 12, 4474, 12, 666, 9, 339, 768, 10315, 272, 347, 3504, 8, 277, 12, 2653, 29, 403, 304, 267, 408, 20906, 314, 3503, 7267, 12, 5133, 2005, 23821, 570, 2251, 787, 267, 10144, 503, 282, 2653, 12261, 14, 398, 3897, 26, 267, 2653, 1553, 340, 2653, 690, 378, 12, 642, 9314, 314, 5696, 3618, 900, 12, 315, 673, 4696, 673, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
duncanhawthorne/robot-robot
libs/future/backports/urllib/robotparser.py
81
6865
from __future__ import absolute_import, division, unicode_literals from future.builtins import str """ robotparser.py Copyright (C) 2000 Bastian Kleineidam You can choose between two licenses when using this package: 1) GNU GPLv2 2) PSF license for Python 2.2 The robots.txt Exclusion Protocol is implemented as specified in http://info.webcrawler.com/mak/projects/robots/norobots-rfc.html """ # Was: import urllib.parse, urllib.request from future.backports import urllib from future.backports.urllib import parse as _parse, request as _request urllib.parse = _parse urllib.request = _request __all__ = ["RobotFileParser"] class RobotFileParser(object): """ This class provides a set of methods to read, parse and answer questions about a single robots.txt file. """ def __init__(self, url=''): self.entries = [] self.default_entry = None self.disallow_all = False self.allow_all = False self.set_url(url) self.last_checked = 0 def mtime(self): """Returns the time the robots.txt file was last fetched. This is useful for long-running web spiders that need to check for new robots.txt files periodically. """ return self.last_checked def modified(self): """Sets the time the robots.txt file was last fetched to the current time. """ import time self.last_checked = time.time() def set_url(self, url): """Sets the URL referring to a robots.txt file.""" self.url = url self.host, self.path = urllib.parse.urlparse(url)[1:3] def read(self): """Reads the robots.txt URL and feeds it to the parser.""" try: f = urllib.request.urlopen(self.url) except urllib.error.HTTPError as err: if err.code in (401, 403): self.disallow_all = True elif err.code >= 400: self.allow_all = True else: raw = f.read() self.parse(raw.decode("utf-8").splitlines()) def _add_entry(self, entry): if "*" in entry.useragents: # the default entry is considered last if self.default_entry is None: # the first default entry wins self.default_entry = entry else: self.entries.append(entry) def parse(self, lines): """Parse the input lines from a robots.txt file. We allow that a user-agent: line is not preceded by one or more blank lines. """ # states: # 0: start state # 1: saw user-agent line # 2: saw an allow or disallow line state = 0 entry = Entry() for line in lines: if not line: if state == 1: entry = Entry() state = 0 elif state == 2: self._add_entry(entry) entry = Entry() state = 0 # remove optional comment and strip line i = line.find('#') if i >= 0: line = line[:i] line = line.strip() if not line: continue line = line.split(':', 1) if len(line) == 2: line[0] = line[0].strip().lower() line[1] = urllib.parse.unquote(line[1].strip()) if line[0] == "user-agent": if state == 2: self._add_entry(entry) entry = Entry() entry.useragents.append(line[1]) state = 1 elif line[0] == "disallow": if state != 0: entry.rulelines.append(RuleLine(line[1], False)) state = 2 elif line[0] == "allow": if state != 0: entry.rulelines.append(RuleLine(line[1], True)) state = 2 if state == 2: self._add_entry(entry) def can_fetch(self, useragent, url): """using the parsed robots.txt decide if useragent can fetch url""" if self.disallow_all: return False if self.allow_all: return True # search for given user agent matches # the first match counts parsed_url = urllib.parse.urlparse(urllib.parse.unquote(url)) url = urllib.parse.urlunparse(('','',parsed_url.path, parsed_url.params,parsed_url.query, parsed_url.fragment)) url = urllib.parse.quote(url) if not url: url = "/" for entry in self.entries: if entry.applies_to(useragent): return entry.allowance(url) # try the default entry last if self.default_entry: return self.default_entry.allowance(url) # agent not found ==> access granted return True def __str__(self): return ''.join([str(entry) + "\n" for entry in self.entries]) class RuleLine(object): """A rule line is a single "Allow:" (allowance==True) or "Disallow:" (allowance==False) followed by a path.""" def __init__(self, path, allowance): if path == '' and not allowance: # an empty value means allow all allowance = True self.path = urllib.parse.quote(path) self.allowance = allowance def applies_to(self, filename): return self.path == "*" or filename.startswith(self.path) def __str__(self): return (self.allowance and "Allow" or "Disallow") + ": " + self.path class Entry(object): """An entry has one or more user-agents and zero or more rulelines""" def __init__(self): self.useragents = [] self.rulelines = [] def __str__(self): ret = [] for agent in self.useragents: ret.extend(["User-agent: ", agent, "\n"]) for line in self.rulelines: ret.extend([str(line), "\n"]) return ''.join(ret) def applies_to(self, useragent): """check if this entry applies to the specified agent""" # split the name token and make it lower case useragent = useragent.split("/")[0].lower() for agent in self.useragents: if agent == '*': # we have the catch-all agent return True agent = agent.lower() if agent in useragent: return True return False def allowance(self, filename): """Preconditions: - our agent applies to this entry - filename is URL decoded""" for line in self.rulelines: if line.applies_to(filename): return line.allowance return True
mit
[ 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 2649, 63, 5955, 199, 504, 6466, 14, 10372, 492, 620, 199, 624, 14544, 2087, 14, 647, 339, 1898, 334, 35, 9, 12293, 221, 699, 1810, 5653, 1804, 274, 1132, 344, 455, 339, 2047, 883, 11496, 3382, 2877, 12378, 1380, 1808, 642, 2559, 26, 272, 413, 9, 1664, 14629, 86, 18, 272, 499, 9, 29770, 4190, 367, 2018, 499, 14, 18, 339, 710, 14544, 83, 14, 2424, 1316, 10248, 11557, 365, 6366, 465, 2013, 315, 272, 1455, 921, 815, 14, 2520, 23972, 14, 957, 15, 22191, 15, 6776, 15, 28889, 15, 6505, 2873, 16673, 13, 8973, 14, 1360, 199, 624, 199, 199, 3, 644, 305, 26, 492, 4011, 14, 1122, 12, 4011, 14, 1069, 199, 504, 6466, 14, 894, 5203, 492, 4011, 199, 504, 6466, 14, 894, 5203, 14, 4078, 492, 2198, 465, 485, 1122, 12, 1056, 465, 485, 1069, 199, 4078, 14, 1122, 275, 485, 1122, 199, 4078, 14, 1069, 275, 485, 1069, 421, 199, 363, 452, 363, 275, 2097, 21823, 1173, 2842, 937, 199, 199, 533, 820, 17800, 1173, 2842, 8, 785, 304, 272, 408, 961, 1021, 6571, 282, 663, 402, 3102, 370, 1586, 12, 2198, 436, 6385, 272, 23071, 3595, 282, 2849, 14544, 83, 14, 2424, 570, 14, 339, 408, 339, 347, 636, 826, 721, 277, 12, 1166, 9280, 267, 291, 14, 3189, 275, 942, 267, 291, 14, 885, 63, 2373, 275, 488, 267, 291, 14, 2297, 3306, 63, 452, 275, 756, 267, 291, 14, 3306, 63, 452, 275, 756, 267, 291, 14, 409, 63, 633, 8, 633, 9, 267, 291, 14, 2019, 63, 10718, 275, 378, 339, 347, 15005, 8, 277, 304, 267, 408, 3407, 314, 900, 314, 14544, 83, 14, 2424, 570, 1990, 2061, 19251, 14, 398, 961, 365, 2997, 367, 1846, 13, 5720, 3330, 19441, 7735, 626, 1929, 370, 267, 1104, 367, 892, 14544, 83, 14, 2424, 1584, 18745, 1183, 14, 398, 408, 267, 372, 291, 14, 2019, 63, 10718, 339, 347, 6042, 8, 277, 304, 267, 408, 9899, 314, 900, 314, 14544, 83, 14, 2424, 570, 1990, 2061, 19251, 370, 314, 267, 1453, 900, 14, 398, 408, 267, 492, 900, 267, 291, 14, 2019, 63, 10718, 275, 900, 14, 521, 342, 339, 347, 663, 63, 633, 8, 277, 12, 1166, 304, 267, 408, 9899, 314, 2851, 21864, 370, 282, 14544, 83, 14, 2424, 570, 1041, 267, 291, 14, 633, 275, 1166, 267, 291, 14, 1102, 12, 291, 14, 515, 275, 4011, 14, 1122, 14, 10290, 8, 633, 2788, 17, 26, 19, 61, 339, 347, 1586, 8, 277, 304, 267, 408, 23614, 314, 14544, 83, 14, 2424, 2851, 436, 22295, 652, 370, 314, 1798, 1041, 267, 862, 26, 288, 289, 275, 4011, 14, 1069, 14, 10890, 8, 277, 14, 633, 9, 267, 871, 4011, 14, 705, 14, 12815, 465, 2329, 26, 288, 340, 2329, 14, 600, 315, 334, 8854, 12, 13269, 304, 355, 291, 14, 2297, 3306, 63, 452, 275, 715, 288, 916, 2329, 14, 600, 2356, 8290, 26, 355, 291, 14, 3306, 63, 452, 275, 715, 267, 587, 26, 288, 3066, 275, 289, 14, 739, 342, 288, 291, 14, 1122, 8, 1773, 14, 2708, 480, 1624, 13, 24, 3471, 7644, 1012, 339, 347, 485, 525, 63, 2373, 8, 277, 12, 2397, 304, 267, 340, 22423, 315, 2397, 14, 751, 14250, 26, 288, 327, 314, 849, 2397, 365, 8652, 2061, 288, 340, 291, 14, 885, 63, 2373, 365, 488, 26, 355, 327, 314, 1642, 849, 2397, 29431, 355, 291, 14, 885, 63, 2373, 275, 2397, 267, 587, 26, 288, 291, 14, 3189, 14, 740, 8, 2373, 9, 339, 347, 2198, 8, 277, 12, 2385, 304, 267, 408, 4003, 314, 1324, 2385, 687, 282, 14544, 83, 14, 2424, 570, 14, 398, 2136, 2040, 626, 282, 922, 13, 4054, 26, 1004, 365, 440, 9222, 770, 701, 267, 1373, 503, 1655, 4596, 2385, 14, 267, 408, 267, 327, 6363, 26, 267, 327, 257, 378, 26, 1343, 1174, 267, 327, 257, 413, 26, 28454, 922, 13, 4054, 1004, 267, 327, 257, 499, 26, 28454, 376, 2040, 503, 2153, 3306, 1004, 267, 1174, 275, 378, 267, 2397, 275, 11855, 342, 398, 367, 1004, 315, 2385, 26, 288, 340, 440, 1004, 26, 355, 340, 1174, 508, 413, 26, 490, 2397, 275, 11855, 342, 490, 1174, 275, 378, 355, 916, 1174, 508, 499, 26, 490, 291, 423, 525, 63, 2373, 8, 2373, 9, 490, 2397, 275, 11855, 342, 490, 1174, 275, 378, 288, 327, 2813, 2716, 3721, 436, 6202, 1004, 288, 284, 275, 1004, 14, 1623, 7863, 358, 288, 340, 284, 2356, 378, 26, 355, 1004, 275, 1004, 1491, 73, 61, 288, 1004, 275, 1004, 14, 1913, 342, 288, 340, 440, 1004, 26, 355, 1980, 288, 1004, 275, 1004, 14, 1294, 16451, 413, 9, 288, 340, 822, 8, 604, 9, 508, 499, 26, 355, 1004, 59, 16, 61, 275, 1004, 59, 16, 1055, 1913, 1252, 2325, 342, 355, 1004, 59, 17, 61, 275, 4011, 14, 1122, 14, 12240, 8, 604, 59, 17, 1055, 1913, 1012, 355, 340, 1004, 59, 16, 61, 508, 298, 751, 13, 4054, 582, 490, 340, 1174, 508, 499, 26, 717, 291, 423, 525, 63, 2373, 8, 2373, 9, 717, 2397, 275, 11855, 342, 490, 2397, 14, 751, 14250, 14, 740, 8, 604, 59, 17, 566, 490, 1174, 275, 413, 355, 916, 1004, 59, 16, 61, 508, 298, 2297, 3306, 582, 490, 340, 1174, 1137, 378, 26, 717, 2397, 14, 2200, 1278, 14, 740, 8, 5065, 3049, 8, 604, 59, 17, 467, 756, 430, 717, 1174, 275, 499, 355, 916, 1004, 59, 16, 61, 508, 298, 3306, 582, 490, 340, 1174, 1137, 378, 26, 717, 2397, 14, 2200, 1278, 14, 740, 8, 5065, 3049, 8, 604, 59, 17, 467, 715, 430, 717, 1174, 275, 499, 267, 340, 1174, 508, 499, 26, 288, 291, 423, 525, 63, 2373, 8, 2373, 9, 2378, 347, 883, 63, 3535, 8, 277, 12, 922, 4054, 12, 1166, 304, 267, 408, 4941, 314, 4565, 14544, 83, 14, 2424, 19822, 340, 922, 4054, 883, 5267, 1166, 624, 267, 340, 291, 14, 2297, 3306, 63, 452, 26, 288, 372, 756, 267, 340, 291, 14, 3306, 63, 452, 26, 288, 372, 715, 267, 327, 2754, 367, 1627, 922, 6631, 4450, 267 ]
[ 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 2649, 63, 5955, 199, 504, 6466, 14, 10372, 492, 620, 199, 624, 14544, 2087, 14, 647, 339, 1898, 334, 35, 9, 12293, 221, 699, 1810, 5653, 1804, 274, 1132, 344, 455, 339, 2047, 883, 11496, 3382, 2877, 12378, 1380, 1808, 642, 2559, 26, 272, 413, 9, 1664, 14629, 86, 18, 272, 499, 9, 29770, 4190, 367, 2018, 499, 14, 18, 339, 710, 14544, 83, 14, 2424, 1316, 10248, 11557, 365, 6366, 465, 2013, 315, 272, 1455, 921, 815, 14, 2520, 23972, 14, 957, 15, 22191, 15, 6776, 15, 28889, 15, 6505, 2873, 16673, 13, 8973, 14, 1360, 199, 624, 199, 199, 3, 644, 305, 26, 492, 4011, 14, 1122, 12, 4011, 14, 1069, 199, 504, 6466, 14, 894, 5203, 492, 4011, 199, 504, 6466, 14, 894, 5203, 14, 4078, 492, 2198, 465, 485, 1122, 12, 1056, 465, 485, 1069, 199, 4078, 14, 1122, 275, 485, 1122, 199, 4078, 14, 1069, 275, 485, 1069, 421, 199, 363, 452, 363, 275, 2097, 21823, 1173, 2842, 937, 199, 199, 533, 820, 17800, 1173, 2842, 8, 785, 304, 272, 408, 961, 1021, 6571, 282, 663, 402, 3102, 370, 1586, 12, 2198, 436, 6385, 272, 23071, 3595, 282, 2849, 14544, 83, 14, 2424, 570, 14, 339, 408, 339, 347, 636, 826, 721, 277, 12, 1166, 9280, 267, 291, 14, 3189, 275, 942, 267, 291, 14, 885, 63, 2373, 275, 488, 267, 291, 14, 2297, 3306, 63, 452, 275, 756, 267, 291, 14, 3306, 63, 452, 275, 756, 267, 291, 14, 409, 63, 633, 8, 633, 9, 267, 291, 14, 2019, 63, 10718, 275, 378, 339, 347, 15005, 8, 277, 304, 267, 408, 3407, 314, 900, 314, 14544, 83, 14, 2424, 570, 1990, 2061, 19251, 14, 398, 961, 365, 2997, 367, 1846, 13, 5720, 3330, 19441, 7735, 626, 1929, 370, 267, 1104, 367, 892, 14544, 83, 14, 2424, 1584, 18745, 1183, 14, 398, 408, 267, 372, 291, 14, 2019, 63, 10718, 339, 347, 6042, 8, 277, 304, 267, 408, 9899, 314, 900, 314, 14544, 83, 14, 2424, 570, 1990, 2061, 19251, 370, 314, 267, 1453, 900, 14, 398, 408, 267, 492, 900, 267, 291, 14, 2019, 63, 10718, 275, 900, 14, 521, 342, 339, 347, 663, 63, 633, 8, 277, 12, 1166, 304, 267, 408, 9899, 314, 2851, 21864, 370, 282, 14544, 83, 14, 2424, 570, 1041, 267, 291, 14, 633, 275, 1166, 267, 291, 14, 1102, 12, 291, 14, 515, 275, 4011, 14, 1122, 14, 10290, 8, 633, 2788, 17, 26, 19, 61, 339, 347, 1586, 8, 277, 304, 267, 408, 23614, 314, 14544, 83, 14, 2424, 2851, 436, 22295, 652, 370, 314, 1798, 1041, 267, 862, 26, 288, 289, 275, 4011, 14, 1069, 14, 10890, 8, 277, 14, 633, 9, 267, 871, 4011, 14, 705, 14, 12815, 465, 2329, 26, 288, 340, 2329, 14, 600, 315, 334, 8854, 12, 13269, 304, 355, 291, 14, 2297, 3306, 63, 452, 275, 715, 288, 916, 2329, 14, 600, 2356, 8290, 26, 355, 291, 14, 3306, 63, 452, 275, 715, 267, 587, 26, 288, 3066, 275, 289, 14, 739, 342, 288, 291, 14, 1122, 8, 1773, 14, 2708, 480, 1624, 13, 24, 3471, 7644, 1012, 339, 347, 485, 525, 63, 2373, 8, 277, 12, 2397, 304, 267, 340, 22423, 315, 2397, 14, 751, 14250, 26, 288, 327, 314, 849, 2397, 365, 8652, 2061, 288, 340, 291, 14, 885, 63, 2373, 365, 488, 26, 355, 327, 314, 1642, 849, 2397, 29431, 355, 291, 14, 885, 63, 2373, 275, 2397, 267, 587, 26, 288, 291, 14, 3189, 14, 740, 8, 2373, 9, 339, 347, 2198, 8, 277, 12, 2385, 304, 267, 408, 4003, 314, 1324, 2385, 687, 282, 14544, 83, 14, 2424, 570, 14, 398, 2136, 2040, 626, 282, 922, 13, 4054, 26, 1004, 365, 440, 9222, 770, 701, 267, 1373, 503, 1655, 4596, 2385, 14, 267, 408, 267, 327, 6363, 26, 267, 327, 257, 378, 26, 1343, 1174, 267, 327, 257, 413, 26, 28454, 922, 13, 4054, 1004, 267, 327, 257, 499, 26, 28454, 376, 2040, 503, 2153, 3306, 1004, 267, 1174, 275, 378, 267, 2397, 275, 11855, 342, 398, 367, 1004, 315, 2385, 26, 288, 340, 440, 1004, 26, 355, 340, 1174, 508, 413, 26, 490, 2397, 275, 11855, 342, 490, 1174, 275, 378, 355, 916, 1174, 508, 499, 26, 490, 291, 423, 525, 63, 2373, 8, 2373, 9, 490, 2397, 275, 11855, 342, 490, 1174, 275, 378, 288, 327, 2813, 2716, 3721, 436, 6202, 1004, 288, 284, 275, 1004, 14, 1623, 7863, 358, 288, 340, 284, 2356, 378, 26, 355, 1004, 275, 1004, 1491, 73, 61, 288, 1004, 275, 1004, 14, 1913, 342, 288, 340, 440, 1004, 26, 355, 1980, 288, 1004, 275, 1004, 14, 1294, 16451, 413, 9, 288, 340, 822, 8, 604, 9, 508, 499, 26, 355, 1004, 59, 16, 61, 275, 1004, 59, 16, 1055, 1913, 1252, 2325, 342, 355, 1004, 59, 17, 61, 275, 4011, 14, 1122, 14, 12240, 8, 604, 59, 17, 1055, 1913, 1012, 355, 340, 1004, 59, 16, 61, 508, 298, 751, 13, 4054, 582, 490, 340, 1174, 508, 499, 26, 717, 291, 423, 525, 63, 2373, 8, 2373, 9, 717, 2397, 275, 11855, 342, 490, 2397, 14, 751, 14250, 14, 740, 8, 604, 59, 17, 566, 490, 1174, 275, 413, 355, 916, 1004, 59, 16, 61, 508, 298, 2297, 3306, 582, 490, 340, 1174, 1137, 378, 26, 717, 2397, 14, 2200, 1278, 14, 740, 8, 5065, 3049, 8, 604, 59, 17, 467, 756, 430, 717, 1174, 275, 499, 355, 916, 1004, 59, 16, 61, 508, 298, 3306, 582, 490, 340, 1174, 1137, 378, 26, 717, 2397, 14, 2200, 1278, 14, 740, 8, 5065, 3049, 8, 604, 59, 17, 467, 715, 430, 717, 1174, 275, 499, 267, 340, 1174, 508, 499, 26, 288, 291, 423, 525, 63, 2373, 8, 2373, 9, 2378, 347, 883, 63, 3535, 8, 277, 12, 922, 4054, 12, 1166, 304, 267, 408, 4941, 314, 4565, 14544, 83, 14, 2424, 19822, 340, 922, 4054, 883, 5267, 1166, 624, 267, 340, 291, 14, 2297, 3306, 63, 452, 26, 288, 372, 756, 267, 340, 291, 14, 3306, 63, 452, 26, 288, 372, 715, 267, 327, 2754, 367, 1627, 922, 6631, 4450, 267, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
talha81/TACTIC-DEV
src/pyasm/widget/timecard_wdg.py
6
41157
########################################################### # # Copyright (c) 2005, Southpaw Technology # All Rights Reserved # # PROPRIETARY INFORMATION. This software is proprietary to # Southpaw Technology, and is not to be reproduced, transmitted, # or disclosed in any way without written permission. # # # #__all__ = [ 'MilestoneTableElement', # 'MilestoneWdg', 'MilestoneSetCmd'] __all__ = ['TimecardWdg', 'TimecardHourCmd', 'TimecardTaskRowWdg', 'TimecardCmd','TimecardCreateCmd', 'SpecialDayWdg', 'WeekTableElement', 'TimecardInfoTableElement', 'WeekHourInputWdg'] from pyasm.command import Command, CommandExitException, DatabaseAction from pyasm.search import Search, SObjectFactory, SObject, Sql from pyasm.biz import Pipeline, Timecard, Project, Task from pyasm.web import * from pyasm.widget import IconSubmitWdg, HiddenWdg, WidgetConfig, HintWdg, ExpandableTextWdg, CalendarInputWdg from pyasm.common import * from input_wdg import TextWdg, CalendarWdg, SelectWdg, ActionSelectWdg, FilterSelectWdg from table_element_wdg import BaseTableElementWdg from icon_wdg import IconWdg from file_wdg import ThumbWdg from custom_info_wdg import CustomInfoInputWdg def _get_div(width): ''' just to get a div to draw this widget ''' return FloatDivWdg(width=width) class TimecardTaskRowWdg(AjaxWdg): def init(my): ''' initializes a few variables ''' today = Date() my.week = int(today.get_week()) my.year = int(today.get_year()) my.process_len = 0 my.week_element_name = '' my.year_element_name = '' my.task = None my.cmd = None my.overtime_dict = {} def init_cgi(my): # get the sobject keys = my.web.get_form_keys() search_key = '' for key in keys: if key.startswith('skey_TimecardWdg_'): search_key = my.web.get_form_value(key) continue if key.startswith('week_'): my.week_element_name = key my.week = my.web.get_int_form_value(key) continue if key.startswith('year_'): my.year_element_name = key my.year = my.web.get_int_form_value(key) continue if search_key: sobject = Search.get_by_search_key(search_key) my.task = sobject my.init_setup() my.add_inputs() def add_inputs(my): ''' register the inputs ''' if not my.task: return hidden = HiddenWdg('skey_TimecardWdg_%s' %my.task.get_id()) my.add_ajax_input(hidden) week_text = TextWdg('week_%s' %my.task.get_search_key()) my.add_ajax_input(week_text) year_text = HiddenWdg('year_%s' %my.task.get_search_key()) my.add_ajax_input(year_text) def init_setup(my): ''' set up the ajax top and the ajax command ''' div_id = 'main_div_general' cmd_id = 'cal_general' if my.task: div_id = 'main_div_%s' %my.task.get_id() cmd_id = 'cal_%s' %my.task.get_id() my.main_div = DivWdg(id=div_id) my.set_ajax_top(my.main_div) my.cmd = AjaxCmd(cmd_id) my.cmd.add_element_name(my.week_element_name) my.cmd.add_element_name(my.year_element_name) def set_task(my, task): my.task = task my.init_setup() def get_cmd(my): return my.cmd def get_script(week_name, year_name, add=True): ''' if add==True, we are advancing to the next week ''' if add: return "Timecard.update_date('%s','%s','forward')"%(week_name, year_name) else: return "Timecard.update_date('%s','%s','backward')"%(week_name, year_name) get_script =staticmethod(get_script) def get_display(my): if not my.is_from_ajax(): return my.main_div my.process_len = TimecardWdg.get_process_width(my.task) if my.process_len > TimecardWdg.PROCESS_WIDTH: main_width = 50 * my.process_len / TimecardWdg.PROCESS_WIDTH my.main_div.add_style('width', '%sem' %main_width) my.add_control(my.main_div) my.main_div.add(HtmlElement.br(2)) my.add_unregistered_hours(my.main_div) my.main_div.add(HtmlElement.br()) my.add_overtime_hours(my.main_div) return my.main_div def add_control(my, main_div): ''' add the control for adjusting time card hours''' weekday_list = Calendar.get_monthday_time(my.year, my.week) month_list = [] for item in weekday_list: month, day, time = item if month not in month_list: month_list.append(month) today = Date() current_week = int(today.get_week()) current_year = int(today.get_year()) today_div = _get_div(TimecardWdg.PROCESS_WIDTH) today_div.add(my._get_this_week_link(current_week, current_year)) main_div.add(today_div) title_div = _get_div(270) #title_div.add_style('color: #6869a3') title_div.add_class('right_content') main_div.add(title_div) # show the year and month month = ' / '.join(month_list) year = my.year title_div.add(SpanWdg(month, css='small')) title_div.add('&middot;') title_div.add(SpanWdg(year, css='small')) if not my.task or not my.week: main_div.add('Invalid task info or undetermined week found!') return main_div main_div.add(HtmlElement.br(2)) process_div = _get_div(my.process_len) process_div.add('&nbsp;') main_div.add(process_div) for idx, weekday in enumerate(TimecardWdg.WEEK_CALENDAR): div = _get_div(50) div.add(weekday.capitalize()[0:1]) month, day, time = weekday_list[idx] div.add(SpanWdg(day, css='med')) main_div.add(div) main_div.add(HtmlElement.br()) process_div_container = _get_div(my.process_len) process = 'general' if isinstance(my.task, Task): process = my.task.get_process() process_div = FloatDivWdg(process, css='timecard_process') process_div.add_style("padding-right: 6px") process_div_container.add(process_div) main_div.add(process_div_container) # register cmd my.cmd.register_cmd("TimecardHourCmd") # query the db values timecard = Timecard.get(my.task.get_search_key(), my.week, my.year,\ login=Environment.get_user_name()) if timecard: timecard = timecard[0] # add the progress icon progress = my.cmd.generate_div() progress.add("&nbsp;") progress.add_style('width: 20px') progress.add_style('float: left') progress.set_post_ajax_script(my.get_refresh_script(show_progress=False)) process_div_container.add(progress) today_time = Date().get_struct_time() for idx, weekday in enumerate(TimecardWdg.WEEK_CALENDAR): div = _get_div(50) month, day, time = weekday_list[idx] select = ActionSelectWdg(weekday) select.add_empty_option() # disable setting time cards in the future if time > today_time: select.set_attr('disabled','') else: # using the MAX_HOUR hours = ['%0.1f'%x for x in xrange(0, TimecardWdg.MAX_HOUR + 1)] select.set_option('values', hours) if timecard: select.set_value( timecard.get_value(weekday)) my.cmd.set_option('search_key', my.task.get_search_key()) my.cmd.set_option('attr_name', weekday) my.cmd.set_option('project_code', Project.get_project_code()) select.add_event("onchange", my.cmd.get_on_script() ) div.add(select) main_div.add(div) def _get_this_week_link(my, week, year): if my.week != week: # add the today link week_name = 'week_%s' %my.task.get_search_key() year_name = 'year_%s' %my.task.get_search_key() script = ["document.form.elements['%s'].value='%s';" \ "document.form.elements['%s'].value='%s'" %(week_name, week, year_name, year)] script.append(my.get_refresh_script()) link = HtmlElement.js_href(';'.join(script), '[this week]') span = SpanWdg(link, css='small') else: span = SpanWdg('[this week]&nbsp;', css='small') span.add_style('color','#bbb') return span def add_unregistered_hours(my, main_div): '''draw the unregistered hours''' row_div = FloatDivWdg() row_div.add_style("margin-bottom: 4px") main_div.add(row_div) process_div = _get_div(my.process_len) process_div.add("unregistered hours") #process_div.add_style('color: #999') row_div.add(process_div) for i in TimecardWdg.WEEK_CALENDAR: unreg_hours = 0.0 div = _get_div(50) row_div.add(div) div.add_class('center_content') span = SpanWdg() div.add(span) span.add_style('padding: 0 6px 0 6px') max_hours = Project.get_reg_hours() if not max_hours: max_hours = TimecardWdg.MAX_REG_HOURS max_hours = float(max_hours) # get all the timecards for the week and hours reg_hours = Timecard.get_registered_hours(None, my.week, i, my.year) unreg_hours = max_hours-reg_hours if unreg_hours <= 0: my.overtime_dict[i] = abs(unreg_hours) unreg_hours = IconWdg(icon=IconWdg.GOOD) else: my.overtime_dict[i] = '' unreg_hours = str(unreg_hours) span.add(unreg_hours) def add_overtime_hours(my, main_div): '''draw the unregistered hours''' row_div = FloatDivWdg() main_div.add(row_div) process_div = _get_div(my.process_len) process_div.add("overtime hours") #process_div.add_style('color: #999') row_div.add(process_div) for i in TimecardWdg.WEEK_CALENDAR: div = _get_div(50) div.add_class('center_content') row_div.add(div) span = SpanWdg() div.add(span) span.add_style('padding: 0 6px 0 6px') hour = my.overtime_dict.get(i) if hour: span.add(hour) span.add_class('timecard_overtime') else: span.add('&nbsp;') class TimecardWdg(AjaxWdg): WEEK_CALENDAR = ["mon","tue","wed","thu","fri","sat","sun"] MAX_HOUR = 12 MAX_REG_HOURS = 10 PROCESS_WIDTH = 120 def init(my): my.task = None my.week = None my.year = None my.main_div = DivWdg() def init_cgi(my): # get the sobject keys = my.web.get_form_keys() search_key = '' for key in keys: if key.startswith('skey_TimecardWdg_'): search_key = my.web.get_form_value(key) continue if key.startswith('week_'): my.week = my.web.get_int_form_value(key) continue if key.startswith('year_'): my.year = my.web.get_int_form_value(key) continue if search_key: sobject = Search.get_by_search_key(search_key) my.task = sobject my.init_setup() def init_setup(my): '''set the ajax top and register some inputs''' div_id = 'timecard_%s' %my.task.get_id() my.main_div = DivWdg(id=div_id) my.set_ajax_top(my.main_div) # register the inputs first hidden = HiddenWdg('skey_TimecardWdg_%s' %my.task.get_id()) my.add_ajax_input(hidden) week_text = TextWdg('week_%s' %my.task.get_search_key()) my.add_ajax_input(week_text) year_text = HiddenWdg('year_%s' %my.task.get_search_key()) my.add_ajax_input(year_text) def set_task(my, task): my.task = task my.init_setup() def get_display(my): main_div = my.main_div if not my.week: today = Date() my.week = today.get_week() my.year = today.get_year() task_row = TimecardTaskRowWdg() task_row.set_task(my.task) if my.task: hidden = HiddenWdg('skey_TimecardWdg_%s' %my.task.get_id(), my.task.get_search_key()) main_div.add(hidden) else: return "There was a problem reading task data. Refresh" my._add_week(main_div, my.week, task_row) my._add_year(main_div, my.year, task_row) main_div.add(task_row) main_div.add(HtmlElement.br(2)) # draw the processing icon process_div = _get_div(1) process_div.add("&nbsp;") main_div.add(process_div) main_div.add(HtmlElement.br()) return main_div def _add_year(my, main_div, year, widget): '''add year display''' name = 'year_%s' %my.task.get_search_key() year_text = HiddenWdg(name, year) main_div.add(year_text) widget.get_cmd().add_element_name(name) def _add_week(my, main_div, week, widget): '''add week display''' week_name = 'week_%s' %my.task.get_search_key() year_name = 'year_%s' %my.task.get_search_key() weeks = [i for i in xrange(1, 53)] week_filter = SelectWdg(week_name) week_filter.add_class('med') week_filter.set_option('values', weeks) week_filter.set_value(week) #widget.add_ajax_input(week_text) # add the name to the TimecardHourCmd widget.get_cmd().add_element_name(week_name) refresh_script = widget.get_refresh_script() week_filter.add_event('onchange', refresh_script) script = [TimecardTaskRowWdg.get_script(week_name, year_name, add=False)] script.append(refresh_script) img = IconWdg(icon=IconWdg.ARROW_LEFT) link = HtmlElement.js_href(';'.join(script), data=img) div = _get_div(20) div.add(link) main_div.add(div) div = _get_div(70) div.add("Wk&nbsp;") div.add(week_filter) main_div.add(div) div = _get_div(20) script = [TimecardTaskRowWdg.get_script(week_name, year_name, add=True)] script.append(refresh_script) img = IconWdg(icon=IconWdg.ARROW_RIGHT) link = HtmlElement.js_href(';'.join(script), data=img) div.add(link) main_div.add(div) # static functions def get_process_width(task): ''' get the width for the process div depending on the length of the process''' return max(TimecardWdg.PROCESS_WIDTH, (len(task.get_process()) + 1) * 9) get_process_width = staticmethod(get_process_width) class SpecialDayWdg(TimecardWdg): def get_display(my): main_div = my.main_div if not my.week: today = Date() my.week = today.get_week() my.year = today.get_year() task_row = TimecardTaskRowWdg() task_row.set_task(my.task) hidden = HiddenWdg('skey_SpecialDayWdg_%s' %my.task.get_id(), my.task.get_search_key()) main_div.add(hidden) my._add_week(main_div, my.week, task_row) my._add_year(main_div, my.year, task_row) main_div.add(task_row) main_div.add(HtmlElement.br(2)) # draw the processing icon process_div = _get_div(1) process_div.add("&nbsp;") main_div.add(process_div) main_div.add(HtmlElement.br()) return main_div class WeekTableElement(BaseTableElementWdg): CAL_NAME = "work_date_selector" DAY_TITLE_WIDTH = 15 WEEK_TITLE_WIDTH = 80 def preprocess(my): my.hours_dict = {} def init(my): my.weekday = None my.mode = 'week' my.sel = FilterSelectWdg('time_card_mode', label='View: ') my.sel.set_option('values', 'week|day') my.prefix = "timecard_filter" def get_prefs(my): my.sel = FilterSelectWdg('time_card_mode', label='View: ') my.sel.set_option('values', 'week|day') return my.sel def get_title(my): from tactic.ui.filter import FilterData values = FilterData.get().get_values_by_index(my.prefix, 0) selected_year = '' date = None selected_date_value = values.get(my.CAL_NAME) work_date_selector = CalendarInputWdg(my.CAL_NAME) if selected_date_value: selected_date = Date(db_date=selected_date_value) else: selected_date = Date() #my.mode = my.sel.get_value() week = int(selected_date.get_week()) year = int(selected_date.get_year()) weekday_list = Calendar.get_monthday_time(year, week) div = DivWdg() if my.mode == 'day': spacer = FloatDivWdg('&nbsp;', width=my.DAY_TITLE_WIDTH) div.add(spacer) my.weekday = int(selected_date.get_weekday(is_digit=True)) month = selected_date.get_month(is_digit=False) month_div = FloatDivWdg(css='center_content') month_div.add(month) div.add_style('width: 15em') else: month_list = [] for item in weekday_list: month, day, time = item if month not in month_list: month_list.append(month) month_div = FloatDivWdg(width=my.WEEK_TITLE_WIDTH, css='right_content') month_div.add(' / '.join(month_list)) div.add_style('width: 45em') div.add(month_div) for idx, i in enumerate(TimecardWdg.WEEK_CALENDAR): if my.weekday != None and idx != my.weekday: continue total = FloatDivWdg(width=50, css='center_content') span = SpanWdg(weekday_list[idx][1]) if i in ["sat", "sun"]: span.add_style('color', '#995151') span.add(HtmlElement.br()) weekday_span = SpanWdg('%s' %i.capitalize(), css='smaller') span.add(weekday_span) total.add(span) div.add(total) return div def get_display(my): mode = my.sel.get_value() div = DivWdg() if my.mode == 'day': spacer = FloatDivWdg('&nbsp;', width=my.DAY_TITLE_WIDTH) else: spacer = FloatDivWdg('&nbsp;', width=my.WEEK_TITLE_WIDTH) div.add(spacer) timecard = my.get_current_sobject() for idx, i in enumerate(TimecardWdg.WEEK_CALENDAR): if my.weekday != None and idx != my.weekday: continue total = FloatDivWdg(width=50, css='center_content') hours = timecard.get_value(i) hours_label = hours if not hours: hours = 0 hours_label = '-' span = SpanWdg(hours_label) cur_val = my.hours_dict.get(i) if not cur_val: cur_val = 0 my.hours_dict[i] = cur_val + float(hours) total.add(span) div.add(total) return div def get_bottom_wdg(my): div = DivWdg() if my.mode == 'day': spacer = FloatDivWdg('Daily Total: ', width=my.DAY_TITLE_WIDTH, css='right_content') else: spacer = FloatDivWdg('Weekly Total: ', width=my.WEEK_TITLE_WIDTH, css='right_content') div.add(spacer) weekly_hours = 0 timecard = my.get_current_sobject() for idx, i in enumerate(TimecardWdg.WEEK_CALENDAR): if my.weekday != None and idx != my.weekday: continue total = FloatDivWdg(width=50, css='center_content') hours = my.hours_dict.get(i) hours_label = hours if not hours: hours = 0 hours_label = '-' span = SpanWdg(hours_label) weekly_hours += float(hours) if my.weekday == None: total.add(span) div.add(total) weekly_total = FloatDivWdg(width=60, css='center_content') weekly_total.add(HtmlElement.b(weekly_hours)) div.add(weekly_total) return div class TimecardCreateCmd(DatabaseAction): def __init__(my): super(TimecardCreateCmd, my).__init__() my.desc = None my.date = None my.project_code = None def get_title(my): return "TimecardCreateCmd" def check(my): my.web = WebContainer.get_web() search_type = my.sobject.get_search_type_obj() config = WidgetConfig.get_by_search_type(search_type, "insert", local_search=True) columns = config.get_element_names() if len(columns) != 3: raise TacticException('The command is expecting 3 fields only.') my.date = my.web.get_form_value('edit|%s' % columns[0]) my.desc = my.web.get_form_value('edit|%s'% columns[1]) date = Date(db_date=my.date) my.year = date.get_year() my.week = date.get_week() my.project_code = my.web.get_form_value('edit|%s'% columns[2]) if not my.desc or not my.date or not my.project_code: raise UserException('One or more fields are empty.') Project.set_project(my.project_code) return True def execute(my): cards = Timecard.get(None, week=my.week, year=my.year, \ desc=my.desc, project=my.project_code) if not cards: # this has been set in the EditCmd timecard = my.sobject timecard.set_value('login', Environment.get_user_name()) timecard.set_value('project_code', my.project_code) timecard.set_value("year", my.year) timecard.set_value("week", my.week) timecard.set_value("description", my.desc) timecard.commit() else: raise UserException('This time card already exists. '\ 'Please edit the existing one instead.') ''' deprecated class TimecardTableElement(BaseTableElementWdg): def get_title(my): # TODO: this is not the proper way to call class_init, but it is # broken now widget = Widget() init = my._class_init() widget.add(init) # have to put this here because of the broken class init WebContainer.register_cmd("TimecardCmd") div = DivWdg() week = DivWdg('Week') week.set_style("width: 50px; float: left") div.add(week) for i in ("mon","tue","wed","thu","fri","sat","sun"): total = DivWdg() total.add_style("width: 50px") total.add_style("float: left") total.add(i.capitalize()) div.add(total) ids = [ str(x.get_id()) for x in my.sobjects ] ids_str = ", ".join(ids) script = HtmlElement.script("timecard_ids = [%s]" % ids_str) widget.add(div) widget.add(script) return widget def _class_init(my): script = HtmlElement.script(""" timecard_ids = [] add = function(id) { var total = 0 var days = ["mon","tue","wed","thu","fri","sat","sun"] for ( var i = 0; i < 7; i++ ) { day = days[i] var name = "timecard|"+id+"|"+day timecard_elem = document.getElementById("timecard|"+id+"|"+day) timecard = timecard_elem.value if ( timecard == "" ) continue timecard = parseInt(timecard*10)/10 if ( isNaN(timecard) ) { alert("You must enter a number") return } total = total + timecard } total_elem = document.getElementById("timecard|total|"+id) total_elem.innerHTML = total // calculate day total for ( var i = 0; i < 7; i++ ) { day = days[i] day_total_elem = document.getElementById( "timecard|total|" + day) day_total = 0 for (j in timecard_ids) { tmp = timecard_ids[j] timecard_elem = document.getElementById("timecard|"+tmp+"|"+day) timecard = timecard_elem.value if ( timecard == "" ) continue timecard = parseInt(timecard*10)/10 day_total = day_total + timecard } day_total_elem.innerHTML = day_total } } """) #my.add(script) return script def get_display(my): sobject = my.get_current_sobject() # get the timecard object search = Search("sthpw/timecard") search.add_sobject_filter(sobject) #search.add_filter("week", week) timecard = search.get_sobject() widget = DivWdg() widget.add_style("text-align: left") widget.add(DivWdg(sobject.get_value('week'))) for i in ("mon","tue","wed","thu","fri","sat","sun"): name = "timecard|%s|%s" % (sobject.get_id(), i) hours_wdg = TextWdg("timecard|%s|%s" % (sobject.get_id(), i) ) if timecard != None: hours_wdg.set_value( timecard.get_value(i) ) div = DivWdg() div.add_style("width: 50px") div.add_style("float: left") hours_wdg.set_id(name) hours_wdg.set_attr("size", "3") hours_wdg.add_event("onchange", "add(%s)" % sobject.get_id() ) div.add( hours_wdg ) widget.add(div) name = "timecard|total|%s" % sobject.get_id() total = SpanWdg() total.add( "0" ) total.add_style("font-size: 1.2em") total.add_style("font-weight: bold") total.set_id(name) widget.add( " = " ) widget.add( total ) widget.add( " hours" ) return widget def get_bottom(my): div = DivWdg() for day in ("mon","tue","wed","thu","fri","sat","sun"): total = DivWdg() total.set_id("timecard|total|%s" % day) total.add_style("width: 50px") total.add_style("float: left") total.add_style("font-size: 1.2em") total.add_style("font-weight: bold") total.add("0") div.add(total) return div ''' class TimecardHourCmd(Callback): def __init__(my): super(TimecardHourCmd,my).__init__() my.search_key = None my.attr_name = None my.sobject = None my.value = None my.week = None my.year = None my.project_code = '' def get_title(my): return "TimecardHourCmd" def check(my): my.web = WebContainer.get_web() my.value = my.web.get_form_value('value') my.search_key = my.web.get_form_value('search_key') my.attr_name = my.web.get_form_value('attr_name') my.project_code = my.web.get_form_value('project_code') if my.project_code: Project.set_project(my.project_code) keys = my.web.get_form_keys() for key in keys: if key.startswith('week_'): my.week = my.web.get_form_value(key) continue if key.startswith('year_'): my.year = my.web.get_form_value(key) continue if not my.value or not my.attr_name or not my.week or not my.year: raise CommandExitException() return True def execute(my): if my.search_key: search_type, search_id = my.search_key.split('|') timecard = Timecard.get(my.search_key, my.week, my.year) if not timecard: timecard = my._create_timecard(search_type, search_id) else: timecard = timecard[0] timecard.set_value(my.attr_name, my.value) # set week timecard.set_value('week', my.week) # set year timecard.set_value('year', my.year) timecard.commit() sobj = Search.get_by_search_key(my.search_key) my.description = "Set timecard %shr for [%s]"%(my.value, sobj.get_code()) def _create_timecard(my, search_type, search_id): '''create an entry in the timecard table''' timecard = SObjectFactory.create("sthpw/timecard") timecard.set_value("search_type", search_type) timecard.set_value("search_id", search_id) timecard.set_value('login', Environment.get_user_name()) timecard.set_value('project_code', Project.get_project_name()) return timecard class TimecardCmd(Command): def execute(my): web = WebContainer.get_web() if web.get_form_value("Register") == "": raise CommandExitException() # hard code this to tasks for now search_type = "sthpw/task" info = {} for key in web.get_form_keys(): # filter out unwanted keys if not key.startswith("timecard|"): continue value = web.get_form_value(key) if value == "": continue tmp, search_id, col = key.split("|") if not info.has_key(search_id): info[search_id] = [] info[search_id].append( (col,value) ) for search_id, values in info.items(): timecard = SObjectFactory.create("sthpw/timecard") timecard.set_value("search_type", search_type) timecard.set_value("search_id", search_id) for value in values: timecard.set_value(value[0],value[1]) timecard.commit() class TimecardInfoTableElement(BaseTableElementWdg): ''' Info about the time card ''' def get_prefs(my): span = SpanWdg(css='med') my.select = FilterSelectWdg('timecard_view', label='View: ') my.select.set_option('values','compact|detailed') my.select.set_option('default', 'compact') span.add(my.select) return span def init(my): my.select = FilterSelectWdg('timecard_view', label='View: ') my.select.set_option('values','compact|detailed') my.select.set_option('default', 'compact') my.info_dict = {} my.is_preprocessed = False def preprocess(my): if not my.sobjects: return task_dict = {} misc_cards = [] my.info_dict = {} for timecard in my.sobjects: if timecard.get_value('search_type') == Task.SEARCH_TYPE: task_dict[timecard.get_value('search_id')] = timecard.get_id() else: misc_cards.append(timecard) tasks = Search.get_by_id(Task.SEARCH_TYPE, task_dict.keys()) if not tasks: return for task in tasks: my.info_dict[ task_dict.get(task.get_id()) ] = task # store the rest of the timecards which do not have an associated task # or have association with some other sobjects (not implemented yet) for card in misc_cards: my.info_dict[card.get_id()] = card def get_display(my): if not my.is_preprocessed: my.preprocess() my.is_preprocessed = True card = my.get_current_sobject() div = DivWdg() sobj = my.info_dict.get(card.get_id()) if isinstance(sobj, Timecard): # add basic timecard info if sobj.get_value('search_type'): # this is still valid div.add("Timecard for [%s] is not implemented yet" % sobj.get_value('search_type')) else: div.add("General") return div elif isinstance(sobj, Task): # add task info if my.select.get_value() =='detailed': return my.get_detailed(sobj) else: return my.get_compact(sobj) def get_compact(my, sobj): table = Table(css='embed') col = table.add_col() col.add_style("width: 80px") table.add_col(css='med') table.add_col(css='large') table.add_style("width: 200px") table.add_row() src_sobj = sobj.get_parent() thumb = ThumbWdg() thumb.set_icon_size(40) thumb.set_sobject(src_sobj) table.add_cell(thumb) table.add_cell(src_sobj.get_code()) table.add_data(SpanWdg(HtmlElement.b(sobj.get_process()), css='small')) #table.add_row() expand = ExpandableTextWdg() expand.set_max_length(20) desc = sobj.get_value("description") if not desc: desc = '&nbsp;' expand.set_value(desc) table.add_row_cell(expand) return table def get_detailed(my, sobj): table = Table(css='embed') table.add_style("width: 200px") col = table.add_col() col.add_style("width: 80px") table.add_col(css='large') table.add_col(css='large') src_sobj = sobj.get_parent() thumb = ThumbWdg() thumb.set_icon_size(40) thumb.set_sobject(src_sobj) table.add_row() td = table.add_cell(thumb) td.set_attr('rowspan','2') my._add_code(table, src_sobj) my._add_process(table, sobj) my._add_desc(table, sobj) return table def _add_code(my, table, sobj): table.add_cell(HtmlElement.i("%s Code: " % sobj.get_search_type_obj().get_title())) table.add_cell( HtmlElement.b(sobj.get_code())) def _add_process(my, table, sobj): table.add_row() table.add_cell(HtmlElement.i("Process: ")) table.add_cell( sobj.get_value("process") ) def _add_desc(my, table, sobj): tr = table.add_row() #tr.set_attr('colspan', '3') table.add_cell(HtmlElement.i("Desc: ")) expand = ExpandableTextWdg() expand.set_max_length(40) desc = sobj.get_value("description") if not desc: desc = '&nbsp;' expand.set_value(desc) td = table.add_cell( expand ) td.set_attr('colspan', '2') class WeekHourInputWdg(CustomInfoInputWdg): def preprocess(my): sobject = my.get_current_sobject() my.day_list = [] if sobject: year = sobject.get_value('year') week = sobject.get_value('week') if year and week: my.day_list = Calendar.get_monthday_time(year, week) def process_widget(my, idx, widget, sobject): ''' process each widget in the CustomInfoInputWdg''' if not my.day_list: return today = Date() month, day, time = my.day_list[idx] if time > today.get_struct_time(): widget.set_attr('readonly', 'readonly') widget.add_class('disabled') """ class MilestoneTableElement(BaseTableElementWdg): TRIGGER = "set_milestone" CMD_INPUT = "milestone_cmd" BID_START_DATE = "bid_start_date" BID_END_DATE = "bid_end_date" ACTUAL_START_DATE = "actual_start_date" ACTUAL_END_DATE = "actual_end_date" def init(my): WebContainer.register_cmd("pyasm.widget.MilestoneSetCmd") def get_title(my): wdg = IconSubmitWdg(my.TRIGGER, icon=IconWdg.TABLE_UPDATE_ENTRY, long=True) wdg.set_text("Set Milestone") return wdg def get_input(my): return Container.get("MilestoneTableElement:" + my.CMD_INPUT) def store_input(my, value): hidden = my.get_input() if not hidden: Container.put("MilestoneTableElement:" + my.CMD_INPUT, [value]) else: hidden.append(value) def get_display(my): table = Table() table.add_row() current_sobject = my.get_current_sobject() start_select = CalendarWdg(name=my.ACTUAL_START_DATE, id="%s|%s,%s" \ % (my.name, my.ACTUAL_START_DATE, current_sobject.get_search_key() )) start_select.set_sobject(current_sobject) my.store_input(start_select.get_id()) table.add_cell("Start: ") td = table.add_cell(start_select) td.add_style('white-space','nowrap') table.add_row() end_select = CalendarWdg(name=my.ACTUAL_END_DATE, id="%s|%s,%s" \ % (my.name, my.ACTUAL_END_DATE, current_sobject.get_search_key() )) end_select.set_sobject(current_sobject) my.store_input(end_select.get_id()) td2 = table.add_cell("End: ") td2.add_style('white-space','nowrap') widget = Widget() widget.add(end_select) table.add_cell(widget) # store all the input names in one hidden input if my.get_current_index() == len(my.sobjects) - 1: hidden_wdg = HiddenWdg(my.CMD_INPUT, ':'.join(my.get_input()) ) widget.add(hidden_wdg) return table class MilestoneWdg(Widget): def get_display(my): pipeline = Pipeline.get_by_name("shot") processes = pipeline.get_process_names() # get the users search = Search("sthpw/login") users = search.get_sobjects() user_labels = [user.get_full_name() for user in users] user_values = [user.get_value("login") for user in users] table = Table() table.set_style("minimal") table.add_row() table.add_header("Process") table.add_header("Artist") table.add_header("Start Date") table.add_header("End Date") for process in processes: table.add_row() table.add_cell(process) user_select = SelectWdg("%s|user" % process ) user_select.set_option("values", user_values) user_select.set_option("labels", user_labels) user_select.add_empty_option() table.add_cell(user_select) start_select = CalendarWdg("%s|start_select" % process ) end_select = CalendarWdg("%s|end_select" % process ) table.add_cell(start_select) table.add_cell(end_select) return table class MilestoneSetCmd(Command): NONE_VAL = '__NONE__' def get_title(my): return MilestoneTableElement.TRIGGER def check(my): web = WebContainer.get_web() if web.get_form_value(MilestoneTableElement.TRIGGER) != "": return True def execute(my): web = WebContainer.get_web() # get the input names input_names = web.get_form_value(MilestoneTableElement.CMD_INPUT).split(':') for input_name in input_names: value = web.get_form_value(input_name) if value != my.NONE_VAL: if MilestoneTableElement.ACTUAL_START_DATE in input_name: my.store(input_name.split(',')[1], 'actual_start_date', \ web.get_form_value(input_name)) elif MilestoneTableElement.ACTUAL_END_DATE in input_name: my.store(input_name.split(',')[1], 'actual_end_date', \ web.get_form_value(input_name)) def store(my, key, column, value): ''' commit the values ''' sobject = Search.get_by_search_key(key) sobject.set_value(column, value ) update_column = 'timestamp' sobject.set_value(update_column, Sql.get_timestamp_now(), quoted=False) sobject.commit() """
epl-1.0
[ 26207, 5680, 199, 3, 199, 3, 1898, 334, 67, 9, 11811, 12, 23150, 387, 87, 21580, 199, 3, 9326, 2900, 5924, 5702, 199, 3, 199, 3, 3611, 20076, 775, 4392, 1621, 18623, 14, 221, 961, 2032, 365, 557, 1359, 386, 695, 370, 199, 3, 23150, 387, 87, 21580, 12, 436, 365, 440, 370, 506, 9172, 68, 12, 29818, 12, 199, 3, 503, 4339, 320, 939, 315, 1263, 4340, 1928, 5313, 4983, 14, 199, 3, 199, 3, 199, 3, 199, 199, 3, 363, 452, 363, 275, 359, 283, 45, 18072, 3186, 2162, 297, 221, 199, 3, 259, 283, 45, 18072, 21700, 297, 283, 45, 18072, 1084, 7874, 418, 199, 363, 452, 363, 275, 788, 1366, 5841, 21700, 297, 283, 1366, 5841, 24246, 7874, 297, 283, 1366, 5841, 4476, 5810, 21700, 297, 881, 283, 1366, 5841, 7874, 1673, 1366, 5841, 2499, 7874, 297, 268, 283, 12246, 12631, 21700, 297, 283, 20995, 3186, 2162, 297, 283, 1366, 5841, 2354, 3186, 2162, 297, 221, 268, 283, 20995, 24246, 3205, 21700, 418, 1467, 199, 199, 504, 1134, 11374, 14, 1531, 492, 5817, 12, 5817, 6699, 1726, 12, 8692, 3310, 199, 504, 1134, 11374, 14, 1733, 492, 8730, 12, 428, 8634, 12, 428, 1692, 12, 428, 1710, 199, 504, 1134, 11374, 14, 66, 565, 492, 19090, 12, 4703, 5841, 12, 7290, 12, 8495, 199, 504, 1134, 11374, 14, 2520, 492, 627, 199, 504, 1134, 11374, 14, 3440, 492, 473, 388, 17187, 21700, 12, 26401, 21700, 12, 16905, 2028, 12, 869, 442, 21700, 12, 18890, 461, 1872, 21700, 12, 27779, 3205, 21700, 199, 504, 1134, 11374, 14, 2330, 492, 627, 199, 504, 1324, 63, 2989, 71, 492, 4516, 21700, 12, 27779, 21700, 12, 9496, 21700, 12, 10033, 5446, 21700, 12, 9388, 5446, 21700, 199, 504, 1817, 63, 2108, 63, 2989, 71, 492, 3523, 3186, 2162, 21700, 199, 504, 7016, 63, 2989, 71, 492, 473, 388, 21700, 199, 504, 570, 63, 2989, 71, 492, 3868, 4295, 21700, 199, 504, 3537, 63, 815, 63, 2989, 71, 492, 8388, 2354, 3205, 21700, 199, 199, 318, 485, 362, 63, 3015, 8, 2063, 304, 272, 1449, 2951, 370, 664, 282, 9073, 370, 5954, 642, 3938, 1449, 272, 372, 11140, 24305, 21700, 8, 2063, 29, 2063, 9, 1362, 199, 533, 4703, 5841, 4476, 5810, 21700, 8, 33, 15863, 21700, 304, 339, 347, 4205, 8, 1662, 304, 267, 1449, 2536, 6491, 282, 9284, 2860, 1449, 4960, 11168, 275, 6148, 342, 267, 3002, 14, 6419, 275, 1109, 8, 8136, 14, 362, 63, 6419, 1012, 881, 267, 3002, 14, 3403, 275, 1109, 8, 8136, 14, 362, 63, 3403, 1012, 267, 3002, 14, 1412, 63, 552, 275, 378, 267, 3002, 14, 6419, 63, 2108, 63, 354, 275, 2125, 267, 3002, 14, 3403, 63, 2108, 63, 354, 275, 2125, 267, 3002, 14, 1765, 275, 488, 267, 3002, 14, 1760, 275, 488, 267, 3002, 14, 1883, 521, 63, 807, 275, 1052, 268, 2286, 347, 4205, 63, 13814, 8, 1662, 304, 267, 327, 664, 314, 308, 785, 267, 2883, 275, 3002, 14, 2520, 14, 362, 63, 964, 63, 1612, 342, 267, 2754, 63, 498, 275, 2125, 2728, 367, 790, 315, 2883, 26, 288, 340, 790, 14, 2460, 360, 83, 498, 63, 1366, 5841, 21700, 25865, 355, 2754, 63, 498, 275, 3002, 14, 2520, 14, 362, 63, 964, 63, 585, 8, 498, 9, 355, 1980, 288, 340, 790, 14, 2460, 360, 6419, 25865, 355, 3002, 14, 6419, 63, 2108, 63, 354, 275, 790, 355, 3002, 14, 6419, 275, 3002, 14, 2520, 14, 362, 63, 442, 63, 964, 63, 585, 8, 498, 9, 355, 1980, 288, 340, 790, 14, 2460, 360, 3403, 25865, 355, 3002, 14, 3403, 63, 2108, 63, 354, 275, 790, 355, 3002, 14, 3403, 275, 3002, 14, 2520, 14, 362, 63, 442, 63, 964, 63, 585, 8, 498, 9, 355, 1980, 267, 340, 2754, 63, 498, 26, 288, 308, 785, 275, 8730, 14, 362, 63, 991, 63, 1733, 63, 498, 8, 1733, 63, 498, 9, 288, 3002, 14, 1765, 275, 308, 785, 7846, 3002, 14, 826, 63, 2758, 342, 268, 27180, 3002, 14, 525, 63, 3711, 342, 267, 272, 347, 1050, 63, 3711, 8, 1662, 304, 267, 1449, 2274, 314, 4153, 1449, 267, 340, 440, 3002, 14, 1765, 26, 288, 372, 267, 8752, 275, 26401, 21700, 360, 83, 498, 63, 1366, 5841, 21700, 4970, 83, 7, 450, 1662, 14, 1765, 14, 362, 63, 344, 1012, 267, 3002, 14, 525, 63, 12774, 63, 1210, 8, 5642, 9, 2728, 8620, 63, 505, 275, 4516, 21700, 360, 6419, 4970, 83, 7, 450, 1662, 14, 1765, 14, 362, 63, 1733, 63, 498, 1012, 267, 3002, 14, 525, 63, 12774, 63, 1210, 8, 6419, 63, 505, 9, 24807, 5361, 63, 505, 275, 26401, 21700, 360, 3403, 4970, 83, 7, 450, 1662, 14, 1765, 14, 362, 63, 1733, 63, 498, 1012, 267, 3002, 14, 525, 63, 12774, 63, 1210, 8, 3403, 63, 505, 9, 4960, 272, 347, 4205, 63, 2758, 8, 1662, 304, 267, 1449, 663, 1536, 314, 25930, 2746, 436, 314, 25930, 1414, 1449, 267, 9073, 63, 344, 275, 283, 973, 63, 3015, 63, 10706, 7, 267, 2088, 63, 344, 275, 283, 915, 63, 10706, 7, 398, 340, 3002, 14, 1765, 26, 288, 9073, 63, 344, 275, 283, 973, 63, 3015, 4970, 83, 7, 450, 1662, 14, 1765, 14, 362, 63, 344, 342, 288, 2088, 63, 344, 275, 283, 915, 4970, 83, 7, 450, 1662, 14, 1765, 14, 362, 63, 344, 342, 10631, 3002, 14, 973, 63, 3015, 275, 32077, 21700, 8, 344, 29, 3015, 63, 344, 9, 267, 3002, 14, 409, 63, 12774, 63, 2119, 8, 1662, 14, 973, 63, 3015, 9, 2728, 3002, 14, 1760, 275, 437, 15863, 7874, 8, 1760, 63, 344, 9, 267, 3002, 14, 1760, 14, 525, 63, 2108, 63, 354, 8, 1662, 14, 6419, 63, 2108, 63, 354, 9, 4960, 3002, 14, 1760, 14, 525, 63, 2108, 63, 354, 8, 1662, 14, 3403, 63, 2108, 63, 354, 9, 221, 268, 339, 347, 663, 63, 1765, 8, 1662, 12, 2120, 304, 267, 3002, 14, 1765, 275, 2120, 267, 3002, 14, 826, 63, 2758, 342, 267, 272, 347, 664, 63, 1760, 8, 1662, 304, 267, 372, 3002, 14, 1760, 5493, 347, 664, 63, 1579, 8, 6419, 63, 354, 12, 5361, 63, 354, 12, 1050 ]
[ 5680, 199, 3, 199, 3, 1898, 334, 67, 9, 11811, 12, 23150, 387, 87, 21580, 199, 3, 9326, 2900, 5924, 5702, 199, 3, 199, 3, 3611, 20076, 775, 4392, 1621, 18623, 14, 221, 961, 2032, 365, 557, 1359, 386, 695, 370, 199, 3, 23150, 387, 87, 21580, 12, 436, 365, 440, 370, 506, 9172, 68, 12, 29818, 12, 199, 3, 503, 4339, 320, 939, 315, 1263, 4340, 1928, 5313, 4983, 14, 199, 3, 199, 3, 199, 3, 199, 199, 3, 363, 452, 363, 275, 359, 283, 45, 18072, 3186, 2162, 297, 221, 199, 3, 259, 283, 45, 18072, 21700, 297, 283, 45, 18072, 1084, 7874, 418, 199, 363, 452, 363, 275, 788, 1366, 5841, 21700, 297, 283, 1366, 5841, 24246, 7874, 297, 283, 1366, 5841, 4476, 5810, 21700, 297, 881, 283, 1366, 5841, 7874, 1673, 1366, 5841, 2499, 7874, 297, 268, 283, 12246, 12631, 21700, 297, 283, 20995, 3186, 2162, 297, 283, 1366, 5841, 2354, 3186, 2162, 297, 221, 268, 283, 20995, 24246, 3205, 21700, 418, 1467, 199, 199, 504, 1134, 11374, 14, 1531, 492, 5817, 12, 5817, 6699, 1726, 12, 8692, 3310, 199, 504, 1134, 11374, 14, 1733, 492, 8730, 12, 428, 8634, 12, 428, 1692, 12, 428, 1710, 199, 504, 1134, 11374, 14, 66, 565, 492, 19090, 12, 4703, 5841, 12, 7290, 12, 8495, 199, 504, 1134, 11374, 14, 2520, 492, 627, 199, 504, 1134, 11374, 14, 3440, 492, 473, 388, 17187, 21700, 12, 26401, 21700, 12, 16905, 2028, 12, 869, 442, 21700, 12, 18890, 461, 1872, 21700, 12, 27779, 3205, 21700, 199, 504, 1134, 11374, 14, 2330, 492, 627, 199, 504, 1324, 63, 2989, 71, 492, 4516, 21700, 12, 27779, 21700, 12, 9496, 21700, 12, 10033, 5446, 21700, 12, 9388, 5446, 21700, 199, 504, 1817, 63, 2108, 63, 2989, 71, 492, 3523, 3186, 2162, 21700, 199, 504, 7016, 63, 2989, 71, 492, 473, 388, 21700, 199, 504, 570, 63, 2989, 71, 492, 3868, 4295, 21700, 199, 504, 3537, 63, 815, 63, 2989, 71, 492, 8388, 2354, 3205, 21700, 199, 199, 318, 485, 362, 63, 3015, 8, 2063, 304, 272, 1449, 2951, 370, 664, 282, 9073, 370, 5954, 642, 3938, 1449, 272, 372, 11140, 24305, 21700, 8, 2063, 29, 2063, 9, 1362, 199, 533, 4703, 5841, 4476, 5810, 21700, 8, 33, 15863, 21700, 304, 339, 347, 4205, 8, 1662, 304, 267, 1449, 2536, 6491, 282, 9284, 2860, 1449, 4960, 11168, 275, 6148, 342, 267, 3002, 14, 6419, 275, 1109, 8, 8136, 14, 362, 63, 6419, 1012, 881, 267, 3002, 14, 3403, 275, 1109, 8, 8136, 14, 362, 63, 3403, 1012, 267, 3002, 14, 1412, 63, 552, 275, 378, 267, 3002, 14, 6419, 63, 2108, 63, 354, 275, 2125, 267, 3002, 14, 3403, 63, 2108, 63, 354, 275, 2125, 267, 3002, 14, 1765, 275, 488, 267, 3002, 14, 1760, 275, 488, 267, 3002, 14, 1883, 521, 63, 807, 275, 1052, 268, 2286, 347, 4205, 63, 13814, 8, 1662, 304, 267, 327, 664, 314, 308, 785, 267, 2883, 275, 3002, 14, 2520, 14, 362, 63, 964, 63, 1612, 342, 267, 2754, 63, 498, 275, 2125, 2728, 367, 790, 315, 2883, 26, 288, 340, 790, 14, 2460, 360, 83, 498, 63, 1366, 5841, 21700, 25865, 355, 2754, 63, 498, 275, 3002, 14, 2520, 14, 362, 63, 964, 63, 585, 8, 498, 9, 355, 1980, 288, 340, 790, 14, 2460, 360, 6419, 25865, 355, 3002, 14, 6419, 63, 2108, 63, 354, 275, 790, 355, 3002, 14, 6419, 275, 3002, 14, 2520, 14, 362, 63, 442, 63, 964, 63, 585, 8, 498, 9, 355, 1980, 288, 340, 790, 14, 2460, 360, 3403, 25865, 355, 3002, 14, 3403, 63, 2108, 63, 354, 275, 790, 355, 3002, 14, 3403, 275, 3002, 14, 2520, 14, 362, 63, 442, 63, 964, 63, 585, 8, 498, 9, 355, 1980, 267, 340, 2754, 63, 498, 26, 288, 308, 785, 275, 8730, 14, 362, 63, 991, 63, 1733, 63, 498, 8, 1733, 63, 498, 9, 288, 3002, 14, 1765, 275, 308, 785, 7846, 3002, 14, 826, 63, 2758, 342, 268, 27180, 3002, 14, 525, 63, 3711, 342, 267, 272, 347, 1050, 63, 3711, 8, 1662, 304, 267, 1449, 2274, 314, 4153, 1449, 267, 340, 440, 3002, 14, 1765, 26, 288, 372, 267, 8752, 275, 26401, 21700, 360, 83, 498, 63, 1366, 5841, 21700, 4970, 83, 7, 450, 1662, 14, 1765, 14, 362, 63, 344, 1012, 267, 3002, 14, 525, 63, 12774, 63, 1210, 8, 5642, 9, 2728, 8620, 63, 505, 275, 4516, 21700, 360, 6419, 4970, 83, 7, 450, 1662, 14, 1765, 14, 362, 63, 1733, 63, 498, 1012, 267, 3002, 14, 525, 63, 12774, 63, 1210, 8, 6419, 63, 505, 9, 24807, 5361, 63, 505, 275, 26401, 21700, 360, 3403, 4970, 83, 7, 450, 1662, 14, 1765, 14, 362, 63, 1733, 63, 498, 1012, 267, 3002, 14, 525, 63, 12774, 63, 1210, 8, 3403, 63, 505, 9, 4960, 272, 347, 4205, 63, 2758, 8, 1662, 304, 267, 1449, 663, 1536, 314, 25930, 2746, 436, 314, 25930, 1414, 1449, 267, 9073, 63, 344, 275, 283, 973, 63, 3015, 63, 10706, 7, 267, 2088, 63, 344, 275, 283, 915, 63, 10706, 7, 398, 340, 3002, 14, 1765, 26, 288, 9073, 63, 344, 275, 283, 973, 63, 3015, 4970, 83, 7, 450, 1662, 14, 1765, 14, 362, 63, 344, 342, 288, 2088, 63, 344, 275, 283, 915, 4970, 83, 7, 450, 1662, 14, 1765, 14, 362, 63, 344, 342, 10631, 3002, 14, 973, 63, 3015, 275, 32077, 21700, 8, 344, 29, 3015, 63, 344, 9, 267, 3002, 14, 409, 63, 12774, 63, 2119, 8, 1662, 14, 973, 63, 3015, 9, 2728, 3002, 14, 1760, 275, 437, 15863, 7874, 8, 1760, 63, 344, 9, 267, 3002, 14, 1760, 14, 525, 63, 2108, 63, 354, 8, 1662, 14, 6419, 63, 2108, 63, 354, 9, 4960, 3002, 14, 1760, 14, 525, 63, 2108, 63, 354, 8, 1662, 14, 3403, 63, 2108, 63, 354, 9, 221, 268, 339, 347, 663, 63, 1765, 8, 1662, 12, 2120, 304, 267, 3002, 14, 1765, 275, 2120, 267, 3002, 14, 826, 63, 2758, 342, 267, 272, 347, 664, 63, 1760, 8, 1662, 304, 267, 372, 3002, 14, 1760, 5493, 347, 664, 63, 1579, 8, 6419, 63, 354, 12, 5361, 63, 354, 12, 1050, 0 ]
[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]
PostTenebrasLab/DrinkingBuddyServer
drinkingBuddyDB_declarative.py
1
3467
#!/usr/bin/python3 import os import sys from sqlalchemy import Column, ForeignKey, Integer, String, DateTime, Boolean from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relationship from sqlalchemy import create_engine from marshmallow import Schema, fields from flask_sqlalchemy import SQLAlchemy from flask_marshmallow import Marshmallow Base = declarative_base() class Category(Base): __tablename__ = 'categories' id = Column(Integer, primary_key=True) name = Column(String(50), nullable=False) class Terminal(Base): __tablename__ = 'terminals' id = Column(Integer, primary_key=True) name = Column(String(50), nullable=False) key = Column(String(64), nullable=False) class Functionality(Base): __tablename__ = 'functionalities' id = Column(Integer, primary_key=True) category_id = Column(Integer, ForeignKey('categories.id')) category = relationship(Category) terminal_id = Column(Integer, ForeignKey('terminals.id')) terminal = relationship(Terminal) class Item(Base): __tablename__ = 'items' id = Column(Integer, primary_key=True) name = Column(String(50), nullable=False) quantity = Column(Integer) minquantity = Column(Integer) price = Column(Integer) barcode = Column(String(32), nullable=True) pictureURL = Column(String(512), nullable=True) category_id = Column(Integer, ForeignKey('categories.id')) category = relationship(Category) class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String(50)) balance = Column(Integer) type = Column(Integer) class Card(Base): __tablename__ = 'cards' id = Column(Integer, primary_key=True) user_id = Column(Integer, ForeignKey('users.id')) user = relationship(User) class Locker(Base): __tablename__ = 'locker' id = Column(Integer, primary_key=True) user_id = Column(Integer, ForeignKey('users.id')) user = relationship(User) class Transaction(Base): __tablename__ = 'transactions' id = Column(Integer, primary_key=True) date = Column(DateTime) value = Column(Integer) user_id = Column(Integer, ForeignKey('users.id')) user = relationship(User) class TransactionItem(Base): __tablename__ = 'transaction_items' id = Column(Integer, primary_key=True) date = Column(DateTime) quantity = Column(Integer) price_per_item = Column(Integer) canceled = Column(Boolean, default=False) canceled_date = Column(DateTime) element_id = Column(Integer, ForeignKey('items.id')) element = relationship(Item) transaction_id = Column(Integer, ForeignKey('transactions.id')) transaction = relationship(Transaction) class UserSchema(Schema): class Meta: fields = ("id", "name", "balance") class ItemSchema(Schema): class Meta: fields = ("id", "name") class TransactionItemSchema(Schema): element = fields.Nested(ItemSchema) class Meta: fields = ("id", "date", "value", "element_id", "element") class TransactionSchema(Schema): user = fields.Nested(UserSchema) transactionItems = fields.Nested(TransactionItemSchema, many=True) class Meta: fields = ("id", "date", "value", "user_id", "user", "transactionItems") # Create Database # engine = create_engine("sqlite:///db.db", echo=True) # Base.metadata.create_all(engine)
mit
[ 3381, 2647, 15, 1393, 15, 1548, 19, 199, 199, 646, 747, 199, 646, 984, 199, 504, 8335, 492, 4996, 12, 12718, 12, 7225, 12, 2624, 12, 13686, 12, 9411, 199, 504, 8335, 14, 832, 14, 12164, 1905, 492, 30191, 63, 1095, 199, 504, 8335, 14, 1025, 492, 8931, 199, 504, 8335, 492, 1218, 63, 3908, 199, 504, 7557, 609, 2174, 674, 492, 13268, 12, 1504, 199, 504, 7209, 63, 14536, 492, 14303, 199, 504, 7209, 63, 28128, 2174, 674, 492, 16794, 609, 2174, 674, 199, 199, 1563, 275, 30191, 63, 1095, 342, 421, 199, 533, 13573, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 8906, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 536, 275, 4996, 8, 1558, 8, 1400, 395, 7854, 29, 797, 9, 421, 199, 533, 20429, 279, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 24322, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 536, 275, 4996, 8, 1558, 8, 1400, 395, 7854, 29, 797, 9, 272, 790, 275, 4996, 8, 1558, 8, 772, 395, 7854, 29, 797, 9, 421, 199, 533, 6801, 6712, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 1593, 10874, 1417, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 4637, 63, 344, 275, 4996, 8, 2674, 12, 12718, 360, 8906, 14, 344, 1333, 272, 4637, 275, 8931, 8, 7841, 9, 272, 11167, 63, 344, 275, 4996, 8, 2674, 12, 12718, 360, 24322, 14, 344, 1333, 272, 11167, 275, 8931, 8, 22015, 9, 421, 199, 533, 7020, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 1744, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 536, 275, 4996, 8, 1558, 8, 1400, 395, 7854, 29, 797, 9, 272, 12524, 275, 4996, 8, 2674, 9, 272, 1748, 10577, 275, 4996, 8, 2674, 9, 272, 8033, 275, 4996, 8, 2674, 9, 272, 24323, 275, 4996, 8, 1558, 8, 708, 395, 7854, 29, 549, 9, 272, 24945, 2632, 275, 4996, 8, 1558, 8, 7736, 395, 7854, 29, 549, 9, 272, 4637, 63, 344, 275, 4996, 8, 2674, 12, 12718, 360, 8906, 14, 344, 1333, 272, 4637, 275, 8931, 8, 7841, 9, 421, 199, 533, 2876, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 3707, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 536, 275, 4996, 8, 1558, 8, 1400, 430, 272, 14094, 275, 4996, 8, 2674, 9, 272, 730, 275, 4996, 8, 2674, 9, 421, 199, 533, 445, 1005, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 13761, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 922, 63, 344, 275, 4996, 8, 2674, 12, 12718, 360, 3707, 14, 344, 1333, 272, 922, 275, 8931, 8, 1899, 9, 199, 199, 533, 491, 6309, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 831, 281, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 922, 63, 344, 275, 4996, 8, 2674, 12, 12718, 360, 3707, 14, 344, 1333, 272, 922, 275, 8931, 8, 1899, 9, 199, 199, 533, 18244, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 13754, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 1434, 275, 4996, 8, 3926, 9, 272, 574, 275, 4996, 8, 2674, 9, 272, 922, 63, 344, 275, 4996, 8, 2674, 12, 12718, 360, 3707, 14, 344, 1333, 272, 922, 275, 8931, 8, 1899, 9, 421, 199, 533, 18244, 2081, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 5945, 63, 1744, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 1434, 275, 4996, 8, 3926, 9, 272, 12524, 275, 4996, 8, 2674, 9, 272, 8033, 63, 529, 63, 1053, 275, 4996, 8, 2674, 9, 272, 286, 18959, 275, 4996, 8, 4082, 12, 849, 29, 797, 9, 272, 286, 18959, 63, 602, 275, 4996, 8, 3926, 9, 272, 1819, 63, 344, 275, 4996, 8, 2674, 12, 12718, 360, 1744, 14, 344, 1333, 272, 1819, 275, 8931, 8, 2081, 9, 272, 6008, 63, 344, 275, 4996, 8, 2674, 12, 12718, 360, 13754, 14, 344, 1333, 272, 6008, 275, 8931, 8, 10161, 9, 421, 199, 533, 2876, 6700, 8, 6700, 304, 398, 1021, 6288, 26, 355, 1504, 275, 1689, 344, 401, 298, 354, 401, 298, 7358, 531, 421, 199, 533, 7020, 6700, 8, 6700, 304, 398, 1021, 6288, 26, 355, 1504, 275, 1689, 344, 401, 298, 354, 531, 421, 199, 533, 18244, 2081, 6700, 8, 6700, 304, 272, 1819, 275, 1504, 14, 13029, 8, 2081, 6700, 9, 339, 1021, 6288, 26, 267, 1504, 275, 1689, 344, 401, 298, 602, 401, 298, 585, 401, 298, 2108, 63, 344, 401, 298, 2108, 531, 421, 199, 533, 18244, 6700, 8, 6700, 304, 267, 922, 275, 1504, 14, 13029, 8, 1899, 6700, 9, 267, 6008, 7412, 275, 1504, 14, 13029, 8, 10161, 2081, 6700, 12, 5002, 29, 549, 9, 398, 1021, 6288, 26, 355, 1504, 275, 1689, 344, 401, 298, 602, 401, 298, 585, 401, 298, 751, 63, 344, 401, 298, 751, 401, 298, 5945, 7412, 531, 199, 199, 3, 2790, 8692, 199, 3, 6869, 275, 1218, 63, 3908, 480, 10659, 24436, 697, 14, 697, 401, 11343, 29, 549, 9, 199, 3, 3523, 14, 2343, 14, 981, 63, 452, 8, 3908, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1548, 19, 199, 199, 646, 747, 199, 646, 984, 199, 504, 8335, 492, 4996, 12, 12718, 12, 7225, 12, 2624, 12, 13686, 12, 9411, 199, 504, 8335, 14, 832, 14, 12164, 1905, 492, 30191, 63, 1095, 199, 504, 8335, 14, 1025, 492, 8931, 199, 504, 8335, 492, 1218, 63, 3908, 199, 504, 7557, 609, 2174, 674, 492, 13268, 12, 1504, 199, 504, 7209, 63, 14536, 492, 14303, 199, 504, 7209, 63, 28128, 2174, 674, 492, 16794, 609, 2174, 674, 199, 199, 1563, 275, 30191, 63, 1095, 342, 421, 199, 533, 13573, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 8906, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 536, 275, 4996, 8, 1558, 8, 1400, 395, 7854, 29, 797, 9, 421, 199, 533, 20429, 279, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 24322, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 536, 275, 4996, 8, 1558, 8, 1400, 395, 7854, 29, 797, 9, 272, 790, 275, 4996, 8, 1558, 8, 772, 395, 7854, 29, 797, 9, 421, 199, 533, 6801, 6712, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 1593, 10874, 1417, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 4637, 63, 344, 275, 4996, 8, 2674, 12, 12718, 360, 8906, 14, 344, 1333, 272, 4637, 275, 8931, 8, 7841, 9, 272, 11167, 63, 344, 275, 4996, 8, 2674, 12, 12718, 360, 24322, 14, 344, 1333, 272, 11167, 275, 8931, 8, 22015, 9, 421, 199, 533, 7020, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 1744, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 536, 275, 4996, 8, 1558, 8, 1400, 395, 7854, 29, 797, 9, 272, 12524, 275, 4996, 8, 2674, 9, 272, 1748, 10577, 275, 4996, 8, 2674, 9, 272, 8033, 275, 4996, 8, 2674, 9, 272, 24323, 275, 4996, 8, 1558, 8, 708, 395, 7854, 29, 549, 9, 272, 24945, 2632, 275, 4996, 8, 1558, 8, 7736, 395, 7854, 29, 549, 9, 272, 4637, 63, 344, 275, 4996, 8, 2674, 12, 12718, 360, 8906, 14, 344, 1333, 272, 4637, 275, 8931, 8, 7841, 9, 421, 199, 533, 2876, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 3707, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 536, 275, 4996, 8, 1558, 8, 1400, 430, 272, 14094, 275, 4996, 8, 2674, 9, 272, 730, 275, 4996, 8, 2674, 9, 421, 199, 533, 445, 1005, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 13761, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 922, 63, 344, 275, 4996, 8, 2674, 12, 12718, 360, 3707, 14, 344, 1333, 272, 922, 275, 8931, 8, 1899, 9, 199, 199, 533, 491, 6309, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 831, 281, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 922, 63, 344, 275, 4996, 8, 2674, 12, 12718, 360, 3707, 14, 344, 1333, 272, 922, 275, 8931, 8, 1899, 9, 199, 199, 533, 18244, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 13754, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 1434, 275, 4996, 8, 3926, 9, 272, 574, 275, 4996, 8, 2674, 9, 272, 922, 63, 344, 275, 4996, 8, 2674, 12, 12718, 360, 3707, 14, 344, 1333, 272, 922, 275, 8931, 8, 1899, 9, 421, 199, 533, 18244, 2081, 8, 1563, 304, 272, 636, 10983, 363, 275, 283, 5945, 63, 1744, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 1434, 275, 4996, 8, 3926, 9, 272, 12524, 275, 4996, 8, 2674, 9, 272, 8033, 63, 529, 63, 1053, 275, 4996, 8, 2674, 9, 272, 286, 18959, 275, 4996, 8, 4082, 12, 849, 29, 797, 9, 272, 286, 18959, 63, 602, 275, 4996, 8, 3926, 9, 272, 1819, 63, 344, 275, 4996, 8, 2674, 12, 12718, 360, 1744, 14, 344, 1333, 272, 1819, 275, 8931, 8, 2081, 9, 272, 6008, 63, 344, 275, 4996, 8, 2674, 12, 12718, 360, 13754, 14, 344, 1333, 272, 6008, 275, 8931, 8, 10161, 9, 421, 199, 533, 2876, 6700, 8, 6700, 304, 398, 1021, 6288, 26, 355, 1504, 275, 1689, 344, 401, 298, 354, 401, 298, 7358, 531, 421, 199, 533, 7020, 6700, 8, 6700, 304, 398, 1021, 6288, 26, 355, 1504, 275, 1689, 344, 401, 298, 354, 531, 421, 199, 533, 18244, 2081, 6700, 8, 6700, 304, 272, 1819, 275, 1504, 14, 13029, 8, 2081, 6700, 9, 339, 1021, 6288, 26, 267, 1504, 275, 1689, 344, 401, 298, 602, 401, 298, 585, 401, 298, 2108, 63, 344, 401, 298, 2108, 531, 421, 199, 533, 18244, 6700, 8, 6700, 304, 267, 922, 275, 1504, 14, 13029, 8, 1899, 6700, 9, 267, 6008, 7412, 275, 1504, 14, 13029, 8, 10161, 2081, 6700, 12, 5002, 29, 549, 9, 398, 1021, 6288, 26, 355, 1504, 275, 1689, 344, 401, 298, 602, 401, 298, 585, 401, 298, 751, 63, 344, 401, 298, 751, 401, 298, 5945, 7412, 531, 199, 199, 3, 2790, 8692, 199, 3, 6869, 275, 1218, 63, 3908, 480, 10659, 24436, 697, 14, 697, 401, 11343, 29, 549, 9, 199, 3, 3523, 14, 2343, 14, 981, 63, 452, 8, 3908, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
tragiclifestories/django
tests/auth_tests/models/invalid_models.py
251
1340
from django.contrib.auth.models import AbstractBaseUser, UserManager from django.db import models class CustomUserNonUniqueUsername(AbstractBaseUser): """ A user with a non-unique username. This model is not invalid if it is used with a custom authentication backend which supports non-unique usernames. """ username = models.CharField(max_length=30) email = models.EmailField(blank=True) is_staff = models.BooleanField(default=False) is_superuser = models.BooleanField(default=False) USERNAME_FIELD = 'username' REQUIRED_FIELDS = ['email'] objects = UserManager() class Meta: app_label = 'auth' class CustomUserNonListRequiredFields(AbstractBaseUser): "A user with a non-list REQUIRED_FIELDS" username = models.CharField(max_length=30, unique=True) date_of_birth = models.DateField() USERNAME_FIELD = 'username' REQUIRED_FIELDS = 'date_of_birth' class Meta: app_label = 'auth' class CustomUserBadRequiredFields(AbstractBaseUser): "A user with a USERNAME_FIELD that appears in REQUIRED_FIELDS (invalid)" username = models.CharField(max_length=30, unique=True) date_of_birth = models.DateField() USERNAME_FIELD = 'username' REQUIRED_FIELDS = ['username', 'date_of_birth'] class Meta: app_label = 'auth'
bsd-3-clause
[ 504, 1639, 14, 2828, 14, 1178, 14, 992, 492, 11836, 1563, 1899, 12, 2876, 2988, 199, 504, 1639, 14, 697, 492, 1709, 421, 199, 533, 8388, 1899, 6932, 11427, 13355, 8, 8458, 1563, 1899, 304, 272, 408, 272, 437, 922, 543, 282, 2222, 13, 3235, 3434, 14, 339, 961, 1402, 365, 440, 3866, 340, 652, 365, 1202, 543, 282, 3537, 6299, 272, 4865, 1314, 5171, 2222, 13, 3235, 922, 1247, 14, 272, 408, 272, 3434, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1216, 9, 272, 3031, 275, 1709, 14, 16577, 8, 2500, 29, 549, 9, 272, 365, 63, 7018, 275, 1709, 14, 5036, 8, 885, 29, 797, 9, 272, 365, 63, 11434, 275, 1709, 14, 5036, 8, 885, 29, 797, 9, 339, 13044, 2339, 63, 8609, 275, 283, 2473, 7, 272, 25090, 63, 12767, 275, 788, 2123, 418, 339, 2251, 275, 2876, 2988, 342, 339, 1021, 6288, 26, 267, 1145, 63, 1302, 275, 283, 1178, 7, 421, 199, 533, 8388, 1899, 6932, 1296, 8030, 7304, 8, 8458, 1563, 1899, 304, 272, 298, 33, 922, 543, 282, 2222, 13, 513, 25090, 63, 12767, 2, 272, 3434, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1216, 12, 3747, 29, 549, 9, 272, 1434, 63, 1618, 63, 10907, 275, 1709, 14, 14071, 342, 339, 13044, 2339, 63, 8609, 275, 283, 2473, 7, 272, 25090, 63, 12767, 275, 283, 602, 63, 1618, 63, 10907, 7, 339, 1021, 6288, 26, 267, 1145, 63, 1302, 275, 283, 1178, 7, 421, 199, 533, 8388, 1899, 5725, 8030, 7304, 8, 8458, 1563, 1899, 304, 272, 298, 33, 922, 543, 282, 13044, 2339, 63, 8609, 626, 11337, 315, 25090, 63, 12767, 334, 3197, 2924, 272, 3434, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1216, 12, 3747, 29, 549, 9, 272, 1434, 63, 1618, 63, 10907, 275, 1709, 14, 14071, 342, 339, 13044, 2339, 63, 8609, 275, 283, 2473, 7, 272, 25090, 63, 12767, 275, 788, 2473, 297, 283, 602, 63, 1618, 63, 10907, 418, 339, 1021, 6288, 26, 267, 1145, 63, 1302, 275, 283, 1178, 7, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1639, 14, 2828, 14, 1178, 14, 992, 492, 11836, 1563, 1899, 12, 2876, 2988, 199, 504, 1639, 14, 697, 492, 1709, 421, 199, 533, 8388, 1899, 6932, 11427, 13355, 8, 8458, 1563, 1899, 304, 272, 408, 272, 437, 922, 543, 282, 2222, 13, 3235, 3434, 14, 339, 961, 1402, 365, 440, 3866, 340, 652, 365, 1202, 543, 282, 3537, 6299, 272, 4865, 1314, 5171, 2222, 13, 3235, 922, 1247, 14, 272, 408, 272, 3434, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1216, 9, 272, 3031, 275, 1709, 14, 16577, 8, 2500, 29, 549, 9, 272, 365, 63, 7018, 275, 1709, 14, 5036, 8, 885, 29, 797, 9, 272, 365, 63, 11434, 275, 1709, 14, 5036, 8, 885, 29, 797, 9, 339, 13044, 2339, 63, 8609, 275, 283, 2473, 7, 272, 25090, 63, 12767, 275, 788, 2123, 418, 339, 2251, 275, 2876, 2988, 342, 339, 1021, 6288, 26, 267, 1145, 63, 1302, 275, 283, 1178, 7, 421, 199, 533, 8388, 1899, 6932, 1296, 8030, 7304, 8, 8458, 1563, 1899, 304, 272, 298, 33, 922, 543, 282, 2222, 13, 513, 25090, 63, 12767, 2, 272, 3434, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1216, 12, 3747, 29, 549, 9, 272, 1434, 63, 1618, 63, 10907, 275, 1709, 14, 14071, 342, 339, 13044, 2339, 63, 8609, 275, 283, 2473, 7, 272, 25090, 63, 12767, 275, 283, 602, 63, 1618, 63, 10907, 7, 339, 1021, 6288, 26, 267, 1145, 63, 1302, 275, 283, 1178, 7, 421, 199, 533, 8388, 1899, 5725, 8030, 7304, 8, 8458, 1563, 1899, 304, 272, 298, 33, 922, 543, 282, 13044, 2339, 63, 8609, 626, 11337, 315, 25090, 63, 12767, 334, 3197, 2924, 272, 3434, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1216, 12, 3747, 29, 549, 9, 272, 1434, 63, 1618, 63, 10907, 275, 1709, 14, 14071, 342, 339, 13044, 2339, 63, 8609, 275, 283, 2473, 7, 272, 25090, 63, 12767, 275, 788, 2473, 297, 283, 602, 63, 1618, 63, 10907, 418, 339, 1021, 6288, 26, 267, 1145, 63, 1302, 275, 283, 1178, 7, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
tkingless/webtesting
venvs/tutorials/lib/python2.7/site-packages/pip/commands/hash.py
514
1597
from __future__ import absolute_import import hashlib import logging import sys from pip.basecommand import Command from pip.status_codes import ERROR from pip.utils import read_chunks from pip.utils.hashes import FAVORITE_HASH, STRONG_HASHES logger = logging.getLogger(__name__) class HashCommand(Command): """ Compute a hash of a local package archive. These can be used with --hash in a requirements file to do repeatable installs. """ name = 'hash' usage = '%prog [options] <file> ...' summary = 'Compute hashes of package archives.' def __init__(self, *args, **kw): super(HashCommand, self).__init__(*args, **kw) self.cmd_opts.add_option( '-a', '--algorithm', dest='algorithm', choices=STRONG_HASHES, action='store', default=FAVORITE_HASH, help='The hash algorithm to use: one of %s' % ', '.join(STRONG_HASHES)) self.parser.insert_option_group(0, self.cmd_opts) def run(self, options, args): if not args: self.parser.print_usage(sys.stderr) return ERROR algorithm = options.algorithm for path in args: logger.info('%s:\n--hash=%s:%s', path, algorithm, _hash_of_file(path, algorithm)) def _hash_of_file(path, algorithm): """Return the hash digest of a file.""" with open(path, 'rb') as archive: hash = hashlib.new(algorithm) for chunk in read_chunks(archive): hash.update(chunk) return hash.hexdigest()
mit
[ 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 646, 8337, 199, 646, 2050, 199, 646, 984, 199, 199, 504, 7305, 14, 1095, 1531, 492, 5817, 199, 504, 7305, 14, 1205, 63, 6021, 492, 12539, 199, 504, 7305, 14, 1208, 492, 1586, 63, 10660, 199, 504, 7305, 14, 1208, 14, 12428, 492, 481, 6087, 726, 4427, 63, 14395, 12, 7553, 7770, 63, 14395, 654, 421, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 421, 199, 533, 16101, 3110, 8, 3110, 304, 272, 408, 272, 8354, 282, 2631, 402, 282, 2257, 2559, 6359, 14, 339, 5723, 883, 506, 1202, 543, 1553, 2227, 315, 282, 9760, 570, 370, 886, 11982, 461, 272, 25801, 14, 339, 408, 272, 536, 275, 283, 2227, 7, 272, 4503, 275, 1543, 6595, 359, 1419, 61, 665, 493, 30, 2263, 7, 272, 6212, 275, 283, 8564, 14647, 402, 2559, 25993, 3530, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 829, 304, 267, 1613, 8, 3476, 3110, 12, 291, 2843, 826, 9308, 589, 12, 1011, 829, 9, 267, 291, 14, 1760, 63, 3291, 14, 525, 63, 1422, 8, 288, 2475, 65, 297, 2850, 8833, 297, 288, 2053, 534, 8833, 297, 288, 3415, 29, 3027, 7770, 63, 14395, 654, 12, 288, 1595, 534, 1617, 297, 288, 849, 29, 2078, 54, 726, 4427, 63, 14395, 12, 288, 1720, 534, 1918, 2631, 5563, 370, 675, 26, 1373, 402, 450, 83, 7, 450, 326, 1656, 1987, 904, 8, 3027, 7770, 63, 14395, 654, 430, 267, 291, 14, 2087, 14, 3176, 63, 1422, 63, 923, 8, 16, 12, 291, 14, 1760, 63, 3291, 9, 339, 347, 1255, 8, 277, 12, 1511, 12, 1249, 304, 267, 340, 440, 1249, 26, 288, 291, 14, 2087, 14, 1361, 63, 3807, 8, 1274, 14, 3083, 9, 288, 372, 12539, 398, 5563, 275, 1511, 14, 8833, 267, 367, 931, 315, 1249, 26, 288, 2512, 14, 815, 3508, 83, 3427, 78, 306, 2227, 2458, 83, 2689, 83, 297, 717, 931, 12, 5563, 12, 485, 2227, 63, 1618, 63, 493, 8, 515, 12, 5563, 430, 421, 199, 318, 485, 2227, 63, 1618, 63, 493, 8, 515, 12, 5563, 304, 272, 408, 1767, 314, 2631, 10017, 402, 282, 570, 1041, 272, 543, 1551, 8, 515, 12, 283, 4848, 358, 465, 6359, 26, 267, 2631, 275, 8337, 14, 1222, 8, 8833, 9, 267, 367, 3728, 315, 1586, 63, 10660, 8, 6404, 304, 288, 2631, 14, 873, 8, 4604, 9, 272, 372, 2631, 14, 11453, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 646, 8337, 199, 646, 2050, 199, 646, 984, 199, 199, 504, 7305, 14, 1095, 1531, 492, 5817, 199, 504, 7305, 14, 1205, 63, 6021, 492, 12539, 199, 504, 7305, 14, 1208, 492, 1586, 63, 10660, 199, 504, 7305, 14, 1208, 14, 12428, 492, 481, 6087, 726, 4427, 63, 14395, 12, 7553, 7770, 63, 14395, 654, 421, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 421, 199, 533, 16101, 3110, 8, 3110, 304, 272, 408, 272, 8354, 282, 2631, 402, 282, 2257, 2559, 6359, 14, 339, 5723, 883, 506, 1202, 543, 1553, 2227, 315, 282, 9760, 570, 370, 886, 11982, 461, 272, 25801, 14, 339, 408, 272, 536, 275, 283, 2227, 7, 272, 4503, 275, 1543, 6595, 359, 1419, 61, 665, 493, 30, 2263, 7, 272, 6212, 275, 283, 8564, 14647, 402, 2559, 25993, 3530, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 829, 304, 267, 1613, 8, 3476, 3110, 12, 291, 2843, 826, 9308, 589, 12, 1011, 829, 9, 267, 291, 14, 1760, 63, 3291, 14, 525, 63, 1422, 8, 288, 2475, 65, 297, 2850, 8833, 297, 288, 2053, 534, 8833, 297, 288, 3415, 29, 3027, 7770, 63, 14395, 654, 12, 288, 1595, 534, 1617, 297, 288, 849, 29, 2078, 54, 726, 4427, 63, 14395, 12, 288, 1720, 534, 1918, 2631, 5563, 370, 675, 26, 1373, 402, 450, 83, 7, 450, 326, 1656, 1987, 904, 8, 3027, 7770, 63, 14395, 654, 430, 267, 291, 14, 2087, 14, 3176, 63, 1422, 63, 923, 8, 16, 12, 291, 14, 1760, 63, 3291, 9, 339, 347, 1255, 8, 277, 12, 1511, 12, 1249, 304, 267, 340, 440, 1249, 26, 288, 291, 14, 2087, 14, 1361, 63, 3807, 8, 1274, 14, 3083, 9, 288, 372, 12539, 398, 5563, 275, 1511, 14, 8833, 267, 367, 931, 315, 1249, 26, 288, 2512, 14, 815, 3508, 83, 3427, 78, 306, 2227, 2458, 83, 2689, 83, 297, 717, 931, 12, 5563, 12, 485, 2227, 63, 1618, 63, 493, 8, 515, 12, 5563, 430, 421, 199, 318, 485, 2227, 63, 1618, 63, 493, 8, 515, 12, 5563, 304, 272, 408, 1767, 314, 2631, 10017, 402, 282, 570, 1041, 272, 543, 1551, 8, 515, 12, 283, 4848, 358, 465, 6359, 26, 267, 2631, 275, 8337, 14, 1222, 8, 8833, 9, 267, 367, 3728, 315, 1586, 63, 10660, 8, 6404, 304, 288, 2631, 14, 873, 8, 4604, 9, 272, 372, 2631, 14, 11453, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
fintech-circle/edx-platform
lms/djangoapps/badges/api/tests.py
17
9405
""" Tests for the badges API views. """ from ddt import ddt, data, unpack from django.conf import settings from django.test.utils import override_settings from nose.plugins.attrib import attr from badges.tests.factories import BadgeAssertionFactory, BadgeClassFactory, RandomBadgeClassFactory from openedx.core.lib.api.test_utils import ApiTestCase from student.tests.factories import UserFactory from util.testing import UrlResetMixin from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory FEATURES_WITH_BADGES_ENABLED = settings.FEATURES.copy() FEATURES_WITH_BADGES_ENABLED['ENABLE_OPENBADGES'] = True @override_settings(FEATURES=FEATURES_WITH_BADGES_ENABLED) class UserAssertionTestCase(UrlResetMixin, ModuleStoreTestCase, ApiTestCase): """ Mixin for badge API tests. """ def setUp(self, *args, **kwargs): super(UserAssertionTestCase, self).setUp(*args, **kwargs) self.course = CourseFactory.create() self.user = UserFactory.create() # Password defined by factory. self.client.login(username=self.user.username, password='test') def url(self): """ Return the URL to look up the current user's assertions. """ return '/api/badges/v1/assertions/user/{}/'.format(self.user.username) def check_class_structure(self, badge_class, json_class): """ Check a JSON response against a known badge class. """ self.assertEqual(badge_class.issuing_component, json_class['issuing_component']) self.assertEqual(badge_class.slug, json_class['slug']) self.assertIn(badge_class.image.url, json_class['image_url']) self.assertEqual(badge_class.description, json_class['description']) self.assertEqual(badge_class.criteria, json_class['criteria']) self.assertEqual(badge_class.course_id and unicode(badge_class.course_id), json_class['course_id']) def check_assertion_structure(self, assertion, json_assertion): """ Check a JSON response against a known assertion object. """ self.assertEqual(assertion.image_url, json_assertion['image_url']) self.assertEqual(assertion.assertion_url, json_assertion['assertion_url']) self.check_class_structure(assertion.badge_class, json_assertion['badge_class']) def get_course_id(self, wildcard, badge_class): """ Used for tests which may need to test for a course_id or a wildcard. """ if wildcard: return '*' else: return unicode(badge_class.course_id) def create_badge_class(self, check_course, **kwargs): """ Create a badge class, using a course id if it's relevant to the URL pattern. """ if check_course: return RandomBadgeClassFactory.create(course_id=self.course.location.course_key, **kwargs) return RandomBadgeClassFactory.create(**kwargs) def get_qs_args(self, check_course, wildcard, badge_class): """ Get a dictionary to be serialized into querystring params based on class settings. """ qs_args = { 'issuing_component': badge_class.issuing_component, 'slug': badge_class.slug, } if check_course: qs_args['course_id'] = self.get_course_id(wildcard, badge_class) return qs_args class TestUserBadgeAssertions(UserAssertionTestCase): """ Test the general badge assertions retrieval view. """ def test_get_assertions(self): """ Verify we can get all of a user's badge assertions. """ for dummy in range(3): BadgeAssertionFactory(user=self.user) # Add in a course scoped badge-- these should not be excluded from the full listing. BadgeAssertionFactory(user=self.user, badge_class=BadgeClassFactory(course_id=self.course.location.course_key)) # Should not be included. for dummy in range(3): self.create_badge_class(False) response = self.get_json(self.url()) # pylint: disable=no-member self.assertEqual(len(response['results']), 4) def test_assertion_structure(self): badge_class = self.create_badge_class(False) assertion = BadgeAssertionFactory.create(user=self.user, badge_class=badge_class) response = self.get_json(self.url()) # pylint: disable=no-member self.check_assertion_structure(assertion, response['results'][0]) class TestUserCourseBadgeAssertions(UserAssertionTestCase): """ Test the Badge Assertions view with the course_id filter. """ def test_get_assertions(self): """ Verify we can get assertions via the course_id and username. """ course_key = self.course.location.course_key badge_class = BadgeClassFactory.create(course_id=course_key) for dummy in range(3): BadgeAssertionFactory.create(user=self.user, badge_class=badge_class) # Should not be included, as they don't share the target badge class. for dummy in range(3): BadgeAssertionFactory.create(user=self.user) # Also should not be included, as they don't share the same user. for dummy in range(6): BadgeAssertionFactory.create(badge_class=badge_class) response = self.get_json(self.url(), data={'course_id': course_key}) # pylint: disable=no-member self.assertEqual(len(response['results']), 3) unused_course = CourseFactory.create() response = self.get_json(self.url(), data={'course_id': unused_course.location.course_key}) # pylint: disable=no-member self.assertEqual(len(response['results']), 0) def test_assertion_structure(self): """ Verify the badge assertion structure is as expected when a course is involved. """ course_key = self.course.location.course_key badge_class = BadgeClassFactory.create(course_id=course_key) assertion = BadgeAssertionFactory.create(badge_class=badge_class, user=self.user) response = self.get_json(self.url()) # pylint: disable=no-member self.check_assertion_structure(assertion, response['results'][0]) @attr(shard=3) @ddt class TestUserBadgeAssertionsByClass(UserAssertionTestCase): """ Test the Badge Assertions view with the badge class filter. """ @unpack @data((False, False), (True, False), (True, True)) def test_get_assertions(self, check_course, wildcard): """ Verify we can get assertions via the badge class and username. """ badge_class = self.create_badge_class(check_course) for dummy in range(3): BadgeAssertionFactory.create(user=self.user, badge_class=badge_class) if badge_class.course_id: # Also create a version of this badge under a different course. alt_class = BadgeClassFactory.create( slug=badge_class.slug, issuing_component=badge_class.issuing_component, course_id=CourseFactory.create().location.course_key ) BadgeAssertionFactory.create(user=self.user, badge_class=alt_class) # Same badge class, but different user. Should not show up in the list. for dummy in range(5): BadgeAssertionFactory.create(badge_class=badge_class) # Different badge class AND different user. Certainly shouldn't show up in the list! for dummy in range(6): BadgeAssertionFactory.create() response = self.get_json( self.url(), data=self.get_qs_args(check_course, wildcard, badge_class), ) if wildcard: expected_length = 4 else: expected_length = 3 # pylint: disable=no-member self.assertEqual(len(response['results']), expected_length) unused_class = self.create_badge_class(check_course, slug='unused_slug', issuing_component='unused_component') response = self.get_json( self.url(), data=self.get_qs_args(check_course, wildcard, unused_class), ) # pylint: disable=no-member self.assertEqual(len(response['results']), 0) def check_badge_class_assertion(self, check_course, wildcard, badge_class): """ Given a badge class, create an assertion for the current user and fetch it, checking the structure. """ assertion = BadgeAssertionFactory.create(badge_class=badge_class, user=self.user) response = self.get_json( self.url(), data=self.get_qs_args(check_course, wildcard, badge_class), ) # pylint: disable=no-member self.check_assertion_structure(assertion, response['results'][0]) @unpack @data((False, False), (True, False), (True, True)) def test_assertion_structure(self, check_course, wildcard): self.check_badge_class_assertion(check_course, wildcard, self.create_badge_class(check_course)) @unpack @data((False, False), (True, False), (True, True)) def test_empty_issuing_component(self, check_course, wildcard): self.check_badge_class_assertion( check_course, wildcard, self.create_badge_class(check_course, issuing_component='') )
agpl-3.0
[ 624, 199, 2925, 367, 314, 4875, 3389, 3261, 6858, 14, 199, 624, 199, 504, 366, 3583, 492, 366, 3583, 12, 666, 12, 7787, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 396, 14, 1208, 492, 4278, 63, 1751, 199, 504, 11354, 14, 5265, 14, 6640, 492, 1921, 199, 199, 504, 4875, 3389, 14, 2219, 14, 15406, 492, 8857, 303, 26860, 2927, 12, 8857, 303, 2543, 2927, 12, 9571, 5725, 303, 2543, 2927, 199, 504, 22709, 14, 1018, 14, 773, 14, 1246, 14, 396, 63, 1208, 492, 13986, 1746, 199, 504, 6474, 14, 2219, 14, 15406, 492, 16047, 199, 504, 4884, 14, 4776, 492, 20503, 9637, 4256, 199, 504, 9872, 14, 10012, 14, 2219, 14, 1176, 63, 1208, 492, 17996, 1746, 199, 504, 9872, 14, 10012, 14, 2219, 14, 15406, 492, 17862, 199, 199, 13313, 63, 9139, 63, 9439, 39, 654, 63, 15704, 275, 2202, 14, 13313, 14, 1574, 342, 199, 13313, 63, 9139, 63, 9439, 39, 654, 63, 15704, 459, 8898, 63, 9935, 9439, 39, 654, 418, 275, 715, 421, 199, 32, 4415, 63, 1751, 8, 13313, 29, 13313, 63, 9139, 63, 9439, 39, 654, 63, 15704, 9, 199, 533, 2876, 26860, 1746, 8, 6417, 9637, 4256, 12, 17996, 1746, 12, 13986, 1746, 304, 272, 408, 272, 28438, 367, 23122, 3261, 2295, 14, 272, 408, 339, 347, 3613, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 1899, 26860, 1746, 12, 291, 680, 5996, 2031, 589, 12, 1011, 958, 9, 267, 291, 14, 1972, 275, 17862, 14, 981, 342, 267, 291, 14, 751, 275, 16047, 14, 981, 342, 267, 327, 13635, 3247, 701, 6434, 14, 267, 291, 14, 1258, 14, 2886, 8, 2473, 29, 277, 14, 751, 14, 2473, 12, 2505, 534, 396, 358, 339, 347, 1166, 8, 277, 304, 267, 408, 267, 1432, 314, 2851, 370, 3648, 1536, 314, 1453, 922, 1159, 22835, 14, 267, 408, 267, 372, 1994, 1246, 15, 4087, 3389, 15, 86, 17, 15, 305, 13049, 15, 751, 19655, 1370, 908, 8, 277, 14, 751, 14, 2473, 9, 339, 347, 1104, 63, 533, 63, 6976, 8, 277, 12, 23122, 63, 533, 12, 2022, 63, 533, 304, 267, 408, 267, 2670, 282, 4840, 1177, 6169, 282, 6040, 23122, 1021, 14, 267, 408, 267, 291, 14, 629, 8, 18465, 63, 533, 14, 374, 9648, 316, 63, 3173, 12, 2022, 63, 533, 459, 374, 9648, 316, 63, 3173, 1105, 267, 291, 14, 629, 8, 18465, 63, 533, 14, 5464, 12, 2022, 63, 533, 459, 5464, 1105, 267, 291, 14, 4080, 8, 18465, 63, 533, 14, 1569, 14, 633, 12, 2022, 63, 533, 459, 1569, 63, 633, 1105, 267, 291, 14, 629, 8, 18465, 63, 533, 14, 1802, 12, 2022, 63, 533, 459, 1802, 1105, 267, 291, 14, 629, 8, 18465, 63, 533, 14, 20525, 12, 2022, 63, 533, 459, 20525, 1105, 267, 291, 14, 629, 8, 18465, 63, 533, 14, 1972, 63, 344, 436, 2649, 8, 18465, 63, 533, 14, 1972, 63, 344, 395, 2022, 63, 533, 459, 1972, 63, 344, 1105, 339, 347, 1104, 63, 18487, 63, 6976, 8, 277, 12, 14412, 12, 2022, 63, 18487, 304, 267, 408, 267, 2670, 282, 4840, 1177, 6169, 282, 6040, 14412, 909, 14, 267, 408, 267, 291, 14, 629, 8, 18487, 14, 1569, 63, 633, 12, 2022, 63, 18487, 459, 1569, 63, 633, 1105, 267, 291, 14, 629, 8, 18487, 14, 18487, 63, 633, 12, 2022, 63, 18487, 459, 18487, 63, 633, 1105, 267, 291, 14, 1074, 63, 533, 63, 6976, 8, 18487, 14, 18465, 63, 533, 12, 2022, 63, 18487, 459, 18465, 63, 533, 1105, 339, 347, 664, 63, 1972, 63, 344, 8, 277, 12, 16792, 12, 23122, 63, 533, 304, 267, 408, 267, 8051, 367, 2295, 1314, 1443, 1929, 370, 511, 367, 282, 2518, 63, 344, 503, 282, 16792, 14, 267, 408, 267, 340, 16792, 26, 288, 372, 13626, 267, 587, 26, 288, 372, 2649, 8, 18465, 63, 533, 14, 1972, 63, 344, 9, 339, 347, 1218, 63, 18465, 63, 533, 8, 277, 12, 1104, 63, 1972, 12, 1011, 958, 304, 267, 408, 267, 2790, 282, 23122, 1021, 12, 1808, 282, 2518, 1305, 340, 652, 1159, 12082, 370, 314, 2851, 3851, 14, 267, 408, 267, 340, 1104, 63, 1972, 26, 288, 372, 9571, 5725, 303, 2543, 2927, 14, 981, 8, 1972, 63, 344, 29, 277, 14, 1972, 14, 1985, 14, 1972, 63, 498, 12, 1011, 958, 9, 267, 372, 9571, 5725, 303, 2543, 2927, 14, 981, 3682, 958, 9, 339, 347, 664, 63, 6177, 63, 589, 8, 277, 12, 1104, 63, 1972, 12, 16792, 12, 23122, 63, 533, 304, 267, 408, 267, 2372, 282, 2600, 370, 506, 6380, 1901, 1827, 875, 1862, 4079, 641, 1021, 2202, 14, 267, 408, 267, 6377, 63, 589, 275, 469, 288, 283, 374, 9648, 316, 63, 3173, 356, 23122, 63, 533, 14, 374, 9648, 316, 63, 3173, 12, 288, 283, 5464, 356, 23122, 63, 533, 14, 5464, 12, 267, 789, 267, 340, 1104, 63, 1972, 26, 288, 6377, 63, 589, 459, 1972, 63, 344, 418, 275, 291, 14, 362, 63, 1972, 63, 344, 8, 16692, 12, 23122, 63, 533, 9, 267, 372, 6377, 63, 589, 421, 199, 533, 1379, 1899, 5725, 303, 2822, 13049, 8, 1899, 26860, 1746, 304, 272, 408, 272, 1379, 314, 8605, 23122, 22835, 27157, 2455, 14, 272, 408, 339, 347, 511, 63, 362, 63, 305, 13049, 8, 277, 304, 267, 408, 267, 7635, 781, 883, 664, 1006, 402, 282, 922, 1159, 23122, 22835, 14, 267, 408, 267, 367, 7283, 315, 1425, 8, 19, 304, 288, 8857, 303, 26860, 2927, 8, 751, 29, 277, 14, 751, 9, 267, 327, 2654, 315, 282, 2518, 27582, 23122, 306, 3520, 1077, 440, 506, 8789, 687, 314, 2615, 13778, 14, 267, 8857, 303, 26860, 2927, 8, 751, 29, 277, 14, 751, 12, 23122, 63, 533, 29, 5725, 303, 2543, 2927, 8, 1972, 63, 344, 29, 277, 14, 1972, 14, 1985, 14, 1972, 63, 498, 430, 267, 327, 7719, 440, 506, 5120, 14, 267, 367, 7283, 315, 1425, 8, 19, 304, 288, 291, 14, 981, 63, 18465, 63, 533, 8, 797, 9, 267, 1177, 275, 291, 14, 362, 63, 1001, 8, 277, 14, 633, 1012, 267, 327, 4287, 26, 3507, 29, 889, 13, 1114 ]
[ 199, 2925, 367, 314, 4875, 3389, 3261, 6858, 14, 199, 624, 199, 504, 366, 3583, 492, 366, 3583, 12, 666, 12, 7787, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 396, 14, 1208, 492, 4278, 63, 1751, 199, 504, 11354, 14, 5265, 14, 6640, 492, 1921, 199, 199, 504, 4875, 3389, 14, 2219, 14, 15406, 492, 8857, 303, 26860, 2927, 12, 8857, 303, 2543, 2927, 12, 9571, 5725, 303, 2543, 2927, 199, 504, 22709, 14, 1018, 14, 773, 14, 1246, 14, 396, 63, 1208, 492, 13986, 1746, 199, 504, 6474, 14, 2219, 14, 15406, 492, 16047, 199, 504, 4884, 14, 4776, 492, 20503, 9637, 4256, 199, 504, 9872, 14, 10012, 14, 2219, 14, 1176, 63, 1208, 492, 17996, 1746, 199, 504, 9872, 14, 10012, 14, 2219, 14, 15406, 492, 17862, 199, 199, 13313, 63, 9139, 63, 9439, 39, 654, 63, 15704, 275, 2202, 14, 13313, 14, 1574, 342, 199, 13313, 63, 9139, 63, 9439, 39, 654, 63, 15704, 459, 8898, 63, 9935, 9439, 39, 654, 418, 275, 715, 421, 199, 32, 4415, 63, 1751, 8, 13313, 29, 13313, 63, 9139, 63, 9439, 39, 654, 63, 15704, 9, 199, 533, 2876, 26860, 1746, 8, 6417, 9637, 4256, 12, 17996, 1746, 12, 13986, 1746, 304, 272, 408, 272, 28438, 367, 23122, 3261, 2295, 14, 272, 408, 339, 347, 3613, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 1899, 26860, 1746, 12, 291, 680, 5996, 2031, 589, 12, 1011, 958, 9, 267, 291, 14, 1972, 275, 17862, 14, 981, 342, 267, 291, 14, 751, 275, 16047, 14, 981, 342, 267, 327, 13635, 3247, 701, 6434, 14, 267, 291, 14, 1258, 14, 2886, 8, 2473, 29, 277, 14, 751, 14, 2473, 12, 2505, 534, 396, 358, 339, 347, 1166, 8, 277, 304, 267, 408, 267, 1432, 314, 2851, 370, 3648, 1536, 314, 1453, 922, 1159, 22835, 14, 267, 408, 267, 372, 1994, 1246, 15, 4087, 3389, 15, 86, 17, 15, 305, 13049, 15, 751, 19655, 1370, 908, 8, 277, 14, 751, 14, 2473, 9, 339, 347, 1104, 63, 533, 63, 6976, 8, 277, 12, 23122, 63, 533, 12, 2022, 63, 533, 304, 267, 408, 267, 2670, 282, 4840, 1177, 6169, 282, 6040, 23122, 1021, 14, 267, 408, 267, 291, 14, 629, 8, 18465, 63, 533, 14, 374, 9648, 316, 63, 3173, 12, 2022, 63, 533, 459, 374, 9648, 316, 63, 3173, 1105, 267, 291, 14, 629, 8, 18465, 63, 533, 14, 5464, 12, 2022, 63, 533, 459, 5464, 1105, 267, 291, 14, 4080, 8, 18465, 63, 533, 14, 1569, 14, 633, 12, 2022, 63, 533, 459, 1569, 63, 633, 1105, 267, 291, 14, 629, 8, 18465, 63, 533, 14, 1802, 12, 2022, 63, 533, 459, 1802, 1105, 267, 291, 14, 629, 8, 18465, 63, 533, 14, 20525, 12, 2022, 63, 533, 459, 20525, 1105, 267, 291, 14, 629, 8, 18465, 63, 533, 14, 1972, 63, 344, 436, 2649, 8, 18465, 63, 533, 14, 1972, 63, 344, 395, 2022, 63, 533, 459, 1972, 63, 344, 1105, 339, 347, 1104, 63, 18487, 63, 6976, 8, 277, 12, 14412, 12, 2022, 63, 18487, 304, 267, 408, 267, 2670, 282, 4840, 1177, 6169, 282, 6040, 14412, 909, 14, 267, 408, 267, 291, 14, 629, 8, 18487, 14, 1569, 63, 633, 12, 2022, 63, 18487, 459, 1569, 63, 633, 1105, 267, 291, 14, 629, 8, 18487, 14, 18487, 63, 633, 12, 2022, 63, 18487, 459, 18487, 63, 633, 1105, 267, 291, 14, 1074, 63, 533, 63, 6976, 8, 18487, 14, 18465, 63, 533, 12, 2022, 63, 18487, 459, 18465, 63, 533, 1105, 339, 347, 664, 63, 1972, 63, 344, 8, 277, 12, 16792, 12, 23122, 63, 533, 304, 267, 408, 267, 8051, 367, 2295, 1314, 1443, 1929, 370, 511, 367, 282, 2518, 63, 344, 503, 282, 16792, 14, 267, 408, 267, 340, 16792, 26, 288, 372, 13626, 267, 587, 26, 288, 372, 2649, 8, 18465, 63, 533, 14, 1972, 63, 344, 9, 339, 347, 1218, 63, 18465, 63, 533, 8, 277, 12, 1104, 63, 1972, 12, 1011, 958, 304, 267, 408, 267, 2790, 282, 23122, 1021, 12, 1808, 282, 2518, 1305, 340, 652, 1159, 12082, 370, 314, 2851, 3851, 14, 267, 408, 267, 340, 1104, 63, 1972, 26, 288, 372, 9571, 5725, 303, 2543, 2927, 14, 981, 8, 1972, 63, 344, 29, 277, 14, 1972, 14, 1985, 14, 1972, 63, 498, 12, 1011, 958, 9, 267, 372, 9571, 5725, 303, 2543, 2927, 14, 981, 3682, 958, 9, 339, 347, 664, 63, 6177, 63, 589, 8, 277, 12, 1104, 63, 1972, 12, 16792, 12, 23122, 63, 533, 304, 267, 408, 267, 2372, 282, 2600, 370, 506, 6380, 1901, 1827, 875, 1862, 4079, 641, 1021, 2202, 14, 267, 408, 267, 6377, 63, 589, 275, 469, 288, 283, 374, 9648, 316, 63, 3173, 356, 23122, 63, 533, 14, 374, 9648, 316, 63, 3173, 12, 288, 283, 5464, 356, 23122, 63, 533, 14, 5464, 12, 267, 789, 267, 340, 1104, 63, 1972, 26, 288, 6377, 63, 589, 459, 1972, 63, 344, 418, 275, 291, 14, 362, 63, 1972, 63, 344, 8, 16692, 12, 23122, 63, 533, 9, 267, 372, 6377, 63, 589, 421, 199, 533, 1379, 1899, 5725, 303, 2822, 13049, 8, 1899, 26860, 1746, 304, 272, 408, 272, 1379, 314, 8605, 23122, 22835, 27157, 2455, 14, 272, 408, 339, 347, 511, 63, 362, 63, 305, 13049, 8, 277, 304, 267, 408, 267, 7635, 781, 883, 664, 1006, 402, 282, 922, 1159, 23122, 22835, 14, 267, 408, 267, 367, 7283, 315, 1425, 8, 19, 304, 288, 8857, 303, 26860, 2927, 8, 751, 29, 277, 14, 751, 9, 267, 327, 2654, 315, 282, 2518, 27582, 23122, 306, 3520, 1077, 440, 506, 8789, 687, 314, 2615, 13778, 14, 267, 8857, 303, 26860, 2927, 8, 751, 29, 277, 14, 751, 12, 23122, 63, 533, 29, 5725, 303, 2543, 2927, 8, 1972, 63, 344, 29, 277, 14, 1972, 14, 1985, 14, 1972, 63, 498, 430, 267, 327, 7719, 440, 506, 5120, 14, 267, 367, 7283, 315, 1425, 8, 19, 304, 288, 291, 14, 981, 63, 18465, 63, 533, 8, 797, 9, 267, 1177, 275, 291, 14, 362, 63, 1001, 8, 277, 14, 633, 1012, 267, 327, 4287, 26, 3507, 29, 889, 13, 1114, 0 ]
[ 1, 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ex100/odoo
addons/report/controllers/main.py
210
6943
# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2014-Today OpenERP SA (<http://www.openerp.com>). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## from openerp.addons.web.http import Controller, route, request from openerp.addons.web.controllers.main import _serialize_exception from openerp.osv import osv from openerp.tools import html_escape import simplejson from werkzeug import exceptions, url_decode from werkzeug.test import Client from werkzeug.wrappers import BaseResponse from werkzeug.datastructures import Headers from reportlab.graphics.barcode import createBarcodeDrawing class ReportController(Controller): #------------------------------------------------------ # Report controllers #------------------------------------------------------ @route([ '/report/<path:converter>/<reportname>', '/report/<path:converter>/<reportname>/<docids>', ], type='http', auth='user', website=True) def report_routes(self, reportname, docids=None, converter=None, **data): report_obj = request.registry['report'] cr, uid, context = request.cr, request.uid, request.context if docids: docids = [int(i) for i in docids.split(',')] options_data = None if data.get('options'): options_data = simplejson.loads(data['options']) if data.get('context'): # Ignore 'lang' here, because the context in data is the one from the webclient *but* if # the user explicitely wants to change the lang, this mechanism overwrites it. data_context = simplejson.loads(data['context']) if data_context.get('lang'): del data_context['lang'] context.update(data_context) if converter == 'html': html = report_obj.get_html(cr, uid, docids, reportname, data=options_data, context=context) return request.make_response(html) elif converter == 'pdf': pdf = report_obj.get_pdf(cr, uid, docids, reportname, data=options_data, context=context) pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))] return request.make_response(pdf, headers=pdfhttpheaders) else: raise exceptions.HTTPException(description='Converter %s not implemented.' % converter) #------------------------------------------------------ # Misc. route utils #------------------------------------------------------ @route(['/report/barcode', '/report/barcode/<type>/<path:value>'], type='http', auth="user") def report_barcode(self, type, value, width=600, height=100, humanreadable=0): """Contoller able to render barcode images thanks to reportlab. Samples: <img t-att-src="'/report/barcode/QR/%s' % o.name"/> <img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('QR', o.name, 200, 200)"/> :param type: Accepted types: 'Codabar', 'Code11', 'Code128', 'EAN13', 'EAN8', 'Extended39', 'Extended93', 'FIM', 'I2of5', 'MSI', 'POSTNET', 'QR', 'Standard39', 'Standard93', 'UPCA', 'USPS_4State' :param humanreadable: Accepted values: 0 (default) or 1. 1 will insert the readable value at the bottom of the output image """ try: width, height, humanreadable = int(width), int(height), bool(humanreadable) barcode = createBarcodeDrawing( type, value=value, format='png', width=width, height=height, humanReadable = humanreadable ) barcode = barcode.asString('png') except (ValueError, AttributeError): raise exceptions.HTTPException(description='Cannot convert into barcode.') return request.make_response(barcode, headers=[('Content-Type', 'image/png')]) @route(['/report/download'], type='http', auth="user") def report_download(self, data, token): """This function is used by 'qwebactionmanager.js' in order to trigger the download of a pdf/controller report. :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = simplejson.loads(data) url, type = requestcontent[0], requestcontent[1] try: if type == 'qweb-pdf': reportname = url.split('/report/pdf/')[1].split('?')[0] docids = None if '/' in reportname: reportname, docids = reportname.split('/') if docids: # Generic report: response = self.report_routes(reportname, docids=docids, converter='pdf') else: # Particular report: data = url_decode(url.split('?')[1]).items() # decoding the args represented in JSON response = self.report_routes(reportname, converter='pdf', **dict(data)) response.headers.add('Content-Disposition', 'attachment; filename=%s.pdf;' % reportname) response.set_cookie('fileToken', token) return response elif type =='controller': reqheaders = Headers(request.httprequest.headers) response = Client(request.httprequest.app, BaseResponse).get(url, headers=reqheaders, follow_redirects=True) response.set_cookie('fileToken', token) return response else: return except Exception, e: se = _serialize_exception(e) error = { 'code': 200, 'message': "Odoo Server Error", 'data': se } return request.make_response(html_escape(simplejson.dumps(error))) @route(['/report/check_wkhtmltopdf'], type='json', auth="user") def check_wkhtmltopdf(self): return request.registry['report']._check_wkhtmltopdf()
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 199, 3, 199, 3, 259, 7653, 12, 3232, 5800, 8259, 9274, 199, 3, 259, 1898, 334, 35, 9, 6927, 13, 31982, 7653, 13950, 8642, 1014, 921, 1544, 14, 11267, 14, 957, 10121, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 199, 3, 259, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 259, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 4605, 199, 199, 504, 5166, 14, 10788, 14, 2520, 14, 1014, 492, 16282, 12, 7475, 12, 1056, 199, 504, 5166, 14, 10788, 14, 2520, 14, 20531, 14, 973, 492, 485, 3549, 63, 1971, 199, 504, 5166, 14, 4795, 492, 9506, 199, 504, 5166, 14, 2537, 492, 3517, 63, 3765, 199, 199, 646, 13804, 199, 504, 10380, 492, 4967, 12, 1166, 63, 2708, 199, 504, 10380, 14, 396, 492, 6810, 199, 504, 10380, 14, 21148, 492, 3523, 2364, 199, 504, 10380, 14, 23004, 492, 21391, 199, 504, 21773, 14, 15707, 14, 22091, 492, 1218, 5281, 600, 9654, 316, 421, 199, 533, 11774, 7506, 8, 7506, 304, 339, 27721, 8648, 272, 327, 11774, 27325, 272, 27721, 8648, 272, 768, 4449, 779, 267, 1994, 3070, 8316, 515, 26, 11256, 23220, 3070, 354, 4206, 267, 1994, 3070, 8316, 515, 26, 11256, 23220, 3070, 354, 23220, 1301, 1580, 4206, 272, 2156, 730, 534, 1014, 297, 1790, 534, 751, 297, 10691, 29, 549, 9, 272, 347, 3622, 63, 13243, 8, 277, 12, 3622, 354, 12, 1382, 1580, 29, 403, 12, 11109, 29, 403, 12, 1011, 576, 304, 267, 3622, 63, 1113, 275, 1056, 14, 5189, 459, 3070, 418, 267, 2467, 12, 1747, 12, 1067, 275, 1056, 14, 1556, 12, 1056, 14, 1535, 12, 1056, 14, 1100, 398, 340, 1382, 1580, 26, 288, 1382, 1580, 275, 359, 442, 8, 73, 9, 367, 284, 315, 1382, 1580, 14, 1294, 29972, 267, 1511, 63, 576, 275, 488, 267, 340, 666, 14, 362, 360, 1419, 735, 288, 1511, 63, 576, 275, 13804, 14, 3640, 8, 576, 459, 1419, 1105, 267, 340, 666, 14, 362, 360, 1100, 735, 288, 327, 14092, 283, 4159, 7, 2348, 12, 2952, 314, 1067, 315, 666, 365, 314, 1373, 687, 314, 3330, 1258, 627, 7911, 10, 340, 288, 327, 314, 922, 1437, 317, 25171, 590, 15061, 370, 1570, 314, 6339, 12, 642, 14729, 1806, 16334, 652, 14, 7205, 666, 63, 1100, 275, 13804, 14, 3640, 8, 576, 459, 1100, 1105, 288, 340, 666, 63, 1100, 14, 362, 360, 4159, 735, 355, 2150, 666, 63, 1100, 459, 4159, 418, 288, 1067, 14, 873, 8, 576, 63, 1100, 9, 398, 340, 11109, 508, 283, 1360, 356, 288, 3517, 275, 3622, 63, 1113, 14, 362, 63, 1360, 8, 1556, 12, 1747, 12, 1382, 1580, 12, 3622, 354, 12, 666, 29, 1419, 63, 576, 12, 1067, 29, 1100, 9, 288, 372, 1056, 14, 1875, 63, 1310, 8, 1360, 9, 267, 916, 11109, 508, 283, 5607, 356, 288, 11249, 275, 3622, 63, 1113, 14, 362, 63, 5607, 8, 1556, 12, 1747, 12, 1382, 1580, 12, 3622, 354, 12, 666, 29, 1419, 63, 576, 12, 1067, 29, 1100, 9, 288, 11249, 1014, 2139, 275, 4274, 2714, 13, 804, 297, 283, 3578, 15, 5607, 659, 661, 2714, 13, 4625, 297, 822, 8, 5607, 10524, 288, 372, 1056, 14, 1875, 63, 1310, 8, 5607, 12, 2323, 29, 5607, 1014, 2139, 9, 267, 587, 26, 288, 746, 4967, 14, 26871, 8, 1802, 534, 11907, 450, 83, 440, 6366, 3530, 450, 11109, 9, 339, 27721, 8648, 272, 327, 603, 10840, 14, 7475, 3778, 272, 27721, 8648, 272, 768, 4449, 26352, 3070, 15, 22091, 297, 1994, 3070, 15, 22091, 8316, 466, 23220, 515, 26, 585, 16619, 730, 534, 1014, 297, 1790, 628, 751, 531, 272, 347, 3622, 63, 22091, 8, 277, 12, 730, 12, 574, 12, 3462, 29, 6683, 12, 4569, 29, 1960, 12, 11779, 11875, 29, 16, 304, 267, 408, 714, 6896, 1435, 7688, 370, 3795, 24323, 5935, 2419, 6080, 370, 21773, 14, 267, 428, 1889, 26, 7205, 665, 4060, 307, 13, 6796, 13, 2164, 628, 9807, 3070, 15, 22091, 15, 26779, 3149, 83, 7, 450, 312, 14, 354, 7897, 288, 665, 4060, 307, 13, 6796, 13, 2164, 628, 9807, 3070, 15, 22091, 10197, 466, 2458, 83, 6, 5282, 27, 585, 2458, 83, 6, 5282, 27, 2063, 2458, 83, 6, 5282, 27, 3333, 2458, 83, 7, 450, 8892, 661, 26779, 297, 312, 14, 354, 12, 1926, 12, 1926, 2924, 3133, 398, 520, 635, 730, 26, 4473, 7203, 2943, 26, 283, 35, 364, 371, 285, 297, 283, 3034, 845, 297, 283, 3034, 3933, 297, 283, 37, 879, 969, 297, 283, 37, 879, 24, 297, 283, 14107, 1355, 297, 267, 283, 14107, 3129, 297, 283, 38, 1469, 297, 283, 41, 18, 1618, 21, 297, 283, 45, 2684, 297, 283, 4030, 7278, 297, 283, 26779, 297, 283, 9232, 1355, 297, 283, 9232, 3129, 297, 267, 283, 2160, 3263, 297, 283, 1668, 5067, 63, 20, 2223, 7, 267, 520, 635, 11779, 11875, 26, 4473, 7203, 1338, 26, 378, 334, 885, 9, 503, 413, 14, 413, 911, 5518, 314, 12701, 574, 267, 737, 314, 9048, 402, 314, 1072, 1834, 267, 408, 267, 862, 26, 288, 3462, 12, 4569, 12, 11779, 11875, 275, 1109, 8, 2063, 395, 1109, 8, 3333, 395, 2155, 8, 14864, 11875, 9, 288, 24323, 275, 1218, 5281, 600, 9654, 316, 8, 355, 730, 12, 574, 29, 585, 12, 1475, 534, 4524, 297, 3462 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 199, 3, 199, 3, 259, 7653, 12, 3232, 5800, 8259, 9274, 199, 3, 259, 1898, 334, 35, 9, 6927, 13, 31982, 7653, 13950, 8642, 1014, 921, 1544, 14, 11267, 14, 957, 10121, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 199, 3, 259, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 259, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 4605, 199, 199, 504, 5166, 14, 10788, 14, 2520, 14, 1014, 492, 16282, 12, 7475, 12, 1056, 199, 504, 5166, 14, 10788, 14, 2520, 14, 20531, 14, 973, 492, 485, 3549, 63, 1971, 199, 504, 5166, 14, 4795, 492, 9506, 199, 504, 5166, 14, 2537, 492, 3517, 63, 3765, 199, 199, 646, 13804, 199, 504, 10380, 492, 4967, 12, 1166, 63, 2708, 199, 504, 10380, 14, 396, 492, 6810, 199, 504, 10380, 14, 21148, 492, 3523, 2364, 199, 504, 10380, 14, 23004, 492, 21391, 199, 504, 21773, 14, 15707, 14, 22091, 492, 1218, 5281, 600, 9654, 316, 421, 199, 533, 11774, 7506, 8, 7506, 304, 339, 27721, 8648, 272, 327, 11774, 27325, 272, 27721, 8648, 272, 768, 4449, 779, 267, 1994, 3070, 8316, 515, 26, 11256, 23220, 3070, 354, 4206, 267, 1994, 3070, 8316, 515, 26, 11256, 23220, 3070, 354, 23220, 1301, 1580, 4206, 272, 2156, 730, 534, 1014, 297, 1790, 534, 751, 297, 10691, 29, 549, 9, 272, 347, 3622, 63, 13243, 8, 277, 12, 3622, 354, 12, 1382, 1580, 29, 403, 12, 11109, 29, 403, 12, 1011, 576, 304, 267, 3622, 63, 1113, 275, 1056, 14, 5189, 459, 3070, 418, 267, 2467, 12, 1747, 12, 1067, 275, 1056, 14, 1556, 12, 1056, 14, 1535, 12, 1056, 14, 1100, 398, 340, 1382, 1580, 26, 288, 1382, 1580, 275, 359, 442, 8, 73, 9, 367, 284, 315, 1382, 1580, 14, 1294, 29972, 267, 1511, 63, 576, 275, 488, 267, 340, 666, 14, 362, 360, 1419, 735, 288, 1511, 63, 576, 275, 13804, 14, 3640, 8, 576, 459, 1419, 1105, 267, 340, 666, 14, 362, 360, 1100, 735, 288, 327, 14092, 283, 4159, 7, 2348, 12, 2952, 314, 1067, 315, 666, 365, 314, 1373, 687, 314, 3330, 1258, 627, 7911, 10, 340, 288, 327, 314, 922, 1437, 317, 25171, 590, 15061, 370, 1570, 314, 6339, 12, 642, 14729, 1806, 16334, 652, 14, 7205, 666, 63, 1100, 275, 13804, 14, 3640, 8, 576, 459, 1100, 1105, 288, 340, 666, 63, 1100, 14, 362, 360, 4159, 735, 355, 2150, 666, 63, 1100, 459, 4159, 418, 288, 1067, 14, 873, 8, 576, 63, 1100, 9, 398, 340, 11109, 508, 283, 1360, 356, 288, 3517, 275, 3622, 63, 1113, 14, 362, 63, 1360, 8, 1556, 12, 1747, 12, 1382, 1580, 12, 3622, 354, 12, 666, 29, 1419, 63, 576, 12, 1067, 29, 1100, 9, 288, 372, 1056, 14, 1875, 63, 1310, 8, 1360, 9, 267, 916, 11109, 508, 283, 5607, 356, 288, 11249, 275, 3622, 63, 1113, 14, 362, 63, 5607, 8, 1556, 12, 1747, 12, 1382, 1580, 12, 3622, 354, 12, 666, 29, 1419, 63, 576, 12, 1067, 29, 1100, 9, 288, 11249, 1014, 2139, 275, 4274, 2714, 13, 804, 297, 283, 3578, 15, 5607, 659, 661, 2714, 13, 4625, 297, 822, 8, 5607, 10524, 288, 372, 1056, 14, 1875, 63, 1310, 8, 5607, 12, 2323, 29, 5607, 1014, 2139, 9, 267, 587, 26, 288, 746, 4967, 14, 26871, 8, 1802, 534, 11907, 450, 83, 440, 6366, 3530, 450, 11109, 9, 339, 27721, 8648, 272, 327, 603, 10840, 14, 7475, 3778, 272, 27721, 8648, 272, 768, 4449, 26352, 3070, 15, 22091, 297, 1994, 3070, 15, 22091, 8316, 466, 23220, 515, 26, 585, 16619, 730, 534, 1014, 297, 1790, 628, 751, 531, 272, 347, 3622, 63, 22091, 8, 277, 12, 730, 12, 574, 12, 3462, 29, 6683, 12, 4569, 29, 1960, 12, 11779, 11875, 29, 16, 304, 267, 408, 714, 6896, 1435, 7688, 370, 3795, 24323, 5935, 2419, 6080, 370, 21773, 14, 267, 428, 1889, 26, 7205, 665, 4060, 307, 13, 6796, 13, 2164, 628, 9807, 3070, 15, 22091, 15, 26779, 3149, 83, 7, 450, 312, 14, 354, 7897, 288, 665, 4060, 307, 13, 6796, 13, 2164, 628, 9807, 3070, 15, 22091, 10197, 466, 2458, 83, 6, 5282, 27, 585, 2458, 83, 6, 5282, 27, 2063, 2458, 83, 6, 5282, 27, 3333, 2458, 83, 7, 450, 8892, 661, 26779, 297, 312, 14, 354, 12, 1926, 12, 1926, 2924, 3133, 398, 520, 635, 730, 26, 4473, 7203, 2943, 26, 283, 35, 364, 371, 285, 297, 283, 3034, 845, 297, 283, 3034, 3933, 297, 283, 37, 879, 969, 297, 283, 37, 879, 24, 297, 283, 14107, 1355, 297, 267, 283, 14107, 3129, 297, 283, 38, 1469, 297, 283, 41, 18, 1618, 21, 297, 283, 45, 2684, 297, 283, 4030, 7278, 297, 283, 26779, 297, 283, 9232, 1355, 297, 283, 9232, 3129, 297, 267, 283, 2160, 3263, 297, 283, 1668, 5067, 63, 20, 2223, 7, 267, 520, 635, 11779, 11875, 26, 4473, 7203, 1338, 26, 378, 334, 885, 9, 503, 413, 14, 413, 911, 5518, 314, 12701, 574, 267, 737, 314, 9048, 402, 314, 1072, 1834, 267, 408, 267, 862, 26, 288, 3462, 12, 4569, 12, 11779, 11875, 275, 1109, 8, 2063, 395, 1109, 8, 3333, 395, 2155, 8, 14864, 11875, 9, 288, 24323, 275, 1218, 5281, 600, 9654, 316, 8, 355, 730, 12, 574, 29, 585, 12, 1475, 534, 4524, 297, 3462, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
imatge-upc/saliency
shallow/train.py
2
3064
# add to kfkd.py from lasagne import layers from lasagne.updates import nesterov_momentum from nolearn.lasagne import NeuralNet,BatchIterator import os import numpy as np from sklearn.utils import shuffle import cPickle as pickle import matplotlib.pyplot as plt import Image import ImageOps from scipy import misc import scipy.io import theano def load(): f = file('data_Salicon_T.cPickle', 'rb') loaded_obj = pickle.load(f) f.close() X, y = loaded_obj return X, y def float32(k): return np.cast['float32'](k) class AdjustVariable(object): def __init__(self, name, start=0.03, stop=0.001): self.name = name self.start, self.stop = start, stop self.ls = None def __call__(self, nn, train_history): if self.ls is None: self.ls = np.linspace(self.start, self.stop, nn.max_epochs) epoch = train_history[-1]['epoch'] new_value = float32(self.ls[epoch - 1]) getattr(nn, self.name).set_value(new_value) class FlipBatchIterator(BatchIterator): def transform(self, Xb, yb): Xb, yb = super(FlipBatchIterator, self).transform(Xb, yb) # Flip half of the images in this batch at random: bs = Xb.shape[0] indices = np.random.choice(bs, bs / 2, replace=False) Xb[indices] = Xb[indices, :, :, ::-1] tmp = yb[indices].reshape(bs/2,1,48,48) mirror = tmp[ :,:,:, ::-1] yb[indices] = mirror.reshape(bs/2,48*48) return Xb, yb net2 = NeuralNet( layers=[ ('input', layers.InputLayer), ('conv1', layers.Conv2DLayer), ('pool1', layers.MaxPool2DLayer), ('conv2', layers.Conv2DLayer), ('pool2', layers.MaxPool2DLayer), ('conv3', layers.Conv2DLayer), ('pool3', layers.MaxPool2DLayer), ('hidden4', layers.DenseLayer), ('maxout6',layers.FeaturePoolLayer), ('output', layers.DenseLayer), ], input_shape=(None, 3, 96, 96), conv1_num_filters=32, conv1_filter_size=(5, 5), pool1_pool_size=(2, 2), conv2_num_filters=64, conv2_filter_size=(3, 3), pool2_pool_size=(2, 2), conv3_num_filters=64, conv3_filter_size=(3, 3), pool3_pool_size=(2, 2), hidden4_num_units=48*48*2, maxout6_pool_size=2,output_num_units=48*48,output_nonlinearity=None, update_learning_rate=theano.shared(float32(0.05)), update_momentum=theano.shared(float32(0.9)), regression=True, on_epoch_finished=[ AdjustVariable('update_learning_rate', start=0.05, stop=0.0001), AdjustVariable('update_momentum', start=0.9, stop=0.999), ], batch_iterator_train=FlipBatchIterator(batch_size=128), max_epochs=1200, verbose=1, ) X, y = load() print("X.shape == {}; X.min == {:.3f}; X.max == {:.3f}".format( X.shape, X.min(), X.max())) print("y.shape == {}; y.min == {:.3f}; y.max == {:.3f}".format( y.shape, y.min(), y.max())) X = X.astype(np.float32) y = y.astype(np.float32) net.fit(X, y) with open('JuntingNet_SALICON.pickle', 'wb') as f: pickle.dump(net2, f, -1)
mit
[ 3, 1050, 370, 1022, 9010, 68, 14, 647, 199, 504, 23325, 29575, 492, 9393, 199, 504, 23325, 29575, 14, 7618, 492, 302, 397, 24208, 86, 63, 25710, 199, 504, 949, 4643, 14, 12536, 29575, 492, 5612, 4889, 2480, 12, 8842, 3585, 199, 646, 747, 199, 646, 2680, 465, 980, 199, 504, 6357, 14, 1208, 492, 13031, 199, 646, 17572, 465, 5927, 199, 646, 8027, 14, 13563, 465, 4488, 199, 646, 6047, 199, 646, 6047, 16452, 199, 504, 7026, 492, 18576, 199, 646, 7026, 14, 2308, 199, 646, 14377, 199, 199, 318, 2248, 837, 272, 289, 275, 570, 360, 576, 63, 27177, 4677, 63, 52, 14, 67, 12755, 297, 283, 4848, 358, 272, 6511, 63, 1113, 275, 5927, 14, 912, 8, 70, 9, 272, 289, 14, 1600, 342, 272, 1323, 12, 612, 275, 6511, 63, 1113, 272, 372, 1323, 12, 612, 199, 199, 318, 2069, 708, 8, 75, 304, 272, 372, 980, 14, 2931, 459, 1609, 708, 21407, 75, 9, 199, 199, 533, 26412, 2773, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 536, 12, 1343, 29, 16, 14, 1644, 12, 3631, 29, 16, 14, 4587, 304, 267, 291, 14, 354, 275, 536, 267, 291, 14, 928, 12, 291, 14, 2379, 275, 1343, 12, 3631, 267, 291, 14, 478, 275, 488, 339, 347, 636, 1250, 721, 277, 12, 11542, 12, 3560, 63, 5570, 304, 267, 340, 291, 14, 478, 365, 488, 26, 288, 291, 14, 478, 275, 980, 14, 11649, 8, 277, 14, 928, 12, 291, 14, 2379, 12, 11542, 14, 988, 63, 13161, 9, 398, 9463, 275, 3560, 63, 5570, 1988, 17, 2733, 7367, 418, 267, 892, 63, 585, 275, 2069, 708, 8, 277, 14, 478, 59, 7367, 446, 413, 566, 267, 2519, 8, 4411, 12, 291, 14, 354, 680, 409, 63, 585, 8, 1222, 63, 585, 9, 199, 199, 533, 481, 3587, 8842, 3585, 8, 8842, 3585, 304, 272, 347, 5793, 8, 277, 12, 1323, 66, 12, 612, 66, 304, 267, 1323, 66, 12, 612, 66, 275, 1613, 8, 38, 3587, 8842, 3585, 12, 291, 680, 4711, 8, 56, 66, 12, 612, 66, 9, 398, 327, 481, 3587, 12995, 402, 314, 5935, 315, 642, 3522, 737, 2196, 26, 267, 9922, 275, 1323, 66, 14, 1392, 59, 16, 61, 267, 4918, 275, 980, 14, 2355, 14, 5095, 8, 1533, 12, 9922, 1182, 499, 12, 3350, 29, 797, 9, 267, 1323, 66, 59, 4108, 61, 275, 1323, 66, 59, 4108, 12, 13785, 13785, 3800, 13, 17, 61, 267, 3529, 275, 221, 612, 66, 59, 4108, 1055, 5217, 8, 1533, 15, 18, 12, 17, 12, 2006, 12, 2006, 9, 267, 15216, 275, 3529, 59, 13785, 11941, 11941, 3800, 13, 17, 61, 267, 612, 66, 59, 4108, 61, 275, 221, 15216, 14, 5217, 8, 1533, 15, 18, 12, 2006, 10, 2006, 9, 267, 372, 1323, 66, 12, 612, 66, 421, 199, 846, 18, 275, 5612, 4889, 2480, 8, 272, 9393, 1524, 267, 661, 1210, 297, 9393, 14, 3205, 5003, 395, 267, 661, 5598, 17, 297, 9393, 14, 11596, 18, 36, 5003, 395, 267, 661, 2293, 17, 297, 9393, 14, 29883, 18, 36, 5003, 395, 267, 661, 5598, 18, 297, 9393, 14, 11596, 18, 36, 5003, 395, 267, 661, 2293, 18, 297, 9393, 14, 29883, 18, 36, 5003, 395, 267, 661, 5598, 19, 297, 9393, 14, 11596, 18, 36, 5003, 395, 267, 661, 2293, 19, 297, 9393, 14, 29883, 18, 36, 5003, 395, 267, 661, 5642, 20, 297, 9393, 14, 15327, 5003, 395, 267, 661, 988, 548, 22, 297, 4359, 14, 5968, 5453, 5003, 395, 267, 661, 1199, 297, 9393, 14, 15327, 5003, 395, 267, 2156, 272, 1324, 63, 1392, 2687, 403, 12, 650, 12, 15580, 12, 15580, 395, 272, 8260, 17, 63, 1507, 63, 4273, 29, 708, 12, 8260, 17, 63, 1541, 63, 890, 2687, 21, 12, 959, 395, 4203, 17, 63, 2293, 63, 890, 2687, 18, 12, 499, 395, 272, 8260, 18, 63, 1507, 63, 4273, 29, 772, 12, 8260, 18, 63, 1541, 63, 890, 2687, 19, 12, 650, 395, 4203, 18, 63, 2293, 63, 890, 2687, 18, 12, 499, 395, 272, 8260, 19, 63, 1507, 63, 4273, 29, 772, 12, 8260, 19, 63, 1541, 63, 890, 2687, 19, 12, 650, 395, 4203, 19, 63, 2293, 63, 890, 2687, 18, 12, 499, 395, 272, 8752, 20, 63, 1507, 63, 5260, 29, 2006, 10, 2006, 10, 18, 12, 5591, 1390, 548, 22, 63, 2293, 63, 890, 29, 18, 12, 1199, 63, 1507, 63, 5260, 29, 2006, 10, 2006, 12, 1199, 63, 2865, 30440, 29, 403, 12, 339, 1678, 63, 10546, 63, 1866, 29, 32057, 14, 5555, 8, 1609, 708, 8, 16, 14, 1717, 1826, 272, 1678, 63, 25710, 29, 32057, 14, 5555, 8, 1609, 708, 8, 16, 14, 25, 1826, 339, 10864, 29, 549, 12, 339, 641, 63, 7367, 63, 8669, 1524, 267, 26412, 2773, 360, 873, 63, 10546, 63, 1866, 297, 1343, 29, 16, 14, 1717, 12, 3631, 29, 16, 14, 4183, 395, 267, 26412, 2773, 360, 873, 63, 25710, 297, 1343, 29, 16, 14, 25, 12, 3631, 29, 16, 14, 5637, 395, 267, 2156, 272, 3522, 63, 5778, 63, 2834, 29, 38, 3587, 8842, 3585, 8, 2912, 63, 890, 29, 3933, 395, 272, 1390, 63, 13161, 29, 23781, 12, 272, 3376, 29, 17, 12, 272, 776, 199, 199, 56, 12, 612, 275, 2248, 342, 9948, 199, 1361, 480, 56, 14, 1392, 508, 27978, 1323, 14, 827, 508, 469, 14010, 19, 70, 12084, 1323, 14, 988, 508, 469, 14010, 19, 70, 5469, 908, 8, 272, 1323, 14, 1392, 12, 1323, 14, 827, 1062, 1323, 14, 988, 4059, 199, 1361, 480, 89, 14, 1392, 508, 27978, 612, 14, 827, 508, 469, 14010, 19, 70, 12084, 612, 14, 988, 508, 469, 14010, 19, 70, 5469, 908, 8, 272, 612, 14, 1392, 12, 612, 14, 827, 1062, 612, 14, 988, 4059, 199, 199, 56, 275, 1323, 14, 6041, 8, 1590, 14, 1609, 708, 9, 199, 89, 275, 612, 14, 6041, 8, 1590, 14, 1609, 708, 9, 199, 846, 14, 3269, 8, 56, 12, 612, 9, 199, 199, 1045, 1551, 360, 42, 638, 316, 2480, 63, 51, 748, 15903, 14, 8092, 297, 283, 6603, 358, 465, 289, 26, 2043, 5927, 14, 2724, 8, 846, 18, 12, 289, 12 ]
[ 1050, 370, 1022, 9010, 68, 14, 647, 199, 504, 23325, 29575, 492, 9393, 199, 504, 23325, 29575, 14, 7618, 492, 302, 397, 24208, 86, 63, 25710, 199, 504, 949, 4643, 14, 12536, 29575, 492, 5612, 4889, 2480, 12, 8842, 3585, 199, 646, 747, 199, 646, 2680, 465, 980, 199, 504, 6357, 14, 1208, 492, 13031, 199, 646, 17572, 465, 5927, 199, 646, 8027, 14, 13563, 465, 4488, 199, 646, 6047, 199, 646, 6047, 16452, 199, 504, 7026, 492, 18576, 199, 646, 7026, 14, 2308, 199, 646, 14377, 199, 199, 318, 2248, 837, 272, 289, 275, 570, 360, 576, 63, 27177, 4677, 63, 52, 14, 67, 12755, 297, 283, 4848, 358, 272, 6511, 63, 1113, 275, 5927, 14, 912, 8, 70, 9, 272, 289, 14, 1600, 342, 272, 1323, 12, 612, 275, 6511, 63, 1113, 272, 372, 1323, 12, 612, 199, 199, 318, 2069, 708, 8, 75, 304, 272, 372, 980, 14, 2931, 459, 1609, 708, 21407, 75, 9, 199, 199, 533, 26412, 2773, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 536, 12, 1343, 29, 16, 14, 1644, 12, 3631, 29, 16, 14, 4587, 304, 267, 291, 14, 354, 275, 536, 267, 291, 14, 928, 12, 291, 14, 2379, 275, 1343, 12, 3631, 267, 291, 14, 478, 275, 488, 339, 347, 636, 1250, 721, 277, 12, 11542, 12, 3560, 63, 5570, 304, 267, 340, 291, 14, 478, 365, 488, 26, 288, 291, 14, 478, 275, 980, 14, 11649, 8, 277, 14, 928, 12, 291, 14, 2379, 12, 11542, 14, 988, 63, 13161, 9, 398, 9463, 275, 3560, 63, 5570, 1988, 17, 2733, 7367, 418, 267, 892, 63, 585, 275, 2069, 708, 8, 277, 14, 478, 59, 7367, 446, 413, 566, 267, 2519, 8, 4411, 12, 291, 14, 354, 680, 409, 63, 585, 8, 1222, 63, 585, 9, 199, 199, 533, 481, 3587, 8842, 3585, 8, 8842, 3585, 304, 272, 347, 5793, 8, 277, 12, 1323, 66, 12, 612, 66, 304, 267, 1323, 66, 12, 612, 66, 275, 1613, 8, 38, 3587, 8842, 3585, 12, 291, 680, 4711, 8, 56, 66, 12, 612, 66, 9, 398, 327, 481, 3587, 12995, 402, 314, 5935, 315, 642, 3522, 737, 2196, 26, 267, 9922, 275, 1323, 66, 14, 1392, 59, 16, 61, 267, 4918, 275, 980, 14, 2355, 14, 5095, 8, 1533, 12, 9922, 1182, 499, 12, 3350, 29, 797, 9, 267, 1323, 66, 59, 4108, 61, 275, 1323, 66, 59, 4108, 12, 13785, 13785, 3800, 13, 17, 61, 267, 3529, 275, 221, 612, 66, 59, 4108, 1055, 5217, 8, 1533, 15, 18, 12, 17, 12, 2006, 12, 2006, 9, 267, 15216, 275, 3529, 59, 13785, 11941, 11941, 3800, 13, 17, 61, 267, 612, 66, 59, 4108, 61, 275, 221, 15216, 14, 5217, 8, 1533, 15, 18, 12, 2006, 10, 2006, 9, 267, 372, 1323, 66, 12, 612, 66, 421, 199, 846, 18, 275, 5612, 4889, 2480, 8, 272, 9393, 1524, 267, 661, 1210, 297, 9393, 14, 3205, 5003, 395, 267, 661, 5598, 17, 297, 9393, 14, 11596, 18, 36, 5003, 395, 267, 661, 2293, 17, 297, 9393, 14, 29883, 18, 36, 5003, 395, 267, 661, 5598, 18, 297, 9393, 14, 11596, 18, 36, 5003, 395, 267, 661, 2293, 18, 297, 9393, 14, 29883, 18, 36, 5003, 395, 267, 661, 5598, 19, 297, 9393, 14, 11596, 18, 36, 5003, 395, 267, 661, 2293, 19, 297, 9393, 14, 29883, 18, 36, 5003, 395, 267, 661, 5642, 20, 297, 9393, 14, 15327, 5003, 395, 267, 661, 988, 548, 22, 297, 4359, 14, 5968, 5453, 5003, 395, 267, 661, 1199, 297, 9393, 14, 15327, 5003, 395, 267, 2156, 272, 1324, 63, 1392, 2687, 403, 12, 650, 12, 15580, 12, 15580, 395, 272, 8260, 17, 63, 1507, 63, 4273, 29, 708, 12, 8260, 17, 63, 1541, 63, 890, 2687, 21, 12, 959, 395, 4203, 17, 63, 2293, 63, 890, 2687, 18, 12, 499, 395, 272, 8260, 18, 63, 1507, 63, 4273, 29, 772, 12, 8260, 18, 63, 1541, 63, 890, 2687, 19, 12, 650, 395, 4203, 18, 63, 2293, 63, 890, 2687, 18, 12, 499, 395, 272, 8260, 19, 63, 1507, 63, 4273, 29, 772, 12, 8260, 19, 63, 1541, 63, 890, 2687, 19, 12, 650, 395, 4203, 19, 63, 2293, 63, 890, 2687, 18, 12, 499, 395, 272, 8752, 20, 63, 1507, 63, 5260, 29, 2006, 10, 2006, 10, 18, 12, 5591, 1390, 548, 22, 63, 2293, 63, 890, 29, 18, 12, 1199, 63, 1507, 63, 5260, 29, 2006, 10, 2006, 12, 1199, 63, 2865, 30440, 29, 403, 12, 339, 1678, 63, 10546, 63, 1866, 29, 32057, 14, 5555, 8, 1609, 708, 8, 16, 14, 1717, 1826, 272, 1678, 63, 25710, 29, 32057, 14, 5555, 8, 1609, 708, 8, 16, 14, 25, 1826, 339, 10864, 29, 549, 12, 339, 641, 63, 7367, 63, 8669, 1524, 267, 26412, 2773, 360, 873, 63, 10546, 63, 1866, 297, 1343, 29, 16, 14, 1717, 12, 3631, 29, 16, 14, 4183, 395, 267, 26412, 2773, 360, 873, 63, 25710, 297, 1343, 29, 16, 14, 25, 12, 3631, 29, 16, 14, 5637, 395, 267, 2156, 272, 3522, 63, 5778, 63, 2834, 29, 38, 3587, 8842, 3585, 8, 2912, 63, 890, 29, 3933, 395, 272, 1390, 63, 13161, 29, 23781, 12, 272, 3376, 29, 17, 12, 272, 776, 199, 199, 56, 12, 612, 275, 2248, 342, 9948, 199, 1361, 480, 56, 14, 1392, 508, 27978, 1323, 14, 827, 508, 469, 14010, 19, 70, 12084, 1323, 14, 988, 508, 469, 14010, 19, 70, 5469, 908, 8, 272, 1323, 14, 1392, 12, 1323, 14, 827, 1062, 1323, 14, 988, 4059, 199, 1361, 480, 89, 14, 1392, 508, 27978, 612, 14, 827, 508, 469, 14010, 19, 70, 12084, 612, 14, 988, 508, 469, 14010, 19, 70, 5469, 908, 8, 272, 612, 14, 1392, 12, 612, 14, 827, 1062, 612, 14, 988, 4059, 199, 199, 56, 275, 1323, 14, 6041, 8, 1590, 14, 1609, 708, 9, 199, 89, 275, 612, 14, 6041, 8, 1590, 14, 1609, 708, 9, 199, 846, 14, 3269, 8, 56, 12, 612, 9, 199, 199, 1045, 1551, 360, 42, 638, 316, 2480, 63, 51, 748, 15903, 14, 8092, 297, 283, 6603, 358, 465, 289, 26, 2043, 5927, 14, 2724, 8, 846, 18, 12, 289, 12, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
Distrotech/intellij-community
python/helpers/pydev/pydevd_attach_to_process/winappdbg/interactive.py
102
85840
#!~/.wine/drive_c/Python25/python.exe # -*- coding: utf-8 -*- # Acknowledgements: # Nicolas Economou, for his command line debugger on which this is inspired. # http://tinyurl.com/nicolaseconomou # Copyright (c) 2009-2014, Mario Vilas # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice,this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. """ Interactive debugging console. @group Debugging: ConsoleDebugger @group Exceptions: CmdError """ from __future__ import with_statement __revision__ = "$Id$" __all__ = [ 'ConsoleDebugger', 'CmdError' ] # TODO document this module with docstrings. # TODO command to set a last error breakpoint. # TODO command to show available plugins. from winappdbg import win32 from winappdbg import compat from winappdbg.system import System from winappdbg.util import PathOperations from winappdbg.event import EventHandler, NoEvent from winappdbg.textio import HexInput, HexOutput, HexDump, CrashDump, DebugLog import os import sys import code import time import warnings import traceback # too many variables named "cmd" to have a module by the same name :P from cmd import Cmd # lazy imports readline = None #============================================================================== class DummyEvent (NoEvent): "Dummy event object used internally by L{ConsoleDebugger}." def get_pid(self): return self._pid def get_tid(self): return self._tid def get_process(self): return self._process def get_thread(self): return self._thread #============================================================================== class CmdError (Exception): """ Exception raised when a command parsing error occurs. Used internally by L{ConsoleDebugger}. """ #============================================================================== class ConsoleDebugger (Cmd, EventHandler): """ Interactive console debugger. @see: L{Debug.interactive} """ #------------------------------------------------------------------------------ # Class variables # Exception to raise when an error occurs executing a command. command_error_exception = CmdError # Milliseconds to wait for debug events in the main loop. dwMilliseconds = 100 # History file name. history_file = '.winappdbg_history' # Confirm before quitting? confirm_quit = True # Valid plugin name characters. valid_plugin_name_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXY' \ 'abcdefghijklmnopqrstuvwxy' \ '012345678' \ '_' # Names of the registers. segment_names = ( 'cs', 'ds', 'es', 'fs', 'gs' ) register_alias_64_to_32 = { 'eax':'Rax', 'ebx':'Rbx', 'ecx':'Rcx', 'edx':'Rdx', 'eip':'Rip', 'ebp':'Rbp', 'esp':'Rsp', 'esi':'Rsi', 'edi':'Rdi' } register_alias_64_to_16 = { 'ax':'Rax', 'bx':'Rbx', 'cx':'Rcx', 'dx':'Rdx' } register_alias_64_to_8_low = { 'al':'Rax', 'bl':'Rbx', 'cl':'Rcx', 'dl':'Rdx' } register_alias_64_to_8_high = { 'ah':'Rax', 'bh':'Rbx', 'ch':'Rcx', 'dh':'Rdx' } register_alias_32_to_16 = { 'ax':'Eax', 'bx':'Ebx', 'cx':'Ecx', 'dx':'Edx' } register_alias_32_to_8_low = { 'al':'Eax', 'bl':'Ebx', 'cl':'Ecx', 'dl':'Edx' } register_alias_32_to_8_high = { 'ah':'Eax', 'bh':'Ebx', 'ch':'Ecx', 'dh':'Edx' } register_aliases_full_32 = list(segment_names) register_aliases_full_32.extend(compat.iterkeys(register_alias_32_to_16)) register_aliases_full_32.extend(compat.iterkeys(register_alias_32_to_8_low)) register_aliases_full_32.extend(compat.iterkeys(register_alias_32_to_8_high)) register_aliases_full_32 = tuple(register_aliases_full_32) register_aliases_full_64 = list(segment_names) register_aliases_full_64.extend(compat.iterkeys(register_alias_64_to_32)) register_aliases_full_64.extend(compat.iterkeys(register_alias_64_to_16)) register_aliases_full_64.extend(compat.iterkeys(register_alias_64_to_8_low)) register_aliases_full_64.extend(compat.iterkeys(register_alias_64_to_8_high)) register_aliases_full_64 = tuple(register_aliases_full_64) # Names of the control flow instructions. jump_instructions = ( 'jmp', 'jecxz', 'jcxz', 'ja', 'jnbe', 'jae', 'jnb', 'jb', 'jnae', 'jbe', 'jna', 'jc', 'je', 'jz', 'jnc', 'jne', 'jnz', 'jnp', 'jpo', 'jp', 'jpe', 'jg', 'jnle', 'jge', 'jnl', 'jl', 'jnge', 'jle', 'jng', 'jno', 'jns', 'jo', 'js' ) call_instructions = ( 'call', 'ret', 'retn' ) loop_instructions = ( 'loop', 'loopz', 'loopnz', 'loope', 'loopne' ) control_flow_instructions = call_instructions + loop_instructions + \ jump_instructions #------------------------------------------------------------------------------ # Instance variables def __init__(self): """ Interactive console debugger. @see: L{Debug.interactive} """ Cmd.__init__(self) EventHandler.__init__(self) # Quit the debugger when True. self.debuggerExit = False # Full path to the history file. self.history_file_full_path = None # Last executed command. self.__lastcmd = "" #------------------------------------------------------------------------------ # Debugger # Use this Debug object. def start_using_debugger(self, debug): # Clear the previous Debug object. self.stop_using_debugger() # Keep the Debug object. self.debug = debug # Set ourselves as the event handler for the debugger. self.prevHandler = debug.set_event_handler(self) # Stop using the Debug object given by start_using_debugger(). # Circular references must be removed, or the destructors never get called. def stop_using_debugger(self): if hasattr(self, 'debug'): debug = self.debug debug.set_event_handler(self.prevHandler) del self.prevHandler del self.debug return debug return None # Destroy the Debug object. def destroy_debugger(self, autodetach = True): debug = self.stop_using_debugger() if debug is not None: if not autodetach: debug.kill_all(bIgnoreExceptions=True) debug.lastEvent = None debug.stop() del debug @property def lastEvent(self): return self.debug.lastEvent def set_fake_last_event(self, process): if self.lastEvent is None: self.debug.lastEvent = DummyEvent(self.debug) self.debug.lastEvent._process = process self.debug.lastEvent._thread = process.get_thread( process.get_thread_ids()[0]) self.debug.lastEvent._pid = process.get_pid() self.debug.lastEvent._tid = self.lastEvent._thread.get_tid() #------------------------------------------------------------------------------ # Input # TODO # * try to guess breakpoints when insufficient data is given # * child Cmd instances will have to be used for other prompts, for example # when assembling or editing memory - it may also be a good idea to think # if it's possible to make the main Cmd instance also a child, instead of # the debugger itself - probably the same goes for the EventHandler, maybe # it can be used as a contained object rather than a parent class. # Join a token list into an argument string. def join_tokens(self, token_list): return self.debug.system.argv_to_cmdline(token_list) # Split an argument string into a token list. def split_tokens(self, arg, min_count = 0, max_count = None): token_list = self.debug.system.cmdline_to_argv(arg) if len(token_list) < min_count: raise CmdError("missing parameters.") if max_count and len(token_list) > max_count: raise CmdError("too many parameters.") return token_list # Token is a thread ID or name. def input_thread(self, token): targets = self.input_thread_list( [token] ) if len(targets) == 0: raise CmdError("missing thread name or ID") if len(targets) > 1: msg = "more than one thread with that name:\n" for tid in targets: msg += "\t%d\n" % tid msg = msg[:-len("\n")] raise CmdError(msg) return targets[0] # Token list is a list of thread IDs or names. def input_thread_list(self, token_list): targets = set() system = self.debug.system for token in token_list: try: tid = self.input_integer(token) if not system.has_thread(tid): raise CmdError("thread not found (%d)" % tid) targets.add(tid) except ValueError: found = set() for process in system.iter_processes(): found.update( system.find_threads_by_name(token) ) if not found: raise CmdError("thread not found (%s)" % token) for thread in found: targets.add( thread.get_tid() ) targets = list(targets) targets.sort() return targets # Token is a process ID or name. def input_process(self, token): targets = self.input_process_list( [token] ) if len(targets) == 0: raise CmdError("missing process name or ID") if len(targets) > 1: msg = "more than one process with that name:\n" for pid in targets: msg += "\t%d\n" % pid msg = msg[:-len("\n")] raise CmdError(msg) return targets[0] # Token list is a list of process IDs or names. def input_process_list(self, token_list): targets = set() system = self.debug.system for token in token_list: try: pid = self.input_integer(token) if not system.has_process(pid): raise CmdError("process not found (%d)" % pid) targets.add(pid) except ValueError: found = system.find_processes_by_filename(token) if not found: raise CmdError("process not found (%s)" % token) for (process, _) in found: targets.add( process.get_pid() ) targets = list(targets) targets.sort() return targets # Token is a command line to execute. def input_command_line(self, command_line): argv = self.debug.system.cmdline_to_argv(command_line) if not argv: raise CmdError("missing command line to execute") fname = argv[0] if not os.path.exists(fname): try: fname, _ = win32.SearchPath(None, fname, '.exe') except WindowsError: raise CmdError("file not found: %s" % fname) argv[0] = fname command_line = self.debug.system.argv_to_cmdline(argv) return command_line # Token is an integer. # Only hexadecimal format is supported. def input_hexadecimal_integer(self, token): return int(token, 0x10) # Token is an integer. # It can be in any supported format. def input_integer(self, token): return HexInput.integer(token) ## input_integer = input_hexadecimal_integer # Token is an address. # The address can be a integer, a label or a register. def input_address(self, token, pid = None, tid = None): address = None if self.is_register(token): if tid is None: if self.lastEvent is None or pid != self.lastEvent.get_pid(): msg = "can't resolve register (%s) for unknown thread" raise CmdError(msg % token) tid = self.lastEvent.get_tid() address = self.input_register(token, tid) if address is None: try: address = self.input_hexadecimal_integer(token) except ValueError: if pid is None: if self.lastEvent is None: raise CmdError("no current process set") process = self.lastEvent.get_process() elif self.lastEvent is not None and pid == self.lastEvent.get_pid(): process = self.lastEvent.get_process() else: try: process = self.debug.system.get_process(pid) except KeyError: raise CmdError("process not found (%d)" % pid) try: address = process.resolve_label(token) except Exception: raise CmdError("unknown address (%s)" % token) return address # Token is an address range, or a single address. # The addresses can be integers, labels or registers. def input_address_range(self, token_list, pid = None, tid = None): if len(token_list) == 2: token_1, token_2 = token_list address = self.input_address(token_1, pid, tid) try: size = self.input_integer(token_2) except ValueError: raise CmdError("bad address range: %s %s" % (token_1, token_2)) elif len(token_list) == 1: token = token_list[0] if '-' in token: try: token_1, token_2 = token.split('-') except Exception: raise CmdError("bad address range: %s" % token) address = self.input_address(token_1, pid, tid) size = self.input_address(token_2, pid, tid) - address else: address = self.input_address(token, pid, tid) size = None return address, size # XXX TODO # Support non-integer registers here. def is_register(self, token): if win32.arch == 'i386': if token in self.register_aliases_full_32: return True token = token.title() for (name, typ) in win32.CONTEXT._fields_: if name == token: return win32.sizeof(typ) == win32.sizeof(win32.DWORD) elif win32.arch == 'amd64': if token in self.register_aliases_full_64: return True token = token.title() for (name, typ) in win32.CONTEXT._fields_: if name == token: return win32.sizeof(typ) == win32.sizeof(win32.DWORD64) return False # The token is a register name. # Returns None if no register name is matched. def input_register(self, token, tid = None): if tid is None: if self.lastEvent is None: raise CmdError("no current process set") thread = self.lastEvent.get_thread() else: thread = self.debug.system.get_thread(tid) ctx = thread.get_context() token = token.lower() title = token.title() if title in ctx: return ctx.get(title) # eax -> Eax if ctx.arch == 'i386': if token in self.segment_names: return ctx.get( 'Seg%s' % title ) # cs -> SegCs if token in self.register_alias_32_to_16: return ctx.get( self.register_alias_32_to_16[token] ) & 0xFFFF if token in self.register_alias_32_to_8_low: return ctx.get( self.register_alias_32_to_8_low[token] ) & 0xFF if token in self.register_alias_32_to_8_high: return (ctx.get( self.register_alias_32_to_8_high[token] ) & 0xFF00) >> 8 elif ctx.arch == 'amd64': if token in self.segment_names: return ctx.get( 'Seg%s' % title ) # cs -> SegCs if token in self.register_alias_64_to_32: return ctx.get( self.register_alias_64_to_32[token] ) & 0xFFFFFFFF if token in self.register_alias_64_to_16: return ctx.get( self.register_alias_64_to_16[token] ) & 0xFFFF if token in self.register_alias_64_to_8_low: return ctx.get( self.register_alias_64_to_8_low[token] ) & 0xFF if token in self.register_alias_64_to_8_high: return (ctx.get( self.register_alias_64_to_8_high[token] ) & 0xFF00) >> 8 return None # Token list contains an address or address range. # The prefix is also parsed looking for process and thread IDs. def input_full_address_range(self, token_list): pid, tid = self.get_process_and_thread_ids_from_prefix() address, size = self.input_address_range(token_list, pid, tid) return pid, tid, address, size # Token list contains a breakpoint. def input_breakpoint(self, token_list): pid, tid, address, size = self.input_full_address_range(token_list) if not self.debug.is_debugee(pid): raise CmdError("target process is not being debugged") return pid, tid, address, size # Token list contains a memory address, and optional size and process. # Sets the results as the default for the next display command. def input_display(self, token_list, default_size = 64): pid, tid, address, size = self.input_full_address_range(token_list) if not size: size = default_size next_address = HexOutput.integer(address + size) self.default_display_target = next_address return pid, tid, address, size #------------------------------------------------------------------------------ # Output # Tell the user a module was loaded. def print_module_load(self, event): mod = event.get_module() base = mod.get_base() name = mod.get_filename() if not name: name = '' msg = "Loaded module (%s) %s" msg = msg % (HexDump.address(base), name) print(msg) # Tell the user a module was unloaded. def print_module_unload(self, event): mod = event.get_module() base = mod.get_base() name = mod.get_filename() if not name: name = '' msg = "Unloaded module (%s) %s" msg = msg % (HexDump.address(base), name) print(msg) # Tell the user a process was started. def print_process_start(self, event): pid = event.get_pid() start = event.get_start_address() if start: start = HexOutput.address(start) print("Started process %d at %s" % (pid, start)) else: print("Attached to process %d" % pid) # Tell the user a thread was started. def print_thread_start(self, event): tid = event.get_tid() start = event.get_start_address() if start: with warnings.catch_warnings(): warnings.simplefilter("ignore") start = event.get_process().get_label_at_address(start) print("Started thread %d at %s" % (tid, start)) else: print("Attached to thread %d" % tid) # Tell the user a process has finished. def print_process_end(self, event): pid = event.get_pid() code = event.get_exit_code() print("Process %d terminated, exit code %d" % (pid, code)) # Tell the user a thread has finished. def print_thread_end(self, event): tid = event.get_tid() code = event.get_exit_code() print("Thread %d terminated, exit code %d" % (tid, code)) # Print(debug strings. def print_debug_string(self, event): tid = event.get_tid() string = event.get_debug_string() print("Thread %d says: %r" % (tid, string)) # Inform the user of any other debugging event. def print_event(self, event): code = HexDump.integer( event.get_event_code() ) name = event.get_event_name() desc = event.get_event_description() if code in desc: print('') print("%s: %s" % (name, desc)) else: print('') print("%s (%s): %s" % (name, code, desc)) self.print_event_location(event) # Stop on exceptions and prompt for commands. def print_exception(self, event): address = HexDump.address( event.get_exception_address() ) code = HexDump.integer( event.get_exception_code() ) desc = event.get_exception_description() if event.is_first_chance(): chance = 'first' else: chance = 'second' if code in desc: msg = "%s at address %s (%s chance)" % (desc, address, chance) else: msg = "%s (%s) at address %s (%s chance)" % (desc, code, address, chance) print('') print(msg) self.print_event_location(event) # Show the current location in the code. def print_event_location(self, event): process = event.get_process() thread = event.get_thread() self.print_current_location(process, thread) # Show the current location in the code. def print_breakpoint_location(self, event): process = event.get_process() thread = event.get_thread() pc = event.get_exception_address() self.print_current_location(process, thread, pc) # Show the current location in any process and thread. def print_current_location(self, process = None, thread = None, pc = None): if not process: if self.lastEvent is None: raise CmdError("no current process set") process = self.lastEvent.get_process() if not thread: if self.lastEvent is None: raise CmdError("no current process set") thread = self.lastEvent.get_thread() thread.suspend() try: if pc is None: pc = thread.get_pc() ctx = thread.get_context() finally: thread.resume() label = process.get_label_at_address(pc) try: disasm = process.disassemble(pc, 15) except WindowsError: disasm = None except NotImplementedError: disasm = None print('') print(CrashDump.dump_registers(ctx),) print("%s:" % label) if disasm: print(CrashDump.dump_code_line(disasm[0], pc, bShowDump = True)) else: try: data = process.peek(pc, 15) except Exception: data = None if data: print('%s: %s' % (HexDump.address(pc), HexDump.hexblock_byte(data))) else: print('%s: ???' % HexDump.address(pc)) # Display memory contents using a given method. def print_memory_display(self, arg, method): if not arg: arg = self.default_display_target token_list = self.split_tokens(arg, 1, 2) pid, tid, address, size = self.input_display(token_list) label = self.get_process(pid).get_label_at_address(address) data = self.read_memory(address, size, pid) if data: print("%s:" % label) print(method(data, address),) #------------------------------------------------------------------------------ # Debugging # Get the process ID from the prefix or the last event. def get_process_id_from_prefix(self): if self.cmdprefix: pid = self.input_process(self.cmdprefix) else: if self.lastEvent is None: raise CmdError("no current process set") pid = self.lastEvent.get_pid() return pid # Get the thread ID from the prefix or the last event. def get_thread_id_from_prefix(self): if self.cmdprefix: tid = self.input_thread(self.cmdprefix) else: if self.lastEvent is None: raise CmdError("no current process set") tid = self.lastEvent.get_tid() return tid # Get the process from the prefix or the last event. def get_process_from_prefix(self): pid = self.get_process_id_from_prefix() return self.get_process(pid) # Get the thread from the prefix or the last event. def get_thread_from_prefix(self): tid = self.get_thread_id_from_prefix() return self.get_thread(tid) # Get the process and thread IDs from the prefix or the last event. def get_process_and_thread_ids_from_prefix(self): if self.cmdprefix: try: pid = self.input_process(self.cmdprefix) tid = None except CmdError: try: tid = self.input_thread(self.cmdprefix) pid = self.debug.system.get_thread(tid).get_pid() except CmdError: msg = "unknown process or thread (%s)" % self.cmdprefix raise CmdError(msg) else: if self.lastEvent is None: raise CmdError("no current process set") pid = self.lastEvent.get_pid() tid = self.lastEvent.get_tid() return pid, tid # Get the process and thread from the prefix or the last event. def get_process_and_thread_from_prefix(self): pid, tid = self.get_process_and_thread_ids_from_prefix() process = self.get_process(pid) thread = self.get_thread(tid) return process, thread # Get the process object. def get_process(self, pid = None): if pid is None: if self.lastEvent is None: raise CmdError("no current process set") process = self.lastEvent.get_process() elif self.lastEvent is not None and pid == self.lastEvent.get_pid(): process = self.lastEvent.get_process() else: try: process = self.debug.system.get_process(pid) except KeyError: raise CmdError("process not found (%d)" % pid) return process # Get the thread object. def get_thread(self, tid = None): if tid is None: if self.lastEvent is None: raise CmdError("no current process set") thread = self.lastEvent.get_thread() elif self.lastEvent is not None and tid == self.lastEvent.get_tid(): thread = self.lastEvent.get_thread() else: try: thread = self.debug.system.get_thread(tid) except KeyError: raise CmdError("thread not found (%d)" % tid) return thread # Read the process memory. def read_memory(self, address, size, pid = None): process = self.get_process(pid) try: data = process.peek(address, size) except WindowsError: orig_address = HexOutput.integer(address) next_address = HexOutput.integer(address + size) msg = "error reading process %d, from %s to %s (%d bytes)" msg = msg % (pid, orig_address, next_address, size) raise CmdError(msg) return data # Write the process memory. def write_memory(self, address, data, pid = None): process = self.get_process(pid) try: process.write(address, data) except WindowsError: size = len(data) orig_address = HexOutput.integer(address) next_address = HexOutput.integer(address + size) msg = "error reading process %d, from %s to %s (%d bytes)" msg = msg % (pid, orig_address, next_address, size) raise CmdError(msg) # Change a register value. def change_register(self, register, value, tid = None): # Get the thread. if tid is None: if self.lastEvent is None: raise CmdError("no current process set") thread = self.lastEvent.get_thread() else: try: thread = self.debug.system.get_thread(tid) except KeyError: raise CmdError("thread not found (%d)" % tid) # Convert the value to integer type. try: value = self.input_integer(value) except ValueError: pid = thread.get_pid() value = self.input_address(value, pid, tid) # Suspend the thread. # The finally clause ensures the thread is resumed before returning. thread.suspend() try: # Get the current context. ctx = thread.get_context() # Register name matching is case insensitive. register = register.lower() # Integer 32 bits registers. if register in self.register_names: register = register.title() # eax -> Eax # Segment (16 bit) registers. if register in self.segment_names: register = 'Seg%s' % register.title() # cs -> SegCs value = value & 0x0000FFFF # Integer 16 bits registers. if register in self.register_alias_16: register = self.register_alias_16[register] previous = ctx.get(register) & 0xFFFF0000 value = (value & 0x0000FFFF) | previous # Integer 8 bits registers (low part). if register in self.register_alias_8_low: register = self.register_alias_8_low[register] previous = ctx.get(register) % 0xFFFFFF00 value = (value & 0x000000FF) | previous # Integer 8 bits registers (high part). if register in self.register_alias_8_high: register = self.register_alias_8_high[register] previous = ctx.get(register) % 0xFFFF00FF value = ((value & 0x000000FF) << 8) | previous # Set the new context. ctx.__setitem__(register, value) thread.set_context(ctx) # Resume the thread. finally: thread.resume() # Very crude way to find data within the process memory. # TODO: Perhaps pfind.py can be integrated here instead. def find_in_memory(self, query, process): for mbi in process.get_memory_map(): if mbi.State != win32.MEM_COMMIT or mbi.Protect & win32.PAGE_GUARD: continue address = mbi.BaseAddress size = mbi.RegionSize try: data = process.read(address, size) except WindowsError: msg = "*** Warning: read error at address %s" msg = msg % HexDump.address(address) print(msg) width = min(len(query), 16) p = data.find(query) while p >= 0: q = p + len(query) d = data[ p : min(q, p + width) ] h = HexDump.hexline(d, width = width) a = HexDump.address(address + p) print("%s: %s" % (a, h)) p = data.find(query, q) # Kill a process. def kill_process(self, pid): process = self.debug.system.get_process(pid) try: process.kill() if self.debug.is_debugee(pid): self.debug.detach(pid) print("Killed process (%d)" % pid) except Exception: print("Error trying to kill process (%d)" % pid) # Kill a thread. def kill_thread(self, tid): thread = self.debug.system.get_thread(tid) try: thread.kill() process = thread.get_process() pid = process.get_pid() if self.debug.is_debugee(pid) and not process.is_alive(): self.debug.detach(pid) print("Killed thread (%d)" % tid) except Exception: print("Error trying to kill thread (%d)" % tid) #------------------------------------------------------------------------------ # Command prompt input # Prompt the user for commands. def prompt_user(self): while not self.debuggerExit: try: self.cmdloop() break except CmdError: e = sys.exc_info()[1] print("*** Error: %s" % str(e)) except Exception: traceback.print_exc() ## self.debuggerExit = True # Prompt the user for a YES/NO kind of question. def ask_user(self, msg, prompt = "Are you sure? (y/N): "): print(msg) answer = raw_input(prompt) answer = answer.strip()[:1].lower() return answer == 'y' # Autocomplete the given command when not ambiguous. # Convert it to lowercase (so commands are seen as case insensitive). def autocomplete(self, cmd): cmd = cmd.lower() completed = self.completenames(cmd) if len(completed) == 1: cmd = completed[0] return cmd # Get the help text for the given list of command methods. # Note it's NOT a list of commands, but a list of actual method names. # Each line of text is stripped and all lines are sorted. # Repeated text lines are removed. # Returns a single, possibly multiline, string. def get_help(self, commands): msg = set() for name in commands: if name != 'do_help': try: doc = getattr(self, name).__doc__.split('\n') except Exception: return ( "No help available when Python" " is run with the -OO switch." ) for x in doc: x = x.strip() if x: msg.add(' %s' % x) msg = list(msg) msg.sort() msg = '\n'.join(msg) return msg # Parse the prefix and remove it from the command line. def split_prefix(self, line): prefix = None if line.startswith('~'): pos = line.find(' ') if pos == 1: pos = line.find(' ', pos + 1) if not pos < 0: prefix = line[ 1 : pos ].strip() line = line[ pos : ].strip() return prefix, line #------------------------------------------------------------------------------ # Cmd() hacks # Header for help page. doc_header = 'Available commands (type help * or help <command>)' ## # Read and write directly to stdin and stdout. ## # This prevents the use of raw_input and print. ## use_rawinput = False @property def prompt(self): if self.lastEvent: pid = self.lastEvent.get_pid() tid = self.lastEvent.get_tid() if self.debug.is_debugee(pid): ## return '~%d(%d)> ' % (tid, pid) return '%d:%d> ' % (pid, tid) return '> ' # Return a sorted list of method names. # Only returns the methods that implement commands. def get_names(self): names = Cmd.get_names(self) names = [ x for x in set(names) if x.startswith('do_') ] names.sort() return names # Automatically autocomplete commands, even if Tab wasn't pressed. # The prefix is removed from the line and stored in self.cmdprefix. # Also implement the commands that consist of a symbol character. def parseline(self, line): self.cmdprefix, line = self.split_prefix(line) line = line.strip() if line: if line[0] == '.': line = 'plugin ' + line[1:] elif line[0] == '#': line = 'python ' + line[1:] cmd, arg, line = Cmd.parseline(self, line) if cmd: cmd = self.autocomplete(cmd) return cmd, arg, line ## # Don't repeat the last executed command. ## def emptyline(self): ## pass # Reset the defaults for some commands. def preloop(self): self.default_disasm_target = 'eip' self.default_display_target = 'eip' self.last_display_command = self.do_db # Put the prefix back in the command line. def get_lastcmd(self): return self.__lastcmd def set_lastcmd(self, lastcmd): if self.cmdprefix: lastcmd = '~%s %s' % (self.cmdprefix, lastcmd) self.__lastcmd = lastcmd lastcmd = property(get_lastcmd, set_lastcmd) # Quit the command prompt if the debuggerExit flag is on. def postcmd(self, stop, line): return stop or self.debuggerExit #------------------------------------------------------------------------------ # Commands # Each command contains a docstring with it's help text. # The help text consist of independent text lines, # where each line shows a command and it's parameters. # Each command method has the help message for itself and all it's aliases. # Only the docstring for the "help" command is shown as-is. # NOTE: Command methods MUST be all lowercase! # Extended help command. def do_help(self, arg): """ ? - show the list of available commands ? * - show help for all commands ? <command> [command...] - show help for the given command(s) help - show the list of available commands help * - show help for all commands help <command> [command...] - show help for the given command(s) """ if not arg: Cmd.do_help(self, arg) elif arg in ('?', 'help'): # An easter egg :) print(" Help! I need somebody...") print(" Help! Not just anybody...") print(" Help! You know, I need someone...") print(" Heeelp!") else: if arg == '*': commands = self.get_names() commands = [ x for x in commands if x.startswith('do_') ] else: commands = set() for x in arg.split(' '): x = x.strip() if x: for n in self.completenames(x): commands.add( 'do_%s' % n ) commands = list(commands) commands.sort() print(self.get_help(commands)) def do_shell(self, arg): """ ! - spawn a system shell shell - spawn a system shell ! <command> [arguments...] - execute a single shell command shell <command> [arguments...] - execute a single shell command """ if self.cmdprefix: raise CmdError("prefix not allowed") # Try to use the environment to locate cmd.exe. # If not found, it's usually OK to just use the filename, # since cmd.exe is one of those "magic" programs that # can be automatically found by CreateProcess. shell = os.getenv('ComSpec', 'cmd.exe') # When given a command, run it and return. # When no command is given, spawn a shell. if arg: arg = '%s /c %s' % (shell, arg) else: arg = shell process = self.debug.system.start_process(arg, bConsole = True) process.wait() # This hack fixes a bug in Python, the interpreter console is closing the # stdin pipe when calling the exit() function (Ctrl+Z seems to work fine). class _PythonExit(object): def __repr__(self): return "Use exit() or Ctrl-Z plus Return to exit" def __call__(self): raise SystemExit() _python_exit = _PythonExit() # Spawns a Python shell with some handy local variables and the winappdbg # module already imported. Also the console banner is improved. def _spawn_python_shell(self, arg): import winappdbg banner = ('Python %s on %s\nType "help", "copyright", ' '"credits" or "license" for more information.\n') platform = winappdbg.version.lower() platform = 'WinAppDbg %s' % platform banner = banner % (sys.version, platform) local = {} local.update(__builtins__) local.update({ '__name__' : '__console__', '__doc__' : None, 'exit' : self._python_exit, 'self' : self, 'arg' : arg, 'winappdbg' : winappdbg, }) try: code.interact(banner=banner, local=local) except SystemExit: # We need to catch it so it doesn't kill our program. pass def do_python(self, arg): """ # - spawn a python interpreter python - spawn a python interpreter # <statement> - execute a single python statement python <statement> - execute a single python statement """ if self.cmdprefix: raise CmdError("prefix not allowed") # When given a Python statement, execute it directly. if arg: try: compat.exec_(arg, globals(), locals()) except Exception: traceback.print_exc() # When no statement is given, spawn a Python interpreter. else: try: self._spawn_python_shell(arg) except Exception: e = sys.exc_info()[1] raise CmdError( "unhandled exception when running Python console: %s" % e) # The plugins interface is quite simple. # # Just place a .py file with the plugin name in the "plugins" folder, # for example "do_example.py" would implement the "example" command. # # The plugin must have a function named "do", which implements the # command functionality exactly like the do_* methods of Cmd instances. # # The docstring for the "do" function will be parsed exactly like # one of the debugger's commands - that is, each line is treated # independently. # def do_plugin(self, arg): """ [~prefix] .<name> [arguments] - run a plugin command [~prefix] plugin <name> [arguments] - run a plugin command """ pos = arg.find(' ') if pos < 0: name = arg arg = '' else: name = arg[:pos] arg = arg[pos:].strip() if not name: raise CmdError("missing plugin name") for c in name: if c not in self.valid_plugin_name_chars: raise CmdError("invalid plugin name: %r" % name) name = 'winappdbg.plugins.do_%s' % name try: plugin = __import__(name) components = name.split('.') for comp in components[1:]: plugin = getattr(plugin, comp) reload(plugin) except ImportError: raise CmdError("plugin not found: %s" % name) try: return plugin.do(self, arg) except CmdError: raise except Exception: e = sys.exc_info()[1] ## traceback.print_exc(e) # XXX DEBUG raise CmdError("unhandled exception in plugin: %s" % e) def do_quit(self, arg): """ quit - close the debugging session q - close the debugging session """ if self.cmdprefix: raise CmdError("prefix not allowed") if arg: raise CmdError("too many arguments") if self.confirm_quit: count = self.debug.get_debugee_count() if count > 0: if count == 1: msg = "There's a program still running." else: msg = "There are %s programs still running." % count if not self.ask_user(msg): return False self.debuggerExit = True return True do_q = do_quit def do_attach(self, arg): """ attach <target> [target...] - attach to the given process(es) """ if self.cmdprefix: raise CmdError("prefix not allowed") targets = self.input_process_list( self.split_tokens(arg, 1) ) if not targets: print("Error: missing parameters") else: debug = self.debug for pid in targets: try: debug.attach(pid) print("Attached to process (%d)" % pid) except Exception: print("Error: can't attach to process (%d)" % pid) def do_detach(self, arg): """ [~process] detach - detach from the current process detach - detach from the current process detach <target> [target...] - detach from the given process(es) """ debug = self.debug token_list = self.split_tokens(arg) if self.cmdprefix: token_list.insert(0, self.cmdprefix) targets = self.input_process_list(token_list) if not targets: if self.lastEvent is None: raise CmdError("no current process set") targets = [ self.lastEvent.get_pid() ] for pid in targets: try: debug.detach(pid) print("Detached from process (%d)" % pid) except Exception: print("Error: can't detach from process (%d)" % pid) def do_windowed(self, arg): """ windowed <target> [arguments...] - run a windowed program for debugging """ if self.cmdprefix: raise CmdError("prefix not allowed") cmdline = self.input_command_line(arg) try: process = self.debug.execl(arg, bConsole = False, bFollow = self.options.follow) print("Spawned process (%d)" % process.get_pid()) except Exception: raise CmdError("can't execute") self.set_fake_last_event(process) def do_console(self, arg): """ console <target> [arguments...] - run a console program for debugging """ if self.cmdprefix: raise CmdError("prefix not allowed") cmdline = self.input_command_line(arg) try: process = self.debug.execl(arg, bConsole = True, bFollow = self.options.follow) print("Spawned process (%d)" % process.get_pid()) except Exception: raise CmdError("can't execute") self.set_fake_last_event(process) def do_continue(self, arg): """ continue - continue execution g - continue execution go - continue execution """ if self.cmdprefix: raise CmdError("prefix not allowed") if arg: raise CmdError("too many arguments") if self.debug.get_debugee_count() > 0: return True do_g = do_continue do_go = do_continue def do_gh(self, arg): """ gh - go with exception handled """ if self.cmdprefix: raise CmdError("prefix not allowed") if arg: raise CmdError("too many arguments") if self.lastEvent: self.lastEvent.continueStatus = win32.DBG_EXCEPTION_HANDLED return self.do_go(arg) def do_gn(self, arg): """ gn - go with exception not handled """ if self.cmdprefix: raise CmdError("prefix not allowed") if arg: raise CmdError("too many arguments") if self.lastEvent: self.lastEvent.continueStatus = win32.DBG_EXCEPTION_NOT_HANDLED return self.do_go(arg) def do_refresh(self, arg): """ refresh - refresh the list of running processes and threads [~process] refresh - refresh the list of running threads """ if arg: raise CmdError("too many arguments") if self.cmdprefix: process = self.get_process_from_prefix() process.scan() else: self.debug.system.scan() def do_processlist(self, arg): """ pl - show the processes being debugged processlist - show the processes being debugged """ if self.cmdprefix: raise CmdError("prefix not allowed") if arg: raise CmdError("too many arguments") system = self.debug.system pid_list = self.debug.get_debugee_pids() if pid_list: print("Process ID File name") for pid in pid_list: if pid == 0: filename = "System Idle Process" elif pid == 4: filename = "System" else: filename = system.get_process(pid).get_filename() filename = PathOperations.pathname_to_filename(filename) print("%-12d %s" % (pid, filename)) do_pl = do_processlist def do_threadlist(self, arg): """ tl - show the threads being debugged threadlist - show the threads being debugged """ if arg: raise CmdError("too many arguments") if self.cmdprefix: process = self.get_process_from_prefix() for thread in process.iter_threads(): tid = thread.get_tid() name = thread.get_name() print("%-12d %s" % (tid, name)) else: system = self.debug.system pid_list = self.debug.get_debugee_pids() if pid_list: print("Thread ID Thread name") for pid in pid_list: process = system.get_process(pid) for thread in process.iter_threads(): tid = thread.get_tid() name = thread.get_name() print("%-12d %s" % (tid, name)) do_tl = do_threadlist def do_kill(self, arg): """ [~process] kill - kill a process [~thread] kill - kill a thread kill - kill the current process kill * - kill all debugged processes kill <processes and/or threads...> - kill the given processes and threads """ if arg: if arg == '*': target_pids = self.debug.get_debugee_pids() target_tids = list() else: target_pids = set() target_tids = set() if self.cmdprefix: pid, tid = self.get_process_and_thread_ids_from_prefix() if tid is None: target_tids.add(tid) else: target_pids.add(pid) for token in self.split_tokens(arg): try: pid = self.input_process(token) target_pids.add(pid) except CmdError: try: tid = self.input_process(token) target_pids.add(pid) except CmdError: msg = "unknown process or thread (%s)" % token raise CmdError(msg) target_pids = list(target_pids) target_tids = list(target_tids) target_pids.sort() target_tids.sort() msg = "You are about to kill %d processes and %d threads." msg = msg % ( len(target_pids), len(target_tids) ) if self.ask_user(msg): for pid in target_pids: self.kill_process(pid) for tid in target_tids: self.kill_thread(tid) else: if self.cmdprefix: pid, tid = self.get_process_and_thread_ids_from_prefix() if tid is None: if self.lastEvent is not None and pid == self.lastEvent.get_pid(): msg = "You are about to kill the current process." else: msg = "You are about to kill process %d." % pid if self.ask_user(msg): self.kill_process(pid) else: if self.lastEvent is not None and tid == self.lastEvent.get_tid(): msg = "You are about to kill the current thread." else: msg = "You are about to kill thread %d." % tid if self.ask_user(msg): self.kill_thread(tid) else: if self.lastEvent is None: raise CmdError("no current process set") pid = self.lastEvent.get_pid() if self.ask_user("You are about to kill the current process."): self.kill_process(pid) # TODO: create hidden threads using undocumented API calls. def do_modload(self, arg): """ [~process] modload <filename.dll> - load a DLL module """ filename = self.split_tokens(arg, 1, 1)[0] process = self.get_process_from_prefix() try: process.inject_dll(filename, bWait=False) except RuntimeError: print("Can't inject module: %r" % filename) # TODO: modunload def do_stack(self, arg): """ [~thread] k - show the stack trace [~thread] stack - show the stack trace """ if arg: # XXX TODO add depth parameter raise CmdError("too many arguments") pid, tid = self.get_process_and_thread_ids_from_prefix() process = self.get_process(pid) thread = process.get_thread(tid) try: stack_trace = thread.get_stack_trace_with_labels() if stack_trace: print(CrashDump.dump_stack_trace_with_labels(stack_trace),) else: print("No stack trace available for thread (%d)" % tid) except WindowsError: print("Can't get stack trace for thread (%d)" % tid) do_k = do_stack def do_break(self, arg): """ break - force a debug break in all debugees break <process> [process...] - force a debug break """ debug = self.debug system = debug.system targets = self.input_process_list( self.split_tokens(arg) ) if not targets: targets = debug.get_debugee_pids() targets.sort() if self.lastEvent: current = self.lastEvent.get_pid() else: current = None for pid in targets: if pid != current and debug.is_debugee(pid): process = system.get_process(pid) try: process.debug_break() except WindowsError: print("Can't force a debug break on process (%d)") def do_step(self, arg): """ p - step on the current assembly instruction next - step on the current assembly instruction step - step on the current assembly instruction """ if self.cmdprefix: raise CmdError("prefix not allowed") if self.lastEvent is None: raise CmdError("no current process set") if arg: # XXX this check is to be removed raise CmdError("too many arguments") pid = self.lastEvent.get_pid() thread = self.lastEvent.get_thread() pc = thread.get_pc() code = thread.disassemble(pc, 16)[0] size = code[1] opcode = code[2].lower() if ' ' in opcode: opcode = opcode[ : opcode.find(' ') ] if opcode in self.jump_instructions or opcode in ('int', 'ret', 'retn'): return self.do_trace(arg) address = pc + size ## print(hex(pc), hex(address), size # XXX DEBUG self.debug.stalk_at(pid, address) return True do_p = do_step do_next = do_step def do_trace(self, arg): """ t - trace at the current assembly instruction trace - trace at the current assembly instruction """ if arg: # XXX this check is to be removed raise CmdError("too many arguments") if self.lastEvent is None: raise CmdError("no current thread set") self.lastEvent.get_thread().set_tf() return True do_t = do_trace def do_bp(self, arg): """ [~process] bp <address> - set a code breakpoint """ pid = self.get_process_id_from_prefix() if not self.debug.is_debugee(pid): raise CmdError("target process is not being debugged") process = self.get_process(pid) token_list = self.split_tokens(arg, 1, 1) try: address = self.input_address(token_list[0], pid) deferred = False except Exception: address = token_list[0] deferred = True if not address: address = token_list[0] deferred = True self.debug.break_at(pid, address) if deferred: print("Deferred breakpoint set at %s" % address) else: print("Breakpoint set at %s" % address) def do_ba(self, arg): """ [~thread] ba <a|w|e> <1|2|4|8> <address> - set hardware breakpoint """ debug = self.debug thread = self.get_thread_from_prefix() pid = thread.get_pid() tid = thread.get_tid() if not debug.is_debugee(pid): raise CmdError("target thread is not being debugged") token_list = self.split_tokens(arg, 3, 3) access = token_list[0].lower() size = token_list[1] address = token_list[2] if access == 'a': access = debug.BP_BREAK_ON_ACCESS elif access == 'w': access = debug.BP_BREAK_ON_WRITE elif access == 'e': access = debug.BP_BREAK_ON_EXECUTION else: raise CmdError("bad access type: %s" % token_list[0]) if size == '1': size = debug.BP_WATCH_BYTE elif size == '2': size = debug.BP_WATCH_WORD elif size == '4': size = debug.BP_WATCH_DWORD elif size == '8': size = debug.BP_WATCH_QWORD else: raise CmdError("bad breakpoint size: %s" % size) thread = self.get_thread_from_prefix() tid = thread.get_tid() pid = thread.get_pid() if not debug.is_debugee(pid): raise CmdError("target process is not being debugged") address = self.input_address(address, pid) if debug.has_hardware_breakpoint(tid, address): debug.erase_hardware_breakpoint(tid, address) debug.define_hardware_breakpoint(tid, address, access, size) debug.enable_hardware_breakpoint(tid, address) def do_bm(self, arg): """ [~process] bm <address-address> - set memory breakpoint """ pid = self.get_process_id_from_prefix() if not self.debug.is_debugee(pid): raise CmdError("target process is not being debugged") process = self.get_process(pid) token_list = self.split_tokens(arg, 1, 2) address, size = self.input_address_range(token_list[0], pid) self.debug.watch_buffer(pid, address, size) def do_bl(self, arg): """ bl - list the breakpoints for the current process bl * - list the breakpoints for all processes [~process] bl - list the breakpoints for the given process bl <process> [process...] - list the breakpoints for each given process """ debug = self.debug if arg == '*': if self.cmdprefix: raise CmdError("prefix not supported") breakpoints = debug.get_debugee_pids() else: targets = self.input_process_list( self.split_tokens(arg) ) if self.cmdprefix: targets.insert(0, self.input_process(self.cmdprefix)) if not targets: if self.lastEvent is None: raise CmdError("no current process is set") targets = [ self.lastEvent.get_pid() ] for pid in targets: bplist = debug.get_process_code_breakpoints(pid) printed_process_banner = False if bplist: if not printed_process_banner: print("Process %d:" % pid) printed_process_banner = True for bp in bplist: address = repr(bp)[1:-1].replace('remote address ','') print(" %s" % address) dbplist = debug.get_process_deferred_code_breakpoints(pid) if dbplist: if not printed_process_banner: print("Process %d:" % pid) printed_process_banner = True for (label, action, oneshot) in dbplist: if oneshot: address = " Deferred unconditional one-shot" \ " code breakpoint at %s" else: address = " Deferred unconditional" \ " code breakpoint at %s" address = address % label print(" %s" % address) bplist = debug.get_process_page_breakpoints(pid) if bplist: if not printed_process_banner: print("Process %d:" % pid) printed_process_banner = True for bp in bplist: address = repr(bp)[1:-1].replace('remote address ','') print(" %s" % address) for tid in debug.system.get_process(pid).iter_thread_ids(): bplist = debug.get_thread_hardware_breakpoints(tid) if bplist: print("Thread %d:" % tid) for bp in bplist: address = repr(bp)[1:-1].replace('remote address ','') print(" %s" % address) def do_bo(self, arg): """ [~process] bo <address> - make a code breakpoint one-shot [~thread] bo <address> - make a hardware breakpoint one-shot [~process] bo <address-address> - make a memory breakpoint one-shot [~process] bo <address> <size> - make a memory breakpoint one-shot """ token_list = self.split_tokens(arg, 1, 2) pid, tid, address, size = self.input_breakpoint(token_list) debug = self.debug found = False if size is None: if tid is not None: if debug.has_hardware_breakpoint(tid, address): debug.enable_one_shot_hardware_breakpoint(tid, address) found = True if pid is not None: if debug.has_code_breakpoint(pid, address): debug.enable_one_shot_code_breakpoint(pid, address) found = True else: if debug.has_page_breakpoint(pid, address): debug.enable_one_shot_page_breakpoint(pid, address) found = True if not found: print("Error: breakpoint not found.") def do_be(self, arg): """ [~process] be <address> - enable a code breakpoint [~thread] be <address> - enable a hardware breakpoint [~process] be <address-address> - enable a memory breakpoint [~process] be <address> <size> - enable a memory breakpoint """ token_list = self.split_tokens(arg, 1, 2) pid, tid, address, size = self.input_breakpoint(token_list) debug = self.debug found = False if size is None: if tid is not None: if debug.has_hardware_breakpoint(tid, address): debug.enable_hardware_breakpoint(tid, address) found = True if pid is not None: if debug.has_code_breakpoint(pid, address): debug.enable_code_breakpoint(pid, address) found = True else: if debug.has_page_breakpoint(pid, address): debug.enable_page_breakpoint(pid, address) found = True if not found: print("Error: breakpoint not found.") def do_bd(self, arg): """ [~process] bd <address> - disable a code breakpoint [~thread] bd <address> - disable a hardware breakpoint [~process] bd <address-address> - disable a memory breakpoint [~process] bd <address> <size> - disable a memory breakpoint """ token_list = self.split_tokens(arg, 1, 2) pid, tid, address, size = self.input_breakpoint(token_list) debug = self.debug found = False if size is None: if tid is not None: if debug.has_hardware_breakpoint(tid, address): debug.disable_hardware_breakpoint(tid, address) found = True if pid is not None: if debug.has_code_breakpoint(pid, address): debug.disable_code_breakpoint(pid, address) found = True else: if debug.has_page_breakpoint(pid, address): debug.disable_page_breakpoint(pid, address) found = True if not found: print("Error: breakpoint not found.") def do_bc(self, arg): """ [~process] bc <address> - clear a code breakpoint [~thread] bc <address> - clear a hardware breakpoint [~process] bc <address-address> - clear a memory breakpoint [~process] bc <address> <size> - clear a memory breakpoint """ token_list = self.split_tokens(arg, 1, 2) pid, tid, address, size = self.input_breakpoint(token_list) debug = self.debug found = False if size is None: if tid is not None: if debug.has_hardware_breakpoint(tid, address): debug.dont_watch_variable(tid, address) found = True if pid is not None: if debug.has_code_breakpoint(pid, address): debug.dont_break_at(pid, address) found = True else: if debug.has_page_breakpoint(pid, address): debug.dont_watch_buffer(pid, address, size) found = True if not found: print("Error: breakpoint not found.") def do_disassemble(self, arg): """ [~thread] u [register] - show code disassembly [~process] u [address] - show code disassembly [~thread] disassemble [register] - show code disassembly [~process] disassemble [address] - show code disassembly """ if not arg: arg = self.default_disasm_target token_list = self.split_tokens(arg, 1, 1) pid, tid = self.get_process_and_thread_ids_from_prefix() process = self.get_process(pid) address = self.input_address(token_list[0], pid, tid) try: code = process.disassemble(address, 15*8)[:8] except Exception: msg = "can't disassemble address %s" msg = msg % HexDump.address(address) raise CmdError(msg) if code: label = process.get_label_at_address(address) last_code = code[-1] next_address = last_code[0] + last_code[1] next_address = HexOutput.integer(next_address) self.default_disasm_target = next_address print("%s:" % label) ## print(CrashDump.dump_code(code)) for line in code: print(CrashDump.dump_code_line(line, bShowDump = False)) do_u = do_disassemble def do_search(self, arg): """ [~process] s [address-address] <search string> [~process] search [address-address] <search string> """ token_list = self.split_tokens(arg, 1, 3) pid, tid = self.get_process_and_thread_ids_from_prefix() process = self.get_process(pid) if len(token_list) == 1: pattern = token_list[0] minAddr = None maxAddr = None else: pattern = token_list[-1] addr, size = self.input_address_range(token_list[:-1], pid, tid) minAddr = addr maxAddr = addr + size iter = process.search_bytes(pattern) if process.get_bits() == 32: addr_width = 8 else: addr_width = 16 # TODO: need a prettier output here! for addr in iter: print(HexDump.address(addr, addr_width)) do_s = do_search def do_searchhex(self, arg): """ [~process] sh [address-address] <hexadecimal pattern> [~process] searchhex [address-address] <hexadecimal pattern> """ token_list = self.split_tokens(arg, 1, 3) pid, tid = self.get_process_and_thread_ids_from_prefix() process = self.get_process(pid) if len(token_list) == 1: pattern = token_list[0] minAddr = None maxAddr = None else: pattern = token_list[-1] addr, size = self.input_address_range(token_list[:-1], pid, tid) minAddr = addr maxAddr = addr + size iter = process.search_hexa(pattern) if process.get_bits() == 32: addr_width = 8 else: addr_width = 16 for addr, bytes in iter: print(HexDump.hexblock(bytes, addr, addr_width),) do_sh = do_searchhex ## def do_strings(self, arg): ## """ ## [~process] strings - extract ASCII strings from memory ## """ ## if arg: ## raise CmdError("too many arguments") ## pid, tid = self.get_process_and_thread_ids_from_prefix() ## process = self.get_process(pid) ## for addr, size, data in process.strings(): ## print("%s: %r" % (HexDump.address(addr), data) def do_d(self, arg): """ [~thread] d <register> - show memory contents [~thread] d <register-register> - show memory contents [~thread] d <register> <size> - show memory contents [~process] d <address> - show memory contents [~process] d <address-address> - show memory contents [~process] d <address> <size> - show memory contents """ return self.last_display_command(arg) def do_db(self, arg): """ [~thread] db <register> - show memory contents as bytes [~thread] db <register-register> - show memory contents as bytes [~thread] db <register> <size> - show memory contents as bytes [~process] db <address> - show memory contents as bytes [~process] db <address-address> - show memory contents as bytes [~process] db <address> <size> - show memory contents as bytes """ self.print_memory_display(arg, HexDump.hexblock) self.last_display_command = self.do_db def do_dw(self, arg): """ [~thread] dw <register> - show memory contents as words [~thread] dw <register-register> - show memory contents as words [~thread] dw <register> <size> - show memory contents as words [~process] dw <address> - show memory contents as words [~process] dw <address-address> - show memory contents as words [~process] dw <address> <size> - show memory contents as words """ self.print_memory_display(arg, HexDump.hexblock_word) self.last_display_command = self.do_dw def do_dd(self, arg): """ [~thread] dd <register> - show memory contents as dwords [~thread] dd <register-register> - show memory contents as dwords [~thread] dd <register> <size> - show memory contents as dwords [~process] dd <address> - show memory contents as dwords [~process] dd <address-address> - show memory contents as dwords [~process] dd <address> <size> - show memory contents as dwords """ self.print_memory_display(arg, HexDump.hexblock_dword) self.last_display_command = self.do_dd def do_dq(self, arg): """ [~thread] dq <register> - show memory contents as qwords [~thread] dq <register-register> - show memory contents as qwords [~thread] dq <register> <size> - show memory contents as qwords [~process] dq <address> - show memory contents as qwords [~process] dq <address-address> - show memory contents as qwords [~process] dq <address> <size> - show memory contents as qwords """ self.print_memory_display(arg, HexDump.hexblock_qword) self.last_display_command = self.do_dq # XXX TODO # Change the way the default is used with ds and du def do_ds(self, arg): """ [~thread] ds <register> - show memory contents as ANSI string [~process] ds <address> - show memory contents as ANSI string """ if not arg: arg = self.default_display_target token_list = self.split_tokens(arg, 1, 1) pid, tid, address, size = self.input_display(token_list, 256) process = self.get_process(pid) data = process.peek_string(address, False, size) if data: print(repr(data)) self.last_display_command = self.do_ds def do_du(self, arg): """ [~thread] du <register> - show memory contents as Unicode string [~process] du <address> - show memory contents as Unicode string """ if not arg: arg = self.default_display_target token_list = self.split_tokens(arg, 1, 2) pid, tid, address, size = self.input_display(token_list, 256) process = self.get_process(pid) data = process.peek_string(address, True, size) if data: print(repr(data)) self.last_display_command = self.do_du def do_register(self, arg): """ [~thread] r - print(the value of all registers [~thread] r <register> - print(the value of a register [~thread] r <register>=<value> - change the value of a register [~thread] register - print(the value of all registers [~thread] register <register> - print(the value of a register [~thread] register <register>=<value> - change the value of a register """ arg = arg.strip() if not arg: self.print_current_location() else: equ = arg.find('=') if equ >= 0: register = arg[:equ].strip() value = arg[equ+1:].strip() if not value: value = '0' self.change_register(register, value) else: value = self.input_register(arg) if value is None: raise CmdError("unknown register: %s" % arg) try: label = None thread = self.get_thread_from_prefix() process = thread.get_process() module = process.get_module_at_address(value) if module: label = module.get_label_at_address(value) except RuntimeError: label = None reg = arg.upper() val = HexDump.address(value) if label: print("%s: %s (%s)" % (reg, val, label)) else: print("%s: %s" % (reg, val)) do_r = do_register def do_eb(self, arg): """ [~process] eb <address> <data> - write the data to the specified address """ # TODO # data parameter should be optional, use a child Cmd here pid = self.get_process_id_from_prefix() token_list = self.split_tokens(arg, 2) address = self.input_address(token_list[0], pid) data = HexInput.hexadecimal(' '.join(token_list[1:])) self.write_memory(address, data, pid) # XXX TODO # add ew, ed and eq here def do_find(self, arg): """ [~process] f <string> - find the string in the process memory [~process] find <string> - find the string in the process memory """ if not arg: raise CmdError("missing parameter: string") process = self.get_process_from_prefix() self.find_in_memory(arg, process) do_f = do_find def do_memory(self, arg): """ [~process] m - show the process memory map [~process] memory - show the process memory map """ if arg: # TODO: take min and max addresses raise CmdError("too many arguments") process = self.get_process_from_prefix() try: memoryMap = process.get_memory_map() mappedFilenames = process.get_mapped_filenames() print('') print(CrashDump.dump_memory_map(memoryMap, mappedFilenames)) except WindowsError: msg = "can't get memory information for process (%d)" raise CmdError(msg % process.get_pid()) do_m = do_memory #------------------------------------------------------------------------------ # Event handling # TODO # * add configurable stop/don't stop behavior on events and exceptions # Stop for all events, unless stated otherwise. def event(self, event): self.print_event(event) self.prompt_user() # Stop for all exceptions, unless stated otherwise. def exception(self, event): self.print_exception(event) self.prompt_user() # Stop for breakpoint exceptions. def breakpoint(self, event): if hasattr(event, 'breakpoint') and event.breakpoint: self.print_breakpoint_location(event) else: self.print_exception(event) self.prompt_user() # Stop for WOW64 breakpoint exceptions. def wow64_breakpoint(self, event): self.print_exception(event) self.prompt_user() # Stop for single step exceptions. def single_step(self, event): if event.debug.is_tracing(event.get_tid()): self.print_breakpoint_location(event) else: self.print_exception(event) self.prompt_user() # Don't stop for C++ exceptions. def ms_vc_exception(self, event): self.print_exception(event) event.continueStatus = win32.DBG_CONTINUE # Don't stop for process start. def create_process(self, event): self.print_process_start(event) self.print_thread_start(event) self.print_module_load(event) # Don't stop for process exit. def exit_process(self, event): self.print_process_end(event) # Don't stop for thread creation. def create_thread(self, event): self.print_thread_start(event) # Don't stop for thread exit. def exit_thread(self, event): self.print_thread_end(event) # Don't stop for DLL load. def load_dll(self, event): self.print_module_load(event) # Don't stop for DLL unload. def unload_dll(self, event): self.print_module_unload(event) # Don't stop for debug strings. def output_string(self, event): self.print_debug_string(event) #------------------------------------------------------------------------------ # History file def load_history(self): global readline if readline is None: try: import readline except ImportError: return if self.history_file_full_path is None: folder = os.environ.get('USERPROFILE', '') if not folder: folder = os.environ.get('HOME', '') if not folder: folder = os.path.split(sys.argv[0])[1] if not folder: folder = os.path.curdir self.history_file_full_path = os.path.join(folder, self.history_file) try: if os.path.exists(self.history_file_full_path): readline.read_history_file(self.history_file_full_path) except IOError: e = sys.exc_info()[1] warnings.warn("Cannot load history file, reason: %s" % str(e)) def save_history(self): if self.history_file_full_path is not None: global readline if readline is None: try: import readline except ImportError: return try: readline.write_history_file(self.history_file_full_path) except IOError: e = sys.exc_info()[1] warnings.warn("Cannot save history file, reason: %s" % str(e)) #------------------------------------------------------------------------------ # Main loop # Debugging loop. def loop(self): self.debuggerExit = False debug = self.debug # Stop on the initial event, if any. if self.lastEvent is not None: self.cmdqueue.append('r') self.prompt_user() # Loop until the debugger is told to quit. while not self.debuggerExit: try: # If for some reason the last event wasn't continued, # continue it here. This won't be done more than once # for a given Event instance, though. try: debug.cont() # On error, show the command prompt. except Exception: traceback.print_exc() self.prompt_user() # While debugees are attached, handle debug events. # Some debug events may cause the command prompt to be shown. if self.debug.get_debugee_count() > 0: try: # Get the next debug event. debug.wait() # Dispatch the debug event. try: debug.dispatch() # Continue the debug event. finally: debug.cont() # On error, show the command prompt. except Exception: traceback.print_exc() self.prompt_user() # While no debugees are attached, show the command prompt. else: self.prompt_user() # When the user presses Ctrl-C send a debug break to all debugees. except KeyboardInterrupt: success = False try: print("*** User requested debug break") system = debug.system for pid in debug.get_debugee_pids(): try: system.get_process(pid).debug_break() success = True except: traceback.print_exc() except: traceback.print_exc() if not success: raise # This should never happen!
apache-2.0
[ 3168, 94, 8083, 87, 1132, 15, 9541, 63, 67, 15, 4718, 821, 15, 1548, 14, 5803, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 437, 346, 23504, 1470, 26, 199, 3, 221, 30650, 761, 305, 662, 388, 79, 573, 85, 12, 367, 17049, 1414, 1004, 14958, 641, 1314, 642, 365, 315, 8721, 581, 14, 199, 3, 221, 1455, 921, 9864, 633, 14, 957, 15, 8445, 331, 416, 261, 388, 79, 573, 85, 199, 199, 3, 1898, 334, 67, 9, 8937, 13, 7280, 12, 603, 6936, 812, 382, 305, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 7647, 26, 199, 3, 199, 3, 258, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 4245, 12, 199, 3, 755, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 258, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 199, 3, 755, 4245, 12, 3749, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 199, 3, 755, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 199, 3, 258, 627, 11443, 314, 536, 402, 314, 4248, 16712, 6590, 314, 1561, 402, 2399, 199, 3, 755, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 755, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 298, 1179, 2281, 2, 199, 3, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 2296, 12, 2334, 199, 3, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 437, 3115, 3104, 199, 3, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 11489, 1549, 6483, 6262, 199, 3, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 8820, 12, 9836, 12, 1549, 199, 3, 9110, 6736, 334, 6446, 12, 5400, 2845, 5471, 2296, 12, 9838, 1634, 199, 3, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 7126, 12, 1549, 9206, 27, 1549, 9748, 199, 3, 9831, 9, 9802, 9817, 2401, 5258, 1821, 9815, 1634, 5603, 12, 7061, 1621, 199, 3, 7066, 12, 9644, 5603, 12, 1549, 7056, 334, 6446, 9254, 1549, 7334, 9, 199, 3, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 199, 3, 9726, 1634, 9712, 9784, 14, 199, 199, 624, 199, 23879, 10201, 8559, 14, 199, 199, 32, 923, 14245, 1540, 26, 272, 19809, 31521, 199, 199, 32, 923, 24873, 26, 272, 26005, 547, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 543, 63, 6242, 199, 199, 363, 5792, 363, 275, 7880, 1304, 17351, 199, 199, 363, 452, 363, 275, 359, 283, 9270, 31521, 297, 283, 7874, 547, 7, 1622, 199, 199, 3, 3254, 2213, 642, 859, 543, 20964, 14, 199, 3, 3254, 1414, 370, 663, 282, 2061, 1125, 17944, 14, 199, 3, 3254, 1414, 370, 2498, 2808, 8963, 14, 199, 199, 504, 4747, 571, 16310, 492, 4747, 708, 199, 504, 4747, 571, 16310, 492, 8434, 199, 504, 4747, 571, 16310, 14, 2253, 492, 6187, 199, 504, 4747, 571, 16310, 14, 1974, 492, 6912, 12929, 199, 504, 4747, 571, 16310, 14, 1430, 492, 6763, 2461, 12, 3091, 2390, 199, 504, 4747, 571, 16310, 14, 3858, 4538, 492, 28333, 3205, 12, 28333, 2959, 12, 28333, 11772, 12, 30277, 1119, 11772, 12, 14245, 2445, 199, 199, 646, 747, 199, 646, 984, 199, 646, 1233, 199, 646, 900, 199, 646, 3598, 199, 646, 5190, 199, 199, 3, 4634, 5002, 2860, 4310, 298, 1760, 2, 370, 1172, 282, 859, 701, 314, 2011, 536, 520, 48, 199, 504, 2088, 492, 26005, 199, 199, 3, 9617, 8925, 199, 6407, 275, 488, 199, 199, 31436, 199, 199, 533, 9762, 2390, 334, 1944, 2390, 304, 272, 298, 11324, 1566, 909, 1202, 14448, 701, 491, 91, 9270, 31521, 93, 2122, 339, 347, 664, 63, 3150, 8, 277, 304, 267, 372, 291, 423, 3150, 339, 347, 664, 63, 5700, 8, 277, 304, 267, 372, 291, 423, 5700, 339, 347, 664, 63, 1412, 8, 277, 304, 267, 372, 291, 423, 1412, 339, 347, 664, 63, 2671, 8, 277, 304, 267, 372, 291, 423, 2671, 199, 199, 31436, 199, 199, 533, 26005, 547, 334, 1726, 304, 272, 408, 272, 2186, 4915, 1380, 282, 1414, 6057, 1125, 11058, 14, 272, 8051, 14448, 701, 491, 91, 9270, 31521, 5565, 272, 408, 199, 199, 31436, 199, 199, 533, 19809, 31521, 334, 7874, 12, 6763, 2461, 304, 272, 408, 272, 1010, 7502, 8559, 14958, 14, 339, 768, 3239, 26, 491, 91, 7084, 14, 13543, 93, 272, 408, 199, 199, 20974, 199, 3, 8089, 2860, 339, 327, 2186, 370, 746, 1380, 376, 1125, 11058, 14043, 282, 1414, 14, 272, 1414, 63, 705, 63, 1971, 275, 26005, 547, 339, 327, 603, 8148, 4515, 370, 3618, 367, 3105, 4474, 315, 314, 2446, 4438, 14, 272, 17594, 30145, 4515, 275, 2948, 339, 327, 27829, 570, 536, 14, 272, 7994, 63, 493, 275, 1987, 2676, 571, 16310, 63, 5570, 7, 339, 327, 32112, 2544, 17242, 1337, 31, 272, 12679, 63, 10589, 275, 715, 339, 327, 4821, 3589, 536, 4110, 14, 272, 1686, 63, 2718, 63, 354, 63, 6574, 275, 283, 27108, 25407, 55, 8195, 7, 971, 2892, 283, 22017, 21241, 87, 1702, 7, 971, 2892, 283, 9461, 12970, 7, 463, 971, 2892, 14135, 339, 327, 23923, 402, 314, 24493, 14, 272, 8135, 63, 1247, 5185, 275, 334, 283, 1259, 297, 283, 795, 297, 283, 397, 297, 283, 2319, 297, 283, 458, 7, 776, 339, 2274, 63, 3620, 63, 772, 63, 475, 63, 708, 258, 275, 469, 267, 283, 32156, 5242, 50, 1219, 297, 283, 2871, 88, 5242, 50, 13691, 297, 283, 825, 88, 5242, 50, 11859, 297, 283, 8268, 5242, 50, 8373, 297, 267, 283, 69, 711, 5242, 50, 711, 297, 283, 2871, 80, 5242, 50, 10913, 297, 283, 397, 80, 5242, 17796, 297, 283, 69, 338, 5242, 50, 338, 297, 283, 6297, 5242, 50, 328, 7, 272, 789, 272, 2274, 63, 3620, 63, 772, 63, 475, 63, 975, 258, 275, 469, 283, 1219, 5242, 50, 1219, 297, 283, 13691, 5242, 50, 13691, 297, 283 ]
[ 94, 8083, 87, 1132, 15, 9541, 63, 67, 15, 4718, 821, 15, 1548, 14, 5803, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 437, 346, 23504, 1470, 26, 199, 3, 221, 30650, 761, 305, 662, 388, 79, 573, 85, 12, 367, 17049, 1414, 1004, 14958, 641, 1314, 642, 365, 315, 8721, 581, 14, 199, 3, 221, 1455, 921, 9864, 633, 14, 957, 15, 8445, 331, 416, 261, 388, 79, 573, 85, 199, 199, 3, 1898, 334, 67, 9, 8937, 13, 7280, 12, 603, 6936, 812, 382, 305, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 7647, 26, 199, 3, 199, 3, 258, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 4245, 12, 199, 3, 755, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 258, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 199, 3, 755, 4245, 12, 3749, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 199, 3, 755, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 199, 3, 258, 627, 11443, 314, 536, 402, 314, 4248, 16712, 6590, 314, 1561, 402, 2399, 199, 3, 755, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 755, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 298, 1179, 2281, 2, 199, 3, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 2296, 12, 2334, 199, 3, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 437, 3115, 3104, 199, 3, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 11489, 1549, 6483, 6262, 199, 3, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 8820, 12, 9836, 12, 1549, 199, 3, 9110, 6736, 334, 6446, 12, 5400, 2845, 5471, 2296, 12, 9838, 1634, 199, 3, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 7126, 12, 1549, 9206, 27, 1549, 9748, 199, 3, 9831, 9, 9802, 9817, 2401, 5258, 1821, 9815, 1634, 5603, 12, 7061, 1621, 199, 3, 7066, 12, 9644, 5603, 12, 1549, 7056, 334, 6446, 9254, 1549, 7334, 9, 199, 3, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 199, 3, 9726, 1634, 9712, 9784, 14, 199, 199, 624, 199, 23879, 10201, 8559, 14, 199, 199, 32, 923, 14245, 1540, 26, 272, 19809, 31521, 199, 199, 32, 923, 24873, 26, 272, 26005, 547, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 543, 63, 6242, 199, 199, 363, 5792, 363, 275, 7880, 1304, 17351, 199, 199, 363, 452, 363, 275, 359, 283, 9270, 31521, 297, 283, 7874, 547, 7, 1622, 199, 199, 3, 3254, 2213, 642, 859, 543, 20964, 14, 199, 3, 3254, 1414, 370, 663, 282, 2061, 1125, 17944, 14, 199, 3, 3254, 1414, 370, 2498, 2808, 8963, 14, 199, 199, 504, 4747, 571, 16310, 492, 4747, 708, 199, 504, 4747, 571, 16310, 492, 8434, 199, 504, 4747, 571, 16310, 14, 2253, 492, 6187, 199, 504, 4747, 571, 16310, 14, 1974, 492, 6912, 12929, 199, 504, 4747, 571, 16310, 14, 1430, 492, 6763, 2461, 12, 3091, 2390, 199, 504, 4747, 571, 16310, 14, 3858, 4538, 492, 28333, 3205, 12, 28333, 2959, 12, 28333, 11772, 12, 30277, 1119, 11772, 12, 14245, 2445, 199, 199, 646, 747, 199, 646, 984, 199, 646, 1233, 199, 646, 900, 199, 646, 3598, 199, 646, 5190, 199, 199, 3, 4634, 5002, 2860, 4310, 298, 1760, 2, 370, 1172, 282, 859, 701, 314, 2011, 536, 520, 48, 199, 504, 2088, 492, 26005, 199, 199, 3, 9617, 8925, 199, 6407, 275, 488, 199, 199, 31436, 199, 199, 533, 9762, 2390, 334, 1944, 2390, 304, 272, 298, 11324, 1566, 909, 1202, 14448, 701, 491, 91, 9270, 31521, 93, 2122, 339, 347, 664, 63, 3150, 8, 277, 304, 267, 372, 291, 423, 3150, 339, 347, 664, 63, 5700, 8, 277, 304, 267, 372, 291, 423, 5700, 339, 347, 664, 63, 1412, 8, 277, 304, 267, 372, 291, 423, 1412, 339, 347, 664, 63, 2671, 8, 277, 304, 267, 372, 291, 423, 2671, 199, 199, 31436, 199, 199, 533, 26005, 547, 334, 1726, 304, 272, 408, 272, 2186, 4915, 1380, 282, 1414, 6057, 1125, 11058, 14, 272, 8051, 14448, 701, 491, 91, 9270, 31521, 5565, 272, 408, 199, 199, 31436, 199, 199, 533, 19809, 31521, 334, 7874, 12, 6763, 2461, 304, 272, 408, 272, 1010, 7502, 8559, 14958, 14, 339, 768, 3239, 26, 491, 91, 7084, 14, 13543, 93, 272, 408, 199, 199, 20974, 199, 3, 8089, 2860, 339, 327, 2186, 370, 746, 1380, 376, 1125, 11058, 14043, 282, 1414, 14, 272, 1414, 63, 705, 63, 1971, 275, 26005, 547, 339, 327, 603, 8148, 4515, 370, 3618, 367, 3105, 4474, 315, 314, 2446, 4438, 14, 272, 17594, 30145, 4515, 275, 2948, 339, 327, 27829, 570, 536, 14, 272, 7994, 63, 493, 275, 1987, 2676, 571, 16310, 63, 5570, 7, 339, 327, 32112, 2544, 17242, 1337, 31, 272, 12679, 63, 10589, 275, 715, 339, 327, 4821, 3589, 536, 4110, 14, 272, 1686, 63, 2718, 63, 354, 63, 6574, 275, 283, 27108, 25407, 55, 8195, 7, 971, 2892, 283, 22017, 21241, 87, 1702, 7, 971, 2892, 283, 9461, 12970, 7, 463, 971, 2892, 14135, 339, 327, 23923, 402, 314, 24493, 14, 272, 8135, 63, 1247, 5185, 275, 334, 283, 1259, 297, 283, 795, 297, 283, 397, 297, 283, 2319, 297, 283, 458, 7, 776, 339, 2274, 63, 3620, 63, 772, 63, 475, 63, 708, 258, 275, 469, 267, 283, 32156, 5242, 50, 1219, 297, 283, 2871, 88, 5242, 50, 13691, 297, 283, 825, 88, 5242, 50, 11859, 297, 283, 8268, 5242, 50, 8373, 297, 267, 283, 69, 711, 5242, 50, 711, 297, 283, 2871, 80, 5242, 50, 10913, 297, 283, 397, 80, 5242, 17796, 297, 283, 69, 338, 5242, 50, 338, 297, 283, 6297, 5242, 50, 328, 7, 272, 789, 272,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
gavinp/chromium
build/android/flag_changer.py
9
1779
# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # Location where chrome reads command line flags from CHROME_COMMAND_FILE = '/data/local/chrome-command-line' class FlagChanger(object): """Temporarily changes the flags Chrome runs with.""" def __init__(self, android_cmd): self._android_cmd = android_cmd self._old_flags = None def Set(self, flags, append=False): """Sets the command line flags used when chrome is started. Args: flags: A list of flags to set, eg. ['--single-process']. append: Whether to append to existing flags or overwrite them. """ if flags: assert flags[0] != 'chrome' if not self._old_flags: self._old_flags = self._android_cmd.GetFileContents(CHROME_COMMAND_FILE) if self._old_flags: self._old_flags = self._old_flags[0].strip() if append and self._old_flags: # Avoid appending flags that are already present. new_flags = filter(lambda flag: self._old_flags.find(flag) == -1, flags) self._android_cmd.SetFileContents(CHROME_COMMAND_FILE, self._old_flags + ' ' + ' '.join(new_flags)) else: self._android_cmd.SetFileContents(CHROME_COMMAND_FILE, 'chrome ' + ' '.join(flags)) def Restore(self): """Restores the flags to their original state.""" if self._old_flags == None: return # Set() was never called. elif self._old_flags: self._android_cmd.SetFileContents(CHROME_COMMAND_FILE, self._old_flags) else: self._android_cmd.RunShellCommand('rm ' + CHROME_COMMAND_FILE)
bsd-3-clause
[ 3, 1898, 334, 67, 9, 7760, 710, 12051, 6642, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 421, 199, 3, 12625, 2382, 18221, 11597, 1414, 1004, 3285, 687, 199, 1244, 31364, 63, 10761, 63, 3817, 275, 1994, 576, 15, 1832, 15, 9887, 13, 1531, 13, 604, 7, 421, 199, 533, 18241, 1049, 12974, 8, 785, 304, 523, 408, 6530, 269, 11406, 4493, 314, 3285, 16776, 7858, 543, 1041, 819, 347, 636, 826, 721, 277, 12, 15516, 63, 1760, 304, 272, 291, 423, 6238, 63, 1760, 275, 15516, 63, 1760, 272, 291, 423, 1753, 63, 2469, 275, 488, 819, 347, 2494, 8, 277, 12, 3285, 12, 5666, 29, 797, 304, 272, 408, 9899, 314, 1414, 1004, 3285, 1202, 1380, 18221, 365, 8239, 14, 339, 3033, 26, 489, 3285, 26, 437, 769, 402, 3285, 370, 663, 12, 11837, 14, 14574, 4780, 13, 1412, 2278, 489, 5666, 26, 7480, 370, 5666, 370, 3411, 3285, 503, 8970, 3062, 14, 272, 408, 272, 340, 3285, 26, 489, 702, 3285, 59, 16, 61, 1137, 283, 9887, 7, 339, 340, 440, 291, 423, 1753, 63, 2469, 26, 489, 291, 423, 1753, 63, 2469, 275, 291, 423, 6238, 63, 1760, 14, 26535, 11383, 8, 1244, 31364, 63, 10761, 63, 3817, 9, 489, 340, 291, 423, 1753, 63, 2469, 26, 267, 291, 423, 1753, 63, 2469, 275, 291, 423, 1753, 63, 2469, 59, 16, 1055, 1913, 342, 339, 340, 5666, 436, 291, 423, 1753, 63, 2469, 26, 489, 327, 19503, 24373, 3285, 626, 787, 2575, 3451, 14, 489, 892, 63, 2469, 275, 2457, 8, 2734, 3305, 26, 291, 423, 1753, 63, 2469, 14, 1623, 8, 4173, 9, 508, 446, 17, 12, 3285, 9, 489, 291, 423, 6238, 63, 1760, 14, 1084, 1173, 11383, 8, 1244, 31364, 63, 10761, 63, 3817, 12, 3147, 291, 423, 1753, 63, 2469, 435, 283, 283, 435, 3147, 283, 1987, 904, 8, 1222, 63, 2469, 430, 272, 587, 26, 489, 291, 423, 6238, 63, 1760, 14, 1084, 1173, 11383, 8, 1244, 31364, 63, 10761, 63, 3817, 12, 3147, 283, 9887, 283, 435, 283, 1987, 904, 8, 2469, 430, 819, 347, 22379, 8, 277, 304, 272, 408, 13726, 7944, 314, 3285, 370, 3932, 3379, 1174, 1041, 272, 340, 291, 423, 1753, 63, 2469, 508, 488, 26, 489, 372, 221, 327, 2494, 342, 1990, 7078, 2797, 14, 272, 916, 291, 423, 1753, 63, 2469, 26, 489, 291, 423, 6238, 63, 1760, 14, 1084, 1173, 11383, 8, 1244, 31364, 63, 10761, 63, 3817, 12, 291, 423, 1753, 63, 2469, 9, 272, 587, 26, 489, 291, 423, 6238, 63, 1760, 14, 2540, 8529, 3110, 360, 5682, 283, 435, 6624, 31364, 63, 10761, 63, 3817, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1898, 334, 67, 9, 7760, 710, 12051, 6642, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 421, 199, 3, 12625, 2382, 18221, 11597, 1414, 1004, 3285, 687, 199, 1244, 31364, 63, 10761, 63, 3817, 275, 1994, 576, 15, 1832, 15, 9887, 13, 1531, 13, 604, 7, 421, 199, 533, 18241, 1049, 12974, 8, 785, 304, 523, 408, 6530, 269, 11406, 4493, 314, 3285, 16776, 7858, 543, 1041, 819, 347, 636, 826, 721, 277, 12, 15516, 63, 1760, 304, 272, 291, 423, 6238, 63, 1760, 275, 15516, 63, 1760, 272, 291, 423, 1753, 63, 2469, 275, 488, 819, 347, 2494, 8, 277, 12, 3285, 12, 5666, 29, 797, 304, 272, 408, 9899, 314, 1414, 1004, 3285, 1202, 1380, 18221, 365, 8239, 14, 339, 3033, 26, 489, 3285, 26, 437, 769, 402, 3285, 370, 663, 12, 11837, 14, 14574, 4780, 13, 1412, 2278, 489, 5666, 26, 7480, 370, 5666, 370, 3411, 3285, 503, 8970, 3062, 14, 272, 408, 272, 340, 3285, 26, 489, 702, 3285, 59, 16, 61, 1137, 283, 9887, 7, 339, 340, 440, 291, 423, 1753, 63, 2469, 26, 489, 291, 423, 1753, 63, 2469, 275, 291, 423, 6238, 63, 1760, 14, 26535, 11383, 8, 1244, 31364, 63, 10761, 63, 3817, 9, 489, 340, 291, 423, 1753, 63, 2469, 26, 267, 291, 423, 1753, 63, 2469, 275, 291, 423, 1753, 63, 2469, 59, 16, 1055, 1913, 342, 339, 340, 5666, 436, 291, 423, 1753, 63, 2469, 26, 489, 327, 19503, 24373, 3285, 626, 787, 2575, 3451, 14, 489, 892, 63, 2469, 275, 2457, 8, 2734, 3305, 26, 291, 423, 1753, 63, 2469, 14, 1623, 8, 4173, 9, 508, 446, 17, 12, 3285, 9, 489, 291, 423, 6238, 63, 1760, 14, 1084, 1173, 11383, 8, 1244, 31364, 63, 10761, 63, 3817, 12, 3147, 291, 423, 1753, 63, 2469, 435, 283, 283, 435, 3147, 283, 1987, 904, 8, 1222, 63, 2469, 430, 272, 587, 26, 489, 291, 423, 6238, 63, 1760, 14, 1084, 1173, 11383, 8, 1244, 31364, 63, 10761, 63, 3817, 12, 3147, 283, 9887, 283, 435, 283, 1987, 904, 8, 2469, 430, 819, 347, 22379, 8, 277, 304, 272, 408, 13726, 7944, 314, 3285, 370, 3932, 3379, 1174, 1041, 272, 340, 291, 423, 1753, 63, 2469, 508, 488, 26, 489, 372, 221, 327, 2494, 342, 1990, 7078, 2797, 14, 272, 916, 291, 423, 1753, 63, 2469, 26, 489, 291, 423, 6238, 63, 1760, 14, 1084, 1173, 11383, 8, 1244, 31364, 63, 10761, 63, 3817, 12, 291, 423, 1753, 63, 2469, 9, 272, 587, 26, 489, 291, 423, 6238, 63, 1760, 14, 2540, 8529, 3110, 360, 5682, 283, 435, 6624, 31364, 63, 10761, 63, 3817, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
joshainglis/ansible
lib/ansible/module_utils/facts.py
3
133495
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com> # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. import os import sys import stat import time import array import shlex import errno import fcntl import fnmatch import glob import platform import re import signal import socket import struct import datetime import getpass import pwd import ConfigParser import StringIO from string import maketrans try: import selinux HAVE_SELINUX=True except ImportError: HAVE_SELINUX=False try: import json # Detect python-json which is incompatible and fallback to simplejson in # that case try: json.loads json.dumps except AttributeError: raise ImportError except ImportError: import simplejson as json # The distutils module is not shipped with SUNWPython on Solaris. # It's in the SUNWPython-devel package which also contains development files # that don't belong on production boxes. Since our Solaris code doesn't # depend on LooseVersion, do not import it on Solaris. if platform.system() != 'SunOS': from distutils.version import LooseVersion # -------------------------------------------------------------- # timeout function to make sure some fact gathering # steps do not exceed a time limit class TimeoutError(Exception): pass def timeout(seconds=10, error_message="Timer expired"): def decorator(func): def _handle_timeout(signum, frame): raise TimeoutError(error_message) def wrapper(*args, **kwargs): signal.signal(signal.SIGALRM, _handle_timeout) signal.alarm(seconds) try: result = func(*args, **kwargs) finally: signal.alarm(0) return result return wrapper return decorator # -------------------------------------------------------------- class Facts(object): """ This class should only attempt to populate those facts that are mostly generic to all systems. This includes platform facts, service facts (e.g. ssh keys or selinux), and distribution facts. Anything that requires extensive code or may have more than one possible implementation to establish facts for a given topic should subclass Facts. """ # i86pc is a Solaris and derivatives-ism _I386RE = re.compile(r'i([3456]86|86pc)') # For the most part, we assume that platform.dist() will tell the truth. # This is the fallback to handle unknowns or exceptions OSDIST_LIST = ( ('/etc/oracle-release', 'OracleLinux'), ('/etc/slackware-version', 'Slackware'), ('/etc/redhat-release', 'RedHat'), ('/etc/vmware-release', 'VMwareESX'), ('/etc/openwrt_release', 'OpenWrt'), ('/etc/system-release', 'OtherLinux'), ('/etc/alpine-release', 'Alpine'), ('/etc/release', 'Solaris'), ('/etc/arch-release', 'Archlinux'), ('/etc/SuSE-release', 'SuSE'), ('/etc/os-release', 'SuSE'), ('/etc/gentoo-release', 'Gentoo'), ('/etc/os-release', 'Debian'), ('/etc/lsb-release', 'Mandriva'), ('/etc/altlinux-release', 'Altlinux'), ('/etc/os-release', 'NA'), ) SELINUX_MODE_DICT = { 1: 'enforcing', 0: 'permissive', -1: 'disabled' } # A list of dicts. If there is a platform with more than one # package manager, put the preferred one last. If there is an # ansible module, use that as the value for the 'name' key. PKG_MGRS = [ { 'path' : '/usr/bin/yum', 'name' : 'yum' }, { 'path' : '/usr/bin/dnf', 'name' : 'dnf' }, { 'path' : '/usr/bin/apt-get', 'name' : 'apt' }, { 'path' : '/usr/bin/zypper', 'name' : 'zypper' }, { 'path' : '/usr/sbin/urpmi', 'name' : 'urpmi' }, { 'path' : '/usr/bin/pacman', 'name' : 'pacman' }, { 'path' : '/bin/opkg', 'name' : 'opkg' }, { 'path' : '/opt/local/bin/pkgin', 'name' : 'pkgin' }, { 'path' : '/opt/local/bin/port', 'name' : 'macports' }, { 'path' : '/usr/local/bin/brew', 'name' : 'homebrew' }, { 'path' : '/sbin/apk', 'name' : 'apk' }, { 'path' : '/usr/sbin/pkg', 'name' : 'pkgng' }, { 'path' : '/usr/sbin/swlist', 'name' : 'SD-UX' }, { 'path' : '/usr/bin/emerge', 'name' : 'portage' }, { 'path' : '/usr/sbin/pkgadd', 'name' : 'svr4pkg' }, { 'path' : '/usr/bin/pkg', 'name' : 'pkg' }, { 'path' : '/usr/bin/xbps-install','name' : 'xbps' }, { 'path' : '/usr/local/sbin/pkg', 'name' : 'pkgng' }, ] def __init__(self, load_on_init=True): self.facts = {} if load_on_init: self.get_platform_facts() self.get_distribution_facts() self.get_cmdline() self.get_public_ssh_host_keys() self.get_selinux_facts() self.get_fips_facts() self.get_pkg_mgr_facts() self.get_service_mgr_facts() self.get_lsb_facts() self.get_date_time_facts() self.get_user_facts() self.get_local_facts() self.get_env_facts() self.get_dns_facts() def populate(self): return self.facts # Platform # platform.system() can be Linux, Darwin, Java, or Windows def get_platform_facts(self): self.facts['system'] = platform.system() self.facts['kernel'] = platform.release() self.facts['machine'] = platform.machine() self.facts['python_version'] = platform.python_version() self.facts['fqdn'] = socket.getfqdn() self.facts['hostname'] = platform.node().split('.')[0] self.facts['nodename'] = platform.node() self.facts['domain'] = '.'.join(self.facts['fqdn'].split('.')[1:]) arch_bits = platform.architecture()[0] self.facts['userspace_bits'] = arch_bits.replace('bit', '') if self.facts['machine'] == 'x86_64': self.facts['architecture'] = self.facts['machine'] if self.facts['userspace_bits'] == '64': self.facts['userspace_architecture'] = 'x86_64' elif self.facts['userspace_bits'] == '32': self.facts['userspace_architecture'] = 'i386' elif Facts._I386RE.search(self.facts['machine']): self.facts['architecture'] = 'i386' if self.facts['userspace_bits'] == '64': self.facts['userspace_architecture'] = 'x86_64' elif self.facts['userspace_bits'] == '32': self.facts['userspace_architecture'] = 'i386' else: self.facts['architecture'] = self.facts['machine'] if self.facts['system'] == 'Linux': self.get_distribution_facts() elif self.facts['system'] == 'AIX': # Attempt to use getconf to figure out architecture # fall back to bootinfo if needed if module.get_bin_path('getconf'): rc, out, err = module.run_command([module.get_bin_path('getconf'), 'MACHINE_ARCHITECTURE']) data = out.split('\n') self.facts['architecture'] = data[0] else: rc, out, err = module.run_command([module.get_bin_path('bootinfo'), '-p']) data = out.split('\n') self.facts['architecture'] = data[0] elif self.facts['system'] == 'OpenBSD': self.facts['architecture'] = platform.uname()[5] def get_local_facts(self): fact_path = module.params.get('fact_path', None) if not fact_path or not os.path.exists(fact_path): return local = {} for fn in sorted(glob.glob(fact_path + '/*.fact')): # where it will sit under local facts fact_base = os.path.basename(fn).replace('.fact','') if stat.S_IXUSR & os.stat(fn)[stat.ST_MODE]: # run it # try to read it as json first # if that fails read it with ConfigParser # if that fails, skip it rc, out, err = module.run_command(fn) else: out = get_file_content(fn, default='') # load raw json fact = 'loading %s' % fact_base try: fact = json.loads(out) except ValueError: # load raw ini cp = ConfigParser.ConfigParser() try: cp.readfp(StringIO.StringIO(out)) except ConfigParser.Error: fact = "error loading fact - please check content" else: fact = {} #print cp.sections() for sect in cp.sections(): if sect not in fact: fact[sect] = {} for opt in cp.options(sect): val = cp.get(sect, opt) fact[sect][opt]=val local[fact_base] = fact if not local: return self.facts['local'] = local # platform.dist() is deprecated in 2.6 # in 2.6 and newer, you should use platform.linux_distribution() def get_distribution_facts(self): # A list with OS Family members OS_FAMILY = dict( RedHat = 'RedHat', Fedora = 'RedHat', CentOS = 'RedHat', Scientific = 'RedHat', SLC = 'RedHat', Ascendos = 'RedHat', CloudLinux = 'RedHat', PSBM = 'RedHat', OracleLinux = 'RedHat', OVS = 'RedHat', OEL = 'RedHat', Amazon = 'RedHat', XenServer = 'RedHat', Ubuntu = 'Debian', Debian = 'Debian', Raspbian = 'Debian', Slackware = 'Slackware', SLES = 'Suse', SLED = 'Suse', openSUSE = 'Suse', SuSE = 'Suse', SLES_SAP = 'Suse', Gentoo = 'Gentoo', Funtoo = 'Gentoo', Archlinux = 'Archlinux', Manjaro = 'Archlinux', Mandriva = 'Mandrake', Mandrake = 'Mandrake', Altlinux = 'Altlinux', Solaris = 'Solaris', Nexenta = 'Solaris', OmniOS = 'Solaris', OpenIndiana = 'Solaris', SmartOS = 'Solaris', AIX = 'AIX', Alpine = 'Alpine', MacOSX = 'Darwin', FreeBSD = 'FreeBSD', HPUX = 'HP-UX' ) # TODO: Rewrite this to use the function references in a dict pattern # as it's much cleaner than this massive if-else if self.facts['system'] == 'AIX': self.facts['distribution'] = 'AIX' rc, out, err = module.run_command("/usr/bin/oslevel") data = out.split('.') self.facts['distribution_version'] = data[0] self.facts['distribution_release'] = data[1] elif self.facts['system'] == 'HP-UX': self.facts['distribution'] = 'HP-UX' rc, out, err = module.run_command("/usr/sbin/swlist |egrep 'HPUX.*OE.*[AB].[0-9]+\.[0-9]+'", use_unsafe_shell=True) data = re.search('HPUX.*OE.*([AB].[0-9]+\.[0-9]+)\.([0-9]+).*', out) if data: self.facts['distribution_version'] = data.groups()[0] self.facts['distribution_release'] = data.groups()[1] elif self.facts['system'] == 'Darwin': self.facts['distribution'] = 'MacOSX' rc, out, err = module.run_command("/usr/bin/sw_vers -productVersion") data = out.split()[-1] self.facts['distribution_version'] = data elif self.facts['system'] == 'FreeBSD': self.facts['distribution'] = 'FreeBSD' self.facts['distribution_release'] = platform.release() self.facts['distribution_version'] = platform.version() elif self.facts['system'] == 'NetBSD': self.facts['distribution'] = 'NetBSD' self.facts['distribution_release'] = platform.release() self.facts['distribution_version'] = platform.version() elif self.facts['system'] == 'OpenBSD': self.facts['distribution'] = 'OpenBSD' self.facts['distribution_release'] = platform.release() rc, out, err = module.run_command("/sbin/sysctl -n kern.version") match = re.match('OpenBSD\s[0-9]+.[0-9]+-(\S+)\s.*', out) if match: self.facts['distribution_version'] = match.groups()[0] else: self.facts['distribution_version'] = 'release' else: dist = platform.dist() self.facts['distribution'] = dist[0].capitalize() or 'NA' self.facts['distribution_version'] = dist[1] or 'NA' self.facts['distribution_major_version'] = dist[1].split('.')[0] or 'NA' self.facts['distribution_release'] = dist[2] or 'NA' # Try to handle the exceptions now ... for (path, name) in Facts.OSDIST_LIST: if os.path.exists(path): if os.path.getsize(path) > 0: if self.facts['distribution'] in ('Fedora', 'Altlinux', ): # Once we determine the value is one of these distros # we trust the values are always correct break elif name == 'Archlinux': data = get_file_content(path) if 'Arch Linux' in data: self.facts['distribution'] = name else: self.facts['distribution'] = data.split()[0] break elif name == 'Slackware': data = get_file_content(path) if 'Slackware' in data: self.facts['distribution'] = name version = re.findall('\w+[.]\w+', data) if version: self.facts['distribution_version'] = version[0] break elif name == 'OracleLinux': data = get_file_content(path) if 'Oracle Linux' in data: self.facts['distribution'] = name else: self.facts['distribution'] = data.split()[0] break elif name == 'RedHat': data = get_file_content(path) if 'Red Hat' in data: self.facts['distribution'] = name else: self.facts['distribution'] = data.split()[0] break elif name == 'Altlinux': data = get_file_content(path) if 'ALT Linux' in data: self.facts['distribution'] = name else: self.facts['distribution'] = data.split()[0] break elif name == 'OtherLinux': data = get_file_content(path) if 'Amazon' in data: self.facts['distribution'] = 'Amazon' self.facts['distribution_version'] = data.split()[-1] break elif name == 'OpenWrt': data = get_file_content(path) if 'OpenWrt' in data: self.facts['distribution'] = name version = re.search('DISTRIB_RELEASE="(.*)"', data) if version: self.facts['distribution_version'] = version.groups()[0] release = re.search('DISTRIB_CODENAME="(.*)"', data) if release: self.facts['distribution_release'] = release.groups()[0] break elif name == 'Alpine': data = get_file_content(path) self.facts['distribution'] = name self.facts['distribution_version'] = data break elif name == 'Solaris': data = get_file_content(path).split('\n')[0] if 'Solaris' in data: ora_prefix = '' if 'Oracle Solaris' in data: data = data.replace('Oracle ','') ora_prefix = 'Oracle ' self.facts['distribution'] = data.split()[0] self.facts['distribution_version'] = data.split()[1] self.facts['distribution_release'] = ora_prefix + data break uname_rc, uname_out, uname_err = module.run_command(['uname', '-v']) distribution_version = None if 'SmartOS' in data: self.facts['distribution'] = 'SmartOS' if os.path.exists('/etc/product'): product_data = dict([l.split(': ', 1) for l in get_file_content('/etc/product').split('\n') if ': ' in l]) if 'Image' in product_data: distribution_version = product_data.get('Image').split()[-1] elif 'OpenIndiana' in data: self.facts['distribution'] = 'OpenIndiana' elif 'OmniOS' in data: self.facts['distribution'] = 'OmniOS' distribution_version = data.split()[-1] elif uname_rc == 0 and 'NexentaOS_' in uname_out: self.facts['distribution'] = 'Nexenta' distribution_version = data.split()[-1].lstrip('v') if self.facts['distribution'] in ('SmartOS', 'OpenIndiana', 'OmniOS', 'Nexenta'): self.facts['distribution_release'] = data.strip() if distribution_version is not None: self.facts['distribution_version'] = distribution_version elif uname_rc == 0: self.facts['distribution_version'] = uname_out.split('\n')[0].strip() break elif name == 'SuSE': data = get_file_content(path) if 'suse' in data.lower(): if path == '/etc/os-release': for line in data.splitlines(): distribution = re.search("^NAME=(.*)", line) if distribution: self.facts['distribution'] = distribution.group(1).strip('"') distribution_version = re.search('^VERSION_ID="?([0-9]+\.?[0-9]*)"?', line) # example pattern are 13.04 13.0 13 if distribution_version: self.facts['distribution_version'] = distribution_version.group(1) if 'open' in data.lower(): release = re.search("^PRETTY_NAME=[^(]+ \(?([^)]+?)\)", line) if release: self.facts['distribution_release'] = release.groups()[0] elif 'enterprise' in data.lower(): release = re.search('^VERSION_ID="?[0-9]+\.?([0-9]*)"?', line) # SLES doesn't got funny release names if release: release = release.group(1) else: release = "0" # no minor number, so it is the first release self.facts['distribution_release'] = release break elif path == '/etc/SuSE-release': if 'open' in data.lower(): data = data.splitlines() distdata = get_file_content(path).split('\n')[0] self.facts['distribution'] = distdata.split()[0] for line in data: release = re.search('CODENAME *= *([^\n]+)', line) if release: self.facts['distribution_release'] = release.groups()[0].strip() elif 'enterprise' in data.lower(): lines = data.splitlines() distribution = lines[0].split()[0] if "Server" in data: self.facts['distribution'] = "SLES" elif "Desktop" in data: self.facts['distribution'] = "SLED" for line in lines: release = re.search('PATCHLEVEL = ([0-9]+)', line) # SLES doesn't got funny release names if release: self.facts['distribution_release'] = release.group(1) self.facts['distribution_version'] = self.facts['distribution_version'] + '.' + release.group(1) elif name == 'Debian': data = get_file_content(path) if 'Debian' in data or 'Raspbian' in data: release = re.search("PRETTY_NAME=[^(]+ \(?([^)]+?)\)", data) if release: self.facts['distribution_release'] = release.groups()[0] break elif 'Ubuntu' in data: break # Ubuntu gets correct info from python functions elif name == 'Mandriva': data = get_file_content(path) if 'Mandriva' in data: version = re.search('DISTRIB_RELEASE="(.*)"', data) if version: self.facts['distribution_version'] = version.groups()[0] release = re.search('DISTRIB_CODENAME="(.*)"', data) if release: self.facts['distribution_release'] = release.groups()[0] self.facts['distribution'] = name break elif name == 'NA': data = get_file_content(path) for line in data.splitlines(): if self.facts['distribution'] == 'NA': distribution = re.search("^NAME=(.*)", line) if distribution: self.facts['distribution'] = distribution.group(1).strip('"') if self.facts['distribution_version'] == 'NA': version = re.search("^VERSION=(.*)", line) if version: self.facts['distribution_version'] = version.group(1).strip('"') if self.facts['distribution'].lower() == 'coreos': data = get_file_content('/etc/coreos/update.conf') release = re.search("^GROUP=(.*)", data) if release: self.facts['distribution_release'] = release.group(1).strip('"') else: self.facts['distribution'] = name machine_id = get_file_content("/var/lib/dbus/machine-id") or get_file_content("/etc/machine-id") if machine_id: machine_id = machine_id.split('\n')[0] self.facts["machine_id"] = machine_id self.facts['os_family'] = self.facts['distribution'] if self.facts['distribution'] in OS_FAMILY: self.facts['os_family'] = OS_FAMILY[self.facts['distribution']] def get_cmdline(self): data = get_file_content('/proc/cmdline') if data: self.facts['cmdline'] = {} try: for piece in shlex.split(data): item = piece.split('=', 1) if len(item) == 1: self.facts['cmdline'][item[0]] = True else: self.facts['cmdline'][item[0]] = item[1] except ValueError: pass def get_public_ssh_host_keys(self): keytypes = ('dsa', 'rsa', 'ecdsa', 'ed25519') if self.facts['system'] == 'Darwin': if self.facts['distribution'] == 'MacOSX' and LooseVersion(self.facts['distribution_version']) >= LooseVersion('10.11') : keydir = '/etc/ssh' else: keydir = '/etc' else: keydir = '/etc/ssh' for type_ in keytypes: key_filename = '%s/ssh_host_%s_key.pub' % (keydir, type_) keydata = get_file_content(key_filename) if keydata is not None: factname = 'ssh_host_key_%s_public' % type_ self.facts[factname] = keydata.split()[1] def get_pkg_mgr_facts(self): self.facts['pkg_mgr'] = 'unknown' for pkg in Facts.PKG_MGRS: if os.path.exists(pkg['path']): self.facts['pkg_mgr'] = pkg['name'] if self.facts['system'] == 'OpenBSD': self.facts['pkg_mgr'] = 'openbsd_pkg' def get_service_mgr_facts(self): #TODO: detect more custom init setups like bootscripts, dmd, s6, Epoch, runit, etc # also other OSs other than linux might need to check across several possible candidates # try various forms of querying pid 1 proc_1 = get_file_content('/proc/1/comm') if proc_1 is None: rc, proc_1, err = module.run_command("ps -p 1 -o comm|tail -n 1", use_unsafe_shell=True) else: proc_1 = os.path.basename(proc_1) if proc_1 == 'init' or proc_1.endswith('sh'): # many systems return init, so this cannot be trusted, if it ends in 'sh' it probalby is a shell in a container proc_1 = None # if not init/None it should be an identifiable or custom init, so we are done! if proc_1 is not None: self.facts['service_mgr'] = proc_1.strip() # start with the easy ones elif self.facts['distribution'] == 'MacOSX': #FIXME: find way to query executable, version matching is not ideal if LooseVersion(platform.mac_ver()[0]) >= LooseVersion('10.4'): self.facts['service_mgr'] = 'launchd' else: self.facts['service_mgr'] = 'systemstarter' elif 'BSD' in self.facts['system'] or self.facts['system'] in ['Bitrig', 'DragonFly']: #FIXME: we might want to break out to individual BSDs self.facts['service_mgr'] = 'bsdinit' elif self.facts['system'] == 'AIX': self.facts['service_mgr'] = 'src' elif self.facts['system'] == 'SunOS': #FIXME: smf? self.facts['service_mgr'] = 'svcs' elif self.facts['system'] == 'Linux': if self._check_systemd(): self.facts['service_mgr'] = 'systemd' elif module.get_bin_path('initctl') and os.path.exists("/etc/init/"): self.facts['service_mgr'] = 'upstart' elif os.path.realpath('/sbin/rc') == '/sbin/openrc': self.facts['service_mgr'] = 'openrc' elif os.path.exists('/etc/init.d/'): self.facts['service_mgr'] = 'sysvinit' if not self.facts.get('service_mgr', False): # if we cannot detect, fallback to generic 'service' self.facts['service_mgr'] = 'service' def get_lsb_facts(self): lsb_path = module.get_bin_path('lsb_release') if lsb_path: rc, out, err = module.run_command([lsb_path, "-a"]) if rc == 0: self.facts['lsb'] = {} for line in out.split('\n'): if len(line) < 1 or ':' not in line: continue value = line.split(':', 1)[1].strip() if 'LSB Version:' in line: self.facts['lsb']['release'] = value elif 'Distributor ID:' in line: self.facts['lsb']['id'] = value elif 'Description:' in line: self.facts['lsb']['description'] = value elif 'Release:' in line: self.facts['lsb']['release'] = value elif 'Codename:' in line: self.facts['lsb']['codename'] = value if 'lsb' in self.facts and 'release' in self.facts['lsb']: self.facts['lsb']['major_release'] = self.facts['lsb']['release'].split('.')[0] elif lsb_path is None and os.path.exists('/etc/lsb-release'): self.facts['lsb'] = {} for line in get_file_lines('/etc/lsb-release'): value = line.split('=',1)[1].strip() if 'DISTRIB_ID' in line: self.facts['lsb']['id'] = value elif 'DISTRIB_RELEASE' in line: self.facts['lsb']['release'] = value elif 'DISTRIB_DESCRIPTION' in line: self.facts['lsb']['description'] = value elif 'DISTRIB_CODENAME' in line: self.facts['lsb']['codename'] = value else: return self.facts if 'lsb' in self.facts and 'release' in self.facts['lsb']: self.facts['lsb']['major_release'] = self.facts['lsb']['release'].split('.')[0] def get_selinux_facts(self): if not HAVE_SELINUX: self.facts['selinux'] = False return self.facts['selinux'] = {} if not selinux.is_selinux_enabled(): self.facts['selinux']['status'] = 'disabled' else: self.facts['selinux']['status'] = 'enabled' try: self.facts['selinux']['policyvers'] = selinux.security_policyvers() except OSError: self.facts['selinux']['policyvers'] = 'unknown' try: (rc, configmode) = selinux.selinux_getenforcemode() if rc == 0: self.facts['selinux']['config_mode'] = Facts.SELINUX_MODE_DICT.get(configmode, 'unknown') else: self.facts['selinux']['config_mode'] = 'unknown' except OSError: self.facts['selinux']['config_mode'] = 'unknown' try: mode = selinux.security_getenforce() self.facts['selinux']['mode'] = Facts.SELINUX_MODE_DICT.get(mode, 'unknown') except OSError: self.facts['selinux']['mode'] = 'unknown' try: (rc, policytype) = selinux.selinux_getpolicytype() if rc == 0: self.facts['selinux']['type'] = policytype else: self.facts['selinux']['type'] = 'unknown' except OSError: self.facts['selinux']['type'] = 'unknown' def get_fips_facts(self): self.facts['fips'] = False data = get_file_content('/proc/sys/crypto/fips_enabled') if data and data == '1': self.facts['fips'] = True def get_date_time_facts(self): self.facts['date_time'] = {} now = datetime.datetime.now() self.facts['date_time']['year'] = now.strftime('%Y') self.facts['date_time']['month'] = now.strftime('%m') self.facts['date_time']['weekday'] = now.strftime('%A') self.facts['date_time']['weekday_number'] = now.strftime('%w') self.facts['date_time']['weeknumber'] = now.strftime('%W') self.facts['date_time']['day'] = now.strftime('%d') self.facts['date_time']['hour'] = now.strftime('%H') self.facts['date_time']['minute'] = now.strftime('%M') self.facts['date_time']['second'] = now.strftime('%S') self.facts['date_time']['epoch'] = now.strftime('%s') if self.facts['date_time']['epoch'] == '' or self.facts['date_time']['epoch'][0] == '%': self.facts['date_time']['epoch'] = str(int(time.time())) self.facts['date_time']['date'] = now.strftime('%Y-%m-%d') self.facts['date_time']['time'] = now.strftime('%H:%M:%S') self.facts['date_time']['iso8601_micro'] = now.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%fZ") self.facts['date_time']['iso8601'] = now.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") self.facts['date_time']['iso8601_basic'] = now.strftime("%Y%m%dT%H%M%S%f") self.facts['date_time']['iso8601_basic_short'] = now.strftime("%Y%m%dT%H%M%S") self.facts['date_time']['tz'] = time.strftime("%Z") self.facts['date_time']['tz_offset'] = time.strftime("%z") def _check_systemd(self): # tools must be installed if module.get_bin_path('systemctl'): # this should show if systemd is the boot init system, if checking init faild to mark as systemd # these mirror systemd's own sd_boot test http://www.freedesktop.org/software/systemd/man/sd_booted.html for canary in ["/run/systemd/system/", "/dev/.run/systemd/", "/dev/.systemd/"]: if os.path.exists(canary): return True return False # User def get_user_facts(self): self.facts['user_id'] = getpass.getuser() pwent = pwd.getpwnam(getpass.getuser()) self.facts['user_uid'] = pwent.pw_uid self.facts['user_gid'] = pwent.pw_gid self.facts['user_gecos'] = pwent.pw_gecos self.facts['user_dir'] = pwent.pw_dir self.facts['user_shell'] = pwent.pw_shell def get_env_facts(self): self.facts['env'] = {} for k,v in os.environ.iteritems(): self.facts['env'][k] = v def get_dns_facts(self): self.facts['dns'] = {} for line in get_file_content('/etc/resolv.conf', '').splitlines(): if line.startswith('#') or line.startswith(';') or line.strip() == '': continue tokens = line.split() if len(tokens) == 0: continue if tokens[0] == 'nameserver': self.facts['dns']['nameservers'] = [] for nameserver in tokens[1:]: self.facts['dns']['nameservers'].append(nameserver) elif tokens[0] == 'domain': self.facts['dns']['domain'] = tokens[1] elif tokens[0] == 'search': self.facts['dns']['search'] = [] for suffix in tokens[1:]: self.facts['dns']['search'].append(suffix) elif tokens[0] == 'sortlist': self.facts['dns']['sortlist'] = [] for address in tokens[1:]: self.facts['dns']['sortlist'].append(address) elif tokens[0] == 'options': self.facts['dns']['options'] = {} for option in tokens[1:]: option_tokens = option.split(':', 1) if len(option_tokens) == 0: continue val = len(option_tokens) == 2 and option_tokens[1] or True self.facts['dns']['options'][option_tokens[0]] = val class Hardware(Facts): """ This is a generic Hardware subclass of Facts. This should be further subclassed to implement per platform. If you subclass this, it should define: - memfree_mb - memtotal_mb - swapfree_mb - swaptotal_mb - processor (a list) - processor_cores - processor_count All subclasses MUST define platform. """ platform = 'Generic' def __new__(cls, *arguments, **keyword): subclass = cls for sc in Hardware.__subclasses__(): if sc.platform == platform.system(): subclass = sc return super(cls, subclass).__new__(subclass, *arguments, **keyword) def __init__(self): Facts.__init__(self) def populate(self): return self.facts class LinuxHardware(Hardware): """ Linux-specific subclass of Hardware. Defines memory and CPU facts: - memfree_mb - memtotal_mb - swapfree_mb - swaptotal_mb - processor (a list) - processor_cores - processor_count In addition, it also defines number of DMI facts and device facts. """ platform = 'Linux' # Originally only had these four as toplevelfacts ORIGINAL_MEMORY_FACTS = frozenset(('MemTotal', 'SwapTotal', 'MemFree', 'SwapFree')) # Now we have all of these in a dict structure MEMORY_FACTS = ORIGINAL_MEMORY_FACTS.union(('Buffers', 'Cached', 'SwapCached')) def __init__(self): Hardware.__init__(self) def populate(self): self.get_cpu_facts() self.get_memory_facts() self.get_dmi_facts() self.get_device_facts() self.get_uptime_facts() self.get_lvm_facts() try: self.get_mount_facts() except TimeoutError: pass return self.facts def get_memory_facts(self): if not os.access("/proc/meminfo", os.R_OK): return memstats = {} for line in get_file_lines("/proc/meminfo"): data = line.split(":", 1) key = data[0] if key in self.ORIGINAL_MEMORY_FACTS: val = data[1].strip().split(' ')[0] self.facts["%s_mb" % key.lower()] = long(val) / 1024 if key in self.MEMORY_FACTS: val = data[1].strip().split(' ')[0] memstats[key.lower()] = long(val) / 1024 if None not in (memstats.get('memtotal'), memstats.get('memfree')): memstats['real:used'] = memstats['memtotal'] - memstats['memfree'] if None not in (memstats.get('cached'), memstats.get('memfree'), memstats.get('buffers')): memstats['nocache:free'] = memstats['cached'] + memstats['memfree'] + memstats['buffers'] if None not in (memstats.get('memtotal'), memstats.get('nocache:free')): memstats['nocache:used'] = memstats['memtotal'] - memstats['nocache:free'] if None not in (memstats.get('swaptotal'), memstats.get('swapfree')): memstats['swap:used'] = memstats['swaptotal'] - memstats['swapfree'] self.facts['memory_mb'] = { 'real' : { 'total': memstats.get('memtotal'), 'used': memstats.get('real:used'), 'free': memstats.get('memfree'), }, 'nocache' : { 'free': memstats.get('nocache:free'), 'used': memstats.get('nocache:used'), }, 'swap' : { 'total': memstats.get('swaptotal'), 'free': memstats.get('swapfree'), 'used': memstats.get('swap:used'), 'cached': memstats.get('swapcached'), }, } def get_cpu_facts(self): i = 0 vendor_id_occurrence = 0 model_name_occurrence = 0 physid = 0 coreid = 0 sockets = {} cores = {} xen = False xen_paravirt = False try: if os.path.exists('/proc/xen'): xen = True else: for line in get_file_lines('/sys/hypervisor/type'): if line.strip() == 'xen': xen = True # Only interested in the first line break except IOError: pass if not os.access("/proc/cpuinfo", os.R_OK): return self.facts['processor'] = [] for line in get_file_lines('/proc/cpuinfo'): data = line.split(":", 1) key = data[0].strip() if xen: if key == 'flags': # Check for vme cpu flag, Xen paravirt does not expose this. # Need to detect Xen paravirt because it exposes cpuinfo # differently than Xen HVM or KVM and causes reporting of # only a single cpu core. if 'vme' not in data: xen_paravirt = True # model name is for Intel arch, Processor (mind the uppercase P) # works for some ARM devices, like the Sheevaplug. if key in ['model name', 'Processor', 'vendor_id', 'cpu', 'Vendor']: if 'processor' not in self.facts: self.facts['processor'] = [] self.facts['processor'].append(data[1].strip()) if key == 'vendor_id': vendor_id_occurrence += 1 if key == 'model name': model_name_occurrence += 1 i += 1 elif key == 'physical id': physid = data[1].strip() if physid not in sockets: sockets[physid] = 1 elif key == 'core id': coreid = data[1].strip() if coreid not in sockets: cores[coreid] = 1 elif key == 'cpu cores': sockets[physid] = int(data[1].strip()) elif key == 'siblings': cores[coreid] = int(data[1].strip()) elif key == '# processors': self.facts['processor_cores'] = int(data[1].strip()) if vendor_id_occurrence == model_name_occurrence: i = vendor_id_occurrence if self.facts['architecture'] != 's390x': if xen_paravirt: self.facts['processor_count'] = i self.facts['processor_cores'] = i self.facts['processor_threads_per_core'] = 1 self.facts['processor_vcpus'] = i else: self.facts['processor_count'] = sockets and len(sockets) or i self.facts['processor_cores'] = sockets.values() and sockets.values()[0] or 1 self.facts['processor_threads_per_core'] = ((cores.values() and cores.values()[0] or 1) / self.facts['processor_cores']) self.facts['processor_vcpus'] = (self.facts['processor_threads_per_core'] * self.facts['processor_count'] * self.facts['processor_cores']) def get_dmi_facts(self): ''' learn dmi facts from system Try /sys first for dmi related facts. If that is not available, fall back to dmidecode executable ''' if os.path.exists('/sys/devices/virtual/dmi/id/product_name'): # Use kernel DMI info, if available # DMI SPEC -- http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.0.pdf FORM_FACTOR = [ "Unknown", "Other", "Unknown", "Desktop", "Low Profile Desktop", "Pizza Box", "Mini Tower", "Tower", "Portable", "Laptop", "Notebook", "Hand Held", "Docking Station", "All In One", "Sub Notebook", "Space-saving", "Lunch Box", "Main Server Chassis", "Expansion Chassis", "Sub Chassis", "Bus Expansion Chassis", "Peripheral Chassis", "RAID Chassis", "Rack Mount Chassis", "Sealed-case PC", "Multi-system", "CompactPCI", "AdvancedTCA", "Blade" ] DMI_DICT = { 'bios_date': '/sys/devices/virtual/dmi/id/bios_date', 'bios_version': '/sys/devices/virtual/dmi/id/bios_version', 'form_factor': '/sys/devices/virtual/dmi/id/chassis_type', 'product_name': '/sys/devices/virtual/dmi/id/product_name', 'product_serial': '/sys/devices/virtual/dmi/id/product_serial', 'product_uuid': '/sys/devices/virtual/dmi/id/product_uuid', 'product_version': '/sys/devices/virtual/dmi/id/product_version', 'system_vendor': '/sys/devices/virtual/dmi/id/sys_vendor' } for (key,path) in DMI_DICT.items(): data = get_file_content(path) if data is not None: if key == 'form_factor': try: self.facts['form_factor'] = FORM_FACTOR[int(data)] except IndexError: self.facts['form_factor'] = 'unknown (%s)' % data else: self.facts[key] = data else: self.facts[key] = 'NA' else: # Fall back to using dmidecode, if available dmi_bin = module.get_bin_path('dmidecode') DMI_DICT = { 'bios_date': 'bios-release-date', 'bios_version': 'bios-version', 'form_factor': 'chassis-type', 'product_name': 'system-product-name', 'product_serial': 'system-serial-number', 'product_uuid': 'system-uuid', 'product_version': 'system-version', 'system_vendor': 'system-manufacturer' } for (k, v) in DMI_DICT.items(): if dmi_bin is not None: (rc, out, err) = module.run_command('%s -s %s' % (dmi_bin, v)) if rc == 0: # Strip out commented lines (specific dmidecode output) thisvalue = ''.join([ line for line in out.split('\n') if not line.startswith('#') ]) try: json.dumps(thisvalue) except UnicodeDecodeError: thisvalue = "NA" self.facts[k] = thisvalue else: self.facts[k] = 'NA' else: self.facts[k] = 'NA' @timeout(10) def get_mount_facts(self): self.facts['mounts'] = [] mtab = get_file_content('/etc/mtab', '') for line in mtab.split('\n'): if line.startswith('/'): fields = line.rstrip('\n').split() if(fields[2] != 'none'): size_total = None size_available = None try: statvfs_result = os.statvfs(fields[1]) size_total = statvfs_result.f_bsize * statvfs_result.f_blocks size_available = statvfs_result.f_bsize * (statvfs_result.f_bavail) except OSError: continue uuid = 'NA' lsblkPath = module.get_bin_path("lsblk") if lsblkPath: rc, out, err = module.run_command("%s -ln --output UUID %s" % (lsblkPath, fields[0]), use_unsafe_shell=True) if rc == 0: uuid = out.strip() self.facts['mounts'].append( {'mount': fields[1], 'device':fields[0], 'fstype': fields[2], 'options': fields[3], # statvfs data 'size_total': size_total, 'size_available': size_available, 'uuid': uuid, }) def get_device_facts(self): self.facts['devices'] = {} lspci = module.get_bin_path('lspci') if lspci: rc, pcidata, err = module.run_command([lspci, '-D']) else: pcidata = None try: block_devs = os.listdir("/sys/block") except OSError: return for block in block_devs: virtual = 1 sysfs_no_links = 0 try: path = os.readlink(os.path.join("/sys/block/", block)) except OSError, e: if e.errno == errno.EINVAL: path = block sysfs_no_links = 1 else: continue if "virtual" in path: continue sysdir = os.path.join("/sys/block", path) if sysfs_no_links == 1: for folder in os.listdir(sysdir): if "device" in folder: virtual = 0 break if virtual: continue d = {} diskname = os.path.basename(sysdir) for key in ['vendor', 'model']: d[key] = get_file_content(sysdir + "/device/" + key) for key,test in [ ('removable','/removable'), \ ('support_discard','/queue/discard_granularity'), ]: d[key] = get_file_content(sysdir + test) d['partitions'] = {} for folder in os.listdir(sysdir): m = re.search("(" + diskname + "\d+)", folder) if m: part = {} partname = m.group(1) part_sysdir = sysdir + "/" + partname part['start'] = get_file_content(part_sysdir + "/start",0) part['sectors'] = get_file_content(part_sysdir + "/size",0) part['sectorsize'] = get_file_content(part_sysdir + "/queue/logical_block_size") if not part['sectorsize']: part['sectorsize'] = get_file_content(part_sysdir + "/queue/hw_sector_size",512) part['size'] = module.pretty_bytes((float(part['sectors']) * float(part['sectorsize']))) d['partitions'][partname] = part d['rotational'] = get_file_content(sysdir + "/queue/rotational") d['scheduler_mode'] = "" scheduler = get_file_content(sysdir + "/queue/scheduler") if scheduler is not None: m = re.match(".*?(\[(.*)\])", scheduler) if m: d['scheduler_mode'] = m.group(2) d['sectors'] = get_file_content(sysdir + "/size") if not d['sectors']: d['sectors'] = 0 d['sectorsize'] = get_file_content(sysdir + "/queue/logical_block_size") if not d['sectorsize']: d['sectorsize'] = get_file_content(sysdir + "/queue/hw_sector_size",512) d['size'] = module.pretty_bytes(float(d['sectors']) * float(d['sectorsize'])) d['host'] = "" # domains are numbered (0 to ffff), bus (0 to ff), slot (0 to 1f), and function (0 to 7). m = re.match(".+/([a-f0-9]{4}:[a-f0-9]{2}:[0|1][a-f0-9]\.[0-7])/", sysdir) if m and pcidata: pciid = m.group(1) did = re.escape(pciid) m = re.search("^" + did + "\s(.*)$", pcidata, re.MULTILINE) if m: d['host'] = m.group(1) d['holders'] = [] if os.path.isdir(sysdir + "/holders"): for folder in os.listdir(sysdir + "/holders"): if not folder.startswith("dm-"): continue name = get_file_content(sysdir + "/holders/" + folder + "/dm/name") if name: d['holders'].append(name) else: d['holders'].append(folder) self.facts['devices'][diskname] = d def get_uptime_facts(self): uptime_file_content = get_file_content('/proc/uptime') if uptime_file_content: uptime_seconds_string = uptime_file_content.split(' ')[0] self.facts['uptime_seconds'] = int(float(uptime_seconds_string)) def get_lvm_facts(self): """ Get LVM Facts if running as root and lvm utils are available """ if os.getuid() == 0 and module.get_bin_path('vgs'): lvm_util_options = '--noheadings --nosuffix --units g' vgs_path = module.get_bin_path('vgs') #vgs fields: VG #PV #LV #SN Attr VSize VFree vgs={} if vgs_path: rc, vg_lines, err = module.run_command( '%s %s' % (vgs_path, lvm_util_options)) for vg_line in vg_lines.splitlines(): items = vg_line.split() vgs[items[0]] = {'size_g':items[-2], 'free_g':items[-1], 'num_lvs': items[2], 'num_pvs': items[1]} lvs_path = module.get_bin_path('lvs') #lvs fields: #LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert lvs = {} if lvs_path: rc, lv_lines, err = module.run_command( '%s %s' % (lvs_path, lvm_util_options)) for lv_line in lv_lines.splitlines(): items = lv_line.split() lvs[items[0]] = {'size_g': items[3], 'vg': items[1]} self.facts['lvm'] = {'lvs': lvs, 'vgs': vgs} class SunOSHardware(Hardware): """ In addition to the generic memory and cpu facts, this also sets swap_reserved_mb and swap_allocated_mb that is available from *swap -s*. """ platform = 'SunOS' def __init__(self): Hardware.__init__(self) def populate(self): self.get_cpu_facts() self.get_memory_facts() try: self.get_mount_facts() except TimeoutError: pass return self.facts def get_cpu_facts(self): physid = 0 sockets = {} rc, out, err = module.run_command("/usr/bin/kstat cpu_info") self.facts['processor'] = [] for line in out.split('\n'): if len(line) < 1: continue data = line.split(None, 1) key = data[0].strip() # "brand" works on Solaris 10 & 11. "implementation" for Solaris 9. if key == 'module:': brand = '' elif key == 'brand': brand = data[1].strip() elif key == 'clock_MHz': clock_mhz = data[1].strip() elif key == 'implementation': processor = brand or data[1].strip() # Add clock speed to description for SPARC CPU if self.facts['machine'] != 'i86pc': processor += " @ " + clock_mhz + "MHz" if 'processor' not in self.facts: self.facts['processor'] = [] self.facts['processor'].append(processor) elif key == 'chip_id': physid = data[1].strip() if physid not in sockets: sockets[physid] = 1 else: sockets[physid] += 1 # Counting cores on Solaris can be complicated. # https://blogs.oracle.com/mandalika/entry/solaris_show_me_the_cpu # Treat 'processor_count' as physical sockets and 'processor_cores' as # virtual CPUs visisble to Solaris. Not a true count of cores for modern SPARC as # these processors have: sockets -> cores -> threads/virtual CPU. if len(sockets) > 0: self.facts['processor_count'] = len(sockets) self.facts['processor_cores'] = reduce(lambda x, y: x + y, sockets.values()) else: self.facts['processor_cores'] = 'NA' self.facts['processor_count'] = len(self.facts['processor']) def get_memory_facts(self): rc, out, err = module.run_command(["/usr/sbin/prtconf"]) for line in out.split('\n'): if 'Memory size' in line: self.facts['memtotal_mb'] = line.split()[2] rc, out, err = module.run_command("/usr/sbin/swap -s") allocated = long(out.split()[1][:-1]) reserved = long(out.split()[5][:-1]) used = long(out.split()[8][:-1]) free = long(out.split()[10][:-1]) self.facts['swapfree_mb'] = free / 1024 self.facts['swaptotal_mb'] = (free + used) / 1024 self.facts['swap_allocated_mb'] = allocated / 1024 self.facts['swap_reserved_mb'] = reserved / 1024 @timeout(10) def get_mount_facts(self): self.facts['mounts'] = [] # For a detailed format description see mnttab(4) # special mount_point fstype options time fstab = get_file_content('/etc/mnttab') if fstab: for line in fstab.split('\n'): fields = line.rstrip('\n').split('\t') self.facts['mounts'].append({'mount': fields[1], 'device': fields[0], 'fstype' : fields[2], 'options': fields[3], 'time': fields[4]}) class OpenBSDHardware(Hardware): """ OpenBSD-specific subclass of Hardware. Defines memory, CPU and device facts: - memfree_mb - memtotal_mb - swapfree_mb - swaptotal_mb - processor (a list) - processor_cores - processor_count - processor_speed - devices """ platform = 'OpenBSD' DMESG_BOOT = '/var/run/dmesg.boot' def __init__(self): Hardware.__init__(self) def populate(self): self.sysctl = self.get_sysctl() self.get_memory_facts() self.get_processor_facts() self.get_device_facts() self.get_mount_facts() return self.facts def get_sysctl(self): rc, out, err = module.run_command(["/sbin/sysctl", "hw"]) if rc != 0: return dict() sysctl = dict() for line in out.splitlines(): (key, value) = line.split('=') sysctl[key] = value.strip() return sysctl @timeout(10) def get_mount_facts(self): self.facts['mounts'] = [] fstab = get_file_content('/etc/fstab') if fstab: for line in fstab.split('\n'): if line.startswith('#') or line.strip() == '': continue fields = re.sub(r'\s+',' ',line.rstrip('\n')).split() if fields[1] == 'none' or fields[3] == 'xx': continue self.facts['mounts'].append({'mount': fields[1], 'device': fields[0], 'fstype' : fields[2], 'options': fields[3]}) def get_memory_facts(self): # Get free memory. vmstat output looks like: # procs memory page disks traps cpu # r b w avm fre flt re pi po fr sr wd0 fd0 int sys cs us sy id # 0 0 0 47512 28160 51 0 0 0 0 0 1 0 116 89 17 0 1 99 rc, out, err = module.run_command("/usr/bin/vmstat") if rc == 0: self.facts['memfree_mb'] = long(out.splitlines()[-1].split()[4]) / 1024 self.facts['memtotal_mb'] = long(self.sysctl['hw.usermem']) / 1024 / 1024 # Get swapctl info. swapctl output looks like: # total: 69268 1K-blocks allocated, 0 used, 69268 available # And for older OpenBSD: # total: 69268k bytes allocated = 0k used, 69268k available rc, out, err = module.run_command("/sbin/swapctl -sk") if rc == 0: swaptrans = maketrans(' ', ' ') data = out.split() self.facts['swapfree_mb'] = long(data[-2].translate(swaptrans, "kmg")) / 1024 self.facts['swaptotal_mb'] = long(data[1].translate(swaptrans, "kmg")) / 1024 def get_processor_facts(self): processor = [] dmesg_boot = get_file_content(OpenBSDHardware.DMESG_BOOT) if not dmesg_boot: rc, dmesg_boot, err = module.run_command("/sbin/dmesg") i = 0 for line in dmesg_boot.splitlines(): if line.split(' ', 1)[0] == 'cpu%i:' % i: processor.append(line.split(' ', 1)[1]) i = i + 1 processor_count = i self.facts['processor'] = processor self.facts['processor_count'] = processor_count # I found no way to figure out the number of Cores per CPU in OpenBSD self.facts['processor_cores'] = 'NA' def get_device_facts(self): devices = [] devices.extend(self.sysctl['hw.disknames'].split(',')) self.facts['devices'] = devices class FreeBSDHardware(Hardware): """ FreeBSD-specific subclass of Hardware. Defines memory and CPU facts: - memfree_mb - memtotal_mb - swapfree_mb - swaptotal_mb - processor (a list) - processor_cores - processor_count - devices """ platform = 'FreeBSD' DMESG_BOOT = '/var/run/dmesg.boot' def __init__(self): Hardware.__init__(self) def populate(self): self.get_cpu_facts() self.get_memory_facts() self.get_dmi_facts() self.get_device_facts() try: self.get_mount_facts() except TimeoutError: pass return self.facts def get_cpu_facts(self): self.facts['processor'] = [] rc, out, err = module.run_command("/sbin/sysctl -n hw.ncpu") self.facts['processor_count'] = out.strip() dmesg_boot = get_file_content(FreeBSDHardware.DMESG_BOOT) if not dmesg_boot: rc, dmesg_boot, err = module.run_command("/sbin/dmesg") for line in dmesg_boot.split('\n'): if 'CPU:' in line: cpu = re.sub(r'CPU:\s+', r"", line) self.facts['processor'].append(cpu.strip()) if 'Logical CPUs per core' in line: self.facts['processor_cores'] = line.split()[4] def get_memory_facts(self): rc, out, err = module.run_command("/sbin/sysctl vm.stats") for line in out.split('\n'): data = line.split() if 'vm.stats.vm.v_page_size' in line: pagesize = long(data[1]) if 'vm.stats.vm.v_page_count' in line: pagecount = long(data[1]) if 'vm.stats.vm.v_free_count' in line: freecount = long(data[1]) self.facts['memtotal_mb'] = pagesize * pagecount / 1024 / 1024 self.facts['memfree_mb'] = pagesize * freecount / 1024 / 1024 # Get swapinfo. swapinfo output looks like: # Device 1M-blocks Used Avail Capacity # /dev/ada0p3 314368 0 314368 0% # rc, out, err = module.run_command("/usr/sbin/swapinfo -k") lines = out.split('\n') if len(lines[-1]) == 0: lines.pop() data = lines[-1].split() if data[0] != 'Device': self.facts['swaptotal_mb'] = int(data[1]) / 1024 self.facts['swapfree_mb'] = int(data[3]) / 1024 @timeout(10) def get_mount_facts(self): self.facts['mounts'] = [] fstab = get_file_content('/etc/fstab') if fstab: for line in fstab.split('\n'): if line.startswith('#') or line.strip() == '': continue fields = re.sub(r'\s+',' ',line.rstrip('\n')).split() self.facts['mounts'].append({'mount': fields[1], 'device': fields[0], 'fstype' : fields[2], 'options': fields[3]}) def get_device_facts(self): sysdir = '/dev' self.facts['devices'] = {} drives = re.compile('(ada?\d+|da\d+|a?cd\d+)') #TODO: rc, disks, err = module.run_command("/sbin/sysctl kern.disks") slices = re.compile('(ada?\d+s\d+\w*|da\d+s\d+\w*)') if os.path.isdir(sysdir): dirlist = sorted(os.listdir(sysdir)) for device in dirlist: d = drives.match(device) if d: self.facts['devices'][d.group(1)] = [] s = slices.match(device) if s: self.facts['devices'][d.group(1)].append(s.group(1)) def get_dmi_facts(self): ''' learn dmi facts from system Use dmidecode executable if available''' # Fall back to using dmidecode, if available dmi_bin = module.get_bin_path('dmidecode') DMI_DICT = dict( bios_date='bios-release-date', bios_version='bios-version', form_factor='chassis-type', product_name='system-product-name', product_serial='system-serial-number', product_uuid='system-uuid', product_version='system-version', system_vendor='system-manufacturer' ) for (k, v) in DMI_DICT.items(): if dmi_bin is not None: (rc, out, err) = module.run_command('%s -s %s' % (dmi_bin, v)) if rc == 0: # Strip out commented lines (specific dmidecode output) self.facts[k] = ''.join([ line for line in out.split('\n') if not line.startswith('#') ]) try: json.dumps(self.facts[k]) except UnicodeDecodeError: self.facts[k] = 'NA' else: self.facts[k] = 'NA' else: self.facts[k] = 'NA' class DragonFlyHardware(FreeBSDHardware): pass class NetBSDHardware(Hardware): """ NetBSD-specific subclass of Hardware. Defines memory and CPU facts: - memfree_mb - memtotal_mb - swapfree_mb - swaptotal_mb - processor (a list) - processor_cores - processor_count - devices """ platform = 'NetBSD' MEMORY_FACTS = ['MemTotal', 'SwapTotal', 'MemFree', 'SwapFree'] def __init__(self): Hardware.__init__(self) def populate(self): self.get_cpu_facts() self.get_memory_facts() try: self.get_mount_facts() except TimeoutError: pass return self.facts def get_cpu_facts(self): i = 0 physid = 0 sockets = {} if not os.access("/proc/cpuinfo", os.R_OK): return self.facts['processor'] = [] for line in get_file_lines("/proc/cpuinfo"): data = line.split(":", 1) key = data[0].strip() # model name is for Intel arch, Processor (mind the uppercase P) # works for some ARM devices, like the Sheevaplug. if key == 'model name' or key == 'Processor': if 'processor' not in self.facts: self.facts['processor'] = [] self.facts['processor'].append(data[1].strip()) i += 1 elif key == 'physical id': physid = data[1].strip() if physid not in sockets: sockets[physid] = 1 elif key == 'cpu cores': sockets[physid] = int(data[1].strip()) if len(sockets) > 0: self.facts['processor_count'] = len(sockets) self.facts['processor_cores'] = reduce(lambda x, y: x + y, sockets.values()) else: self.facts['processor_count'] = i self.facts['processor_cores'] = 'NA' def get_memory_facts(self): if not os.access("/proc/meminfo", os.R_OK): return for line in get_file_lines("/proc/meminfo"): data = line.split(":", 1) key = data[0] if key in NetBSDHardware.MEMORY_FACTS: val = data[1].strip().split(' ')[0] self.facts["%s_mb" % key.lower()] = long(val) / 1024 @timeout(10) def get_mount_facts(self): self.facts['mounts'] = [] fstab = get_file_content('/etc/fstab') if fstab: for line in fstab.split('\n'): if line.startswith('#') or line.strip() == '': continue fields = re.sub(r'\s+',' ',line.rstrip('\n')).split() self.facts['mounts'].append({'mount': fields[1], 'device': fields[0], 'fstype' : fields[2], 'options': fields[3]}) class AIX(Hardware): """ AIX-specific subclass of Hardware. Defines memory and CPU facts: - memfree_mb - memtotal_mb - swapfree_mb - swaptotal_mb - processor (a list) - processor_cores - processor_count """ platform = 'AIX' def __init__(self): Hardware.__init__(self) def populate(self): self.get_cpu_facts() self.get_memory_facts() self.get_dmi_facts() return self.facts def get_cpu_facts(self): self.facts['processor'] = [] rc, out, err = module.run_command("/usr/sbin/lsdev -Cc processor") if out: i = 0 for line in out.split('\n'): if 'Available' in line: if i == 0: data = line.split(' ') cpudev = data[0] i += 1 self.facts['processor_count'] = int(i) rc, out, err = module.run_command("/usr/sbin/lsattr -El " + cpudev + " -a type") data = out.split(' ') self.facts['processor'] = data[1] rc, out, err = module.run_command("/usr/sbin/lsattr -El " + cpudev + " -a smt_threads") data = out.split(' ') self.facts['processor_cores'] = int(data[1]) def get_memory_facts(self): pagesize = 4096 rc, out, err = module.run_command("/usr/bin/vmstat -v") for line in out.split('\n'): data = line.split() if 'memory pages' in line: pagecount = long(data[0]) if 'free pages' in line: freecount = long(data[0]) self.facts['memtotal_mb'] = pagesize * pagecount / 1024 / 1024 self.facts['memfree_mb'] = pagesize * freecount / 1024 / 1024 # Get swapinfo. swapinfo output looks like: # Device 1M-blocks Used Avail Capacity # /dev/ada0p3 314368 0 314368 0% # rc, out, err = module.run_command("/usr/sbin/lsps -s") if out: lines = out.split('\n') data = lines[1].split() swaptotal_mb = long(data[0].rstrip('MB')) percused = int(data[1].rstrip('%')) self.facts['swaptotal_mb'] = swaptotal_mb self.facts['swapfree_mb'] = long(swaptotal_mb * ( 100 - percused ) / 100) def get_dmi_facts(self): rc, out, err = module.run_command("/usr/sbin/lsattr -El sys0 -a fwversion") data = out.split() self.facts['firmware_version'] = data[1].strip('IBM,') class HPUX(Hardware): """ HP-UX-specific subclass of Hardware. Defines memory and CPU facts: - memfree_mb - memtotal_mb - swapfree_mb - swaptotal_mb - processor - processor_cores - processor_count - model - firmware """ platform = 'HP-UX' def __init__(self): Hardware.__init__(self) def populate(self): self.get_cpu_facts() self.get_memory_facts() self.get_hw_facts() return self.facts def get_cpu_facts(self): if self.facts['architecture'] == '9000/800': rc, out, err = module.run_command("ioscan -FkCprocessor | wc -l", use_unsafe_shell=True) self.facts['processor_count'] = int(out.strip()) #Working with machinfo mess elif self.facts['architecture'] == 'ia64': if self.facts['distribution_version'] == "B.11.23": rc, out, err = module.run_command("/usr/contrib/bin/machinfo | grep 'Number of CPUs'", use_unsafe_shell=True) self.facts['processor_count'] = int(out.strip().split('=')[1]) rc, out, err = module.run_command("/usr/contrib/bin/machinfo | grep 'processor family'", use_unsafe_shell=True) self.facts['processor'] = re.search('.*(Intel.*)', out).groups()[0].strip() rc, out, err = module.run_command("ioscan -FkCprocessor | wc -l", use_unsafe_shell=True) self.facts['processor_cores'] = int(out.strip()) if self.facts['distribution_version'] == "B.11.31": #if machinfo return cores strings release B.11.31 > 1204 rc, out, err = module.run_command("/usr/contrib/bin/machinfo | grep core | wc -l", use_unsafe_shell=True) if out.strip()== '0': rc, out, err = module.run_command("/usr/contrib/bin/machinfo | grep Intel", use_unsafe_shell=True) self.facts['processor_count'] = int(out.strip().split(" ")[0]) #If hyperthreading is active divide cores by 2 rc, out, err = module.run_command("/usr/sbin/psrset | grep LCPU", use_unsafe_shell=True) data = re.sub(' +',' ',out).strip().split(' ') if len(data) == 1: hyperthreading = 'OFF' else: hyperthreading = data[1] rc, out, err = module.run_command("/usr/contrib/bin/machinfo | grep logical", use_unsafe_shell=True) data = out.strip().split(" ") if hyperthreading == 'ON': self.facts['processor_cores'] = int(data[0])/2 else: if len(data) == 1: self.facts['processor_cores'] = self.facts['processor_count'] else: self.facts['processor_cores'] = int(data[0]) rc, out, err = module.run_command("/usr/contrib/bin/machinfo | grep Intel |cut -d' ' -f4-", use_unsafe_shell=True) self.facts['processor'] = out.strip() else: rc, out, err = module.run_command("/usr/contrib/bin/machinfo | egrep 'socket[s]?$' | tail -1", use_unsafe_shell=True) self.facts['processor_count'] = int(out.strip().split(" ")[0]) rc, out, err = module.run_command("/usr/contrib/bin/machinfo | grep -e '[0-9] core' | tail -1", use_unsafe_shell=True) self.facts['processor_cores'] = int(out.strip().split(" ")[0]) rc, out, err = module.run_command("/usr/contrib/bin/machinfo | grep Intel", use_unsafe_shell=True) self.facts['processor'] = out.strip() def get_memory_facts(self): pagesize = 4096 rc, out, err = module.run_command("/usr/bin/vmstat | tail -1", use_unsafe_shell=True) data = int(re.sub(' +',' ',out).split(' ')[5].strip()) self.facts['memfree_mb'] = pagesize * data / 1024 / 1024 if self.facts['architecture'] == '9000/800': try: rc, out, err = module.run_command("grep Physical /var/adm/syslog/syslog.log") data = re.search('.*Physical: ([0-9]*) Kbytes.*',out).groups()[0].strip() self.facts['memtotal_mb'] = int(data) / 1024 except AttributeError: #For systems where memory details aren't sent to syslog or the log has rotated, use parsed #adb output. Unfortunately /dev/kmem doesn't have world-read, so this only works as root. if os.access("/dev/kmem", os.R_OK): rc, out, err = module.run_command("echo 'phys_mem_pages/D' | adb -k /stand/vmunix /dev/kmem | tail -1 | awk '{print $2}'", use_unsafe_shell=True) if not err: data = out self.facts['memtotal_mb'] = int(data) / 256 else: rc, out, err = module.run_command("/usr/contrib/bin/machinfo | grep Memory", use_unsafe_shell=True) data = re.search('Memory[\ :=]*([0-9]*).*MB.*',out).groups()[0].strip() self.facts['memtotal_mb'] = int(data) rc, out, err = module.run_command("/usr/sbin/swapinfo -m -d -f -q") self.facts['swaptotal_mb'] = int(out.strip()) rc, out, err = module.run_command("/usr/sbin/swapinfo -m -d -f | egrep '^dev|^fs'", use_unsafe_shell=True) swap = 0 for line in out.strip().split('\n'): swap += int(re.sub(' +',' ',line).split(' ')[3].strip()) self.facts['swapfree_mb'] = swap def get_hw_facts(self): rc, out, err = module.run_command("model") self.facts['model'] = out.strip() if self.facts['architecture'] == 'ia64': separator = ':' if self.facts['distribution_version'] == "B.11.23": separator = '=' rc, out, err = module.run_command("/usr/contrib/bin/machinfo |grep -i 'Firmware revision' | grep -v BMC", use_unsafe_shell=True) self.facts['firmware_version'] = out.split(separator)[1].strip() class Darwin(Hardware): """ Darwin-specific subclass of Hardware. Defines memory and CPU facts: - processor - processor_cores - memtotal_mb - memfree_mb - model - osversion - osrevision """ platform = 'Darwin' def __init__(self): Hardware.__init__(self) def populate(self): self.sysctl = self.get_sysctl() self.get_mac_facts() self.get_cpu_facts() self.get_memory_facts() return self.facts def get_sysctl(self): rc, out, err = module.run_command(["/usr/sbin/sysctl", "hw", "machdep", "kern"]) if rc != 0: return dict() sysctl = dict() for line in out.splitlines(): if line.rstrip("\n"): (key, value) = re.split(' = |: ', line, maxsplit=1) sysctl[key] = value.strip() return sysctl def get_system_profile(self): rc, out, err = module.run_command(["/usr/sbin/system_profiler", "SPHardwareDataType"]) if rc != 0: return dict() system_profile = dict() for line in out.splitlines(): if ': ' in line: (key, value) = line.split(': ', 1) system_profile[key.strip()] = ' '.join(value.strip().split()) return system_profile def get_mac_facts(self): rc, out, err = module.run_command("sysctl hw.model") if rc == 0: self.facts['model'] = out.splitlines()[-1].split()[1] self.facts['osversion'] = self.sysctl['kern.osversion'] self.facts['osrevision'] = self.sysctl['kern.osrevision'] def get_cpu_facts(self): if 'machdep.cpu.brand_string' in self.sysctl: # Intel self.facts['processor'] = self.sysctl['machdep.cpu.brand_string'] self.facts['processor_cores'] = self.sysctl['machdep.cpu.core_count'] else: # PowerPC system_profile = self.get_system_profile() self.facts['processor'] = '%s @ %s' % (system_profile['Processor Name'], system_profile['Processor Speed']) self.facts['processor_cores'] = self.sysctl['hw.physicalcpu'] def get_memory_facts(self): self.facts['memtotal_mb'] = long(self.sysctl['hw.memsize']) / 1024 / 1024 rc, out, err = module.run_command("sysctl hw.usermem") if rc == 0: self.facts['memfree_mb'] = long(out.splitlines()[-1].split()[1]) / 1024 / 1024 class Network(Facts): """ This is a generic Network subclass of Facts. This should be further subclassed to implement per platform. If you subclass this, you must define: - interfaces (a list of interface names) - interface_<name> dictionary of ipv4, ipv6, and mac address information. All subclasses MUST define platform. """ platform = 'Generic' IPV6_SCOPE = { '0' : 'global', '10' : 'host', '20' : 'link', '40' : 'admin', '50' : 'site', '80' : 'organization' } def __new__(cls, *arguments, **keyword): subclass = cls for sc in Network.__subclasses__(): if sc.platform == platform.system(): subclass = sc return super(cls, subclass).__new__(subclass, *arguments, **keyword) def __init__(self, module): self.module = module Facts.__init__(self) def populate(self): return self.facts class LinuxNetwork(Network): """ This is a Linux-specific subclass of Network. It defines - interfaces (a list of interface names) - interface_<name> dictionary of ipv4, ipv6, and mac address information. - all_ipv4_addresses and all_ipv6_addresses: lists of all configured addresses. - ipv4_address and ipv6_address: the first non-local address for each family. """ platform = 'Linux' def __init__(self, module): Network.__init__(self, module) def populate(self): ip_path = self.module.get_bin_path('ip') if ip_path is None: return self.facts default_ipv4, default_ipv6 = self.get_default_interfaces(ip_path) interfaces, ips = self.get_interfaces_info(ip_path, default_ipv4, default_ipv6) self.facts['interfaces'] = interfaces.keys() for iface in interfaces: self.facts[iface] = interfaces[iface] self.facts['default_ipv4'] = default_ipv4 self.facts['default_ipv6'] = default_ipv6 self.facts['all_ipv4_addresses'] = ips['all_ipv4_addresses'] self.facts['all_ipv6_addresses'] = ips['all_ipv6_addresses'] return self.facts def get_default_interfaces(self, ip_path): # Use the commands: # ip -4 route get 8.8.8.8 -> Google public DNS # ip -6 route get 2404:6800:400a:800::1012 -> ipv6.google.com # to find out the default outgoing interface, address, and gateway command = dict( v4 = [ip_path, '-4', 'route', 'get', '8.8.8.8'], v6 = [ip_path, '-6', 'route', 'get', '2404:6800:400a:800::1012'] ) interface = dict(v4 = {}, v6 = {}) for v in 'v4', 'v6': if v == 'v6' and self.facts['os_family'] == 'RedHat' \ and self.facts['distribution_version'].startswith('4.'): continue if v == 'v6' and not socket.has_ipv6: continue rc, out, err = module.run_command(command[v]) if not out: # v6 routing may result in # RTNETLINK answers: Invalid argument continue words = out.split('\n')[0].split() # A valid output starts with the queried address on the first line if len(words) > 0 and words[0] == command[v][-1]: for i in range(len(words) - 1): if words[i] == 'dev': interface[v]['interface'] = words[i+1] elif words[i] == 'src': interface[v]['address'] = words[i+1] elif words[i] == 'via' and words[i+1] != command[v][-1]: interface[v]['gateway'] = words[i+1] return interface['v4'], interface['v6'] def get_interfaces_info(self, ip_path, default_ipv4, default_ipv6): interfaces = {} ips = dict( all_ipv4_addresses = [], all_ipv6_addresses = [], ) for path in glob.glob('/sys/class/net/*'): if not os.path.isdir(path): continue device = os.path.basename(path) interfaces[device] = { 'device': device } if os.path.exists(os.path.join(path, 'address')): macaddress = get_file_content(os.path.join(path, 'address'), default='') if macaddress and macaddress != '00:00:00:00:00:00': interfaces[device]['macaddress'] = macaddress if os.path.exists(os.path.join(path, 'mtu')): interfaces[device]['mtu'] = int(get_file_content(os.path.join(path, 'mtu'))) if os.path.exists(os.path.join(path, 'operstate')): interfaces[device]['active'] = get_file_content(os.path.join(path, 'operstate')) != 'down' # if os.path.exists(os.path.join(path, 'carrier')): # interfaces[device]['link'] = get_file_content(os.path.join(path, 'carrier')) == '1' if os.path.exists(os.path.join(path, 'device','driver', 'module')): interfaces[device]['module'] = os.path.basename(os.path.realpath(os.path.join(path, 'device', 'driver', 'module'))) if os.path.exists(os.path.join(path, 'type')): _type = get_file_content(os.path.join(path, 'type')) if _type == '1': interfaces[device]['type'] = 'ether' elif _type == '512': interfaces[device]['type'] = 'ppp' elif _type == '772': interfaces[device]['type'] = 'loopback' if os.path.exists(os.path.join(path, 'bridge')): interfaces[device]['type'] = 'bridge' interfaces[device]['interfaces'] = [ os.path.basename(b) for b in glob.glob(os.path.join(path, 'brif', '*')) ] if os.path.exists(os.path.join(path, 'bridge', 'bridge_id')): interfaces[device]['id'] = get_file_content(os.path.join(path, 'bridge', 'bridge_id'), default='') if os.path.exists(os.path.join(path, 'bridge', 'stp_state')): interfaces[device]['stp'] = get_file_content(os.path.join(path, 'bridge', 'stp_state')) == '1' if os.path.exists(os.path.join(path, 'bonding')): interfaces[device]['type'] = 'bonding' interfaces[device]['slaves'] = get_file_content(os.path.join(path, 'bonding', 'slaves'), default='').split() interfaces[device]['mode'] = get_file_content(os.path.join(path, 'bonding', 'mode'), default='').split()[0] interfaces[device]['miimon'] = get_file_content(os.path.join(path, 'bonding', 'miimon'), default='').split()[0] interfaces[device]['lacp_rate'] = get_file_content(os.path.join(path, 'bonding', 'lacp_rate'), default='').split()[0] primary = get_file_content(os.path.join(path, 'bonding', 'primary')) if primary: interfaces[device]['primary'] = primary path = os.path.join(path, 'bonding', 'all_slaves_active') if os.path.exists(path): interfaces[device]['all_slaves_active'] = get_file_content(path) == '1' if os.path.exists(os.path.join(path,'device')): interfaces[device]['pciid'] = os.path.basename(os.readlink(os.path.join(path,'device'))) # Check whether an interface is in promiscuous mode if os.path.exists(os.path.join(path,'flags')): promisc_mode = False # The second byte indicates whether the interface is in promiscuous mode. # 1 = promisc # 0 = no promisc data = int(get_file_content(os.path.join(path, 'flags')),16) promisc_mode = (data & 0x0100 > 0) interfaces[device]['promisc'] = promisc_mode def parse_ip_output(output, secondary=False): for line in output.split('\n'): if not line: continue words = line.split() broadcast = '' if words[0] == 'inet': if '/' in words[1]: address, netmask_length = words[1].split('/') if len(words) > 3: broadcast = words[3] else: # pointopoint interfaces do not have a prefix address = words[1] netmask_length = "32" address_bin = struct.unpack('!L', socket.inet_aton(address))[0] netmask_bin = (1<<32) - (1<<32>>int(netmask_length)) netmask = socket.inet_ntoa(struct.pack('!L', netmask_bin)) network = socket.inet_ntoa(struct.pack('!L', address_bin & netmask_bin)) iface = words[-1] if iface != device: interfaces[iface] = {} if not secondary and "ipv4" not in interfaces[iface]: interfaces[iface]['ipv4'] = {'address': address, 'broadcast': broadcast, 'netmask': netmask, 'network': network} else: if "ipv4_secondaries" not in interfaces[iface]: interfaces[iface]["ipv4_secondaries"] = [] interfaces[iface]["ipv4_secondaries"].append({ 'address': address, 'broadcast': broadcast, 'netmask': netmask, 'network': network, }) # add this secondary IP to the main device if secondary: if "ipv4_secondaries" not in interfaces[device]: interfaces[device]["ipv4_secondaries"] = [] interfaces[device]["ipv4_secondaries"].append({ 'address': address, 'broadcast': broadcast, 'netmask': netmask, 'network': network, }) # If this is the default address, update default_ipv4 if 'address' in default_ipv4 and default_ipv4['address'] == address: default_ipv4['broadcast'] = broadcast default_ipv4['netmask'] = netmask default_ipv4['network'] = network default_ipv4['macaddress'] = macaddress default_ipv4['mtu'] = interfaces[device]['mtu'] default_ipv4['type'] = interfaces[device].get("type", "unknown") default_ipv4['alias'] = words[-1] if not address.startswith('127.'): ips['all_ipv4_addresses'].append(address) elif words[0] == 'inet6': address, prefix = words[1].split('/') scope = words[3] if 'ipv6' not in interfaces[device]: interfaces[device]['ipv6'] = [] interfaces[device]['ipv6'].append({ 'address' : address, 'prefix' : prefix, 'scope' : scope }) # If this is the default address, update default_ipv6 if 'address' in default_ipv6 and default_ipv6['address'] == address: default_ipv6['prefix'] = prefix default_ipv6['scope'] = scope default_ipv6['macaddress'] = macaddress default_ipv6['mtu'] = interfaces[device]['mtu'] default_ipv6['type'] = interfaces[device].get("type", "unknown") if not address == '::1': ips['all_ipv6_addresses'].append(address) ip_path = module.get_bin_path("ip") args = [ip_path, 'addr', 'show', 'primary', device] rc, stdout, stderr = self.module.run_command(args) primary_data = stdout args = [ip_path, 'addr', 'show', 'secondary', device] rc, stdout, stderr = self.module.run_command(args) secondary_data = stdout parse_ip_output(primary_data) parse_ip_output(secondary_data, secondary=True) # replace : by _ in interface name since they are hard to use in template new_interfaces = {} for i in interfaces: if ':' in i: new_interfaces[i.replace(':','_')] = interfaces[i] else: new_interfaces[i] = interfaces[i] return new_interfaces, ips class GenericBsdIfconfigNetwork(Network): """ This is a generic BSD subclass of Network using the ifconfig command. It defines - interfaces (a list of interface names) - interface_<name> dictionary of ipv4, ipv6, and mac address information. - all_ipv4_addresses and all_ipv6_addresses: lists of all configured addresses. It currently does not define - default_ipv4 and default_ipv6 - type, mtu and network on interfaces """ platform = 'Generic_BSD_Ifconfig' def __init__(self, module): Network.__init__(self, module) def populate(self): ifconfig_path = module.get_bin_path('ifconfig') if ifconfig_path is None: return self.facts route_path = module.get_bin_path('route') if route_path is None: return self.facts default_ipv4, default_ipv6 = self.get_default_interfaces(route_path) interfaces, ips = self.get_interfaces_info(ifconfig_path) self.merge_default_interface(default_ipv4, interfaces, 'ipv4') self.merge_default_interface(default_ipv6, interfaces, 'ipv6') self.facts['interfaces'] = interfaces.keys() for iface in interfaces: self.facts[iface] = interfaces[iface] self.facts['default_ipv4'] = default_ipv4 self.facts['default_ipv6'] = default_ipv6 self.facts['all_ipv4_addresses'] = ips['all_ipv4_addresses'] self.facts['all_ipv6_addresses'] = ips['all_ipv6_addresses'] return self.facts def get_default_interfaces(self, route_path): # Use the commands: # route -n get 8.8.8.8 -> Google public DNS # route -n get -inet6 2404:6800:400a:800::1012 -> ipv6.google.com # to find out the default outgoing interface, address, and gateway command = dict( v4 = [route_path, '-n', 'get', '8.8.8.8'], v6 = [route_path, '-n', 'get', '-inet6', '2404:6800:400a:800::1012'] ) interface = dict(v4 = {}, v6 = {}) for v in 'v4', 'v6': if v == 'v6' and not socket.has_ipv6: continue rc, out, err = module.run_command(command[v]) if not out: # v6 routing may result in # RTNETLINK answers: Invalid argument continue lines = out.split('\n') for line in lines: words = line.split() # Collect output from route command if len(words) > 1: if words[0] == 'interface:': interface[v]['interface'] = words[1] if words[0] == 'gateway:': interface[v]['gateway'] = words[1] return interface['v4'], interface['v6'] def get_interfaces_info(self, ifconfig_path, ifconfig_options='-a'): interfaces = {} current_if = {} ips = dict( all_ipv4_addresses = [], all_ipv6_addresses = [], ) # FreeBSD, DragonflyBSD, NetBSD, OpenBSD and OS X all implicitly add '-a' # when running the command 'ifconfig'. # Solaris must explicitly run the command 'ifconfig -a'. rc, out, err = module.run_command([ifconfig_path, ifconfig_options]) for line in out.split('\n'): if line: words = line.split() if words[0] == 'pass': continue elif re.match('^\S', line) and len(words) > 3: current_if = self.parse_interface_line(words) interfaces[ current_if['device'] ] = current_if elif words[0].startswith('options='): self.parse_options_line(words, current_if, ips) elif words[0] == 'nd6': self.parse_nd6_line(words, current_if, ips) elif words[0] == 'ether': self.parse_ether_line(words, current_if, ips) elif words[0] == 'media:': self.parse_media_line(words, current_if, ips) elif words[0] == 'status:': self.parse_status_line(words, current_if, ips) elif words[0] == 'lladdr': self.parse_lladdr_line(words, current_if, ips) elif words[0] == 'inet': self.parse_inet_line(words, current_if, ips) elif words[0] == 'inet6': self.parse_inet6_line(words, current_if, ips) else: self.parse_unknown_line(words, current_if, ips) return interfaces, ips def parse_interface_line(self, words): device = words[0][0:-1] current_if = {'device': device, 'ipv4': [], 'ipv6': [], 'type': 'unknown'} current_if['flags'] = self.get_options(words[1]) current_if['macaddress'] = 'unknown' # will be overwritten later if len(words) >= 5 : # Newer FreeBSD versions current_if['metric'] = words[3] current_if['mtu'] = words[5] else: current_if['mtu'] = words[3] return current_if def parse_options_line(self, words, current_if, ips): # Mac has options like this... current_if['options'] = self.get_options(words[0]) def parse_nd6_line(self, words, current_if, ips): # FreeBSD has options like this... current_if['options'] = self.get_options(words[1]) def parse_ether_line(self, words, current_if, ips): current_if['macaddress'] = words[1] def parse_media_line(self, words, current_if, ips): # not sure if this is useful - we also drop information current_if['media'] = words[1] if len(words) > 2: current_if['media_select'] = words[2] if len(words) > 3: current_if['media_type'] = words[3][1:] if len(words) > 4: current_if['media_options'] = self.get_options(words[4]) def parse_status_line(self, words, current_if, ips): current_if['status'] = words[1] def parse_lladdr_line(self, words, current_if, ips): current_if['lladdr'] = words[1] def parse_inet_line(self, words, current_if, ips): address = {'address': words[1]} # deal with hex netmask if re.match('([0-9a-f]){8}', words[3]) and len(words[3]) == 8: words[3] = '0x' + words[3] if words[3].startswith('0x'): address['netmask'] = socket.inet_ntoa(struct.pack('!L', int(words[3], base=16))) else: # otherwise assume this is a dotted quad address['netmask'] = words[3] # calculate the network address_bin = struct.unpack('!L', socket.inet_aton(address['address']))[0] netmask_bin = struct.unpack('!L', socket.inet_aton(address['netmask']))[0] address['network'] = socket.inet_ntoa(struct.pack('!L', address_bin & netmask_bin)) # broadcast may be given or we need to calculate if len(words) > 5: address['broadcast'] = words[5] else: address['broadcast'] = socket.inet_ntoa(struct.pack('!L', address_bin | (~netmask_bin & 0xffffffff))) # add to our list of addresses if not words[1].startswith('127.'): ips['all_ipv4_addresses'].append(address['address']) current_if['ipv4'].append(address) def parse_inet6_line(self, words, current_if, ips): address = {'address': words[1]} if (len(words) >= 4) and (words[2] == 'prefixlen'): address['prefix'] = words[3] if (len(words) >= 6) and (words[4] == 'scopeid'): address['scope'] = words[5] localhost6 = ['::1', '::1/128', 'fe80::1%lo0'] if address['address'] not in localhost6: ips['all_ipv6_addresses'].append(address['address']) current_if['ipv6'].append(address) def parse_unknown_line(self, words, current_if, ips): # we are going to ignore unknown lines here - this may be # a bad idea - but you can override it in your subclass pass def get_options(self, option_string): start = option_string.find('<') + 1 end = option_string.rfind('>') if (start > 0) and (end > 0) and (end > start + 1): option_csv = option_string[start:end] return option_csv.split(',') else: return [] def merge_default_interface(self, defaults, interfaces, ip_type): if not 'interface' in defaults.keys(): return if not defaults['interface'] in interfaces: return ifinfo = interfaces[defaults['interface']] # copy all the interface values across except addresses for item in ifinfo.keys(): if item != 'ipv4' and item != 'ipv6': defaults[item] = ifinfo[item] if len(ifinfo[ip_type]) > 0: for item in ifinfo[ip_type][0].keys(): defaults[item] = ifinfo[ip_type][0][item] class HPUXNetwork(Network): """ HP-UX-specifig subclass of Network. Defines networking facts: - default_interface - interfaces (a list of interface names) - interface_<name> dictionary of ipv4 address information. """ platform = 'HP-UX' def __init__(self, module): Network.__init__(self, module) def populate(self): netstat_path = self.module.get_bin_path('netstat') if netstat_path is None: return self.facts self.get_default_interfaces() interfaces = self.get_interfaces_info() self.facts['interfaces'] = interfaces.keys() for iface in interfaces: self.facts[iface] = interfaces[iface] return self.facts def get_default_interfaces(self): rc, out, err = module.run_command("/usr/bin/netstat -nr") lines = out.split('\n') for line in lines: words = line.split() if len(words) > 1: if words[0] == 'default': self.facts['default_interface'] = words[4] self.facts['default_gateway'] = words[1] def get_interfaces_info(self): interfaces = {} rc, out, err = module.run_command("/usr/bin/netstat -ni") lines = out.split('\n') for line in lines: words = line.split() for i in range(len(words) - 1): if words[i][:3] == 'lan': device = words[i] interfaces[device] = { 'device': device } address = words[i+3] interfaces[device]['ipv4'] = { 'address': address } network = words[i+2] interfaces[device]['ipv4'] = { 'network': network, 'interface': device, 'address': address } return interfaces class DarwinNetwork(GenericBsdIfconfigNetwork, Network): """ This is the Mac OS X/Darwin Network Class. It uses the GenericBsdIfconfigNetwork unchanged """ platform = 'Darwin' # media line is different to the default FreeBSD one def parse_media_line(self, words, current_if, ips): # not sure if this is useful - we also drop information current_if['media'] = 'Unknown' # Mac does not give us this current_if['media_select'] = words[1] if len(words) > 2: current_if['media_type'] = words[2][1:-1] if len(words) > 3: current_if['media_options'] = self.get_options(words[3]) class FreeBSDNetwork(GenericBsdIfconfigNetwork, Network): """ This is the FreeBSD Network Class. It uses the GenericBsdIfconfigNetwork unchanged. """ platform = 'FreeBSD' class DragonFlyNetwork(GenericBsdIfconfigNetwork, Network): """ This is the DragonFly Network Class. It uses the GenericBsdIfconfigNetwork unchanged. """ platform = 'DragonFly' class AIXNetwork(GenericBsdIfconfigNetwork, Network): """ This is the AIX Network Class. It uses the GenericBsdIfconfigNetwork unchanged. """ platform = 'AIX' def get_default_interfaces(self, route_path): netstat_path = module.get_bin_path('netstat') rc, out, err = module.run_command([netstat_path, '-nr']) interface = dict(v4 = {}, v6 = {}) lines = out.split('\n') for line in lines: words = line.split() if len(words) > 1 and words[0] == 'default': if '.' in words[1]: interface['v4']['gateway'] = words[1] interface['v4']['interface'] = words[5] elif ':' in words[1]: interface['v6']['gateway'] = words[1] interface['v6']['interface'] = words[5] return interface['v4'], interface['v6'] # AIX 'ifconfig -a' does not have three words in the interface line def get_interfaces_info(self, ifconfig_path, ifconfig_options='-a'): interfaces = {} current_if = {} ips = dict( all_ipv4_addresses = [], all_ipv6_addresses = [], ) rc, out, err = module.run_command([ifconfig_path, ifconfig_options]) for line in out.split('\n'): if line: words = line.split() # only this condition differs from GenericBsdIfconfigNetwork if re.match('^\w*\d*:', line): current_if = self.parse_interface_line(words) interfaces[ current_if['device'] ] = current_if elif words[0].startswith('options='): self.parse_options_line(words, current_if, ips) elif words[0] == 'nd6': self.parse_nd6_line(words, current_if, ips) elif words[0] == 'ether': self.parse_ether_line(words, current_if, ips) elif words[0] == 'media:': self.parse_media_line(words, current_if, ips) elif words[0] == 'status:': self.parse_status_line(words, current_if, ips) elif words[0] == 'lladdr': self.parse_lladdr_line(words, current_if, ips) elif words[0] == 'inet': self.parse_inet_line(words, current_if, ips) elif words[0] == 'inet6': self.parse_inet6_line(words, current_if, ips) else: self.parse_unknown_line(words, current_if, ips) uname_path = module.get_bin_path('uname') if uname_path: rc, out, err = module.run_command([uname_path, '-W']) # don't bother with wpars it does not work # zero means not in wpar if not rc and out.split()[0] == '0': if current_if['macaddress'] == 'unknown' and re.match('^en', current_if['device']): entstat_path = module.get_bin_path('entstat') if entstat_path: rc, out, err = module.run_command([entstat_path, current_if['device'] ]) if rc != 0: break for line in out.split('\n'): if not line: pass buff = re.match('^Hardware Address: (.*)', line) if buff: current_if['macaddress'] = buff.group(1) buff = re.match('^Device Type:', line) if buff and re.match('.*Ethernet', line): current_if['type'] = 'ether' # device must have mtu attribute in ODM if 'mtu' not in current_if: lsattr_path = module.get_bin_path('lsattr') if lsattr_path: rc, out, err = module.run_command([lsattr_path,'-El', current_if['device'] ]) if rc != 0: break for line in out.split('\n'): if line: words = line.split() if words[0] == 'mtu': current_if['mtu'] = words[1] return interfaces, ips # AIX 'ifconfig -a' does not inform about MTU, so remove current_if['mtu'] here def parse_interface_line(self, words): device = words[0][0:-1] current_if = {'device': device, 'ipv4': [], 'ipv6': [], 'type': 'unknown'} current_if['flags'] = self.get_options(words[1]) current_if['macaddress'] = 'unknown' # will be overwritten later return current_if class OpenBSDNetwork(GenericBsdIfconfigNetwork, Network): """ This is the OpenBSD Network Class. It uses the GenericBsdIfconfigNetwork. """ platform = 'OpenBSD' # OpenBSD 'ifconfig -a' does not have information about aliases def get_interfaces_info(self, ifconfig_path, ifconfig_options='-aA'): return super(OpenBSDNetwork, self).get_interfaces_info(ifconfig_path, ifconfig_options) # Return macaddress instead of lladdr def parse_lladdr_line(self, words, current_if, ips): current_if['macaddress'] = words[1] class SunOSNetwork(GenericBsdIfconfigNetwork, Network): """ This is the SunOS Network Class. It uses the GenericBsdIfconfigNetwork. Solaris can have different FLAGS and MTU for IPv4 and IPv6 on the same interface so these facts have been moved inside the 'ipv4' and 'ipv6' lists. """ platform = 'SunOS' # Solaris 'ifconfig -a' will print interfaces twice, once for IPv4 and again for IPv6. # MTU and FLAGS also may differ between IPv4 and IPv6 on the same interface. # 'parse_interface_line()' checks for previously seen interfaces before defining # 'current_if' so that IPv6 facts don't clobber IPv4 facts (or vice versa). def get_interfaces_info(self, ifconfig_path): interfaces = {} current_if = {} ips = dict( all_ipv4_addresses = [], all_ipv6_addresses = [], ) rc, out, err = module.run_command([ifconfig_path, '-a']) for line in out.split('\n'): if line: words = line.split() if re.match('^\S', line) and len(words) > 3: current_if = self.parse_interface_line(words, current_if, interfaces) interfaces[ current_if['device'] ] = current_if elif words[0].startswith('options='): self.parse_options_line(words, current_if, ips) elif words[0] == 'nd6': self.parse_nd6_line(words, current_if, ips) elif words[0] == 'ether': self.parse_ether_line(words, current_if, ips) elif words[0] == 'media:': self.parse_media_line(words, current_if, ips) elif words[0] == 'status:': self.parse_status_line(words, current_if, ips) elif words[0] == 'lladdr': self.parse_lladdr_line(words, current_if, ips) elif words[0] == 'inet': self.parse_inet_line(words, current_if, ips) elif words[0] == 'inet6': self.parse_inet6_line(words, current_if, ips) else: self.parse_unknown_line(words, current_if, ips) # 'parse_interface_line' and 'parse_inet*_line' leave two dicts in the # ipv4/ipv6 lists which is ugly and hard to read. # This quick hack merges the dictionaries. Purely cosmetic. for iface in interfaces: for v in 'ipv4', 'ipv6': combined_facts = {} for facts in interfaces[iface][v]: combined_facts.update(facts) if len(combined_facts.keys()) > 0: interfaces[iface][v] = [combined_facts] return interfaces, ips def parse_interface_line(self, words, current_if, interfaces): device = words[0][0:-1] if device not in interfaces.keys(): current_if = {'device': device, 'ipv4': [], 'ipv6': [], 'type': 'unknown'} else: current_if = interfaces[device] flags = self.get_options(words[1]) v = 'ipv4' if 'IPv6' in flags: v = 'ipv6' current_if[v].append({'flags': flags, 'mtu': words[3]}) current_if['macaddress'] = 'unknown' # will be overwritten later return current_if # Solaris displays single digit octets in MAC addresses e.g. 0:1:2:d:e:f # Add leading zero to each octet where needed. def parse_ether_line(self, words, current_if, ips): macaddress = '' for octet in words[1].split(':'): octet = ('0' + octet)[-2:None] macaddress += (octet + ':') current_if['macaddress'] = macaddress[0:-1] class Virtual(Facts): """ This is a generic Virtual subclass of Facts. This should be further subclassed to implement per platform. If you subclass this, you should define: - virtualization_type - virtualization_role - container (e.g. solaris zones, freebsd jails, linux containers) All subclasses MUST define platform. """ def __new__(cls, *arguments, **keyword): subclass = cls for sc in Virtual.__subclasses__(): if sc.platform == platform.system(): subclass = sc return super(cls, subclass).__new__(subclass, *arguments, **keyword) def __init__(self): Facts.__init__(self) def populate(self): return self.facts class LinuxVirtual(Virtual): """ This is a Linux-specific subclass of Virtual. It defines - virtualization_type - virtualization_role """ platform = 'Linux' def __init__(self): Virtual.__init__(self) def populate(self): self.get_virtual_facts() return self.facts # For more information, check: http://people.redhat.com/~rjones/virt-what/ def get_virtual_facts(self): if os.path.exists('/proc/1/cgroup'): for line in get_file_lines('/proc/1/cgroup'): if re.search(r'/docker(/|-[0-9a-f]+\.scope)', line): self.facts['virtualization_type'] = 'docker' self.facts['virtualization_role'] = 'guest' return if re.search('/lxc/', line): self.facts['virtualization_type'] = 'lxc' self.facts['virtualization_role'] = 'guest' return if os.path.exists('/proc/vz'): self.facts['virtualization_type'] = 'openvz' if os.path.exists('/proc/bc'): self.facts['virtualization_role'] = 'host' else: self.facts['virtualization_role'] = 'guest' return systemd_container = get_file_content('/run/systemd/container') if systemd_container: self.facts['virtualization_type'] = systemd_container self.facts['virtualization_role'] = 'guest' return if os.path.exists("/proc/xen"): self.facts['virtualization_type'] = 'xen' self.facts['virtualization_role'] = 'guest' try: for line in get_file_lines('/proc/xen/capabilities'): if "control_d" in line: self.facts['virtualization_role'] = 'host' except IOError: pass return product_name = get_file_content('/sys/devices/virtual/dmi/id/product_name') if product_name in ['KVM', 'Bochs']: self.facts['virtualization_type'] = 'kvm' self.facts['virtualization_role'] = 'guest' return if product_name == 'RHEV Hypervisor': self.facts['virtualization_type'] = 'RHEV' self.facts['virtualization_role'] = 'guest' return if product_name == 'VMware Virtual Platform': self.facts['virtualization_type'] = 'VMware' self.facts['virtualization_role'] = 'guest' return bios_vendor = get_file_content('/sys/devices/virtual/dmi/id/bios_vendor') if bios_vendor == 'Xen': self.facts['virtualization_type'] = 'xen' self.facts['virtualization_role'] = 'guest' return if bios_vendor == 'innotek GmbH': self.facts['virtualization_type'] = 'virtualbox' self.facts['virtualization_role'] = 'guest' return sys_vendor = get_file_content('/sys/devices/virtual/dmi/id/sys_vendor') # FIXME: This does also match hyperv if sys_vendor == 'Microsoft Corporation': self.facts['virtualization_type'] = 'VirtualPC' self.facts['virtualization_role'] = 'guest' return if sys_vendor == 'Parallels Software International Inc.': self.facts['virtualization_type'] = 'parallels' self.facts['virtualization_role'] = 'guest' return if sys_vendor == 'QEMU': self.facts['virtualization_type'] = 'kvm' self.facts['virtualization_role'] = 'guest' return if sys_vendor == 'oVirt': self.facts['virtualization_type'] = 'kvm' self.facts['virtualization_role'] = 'guest' return if os.path.exists('/proc/self/status'): for line in get_file_lines('/proc/self/status'): if re.match('^VxID: \d+', line): self.facts['virtualization_type'] = 'linux_vserver' if re.match('^VxID: 0', line): self.facts['virtualization_role'] = 'host' else: self.facts['virtualization_role'] = 'guest' return if os.path.exists('/proc/cpuinfo'): for line in get_file_lines('/proc/cpuinfo'): if re.match('^model name.*QEMU Virtual CPU', line): self.facts['virtualization_type'] = 'kvm' elif re.match('^vendor_id.*User Mode Linux', line): self.facts['virtualization_type'] = 'uml' elif re.match('^model name.*UML', line): self.facts['virtualization_type'] = 'uml' elif re.match('^vendor_id.*PowerVM Lx86', line): self.facts['virtualization_type'] = 'powervm_lx86' elif re.match('^vendor_id.*IBM/S390', line): self.facts['virtualization_type'] = 'PR/SM' lscpu = module.get_bin_path('lscpu') if lscpu: rc, out, err = module.run_command(["lscpu"]) if rc == 0: for line in out.split("\n"): data = line.split(":", 1) key = data[0].strip() if key == 'Hypervisor': self.facts['virtualization_type'] = data[1].strip() else: self.facts['virtualization_type'] = 'ibm_systemz' else: continue if self.facts['virtualization_type'] == 'PR/SM': self.facts['virtualization_role'] = 'LPAR' else: self.facts['virtualization_role'] = 'guest' return # Beware that we can have both kvm and virtualbox running on a single system if os.path.exists("/proc/modules") and os.access('/proc/modules', os.R_OK): modules = [] for line in get_file_lines("/proc/modules"): data = line.split(" ", 1) modules.append(data[0]) if 'kvm' in modules: self.facts['virtualization_type'] = 'kvm' self.facts['virtualization_role'] = 'host' return if 'vboxdrv' in modules: self.facts['virtualization_type'] = 'virtualbox' self.facts['virtualization_role'] = 'host' return # If none of the above matches, return 'NA' for virtualization_type # and virtualization_role. This allows for proper grouping. self.facts['virtualization_type'] = 'NA' self.facts['virtualization_role'] = 'NA' return class FreeBSDVirtual(Virtual): """ This is a FreeBSD-specific subclass of Virtual. It defines - virtualization_type - virtualization_role """ platform = 'FreeBSD' def __init__(self): Virtual.__init__(self) def populate(self): self.get_virtual_facts() return self.facts def get_virtual_facts(self): self.facts['virtualization_type'] = '' self.facts['virtualization_role'] = '' class DragonFlyVirtual(FreeBSDVirtual): pass class OpenBSDVirtual(Virtual): """ This is a OpenBSD-specific subclass of Virtual. It defines - virtualization_type - virtualization_role """ platform = 'OpenBSD' def __init__(self): Virtual.__init__(self) def populate(self): self.get_virtual_facts() return self.facts def get_virtual_facts(self): self.facts['virtualization_type'] = '' self.facts['virtualization_role'] = '' class HPUXVirtual(Virtual): """ This is a HP-UX specific subclass of Virtual. It defines - virtualization_type - virtualization_role """ platform = 'HP-UX' def __init__(self): Virtual.__init__(self) def populate(self): self.get_virtual_facts() return self.facts def get_virtual_facts(self): if os.path.exists('/usr/sbin/vecheck'): rc, out, err = module.run_command("/usr/sbin/vecheck") if rc == 0: self.facts['virtualization_type'] = 'guest' self.facts['virtualization_role'] = 'HP vPar' if os.path.exists('/opt/hpvm/bin/hpvminfo'): rc, out, err = module.run_command("/opt/hpvm/bin/hpvminfo") if rc == 0 and re.match('.*Running.*HPVM vPar.*', out): self.facts['virtualization_type'] = 'guest' self.facts['virtualization_role'] = 'HPVM vPar' elif rc == 0 and re.match('.*Running.*HPVM guest.*', out): self.facts['virtualization_type'] = 'guest' self.facts['virtualization_role'] = 'HPVM IVM' elif rc == 0 and re.match('.*Running.*HPVM host.*', out): self.facts['virtualization_type'] = 'host' self.facts['virtualization_role'] = 'HPVM' if os.path.exists('/usr/sbin/parstatus'): rc, out, err = module.run_command("/usr/sbin/parstatus") if rc == 0: self.facts['virtualization_type'] = 'guest' self.facts['virtualization_role'] = 'HP nPar' class SunOSVirtual(Virtual): """ This is a SunOS-specific subclass of Virtual. It defines - virtualization_type - virtualization_role - container """ platform = 'SunOS' def __init__(self): Virtual.__init__(self) def populate(self): self.get_virtual_facts() return self.facts def get_virtual_facts(self): rc, out, err = module.run_command("/usr/sbin/prtdiag") for line in out.split('\n'): if 'VMware' in line: self.facts['virtualization_type'] = 'vmware' self.facts['virtualization_role'] = 'guest' if 'Parallels' in line: self.facts['virtualization_type'] = 'parallels' self.facts['virtualization_role'] = 'guest' if 'VirtualBox' in line: self.facts['virtualization_type'] = 'virtualbox' self.facts['virtualization_role'] = 'guest' if 'HVM domU' in line: self.facts['virtualization_type'] = 'xen' self.facts['virtualization_role'] = 'guest' # Check if it's a zone if os.path.exists("/usr/bin/zonename"): rc, out, err = module.run_command("/usr/bin/zonename") if out.rstrip() != "global": self.facts['container'] = 'zone' # Check if it's a branded zone (i.e. Solaris 8/9 zone) if os.path.isdir('/.SUNWnative'): self.facts['container'] = 'zone' # If it's a zone check if we can detect if our global zone is itself virtualized. # Relies on the "guest tools" (e.g. vmware tools) to be installed if 'container' in self.facts and self.facts['container'] == 'zone': rc, out, err = module.run_command("/usr/sbin/modinfo") for line in out.split('\n'): if 'VMware' in line: self.facts['virtualization_type'] = 'vmware' self.facts['virtualization_role'] = 'guest' if 'VirtualBox' in line: self.facts['virtualization_type'] = 'virtualbox' self.facts['virtualization_role'] = 'guest' # Detect domaining on Sparc hardware if os.path.exists("/usr/sbin/virtinfo"): # The output of virtinfo is different whether we are on a machine with logical # domains ('LDoms') on a T-series or domains ('Domains') on a M-series. Try LDoms first. rc, out, err = module.run_command("/usr/sbin/virtinfo -p") # The output contains multiple lines with different keys like this: # DOMAINROLE|impl=LDoms|control=false|io=false|service=false|root=false # The output may also be not formatted and the returncode is set to 0 regardless of the error condition: # virtinfo can only be run from the global zone try: for line in out.split('\n'): fields = line.split('|') if( fields[0] == 'DOMAINROLE' and fields[1] == 'impl=LDoms' ): self.facts['virtualization_type'] = 'ldom' self.facts['virtualization_role'] = 'guest' hostfeatures = [] for field in fields[2:]: arg = field.split('=') if( arg[1] == 'true' ): hostfeatures.append(arg[0]) if( len(hostfeatures) > 0 ): self.facts['virtualization_role'] = 'host (' + ','.join(hostfeatures) + ')' except ValueError: pass def get_file_content(path, default=None, strip=True): data = default if os.path.exists(path) and os.access(path, os.R_OK): try: try: datafile = open(path) data = datafile.read() if strip: data = data.strip() if len(data) == 0: data = default finally: datafile.close() except: # ignore errors as some jails/containers might have readable permissions but not allow reads to proc # done in 2 blocks for 2.4 compat pass return data def get_file_lines(path): '''get list of lines from file''' data = get_file_content(path) if data: ret = data.splitlines() else: ret = [] return ret def ansible_facts(module): facts = {} facts.update(Facts().populate()) facts.update(Hardware().populate()) facts.update(Network(module).populate()) facts.update(Virtual().populate()) return facts # =========================================== def get_all_facts(module): setup_options = dict(module_setup=True) facts = ansible_facts(module) for (k, v) in facts.items(): setup_options["ansible_%s" % k.replace('-', '_')] = v # Look for the path to the facter, cfacter, and ohai binaries and set # the variable to that path. facter_path = module.get_bin_path('facter') cfacter_path = module.get_bin_path('cfacter') ohai_path = module.get_bin_path('ohai') # Prefer to use cfacter if available if cfacter_path is not None: facter_path = cfacter_path # if facter is installed, and we can use --json because # ruby-json is ALSO installed, include facter data in the JSON if facter_path is not None: rc, out, err = module.run_command(facter_path + " --json") facter = True try: facter_ds = json.loads(out) except: facter = False if facter: for (k,v) in facter_ds.items(): setup_options["facter_%s" % k] = v # ditto for ohai if ohai_path is not None: rc, out, err = module.run_command(ohai_path) ohai = True try: ohai_ds = json.loads(out) except: ohai = False if ohai: for (k,v) in ohai_ds.items(): k2 = "ohai_%s" % k.replace('-', '_') setup_options[k2] = v setup_result = { 'ansible_facts': {} } for (k,v) in setup_options.items(): if module.params['filter'] == '*' or fnmatch.fnmatch(k, module.params['filter']): setup_result['ansible_facts'][k] = v # hack to keep --verbose from showing all the setup module results setup_result['_ansible_verbose_override'] = True return setup_result
gpl-3.0
[ 3, 334, 67, 9, 6029, 12, 16922, 22453, 665, 22333, 14, 24247, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 646, 747, 199, 646, 984, 199, 646, 5672, 199, 646, 900, 199, 646, 1625, 199, 646, 16701, 199, 646, 7554, 199, 646, 12871, 199, 646, 15951, 199, 646, 5739, 199, 646, 4298, 199, 646, 295, 199, 646, 4673, 199, 646, 2838, 199, 646, 2702, 199, 646, 2197, 199, 646, 18354, 199, 646, 14374, 199, 646, 14196, 199, 646, 5228, 199, 199, 504, 1059, 492, 5475, 31552, 199, 199, 893, 26, 272, 492, 542, 5135, 272, 25227, 63, 899, 26030, 29, 549, 199, 2590, 3545, 26, 272, 25227, 63, 899, 26030, 29, 797, 199, 199, 893, 26, 272, 492, 2022, 272, 327, 30577, 2366, 13, 1001, 1314, 365, 18457, 436, 9567, 370, 13804, 315, 272, 327, 626, 1930, 272, 862, 26, 267, 2022, 14, 3640, 267, 2022, 14, 4180, 272, 871, 4281, 26, 267, 746, 3545, 199, 2590, 3545, 26, 272, 492, 13804, 465, 2022, 199, 199, 3, 710, 7065, 859, 365, 440, 15924, 1915, 543, 428, 1734, 55, 4718, 641, 17991, 4663, 14, 199, 3, 2779, 1159, 315, 314, 428, 1734, 55, 4718, 13, 27870, 2559, 1314, 2597, 3509, 16367, 1584, 199, 3, 626, 2793, 1133, 13511, 641, 9920, 17193, 14, 221, 9336, 4154, 17991, 4663, 1233, 3181, 1133, 199, 3, 11687, 641, 18462, 12, 886, 440, 492, 652, 641, 17991, 4663, 14, 199, 692, 4298, 14, 2253, 342, 1137, 283, 22546, 3100, 356, 272, 687, 7065, 14, 1023, 492, 18462, 421, 199, 3, 9527, 10965, 199, 3, 2653, 805, 370, 1852, 3238, 2005, 10572, 13082, 316, 199, 3, 7124, 886, 440, 24068, 282, 900, 2304, 199, 199, 533, 31886, 8, 1726, 304, 272, 986, 199, 199, 318, 2653, 8, 4515, 29, 709, 12, 1125, 63, 1188, 628, 7929, 14721, 2349, 272, 347, 7531, 8, 1532, 304, 267, 347, 485, 2479, 63, 2593, 8, 1037, 453, 12, 2787, 304, 288, 746, 31886, 8, 705, 63, 1188, 9, 398, 347, 4975, 2031, 589, 12, 1011, 958, 304, 288, 4673, 14, 4653, 8, 4653, 14, 7864, 748, 11026, 12, 485, 2479, 63, 2593, 9, 288, 4673, 14, 14160, 8, 4515, 9, 288, 862, 26, 355, 754, 275, 2562, 2031, 589, 12, 1011, 958, 9, 288, 3753, 26, 355, 4673, 14, 14160, 8, 16, 9, 288, 372, 754, 398, 372, 4975, 339, 372, 7531, 199, 199, 3, 9527, 10965, 199, 199, 533, 481, 22282, 8, 785, 304, 272, 408, 272, 961, 1021, 1077, 1454, 7427, 370, 13904, 5204, 9036, 626, 272, 787, 19762, 7809, 370, 1006, 10460, 14, 221, 961, 6952, 4298, 9036, 12, 272, 2435, 9036, 334, 69, 14, 71, 14, 8635, 2883, 503, 542, 5135, 395, 436, 4084, 9036, 14, 272, 6184, 2127, 626, 5074, 2178, 3398, 1233, 503, 1443, 1172, 1655, 2419, 1373, 272, 3962, 4514, 370, 16873, 9036, 367, 282, 1627, 7482, 1077, 272, 5516, 481, 22282, 14, 272, 408, 339, 327, 284, 1184, 2352, 365, 282, 17991, 4663, 436, 28059, 13, 19185, 272, 485, 41, 8040, 907, 275, 295, 14, 2014, 8, 82, 7, 73, 779, 1082, 1367, 61, 1184, 92, 1184, 2352, 5942, 272, 327, 2104, 314, 4750, 1777, 12, 781, 5534, 626, 4298, 14, 2686, 342, 911, 11480, 314, 16865, 14, 272, 327, 961, 365, 314, 9567, 370, 2429, 625, 14996, 561, 503, 4967, 272, 4403, 13783, 63, 4924, 275, 334, 14606, 6839, 15, 16404, 13, 3221, 297, 283, 21202, 14091, 659, 490, 14606, 6839, 15, 24567, 1068, 13, 1023, 297, 283, 51, 5143, 1068, 659, 490, 14606, 6839, 15, 17164, 13, 3221, 297, 283, 10858, 40, 292, 659, 490, 14606, 6839, 15, 18970, 13, 3221, 297, 283, 6849, 1068, 654, 56, 659, 490, 14606, 6839, 15, 1490, 87, 2591, 63, 3221, 297, 283, 4299, 55, 2591, 659, 490, 14606, 6839, 15, 2253, 13, 3221, 297, 283, 8632, 14091, 659, 490, 14606, 6839, 15, 279, 80, 1132, 13, 3221, 297, 283, 2439, 80, 1132, 659, 490, 14606, 6839, 15, 3221, 297, 283, 27262, 4663, 659, 490, 14606, 6839, 15, 1047, 13, 3221, 297, 283, 8438, 5135, 659, 490, 14606, 6839, 15, 27032, 899, 13, 3221, 297, 283, 27032, 899, 659, 490, 14606, 6839, 15, 736, 13, 3221, 297, 283, 27032, 899, 659, 490, 14606, 6839, 15, 2268, 7354, 13, 3221, 297, 283, 8168, 7354, 659, 490, 14606, 6839, 15, 736, 13, 3221, 297, 283, 872, 9662, 659, 490, 14606, 6839, 15, 30740, 13, 3221, 297, 283, 45, 460, 322, 3042, 659, 490, 14606, 6839, 15, 4478, 5135, 13, 3221, 297, 283, 16985, 5135, 659, 490, 14606, 6839, 15, 736, 13, 3221, 297, 283, 7170, 659, 355, 776, 272, 428, 2901, 568, 14272, 63, 6963, 63, 12511, 275, 469, 413, 26, 283, 287, 509, 4477, 297, 378, 26, 283, 529, 32237, 297, 446, 17, 26, 283, 7011, 7, 789, 339, 327, 437, 769, 402, 10809, 14, 221, 982, 2337, 365, 282, 4298, 543, 1655, 2419, 1373, 272, 327, 2559, 5256, 12, 5324, 314, 14388, 1373, 2061, 14, 221, 982, 2337, 365, 376, 272, 327, 3242, 859, 12, 675, 626, 465, 314, 574, 367, 314, 283, 354, 7, 790, 14, 272, 30281, 63, 45, 3975, 51, 275, 359, 469, 283, 515, 7, 520, 1994, 2647, 15, 1393, 15, 22108, 297, 260, 283, 354, 7, 520 ]
[ 334, 67, 9, 6029, 12, 16922, 22453, 665, 22333, 14, 24247, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 646, 747, 199, 646, 984, 199, 646, 5672, 199, 646, 900, 199, 646, 1625, 199, 646, 16701, 199, 646, 7554, 199, 646, 12871, 199, 646, 15951, 199, 646, 5739, 199, 646, 4298, 199, 646, 295, 199, 646, 4673, 199, 646, 2838, 199, 646, 2702, 199, 646, 2197, 199, 646, 18354, 199, 646, 14374, 199, 646, 14196, 199, 646, 5228, 199, 199, 504, 1059, 492, 5475, 31552, 199, 199, 893, 26, 272, 492, 542, 5135, 272, 25227, 63, 899, 26030, 29, 549, 199, 2590, 3545, 26, 272, 25227, 63, 899, 26030, 29, 797, 199, 199, 893, 26, 272, 492, 2022, 272, 327, 30577, 2366, 13, 1001, 1314, 365, 18457, 436, 9567, 370, 13804, 315, 272, 327, 626, 1930, 272, 862, 26, 267, 2022, 14, 3640, 267, 2022, 14, 4180, 272, 871, 4281, 26, 267, 746, 3545, 199, 2590, 3545, 26, 272, 492, 13804, 465, 2022, 199, 199, 3, 710, 7065, 859, 365, 440, 15924, 1915, 543, 428, 1734, 55, 4718, 641, 17991, 4663, 14, 199, 3, 2779, 1159, 315, 314, 428, 1734, 55, 4718, 13, 27870, 2559, 1314, 2597, 3509, 16367, 1584, 199, 3, 626, 2793, 1133, 13511, 641, 9920, 17193, 14, 221, 9336, 4154, 17991, 4663, 1233, 3181, 1133, 199, 3, 11687, 641, 18462, 12, 886, 440, 492, 652, 641, 17991, 4663, 14, 199, 692, 4298, 14, 2253, 342, 1137, 283, 22546, 3100, 356, 272, 687, 7065, 14, 1023, 492, 18462, 421, 199, 3, 9527, 10965, 199, 3, 2653, 805, 370, 1852, 3238, 2005, 10572, 13082, 316, 199, 3, 7124, 886, 440, 24068, 282, 900, 2304, 199, 199, 533, 31886, 8, 1726, 304, 272, 986, 199, 199, 318, 2653, 8, 4515, 29, 709, 12, 1125, 63, 1188, 628, 7929, 14721, 2349, 272, 347, 7531, 8, 1532, 304, 267, 347, 485, 2479, 63, 2593, 8, 1037, 453, 12, 2787, 304, 288, 746, 31886, 8, 705, 63, 1188, 9, 398, 347, 4975, 2031, 589, 12, 1011, 958, 304, 288, 4673, 14, 4653, 8, 4653, 14, 7864, 748, 11026, 12, 485, 2479, 63, 2593, 9, 288, 4673, 14, 14160, 8, 4515, 9, 288, 862, 26, 355, 754, 275, 2562, 2031, 589, 12, 1011, 958, 9, 288, 3753, 26, 355, 4673, 14, 14160, 8, 16, 9, 288, 372, 754, 398, 372, 4975, 339, 372, 7531, 199, 199, 3, 9527, 10965, 199, 199, 533, 481, 22282, 8, 785, 304, 272, 408, 272, 961, 1021, 1077, 1454, 7427, 370, 13904, 5204, 9036, 626, 272, 787, 19762, 7809, 370, 1006, 10460, 14, 221, 961, 6952, 4298, 9036, 12, 272, 2435, 9036, 334, 69, 14, 71, 14, 8635, 2883, 503, 542, 5135, 395, 436, 4084, 9036, 14, 272, 6184, 2127, 626, 5074, 2178, 3398, 1233, 503, 1443, 1172, 1655, 2419, 1373, 272, 3962, 4514, 370, 16873, 9036, 367, 282, 1627, 7482, 1077, 272, 5516, 481, 22282, 14, 272, 408, 339, 327, 284, 1184, 2352, 365, 282, 17991, 4663, 436, 28059, 13, 19185, 272, 485, 41, 8040, 907, 275, 295, 14, 2014, 8, 82, 7, 73, 779, 1082, 1367, 61, 1184, 92, 1184, 2352, 5942, 272, 327, 2104, 314, 4750, 1777, 12, 781, 5534, 626, 4298, 14, 2686, 342, 911, 11480, 314, 16865, 14, 272, 327, 961, 365, 314, 9567, 370, 2429, 625, 14996, 561, 503, 4967, 272, 4403, 13783, 63, 4924, 275, 334, 14606, 6839, 15, 16404, 13, 3221, 297, 283, 21202, 14091, 659, 490, 14606, 6839, 15, 24567, 1068, 13, 1023, 297, 283, 51, 5143, 1068, 659, 490, 14606, 6839, 15, 17164, 13, 3221, 297, 283, 10858, 40, 292, 659, 490, 14606, 6839, 15, 18970, 13, 3221, 297, 283, 6849, 1068, 654, 56, 659, 490, 14606, 6839, 15, 1490, 87, 2591, 63, 3221, 297, 283, 4299, 55, 2591, 659, 490, 14606, 6839, 15, 2253, 13, 3221, 297, 283, 8632, 14091, 659, 490, 14606, 6839, 15, 279, 80, 1132, 13, 3221, 297, 283, 2439, 80, 1132, 659, 490, 14606, 6839, 15, 3221, 297, 283, 27262, 4663, 659, 490, 14606, 6839, 15, 1047, 13, 3221, 297, 283, 8438, 5135, 659, 490, 14606, 6839, 15, 27032, 899, 13, 3221, 297, 283, 27032, 899, 659, 490, 14606, 6839, 15, 736, 13, 3221, 297, 283, 27032, 899, 659, 490, 14606, 6839, 15, 2268, 7354, 13, 3221, 297, 283, 8168, 7354, 659, 490, 14606, 6839, 15, 736, 13, 3221, 297, 283, 872, 9662, 659, 490, 14606, 6839, 15, 30740, 13, 3221, 297, 283, 45, 460, 322, 3042, 659, 490, 14606, 6839, 15, 4478, 5135, 13, 3221, 297, 283, 16985, 5135, 659, 490, 14606, 6839, 15, 736, 13, 3221, 297, 283, 7170, 659, 355, 776, 272, 428, 2901, 568, 14272, 63, 6963, 63, 12511, 275, 469, 413, 26, 283, 287, 509, 4477, 297, 378, 26, 283, 529, 32237, 297, 446, 17, 26, 283, 7011, 7, 789, 339, 327, 437, 769, 402, 10809, 14, 221, 982, 2337, 365, 282, 4298, 543, 1655, 2419, 1373, 272, 327, 2559, 5256, 12, 5324, 314, 14388, 1373, 2061, 14, 221, 982, 2337, 365, 376, 272, 327, 3242, 859, 12, 675, 626, 465, 314, 574, 367, 314, 283, 354, 7, 790, 14, 272, 30281, 63, 45, 3975, 51, 275, 359, 469, 283, 515, 7, 520, 1994, 2647, 15, 1393, 15, 22108, 297, 260, 283, 354, 7, 520, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
ifzing/ceilometer-extended-monitor
network/lbaas.py
1
2469
# -*- encoding: utf-8 -*- from ceilometer.openstack.common import log from ceilometer.openstack.common import timeutils from ceilometer.central import plugin from ceilometer import sample from ceilometer import neutron_client class LbaasInBytesPollster(plugin.CentralPollster): LOG = log.getLogger(__name__ + '.LBaaS') def _get_lb_in_bytes(self): in_bytes = [] nt = neutron_client.Client() for pool in nt._list_pools(): bytes = nt._get_lb_in_bytes(pool['id']) in_bytes.append({'id': pool['id'], 'bytes': bytes}) return in_bytes def _iter_pool_stats(self, cache): if 'in_bytes' not in cache: cache['in_bytes'] = list(self._get_lb_in_bytes()) return iter(cache['in_bytes']) def get_samples(self, manager, cache): for pool in self._iter_pool_stats(cache): self.LOG.info("LBAAS POOL: %s" % pool['id']) yield sample.Sample( name='network.lb.in.bytes', type=sample.TYPE_CUMULATIVE, unit='byte', volume=pool['bytes'], user_id=None, project_id=None, resource_id=pool['id'], timestamp=timeutils.utcnow().isoformat(), resource_metadata={}) class LbaasOutBytesPollster(plugin.CentralPollster): LOG = log.getLogger(__name__ + '.LBaaS') def _get_lb_out_bytes(self): in_bytes = [] nt = neutron_client.Client() for pool in nt._list_pools(): bytes = nt._get_lb_out_bytes(pool['id']) in_bytes.append({'id': pool['id'], 'bytes': bytes}) return in_bytes def _iter_pool_stats(self, cache): if 'out_bytes' not in cache: cache['out_bytes'] = list(self._get_lb_out_bytes()) return iter(cache['out_bytes']) def get_samples(self, manager, cache): for pool in self._iter_pool_stats(cache): self.LOG.info("LBAAS POOL: %s" % pool['id']) yield sample.Sample( name='network.lb.out.bytes', type=sample.TYPE_CUMULATIVE, unit='byte', volume=pool['bytes'], user_id=None, project_id=None, resource_id=pool['id'], timestamp=timeutils.utcnow().isoformat(), resource_metadata={})
apache-2.0
[ 3, 1882, 2644, 26, 2774, 13, 24, 1882, 199, 504, 10142, 25617, 14, 8512, 14, 2330, 492, 943, 199, 504, 10142, 25617, 14, 8512, 14, 2330, 492, 23011, 199, 199, 504, 10142, 25617, 14, 16067, 492, 3589, 199, 504, 10142, 25617, 492, 2690, 199, 504, 10142, 25617, 492, 8224, 63, 1258, 421, 199, 533, 491, 2470, 305, 607, 5571, 5858, 478, 351, 8, 2718, 14, 25290, 5858, 478, 351, 304, 20950, 5051, 275, 943, 14, 5572, 3460, 354, 363, 435, 1987, 11568, 2158, 51, 358, 339, 347, 485, 362, 63, 6374, 63, 262, 63, 2394, 8, 277, 304, 267, 315, 63, 2394, 275, 942, 267, 13377, 275, 8224, 63, 1258, 14, 3041, 342, 398, 367, 4203, 315, 13377, 423, 513, 63, 12406, 837, 288, 2783, 275, 13377, 423, 362, 63, 6374, 63, 262, 63, 2394, 8, 2293, 459, 344, 1105, 288, 315, 63, 2394, 14, 740, 3252, 344, 356, 4203, 459, 344, 995, 2490, 283, 2394, 356, 2783, 1552, 267, 372, 315, 63, 2394, 339, 347, 485, 1661, 63, 2293, 63, 3200, 8, 277, 12, 2581, 304, 267, 340, 283, 262, 63, 2394, 7, 440, 315, 2581, 26, 288, 2581, 459, 262, 63, 2394, 418, 275, 769, 8, 277, 423, 362, 63, 6374, 63, 262, 63, 2394, 1012, 267, 372, 2740, 8, 1637, 459, 262, 63, 2394, 1105, 339, 347, 664, 63, 3356, 8, 277, 12, 5256, 12, 2581, 304, 267, 367, 4203, 315, 291, 423, 1661, 63, 2293, 63, 3200, 8, 1637, 304, 288, 291, 14, 4947, 14, 815, 480, 44, 4134, 1179, 3625, 2228, 26, 450, 83, 2, 450, 4203, 459, 344, 1105, 288, 1995, 2690, 14, 8176, 8, 355, 536, 534, 1200, 14, 6374, 14, 262, 14, 2394, 297, 355, 730, 29, 3271, 14, 2711, 63, 5497, 1293, 14277, 12, 355, 4137, 534, 4414, 297, 355, 3301, 29, 2293, 459, 2394, 995, 355, 922, 63, 344, 29, 403, 12, 355, 2199, 63, 344, 29, 403, 12, 355, 2073, 63, 344, 29, 2293, 459, 344, 995, 355, 4913, 29, 521, 1208, 14, 10779, 1252, 17070, 1062, 355, 2073, 63, 2343, 21146, 421, 199, 533, 491, 2470, 305, 2204, 5571, 5858, 478, 351, 8, 2718, 14, 25290, 5858, 478, 351, 304, 339, 5051, 275, 943, 14, 5572, 3460, 354, 363, 435, 1987, 11568, 2158, 51, 358, 339, 347, 485, 362, 63, 6374, 63, 548, 63, 2394, 8, 277, 304, 267, 315, 63, 2394, 275, 942, 267, 13377, 275, 8224, 63, 1258, 14, 3041, 342, 398, 367, 4203, 315, 13377, 423, 513, 63, 12406, 837, 288, 2783, 275, 13377, 423, 362, 63, 6374, 63, 548, 63, 2394, 8, 2293, 459, 344, 1105, 288, 315, 63, 2394, 14, 740, 3252, 344, 356, 4203, 459, 344, 995, 2490, 283, 2394, 356, 2783, 1552, 267, 372, 315, 63, 2394, 339, 347, 485, 1661, 63, 2293, 63, 3200, 8, 277, 12, 2581, 304, 267, 340, 283, 548, 63, 2394, 7, 440, 315, 2581, 26, 288, 2581, 459, 548, 63, 2394, 418, 275, 769, 8, 277, 423, 362, 63, 6374, 63, 548, 63, 2394, 1012, 267, 372, 2740, 8, 1637, 459, 548, 63, 2394, 1105, 339, 347, 664, 63, 3356, 8, 277, 12, 5256, 12, 2581, 304, 267, 367, 4203, 315, 291, 423, 1661, 63, 2293, 63, 3200, 8, 1637, 304, 288, 291, 14, 4947, 14, 815, 480, 44, 4134, 1179, 3625, 2228, 26, 450, 83, 2, 450, 4203, 459, 344, 1105, 288, 1995, 2690, 14, 8176, 8, 355, 536, 534, 1200, 14, 6374, 14, 548, 14, 2394, 297, 355, 730, 29, 3271, 14, 2711, 63, 5497, 1293, 14277, 12, 355, 4137, 534, 4414, 297, 355, 3301, 29, 2293, 459, 2394, 995, 355, 922, 63, 344, 29, 403, 12, 355, 2199, 63, 344, 29, 403, 12, 355, 2073, 63, 344, 29, 2293, 459, 344, 995, 355, 4913, 29, 521, 1208, 14, 10779, 1252, 17070, 1062, 355, 2073, 63, 2343, 21146, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2644, 26, 2774, 13, 24, 1882, 199, 504, 10142, 25617, 14, 8512, 14, 2330, 492, 943, 199, 504, 10142, 25617, 14, 8512, 14, 2330, 492, 23011, 199, 199, 504, 10142, 25617, 14, 16067, 492, 3589, 199, 504, 10142, 25617, 492, 2690, 199, 504, 10142, 25617, 492, 8224, 63, 1258, 421, 199, 533, 491, 2470, 305, 607, 5571, 5858, 478, 351, 8, 2718, 14, 25290, 5858, 478, 351, 304, 20950, 5051, 275, 943, 14, 5572, 3460, 354, 363, 435, 1987, 11568, 2158, 51, 358, 339, 347, 485, 362, 63, 6374, 63, 262, 63, 2394, 8, 277, 304, 267, 315, 63, 2394, 275, 942, 267, 13377, 275, 8224, 63, 1258, 14, 3041, 342, 398, 367, 4203, 315, 13377, 423, 513, 63, 12406, 837, 288, 2783, 275, 13377, 423, 362, 63, 6374, 63, 262, 63, 2394, 8, 2293, 459, 344, 1105, 288, 315, 63, 2394, 14, 740, 3252, 344, 356, 4203, 459, 344, 995, 2490, 283, 2394, 356, 2783, 1552, 267, 372, 315, 63, 2394, 339, 347, 485, 1661, 63, 2293, 63, 3200, 8, 277, 12, 2581, 304, 267, 340, 283, 262, 63, 2394, 7, 440, 315, 2581, 26, 288, 2581, 459, 262, 63, 2394, 418, 275, 769, 8, 277, 423, 362, 63, 6374, 63, 262, 63, 2394, 1012, 267, 372, 2740, 8, 1637, 459, 262, 63, 2394, 1105, 339, 347, 664, 63, 3356, 8, 277, 12, 5256, 12, 2581, 304, 267, 367, 4203, 315, 291, 423, 1661, 63, 2293, 63, 3200, 8, 1637, 304, 288, 291, 14, 4947, 14, 815, 480, 44, 4134, 1179, 3625, 2228, 26, 450, 83, 2, 450, 4203, 459, 344, 1105, 288, 1995, 2690, 14, 8176, 8, 355, 536, 534, 1200, 14, 6374, 14, 262, 14, 2394, 297, 355, 730, 29, 3271, 14, 2711, 63, 5497, 1293, 14277, 12, 355, 4137, 534, 4414, 297, 355, 3301, 29, 2293, 459, 2394, 995, 355, 922, 63, 344, 29, 403, 12, 355, 2199, 63, 344, 29, 403, 12, 355, 2073, 63, 344, 29, 2293, 459, 344, 995, 355, 4913, 29, 521, 1208, 14, 10779, 1252, 17070, 1062, 355, 2073, 63, 2343, 21146, 421, 199, 533, 491, 2470, 305, 2204, 5571, 5858, 478, 351, 8, 2718, 14, 25290, 5858, 478, 351, 304, 339, 5051, 275, 943, 14, 5572, 3460, 354, 363, 435, 1987, 11568, 2158, 51, 358, 339, 347, 485, 362, 63, 6374, 63, 548, 63, 2394, 8, 277, 304, 267, 315, 63, 2394, 275, 942, 267, 13377, 275, 8224, 63, 1258, 14, 3041, 342, 398, 367, 4203, 315, 13377, 423, 513, 63, 12406, 837, 288, 2783, 275, 13377, 423, 362, 63, 6374, 63, 548, 63, 2394, 8, 2293, 459, 344, 1105, 288, 315, 63, 2394, 14, 740, 3252, 344, 356, 4203, 459, 344, 995, 2490, 283, 2394, 356, 2783, 1552, 267, 372, 315, 63, 2394, 339, 347, 485, 1661, 63, 2293, 63, 3200, 8, 277, 12, 2581, 304, 267, 340, 283, 548, 63, 2394, 7, 440, 315, 2581, 26, 288, 2581, 459, 548, 63, 2394, 418, 275, 769, 8, 277, 423, 362, 63, 6374, 63, 548, 63, 2394, 1012, 267, 372, 2740, 8, 1637, 459, 548, 63, 2394, 1105, 339, 347, 664, 63, 3356, 8, 277, 12, 5256, 12, 2581, 304, 267, 367, 4203, 315, 291, 423, 1661, 63, 2293, 63, 3200, 8, 1637, 304, 288, 291, 14, 4947, 14, 815, 480, 44, 4134, 1179, 3625, 2228, 26, 450, 83, 2, 450, 4203, 459, 344, 1105, 288, 1995, 2690, 14, 8176, 8, 355, 536, 534, 1200, 14, 6374, 14, 548, 14, 2394, 297, 355, 730, 29, 3271, 14, 2711, 63, 5497, 1293, 14277, 12, 355, 4137, 534, 4414, 297, 355, 3301, 29, 2293, 459, 2394, 995, 355, 922, 63, 344, 29, 403, 12, 355, 2199, 63, 344, 29, 403, 12, 355, 2073, 63, 344, 29, 2293, 459, 344, 995, 355, 4913, 29, 521, 1208, 14, 10779, 1252, 17070, 1062, 355, 2073, 63, 2343, 21146, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
TNT-Samuel/Coding-Projects
DNS Server/Source/Lib/site-packages/qtpy/tests/test_macos_checks.py
8
2939
from __future__ import absolute_import import mock import platform import sys import pytest from qtpy import PYQT5, PYSIDE2 @pytest.mark.skipif(not PYQT5, reason="Targeted to PyQt5") @mock.patch.object(platform, 'mac_ver') def test_qt59_exception(mac_ver, monkeypatch): # Remove qtpy to reimport it again try: del sys.modules["qtpy"] except KeyError: pass # Patch stdlib to emulate a macOS system monkeypatch.setattr("sys.platform", 'darwin') mac_ver.return_value = ('10.9.2',) # Patch Qt version monkeypatch.setattr("PyQt5.QtCore.QT_VERSION_STR", '5.9.1') # This should raise an Exception with pytest.raises(Exception) as e: import qtpy assert '10.10' in str(e.value) assert '5.9' in str(e.value) @pytest.mark.skipif(not PYQT5, reason="Targeted to PyQt5") @mock.patch.object(platform, 'mac_ver') def test_qt59_no_exception(mac_ver, monkeypatch): # Remove qtpy to reimport it again try: del sys.modules["qtpy"] except KeyError: pass # Patch stdlib to emulate a macOS system monkeypatch.setattr("sys.platform", 'darwin') mac_ver.return_value = ('10.10.1',) # Patch Qt version monkeypatch.setattr("PyQt5.QtCore.QT_VERSION_STR", '5.9.5') # This should not raise an Exception try: import qtpy except Exception: pytest.fail("Error!") @pytest.mark.skipif(not (PYQT5 or PYSIDE2), reason="Targeted to PyQt5 or PySide2") @mock.patch.object(platform, 'mac_ver') def test_qt511_exception(mac_ver, monkeypatch): # Remove qtpy to reimport it again try: del sys.modules["qtpy"] except KeyError: pass # Patch stdlib to emulate a macOS system monkeypatch.setattr("sys.platform", 'darwin') mac_ver.return_value = ('10.10.3',) # Patch Qt version if PYQT5: monkeypatch.setattr("PyQt5.QtCore.QT_VERSION_STR", '5.11.1') else: monkeypatch.setattr("PySide2.QtCore.__version__", '5.11.1') # This should raise an Exception with pytest.raises(Exception) as e: import qtpy assert '10.11' in str(e.value) assert '5.11' in str(e.value) @pytest.mark.skipif(not (PYQT5 or PYSIDE2), reason="Targeted to PyQt5 or PySide2") @mock.patch.object(platform, 'mac_ver') def test_qt511_no_exception(mac_ver, monkeypatch): # Remove qtpy to reimport it again try: del sys.modules["qtpy"] except KeyError: pass # Patch stdlib to emulate a macOS system monkeypatch.setattr("sys.platform", 'darwin') mac_ver.return_value = ('10.13.2',) # Patch Qt version if PYQT5: monkeypatch.setattr("PyQt5.QtCore.QT_VERSION_STR", '5.11.1') else: monkeypatch.setattr("PySide2.QtCore.__version__", '5.11.1') # This should not raise an Exception try: import qtpy except Exception: pytest.fail("Error!")
gpl-3.0
[ 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 646, 1683, 199, 646, 4298, 199, 646, 984, 199, 199, 646, 4613, 199, 504, 19227, 647, 492, 7843, 19229, 21, 12, 7843, 28035, 18, 421, 199, 32, 4462, 14, 1657, 14, 22696, 8, 1397, 7843, 19229, 21, 12, 4499, 628, 52, 20174, 370, 14084, 21, 531, 199, 32, 1805, 14, 2068, 14, 785, 8, 3246, 12, 283, 3088, 63, 422, 358, 199, 318, 511, 63, 8440, 1427, 63, 1971, 8, 3088, 63, 422, 12, 17309, 304, 272, 327, 5852, 19227, 647, 370, 295, 646, 652, 4020, 272, 862, 26, 267, 2150, 984, 14, 3112, 905, 8440, 647, 937, 272, 871, 4067, 26, 267, 986, 339, 327, 19292, 26678, 370, 31102, 282, 4497, 3100, 2656, 272, 17309, 14, 10202, 480, 1274, 14, 3246, 401, 283, 13245, 358, 272, 4497, 63, 422, 14, 1107, 63, 585, 275, 661, 709, 14, 25, 14, 18, 9538, 339, 327, 19292, 3959, 1015, 272, 17309, 14, 10202, 480, 24107, 21, 14, 10901, 14, 19229, 63, 4612, 63, 3027, 401, 283, 21, 14, 25, 14, 17, 358, 339, 327, 961, 1077, 746, 376, 2186, 272, 543, 4613, 14, 3536, 8, 1726, 9, 465, 325, 26, 267, 492, 19227, 647, 339, 702, 283, 709, 14, 709, 7, 315, 620, 8, 69, 14, 585, 9, 272, 702, 283, 21, 14, 25, 7, 315, 620, 8, 69, 14, 585, 9, 421, 199, 32, 4462, 14, 1657, 14, 22696, 8, 1397, 7843, 19229, 21, 12, 4499, 628, 52, 20174, 370, 14084, 21, 531, 199, 32, 1805, 14, 2068, 14, 785, 8, 3246, 12, 283, 3088, 63, 422, 358, 199, 318, 511, 63, 8440, 1427, 63, 889, 63, 1971, 8, 3088, 63, 422, 12, 17309, 304, 272, 327, 5852, 19227, 647, 370, 295, 646, 652, 4020, 272, 862, 26, 267, 2150, 984, 14, 3112, 905, 8440, 647, 937, 272, 871, 4067, 26, 267, 986, 339, 327, 19292, 26678, 370, 31102, 282, 4497, 3100, 2656, 272, 17309, 14, 10202, 480, 1274, 14, 3246, 401, 283, 13245, 358, 272, 4497, 63, 422, 14, 1107, 63, 585, 275, 661, 709, 14, 709, 14, 17, 9538, 339, 327, 19292, 3959, 1015, 272, 17309, 14, 10202, 480, 24107, 21, 14, 10901, 14, 19229, 63, 4612, 63, 3027, 401, 283, 21, 14, 25, 14, 21, 358, 339, 327, 961, 1077, 440, 746, 376, 2186, 272, 862, 26, 267, 492, 19227, 647, 272, 871, 2186, 26, 267, 4613, 14, 1633, 480, 547, 9124, 421, 199, 32, 4462, 14, 1657, 14, 22696, 8, 1397, 334, 4521, 19229, 21, 503, 7843, 28035, 18, 395, 490, 4499, 628, 52, 20174, 370, 14084, 21, 503, 1611, 15414, 18, 531, 199, 32, 1805, 14, 2068, 14, 785, 8, 3246, 12, 283, 3088, 63, 422, 358, 199, 318, 511, 63, 8440, 27176, 63, 1971, 8, 3088, 63, 422, 12, 17309, 304, 272, 327, 5852, 19227, 647, 370, 295, 646, 652, 4020, 272, 862, 26, 267, 2150, 984, 14, 3112, 905, 8440, 647, 937, 272, 871, 4067, 26, 267, 986, 339, 327, 19292, 26678, 370, 31102, 282, 4497, 3100, 2656, 272, 17309, 14, 10202, 480, 1274, 14, 3246, 401, 283, 13245, 358, 272, 4497, 63, 422, 14, 1107, 63, 585, 275, 661, 709, 14, 709, 14, 19, 9538, 339, 327, 19292, 3959, 1015, 272, 340, 7843, 19229, 21, 26, 267, 17309, 14, 10202, 480, 24107, 21, 14, 10901, 14, 19229, 63, 4612, 63, 3027, 401, 283, 21, 14, 845, 14, 17, 358, 272, 587, 26, 267, 17309, 14, 10202, 480, 2713, 15414, 18, 14, 10901, 855, 1023, 13915, 283, 21, 14, 845, 14, 17, 358, 339, 327, 961, 1077, 746, 376, 2186, 272, 543, 4613, 14, 3536, 8, 1726, 9, 465, 325, 26, 267, 492, 19227, 647, 339, 702, 283, 709, 14, 845, 7, 315, 620, 8, 69, 14, 585, 9, 272, 702, 283, 21, 14, 845, 7, 315, 620, 8, 69, 14, 585, 9, 421, 199, 32, 4462, 14, 1657, 14, 22696, 8, 1397, 334, 4521, 19229, 21, 503, 7843, 28035, 18, 395, 490, 4499, 628, 52, 20174, 370, 14084, 21, 503, 1611, 15414, 18, 531, 199, 32, 1805, 14, 2068, 14, 785, 8, 3246, 12, 283, 3088, 63, 422, 358, 199, 318, 511, 63, 8440, 27176, 63, 889, 63, 1971, 8, 3088, 63, 422, 12, 17309, 304, 272, 327, 5852, 19227, 647, 370, 295, 646, 652, 4020, 272, 862, 26, 267, 2150, 984, 14, 3112, 905, 8440, 647, 937, 272, 871, 4067, 26, 267, 986, 339, 327, 19292, 26678, 370, 31102, 282, 4497, 3100, 2656, 272, 17309, 14, 10202, 480, 1274, 14, 3246, 401, 283, 13245, 358, 272, 4497, 63, 422, 14, 1107, 63, 585, 275, 661, 709, 14, 969, 14, 18, 9538, 339, 327, 19292, 3959, 1015, 272, 340, 7843, 19229, 21, 26, 267, 17309, 14, 10202, 480, 24107, 21, 14, 10901, 14, 19229, 63, 4612, 63, 3027, 401, 283, 21, 14, 845, 14, 17, 358, 272, 587, 26, 267, 17309, 14, 10202, 480, 2713, 15414, 18, 14, 10901, 855, 1023, 13915, 283, 21, 14, 845, 14, 17, 358, 8410, 327, 961, 1077, 440, 746, 376, 2186, 272, 862, 26, 267, 492, 19227, 647, 272, 871, 2186, 26, 267, 4613, 14, 1633, 480, 547, 9124, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 646, 1683, 199, 646, 4298, 199, 646, 984, 199, 199, 646, 4613, 199, 504, 19227, 647, 492, 7843, 19229, 21, 12, 7843, 28035, 18, 421, 199, 32, 4462, 14, 1657, 14, 22696, 8, 1397, 7843, 19229, 21, 12, 4499, 628, 52, 20174, 370, 14084, 21, 531, 199, 32, 1805, 14, 2068, 14, 785, 8, 3246, 12, 283, 3088, 63, 422, 358, 199, 318, 511, 63, 8440, 1427, 63, 1971, 8, 3088, 63, 422, 12, 17309, 304, 272, 327, 5852, 19227, 647, 370, 295, 646, 652, 4020, 272, 862, 26, 267, 2150, 984, 14, 3112, 905, 8440, 647, 937, 272, 871, 4067, 26, 267, 986, 339, 327, 19292, 26678, 370, 31102, 282, 4497, 3100, 2656, 272, 17309, 14, 10202, 480, 1274, 14, 3246, 401, 283, 13245, 358, 272, 4497, 63, 422, 14, 1107, 63, 585, 275, 661, 709, 14, 25, 14, 18, 9538, 339, 327, 19292, 3959, 1015, 272, 17309, 14, 10202, 480, 24107, 21, 14, 10901, 14, 19229, 63, 4612, 63, 3027, 401, 283, 21, 14, 25, 14, 17, 358, 339, 327, 961, 1077, 746, 376, 2186, 272, 543, 4613, 14, 3536, 8, 1726, 9, 465, 325, 26, 267, 492, 19227, 647, 339, 702, 283, 709, 14, 709, 7, 315, 620, 8, 69, 14, 585, 9, 272, 702, 283, 21, 14, 25, 7, 315, 620, 8, 69, 14, 585, 9, 421, 199, 32, 4462, 14, 1657, 14, 22696, 8, 1397, 7843, 19229, 21, 12, 4499, 628, 52, 20174, 370, 14084, 21, 531, 199, 32, 1805, 14, 2068, 14, 785, 8, 3246, 12, 283, 3088, 63, 422, 358, 199, 318, 511, 63, 8440, 1427, 63, 889, 63, 1971, 8, 3088, 63, 422, 12, 17309, 304, 272, 327, 5852, 19227, 647, 370, 295, 646, 652, 4020, 272, 862, 26, 267, 2150, 984, 14, 3112, 905, 8440, 647, 937, 272, 871, 4067, 26, 267, 986, 339, 327, 19292, 26678, 370, 31102, 282, 4497, 3100, 2656, 272, 17309, 14, 10202, 480, 1274, 14, 3246, 401, 283, 13245, 358, 272, 4497, 63, 422, 14, 1107, 63, 585, 275, 661, 709, 14, 709, 14, 17, 9538, 339, 327, 19292, 3959, 1015, 272, 17309, 14, 10202, 480, 24107, 21, 14, 10901, 14, 19229, 63, 4612, 63, 3027, 401, 283, 21, 14, 25, 14, 21, 358, 339, 327, 961, 1077, 440, 746, 376, 2186, 272, 862, 26, 267, 492, 19227, 647, 272, 871, 2186, 26, 267, 4613, 14, 1633, 480, 547, 9124, 421, 199, 32, 4462, 14, 1657, 14, 22696, 8, 1397, 334, 4521, 19229, 21, 503, 7843, 28035, 18, 395, 490, 4499, 628, 52, 20174, 370, 14084, 21, 503, 1611, 15414, 18, 531, 199, 32, 1805, 14, 2068, 14, 785, 8, 3246, 12, 283, 3088, 63, 422, 358, 199, 318, 511, 63, 8440, 27176, 63, 1971, 8, 3088, 63, 422, 12, 17309, 304, 272, 327, 5852, 19227, 647, 370, 295, 646, 652, 4020, 272, 862, 26, 267, 2150, 984, 14, 3112, 905, 8440, 647, 937, 272, 871, 4067, 26, 267, 986, 339, 327, 19292, 26678, 370, 31102, 282, 4497, 3100, 2656, 272, 17309, 14, 10202, 480, 1274, 14, 3246, 401, 283, 13245, 358, 272, 4497, 63, 422, 14, 1107, 63, 585, 275, 661, 709, 14, 709, 14, 19, 9538, 339, 327, 19292, 3959, 1015, 272, 340, 7843, 19229, 21, 26, 267, 17309, 14, 10202, 480, 24107, 21, 14, 10901, 14, 19229, 63, 4612, 63, 3027, 401, 283, 21, 14, 845, 14, 17, 358, 272, 587, 26, 267, 17309, 14, 10202, 480, 2713, 15414, 18, 14, 10901, 855, 1023, 13915, 283, 21, 14, 845, 14, 17, 358, 339, 327, 961, 1077, 746, 376, 2186, 272, 543, 4613, 14, 3536, 8, 1726, 9, 465, 325, 26, 267, 492, 19227, 647, 339, 702, 283, 709, 14, 845, 7, 315, 620, 8, 69, 14, 585, 9, 272, 702, 283, 21, 14, 845, 7, 315, 620, 8, 69, 14, 585, 9, 421, 199, 32, 4462, 14, 1657, 14, 22696, 8, 1397, 334, 4521, 19229, 21, 503, 7843, 28035, 18, 395, 490, 4499, 628, 52, 20174, 370, 14084, 21, 503, 1611, 15414, 18, 531, 199, 32, 1805, 14, 2068, 14, 785, 8, 3246, 12, 283, 3088, 63, 422, 358, 199, 318, 511, 63, 8440, 27176, 63, 889, 63, 1971, 8, 3088, 63, 422, 12, 17309, 304, 272, 327, 5852, 19227, 647, 370, 295, 646, 652, 4020, 272, 862, 26, 267, 2150, 984, 14, 3112, 905, 8440, 647, 937, 272, 871, 4067, 26, 267, 986, 339, 327, 19292, 26678, 370, 31102, 282, 4497, 3100, 2656, 272, 17309, 14, 10202, 480, 1274, 14, 3246, 401, 283, 13245, 358, 272, 4497, 63, 422, 14, 1107, 63, 585, 275, 661, 709, 14, 969, 14, 18, 9538, 339, 327, 19292, 3959, 1015, 272, 340, 7843, 19229, 21, 26, 267, 17309, 14, 10202, 480, 24107, 21, 14, 10901, 14, 19229, 63, 4612, 63, 3027, 401, 283, 21, 14, 845, 14, 17, 358, 272, 587, 26, 267, 17309, 14, 10202, 480, 2713, 15414, 18, 14, 10901, 855, 1023, 13915, 283, 21, 14, 845, 14, 17, 358, 8410, 327, 961, 1077, 440, 746, 376, 2186, 272, 862, 26, 267, 492, 19227, 647, 272, 871, 2186, 26, 267, 4613, 14, 1633, 480, 547, 9124, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
bromjiri/Presto
predictor/predictor_new.py
1
8137
import settings import pandas as pd import numpy as np import os from datetime import datetime from datetime import timedelta import predictor.predictor_classifier as cls import predictor.predictor_statistic as stat import random import nltk class Stock: def __init__(self, subject): input_file = settings.PREDICTOR_STOCK + "/" + subject + ".csv" self.stock_df = pd.read_csv(input_file, sep=',', index_col='Date') def create_dict(self, from_date, to_date): self.stock_ser = self.stock_df['Diff'].loc[from_date:to_date] # binning self.stock_ser = self.stock_ser.apply(binning_none) self.stock_dict = self.stock_ser.dropna().astype(int).to_dict() def get_dict(self): return self.stock_dict def get_stock_dates(self): return self.stock_ser.index.values class Sent: def __init__(self, subject, source): input_file = settings.PREDICTOR_SENTIMENT + "/" + source + "/" + source + "-sent-" + subject + ".csv" self.sent_df = pd.read_csv(input_file, sep=',', index_col='Date') def get_weekend(self, col_name, stock_dates): weekend_df = np.round(self.sent_df, 2) aggreg = 0 days = 1 for idx, row in weekend_df.iterrows(): value = row[col_name] date = pd.to_datetime(idx) date_plus = date + timedelta(days=1) if str(date_plus.date()) not in stock_dates: # print("weekend") value += aggreg aggreg = value days += 1 else: total = value + aggreg mean = total / days aggreg = 0 days = 1 weekend_df.set_value(idx, col_name, mean) # print(date.date(), row[col_name], value) return np.round(weekend_df[col_name].diff().loc[stock_dates], 2) def create_dict(self, precision, method, from_date, to_date, stock_dates, binning): sentiment_col = "Sent" + precision sent_ser = self.sent_df[sentiment_col] if method == "Natural": sent_ser = sent_ser.diff().loc[from_date:to_date] elif method == "Friday": sent_ser = sent_ser.loc[stock_dates].diff() elif method == "Sunday": sent_ser = sent_ser.diff().loc[stock_dates] elif method == "Weekend": sent_ser = self.get_weekend(sentiment_col, stock_dates) # binning std_dev1 = sent_ser.std() / 4 std_dev2 = sent_ser.std() if binning == 'none': sent_ser_new = sent_ser.apply(binning_none) elif binning == 'low': sent_ser_new = sent_ser.apply(binning_low, args=(std_dev1,)) else: sent_ser_new = sent_ser.apply(binning_high, args=(std_dev1, std_dev2,)) # print(pd.concat([sent_ser, sent_ser_new], axis=1)) self.sent_dict = sent_ser_new.dropna().astype(int).to_dict() self.key_list = sorted(self.sent_dict.keys()) def get_dict(self): return self.sent_dict def get_features(self, key): index = self.key_list.index(key) features = dict() features['d1'] = self.sent_dict[self.key_list[index-3]] features['d2'] = self.sent_dict[self.key_list[index-2]] features['d3'] = self.sent_dict[self.key_list[index-1]] return features def binning_none(row): if row > 0: return 4 elif row < 0: return 0 else: return row def binning_low(row, std_dev1): if row > std_dev1: return 4 elif row < std_dev1 and row > -std_dev1: return 2 elif row < -std_dev1: return 0 else: return row def binning_high(row, std_dev1, std_dev2): if row > std_dev2: return 4 elif row < std_dev2 and row > std_dev1: return 3 elif row < std_dev1 and row > -std_dev1: return 2 elif row < -std_dev1 and row > -std_dev2: return 1 elif row < -std_dev2: return 0 else: return row def run_one(source, subject, precision, method, from_date, to_date, binning, filename_nltk, filename_skl): # stock dataframe stock = Stock(subject) stock.create_dict(from_date, to_date) stock_dict = stock.get_dict() # print(sorted(stock_dict.items())) indexes = ["djia", "snp", "nasdaq"] # if subject in indexes: # subject = "the" # sentiment dataframe sent = Sent(subject, source) sent.create_dict(precision, method, from_date, to_date, stock.get_stock_dates(), binning) # print(sorted(sent.get_dict().items())) # features features_list = list() for key in sorted(stock_dict)[3:]: features = sent.get_features(key) features_list.append([features, stock_dict[key]]) # print([key, sorted(features.items()), stock_dict[key]]) features_list_pos = list() features_list_neg = list() for feature in features_list: if feature[1] == 0: features_list_neg.append(feature) else: features_list_pos.append(feature) statistic = stat.Statistic(source, subject, precision, method, binning) # print(len(features_list), len(features_list_pos), len(features_list_neg)) max_half = min(len(features_list_pos), len(features_list_neg)) train_border = int(max_half * 4 / 5) # print(train_border, max_half) # exit() cycles = 50 for x in range(0, cycles): random.shuffle(features_list_pos) random.shuffle(features_list_neg) # random.shuffle(features_list) trainfeats = features_list_pos[:train_border] + features_list_neg[:train_border] testfeats = features_list_pos[train_border:max_half] + features_list_neg[train_border:max_half] # print(len(trainfeats), len(testfeats)) # trainfeats = features_list[:170] # testfeats = features_list[170:] nlt_output, skl_output = cls.train(trainfeats, testfeats, nlt=nltk_run, skl=sklearn_run) # print(nlt_output['most1']) # exit() if nltk_run: statistic.add_nltk(nlt_output) if sklearn_run: statistic.add_skl(skl_output) if nltk_run: statistic.mean_nltk(cycles) statistic.print_nltk() # statistic.write_nltk(filename_nltk) if sklearn_run: statistic.mean_skl(cycles) statistic.print_skl() statistic.print_stddev() # statistic.write_skl(filename_skl) nltk_run = True sklearn_run = True from_date = '2016-11-01' to_date = '2017-08-31' source = "stwits-comb" binnings = ['none', 'low', 'high'] # subjects = ["snp", "djia", "nasdaq"] subjects = ["djia", "snp", "nasdaq"] # subjects = ["microsoft"] precisions = ["0.6", "0.8", "1.0"] # precisions = ["0.6"] methods = ["Friday", "Natural", "Weekend", "Sunday"] # methods = ["Friday"] for subject in subjects: folder = settings.PREDICTOR_PREDICTION + '/' + source + '/' + subject + '/' os.makedirs(folder, exist_ok=True) filename_nltk = folder + source + '-prediction-' + subject + "-nltk.csv" filename_skl = folder + source + '-prediction-' + subject + "-skl.csv" # if nltk_run: # open(filename_nltk, 'w').close() # # if sklearn_run: # open(filename_skl, 'w').close() for method in methods: # if nltk_run: # f = open(filename_nltk, 'a') # f.write(source + ", " + subject + ", " + method + ", NLTK\n") # f.write("precision, binning, accuracy, pos_prec, neg_prec, pos_rec, neg_rec, d1, d2, d3\n") # f.close() # # if sklearn_run: # f = open(filename_skl, 'a') # f.write(source + ", " + subject + ", " + method + ", SKL\n") # f.write("precision, binning, mnb, bnb, lr, lsvc, nsvc, voted\n") # f.close() for precision in precisions: for binning in binnings: # print(source, subject, precision, method) run_one(source, subject, precision, method, from_date, to_date, binning, filename_nltk, filename_skl)
mit
[ 646, 2202, 199, 646, 10634, 465, 6454, 199, 646, 2680, 465, 980, 199, 646, 747, 199, 504, 2197, 492, 2197, 199, 504, 2197, 492, 6871, 199, 646, 4557, 630, 14, 5790, 630, 63, 14720, 465, 843, 199, 646, 4557, 630, 14, 5790, 630, 63, 26065, 465, 5672, 199, 646, 2196, 199, 646, 24706, 421, 199, 533, 28406, 26, 339, 347, 636, 826, 721, 277, 12, 5420, 304, 267, 1324, 63, 493, 275, 2202, 14, 4225, 12511, 726, 63, 24838, 435, 10609, 435, 5420, 435, 3680, 4737, 2, 267, 291, 14, 6088, 63, 1587, 275, 6454, 14, 739, 63, 4737, 8, 1210, 63, 493, 12, 7375, 4009, 297, 1478, 63, 761, 534, 2506, 358, 339, 347, 1218, 63, 807, 8, 277, 12, 687, 63, 602, 12, 370, 63, 602, 304, 267, 291, 14, 6088, 63, 332, 275, 291, 14, 6088, 63, 1587, 459, 10746, 2278, 2102, 59, 504, 63, 602, 26, 475, 63, 602, 61, 398, 327, 2517, 1835, 267, 291, 14, 6088, 63, 332, 275, 291, 14, 6088, 63, 332, 14, 4998, 8, 1393, 1835, 63, 3592, 9, 398, 291, 14, 6088, 63, 807, 275, 291, 14, 6088, 63, 332, 14, 4824, 3540, 1252, 6041, 8, 442, 680, 475, 63, 807, 342, 339, 347, 664, 63, 807, 8, 277, 304, 267, 372, 291, 14, 6088, 63, 807, 339, 347, 664, 63, 6088, 63, 9356, 8, 277, 304, 267, 372, 291, 14, 6088, 63, 332, 14, 1080, 14, 1459, 421, 199, 533, 428, 484, 26, 339, 347, 636, 826, 721, 277, 12, 5420, 12, 1350, 304, 267, 1324, 63, 493, 275, 2202, 14, 4225, 12511, 726, 63, 32173, 1469, 1309, 435, 10609, 435, 1350, 435, 10609, 435, 1350, 435, 3905, 1150, 23245, 435, 5420, 435, 3680, 4737, 2, 267, 291, 14, 1150, 63, 1587, 275, 6454, 14, 739, 63, 4737, 8, 1210, 63, 493, 12, 7375, 4009, 297, 1478, 63, 761, 534, 2506, 358, 339, 347, 664, 63, 6419, 500, 8, 277, 12, 1048, 63, 354, 12, 10952, 63, 9356, 304, 398, 8620, 500, 63, 1587, 275, 980, 14, 2363, 8, 277, 14, 1150, 63, 1587, 12, 499, 9, 398, 10454, 275, 378, 267, 7609, 275, 413, 267, 367, 4280, 12, 1962, 315, 8620, 500, 63, 1587, 14, 1661, 3838, 837, 288, 574, 275, 1962, 59, 761, 63, 354, 61, 288, 1434, 275, 6454, 14, 475, 63, 2083, 8, 2996, 9, 288, 1434, 63, 6666, 275, 1434, 435, 6871, 8, 4899, 29, 17, 9, 288, 340, 620, 8, 602, 63, 6666, 14, 602, 1012, 440, 315, 10952, 63, 9356, 26, 355, 327, 870, 480, 6419, 500, 531, 355, 574, 847, 10454, 355, 10454, 275, 574, 355, 7609, 847, 413, 288, 587, 26, 355, 3141, 275, 574, 435, 10454, 355, 4615, 275, 3141, 1182, 7609, 355, 10454, 275, 378, 355, 7609, 275, 413, 355, 8620, 500, 63, 1587, 14, 409, 63, 585, 8, 2996, 12, 1048, 63, 354, 12, 4615, 9, 953, 327, 870, 8, 602, 14, 602, 1062, 1962, 59, 761, 63, 354, 467, 574, 9, 398, 372, 980, 14, 2363, 8, 6419, 500, 63, 1587, 59, 761, 63, 354, 1055, 3028, 1252, 2102, 59, 6088, 63, 9356, 467, 499, 9, 339, 347, 1218, 63, 807, 8, 277, 12, 7151, 12, 1083, 12, 687, 63, 602, 12, 370, 63, 602, 12, 10952, 63, 9356, 12, 2517, 1835, 304, 267, 4334, 280, 434, 63, 761, 275, 298, 17367, 2, 435, 7151, 267, 4847, 63, 332, 275, 291, 14, 1150, 63, 1587, 59, 2464, 280, 434, 63, 761, 61, 398, 340, 1083, 508, 298, 23604, 4889, 582, 288, 4847, 63, 332, 275, 4847, 63, 332, 14, 3028, 1252, 2102, 59, 504, 63, 602, 26, 475, 63, 602, 61, 267, 916, 1083, 508, 298, 22533, 2977, 582, 288, 4847, 63, 332, 275, 4847, 63, 332, 14, 2102, 59, 6088, 63, 9356, 1055, 3028, 342, 267, 916, 1083, 508, 298, 51, 24759, 582, 288, 4847, 63, 332, 275, 4847, 63, 332, 14, 3028, 1252, 2102, 59, 6088, 63, 9356, 61, 267, 916, 1083, 508, 298, 20995, 500, 582, 288, 4847, 63, 332, 275, 291, 14, 362, 63, 6419, 500, 8, 2464, 280, 434, 63, 761, 12, 10952, 63, 9356, 9, 398, 327, 2517, 1835, 267, 2418, 63, 2374, 17, 275, 4847, 63, 332, 14, 1516, 342, 1182, 841, 267, 2418, 63, 2374, 18, 275, 4847, 63, 332, 14, 1516, 342, 398, 340, 2517, 1835, 508, 283, 3592, 356, 288, 4847, 63, 332, 63, 1222, 275, 4847, 63, 332, 14, 4998, 8, 1393, 1835, 63, 3592, 9, 267, 916, 2517, 1835, 508, 283, 674, 356, 288, 4847, 63, 332, 63, 1222, 275, 4847, 63, 332, 14, 4998, 8, 1393, 1835, 63, 674, 12, 1249, 2687, 1516, 63, 2374, 17, 4641, 267, 587, 26, 288, 4847, 63, 332, 63, 1222, 275, 4847, 63, 332, 14, 4998, 8, 1393, 1835, 63, 6260, 12, 1249, 2687, 1516, 63, 2374, 17, 12, 2418, 63, 2374, 18, 4641, 398, 327, 870, 8, 8961, 14, 9419, 779, 1150, 63, 332, 12, 4847, 63, 332, 63, 1222, 467, 3114, 29, 17, 430, 398, 291, 14, 1150, 63, 807, 275, 4847, 63, 332, 63, 1222, 14, 4824, 3540, 1252, 6041, 8, 442, 680, 475, 63, 807, 342, 267, 291, 14, 498, 63, 513, 275, 3355, 8, 277, 14, 1150, 63, 807, 14, 1612, 1012, 339, 347, 664, 63, 807, 8, 277, 304, 267, 372, 291, 14, 1150, 63, 807, 339, 347, 664, 63, 3179, 8, 277, 12, 790, 304, 267, 1478, 275, 291, 14, 498, 63, 513, 14, 1080, 8, 498, 9, 398, 4534, 275, 1211, 342, 267, 4534, 459, 68, 17, 418, 275, 291, 14, 1150, 63, 807, 59, 277, 14, 498, 63, 513, 59, 1080, 13, 19, 2677, 267, 4534, 459, 68, 18, 418, 275, 291, 14, 1150, 63, 807, 59, 277, 14, 498, 63, 513, 59, 1080, 13, 18, 2677, 267, 4534, 459, 68, 19, 418, 275, 291, 14, 1150, 63, 807, 59, 277, 14, 498, 63, 513, 59, 1080, 13, 17, 2677, 267, 372, 4534, 421, 199, 318, 2517, 1835, 63, 3592, 8, 1143, 304, 339, 340, 1962, 690, 378, 26, 267, 372, 841, 272, 916, 1962, 665, 378, 26, 267, 372, 378, 272, 587, 26, 267, 372, 1962, 421, 199, 318, 2517, 1835 ]
[ 2202, 199, 646, 10634, 465, 6454, 199, 646, 2680, 465, 980, 199, 646, 747, 199, 504, 2197, 492, 2197, 199, 504, 2197, 492, 6871, 199, 646, 4557, 630, 14, 5790, 630, 63, 14720, 465, 843, 199, 646, 4557, 630, 14, 5790, 630, 63, 26065, 465, 5672, 199, 646, 2196, 199, 646, 24706, 421, 199, 533, 28406, 26, 339, 347, 636, 826, 721, 277, 12, 5420, 304, 267, 1324, 63, 493, 275, 2202, 14, 4225, 12511, 726, 63, 24838, 435, 10609, 435, 5420, 435, 3680, 4737, 2, 267, 291, 14, 6088, 63, 1587, 275, 6454, 14, 739, 63, 4737, 8, 1210, 63, 493, 12, 7375, 4009, 297, 1478, 63, 761, 534, 2506, 358, 339, 347, 1218, 63, 807, 8, 277, 12, 687, 63, 602, 12, 370, 63, 602, 304, 267, 291, 14, 6088, 63, 332, 275, 291, 14, 6088, 63, 1587, 459, 10746, 2278, 2102, 59, 504, 63, 602, 26, 475, 63, 602, 61, 398, 327, 2517, 1835, 267, 291, 14, 6088, 63, 332, 275, 291, 14, 6088, 63, 332, 14, 4998, 8, 1393, 1835, 63, 3592, 9, 398, 291, 14, 6088, 63, 807, 275, 291, 14, 6088, 63, 332, 14, 4824, 3540, 1252, 6041, 8, 442, 680, 475, 63, 807, 342, 339, 347, 664, 63, 807, 8, 277, 304, 267, 372, 291, 14, 6088, 63, 807, 339, 347, 664, 63, 6088, 63, 9356, 8, 277, 304, 267, 372, 291, 14, 6088, 63, 332, 14, 1080, 14, 1459, 421, 199, 533, 428, 484, 26, 339, 347, 636, 826, 721, 277, 12, 5420, 12, 1350, 304, 267, 1324, 63, 493, 275, 2202, 14, 4225, 12511, 726, 63, 32173, 1469, 1309, 435, 10609, 435, 1350, 435, 10609, 435, 1350, 435, 3905, 1150, 23245, 435, 5420, 435, 3680, 4737, 2, 267, 291, 14, 1150, 63, 1587, 275, 6454, 14, 739, 63, 4737, 8, 1210, 63, 493, 12, 7375, 4009, 297, 1478, 63, 761, 534, 2506, 358, 339, 347, 664, 63, 6419, 500, 8, 277, 12, 1048, 63, 354, 12, 10952, 63, 9356, 304, 398, 8620, 500, 63, 1587, 275, 980, 14, 2363, 8, 277, 14, 1150, 63, 1587, 12, 499, 9, 398, 10454, 275, 378, 267, 7609, 275, 413, 267, 367, 4280, 12, 1962, 315, 8620, 500, 63, 1587, 14, 1661, 3838, 837, 288, 574, 275, 1962, 59, 761, 63, 354, 61, 288, 1434, 275, 6454, 14, 475, 63, 2083, 8, 2996, 9, 288, 1434, 63, 6666, 275, 1434, 435, 6871, 8, 4899, 29, 17, 9, 288, 340, 620, 8, 602, 63, 6666, 14, 602, 1012, 440, 315, 10952, 63, 9356, 26, 355, 327, 870, 480, 6419, 500, 531, 355, 574, 847, 10454, 355, 10454, 275, 574, 355, 7609, 847, 413, 288, 587, 26, 355, 3141, 275, 574, 435, 10454, 355, 4615, 275, 3141, 1182, 7609, 355, 10454, 275, 378, 355, 7609, 275, 413, 355, 8620, 500, 63, 1587, 14, 409, 63, 585, 8, 2996, 12, 1048, 63, 354, 12, 4615, 9, 953, 327, 870, 8, 602, 14, 602, 1062, 1962, 59, 761, 63, 354, 467, 574, 9, 398, 372, 980, 14, 2363, 8, 6419, 500, 63, 1587, 59, 761, 63, 354, 1055, 3028, 1252, 2102, 59, 6088, 63, 9356, 467, 499, 9, 339, 347, 1218, 63, 807, 8, 277, 12, 7151, 12, 1083, 12, 687, 63, 602, 12, 370, 63, 602, 12, 10952, 63, 9356, 12, 2517, 1835, 304, 267, 4334, 280, 434, 63, 761, 275, 298, 17367, 2, 435, 7151, 267, 4847, 63, 332, 275, 291, 14, 1150, 63, 1587, 59, 2464, 280, 434, 63, 761, 61, 398, 340, 1083, 508, 298, 23604, 4889, 582, 288, 4847, 63, 332, 275, 4847, 63, 332, 14, 3028, 1252, 2102, 59, 504, 63, 602, 26, 475, 63, 602, 61, 267, 916, 1083, 508, 298, 22533, 2977, 582, 288, 4847, 63, 332, 275, 4847, 63, 332, 14, 2102, 59, 6088, 63, 9356, 1055, 3028, 342, 267, 916, 1083, 508, 298, 51, 24759, 582, 288, 4847, 63, 332, 275, 4847, 63, 332, 14, 3028, 1252, 2102, 59, 6088, 63, 9356, 61, 267, 916, 1083, 508, 298, 20995, 500, 582, 288, 4847, 63, 332, 275, 291, 14, 362, 63, 6419, 500, 8, 2464, 280, 434, 63, 761, 12, 10952, 63, 9356, 9, 398, 327, 2517, 1835, 267, 2418, 63, 2374, 17, 275, 4847, 63, 332, 14, 1516, 342, 1182, 841, 267, 2418, 63, 2374, 18, 275, 4847, 63, 332, 14, 1516, 342, 398, 340, 2517, 1835, 508, 283, 3592, 356, 288, 4847, 63, 332, 63, 1222, 275, 4847, 63, 332, 14, 4998, 8, 1393, 1835, 63, 3592, 9, 267, 916, 2517, 1835, 508, 283, 674, 356, 288, 4847, 63, 332, 63, 1222, 275, 4847, 63, 332, 14, 4998, 8, 1393, 1835, 63, 674, 12, 1249, 2687, 1516, 63, 2374, 17, 4641, 267, 587, 26, 288, 4847, 63, 332, 63, 1222, 275, 4847, 63, 332, 14, 4998, 8, 1393, 1835, 63, 6260, 12, 1249, 2687, 1516, 63, 2374, 17, 12, 2418, 63, 2374, 18, 4641, 398, 327, 870, 8, 8961, 14, 9419, 779, 1150, 63, 332, 12, 4847, 63, 332, 63, 1222, 467, 3114, 29, 17, 430, 398, 291, 14, 1150, 63, 807, 275, 4847, 63, 332, 63, 1222, 14, 4824, 3540, 1252, 6041, 8, 442, 680, 475, 63, 807, 342, 267, 291, 14, 498, 63, 513, 275, 3355, 8, 277, 14, 1150, 63, 807, 14, 1612, 1012, 339, 347, 664, 63, 807, 8, 277, 304, 267, 372, 291, 14, 1150, 63, 807, 339, 347, 664, 63, 3179, 8, 277, 12, 790, 304, 267, 1478, 275, 291, 14, 498, 63, 513, 14, 1080, 8, 498, 9, 398, 4534, 275, 1211, 342, 267, 4534, 459, 68, 17, 418, 275, 291, 14, 1150, 63, 807, 59, 277, 14, 498, 63, 513, 59, 1080, 13, 19, 2677, 267, 4534, 459, 68, 18, 418, 275, 291, 14, 1150, 63, 807, 59, 277, 14, 498, 63, 513, 59, 1080, 13, 18, 2677, 267, 4534, 459, 68, 19, 418, 275, 291, 14, 1150, 63, 807, 59, 277, 14, 498, 63, 513, 59, 1080, 13, 17, 2677, 267, 372, 4534, 421, 199, 318, 2517, 1835, 63, 3592, 8, 1143, 304, 339, 340, 1962, 690, 378, 26, 267, 372, 841, 272, 916, 1962, 665, 378, 26, 267, 372, 378, 272, 587, 26, 267, 372, 1962, 421, 199, 318, 2517, 1835, 0 ]
[ 1, 1, 1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terisk-scripts
script/googlecontacts.py
1
2701
#!/usr/bin/python3 """Get Google Contacts Usage: google_contacts.py [--noauth_local_webserver] Options: --noauth_local_webserver passed on to google auth """ import docopt import httplib2 import subprocess import unidecode from apiclient import discovery from argparse import Namespace from oauth2client import client from oauth2client import tools from oauth2client.file import Storage ### APPLICATION_NAME = "Asterisk DB Updater" # If modifying these scopes, delete your previously saved credentials SCOPES = [ "https://www.googleapis.com/auth/contacts.readonly", "https://www.googleapis.com/auth/people.readonly", ] OAUTH_CONFIG_FILE = "/etc/asterisk-scripts/asterisk_client_secrets.json" OAUTH_TOKEN_FILE = "/etc/asterisk-scripts/asterisk_script_tokens.json" ### def get_credentials(flags): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. :param flags: oauth flags :return: the obtained credentials """ store = Storage(OAUTH_TOKEN_FILE) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(OAUTH_CONFIG_FILE, SCOPES) flow.user_agent = APPLICATION_NAME credentials = tools.run_flow(flow, store, flags) print(f"Storing credentials to: {OAUTH_TOKEN_FILE}") return credentials def main(): """Update asterisk db from google contacts""" opts = docopt.docopt(__doc__) flags = Namespace( auth_host_name="localhost", auth_host_port=[8080, 8090], logging_level="ERROR", noauth_local_webserver=opts["--noauth_local_webserver"], ) credentials = get_credentials(flags) http = credentials.authorize(httplib2.Http()) if opts["--noauth_local_webserver"]: return service = discovery.build("people", "v1", http=http) contacts_response = ( service.people() .connections() .list( resourceName="people/me", personFields="names,phoneNumbers", sortOrder="LAST_NAME_ASCENDING", ) .execute() ) for i, contact in enumerate(contacts_response["connections"]): display_name = ( contact["names"][0]["displayName"] if len(contact["names"]) > 0 else "Unknown" ) for phone in contact["phoneNumbers"]: ast_cmd = f'database put cidname {phone["canonicalForm"]} "{display_name}"' subprocess.run(["asterisk", "-rx", unidecode.unidecode(ast_cmd)]) if __name__ == "__main__": main()
mit
[ 3381, 2647, 15, 1393, 15, 1548, 19, 199, 624, 1002, 4475, 1448, 11961, 199, 199, 7692, 26, 6233, 63, 18147, 14, 647, 19344, 889, 1178, 63, 1832, 63, 29819, 61, 199, 199, 4558, 26, 272, 1553, 889, 1178, 63, 1832, 63, 29819, 8295, 3032, 641, 370, 6233, 1790, 199, 624, 199, 646, 886, 32626, 199, 646, 8809, 18, 199, 646, 3873, 199, 646, 625, 2655, 600, 199, 199, 504, 2771, 530, 864, 492, 13172, 199, 504, 7534, 492, 19317, 199, 504, 9725, 18, 1258, 492, 1890, 199, 504, 9725, 18, 1258, 492, 7249, 199, 504, 9725, 18, 1258, 14, 493, 492, 10533, 199, 199, 5680, 421, 199, 24051, 63, 2339, 275, 298, 33, 1597, 27473, 6249, 6162, 82, 2, 199, 199, 3, 982, 24662, 3520, 14570, 12, 3145, 2195, 10889, 6290, 6235, 199, 15901, 48, 654, 275, 359, 272, 298, 2859, 921, 1544, 14, 17533, 14, 957, 15, 1178, 15, 18147, 14, 6753, 401, 272, 298, 2859, 921, 1544, 14, 17533, 14, 957, 15, 1178, 15, 13562, 14, 6753, 401, 199, 61, 199, 199, 24041, 63, 5569, 63, 3817, 275, 3286, 6839, 15, 305, 6236, 1339, 13, 6429, 15, 305, 6236, 1339, 63, 1258, 63, 16153, 14, 1001, 2, 199, 24041, 63, 8803, 63, 3817, 275, 3286, 6839, 15, 305, 6236, 1339, 13, 6429, 15, 305, 6236, 1339, 63, 1579, 63, 4504, 14, 1001, 2, 421, 199, 5680, 421, 199, 318, 664, 63, 6942, 8, 2469, 304, 272, 408, 14426, 1686, 922, 6235, 687, 4887, 14, 339, 982, 6548, 965, 2757, 5489, 12, 503, 340, 314, 5489, 6235, 787, 3866, 12, 272, 314, 11715, 18, 6369, 365, 9709, 370, 3332, 314, 892, 6235, 14, 339, 520, 635, 3285, 26, 9725, 3285, 272, 520, 1107, 26, 314, 15884, 6235, 272, 408, 272, 3877, 275, 10533, 8, 24041, 63, 8803, 63, 3817, 9, 272, 6235, 275, 3877, 14, 362, 342, 272, 340, 440, 6235, 503, 6235, 14, 3197, 26, 267, 6369, 275, 1890, 14, 1659, 63, 504, 63, 1258, 16153, 8, 24041, 63, 5569, 63, 3817, 12, 428, 32324, 654, 9, 267, 6369, 14, 751, 63, 4054, 275, 19525, 17939, 63, 2339, 267, 6235, 275, 7249, 14, 1065, 63, 1659, 8, 1659, 12, 3877, 12, 3285, 9, 267, 870, 8, 70, 2, 933, 6854, 6235, 370, 26, 469, 24041, 63, 8803, 63, 3817, 15412, 272, 372, 6235, 421, 199, 318, 2446, 837, 272, 408, 4152, 465, 6236, 1339, 1592, 687, 6233, 27989, 624, 272, 3999, 275, 886, 32626, 14, 1117, 32626, 3460, 1301, 3368, 272, 3285, 275, 19317, 8, 267, 1790, 63, 1102, 63, 354, 628, 5967, 401, 267, 1790, 63, 1102, 63, 719, 1524, 15844, 12, 5939, 2710, 467, 267, 2050, 63, 1896, 628, 3170, 401, 267, 949, 1178, 63, 1832, 63, 29819, 29, 3291, 905, 306, 889, 1178, 63, 1832, 63, 29819, 2255, 272, 776, 339, 6235, 275, 664, 63, 6942, 8, 2469, 9, 272, 1455, 275, 6235, 14, 14204, 8, 12942, 18, 14, 5779, 1012, 339, 340, 3999, 905, 306, 889, 1178, 63, 1832, 63, 29819, 6229, 267, 372, 339, 2435, 275, 13172, 14, 1506, 480, 13562, 401, 298, 86, 17, 401, 1455, 29, 1014, 9, 272, 27989, 63, 1310, 275, 334, 267, 2435, 14, 13562, 342, 267, 1275, 7995, 342, 267, 1275, 513, 8, 288, 2073, 985, 628, 13562, 15, 278, 401, 288, 4954, 7304, 628, 1247, 12, 9339, 22951, 401, 288, 4069, 4738, 628, 16901, 63, 2339, 63, 22767, 15219, 401, 267, 776, 267, 1275, 2526, 342, 272, 776, 339, 367, 284, 12, 8966, 315, 3874, 8, 18147, 63, 1310, 905, 7995, 21473, 267, 2929, 63, 354, 275, 334, 288, 8966, 905, 1247, 9210, 16, 7541, 2918, 985, 937, 288, 340, 822, 8, 7811, 905, 1247, 3135, 690, 378, 288, 587, 298, 5912, 2, 267, 776, 398, 367, 14617, 315, 8966, 905, 9339, 22951, 6229, 288, 6073, 63, 1760, 275, 289, 5121, 1963, 5324, 12229, 354, 469, 9339, 905, 13109, 2821, 27635, 5310, 2918, 63, 354, 93, 4507, 288, 3873, 14, 1065, 5234, 305, 6236, 1339, 401, 3905, 6872, 401, 625, 2655, 600, 14, 324, 2655, 600, 8, 1810, 63, 1760, 3948, 421, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 2446, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1548, 19, 199, 624, 1002, 4475, 1448, 11961, 199, 199, 7692, 26, 6233, 63, 18147, 14, 647, 19344, 889, 1178, 63, 1832, 63, 29819, 61, 199, 199, 4558, 26, 272, 1553, 889, 1178, 63, 1832, 63, 29819, 8295, 3032, 641, 370, 6233, 1790, 199, 624, 199, 646, 886, 32626, 199, 646, 8809, 18, 199, 646, 3873, 199, 646, 625, 2655, 600, 199, 199, 504, 2771, 530, 864, 492, 13172, 199, 504, 7534, 492, 19317, 199, 504, 9725, 18, 1258, 492, 1890, 199, 504, 9725, 18, 1258, 492, 7249, 199, 504, 9725, 18, 1258, 14, 493, 492, 10533, 199, 199, 5680, 421, 199, 24051, 63, 2339, 275, 298, 33, 1597, 27473, 6249, 6162, 82, 2, 199, 199, 3, 982, 24662, 3520, 14570, 12, 3145, 2195, 10889, 6290, 6235, 199, 15901, 48, 654, 275, 359, 272, 298, 2859, 921, 1544, 14, 17533, 14, 957, 15, 1178, 15, 18147, 14, 6753, 401, 272, 298, 2859, 921, 1544, 14, 17533, 14, 957, 15, 1178, 15, 13562, 14, 6753, 401, 199, 61, 199, 199, 24041, 63, 5569, 63, 3817, 275, 3286, 6839, 15, 305, 6236, 1339, 13, 6429, 15, 305, 6236, 1339, 63, 1258, 63, 16153, 14, 1001, 2, 199, 24041, 63, 8803, 63, 3817, 275, 3286, 6839, 15, 305, 6236, 1339, 13, 6429, 15, 305, 6236, 1339, 63, 1579, 63, 4504, 14, 1001, 2, 421, 199, 5680, 421, 199, 318, 664, 63, 6942, 8, 2469, 304, 272, 408, 14426, 1686, 922, 6235, 687, 4887, 14, 339, 982, 6548, 965, 2757, 5489, 12, 503, 340, 314, 5489, 6235, 787, 3866, 12, 272, 314, 11715, 18, 6369, 365, 9709, 370, 3332, 314, 892, 6235, 14, 339, 520, 635, 3285, 26, 9725, 3285, 272, 520, 1107, 26, 314, 15884, 6235, 272, 408, 272, 3877, 275, 10533, 8, 24041, 63, 8803, 63, 3817, 9, 272, 6235, 275, 3877, 14, 362, 342, 272, 340, 440, 6235, 503, 6235, 14, 3197, 26, 267, 6369, 275, 1890, 14, 1659, 63, 504, 63, 1258, 16153, 8, 24041, 63, 5569, 63, 3817, 12, 428, 32324, 654, 9, 267, 6369, 14, 751, 63, 4054, 275, 19525, 17939, 63, 2339, 267, 6235, 275, 7249, 14, 1065, 63, 1659, 8, 1659, 12, 3877, 12, 3285, 9, 267, 870, 8, 70, 2, 933, 6854, 6235, 370, 26, 469, 24041, 63, 8803, 63, 3817, 15412, 272, 372, 6235, 421, 199, 318, 2446, 837, 272, 408, 4152, 465, 6236, 1339, 1592, 687, 6233, 27989, 624, 272, 3999, 275, 886, 32626, 14, 1117, 32626, 3460, 1301, 3368, 272, 3285, 275, 19317, 8, 267, 1790, 63, 1102, 63, 354, 628, 5967, 401, 267, 1790, 63, 1102, 63, 719, 1524, 15844, 12, 5939, 2710, 467, 267, 2050, 63, 1896, 628, 3170, 401, 267, 949, 1178, 63, 1832, 63, 29819, 29, 3291, 905, 306, 889, 1178, 63, 1832, 63, 29819, 2255, 272, 776, 339, 6235, 275, 664, 63, 6942, 8, 2469, 9, 272, 1455, 275, 6235, 14, 14204, 8, 12942, 18, 14, 5779, 1012, 339, 340, 3999, 905, 306, 889, 1178, 63, 1832, 63, 29819, 6229, 267, 372, 339, 2435, 275, 13172, 14, 1506, 480, 13562, 401, 298, 86, 17, 401, 1455, 29, 1014, 9, 272, 27989, 63, 1310, 275, 334, 267, 2435, 14, 13562, 342, 267, 1275, 7995, 342, 267, 1275, 513, 8, 288, 2073, 985, 628, 13562, 15, 278, 401, 288, 4954, 7304, 628, 1247, 12, 9339, 22951, 401, 288, 4069, 4738, 628, 16901, 63, 2339, 63, 22767, 15219, 401, 267, 776, 267, 1275, 2526, 342, 272, 776, 339, 367, 284, 12, 8966, 315, 3874, 8, 18147, 63, 1310, 905, 7995, 21473, 267, 2929, 63, 354, 275, 334, 288, 8966, 905, 1247, 9210, 16, 7541, 2918, 985, 937, 288, 340, 822, 8, 7811, 905, 1247, 3135, 690, 378, 288, 587, 298, 5912, 2, 267, 776, 398, 367, 14617, 315, 8966, 905, 9339, 22951, 6229, 288, 6073, 63, 1760, 275, 289, 5121, 1963, 5324, 12229, 354, 469, 9339, 905, 13109, 2821, 27635, 5310, 2918, 63, 354, 93, 4507, 288, 3873, 14, 1065, 5234, 305, 6236, 1339, 401, 3905, 6872, 401, 625, 2655, 600, 14, 324, 2655, 600, 8, 1810, 63, 1760, 3948, 421, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 2446, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
DueLaser/oprint_raster_develop
src/octoprint/filemanager/storage.py
26
36038
# coding=utf-8 from __future__ import absolute_import __author__ = "Gina Häußge <osd@foosel.net>" __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms of the AGPLv3 License" import logging import os import pylru import tempfile import octoprint.filemanager class StorageInterface(object): """ Interface of storage adapters for OctoPrint. """ @property def analysis_backlog(self): """ Get an iterator over all items stored in the storage that need to be analysed by the :class:`~octoprint.filemanager.AnalysisQueue`. The yielded elements are expected as storage specific absolute paths to the respective files. Don't forget to recurse into folders if your storage adapter supports those. :return: an iterator yielding all un-analysed files in the storage """ # empty generator pattern, yield is intentionally unreachable return yield def file_exists(self, path): """ Returns whether the file indicated by ``path`` exists or not. :param string path: the path to check for existence :return: ``True`` if the file exists, ``False`` otherwise """ raise NotImplementedError() def list_files(self, path=None, filter=None, recursive=True): """ List all files in storage starting at ``path``. If ``recursive`` is set to True (the default), also dives into subfolders. An optional filter function can be supplied which will be called with a file name and file data and which has to return True if the file is to be included in the result or False if not. The data structure of the returned result will be a dictionary mapping from file names to entry data. File nodes will contain their metadata here, folder nodes will contain their contained files and folders. Example:: { "some_folder": { "type": "folder", "children": { "some_sub_folder": { "type": "folder", "children": { ... } }, "some_file.gcode": { "type": "machinecode", "hash": "<sha1 hash>", "links": [ ... ], ... }, ... } "test.gcode": { "type": "machinecode", "hash": "<sha1 hash>", "links": [...], ... }, "test.stl": { "type": "model", "hash": "<sha1 hash>", "links": [...], ... }, ... } :param string path: base path from which to recursively list all files, optional, if not supplied listing will start from root of base folder :param function filter: a filter that matches the files that are to be returned, may be left out in which case no filtering will take place :param bool recursive: will also step into sub folders for building the complete list if set to True :return: a dictionary mapping entry names to entry data that represents the whole file list """ raise NotImplementedError() def add_folder(self, path, ignore_existing=True): """ Adds a folder as ``path``. The ``path`` will be sanitized. :param string path: the path of the new folder :param bool ignore_existing: if set to True, no error will be raised if the folder to be added already exists :return: the sanitized name of the new folder to be used for future references to the folder """ raise NotImplementedError() def remove_folder(self, path, recursive=True): """ Removes the folder at ``path``. :param string path: the path of the folder to remove :param bool recursive: if set to True, contained folders and files will also be removed, otherwise and error will be raised if the folder is not empty (apart from ``.metadata.yaml``) when it's to be removed """ raise NotImplementedError() def add_file(self, path, file_object, printer_profile=None, links=None, allow_overwrite=False): """ Adds the file ``file_object`` as ``path`` :param string path: the file's new path, will be sanitized :param object file_object: a file object that provides a ``save`` method which will be called with the destination path where the object should then store its contents :param object printer_profile: the printer profile associated with this file (if any) :param list links: any links to add with the file :param bool allow_overwrite: if set to True no error will be raised if the file already exists and the existing file and its metadata will just be silently overwritten :return: the sanitized name of the file to be used for future references to it """ raise NotImplementedError() def remove_file(self, path): """ Removes the file at ``path``. Will also take care of deleting the corresponding entries in the metadata and deleting all links pointing to the file. :param string path: path of the file to remove """ raise NotImplementedError() def get_metadata(self, path): """ Retrieves the metadata for the file ``path``. :param path: virtual path to the file for which to retrieve the metadata :return: the metadata associated with the file """ raise NotImplementedError() def add_link(self, path, rel, data): """ Adds a link of relation ``rel`` to file ``path`` with the given ``data``. The following relation types are currently supported: * ``model``: adds a link to a model from which the file was created/sliced, expected additional data is the ``name`` and optionally the ``hash`` of the file to link to. If the link can be resolved against another file on the current ``path``, not only will it be added to the links of ``name`` but a reverse link of type ``machinecode`` refering to ``name`` and its hash will also be added to the linked ``model`` file * ``machinecode``: adds a link to a file containing machine code created from the current file (model), expected additional data is the ``name`` and optionally the ``hash`` of the file to link to. If the link can be resolved against another file on the current ``path``, not only will it be added to the links of ``name`` but a reverse link of type ``model`` refering to ``name`` and its hash will also be added to the linked ``model`` file. * ``web``: adds a location on the web associated with this file (e.g. a website where to download a model), expected additional data is a ``href`` attribute holding the website's URL and optionally a ``retrieved`` attribute describing when the content was retrieved Note that adding ``model`` links to files identifying as models or ``machinecode`` links to files identifying as machine code will be refused. :param path: path of the file for which to add a link :param rel: type of relation of the link to add (currently ``model``, ``machinecode`` and ``web`` are supported) :param data: additional data of the link to add """ raise NotImplementedError() def remove_link(self, path, rel, data): """ Removes the link consisting of ``rel`` and ``data`` from file ``name`` on ``path``. :param path: path of the file from which to remove the link :param rel: type of relation of the link to remove (currently ``model``, ``machinecode`` and ``web`` are supported) :param data: additional data of the link to remove, must match existing link """ raise NotImplementedError() def set_additional_metadata(self, path, key, data, overwrite=False, merge=False): """ Adds additional metadata to the metadata of ``path``. Metadata in ``data`` will be saved under ``key``. If ``overwrite`` is set and ``key`` already exists in ``name``'s metadata, the current value will be overwritten. If ``merge`` is set and ``key`` already exists and both ``data`` and the existing data under ``key`` are dictionaries, the two dictionaries will be merged recursively. :param path: the virtual path to the file for which to add additional metadata :param key: key of metadata to add :param data: metadata to add :param overwrite: if True and ``key`` already exists, it will be overwritten :param merge: if True and ``key`` already exists and both ``data`` and the existing data are dictionaries, they will be merged """ raise NotImplementedError() def remove_additional_metadata(self, path, key): """ Removes additional metadata under ``key`` for ``name`` on ``path`` :param path: the virtual path to the file for which to remove the metadata under ``key`` :param key: the key to remove """ raise NotImplementedError() def sanitize(self, path): """ Sanitizes the given ``path``, stripping it of all invalid characters. The ``path`` may consist of both folder and file name, the underlying implementation must separate those if necessary and sanitize individually. :param string path: the path to sanitize :return: a 2-tuple containing the sanitized path and file name """ raise NotImplementedError() def sanitize_path(self, path): """ Sanitizes the given folder-only ``path``, stripping it of all invalid characters. :param string path: the path to sanitize :return: the sanitized path """ raise NotImplementedError() def sanitize_name(self, name): """ Sanitizes the given file ``name``, stripping it of all invalid characters. :param string name: the file name to sanitize :return: the sanitized name """ raise NotImplementedError() def split_path(self, path): """ Split ``path`` into base directory and file name. :param path: the path to split :return: a tuple (base directory, file name) """ raise NotImplementedError() def join_path(self, *path): """ Join path elements together :param path: path elements to join :return: joined representation of the path to be usable as fully qualified path for further operations """ raise NotImplementedError() def path_on_disk(self, path): """ Retrieves the path on disk for ``path``. Note: if the storage is not on disk and there exists no path on disk to refer to it, this method should raise an :class:`io.UnsupportedOperation` Opposite of :func:`path_in_storage`. :param string path: the virtual path for which to retrieve the path on disk :return: the path on disk to ``path`` """ raise NotImplementedError() def path_in_storage(self, path): """ Retrieves the equivalent in the storage adapter for ``path``. Opposite of :func:`path_on_disk`. :param string path: the path for which to retrieve the storage path :return: the path in storage to ``path`` """ raise NotImplementedError() class LocalFileStorage(StorageInterface): """ The ``LocalFileStorage`` is a storage implementation which holds all files, folders and metadata on disk. Metadata is managed inside ``.metadata.yaml`` files in the respective folders, indexed by the sanitized filenames stored within the folder. Metadata access is managed through an LRU cache to minimize access overhead. This storage type implements :func:`path_on_disk`. """ def __init__(self, basefolder, create=False): """ Initializes a ``LocalFileStorage`` instance under the given ``basefolder``, creating the necessary folder if necessary and ``create`` is set to ``True``. :param string basefolder: the path to the folder under which to create the storage :param bool create: ``True`` if the folder should be created if it doesn't exist yet, ``False`` otherwise """ self._logger = logging.getLogger(__name__) self.basefolder = os.path.realpath(os.path.abspath(basefolder)) if not os.path.exists(self.basefolder) and create: os.makedirs(self.basefolder) if not os.path.exists(self.basefolder) or not os.path.isdir(self.basefolder): raise RuntimeError("{basefolder} is not a valid directory".format(**locals())) import threading self._metadata_lock = threading.Lock() self._metadata_cache = pylru.lrucache(10) self._old_metadata = None self._initialize_metadata() def _initialize_metadata(self): self._logger.info("Initializing the file metadata for {}...".format(self.basefolder)) old_metadata_path = os.path.join(self.basefolder, "metadata.yaml") backup_path = os.path.join(self.basefolder, "metadata.yaml.backup") if os.path.exists(old_metadata_path): # load the old metadata file try: with open(old_metadata_path) as f: import yaml self._old_metadata = yaml.safe_load(f) except: self._logger.exception("Error while loading old metadata file") # make sure the metadata is initialized as far as possible self._list_folder(self.basefolder) # rename the old metadata file self._old_metadata = None try: import shutil shutil.move(old_metadata_path, backup_path) except: self._logger.exception("Could not rename old metadata.yaml file") else: # make sure the metadata is initialized as far as possible self._list_folder(self.basefolder) self._logger.info("... file metadata for {} initialized successfully.".format(self.basefolder)) @property def analysis_backlog(self): for entry in self._analysis_backlog_generator(): yield entry def _analysis_backlog_generator(self, path=None): if path is None: path = self.basefolder metadata = self._get_metadata(path) if not metadata: metadata = dict() for entry in os.listdir(path): if entry.startswith(".") or not octoprint.filemanager.valid_file_type(entry): continue absolute_path = os.path.join(path, entry) if os.path.isfile(absolute_path): if not entry in metadata or not isinstance(metadata[entry], dict) or not "analysis" in metadata[entry]: printer_profile_rels = self.get_link(absolute_path, "printerprofile") if printer_profile_rels: printer_profile_id = printer_profile_rels[0]["id"] else: printer_profile_id = None yield entry, absolute_path, printer_profile_id elif os.path.isdir(absolute_path): for sub_entry in self._analysis_backlog_generator(absolute_path): yield self.join_path(entry, sub_entry[0]), sub_entry[1], sub_entry[2] def file_exists(self, path): path, name = self.sanitize(path) file_path = os.path.join(path, name) return os.path.exists(file_path) and os.path.isfile(file_path) def list_files(self, path=None, filter=None, recursive=True): if path: path = self.sanitize_path(path) else: path = self.basefolder return self._list_folder(path, filter=filter, recursive=recursive) def add_folder(self, path, ignore_existing=True): path, name = self.sanitize(path) folder_path = os.path.join(path, name) if os.path.exists(folder_path): if not ignore_existing: raise RuntimeError("{sanitized_foldername} does already exist in {virtual_path}".format(**locals())) else: os.mkdir(folder_path) return self.path_in_storage((path, name)) def remove_folder(self, path, recursive=True): path, name = self.sanitize(path) folder_path = os.path.join(path, name) if not os.path.exists(folder_path): return contents = os.listdir(folder_path) if ".metadata.yaml" in contents: contents.remove(".metadata.yaml") if contents and not recursive: raise RuntimeError("{sanitized_foldername} in {virtual_path} is not empty".format(**locals())) import shutil shutil.rmtree(folder_path) def add_file(self, path, file_object, printer_profile=None, links=None, allow_overwrite=False): path, name = self.sanitize(path) if not octoprint.filemanager.valid_file_type(name): raise RuntimeError("{name} is an unrecognized file type".format(**locals())) metadata = self._get_metadata(path) if not metadata: metadata = dict() file_path = os.path.join(path, name) if os.path.exists(file_path) and not os.path.isfile(file_path): raise RuntimeError("{name} does already exist in {path} and is not a file".format(**locals())) if os.path.exists(file_path) and not allow_overwrite: raise RuntimeError("{name} does already exist in {path} and overwriting is prohibited".format(**locals())) # make sure folders exist if not os.path.exists(path): os.makedirs(path) # save the file file_object.save(file_path) # save the file's hash to the metadata of the folder file_hash = self._create_hash(file_path) if not name in metadata or not "hash" in metadata[name] or metadata[name]["hash"] != file_hash: # make sure to create a new metadata entry if we've never seen that file with that content before file_metadata = dict( hash=file_hash ) metadata[name] = file_metadata self._save_metadata(path, metadata) # process any links that were also provided for adding to the file if not links: links = [] if printer_profile is not None: links.append(("printerprofile", dict(id=printer_profile["id"], name=printer_profile["name"]))) self._add_links(name, path, links) # touch the file to set last access and modification time to now os.utime(file_path, None) return self.path_in_storage((path, name)) def remove_file(self, path): path, name = self.sanitize(path) metadata = self._get_metadata(path) file_path = os.path.join(path, name) if not os.path.exists(file_path): return if not os.path.isfile(file_path): raise RuntimeError("{name} in {path} is not a file".format(**locals())) try: os.remove(file_path) except Exception as e: raise RuntimeError("Could not delete {name} in {path}".format(**locals()), e) if name in metadata: if "hash" in metadata[name]: hash = metadata[name]["hash"] for m in metadata.values(): if not "links" in m: continue for link in m["links"]: if "rel" in link and "hash" in link and (link["rel"] == "model" or link["rel"] == "machinecode") and link["hash"] == hash: m["links"].remove(link) del metadata[name] self._save_metadata(path, metadata) def get_metadata(self, path): path, name = self.sanitize(path) metadata = self._get_metadata(path) if name in metadata: return metadata[name] else: return None def get_link(self, path, rel): path, name = self.sanitize(path) return self._get_links(name, path, rel) def add_link(self, path, rel, data): path, name = self.sanitize(path) self._add_links(name, path, [(rel, data)]) def remove_link(self, path, rel, data): path, name = self.sanitize(path) self._remove_links(name, path, [(rel, data)]) def add_history(self, path, data): path, name = self.sanitize(path) self._add_history(name, path, data) def update_history(self, path, index, data): path, name = self.sanitize(path) self._update_history(name, path, index, data) def remove_history(self, path, index): path, name = self.sanitize(path) self._update_history(name, path, index) def set_additional_metadata(self, path, key, data, overwrite=False, merge=False): path, name = self.sanitize(path) metadata = self._get_metadata(path) metadata_dirty = False if not name in metadata: return if not key in metadata[name] or overwrite: metadata[name][key] = data metadata_dirty = True elif key in metadata[name] and isinstance(metadata[name][key], dict) and isinstance(data, dict) and merge: current_data = metadata[name][key] import octoprint.util new_data = octoprint.util.dict_merge(current_data, data) metadata[name][key] = new_data metadata_dirty = True elif key in metadata[name] and overwrite: metadata[name][key] = data metadata_dirty = True if metadata_dirty: self._save_metadata(path, metadata) def remove_additional_metadata(self, path, key): path, name = self.sanitize(path) metadata = self._get_metadata(path) if not name in metadata: return if not key in metadata[name]: return del metadata[name][key] self._save_metadata(path, metadata) def split_path(self, path): split = path.split("/") if len(split) == 1: return "", split[0] else: return self.join_path(*split[:-1]), split[-1] def join_path(self, *path): return "/".join(path) def sanitize(self, path): """ Returns a ``(path, name)`` tuple derived from the provided ``path``. ``path`` may be: * a storage path * an absolute file system path * a tuple or list containing all individual path elements * a string representation of the path * with or without a file name Note that for a ``path`` without a trailing slash the last part will be considered a file name and hence be returned at second position. If you only need to convert a folder path, be sure to include a trailing slash for a string ``path`` or an empty last element for a list ``path``. Examples:: >>> storage = LocalFileStorage("/some/base/folder") >>> storage.sanitize("some/folder/and/some file.gco") ("/some/base/folder/some/folder/and", "some_file.gco") >>> storage.sanitize(("some", "folder", "and", "some file.gco")) ("/some/base/folder/some/folder/and", "some_file.gco") >>> storage.sanitize("some file.gco") ("/some/base/folder", "some_file.gco") >>> storage.sanitize(("some file.gco",)) ("/some/base/folder", "some_file.gco") >>> storage.sanitize("") ("/some/base/folder", "") >>> storage.sanitize("some/folder/with/trailing/slash/") ("/some/base/folder/some/folder/with/trailing/slash", "") >>> storage.sanitize("some", "folder", "") ("/some/base/folder/some/folder", "") """ name = None if isinstance(path, (str, unicode, basestring)): if path.startswith(self.basefolder): path = path[len(self.basefolder):] path = path.replace(os.path.sep, "/") path = path.split("/") if isinstance(path, (list, tuple)): if len(path) == 1: name = path[0] path = "/" else: name = path[-1] path = "/" + self.join_path(*path[:-1]) if not path: path = "/" name = self.sanitize_name(name) path = self.sanitize_path(path) return path, name def sanitize_name(self, name): """ Raises a :class:`ValueError` for a ``name`` containing ``/`` or ``\``. Otherwise strips any characters from the given ``name`` that are not any of the ASCII characters, digits, ``-``, ``_``, ``.``, ``(``, ``)`` or space and replaces and spaces with ``_``. Examples:: >>> storage = LocalFileStorage("/some/base/folder") >>> storage.sanitize_name("some_file.gco") "some_file.gco" >>> storage.sanitize_name("some_file with (parentheses) and ümläuts and digits 123.gco") "some_file_with_(parentheses)_and_mluts_and_digits_123.gco" >>> storage.sanitize_name("pengüino pequeño.stl") "pengino_pequeo.stl" >>> storage.sanitize_name("some/folder/still/left.gco") Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: name must not contain / or \ >>> storage.sanitize_name("also\\no\\backslashes.gco") Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: name must not contain / or \ """ if name is None: return None if "/" in name or "\\" in name: raise ValueError("name must not contain / or \\") import string valid_chars = "-_.() {ascii}{digits}".format(ascii=string.ascii_letters, digits=string.digits) sanitized_name = ''.join(c for c in name if c in valid_chars) sanitized_name = sanitized_name.replace(" ", "_") return sanitized_name def sanitize_path(self, path): """ Ensures that the on disk representation of ``path`` is located under the configured basefolder. Resolves all relative path elements (e.g. ``..``) and sanitizes folder names using :func:`sanitize_name`. Final path is the absolute path including leading ``basefolder`` path. Examples:: >>> storage = LocalFileStorage("/some/base/folder") >>> storage.sanitize_path("folder/with/subfolder") "/some/base/folder/folder/with/subfolder" >>> storage.sanitize_path("folder/with/subfolder/../other/folder") "/some/base/folder/folder/with/other/folder" >>> storage.sanitize_path("/folder/with/leading/slash") "/some/base/folder/folder/with/leading/slash" >>> storage.sanitize_path(".folder/with/leading/dot") "/some/base/folder/folder/with/leading/dot >>> storage.sanitize_path("../../folder/out/of/the/basefolder") Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: path not contained in base folder: /some/folder/out/of/the/basefolder """ if path[0] == "/" or path[0] == ".": path = path[1:] path_elements = path.split("/") joined_path = self.basefolder for path_element in path_elements: joined_path = os.path.join(joined_path, self.sanitize_name(path_element)) path = os.path.realpath(joined_path) if not path.startswith(self.basefolder): raise ValueError("path not contained in base folder: {path}".format(**locals())) return path def path_in_storage(self, path): if isinstance(path, (tuple, list)): path = self.join_path(*path) if isinstance(path, (str, unicode, basestring)): if path.startswith(self.basefolder): path = path[len(self.basefolder):] path = path.replace(os.path.sep, "/") if path.startswith("/"): path = path[1:] return path def path_on_disk(self, path): path, name = self.sanitize(path) return os.path.join(path, name) ##~~ internals def _add_history(self, name, path, data): metadata = self._get_metadata(path) if not name in metadata: metadata[name] = dict() if not "hash" in metadata[name]: metadata[name]["hash"] = self._create_hash(os.path.join(path, name)) if not "history" in metadata[name]: metadata[name]["history"] = [] metadata[name]["history"].append(data) self._calculate_stats_from_history(name, path, metadata=metadata, save=False) self._save_metadata(path, metadata) def _update_history(self, name, path, index, data): metadata = self._get_metadata(path) if not name in metadata or not "history" in metadata[name]: return try: metadata[name]["history"][index].update(data) self._calculate_stats_from_history(name, path, metadata=metadata, save=False) self._save_metadata(path, metadata) except IndexError: pass def _delete_history(self, name, path, index): metadata = self._get_metadata(path) if not name in metadata or not "history" in metadata[name]: return try: del metadata[name]["history"][index] self._calculate_stats_from_history(name, path, metadata=metadata, save=False) self._save_metadata(path, metadata) except IndexError: pass def _calculate_stats_from_history(self, name, path, metadata=None, save=True): if metadata is None: metadata = self._get_metadata(path) if not name in metadata or not "history" in metadata[name]: return # collect data from history former_print_times = dict() last_print = dict() for history_entry in metadata[name]["history"]: if not "printTime" in history_entry or not "success" in history_entry or not history_entry["success"] or not "printerProfile" in history_entry: continue printer_profile = history_entry["printerProfile"] print_time = history_entry["printTime"] if not printer_profile in former_print_times: former_print_times[printer_profile] = [] former_print_times[printer_profile].append(print_time) if not printer_profile in last_print or last_print[printer_profile] is None or ("timestamp" in history_entry and history_entry["timestamp"] > last_print[printer_profile]["timestamp"]): last_print[printer_profile] = history_entry # calculate stats statistics = dict(averagePrintTime=dict(), lastPrintTime=dict()) for printer_profile in former_print_times: if not former_print_times[printer_profile]: continue statistics["averagePrintTime"][printer_profile] = sum(former_print_times[printer_profile]) / float(len(former_print_times[printer_profile])) for printer_profile in last_print: if not last_print[printer_profile]: continue statistics["lastPrintTime"][printer_profile] = last_print[printer_profile]["printTime"] metadata[name]["statistics"] = statistics if save: self._save_metadata(path, metadata) def _get_links(self, name, path, searched_rel): metadata = self._get_metadata(path) result = [] if not name in metadata: return result if not "links" in metadata[name]: return result for data in metadata[name]["links"]: if not "rel" in data or not data["rel"] == searched_rel: continue result.append(data) return result def _add_links(self, name, path, links): file_type = octoprint.filemanager.get_file_type(name) if file_type: file_type = file_type[0] metadata = self._get_metadata(path) metadata_dirty = False if not name in metadata: metadata[name] = dict() if not "hash" in metadata[name]: metadata[name]["hash"] = self._create_hash(os.path.join(path, name)) if not "links" in metadata[name]: metadata[name]["links"] = [] for rel, data in links: if (rel == "model" or rel == "machinecode") and "name" in data: if file_type == "model" and rel == "model": # adding a model link to a model doesn't make sense return elif file_type == "machinecode" and rel == "machinecode": # adding a machinecode link to a machinecode doesn't make sense return ref_path = os.path.join(path, data["name"]) if not os.path.exists(ref_path): # file doesn't exist, we won't create the link continue # fetch hash of target file if data["name"] in metadata and "hash" in metadata[data["name"]]: hash = metadata[data["name"]]["hash"] else: hash = self._create_hash(ref_path) if not data["name"] in metadata: metadata[data["name"]] = dict( hash=hash, links=[] ) else: metadata[data["name"]]["hash"] = hash if "hash" in data and not data["hash"] == hash: # file doesn't have the correct hash, we won't create the link continue if not "links" in metadata[data["name"]]: metadata[data["name"]]["links"] = [] # add reverse link to link target file metadata[data["name"]]["links"].append( dict(rel="machinecode" if rel == "model" else "model", name=name, hash=metadata[name]["hash"]) ) metadata_dirty = True link_dict = dict( rel=rel, name=data["name"], hash=hash ) elif rel == "web" and "href" in data: link_dict = dict( rel=rel, href=data["href"] ) if "retrieved" in data: link_dict["retrieved"] = data["retrieved"] else: continue if link_dict: metadata[name]["links"].append(link_dict) metadata_dirty = True if metadata_dirty: self._save_metadata(path, metadata) def _remove_links(self, name, path, links): metadata = self._get_metadata(path) metadata_dirty = False if not name in metadata or not "hash" in metadata[name]: hash = self._create_hash(os.path.join(path, name)) else: hash = metadata[name]["hash"] for rel, data in links: if (rel == "model" or rel == "machinecode") and "name" in data: if data["name"] in metadata and "links" in metadata[data["name"]]: ref_rel = "model" if rel == "machinecode" else "machinecode" for link in metadata[data["name"]]["links"]: if link["rel"] == ref_rel and "name" in link and link["name"] == name and "hash" in link and link["hash"] == hash: metadata[data["name"]]["links"].remove(link) metadata_dirty = True if "links" in metadata[name]: for link in metadata[name]["links"]: if not link["rel"] == rel: continue matches = True for k, v in data.items(): if not k in link or not link[k] == v: matches = False break if not matches: continue metadata[name]["links"].remove(link) metadata_dirty = True if metadata_dirty: self._save_metadata(path, metadata) def _list_folder(self, path, filter=None, recursive=True): metadata = self._get_metadata(path) if not metadata: metadata = dict() metadata_dirty = False result = dict() for entry in os.listdir(path): if entry.startswith("."): # no hidden files and folders continue entry_path = os.path.join(path, entry) # file handling if os.path.isfile(entry_path): file_type = octoprint.filemanager.get_file_type(entry) if not file_type: # only supported extensions continue else: file_type = file_type[0] if entry in metadata and isinstance(metadata[entry], dict): entry_data = metadata[entry] else: entry_data = self._add_basic_metadata(path, entry, save=False, metadata=metadata) metadata_dirty = True # TODO extract model hash from source if possible to recreate link if not filter or filter(entry, entry_data): # only add files passing the optional filter extended_entry_data = dict() extended_entry_data.update(entry_data) extended_entry_data["name"] = entry extended_entry_data["type"] = file_type stat = os.stat(entry_path) if stat: extended_entry_data["size"] = stat.st_size extended_entry_data["date"] = int(stat.st_mtime) result[entry] = extended_entry_data # folder recursion elif os.path.isdir(entry_path) and recursive: sub_result = self._list_folder(entry_path, filter=filter) result[entry] = dict( name=entry, type="folder", children=sub_result ) # TODO recreate links if we have metadata less entries # save metadata if metadata_dirty: self._save_metadata(path, metadata) return result def _add_basic_metadata(self, path, entry, additional_metadata=None, save=True, metadata=None): if additional_metadata is None: additional_metadata = dict() if metadata is None: metadata = self._get_metadata(path) entry_data = dict( hash=self._create_hash(os.path.join(path, entry)), links=[], notes=[] ) if path == self.basefolder and self._old_metadata is not None and entry in self._old_metadata and "gcodeAnalysis" in self._old_metadata[entry]: # if there is still old metadata available and that contains an analysis for this file, use it! entry_data["analysis"] = self._old_metadata[entry]["gcodeAnalysis"] entry_data.update(additional_metadata) metadata[entry] = entry_data if save: self._save_metadata(path, metadata) return entry_data def _create_hash(self, path): import hashlib blocksize = 65536 hash = hashlib.sha1() with open(path, "rb") as f: buffer = f.read(blocksize) while len(buffer) > 0: hash.update(buffer) buffer = f.read(blocksize) return hash.hexdigest() def _get_metadata(self, path): if path in self._metadata_cache: return self._metadata_cache[path] metadata_path = os.path.join(path, ".metadata.yaml") if os.path.exists(metadata_path): with self._metadata_lock: with open(metadata_path) as f: try: import yaml metadata = yaml.safe_load(f) except: self._logger.exception("Error while reading .metadata.yaml from {path}".format(**locals())) else: self._metadata_cache[path] = metadata return metadata return dict() def _save_metadata(self, path, metadata): metadata_path = os.path.join(path, ".metadata.yaml") with self._metadata_lock: try: import yaml import shutil file_obj = tempfile.NamedTemporaryFile(delete=False) try: yaml.safe_dump(metadata, stream=file_obj, default_flow_style=False, indent=" ", allow_unicode=True) file_obj.close() shutil.move(file_obj.name, metadata_path) finally: try: if os.path.exists(file_obj.name): os.remove(file_obj.name) except Exception as e: self._logger.warn("Could not delete file {}: {}".format(file_obj.name, str(e))) except: self._logger.exception("Error while writing .metadata.yaml to {path}".format(**locals())) else: self._metadata_cache[path] = metadata
agpl-3.0
[ 3, 2803, 29, 1624, 13, 24, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 363, 2502, 363, 275, 298, 39, 13765, 869, 13733, 85, 128, 254, 303, 665, 736, 68, 32, 1421, 5891, 14, 846, 4335, 199, 363, 1682, 363, 275, 283, 17732, 4265, 1696, 1684, 844, 1455, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 643, 1168, 14, 1360, 7, 199, 363, 7307, 363, 275, 298, 7384, 334, 35, 9, 6927, 710, 18365, 79, 5375, 7290, 446, 17646, 68, 1334, 2895, 402, 314, 437, 28863, 19, 844, 2, 421, 199, 646, 2050, 199, 646, 747, 199, 646, 1134, 25003, 199, 646, 5549, 199, 199, 646, 17162, 411, 672, 14, 493, 2609, 199, 199, 533, 10533, 4267, 8, 785, 304, 199, 198, 624, 199, 198, 4267, 402, 4887, 1503, 12552, 367, 18365, 79, 5375, 14, 199, 198, 624, 4388, 198, 32, 1829, 199, 198, 318, 11284, 63, 31267, 8, 277, 304, 507, 198, 624, 507, 198, 1002, 376, 6122, 1806, 1006, 2974, 5489, 315, 314, 4887, 626, 1929, 370, 506, 5909, 939, 701, 314, 520, 533, 6054, 15560, 411, 672, 14, 493, 2609, 14, 13182, 3737, 2313, 2742, 198, 1918, 28653, 4008, 787, 1420, 465, 4887, 2488, 3679, 3792, 370, 314, 26820, 1584, 14, 7529, 1133, 19459, 507, 198, 475, 18011, 1901, 16533, 340, 2195, 4887, 12146, 5171, 5204, 14, 2742, 198, 26, 1107, 26, 376, 6122, 32035, 1006, 625, 13, 4797, 939, 1584, 315, 314, 4887, 507, 198, 624, 507, 198, 3, 2701, 4306, 3851, 12, 1995, 365, 32005, 625, 15837, 507, 198, 1107, 507, 198, 11481, 421, 198, 318, 570, 63, 2444, 8, 277, 12, 931, 304, 507, 198, 624, 507, 198, 3407, 3775, 314, 570, 22141, 701, 1124, 515, 1040, 3495, 503, 440, 14, 507, 198, 26, 635, 1059, 931, 26, 314, 931, 370, 1104, 367, 23780, 507, 198, 26, 1107, 26, 1124, 549, 1040, 340, 314, 570, 3495, 12, 1124, 797, 1040, 4257, 507, 198, 624, 507, 198, 3730, 4279, 342, 421, 198, 318, 769, 63, 1725, 8, 277, 12, 931, 29, 403, 12, 2457, 29, 403, 12, 9133, 29, 549, 304, 507, 198, 624, 507, 198, 1296, 1006, 1584, 315, 4887, 6617, 737, 1124, 515, 4345, 982, 1124, 9931, 1040, 365, 663, 370, 715, 334, 1589, 849, 395, 2597, 487, 2310, 1901, 507, 198, 954, 15171, 14, 2742, 198, 2493, 2716, 2457, 805, 883, 506, 6841, 1314, 911, 506, 2797, 543, 282, 570, 536, 436, 570, 666, 436, 1314, 965, 507, 198, 475, 372, 715, 340, 314, 570, 365, 370, 506, 5120, 315, 314, 754, 503, 756, 340, 440, 14, 2742, 198, 1918, 666, 5523, 402, 314, 2138, 754, 911, 506, 282, 2600, 4412, 687, 570, 1561, 370, 2397, 666, 14, 3814, 3380, 507, 198, 14117, 1395, 3932, 3341, 2348, 12, 4922, 3380, 911, 1395, 3932, 10470, 1584, 436, 16533, 14, 5679, 447, 6319, 257, 469, 686, 258, 298, 3972, 63, 3741, 582, 469, 686, 755, 298, 466, 582, 298, 3741, 401, 686, 755, 298, 3223, 582, 469, 686, 260, 298, 3972, 63, 954, 63, 3741, 582, 469, 686, 3698, 298, 466, 582, 298, 3741, 401, 686, 3698, 298, 3223, 582, 469, 2263, 789, 686, 260, 1660, 686, 260, 298, 3972, 63, 493, 14, 71, 600, 582, 469, 686, 3698, 298, 466, 582, 298, 6744, 600, 401, 686, 3698, 298, 2227, 582, 3886, 4835, 17, 2631, 7166, 686, 3698, 298, 4614, 582, 359, 2263, 2156, 686, 3698, 2263, 686, 260, 1660, 686, 260, 2263, 686, 755, 789, 686, 258, 298, 396, 14, 71, 600, 582, 469, 686, 755, 298, 466, 582, 298, 6744, 600, 401, 686, 755, 298, 2227, 582, 3886, 4835, 17, 2631, 7166, 686, 755, 298, 4614, 582, 359, 1396, 467, 686, 755, 2263, 686, 258, 1660, 686, 258, 298, 396, 14, 270, 76, 582, 469, 686, 755, 298, 466, 582, 298, 1238, 401, 686, 755, 298, 2227, 582, 3886, 4835, 17, 2631, 7166, 686, 755, 298, 4614, 582, 359, 1396, 467, 686, 755, 2263, 686, 258, 1660, 686, 258, 2263, 686, 257, 789, 2742, 198, 26, 635, 1059, 931, 26, 258, 1300, 931, 687, 1314, 370, 15035, 769, 1006, 1584, 12, 2716, 12, 340, 440, 6841, 13778, 911, 1343, 686, 12788, 687, 1738, 402, 1300, 4922, 507, 198, 26, 635, 805, 2457, 26, 282, 2457, 626, 4450, 314, 1584, 626, 787, 370, 506, 2138, 12, 1443, 506, 3602, 734, 315, 1314, 1930, 949, 686, 12788, 14545, 911, 5452, 4192, 507, 198, 26, 635, 2155, 9133, 26, 221, 911, 2597, 3650, 1901, 1007, 16533, 367, 10015, 314, 4890, 769, 340, 663, 370, 715, 507, 198, 26, 1107, 26, 282, 2600, 4412, 2397, 1561, 370, 2397, 666, 626, 8469, 314, 8852, 570, 769, 507, 198, 624, 507, 198, 3730, 4279, 342, 421, 198, 318, 1050, 63, 3741, 8, 277, 12, 931, 12, 3686, 63, 5952, 29, 549, 304, 507, 198, 624, 507, 198, 14995, 282, 4922, 465, 1124, 515, 4345, 710, 1124, 515, 1040, 911, 506, 31734, 14, 2742, 198, 26, 635, 1059, 931, 26, 3515, 314, 931, 402, 314, 892, 4922, 507, 198, 26, 635, 2155, 3686, 63, 5952, 26, 340, 663, 370, 715, 12, 949, 1125, 911, 506, 4915, 340, 314, 4922, 370, 506, 3483, 2575, 3495, 507, 198, 26, 1107, 26, 314, 31734, 536, 402, 314, 892, 4922, 370, 506, 1202, 367, 6466, 6941, 370, 314, 4922, 507, 198, 624, 507, 198, 3730, 4279, 342, 421, 198, 318, 2813, 63, 3741, 8, 277, 12, 931, 12, 9133, 29, 549, 304, 507, 198, 624, 507, 198, 22948, 314, 4922, 737, 1124, 515, 4345, 2742, 198, 26, 635, 1059, 931, 26, 259, 314, 931, 402, 314, 4922, 370, 2813, 507, 198, 26, 635, 2155, 9133, 26, 340, 663, 370, 715, 12, 10470, 16533, 436, 1584, 911, 2597, 506, 4829, 12, 4257, 436, 1125, 911, 686, 9668, 506, 4915, 340, 314, 4922, 365, 440, 2701, 334, 439, 580, 687, 21502, 2343, 14, 5963, 16580, 1380, 652, 1159, 370, 506, 4829, 507, 198, 624, 507, 198, 3730, 4279, 342, 421, 198, 318, 1050, 63, 493, 8, 277, 12, 931, 12, 570, 63, 785, 12, 16639, 63, 2913, 29, 403, 12, 6220, 29, 403, 12, 2040, 63, 14658, 29, 797, 304, 507, 198, 624, 507, 198 ]
[ 2803, 29, 1624, 13, 24, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 363, 2502, 363, 275, 298, 39, 13765, 869, 13733, 85, 128, 254, 303, 665, 736, 68, 32, 1421, 5891, 14, 846, 4335, 199, 363, 1682, 363, 275, 283, 17732, 4265, 1696, 1684, 844, 1455, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 643, 1168, 14, 1360, 7, 199, 363, 7307, 363, 275, 298, 7384, 334, 35, 9, 6927, 710, 18365, 79, 5375, 7290, 446, 17646, 68, 1334, 2895, 402, 314, 437, 28863, 19, 844, 2, 421, 199, 646, 2050, 199, 646, 747, 199, 646, 1134, 25003, 199, 646, 5549, 199, 199, 646, 17162, 411, 672, 14, 493, 2609, 199, 199, 533, 10533, 4267, 8, 785, 304, 199, 198, 624, 199, 198, 4267, 402, 4887, 1503, 12552, 367, 18365, 79, 5375, 14, 199, 198, 624, 4388, 198, 32, 1829, 199, 198, 318, 11284, 63, 31267, 8, 277, 304, 507, 198, 624, 507, 198, 1002, 376, 6122, 1806, 1006, 2974, 5489, 315, 314, 4887, 626, 1929, 370, 506, 5909, 939, 701, 314, 520, 533, 6054, 15560, 411, 672, 14, 493, 2609, 14, 13182, 3737, 2313, 2742, 198, 1918, 28653, 4008, 787, 1420, 465, 4887, 2488, 3679, 3792, 370, 314, 26820, 1584, 14, 7529, 1133, 19459, 507, 198, 475, 18011, 1901, 16533, 340, 2195, 4887, 12146, 5171, 5204, 14, 2742, 198, 26, 1107, 26, 376, 6122, 32035, 1006, 625, 13, 4797, 939, 1584, 315, 314, 4887, 507, 198, 624, 507, 198, 3, 2701, 4306, 3851, 12, 1995, 365, 32005, 625, 15837, 507, 198, 1107, 507, 198, 11481, 421, 198, 318, 570, 63, 2444, 8, 277, 12, 931, 304, 507, 198, 624, 507, 198, 3407, 3775, 314, 570, 22141, 701, 1124, 515, 1040, 3495, 503, 440, 14, 507, 198, 26, 635, 1059, 931, 26, 314, 931, 370, 1104, 367, 23780, 507, 198, 26, 1107, 26, 1124, 549, 1040, 340, 314, 570, 3495, 12, 1124, 797, 1040, 4257, 507, 198, 624, 507, 198, 3730, 4279, 342, 421, 198, 318, 769, 63, 1725, 8, 277, 12, 931, 29, 403, 12, 2457, 29, 403, 12, 9133, 29, 549, 304, 507, 198, 624, 507, 198, 1296, 1006, 1584, 315, 4887, 6617, 737, 1124, 515, 4345, 982, 1124, 9931, 1040, 365, 663, 370, 715, 334, 1589, 849, 395, 2597, 487, 2310, 1901, 507, 198, 954, 15171, 14, 2742, 198, 2493, 2716, 2457, 805, 883, 506, 6841, 1314, 911, 506, 2797, 543, 282, 570, 536, 436, 570, 666, 436, 1314, 965, 507, 198, 475, 372, 715, 340, 314, 570, 365, 370, 506, 5120, 315, 314, 754, 503, 756, 340, 440, 14, 2742, 198, 1918, 666, 5523, 402, 314, 2138, 754, 911, 506, 282, 2600, 4412, 687, 570, 1561, 370, 2397, 666, 14, 3814, 3380, 507, 198, 14117, 1395, 3932, 3341, 2348, 12, 4922, 3380, 911, 1395, 3932, 10470, 1584, 436, 16533, 14, 5679, 447, 6319, 257, 469, 686, 258, 298, 3972, 63, 3741, 582, 469, 686, 755, 298, 466, 582, 298, 3741, 401, 686, 755, 298, 3223, 582, 469, 686, 260, 298, 3972, 63, 954, 63, 3741, 582, 469, 686, 3698, 298, 466, 582, 298, 3741, 401, 686, 3698, 298, 3223, 582, 469, 2263, 789, 686, 260, 1660, 686, 260, 298, 3972, 63, 493, 14, 71, 600, 582, 469, 686, 3698, 298, 466, 582, 298, 6744, 600, 401, 686, 3698, 298, 2227, 582, 3886, 4835, 17, 2631, 7166, 686, 3698, 298, 4614, 582, 359, 2263, 2156, 686, 3698, 2263, 686, 260, 1660, 686, 260, 2263, 686, 755, 789, 686, 258, 298, 396, 14, 71, 600, 582, 469, 686, 755, 298, 466, 582, 298, 6744, 600, 401, 686, 755, 298, 2227, 582, 3886, 4835, 17, 2631, 7166, 686, 755, 298, 4614, 582, 359, 1396, 467, 686, 755, 2263, 686, 258, 1660, 686, 258, 298, 396, 14, 270, 76, 582, 469, 686, 755, 298, 466, 582, 298, 1238, 401, 686, 755, 298, 2227, 582, 3886, 4835, 17, 2631, 7166, 686, 755, 298, 4614, 582, 359, 1396, 467, 686, 755, 2263, 686, 258, 1660, 686, 258, 2263, 686, 257, 789, 2742, 198, 26, 635, 1059, 931, 26, 258, 1300, 931, 687, 1314, 370, 15035, 769, 1006, 1584, 12, 2716, 12, 340, 440, 6841, 13778, 911, 1343, 686, 12788, 687, 1738, 402, 1300, 4922, 507, 198, 26, 635, 805, 2457, 26, 282, 2457, 626, 4450, 314, 1584, 626, 787, 370, 506, 2138, 12, 1443, 506, 3602, 734, 315, 1314, 1930, 949, 686, 12788, 14545, 911, 5452, 4192, 507, 198, 26, 635, 2155, 9133, 26, 221, 911, 2597, 3650, 1901, 1007, 16533, 367, 10015, 314, 4890, 769, 340, 663, 370, 715, 507, 198, 26, 1107, 26, 282, 2600, 4412, 2397, 1561, 370, 2397, 666, 626, 8469, 314, 8852, 570, 769, 507, 198, 624, 507, 198, 3730, 4279, 342, 421, 198, 318, 1050, 63, 3741, 8, 277, 12, 931, 12, 3686, 63, 5952, 29, 549, 304, 507, 198, 624, 507, 198, 14995, 282, 4922, 465, 1124, 515, 4345, 710, 1124, 515, 1040, 911, 506, 31734, 14, 2742, 198, 26, 635, 1059, 931, 26, 3515, 314, 931, 402, 314, 892, 4922, 507, 198, 26, 635, 2155, 3686, 63, 5952, 26, 340, 663, 370, 715, 12, 949, 1125, 911, 506, 4915, 340, 314, 4922, 370, 506, 3483, 2575, 3495, 507, 198, 26, 1107, 26, 314, 31734, 536, 402, 314, 892, 4922, 370, 506, 1202, 367, 6466, 6941, 370, 314, 4922, 507, 198, 624, 507, 198, 3730, 4279, 342, 421, 198, 318, 2813, 63, 3741, 8, 277, 12, 931, 12, 9133, 29, 549, 304, 507, 198, 624, 507, 198, 22948, 314, 4922, 737, 1124, 515, 4345, 2742, 198, 26, 635, 1059, 931, 26, 259, 314, 931, 402, 314, 4922, 370, 2813, 507, 198, 26, 635, 2155, 9133, 26, 340, 663, 370, 715, 12, 10470, 16533, 436, 1584, 911, 2597, 506, 4829, 12, 4257, 436, 1125, 911, 686, 9668, 506, 4915, 340, 314, 4922, 365, 440, 2701, 334, 439, 580, 687, 21502, 2343, 14, 5963, 16580, 1380, 652, 1159, 370, 506, 4829, 507, 198, 624, 507, 198, 3730, 4279, 342, 421, 198, 318, 1050, 63, 493, 8, 277, 12, 931, 12, 570, 63, 785, 12, 16639, 63, 2913, 29, 403, 12, 6220, 29, 403, 12, 2040, 63, 14658, 29, 797, 304, 507, 198, 624, 507, 198, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
MotorolaMobilityLLC/external-chromium_org
third_party/tlslite/tlslite/utils/dateFuncs.py
407
2181
import os #Functions for manipulating datetime objects #CCYY-MM-DDThh:mm:ssZ def parseDateClass(s): year, month, day = s.split("-") day, tail = day[:2], day[2:] hour, minute, second = tail[1:].split(":") second = second[:2] year, month, day = int(year), int(month), int(day) hour, minute, second = int(hour), int(minute), int(second) return createDateClass(year, month, day, hour, minute, second) if os.name != "java": from datetime import datetime, timedelta #Helper functions for working with a date/time class def createDateClass(year, month, day, hour, minute, second): return datetime(year, month, day, hour, minute, second) def printDateClass(d): #Split off fractional seconds, append 'Z' return d.isoformat().split(".")[0]+"Z" def getNow(): return datetime.utcnow() def getHoursFromNow(hours): return datetime.utcnow() + timedelta(hours=hours) def getMinutesFromNow(minutes): return datetime.utcnow() + timedelta(minutes=minutes) def isDateClassExpired(d): return d < datetime.utcnow() def isDateClassBefore(d1, d2): return d1 < d2 else: #Jython 2.1 is missing lots of python 2.3 stuff, #which we have to emulate here: import java import jarray def createDateClass(year, month, day, hour, minute, second): c = java.util.Calendar.getInstance() c.setTimeZone(java.util.TimeZone.getTimeZone("UTC")) c.set(year, month-1, day, hour, minute, second) return c def printDateClass(d): return "%04d-%02d-%02dT%02d:%02d:%02dZ" % \ (d.get(d.YEAR), d.get(d.MONTH)+1, d.get(d.DATE), \ d.get(d.HOUR_OF_DAY), d.get(d.MINUTE), d.get(d.SECOND)) def getNow(): c = java.util.Calendar.getInstance() c.setTimeZone(java.util.TimeZone.getTimeZone("UTC")) c.get(c.HOUR) #force refresh? return c def getHoursFromNow(hours): d = getNow() d.add(d.HOUR, hours) return d def isDateClassExpired(d): n = getNow() return d.before(n) def isDateClassBefore(d1, d2): return d1.before(d2)
bsd-3-clause
[ 199, 646, 747, 199, 199, 3, 13967, 367, 13335, 20529, 2197, 2251, 199, 3, 2571, 7080, 13, 3218, 13, 5745, 2719, 72, 26, 596, 26, 385, 58, 199, 318, 2198, 2506, 2543, 8, 83, 304, 272, 5361, 12, 5794, 12, 5382, 275, 308, 14, 1294, 6096, 531, 272, 5382, 12, 9483, 275, 5382, 1491, 18, 467, 5382, 59, 18, 2938, 272, 6925, 12, 12709, 12, 3499, 275, 9483, 59, 17, 11455, 1294, 20063, 272, 3499, 275, 3499, 1491, 18, 61, 272, 5361, 12, 5794, 12, 5382, 275, 1109, 8, 3403, 395, 1109, 8, 4482, 395, 1109, 8, 2977, 9, 272, 6925, 12, 12709, 12, 3499, 275, 1109, 8, 5180, 395, 1109, 8, 10698, 395, 1109, 8, 4375, 9, 272, 372, 1218, 2506, 2543, 8, 3403, 12, 5794, 12, 5382, 12, 6925, 12, 12709, 12, 3499, 9, 421, 199, 692, 747, 14, 354, 1137, 298, 6138, 582, 272, 687, 2197, 492, 2197, 12, 6871, 339, 327, 4433, 3423, 367, 6449, 543, 282, 1434, 15, 521, 1021, 272, 347, 1218, 2506, 2543, 8, 3403, 12, 5794, 12, 5382, 12, 6925, 12, 12709, 12, 3499, 304, 267, 372, 2197, 8, 3403, 12, 5794, 12, 5382, 12, 6925, 12, 12709, 12, 3499, 9, 339, 347, 870, 2506, 2543, 8, 68, 304, 267, 327, 8862, 2331, 27487, 4696, 12, 5666, 283, 58, 7, 267, 372, 366, 14, 17070, 1252, 1294, 15857, 59, 16, 2807, 2, 58, 2, 339, 347, 664, 14351, 837, 267, 372, 2197, 14, 10779, 342, 339, 347, 664, 30927, 2532, 14351, 8, 8419, 304, 267, 372, 2197, 14, 10779, 342, 435, 6871, 8, 8419, 29, 8419, 9, 339, 347, 664, 4649, 3862, 2532, 14351, 8, 10430, 304, 267, 372, 2197, 14, 10779, 342, 435, 6871, 8, 10430, 29, 10430, 9, 339, 347, 365, 2506, 2543, 20898, 8, 68, 304, 267, 372, 366, 665, 2197, 14, 10779, 342, 339, 347, 365, 2506, 2543, 13569, 8, 68, 17, 12, 366, 18, 304, 267, 372, 366, 17, 665, 366, 18, 199, 199, 2836, 26, 272, 327, 42, 11361, 499, 14, 17, 365, 4124, 24213, 402, 2366, 499, 14, 19, 8292, 12, 272, 327, 6777, 781, 1172, 370, 31102, 2348, 26, 272, 492, 12120, 272, 492, 1335, 1144, 339, 347, 1218, 2506, 2543, 8, 3403, 12, 5794, 12, 5382, 12, 6925, 12, 12709, 12, 3499, 304, 267, 286, 275, 12120, 14, 1974, 14, 18688, 14, 29964, 342, 267, 286, 14, 409, 32515, 8, 6138, 14, 1974, 14, 32515, 14, 362, 32515, 480, 11288, 2237, 267, 286, 14, 409, 8, 3403, 12, 5794, 13, 17, 12, 5382, 12, 6925, 12, 12709, 12, 3499, 9, 267, 372, 286, 339, 347, 870, 2506, 2543, 8, 68, 304, 267, 372, 2071, 966, 68, 3295, 996, 68, 3295, 996, 19772, 5, 996, 68, 2689, 996, 68, 2689, 996, 68, 58, 2, 450, 971, 267, 334, 68, 14, 362, 8, 68, 14, 19216, 395, 366, 14, 362, 8, 68, 14, 16413, 6393, 17, 12, 366, 14, 362, 8, 68, 14, 5390, 395, 971, 267, 366, 14, 362, 8, 68, 14, 2979, 1230, 63, 3359, 63, 11655, 395, 366, 14, 362, 8, 68, 14, 4896, 4586, 395, 366, 14, 362, 8, 68, 14, 24236, 430, 339, 347, 664, 14351, 837, 267, 286, 275, 12120, 14, 1974, 14, 18688, 14, 29964, 342, 267, 286, 14, 409, 32515, 8, 6138, 14, 1974, 14, 32515, 14, 362, 32515, 480, 11288, 2237, 267, 286, 14, 362, 8, 67, 14, 2979, 1230, 9, 327, 3990, 9236, 31, 267, 372, 286, 339, 347, 664, 30927, 2532, 14351, 8, 8419, 304, 267, 366, 275, 664, 14351, 342, 267, 366, 14, 525, 8, 68, 14, 2979, 1230, 12, 10857, 9, 267, 372, 366, 339, 347, 365, 2506, 2543, 20898, 8, 68, 304, 267, 302, 275, 664, 14351, 342, 267, 372, 366, 14, 5182, 8, 78, 9, 339, 347, 365, 2506, 2543, 13569, 8, 68, 17, 12, 366, 18, 304, 267, 372, 366, 17, 14, 5182, 8, 68, 18, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 646, 747, 199, 199, 3, 13967, 367, 13335, 20529, 2197, 2251, 199, 3, 2571, 7080, 13, 3218, 13, 5745, 2719, 72, 26, 596, 26, 385, 58, 199, 318, 2198, 2506, 2543, 8, 83, 304, 272, 5361, 12, 5794, 12, 5382, 275, 308, 14, 1294, 6096, 531, 272, 5382, 12, 9483, 275, 5382, 1491, 18, 467, 5382, 59, 18, 2938, 272, 6925, 12, 12709, 12, 3499, 275, 9483, 59, 17, 11455, 1294, 20063, 272, 3499, 275, 3499, 1491, 18, 61, 272, 5361, 12, 5794, 12, 5382, 275, 1109, 8, 3403, 395, 1109, 8, 4482, 395, 1109, 8, 2977, 9, 272, 6925, 12, 12709, 12, 3499, 275, 1109, 8, 5180, 395, 1109, 8, 10698, 395, 1109, 8, 4375, 9, 272, 372, 1218, 2506, 2543, 8, 3403, 12, 5794, 12, 5382, 12, 6925, 12, 12709, 12, 3499, 9, 421, 199, 692, 747, 14, 354, 1137, 298, 6138, 582, 272, 687, 2197, 492, 2197, 12, 6871, 339, 327, 4433, 3423, 367, 6449, 543, 282, 1434, 15, 521, 1021, 272, 347, 1218, 2506, 2543, 8, 3403, 12, 5794, 12, 5382, 12, 6925, 12, 12709, 12, 3499, 304, 267, 372, 2197, 8, 3403, 12, 5794, 12, 5382, 12, 6925, 12, 12709, 12, 3499, 9, 339, 347, 870, 2506, 2543, 8, 68, 304, 267, 327, 8862, 2331, 27487, 4696, 12, 5666, 283, 58, 7, 267, 372, 366, 14, 17070, 1252, 1294, 15857, 59, 16, 2807, 2, 58, 2, 339, 347, 664, 14351, 837, 267, 372, 2197, 14, 10779, 342, 339, 347, 664, 30927, 2532, 14351, 8, 8419, 304, 267, 372, 2197, 14, 10779, 342, 435, 6871, 8, 8419, 29, 8419, 9, 339, 347, 664, 4649, 3862, 2532, 14351, 8, 10430, 304, 267, 372, 2197, 14, 10779, 342, 435, 6871, 8, 10430, 29, 10430, 9, 339, 347, 365, 2506, 2543, 20898, 8, 68, 304, 267, 372, 366, 665, 2197, 14, 10779, 342, 339, 347, 365, 2506, 2543, 13569, 8, 68, 17, 12, 366, 18, 304, 267, 372, 366, 17, 665, 366, 18, 199, 199, 2836, 26, 272, 327, 42, 11361, 499, 14, 17, 365, 4124, 24213, 402, 2366, 499, 14, 19, 8292, 12, 272, 327, 6777, 781, 1172, 370, 31102, 2348, 26, 272, 492, 12120, 272, 492, 1335, 1144, 339, 347, 1218, 2506, 2543, 8, 3403, 12, 5794, 12, 5382, 12, 6925, 12, 12709, 12, 3499, 304, 267, 286, 275, 12120, 14, 1974, 14, 18688, 14, 29964, 342, 267, 286, 14, 409, 32515, 8, 6138, 14, 1974, 14, 32515, 14, 362, 32515, 480, 11288, 2237, 267, 286, 14, 409, 8, 3403, 12, 5794, 13, 17, 12, 5382, 12, 6925, 12, 12709, 12, 3499, 9, 267, 372, 286, 339, 347, 870, 2506, 2543, 8, 68, 304, 267, 372, 2071, 966, 68, 3295, 996, 68, 3295, 996, 19772, 5, 996, 68, 2689, 996, 68, 2689, 996, 68, 58, 2, 450, 971, 267, 334, 68, 14, 362, 8, 68, 14, 19216, 395, 366, 14, 362, 8, 68, 14, 16413, 6393, 17, 12, 366, 14, 362, 8, 68, 14, 5390, 395, 971, 267, 366, 14, 362, 8, 68, 14, 2979, 1230, 63, 3359, 63, 11655, 395, 366, 14, 362, 8, 68, 14, 4896, 4586, 395, 366, 14, 362, 8, 68, 14, 24236, 430, 339, 347, 664, 14351, 837, 267, 286, 275, 12120, 14, 1974, 14, 18688, 14, 29964, 342, 267, 286, 14, 409, 32515, 8, 6138, 14, 1974, 14, 32515, 14, 362, 32515, 480, 11288, 2237, 267, 286, 14, 362, 8, 67, 14, 2979, 1230, 9, 327, 3990, 9236, 31, 267, 372, 286, 339, 347, 664, 30927, 2532, 14351, 8, 8419, 304, 267, 366, 275, 664, 14351, 342, 267, 366, 14, 525, 8, 68, 14, 2979, 1230, 12, 10857, 9, 267, 372, 366, 339, 347, 365, 2506, 2543, 20898, 8, 68, 304, 267, 302, 275, 664, 14351, 342, 267, 372, 366, 14, 5182, 8, 78, 9, 339, 347, 365, 2506, 2543, 13569, 8, 68, 17, 12, 366, 18, 304, 267, 372, 366, 17, 14, 5182, 8, 68, 18, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
ewindisch/nova
tools/xenserver/vdi_chain_cleanup.py
139
3678
#!/usr/bin/env python # Copyright 2012 OpenStack Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ This script is designed to cleanup any VHDs (and their descendents) which have a bad parent pointer. The script needs to be run in the dom0 of the affected host. The available actions are: - print: display the filenames of the affected VHDs - delete: remove the affected VHDs - move: move the affected VHDs out of the SR into another directory """ import glob import os import subprocess import sys class ExecutionFailed(Exception): def __init__(self, returncode, stdout, stderr, max_stream_length=32): self.returncode = returncode self.stdout = stdout[:max_stream_length] self.stderr = stderr[:max_stream_length] self.max_stream_length = max_stream_length def __repr__(self): return "<ExecutionFailed returncode=%s out='%s' stderr='%s'>" % ( self.returncode, self.stdout, self.stderr) __str__ = __repr__ def execute(cmd, ok_exit_codes=None): if ok_exit_codes is None: ok_exit_codes = [0] proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = proc.communicate() if proc.returncode not in ok_exit_codes: raise ExecutionFailed(proc.returncode, stdout, stderr) return proc.returncode, stdout, stderr def usage(): print "usage: %s <SR PATH> <print|delete|move>" % sys.argv[0] sys.exit(1) def main(): if len(sys.argv) < 3: usage() sr_path = sys.argv[1] action = sys.argv[2] if action not in ('print', 'delete', 'move'): usage() if action == 'move': if len(sys.argv) < 4: print "error: must specify where to move bad VHDs" sys.exit(1) bad_vhd_path = sys.argv[3] if not os.path.exists(bad_vhd_path): os.makedirs(bad_vhd_path) bad_leaves = [] descendents = {} for fname in glob.glob(os.path.join(sr_path, "*.vhd")): (returncode, stdout, stderr) = execute( ['vhd-util', 'query', '-n', fname, '-p'], ok_exit_codes=[0, 22]) stdout = stdout.strip() if stdout.endswith('.vhd'): try: descendents[stdout].append(fname) except KeyError: descendents[stdout] = [fname] elif 'query failed' in stdout: bad_leaves.append(fname) def walk_vhds(root): yield root if root in descendents: for child in descendents[root]: for vhd in walk_vhds(child): yield vhd for bad_leaf in bad_leaves: for bad_vhd in walk_vhds(bad_leaf): print bad_vhd if action == "print": pass elif action == "delete": os.unlink(bad_vhd) elif action == "move": new_path = os.path.join(bad_vhd_path, os.path.basename(bad_vhd)) os.rename(bad_vhd, new_path) else: raise Exception("invalid action %s" % action) if __name__ == '__main__': main()
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 199, 3, 1898, 6029, 14260, 2752, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 199, 624, 199, 2765, 2884, 365, 19829, 370, 9058, 1263, 812, 14903, 83, 334, 460, 3932, 4328, 287, 1326, 83, 9, 1314, 1172, 199, 65, 4875, 1676, 7849, 14, 199, 199, 1918, 2884, 4839, 370, 506, 1255, 315, 314, 8266, 16, 402, 314, 16955, 1591, 14, 199, 199, 1918, 2808, 5445, 787, 26, 339, 446, 870, 26, 2929, 314, 6203, 402, 314, 16955, 812, 14903, 83, 272, 446, 3145, 26, 2813, 314, 16955, 812, 14903, 83, 272, 446, 4057, 26, 4057, 314, 16955, 812, 14903, 83, 734, 402, 314, 12765, 1901, 4573, 2082, 199, 624, 199, 646, 5739, 199, 646, 747, 199, 646, 3873, 199, 646, 984, 421, 199, 533, 28573, 4276, 8, 1726, 304, 272, 347, 636, 826, 721, 277, 12, 17630, 12, 3839, 12, 4635, 12, 1390, 63, 1745, 63, 1267, 29, 708, 304, 267, 291, 14, 9913, 275, 17630, 267, 291, 14, 2703, 275, 3839, 1491, 988, 63, 1745, 63, 1267, 61, 267, 291, 14, 3083, 275, 4635, 1491, 988, 63, 1745, 63, 1267, 61, 267, 291, 14, 988, 63, 1745, 63, 1267, 275, 1390, 63, 1745, 63, 1267, 339, 347, 636, 2722, 721, 277, 304, 267, 372, 3886, 11310, 4276, 17630, 2458, 83, 734, 9569, 83, 7, 4635, 9569, 83, 7, 4335, 450, 334, 288, 291, 14, 9913, 12, 291, 14, 2703, 12, 291, 14, 3083, 9, 339, 636, 495, 363, 275, 636, 2722, 363, 421, 199, 318, 5341, 8, 1760, 12, 4112, 63, 2224, 63, 6021, 29, 403, 304, 272, 340, 4112, 63, 2224, 63, 6021, 365, 488, 26, 267, 4112, 63, 2224, 63, 6021, 275, 359, 16, 61, 339, 6499, 275, 3873, 14, 7942, 8, 267, 2088, 12, 3839, 29, 5781, 14, 6089, 12, 4635, 29, 5781, 14, 6089, 9, 339, 334, 2703, 12, 4635, 9, 275, 6499, 14, 10664, 342, 339, 340, 6499, 14, 9913, 440, 315, 4112, 63, 2224, 63, 6021, 26, 267, 746, 28573, 4276, 8, 4687, 14, 9913, 12, 3839, 12, 4635, 9, 339, 372, 6499, 14, 9913, 12, 3839, 12, 4635, 421, 199, 318, 4503, 837, 272, 870, 298, 3807, 26, 450, 83, 665, 5943, 15097, 30, 665, 1361, 92, 1807, 92, 1185, 4335, 450, 984, 14, 3020, 59, 16, 61, 272, 984, 14, 2224, 8, 17, 9, 421, 199, 318, 2446, 837, 272, 340, 822, 8, 1274, 14, 3020, 9, 665, 650, 26, 267, 4503, 342, 339, 11483, 63, 515, 275, 984, 14, 3020, 59, 17, 61, 272, 1595, 275, 984, 14, 3020, 59, 18, 61, 339, 340, 1595, 440, 315, 661, 1361, 297, 283, 1807, 297, 283, 1185, 735, 267, 4503, 342, 339, 340, 1595, 508, 283, 1185, 356, 267, 340, 822, 8, 1274, 14, 3020, 9, 665, 841, 26, 288, 870, 298, 705, 26, 1471, 4165, 2382, 370, 4057, 4875, 812, 14903, 83, 2, 288, 984, 14, 2224, 8, 17, 9, 398, 4875, 63, 20961, 63, 515, 275, 984, 14, 3020, 59, 19, 61, 267, 340, 440, 747, 14, 515, 14, 2444, 8, 4087, 63, 20961, 63, 515, 304, 288, 747, 14, 8347, 8, 4087, 63, 20961, 63, 515, 9, 339, 4875, 63, 16554, 275, 942, 272, 4328, 287, 1326, 83, 275, 1052, 339, 367, 6748, 315, 5739, 14, 6463, 8, 736, 14, 515, 14, 904, 8, 5474, 63, 515, 12, 298, 4856, 20961, 14150, 267, 334, 9913, 12, 3839, 12, 4635, 9, 275, 5341, 8, 288, 788, 20961, 13, 1974, 297, 283, 1131, 297, 2475, 78, 297, 6748, 12, 2475, 80, 995, 4112, 63, 2224, 63, 6021, 1524, 16, 12, 6928, 566, 398, 3839, 275, 3839, 14, 1913, 342, 398, 340, 3839, 14, 4130, 5175, 20961, 735, 288, 862, 26, 355, 4328, 287, 1326, 83, 59, 2703, 1055, 740, 8, 5252, 9, 288, 871, 4067, 26, 355, 4328, 287, 1326, 83, 59, 2703, 61, 275, 359, 5252, 61, 267, 916, 283, 1131, 3405, 7, 315, 3839, 26, 288, 4875, 63, 16554, 14, 740, 8, 5252, 9, 339, 347, 12778, 63, 20369, 795, 8, 1231, 304, 267, 1995, 1738, 267, 340, 1738, 315, 4328, 287, 1326, 83, 26, 288, 367, 1982, 315, 4328, 287, 1326, 83, 59, 1231, 2189, 355, 367, 373, 7952, 315, 12778, 63, 20369, 795, 8, 1739, 304, 490, 1995, 373, 7952, 339, 367, 4875, 63, 8914, 315, 4875, 63, 16554, 26, 267, 367, 4875, 63, 20961, 315, 12778, 63, 20369, 795, 8, 4087, 63, 8914, 304, 288, 870, 4875, 63, 20961, 288, 340, 1595, 508, 298, 1361, 582, 355, 986, 288, 916, 1595, 508, 298, 1807, 582, 355, 747, 14, 7162, 8, 4087, 63, 20961, 9, 288, 916, 1595, 508, 298, 1185, 582, 355, 892, 63, 515, 275, 747, 14, 515, 14, 904, 8, 4087, 63, 20961, 63, 515, 12, 3147, 747, 14, 515, 14, 4846, 8, 4087, 63, 20961, 430, 355, 747, 14, 8165, 8, 4087, 63, 20961, 12, 892, 63, 515, 9, 288, 587, 26, 355, 746, 2186, 480, 3197, 1595, 450, 83, 2, 450, 1595, 9, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 2446, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 199, 3, 1898, 6029, 14260, 2752, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 199, 624, 199, 2765, 2884, 365, 19829, 370, 9058, 1263, 812, 14903, 83, 334, 460, 3932, 4328, 287, 1326, 83, 9, 1314, 1172, 199, 65, 4875, 1676, 7849, 14, 199, 199, 1918, 2884, 4839, 370, 506, 1255, 315, 314, 8266, 16, 402, 314, 16955, 1591, 14, 199, 199, 1918, 2808, 5445, 787, 26, 339, 446, 870, 26, 2929, 314, 6203, 402, 314, 16955, 812, 14903, 83, 272, 446, 3145, 26, 2813, 314, 16955, 812, 14903, 83, 272, 446, 4057, 26, 4057, 314, 16955, 812, 14903, 83, 734, 402, 314, 12765, 1901, 4573, 2082, 199, 624, 199, 646, 5739, 199, 646, 747, 199, 646, 3873, 199, 646, 984, 421, 199, 533, 28573, 4276, 8, 1726, 304, 272, 347, 636, 826, 721, 277, 12, 17630, 12, 3839, 12, 4635, 12, 1390, 63, 1745, 63, 1267, 29, 708, 304, 267, 291, 14, 9913, 275, 17630, 267, 291, 14, 2703, 275, 3839, 1491, 988, 63, 1745, 63, 1267, 61, 267, 291, 14, 3083, 275, 4635, 1491, 988, 63, 1745, 63, 1267, 61, 267, 291, 14, 988, 63, 1745, 63, 1267, 275, 1390, 63, 1745, 63, 1267, 339, 347, 636, 2722, 721, 277, 304, 267, 372, 3886, 11310, 4276, 17630, 2458, 83, 734, 9569, 83, 7, 4635, 9569, 83, 7, 4335, 450, 334, 288, 291, 14, 9913, 12, 291, 14, 2703, 12, 291, 14, 3083, 9, 339, 636, 495, 363, 275, 636, 2722, 363, 421, 199, 318, 5341, 8, 1760, 12, 4112, 63, 2224, 63, 6021, 29, 403, 304, 272, 340, 4112, 63, 2224, 63, 6021, 365, 488, 26, 267, 4112, 63, 2224, 63, 6021, 275, 359, 16, 61, 339, 6499, 275, 3873, 14, 7942, 8, 267, 2088, 12, 3839, 29, 5781, 14, 6089, 12, 4635, 29, 5781, 14, 6089, 9, 339, 334, 2703, 12, 4635, 9, 275, 6499, 14, 10664, 342, 339, 340, 6499, 14, 9913, 440, 315, 4112, 63, 2224, 63, 6021, 26, 267, 746, 28573, 4276, 8, 4687, 14, 9913, 12, 3839, 12, 4635, 9, 339, 372, 6499, 14, 9913, 12, 3839, 12, 4635, 421, 199, 318, 4503, 837, 272, 870, 298, 3807, 26, 450, 83, 665, 5943, 15097, 30, 665, 1361, 92, 1807, 92, 1185, 4335, 450, 984, 14, 3020, 59, 16, 61, 272, 984, 14, 2224, 8, 17, 9, 421, 199, 318, 2446, 837, 272, 340, 822, 8, 1274, 14, 3020, 9, 665, 650, 26, 267, 4503, 342, 339, 11483, 63, 515, 275, 984, 14, 3020, 59, 17, 61, 272, 1595, 275, 984, 14, 3020, 59, 18, 61, 339, 340, 1595, 440, 315, 661, 1361, 297, 283, 1807, 297, 283, 1185, 735, 267, 4503, 342, 339, 340, 1595, 508, 283, 1185, 356, 267, 340, 822, 8, 1274, 14, 3020, 9, 665, 841, 26, 288, 870, 298, 705, 26, 1471, 4165, 2382, 370, 4057, 4875, 812, 14903, 83, 2, 288, 984, 14, 2224, 8, 17, 9, 398, 4875, 63, 20961, 63, 515, 275, 984, 14, 3020, 59, 19, 61, 267, 340, 440, 747, 14, 515, 14, 2444, 8, 4087, 63, 20961, 63, 515, 304, 288, 747, 14, 8347, 8, 4087, 63, 20961, 63, 515, 9, 339, 4875, 63, 16554, 275, 942, 272, 4328, 287, 1326, 83, 275, 1052, 339, 367, 6748, 315, 5739, 14, 6463, 8, 736, 14, 515, 14, 904, 8, 5474, 63, 515, 12, 298, 4856, 20961, 14150, 267, 334, 9913, 12, 3839, 12, 4635, 9, 275, 5341, 8, 288, 788, 20961, 13, 1974, 297, 283, 1131, 297, 2475, 78, 297, 6748, 12, 2475, 80, 995, 4112, 63, 2224, 63, 6021, 1524, 16, 12, 6928, 566, 398, 3839, 275, 3839, 14, 1913, 342, 398, 340, 3839, 14, 4130, 5175, 20961, 735, 288, 862, 26, 355, 4328, 287, 1326, 83, 59, 2703, 1055, 740, 8, 5252, 9, 288, 871, 4067, 26, 355, 4328, 287, 1326, 83, 59, 2703, 61, 275, 359, 5252, 61, 267, 916, 283, 1131, 3405, 7, 315, 3839, 26, 288, 4875, 63, 16554, 14, 740, 8, 5252, 9, 339, 347, 12778, 63, 20369, 795, 8, 1231, 304, 267, 1995, 1738, 267, 340, 1738, 315, 4328, 287, 1326, 83, 26, 288, 367, 1982, 315, 4328, 287, 1326, 83, 59, 1231, 2189, 355, 367, 373, 7952, 315, 12778, 63, 20369, 795, 8, 1739, 304, 490, 1995, 373, 7952, 339, 367, 4875, 63, 8914, 315, 4875, 63, 16554, 26, 267, 367, 4875, 63, 20961, 315, 12778, 63, 20369, 795, 8, 4087, 63, 8914, 304, 288, 870, 4875, 63, 20961, 288, 340, 1595, 508, 298, 1361, 582, 355, 986, 288, 916, 1595, 508, 298, 1807, 582, 355, 747, 14, 7162, 8, 4087, 63, 20961, 9, 288, 916, 1595, 508, 298, 1185, 582, 355, 892, 63, 515, 275, 747, 14, 515, 14, 904, 8, 4087, 63, 20961, 63, 515, 12, 3147, 747, 14, 515, 14, 4846, 8, 4087, 63, 20961, 430, 355, 747, 14, 8165, 8, 4087, 63, 20961, 12, 892, 63, 515, 9, 288, 587, 26, 355, 746, 2186, 480, 3197, 1595, 450, 83, 2, 450, 1595, 9, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 2446, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
weisongchen/flaskapp
venv/lib/python2.7/site-packages/pip/_vendor/packaging/_structures.py
1152
1416
# This file is dual licensed under the terms of the Apache License, Version # 2.0, and the BSD License. See the LICENSE file in the root of this repository # for complete details. from __future__ import absolute_import, division, print_function class Infinity(object): def __repr__(self): return "Infinity" def __hash__(self): return hash(repr(self)) def __lt__(self, other): return False def __le__(self, other): return False def __eq__(self, other): return isinstance(other, self.__class__) def __ne__(self, other): return not isinstance(other, self.__class__) def __gt__(self, other): return True def __ge__(self, other): return True def __neg__(self): return NegativeInfinity Infinity = Infinity() class NegativeInfinity(object): def __repr__(self): return "-Infinity" def __hash__(self): return hash(repr(self)) def __lt__(self, other): return True def __le__(self, other): return True def __eq__(self, other): return isinstance(other, self.__class__) def __ne__(self, other): return not isinstance(other, self.__class__) def __gt__(self, other): return False def __ge__(self, other): return False def __neg__(self): return Infinity NegativeInfinity = NegativeInfinity()
mit
[ 3, 961, 570, 365, 21164, 18233, 1334, 314, 2895, 402, 314, 3668, 844, 12, 3394, 199, 3, 499, 14, 16, 12, 436, 314, 6289, 844, 14, 1666, 314, 5113, 570, 315, 314, 1738, 402, 642, 7611, 199, 3, 367, 4890, 2436, 14, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 421, 199, 533, 1010, 9693, 8, 785, 304, 339, 347, 636, 2722, 721, 277, 304, 267, 372, 298, 14660, 2, 339, 347, 636, 2227, 721, 277, 304, 267, 372, 2631, 8, 2722, 8, 277, 430, 339, 347, 636, 4116, 721, 277, 12, 1163, 304, 267, 372, 756, 339, 347, 636, 274, 721, 277, 12, 1163, 304, 267, 372, 756, 339, 347, 636, 4077, 721, 277, 12, 1163, 304, 267, 372, 1228, 8, 1848, 12, 291, 855, 533, 3368, 339, 347, 636, 685, 721, 277, 12, 1163, 304, 267, 372, 440, 1228, 8, 1848, 12, 291, 855, 533, 3368, 339, 347, 636, 3308, 721, 277, 12, 1163, 304, 267, 372, 715, 339, 347, 636, 303, 721, 277, 12, 1163, 304, 267, 372, 715, 339, 347, 636, 8705, 721, 277, 304, 267, 372, 32548, 14660, 199, 199, 14660, 275, 1010, 9693, 342, 421, 199, 533, 32548, 14660, 8, 785, 304, 339, 347, 636, 2722, 721, 277, 304, 267, 372, 3905, 14660, 2, 339, 347, 636, 2227, 721, 277, 304, 267, 372, 2631, 8, 2722, 8, 277, 430, 339, 347, 636, 4116, 721, 277, 12, 1163, 304, 267, 372, 715, 339, 347, 636, 274, 721, 277, 12, 1163, 304, 267, 372, 715, 339, 347, 636, 4077, 721, 277, 12, 1163, 304, 267, 372, 1228, 8, 1848, 12, 291, 855, 533, 3368, 339, 347, 636, 685, 721, 277, 12, 1163, 304, 267, 372, 440, 1228, 8, 1848, 12, 291, 855, 533, 3368, 339, 347, 636, 3308, 721, 277, 12, 1163, 304, 267, 372, 756, 339, 347, 636, 303, 721, 277, 12, 1163, 304, 267, 372, 756, 339, 347, 636, 8705, 721, 277, 304, 267, 372, 1010, 9693, 199, 199, 15562, 14660, 275, 32548, 14660, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 961, 570, 365, 21164, 18233, 1334, 314, 2895, 402, 314, 3668, 844, 12, 3394, 199, 3, 499, 14, 16, 12, 436, 314, 6289, 844, 14, 1666, 314, 5113, 570, 315, 314, 1738, 402, 642, 7611, 199, 3, 367, 4890, 2436, 14, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 421, 199, 533, 1010, 9693, 8, 785, 304, 339, 347, 636, 2722, 721, 277, 304, 267, 372, 298, 14660, 2, 339, 347, 636, 2227, 721, 277, 304, 267, 372, 2631, 8, 2722, 8, 277, 430, 339, 347, 636, 4116, 721, 277, 12, 1163, 304, 267, 372, 756, 339, 347, 636, 274, 721, 277, 12, 1163, 304, 267, 372, 756, 339, 347, 636, 4077, 721, 277, 12, 1163, 304, 267, 372, 1228, 8, 1848, 12, 291, 855, 533, 3368, 339, 347, 636, 685, 721, 277, 12, 1163, 304, 267, 372, 440, 1228, 8, 1848, 12, 291, 855, 533, 3368, 339, 347, 636, 3308, 721, 277, 12, 1163, 304, 267, 372, 715, 339, 347, 636, 303, 721, 277, 12, 1163, 304, 267, 372, 715, 339, 347, 636, 8705, 721, 277, 304, 267, 372, 32548, 14660, 199, 199, 14660, 275, 1010, 9693, 342, 421, 199, 533, 32548, 14660, 8, 785, 304, 339, 347, 636, 2722, 721, 277, 304, 267, 372, 3905, 14660, 2, 339, 347, 636, 2227, 721, 277, 304, 267, 372, 2631, 8, 2722, 8, 277, 430, 339, 347, 636, 4116, 721, 277, 12, 1163, 304, 267, 372, 715, 339, 347, 636, 274, 721, 277, 12, 1163, 304, 267, 372, 715, 339, 347, 636, 4077, 721, 277, 12, 1163, 304, 267, 372, 1228, 8, 1848, 12, 291, 855, 533, 3368, 339, 347, 636, 685, 721, 277, 12, 1163, 304, 267, 372, 440, 1228, 8, 1848, 12, 291, 855, 533, 3368, 339, 347, 636, 3308, 721, 277, 12, 1163, 304, 267, 372, 756, 339, 347, 636, 303, 721, 277, 12, 1163, 304, 267, 372, 756, 339, 347, 636, 8705, 721, 277, 304, 267, 372, 1010, 9693, 199, 199, 15562, 14660, 275, 32548, 14660, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
fls-bioinformatics-core/RnaChipIntegrator
test/test_Features.py
1
14809
# # test_Features.py: unit tests for Features module # Copyright (C) University of Manchester 2011-5 Peter Briggs from common import * from rnachipintegrator.Features import Feature from rnachipintegrator.Features import FeatureSet import unittest class TestFeature(unittest.TestCase): def setUp(self): # Set up Feature objects to be used in the tests # Forward strand example self.rna_data = \ Feature('CG9130-RB','chr3L','1252012','1255989','+') # Reverse strand example self.rna_data_2 = \ Feature('CG13051-RA','chr3L','16257914','16258166','-') def test_properties(self): self.assertEqual(self.rna_data.chrom,'chr3L') self.assertEqual(self.rna_data.source_file,None) self.assertEqual(self.rna_data_2.chrom,'chr3L') self.assertEqual(self.rna_data_2.source_file,None) def test_with_source_file(self): feature = Feature('CG9130-RB','chr3L','1252012','1255989','+', source_file="Features1.txt") self.assertEqual(feature.chrom,'chr3L') self.assertEqual(feature.id,'CG9130-RB') self.assertEqual(feature.start,1252012) self.assertEqual(feature.end,1255989) self.assertEqual(feature.strand,'+') self.assertEqual(feature.source_file,"Features1.txt") def test__eq__(self): self.assertEqual(self.rna_data,Feature('CG9130-RB', 'chr3L', '1252012', '1255989','+')) self.assertNotEqual(self.rna_data,self.rna_data_2) def test_contains_position(self): position = 1253000 self.assertTrue(self.rna_data.containsPosition(position), "Transcript should contain position") position = 4250000 self.assertFalse(self.rna_data.containsPosition(position), "Transcript should not contain position") position = 10000 self.assertFalse(self.rna_data.containsPosition(position), "Transcript should not contain position") def test_get_closest_edge_distance(self): # Single position position = 1200000 # Single reference position self.assertEqual(self.rna_data.getClosestEdgeDistanceTo(position), abs(self.rna_data.start-position), "Incorrect closest edge distance #1") position = 1300000 self.assertEqual(self.rna_data.getClosestEdgeDistanceTo(position), abs(self.rna_data.end-position), "Incorrect closest edge distance #2") def test_get_closest_edge_distance_outside_region(self): # Reference region (2 positions) position1 = 1100000 position2 = 1200000 self.assertEqual(self.rna_data.getClosestEdgeDistanceTo(position1, position2), abs(self.rna_data.start-position2), "Incorrect closest edge distance (region #1)") position1 = 1300000 position2 = 1400000 self.assertEqual(self.rna_data.getClosestEdgeDistanceTo(position1, position2), abs(self.rna_data.end-position1), "Incorrect closest edge distance (region #2)") def test_get_closest_edge_distance_partially_inside_region(self): # Partially inside reference region position1 = 1200000 position2 = 1255000 self.assertEqual(self.rna_data.getClosestEdgeDistanceTo(position1, position2), abs(self.rna_data.end-position2), "Incorrect closest edge distance (inside region #1)") self.assertEqual(self.rna_data.getClosestEdgeDistanceTo(position1, position2, zero_inside_region=True), 0, "Incorrect closest edge distance (inside region #2)") def test_get_closest_edge_distance_completely_inside_region(self): # Completely inside reference region position1 = 1250000 position2 = 1300000 self.assertEqual(self.rna_data.getClosestEdgeDistanceTo(position1, position2), abs(self.rna_data.start-position1), "Incorrect closest edge distance (inside region #3)") self.assertEqual(self.rna_data.getClosestEdgeDistanceTo(position1, position2, zero_inside_region=True), 0, "Incorrect closest edge distance (inside region #4)") def test_get_promoter_region(self): leading = 10000 trailing = 2500 promoter = self.rna_data.getPromoterRegion(leading,trailing) self.assertEqual(promoter, (self.rna_data.getTSS()-leading, self.rna_data.getTSS()+trailing), "Incorrect promoter region for + strand example") promoter = self.rna_data_2.getPromoterRegion(leading,trailing) self.assertEqual(promoter, (self.rna_data_2.getTSS()+leading, self.rna_data_2.getTSS()-trailing), "Incorrect promoter region for - strand example") class TestFeatureSet(unittest.TestCase): def setUp(self): # Create input files for tests create_test_file('Transcripts-ex1.txt',transcripts_ex1) create_test_file('Transcripts-ex2.txt',transcripts_ex2) create_test_file('Transcripts-ex2a.txt',transcripts_ex2a) def tearDown(self): # Remove input files delete_test_file('Transcripts-ex1.txt') delete_test_file('Transcripts-ex2.txt') def test_populate_from_list_of_features(self): features = FeatureSet( features_list=( Feature('CG31973','chr2L',25402,59243,'-'), Feature('CG2674-RC','chr2L',107926,114433,'+'), Feature('CG2674-RE','chr2L',106903,114433,'+'), Feature('CG2674-RA','chr2L',107760,114433,'+'))) self.assertEqual(features.source_file,None) self.assertEqual(features[0], Feature('CG31973','chr2L',25402,59243,'-')) self.assertEqual(features[1], Feature('CG2674-RC','chr2L',107926,114433,'+')) self.assertEqual(features[2], Feature('CG2674-RE','chr2L',106903,114433,'+')) self.assertEqual(features[3], Feature('CG2674-RA','chr2L',107760,114433,'+')) def test_reading_in_RNAseq_data(self): rna_seq = FeatureSet('Transcripts-ex1.txt') self.assertEqual(rna_seq.source_file,'Transcripts-ex1.txt') self.assertEqual(len(rna_seq),10, "Wrong number of lines from RNA-seq file") self.assertTrue(rna_seq.isFlagged(), "Data should be flagged") def test_source_file_is_stored(self): features = FeatureSet('Transcripts-ex1.txt') self.assertEqual(features.source_file,'Transcripts-ex1.txt') for feature in features: self.assertEqual(feature.source_file,'Transcripts-ex1.txt') def test_filter_on_chromosome(self): rna_seq = FeatureSet('Transcripts-ex1.txt') rna_chr = rna_seq.filterByChr('chr3LHet') self.assertEqual(len(rna_chr),1, "Wrong number of chromosomes") for rna_data in rna_chr: self.assertEqual(rna_data.chrom,'chr3LHet', "Wrong chromosome filtered") def test_filter_on_strand(self): rna_seq = FeatureSet('Transcripts-ex1.txt') rna_plus = rna_seq.filterByStrand('+') self.assertEqual(len(rna_plus),5, "Wrong number of + strands") rna_minus = rna_seq.filterByStrand('-') self.assertEqual(len(rna_minus),5, "Wrong number of - strands") def test_filter_on_flag(self): rna_seq = FeatureSet('Transcripts-ex1.txt') rna_flagged = rna_seq.filterByFlag(1) self.assertEqual(len(rna_flagged),4, "Wrong number of flagged data lines") def test_getTSS(self): rna_seq = FeatureSet('Transcripts-ex1.txt') rna_plus = rna_seq.filterByStrand('+') for rna_data in rna_plus: self.assertTrue((rna_data.strand == '+' and rna_data.start == rna_data.getTSS()), "Incorrect TSS on + strand") rna_minus = rna_seq.filterByStrand('-') for rna_data in rna_minus: self.assertTrue((rna_data.strand == '-' and rna_data.end == rna_data.getTSS()), "Incorrect TSS on - strand") def test_filter_on_TSS(self): rna_seq = FeatureSet('Transcripts-ex1.txt') lower,upper = 5000000,10000000 rna_tss = rna_seq.filterByTSS(upper,lower) self.assertEqual(len(rna_tss),3, "Wrong number of transcripts filtered on TSS") for rna_data in rna_tss: self.assertTrue((rna_data.getTSS() >= lower and rna_data.getTSS() <= upper), "Transcript outside range") def test_sort_by_distance(self): rna_sort = FeatureSet('Transcripts-ex1.txt') position = 4250000 # Do sort on distance # Sort is done in place, so assignment is not required # however the sort function should return a reference to # the initial object result = rna_sort.sortByDistanceFrom(position) self.assertEqual(result,rna_sort, "Returned object doesn't match subject") # Check that each distance is greater than the previous one last_rna_data = None for rna_data in rna_sort: if not last_rna_data: last_rna_data = rna_data else: self.assertTrue((abs(rna_data.getTSS() - position) >= abs(last_rna_data.getTSS() - position)), "Sort by distance failed") def test_sort_by_closest_distance_to_edge(self): rna_sort = FeatureSet('Transcripts-ex1.txt') position = 4250000 # Do sort # Sort is done in place, so assignment is not required # however the sort function should return a reference to # the initial object result = rna_sort.sortByClosestEdgeTo(position) self.assertEqual(result,rna_sort, "Returned object doesn't match subject") # Check that the closest distances are in ascending order last_rna_data = None for rna_data in rna_sort: if not last_rna_data: last_rna_data = rna_data else: self.assertTrue((min(abs(rna_data.getTSS() - position), abs(rna_data.getTES() - position)) >= min(abs(last_rna_data.getTSS() - position), abs(last_rna_data.getTES() - position))), "Sort by closest distance to edge failed") def test_sort_by_closest_TSS_to_edge(self): rna_sort = FeatureSet('Transcripts-ex1.txt') position = (16000000,17500000) # Do sort # Sort is done in place, so assignment is not required # however the sort function should return a reference to # the initial object result = rna_sort.sortByClosestTSSTo(*position) self.assertEqual(result,rna_sort, "Returned object doesn't match subject") # Check that the closest distances are in ascending order last_rna_data = None for rna_data in rna_sort: if not last_rna_data: last_rna_data = rna_data else: self.assertTrue((min(abs(rna_data.getTSS() - position[0]), abs(rna_data.getTSS() - position[1])) >= min(abs(last_rna_data.getTSS() - position[0]), abs(last_rna_data.getTSS() - position[1]))), "Sort by closest TSS to edge failed") def test_reading_bad_file_scientific_notation(self): self.assertRaises(Exception,FeatureSet,'Transcripts-ex2.txt') def test_reading_bad_file_end_lower_than_start(self): self.assertRaises(Exception,FeatureSet,'Transcripts-ex2a.txt') def test_get_item(self): features = FeatureSet('Transcripts-ex1.txt') feature = features[2] self.assertEqual(feature,Feature('CG32847-RB', 'chr3L', '15114722', '15115217', '+')) def test_get_slice(self): features = FeatureSet('Transcripts-ex1.txt') features_slice = features[1:3] self.assertTrue(isinstance(features_slice,FeatureSet)) self.assertEqual(len(features_slice),2) self.assertEqual(features[1],features_slice[0]) self.assertEqual(features[2],features_slice[1]) def test__eq__(self): # Check equality of FeatureSets feature_set1 = FeatureSet() feature_set2 = FeatureSet() # Empty feature sets self.assertEqual(feature_set1,feature_set2) # Populate feature_set1.addFeature(Feature('CG1000','chr1','1','2','+')) feature_set2.addFeature(Feature('CG1000','chr1','1','2','+')) self.assertEqual(feature_set1,feature_set2) # Add second feature_set1.addFeature(Feature('CG2000','chr1','1','2','+')) self.assertNotEqual(feature_set1,feature_set2) feature_set2.addFeature(Feature('CG2000','chr1','1','2','+')) self.assertEqual(feature_set1,feature_set2) # Add third feature_set1.addFeature(Feature('CG2001','chr2',3,4,'-')) feature_set2.addFeature(Feature('CG2002','chr2',3,5,'+')) self.assertNotEqual(feature_set1,feature_set2)
artistic-2.0
[ 3, 199, 3, 258, 511, 63, 10807, 14, 647, 26, 4137, 2295, 367, 7949, 2093, 859, 199, 3, 258, 1898, 334, 35, 9, 15904, 402, 4688, 12253, 351, 7760, 13, 21, 22912, 699, 322, 71, 458, 199, 199, 504, 2863, 492, 627, 199, 504, 519, 78, 1225, 711, 25323, 707, 14, 10807, 492, 13407, 199, 504, 519, 78, 1225, 711, 25323, 707, 14, 10807, 492, 13407, 1084, 199, 646, 2882, 199, 199, 533, 1379, 5968, 8, 2796, 14, 1746, 304, 339, 347, 3613, 8, 277, 304, 267, 327, 2494, 1536, 13407, 2251, 370, 506, 1202, 315, 314, 2295, 267, 327, 22536, 620, 460, 2893, 267, 291, 14, 82, 3540, 63, 576, 275, 971, 288, 13407, 360, 4064, 25, 9056, 13, 16567, 1673, 10194, 19, 44, 1673, 6889, 7409, 1673, 713, 17257, 1407, 1673, 13854, 267, 327, 22734, 620, 460, 2893, 267, 291, 14, 82, 3540, 63, 576, 63, 18, 275, 971, 288, 13407, 360, 4064, 969, 21101, 13, 2847, 1673, 10194, 19, 44, 1673, 975, 821, 1965, 1079, 1673, 975, 12234, 10642, 21810, 358, 339, 347, 511, 63, 3282, 8, 277, 304, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 14, 23473, 2584, 10194, 19, 44, 358, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 14, 1365, 63, 493, 12, 403, 9, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 63, 18, 14, 23473, 2584, 10194, 19, 44, 358, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 63, 18, 14, 1365, 63, 493, 12, 403, 9, 339, 347, 511, 63, 1045, 63, 1365, 63, 493, 8, 277, 304, 267, 3878, 275, 13407, 360, 4064, 25, 9056, 13, 16567, 1673, 10194, 19, 44, 1673, 6889, 7409, 1673, 713, 17257, 1407, 1673, 7386, 2079, 1350, 63, 493, 628, 10807, 17, 14, 2424, 531, 267, 291, 14, 629, 8, 4445, 14, 23473, 2584, 10194, 19, 44, 358, 267, 291, 14, 629, 8, 4445, 14, 344, 2584, 4064, 25, 9056, 13, 16567, 358, 267, 291, 14, 629, 8, 4445, 14, 928, 12, 6889, 7409, 9, 267, 291, 14, 629, 8, 4445, 14, 500, 12, 713, 17257, 1407, 9, 267, 291, 14, 629, 8, 4445, 14, 30964, 2584, 13854, 267, 291, 14, 629, 8, 4445, 14, 1365, 63, 493, 4589, 10807, 17, 14, 2424, 531, 339, 347, 511, 363, 4077, 721, 277, 304, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 12, 5968, 360, 4064, 25, 9056, 13, 16567, 297, 6901, 283, 10194, 19, 44, 297, 6901, 283, 6889, 7409, 297, 6901, 283, 713, 17257, 1407, 1673, 11, 1333, 267, 291, 14, 7418, 8, 277, 14, 82, 3540, 63, 576, 12, 277, 14, 82, 3540, 63, 576, 63, 18, 9, 339, 347, 511, 63, 6134, 63, 3124, 8, 277, 304, 267, 3421, 275, 413, 3781, 1493, 267, 291, 14, 1815, 8, 277, 14, 82, 3540, 63, 576, 14, 6134, 5625, 8, 3124, 395, 717, 298, 14612, 1579, 1077, 1395, 3421, 531, 267, 3421, 275, 841, 821, 993, 267, 291, 14, 3334, 8, 277, 14, 82, 3540, 63, 576, 14, 6134, 5625, 8, 3124, 395, 586, 298, 14612, 1579, 1077, 440, 1395, 3421, 531, 267, 3421, 275, 11630, 267, 291, 14, 3334, 8, 277, 14, 82, 3540, 63, 576, 14, 6134, 5625, 8, 3124, 395, 586, 298, 14612, 1579, 1077, 440, 1395, 3421, 531, 339, 347, 511, 63, 362, 63, 22061, 63, 5173, 63, 5590, 8, 277, 304, 267, 327, 13050, 3421, 267, 3421, 275, 3144, 5345, 267, 327, 13050, 3659, 3421, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 14, 362, 4724, 270, 12886, 10076, 1378, 8, 3124, 395, 586, 2853, 8, 277, 14, 82, 3540, 63, 576, 14, 928, 13, 3124, 395, 586, 298, 18298, 18284, 6275, 6033, 327, 17, 531, 267, 3421, 275, 4944, 5345, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 14, 362, 4724, 270, 12886, 10076, 1378, 8, 3124, 395, 586, 2853, 8, 277, 14, 82, 3540, 63, 576, 14, 500, 13, 3124, 395, 586, 298, 18298, 18284, 6275, 6033, 327, 18, 531, 339, 347, 511, 63, 362, 63, 22061, 63, 5173, 63, 5590, 63, 22431, 63, 4551, 8, 277, 304, 267, 327, 10944, 4897, 334, 18, 12266, 9, 267, 3421, 17, 275, 4119, 5345, 267, 3421, 18, 275, 3144, 5345, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 14, 362, 4724, 270, 12886, 10076, 1378, 8, 3124, 17, 12, 17743, 3421, 18, 395, 586, 2853, 8, 277, 14, 82, 3540, 63, 576, 14, 928, 13, 3124, 18, 395, 586, 298, 18298, 18284, 6275, 6033, 334, 4551, 327, 17, 6320, 267, 3421, 17, 275, 4944, 5345, 267, 3421, 18, 275, 4329, 5345, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 14, 362, 4724, 270, 12886, 10076, 1378, 8, 3124, 17, 12, 17743, 3421, 18, 395, 586, 2853, 8, 277, 14, 82, 3540, 63, 576, 14, 500, 13, 3124, 17, 395, 586, 298, 18298, 18284, 6275, 6033, 334, 4551, 327, 18, 6320, 339, 347, 511, 63, 362, 63, 22061, 63, 5173, 63, 5590, 63, 462, 9406, 63, 17183, 63, 4551, 8, 277, 304, 267, 327, 2235, 9406, 6272, 3659, 4897, 267, 3421, 17, 275, 3144, 5345, 267, 3421, 18, 275, 413, 2299, 1493, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 14, 362, 4724, 270, 12886, 10076, 1378, 8, 3124, 17, 12, 17743, 3421, 18, 395, 586, 2853, 8, 277, 14, 82, 3540, 63, 576, 14, 500, 13, 3124, 18, 395, 586, 298, 18298, 18284, 6275, 6033, 334, 17183, 4897, 327, 17, 6320, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 14, 362, 4724, 270, 12886, 10076, 1378, 8, 3124, 17, 12, 17743, 3421, 18, 12, 17743, 4697, 63, 17183, 63, 4551, 29, 549, 395, 586, 378, 12, 586, 298, 18298, 18284, 6275, 6033, 334, 17183, 4897, 327, 18, 6320, 339, 347, 511, 63, 362, 63, 22061, 63, 5173, 63, 5590, 63, 4883, 590, 63, 17183, 63, 4551, 8, 277, 304, 267, 327, 28393, 590, 6272, 3659, 4897, 267, 3421, 17, 275, 19163, 993, 267, 3421, 18, 275, 4944, 5345, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 14 ]
[ 199, 3, 258, 511, 63, 10807, 14, 647, 26, 4137, 2295, 367, 7949, 2093, 859, 199, 3, 258, 1898, 334, 35, 9, 15904, 402, 4688, 12253, 351, 7760, 13, 21, 22912, 699, 322, 71, 458, 199, 199, 504, 2863, 492, 627, 199, 504, 519, 78, 1225, 711, 25323, 707, 14, 10807, 492, 13407, 199, 504, 519, 78, 1225, 711, 25323, 707, 14, 10807, 492, 13407, 1084, 199, 646, 2882, 199, 199, 533, 1379, 5968, 8, 2796, 14, 1746, 304, 339, 347, 3613, 8, 277, 304, 267, 327, 2494, 1536, 13407, 2251, 370, 506, 1202, 315, 314, 2295, 267, 327, 22536, 620, 460, 2893, 267, 291, 14, 82, 3540, 63, 576, 275, 971, 288, 13407, 360, 4064, 25, 9056, 13, 16567, 1673, 10194, 19, 44, 1673, 6889, 7409, 1673, 713, 17257, 1407, 1673, 13854, 267, 327, 22734, 620, 460, 2893, 267, 291, 14, 82, 3540, 63, 576, 63, 18, 275, 971, 288, 13407, 360, 4064, 969, 21101, 13, 2847, 1673, 10194, 19, 44, 1673, 975, 821, 1965, 1079, 1673, 975, 12234, 10642, 21810, 358, 339, 347, 511, 63, 3282, 8, 277, 304, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 14, 23473, 2584, 10194, 19, 44, 358, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 14, 1365, 63, 493, 12, 403, 9, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 63, 18, 14, 23473, 2584, 10194, 19, 44, 358, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 63, 18, 14, 1365, 63, 493, 12, 403, 9, 339, 347, 511, 63, 1045, 63, 1365, 63, 493, 8, 277, 304, 267, 3878, 275, 13407, 360, 4064, 25, 9056, 13, 16567, 1673, 10194, 19, 44, 1673, 6889, 7409, 1673, 713, 17257, 1407, 1673, 7386, 2079, 1350, 63, 493, 628, 10807, 17, 14, 2424, 531, 267, 291, 14, 629, 8, 4445, 14, 23473, 2584, 10194, 19, 44, 358, 267, 291, 14, 629, 8, 4445, 14, 344, 2584, 4064, 25, 9056, 13, 16567, 358, 267, 291, 14, 629, 8, 4445, 14, 928, 12, 6889, 7409, 9, 267, 291, 14, 629, 8, 4445, 14, 500, 12, 713, 17257, 1407, 9, 267, 291, 14, 629, 8, 4445, 14, 30964, 2584, 13854, 267, 291, 14, 629, 8, 4445, 14, 1365, 63, 493, 4589, 10807, 17, 14, 2424, 531, 339, 347, 511, 363, 4077, 721, 277, 304, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 12, 5968, 360, 4064, 25, 9056, 13, 16567, 297, 6901, 283, 10194, 19, 44, 297, 6901, 283, 6889, 7409, 297, 6901, 283, 713, 17257, 1407, 1673, 11, 1333, 267, 291, 14, 7418, 8, 277, 14, 82, 3540, 63, 576, 12, 277, 14, 82, 3540, 63, 576, 63, 18, 9, 339, 347, 511, 63, 6134, 63, 3124, 8, 277, 304, 267, 3421, 275, 413, 3781, 1493, 267, 291, 14, 1815, 8, 277, 14, 82, 3540, 63, 576, 14, 6134, 5625, 8, 3124, 395, 717, 298, 14612, 1579, 1077, 1395, 3421, 531, 267, 3421, 275, 841, 821, 993, 267, 291, 14, 3334, 8, 277, 14, 82, 3540, 63, 576, 14, 6134, 5625, 8, 3124, 395, 586, 298, 14612, 1579, 1077, 440, 1395, 3421, 531, 267, 3421, 275, 11630, 267, 291, 14, 3334, 8, 277, 14, 82, 3540, 63, 576, 14, 6134, 5625, 8, 3124, 395, 586, 298, 14612, 1579, 1077, 440, 1395, 3421, 531, 339, 347, 511, 63, 362, 63, 22061, 63, 5173, 63, 5590, 8, 277, 304, 267, 327, 13050, 3421, 267, 3421, 275, 3144, 5345, 267, 327, 13050, 3659, 3421, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 14, 362, 4724, 270, 12886, 10076, 1378, 8, 3124, 395, 586, 2853, 8, 277, 14, 82, 3540, 63, 576, 14, 928, 13, 3124, 395, 586, 298, 18298, 18284, 6275, 6033, 327, 17, 531, 267, 3421, 275, 4944, 5345, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 14, 362, 4724, 270, 12886, 10076, 1378, 8, 3124, 395, 586, 2853, 8, 277, 14, 82, 3540, 63, 576, 14, 500, 13, 3124, 395, 586, 298, 18298, 18284, 6275, 6033, 327, 18, 531, 339, 347, 511, 63, 362, 63, 22061, 63, 5173, 63, 5590, 63, 22431, 63, 4551, 8, 277, 304, 267, 327, 10944, 4897, 334, 18, 12266, 9, 267, 3421, 17, 275, 4119, 5345, 267, 3421, 18, 275, 3144, 5345, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 14, 362, 4724, 270, 12886, 10076, 1378, 8, 3124, 17, 12, 17743, 3421, 18, 395, 586, 2853, 8, 277, 14, 82, 3540, 63, 576, 14, 928, 13, 3124, 18, 395, 586, 298, 18298, 18284, 6275, 6033, 334, 4551, 327, 17, 6320, 267, 3421, 17, 275, 4944, 5345, 267, 3421, 18, 275, 4329, 5345, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 14, 362, 4724, 270, 12886, 10076, 1378, 8, 3124, 17, 12, 17743, 3421, 18, 395, 586, 2853, 8, 277, 14, 82, 3540, 63, 576, 14, 500, 13, 3124, 17, 395, 586, 298, 18298, 18284, 6275, 6033, 334, 4551, 327, 18, 6320, 339, 347, 511, 63, 362, 63, 22061, 63, 5173, 63, 5590, 63, 462, 9406, 63, 17183, 63, 4551, 8, 277, 304, 267, 327, 2235, 9406, 6272, 3659, 4897, 267, 3421, 17, 275, 3144, 5345, 267, 3421, 18, 275, 413, 2299, 1493, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 14, 362, 4724, 270, 12886, 10076, 1378, 8, 3124, 17, 12, 17743, 3421, 18, 395, 586, 2853, 8, 277, 14, 82, 3540, 63, 576, 14, 500, 13, 3124, 18, 395, 586, 298, 18298, 18284, 6275, 6033, 334, 17183, 4897, 327, 17, 6320, 267, 291, 14, 629, 8, 277, 14, 82, 3540, 63, 576, 14, 362, 4724, 270, 12886, 10076, 1378, 8, 3124, 17, 12, 17743, 3421, 18, 12, 17743, 4697, 63, 17183, 63, 4551, 29, 549, 395, 586, 378, 12, 586, 298, 18298, 18284, 6275, 6033, 334, 17183, 4897, 327, 18, 6320, 339, 347, 511, 63, 362, 63, 22061, 63, 5173, 63, 5590, 63, 4883, 590, 63, 17183, 63, 4551, 8, 277, 304, 267, 327, 28393, 590, 6272, 3659, 4897, 267, 3421, 17, 275, 19163, 993, 267, 3421, 18, 275, 4944, 5345, 267, 291, 14, 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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
ravibhure/ansible
lib/ansible/modules/cloud/rackspace/rax_identity.py
151
2712
#!/usr/bin/python # Copyright: Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community'} DOCUMENTATION = ''' --- module: rax_identity short_description: Load Rackspace Cloud Identity description: - Verifies Rackspace Cloud credentials and returns identity information version_added: "1.5" options: state: description: - Indicate desired state of the resource choices: ['present', 'absent'] default: present required: false author: - "Christopher H. Laco (@claco)" - "Matt Martz (@sivel)" extends_documentation_fragment: rackspace.openstack ''' EXAMPLES = ''' - name: Load Rackspace Cloud Identity gather_facts: False hosts: local connection: local tasks: - name: Load Identity local_action: module: rax_identity credentials: ~/.raxpub region: DFW register: rackspace_identity ''' try: import pyrax HAS_PYRAX = True except ImportError: HAS_PYRAX = False from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.rax import (rax_argument_spec, rax_required_together, rax_to_dict, setup_rax_module) def cloud_identity(module, state, identity): instance = dict( authenticated=identity.authenticated, credentials=identity._creds_file ) changed = False instance.update(rax_to_dict(identity)) instance['services'] = instance.get('services', {}).keys() if state == 'present': if not identity.authenticated: module.fail_json(msg='Credentials could not be verified!') module.exit_json(changed=changed, identity=instance) def main(): argument_spec = rax_argument_spec() argument_spec.update( dict( state=dict(default='present', choices=['present']) ) ) module = AnsibleModule( argument_spec=argument_spec, required_together=rax_required_together() ) if not HAS_PYRAX: module.fail_json(msg='pyrax is required for this module') state = module.params.get('state') setup_rax_module(module, pyrax) if not pyrax.identity: module.fail_json(msg='Failed to instantiate client. This ' 'typically indicates an invalid region or an ' 'incorrectly capitalized region name.') cloud_identity(module, state, pyrax.identity) if __name__ == '__main__': main()
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 1898, 26, 2622, 7290, 199, 3, 1664, 1696, 1684, 844, 373, 19, 14, 16, 11, 334, 3239, 9685, 503, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 11692, 13, 19, 14, 16, 14, 2424, 9, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 363, 6577, 363, 275, 730, 421, 199, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 490, 283, 1205, 356, 788, 7780, 995, 490, 283, 4946, 63, 991, 356, 283, 9387, 936, 421, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 16937, 63, 5582, 199, 3612, 63, 1802, 26, 7190, 32679, 8142, 22034, 199, 1802, 26, 1362, 446, 26114, 32679, 8142, 6235, 436, 2529, 8503, 2556, 199, 1023, 63, 3270, 26, 298, 17, 14, 21, 2, 199, 1419, 26, 523, 1174, 26, 272, 1369, 26, 489, 446, 1010, 10188, 6387, 1174, 402, 314, 2073, 272, 3415, 26, 788, 1881, 297, 283, 5575, 418, 272, 849, 26, 3451, 272, 1415, 26, 3055, 199, 2502, 26, 272, 446, 298, 1049, 322, 2379, 2523, 869, 14, 7964, 331, 8593, 3995, 331, 2924, 272, 446, 298, 45, 6796, 603, 28124, 8593, 338, 1090, 2924, 199, 11036, 63, 9970, 63, 7677, 26, 660, 346, 2638, 14, 8512, 199, 2344, 199, 199, 8918, 275, 1449, 199, 13, 536, 26, 7190, 32679, 8142, 22034, 523, 13082, 63, 5047, 26, 756, 523, 7057, 26, 2257, 523, 1950, 26, 2257, 523, 6527, 26, 272, 446, 536, 26, 7190, 22034, 489, 2257, 63, 1287, 26, 267, 859, 26, 16937, 63, 5582, 267, 6235, 26, 25975, 14495, 5645, 267, 4897, 26, 577, 19445, 489, 2274, 26, 660, 346, 2638, 63, 5582, 199, 2344, 199, 199, 893, 26, 272, 492, 23944, 272, 7509, 63, 4521, 2847, 56, 275, 715, 199, 2590, 3545, 26, 272, 7509, 63, 4521, 2847, 56, 275, 756, 199, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 6953, 199, 504, 3242, 14, 578, 63, 1208, 14, 14495, 492, 334, 14495, 63, 2094, 63, 1650, 12, 16937, 63, 2427, 63, 6314, 12, 16937, 63, 475, 63, 807, 12, 4228, 3272, 63, 14495, 63, 578, 9, 421, 199, 318, 8002, 63, 5582, 8, 578, 12, 1174, 12, 8503, 304, 272, 1256, 275, 1211, 8, 267, 15082, 29, 5582, 14, 12177, 12, 267, 6235, 29, 5582, 423, 15226, 63, 493, 272, 776, 272, 2896, 275, 756, 339, 1256, 14, 873, 8, 14495, 63, 475, 63, 807, 8, 5582, 430, 272, 1256, 459, 5950, 418, 275, 1256, 14, 362, 360, 5950, 297, 13056, 1612, 342, 339, 340, 1174, 508, 283, 1881, 356, 267, 340, 440, 8503, 14, 12177, 26, 288, 859, 14, 1633, 63, 1001, 8, 1328, 534, 13428, 4293, 440, 506, 16317, 10916, 339, 859, 14, 2224, 63, 1001, 8, 2489, 29, 2489, 12, 8503, 29, 842, 9, 421, 199, 318, 2446, 837, 272, 1423, 63, 1650, 275, 16937, 63, 2094, 63, 1650, 342, 272, 1423, 63, 1650, 14, 873, 8, 267, 1211, 8, 288, 1174, 29, 807, 8, 885, 534, 1881, 297, 3415, 2968, 1881, 1105, 267, 776, 272, 776, 339, 859, 275, 6953, 8, 267, 1423, 63, 1650, 29, 2094, 63, 1650, 12, 267, 1415, 63, 6314, 29, 14495, 63, 2427, 63, 6314, 342, 272, 776, 339, 340, 440, 7509, 63, 4521, 2847, 56, 26, 267, 859, 14, 1633, 63, 1001, 8, 1328, 534, 647, 14495, 365, 1415, 367, 642, 859, 358, 339, 1174, 275, 859, 14, 1162, 14, 362, 360, 929, 358, 339, 3272, 63, 14495, 63, 578, 8, 578, 12, 23944, 9, 339, 340, 440, 23944, 14, 5582, 26, 267, 859, 14, 1633, 63, 1001, 8, 1328, 534, 4276, 370, 17321, 1890, 14, 961, 283, 2490, 283, 32251, 9126, 376, 3866, 4897, 503, 376, 283, 2490, 283, 15448, 590, 17094, 1759, 4897, 536, 2659, 339, 8002, 63, 5582, 8, 578, 12, 1174, 12, 23944, 14, 5582, 9, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 2446, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1898, 26, 2622, 7290, 199, 3, 1664, 1696, 1684, 844, 373, 19, 14, 16, 11, 334, 3239, 9685, 503, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 11692, 13, 19, 14, 16, 14, 2424, 9, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 363, 6577, 363, 275, 730, 421, 199, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 490, 283, 1205, 356, 788, 7780, 995, 490, 283, 4946, 63, 991, 356, 283, 9387, 936, 421, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 16937, 63, 5582, 199, 3612, 63, 1802, 26, 7190, 32679, 8142, 22034, 199, 1802, 26, 1362, 446, 26114, 32679, 8142, 6235, 436, 2529, 8503, 2556, 199, 1023, 63, 3270, 26, 298, 17, 14, 21, 2, 199, 1419, 26, 523, 1174, 26, 272, 1369, 26, 489, 446, 1010, 10188, 6387, 1174, 402, 314, 2073, 272, 3415, 26, 788, 1881, 297, 283, 5575, 418, 272, 849, 26, 3451, 272, 1415, 26, 3055, 199, 2502, 26, 272, 446, 298, 1049, 322, 2379, 2523, 869, 14, 7964, 331, 8593, 3995, 331, 2924, 272, 446, 298, 45, 6796, 603, 28124, 8593, 338, 1090, 2924, 199, 11036, 63, 9970, 63, 7677, 26, 660, 346, 2638, 14, 8512, 199, 2344, 199, 199, 8918, 275, 1449, 199, 13, 536, 26, 7190, 32679, 8142, 22034, 523, 13082, 63, 5047, 26, 756, 523, 7057, 26, 2257, 523, 1950, 26, 2257, 523, 6527, 26, 272, 446, 536, 26, 7190, 22034, 489, 2257, 63, 1287, 26, 267, 859, 26, 16937, 63, 5582, 267, 6235, 26, 25975, 14495, 5645, 267, 4897, 26, 577, 19445, 489, 2274, 26, 660, 346, 2638, 63, 5582, 199, 2344, 199, 199, 893, 26, 272, 492, 23944, 272, 7509, 63, 4521, 2847, 56, 275, 715, 199, 2590, 3545, 26, 272, 7509, 63, 4521, 2847, 56, 275, 756, 199, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 6953, 199, 504, 3242, 14, 578, 63, 1208, 14, 14495, 492, 334, 14495, 63, 2094, 63, 1650, 12, 16937, 63, 2427, 63, 6314, 12, 16937, 63, 475, 63, 807, 12, 4228, 3272, 63, 14495, 63, 578, 9, 421, 199, 318, 8002, 63, 5582, 8, 578, 12, 1174, 12, 8503, 304, 272, 1256, 275, 1211, 8, 267, 15082, 29, 5582, 14, 12177, 12, 267, 6235, 29, 5582, 423, 15226, 63, 493, 272, 776, 272, 2896, 275, 756, 339, 1256, 14, 873, 8, 14495, 63, 475, 63, 807, 8, 5582, 430, 272, 1256, 459, 5950, 418, 275, 1256, 14, 362, 360, 5950, 297, 13056, 1612, 342, 339, 340, 1174, 508, 283, 1881, 356, 267, 340, 440, 8503, 14, 12177, 26, 288, 859, 14, 1633, 63, 1001, 8, 1328, 534, 13428, 4293, 440, 506, 16317, 10916, 339, 859, 14, 2224, 63, 1001, 8, 2489, 29, 2489, 12, 8503, 29, 842, 9, 421, 199, 318, 2446, 837, 272, 1423, 63, 1650, 275, 16937, 63, 2094, 63, 1650, 342, 272, 1423, 63, 1650, 14, 873, 8, 267, 1211, 8, 288, 1174, 29, 807, 8, 885, 534, 1881, 297, 3415, 2968, 1881, 1105, 267, 776, 272, 776, 339, 859, 275, 6953, 8, 267, 1423, 63, 1650, 29, 2094, 63, 1650, 12, 267, 1415, 63, 6314, 29, 14495, 63, 2427, 63, 6314, 342, 272, 776, 339, 340, 440, 7509, 63, 4521, 2847, 56, 26, 267, 859, 14, 1633, 63, 1001, 8, 1328, 534, 647, 14495, 365, 1415, 367, 642, 859, 358, 339, 1174, 275, 859, 14, 1162, 14, 362, 360, 929, 358, 339, 3272, 63, 14495, 63, 578, 8, 578, 12, 23944, 9, 339, 340, 440, 23944, 14, 5582, 26, 267, 859, 14, 1633, 63, 1001, 8, 1328, 534, 4276, 370, 17321, 1890, 14, 961, 283, 2490, 283, 32251, 9126, 376, 3866, 4897, 503, 376, 283, 2490, 283, 15448, 590, 17094, 1759, 4897, 536, 2659, 339, 8002, 63, 5582, 8, 578, 12, 1174, 12, 23944, 14, 5582, 9, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 2446, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
dingmingliu/quanttrade
bt/core.py
1
37660
""" Contains the core building blocks of the framework. """ import math from copy import deepcopy import pandas as pd import numpy as np import cython as cy class Node(object): """ The Node is the main building block in bt's tree structure design. Both StrategyBase and SecurityBase inherit Node. It contains the core functionality of a tree node. Args: * name (str): The Node name * parent (Node): The parent Node * children (dict, list): A collection of children. If dict, the format is {name: child}, if list then list of children. Attributes: * name (str): Node name * parent (Node): Node parent * root (Node): Root node of the tree (topmost node) * children (dict): Node's children * now (datetime): Used when backtesting to store current date * stale (bool): Flag used to determine if Node is stale and need updating * prices (TimeSeries): Prices of the Node. Prices for a security will be the security's price, for a strategy it will be an index that reflects the value of the strategy over time. * price (float): last price * value (float): last value * weight (float): weight in parent * full_name (str): Name including parents' names * members (list): Current Node + node's children """ _price = cy.declare(cy.double) _value = cy.declare(cy.double) _weight = cy.declare(cy.double) _issec = cy.declare(cy.bint) _has_strat_children = cy.declare(cy.bint) def __init__(self, name, parent=None, children=None): self.name = name # strategy children helpers self._has_strat_children = False self._strat_children = [] # if children is not None, we assume that we want to limit the # available children space to the provided list. if children is not None: if isinstance(children, list): # if all strings - just save as universe_filter if all(isinstance(x, str) for x in children): self._universe_tickers = children # empty dict - don't want to uselessly create # tons of children when they might not be needed children = {} else: # this will be case if we pass in children # (say a bunch of sub-strategies) tmp = {} ut = [] for c in children: if type(c) == str: tmp[c] = SecurityBase(c) ut.append(c) else: # deepcopy object for possible later reuse tmp[c.name] = deepcopy(c) # if strategy, turn on flag and add name to list # strategy children have special treatment if isinstance(c, StrategyBase): self._has_strat_children = True self._strat_children.append(c.name) # if not strategy, then we will want to add this to # universe_tickers to filter on setup else: ut.append(c.name) children = tmp # we want to keep whole universe in this case # so set to None self._universe_tickers = ut if parent is None: self.parent = self self.root = self else: self.parent = parent self.root = parent.root parent._add_child(self) # default children if children is None: children = {} self._universe_tickers = None self.children = children self._childrenv = children.values() for c in self._childrenv: c.parent = self c.root = self.root # set default value for now self.now = 0 # make sure root has stale flag # used to avoid unncessary update # sometimes we change values in the tree and we know that we will need # to update if another node tries to access a given value (say weight). # This avoid calling the update until it is actually needed. self.root.stale = False # helper vars self._price = 0 self._value = 0 self._weight = 0 # is security flag - used to avoid updating 0 pos securities self._issec = False def __getitem__(self, key): return self.children[key] @property def prices(self): """ A TimeSeries of the Node's price. """ # can optimize depending on type - # securities don't need to check stale to # return latest prices, whereas strategies do... raise NotImplementedError() @property def price(self): """ Current price of the Node """ # can optimize depending on type - # securities don't need to check stale to # return latest prices, whereas strategies do... raise NotImplementedError() @property def value(self): """ Current value of the Node """ if self.root.stale: self.root.update(self.root.now, None) return self._value @property def weight(self): """ Current weight of the Node (with respect to the parent). """ if self.root.stale: self.root.update(self.root.now, None) return self._weight def setup(self, dates): """ Setup method used to initialize a Node with a set of dates. """ raise NotImplementedError() def _add_child(self, child): child.parent = self child.root = self.root if self.children is None: self.children = {child.name: child} else: self.children[child.name] = child self._childrenv = self.children.values() def update(self, date, data=None, inow=None): """ Update Node with latest date, and optionally some data. """ raise NotImplementedError() def adjust(self, amount, update=True, isflow=True): """ Adjust Node value by amount. """ raise NotImplementedError() def allocate(self, amount, update=True): """ Allocate capital to Node. """ raise NotImplementedError() @property def members(self): """ Node members. Members include current node as well as Node's children. """ res = [self] for c in self.children.values(): res.extend(c.members) return res @property def full_name(self): if self.parent == self: return self.name else: return '%s>%s' % (self.parent.full_name, self.name) class StrategyBase(Node): """ Strategy Node. Used to define strategy logic within a tree. A Strategy's role is to allocate capital to it's children based on a function. Args: * name (str): Strategy name * children (dict, list): A collection of children. If dict, the format is {name: child}, if list then list of children. Children can be any type of Node. * parent (Node): The parent Node Attributes: * name (str): Strategy name * parent (Strategy): Strategy parent * root (Strategy): Root node of the tree (topmost node) * children (dict): Strategy's children * now (datetime): Used when backtesting to store current date * stale (bool): Flag used to determine if Strategy is stale and need updating * prices (TimeSeries): Prices of the Strategy - basically an index that reflects the value of the strategy over time. * price (float): last price * value (float): last value * weight (float): weight in parent * full_name (str): Name including parents' names * members (list): Current Strategy + strategy's children * commission_fn (fn(quantity, price)): A function used to determine the commission (transaction fee) amount. Could be used to model slippage (implementation shortfall). Note that often fees are symmetric for buy and sell and absolute value of quantity should be used for calculation. * capital (float): Capital amount in Strategy - cash * universe (DataFrame): Data universe available at the current time. Universe contains the data passed in when creating a Backtest. Use this data to determine strategy logic. """ _capital = cy.declare(cy.double) _net_flows = cy.declare(cy.double) _last_value = cy.declare(cy.double) _last_price = cy.declare(cy.double) _last_fee = cy.declare(cy.double) _paper_trade = cy.declare(cy.bint) bankrupt = cy.declare(cy.bint) def __init__(self, name, children=None, parent=None): Node.__init__(self, name, children=children, parent=parent) self._capital = 0 self._weight = 1 self._value = 0 self._price = 100 # helper vars self._net_flows = 0 self._last_value = 0 self._last_price = 100 self._last_fee = 0 # default commission function self.commission_fn = self._dflt_comm_fn self._paper_trade = False self._positions = None self.bankrupt = False @property def price(self): """ Current price. """ if self.root.stale: self.root.update(self.now, None) return self._price @property def prices(self): """ TimeSeries of prices. """ if self.root.stale: self.root.update(self.now, None) return self._prices.ix[:self.now] @property def values(self): """ TimeSeries of values. """ if self.root.stale: self.root.update(self.now, None) return self._values.ix[:self.now] @property def capital(self): """ Current capital - amount of unallocated capital left in strategy. """ # no stale check needed return self._capital @property def cash(self): """ TimeSeries of unallocated capital. """ # no stale check needed return self._cash @property def fees(self): """ TimeSeries of fees. """ # no stale check needed return self._fees @property def universe(self): """ Data universe available at the current time. Universe contains the data passed in when creating a Backtest. Use this data to determine strategy logic. """ # avoid windowing every time # if calling and on same date return # cached value if self.now == self._last_chk: return self._funiverse else: self._last_chk = self.now self._funiverse = self._universe.ix[:self.now] return self._funiverse @property def positions(self): """ TimeSeries of positions. """ # if accessing and stale - update first if self.root.stale: self.root.update(self.root.now, None) if self._positions is not None: return self._positions else: vals = pd.DataFrame({x.name: x.positions for x in self.members if isinstance(x, SecurityBase)}) self._positions = vals return vals def setup(self, universe): """ Setup strategy with universe. This will speed up future calculations and updates. """ # save full universe in case we need it self._original_data = universe # determine if needs paper trading # and setup if so if self is not self.parent: self._paper_trade = True self._paper_amount = 1000000 paper = deepcopy(self) paper.parent = paper paper.root = paper paper._paper_trade = False paper.setup(self._original_data) paper.adjust(self._paper_amount) self._paper = paper # setup universe funiverse = universe if self._universe_tickers is not None: # if we have universe_tickers defined, limit universe to # those tickers valid_filter = list(set(universe.columns) .intersection(self._universe_tickers)) funiverse = universe[valid_filter].copy() # if we have strat children, we will need to create their columns # in the new universe if self._has_strat_children: for c in self._strat_children: funiverse[c] = np.nan # must create to avoid pandas warning funiverse = pd.DataFrame(funiverse) self._universe = funiverse # holds filtered universe self._funiverse = funiverse self._last_chk = None # We're not bankrupt yet self.bankrupt = False # setup internal data self.data = pd.DataFrame(index=funiverse.index, columns=['price', 'value', 'cash', 'fees'], data=0.0) self._prices = self.data['price'] self._values = self.data['value'] self._cash = self.data['cash'] self._fees = self.data['fees'] # setup children as well - use original universe here - don't want to # pollute with potential strategy children in funiverse if self.children is not None: [c.setup(universe) for c in self._childrenv] @cy.locals(newpt=cy.bint, val=cy.double, ret=cy.double) def update(self, date, data=None, inow=None): """ Update strategy. Updates prices, values, weight, etc. """ # resolve stale state self.root.stale = False # update helpers on date change # also set newpt flag newpt = False if self.now == 0: newpt = True elif date != self.now: self._net_flows = 0 self._last_price = self._price self._last_value = self._value self._last_fee = 0.0 newpt = True # update now self.now = date if inow is None: if self.now == 0: inow = 0 else: inow = self.data.index.get_loc(date) # update children if any and calculate value val = self._capital # default if no children if self.children is not None: for c in self._childrenv: # avoid useless update call if c._issec and not c._needupdate: continue c.update(date, data, inow) val += c.value if self.root == self: if (val < 0) and not self.bankrupt: # Declare a bankruptcy self.bankrupt = True self.flatten() # update data if this value is different or # if now has changed - avoid all this if not since it # won't change if newpt or self._value != val: self._value = val self._values.values[inow] = val try: ret = self._value / (self._last_value + self._net_flows) - 1 except ZeroDivisionError: if self._value == 0: ret = 0 else: raise ZeroDivisionError( 'Could not update %s. Last value ' 'was %s and net flows were %s. Current' 'value is %s. Therefore, ' 'we are dividing by zero to obtain the return ' 'for the period.' % (self.name, self._last_value, self._net_flows, self._value)) self._price = self._last_price * (1 + ret) self._prices.values[inow] = self._price # update children weights if self.children is not None: for c in self._childrenv: # avoid useless update call if c._issec and not c._needupdate: continue try: c._weight = c.value / val except ZeroDivisionError: c._weight = 0.0 # if we have strategy children, we will need to update them in universe if self._has_strat_children: for c in self._strat_children: # TODO: optimize ".loc" here as well self._universe.loc[date, c] = self.children[c].price # Cash should track the unallocated capital at the end of the day, so # we should update it every time we call "update". # Same for fees self._cash.values[inow] = self._capital self._fees.values[inow] = self._last_fee # update paper trade if necessary if newpt and self._paper_trade: self._paper.update(date) self._paper.run() self._paper.update(date) # update price self._price = self._paper.price self._prices.values[inow] = self._price @cy.locals(amount=cy.double, update=cy.bint, flow=cy.bint, fees=cy.double) def adjust(self, amount, update=True, flow=True, fee=0.0): """ Adjust capital - used to inject capital to a Strategy. This injection of capital will have no effect on the children. Args: * amount (float): Amount to adjust by. * update (bool): Force update? * flow (bool): Is this adjustment a flow? Basically a flow will have an impact on the price index. Examples of flows are commissions. """ # adjust capital self._capital += amount self._last_fee += fee # if flow - increment net_flows - this will not affect # performance. Commissions and other fees are not flows since # they have a performance impact if flow: self._net_flows += amount if update: # indicates that data is now stale and must # be updated before access self.root.stale = True @cy.locals(amount=cy.double, update=cy.bint) def allocate(self, amount, child=None, update=True): """ Allocate capital to Strategy. By default, capital is allocated recursively down the children, proportionally to the children's weights. If a child is specified, capital will be allocated to that specific child. Allocation also have a side-effect. They will deduct the same amount from the parent's "account" to offset the allocation. If there is remaining capital after allocation, it will remain in Strategy. Args: * amount (float): Amount to allocate. * child (str): If specified, allocation will be directed to child only. Specified by name. * update (bool): Force update. """ # allocate to child if child is not None: if child not in self.children: c = SecurityBase(child) c.setup(self._universe) # update to bring up to speed c.update(self.now) # add child to tree self._add_child(c) # allocate to child self.children[child].allocate(amount) # allocate to self else: # adjust parent's capital # no need to update now - avoids repetition if self.parent == self: self.parent.adjust(-amount, update=False, flow=True) else: # do NOT set as flow - parent will be another strategy # and therefore should not incur flow self.parent.adjust(-amount, update=False, flow=False) # adjust self's capital self.adjust(amount, update=False, flow=True) # push allocation down to children if any # use _weight to avoid triggering an update if self.children is not None: [c.allocate(amount * c._weight, update=False) for c in self._childrenv] # mark as stale if update requested if update: self.root.stale = True @cy.locals(delta=cy.double, weight=cy.double, base=cy.double) def rebalance(self, weight, child, base=np.nan, update=True): """ Rebalance a child to a given weight. This is a helper method to simplify code logic. This method is used when we want to se the weight of a particular child to a set amount. It is similar to allocate, but it calculates the appropriate allocation based on the current weight. Args: * weight (float): The target weight. Usually between -1.0 and 1.0. * child (str): child to allocate to - specified by name. * base (float): If specified, this is the base amount all weight delta calculations will be based off of. This is useful when we determine a set of weights and want to rebalance each child given these new weights. However, as we iterate through each child and call this method, the base (which is by default the current value) will change. Therefore, we can set this base to the original value before the iteration to ensure the proper allocations are made. * update (bool): Force update? """ # if weight is 0 - we want to close child if weight == 0: if child in self.children: return self.close(child) else: return # if no base specified use self's value if np.isnan(base): base = self.value # else make sure we have child if child not in self.children: c = SecurityBase(child) c.setup(self._universe) # update child to bring up to speed c.update(self.now) self._add_child(c) # allocate to child # figure out weight delta c = self.children[child] delta = weight - c.weight c.allocate(delta * base) def close(self, child): """ Close a child position - alias for rebalance(0, child). This will also flatten (close out all) the child's children. Args: * child (str): Child, specified by name. """ c = self.children[child] # flatten if children not None if c.children is not None and len(c.children) != 0: c.flatten() c.allocate(-c.value) def flatten(self): """ Close all child positions. """ # go right to base alloc [c.allocate(-c.value) for c in self._childrenv if c.value != 0] def run(self): """ This is the main logic method. Override this method to provide some algorithm to execute on each date change. This method is called by backtester. """ pass def set_commissions(self, fn): """ Set commission (transaction fee) function. Args: fn (fn(quantity, price)): Function used to determine commission amount. """ self.commission_fn = fn for c in self._childrenv: if isinstance(c, StrategyBase): c.set_commissions(fn) @cy.locals(q=cy.double, p=cy.double) def _dflt_comm_fn(self, q, p): return max(1, abs(q) * 0.01) class SecurityBase(Node): """ Security Node. Used to define a security within a tree. A Security's has no children. It simply models an asset that can be bought or sold. Args: * name (str): Security name * multiplier (float): security multiplier - typically used for derivatives. Attributes: * name (str): Security name * parent (Security): Security parent * root (Security): Root node of the tree (topmost node) * now (datetime): Used when backtesting to store current date * stale (bool): Flag used to determine if Security is stale and need updating * prices (TimeSeries): Security prices. * price (float): last price * value (float): last value - basically position * price * multiplier * weight (float): weight in parent * full_name (str): Name including parents' names * members (list): Current Security + strategy's children * position (float): Current position (quantity). """ _last_pos = cy.declare(cy.double) _position = cy.declare(cy.double) multiplier = cy.declare(cy.double) _prices_set = cy.declare(cy.bint) _needupdate = cy.declare(cy.bint) @cy.locals(multiplier=cy.double) def __init__(self, name, multiplier=1): Node.__init__(self, name, parent=None, children=None) self._value = 0 self._price = 0 self._weight = 0 self._position = 0 self.multiplier = multiplier # opt self._last_pos = 0 self._issec = True self._needupdate = True @property def price(self): """ Current price. """ # if accessing and stale - update first if self._needupdate or self.now != self.parent.now: self.update(self.root.now) return self._price @property def prices(self): """ TimeSeries of prices. """ # if accessing and stale - update first if self._needupdate or self.now != self.parent.now: self.update(self.root.now) return self._prices.ix[:self.now] @property def values(self): """ TimeSeries of values. """ # if accessing and stale - update first if self._needupdate or self.now != self.parent.now: self.update(self.root.now) if self.root.stale: self.root.update(self.root.now, None) return self._values.ix[:self.now] @property def position(self): """ Current position """ # no stale check needed return self._position @property def positions(self): """ TimeSeries of positions. """ # if accessing and stale - update first if self._needupdate: self.update(self.root.now) if self.root.stale: self.root.update(self.root.now, None) return self._positions.ix[:self.now] def setup(self, universe): """ Setup Security with universe. Speeds up future runs. Args: * universe (DataFrame): DataFrame of prices with security's name as one of the columns. """ # if we already have all the prices, we will store them to speed up # future udpates try: prices = universe[self.name] except KeyError: prices = None # setup internal data if prices is not None: self._prices = prices self.data = pd.DataFrame(index=universe.index, columns=['value', 'position'], data=0.0) self._prices_set = True else: self.data = pd.DataFrame(index=universe.index, columns=['price', 'value', 'position']) self._prices = self.data['price'] self._prices_set = False self._values = self.data['value'] self._positions = self.data['position'] @cy.locals(prc=cy.double) def update(self, date, data=None, inow=None): """ Update security with a given date and optionally, some data. This will update price, value, weight, etc. """ # filter for internal calls when position has not changed - nothing to # do. Internal calls (stale root calls) have None data. Also want to # make sure date has not changed, because then we do indeed want to # update. if date == self.now and self._last_pos == self._position: return if inow is None: if date == 0: inow = 0 else: inow = self.data.index.get_loc(date) # date change - update price if date != self.now: # update now self.now = date if self._prices_set: self._price = self._prices.values[inow] # traditional data update elif data is not None: prc = data[self.name] self._price = prc self._prices.values[inow] = prc self._positions.values[inow] = self._position self._last_pos = self._position self._value = self._position * self._price * self.multiplier self._values.values[inow] = self._value if self._weight == 0 and self._position == 0: self._needupdate = False @cy.locals(amount=cy.double, update=cy.bint, q=cy.double, outlay=cy.double) def allocate(self, amount, update=True): """ This allocates capital to the Security. This is the method used to buy/sell the security. A given amount of shares will be determined on the current price, a commisison will be calculated based on the parent's commission fn, and any remaining capital will be passed back up to parent as an adjustment. Args: * amount (float): Amount of adjustment. * update (bool): Force update? """ # will need to update if this has been idle for a while... # update if needupdate or if now is stale # fetch parent's now since our now is stale if self._needupdate or self.now != self.parent.now: self.update(self.parent.now) # ignore 0 alloc # Note that if the price of security has dropped to zero, then it should # never be selected by SelectAll, SelectN etc. I.e. we should not open # the position at zero price. At the same time, we are able to close # it at zero price, because at that point amount=0. # Note also that we don't erase the position in an asset which price has # dropped to zero (though the weight will indeed be = 0) if amount == 0: return if self.parent is self or self.parent is None: raise Exception( 'Cannot allocate capital to a parentless security') if self._price == 0 or np.isnan(self._price): raise Exception( 'Cannot allocate capital to ' '%s because price is 0 or nan as of %s' % (self.name, self.parent.now)) # buy/sell # determine quantity - must also factor in commission # closing out? if amount == -self._value: q = -self._position else: if (self._position > 0) or ((self._position == 0) and (amount > 0)): # if we're going long or changing long position q = math.floor(amount / (self._price * self.multiplier)) else: # if we're going short or changing short position q = math.ceil(amount / (self._price * self.multiplier)) # if q is 0 nothing to do if q == 0 or np.isnan(q): return # this security will need an update, even if pos is 0 (for example if # we close the positions, value and pos is 0, but still need to do that # last update) self._needupdate = True # adjust position & value self._position += q # calculate proper adjustment for parent # parent passed down amount so we want to pass # -outlay back up to parent to adjust for capital # used outlay, fee = self.outlay(q) # call parent self.parent.adjust(-outlay, update=update, flow=False, fee=fee) @cy.locals(q=cy.double, p=cy.double) def commission(self, q, p): """ Calculates the commission (transaction fee) based on quantity and price. Uses the parent's commission_fn. Args: * q (float): quantity * p (float): price """ return self.parent.commission_fn(q, p) @cy.locals(q=cy.double) def outlay(self, q): """ Determines the complete cash outlay (including commission) necessary given a quantity q. Second returning parameter is a commission itself. Args: * q (float): quantity """ fee = self.commission(q, self._price * self.multiplier) full_outlay = q * self._price * self.multiplier + fee return full_outlay, fee def run(self): """ Does nothing - securities have nothing to do on run. """ pass class Algo(object): """ Algos are used to modularize strategy logic so that strategy logic becomes modular, composable, more testable and less error prone. Basically, the Algo should follow the unix philosophy - do one thing well. In practice, algos are simply a function that receives one argument, the Strategy (refered to as target) and are expected to return a bool. When some state preservation is necessary between calls, the Algo object can be used (this object). The __call___ method should be implemented and logic defined therein to mimic a function call. A simple function may also be used if no state preservation is neceesary. Args: * name (str): Algo name """ def __init__(self, name=None): self._name = name @property def name(self): """ Algo name. """ if self._name is None: self._name = self.__class__.__name__ return self._name def __call__(self, target): raise NotImplementedError("%s not implemented!" % self.name) class AlgoStack(Algo): """ An AlgoStack derives from Algo runs multiple Algos until a failure is encountered. The purpose of an AlgoStack is to group a logic set of Algos together. Each Algo in the stack is run. Execution stops if one Algo returns False. Args: * algos (list): List of algos. """ def __init__(self, *algos): super(AlgoStack, self).__init__() self.algos = algos self.check_run_always = any(hasattr(x, 'run_always') for x in self.algos) def __call__(self, target): # normal runing mode if not self.check_run_always: for algo in self.algos: if not algo(target): return False return True # run mode when at least one algo has a run_always attribute else: # store result in res # allows continuation to check for and run # algos that have run_always set to True res = True for algo in self.algos: if res: res = algo(target) elif hasattr(algo, 'run_always'): if algo.run_always: algo(target) return res class Strategy(StrategyBase): """ Strategy expands on the StrategyBase and incorporates Algos. Basically, a Strategy is built by passing in a set of algos. These algos will be placed in an Algo stack and the run function will call the stack. Furthermore, two class attributes are created to pass data between algos. perm for permanent data, temp for temporary data. Args: * name (str): Strategy name * algos (list): List of Algos to be passed into an AlgoStack * children (dict, list): Children - useful when you want to create strategies of strategies Attributes: * stack (AlgoStack): The stack * temp (dict): A dict containing temporary data - cleared on each call to run. This can be used to pass info to other algos. * perm (dict): Permanent data used to pass info from one algo to another. Not cleared on each pass. """ def __init__(self, name, algos=[], children=None): super(Strategy, self).__init__(name, children=children) self.stack = AlgoStack(*algos) self.temp = {} self.perm = {} def run(self): # clear out temp data self.temp = {} # run algo stack self.stack(self) # run children for c in self.children.values(): c.run()
apache-2.0
[ 624, 199, 6906, 314, 6170, 10015, 5664, 402, 314, 10059, 14, 199, 624, 199, 646, 3473, 199, 504, 1331, 492, 14800, 199, 199, 646, 10634, 465, 6454, 199, 646, 2680, 465, 980, 199, 646, 29348, 465, 6325, 421, 199, 533, 5013, 8, 785, 304, 339, 408, 272, 710, 5013, 365, 314, 2446, 10015, 1853, 315, 22342, 1159, 3123, 5523, 12899, 14, 272, 17650, 8303, 5374, 1563, 436, 13863, 1563, 8287, 5013, 14, 2779, 3509, 314, 272, 6170, 9330, 402, 282, 3123, 1031, 14, 339, 3033, 26, 267, 627, 536, 334, 495, 304, 710, 5013, 536, 267, 627, 1676, 334, 1716, 304, 710, 1676, 5013, 267, 627, 4978, 334, 807, 12, 769, 304, 437, 3245, 402, 4978, 14, 982, 1211, 12, 288, 314, 1475, 365, 469, 354, 26, 1982, 1386, 340, 769, 2066, 769, 402, 4978, 14, 339, 9382, 26, 267, 627, 536, 334, 495, 304, 5013, 536, 267, 627, 1676, 334, 1716, 304, 5013, 1676, 267, 627, 1738, 334, 1716, 304, 12826, 1031, 402, 314, 3123, 334, 2119, 2786, 1031, 9, 267, 627, 4978, 334, 807, 304, 5013, 1159, 4978, 267, 627, 3063, 334, 2083, 304, 8051, 1380, 1771, 4776, 370, 3877, 1453, 1434, 267, 627, 20149, 334, 2245, 304, 18241, 1202, 370, 6705, 340, 5013, 365, 20149, 436, 1929, 288, 12928, 267, 627, 1979, 823, 334, 30887, 304, 8538, 823, 402, 314, 5013, 14, 8538, 823, 367, 282, 6391, 911, 288, 506, 314, 6391, 1159, 8033, 12, 367, 282, 10054, 652, 911, 506, 376, 1478, 626, 288, 16806, 83, 314, 574, 402, 314, 10054, 1806, 900, 14, 267, 627, 8033, 334, 1609, 304, 2061, 8033, 267, 627, 574, 334, 1609, 304, 2061, 574, 267, 627, 5401, 334, 1609, 304, 5401, 315, 1676, 267, 627, 2615, 63, 354, 334, 495, 304, 2812, 5893, 8623, 7, 1561, 267, 627, 7556, 334, 513, 304, 9338, 5013, 435, 1031, 1159, 4978, 339, 408, 339, 485, 4777, 275, 6325, 14, 16536, 8, 1480, 14, 3157, 9, 272, 485, 585, 275, 6325, 14, 16536, 8, 1480, 14, 3157, 9, 272, 485, 3463, 275, 6325, 14, 16536, 8, 1480, 14, 3157, 9, 272, 485, 374, 3321, 275, 6325, 14, 16536, 8, 1480, 14, 66, 442, 9, 272, 485, 1989, 63, 495, 292, 63, 3223, 275, 6325, 14, 16536, 8, 1480, 14, 66, 442, 9, 339, 347, 636, 826, 721, 277, 12, 536, 12, 1676, 29, 403, 12, 4978, 29, 403, 304, 398, 291, 14, 354, 275, 536, 398, 327, 10054, 4978, 10897, 267, 291, 423, 1989, 63, 495, 292, 63, 3223, 275, 756, 267, 291, 423, 495, 292, 63, 3223, 275, 942, 398, 327, 340, 4978, 365, 440, 488, 12, 781, 5534, 626, 781, 2934, 370, 2304, 314, 267, 327, 2808, 4978, 4601, 370, 314, 2741, 769, 14, 267, 340, 4978, 365, 440, 488, 26, 288, 340, 1228, 8, 3223, 12, 769, 304, 355, 327, 340, 1006, 3326, 446, 2951, 3354, 465, 15439, 2077, 63, 1541, 355, 340, 1006, 8, 6074, 8, 88, 12, 620, 9, 367, 671, 315, 4978, 304, 490, 291, 423, 30519, 63, 8284, 1192, 275, 4978, 490, 327, 2701, 1211, 446, 2793, 1133, 2934, 370, 31291, 590, 1218, 490, 327, 307, 4654, 402, 4978, 1380, 2985, 5594, 440, 506, 4346, 490, 4978, 275, 1052, 355, 587, 26, 490, 327, 642, 911, 506, 1930, 340, 781, 986, 315, 4978, 490, 327, 334, 19787, 282, 22219, 402, 1007, 13, 20694, 1500, 9, 490, 3529, 275, 1052, 490, 11430, 275, 942, 490, 367, 286, 315, 4978, 26, 717, 340, 730, 8, 67, 9, 508, 620, 26, 1169, 3529, 59, 67, 61, 275, 13863, 1563, 8, 67, 9, 1169, 11430, 14, 740, 8, 67, 9, 717, 587, 26, 1169, 327, 14800, 909, 367, 3962, 2945, 12598, 1169, 3529, 59, 67, 14, 354, 61, 275, 14800, 8, 67, 9, 18008, 327, 340, 10054, 12, 7485, 641, 3305, 436, 1050, 536, 370, 769, 1169, 327, 10054, 4978, 1172, 4539, 14312, 434, 1169, 340, 1228, 8, 67, 12, 8303, 5374, 1563, 304, 1816, 291, 423, 1989, 63, 495, 292, 63, 3223, 275, 715, 1816, 291, 423, 495, 292, 63, 3223, 14, 740, 8, 67, 14, 354, 9, 1169, 327, 340, 440, 10054, 12, 2066, 781, 911, 2934, 370, 1050, 642, 370, 1169, 327, 15439, 2077, 63, 8284, 1192, 370, 2457, 641, 3272, 1169, 587, 26, 1816, 11430, 14, 740, 8, 67, 14, 354, 9, 4951, 4978, 275, 3529, 490, 327, 781, 2934, 370, 4215, 8852, 15439, 2077, 315, 642, 1930, 490, 327, 880, 663, 370, 488, 490, 291, 423, 30519, 63, 8284, 1192, 275, 11430, 398, 340, 1676, 365, 488, 26, 288, 291, 14, 1708, 275, 291, 288, 291, 14, 1231, 275, 291, 267, 587, 26, 288, 291, 14, 1708, 275, 1676, 288, 291, 14, 1231, 275, 1676, 14, 1231, 288, 1676, 423, 525, 63, 1739, 8, 277, 9, 398, 327, 849, 4978, 267, 340, 4978, 365, 488, 26, 288, 4978, 275, 1052, 288, 291, 423, 30519, 63, 8284, 1192, 275, 488, 267, 291, 14, 3223, 275, 4978, 398, 291, 423, 3223, 86, 275, 4978, 14, 1459, 342, 267, 367, 286, 315, 291, 423, 3223, 86, 26, 288, 286, 14, 1708, 275, 291, 288, 286, 14, 1231, 275, 291, 14, 1231, 398, 327, 663, 849, 574, 367, 3063, 267, 291, 14, 2131, 275, 378, 267, 327, 1852, 3238, 1738, 965, 20149, 3305, 267, 327, 1202, 370, 5126, 625, 78, 5205, 1678, 267, 327, 15026, 781, 1570, 1338, 315, 314, 3123, 436, 781, 5715, 626, 781, 911, 1929, 267, 327, 370, 1678, 340, 4573, 1031, 11275, 370, 2879, 282, 1627, 574, 334, 19787, 5401, 680, 267, 327, 961, 5126, 6358, 314, 1678, 5133, 652, 365, 5965, 4346, 14, 267, 291, 14, 1231, 14, 20102, 275, 756, 398, 327, 5922, 6802, 267, 291, 423, 4777, 275, 378, 267, 291, 423, 585, 275, 378, 267, 291, 423, 3463, 275, 378, 398, 327, 365, 6391, 3305, 446, 1202, 370, 5126, 12928, 378, 2086, 542, 895, 12107, 267, 291, 423, 374, 3321, 275, 756, 339, 347, 636, 6095, 721, 277, 12, 790, 304, 267, 372, 291, 14, 3223, 59, 498, 61, 339, 768, 1829, 272, 347, 1979, 823, 8, 277, 304, 267, 408, 267, 437, 4703, 9641, 402, 314, 5013, 1159, 8033, 14, 267, 408, 267, 327, 883 ]
[ 199, 6906, 314, 6170, 10015, 5664, 402, 314, 10059, 14, 199, 624, 199, 646, 3473, 199, 504, 1331, 492, 14800, 199, 199, 646, 10634, 465, 6454, 199, 646, 2680, 465, 980, 199, 646, 29348, 465, 6325, 421, 199, 533, 5013, 8, 785, 304, 339, 408, 272, 710, 5013, 365, 314, 2446, 10015, 1853, 315, 22342, 1159, 3123, 5523, 12899, 14, 272, 17650, 8303, 5374, 1563, 436, 13863, 1563, 8287, 5013, 14, 2779, 3509, 314, 272, 6170, 9330, 402, 282, 3123, 1031, 14, 339, 3033, 26, 267, 627, 536, 334, 495, 304, 710, 5013, 536, 267, 627, 1676, 334, 1716, 304, 710, 1676, 5013, 267, 627, 4978, 334, 807, 12, 769, 304, 437, 3245, 402, 4978, 14, 982, 1211, 12, 288, 314, 1475, 365, 469, 354, 26, 1982, 1386, 340, 769, 2066, 769, 402, 4978, 14, 339, 9382, 26, 267, 627, 536, 334, 495, 304, 5013, 536, 267, 627, 1676, 334, 1716, 304, 5013, 1676, 267, 627, 1738, 334, 1716, 304, 12826, 1031, 402, 314, 3123, 334, 2119, 2786, 1031, 9, 267, 627, 4978, 334, 807, 304, 5013, 1159, 4978, 267, 627, 3063, 334, 2083, 304, 8051, 1380, 1771, 4776, 370, 3877, 1453, 1434, 267, 627, 20149, 334, 2245, 304, 18241, 1202, 370, 6705, 340, 5013, 365, 20149, 436, 1929, 288, 12928, 267, 627, 1979, 823, 334, 30887, 304, 8538, 823, 402, 314, 5013, 14, 8538, 823, 367, 282, 6391, 911, 288, 506, 314, 6391, 1159, 8033, 12, 367, 282, 10054, 652, 911, 506, 376, 1478, 626, 288, 16806, 83, 314, 574, 402, 314, 10054, 1806, 900, 14, 267, 627, 8033, 334, 1609, 304, 2061, 8033, 267, 627, 574, 334, 1609, 304, 2061, 574, 267, 627, 5401, 334, 1609, 304, 5401, 315, 1676, 267, 627, 2615, 63, 354, 334, 495, 304, 2812, 5893, 8623, 7, 1561, 267, 627, 7556, 334, 513, 304, 9338, 5013, 435, 1031, 1159, 4978, 339, 408, 339, 485, 4777, 275, 6325, 14, 16536, 8, 1480, 14, 3157, 9, 272, 485, 585, 275, 6325, 14, 16536, 8, 1480, 14, 3157, 9, 272, 485, 3463, 275, 6325, 14, 16536, 8, 1480, 14, 3157, 9, 272, 485, 374, 3321, 275, 6325, 14, 16536, 8, 1480, 14, 66, 442, 9, 272, 485, 1989, 63, 495, 292, 63, 3223, 275, 6325, 14, 16536, 8, 1480, 14, 66, 442, 9, 339, 347, 636, 826, 721, 277, 12, 536, 12, 1676, 29, 403, 12, 4978, 29, 403, 304, 398, 291, 14, 354, 275, 536, 398, 327, 10054, 4978, 10897, 267, 291, 423, 1989, 63, 495, 292, 63, 3223, 275, 756, 267, 291, 423, 495, 292, 63, 3223, 275, 942, 398, 327, 340, 4978, 365, 440, 488, 12, 781, 5534, 626, 781, 2934, 370, 2304, 314, 267, 327, 2808, 4978, 4601, 370, 314, 2741, 769, 14, 267, 340, 4978, 365, 440, 488, 26, 288, 340, 1228, 8, 3223, 12, 769, 304, 355, 327, 340, 1006, 3326, 446, 2951, 3354, 465, 15439, 2077, 63, 1541, 355, 340, 1006, 8, 6074, 8, 88, 12, 620, 9, 367, 671, 315, 4978, 304, 490, 291, 423, 30519, 63, 8284, 1192, 275, 4978, 490, 327, 2701, 1211, 446, 2793, 1133, 2934, 370, 31291, 590, 1218, 490, 327, 307, 4654, 402, 4978, 1380, 2985, 5594, 440, 506, 4346, 490, 4978, 275, 1052, 355, 587, 26, 490, 327, 642, 911, 506, 1930, 340, 781, 986, 315, 4978, 490, 327, 334, 19787, 282, 22219, 402, 1007, 13, 20694, 1500, 9, 490, 3529, 275, 1052, 490, 11430, 275, 942, 490, 367, 286, 315, 4978, 26, 717, 340, 730, 8, 67, 9, 508, 620, 26, 1169, 3529, 59, 67, 61, 275, 13863, 1563, 8, 67, 9, 1169, 11430, 14, 740, 8, 67, 9, 717, 587, 26, 1169, 327, 14800, 909, 367, 3962, 2945, 12598, 1169, 3529, 59, 67, 14, 354, 61, 275, 14800, 8, 67, 9, 18008, 327, 340, 10054, 12, 7485, 641, 3305, 436, 1050, 536, 370, 769, 1169, 327, 10054, 4978, 1172, 4539, 14312, 434, 1169, 340, 1228, 8, 67, 12, 8303, 5374, 1563, 304, 1816, 291, 423, 1989, 63, 495, 292, 63, 3223, 275, 715, 1816, 291, 423, 495, 292, 63, 3223, 14, 740, 8, 67, 14, 354, 9, 1169, 327, 340, 440, 10054, 12, 2066, 781, 911, 2934, 370, 1050, 642, 370, 1169, 327, 15439, 2077, 63, 8284, 1192, 370, 2457, 641, 3272, 1169, 587, 26, 1816, 11430, 14, 740, 8, 67, 14, 354, 9, 4951, 4978, 275, 3529, 490, 327, 781, 2934, 370, 4215, 8852, 15439, 2077, 315, 642, 1930, 490, 327, 880, 663, 370, 488, 490, 291, 423, 30519, 63, 8284, 1192, 275, 11430, 398, 340, 1676, 365, 488, 26, 288, 291, 14, 1708, 275, 291, 288, 291, 14, 1231, 275, 291, 267, 587, 26, 288, 291, 14, 1708, 275, 1676, 288, 291, 14, 1231, 275, 1676, 14, 1231, 288, 1676, 423, 525, 63, 1739, 8, 277, 9, 398, 327, 849, 4978, 267, 340, 4978, 365, 488, 26, 288, 4978, 275, 1052, 288, 291, 423, 30519, 63, 8284, 1192, 275, 488, 267, 291, 14, 3223, 275, 4978, 398, 291, 423, 3223, 86, 275, 4978, 14, 1459, 342, 267, 367, 286, 315, 291, 423, 3223, 86, 26, 288, 286, 14, 1708, 275, 291, 288, 286, 14, 1231, 275, 291, 14, 1231, 398, 327, 663, 849, 574, 367, 3063, 267, 291, 14, 2131, 275, 378, 267, 327, 1852, 3238, 1738, 965, 20149, 3305, 267, 327, 1202, 370, 5126, 625, 78, 5205, 1678, 267, 327, 15026, 781, 1570, 1338, 315, 314, 3123, 436, 781, 5715, 626, 781, 911, 1929, 267, 327, 370, 1678, 340, 4573, 1031, 11275, 370, 2879, 282, 1627, 574, 334, 19787, 5401, 680, 267, 327, 961, 5126, 6358, 314, 1678, 5133, 652, 365, 5965, 4346, 14, 267, 291, 14, 1231, 14, 20102, 275, 756, 398, 327, 5922, 6802, 267, 291, 423, 4777, 275, 378, 267, 291, 423, 585, 275, 378, 267, 291, 423, 3463, 275, 378, 398, 327, 365, 6391, 3305, 446, 1202, 370, 5126, 12928, 378, 2086, 542, 895, 12107, 267, 291, 423, 374, 3321, 275, 756, 339, 347, 636, 6095, 721, 277, 12, 790, 304, 267, 372, 291, 14, 3223, 59, 498, 61, 339, 768, 1829, 272, 347, 1979, 823, 8, 277, 304, 267, 408, 267, 437, 4703, 9641, 402, 314, 5013, 1159, 8033, 14, 267, 408, 267, 327, 883, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
adamkovics/atmosphere
atmosphere/gas_opacity.py
1
8280
""" Add gas opacities to model based on the composition and vertical structure. """ import numpy as np import logging logger = logging.getLogger() def interpolate_kc(p, T, kc, verbose=False): """Linearly interpolate k-coefficients at a particular pressure and temperature, using the input k-coefficent grid, kc. The standard structure of k-coefficient data array is: [wavelengths,pressures,temperatures,g-nodes] where the g-node are the Legendre-Gauss quadrature nodes or "g-ordinate". Returned array of coefficients corresponds to: [wavelengths,g-nodes] """ pressures = np.array(kc['pressures']) temperatures = np.array(kc['temperatures']) ind_p = np.where(pressures < p) ind_T = np.where(temperatures < T) i = (np.max(ind_p) if np.size(ind_p) else np.array(0)).clip(0,len(pressures)-2) j = (np.max(ind_T) if np.size(ind_T) else np.array(0)).clip(0,len(temperatures)-2) L11 = np.log(kc['kc'][:,i,j,:]) L12 = np.log(kc['kc'][:,i+1,j,:]) L21 = np.log(kc['kc'][:,i,j+1,:]) L22 = np.log(kc['kc'][:,i+1,j+1,:]) L1T = L11 + (L12-L11)*(T-temperatures[j])/(temperatures[j+1]-temperatures[j]) L2T = L21 + (L22-L21)*(T-temperatures[j])/(temperatures[j+1]-temperatures[j]) LPT = L1T + (L2T-L1T)*((np.log(p)-np.log(pressures[i]))/ (np.log(pressures[i+1])-np.log(pressures[i]))) kc_interp = np.exp(LPT) return kc_interp def append_kc_to_layers(model, kc, species): """Set k-coefficients for each layer by interpolating to appropriate temperature and pressure and update the data structure for the amtosphere.""" kc_shape = (model['nlay'], model['nlam'], kc['ng']) model['layers'].update({'kc':{species:np.ndarray(kc_shape), 'ng':kc['ng'], 'g':kc['g'], 'w':kc['w'], }}) for i in range(model['nlay']): model['layers']['kc'][species][i,:,:] = interpolate_kc(model['layers']['p'][i], model['layers']['T'][i], kc) return # There are additional k-coefficients for C2H2, C2H6, and CO. # These are currently calculated on the VIMS grid as they are applicable in # roughly the 2.7--3um wavelength region that is inacccessible from the ground. # # Here we revise the gas opacity in the model to include multiple k-coefficient files. # # It is a reasonable estimate to sum k-coefficients after interpolating each onto the # same pressure and temperature, however, a minimal amount of error-checking should confirm # that the same wavelength grid and g-ordinates are being used. # # Overview of revisions to the code: # # (1) Generalization of the set_methane() to other species. # (2) Error-checking for wavelength (and P,T) grid # (3) back-compatibility for set_methane() method. # (4) Some thought to CH3D abundance variability. # def set_methane(model, kc_file, CH3D_scale=None, verbose=False): """Set methane opacities in atmosphere structure, model, by interpolatating k-coefficents from the specied kc_file, using the temperatures and pressures for each layer. """ if CH3D_scale: if len(kc_file) != 2: logger.debug('two k-coefficient files needed for set_methane_opacity()') return None kc = np.load(kc_file[0]).item() kc_CH3D = np.load(kc_file[1]).item() kc['kc'] = kc['kc']+CH3D_scale*kc_CH3D['kc'] model.update({'wavelength':kc['wavelength']['mu'], 'nlam':kc['wavelength']['nlam'], }) append_kc_to_layers(model, kc, 'CH4') tau_CH4 = model['layers']['kc']['CH4'] * np.reshape(model['layers']['N_CH4'], (model['nlay'],1,1)) if 'tau' not in model['layers']: model['layers'].update({'tau':{}}) model['layers']['tau'].update({'CH4':tau_CH4}) return if kc_file.endswith('.npy'): kc = np.load(kc_file).item() model.update({'wavelength':kc['wavelength']['mu'], 'nlam':kc['wavelength']['nlam'], }) append_kc_to_layers(model, kc, 'CH4') tau_CH4 = model['layers']['kc']['CH4'] * np.reshape(model['layers']['N_CH4'], (model['nlay'],1,1)) if 'tau' not in model['layers']: model['layers'].update({'tau':{}}) model['layers']['tau'].update({'CH4':tau_CH4}) return if kc_file.endswith('.fits'): import pyfits hdu = pyfits.open(kc_file) kc = {'kc': hdu[0].data, 'pressures':hdu[2].data['pressures'], 'temperatures':hdu[3].data['temperatures'], 'g': hdu[4].data['g'], 'w': hdu[5].data['w'], 'ng': hdu[0].header['NG'], } model.update({'wavelength':hdu[1].data['wavelength'], 'nlam':len(hdu[1].data['wavelength']), }) hdu.close() append_kc_to_layers(model, kc, 'CH4') tau_CH4 = model['layers']['kc']['CH4'] * np.reshape(model['layers']['N_CH4'], (model['nlay'],1,1)) if 'tau' not in model['layers']: model['layers'].update({'tau':{}}) model['layers']['tau'].update({'CH4':tau_CH4}) return def print_atmosphere_details(model): logger.debug('model dictionary data structure:') for item in model.keys(): logger.debug("{0:7s} - type: {2} - shape: {1}".format( item, np.shape(model[item]), type(model[item]))) logger.debug("\natmosphere['layers'] dictionary data structure:") for item in model['layers'].keys(): logger.debug("{0:7s} - type: {2} - shape: {1}".format( item, np.shape(model['layers'][item]), type(model['layers'][item]))) def set_cia(model, scale=4.0, show_figure=False): """Append collision-induced-absorption opacity for N2-N2 and H2-N2 (in the near-IR) to the atmosphere data structure, model.""" import pyfits import os fits = pyfits.open(os.path.join(os.getenv('RTDATAPATH'), 'gas_opacity/CIA/N2_N2.fits')) k_N2N2 = fits[0].data fits.close() fits = pyfits.open(os.path.join(os.getenv('RTDATAPATH'), 'gas_opacity/CIA/H2_N2.fits')) k_H2N2 = fits[0].data fits.close() if 'wavelength' not in model.keys(): logger.warning('Set wavelength scale first (e.g., with CH4 opacity.)') return None tau_H2N2 = np.empty((model['nlay'],model['nlam'])) tau_N2N2 = np.empty((model['nlay'],model['nlam'])) layers = model['layers'] N0 = 2.686e19 # Loschmidt number for i in range(model['nlay']): k_H2N2_interp = np.interp(model['wavelength'], (1e4/k_H2N2[::-1,0]), scale*k_H2N2[::-1,1],) k_N2N2_interp = np.interp(model['wavelength'], (1e4/k_N2N2[::-1,0]), scale*k_N2N2[::-1,1],) tau_H2N2[i,:] = k_H2N2_interp*layers['kmamg'][i] * \ layers['n'][i]/N0 * \ layers['m_N2'][i]*layers['m_H2'] tau_N2N2[i,:] = k_N2N2_interp*layers['kmamg'][i] * \ layers['n'][i]/N0 * \ layers['m_N2'][i]*layers['m_N2'][i] layers['tau'].update({'H2_N2':tau_H2N2, 'N2_N2':tau_N2N2,}) if show_figure: fig, ax = subplots(figsize=(16,4)) ax.plot(k_H2N2[:,0], k_H2N2[:,1], 'k', drawstyle='steps-mid') ax.set_xlabel('wavenumber (cm$^{-1}$)') ax.set_ylabel(r'km$^{-1}$ amagat$^{-2}$') ax.set_xlim(4000,5000) fig, ax = subplots(figsize=(16,4)) ax.plot(k_N2N2[:,0], k_N2N2[:,1], 'k', drawstyle='steps-mid') ax.set_xlabel('wavenumber (cm$^{-1}$)') ax.set_ylabel(r'km$^{-1}$ amagat$^{-2}$') ax.set_xlim(4000,5000) ;
gpl-2.0
[ 624, 199, 1123, 486, 305, 312, 387, 18207, 370, 1402, 4079, 641, 314, 31586, 436, 13763, 5523, 14, 199, 624, 199, 199, 646, 2680, 465, 980, 199, 646, 2050, 199, 2921, 275, 2050, 14, 5572, 342, 199, 199, 318, 28884, 63, 75, 67, 8, 80, 12, 377, 12, 1022, 67, 12, 3376, 29, 797, 304, 272, 408, 10608, 590, 28884, 1022, 13, 30477, 737, 282, 6770, 5591, 25471, 436, 14843, 12, 1808, 314, 1324, 1022, 13, 8009, 1792, 484, 6068, 12, 1022, 67, 14, 272, 710, 4465, 5523, 402, 1022, 13, 21329, 666, 1625, 365, 26, 13857, 359, 10024, 14563, 12, 2915, 1482, 12, 808, 281, 2093, 12, 71, 13, 2415, 61, 2286, 2382, 314, 486, 13, 932, 787, 314, 29420, 13, 39, 23822, 16744, 30985, 3380, 272, 503, 298, 71, 13, 4055, 323, 1674, 19907, 1625, 402, 12343, 13718, 370, 26, 2728, 359, 10024, 14563, 12, 71, 13, 2415, 61, 272, 408, 2286, 15105, 1482, 275, 980, 14, 1144, 8, 75, 67, 459, 2915, 1482, 1105, 272, 2388, 281, 2093, 275, 980, 14, 1144, 8, 75, 67, 459, 808, 281, 2093, 1105, 2286, 7654, 63, 80, 275, 980, 14, 4509, 8, 2915, 1482, 665, 299, 9, 272, 7654, 63, 52, 275, 980, 14, 4509, 8, 808, 281, 2093, 665, 377, 9, 339, 284, 275, 334, 1590, 14, 988, 8, 688, 63, 80, 9, 340, 980, 14, 890, 8, 688, 63, 80, 9, 587, 980, 14, 1144, 8, 16, 4992, 7548, 8, 16, 12, 552, 8, 2915, 1482, 7216, 18, 9, 5591, 1335, 275, 334, 1590, 14, 988, 8, 688, 63, 52, 9, 340, 980, 14, 890, 8, 688, 63, 52, 9, 587, 980, 14, 1144, 8, 16, 4992, 7548, 8, 16, 12, 552, 8, 808, 281, 2093, 7216, 18, 9, 339, 491, 845, 275, 980, 14, 793, 8, 75, 67, 459, 75, 67, 418, 3981, 73, 12, 74, 12, 5728, 272, 491, 713, 275, 980, 14, 793, 8, 75, 67, 459, 75, 67, 418, 3981, 73, 11, 17, 12, 74, 12, 5728, 272, 491, 2025, 275, 980, 14, 793, 8, 75, 67, 459, 75, 67, 418, 3981, 73, 12, 74, 11, 17, 12, 5728, 272, 491, 1081, 275, 980, 14, 793, 8, 75, 67, 459, 75, 67, 418, 3981, 73, 11, 17, 12, 74, 11, 17, 12, 5728, 339, 491, 17, 52, 275, 491, 845, 435, 334, 44, 713, 13, 44, 845, 14397, 52, 13, 808, 281, 2093, 59, 74, 566, 7985, 808, 281, 2093, 59, 74, 11, 17, 11285, 808, 281, 2093, 59, 74, 566, 272, 491, 18, 52, 275, 491, 2025, 435, 334, 44, 1081, 13, 44, 2025, 14397, 52, 13, 808, 281, 2093, 59, 74, 566, 7985, 808, 281, 2093, 59, 74, 11, 17, 11285, 808, 281, 2093, 59, 74, 566, 272, 491, 4189, 275, 491, 17, 52, 435, 334, 44, 18, 52, 13, 44, 17, 52, 3342, 1332, 1590, 14, 793, 8, 80, 7216, 1590, 14, 793, 8, 2915, 1482, 59, 73, 2459, 15, 2574, 334, 1590, 14, 793, 8, 2915, 1482, 59, 73, 11, 17, 566, 13, 1590, 14, 793, 8, 2915, 1482, 59, 73, 11845, 272, 1022, 67, 63, 14252, 275, 980, 14, 1474, 8, 44, 4189, 9, 272, 372, 1022, 67, 63, 14252, 199, 199, 318, 5666, 63, 75, 67, 63, 475, 63, 4359, 8, 1238, 12, 1022, 67, 12, 20340, 304, 272, 408, 1084, 1022, 13, 30477, 367, 1924, 4045, 701, 23005, 1958, 272, 370, 5827, 14843, 436, 25471, 436, 1678, 314, 5591, 666, 5523, 367, 314, 8140, 475, 14980, 1041, 2286, 1022, 67, 63, 1392, 275, 334, 1238, 459, 78, 817, 995, 1402, 459, 78, 17984, 995, 1022, 67, 459, 2753, 1105, 272, 1402, 459, 4359, 2278, 873, 3252, 75, 67, 356, 91, 17168, 26, 1590, 14, 8237, 8, 75, 67, 63, 1392, 395, 1816, 283, 2753, 356, 75, 67, 459, 2753, 995, 1816, 283, 71, 356, 75, 67, 459, 71, 995, 1816, 283, 87, 356, 75, 67, 459, 87, 995, 1816, 789, 1552, 14821, 367, 284, 315, 1425, 8, 1238, 459, 78, 817, 9090, 267, 1402, 459, 4359, 2545, 75, 67, 3488, 17168, 1527, 73, 32306, 2938, 275, 28884, 63, 75, 67, 8, 1238, 459, 4359, 2545, 80, 3488, 73, 467, 18193, 1402, 459, 4359, 2545, 52, 3488, 73, 467, 18193, 1022, 67, 9, 272, 372, 421, 199, 3, 6006, 787, 4722, 1022, 13, 30477, 367, 445, 18, 40, 18, 12, 445, 18, 40, 22, 12, 436, 5099, 14, 221, 199, 3, 5723, 221, 787, 5544, 12950, 641, 314, 812, 1469, 51, 6068, 465, 2985, 787, 3964, 315, 221, 199, 3, 28568, 590, 314, 499, 14, 23, 306, 19, 453, 12204, 1267, 4897, 626, 365, 315, 5470, 13339, 687, 314, 19252, 14, 199, 3, 199, 3, 11842, 781, 295, 433, 261, 314, 486, 305, 31835, 315, 314, 1402, 370, 2387, 3663, 1022, 13, 21329, 1584, 14, 221, 199, 3, 199, 3, 2779, 365, 282, 23255, 14497, 370, 3089, 1022, 13, 30477, 2410, 23005, 1958, 1924, 14602, 314, 221, 199, 3, 2011, 25471, 436, 14843, 12, 13432, 12, 282, 13460, 5982, 402, 1125, 13, 19527, 1077, 12679, 199, 3, 626, 314, 2011, 12204, 1267, 6068, 436, 486, 13, 4055, 2335, 787, 3769, 1202, 14, 199, 3, 199, 3, 7259, 1345, 402, 22164, 370, 314, 1233, 26, 199, 3, 199, 3, 259, 334, 17, 9, 1696, 2072, 402, 314, 663, 63, 5247, 5865, 342, 370, 1163, 20340, 14, 199, 3, 259, 334, 18, 9, 4520, 13, 19527, 367, 12204, 1267, 334, 460, 510, 12, 52, 9, 6068, 199, 3, 259, 334, 19, 9, 1771, 13, 15390, 367, 663, 63, 5247, 5865, 342, 1083, 14, 199, 3, 259, 334, 20, 9, 6601, 32463, 370, 6624, 19, 36, 2236, 725, 554, 4172, 3616, 14, 199, 3, 199, 199, 318, 663, 63, 5247, 5865, 8, 1238, 12, 1022, 67, 63, 493, 12, 6624, 19, 36, 63, 3467, 29, 403, 12, 3376, 29, 797, 304, 272, 408, 1084, 12750, 5865, 312, 387, 18207, 315, 737, 573, 14980, 5523, 12, 1402, 12, 701, 5591, 23005, 292, 1958, 1022, 13, 8009, 1792, 24871, 687, 314, 1106, 379, 1022, 67, 63, 493, 12, 272, 1808, 314, 2388, 281, 2093, 436, 15105, 1482, 367, 1924, 4045, 14, 5591, 408, 339, 340, 6624, 19 ]
[ 199, 1123, 486, 305, 312, 387, 18207, 370, 1402, 4079, 641, 314, 31586, 436, 13763, 5523, 14, 199, 624, 199, 199, 646, 2680, 465, 980, 199, 646, 2050, 199, 2921, 275, 2050, 14, 5572, 342, 199, 199, 318, 28884, 63, 75, 67, 8, 80, 12, 377, 12, 1022, 67, 12, 3376, 29, 797, 304, 272, 408, 10608, 590, 28884, 1022, 13, 30477, 737, 282, 6770, 5591, 25471, 436, 14843, 12, 1808, 314, 1324, 1022, 13, 8009, 1792, 484, 6068, 12, 1022, 67, 14, 272, 710, 4465, 5523, 402, 1022, 13, 21329, 666, 1625, 365, 26, 13857, 359, 10024, 14563, 12, 2915, 1482, 12, 808, 281, 2093, 12, 71, 13, 2415, 61, 2286, 2382, 314, 486, 13, 932, 787, 314, 29420, 13, 39, 23822, 16744, 30985, 3380, 272, 503, 298, 71, 13, 4055, 323, 1674, 19907, 1625, 402, 12343, 13718, 370, 26, 2728, 359, 10024, 14563, 12, 71, 13, 2415, 61, 272, 408, 2286, 15105, 1482, 275, 980, 14, 1144, 8, 75, 67, 459, 2915, 1482, 1105, 272, 2388, 281, 2093, 275, 980, 14, 1144, 8, 75, 67, 459, 808, 281, 2093, 1105, 2286, 7654, 63, 80, 275, 980, 14, 4509, 8, 2915, 1482, 665, 299, 9, 272, 7654, 63, 52, 275, 980, 14, 4509, 8, 808, 281, 2093, 665, 377, 9, 339, 284, 275, 334, 1590, 14, 988, 8, 688, 63, 80, 9, 340, 980, 14, 890, 8, 688, 63, 80, 9, 587, 980, 14, 1144, 8, 16, 4992, 7548, 8, 16, 12, 552, 8, 2915, 1482, 7216, 18, 9, 5591, 1335, 275, 334, 1590, 14, 988, 8, 688, 63, 52, 9, 340, 980, 14, 890, 8, 688, 63, 52, 9, 587, 980, 14, 1144, 8, 16, 4992, 7548, 8, 16, 12, 552, 8, 808, 281, 2093, 7216, 18, 9, 339, 491, 845, 275, 980, 14, 793, 8, 75, 67, 459, 75, 67, 418, 3981, 73, 12, 74, 12, 5728, 272, 491, 713, 275, 980, 14, 793, 8, 75, 67, 459, 75, 67, 418, 3981, 73, 11, 17, 12, 74, 12, 5728, 272, 491, 2025, 275, 980, 14, 793, 8, 75, 67, 459, 75, 67, 418, 3981, 73, 12, 74, 11, 17, 12, 5728, 272, 491, 1081, 275, 980, 14, 793, 8, 75, 67, 459, 75, 67, 418, 3981, 73, 11, 17, 12, 74, 11, 17, 12, 5728, 339, 491, 17, 52, 275, 491, 845, 435, 334, 44, 713, 13, 44, 845, 14397, 52, 13, 808, 281, 2093, 59, 74, 566, 7985, 808, 281, 2093, 59, 74, 11, 17, 11285, 808, 281, 2093, 59, 74, 566, 272, 491, 18, 52, 275, 491, 2025, 435, 334, 44, 1081, 13, 44, 2025, 14397, 52, 13, 808, 281, 2093, 59, 74, 566, 7985, 808, 281, 2093, 59, 74, 11, 17, 11285, 808, 281, 2093, 59, 74, 566, 272, 491, 4189, 275, 491, 17, 52, 435, 334, 44, 18, 52, 13, 44, 17, 52, 3342, 1332, 1590, 14, 793, 8, 80, 7216, 1590, 14, 793, 8, 2915, 1482, 59, 73, 2459, 15, 2574, 334, 1590, 14, 793, 8, 2915, 1482, 59, 73, 11, 17, 566, 13, 1590, 14, 793, 8, 2915, 1482, 59, 73, 11845, 272, 1022, 67, 63, 14252, 275, 980, 14, 1474, 8, 44, 4189, 9, 272, 372, 1022, 67, 63, 14252, 199, 199, 318, 5666, 63, 75, 67, 63, 475, 63, 4359, 8, 1238, 12, 1022, 67, 12, 20340, 304, 272, 408, 1084, 1022, 13, 30477, 367, 1924, 4045, 701, 23005, 1958, 272, 370, 5827, 14843, 436, 25471, 436, 1678, 314, 5591, 666, 5523, 367, 314, 8140, 475, 14980, 1041, 2286, 1022, 67, 63, 1392, 275, 334, 1238, 459, 78, 817, 995, 1402, 459, 78, 17984, 995, 1022, 67, 459, 2753, 1105, 272, 1402, 459, 4359, 2278, 873, 3252, 75, 67, 356, 91, 17168, 26, 1590, 14, 8237, 8, 75, 67, 63, 1392, 395, 1816, 283, 2753, 356, 75, 67, 459, 2753, 995, 1816, 283, 71, 356, 75, 67, 459, 71, 995, 1816, 283, 87, 356, 75, 67, 459, 87, 995, 1816, 789, 1552, 14821, 367, 284, 315, 1425, 8, 1238, 459, 78, 817, 9090, 267, 1402, 459, 4359, 2545, 75, 67, 3488, 17168, 1527, 73, 32306, 2938, 275, 28884, 63, 75, 67, 8, 1238, 459, 4359, 2545, 80, 3488, 73, 467, 18193, 1402, 459, 4359, 2545, 52, 3488, 73, 467, 18193, 1022, 67, 9, 272, 372, 421, 199, 3, 6006, 787, 4722, 1022, 13, 30477, 367, 445, 18, 40, 18, 12, 445, 18, 40, 22, 12, 436, 5099, 14, 221, 199, 3, 5723, 221, 787, 5544, 12950, 641, 314, 812, 1469, 51, 6068, 465, 2985, 787, 3964, 315, 221, 199, 3, 28568, 590, 314, 499, 14, 23, 306, 19, 453, 12204, 1267, 4897, 626, 365, 315, 5470, 13339, 687, 314, 19252, 14, 199, 3, 199, 3, 11842, 781, 295, 433, 261, 314, 486, 305, 31835, 315, 314, 1402, 370, 2387, 3663, 1022, 13, 21329, 1584, 14, 221, 199, 3, 199, 3, 2779, 365, 282, 23255, 14497, 370, 3089, 1022, 13, 30477, 2410, 23005, 1958, 1924, 14602, 314, 221, 199, 3, 2011, 25471, 436, 14843, 12, 13432, 12, 282, 13460, 5982, 402, 1125, 13, 19527, 1077, 12679, 199, 3, 626, 314, 2011, 12204, 1267, 6068, 436, 486, 13, 4055, 2335, 787, 3769, 1202, 14, 199, 3, 199, 3, 7259, 1345, 402, 22164, 370, 314, 1233, 26, 199, 3, 199, 3, 259, 334, 17, 9, 1696, 2072, 402, 314, 663, 63, 5247, 5865, 342, 370, 1163, 20340, 14, 199, 3, 259, 334, 18, 9, 4520, 13, 19527, 367, 12204, 1267, 334, 460, 510, 12, 52, 9, 6068, 199, 3, 259, 334, 19, 9, 1771, 13, 15390, 367, 663, 63, 5247, 5865, 342, 1083, 14, 199, 3, 259, 334, 20, 9, 6601, 32463, 370, 6624, 19, 36, 2236, 725, 554, 4172, 3616, 14, 199, 3, 199, 199, 318, 663, 63, 5247, 5865, 8, 1238, 12, 1022, 67, 63, 493, 12, 6624, 19, 36, 63, 3467, 29, 403, 12, 3376, 29, 797, 304, 272, 408, 1084, 12750, 5865, 312, 387, 18207, 315, 737, 573, 14980, 5523, 12, 1402, 12, 701, 5591, 23005, 292, 1958, 1022, 13, 8009, 1792, 24871, 687, 314, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
hanlind/nova
nova/virt/xenapi/firewall.py
8
2689
# Copyright 2010 United States Government as represented by the # Administrator of the National Aeronautics and Space Administration. # All Rights Reserved. # Copyright (c) 2010 Citrix Systems, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from oslo_serialization import jsonutils from nova.virt import firewall class Dom0IptablesFirewallDriver(firewall.IptablesFirewallDriver): """Dom0IptablesFirewallDriver class This class provides an implementation for nova.virt.Firewall using iptables. This class is meant to be used with the xenapi backend and uses xenapi plugin to enforce iptables rules in dom0. """ def _plugin_execute(self, *cmd, **kwargs): # Prepare arguments for plugin call args = {} process_input = kwargs.get('process_input', None) if process_input is not None and isinstance(process_input, bytes): kwargs['process_input'] = process_input.decode('utf-8') args.update(map(lambda x: (x, str(kwargs[x])), kwargs)) args['cmd_args'] = jsonutils.dumps(cmd) ret = self._session.call_plugin('xenhost.py', 'iptables_config', args) json_ret = jsonutils.loads(ret) return (json_ret['out'], json_ret['err']) def __init__(self, xenapi_session=None, **kwargs): from nova.network import linux_net super(Dom0IptablesFirewallDriver, self).__init__(**kwargs) self._session = xenapi_session # Create IpTablesManager with executor through plugin self.iptables = linux_net.IptablesManager(self._plugin_execute) self.iptables.ipv4['filter'].add_chain('sg-fallback') self.iptables.ipv4['filter'].add_rule('sg-fallback', '-j DROP') self.iptables.ipv6['filter'].add_chain('sg-fallback') self.iptables.ipv6['filter'].add_rule('sg-fallback', '-j DROP') def _build_tcp_udp_rule(self, rule, version): if rule.from_port == rule.to_port: return ['--dport', '%s' % (rule.from_port,)] else: # No multiport needed for XS! return ['--dport', '%s:%s' % (rule.from_port, rule.to_port)]
apache-2.0
[ 3, 1898, 7129, 1910, 5703, 24230, 598, 27639, 465, 11159, 701, 314, 199, 3, 30660, 402, 314, 20548, 437, 281, 265, 3844, 7769, 436, 19326, 9516, 4633, 14, 199, 3, 2900, 5924, 5702, 14, 199, 3, 1898, 334, 67, 9, 7129, 445, 390, 1904, 15285, 12, 3277, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 504, 11258, 63, 12161, 492, 18705, 199, 199, 504, 5913, 14, 4549, 492, 12042, 421, 199, 533, 577, 676, 16, 41, 541, 5921, 24260, 6158, 8, 10794, 14, 41, 541, 5921, 24260, 6158, 304, 272, 408, 20106, 16, 41, 541, 5921, 24260, 6158, 1021, 339, 961, 1021, 6571, 376, 4514, 367, 5913, 14, 4549, 14, 24260, 272, 1808, 29458, 14, 961, 1021, 365, 18329, 370, 506, 1202, 543, 314, 20388, 1246, 272, 4865, 436, 4440, 20388, 1246, 3589, 370, 15814, 29458, 4713, 315, 8266, 16, 14, 272, 408, 272, 347, 485, 2718, 63, 2526, 8, 277, 12, 627, 1760, 12, 1011, 958, 304, 267, 327, 17008, 2368, 367, 3589, 1240, 267, 1249, 275, 1052, 267, 2112, 63, 1210, 275, 2074, 14, 362, 360, 1412, 63, 1210, 297, 488, 9, 267, 340, 2112, 63, 1210, 365, 440, 488, 436, 1228, 8, 1412, 63, 1210, 12, 2783, 304, 288, 2074, 459, 1412, 63, 1210, 418, 275, 2112, 63, 1210, 14, 2708, 360, 1624, 13, 24, 358, 267, 1249, 14, 873, 8, 1130, 8, 2734, 671, 26, 334, 88, 12, 620, 8, 958, 59, 88, 12884, 2074, 430, 267, 1249, 459, 1760, 63, 589, 418, 275, 18705, 14, 4180, 8, 1760, 9, 267, 2203, 275, 291, 423, 1730, 14, 1250, 63, 2718, 360, 13615, 1102, 14, 647, 297, 283, 23232, 63, 888, 297, 1249, 9, 267, 2022, 63, 3292, 275, 18705, 14, 3640, 8, 3292, 9, 267, 372, 334, 1001, 63, 3292, 459, 548, 995, 2022, 63, 3292, 459, 1508, 1105, 339, 347, 636, 826, 721, 277, 12, 20388, 1246, 63, 1730, 29, 403, 12, 1011, 958, 304, 267, 687, 5913, 14, 1200, 492, 18369, 63, 846, 267, 1613, 8, 20106, 16, 41, 541, 5921, 24260, 6158, 12, 291, 2843, 826, 14155, 958, 9, 267, 291, 423, 1730, 275, 20388, 1246, 63, 1730, 267, 327, 2790, 31045, 18845, 2988, 543, 13270, 4012, 3589, 267, 291, 14, 23232, 275, 18369, 63, 846, 14, 41, 541, 5921, 2988, 8, 277, 423, 2718, 63, 2526, 9, 267, 291, 14, 23232, 14, 4774, 20, 459, 1541, 2278, 525, 63, 4429, 360, 1226, 13, 10538, 358, 267, 291, 14, 23232, 14, 4774, 20, 459, 1541, 2278, 525, 63, 2200, 360, 1226, 13, 10538, 297, 2475, 74, 26704, 358, 267, 291, 14, 23232, 14, 4774, 22, 459, 1541, 2278, 525, 63, 4429, 360, 1226, 13, 10538, 358, 267, 291, 14, 23232, 14, 4774, 22, 459, 1541, 2278, 525, 63, 2200, 360, 1226, 13, 10538, 297, 2475, 74, 26704, 358, 339, 347, 485, 1506, 63, 8815, 63, 15036, 63, 2200, 8, 277, 12, 2332, 12, 1015, 304, 267, 340, 2332, 14, 504, 63, 719, 508, 2332, 14, 475, 63, 719, 26, 288, 372, 14574, 68, 719, 297, 1543, 83, 7, 450, 334, 2200, 14, 504, 63, 719, 12, 1874, 267, 587, 26, 288, 327, 221, 3091, 3510, 719, 4346, 367, 1323, 51, 1, 288, 372, 14574, 68, 719, 297, 1543, 83, 2689, 83, 7, 450, 334, 2200, 14, 504, 63, 719, 12, 5644, 2332, 14, 475, 63, 719, 1874, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1898, 7129, 1910, 5703, 24230, 598, 27639, 465, 11159, 701, 314, 199, 3, 30660, 402, 314, 20548, 437, 281, 265, 3844, 7769, 436, 19326, 9516, 4633, 14, 199, 3, 2900, 5924, 5702, 14, 199, 3, 1898, 334, 67, 9, 7129, 445, 390, 1904, 15285, 12, 3277, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 504, 11258, 63, 12161, 492, 18705, 199, 199, 504, 5913, 14, 4549, 492, 12042, 421, 199, 533, 577, 676, 16, 41, 541, 5921, 24260, 6158, 8, 10794, 14, 41, 541, 5921, 24260, 6158, 304, 272, 408, 20106, 16, 41, 541, 5921, 24260, 6158, 1021, 339, 961, 1021, 6571, 376, 4514, 367, 5913, 14, 4549, 14, 24260, 272, 1808, 29458, 14, 961, 1021, 365, 18329, 370, 506, 1202, 543, 314, 20388, 1246, 272, 4865, 436, 4440, 20388, 1246, 3589, 370, 15814, 29458, 4713, 315, 8266, 16, 14, 272, 408, 272, 347, 485, 2718, 63, 2526, 8, 277, 12, 627, 1760, 12, 1011, 958, 304, 267, 327, 17008, 2368, 367, 3589, 1240, 267, 1249, 275, 1052, 267, 2112, 63, 1210, 275, 2074, 14, 362, 360, 1412, 63, 1210, 297, 488, 9, 267, 340, 2112, 63, 1210, 365, 440, 488, 436, 1228, 8, 1412, 63, 1210, 12, 2783, 304, 288, 2074, 459, 1412, 63, 1210, 418, 275, 2112, 63, 1210, 14, 2708, 360, 1624, 13, 24, 358, 267, 1249, 14, 873, 8, 1130, 8, 2734, 671, 26, 334, 88, 12, 620, 8, 958, 59, 88, 12884, 2074, 430, 267, 1249, 459, 1760, 63, 589, 418, 275, 18705, 14, 4180, 8, 1760, 9, 267, 2203, 275, 291, 423, 1730, 14, 1250, 63, 2718, 360, 13615, 1102, 14, 647, 297, 283, 23232, 63, 888, 297, 1249, 9, 267, 2022, 63, 3292, 275, 18705, 14, 3640, 8, 3292, 9, 267, 372, 334, 1001, 63, 3292, 459, 548, 995, 2022, 63, 3292, 459, 1508, 1105, 339, 347, 636, 826, 721, 277, 12, 20388, 1246, 63, 1730, 29, 403, 12, 1011, 958, 304, 267, 687, 5913, 14, 1200, 492, 18369, 63, 846, 267, 1613, 8, 20106, 16, 41, 541, 5921, 24260, 6158, 12, 291, 2843, 826, 14155, 958, 9, 267, 291, 423, 1730, 275, 20388, 1246, 63, 1730, 267, 327, 2790, 31045, 18845, 2988, 543, 13270, 4012, 3589, 267, 291, 14, 23232, 275, 18369, 63, 846, 14, 41, 541, 5921, 2988, 8, 277, 423, 2718, 63, 2526, 9, 267, 291, 14, 23232, 14, 4774, 20, 459, 1541, 2278, 525, 63, 4429, 360, 1226, 13, 10538, 358, 267, 291, 14, 23232, 14, 4774, 20, 459, 1541, 2278, 525, 63, 2200, 360, 1226, 13, 10538, 297, 2475, 74, 26704, 358, 267, 291, 14, 23232, 14, 4774, 22, 459, 1541, 2278, 525, 63, 4429, 360, 1226, 13, 10538, 358, 267, 291, 14, 23232, 14, 4774, 22, 459, 1541, 2278, 525, 63, 2200, 360, 1226, 13, 10538, 297, 2475, 74, 26704, 358, 339, 347, 485, 1506, 63, 8815, 63, 15036, 63, 2200, 8, 277, 12, 2332, 12, 1015, 304, 267, 340, 2332, 14, 504, 63, 719, 508, 2332, 14, 475, 63, 719, 26, 288, 372, 14574, 68, 719, 297, 1543, 83, 7, 450, 334, 2200, 14, 504, 63, 719, 12, 1874, 267, 587, 26, 288, 327, 221, 3091, 3510, 719, 4346, 367, 1323, 51, 1, 288, 372, 14574, 68, 719, 297, 1543, 83, 2689, 83, 7, 450, 334, 2200, 14, 504, 63, 719, 12, 5644, 2332, 14, 475, 63, 719, 1874, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
jhawkesworth/ansible
lib/ansible/modules/cloud/vmware/vmware_host_powermgmt_policy.py
43
8768
#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright: (c) 2018, Christian Kotte <christian.kotte@gmx.de> # # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community' } DOCUMENTATION = r''' --- module: vmware_host_powermgmt_policy short_description: Manages the Power Management Policy of an ESXI host system description: - This module can be used to manage the Power Management Policy of ESXi host systems in given vCenter infrastructure. version_added: 2.8 author: - Christian Kotte (@ckotte) <christian.kotte@gmx.de> notes: - Tested on vSphere 6.5 requirements: - python >= 2.6 - PyVmomi options: policy: description: - Set the Power Management Policy of the host system. choices: [ 'high-performance', 'balanced', 'low-power', 'custom' ] default: 'balanced' esxi_hostname: description: - Name of the host system to work with. - This is required parameter if C(cluster_name) is not specified. cluster_name: description: - Name of the cluster from which all host systems will be used. - This is required parameter if C(esxi_hostname) is not specified. extends_documentation_fragment: vmware.documentation ''' EXAMPLES = r''' - name: Set the Power Management Policy of a host system to high-performance vmware_host_powermgmt_policy: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' esxi_hostname: '{{ esxi_host }}' policy: high-performance validate_certs: no delegate_to: localhost - name: Set the Power Management Policy of all host systems from cluster to high-performance vmware_host_powermgmt_policy: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' cluster_name: '{{ cluster_name }}' policy: high-performance validate_certs: no delegate_to: localhost ''' RETURN = r''' result: description: metadata about host system's Power Management Policy returned: always type: dict sample: { "changed": true, "result": { "esxi01": { "changed": true, "current_state": "high-performance", "desired_state": "high-performance", "msg": "Power policy changed", "previous_state": "balanced" } } } ''' try: from pyVmomi import vim, vmodl except ImportError: pass from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.vmware import PyVmomi, vmware_argument_spec from ansible.module_utils._text import to_native class VmwareHostPowerManagement(PyVmomi): """ Class to manage power management policy of an ESXi host system """ def __init__(self, module): super(VmwareHostPowerManagement, self).__init__(module) cluster_name = self.params.get('cluster_name') esxi_host_name = self.params.get('esxi_hostname') self.hosts = self.get_all_host_objs(cluster_name=cluster_name, esxi_host_name=esxi_host_name) if not self.hosts: self.module.fail_json(msg="Failed to find host system with given configuration.") def ensure(self): """ Manage power management policy of an ESXi host system """ results = dict(changed=False, result=dict()) policy = self.params.get('policy') host_change_list = [] power_policies = { 'high-performance': { 'key': 1, 'short_name': 'static' }, 'balanced': { 'key': 2, 'short_name': 'dynamic' }, 'low-power': { 'key': 3, 'short_name': 'low' }, 'custom': { 'key': 4, 'short_name': 'custom' } } for host in self.hosts: changed = False results['result'][host.name] = dict(msg='') power_system = host.configManager.powerSystem # get current power policy power_system_info = power_system.info current_host_power_policy = power_system_info.currentPolicy # the "name" and "description" parameters are pretty useless # they store only strings containing "PowerPolicy.<shortName>.name" and "PowerPolicy.<shortName>.description" if current_host_power_policy.shortName == "static": current_policy = 'high-performance' elif current_host_power_policy.shortName == "dynamic": current_policy = 'balanced' elif current_host_power_policy.shortName == "low": current_policy = 'low-power' elif current_host_power_policy.shortName == "custom": current_policy = 'custom' results['result'][host.name]['desired_state'] = policy # Don't do anything if the power policy is already configured if current_host_power_policy.key == power_policies[policy]['key']: results['result'][host.name]['changed'] = changed results['result'][host.name]['previous_state'] = current_policy results['result'][host.name]['current_state'] = policy results['result'][host.name]['msg'] = "Power policy is already configured" else: # get available power policies and check if policy is included supported_policy = False power_system_capability = power_system.capability available_host_power_policies = power_system_capability.availablePolicy for available_policy in available_host_power_policies: if available_policy.shortName == power_policies[policy]['short_name']: supported_policy = True if supported_policy: if not self.module.check_mode: try: power_system.ConfigurePowerPolicy(key=power_policies[policy]['key']) changed = True results['result'][host.name]['changed'] = True results['result'][host.name]['msg'] = "Power policy changed" except vmodl.fault.InvalidArgument: self.module.fail_json(msg="Invalid power policy key provided for host '%s'" % host.name) except vim.fault.HostConfigFault as host_config_fault: self.module.fail_json(msg="Failed to configure power policy for host '%s': %s" % (host.name, to_native(host_config_fault.msg))) else: changed = True results['result'][host.name]['changed'] = True results['result'][host.name]['msg'] = "Power policy will be changed" results['result'][host.name]['previous_state'] = current_policy results['result'][host.name]['current_state'] = policy else: changed = False results['result'][host.name]['changed'] = changed results['result'][host.name]['previous_state'] = current_policy results['result'][host.name]['current_state'] = current_policy self.module.fail_json(msg="Power policy '%s' isn't supported for host '%s'" % (policy, host.name)) host_change_list.append(changed) if any(host_change_list): results['changed'] = True self.module.exit_json(**results) def main(): """ Main """ argument_spec = vmware_argument_spec() argument_spec.update( policy=dict(type='str', default='balanced', choices=['high-performance', 'balanced', 'low-power', 'custom']), esxi_hostname=dict(type='str', required=False), cluster_name=dict(type='str', required=False), ) module = AnsibleModule(argument_spec=argument_spec, required_one_of=[ ['cluster_name', 'esxi_hostname'], ], supports_check_mode=True ) host_power_management = VmwareHostPowerManagement(module) host_power_management.ensure() if __name__ == '__main__': main()
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 1898, 26, 334, 67, 9, 14894, 12, 2799, 18824, 5653, 1804, 357, 266, 665, 335, 18824, 5653, 14, 75, 357, 266, 32, 71, 9457, 14, 271, 30, 199, 3, 199, 3, 1664, 1696, 1684, 844, 373, 19, 14, 16, 11, 334, 3239, 9685, 503, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 11692, 13, 19, 14, 16, 14, 2424, 9, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 363, 6577, 363, 275, 730, 421, 199, 8490, 63, 8314, 275, 469, 272, 283, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 272, 283, 1205, 356, 788, 7780, 995, 272, 283, 4946, 63, 991, 356, 283, 9387, 7, 199, 93, 199, 199, 8948, 275, 519, 2344, 199, 2595, 199, 578, 26, 19365, 63, 1102, 63, 5652, 9752, 63, 3185, 199, 3612, 63, 1802, 26, 21612, 314, 18879, 8259, 18141, 402, 376, 10427, 56, 41, 1591, 2656, 199, 1802, 26, 199, 13, 961, 859, 883, 506, 1202, 370, 9635, 314, 18879, 8259, 18141, 402, 10427, 14828, 1591, 10460, 315, 1627, 373, 13551, 28890, 6976, 14, 199, 1023, 63, 3270, 26, 499, 14, 24, 199, 2502, 26, 199, 13, 2799, 18824, 5653, 1804, 357, 266, 8593, 346, 357, 266, 9, 665, 335, 18824, 5653, 14, 75, 357, 266, 32, 71, 9457, 14, 271, 30, 199, 5983, 26, 199, 13, 30568, 641, 373, 22385, 1227, 14, 21, 199, 7538, 26, 199, 13, 2366, 2356, 499, 14, 22, 199, 13, 1611, 54, 28603, 199, 1419, 26, 523, 4592, 26, 272, 1369, 26, 272, 446, 2494, 314, 18879, 8259, 18141, 402, 314, 1591, 2656, 14, 272, 3415, 26, 359, 283, 6260, 13, 20576, 297, 283, 18923, 297, 283, 674, 13, 5652, 297, 283, 4229, 7, 1622, 272, 849, 26, 283, 18923, 7, 523, 9455, 6865, 63, 4269, 26, 272, 1369, 26, 272, 446, 2812, 402, 314, 1591, 2656, 370, 1736, 543, 14, 272, 446, 961, 365, 1415, 2725, 340, 445, 8, 4201, 63, 354, 9, 365, 440, 2013, 14, 523, 4350, 63, 354, 26, 272, 1369, 26, 272, 446, 2812, 402, 314, 4350, 687, 1314, 1006, 1591, 10460, 911, 506, 1202, 14, 272, 446, 961, 365, 1415, 2725, 340, 445, 8, 397, 6865, 63, 4269, 9, 365, 440, 2013, 14, 199, 11036, 63, 9970, 63, 7677, 26, 19365, 14, 9970, 199, 2344, 199, 199, 8918, 275, 519, 2344, 199, 13, 536, 26, 2494, 314, 18879, 8259, 18141, 402, 282, 1591, 2656, 370, 4721, 13, 20576, 523, 19365, 63, 1102, 63, 5652, 9752, 63, 3185, 26, 272, 6246, 26, 11400, 27127, 63, 4269, 16339, 272, 3434, 26, 11400, 27127, 63, 2473, 16339, 272, 2505, 26, 11400, 27127, 63, 2060, 16339, 272, 9455, 6865, 63, 4269, 26, 11400, 9455, 6865, 63, 1102, 16339, 272, 4592, 26, 4721, 13, 20576, 272, 4107, 63, 8356, 26, 949, 523, 13080, 63, 475, 26, 11667, 199, 199, 13, 536, 26, 2494, 314, 18879, 8259, 18141, 402, 1006, 1591, 10460, 687, 4350, 370, 4721, 13, 20576, 523, 19365, 63, 1102, 63, 5652, 9752, 63, 3185, 26, 272, 6246, 26, 11400, 27127, 63, 4269, 16339, 272, 3434, 26, 11400, 27127, 63, 2473, 16339, 272, 2505, 26, 11400, 27127, 63, 2060, 16339, 272, 4350, 63, 354, 26, 11400, 4350, 63, 354, 16339, 272, 4592, 26, 4721, 13, 20576, 272, 4107, 63, 8356, 26, 949, 523, 13080, 63, 475, 26, 11667, 199, 2344, 199, 199, 9677, 275, 519, 2344, 199, 1099, 26, 272, 1369, 26, 3341, 3595, 1591, 2656, 1159, 18879, 8259, 18141, 272, 2138, 26, 3544, 272, 730, 26, 1211, 272, 2690, 26, 469, 267, 298, 2489, 582, 2549, 12, 267, 298, 1099, 582, 469, 288, 298, 397, 6865, 614, 582, 469, 355, 298, 2489, 582, 2549, 12, 355, 298, 1818, 63, 929, 582, 298, 6260, 13, 20576, 401, 355, 298, 16035, 63, 929, 582, 298, 6260, 13, 20576, 401, 355, 298, 1328, 582, 298, 6921, 4592, 2896, 401, 355, 298, 6352, 63, 929, 582, 298, 18923, 2, 288, 789, 267, 789, 272, 789, 199, 2344, 199, 199, 893, 26, 272, 687, 1134, 54, 28603, 492, 6695, 12, 373, 1494, 76, 199, 2590, 3545, 26, 272, 986, 199, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 6953, 199, 504, 3242, 14, 578, 63, 1208, 14, 18970, 492, 1611, 54, 28603, 12, 19365, 63, 2094, 63, 1650, 199, 504, 3242, 14, 578, 63, 1208, 423, 505, 492, 370, 63, 6106, 421, 199, 533, 812, 77, 1068, 4965, 6921, 14552, 8, 2713, 54, 28603, 304, 272, 408, 272, 8089, 370, 9635, 7074, 10041, 4592, 402, 376, 10427, 14828, 1591, 2656, 272, 408, 272, 347, 636, 826, 721, 277, 12, 859, 304, 267, 1613, 8, 17402, 1068, 4965, 6921, 14552, 12, 291, 2843, 826, 721, 578, 9, 267, 4350, 63, 354, 275, 291, 14, 1162, 14, 362, 360, 4201, 63, 354, 358, 267, 9455, 6865, 63, 1102, 63, 354, 275, 291, 14, 1162, 14, 362, 360, 397, 6865, 63, 4269, 358, 267, 291, 14, 5146, 275, 291, 14, 362, 63, 452, 63, 1102, 63, 8718, 8, 4201, 63, 354, 29, 4201, 63, 354, 12, 9455, 6865, 63, 1102, 63, 354, 29, 397, 6865, 63, 1102, 63, 354, 9, 267, 340, 440, 291, 14, 5146, 26, 288, 291, 14, 578, 14, 1633, 63, 1001, 8, 1328, 628, 4276, 370, 2342, 1591, 2656, 543, 1627, 2897, 2685, 339, 347, 4868, 8, 277, 304, 267, 408, 267, 14944, 7074, 10041, 4592, 402, 376, 10427, 14828, 1591, 2656, 267, 408, 267, 2058, 275, 1211, 8, 2489, 29, 797, 12, 754, 29, 807, 1012, 267, 4592, 275, 291, 14, 1162, 14, 362, 360, 3185, 358, 267, 1591, 63, 1461, 63, 513, 275, 942, 267, 7074, 63, 11767, 275, 469, 288, 283, 6260, 13, 20576, 356, 469, 355, 283, 498, 356, 413, 12, 355, 283, 3612, 63, 354, 356, 283, 1986, 7, 288, 1660, 288, 283, 18923, 356, 469, 355, 283, 498, 356, 499, 12, 355, 283, 3612, 63, 354, 356, 283, 7764, 7, 288, 1660, 288, 283, 674, 13, 5652, 356, 469, 355, 283, 498, 356, 650, 12, 355, 283, 3612, 63, 354, 356, 283, 674 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 1898, 26, 334, 67, 9, 14894, 12, 2799, 18824, 5653, 1804, 357, 266, 665, 335, 18824, 5653, 14, 75, 357, 266, 32, 71, 9457, 14, 271, 30, 199, 3, 199, 3, 1664, 1696, 1684, 844, 373, 19, 14, 16, 11, 334, 3239, 9685, 503, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 11692, 13, 19, 14, 16, 14, 2424, 9, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 363, 6577, 363, 275, 730, 421, 199, 8490, 63, 8314, 275, 469, 272, 283, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 272, 283, 1205, 356, 788, 7780, 995, 272, 283, 4946, 63, 991, 356, 283, 9387, 7, 199, 93, 199, 199, 8948, 275, 519, 2344, 199, 2595, 199, 578, 26, 19365, 63, 1102, 63, 5652, 9752, 63, 3185, 199, 3612, 63, 1802, 26, 21612, 314, 18879, 8259, 18141, 402, 376, 10427, 56, 41, 1591, 2656, 199, 1802, 26, 199, 13, 961, 859, 883, 506, 1202, 370, 9635, 314, 18879, 8259, 18141, 402, 10427, 14828, 1591, 10460, 315, 1627, 373, 13551, 28890, 6976, 14, 199, 1023, 63, 3270, 26, 499, 14, 24, 199, 2502, 26, 199, 13, 2799, 18824, 5653, 1804, 357, 266, 8593, 346, 357, 266, 9, 665, 335, 18824, 5653, 14, 75, 357, 266, 32, 71, 9457, 14, 271, 30, 199, 5983, 26, 199, 13, 30568, 641, 373, 22385, 1227, 14, 21, 199, 7538, 26, 199, 13, 2366, 2356, 499, 14, 22, 199, 13, 1611, 54, 28603, 199, 1419, 26, 523, 4592, 26, 272, 1369, 26, 272, 446, 2494, 314, 18879, 8259, 18141, 402, 314, 1591, 2656, 14, 272, 3415, 26, 359, 283, 6260, 13, 20576, 297, 283, 18923, 297, 283, 674, 13, 5652, 297, 283, 4229, 7, 1622, 272, 849, 26, 283, 18923, 7, 523, 9455, 6865, 63, 4269, 26, 272, 1369, 26, 272, 446, 2812, 402, 314, 1591, 2656, 370, 1736, 543, 14, 272, 446, 961, 365, 1415, 2725, 340, 445, 8, 4201, 63, 354, 9, 365, 440, 2013, 14, 523, 4350, 63, 354, 26, 272, 1369, 26, 272, 446, 2812, 402, 314, 4350, 687, 1314, 1006, 1591, 10460, 911, 506, 1202, 14, 272, 446, 961, 365, 1415, 2725, 340, 445, 8, 397, 6865, 63, 4269, 9, 365, 440, 2013, 14, 199, 11036, 63, 9970, 63, 7677, 26, 19365, 14, 9970, 199, 2344, 199, 199, 8918, 275, 519, 2344, 199, 13, 536, 26, 2494, 314, 18879, 8259, 18141, 402, 282, 1591, 2656, 370, 4721, 13, 20576, 523, 19365, 63, 1102, 63, 5652, 9752, 63, 3185, 26, 272, 6246, 26, 11400, 27127, 63, 4269, 16339, 272, 3434, 26, 11400, 27127, 63, 2473, 16339, 272, 2505, 26, 11400, 27127, 63, 2060, 16339, 272, 9455, 6865, 63, 4269, 26, 11400, 9455, 6865, 63, 1102, 16339, 272, 4592, 26, 4721, 13, 20576, 272, 4107, 63, 8356, 26, 949, 523, 13080, 63, 475, 26, 11667, 199, 199, 13, 536, 26, 2494, 314, 18879, 8259, 18141, 402, 1006, 1591, 10460, 687, 4350, 370, 4721, 13, 20576, 523, 19365, 63, 1102, 63, 5652, 9752, 63, 3185, 26, 272, 6246, 26, 11400, 27127, 63, 4269, 16339, 272, 3434, 26, 11400, 27127, 63, 2473, 16339, 272, 2505, 26, 11400, 27127, 63, 2060, 16339, 272, 4350, 63, 354, 26, 11400, 4350, 63, 354, 16339, 272, 4592, 26, 4721, 13, 20576, 272, 4107, 63, 8356, 26, 949, 523, 13080, 63, 475, 26, 11667, 199, 2344, 199, 199, 9677, 275, 519, 2344, 199, 1099, 26, 272, 1369, 26, 3341, 3595, 1591, 2656, 1159, 18879, 8259, 18141, 272, 2138, 26, 3544, 272, 730, 26, 1211, 272, 2690, 26, 469, 267, 298, 2489, 582, 2549, 12, 267, 298, 1099, 582, 469, 288, 298, 397, 6865, 614, 582, 469, 355, 298, 2489, 582, 2549, 12, 355, 298, 1818, 63, 929, 582, 298, 6260, 13, 20576, 401, 355, 298, 16035, 63, 929, 582, 298, 6260, 13, 20576, 401, 355, 298, 1328, 582, 298, 6921, 4592, 2896, 401, 355, 298, 6352, 63, 929, 582, 298, 18923, 2, 288, 789, 267, 789, 272, 789, 199, 2344, 199, 199, 893, 26, 272, 687, 1134, 54, 28603, 492, 6695, 12, 373, 1494, 76, 199, 2590, 3545, 26, 272, 986, 199, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 6953, 199, 504, 3242, 14, 578, 63, 1208, 14, 18970, 492, 1611, 54, 28603, 12, 19365, 63, 2094, 63, 1650, 199, 504, 3242, 14, 578, 63, 1208, 423, 505, 492, 370, 63, 6106, 421, 199, 533, 812, 77, 1068, 4965, 6921, 14552, 8, 2713, 54, 28603, 304, 272, 408, 272, 8089, 370, 9635, 7074, 10041, 4592, 402, 376, 10427, 14828, 1591, 2656, 272, 408, 272, 347, 636, 826, 721, 277, 12, 859, 304, 267, 1613, 8, 17402, 1068, 4965, 6921, 14552, 12, 291, 2843, 826, 721, 578, 9, 267, 4350, 63, 354, 275, 291, 14, 1162, 14, 362, 360, 4201, 63, 354, 358, 267, 9455, 6865, 63, 1102, 63, 354, 275, 291, 14, 1162, 14, 362, 360, 397, 6865, 63, 4269, 358, 267, 291, 14, 5146, 275, 291, 14, 362, 63, 452, 63, 1102, 63, 8718, 8, 4201, 63, 354, 29, 4201, 63, 354, 12, 9455, 6865, 63, 1102, 63, 354, 29, 397, 6865, 63, 1102, 63, 354, 9, 267, 340, 440, 291, 14, 5146, 26, 288, 291, 14, 578, 14, 1633, 63, 1001, 8, 1328, 628, 4276, 370, 2342, 1591, 2656, 543, 1627, 2897, 2685, 339, 347, 4868, 8, 277, 304, 267, 408, 267, 14944, 7074, 10041, 4592, 402, 376, 10427, 14828, 1591, 2656, 267, 408, 267, 2058, 275, 1211, 8, 2489, 29, 797, 12, 754, 29, 807, 1012, 267, 4592, 275, 291, 14, 1162, 14, 362, 360, 3185, 358, 267, 1591, 63, 1461, 63, 513, 275, 942, 267, 7074, 63, 11767, 275, 469, 288, 283, 6260, 13, 20576, 356, 469, 355, 283, 498, 356, 413, 12, 355, 283, 3612, 63, 354, 356, 283, 1986, 7, 288, 1660, 288, 283, 18923, 356, 469, 355, 283, 498, 356, 499, 12, 355, 283, 3612, 63, 354, 356, 283, 7764, 7, 288, 1660, 288, 283, 674, 13, 5652, 356, 469, 355, 283, 498, 356, 650, 12, 355, 283, 3612, 63, 354, 356, 283, 674, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
kernel-sanders/arsenic-mobile
Dependencies/zope.interface-4.0.5/src/zope/interface/advice.py
31
7546
############################################################################## # # Copyright (c) 2003 Zope Foundation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## """Class advice. This module was adapted from 'protocols.advice', part of the Python Enterprise Application Kit (PEAK). Please notify the PEAK authors (pje@telecommunity.com and tsarna@sarna.org) if bugs are found or Zope-specific changes are required, so that the PEAK version of this module can be kept in sync. PEAK is a Python application framework that interoperates with (but does not require) Zope 3 and Twisted. It provides tools for manipulating UML models, object-relational persistence, aspect-oriented programming, and more. Visit the PEAK home page at http://peak.telecommunity.com for more information. """ from types import FunctionType try: from types import ClassType except ImportError: #pragma NO COVER Python > 3.x __python3 = True else: #pragma NO COVER Python < 3.x __python3 = False import sys def getFrameInfo(frame): """Return (kind,module,locals,globals) for a frame 'kind' is one of "exec", "module", "class", "function call", or "unknown". """ f_locals = frame.f_locals f_globals = frame.f_globals sameNamespace = f_locals is f_globals hasModule = '__module__' in f_locals hasName = '__name__' in f_globals sameName = hasModule and hasName sameName = sameName and f_globals['__name__']==f_locals['__module__'] module = hasName and sys.modules.get(f_globals['__name__']) or None namespaceIsModule = module and module.__dict__ is f_globals if not namespaceIsModule: # some kind of funky exec kind = "exec" elif sameNamespace and not hasModule: kind = "module" elif sameName and not sameNamespace: kind = "class" elif not sameNamespace: kind = "function call" else: # pragma NO COVER # How can you have f_locals is f_globals, and have '__module__' set? # This is probably module-level code, but with a '__module__' variable. kind = "unknown" return kind, module, f_locals, f_globals def addClassAdvisor(callback, depth=2): """Set up 'callback' to be passed the containing class upon creation This function is designed to be called by an "advising" function executed in a class suite. The "advising" function supplies a callback that it wishes to have executed when the containing class is created. The callback will be given one argument: the newly created containing class. The return value of the callback will be used in place of the class, so the callback should return the input if it does not wish to replace the class. The optional 'depth' argument to this function determines the number of frames between this function and the targeted class suite. 'depth' defaults to 2, since this skips this function's frame and one calling function frame. If you use this function from a function called directly in the class suite, the default will be correct, otherwise you will need to determine the correct depth yourself. This function works by installing a special class factory function in place of the '__metaclass__' of the containing class. Therefore, only callbacks *after* the last '__metaclass__' assignment in the containing class will be executed. Be sure that classes using "advising" functions declare any '__metaclass__' *first*, to ensure all callbacks are run.""" # This entire approach is invalid under Py3K. Don't even try to fix # the coverage for this block there. :( if __python3: #pragma NO COVER raise TypeError('Class advice impossible in Python3') frame = sys._getframe(depth) kind, module, caller_locals, caller_globals = getFrameInfo(frame) # This causes a problem when zope interfaces are used from doctest. # In these cases, kind == "exec". # #if kind != "class": # raise SyntaxError( # "Advice must be in the body of a class statement" # ) previousMetaclass = caller_locals.get('__metaclass__') if __python3: # pragma NO COVER defaultMetaclass = caller_globals.get('__metaclass__', type) else: defaultMetaclass = caller_globals.get('__metaclass__', ClassType) def advise(name, bases, cdict): if '__metaclass__' in cdict: del cdict['__metaclass__'] if previousMetaclass is None: if bases: # find best metaclass or use global __metaclass__ if no bases meta = determineMetaclass(bases) else: meta = defaultMetaclass elif isClassAdvisor(previousMetaclass): # special case: we can't compute the "true" metaclass here, # so we need to invoke the previous metaclass and let it # figure it out for us (and apply its own advice in the process) meta = previousMetaclass else: meta = determineMetaclass(bases, previousMetaclass) newClass = meta(name,bases,cdict) # this lets the callback replace the class completely, if it wants to return callback(newClass) # introspection data only, not used by inner function advise.previousMetaclass = previousMetaclass advise.callback = callback # install the advisor caller_locals['__metaclass__'] = advise def isClassAdvisor(ob): """True if 'ob' is a class advisor function""" return isinstance(ob,FunctionType) and hasattr(ob,'previousMetaclass') def determineMetaclass(bases, explicit_mc=None): """Determine metaclass from 1+ bases and optional explicit __metaclass__""" meta = [getattr(b,'__class__',type(b)) for b in bases] if explicit_mc is not None: # The explicit metaclass needs to be verified for compatibility # as well, and allowed to resolve the incompatible bases, if any meta.append(explicit_mc) if len(meta)==1: # easy case return meta[0] candidates = minimalBases(meta) # minimal set of metaclasses if not candidates: #pragma NO COVER # they're all "classic" classes assert(not __python3) # This should not happen under Python 3 return ClassType elif len(candidates)>1: # We could auto-combine, but for now we won't... raise TypeError("Incompatible metatypes",bases) # Just one, return it return candidates[0] def minimalBases(classes): """Reduce a list of base classes to its ordered minimum equivalent""" if not __python3: #pragma NO COVER classes = [c for c in classes if c is not ClassType] candidates = [] for m in classes: for n in classes: if issubclass(n,m) and m is not n: break else: # m has no subclasses in 'classes' if m in candidates: candidates.remove(m) # ensure that we're later in the list candidates.append(m) return candidates
gpl-3.0
[ 4605, 199, 3, 199, 3, 1898, 334, 67, 9, 13004, 3107, 13458, 2752, 436, 23212, 14, 199, 3, 2900, 5924, 5702, 14, 199, 3, 199, 3, 961, 2032, 365, 5420, 370, 314, 1727, 1356, 402, 314, 3107, 13458, 1684, 844, 12, 199, 3, 3394, 499, 14, 17, 334, 58, 2749, 680, 221, 437, 1331, 402, 314, 3107, 2749, 1077, 21727, 642, 4084, 14, 199, 3, 5749, 4141, 2281, 7049, 298, 1179, 2281, 2, 2401, 1821, 2401, 11727, 7168, 1549, 5292, 199, 3, 2990, 9315, 9706, 12, 6931, 12, 5400, 2845, 5471, 2296, 12, 2334, 5292, 199, 3, 2990, 1634, 377, 16507, 12, 3169, 12, 437, 9741, 7834, 1621, 12600, 12, 2401, 3092, 199, 3, 2381, 437, 3115, 3104, 14, 199, 3, 199, 4605, 199, 624, 2543, 1503, 722, 14, 199, 199, 2765, 859, 1990, 26266, 687, 283, 16541, 14, 350, 722, 297, 1777, 402, 314, 2018, 199, 8468, 13219, 13515, 1804, 390, 334, 1510, 7872, 680, 221, 7754, 11705, 314, 19599, 7872, 11462, 199, 8, 80, 6532, 32, 15253, 9387, 14, 957, 436, 6714, 24252, 32, 83, 24252, 14, 1308, 9, 340, 18227, 787, 1911, 503, 199, 58, 13458, 13, 6100, 4493, 787, 1415, 12, 880, 626, 314, 19599, 7872, 1015, 402, 642, 859, 199, 2425, 506, 16204, 315, 7604, 14, 199, 199, 1510, 7872, 365, 282, 2018, 4223, 10059, 626, 4661, 9198, 2335, 543, 334, 7911, 1630, 199, 1397, 4409, 9, 3107, 13458, 650, 436, 17078, 14, 221, 2779, 6571, 7249, 367, 13335, 20529, 738, 1698, 199, 992, 12, 909, 13, 5690, 279, 26882, 12, 17435, 13, 16039, 287, 471, 31768, 12, 436, 1655, 14, 199, 15087, 314, 19599, 7872, 5629, 2034, 737, 1455, 921, 8556, 14, 15253, 9387, 14, 957, 367, 1655, 2556, 14, 199, 624, 199, 199, 504, 2943, 492, 6801, 804, 199, 893, 26, 272, 687, 2943, 492, 8089, 804, 199, 2590, 3545, 26, 221, 327, 25852, 4825, 5099, 2111, 2018, 690, 650, 14, 88, 272, 636, 1548, 19, 275, 715, 199, 2836, 26, 327, 25852, 4825, 5099, 2111, 2018, 665, 650, 14, 88, 272, 636, 1548, 19, 275, 756, 1362, 199, 646, 984, 199, 199, 318, 664, 3160, 2354, 8, 1943, 304, 272, 408, 1767, 334, 5091, 12, 578, 12, 9350, 12, 8473, 9, 367, 282, 2787, 339, 283, 5091, 7, 365, 1373, 402, 298, 1628, 401, 298, 578, 401, 298, 533, 401, 298, 1593, 1240, 401, 503, 298, 5187, 1674, 272, 408, 339, 289, 63, 9350, 275, 2787, 14, 70, 63, 9350, 272, 289, 63, 8473, 275, 2787, 14, 70, 63, 8473, 339, 2011, 8814, 275, 289, 63, 9350, 365, 289, 63, 8473, 272, 965, 2377, 275, 2560, 578, 12217, 315, 289, 63, 9350, 272, 965, 985, 275, 2560, 354, 12217, 315, 289, 63, 8473, 339, 2011, 985, 275, 965, 2377, 436, 965, 985, 272, 2011, 985, 275, 2011, 985, 436, 289, 63, 8473, 13742, 354, 17501, 389, 70, 63, 9350, 13742, 578, 17501, 339, 859, 275, 965, 985, 436, 984, 14, 3112, 14, 362, 8, 70, 63, 8473, 13742, 354, 363, 1105, 503, 488, 339, 3231, 1831, 2377, 275, 859, 436, 859, 855, 807, 363, 365, 289, 63, 8473, 339, 340, 440, 3231, 1831, 2377, 26, 267, 327, 2005, 4928, 402, 289, 1778, 89, 2146, 267, 4928, 275, 298, 1628, 2, 272, 916, 2011, 8814, 436, 440, 965, 2377, 26, 267, 4928, 275, 298, 578, 2, 272, 916, 2011, 985, 436, 440, 2011, 8814, 26, 267, 4928, 275, 298, 533, 2, 272, 916, 440, 2011, 8814, 26, 267, 4928, 275, 298, 1593, 1240, 2, 272, 587, 26, 257, 327, 11942, 4825, 5099, 2111, 267, 327, 7494, 883, 1265, 1172, 289, 63, 9350, 365, 289, 63, 8473, 12, 436, 1172, 2560, 578, 12217, 663, 31, 267, 327, 961, 365, 8646, 859, 13, 1896, 1233, 12, 1325, 543, 282, 2560, 578, 12217, 1750, 14, 267, 4928, 275, 298, 5187, 2, 272, 372, 4928, 12, 859, 12, 289, 63, 9350, 12, 289, 63, 8473, 421, 199, 318, 1050, 2543, 2767, 8286, 8, 3058, 12, 5818, 29, 18, 304, 272, 408, 1084, 1536, 283, 3058, 7, 370, 506, 3032, 314, 3035, 1021, 12188, 7143, 339, 961, 805, 365, 19829, 370, 506, 2797, 701, 376, 298, 350, 5068, 316, 2, 805, 7934, 272, 315, 282, 1021, 5241, 14, 221, 710, 298, 350, 5068, 316, 2, 805, 4973, 6528, 282, 3233, 626, 652, 272, 13809, 397, 370, 1172, 7934, 1380, 314, 3035, 1021, 365, 2737, 14, 221, 710, 272, 3233, 911, 506, 1627, 1373, 1423, 26, 314, 13903, 2737, 3035, 1021, 14, 272, 710, 372, 574, 402, 314, 3233, 911, 506, 1202, 315, 4192, 402, 314, 1021, 12, 880, 272, 314, 3233, 1077, 372, 314, 1324, 340, 652, 1630, 440, 13809, 370, 3350, 314, 272, 1021, 14, 339, 710, 2716, 283, 4631, 7, 1423, 370, 642, 805, 16756, 314, 1329, 402, 272, 11223, 3382, 642, 805, 436, 314, 307, 20174, 1021, 5241, 14, 221, 283, 4631, 7, 272, 4243, 370, 499, 12, 3967, 642, 30505, 642, 805, 1159, 2787, 436, 1373, 6358, 272, 805, 2787, 14, 221, 982, 1265, 675, 642, 805, 687, 282, 805, 2797, 5370, 272, 315, 314, 1021, 5241, 12, 314, 849, 911, 506, 3211, 12, 4257, 1265, 911, 1929, 272, 370, 6705, 314, 3211, 5818, 28225, 14, 339, 961, 805, 5419, 701, 22200, 282, 4539, 1021, 6434, 805, 315, 272, 4192, 402, 314, 2560, 6577, 12217, 402, 314, 3035, 1021, 14, 221, 21039, 12, 1454, 272, 13484, 627, 4399, 10, 314, 2061, 2560, 6577, 12217, 9801, 315, 314, 3035, 272, 1021, 911, 506, 7934, 14, 221, 6423, 3238, 626, 3992, 1808, 298, 350, 5068, 316, 2, 3423, 272, 20771, 1263, 2560, 6577, 12217, 627, 2246, 10381, 370, 4868, 1006, 13484, 787, 1255, 1041, 272, 327, 961, 8039, 18140, 365, 3866, 1334, 1611, 19, 43, 14, 221, 7529, 1133, 2755, 862, 370, 5325, 272, 327, 314, 11745, 367, 642, 1853, 2337, 14, 520, 8, 272, 340, 636, 1548, 19, 26, 327, 25852, 4825, 5099, 2111, 267, 746, 3146, 360, 2543, 1503, 722, 26847, 315, 2018, 19, 358, 339, 2787, 275, 984, 423, 20912, 8, 4631, 9, 272, 4928, 12, 859, 12, 8025, 63, 9350, 12, 8025, 63, 8473, 275, 664, 3160, 2354, 8, 1943, 9, 339, 327, 961, 14486, 282 ]
[ 199, 3, 199, 3, 1898, 334, 67, 9, 13004, 3107, 13458, 2752, 436, 23212, 14, 199, 3, 2900, 5924, 5702, 14, 199, 3, 199, 3, 961, 2032, 365, 5420, 370, 314, 1727, 1356, 402, 314, 3107, 13458, 1684, 844, 12, 199, 3, 3394, 499, 14, 17, 334, 58, 2749, 680, 221, 437, 1331, 402, 314, 3107, 2749, 1077, 21727, 642, 4084, 14, 199, 3, 5749, 4141, 2281, 7049, 298, 1179, 2281, 2, 2401, 1821, 2401, 11727, 7168, 1549, 5292, 199, 3, 2990, 9315, 9706, 12, 6931, 12, 5400, 2845, 5471, 2296, 12, 2334, 5292, 199, 3, 2990, 1634, 377, 16507, 12, 3169, 12, 437, 9741, 7834, 1621, 12600, 12, 2401, 3092, 199, 3, 2381, 437, 3115, 3104, 14, 199, 3, 199, 4605, 199, 624, 2543, 1503, 722, 14, 199, 199, 2765, 859, 1990, 26266, 687, 283, 16541, 14, 350, 722, 297, 1777, 402, 314, 2018, 199, 8468, 13219, 13515, 1804, 390, 334, 1510, 7872, 680, 221, 7754, 11705, 314, 19599, 7872, 11462, 199, 8, 80, 6532, 32, 15253, 9387, 14, 957, 436, 6714, 24252, 32, 83, 24252, 14, 1308, 9, 340, 18227, 787, 1911, 503, 199, 58, 13458, 13, 6100, 4493, 787, 1415, 12, 880, 626, 314, 19599, 7872, 1015, 402, 642, 859, 199, 2425, 506, 16204, 315, 7604, 14, 199, 199, 1510, 7872, 365, 282, 2018, 4223, 10059, 626, 4661, 9198, 2335, 543, 334, 7911, 1630, 199, 1397, 4409, 9, 3107, 13458, 650, 436, 17078, 14, 221, 2779, 6571, 7249, 367, 13335, 20529, 738, 1698, 199, 992, 12, 909, 13, 5690, 279, 26882, 12, 17435, 13, 16039, 287, 471, 31768, 12, 436, 1655, 14, 199, 15087, 314, 19599, 7872, 5629, 2034, 737, 1455, 921, 8556, 14, 15253, 9387, 14, 957, 367, 1655, 2556, 14, 199, 624, 199, 199, 504, 2943, 492, 6801, 804, 199, 893, 26, 272, 687, 2943, 492, 8089, 804, 199, 2590, 3545, 26, 221, 327, 25852, 4825, 5099, 2111, 2018, 690, 650, 14, 88, 272, 636, 1548, 19, 275, 715, 199, 2836, 26, 327, 25852, 4825, 5099, 2111, 2018, 665, 650, 14, 88, 272, 636, 1548, 19, 275, 756, 1362, 199, 646, 984, 199, 199, 318, 664, 3160, 2354, 8, 1943, 304, 272, 408, 1767, 334, 5091, 12, 578, 12, 9350, 12, 8473, 9, 367, 282, 2787, 339, 283, 5091, 7, 365, 1373, 402, 298, 1628, 401, 298, 578, 401, 298, 533, 401, 298, 1593, 1240, 401, 503, 298, 5187, 1674, 272, 408, 339, 289, 63, 9350, 275, 2787, 14, 70, 63, 9350, 272, 289, 63, 8473, 275, 2787, 14, 70, 63, 8473, 339, 2011, 8814, 275, 289, 63, 9350, 365, 289, 63, 8473, 272, 965, 2377, 275, 2560, 578, 12217, 315, 289, 63, 9350, 272, 965, 985, 275, 2560, 354, 12217, 315, 289, 63, 8473, 339, 2011, 985, 275, 965, 2377, 436, 965, 985, 272, 2011, 985, 275, 2011, 985, 436, 289, 63, 8473, 13742, 354, 17501, 389, 70, 63, 9350, 13742, 578, 17501, 339, 859, 275, 965, 985, 436, 984, 14, 3112, 14, 362, 8, 70, 63, 8473, 13742, 354, 363, 1105, 503, 488, 339, 3231, 1831, 2377, 275, 859, 436, 859, 855, 807, 363, 365, 289, 63, 8473, 339, 340, 440, 3231, 1831, 2377, 26, 267, 327, 2005, 4928, 402, 289, 1778, 89, 2146, 267, 4928, 275, 298, 1628, 2, 272, 916, 2011, 8814, 436, 440, 965, 2377, 26, 267, 4928, 275, 298, 578, 2, 272, 916, 2011, 985, 436, 440, 2011, 8814, 26, 267, 4928, 275, 298, 533, 2, 272, 916, 440, 2011, 8814, 26, 267, 4928, 275, 298, 1593, 1240, 2, 272, 587, 26, 257, 327, 11942, 4825, 5099, 2111, 267, 327, 7494, 883, 1265, 1172, 289, 63, 9350, 365, 289, 63, 8473, 12, 436, 1172, 2560, 578, 12217, 663, 31, 267, 327, 961, 365, 8646, 859, 13, 1896, 1233, 12, 1325, 543, 282, 2560, 578, 12217, 1750, 14, 267, 4928, 275, 298, 5187, 2, 272, 372, 4928, 12, 859, 12, 289, 63, 9350, 12, 289, 63, 8473, 421, 199, 318, 1050, 2543, 2767, 8286, 8, 3058, 12, 5818, 29, 18, 304, 272, 408, 1084, 1536, 283, 3058, 7, 370, 506, 3032, 314, 3035, 1021, 12188, 7143, 339, 961, 805, 365, 19829, 370, 506, 2797, 701, 376, 298, 350, 5068, 316, 2, 805, 7934, 272, 315, 282, 1021, 5241, 14, 221, 710, 298, 350, 5068, 316, 2, 805, 4973, 6528, 282, 3233, 626, 652, 272, 13809, 397, 370, 1172, 7934, 1380, 314, 3035, 1021, 365, 2737, 14, 221, 710, 272, 3233, 911, 506, 1627, 1373, 1423, 26, 314, 13903, 2737, 3035, 1021, 14, 272, 710, 372, 574, 402, 314, 3233, 911, 506, 1202, 315, 4192, 402, 314, 1021, 12, 880, 272, 314, 3233, 1077, 372, 314, 1324, 340, 652, 1630, 440, 13809, 370, 3350, 314, 272, 1021, 14, 339, 710, 2716, 283, 4631, 7, 1423, 370, 642, 805, 16756, 314, 1329, 402, 272, 11223, 3382, 642, 805, 436, 314, 307, 20174, 1021, 5241, 14, 221, 283, 4631, 7, 272, 4243, 370, 499, 12, 3967, 642, 30505, 642, 805, 1159, 2787, 436, 1373, 6358, 272, 805, 2787, 14, 221, 982, 1265, 675, 642, 805, 687, 282, 805, 2797, 5370, 272, 315, 314, 1021, 5241, 12, 314, 849, 911, 506, 3211, 12, 4257, 1265, 911, 1929, 272, 370, 6705, 314, 3211, 5818, 28225, 14, 339, 961, 805, 5419, 701, 22200, 282, 4539, 1021, 6434, 805, 315, 272, 4192, 402, 314, 2560, 6577, 12217, 402, 314, 3035, 1021, 14, 221, 21039, 12, 1454, 272, 13484, 627, 4399, 10, 314, 2061, 2560, 6577, 12217, 9801, 315, 314, 3035, 272, 1021, 911, 506, 7934, 14, 221, 6423, 3238, 626, 3992, 1808, 298, 350, 5068, 316, 2, 3423, 272, 20771, 1263, 2560, 6577, 12217, 627, 2246, 10381, 370, 4868, 1006, 13484, 787, 1255, 1041, 272, 327, 961, 8039, 18140, 365, 3866, 1334, 1611, 19, 43, 14, 221, 7529, 1133, 2755, 862, 370, 5325, 272, 327, 314, 11745, 367, 642, 1853, 2337, 14, 520, 8, 272, 340, 636, 1548, 19, 26, 327, 25852, 4825, 5099, 2111, 267, 746, 3146, 360, 2543, 1503, 722, 26847, 315, 2018, 19, 358, 339, 2787, 275, 984, 423, 20912, 8, 4631, 9, 272, 4928, 12, 859, 12, 8025, 63, 9350, 12, 8025, 63, 8473, 275, 664, 3160, 2354, 8, 1943, 9, 339, 327, 961, 14486, 282, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
vanish87/shadowsocks
setup.py
18
1321
import codecs from setuptools import setup with codecs.open('README.rst', encoding='utf-8') as f: long_description = f.read() setup( name="shadowsocks", version="3.0.0", license='http://www.apache.org/licenses/LICENSE-2.0', description="A fast tunnel proxy that help you get through firewalls", author='clowwindy', author_email='clowwindy42@gmail.com', url='https://github.com/shadowsocks/shadowsocks', packages=['shadowsocks', 'shadowsocks.crypto'], package_data={ 'shadowsocks': ['README.rst', 'LICENSE'] }, install_requires=[], entry_points=""" [console_scripts] sslocal = shadowsocks.local:main ssserver = shadowsocks.server:main """, classifiers=[ 'License :: OSI Approved :: Apache Software License', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Topic :: Internet :: Proxy Servers', ], long_description=long_description, )
apache-2.0
[ 646, 6010, 199, 504, 9116, 492, 3272, 421, 199, 1045, 6010, 14, 1490, 360, 18195, 14, 8332, 297, 2644, 534, 1624, 13, 24, 358, 465, 289, 26, 272, 1846, 63, 1802, 275, 289, 14, 739, 342, 199, 199, 2758, 8, 272, 536, 628, 14714, 21234, 401, 272, 1015, 628, 19, 14, 16, 14, 16, 401, 272, 4190, 534, 1014, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 297, 272, 1369, 628, 33, 7377, 21496, 4566, 626, 1720, 1265, 664, 4012, 12042, 83, 401, 272, 4132, 534, 67, 674, 11530, 89, 297, 272, 4132, 63, 2123, 534, 67, 674, 11530, 89, 2260, 32, 6799, 14, 957, 297, 272, 1166, 534, 2859, 921, 5031, 14, 957, 15, 14714, 21234, 15, 14714, 21234, 297, 272, 6117, 2968, 14714, 21234, 297, 283, 14714, 21234, 14, 10316, 995, 272, 2559, 63, 576, 3126, 267, 283, 14714, 21234, 356, 788, 18195, 14, 8332, 297, 283, 3961, 418, 272, 1660, 272, 3907, 63, 6537, 6034, 272, 2397, 63, 3438, 11916, 272, 359, 6614, 63, 6429, 61, 272, 10110, 1832, 275, 15084, 21234, 14, 1832, 26, 973, 272, 10110, 1000, 275, 15084, 21234, 14, 1000, 26, 973, 272, 10327, 272, 19137, 1524, 267, 283, 3761, 3800, 25718, 26330, 3800, 3668, 2290, 844, 297, 267, 283, 11411, 8466, 3800, 2018, 3800, 499, 297, 267, 283, 11411, 8466, 3800, 2018, 3800, 499, 14, 22, 297, 267, 283, 11411, 8466, 3800, 2018, 3800, 499, 14, 23, 297, 267, 283, 11411, 8466, 3800, 2018, 3800, 650, 297, 267, 283, 11411, 8466, 3800, 2018, 3800, 650, 14, 19, 297, 267, 283, 11411, 8466, 3800, 2018, 3800, 650, 14, 20, 297, 267, 283, 11411, 8466, 3800, 2018, 3800, 24425, 3800, 25654, 297, 267, 283, 11411, 8466, 3800, 2018, 3800, 24425, 3800, 1611, 2713, 297, 267, 283, 12157, 3800, 22026, 3800, 12373, 7146, 83, 297, 272, 2156, 272, 1846, 63, 1802, 29, 2809, 63, 1802, 12, 199, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 6010, 199, 504, 9116, 492, 3272, 421, 199, 1045, 6010, 14, 1490, 360, 18195, 14, 8332, 297, 2644, 534, 1624, 13, 24, 358, 465, 289, 26, 272, 1846, 63, 1802, 275, 289, 14, 739, 342, 199, 199, 2758, 8, 272, 536, 628, 14714, 21234, 401, 272, 1015, 628, 19, 14, 16, 14, 16, 401, 272, 4190, 534, 1014, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 297, 272, 1369, 628, 33, 7377, 21496, 4566, 626, 1720, 1265, 664, 4012, 12042, 83, 401, 272, 4132, 534, 67, 674, 11530, 89, 297, 272, 4132, 63, 2123, 534, 67, 674, 11530, 89, 2260, 32, 6799, 14, 957, 297, 272, 1166, 534, 2859, 921, 5031, 14, 957, 15, 14714, 21234, 15, 14714, 21234, 297, 272, 6117, 2968, 14714, 21234, 297, 283, 14714, 21234, 14, 10316, 995, 272, 2559, 63, 576, 3126, 267, 283, 14714, 21234, 356, 788, 18195, 14, 8332, 297, 283, 3961, 418, 272, 1660, 272, 3907, 63, 6537, 6034, 272, 2397, 63, 3438, 11916, 272, 359, 6614, 63, 6429, 61, 272, 10110, 1832, 275, 15084, 21234, 14, 1832, 26, 973, 272, 10110, 1000, 275, 15084, 21234, 14, 1000, 26, 973, 272, 10327, 272, 19137, 1524, 267, 283, 3761, 3800, 25718, 26330, 3800, 3668, 2290, 844, 297, 267, 283, 11411, 8466, 3800, 2018, 3800, 499, 297, 267, 283, 11411, 8466, 3800, 2018, 3800, 499, 14, 22, 297, 267, 283, 11411, 8466, 3800, 2018, 3800, 499, 14, 23, 297, 267, 283, 11411, 8466, 3800, 2018, 3800, 650, 297, 267, 283, 11411, 8466, 3800, 2018, 3800, 650, 14, 19, 297, 267, 283, 11411, 8466, 3800, 2018, 3800, 650, 14, 20, 297, 267, 283, 11411, 8466, 3800, 2018, 3800, 24425, 3800, 25654, 297, 267, 283, 11411, 8466, 3800, 2018, 3800, 24425, 3800, 1611, 2713, 297, 267, 283, 12157, 3800, 22026, 3800, 12373, 7146, 83, 297, 272, 2156, 272, 1846, 63, 1802, 29, 2809, 63, 1802, 12, 199, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
sander76/home-assistant
homeassistant/components/almond/__init__.py
3
10130
"""Support for Almond.""" from __future__ import annotations import asyncio from datetime import timedelta import logging import time from aiohttp import ClientError, ClientSession import async_timeout from pyalmond import AbstractAlmondWebAuth, AlmondLocalAuth, WebAlmondAPI import voluptuous as vol from homeassistant import config_entries from homeassistant.auth.const import GROUP_ID_ADMIN from homeassistant.components import conversation from homeassistant.const import ( CONF_CLIENT_ID, CONF_CLIENT_SECRET, CONF_HOST, CONF_TYPE, EVENT_HOMEASSISTANT_START, ) from homeassistant.core import Context, CoreState, HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers import ( aiohttp_client, config_entry_oauth2_flow, config_validation as cv, event, intent, network, storage, ) from . import config_flow from .const import DOMAIN, TYPE_LOCAL, TYPE_OAUTH2 STORAGE_VERSION = 1 STORAGE_KEY = DOMAIN ALMOND_SETUP_DELAY = 30 DEFAULT_OAUTH2_HOST = "https://almond.stanford.edu" DEFAULT_LOCAL_HOST = "http://localhost:3000" CONFIG_SCHEMA = vol.Schema( { DOMAIN: vol.Any( vol.Schema( { vol.Required(CONF_TYPE): TYPE_OAUTH2, vol.Required(CONF_CLIENT_ID): cv.string, vol.Required(CONF_CLIENT_SECRET): cv.string, vol.Optional(CONF_HOST, default=DEFAULT_OAUTH2_HOST): cv.url, } ), vol.Schema( {vol.Required(CONF_TYPE): TYPE_LOCAL, vol.Required(CONF_HOST): cv.url} ), ) }, extra=vol.ALLOW_EXTRA, ) _LOGGER = logging.getLogger(__name__) async def async_setup(hass, config): """Set up the Almond component.""" hass.data[DOMAIN] = {} if DOMAIN not in config: return True conf = config[DOMAIN] host = conf[CONF_HOST] if conf[CONF_TYPE] == TYPE_OAUTH2: config_flow.AlmondFlowHandler.async_register_implementation( hass, config_entry_oauth2_flow.LocalOAuth2Implementation( hass, DOMAIN, conf[CONF_CLIENT_ID], conf[CONF_CLIENT_SECRET], f"{host}/me/api/oauth2/authorize", f"{host}/me/api/oauth2/token", ), ) return True if not hass.config_entries.async_entries(DOMAIN): hass.async_create_task( hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={"type": TYPE_LOCAL, "host": conf[CONF_HOST]}, ) ) return True async def async_setup_entry(hass: HomeAssistant, entry: config_entries.ConfigEntry): """Set up Almond config entry.""" websession = aiohttp_client.async_get_clientsession(hass) if entry.data["type"] == TYPE_LOCAL: auth = AlmondLocalAuth(entry.data["host"], websession) else: # OAuth2 implementation = ( await config_entry_oauth2_flow.async_get_config_entry_implementation( hass, entry ) ) oauth_session = config_entry_oauth2_flow.OAuth2Session( hass, entry, implementation ) auth = AlmondOAuth(entry.data["host"], websession, oauth_session) api = WebAlmondAPI(auth) agent = AlmondAgent(hass, api, entry) # Hass.io does its own configuration. if not entry.data.get("is_hassio"): # If we're not starting or local, set up Almond right away if hass.state != CoreState.not_running or entry.data["type"] == TYPE_LOCAL: await _configure_almond_for_ha(hass, entry, api) else: # OAuth2 implementations can potentially rely on the HA Cloud url. # This url is not be available until 30 seconds after boot. async def configure_almond(_now): try: await _configure_almond_for_ha(hass, entry, api) except ConfigEntryNotReady: _LOGGER.warning( "Unable to configure Almond to connect to Home Assistant" ) async def almond_hass_start(_event): event.async_call_later(hass, ALMOND_SETUP_DELAY, configure_almond) hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, almond_hass_start) conversation.async_set_agent(hass, agent) return True async def _configure_almond_for_ha( hass: HomeAssistant, entry: config_entries.ConfigEntry, api: WebAlmondAPI ): """Configure Almond to connect to HA.""" try: if entry.data["type"] == TYPE_OAUTH2: # If we're connecting over OAuth2, we will only set up connection # with Home Assistant if we're remotely accessible. hass_url = network.get_url(hass, allow_internal=False, prefer_cloud=True) else: hass_url = network.get_url(hass) except network.NoURLAvailableError: # If no URL is available, we're not going to configure Almond to connect to HA. return _LOGGER.debug("Configuring Almond to connect to Home Assistant at %s", hass_url) store = storage.Store(hass, STORAGE_VERSION, STORAGE_KEY) data = await store.async_load() if data is None: data = {} user = None if "almond_user" in data: user = await hass.auth.async_get_user(data["almond_user"]) if user is None: user = await hass.auth.async_create_system_user("Almond", [GROUP_ID_ADMIN]) data["almond_user"] = user.id await store.async_save(data) refresh_token = await hass.auth.async_create_refresh_token( user, # Almond will be fine as long as we restart once every 5 years access_token_expiration=timedelta(days=365 * 5), ) # Create long lived access token access_token = hass.auth.async_create_access_token(refresh_token) # Store token in Almond try: with async_timeout.timeout(30): await api.async_create_device( { "kind": "io.home-assistant", "hassUrl": hass_url, "accessToken": access_token, "refreshToken": "", # 5 years from now in ms. "accessTokenExpires": (time.time() + 60 * 60 * 24 * 365 * 5) * 1000, } ) except (asyncio.TimeoutError, ClientError) as err: if isinstance(err, asyncio.TimeoutError): msg = "Request timeout" else: msg = err _LOGGER.warning("Unable to configure Almond: %s", msg) await hass.auth.async_remove_refresh_token(refresh_token) raise ConfigEntryNotReady from err # Clear all other refresh tokens for token in list(user.refresh_tokens.values()): if token.id != refresh_token.id: await hass.auth.async_remove_refresh_token(token) async def async_unload_entry(hass, entry): """Unload Almond.""" conversation.async_set_agent(hass, None) return True class AlmondOAuth(AbstractAlmondWebAuth): """Almond Authentication using OAuth2.""" def __init__( self, host: str, websession: ClientSession, oauth_session: config_entry_oauth2_flow.OAuth2Session, ): """Initialize Almond auth.""" super().__init__(host, websession) self._oauth_session = oauth_session async def async_get_access_token(self): """Return a valid access token.""" if not self._oauth_session.valid_token: await self._oauth_session.async_ensure_token_valid() return self._oauth_session.token["access_token"] class AlmondAgent(conversation.AbstractConversationAgent): """Almond conversation agent.""" def __init__( self, hass: HomeAssistant, api: WebAlmondAPI, entry: config_entries.ConfigEntry ): """Initialize the agent.""" self.hass = hass self.api = api self.entry = entry @property def attribution(self): """Return the attribution.""" return {"name": "Powered by Almond", "url": "https://almond.stanford.edu/"} async def async_get_onboarding(self): """Get onboard url if not onboarded.""" if self.entry.data.get("onboarded"): return None host = self.entry.data["host"] if self.entry.data.get("is_hassio"): host = "/core_almond" return { "text": "Would you like to opt-in to share your anonymized commands with Stanford to improve Almond's responses?", "url": f"{host}/conversation", } async def async_set_onboarding(self, shown): """Set onboarding status.""" self.hass.config_entries.async_update_entry( self.entry, data={**self.entry.data, "onboarded": shown} ) return True async def async_process( self, text: str, context: Context, conversation_id: str | None = None ) -> intent.IntentResponse: """Process a sentence.""" response = await self.api.async_converse_text(text, conversation_id) first_choice = True buffer = "" for message in response["messages"]: if message["type"] == "text": buffer += f"\n{message['text']}" elif message["type"] == "picture": buffer += f"\n Picture: {message['url']}" elif message["type"] == "rdl": buffer += ( f"\n Link: {message['rdl']['displayTitle']} " f"{message['rdl']['webCallback']}" ) elif message["type"] == "choice": if first_choice: first_choice = False else: buffer += "," buffer += f" {message['title']}" intent_result = intent.IntentResponse() intent_result.async_set_speech(buffer.strip()) return intent_result
apache-2.0
[ 624, 11532, 367, 4580, 2106, 68, 1041, 199, 504, 636, 2443, 363, 492, 15538, 199, 199, 646, 16195, 199, 504, 2197, 492, 6871, 199, 646, 2050, 199, 646, 900, 199, 199, 504, 30274, 492, 28972, 12, 6810, 4434, 199, 646, 5316, 63, 2593, 199, 504, 1134, 279, 2106, 68, 492, 11836, 2439, 2106, 68, 5926, 2817, 12, 4580, 2106, 68, 5339, 2817, 12, 6001, 2439, 2106, 68, 3735, 199, 646, 30291, 465, 5236, 199, 199, 504, 8846, 492, 1101, 63, 3189, 199, 504, 8846, 14, 1178, 14, 1297, 492, 15443, 63, 998, 63, 14288, 199, 504, 8846, 14, 4608, 492, 3818, 20592, 199, 504, 8846, 14, 1297, 492, 334, 272, 6392, 63, 9901, 63, 998, 12, 272, 6392, 63, 9901, 63, 12961, 12, 272, 6392, 63, 5449, 12, 272, 6392, 63, 2711, 12, 272, 6461, 63, 9524, 16435, 840, 1441, 63, 7363, 12, 199, 9, 199, 504, 8846, 14, 1018, 492, 9470, 12, 11672, 2223, 12, 29913, 199, 504, 8846, 14, 3924, 492, 4094, 3900, 1763, 17960, 199, 504, 8846, 14, 7546, 492, 334, 272, 30274, 63, 1258, 12, 272, 1101, 63, 2373, 63, 6126, 18, 63, 1659, 12, 272, 1101, 63, 6136, 465, 6277, 12, 272, 1566, 12, 272, 21020, 12, 272, 2784, 12, 272, 4887, 12, 199, 9, 199, 199, 504, 1275, 492, 1101, 63, 1659, 199, 504, 1275, 1297, 492, 15265, 12, 11511, 63, 7486, 12, 11511, 63, 24041, 18, 199, 199, 17467, 63, 4612, 275, 413, 199, 17467, 63, 3078, 275, 15265, 199, 199, 748, 11710, 36, 63, 20836, 63, 18616, 275, 4233, 199, 199, 3472, 63, 24041, 18, 63, 5449, 275, 298, 2859, 921, 279, 2106, 68, 14, 9746, 18090, 14, 8654, 2, 199, 3472, 63, 7486, 63, 5449, 275, 298, 1014, 921, 5967, 26, 19962, 2, 199, 199, 5569, 63, 10926, 275, 5236, 14, 6700, 8, 272, 469, 267, 15265, 26, 5236, 14, 9874, 8, 288, 5236, 14, 6700, 8, 355, 469, 490, 5236, 14, 8030, 8, 3103, 63, 2711, 304, 11511, 63, 24041, 18, 12, 490, 5236, 14, 8030, 8, 3103, 63, 9901, 63, 998, 304, 6277, 14, 875, 12, 490, 5236, 14, 8030, 8, 3103, 63, 9901, 63, 12961, 304, 6277, 14, 875, 12, 490, 5236, 14, 7012, 8, 3103, 63, 5449, 12, 849, 29, 3472, 63, 24041, 18, 63, 5449, 304, 6277, 14, 633, 12, 355, 789, 288, 2318, 288, 5236, 14, 6700, 8, 355, 469, 5650, 14, 8030, 8, 3103, 63, 2711, 304, 11511, 63, 7486, 12, 5236, 14, 8030, 8, 3103, 63, 5449, 304, 6277, 14, 633, 93, 288, 2318, 267, 776, 272, 1660, 272, 2402, 29, 5650, 14, 12231, 63, 18555, 12, 199, 9, 199, 63, 10186, 275, 2050, 14, 5572, 3460, 354, 3368, 421, 199, 4146, 347, 5316, 63, 2758, 8, 5387, 12, 1101, 304, 272, 408, 1084, 1536, 314, 4580, 2106, 68, 3931, 1041, 272, 6298, 14, 576, 59, 7378, 61, 275, 1052, 339, 340, 15265, 440, 315, 1101, 26, 267, 372, 715, 339, 3743, 275, 1101, 59, 7378, 61, 339, 1591, 275, 3743, 59, 3103, 63, 5449, 61, 339, 340, 3743, 59, 3103, 63, 2711, 61, 508, 11511, 63, 24041, 18, 26, 267, 1101, 63, 1659, 14, 2439, 2106, 68, 5060, 2461, 14, 4146, 63, 2683, 63, 12236, 8, 288, 6298, 12, 288, 1101, 63, 2373, 63, 6126, 18, 63, 1659, 14, 5339, 12906, 18, 7921, 8, 355, 6298, 12, 355, 15265, 12, 355, 3743, 59, 3103, 63, 9901, 63, 998, 467, 355, 3743, 59, 3103, 63, 9901, 63, 12961, 467, 355, 289, 14381, 1102, 5995, 278, 15, 1246, 15, 6126, 18, 15, 14204, 401, 355, 289, 14381, 1102, 5995, 278, 15, 1246, 15, 6126, 18, 15, 1418, 401, 288, 2318, 267, 776, 267, 372, 715, 339, 340, 440, 6298, 14, 888, 63, 3189, 14, 4146, 63, 3189, 8, 7378, 304, 267, 6298, 14, 4146, 63, 981, 63, 1765, 8, 288, 6298, 14, 888, 63, 3189, 14, 1659, 14, 4146, 63, 826, 8, 355, 15265, 12, 355, 1067, 8871, 1365, 582, 1101, 63, 3189, 14, 10187, 63, 17576, 1386, 355, 666, 8871, 466, 582, 11511, 63, 7486, 12, 298, 1102, 582, 3743, 59, 3103, 63, 5449, 13888, 288, 776, 267, 776, 272, 372, 715, 421, 199, 4146, 347, 5316, 63, 2758, 63, 2373, 8, 5387, 26, 29913, 12, 2397, 26, 1101, 63, 3189, 14, 2028, 3900, 304, 272, 408, 1084, 1536, 4580, 2106, 68, 1101, 2397, 1041, 272, 3330, 1730, 275, 30274, 63, 1258, 14, 4146, 63, 362, 63, 1258, 1730, 8, 5387, 9, 339, 340, 2397, 14, 576, 905, 466, 937, 508, 11511, 63, 7486, 26, 267, 1790, 275, 4580, 2106, 68, 5339, 2817, 8, 2373, 14, 576, 905, 1102, 2255, 3330, 1730, 9, 272, 587, 26, 267, 327, 11715, 18, 267, 4514, 275, 334, 288, 5517, 1101, 63, 2373, 63, 6126, 18, 63, 1659, 14, 4146, 63, 362, 63, 888, 63, 2373, 63, 12236, 8, 355, 6298, 12, 2397, 288, 776, 267, 776, 267, 9725, 63, 1730, 275, 1101, 63, 2373, 63, 6126, 18, 63, 1659, 14, 12906, 18, 4434, 8, 288, 6298, 12, 2397, 12, 4514, 267, 776, 267, 1790, 275, 4580, 2106, 68, 12906, 8, 2373, 14, 576, 905, 1102, 2255, 3330, 1730, 12, 9725, 63, 1730, 9, 339, 2986, 275, 6001, 2439, 2106, 68, 3735, 8, 1178, 9, 272, 6631, 275, 4580, 2106, 68, 7788, 8, 5387, 12, 2986, 12, 2397, 9, 339, 327, 869, 405, 14, 2308, 1630, 2399, 5705, 2897, 14, 272, 340, 440, 2397, 14, 576, 14, 362, 480, 374, 63, 1989, 22961, 2349, 267, 327, 982, 781, 3984, 440, 6617, 503, 2257, 12, 663, 1536, 4580, 2106, 68, 2451, 13437, 267, 340, 6298, 14, 929, 1137, 11672, 2223, 14, 1397, 63, 5720, 503, 2397, 14, 576, 905, 466, 937, 508, 11511, 63, 7486, 26, 288, 5517, 485, 6472, 63, 279, 2106, 68, 63, 509, 63, 2411, 8, 5387, 12, 2397, 12, 2986, 9, 398, 587, 26, 288, 327, 11715, 18, 12591, 883, 18994, 19687, 641, 314, 16100, 8142, 1166, 14, 288, 327, 961, 1166, 365, 440, 506, 2808, 5133, 4233, 4696, 2410, 8498, 14, 953, 5316, 347, 7908, 63, 279, 2106, 68, 1547, 2131, 304, 355, 862, 26, 490, 5517, 485, 6472, 63, 279, 2106, 68, 63, 509, 63, 2411 ]
[ 11532, 367, 4580, 2106, 68, 1041, 199, 504, 636, 2443, 363, 492, 15538, 199, 199, 646, 16195, 199, 504, 2197, 492, 6871, 199, 646, 2050, 199, 646, 900, 199, 199, 504, 30274, 492, 28972, 12, 6810, 4434, 199, 646, 5316, 63, 2593, 199, 504, 1134, 279, 2106, 68, 492, 11836, 2439, 2106, 68, 5926, 2817, 12, 4580, 2106, 68, 5339, 2817, 12, 6001, 2439, 2106, 68, 3735, 199, 646, 30291, 465, 5236, 199, 199, 504, 8846, 492, 1101, 63, 3189, 199, 504, 8846, 14, 1178, 14, 1297, 492, 15443, 63, 998, 63, 14288, 199, 504, 8846, 14, 4608, 492, 3818, 20592, 199, 504, 8846, 14, 1297, 492, 334, 272, 6392, 63, 9901, 63, 998, 12, 272, 6392, 63, 9901, 63, 12961, 12, 272, 6392, 63, 5449, 12, 272, 6392, 63, 2711, 12, 272, 6461, 63, 9524, 16435, 840, 1441, 63, 7363, 12, 199, 9, 199, 504, 8846, 14, 1018, 492, 9470, 12, 11672, 2223, 12, 29913, 199, 504, 8846, 14, 3924, 492, 4094, 3900, 1763, 17960, 199, 504, 8846, 14, 7546, 492, 334, 272, 30274, 63, 1258, 12, 272, 1101, 63, 2373, 63, 6126, 18, 63, 1659, 12, 272, 1101, 63, 6136, 465, 6277, 12, 272, 1566, 12, 272, 21020, 12, 272, 2784, 12, 272, 4887, 12, 199, 9, 199, 199, 504, 1275, 492, 1101, 63, 1659, 199, 504, 1275, 1297, 492, 15265, 12, 11511, 63, 7486, 12, 11511, 63, 24041, 18, 199, 199, 17467, 63, 4612, 275, 413, 199, 17467, 63, 3078, 275, 15265, 199, 199, 748, 11710, 36, 63, 20836, 63, 18616, 275, 4233, 199, 199, 3472, 63, 24041, 18, 63, 5449, 275, 298, 2859, 921, 279, 2106, 68, 14, 9746, 18090, 14, 8654, 2, 199, 3472, 63, 7486, 63, 5449, 275, 298, 1014, 921, 5967, 26, 19962, 2, 199, 199, 5569, 63, 10926, 275, 5236, 14, 6700, 8, 272, 469, 267, 15265, 26, 5236, 14, 9874, 8, 288, 5236, 14, 6700, 8, 355, 469, 490, 5236, 14, 8030, 8, 3103, 63, 2711, 304, 11511, 63, 24041, 18, 12, 490, 5236, 14, 8030, 8, 3103, 63, 9901, 63, 998, 304, 6277, 14, 875, 12, 490, 5236, 14, 8030, 8, 3103, 63, 9901, 63, 12961, 304, 6277, 14, 875, 12, 490, 5236, 14, 7012, 8, 3103, 63, 5449, 12, 849, 29, 3472, 63, 24041, 18, 63, 5449, 304, 6277, 14, 633, 12, 355, 789, 288, 2318, 288, 5236, 14, 6700, 8, 355, 469, 5650, 14, 8030, 8, 3103, 63, 2711, 304, 11511, 63, 7486, 12, 5236, 14, 8030, 8, 3103, 63, 5449, 304, 6277, 14, 633, 93, 288, 2318, 267, 776, 272, 1660, 272, 2402, 29, 5650, 14, 12231, 63, 18555, 12, 199, 9, 199, 63, 10186, 275, 2050, 14, 5572, 3460, 354, 3368, 421, 199, 4146, 347, 5316, 63, 2758, 8, 5387, 12, 1101, 304, 272, 408, 1084, 1536, 314, 4580, 2106, 68, 3931, 1041, 272, 6298, 14, 576, 59, 7378, 61, 275, 1052, 339, 340, 15265, 440, 315, 1101, 26, 267, 372, 715, 339, 3743, 275, 1101, 59, 7378, 61, 339, 1591, 275, 3743, 59, 3103, 63, 5449, 61, 339, 340, 3743, 59, 3103, 63, 2711, 61, 508, 11511, 63, 24041, 18, 26, 267, 1101, 63, 1659, 14, 2439, 2106, 68, 5060, 2461, 14, 4146, 63, 2683, 63, 12236, 8, 288, 6298, 12, 288, 1101, 63, 2373, 63, 6126, 18, 63, 1659, 14, 5339, 12906, 18, 7921, 8, 355, 6298, 12, 355, 15265, 12, 355, 3743, 59, 3103, 63, 9901, 63, 998, 467, 355, 3743, 59, 3103, 63, 9901, 63, 12961, 467, 355, 289, 14381, 1102, 5995, 278, 15, 1246, 15, 6126, 18, 15, 14204, 401, 355, 289, 14381, 1102, 5995, 278, 15, 1246, 15, 6126, 18, 15, 1418, 401, 288, 2318, 267, 776, 267, 372, 715, 339, 340, 440, 6298, 14, 888, 63, 3189, 14, 4146, 63, 3189, 8, 7378, 304, 267, 6298, 14, 4146, 63, 981, 63, 1765, 8, 288, 6298, 14, 888, 63, 3189, 14, 1659, 14, 4146, 63, 826, 8, 355, 15265, 12, 355, 1067, 8871, 1365, 582, 1101, 63, 3189, 14, 10187, 63, 17576, 1386, 355, 666, 8871, 466, 582, 11511, 63, 7486, 12, 298, 1102, 582, 3743, 59, 3103, 63, 5449, 13888, 288, 776, 267, 776, 272, 372, 715, 421, 199, 4146, 347, 5316, 63, 2758, 63, 2373, 8, 5387, 26, 29913, 12, 2397, 26, 1101, 63, 3189, 14, 2028, 3900, 304, 272, 408, 1084, 1536, 4580, 2106, 68, 1101, 2397, 1041, 272, 3330, 1730, 275, 30274, 63, 1258, 14, 4146, 63, 362, 63, 1258, 1730, 8, 5387, 9, 339, 340, 2397, 14, 576, 905, 466, 937, 508, 11511, 63, 7486, 26, 267, 1790, 275, 4580, 2106, 68, 5339, 2817, 8, 2373, 14, 576, 905, 1102, 2255, 3330, 1730, 9, 272, 587, 26, 267, 327, 11715, 18, 267, 4514, 275, 334, 288, 5517, 1101, 63, 2373, 63, 6126, 18, 63, 1659, 14, 4146, 63, 362, 63, 888, 63, 2373, 63, 12236, 8, 355, 6298, 12, 2397, 288, 776, 267, 776, 267, 9725, 63, 1730, 275, 1101, 63, 2373, 63, 6126, 18, 63, 1659, 14, 12906, 18, 4434, 8, 288, 6298, 12, 2397, 12, 4514, 267, 776, 267, 1790, 275, 4580, 2106, 68, 12906, 8, 2373, 14, 576, 905, 1102, 2255, 3330, 1730, 12, 9725, 63, 1730, 9, 339, 2986, 275, 6001, 2439, 2106, 68, 3735, 8, 1178, 9, 272, 6631, 275, 4580, 2106, 68, 7788, 8, 5387, 12, 2986, 12, 2397, 9, 339, 327, 869, 405, 14, 2308, 1630, 2399, 5705, 2897, 14, 272, 340, 440, 2397, 14, 576, 14, 362, 480, 374, 63, 1989, 22961, 2349, 267, 327, 982, 781, 3984, 440, 6617, 503, 2257, 12, 663, 1536, 4580, 2106, 68, 2451, 13437, 267, 340, 6298, 14, 929, 1137, 11672, 2223, 14, 1397, 63, 5720, 503, 2397, 14, 576, 905, 466, 937, 508, 11511, 63, 7486, 26, 288, 5517, 485, 6472, 63, 279, 2106, 68, 63, 509, 63, 2411, 8, 5387, 12, 2397, 12, 2986, 9, 398, 587, 26, 288, 327, 11715, 18, 12591, 883, 18994, 19687, 641, 314, 16100, 8142, 1166,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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
ArcherSys/ArcherSys
node_modules/npm/node_modules/node-gyp/gyp/buildbot/buildbot_run.py
1
18134
<<<<<<< HEAD <<<<<<< HEAD #!/usr/bin/env python # Copyright (c) 2012 Google Inc. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Argument-less script to select what to run on the buildbots.""" import os import shutil import subprocess import sys if sys.platform in ['win32', 'cygwin']: EXE_SUFFIX = '.exe' else: EXE_SUFFIX = '' BUILDBOT_DIR = os.path.dirname(os.path.abspath(__file__)) TRUNK_DIR = os.path.dirname(BUILDBOT_DIR) ROOT_DIR = os.path.dirname(TRUNK_DIR) ANDROID_DIR = os.path.join(ROOT_DIR, 'android') CMAKE_DIR = os.path.join(ROOT_DIR, 'cmake') CMAKE_BIN_DIR = os.path.join(CMAKE_DIR, 'bin') OUT_DIR = os.path.join(TRUNK_DIR, 'out') def CallSubProcess(*args, **kwargs): """Wrapper around subprocess.call which treats errors as build exceptions.""" retcode = subprocess.call(*args, **kwargs) if retcode != 0: print '@@@STEP_EXCEPTION@@@' sys.exit(1) def PrepareCmake(): """Build CMake 2.8.8 since the version in Precise is 2.8.7.""" if os.environ['BUILDBOT_CLOBBER'] == '1': print '@@@BUILD_STEP Clobber CMake checkout@@@' shutil.rmtree(CMAKE_DIR) # We always build CMake 2.8.8, so no need to do anything # if the directory already exists. if os.path.isdir(CMAKE_DIR): return print '@@@BUILD_STEP Initialize CMake checkout@@@' os.mkdir(CMAKE_DIR) CallSubProcess(['git', 'config', '--global', 'user.name', 'trybot']) CallSubProcess(['git', 'config', '--global', 'user.email', 'chrome-bot@google.com']) CallSubProcess(['git', 'config', '--global', 'color.ui', 'false']) print '@@@BUILD_STEP Sync CMake@@@' CallSubProcess( ['git', 'clone', '--depth', '1', '--single-branch', '--branch', 'v2.8.8', '--', 'git://cmake.org/cmake.git', CMAKE_DIR], cwd=CMAKE_DIR) print '@@@BUILD_STEP Build CMake@@@' CallSubProcess( ['/bin/bash', 'bootstrap', '--prefix=%s' % CMAKE_DIR], cwd=CMAKE_DIR) CallSubProcess( ['make', 'cmake'], cwd=CMAKE_DIR) def PrepareAndroidTree(): """Prepare an Android tree to run 'android' format tests.""" if os.environ['BUILDBOT_CLOBBER'] == '1': print '@@@BUILD_STEP Clobber Android checkout@@@' shutil.rmtree(ANDROID_DIR) # The release of Android we use is static, so there's no need to do anything # if the directory already exists. if os.path.isdir(ANDROID_DIR): return print '@@@BUILD_STEP Initialize Android checkout@@@' os.mkdir(ANDROID_DIR) CallSubProcess(['git', 'config', '--global', 'user.name', 'trybot']) CallSubProcess(['git', 'config', '--global', 'user.email', 'chrome-bot@google.com']) CallSubProcess(['git', 'config', '--global', 'color.ui', 'false']) CallSubProcess( ['repo', 'init', '-u', 'https://android.googlesource.com/platform/manifest', '-b', 'android-4.2.1_r1', '-g', 'all,-notdefault,-device,-darwin,-mips,-x86'], cwd=ANDROID_DIR) print '@@@BUILD_STEP Sync Android@@@' CallSubProcess(['repo', 'sync', '-j4'], cwd=ANDROID_DIR) print '@@@BUILD_STEP Build Android@@@' CallSubProcess( ['/bin/bash', '-c', 'source build/envsetup.sh && lunch full-eng && make -j4'], cwd=ANDROID_DIR) def GypTestFormat(title, format=None, msvs_version=None): """Run the gyp tests for a given format, emitting annotator tags. See annotator docs at: https://sites.google.com/a/chromium.org/dev/developers/testing/chromium-build-infrastructure/buildbot-annotations Args: format: gyp format to test. Returns: 0 for sucesss, 1 for failure. """ if not format: format = title print '@@@BUILD_STEP ' + title + '@@@' sys.stdout.flush() env = os.environ.copy() if msvs_version: env['GYP_MSVS_VERSION'] = msvs_version command = ' '.join( [sys.executable, 'trunk/gyptest.py', '--all', '--passed', '--format', format, '--path', CMAKE_BIN_DIR, '--chdir', 'trunk']) if format == 'android': # gyptest needs the environment setup from envsetup/lunch in order to build # using the 'android' backend, so this is done in a single shell. retcode = subprocess.call( ['/bin/bash', '-c', 'source build/envsetup.sh && lunch full-eng && cd %s && %s' % (ROOT_DIR, command)], cwd=ANDROID_DIR, env=env) else: retcode = subprocess.call(command, cwd=ROOT_DIR, env=env, shell=True) if retcode: # Emit failure tag, and keep going. print '@@@STEP_FAILURE@@@' return 1 return 0 def GypBuild(): # Dump out/ directory. print '@@@BUILD_STEP cleanup@@@' print 'Removing %s...' % OUT_DIR shutil.rmtree(OUT_DIR, ignore_errors=True) print 'Done.' retcode = 0 # The Android gyp bot runs on linux so this must be tested first. if os.environ['BUILDBOT_BUILDERNAME'] == 'gyp-android': PrepareAndroidTree() retcode += GypTestFormat('android') elif sys.platform.startswith('linux'): retcode += GypTestFormat('ninja') retcode += GypTestFormat('make') PrepareCmake() retcode += GypTestFormat('cmake') elif sys.platform == 'darwin': retcode += GypTestFormat('ninja') retcode += GypTestFormat('xcode') retcode += GypTestFormat('make') elif sys.platform == 'win32': retcode += GypTestFormat('ninja') if os.environ['BUILDBOT_BUILDERNAME'] == 'gyp-win64': retcode += GypTestFormat('msvs-2010', format='msvs', msvs_version='2010') retcode += GypTestFormat('msvs-2012', format='msvs', msvs_version='2012') else: raise Exception('Unknown platform') if retcode: # TODO(bradnelson): once the annotator supports a postscript (section for # after the build proper that could be used for cumulative failures), # use that instead of this. This isolates the final return value so # that it isn't misattributed to the last stage. print '@@@BUILD_STEP failures@@@' sys.exit(retcode) if __name__ == '__main__': GypBuild() ======= #!/usr/bin/env python # Copyright (c) 2012 Google Inc. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Argument-less script to select what to run on the buildbots.""" import os import shutil import subprocess import sys if sys.platform in ['win32', 'cygwin']: EXE_SUFFIX = '.exe' else: EXE_SUFFIX = '' BUILDBOT_DIR = os.path.dirname(os.path.abspath(__file__)) TRUNK_DIR = os.path.dirname(BUILDBOT_DIR) ROOT_DIR = os.path.dirname(TRUNK_DIR) ANDROID_DIR = os.path.join(ROOT_DIR, 'android') CMAKE_DIR = os.path.join(ROOT_DIR, 'cmake') CMAKE_BIN_DIR = os.path.join(CMAKE_DIR, 'bin') OUT_DIR = os.path.join(TRUNK_DIR, 'out') def CallSubProcess(*args, **kwargs): """Wrapper around subprocess.call which treats errors as build exceptions.""" retcode = subprocess.call(*args, **kwargs) if retcode != 0: print '@@@STEP_EXCEPTION@@@' sys.exit(1) def PrepareCmake(): """Build CMake 2.8.8 since the version in Precise is 2.8.7.""" if os.environ['BUILDBOT_CLOBBER'] == '1': print '@@@BUILD_STEP Clobber CMake checkout@@@' shutil.rmtree(CMAKE_DIR) # We always build CMake 2.8.8, so no need to do anything # if the directory already exists. if os.path.isdir(CMAKE_DIR): return print '@@@BUILD_STEP Initialize CMake checkout@@@' os.mkdir(CMAKE_DIR) CallSubProcess(['git', 'config', '--global', 'user.name', 'trybot']) CallSubProcess(['git', 'config', '--global', 'user.email', 'chrome-bot@google.com']) CallSubProcess(['git', 'config', '--global', 'color.ui', 'false']) print '@@@BUILD_STEP Sync CMake@@@' CallSubProcess( ['git', 'clone', '--depth', '1', '--single-branch', '--branch', 'v2.8.8', '--', 'git://cmake.org/cmake.git', CMAKE_DIR], cwd=CMAKE_DIR) print '@@@BUILD_STEP Build CMake@@@' CallSubProcess( ['/bin/bash', 'bootstrap', '--prefix=%s' % CMAKE_DIR], cwd=CMAKE_DIR) CallSubProcess( ['make', 'cmake'], cwd=CMAKE_DIR) def PrepareAndroidTree(): """Prepare an Android tree to run 'android' format tests.""" if os.environ['BUILDBOT_CLOBBER'] == '1': print '@@@BUILD_STEP Clobber Android checkout@@@' shutil.rmtree(ANDROID_DIR) # The release of Android we use is static, so there's no need to do anything # if the directory already exists. if os.path.isdir(ANDROID_DIR): return print '@@@BUILD_STEP Initialize Android checkout@@@' os.mkdir(ANDROID_DIR) CallSubProcess(['git', 'config', '--global', 'user.name', 'trybot']) CallSubProcess(['git', 'config', '--global', 'user.email', 'chrome-bot@google.com']) CallSubProcess(['git', 'config', '--global', 'color.ui', 'false']) CallSubProcess( ['repo', 'init', '-u', 'https://android.googlesource.com/platform/manifest', '-b', 'android-4.2.1_r1', '-g', 'all,-notdefault,-device,-darwin,-mips,-x86'], cwd=ANDROID_DIR) print '@@@BUILD_STEP Sync Android@@@' CallSubProcess(['repo', 'sync', '-j4'], cwd=ANDROID_DIR) print '@@@BUILD_STEP Build Android@@@' CallSubProcess( ['/bin/bash', '-c', 'source build/envsetup.sh && lunch full-eng && make -j4'], cwd=ANDROID_DIR) def GypTestFormat(title, format=None, msvs_version=None): """Run the gyp tests for a given format, emitting annotator tags. See annotator docs at: https://sites.google.com/a/chromium.org/dev/developers/testing/chromium-build-infrastructure/buildbot-annotations Args: format: gyp format to test. Returns: 0 for sucesss, 1 for failure. """ if not format: format = title print '@@@BUILD_STEP ' + title + '@@@' sys.stdout.flush() env = os.environ.copy() if msvs_version: env['GYP_MSVS_VERSION'] = msvs_version command = ' '.join( [sys.executable, 'trunk/gyptest.py', '--all', '--passed', '--format', format, '--path', CMAKE_BIN_DIR, '--chdir', 'trunk']) if format == 'android': # gyptest needs the environment setup from envsetup/lunch in order to build # using the 'android' backend, so this is done in a single shell. retcode = subprocess.call( ['/bin/bash', '-c', 'source build/envsetup.sh && lunch full-eng && cd %s && %s' % (ROOT_DIR, command)], cwd=ANDROID_DIR, env=env) else: retcode = subprocess.call(command, cwd=ROOT_DIR, env=env, shell=True) if retcode: # Emit failure tag, and keep going. print '@@@STEP_FAILURE@@@' return 1 return 0 def GypBuild(): # Dump out/ directory. print '@@@BUILD_STEP cleanup@@@' print 'Removing %s...' % OUT_DIR shutil.rmtree(OUT_DIR, ignore_errors=True) print 'Done.' retcode = 0 # The Android gyp bot runs on linux so this must be tested first. if os.environ['BUILDBOT_BUILDERNAME'] == 'gyp-android': PrepareAndroidTree() retcode += GypTestFormat('android') elif sys.platform.startswith('linux'): retcode += GypTestFormat('ninja') retcode += GypTestFormat('make') PrepareCmake() retcode += GypTestFormat('cmake') elif sys.platform == 'darwin': retcode += GypTestFormat('ninja') retcode += GypTestFormat('xcode') retcode += GypTestFormat('make') elif sys.platform == 'win32': retcode += GypTestFormat('ninja') if os.environ['BUILDBOT_BUILDERNAME'] == 'gyp-win64': retcode += GypTestFormat('msvs-2010', format='msvs', msvs_version='2010') retcode += GypTestFormat('msvs-2012', format='msvs', msvs_version='2012') else: raise Exception('Unknown platform') if retcode: # TODO(bradnelson): once the annotator supports a postscript (section for # after the build proper that could be used for cumulative failures), # use that instead of this. This isolates the final return value so # that it isn't misattributed to the last stage. print '@@@BUILD_STEP failures@@@' sys.exit(retcode) if __name__ == '__main__': GypBuild() >>>>>>> b875702c9c06ab5012e52ff4337439b03918f453 ======= #!/usr/bin/env python # Copyright (c) 2012 Google Inc. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Argument-less script to select what to run on the buildbots.""" import os import shutil import subprocess import sys if sys.platform in ['win32', 'cygwin']: EXE_SUFFIX = '.exe' else: EXE_SUFFIX = '' BUILDBOT_DIR = os.path.dirname(os.path.abspath(__file__)) TRUNK_DIR = os.path.dirname(BUILDBOT_DIR) ROOT_DIR = os.path.dirname(TRUNK_DIR) ANDROID_DIR = os.path.join(ROOT_DIR, 'android') CMAKE_DIR = os.path.join(ROOT_DIR, 'cmake') CMAKE_BIN_DIR = os.path.join(CMAKE_DIR, 'bin') OUT_DIR = os.path.join(TRUNK_DIR, 'out') def CallSubProcess(*args, **kwargs): """Wrapper around subprocess.call which treats errors as build exceptions.""" retcode = subprocess.call(*args, **kwargs) if retcode != 0: print '@@@STEP_EXCEPTION@@@' sys.exit(1) def PrepareCmake(): """Build CMake 2.8.8 since the version in Precise is 2.8.7.""" if os.environ['BUILDBOT_CLOBBER'] == '1': print '@@@BUILD_STEP Clobber CMake checkout@@@' shutil.rmtree(CMAKE_DIR) # We always build CMake 2.8.8, so no need to do anything # if the directory already exists. if os.path.isdir(CMAKE_DIR): return print '@@@BUILD_STEP Initialize CMake checkout@@@' os.mkdir(CMAKE_DIR) CallSubProcess(['git', 'config', '--global', 'user.name', 'trybot']) CallSubProcess(['git', 'config', '--global', 'user.email', 'chrome-bot@google.com']) CallSubProcess(['git', 'config', '--global', 'color.ui', 'false']) print '@@@BUILD_STEP Sync CMake@@@' CallSubProcess( ['git', 'clone', '--depth', '1', '--single-branch', '--branch', 'v2.8.8', '--', 'git://cmake.org/cmake.git', CMAKE_DIR], cwd=CMAKE_DIR) print '@@@BUILD_STEP Build CMake@@@' CallSubProcess( ['/bin/bash', 'bootstrap', '--prefix=%s' % CMAKE_DIR], cwd=CMAKE_DIR) CallSubProcess( ['make', 'cmake'], cwd=CMAKE_DIR) def PrepareAndroidTree(): """Prepare an Android tree to run 'android' format tests.""" if os.environ['BUILDBOT_CLOBBER'] == '1': print '@@@BUILD_STEP Clobber Android checkout@@@' shutil.rmtree(ANDROID_DIR) # The release of Android we use is static, so there's no need to do anything # if the directory already exists. if os.path.isdir(ANDROID_DIR): return print '@@@BUILD_STEP Initialize Android checkout@@@' os.mkdir(ANDROID_DIR) CallSubProcess(['git', 'config', '--global', 'user.name', 'trybot']) CallSubProcess(['git', 'config', '--global', 'user.email', 'chrome-bot@google.com']) CallSubProcess(['git', 'config', '--global', 'color.ui', 'false']) CallSubProcess( ['repo', 'init', '-u', 'https://android.googlesource.com/platform/manifest', '-b', 'android-4.2.1_r1', '-g', 'all,-notdefault,-device,-darwin,-mips,-x86'], cwd=ANDROID_DIR) print '@@@BUILD_STEP Sync Android@@@' CallSubProcess(['repo', 'sync', '-j4'], cwd=ANDROID_DIR) print '@@@BUILD_STEP Build Android@@@' CallSubProcess( ['/bin/bash', '-c', 'source build/envsetup.sh && lunch full-eng && make -j4'], cwd=ANDROID_DIR) def GypTestFormat(title, format=None, msvs_version=None): """Run the gyp tests for a given format, emitting annotator tags. See annotator docs at: https://sites.google.com/a/chromium.org/dev/developers/testing/chromium-build-infrastructure/buildbot-annotations Args: format: gyp format to test. Returns: 0 for sucesss, 1 for failure. """ if not format: format = title print '@@@BUILD_STEP ' + title + '@@@' sys.stdout.flush() env = os.environ.copy() if msvs_version: env['GYP_MSVS_VERSION'] = msvs_version command = ' '.join( [sys.executable, 'trunk/gyptest.py', '--all', '--passed', '--format', format, '--path', CMAKE_BIN_DIR, '--chdir', 'trunk']) if format == 'android': # gyptest needs the environment setup from envsetup/lunch in order to build # using the 'android' backend, so this is done in a single shell. retcode = subprocess.call( ['/bin/bash', '-c', 'source build/envsetup.sh && lunch full-eng && cd %s && %s' % (ROOT_DIR, command)], cwd=ANDROID_DIR, env=env) else: retcode = subprocess.call(command, cwd=ROOT_DIR, env=env, shell=True) if retcode: # Emit failure tag, and keep going. print '@@@STEP_FAILURE@@@' return 1 return 0 def GypBuild(): # Dump out/ directory. print '@@@BUILD_STEP cleanup@@@' print 'Removing %s...' % OUT_DIR shutil.rmtree(OUT_DIR, ignore_errors=True) print 'Done.' retcode = 0 # The Android gyp bot runs on linux so this must be tested first. if os.environ['BUILDBOT_BUILDERNAME'] == 'gyp-android': PrepareAndroidTree() retcode += GypTestFormat('android') elif sys.platform.startswith('linux'): retcode += GypTestFormat('ninja') retcode += GypTestFormat('make') PrepareCmake() retcode += GypTestFormat('cmake') elif sys.platform == 'darwin': retcode += GypTestFormat('ninja') retcode += GypTestFormat('xcode') retcode += GypTestFormat('make') elif sys.platform == 'win32': retcode += GypTestFormat('ninja') if os.environ['BUILDBOT_BUILDERNAME'] == 'gyp-win64': retcode += GypTestFormat('msvs-2010', format='msvs', msvs_version='2010') retcode += GypTestFormat('msvs-2012', format='msvs', msvs_version='2012') else: raise Exception('Unknown platform') if retcode: # TODO(bradnelson): once the annotator supports a postscript (section for # after the build proper that could be used for cumulative failures), # use that instead of this. This isolates the final return value so # that it isn't misattributed to the last stage. print '@@@BUILD_STEP failures@@@' sys.exit(retcode) if __name__ == '__main__': GypBuild() >>>>>>> b875702c9c06ab5012e52ff4337439b03918f453
mit
[ 31275, 8999, 28, 13053, 199, 31275, 8999, 28, 13053, 199, 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 334, 67, 9, 6029, 4475, 3277, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 421, 199, 624, 5201, 13, 2003, 2884, 370, 3504, 4052, 370, 1255, 641, 314, 21306, 83, 1041, 421, 199, 646, 747, 199, 646, 5145, 199, 646, 3873, 199, 646, 984, 421, 199, 692, 984, 14, 3246, 315, 788, 2676, 708, 297, 283, 16680, 2565, 523, 3651, 37, 63, 12273, 275, 1987, 5803, 7, 199, 2836, 26, 523, 3651, 37, 63, 12273, 275, 2125, 421, 199, 18637, 2846, 1387, 63, 3022, 275, 747, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 4832, 3460, 493, 8964, 199, 1766, 8019, 63, 3022, 275, 747, 14, 515, 14, 3475, 8, 18637, 2846, 1387, 63, 3022, 9, 199, 5441, 63, 3022, 275, 747, 14, 515, 14, 3475, 8, 1766, 8019, 63, 3022, 9, 199, 25658, 63, 3022, 275, 747, 14, 515, 14, 904, 8, 5441, 63, 3022, 12, 283, 6238, 358, 199, 30250, 63, 3022, 275, 747, 14, 515, 14, 904, 8, 5441, 63, 3022, 12, 283, 16472, 358, 199, 30250, 63, 9431, 63, 3022, 275, 747, 14, 515, 14, 904, 8, 30250, 63, 3022, 12, 283, 1393, 358, 199, 1877, 63, 3022, 275, 747, 14, 515, 14, 904, 8, 1766, 8019, 63, 3022, 12, 283, 548, 358, 421, 199, 318, 6523, 2610, 3498, 2031, 589, 12, 1011, 958, 304, 523, 408, 4590, 6818, 3873, 14, 1250, 1314, 20991, 1956, 2552, 465, 1900, 4967, 1041, 523, 17375, 275, 3873, 14, 1250, 2031, 589, 12, 1011, 958, 9, 523, 340, 17375, 1137, 378, 26, 272, 870, 283, 25673, 17988, 63, 15375, 25673, 7, 272, 984, 14, 2224, 8, 17, 9, 421, 199, 318, 17008, 35, 1875, 837, 523, 408, 3425, 21355, 499, 14, 24, 14, 24, 3967, 314, 1015, 315, 5543, 11900, 365, 499, 14, 24, 14, 23, 1041, 523, 340, 747, 14, 2314, 459, 18637, 2846, 1387, 63, 10353, 5342, 540, 418, 508, 283, 17, 356, 272, 870, 283, 25673, 8248, 63, 17988, 445, 22669, 21355, 15243, 25673, 7, 272, 5145, 14, 9242, 8, 30250, 63, 3022, 9, 819, 327, 2136, 3544, 1900, 21355, 499, 14, 24, 14, 24, 12, 880, 949, 1929, 370, 886, 7003, 523, 327, 340, 314, 2082, 2575, 3495, 14, 523, 340, 747, 14, 515, 14, 6027, 8, 30250, 63, 3022, 304, 272, 372, 819, 870, 283, 25673, 8248, 63, 17988, 11578, 21355, 15243, 25673, 7, 523, 747, 14, 8215, 8, 30250, 63, 3022, 9, 523, 6523, 2610, 3498, 2941, 3187, 297, 283, 888, 297, 2850, 2966, 297, 283, 751, 14, 354, 297, 283, 893, 3018, 1105, 523, 6523, 2610, 3498, 2941, 3187, 297, 283, 888, 297, 2850, 2966, 297, 2116, 283, 751, 14, 2123, 297, 283, 9887, 13, 3018, 32, 3098, 14, 957, 1105, 523, 6523, 2610, 3498, 2941, 3187, 297, 283, 888, 297, 2850, 2966, 297, 283, 2326, 14, 1907, 297, 283, 3910, 1105, 819, 870, 283, 25673, 8248, 63, 17988, 22407, 21355, 25673, 7, 523, 6523, 2610, 3498, 8, 489, 788, 3187, 297, 283, 6311, 297, 2126, 2850, 4631, 297, 283, 17, 297, 2126, 2850, 4780, 13, 4694, 297, 2126, 2850, 4694, 297, 283, 86, 18, 14, 24, 14, 24, 297, 2126, 2850, 297, 2126, 283, 3187, 921, 16472, 14, 1308, 15, 16472, 14, 3187, 297, 2126, 445, 18421, 63, 3022, 467, 489, 8288, 29, 30250, 63, 3022, 9, 819, 870, 283, 25673, 8248, 63, 17988, 6516, 21355, 25673, 7, 523, 6523, 2610, 3498, 8, 489, 18744, 1393, 15, 16408, 297, 283, 11146, 297, 2850, 1861, 2458, 83, 7, 450, 445, 18421, 63, 3022, 467, 489, 8288, 29, 30250, 63, 3022, 9, 819, 6523, 2610, 3498, 8, 788, 1875, 297, 283, 16472, 995, 8288, 29, 30250, 63, 3022, 9, 421, 199, 318, 17008, 20762, 3987, 837, 523, 408, 22281, 376, 14694, 3123, 370, 1255, 283, 6238, 7, 1475, 2295, 1041, 523, 340, 747, 14, 2314, 459, 18637, 2846, 1387, 63, 10353, 5342, 540, 418, 508, 283, 17, 356, 272, 870, 283, 25673, 8248, 63, 17988, 445, 22669, 14694, 15243, 25673, 7, 272, 5145, 14, 9242, 8, 25658, 63, 3022, 9, 819, 327, 710, 4683, 402, 14694, 781, 675, 365, 2955, 12, 880, 2337, 1159, 949, 1929, 370, 886, 7003, 523, 327, 340, 314, 2082, 2575, 3495, 14, 523, 340, 747, 14, 515, 14, 6027, 8, 25658, 63, 3022, 304, 272, 372, 819, 870, 283, 25673, 8248, 63, 17988, 11578, 14694, 15243, 25673, 7, 523, 747, 14, 8215, 8, 25658, 63, 3022, 9, 523, 6523, 2610, 3498, 2941, 3187, 297, 283, 888, 297, 2850, 2966, 297, 283, 751, 14, 354, 297, 283, 893, 3018, 1105, 523, 6523, 2610, 3498, 2941, 3187, 297, 283, 888, 297, 2850, 2966, 297, 2116, 283, 751, 14, 2123, 297, 283, 9887, 13, 3018, 32, 3098, 14, 957, 1105, 523, 6523, 2610, 3498, 2941, 3187, 297, 283, 888, 297, 2850, 2966, 297, 283, 2326, 14, 1907, 297, 283, 3910, 1105, 523, 6523, 2610, 3498, 8, 489, 788, 3417, 297, 283, 826, 297, 2126, 2475, 85, 297, 283, 2859, 921, 6238, 14, 3098, 1365, 14, 957, 15, 3246, 15, 6418, 297, 2126, 2475, 66, 297, 283, 6238, 13, 20, 14, 18, 14, 17, 63, 82, 17, 297, 2126, 2475, 71, 297, 283, 452, 3057, 1397, 885, 3057, 1782, 3057, 13245, 3057, 77, 6142, 3057, 88, 1184, 995, 489, 8288, 29, 25658, 63, 3022, 9, 819, 870, 283, 25673, 8248, 63, 17988, 22407, 14694, 25673, 7, 523, 6523, 2610, 3498, 2941, 3417, 297, 283, 5186, 297, 2475, 74, 20, 995, 8288, 29, 25658, 63, 3022, 9, 819, 870, 283, 25673, 8248, 63, 17988, 6516, 14694, 25673, 7, 523, 6523, 2610, 3498, 8, 489, 18744, 1393, 15, 16408, 297, 2126, 2475, 67, 297, 283, 1365, 1900, 15, 1813, 2758, 14, 609, 10883, 634, 4689, 2615, 13, 7420, 10883, 1852, 446, 74, 20, 995, 489, 8288, 29, 25658, 63, 3022, 9, 421, 199, 318, 14133, 774, 3484, 8, 1213, 12, 1475, 29, 403, 12, 13795, 63, 1023, 29, 403, 304, 523, 408, 2540, 314, 4902 ]
[ 8999, 28, 13053, 199, 31275, 8999, 28, 13053, 199, 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 334, 67, 9, 6029, 4475, 3277, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 421, 199, 624, 5201, 13, 2003, 2884, 370, 3504, 4052, 370, 1255, 641, 314, 21306, 83, 1041, 421, 199, 646, 747, 199, 646, 5145, 199, 646, 3873, 199, 646, 984, 421, 199, 692, 984, 14, 3246, 315, 788, 2676, 708, 297, 283, 16680, 2565, 523, 3651, 37, 63, 12273, 275, 1987, 5803, 7, 199, 2836, 26, 523, 3651, 37, 63, 12273, 275, 2125, 421, 199, 18637, 2846, 1387, 63, 3022, 275, 747, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 4832, 3460, 493, 8964, 199, 1766, 8019, 63, 3022, 275, 747, 14, 515, 14, 3475, 8, 18637, 2846, 1387, 63, 3022, 9, 199, 5441, 63, 3022, 275, 747, 14, 515, 14, 3475, 8, 1766, 8019, 63, 3022, 9, 199, 25658, 63, 3022, 275, 747, 14, 515, 14, 904, 8, 5441, 63, 3022, 12, 283, 6238, 358, 199, 30250, 63, 3022, 275, 747, 14, 515, 14, 904, 8, 5441, 63, 3022, 12, 283, 16472, 358, 199, 30250, 63, 9431, 63, 3022, 275, 747, 14, 515, 14, 904, 8, 30250, 63, 3022, 12, 283, 1393, 358, 199, 1877, 63, 3022, 275, 747, 14, 515, 14, 904, 8, 1766, 8019, 63, 3022, 12, 283, 548, 358, 421, 199, 318, 6523, 2610, 3498, 2031, 589, 12, 1011, 958, 304, 523, 408, 4590, 6818, 3873, 14, 1250, 1314, 20991, 1956, 2552, 465, 1900, 4967, 1041, 523, 17375, 275, 3873, 14, 1250, 2031, 589, 12, 1011, 958, 9, 523, 340, 17375, 1137, 378, 26, 272, 870, 283, 25673, 17988, 63, 15375, 25673, 7, 272, 984, 14, 2224, 8, 17, 9, 421, 199, 318, 17008, 35, 1875, 837, 523, 408, 3425, 21355, 499, 14, 24, 14, 24, 3967, 314, 1015, 315, 5543, 11900, 365, 499, 14, 24, 14, 23, 1041, 523, 340, 747, 14, 2314, 459, 18637, 2846, 1387, 63, 10353, 5342, 540, 418, 508, 283, 17, 356, 272, 870, 283, 25673, 8248, 63, 17988, 445, 22669, 21355, 15243, 25673, 7, 272, 5145, 14, 9242, 8, 30250, 63, 3022, 9, 819, 327, 2136, 3544, 1900, 21355, 499, 14, 24, 14, 24, 12, 880, 949, 1929, 370, 886, 7003, 523, 327, 340, 314, 2082, 2575, 3495, 14, 523, 340, 747, 14, 515, 14, 6027, 8, 30250, 63, 3022, 304, 272, 372, 819, 870, 283, 25673, 8248, 63, 17988, 11578, 21355, 15243, 25673, 7, 523, 747, 14, 8215, 8, 30250, 63, 3022, 9, 523, 6523, 2610, 3498, 2941, 3187, 297, 283, 888, 297, 2850, 2966, 297, 283, 751, 14, 354, 297, 283, 893, 3018, 1105, 523, 6523, 2610, 3498, 2941, 3187, 297, 283, 888, 297, 2850, 2966, 297, 2116, 283, 751, 14, 2123, 297, 283, 9887, 13, 3018, 32, 3098, 14, 957, 1105, 523, 6523, 2610, 3498, 2941, 3187, 297, 283, 888, 297, 2850, 2966, 297, 283, 2326, 14, 1907, 297, 283, 3910, 1105, 819, 870, 283, 25673, 8248, 63, 17988, 22407, 21355, 25673, 7, 523, 6523, 2610, 3498, 8, 489, 788, 3187, 297, 283, 6311, 297, 2126, 2850, 4631, 297, 283, 17, 297, 2126, 2850, 4780, 13, 4694, 297, 2126, 2850, 4694, 297, 283, 86, 18, 14, 24, 14, 24, 297, 2126, 2850, 297, 2126, 283, 3187, 921, 16472, 14, 1308, 15, 16472, 14, 3187, 297, 2126, 445, 18421, 63, 3022, 467, 489, 8288, 29, 30250, 63, 3022, 9, 819, 870, 283, 25673, 8248, 63, 17988, 6516, 21355, 25673, 7, 523, 6523, 2610, 3498, 8, 489, 18744, 1393, 15, 16408, 297, 283, 11146, 297, 2850, 1861, 2458, 83, 7, 450, 445, 18421, 63, 3022, 467, 489, 8288, 29, 30250, 63, 3022, 9, 819, 6523, 2610, 3498, 8, 788, 1875, 297, 283, 16472, 995, 8288, 29, 30250, 63, 3022, 9, 421, 199, 318, 17008, 20762, 3987, 837, 523, 408, 22281, 376, 14694, 3123, 370, 1255, 283, 6238, 7, 1475, 2295, 1041, 523, 340, 747, 14, 2314, 459, 18637, 2846, 1387, 63, 10353, 5342, 540, 418, 508, 283, 17, 356, 272, 870, 283, 25673, 8248, 63, 17988, 445, 22669, 14694, 15243, 25673, 7, 272, 5145, 14, 9242, 8, 25658, 63, 3022, 9, 819, 327, 710, 4683, 402, 14694, 781, 675, 365, 2955, 12, 880, 2337, 1159, 949, 1929, 370, 886, 7003, 523, 327, 340, 314, 2082, 2575, 3495, 14, 523, 340, 747, 14, 515, 14, 6027, 8, 25658, 63, 3022, 304, 272, 372, 819, 870, 283, 25673, 8248, 63, 17988, 11578, 14694, 15243, 25673, 7, 523, 747, 14, 8215, 8, 25658, 63, 3022, 9, 523, 6523, 2610, 3498, 2941, 3187, 297, 283, 888, 297, 2850, 2966, 297, 283, 751, 14, 354, 297, 283, 893, 3018, 1105, 523, 6523, 2610, 3498, 2941, 3187, 297, 283, 888, 297, 2850, 2966, 297, 2116, 283, 751, 14, 2123, 297, 283, 9887, 13, 3018, 32, 3098, 14, 957, 1105, 523, 6523, 2610, 3498, 2941, 3187, 297, 283, 888, 297, 2850, 2966, 297, 283, 2326, 14, 1907, 297, 283, 3910, 1105, 523, 6523, 2610, 3498, 8, 489, 788, 3417, 297, 283, 826, 297, 2126, 2475, 85, 297, 283, 2859, 921, 6238, 14, 3098, 1365, 14, 957, 15, 3246, 15, 6418, 297, 2126, 2475, 66, 297, 283, 6238, 13, 20, 14, 18, 14, 17, 63, 82, 17, 297, 2126, 2475, 71, 297, 283, 452, 3057, 1397, 885, 3057, 1782, 3057, 13245, 3057, 77, 6142, 3057, 88, 1184, 995, 489, 8288, 29, 25658, 63, 3022, 9, 819, 870, 283, 25673, 8248, 63, 17988, 22407, 14694, 25673, 7, 523, 6523, 2610, 3498, 2941, 3417, 297, 283, 5186, 297, 2475, 74, 20, 995, 8288, 29, 25658, 63, 3022, 9, 819, 870, 283, 25673, 8248, 63, 17988, 6516, 14694, 25673, 7, 523, 6523, 2610, 3498, 8, 489, 18744, 1393, 15, 16408, 297, 2126, 2475, 67, 297, 283, 1365, 1900, 15, 1813, 2758, 14, 609, 10883, 634, 4689, 2615, 13, 7420, 10883, 1852, 446, 74, 20, 995, 489, 8288, 29, 25658, 63, 3022, 9, 421, 199, 318, 14133, 774, 3484, 8, 1213, 12, 1475, 29, 403, 12, 13795, 63, 1023, 29, 403, 304, 523, 408, 2540, 314, 4902, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
munyirik/python
cpython/Tools/freeze/freeze.py
5
17071
#! /usr/bin/env python3 """Freeze a Python script into a binary. usage: freeze [options...] script [module]... Options: -p prefix: This is the prefix used when you ran ``make install'' in the Python build directory. (If you never ran this, freeze won't work.) The default is whatever sys.prefix evaluates to. It can also be the top directory of the Python source tree; then -P must point to the build tree. -P exec_prefix: Like -p but this is the 'exec_prefix', used to install objects etc. The default is whatever sys.exec_prefix evaluates to, or the -p argument if given. If -p points to the Python source tree, -P must point to the build tree, if different. -e extension: A directory containing additional .o files that may be used to resolve modules. This directory should also have a Setup file describing the .o files. On Windows, the name of a .INI file describing one or more extensions is passed. More than one -e option may be given. -o dir: Directory where the output files are created; default '.'. -m: Additional arguments are module names instead of filenames. -a package=dir: Additional directories to be added to the package's __path__. Used to simulate directories added by the package at runtime (eg, by OpenGL and win32com). More than one -a option may be given for each package. -l file: Pass the file to the linker (windows only) -d: Debugging mode for the module finder. -q: Make the module finder totally quiet. -h: Print this help message. -x module Exclude the specified module. It will still be imported by the frozen binary if it exists on the host system. -X module Like -x, except the module can never be imported by the frozen binary. -E: Freeze will fail if any modules can't be found (that were not excluded using -x or -X). -i filename: Include a file with additional command line options. Used to prevent command lines growing beyond the capabilities of the shell/OS. All arguments specified in filename are read and the -i option replaced with the parsed params (note - quoting args in this file is NOT supported) -s subsystem: Specify the subsystem (For Windows only.); 'console' (default), 'windows', 'service' or 'com_dll' -w: Toggle Windows (NT or 95) behavior. (For debugging only -- on a win32 platform, win32 behavior is automatic.) -r prefix=f: Replace path prefix. Replace prefix with f in the source path references contained in the resulting binary. Arguments: script: The Python script to be executed by the resulting binary. module ...: Additional Python modules (referenced by pathname) that will be included in the resulting binary. These may be .py or .pyc files. If -m is specified, these are module names that are search in the path instead. NOTES: In order to use freeze successfully, you must have built Python and installed it ("make install"). The script should not use modules provided only as shared libraries; if it does, the resulting binary is not self-contained. """ # Import standard modules import modulefinder import getopt import os import sys # Import the freeze-private modules import checkextensions import makeconfig import makefreeze import makemakefile import parsesetup import bkfile # Main program def main(): # overridable context prefix = None # settable with -p option exec_prefix = None # settable with -P option extensions = [] exclude = [] # settable with -x option addn_link = [] # settable with -l, but only honored under Windows. path = sys.path[:] modargs = 0 debug = 1 odir = '' win = sys.platform[:3] == 'win' replace_paths = [] # settable with -r option error_if_any_missing = 0 # default the exclude list for each platform if win: exclude = exclude + [ 'dos', 'dospath', 'mac', 'macpath', 'macfs', 'MACFS', 'posix', 'ce', ] fail_import = exclude[:] # output files frozen_c = 'frozen.c' config_c = 'config.c' target = 'a.out' # normally derived from script name makefile = 'Makefile' subsystem = 'console' # parse command line by first replacing any "-i" options with the # file contents. pos = 1 while pos < len(sys.argv)-1: # last option can not be "-i", so this ensures "pos+1" is in range! if sys.argv[pos] == '-i': try: options = open(sys.argv[pos+1]).read().split() except IOError as why: usage("File name '%s' specified with the -i option " "can not be read - %s" % (sys.argv[pos+1], why) ) # Replace the '-i' and the filename with the read params. sys.argv[pos:pos+2] = options pos = pos + len(options) - 1 # Skip the name and the included args. pos = pos + 1 # Now parse the command line with the extras inserted. try: opts, args = getopt.getopt(sys.argv[1:], 'r:a:dEe:hmo:p:P:qs:wX:x:l:') except getopt.error as msg: usage('getopt error: ' + str(msg)) # proces option arguments for o, a in opts: if o == '-h': print(__doc__) return if o == '-d': debug = debug + 1 if o == '-e': extensions.append(a) if o == '-m': modargs = 1 if o == '-o': odir = a if o == '-p': prefix = a if o == '-P': exec_prefix = a if o == '-q': debug = 0 if o == '-w': win = not win if o == '-s': if not win: usage("-s subsystem option only on Windows") subsystem = a if o == '-x': exclude.append(a) if o == '-X': exclude.append(a) fail_import.append(a) if o == '-E': error_if_any_missing = 1 if o == '-l': addn_link.append(a) if o == '-a': modulefinder.AddPackagePath(*a.split("=", 2)) if o == '-r': f,r = a.split("=", 2) replace_paths.append( (f,r) ) # modules that are imported by the Python runtime implicits = [] for module in ('site', 'warnings', 'encodings.utf_8', 'encodings.latin_1'): if module not in exclude: implicits.append(module) # default prefix and exec_prefix if not exec_prefix: if prefix: exec_prefix = prefix else: exec_prefix = sys.exec_prefix if not prefix: prefix = sys.prefix # determine whether -p points to the Python source tree ishome = os.path.exists(os.path.join(prefix, 'Python', 'ceval.c')) # locations derived from options version = sys.version[:3] flagged_version = version + sys.abiflags if win: extensions_c = 'frozen_extensions.c' if ishome: print("(Using Python source directory)") binlib = exec_prefix incldir = os.path.join(prefix, 'Include') config_h_dir = exec_prefix config_c_in = os.path.join(prefix, 'Modules', 'config.c.in') frozenmain_c = os.path.join(prefix, 'Python', 'frozenmain.c') makefile_in = os.path.join(exec_prefix, 'Makefile') if win: frozendllmain_c = os.path.join(exec_prefix, 'Pc\\frozen_dllmain.c') else: binlib = os.path.join(exec_prefix, 'lib', 'python%s' % version, 'config-%s' % flagged_version) incldir = os.path.join(prefix, 'include', 'python%s' % flagged_version) config_h_dir = os.path.join(exec_prefix, 'include', 'python%s' % flagged_version) config_c_in = os.path.join(binlib, 'config.c.in') frozenmain_c = os.path.join(binlib, 'frozenmain.c') makefile_in = os.path.join(binlib, 'Makefile') frozendllmain_c = os.path.join(binlib, 'frozen_dllmain.c') supp_sources = [] defines = [] includes = ['-I' + incldir, '-I' + config_h_dir] # sanity check of directories and files check_dirs = [prefix, exec_prefix, binlib, incldir] if not win: # These are not directories on Windows. check_dirs = check_dirs + extensions for dir in check_dirs: if not os.path.exists(dir): usage('needed directory %s not found' % dir) if not os.path.isdir(dir): usage('%s: not a directory' % dir) if win: files = supp_sources + extensions # extensions are files on Windows. else: files = [config_c_in, makefile_in] + supp_sources for file in supp_sources: if not os.path.exists(file): usage('needed file %s not found' % file) if not os.path.isfile(file): usage('%s: not a plain file' % file) if not win: for dir in extensions: setup = os.path.join(dir, 'Setup') if not os.path.exists(setup): usage('needed file %s not found' % setup) if not os.path.isfile(setup): usage('%s: not a plain file' % setup) # check that enough arguments are passed if not args: usage('at least one filename argument required') # check that file arguments exist for arg in args: if arg == '-m': break # if user specified -m on the command line before _any_ # file names, then nothing should be checked (as the # very first file should be a module name) if modargs: break if not os.path.exists(arg): usage('argument %s not found' % arg) if not os.path.isfile(arg): usage('%s: not a plain file' % arg) # process non-option arguments scriptfile = args[0] modules = args[1:] # derive target name from script name base = os.path.basename(scriptfile) base, ext = os.path.splitext(base) if base: if base != scriptfile: target = base else: target = base + '.bin' # handle -o option base_frozen_c = frozen_c base_config_c = config_c base_target = target if odir and not os.path.isdir(odir): try: os.mkdir(odir) print("Created output directory", odir) except OSError as msg: usage('%s: mkdir failed (%s)' % (odir, str(msg))) base = '' if odir: base = os.path.join(odir, '') frozen_c = os.path.join(odir, frozen_c) config_c = os.path.join(odir, config_c) target = os.path.join(odir, target) makefile = os.path.join(odir, makefile) if win: extensions_c = os.path.join(odir, extensions_c) # Handle special entry point requirements # (on Windows, some frozen programs do not use __main__, but # import the module directly. Eg, DLLs, Services, etc custom_entry_point = None # Currently only used on Windows python_entry_is_main = 1 # Is the entry point called __main__? # handle -s option on Windows if win: import winmakemakefile try: custom_entry_point, python_entry_is_main = \ winmakemakefile.get_custom_entry_point(subsystem) except ValueError as why: usage(why) # Actual work starts here... # collect all modules of the program dir = os.path.dirname(scriptfile) path[0] = dir mf = modulefinder.ModuleFinder(path, debug, exclude, replace_paths) if win and subsystem=='service': # If a Windows service, then add the "built-in" module. mod = mf.add_module("servicemanager") mod.__file__="dummy.pyd" # really built-in to the resulting EXE for mod in implicits: mf.import_hook(mod) for mod in modules: if mod == '-m': modargs = 1 continue if modargs: if mod[-2:] == '.*': mf.import_hook(mod[:-2], None, ["*"]) else: mf.import_hook(mod) else: mf.load_file(mod) # Alias "importlib._bootstrap" to "_frozen_importlib" so that the # import machinery can bootstrap. Do the same for # importlib._bootstrap_external. mf.modules["_frozen_importlib"] = mf.modules["importlib._bootstrap"] mf.modules["_frozen_importlib_external"] = mf.modules["importlib._bootstrap_external"] # Add the main script as either __main__, or the actual module name. if python_entry_is_main: mf.run_script(scriptfile) else: mf.load_file(scriptfile) if debug > 0: mf.report() print() dict = mf.modules if error_if_any_missing: missing = mf.any_missing() if missing: sys.exit("There are some missing modules: %r" % missing) # generate output for frozen modules files = makefreeze.makefreeze(base, dict, debug, custom_entry_point, fail_import) # look for unfrozen modules (builtin and of unknown origin) builtins = [] unknown = [] mods = sorted(dict.keys()) for mod in mods: if dict[mod].__code__: continue if not dict[mod].__file__: builtins.append(mod) else: unknown.append(mod) # search for unknown modules in extensions directories (not on Windows) addfiles = [] frozen_extensions = [] # Windows list of modules. if unknown or (not win and builtins): if not win: addfiles, addmods = \ checkextensions.checkextensions(unknown+builtins, extensions) for mod in addmods: if mod in unknown: unknown.remove(mod) builtins.append(mod) else: # Do the windows thang... import checkextensions_win32 # Get a list of CExtension instances, each describing a module # (including its source files) frozen_extensions = checkextensions_win32.checkextensions( unknown, extensions, prefix) for mod in frozen_extensions: unknown.remove(mod.name) # report unknown modules if unknown: sys.stderr.write('Warning: unknown modules remain: %s\n' % ' '.join(unknown)) # windows gets different treatment if win: # Taking a shortcut here... import winmakemakefile, checkextensions_win32 checkextensions_win32.write_extension_table(extensions_c, frozen_extensions) # Create a module definition for the bootstrap C code. xtras = [frozenmain_c, os.path.basename(frozen_c), frozendllmain_c, os.path.basename(extensions_c)] + files maindefn = checkextensions_win32.CExtension( '__main__', xtras ) frozen_extensions.append( maindefn ) with open(makefile, 'w') as outfp: winmakemakefile.makemakefile(outfp, locals(), frozen_extensions, os.path.basename(target)) return # generate config.c and Makefile builtins.sort() with open(config_c_in) as infp, bkfile.open(config_c, 'w') as outfp: makeconfig.makeconfig(infp, outfp, builtins) cflags = ['$(OPT)'] cppflags = defines + includes libs = [os.path.join(binlib, '$(LDLIBRARY)')] somevars = {} if os.path.exists(makefile_in): makevars = parsesetup.getmakevars(makefile_in) for key in makevars: somevars[key] = makevars[key] somevars['CFLAGS'] = ' '.join(cflags) # override somevars['CPPFLAGS'] = ' '.join(cppflags) # override files = [base_config_c, base_frozen_c] + \ files + supp_sources + addfiles + libs + \ ['$(MODLIBS)', '$(LIBS)', '$(SYSLIBS)'] with bkfile.open(makefile, 'w') as outfp: makemakefile.makemakefile(outfp, somevars, files, base_target) # Done! if odir: print('Now run "make" in', odir, end=' ') print('to build the target:', base_target) else: print('Now run "make" to build the target:', base_target) # Print usage message and exit def usage(msg): sys.stdout = sys.stderr print("Error:", msg) print("Use ``%s -h'' for help" % sys.argv[0]) sys.exit(2) main()
bsd-3-clause
[ 3168, 1182, 2647, 15, 1393, 15, 1813, 2366, 19, 199, 199, 624, 10146, 806, 282, 2018, 2884, 1901, 282, 3366, 14, 199, 199, 3807, 26, 22778, 359, 1419, 18737, 2884, 359, 578, 61, 1396, 199, 199, 4558, 26, 199, 13, 80, 2403, 26, 259, 961, 365, 314, 2403, 1202, 1380, 1265, 21471, 1124, 1875, 3907, 891, 1598, 315, 314, 2018, 1900, 2082, 14, 1598, 334, 3917, 1265, 7078, 21471, 642, 12, 22778, 7859, 1133, 1736, 4959, 1598, 710, 849, 365, 15685, 984, 14, 1861, 22014, 370, 14, 1598, 2779, 883, 2597, 506, 314, 2746, 2082, 402, 314, 2018, 1350, 1598, 3123, 27, 2066, 446, 48, 1471, 2376, 370, 314, 1900, 3123, 14, 199, 199, 13, 48, 2146, 63, 1861, 26, 16485, 446, 80, 1325, 642, 365, 314, 283, 1628, 63, 1861, 297, 1202, 370, 355, 3907, 2251, 5423, 14, 221, 710, 849, 365, 15685, 984, 14, 1628, 63, 1861, 355, 22014, 370, 12, 503, 314, 446, 80, 1423, 340, 1627, 14, 355, 982, 446, 80, 4501, 370, 314, 2018, 1350, 3123, 12, 446, 48, 1471, 2376, 355, 370, 314, 1900, 3123, 12, 340, 3365, 14, 199, 199, 13, 69, 3329, 26, 437, 2082, 3035, 4722, 1275, 79, 1584, 626, 1598, 1443, 506, 1202, 370, 7512, 4621, 14, 221, 961, 2082, 1598, 1077, 2597, 1172, 282, 12439, 570, 13660, 314, 1275, 79, 1584, 14, 1598, 4068, 5417, 12, 314, 536, 402, 282, 1275, 568, 41, 570, 13660, 1373, 1598, 503, 1655, 5478, 365, 3032, 14, 1598, 16917, 2419, 1373, 446, 69, 945, 1443, 506, 1627, 14, 199, 199, 13, 79, 2935, 26, 755, 15191, 2382, 314, 1072, 1584, 787, 2737, 27, 849, 15671, 199, 199, 13, 77, 26, 3698, 10961, 2368, 787, 859, 1561, 3140, 402, 6203, 14, 199, 199, 13, 65, 2559, 29, 694, 26, 10961, 6602, 370, 506, 3483, 370, 314, 2559, 1159, 355, 636, 515, 4343, 221, 8051, 370, 20577, 6602, 3483, 701, 314, 355, 2559, 737, 8836, 334, 5902, 12, 701, 24374, 436, 4747, 708, 957, 680, 355, 16917, 2419, 1373, 446, 65, 945, 1443, 506, 1627, 367, 1924, 2559, 14, 199, 199, 13, 76, 570, 26, 420, 8325, 314, 570, 370, 314, 17261, 334, 8258, 1454, 9, 199, 199, 13, 68, 26, 3698, 14245, 1540, 818, 367, 314, 859, 11569, 14, 199, 199, 13, 81, 26, 3698, 4155, 314, 859, 11569, 12657, 1183, 11971, 14, 199, 199, 13, 72, 26, 3698, 9101, 642, 1720, 1245, 14, 199, 199, 13, 88, 859, 258, 28554, 314, 2013, 859, 14, 2779, 911, 5139, 506, 8439, 1598, 701, 314, 8101, 3366, 340, 652, 3495, 641, 314, 1591, 2656, 14, 199, 199, 13, 56, 859, 258, 16485, 446, 88, 12, 871, 314, 859, 883, 7078, 506, 8439, 701, 1598, 314, 8101, 3366, 14, 199, 199, 13, 37, 26, 3698, 2868, 806, 911, 2449, 340, 1263, 4621, 883, 1133, 506, 1911, 334, 9099, 1598, 4898, 440, 8789, 1808, 446, 88, 503, 446, 56, 680, 199, 199, 13, 73, 1788, 26, 221, 15783, 282, 570, 543, 4722, 1414, 1004, 1511, 14, 221, 8051, 1598, 370, 7981, 1414, 2385, 20772, 316, 20561, 314, 14918, 402, 1598, 314, 5218, 15, 3100, 14, 221, 2900, 2368, 2013, 315, 1788, 1598, 787, 1586, 436, 314, 446, 73, 945, 8717, 543, 314, 4565, 1598, 1862, 334, 4610, 446, 18593, 1249, 315, 642, 570, 365, 2845, 3748, 9, 199, 199, 13, 83, 1007, 2253, 26, 13327, 314, 1007, 2253, 334, 1858, 5417, 1454, 14, 2736, 1598, 283, 6614, 7, 334, 885, 395, 283, 8258, 297, 283, 1364, 7, 503, 283, 957, 63, 9259, 7, 199, 199, 13, 87, 26, 3698, 377, 19403, 5417, 334, 12460, 503, 16102, 9, 5953, 14, 1598, 334, 1858, 10201, 1454, 1553, 641, 282, 4747, 708, 4298, 12, 4747, 708, 5953, 1598, 365, 4834, 4959, 199, 199, 13, 82, 2403, 29, 70, 26, 221, 14402, 931, 2403, 14, 1598, 14402, 2403, 543, 289, 315, 314, 1350, 931, 6941, 1598, 10470, 315, 314, 9183, 3366, 14, 199, 199, 14517, 26, 199, 199, 1579, 26, 755, 710, 2018, 2884, 370, 506, 7934, 701, 314, 9183, 3366, 14, 199, 199, 578, 2263, 26, 257, 10961, 2018, 4621, 334, 22355, 701, 11776, 9, 1598, 626, 911, 506, 5120, 315, 314, 9183, 3366, 14, 221, 5723, 1598, 1443, 506, 1275, 647, 503, 1275, 11357, 1584, 14, 221, 982, 446, 77, 365, 2013, 12, 3520, 787, 1598, 859, 1561, 626, 787, 2754, 315, 314, 931, 3140, 14, 199, 199, 4609, 654, 26, 199, 199, 607, 1865, 370, 675, 22778, 8792, 12, 1265, 1471, 1172, 6137, 2018, 436, 199, 7657, 652, 1689, 1875, 3907, 3471, 199, 199, 1918, 2884, 1077, 440, 675, 4621, 2741, 1454, 465, 5709, 8363, 27, 199, 692, 652, 1630, 12, 314, 9183, 3366, 365, 440, 291, 13, 30288, 14, 199, 624, 421, 199, 3, 3161, 4465, 4621, 199, 199, 646, 859, 11681, 199, 646, 12733, 199, 646, 747, 199, 646, 984, 421, 199, 3, 3161, 314, 22778, 13, 4239, 4621, 199, 199, 646, 1104, 5359, 199, 646, 1852, 888, 199, 646, 1852, 18459, 199, 646, 1852, 13941, 199, 646, 2198, 2758, 199, 646, 330, 75, 493, 421, 199, 3, 11298, 2240, 199, 199, 318, 2446, 837, 272, 327, 1806, 1677, 461, 1067, 272, 2403, 275, 488, 9668, 327, 663, 1224, 543, 446, 80, 945, 272, 2146, 63, 1861, 275, 488, 8295, 327, 663, 1224, 543, 446, 48, 945, 272, 5478, 275, 942, 272, 5760, 275, 942, 12788, 327, 663, 1224, 543, 446, 88, 945, 272, 1050, 78, 63, 1073, 275, 942, 420, 327, 663, 1224, 543, 446, 76, 12, 1325, 1454, 394, 265, 2908, 1334, 5417, 14, 272, 931, 275, 984, 14, 515, 5873, 272, 3413, 589, 275, 378, 272, 3105, 275, 413, 272, 312, 694, 275, 2125, 272, 4747, 275, 984, 14, 3246, 1491, 19, 61, 508, 283, 2676, 7, 272, 3350, 63, 3771, 275, 942, 8295, 327, 663, 1224, 543, 446, 82, 945, 272, 1125, 63, 692, 63, 1629, 63, 4752, 275, 378, 339, 327, 849, 314, 5760, 769, 367, 1924, 4298, 272, 340, 4747, 26, 5760, 275, 5760, 435, 359, 267, 283, 18339, 297, 283, 18339, 515, 297, 283, 3088, 297, 283, 3088, 515, 297, 283, 391, 2177, 83, 297, 283, 9410, 7079, 297, 283, 9228, 297, 267, 283 ]
[ 1182, 2647, 15, 1393, 15, 1813, 2366, 19, 199, 199, 624, 10146, 806, 282, 2018, 2884, 1901, 282, 3366, 14, 199, 199, 3807, 26, 22778, 359, 1419, 18737, 2884, 359, 578, 61, 1396, 199, 199, 4558, 26, 199, 13, 80, 2403, 26, 259, 961, 365, 314, 2403, 1202, 1380, 1265, 21471, 1124, 1875, 3907, 891, 1598, 315, 314, 2018, 1900, 2082, 14, 1598, 334, 3917, 1265, 7078, 21471, 642, 12, 22778, 7859, 1133, 1736, 4959, 1598, 710, 849, 365, 15685, 984, 14, 1861, 22014, 370, 14, 1598, 2779, 883, 2597, 506, 314, 2746, 2082, 402, 314, 2018, 1350, 1598, 3123, 27, 2066, 446, 48, 1471, 2376, 370, 314, 1900, 3123, 14, 199, 199, 13, 48, 2146, 63, 1861, 26, 16485, 446, 80, 1325, 642, 365, 314, 283, 1628, 63, 1861, 297, 1202, 370, 355, 3907, 2251, 5423, 14, 221, 710, 849, 365, 15685, 984, 14, 1628, 63, 1861, 355, 22014, 370, 12, 503, 314, 446, 80, 1423, 340, 1627, 14, 355, 982, 446, 80, 4501, 370, 314, 2018, 1350, 3123, 12, 446, 48, 1471, 2376, 355, 370, 314, 1900, 3123, 12, 340, 3365, 14, 199, 199, 13, 69, 3329, 26, 437, 2082, 3035, 4722, 1275, 79, 1584, 626, 1598, 1443, 506, 1202, 370, 7512, 4621, 14, 221, 961, 2082, 1598, 1077, 2597, 1172, 282, 12439, 570, 13660, 314, 1275, 79, 1584, 14, 1598, 4068, 5417, 12, 314, 536, 402, 282, 1275, 568, 41, 570, 13660, 1373, 1598, 503, 1655, 5478, 365, 3032, 14, 1598, 16917, 2419, 1373, 446, 69, 945, 1443, 506, 1627, 14, 199, 199, 13, 79, 2935, 26, 755, 15191, 2382, 314, 1072, 1584, 787, 2737, 27, 849, 15671, 199, 199, 13, 77, 26, 3698, 10961, 2368, 787, 859, 1561, 3140, 402, 6203, 14, 199, 199, 13, 65, 2559, 29, 694, 26, 10961, 6602, 370, 506, 3483, 370, 314, 2559, 1159, 355, 636, 515, 4343, 221, 8051, 370, 20577, 6602, 3483, 701, 314, 355, 2559, 737, 8836, 334, 5902, 12, 701, 24374, 436, 4747, 708, 957, 680, 355, 16917, 2419, 1373, 446, 65, 945, 1443, 506, 1627, 367, 1924, 2559, 14, 199, 199, 13, 76, 570, 26, 420, 8325, 314, 570, 370, 314, 17261, 334, 8258, 1454, 9, 199, 199, 13, 68, 26, 3698, 14245, 1540, 818, 367, 314, 859, 11569, 14, 199, 199, 13, 81, 26, 3698, 4155, 314, 859, 11569, 12657, 1183, 11971, 14, 199, 199, 13, 72, 26, 3698, 9101, 642, 1720, 1245, 14, 199, 199, 13, 88, 859, 258, 28554, 314, 2013, 859, 14, 2779, 911, 5139, 506, 8439, 1598, 701, 314, 8101, 3366, 340, 652, 3495, 641, 314, 1591, 2656, 14, 199, 199, 13, 56, 859, 258, 16485, 446, 88, 12, 871, 314, 859, 883, 7078, 506, 8439, 701, 1598, 314, 8101, 3366, 14, 199, 199, 13, 37, 26, 3698, 2868, 806, 911, 2449, 340, 1263, 4621, 883, 1133, 506, 1911, 334, 9099, 1598, 4898, 440, 8789, 1808, 446, 88, 503, 446, 56, 680, 199, 199, 13, 73, 1788, 26, 221, 15783, 282, 570, 543, 4722, 1414, 1004, 1511, 14, 221, 8051, 1598, 370, 7981, 1414, 2385, 20772, 316, 20561, 314, 14918, 402, 1598, 314, 5218, 15, 3100, 14, 221, 2900, 2368, 2013, 315, 1788, 1598, 787, 1586, 436, 314, 446, 73, 945, 8717, 543, 314, 4565, 1598, 1862, 334, 4610, 446, 18593, 1249, 315, 642, 570, 365, 2845, 3748, 9, 199, 199, 13, 83, 1007, 2253, 26, 13327, 314, 1007, 2253, 334, 1858, 5417, 1454, 14, 2736, 1598, 283, 6614, 7, 334, 885, 395, 283, 8258, 297, 283, 1364, 7, 503, 283, 957, 63, 9259, 7, 199, 199, 13, 87, 26, 3698, 377, 19403, 5417, 334, 12460, 503, 16102, 9, 5953, 14, 1598, 334, 1858, 10201, 1454, 1553, 641, 282, 4747, 708, 4298, 12, 4747, 708, 5953, 1598, 365, 4834, 4959, 199, 199, 13, 82, 2403, 29, 70, 26, 221, 14402, 931, 2403, 14, 1598, 14402, 2403, 543, 289, 315, 314, 1350, 931, 6941, 1598, 10470, 315, 314, 9183, 3366, 14, 199, 199, 14517, 26, 199, 199, 1579, 26, 755, 710, 2018, 2884, 370, 506, 7934, 701, 314, 9183, 3366, 14, 199, 199, 578, 2263, 26, 257, 10961, 2018, 4621, 334, 22355, 701, 11776, 9, 1598, 626, 911, 506, 5120, 315, 314, 9183, 3366, 14, 221, 5723, 1598, 1443, 506, 1275, 647, 503, 1275, 11357, 1584, 14, 221, 982, 446, 77, 365, 2013, 12, 3520, 787, 1598, 859, 1561, 626, 787, 2754, 315, 314, 931, 3140, 14, 199, 199, 4609, 654, 26, 199, 199, 607, 1865, 370, 675, 22778, 8792, 12, 1265, 1471, 1172, 6137, 2018, 436, 199, 7657, 652, 1689, 1875, 3907, 3471, 199, 199, 1918, 2884, 1077, 440, 675, 4621, 2741, 1454, 465, 5709, 8363, 27, 199, 692, 652, 1630, 12, 314, 9183, 3366, 365, 440, 291, 13, 30288, 14, 199, 624, 421, 199, 3, 3161, 4465, 4621, 199, 199, 646, 859, 11681, 199, 646, 12733, 199, 646, 747, 199, 646, 984, 421, 199, 3, 3161, 314, 22778, 13, 4239, 4621, 199, 199, 646, 1104, 5359, 199, 646, 1852, 888, 199, 646, 1852, 18459, 199, 646, 1852, 13941, 199, 646, 2198, 2758, 199, 646, 330, 75, 493, 421, 199, 3, 11298, 2240, 199, 199, 318, 2446, 837, 272, 327, 1806, 1677, 461, 1067, 272, 2403, 275, 488, 9668, 327, 663, 1224, 543, 446, 80, 945, 272, 2146, 63, 1861, 275, 488, 8295, 327, 663, 1224, 543, 446, 48, 945, 272, 5478, 275, 942, 272, 5760, 275, 942, 12788, 327, 663, 1224, 543, 446, 88, 945, 272, 1050, 78, 63, 1073, 275, 942, 420, 327, 663, 1224, 543, 446, 76, 12, 1325, 1454, 394, 265, 2908, 1334, 5417, 14, 272, 931, 275, 984, 14, 515, 5873, 272, 3413, 589, 275, 378, 272, 3105, 275, 413, 272, 312, 694, 275, 2125, 272, 4747, 275, 984, 14, 3246, 1491, 19, 61, 508, 283, 2676, 7, 272, 3350, 63, 3771, 275, 942, 8295, 327, 663, 1224, 543, 446, 82, 945, 272, 1125, 63, 692, 63, 1629, 63, 4752, 275, 378, 339, 327, 849, 314, 5760, 769, 367, 1924, 4298, 272, 340, 4747, 26, 5760, 275, 5760, 435, 359, 267, 283, 18339, 297, 283, 18339, 515, 297, 283, 3088, 297, 283, 3088, 515, 297, 283, 391, 2177, 83, 297, 283, 9410, 7079, 297, 283, 9228, 297, 267, 283, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
jeltz/rust-debian-package
src/llvm/test/Scripts/common_dump.py
10
1441
def dataToHex(d): """ Convert the raw data in 'd' to an hex string with a space every 4 bytes. """ bytes = [] for i,c in enumerate(d): byte = ord(c) hex_byte = hex(byte)[2:] if byte <= 0xf: hex_byte = '0' + hex_byte if i % 4 == 3: hex_byte += ' ' bytes.append(hex_byte) return ''.join(bytes).strip() def dataToHexUnified(d): """ Convert the raw data in 'd' to an hex string with a space every 4 bytes. Each 4byte number is prefixed with 0x for easy sed/rx Fixme: convert all MC tests to use this routine instead of the above """ bytes = [] for i,c in enumerate(d): byte = ord(c) hex_byte = hex(byte)[2:] if byte <= 0xf: hex_byte = '0' + hex_byte if i % 4 == 0: hex_byte = '0x' + hex_byte if i % 4 == 3: hex_byte += ' ' bytes.append(hex_byte) return ''.join(bytes).strip() def HexDump(valPair): """ 1. do not print 'L' 2. Handle negatives and large numbers by mod (2^numBits) 3. print fixed length, prepend with zeros. Length is exactly 2+(numBits/4) 4. Do print 0x Why? so that they can be easily distinguished using sed/rx """ val, numBits = valPair assert 0 <= val < (1 << numBits) val = val & (( 1 << numBits) - 1) newFmt = "0x%0" + "%d" % (numBits / 4) + "x" return newFmt % val
apache-2.0
[ 318, 666, 1378, 10373, 8, 68, 304, 272, 408, 7905, 314, 3066, 666, 315, 283, 68, 7, 370, 376, 6318, 1059, 543, 282, 4601, 4036, 841, 2783, 14, 272, 408, 272, 2783, 275, 942, 272, 367, 284, 12, 67, 315, 3874, 8, 68, 304, 267, 3696, 275, 6206, 8, 67, 9, 267, 6318, 63, 4414, 275, 6318, 8, 4414, 2788, 18, 2938, 267, 340, 3696, 2695, 378, 1949, 26, 288, 6318, 63, 4414, 275, 283, 16, 7, 435, 6318, 63, 4414, 267, 340, 284, 450, 841, 508, 650, 26, 288, 6318, 63, 4414, 847, 283, 283, 267, 2783, 14, 740, 8, 4097, 63, 4414, 9, 272, 372, 6522, 904, 8, 2394, 680, 1913, 342, 199, 199, 318, 666, 1378, 10373, 1358, 4541, 8, 68, 304, 272, 408, 7905, 314, 3066, 666, 315, 283, 68, 7, 370, 376, 6318, 1059, 543, 282, 4601, 4036, 841, 2783, 14, 272, 7048, 841, 4414, 1329, 365, 18239, 543, 378, 88, 367, 8837, 542, 68, 15, 6872, 272, 14811, 278, 26, 3957, 1006, 32685, 2295, 370, 675, 642, 12981, 3140, 402, 314, 3432, 272, 408, 272, 2783, 275, 942, 272, 367, 284, 12, 67, 315, 3874, 8, 68, 304, 267, 3696, 275, 6206, 8, 67, 9, 267, 6318, 63, 4414, 275, 6318, 8, 4414, 2788, 18, 2938, 267, 340, 3696, 2695, 378, 1949, 26, 288, 6318, 63, 4414, 275, 283, 16, 7, 435, 6318, 63, 4414, 267, 340, 284, 450, 841, 508, 378, 26, 288, 6318, 63, 4414, 275, 283, 16, 88, 7, 435, 6318, 63, 4414, 267, 340, 284, 450, 841, 508, 650, 26, 288, 6318, 63, 4414, 847, 283, 283, 267, 2783, 14, 740, 8, 4097, 63, 4414, 9, 272, 372, 6522, 904, 8, 2394, 680, 1913, 342, 421, 199, 318, 28333, 11772, 8, 637, 12882, 304, 272, 408, 272, 413, 14, 886, 440, 870, 283, 44, 7, 272, 499, 14, 8690, 14158, 10661, 436, 7031, 5579, 701, 3413, 334, 18, 62, 1507, 10787, 9, 272, 650, 14, 870, 6317, 2582, 12, 18213, 543, 10136, 14, 2126, 19893, 365, 8840, 499, 15622, 1507, 10787, 15, 20, 9, 272, 841, 14, 4226, 870, 378, 88, 6827, 31, 2126, 880, 626, 2985, 883, 506, 16174, 2917, 14659, 4387, 1808, 542, 68, 15, 6872, 272, 408, 272, 1139, 12, 1967, 10787, 275, 1139, 12882, 272, 702, 378, 2695, 1139, 665, 334, 17, 5213, 1967, 10787, 9, 339, 1139, 275, 1139, 1253, 3666, 413, 5213, 1967, 10787, 9, 446, 413, 9, 272, 892, 38, 2037, 275, 298, 16, 88, 5, 16, 2, 435, 2071, 68, 2, 450, 334, 1507, 10787, 1182, 841, 9, 435, 298, 88, 2, 272, 372, 892, 38, 2037, 450, 1139, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 666, 1378, 10373, 8, 68, 304, 272, 408, 7905, 314, 3066, 666, 315, 283, 68, 7, 370, 376, 6318, 1059, 543, 282, 4601, 4036, 841, 2783, 14, 272, 408, 272, 2783, 275, 942, 272, 367, 284, 12, 67, 315, 3874, 8, 68, 304, 267, 3696, 275, 6206, 8, 67, 9, 267, 6318, 63, 4414, 275, 6318, 8, 4414, 2788, 18, 2938, 267, 340, 3696, 2695, 378, 1949, 26, 288, 6318, 63, 4414, 275, 283, 16, 7, 435, 6318, 63, 4414, 267, 340, 284, 450, 841, 508, 650, 26, 288, 6318, 63, 4414, 847, 283, 283, 267, 2783, 14, 740, 8, 4097, 63, 4414, 9, 272, 372, 6522, 904, 8, 2394, 680, 1913, 342, 199, 199, 318, 666, 1378, 10373, 1358, 4541, 8, 68, 304, 272, 408, 7905, 314, 3066, 666, 315, 283, 68, 7, 370, 376, 6318, 1059, 543, 282, 4601, 4036, 841, 2783, 14, 272, 7048, 841, 4414, 1329, 365, 18239, 543, 378, 88, 367, 8837, 542, 68, 15, 6872, 272, 14811, 278, 26, 3957, 1006, 32685, 2295, 370, 675, 642, 12981, 3140, 402, 314, 3432, 272, 408, 272, 2783, 275, 942, 272, 367, 284, 12, 67, 315, 3874, 8, 68, 304, 267, 3696, 275, 6206, 8, 67, 9, 267, 6318, 63, 4414, 275, 6318, 8, 4414, 2788, 18, 2938, 267, 340, 3696, 2695, 378, 1949, 26, 288, 6318, 63, 4414, 275, 283, 16, 7, 435, 6318, 63, 4414, 267, 340, 284, 450, 841, 508, 378, 26, 288, 6318, 63, 4414, 275, 283, 16, 88, 7, 435, 6318, 63, 4414, 267, 340, 284, 450, 841, 508, 650, 26, 288, 6318, 63, 4414, 847, 283, 283, 267, 2783, 14, 740, 8, 4097, 63, 4414, 9, 272, 372, 6522, 904, 8, 2394, 680, 1913, 342, 421, 199, 318, 28333, 11772, 8, 637, 12882, 304, 272, 408, 272, 413, 14, 886, 440, 870, 283, 44, 7, 272, 499, 14, 8690, 14158, 10661, 436, 7031, 5579, 701, 3413, 334, 18, 62, 1507, 10787, 9, 272, 650, 14, 870, 6317, 2582, 12, 18213, 543, 10136, 14, 2126, 19893, 365, 8840, 499, 15622, 1507, 10787, 15, 20, 9, 272, 841, 14, 4226, 870, 378, 88, 6827, 31, 2126, 880, 626, 2985, 883, 506, 16174, 2917, 14659, 4387, 1808, 542, 68, 15, 6872, 272, 408, 272, 1139, 12, 1967, 10787, 275, 1139, 12882, 272, 702, 378, 2695, 1139, 665, 334, 17, 5213, 1967, 10787, 9, 339, 1139, 275, 1139, 1253, 3666, 413, 5213, 1967, 10787, 9, 446, 413, 9, 272, 892, 38, 2037, 275, 298, 16, 88, 5, 16, 2, 435, 2071, 68, 2, 450, 334, 1507, 10787, 1182, 841, 9, 435, 298, 88, 2, 272, 372, 892, 38, 2037, 450, 1139, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
linjoahow/w17test_1
static/Brython3.1.3-20150514-095342/Lib/test/re_tests.py
879
31796
#!/usr/bin/env python3 # -*- mode: python -*- # Re test suite and benchmark suite v1.5 # The 3 possible outcomes for each pattern [SUCCEED, FAIL, SYNTAX_ERROR] = range(3) # Benchmark suite (needs expansion) # # The benchmark suite does not test correctness, just speed. The # first element of each tuple is the regex pattern; the second is a # string to match it against. The benchmarking code will embed the # second string inside several sizes of padding, to test how regex # matching performs on large strings. benchmarks = [ # test common prefix ('Python|Perl', 'Perl'), # Alternation ('(Python|Perl)', 'Perl'), # Grouped alternation ('Python|Perl|Tcl', 'Perl'), # Alternation ('(Python|Perl|Tcl)', 'Perl'), # Grouped alternation ('(Python)\\1', 'PythonPython'), # Backreference ('([0a-z][a-z0-9]*,)+', 'a5,b7,c9,'), # Disable the fastmap optimization ('([a-z][a-z0-9]*,)+', 'a5,b7,c9,'), # A few sets ('Python', 'Python'), # Simple text literal ('.*Python', 'Python'), # Bad text literal ('.*Python.*', 'Python'), # Worse text literal ('.*(Python)', 'Python'), # Bad text literal with grouping ] # Test suite (for verifying correctness) # # The test suite is a list of 5- or 3-tuples. The 5 parts of a # complete tuple are: # element 0: a string containing the pattern # 1: the string to match against the pattern # 2: the expected result (SUCCEED, FAIL, SYNTAX_ERROR) # 3: a string that will be eval()'ed to produce a test string. # This is an arbitrary Python expression; the available # variables are "found" (the whole match), and "g1", "g2", ... # up to "g99" contain the contents of each group, or the # string 'None' if the group wasn't given a value, or the # string 'Error' if the group index was out of range; # also "groups", the return value of m.group() (a tuple). # 4: The expected result of evaluating the expression. # If the two don't match, an error is reported. # # If the regex isn't expected to work, the latter two elements can be omitted. tests = [ # Test ?P< and ?P= extensions ('(?P<foo_123', '', SYNTAX_ERROR), # Unterminated group identifier ('(?P<1>a)', '', SYNTAX_ERROR), # Begins with a digit ('(?P<!>a)', '', SYNTAX_ERROR), # Begins with an illegal char ('(?P<foo!>a)', '', SYNTAX_ERROR), # Begins with an illegal char # Same tests, for the ?P= form ('(?P<foo_123>a)(?P=foo_123', 'aa', SYNTAX_ERROR), ('(?P<foo_123>a)(?P=1)', 'aa', SYNTAX_ERROR), ('(?P<foo_123>a)(?P=!)', 'aa', SYNTAX_ERROR), ('(?P<foo_123>a)(?P=foo_124', 'aa', SYNTAX_ERROR), # Backref to undefined group ('(?P<foo_123>a)', 'a', SUCCEED, 'g1', 'a'), ('(?P<foo_123>a)(?P=foo_123)', 'aa', SUCCEED, 'g1', 'a'), # Test octal escapes ('\\1', 'a', SYNTAX_ERROR), # Backreference ('[\\1]', '\1', SUCCEED, 'found', '\1'), # Character ('\\09', chr(0) + '9', SUCCEED, 'found', chr(0) + '9'), ('\\141', 'a', SUCCEED, 'found', 'a'), ('(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)\\119', 'abcdefghijklk9', SUCCEED, 'found+"-"+g11', 'abcdefghijklk9-k'), # Test \0 is handled everywhere (r'\0', '\0', SUCCEED, 'found', '\0'), (r'[\0a]', '\0', SUCCEED, 'found', '\0'), (r'[a\0]', '\0', SUCCEED, 'found', '\0'), (r'[^a\0]', '\0', FAIL), # Test various letter escapes (r'\a[\b]\f\n\r\t\v', '\a\b\f\n\r\t\v', SUCCEED, 'found', '\a\b\f\n\r\t\v'), (r'[\a][\b][\f][\n][\r][\t][\v]', '\a\b\f\n\r\t\v', SUCCEED, 'found', '\a\b\f\n\r\t\v'), # NOTE: not an error under PCRE/PRE: # (r'\u', '', SYNTAX_ERROR), # A Perl escape (r'\c\e\g\h\i\j\k\m\o\p\q\y\z', 'ceghijkmopqyz', SUCCEED, 'found', 'ceghijkmopqyz'), (r'\xff', '\377', SUCCEED, 'found', chr(255)), # new \x semantics (r'\x00ffffffffffffff', '\377', FAIL, 'found', chr(255)), (r'\x00f', '\017', FAIL, 'found', chr(15)), (r'\x00fe', '\376', FAIL, 'found', chr(254)), # (r'\x00ffffffffffffff', '\377', SUCCEED, 'found', chr(255)), # (r'\x00f', '\017', SUCCEED, 'found', chr(15)), # (r'\x00fe', '\376', SUCCEED, 'found', chr(254)), (r"^\w+=(\\[\000-\277]|[^\n\\])*", "SRC=eval.c g.c blah blah blah \\\\\n\tapes.c", SUCCEED, 'found', "SRC=eval.c g.c blah blah blah \\\\"), # Test that . only matches \n in DOTALL mode ('a.b', 'acb', SUCCEED, 'found', 'acb'), ('a.b', 'a\nb', FAIL), ('a.*b', 'acc\nccb', FAIL), ('a.{4,5}b', 'acc\nccb', FAIL), ('a.b', 'a\rb', SUCCEED, 'found', 'a\rb'), ('a.b(?s)', 'a\nb', SUCCEED, 'found', 'a\nb'), ('a.*(?s)b', 'acc\nccb', SUCCEED, 'found', 'acc\nccb'), ('(?s)a.{4,5}b', 'acc\nccb', SUCCEED, 'found', 'acc\nccb'), ('(?s)a.b', 'a\nb', SUCCEED, 'found', 'a\nb'), (')', '', SYNTAX_ERROR), # Unmatched right bracket ('', '', SUCCEED, 'found', ''), # Empty pattern ('abc', 'abc', SUCCEED, 'found', 'abc'), ('abc', 'xbc', FAIL), ('abc', 'axc', FAIL), ('abc', 'abx', FAIL), ('abc', 'xabcy', SUCCEED, 'found', 'abc'), ('abc', 'ababc', SUCCEED, 'found', 'abc'), ('ab*c', 'abc', SUCCEED, 'found', 'abc'), ('ab*bc', 'abc', SUCCEED, 'found', 'abc'), ('ab*bc', 'abbc', SUCCEED, 'found', 'abbc'), ('ab*bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'), ('ab+bc', 'abbc', SUCCEED, 'found', 'abbc'), ('ab+bc', 'abc', FAIL), ('ab+bc', 'abq', FAIL), ('ab+bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'), ('ab?bc', 'abbc', SUCCEED, 'found', 'abbc'), ('ab?bc', 'abc', SUCCEED, 'found', 'abc'), ('ab?bc', 'abbbbc', FAIL), ('ab?c', 'abc', SUCCEED, 'found', 'abc'), ('^abc$', 'abc', SUCCEED, 'found', 'abc'), ('^abc$', 'abcc', FAIL), ('^abc', 'abcc', SUCCEED, 'found', 'abc'), ('^abc$', 'aabc', FAIL), ('abc$', 'aabc', SUCCEED, 'found', 'abc'), ('^', 'abc', SUCCEED, 'found+"-"', '-'), ('$', 'abc', SUCCEED, 'found+"-"', '-'), ('a.c', 'abc', SUCCEED, 'found', 'abc'), ('a.c', 'axc', SUCCEED, 'found', 'axc'), ('a.*c', 'axyzc', SUCCEED, 'found', 'axyzc'), ('a.*c', 'axyzd', FAIL), ('a[bc]d', 'abc', FAIL), ('a[bc]d', 'abd', SUCCEED, 'found', 'abd'), ('a[b-d]e', 'abd', FAIL), ('a[b-d]e', 'ace', SUCCEED, 'found', 'ace'), ('a[b-d]', 'aac', SUCCEED, 'found', 'ac'), ('a[-b]', 'a-', SUCCEED, 'found', 'a-'), ('a[\\-b]', 'a-', SUCCEED, 'found', 'a-'), # NOTE: not an error under PCRE/PRE: # ('a[b-]', 'a-', SYNTAX_ERROR), ('a[]b', '-', SYNTAX_ERROR), ('a[', '-', SYNTAX_ERROR), ('a\\', '-', SYNTAX_ERROR), ('abc)', '-', SYNTAX_ERROR), ('(abc', '-', SYNTAX_ERROR), ('a]', 'a]', SUCCEED, 'found', 'a]'), ('a[]]b', 'a]b', SUCCEED, 'found', 'a]b'), ('a[\]]b', 'a]b', SUCCEED, 'found', 'a]b'), ('a[^bc]d', 'aed', SUCCEED, 'found', 'aed'), ('a[^bc]d', 'abd', FAIL), ('a[^-b]c', 'adc', SUCCEED, 'found', 'adc'), ('a[^-b]c', 'a-c', FAIL), ('a[^]b]c', 'a]c', FAIL), ('a[^]b]c', 'adc', SUCCEED, 'found', 'adc'), ('\\ba\\b', 'a-', SUCCEED, '"-"', '-'), ('\\ba\\b', '-a', SUCCEED, '"-"', '-'), ('\\ba\\b', '-a-', SUCCEED, '"-"', '-'), ('\\by\\b', 'xy', FAIL), ('\\by\\b', 'yz', FAIL), ('\\by\\b', 'xyz', FAIL), ('x\\b', 'xyz', FAIL), ('x\\B', 'xyz', SUCCEED, '"-"', '-'), ('\\Bz', 'xyz', SUCCEED, '"-"', '-'), ('z\\B', 'xyz', FAIL), ('\\Bx', 'xyz', FAIL), ('\\Ba\\B', 'a-', FAIL, '"-"', '-'), ('\\Ba\\B', '-a', FAIL, '"-"', '-'), ('\\Ba\\B', '-a-', FAIL, '"-"', '-'), ('\\By\\B', 'xy', FAIL), ('\\By\\B', 'yz', FAIL), ('\\By\\b', 'xy', SUCCEED, '"-"', '-'), ('\\by\\B', 'yz', SUCCEED, '"-"', '-'), ('\\By\\B', 'xyz', SUCCEED, '"-"', '-'), ('ab|cd', 'abc', SUCCEED, 'found', 'ab'), ('ab|cd', 'abcd', SUCCEED, 'found', 'ab'), ('()ef', 'def', SUCCEED, 'found+"-"+g1', 'ef-'), ('$b', 'b', FAIL), ('a\\(b', 'a(b', SUCCEED, 'found+"-"+g1', 'a(b-Error'), ('a\\(*b', 'ab', SUCCEED, 'found', 'ab'), ('a\\(*b', 'a((b', SUCCEED, 'found', 'a((b'), ('a\\\\b', 'a\\b', SUCCEED, 'found', 'a\\b'), ('((a))', 'abc', SUCCEED, 'found+"-"+g1+"-"+g2', 'a-a-a'), ('(a)b(c)', 'abc', SUCCEED, 'found+"-"+g1+"-"+g2', 'abc-a-c'), ('a+b+c', 'aabbabc', SUCCEED, 'found', 'abc'), ('(a+|b)*', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'), ('(a+|b)+', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'), ('(a+|b)?', 'ab', SUCCEED, 'found+"-"+g1', 'a-a'), (')(', '-', SYNTAX_ERROR), ('[^ab]*', 'cde', SUCCEED, 'found', 'cde'), ('abc', '', FAIL), ('a*', '', SUCCEED, 'found', ''), ('a|b|c|d|e', 'e', SUCCEED, 'found', 'e'), ('(a|b|c|d|e)f', 'ef', SUCCEED, 'found+"-"+g1', 'ef-e'), ('abcd*efg', 'abcdefg', SUCCEED, 'found', 'abcdefg'), ('ab*', 'xabyabbbz', SUCCEED, 'found', 'ab'), ('ab*', 'xayabbbz', SUCCEED, 'found', 'a'), ('(ab|cd)e', 'abcde', SUCCEED, 'found+"-"+g1', 'cde-cd'), ('[abhgefdc]ij', 'hij', SUCCEED, 'found', 'hij'), ('^(ab|cd)e', 'abcde', FAIL, 'xg1y', 'xy'), ('(abc|)ef', 'abcdef', SUCCEED, 'found+"-"+g1', 'ef-'), ('(a|b)c*d', 'abcd', SUCCEED, 'found+"-"+g1', 'bcd-b'), ('(ab|ab*)bc', 'abc', SUCCEED, 'found+"-"+g1', 'abc-a'), ('a([bc]*)c*', 'abc', SUCCEED, 'found+"-"+g1', 'abc-bc'), ('a([bc]*)(c*d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-bc-d'), ('a([bc]+)(c*d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-bc-d'), ('a([bc]*)(c+d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-b-cd'), ('a[bcd]*dcdcde', 'adcdcde', SUCCEED, 'found', 'adcdcde'), ('a[bcd]+dcdcde', 'adcdcde', FAIL), ('(ab|a)b*c', 'abc', SUCCEED, 'found+"-"+g1', 'abc-ab'), ('((a)(b)c)(d)', 'abcd', SUCCEED, 'g1+"-"+g2+"-"+g3+"-"+g4', 'abc-a-b-d'), ('[a-zA-Z_][a-zA-Z0-9_]*', 'alpha', SUCCEED, 'found', 'alpha'), ('^a(bc+|b[eh])g|.h$', 'abh', SUCCEED, 'found+"-"+g1', 'bh-None'), ('(bc+d$|ef*g.|h?i(j|k))', 'effgz', SUCCEED, 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'), ('(bc+d$|ef*g.|h?i(j|k))', 'ij', SUCCEED, 'found+"-"+g1+"-"+g2', 'ij-ij-j'), ('(bc+d$|ef*g.|h?i(j|k))', 'effg', FAIL), ('(bc+d$|ef*g.|h?i(j|k))', 'bcdd', FAIL), ('(bc+d$|ef*g.|h?i(j|k))', 'reffgz', SUCCEED, 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'), ('(((((((((a)))))))))', 'a', SUCCEED, 'found', 'a'), ('multiple words of text', 'uh-uh', FAIL), ('multiple words', 'multiple words, yeah', SUCCEED, 'found', 'multiple words'), ('(.*)c(.*)', 'abcde', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcde-ab-de'), ('\\((.*), (.*)\\)', '(a, b)', SUCCEED, 'g2+"-"+g1', 'b-a'), ('[k]', 'ab', FAIL), ('a[-]?c', 'ac', SUCCEED, 'found', 'ac'), ('(abc)\\1', 'abcabc', SUCCEED, 'g1', 'abc'), ('([a-c]*)\\1', 'abcabc', SUCCEED, 'g1', 'abc'), ('^(.+)?B', 'AB', SUCCEED, 'g1', 'A'), ('(a+).\\1$', 'aaaaa', SUCCEED, 'found+"-"+g1', 'aaaaa-aa'), ('^(a+).\\1$', 'aaaa', FAIL), ('(abc)\\1', 'abcabc', SUCCEED, 'found+"-"+g1', 'abcabc-abc'), ('([a-c]+)\\1', 'abcabc', SUCCEED, 'found+"-"+g1', 'abcabc-abc'), ('(a)\\1', 'aa', SUCCEED, 'found+"-"+g1', 'aa-a'), ('(a+)\\1', 'aa', SUCCEED, 'found+"-"+g1', 'aa-a'), ('(a+)+\\1', 'aa', SUCCEED, 'found+"-"+g1', 'aa-a'), ('(a).+\\1', 'aba', SUCCEED, 'found+"-"+g1', 'aba-a'), ('(a)ba*\\1', 'aba', SUCCEED, 'found+"-"+g1', 'aba-a'), ('(aa|a)a\\1$', 'aaa', SUCCEED, 'found+"-"+g1', 'aaa-a'), ('(a|aa)a\\1$', 'aaa', SUCCEED, 'found+"-"+g1', 'aaa-a'), ('(a+)a\\1$', 'aaa', SUCCEED, 'found+"-"+g1', 'aaa-a'), ('([abc]*)\\1', 'abcabc', SUCCEED, 'found+"-"+g1', 'abcabc-abc'), ('(a)(b)c|ab', 'ab', SUCCEED, 'found+"-"+g1+"-"+g2', 'ab-None-None'), ('(a)+x', 'aaax', SUCCEED, 'found+"-"+g1', 'aaax-a'), ('([ac])+x', 'aacx', SUCCEED, 'found+"-"+g1', 'aacx-c'), ('([^/]*/)*sub1/', 'd:msgs/tdir/sub1/trial/away.cpp', SUCCEED, 'found+"-"+g1', 'd:msgs/tdir/sub1/-tdir/'), ('([^.]*)\\.([^:]*):[T ]+(.*)', 'track1.title:TBlah blah blah', SUCCEED, 'found+"-"+g1+"-"+g2+"-"+g3', 'track1.title:TBlah blah blah-track1-title-Blah blah blah'), ('([^N]*N)+', 'abNNxyzN', SUCCEED, 'found+"-"+g1', 'abNNxyzN-xyzN'), ('([^N]*N)+', 'abNNxyz', SUCCEED, 'found+"-"+g1', 'abNN-N'), ('([abc]*)x', 'abcx', SUCCEED, 'found+"-"+g1', 'abcx-abc'), ('([abc]*)x', 'abc', FAIL), ('([xyz]*)x', 'abcx', SUCCEED, 'found+"-"+g1', 'x-'), ('(a)+b|aac', 'aac', SUCCEED, 'found+"-"+g1', 'aac-None'), # Test symbolic groups ('(?P<i d>aaa)a', 'aaaa', SYNTAX_ERROR), ('(?P<id>aaa)a', 'aaaa', SUCCEED, 'found+"-"+id', 'aaaa-aaa'), ('(?P<id>aa)(?P=id)', 'aaaa', SUCCEED, 'found+"-"+id', 'aaaa-aa'), ('(?P<id>aa)(?P=xd)', 'aaaa', SYNTAX_ERROR), # Test octal escapes/memory references ('\\1', 'a', SYNTAX_ERROR), ('\\09', chr(0) + '9', SUCCEED, 'found', chr(0) + '9'), ('\\141', 'a', SUCCEED, 'found', 'a'), ('(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)\\119', 'abcdefghijklk9', SUCCEED, 'found+"-"+g11', 'abcdefghijklk9-k'), # All tests from Perl ('abc', 'abc', SUCCEED, 'found', 'abc'), ('abc', 'xbc', FAIL), ('abc', 'axc', FAIL), ('abc', 'abx', FAIL), ('abc', 'xabcy', SUCCEED, 'found', 'abc'), ('abc', 'ababc', SUCCEED, 'found', 'abc'), ('ab*c', 'abc', SUCCEED, 'found', 'abc'), ('ab*bc', 'abc', SUCCEED, 'found', 'abc'), ('ab*bc', 'abbc', SUCCEED, 'found', 'abbc'), ('ab*bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'), ('ab{0,}bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'), ('ab+bc', 'abbc', SUCCEED, 'found', 'abbc'), ('ab+bc', 'abc', FAIL), ('ab+bc', 'abq', FAIL), ('ab{1,}bc', 'abq', FAIL), ('ab+bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'), ('ab{1,}bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'), ('ab{1,3}bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'), ('ab{3,4}bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'), ('ab{4,5}bc', 'abbbbc', FAIL), ('ab?bc', 'abbc', SUCCEED, 'found', 'abbc'), ('ab?bc', 'abc', SUCCEED, 'found', 'abc'), ('ab{0,1}bc', 'abc', SUCCEED, 'found', 'abc'), ('ab?bc', 'abbbbc', FAIL), ('ab?c', 'abc', SUCCEED, 'found', 'abc'), ('ab{0,1}c', 'abc', SUCCEED, 'found', 'abc'), ('^abc$', 'abc', SUCCEED, 'found', 'abc'), ('^abc$', 'abcc', FAIL), ('^abc', 'abcc', SUCCEED, 'found', 'abc'), ('^abc$', 'aabc', FAIL), ('abc$', 'aabc', SUCCEED, 'found', 'abc'), ('^', 'abc', SUCCEED, 'found', ''), ('$', 'abc', SUCCEED, 'found', ''), ('a.c', 'abc', SUCCEED, 'found', 'abc'), ('a.c', 'axc', SUCCEED, 'found', 'axc'), ('a.*c', 'axyzc', SUCCEED, 'found', 'axyzc'), ('a.*c', 'axyzd', FAIL), ('a[bc]d', 'abc', FAIL), ('a[bc]d', 'abd', SUCCEED, 'found', 'abd'), ('a[b-d]e', 'abd', FAIL), ('a[b-d]e', 'ace', SUCCEED, 'found', 'ace'), ('a[b-d]', 'aac', SUCCEED, 'found', 'ac'), ('a[-b]', 'a-', SUCCEED, 'found', 'a-'), ('a[b-]', 'a-', SUCCEED, 'found', 'a-'), ('a[b-a]', '-', SYNTAX_ERROR), ('a[]b', '-', SYNTAX_ERROR), ('a[', '-', SYNTAX_ERROR), ('a]', 'a]', SUCCEED, 'found', 'a]'), ('a[]]b', 'a]b', SUCCEED, 'found', 'a]b'), ('a[^bc]d', 'aed', SUCCEED, 'found', 'aed'), ('a[^bc]d', 'abd', FAIL), ('a[^-b]c', 'adc', SUCCEED, 'found', 'adc'), ('a[^-b]c', 'a-c', FAIL), ('a[^]b]c', 'a]c', FAIL), ('a[^]b]c', 'adc', SUCCEED, 'found', 'adc'), ('ab|cd', 'abc', SUCCEED, 'found', 'ab'), ('ab|cd', 'abcd', SUCCEED, 'found', 'ab'), ('()ef', 'def', SUCCEED, 'found+"-"+g1', 'ef-'), ('*a', '-', SYNTAX_ERROR), ('(*)b', '-', SYNTAX_ERROR), ('$b', 'b', FAIL), ('a\\', '-', SYNTAX_ERROR), ('a\\(b', 'a(b', SUCCEED, 'found+"-"+g1', 'a(b-Error'), ('a\\(*b', 'ab', SUCCEED, 'found', 'ab'), ('a\\(*b', 'a((b', SUCCEED, 'found', 'a((b'), ('a\\\\b', 'a\\b', SUCCEED, 'found', 'a\\b'), ('abc)', '-', SYNTAX_ERROR), ('(abc', '-', SYNTAX_ERROR), ('((a))', 'abc', SUCCEED, 'found+"-"+g1+"-"+g2', 'a-a-a'), ('(a)b(c)', 'abc', SUCCEED, 'found+"-"+g1+"-"+g2', 'abc-a-c'), ('a+b+c', 'aabbabc', SUCCEED, 'found', 'abc'), ('a{1,}b{1,}c', 'aabbabc', SUCCEED, 'found', 'abc'), ('a**', '-', SYNTAX_ERROR), ('a.+?c', 'abcabc', SUCCEED, 'found', 'abc'), ('(a+|b)*', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'), ('(a+|b){0,}', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'), ('(a+|b)+', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'), ('(a+|b){1,}', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'), ('(a+|b)?', 'ab', SUCCEED, 'found+"-"+g1', 'a-a'), ('(a+|b){0,1}', 'ab', SUCCEED, 'found+"-"+g1', 'a-a'), (')(', '-', SYNTAX_ERROR), ('[^ab]*', 'cde', SUCCEED, 'found', 'cde'), ('abc', '', FAIL), ('a*', '', SUCCEED, 'found', ''), ('([abc])*d', 'abbbcd', SUCCEED, 'found+"-"+g1', 'abbbcd-c'), ('([abc])*bcd', 'abcd', SUCCEED, 'found+"-"+g1', 'abcd-a'), ('a|b|c|d|e', 'e', SUCCEED, 'found', 'e'), ('(a|b|c|d|e)f', 'ef', SUCCEED, 'found+"-"+g1', 'ef-e'), ('abcd*efg', 'abcdefg', SUCCEED, 'found', 'abcdefg'), ('ab*', 'xabyabbbz', SUCCEED, 'found', 'ab'), ('ab*', 'xayabbbz', SUCCEED, 'found', 'a'), ('(ab|cd)e', 'abcde', SUCCEED, 'found+"-"+g1', 'cde-cd'), ('[abhgefdc]ij', 'hij', SUCCEED, 'found', 'hij'), ('^(ab|cd)e', 'abcde', FAIL), ('(abc|)ef', 'abcdef', SUCCEED, 'found+"-"+g1', 'ef-'), ('(a|b)c*d', 'abcd', SUCCEED, 'found+"-"+g1', 'bcd-b'), ('(ab|ab*)bc', 'abc', SUCCEED, 'found+"-"+g1', 'abc-a'), ('a([bc]*)c*', 'abc', SUCCEED, 'found+"-"+g1', 'abc-bc'), ('a([bc]*)(c*d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-bc-d'), ('a([bc]+)(c*d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-bc-d'), ('a([bc]*)(c+d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-b-cd'), ('a[bcd]*dcdcde', 'adcdcde', SUCCEED, 'found', 'adcdcde'), ('a[bcd]+dcdcde', 'adcdcde', FAIL), ('(ab|a)b*c', 'abc', SUCCEED, 'found+"-"+g1', 'abc-ab'), ('((a)(b)c)(d)', 'abcd', SUCCEED, 'g1+"-"+g2+"-"+g3+"-"+g4', 'abc-a-b-d'), ('[a-zA-Z_][a-zA-Z0-9_]*', 'alpha', SUCCEED, 'found', 'alpha'), ('^a(bc+|b[eh])g|.h$', 'abh', SUCCEED, 'found+"-"+g1', 'bh-None'), ('(bc+d$|ef*g.|h?i(j|k))', 'effgz', SUCCEED, 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'), ('(bc+d$|ef*g.|h?i(j|k))', 'ij', SUCCEED, 'found+"-"+g1+"-"+g2', 'ij-ij-j'), ('(bc+d$|ef*g.|h?i(j|k))', 'effg', FAIL), ('(bc+d$|ef*g.|h?i(j|k))', 'bcdd', FAIL), ('(bc+d$|ef*g.|h?i(j|k))', 'reffgz', SUCCEED, 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'), ('((((((((((a))))))))))', 'a', SUCCEED, 'g10', 'a'), ('((((((((((a))))))))))\\10', 'aa', SUCCEED, 'found', 'aa'), # Python does not have the same rules for \\41 so this is a syntax error # ('((((((((((a))))))))))\\41', 'aa', FAIL), # ('((((((((((a))))))))))\\41', 'a!', SUCCEED, 'found', 'a!'), ('((((((((((a))))))))))\\41', '', SYNTAX_ERROR), ('(?i)((((((((((a))))))))))\\41', '', SYNTAX_ERROR), ('(((((((((a)))))))))', 'a', SUCCEED, 'found', 'a'), ('multiple words of text', 'uh-uh', FAIL), ('multiple words', 'multiple words, yeah', SUCCEED, 'found', 'multiple words'), ('(.*)c(.*)', 'abcde', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcde-ab-de'), ('\\((.*), (.*)\\)', '(a, b)', SUCCEED, 'g2+"-"+g1', 'b-a'), ('[k]', 'ab', FAIL), ('a[-]?c', 'ac', SUCCEED, 'found', 'ac'), ('(abc)\\1', 'abcabc', SUCCEED, 'g1', 'abc'), ('([a-c]*)\\1', 'abcabc', SUCCEED, 'g1', 'abc'), ('(?i)abc', 'ABC', SUCCEED, 'found', 'ABC'), ('(?i)abc', 'XBC', FAIL), ('(?i)abc', 'AXC', FAIL), ('(?i)abc', 'ABX', FAIL), ('(?i)abc', 'XABCY', SUCCEED, 'found', 'ABC'), ('(?i)abc', 'ABABC', SUCCEED, 'found', 'ABC'), ('(?i)ab*c', 'ABC', SUCCEED, 'found', 'ABC'), ('(?i)ab*bc', 'ABC', SUCCEED, 'found', 'ABC'), ('(?i)ab*bc', 'ABBC', SUCCEED, 'found', 'ABBC'), ('(?i)ab*?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'), ('(?i)ab{0,}?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'), ('(?i)ab+?bc', 'ABBC', SUCCEED, 'found', 'ABBC'), ('(?i)ab+bc', 'ABC', FAIL), ('(?i)ab+bc', 'ABQ', FAIL), ('(?i)ab{1,}bc', 'ABQ', FAIL), ('(?i)ab+bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'), ('(?i)ab{1,}?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'), ('(?i)ab{1,3}?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'), ('(?i)ab{3,4}?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'), ('(?i)ab{4,5}?bc', 'ABBBBC', FAIL), ('(?i)ab??bc', 'ABBC', SUCCEED, 'found', 'ABBC'), ('(?i)ab??bc', 'ABC', SUCCEED, 'found', 'ABC'), ('(?i)ab{0,1}?bc', 'ABC', SUCCEED, 'found', 'ABC'), ('(?i)ab??bc', 'ABBBBC', FAIL), ('(?i)ab??c', 'ABC', SUCCEED, 'found', 'ABC'), ('(?i)ab{0,1}?c', 'ABC', SUCCEED, 'found', 'ABC'), ('(?i)^abc$', 'ABC', SUCCEED, 'found', 'ABC'), ('(?i)^abc$', 'ABCC', FAIL), ('(?i)^abc', 'ABCC', SUCCEED, 'found', 'ABC'), ('(?i)^abc$', 'AABC', FAIL), ('(?i)abc$', 'AABC', SUCCEED, 'found', 'ABC'), ('(?i)^', 'ABC', SUCCEED, 'found', ''), ('(?i)$', 'ABC', SUCCEED, 'found', ''), ('(?i)a.c', 'ABC', SUCCEED, 'found', 'ABC'), ('(?i)a.c', 'AXC', SUCCEED, 'found', 'AXC'), ('(?i)a.*?c', 'AXYZC', SUCCEED, 'found', 'AXYZC'), ('(?i)a.*c', 'AXYZD', FAIL), ('(?i)a[bc]d', 'ABC', FAIL), ('(?i)a[bc]d', 'ABD', SUCCEED, 'found', 'ABD'), ('(?i)a[b-d]e', 'ABD', FAIL), ('(?i)a[b-d]e', 'ACE', SUCCEED, 'found', 'ACE'), ('(?i)a[b-d]', 'AAC', SUCCEED, 'found', 'AC'), ('(?i)a[-b]', 'A-', SUCCEED, 'found', 'A-'), ('(?i)a[b-]', 'A-', SUCCEED, 'found', 'A-'), ('(?i)a[b-a]', '-', SYNTAX_ERROR), ('(?i)a[]b', '-', SYNTAX_ERROR), ('(?i)a[', '-', SYNTAX_ERROR), ('(?i)a]', 'A]', SUCCEED, 'found', 'A]'), ('(?i)a[]]b', 'A]B', SUCCEED, 'found', 'A]B'), ('(?i)a[^bc]d', 'AED', SUCCEED, 'found', 'AED'), ('(?i)a[^bc]d', 'ABD', FAIL), ('(?i)a[^-b]c', 'ADC', SUCCEED, 'found', 'ADC'), ('(?i)a[^-b]c', 'A-C', FAIL), ('(?i)a[^]b]c', 'A]C', FAIL), ('(?i)a[^]b]c', 'ADC', SUCCEED, 'found', 'ADC'), ('(?i)ab|cd', 'ABC', SUCCEED, 'found', 'AB'), ('(?i)ab|cd', 'ABCD', SUCCEED, 'found', 'AB'), ('(?i)()ef', 'DEF', SUCCEED, 'found+"-"+g1', 'EF-'), ('(?i)*a', '-', SYNTAX_ERROR), ('(?i)(*)b', '-', SYNTAX_ERROR), ('(?i)$b', 'B', FAIL), ('(?i)a\\', '-', SYNTAX_ERROR), ('(?i)a\\(b', 'A(B', SUCCEED, 'found+"-"+g1', 'A(B-Error'), ('(?i)a\\(*b', 'AB', SUCCEED, 'found', 'AB'), ('(?i)a\\(*b', 'A((B', SUCCEED, 'found', 'A((B'), ('(?i)a\\\\b', 'A\\B', SUCCEED, 'found', 'A\\B'), ('(?i)abc)', '-', SYNTAX_ERROR), ('(?i)(abc', '-', SYNTAX_ERROR), ('(?i)((a))', 'ABC', SUCCEED, 'found+"-"+g1+"-"+g2', 'A-A-A'), ('(?i)(a)b(c)', 'ABC', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABC-A-C'), ('(?i)a+b+c', 'AABBABC', SUCCEED, 'found', 'ABC'), ('(?i)a{1,}b{1,}c', 'AABBABC', SUCCEED, 'found', 'ABC'), ('(?i)a**', '-', SYNTAX_ERROR), ('(?i)a.+?c', 'ABCABC', SUCCEED, 'found', 'ABC'), ('(?i)a.*?c', 'ABCABC', SUCCEED, 'found', 'ABC'), ('(?i)a.{0,5}?c', 'ABCABC', SUCCEED, 'found', 'ABC'), ('(?i)(a+|b)*', 'AB', SUCCEED, 'found+"-"+g1', 'AB-B'), ('(?i)(a+|b){0,}', 'AB', SUCCEED, 'found+"-"+g1', 'AB-B'), ('(?i)(a+|b)+', 'AB', SUCCEED, 'found+"-"+g1', 'AB-B'), ('(?i)(a+|b){1,}', 'AB', SUCCEED, 'found+"-"+g1', 'AB-B'), ('(?i)(a+|b)?', 'AB', SUCCEED, 'found+"-"+g1', 'A-A'), ('(?i)(a+|b){0,1}', 'AB', SUCCEED, 'found+"-"+g1', 'A-A'), ('(?i)(a+|b){0,1}?', 'AB', SUCCEED, 'found+"-"+g1', '-None'), ('(?i))(', '-', SYNTAX_ERROR), ('(?i)[^ab]*', 'CDE', SUCCEED, 'found', 'CDE'), ('(?i)abc', '', FAIL), ('(?i)a*', '', SUCCEED, 'found', ''), ('(?i)([abc])*d', 'ABBBCD', SUCCEED, 'found+"-"+g1', 'ABBBCD-C'), ('(?i)([abc])*bcd', 'ABCD', SUCCEED, 'found+"-"+g1', 'ABCD-A'), ('(?i)a|b|c|d|e', 'E', SUCCEED, 'found', 'E'), ('(?i)(a|b|c|d|e)f', 'EF', SUCCEED, 'found+"-"+g1', 'EF-E'), ('(?i)abcd*efg', 'ABCDEFG', SUCCEED, 'found', 'ABCDEFG'), ('(?i)ab*', 'XABYABBBZ', SUCCEED, 'found', 'AB'), ('(?i)ab*', 'XAYABBBZ', SUCCEED, 'found', 'A'), ('(?i)(ab|cd)e', 'ABCDE', SUCCEED, 'found+"-"+g1', 'CDE-CD'), ('(?i)[abhgefdc]ij', 'HIJ', SUCCEED, 'found', 'HIJ'), ('(?i)^(ab|cd)e', 'ABCDE', FAIL), ('(?i)(abc|)ef', 'ABCDEF', SUCCEED, 'found+"-"+g1', 'EF-'), ('(?i)(a|b)c*d', 'ABCD', SUCCEED, 'found+"-"+g1', 'BCD-B'), ('(?i)(ab|ab*)bc', 'ABC', SUCCEED, 'found+"-"+g1', 'ABC-A'), ('(?i)a([bc]*)c*', 'ABC', SUCCEED, 'found+"-"+g1', 'ABC-BC'), ('(?i)a([bc]*)(c*d)', 'ABCD', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABCD-BC-D'), ('(?i)a([bc]+)(c*d)', 'ABCD', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABCD-BC-D'), ('(?i)a([bc]*)(c+d)', 'ABCD', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABCD-B-CD'), ('(?i)a[bcd]*dcdcde', 'ADCDCDE', SUCCEED, 'found', 'ADCDCDE'), ('(?i)a[bcd]+dcdcde', 'ADCDCDE', FAIL), ('(?i)(ab|a)b*c', 'ABC', SUCCEED, 'found+"-"+g1', 'ABC-AB'), ('(?i)((a)(b)c)(d)', 'ABCD', SUCCEED, 'g1+"-"+g2+"-"+g3+"-"+g4', 'ABC-A-B-D'), ('(?i)[a-zA-Z_][a-zA-Z0-9_]*', 'ALPHA', SUCCEED, 'found', 'ALPHA'), ('(?i)^a(bc+|b[eh])g|.h$', 'ABH', SUCCEED, 'found+"-"+g1', 'BH-None'), ('(?i)(bc+d$|ef*g.|h?i(j|k))', 'EFFGZ', SUCCEED, 'found+"-"+g1+"-"+g2', 'EFFGZ-EFFGZ-None'), ('(?i)(bc+d$|ef*g.|h?i(j|k))', 'IJ', SUCCEED, 'found+"-"+g1+"-"+g2', 'IJ-IJ-J'), ('(?i)(bc+d$|ef*g.|h?i(j|k))', 'EFFG', FAIL), ('(?i)(bc+d$|ef*g.|h?i(j|k))', 'BCDD', FAIL), ('(?i)(bc+d$|ef*g.|h?i(j|k))', 'REFFGZ', SUCCEED, 'found+"-"+g1+"-"+g2', 'EFFGZ-EFFGZ-None'), ('(?i)((((((((((a))))))))))', 'A', SUCCEED, 'g10', 'A'), ('(?i)((((((((((a))))))))))\\10', 'AA', SUCCEED, 'found', 'AA'), #('(?i)((((((((((a))))))))))\\41', 'AA', FAIL), #('(?i)((((((((((a))))))))))\\41', 'A!', SUCCEED, 'found', 'A!'), ('(?i)(((((((((a)))))))))', 'A', SUCCEED, 'found', 'A'), ('(?i)(?:(?:(?:(?:(?:(?:(?:(?:(?:(a))))))))))', 'A', SUCCEED, 'g1', 'A'), ('(?i)(?:(?:(?:(?:(?:(?:(?:(?:(?:(a|b|c))))))))))', 'C', SUCCEED, 'g1', 'C'), ('(?i)multiple words of text', 'UH-UH', FAIL), ('(?i)multiple words', 'MULTIPLE WORDS, YEAH', SUCCEED, 'found', 'MULTIPLE WORDS'), ('(?i)(.*)c(.*)', 'ABCDE', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABCDE-AB-DE'), ('(?i)\\((.*), (.*)\\)', '(A, B)', SUCCEED, 'g2+"-"+g1', 'B-A'), ('(?i)[k]', 'AB', FAIL), # ('(?i)abcd', 'ABCD', SUCCEED, 'found+"-"+\\found+"-"+\\\\found', 'ABCD-$&-\\ABCD'), # ('(?i)a(bc)d', 'ABCD', SUCCEED, 'g1+"-"+\\g1+"-"+\\\\g1', 'BC-$1-\\BC'), ('(?i)a[-]?c', 'AC', SUCCEED, 'found', 'AC'), ('(?i)(abc)\\1', 'ABCABC', SUCCEED, 'g1', 'ABC'), ('(?i)([a-c]*)\\1', 'ABCABC', SUCCEED, 'g1', 'ABC'), ('a(?!b).', 'abad', SUCCEED, 'found', 'ad'), ('a(?=d).', 'abad', SUCCEED, 'found', 'ad'), ('a(?=c|d).', 'abad', SUCCEED, 'found', 'ad'), ('a(?:b|c|d)(.)', 'ace', SUCCEED, 'g1', 'e'), ('a(?:b|c|d)*(.)', 'ace', SUCCEED, 'g1', 'e'), ('a(?:b|c|d)+?(.)', 'ace', SUCCEED, 'g1', 'e'), ('a(?:b|(c|e){1,2}?|d)+?(.)', 'ace', SUCCEED, 'g1 + g2', 'ce'), ('^(.+)?B', 'AB', SUCCEED, 'g1', 'A'), # lookbehind: split by : but not if it is escaped by -. ('(?<!-):(.*?)(?<!-):', 'a:bc-:de:f', SUCCEED, 'g1', 'bc-:de' ), # escaping with \ as we know it ('(?<!\\\):(.*?)(?<!\\\):', 'a:bc\\:de:f', SUCCEED, 'g1', 'bc\\:de' ), # terminating with ' and escaping with ? as in edifact ("(?<!\\?)'(.*?)(?<!\\?)'", "a'bc?'de'f", SUCCEED, 'g1', "bc?'de" ), # Comments using the (?#...) syntax ('w(?# comment', 'w', SYNTAX_ERROR), ('w(?# comment 1)xy(?# comment 2)z', 'wxyz', SUCCEED, 'found', 'wxyz'), # Check odd placement of embedded pattern modifiers # not an error under PCRE/PRE: ('w(?i)', 'W', SUCCEED, 'found', 'W'), # ('w(?i)', 'W', SYNTAX_ERROR), # Comments using the x embedded pattern modifier ("""(?x)w# comment 1 x y # comment 2 z""", 'wxyz', SUCCEED, 'found', 'wxyz'), # using the m embedded pattern modifier ('^abc', """jkl abc xyz""", FAIL), ('(?m)^abc', """jkl abc xyz""", SUCCEED, 'found', 'abc'), ('(?m)abc$', """jkl xyzabc 123""", SUCCEED, 'found', 'abc'), # using the s embedded pattern modifier ('a.b', 'a\nb', FAIL), ('(?s)a.b', 'a\nb', SUCCEED, 'found', 'a\nb'), # test \w, etc. both inside and outside character classes ('\\w+', '--ab_cd0123--', SUCCEED, 'found', 'ab_cd0123'), ('[\\w]+', '--ab_cd0123--', SUCCEED, 'found', 'ab_cd0123'), ('\\D+', '1234abc5678', SUCCEED, 'found', 'abc'), ('[\\D]+', '1234abc5678', SUCCEED, 'found', 'abc'), ('[\\da-fA-F]+', '123abc', SUCCEED, 'found', '123abc'), # not an error under PCRE/PRE: # ('[\\d-x]', '-', SYNTAX_ERROR), (r'([\s]*)([\S]*)([\s]*)', ' testing!1972', SUCCEED, 'g3+g2+g1', 'testing!1972 '), (r'(\s*)(\S*)(\s*)', ' testing!1972', SUCCEED, 'g3+g2+g1', 'testing!1972 '), (r'\xff', '\377', SUCCEED, 'found', chr(255)), # new \x semantics (r'\x00ff', '\377', FAIL), # (r'\x00ff', '\377', SUCCEED, 'found', chr(255)), (r'\t\n\v\r\f\a\g', '\t\n\v\r\f\ag', SUCCEED, 'found', '\t\n\v\r\f\ag'), ('\t\n\v\r\f\a\g', '\t\n\v\r\f\ag', SUCCEED, 'found', '\t\n\v\r\f\ag'), (r'\t\n\v\r\f\a', '\t\n\v\r\f\a', SUCCEED, 'found', chr(9)+chr(10)+chr(11)+chr(13)+chr(12)+chr(7)), (r'[\t][\n][\v][\r][\f][\b]', '\t\n\v\r\f\b', SUCCEED, 'found', '\t\n\v\r\f\b'), # # post-1.5.2 additions # xmllib problem (r'(([a-z]+):)?([a-z]+)$', 'smil', SUCCEED, 'g1+"-"+g2+"-"+g3', 'None-None-smil'), # bug 110866: reference to undefined group (r'((.)\1+)', '', SYNTAX_ERROR), # bug 111869: search (PRE/PCRE fails on this one, SRE doesn't) (r'.*d', 'abc\nabd', SUCCEED, 'found', 'abd'), # bug 112468: various expected syntax errors (r'(', '', SYNTAX_ERROR), (r'[\41]', '!', SUCCEED, 'found', '!'), # bug 114033: nothing to repeat (r'(x?)?', 'x', SUCCEED, 'found', 'x'), # bug 115040: rescan if flags are modified inside pattern (r' (?x)foo ', 'foo', SUCCEED, 'found', 'foo'), # bug 115618: negative lookahead (r'(?<!abc)(d.f)', 'abcdefdof', SUCCEED, 'found', 'dof'), # bug 116251: character class bug (r'[\w-]+', 'laser_beam', SUCCEED, 'found', 'laser_beam'), # bug 123769+127259: non-greedy backtracking bug (r'.*?\S *:', 'xx:', SUCCEED, 'found', 'xx:'), (r'a[ ]*?\ (\d+).*', 'a 10', SUCCEED, 'found', 'a 10'), (r'a[ ]*?\ (\d+).*', 'a 10', SUCCEED, 'found', 'a 10'), # bug 127259: \Z shouldn't depend on multiline mode (r'(?ms).*?x\s*\Z(.*)','xx\nx\n', SUCCEED, 'g1', ''), # bug 128899: uppercase literals under the ignorecase flag (r'(?i)M+', 'MMM', SUCCEED, 'found', 'MMM'), (r'(?i)m+', 'MMM', SUCCEED, 'found', 'MMM'), (r'(?i)[M]+', 'MMM', SUCCEED, 'found', 'MMM'), (r'(?i)[m]+', 'MMM', SUCCEED, 'found', 'MMM'), # bug 130748: ^* should be an error (nothing to repeat) (r'^*', '', SYNTAX_ERROR), # bug 133283: minimizing repeat problem (r'"(?:\\"|[^"])*?"', r'"\""', SUCCEED, 'found', r'"\""'), # bug 477728: minimizing repeat problem (r'^.*?$', 'one\ntwo\nthree\n', FAIL), # bug 483789: minimizing repeat problem (r'a[^>]*?b', 'a>b', FAIL), # bug 490573: minimizing repeat problem (r'^a*?$', 'foo', FAIL), # bug 470582: nested groups problem (r'^((a)c)?(ab)$', 'ab', SUCCEED, 'g1+"-"+g2+"-"+g3', 'None-None-ab'), # another minimizing repeat problem (capturing groups in assertions) ('^([ab]*?)(?=(b)?)c', 'abc', SUCCEED, 'g1+"-"+g2', 'ab-None'), ('^([ab]*?)(?!(b))c', 'abc', SUCCEED, 'g1+"-"+g2', 'ab-None'), ('^([ab]*?)(?<!(a))c', 'abc', SUCCEED, 'g1+"-"+g2', 'ab-None'), ] u = '\N{LATIN CAPITAL LETTER A WITH DIAERESIS}' tests.extend([ # bug 410271: \b broken under locales (r'\b.\b', 'a', SUCCEED, 'found', 'a'), (r'(?u)\b.\b', u, SUCCEED, 'found', u), (r'(?u)\w', u, SUCCEED, 'found', u), ])
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 19, 199, 3, 1882, 818, 26, 2366, 1882, 199, 199, 3, 799, 511, 5241, 436, 12338, 5241, 373, 17, 14, 21, 199, 199, 3, 710, 650, 3962, 15955, 83, 367, 1924, 3851, 199, 59, 6195, 8890, 12, 10341, 12, 25486, 63, 3170, 61, 275, 1425, 8, 19, 9, 199, 199, 3, 27067, 5241, 334, 10065, 14819, 9, 199, 3, 199, 3, 710, 12338, 5241, 1630, 440, 511, 29102, 12, 2951, 8112, 14, 221, 710, 199, 3, 1642, 1819, 402, 1924, 2008, 365, 314, 5163, 3851, 27, 314, 3499, 365, 282, 199, 3, 1059, 370, 1336, 652, 6169, 14, 221, 710, 12338, 316, 1233, 911, 6441, 314, 199, 3, 3499, 1059, 6272, 9978, 10627, 402, 6273, 12, 370, 511, 4212, 5163, 199, 3, 4877, 18628, 641, 7031, 3326, 14, 199, 199, 11861, 83, 275, 359, 339, 327, 511, 2863, 2403, 272, 661, 4718, 92, 2623, 76, 297, 283, 2623, 76, 659, 259, 327, 17669, 425, 272, 23845, 4718, 92, 2623, 76, 3196, 283, 2623, 76, 659, 221, 327, 598, 11330, 8679, 425, 339, 661, 4718, 92, 2623, 76, 92, 29175, 297, 283, 2623, 76, 659, 263, 327, 17669, 425, 272, 23845, 4718, 92, 2623, 76, 92, 29175, 3196, 283, 2623, 76, 659, 420, 327, 598, 11330, 8679, 425, 339, 23845, 4718, 22532, 17, 297, 283, 4718, 4718, 659, 259, 327, 10257, 4443, 272, 661, 779, 16, 65, 13, 90, 1527, 65, 13, 90, 16, 13, 25, 3672, 4258, 7386, 283, 65, 21, 12, 66, 23, 12, 67, 25, 12, 659, 327, 17534, 314, 7377, 1130, 13712, 272, 661, 779, 65, 13, 90, 1527, 65, 13, 90, 16, 13, 25, 3672, 4258, 7386, 283, 65, 21, 12, 66, 23, 12, 67, 25, 12, 659, 327, 437, 9284, 5951, 339, 661, 4718, 297, 283, 4718, 659, 5185, 327, 5870, 1318, 8785, 272, 661, 2795, 4718, 297, 283, 4718, 659, 3777, 327, 8857, 1318, 8785, 272, 661, 2795, 4718, 16110, 283, 4718, 659, 3698, 327, 644, 9050, 1318, 8785, 272, 661, 2795, 8, 4718, 3196, 283, 4718, 659, 3698, 327, 8857, 1318, 8785, 543, 17786, 199, 199, 61, 199, 199, 3, 1379, 5241, 334, 509, 31866, 29102, 9, 199, 3, 199, 3, 710, 511, 5241, 365, 282, 769, 402, 959, 13, 503, 650, 13, 11760, 14, 221, 710, 959, 4184, 402, 282, 199, 3, 4890, 2008, 787, 26, 199, 3, 1819, 378, 26, 282, 1059, 3035, 314, 3851, 199, 3, 260, 413, 26, 314, 1059, 370, 1336, 6169, 314, 3851, 199, 3, 260, 499, 26, 314, 1420, 754, 334, 6195, 8890, 12, 10341, 12, 25486, 63, 3170, 9, 199, 3, 260, 650, 26, 282, 1059, 626, 911, 506, 3468, 11716, 379, 370, 7389, 282, 511, 1059, 14, 199, 3, 3322, 961, 365, 376, 9697, 2018, 3965, 27, 314, 2808, 199, 3, 3322, 2860, 787, 298, 4214, 2, 334, 1589, 8852, 1336, 395, 436, 298, 71, 17, 401, 298, 71, 18, 401, 2263, 199, 3, 3322, 1536, 370, 298, 71, 1020, 2, 1395, 314, 4072, 402, 1924, 1572, 12, 503, 314, 199, 3, 3322, 1059, 283, 403, 7, 340, 314, 1572, 17373, 1133, 1627, 282, 574, 12, 503, 314, 199, 3, 3322, 1059, 283, 547, 7, 340, 314, 1572, 1478, 1990, 734, 402, 1425, 27, 199, 3, 3322, 2597, 298, 2634, 401, 314, 372, 574, 402, 333, 14, 923, 342, 334, 65, 2008, 680, 199, 3, 260, 841, 26, 710, 1420, 754, 402, 27083, 314, 3965, 14, 199, 3, 3322, 982, 314, 2877, 2793, 1133, 1336, 12, 376, 1125, 365, 14581, 14, 199, 3, 199, 3, 982, 314, 5163, 5712, 1133, 1420, 370, 1736, 12, 314, 19045, 2877, 4008, 883, 506, 11684, 14, 199, 199, 2219, 275, 359, 272, 327, 1379, 5805, 48, 28, 436, 5805, 48, 29, 5478, 272, 15950, 48, 28, 1421, 63, 4288, 297, 3260, 25486, 63, 3170, 395, 420, 327, 1910, 18375, 1572, 5148, 272, 15950, 48, 28, 17, 30, 65, 3196, 3260, 25486, 63, 3170, 395, 260, 327, 25754, 83, 543, 282, 10964, 272, 15950, 48, 11230, 30, 65, 3196, 3260, 25486, 63, 3170, 395, 260, 327, 25754, 83, 543, 376, 20282, 1495, 272, 15950, 48, 28, 1421, 1, 30, 65, 3196, 3260, 25486, 63, 3170, 395, 420, 327, 25754, 83, 543, 376, 20282, 1495, 339, 327, 14766, 2295, 12, 367, 314, 5805, 48, 29, 1824, 272, 15950, 48, 28, 1421, 63, 4288, 30, 65, 18168, 48, 29, 1421, 63, 4288, 297, 283, 2158, 297, 25486, 63, 3170, 395, 272, 15950, 48, 28, 1421, 63, 4288, 30, 65, 18168, 48, 29, 17, 3196, 283, 2158, 297, 25486, 63, 3170, 395, 272, 15950, 48, 28, 1421, 63, 4288, 30, 65, 18168, 48, 29, 1, 3196, 283, 2158, 297, 25486, 63, 3170, 395, 272, 15950, 48, 28, 1421, 63, 4288, 30, 65, 18168, 48, 29, 1421, 63, 7214, 297, 283, 2158, 297, 25486, 63, 3170, 395, 221, 327, 10257, 1121, 370, 10942, 1572, 339, 15950, 48, 28, 1421, 63, 4288, 30, 65, 3196, 283, 65, 297, 8955, 12, 283, 71, 17, 297, 283, 65, 659, 272, 15950, 48, 28, 1421, 63, 4288, 30, 65, 18168, 48, 29, 1421, 63, 4288, 3196, 283, 2158, 297, 8955, 12, 283, 71, 17, 297, 283, 65, 659, 339, 327, 1379, 30100, 24644, 272, 661, 1103, 17, 297, 283, 65, 297, 25486, 63, 3170, 395, 259, 327, 10257, 4443, 272, 23734, 1103, 17, 4300, 1557, 17, 297, 8955, 12, 283, 4214, 297, 1557, 17, 659, 221, 327, 17660, 272, 661, 1103, 1643, 297, 8678, 8, 16, 9, 435, 283, 25, 297, 8955, 12, 283, 4214, 297, 8678, 8, 16, 9, 435, 283, 25, 659, 272, 661, 1103, 12735, 297, 283, 65, 297, 8955, 12, 283, 4214, 297, 283, 65, 659, 272, 23845, 65, 5130, 66, 5130, 67, 5130, 68, 5130, 69, 5130, 70, 5130, 71, 5130, 72, 5130, 73, 5130, 74, 5130, 75, 5130, 76, 22532, 7119, 297, 283, 18677, 9503, 75, 25, 297, 8955, 12, 283, 4214, 15200, 71, 845, 297, 283, 18677, 9503, 75, 25, 13, 75, 659, 339, 327, 1379, 971, 16, 365, 8860, 4036, 4509, 272, 334, 82, 1154, 16, 297, 1557, 16, 297, 8955, 12, 283, 4214, 297, 1557, 16, 659, 272, 334, 82, 22123, 16, 65, 4300, 1557 ]
[ 2647, 15, 1393, 15, 1813, 2366, 19, 199, 3, 1882, 818, 26, 2366, 1882, 199, 199, 3, 799, 511, 5241, 436, 12338, 5241, 373, 17, 14, 21, 199, 199, 3, 710, 650, 3962, 15955, 83, 367, 1924, 3851, 199, 59, 6195, 8890, 12, 10341, 12, 25486, 63, 3170, 61, 275, 1425, 8, 19, 9, 199, 199, 3, 27067, 5241, 334, 10065, 14819, 9, 199, 3, 199, 3, 710, 12338, 5241, 1630, 440, 511, 29102, 12, 2951, 8112, 14, 221, 710, 199, 3, 1642, 1819, 402, 1924, 2008, 365, 314, 5163, 3851, 27, 314, 3499, 365, 282, 199, 3, 1059, 370, 1336, 652, 6169, 14, 221, 710, 12338, 316, 1233, 911, 6441, 314, 199, 3, 3499, 1059, 6272, 9978, 10627, 402, 6273, 12, 370, 511, 4212, 5163, 199, 3, 4877, 18628, 641, 7031, 3326, 14, 199, 199, 11861, 83, 275, 359, 339, 327, 511, 2863, 2403, 272, 661, 4718, 92, 2623, 76, 297, 283, 2623, 76, 659, 259, 327, 17669, 425, 272, 23845, 4718, 92, 2623, 76, 3196, 283, 2623, 76, 659, 221, 327, 598, 11330, 8679, 425, 339, 661, 4718, 92, 2623, 76, 92, 29175, 297, 283, 2623, 76, 659, 263, 327, 17669, 425, 272, 23845, 4718, 92, 2623, 76, 92, 29175, 3196, 283, 2623, 76, 659, 420, 327, 598, 11330, 8679, 425, 339, 23845, 4718, 22532, 17, 297, 283, 4718, 4718, 659, 259, 327, 10257, 4443, 272, 661, 779, 16, 65, 13, 90, 1527, 65, 13, 90, 16, 13, 25, 3672, 4258, 7386, 283, 65, 21, 12, 66, 23, 12, 67, 25, 12, 659, 327, 17534, 314, 7377, 1130, 13712, 272, 661, 779, 65, 13, 90, 1527, 65, 13, 90, 16, 13, 25, 3672, 4258, 7386, 283, 65, 21, 12, 66, 23, 12, 67, 25, 12, 659, 327, 437, 9284, 5951, 339, 661, 4718, 297, 283, 4718, 659, 5185, 327, 5870, 1318, 8785, 272, 661, 2795, 4718, 297, 283, 4718, 659, 3777, 327, 8857, 1318, 8785, 272, 661, 2795, 4718, 16110, 283, 4718, 659, 3698, 327, 644, 9050, 1318, 8785, 272, 661, 2795, 8, 4718, 3196, 283, 4718, 659, 3698, 327, 8857, 1318, 8785, 543, 17786, 199, 199, 61, 199, 199, 3, 1379, 5241, 334, 509, 31866, 29102, 9, 199, 3, 199, 3, 710, 511, 5241, 365, 282, 769, 402, 959, 13, 503, 650, 13, 11760, 14, 221, 710, 959, 4184, 402, 282, 199, 3, 4890, 2008, 787, 26, 199, 3, 1819, 378, 26, 282, 1059, 3035, 314, 3851, 199, 3, 260, 413, 26, 314, 1059, 370, 1336, 6169, 314, 3851, 199, 3, 260, 499, 26, 314, 1420, 754, 334, 6195, 8890, 12, 10341, 12, 25486, 63, 3170, 9, 199, 3, 260, 650, 26, 282, 1059, 626, 911, 506, 3468, 11716, 379, 370, 7389, 282, 511, 1059, 14, 199, 3, 3322, 961, 365, 376, 9697, 2018, 3965, 27, 314, 2808, 199, 3, 3322, 2860, 787, 298, 4214, 2, 334, 1589, 8852, 1336, 395, 436, 298, 71, 17, 401, 298, 71, 18, 401, 2263, 199, 3, 3322, 1536, 370, 298, 71, 1020, 2, 1395, 314, 4072, 402, 1924, 1572, 12, 503, 314, 199, 3, 3322, 1059, 283, 403, 7, 340, 314, 1572, 17373, 1133, 1627, 282, 574, 12, 503, 314, 199, 3, 3322, 1059, 283, 547, 7, 340, 314, 1572, 1478, 1990, 734, 402, 1425, 27, 199, 3, 3322, 2597, 298, 2634, 401, 314, 372, 574, 402, 333, 14, 923, 342, 334, 65, 2008, 680, 199, 3, 260, 841, 26, 710, 1420, 754, 402, 27083, 314, 3965, 14, 199, 3, 3322, 982, 314, 2877, 2793, 1133, 1336, 12, 376, 1125, 365, 14581, 14, 199, 3, 199, 3, 982, 314, 5163, 5712, 1133, 1420, 370, 1736, 12, 314, 19045, 2877, 4008, 883, 506, 11684, 14, 199, 199, 2219, 275, 359, 272, 327, 1379, 5805, 48, 28, 436, 5805, 48, 29, 5478, 272, 15950, 48, 28, 1421, 63, 4288, 297, 3260, 25486, 63, 3170, 395, 420, 327, 1910, 18375, 1572, 5148, 272, 15950, 48, 28, 17, 30, 65, 3196, 3260, 25486, 63, 3170, 395, 260, 327, 25754, 83, 543, 282, 10964, 272, 15950, 48, 11230, 30, 65, 3196, 3260, 25486, 63, 3170, 395, 260, 327, 25754, 83, 543, 376, 20282, 1495, 272, 15950, 48, 28, 1421, 1, 30, 65, 3196, 3260, 25486, 63, 3170, 395, 420, 327, 25754, 83, 543, 376, 20282, 1495, 339, 327, 14766, 2295, 12, 367, 314, 5805, 48, 29, 1824, 272, 15950, 48, 28, 1421, 63, 4288, 30, 65, 18168, 48, 29, 1421, 63, 4288, 297, 283, 2158, 297, 25486, 63, 3170, 395, 272, 15950, 48, 28, 1421, 63, 4288, 30, 65, 18168, 48, 29, 17, 3196, 283, 2158, 297, 25486, 63, 3170, 395, 272, 15950, 48, 28, 1421, 63, 4288, 30, 65, 18168, 48, 29, 1, 3196, 283, 2158, 297, 25486, 63, 3170, 395, 272, 15950, 48, 28, 1421, 63, 4288, 30, 65, 18168, 48, 29, 1421, 63, 7214, 297, 283, 2158, 297, 25486, 63, 3170, 395, 221, 327, 10257, 1121, 370, 10942, 1572, 339, 15950, 48, 28, 1421, 63, 4288, 30, 65, 3196, 283, 65, 297, 8955, 12, 283, 71, 17, 297, 283, 65, 659, 272, 15950, 48, 28, 1421, 63, 4288, 30, 65, 18168, 48, 29, 1421, 63, 4288, 3196, 283, 2158, 297, 8955, 12, 283, 71, 17, 297, 283, 65, 659, 339, 327, 1379, 30100, 24644, 272, 661, 1103, 17, 297, 283, 65, 297, 25486, 63, 3170, 395, 259, 327, 10257, 4443, 272, 23734, 1103, 17, 4300, 1557, 17, 297, 8955, 12, 283, 4214, 297, 1557, 17, 659, 221, 327, 17660, 272, 661, 1103, 1643, 297, 8678, 8, 16, 9, 435, 283, 25, 297, 8955, 12, 283, 4214, 297, 8678, 8, 16, 9, 435, 283, 25, 659, 272, 661, 1103, 12735, 297, 283, 65, 297, 8955, 12, 283, 4214, 297, 283, 65, 659, 272, 23845, 65, 5130, 66, 5130, 67, 5130, 68, 5130, 69, 5130, 70, 5130, 71, 5130, 72, 5130, 73, 5130, 74, 5130, 75, 5130, 76, 22532, 7119, 297, 283, 18677, 9503, 75, 25, 297, 8955, 12, 283, 4214, 15200, 71, 845, 297, 283, 18677, 9503, 75, 25, 13, 75, 659, 339, 327, 1379, 971, 16, 365, 8860, 4036, 4509, 272, 334, 82, 1154, 16, 297, 1557, 16, 297, 8955, 12, 283, 4214, 297, 1557, 16, 659, 272, 334, 82, 22123, 16, 65, 4300, 1557, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
dawsonjon/Chips-2.0
chips/compiler/tokens.py
1
9314
__author__ = "Jon Dawson" __copyright__ = "Copyright (C) 2012, Jonathan P Dawson" __version__ = "0.1" import os.path import subprocess from chips.compiler.exceptions import C2CHIPError operators = [ "!", "~", "+", "-", "*", "/", "//", "%", "=", "==", "<", ">", "<=", ">=", "!=", "|", "&", "^", "||", "&&", "(", ")", "{", "}", "[", "]", ";", "<<", ">>", ",", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "<<=", ">>=", "^=", "++", "--", "?", ":", ".", "->", ] class Tokens: """Break the input file into a stream of tokens, provide functions to traverse the stream.""" def __init__(self, filename, parameters={}): self.tokens = [] self.definitions = [] self.filename = None self.lineno = None self.scan( os.path.join(os.path.dirname(__file__), "builtins.h"), external_preprocessor=False) self.scan(os.path.abspath(filename)) tokens = [] for token in self.tokens: f, l, t = token if t in parameters: tokens.append((f, l, str(parameters[t]))) else: tokens.append(token) self.tokens = tokens def scan(self, filename, input_file=None, parameters={}, external_preprocessor=True): """Convert the test file into tokens""" self.filename = filename if external_preprocessor: directory = os.path.abspath(__file__) directory = os.path.dirname(directory) directory = os.path.join(directory, "include") cpp_commands = [ "cpp", "-nostdinc", "-isystem", directory, filename] pipe = subprocess.Popen(cpp_commands, stdout=subprocess.PIPE) input_file = pipe.stdout else: if input_file is None: try: input_file = open(self.filename) except IOError: raise C2CHIPError("Cannot open file: " + self.filename) token = [] tokens = [] self.lineno = 1 jump = False for line in input_file: # include files line = line + " " if jump: if line.strip().startswith("#endif"): jump = False if line.strip().startswith("#else"): jump = False self.lineno += 1 continue elif external_preprocessor and line.strip().startswith("#"): l = line.strip() l = l.lstrip("#") l = l.split('"') lineno = int(l[0].strip()) self.lineno = lineno filename = l[1].strip().strip('"') self.filename = filename continue elif line.strip().startswith("#include"): filename = self.filename lineno = self.lineno self.tokens.extend(tokens) if line.strip().endswith(">"): directory = os.path.abspath(__file__) directory = os.path.dirname(directory) directory = os.path.join(directory, "include") else: directory = os.path.abspath(self.filename) directory = os.path.dirname(directory) self.filename = line.strip().replace( "#include", "").strip(' ><"') self.filename = os.path.join(directory, self.filename) self.scan(self.filename) self.lineno = lineno self.filename = filename tokens = [] self.lineno += 1 continue elif line.strip().startswith("#define"): definition = line.strip().split(" ")[1] self.definitions.append(definition) self.lineno += 1 continue elif line.strip().startswith("#undef"): definition = line.strip().split(" ")[1] self.definitions.remove(definition) self.lineno += 1 continue elif line.strip().startswith("#ifdef"): definition = line.strip().split(" ")[1] if definition not in self.definitions: jump = True self.lineno += 1 continue elif line.strip().startswith("#ifndef"): definition = line.strip().split(" ")[1] if definition in self.definitions: jump = True self.lineno += 1 continue elif line.strip().startswith("#else"): jump = True self.lineno += 1 continue elif line.strip().startswith("#endif"): self.lineno += 1 continue newline = True for char in line: if not token: token = char # c style comment elif (token + char).startswith("/*"): if (token + char).endswith("*/"): token = "" else: token += char # c++ style comment elif token.startswith("//"): if newline: token = char else: token += char # identifier elif token[0].isalpha(): if char.isalnum() or char == "_": token += char else: tokens.append((self.filename, self.lineno, token)) token = char # number elif token[0].isdigit(): if char.upper() in "0123456789ABCDEFXUL.": token += char elif token.upper().endswith("E") and char in ["+", "-"]: token += char else: tokens.append((self.filename, self.lineno, token)) token = char # string literal elif token.startswith('"'): if char == '"' and previous_char != "\\": token += char tokens.append((self.filename, self.lineno, token)) token = "" else: # remove dummy space from the end of a line if newline: token = token[:-1] previous_char = char token += char # character literal elif token.startswith("'"): if char == "'": token += char tokens.append((self.filename, self.lineno, token)) token = "" else: token += char # operator elif token in operators: if token + char in operators: token += char else: tokens.append((self.filename, self.lineno, token)) token = char else: token = char newline = False self.lineno += 1 self.tokens.extend(tokens) def error(self, string): """ Generate an error message (including the filename and line number) """ raise C2CHIPError(string + "\n", self.filename, self.lineno) def peek(self): """ Return the next token in the stream, but don't consume it. """ if self.tokens: return self.tokens[0][2] else: return "" def peek_next(self): """ Return the next next token in the stream, but don't consume it. """ if len(self.tokens) > 1: return self.tokens[1][2] else: return "" def get(self): """Return the next token in the stream, and consume it.""" if self.tokens: self.lineno = self.tokens[0][1] self.filename = self.tokens[0][0] try: filename, lineno, token = self.tokens.pop(0) except IndexError: self.error("Unexpected end of file") return token def end(self): """Return True if all the tokens have been consumed.""" return not self.tokens def expect(self, expected): """Consume the next token in the stream, generate an error if it is not as expected.""" try: filename, lineno, actual = self.tokens.pop(0) except IndexError: self.error("Unexpected end of file") if self.tokens: self.lineno = self.tokens[0][1] self.filename = self.tokens[0][0] if actual == expected: return else: self.error("Expected: %s, got: %s" % (expected, actual))
mit
[ 363, 2502, 363, 275, 298, 42, 265, 577, 10084, 834, 2, 199, 363, 7307, 363, 275, 298, 7384, 334, 35, 9, 6029, 12, 1603, 265, 1619, 290, 510, 577, 10084, 834, 2, 199, 363, 1023, 363, 275, 298, 16, 14, 17, 2, 199, 199, 646, 747, 14, 515, 199, 646, 3873, 199, 199, 504, 682, 6142, 14, 5772, 14, 3924, 492, 445, 18, 1244, 1772, 547, 199, 199, 12688, 275, 359, 272, 298, 17716, 26810, 401, 7210, 401, 3905, 401, 8969, 401, 3286, 401, 23057, 401, 2071, 401, 298, 11107, 298, 389, 401, 3886, 401, 298, 7166, 3886, 11107, 298, 8119, 401, 272, 298, 1111, 401, 15733, 401, 11746, 401, 18129, 401, 298, 10644, 401, 11746, 6, 401, 7340, 401, 298, 4186, 5310, 401, 298, 10750, 7369, 401, 298, 11472, 298, 17259, 3886, 28, 401, 272, 298, 1140, 401, 3872, 401, 7210, 11107, 3905, 11107, 8969, 11107, 3286, 11107, 2071, 11107, 11746, 11107, 15733, 11107, 3886, 28, 11107, 298, 1140, 11107, 18129, 11107, 272, 298, 4176, 401, 4320, 401, 298, 15583, 298, 6783, 3680, 401, 3905, 7166, 199, 61, 421, 199, 533, 8767, 83, 26, 339, 408, 13948, 314, 1324, 570, 1901, 282, 2547, 402, 4645, 12, 272, 5647, 3423, 370, 24749, 314, 2547, 1041, 339, 347, 636, 826, 721, 277, 12, 1788, 12, 2633, 16420, 267, 291, 14, 4504, 275, 942, 267, 291, 14, 15388, 275, 942, 267, 291, 14, 1501, 275, 488, 267, 291, 14, 3469, 275, 488, 267, 291, 14, 6282, 8, 288, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 298, 10372, 14, 72, 1288, 288, 5957, 63, 657, 6459, 29, 797, 9, 267, 291, 14, 6282, 8, 736, 14, 515, 14, 4832, 8, 1501, 430, 398, 4645, 275, 942, 267, 367, 1526, 315, 291, 14, 4504, 26, 288, 289, 12, 634, 12, 307, 275, 1526, 288, 340, 307, 315, 2633, 26, 355, 4645, 14, 740, 1332, 70, 12, 634, 12, 620, 8, 3214, 59, 84, 11845, 288, 587, 26, 355, 4645, 14, 740, 8, 1418, 9, 267, 291, 14, 4504, 275, 4645, 339, 347, 8000, 8, 277, 12, 1467, 1788, 12, 1467, 1324, 63, 493, 29, 403, 12, 1467, 2633, 10324, 1467, 5957, 63, 657, 6459, 29, 549, 304, 267, 408, 7306, 314, 511, 570, 1901, 4645, 624, 398, 291, 14, 1501, 275, 1788, 398, 340, 5957, 63, 657, 6459, 26, 953, 2082, 275, 747, 14, 515, 14, 4832, 3460, 493, 3368, 288, 2082, 275, 747, 14, 515, 14, 3475, 8, 3619, 9, 288, 2082, 275, 747, 14, 515, 14, 904, 8, 3619, 12, 298, 2613, 531, 953, 7246, 63, 4405, 275, 359, 355, 298, 5910, 401, 355, 3905, 889, 1516, 6559, 401, 355, 3905, 374, 3045, 401, 355, 2082, 12, 355, 1788, 61, 288, 5200, 275, 3873, 14, 7942, 8, 5910, 63, 4405, 12, 3839, 29, 5781, 14, 6089, 9, 288, 1324, 63, 493, 275, 5200, 14, 2703, 267, 587, 26, 288, 340, 1324, 63, 493, 365, 488, 26, 355, 862, 26, 490, 1324, 63, 493, 275, 1551, 8, 277, 14, 1501, 9, 355, 871, 5925, 26, 490, 746, 445, 18, 1244, 1772, 547, 480, 6612, 1551, 570, 26, 298, 435, 291, 14, 1501, 9, 398, 1526, 275, 942, 267, 4645, 275, 942, 267, 291, 14, 3469, 275, 413, 267, 14882, 275, 756, 267, 367, 1004, 315, 1324, 63, 493, 26, 953, 327, 2387, 1584, 288, 1004, 275, 1004, 435, 298, 298, 288, 340, 14882, 26, 355, 340, 1004, 14, 1913, 1252, 2460, 10064, 13739, 2349, 490, 14882, 275, 756, 355, 340, 1004, 14, 1913, 1252, 2460, 10064, 2836, 2349, 490, 14882, 275, 756, 355, 291, 14, 3469, 847, 413, 355, 1980, 953, 916, 5957, 63, 657, 6459, 436, 1004, 14, 1913, 1252, 2460, 10064, 2349, 355, 634, 275, 1004, 14, 1913, 342, 355, 634, 275, 634, 14, 10124, 10064, 531, 355, 634, 275, 634, 14, 1294, 25441, 355, 5874, 275, 1109, 8, 76, 59, 16, 1055, 1913, 1012, 355, 291, 14, 3469, 275, 5874, 355, 1788, 275, 634, 59, 17, 1055, 1913, 1252, 1913, 25441, 355, 291, 14, 1501, 275, 1788, 355, 1980, 953, 916, 1004, 14, 1913, 1252, 2460, 10064, 2613, 2349, 355, 1788, 275, 291, 14, 1501, 355, 5874, 275, 291, 14, 3469, 355, 291, 14, 4504, 14, 2880, 8, 4504, 9, 355, 340, 1004, 14, 1913, 1252, 4130, 19651, 2349, 490, 2082, 275, 747, 14, 515, 14, 4832, 3460, 493, 3368, 490, 2082, 275, 747, 14, 515, 14, 3475, 8, 3619, 9, 490, 2082, 275, 747, 14, 515, 14, 904, 8, 3619, 12, 298, 2613, 531, 355, 587, 26, 490, 2082, 275, 747, 14, 515, 14, 4832, 8, 277, 14, 1501, 9, 490, 2082, 275, 747, 14, 515, 14, 3475, 8, 3619, 9, 355, 291, 14, 1501, 275, 1004, 14, 1913, 1252, 1814, 8, 490, 5426, 2613, 401, 25354, 1913, 360, 690, 28, 9008, 355, 291, 14, 1501, 275, 747, 14, 515, 14, 904, 8, 3619, 12, 291, 14, 1501, 9, 355, 291, 14, 6282, 8, 277, 14, 1501, 9, 355, 291, 14, 3469, 275, 5874, 355, 291, 14, 1501, 275, 1788, 355, 4645, 275, 942, 355, 291, 14, 3469, 847, 413, 355, 1980, 953, 916, 1004, 14, 1913, 1252, 2460, 10064, 4640, 2349, 355, 5492, 275, 1004, 14, 1913, 1252, 1294, 480, 298, 2788, 17, 61, 355, 291, 14, 15388, 14, 740, 8, 7463, 9, 355, 291, 14, 3469, 847, 413, 355, 1980, 953, 916, 1004, 14, 1913, 1252, 2460, 10064, 25878, 2349, 355, 5492, 275, 1004, 14, 1913, 1252, 1294, 480, 298, 2788, 17, 61, 355, 291, 14, 15388, 14, 2168, 8, 7463, 9, 355, 291, 14, 3469, 847, 413, 355, 1980, 953, 916, 1004, 14, 1913, 1252, 2460, 10064, 27737, 2349, 355, 5492, 275, 1004, 14, 1913, 1252, 1294, 480, 298, 2788, 17, 61, 355, 340, 5492, 440, 315, 291, 14, 15388, 26, 490, 14882, 275, 715, 355, 291, 14, 3469, 847, 413, 355, 1980, 953, 916, 1004, 14, 1913, 1252, 2460, 10064, 27708, 2349, 355, 5492, 275, 1004, 14, 1913, 1252, 1294, 480, 298, 2788, 17, 61, 355, 340, 5492, 315, 291, 14, 15388, 26, 490, 14882, 275, 715, 355, 291, 14, 3469, 847, 413, 355, 1980, 953, 916, 1004, 14, 1913, 1252, 2460 ]
[ 2502, 363, 275, 298, 42, 265, 577, 10084, 834, 2, 199, 363, 7307, 363, 275, 298, 7384, 334, 35, 9, 6029, 12, 1603, 265, 1619, 290, 510, 577, 10084, 834, 2, 199, 363, 1023, 363, 275, 298, 16, 14, 17, 2, 199, 199, 646, 747, 14, 515, 199, 646, 3873, 199, 199, 504, 682, 6142, 14, 5772, 14, 3924, 492, 445, 18, 1244, 1772, 547, 199, 199, 12688, 275, 359, 272, 298, 17716, 26810, 401, 7210, 401, 3905, 401, 8969, 401, 3286, 401, 23057, 401, 2071, 401, 298, 11107, 298, 389, 401, 3886, 401, 298, 7166, 3886, 11107, 298, 8119, 401, 272, 298, 1111, 401, 15733, 401, 11746, 401, 18129, 401, 298, 10644, 401, 11746, 6, 401, 7340, 401, 298, 4186, 5310, 401, 298, 10750, 7369, 401, 298, 11472, 298, 17259, 3886, 28, 401, 272, 298, 1140, 401, 3872, 401, 7210, 11107, 3905, 11107, 8969, 11107, 3286, 11107, 2071, 11107, 11746, 11107, 15733, 11107, 3886, 28, 11107, 298, 1140, 11107, 18129, 11107, 272, 298, 4176, 401, 4320, 401, 298, 15583, 298, 6783, 3680, 401, 3905, 7166, 199, 61, 421, 199, 533, 8767, 83, 26, 339, 408, 13948, 314, 1324, 570, 1901, 282, 2547, 402, 4645, 12, 272, 5647, 3423, 370, 24749, 314, 2547, 1041, 339, 347, 636, 826, 721, 277, 12, 1788, 12, 2633, 16420, 267, 291, 14, 4504, 275, 942, 267, 291, 14, 15388, 275, 942, 267, 291, 14, 1501, 275, 488, 267, 291, 14, 3469, 275, 488, 267, 291, 14, 6282, 8, 288, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 298, 10372, 14, 72, 1288, 288, 5957, 63, 657, 6459, 29, 797, 9, 267, 291, 14, 6282, 8, 736, 14, 515, 14, 4832, 8, 1501, 430, 398, 4645, 275, 942, 267, 367, 1526, 315, 291, 14, 4504, 26, 288, 289, 12, 634, 12, 307, 275, 1526, 288, 340, 307, 315, 2633, 26, 355, 4645, 14, 740, 1332, 70, 12, 634, 12, 620, 8, 3214, 59, 84, 11845, 288, 587, 26, 355, 4645, 14, 740, 8, 1418, 9, 267, 291, 14, 4504, 275, 4645, 339, 347, 8000, 8, 277, 12, 1467, 1788, 12, 1467, 1324, 63, 493, 29, 403, 12, 1467, 2633, 10324, 1467, 5957, 63, 657, 6459, 29, 549, 304, 267, 408, 7306, 314, 511, 570, 1901, 4645, 624, 398, 291, 14, 1501, 275, 1788, 398, 340, 5957, 63, 657, 6459, 26, 953, 2082, 275, 747, 14, 515, 14, 4832, 3460, 493, 3368, 288, 2082, 275, 747, 14, 515, 14, 3475, 8, 3619, 9, 288, 2082, 275, 747, 14, 515, 14, 904, 8, 3619, 12, 298, 2613, 531, 953, 7246, 63, 4405, 275, 359, 355, 298, 5910, 401, 355, 3905, 889, 1516, 6559, 401, 355, 3905, 374, 3045, 401, 355, 2082, 12, 355, 1788, 61, 288, 5200, 275, 3873, 14, 7942, 8, 5910, 63, 4405, 12, 3839, 29, 5781, 14, 6089, 9, 288, 1324, 63, 493, 275, 5200, 14, 2703, 267, 587, 26, 288, 340, 1324, 63, 493, 365, 488, 26, 355, 862, 26, 490, 1324, 63, 493, 275, 1551, 8, 277, 14, 1501, 9, 355, 871, 5925, 26, 490, 746, 445, 18, 1244, 1772, 547, 480, 6612, 1551, 570, 26, 298, 435, 291, 14, 1501, 9, 398, 1526, 275, 942, 267, 4645, 275, 942, 267, 291, 14, 3469, 275, 413, 267, 14882, 275, 756, 267, 367, 1004, 315, 1324, 63, 493, 26, 953, 327, 2387, 1584, 288, 1004, 275, 1004, 435, 298, 298, 288, 340, 14882, 26, 355, 340, 1004, 14, 1913, 1252, 2460, 10064, 13739, 2349, 490, 14882, 275, 756, 355, 340, 1004, 14, 1913, 1252, 2460, 10064, 2836, 2349, 490, 14882, 275, 756, 355, 291, 14, 3469, 847, 413, 355, 1980, 953, 916, 5957, 63, 657, 6459, 436, 1004, 14, 1913, 1252, 2460, 10064, 2349, 355, 634, 275, 1004, 14, 1913, 342, 355, 634, 275, 634, 14, 10124, 10064, 531, 355, 634, 275, 634, 14, 1294, 25441, 355, 5874, 275, 1109, 8, 76, 59, 16, 1055, 1913, 1012, 355, 291, 14, 3469, 275, 5874, 355, 1788, 275, 634, 59, 17, 1055, 1913, 1252, 1913, 25441, 355, 291, 14, 1501, 275, 1788, 355, 1980, 953, 916, 1004, 14, 1913, 1252, 2460, 10064, 2613, 2349, 355, 1788, 275, 291, 14, 1501, 355, 5874, 275, 291, 14, 3469, 355, 291, 14, 4504, 14, 2880, 8, 4504, 9, 355, 340, 1004, 14, 1913, 1252, 4130, 19651, 2349, 490, 2082, 275, 747, 14, 515, 14, 4832, 3460, 493, 3368, 490, 2082, 275, 747, 14, 515, 14, 3475, 8, 3619, 9, 490, 2082, 275, 747, 14, 515, 14, 904, 8, 3619, 12, 298, 2613, 531, 355, 587, 26, 490, 2082, 275, 747, 14, 515, 14, 4832, 8, 277, 14, 1501, 9, 490, 2082, 275, 747, 14, 515, 14, 3475, 8, 3619, 9, 355, 291, 14, 1501, 275, 1004, 14, 1913, 1252, 1814, 8, 490, 5426, 2613, 401, 25354, 1913, 360, 690, 28, 9008, 355, 291, 14, 1501, 275, 747, 14, 515, 14, 904, 8, 3619, 12, 291, 14, 1501, 9, 355, 291, 14, 6282, 8, 277, 14, 1501, 9, 355, 291, 14, 3469, 275, 5874, 355, 291, 14, 1501, 275, 1788, 355, 4645, 275, 942, 355, 291, 14, 3469, 847, 413, 355, 1980, 953, 916, 1004, 14, 1913, 1252, 2460, 10064, 4640, 2349, 355, 5492, 275, 1004, 14, 1913, 1252, 1294, 480, 298, 2788, 17, 61, 355, 291, 14, 15388, 14, 740, 8, 7463, 9, 355, 291, 14, 3469, 847, 413, 355, 1980, 953, 916, 1004, 14, 1913, 1252, 2460, 10064, 25878, 2349, 355, 5492, 275, 1004, 14, 1913, 1252, 1294, 480, 298, 2788, 17, 61, 355, 291, 14, 15388, 14, 2168, 8, 7463, 9, 355, 291, 14, 3469, 847, 413, 355, 1980, 953, 916, 1004, 14, 1913, 1252, 2460, 10064, 27737, 2349, 355, 5492, 275, 1004, 14, 1913, 1252, 1294, 480, 298, 2788, 17, 61, 355, 340, 5492, 440, 315, 291, 14, 15388, 26, 490, 14882, 275, 715, 355, 291, 14, 3469, 847, 413, 355, 1980, 953, 916, 1004, 14, 1913, 1252, 2460, 10064, 27708, 2349, 355, 5492, 275, 1004, 14, 1913, 1252, 1294, 480, 298, 2788, 17, 61, 355, 340, 5492, 315, 291, 14, 15388, 26, 490, 14882, 275, 715, 355, 291, 14, 3469, 847, 413, 355, 1980, 953, 916, 1004, 14, 1913, 1252, 2460, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
hsaputra/tensorflow
tensorflow/compiler/tests/ternary_ops_test.py
101
4286
# Copyright 2017 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== """Test cases for ternary operators.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import numpy as np from tensorflow.compiler.tests.xla_test import XLATestCase from tensorflow.python.framework import dtypes from tensorflow.python.ops import array_ops from tensorflow.python.ops import math_ops from tensorflow.python.platform import googletest class TernaryOpsTest(XLATestCase): def _testTernary(self, op, a, b, c, expected): with self.test_session() as session: with self.test_scope(): pa = array_ops.placeholder(dtypes.as_dtype(a.dtype), a.shape, name="a") pb = array_ops.placeholder(dtypes.as_dtype(b.dtype), b.shape, name="b") pc = array_ops.placeholder(dtypes.as_dtype(c.dtype), c.shape, name="c") output = op(pa, pb, pc) result = session.run(output, {pa: a, pb: b, pc: c}) self.assertAllClose(result, expected, rtol=1e-3) def testLinspace(self): self._testTernary( math_ops.linspace, np.float32(1), np.float32(2), np.int32(1), expected=np.array([1], dtype=np.float32)) self._testTernary( math_ops.linspace, np.float32(1), np.float32(4), np.int32(3), expected=np.array([1, 2.5, 4], dtype=np.float32)) def testRange(self): self._testTernary( math_ops.range, np.int32(1), np.int32(2), np.int32(1), expected=np.array([1], dtype=np.int32)) self._testTernary( math_ops.range, np.int32(1), np.int32(7), np.int32(2), expected=np.array([1, 3, 5], dtype=np.int32)) def testSelect(self): self._testTernary( array_ops.where, np.array(0, dtype=np.bool), np.array(2, dtype=np.float32), np.array(7, dtype=np.float32), expected=np.array(7, dtype=np.float32)) self._testTernary( array_ops.where, np.array(1, dtype=np.bool), np.array([1, 2, 3, 4], dtype=np.float32), np.array([5, 6, 7, 8], dtype=np.float32), expected=np.array([1, 2, 3, 4], dtype=np.float32)) self._testTernary( array_ops.where, np.array(0, dtype=np.bool), np.array([[1, 2], [3, 4], [5, 6]], dtype=np.float32), np.array([[7, 8], [9, 10], [11, 12]], dtype=np.float32), expected=np.array([[7, 8], [9, 10], [11, 12]], dtype=np.float32)) self._testTernary( array_ops.where, np.array([0, 1, 1, 0], dtype=np.bool), np.array([1, 2, 3, 4], dtype=np.float32), np.array([5, 6, 7, 8], dtype=np.float32), expected=np.array([5, 2, 3, 8], dtype=np.float32)) self._testTernary( array_ops.where, np.array([0, 1, 0], dtype=np.bool), np.array([[1, 2], [3, 4], [5, 6]], dtype=np.float32), np.array([[7, 8], [9, 10], [11, 12]], dtype=np.float32), expected=np.array([[7, 8], [3, 4], [11, 12]], dtype=np.float32)) def testSlice(self): for dtype in self.numeric_types: self._testTernary( array_ops.slice, np.array([[], [], []], dtype=dtype), np.array([1, 0], dtype=np.int32), np.array([2, 0], dtype=np.int32), expected=np.array([[], []], dtype=dtype)) self._testTernary( array_ops.slice, np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=dtype), np.array([0, 1], dtype=np.int32), np.array([2, 1], dtype=np.int32), expected=np.array([[2], [5]], dtype=dtype)) if __name__ == "__main__": googletest.main()
apache-2.0
[ 3, 1898, 9708, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 774, 5560, 367, 221, 1203, 695, 10211, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 2680, 465, 980, 199, 199, 504, 3228, 14, 5772, 14, 2219, 14, 88, 416, 63, 396, 492, 1323, 20307, 27309, 199, 504, 3228, 14, 1548, 14, 4857, 492, 6674, 199, 504, 3228, 14, 1548, 14, 1483, 492, 1625, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3473, 63, 1483, 199, 504, 3228, 14, 1548, 14, 3246, 492, 31141, 421, 199, 533, 13861, 78, 695, 16452, 774, 8, 56, 20307, 27309, 304, 819, 347, 485, 396, 8600, 78, 695, 8, 277, 12, 1687, 12, 282, 12, 330, 12, 286, 12, 1420, 304, 272, 543, 291, 14, 396, 63, 1730, 342, 465, 2351, 26, 489, 543, 291, 14, 396, 63, 2645, 837, 267, 691, 275, 1625, 63, 1483, 14, 6199, 8, 5717, 14, 305, 63, 2271, 8, 65, 14, 2271, 395, 282, 14, 1392, 12, 536, 628, 65, 531, 267, 10446, 275, 1625, 63, 1483, 14, 6199, 8, 5717, 14, 305, 63, 2271, 8, 66, 14, 2271, 395, 330, 14, 1392, 12, 536, 628, 66, 531, 267, 13171, 275, 1625, 63, 1483, 14, 6199, 8, 5717, 14, 305, 63, 2271, 8, 67, 14, 2271, 395, 286, 14, 1392, 12, 536, 628, 67, 531, 267, 1072, 275, 1687, 8, 387, 12, 10446, 12, 13171, 9, 489, 754, 275, 2351, 14, 1065, 8, 1199, 12, 469, 387, 26, 282, 12, 10446, 26, 330, 12, 13171, 26, 286, 1552, 489, 291, 14, 7260, 8, 1099, 12, 1420, 12, 10561, 29, 17, 69, 13, 19, 9, 819, 347, 511, 27889, 2638, 8, 277, 304, 272, 291, 423, 396, 8600, 78, 695, 8, 267, 3473, 63, 1483, 14, 11649, 12, 267, 980, 14, 1609, 708, 8, 17, 395, 267, 980, 14, 1609, 708, 8, 18, 395, 267, 980, 14, 442, 708, 8, 17, 395, 267, 1420, 29, 1590, 14, 1144, 779, 17, 467, 2152, 29, 1590, 14, 1609, 708, 430, 272, 291, 423, 396, 8600, 78, 695, 8, 267, 3473, 63, 1483, 14, 11649, 12, 267, 980, 14, 1609, 708, 8, 17, 395, 267, 980, 14, 1609, 708, 8, 20, 395, 267, 980, 14, 442, 708, 8, 19, 395, 267, 1420, 29, 1590, 14, 1144, 779, 17, 12, 499, 14, 21, 12, 841, 467, 2152, 29, 1590, 14, 1609, 708, 430, 819, 347, 511, 4709, 8, 277, 304, 272, 291, 423, 396, 8600, 78, 695, 8, 267, 3473, 63, 1483, 14, 1842, 12, 267, 980, 14, 442, 708, 8, 17, 395, 267, 980, 14, 442, 708, 8, 18, 395, 267, 980, 14, 442, 708, 8, 17, 395, 267, 1420, 29, 1590, 14, 1144, 779, 17, 467, 2152, 29, 1590, 14, 442, 708, 430, 272, 291, 423, 396, 8600, 78, 695, 8, 267, 3473, 63, 1483, 14, 1842, 12, 267, 980, 14, 442, 708, 8, 17, 395, 267, 980, 14, 442, 708, 8, 23, 395, 267, 980, 14, 442, 708, 8, 18, 395, 267, 1420, 29, 1590, 14, 1144, 779, 17, 12, 650, 12, 959, 467, 2152, 29, 1590, 14, 442, 708, 430, 819, 347, 511, 5446, 8, 277, 304, 272, 291, 423, 396, 8600, 78, 695, 8, 267, 1625, 63, 1483, 14, 4509, 12, 267, 980, 14, 1144, 8, 16, 12, 2152, 29, 1590, 14, 2245, 395, 267, 980, 14, 1144, 8, 18, 12, 2152, 29, 1590, 14, 1609, 708, 395, 267, 980, 14, 1144, 8, 23, 12, 2152, 29, 1590, 14, 1609, 708, 395, 267, 1420, 29, 1590, 14, 1144, 8, 23, 12, 2152, 29, 1590, 14, 1609, 708, 430, 339, 291, 423, 396, 8600, 78, 695, 8, 267, 1625, 63, 1483, 14, 4509, 12, 267, 980, 14, 1144, 8, 17, 12, 2152, 29, 1590, 14, 2245, 395, 267, 980, 14, 1144, 779, 17, 12, 499, 12, 650, 12, 841, 467, 2152, 29, 1590, 14, 1609, 708, 395, 267, 980, 14, 1144, 779, 21, 12, 1227, 12, 1520, 12, 1695, 467, 2152, 29, 1590, 14, 1609, 708, 395, 267, 1420, 29, 1590, 14, 1144, 779, 17, 12, 499, 12, 650, 12, 841, 467, 2152, 29, 1590, 14, 1609, 708, 430, 339, 291, 423, 396, 8600, 78, 695, 8, 267, 1625, 63, 1483, 14, 4509, 12, 267, 980, 14, 1144, 8, 16, 12, 2152, 29, 1590, 14, 2245, 395, 267, 980, 14, 1144, 4038, 17, 12, 499, 467, 359, 19, 12, 841, 467, 359, 21, 12, 1227, 2365, 2152, 29, 1590, 14, 1609, 708, 395, 267, 980, 14, 1144, 4038, 23, 12, 1695, 467, 359, 25, 12, 1616, 467, 359, 845, 12, 3144, 2365, 2152, 29, 1590, 14, 1609, 708, 395, 267, 1420, 29, 1590, 14, 1144, 4038, 23, 12, 1695, 467, 359, 25, 12, 1616, 467, 359, 845, 12, 3144, 2365, 2152, 29, 1590, 14, 1609, 708, 430, 339, 291, 423, 396, 8600, 78, 695, 8, 267, 1625, 63, 1483, 14, 4509, 12, 267, 980, 14, 1144, 779, 16, 12, 413, 12, 413, 12, 378, 467, 2152, 29, 1590, 14, 2245, 395, 267, 980, 14, 1144, 779, 17, 12, 499, 12, 650, 12, 841, 467, 2152, 29, 1590, 14, 1609, 708, 395, 267, 980, 14, 1144, 779, 21, 12, 1227, 12, 1520, 12, 1695, 467, 2152, 29, 1590, 14, 1609, 708, 395, 267, 1420 ]
[ 1898, 9708, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 774, 5560, 367, 221, 1203, 695, 10211, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 2680, 465, 980, 199, 199, 504, 3228, 14, 5772, 14, 2219, 14, 88, 416, 63, 396, 492, 1323, 20307, 27309, 199, 504, 3228, 14, 1548, 14, 4857, 492, 6674, 199, 504, 3228, 14, 1548, 14, 1483, 492, 1625, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3473, 63, 1483, 199, 504, 3228, 14, 1548, 14, 3246, 492, 31141, 421, 199, 533, 13861, 78, 695, 16452, 774, 8, 56, 20307, 27309, 304, 819, 347, 485, 396, 8600, 78, 695, 8, 277, 12, 1687, 12, 282, 12, 330, 12, 286, 12, 1420, 304, 272, 543, 291, 14, 396, 63, 1730, 342, 465, 2351, 26, 489, 543, 291, 14, 396, 63, 2645, 837, 267, 691, 275, 1625, 63, 1483, 14, 6199, 8, 5717, 14, 305, 63, 2271, 8, 65, 14, 2271, 395, 282, 14, 1392, 12, 536, 628, 65, 531, 267, 10446, 275, 1625, 63, 1483, 14, 6199, 8, 5717, 14, 305, 63, 2271, 8, 66, 14, 2271, 395, 330, 14, 1392, 12, 536, 628, 66, 531, 267, 13171, 275, 1625, 63, 1483, 14, 6199, 8, 5717, 14, 305, 63, 2271, 8, 67, 14, 2271, 395, 286, 14, 1392, 12, 536, 628, 67, 531, 267, 1072, 275, 1687, 8, 387, 12, 10446, 12, 13171, 9, 489, 754, 275, 2351, 14, 1065, 8, 1199, 12, 469, 387, 26, 282, 12, 10446, 26, 330, 12, 13171, 26, 286, 1552, 489, 291, 14, 7260, 8, 1099, 12, 1420, 12, 10561, 29, 17, 69, 13, 19, 9, 819, 347, 511, 27889, 2638, 8, 277, 304, 272, 291, 423, 396, 8600, 78, 695, 8, 267, 3473, 63, 1483, 14, 11649, 12, 267, 980, 14, 1609, 708, 8, 17, 395, 267, 980, 14, 1609, 708, 8, 18, 395, 267, 980, 14, 442, 708, 8, 17, 395, 267, 1420, 29, 1590, 14, 1144, 779, 17, 467, 2152, 29, 1590, 14, 1609, 708, 430, 272, 291, 423, 396, 8600, 78, 695, 8, 267, 3473, 63, 1483, 14, 11649, 12, 267, 980, 14, 1609, 708, 8, 17, 395, 267, 980, 14, 1609, 708, 8, 20, 395, 267, 980, 14, 442, 708, 8, 19, 395, 267, 1420, 29, 1590, 14, 1144, 779, 17, 12, 499, 14, 21, 12, 841, 467, 2152, 29, 1590, 14, 1609, 708, 430, 819, 347, 511, 4709, 8, 277, 304, 272, 291, 423, 396, 8600, 78, 695, 8, 267, 3473, 63, 1483, 14, 1842, 12, 267, 980, 14, 442, 708, 8, 17, 395, 267, 980, 14, 442, 708, 8, 18, 395, 267, 980, 14, 442, 708, 8, 17, 395, 267, 1420, 29, 1590, 14, 1144, 779, 17, 467, 2152, 29, 1590, 14, 442, 708, 430, 272, 291, 423, 396, 8600, 78, 695, 8, 267, 3473, 63, 1483, 14, 1842, 12, 267, 980, 14, 442, 708, 8, 17, 395, 267, 980, 14, 442, 708, 8, 23, 395, 267, 980, 14, 442, 708, 8, 18, 395, 267, 1420, 29, 1590, 14, 1144, 779, 17, 12, 650, 12, 959, 467, 2152, 29, 1590, 14, 442, 708, 430, 819, 347, 511, 5446, 8, 277, 304, 272, 291, 423, 396, 8600, 78, 695, 8, 267, 1625, 63, 1483, 14, 4509, 12, 267, 980, 14, 1144, 8, 16, 12, 2152, 29, 1590, 14, 2245, 395, 267, 980, 14, 1144, 8, 18, 12, 2152, 29, 1590, 14, 1609, 708, 395, 267, 980, 14, 1144, 8, 23, 12, 2152, 29, 1590, 14, 1609, 708, 395, 267, 1420, 29, 1590, 14, 1144, 8, 23, 12, 2152, 29, 1590, 14, 1609, 708, 430, 339, 291, 423, 396, 8600, 78, 695, 8, 267, 1625, 63, 1483, 14, 4509, 12, 267, 980, 14, 1144, 8, 17, 12, 2152, 29, 1590, 14, 2245, 395, 267, 980, 14, 1144, 779, 17, 12, 499, 12, 650, 12, 841, 467, 2152, 29, 1590, 14, 1609, 708, 395, 267, 980, 14, 1144, 779, 21, 12, 1227, 12, 1520, 12, 1695, 467, 2152, 29, 1590, 14, 1609, 708, 395, 267, 1420, 29, 1590, 14, 1144, 779, 17, 12, 499, 12, 650, 12, 841, 467, 2152, 29, 1590, 14, 1609, 708, 430, 339, 291, 423, 396, 8600, 78, 695, 8, 267, 1625, 63, 1483, 14, 4509, 12, 267, 980, 14, 1144, 8, 16, 12, 2152, 29, 1590, 14, 2245, 395, 267, 980, 14, 1144, 4038, 17, 12, 499, 467, 359, 19, 12, 841, 467, 359, 21, 12, 1227, 2365, 2152, 29, 1590, 14, 1609, 708, 395, 267, 980, 14, 1144, 4038, 23, 12, 1695, 467, 359, 25, 12, 1616, 467, 359, 845, 12, 3144, 2365, 2152, 29, 1590, 14, 1609, 708, 395, 267, 1420, 29, 1590, 14, 1144, 4038, 23, 12, 1695, 467, 359, 25, 12, 1616, 467, 359, 845, 12, 3144, 2365, 2152, 29, 1590, 14, 1609, 708, 430, 339, 291, 423, 396, 8600, 78, 695, 8, 267, 1625, 63, 1483, 14, 4509, 12, 267, 980, 14, 1144, 779, 16, 12, 413, 12, 413, 12, 378, 467, 2152, 29, 1590, 14, 2245, 395, 267, 980, 14, 1144, 779, 17, 12, 499, 12, 650, 12, 841, 467, 2152, 29, 1590, 14, 1609, 708, 395, 267, 980, 14, 1144, 779, 21, 12, 1227, 12, 1520, 12, 1695, 467, 2152, 29, 1590, 14, 1609, 708, 395, 267, 1420, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
caisq/tensorflow
tensorflow/python/training/proximal_adagrad_test.py
36
9246
# Copyright 2015 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== """Functional tests for Proximal Adagrad operations.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import numpy as np from tensorflow.python.framework import constant_op from tensorflow.python.framework import dtypes from tensorflow.python.framework import ops from tensorflow.python.ops import embedding_ops from tensorflow.python.ops import math_ops from tensorflow.python.ops import resource_variable_ops from tensorflow.python.ops import variables from tensorflow.python.platform import test from tensorflow.python.training import adagrad from tensorflow.python.training import proximal_adagrad class ProximalAdagradOptimizerTest(test.TestCase): def doTestProximalAdagradwithoutRegularization(self, use_resource=False): with self.test_session() as sess: var0 = variables.Variable([0.0, 0.0]) var1 = variables.Variable([0.0, 0.0]) grads0 = constant_op.constant([0.1, 0.2]) grads1 = constant_op.constant([0.01, 0.02]) opt = proximal_adagrad.ProximalAdagradOptimizer( 3.0, initial_accumulator_value=0.1, l1_regularization_strength=0.0, l2_regularization_strength=0.0) update = opt.apply_gradients(zip([grads0, grads1], [var0, var1])) variables.global_variables_initializer().run() v0_val, v1_val = sess.run([var0, var1]) self.assertAllClose([0.0, 0.0], v0_val) self.assertAllClose([0.0, 0.0], v1_val) # Run 3 steps Proximal Adagrad. for _ in range(3): update.run() v0_val, v1_val = sess.run([var0, var1]) self.assertAllClose(np.array([-2.60260963, -4.29698515]), v0_val) self.assertAllClose(np.array([-0.28432083, -0.56694895]), v1_val) opt_vars = opt.variables() self.assertStartsWith(opt_vars[0].name, var0._shared_name) self.assertStartsWith(opt_vars[1].name, var1._shared_name) self.assertEqual(2, len(opt_vars)) def testProximalAdagradwithoutRegularization(self): self.doTestProximalAdagradwithoutRegularization(use_resource=False) def testResourceProximalAdagradwithoutRegularization(self): self.doTestProximalAdagradwithoutRegularization(use_resource=True) def testProximalAdagradwithoutRegularization2(self): with self.test_session() as sess: var0 = variables.Variable([1.0, 2.0]) var1 = variables.Variable([4.0, 3.0]) grads0 = constant_op.constant([0.1, 0.2]) grads1 = constant_op.constant([0.01, 0.02]) opt = proximal_adagrad.ProximalAdagradOptimizer( 3.0, initial_accumulator_value=0.1, l1_regularization_strength=0.0, l2_regularization_strength=0.0) update = opt.apply_gradients(zip([grads0, grads1], [var0, var1])) variables.global_variables_initializer().run() v0_val, v1_val = sess.run([var0, var1]) self.assertAllClose([1.0, 2.0], v0_val) self.assertAllClose([4.0, 3.0], v1_val) # Run 3 steps Proximal Adagrad. for _ in range(3): update.run() v0_val, v1_val = sess.run([var0, var1]) self.assertAllClose(np.array([-1.60261, -2.296985]), v0_val) self.assertAllClose(np.array([3.715679, 2.433051]), v1_val) def testMinimizeSparseResourceVariable(self): for dtype in [dtypes.float32, dtypes.float64]: with self.test_session(): var0 = resource_variable_ops.ResourceVariable([[1.0, 2.0]], dtype=dtype) x = constant_op.constant([[4.0], [5.0]], dtype=dtype) pred = math_ops.matmul(embedding_ops.embedding_lookup([var0], [0]), x) loss = pred * pred sgd_op = proximal_adagrad.ProximalAdagradOptimizer(1.0).minimize(loss) variables.global_variables_initializer().run() # Fetch params to validate initial values self.assertAllCloseAccordingToType([[1.0, 2.0]], var0.eval()) # Run 1 step of sgd sgd_op.run() # Validate updated params self.assertAllCloseAccordingToType( [[0, 1]], var0.eval(), atol=0.01) def testProximalAdagradWithL1(self): with self.test_session() as sess: var0 = variables.Variable([1.0, 2.0]) var1 = variables.Variable([4.0, 3.0]) grads0 = constant_op.constant([0.1, 0.2]) grads1 = constant_op.constant([0.01, 0.02]) opt = proximal_adagrad.ProximalAdagradOptimizer( 3.0, initial_accumulator_value=0.1, l1_regularization_strength=0.001, l2_regularization_strength=0.0) update = opt.apply_gradients(zip([grads0, grads1], [var0, var1])) variables.global_variables_initializer().run() v0_val, v1_val = sess.run([var0, var1]) self.assertAllClose([1.0, 2.0], v0_val) self.assertAllClose([4.0, 3.0], v1_val) # Run 10 steps Proximal Adagrad for _ in range(10): update.run() v0_val, v1_val = sess.run([var0, var1]) self.assertAllClose(np.array([-6.663634, -9.190331]), v0_val) self.assertAllClose(np.array([2.959304, 1.029232]), v1_val) def testProximalAdagradWithL1_L2(self): with self.test_session() as sess: var0 = variables.Variable([1.0, 2.0]) var1 = variables.Variable([4.0, 3.0]) grads0 = constant_op.constant([0.1, 0.2]) grads1 = constant_op.constant([0.01, 0.02]) opt = proximal_adagrad.ProximalAdagradOptimizer( 3.0, initial_accumulator_value=0.1, l1_regularization_strength=0.001, l2_regularization_strength=2.0) update = opt.apply_gradients(zip([grads0, grads1], [var0, var1])) variables.global_variables_initializer().run() v0_val, v1_val = sess.run([var0, var1]) self.assertAllClose([1.0, 2.0], v0_val) self.assertAllClose([4.0, 3.0], v1_val) # Run 10 steps Proximal Adagrad. for _ in range(10): update.run() v0_val, v1_val = sess.run([var0, var1]) self.assertAllClose(np.array([-0.0495, -0.0995]), v0_val) self.assertAllClose(np.array([-0.0045, -0.0095]), v1_val) def applyOptimizer(self, opt, steps=5, is_sparse=False): if is_sparse: var0 = variables.Variable([[1.0], [2.0]]) var1 = variables.Variable([[3.0], [4.0]]) grads0 = ops.IndexedSlices( constant_op.constant( [0.1], shape=[1, 1]), constant_op.constant([0]), constant_op.constant([2, 1])) grads1 = ops.IndexedSlices( constant_op.constant( [0.02], shape=[1, 1]), constant_op.constant([1]), constant_op.constant([2, 1])) else: var0 = variables.Variable([1.0, 2.0]) var1 = variables.Variable([3.0, 4.0]) grads0 = constant_op.constant([0.1, 0.2]) grads1 = constant_op.constant([0.01, 0.02]) update = opt.apply_gradients(zip([grads0, grads1], [var0, var1])) variables.global_variables_initializer().run() sess = ops.get_default_session() v0_val, v1_val = sess.run([var0, var1]) if is_sparse: self.assertAllClose([[1.0], [2.0]], v0_val) self.assertAllClose([[3.0], [4.0]], v1_val) else: self.assertAllClose([1.0, 2.0], v0_val) self.assertAllClose([3.0, 4.0], v1_val) # Run ProximalAdagrad for a few steps for _ in range(steps): update.run() v0_val, v1_val = sess.run([var0, var1]) return v0_val, v1_val def testEquivAdagradwithoutRegularization(self): with self.test_session(): val0, val1 = self.applyOptimizer( proximal_adagrad.ProximalAdagradOptimizer( 3.0, initial_accumulator_value=0.1, l1_regularization_strength=0.0, l2_regularization_strength=0.0)) with self.test_session(): val2, val3 = self.applyOptimizer( adagrad.AdagradOptimizer( 3.0, initial_accumulator_value=0.1)) self.assertAllClose(val0, val2) self.assertAllClose(val1, val3) def testEquivSparseAdagradwithoutRegularization(self): with self.test_session(): val0, val1 = self.applyOptimizer( proximal_adagrad.ProximalAdagradOptimizer( 3.0, initial_accumulator_value=0.1, l1_regularization_strength=0.0, l2_regularization_strength=0.0), is_sparse=True) with self.test_session(): val2, val3 = self.applyOptimizer( adagrad.AdagradOptimizer( 3.0, initial_accumulator_value=0.1), is_sparse=True) self.assertAllClose(val0, val2) self.assertAllClose(val1, val3) if __name__ == "__main__": test.main()
apache-2.0
[ 3, 1898, 6900, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 3481, 279, 2295, 367, 2165, 88, 7265, 4431, 27707, 5331, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 2680, 465, 980, 199, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4413, 63, 411, 199, 504, 3228, 14, 1548, 14, 4857, 492, 6674, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4156, 199, 504, 3228, 14, 1548, 14, 1483, 492, 12452, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3473, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 2073, 63, 1975, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 2860, 199, 504, 3228, 14, 1548, 14, 3246, 492, 511, 199, 504, 3228, 14, 1548, 14, 7588, 492, 1503, 27707, 199, 504, 3228, 14, 1548, 14, 7588, 492, 10645, 7265, 63, 350, 27707, 421, 199, 533, 2165, 88, 7265, 2767, 27707, 13946, 774, 8, 396, 14, 1746, 304, 819, 347, 886, 774, 26689, 7265, 2767, 27707, 7395, 16038, 2072, 8, 277, 12, 675, 63, 1927, 29, 797, 304, 272, 543, 291, 14, 396, 63, 1730, 342, 465, 4043, 26, 489, 2729, 16, 275, 2860, 14, 2773, 779, 16, 14, 16, 12, 378, 14, 16, 566, 489, 2729, 17, 275, 2860, 14, 2773, 779, 16, 14, 16, 12, 378, 14, 16, 566, 489, 18300, 16, 275, 4413, 63, 411, 14, 4083, 779, 16, 14, 17, 12, 378, 14, 18, 566, 489, 18300, 17, 275, 4413, 63, 411, 14, 4083, 779, 16, 14, 614, 12, 378, 14, 996, 566, 489, 2450, 275, 10645, 7265, 63, 350, 27707, 14, 26689, 7265, 2767, 27707, 13946, 8, 881, 650, 14, 16, 12, 881, 2536, 63, 21417, 63, 585, 29, 16, 14, 17, 12, 881, 634, 17, 63, 18948, 63, 21049, 29, 16, 14, 16, 12, 881, 634, 18, 63, 18948, 63, 21049, 29, 16, 14, 16, 9, 489, 1678, 275, 2450, 14, 4998, 63, 13065, 8, 3065, 779, 16525, 16, 12, 18300, 17, 467, 359, 1391, 16, 12, 2729, 17, 2459, 489, 2860, 14, 2966, 63, 3669, 63, 6498, 1252, 1065, 342, 2541, 373, 16, 63, 637, 12, 373, 17, 63, 637, 275, 4043, 14, 1065, 779, 1391, 16, 12, 2729, 17, 566, 489, 291, 14, 7260, 779, 16, 14, 16, 12, 378, 14, 16, 467, 373, 16, 63, 637, 9, 489, 291, 14, 7260, 779, 16, 14, 16, 12, 378, 14, 16, 467, 373, 17, 63, 637, 9, 2541, 327, 3378, 650, 7124, 2165, 88, 7265, 4431, 27707, 14, 489, 367, 485, 315, 1425, 8, 19, 304, 267, 1678, 14, 1065, 342, 2541, 373, 16, 63, 637, 12, 373, 17, 63, 637, 275, 4043, 14, 1065, 779, 1391, 16, 12, 2729, 17, 566, 489, 291, 14, 7260, 8, 1590, 14, 1144, 11468, 18, 14, 28384, 14520, 2766, 12, 446, 20, 14, 1398, 1876, 2426, 1046, 2522, 373, 16, 63, 637, 9, 489, 291, 14, 7260, 8, 1590, 14, 1144, 11468, 16, 14, 10681, 708, 19573, 12, 446, 16, 14, 29982, 2635, 11382, 2522, 373, 17, 63, 637, 9, 489, 2450, 63, 2936, 275, 2450, 14, 3669, 342, 489, 291, 14, 479, 32142, 3007, 8, 2992, 63, 2936, 59, 16, 1055, 354, 12, 2729, 16, 423, 5555, 63, 354, 9, 489, 291, 14, 479, 32142, 3007, 8, 2992, 63, 2936, 59, 17, 1055, 354, 12, 2729, 17, 423, 5555, 63, 354, 9, 489, 291, 14, 629, 8, 18, 12, 822, 8, 2992, 63, 2936, 430, 819, 347, 511, 26689, 7265, 2767, 27707, 7395, 16038, 2072, 8, 277, 304, 272, 291, 14, 1117, 774, 26689, 7265, 2767, 27707, 7395, 16038, 2072, 8, 1180, 63, 1927, 29, 797, 9, 819, 347, 511, 4031, 26689, 7265, 2767, 27707, 7395, 16038, 2072, 8, 277, 304, 272, 291, 14, 1117, 774, 26689, 7265, 2767, 27707, 7395, 16038, 2072, 8, 1180, 63, 1927, 29, 549, 9, 819, 347, 511, 26689, 7265, 2767, 27707, 7395, 16038, 2072, 18, 8, 277, 304, 272, 543, 291, 14, 396, 63, 1730, 342, 465, 4043, 26, 489, 2729, 16, 275, 2860, 14, 2773, 779, 17, 14, 16, 12, 499, 14, 16, 566, 489, 2729, 17, 275, 2860, 14, 2773, 779, 20, 14, 16, 12, 650, 14, 16, 566, 489, 18300, 16, 275, 4413, 63, 411, 14, 4083, 779, 16, 14, 17, 12, 378, 14, 18, 566, 489, 18300, 17, 275, 4413, 63, 411, 14, 4083, 779, 16, 14, 614, 12, 378, 14, 996, 566, 2541, 2450, 275, 10645, 7265, 63, 350, 27707, 14, 26689, 7265, 2767, 27707, 13946, 8, 881, 650, 14, 16, 12, 881, 2536, 63, 21417, 63, 585, 29, 16, 14, 17, 12, 881, 634, 17, 63, 18948, 63, 21049, 29, 16, 14, 16, 12, 881, 634, 18, 63, 18948, 63, 21049, 29, 16, 14, 16, 9, 489, 1678, 275, 2450, 14, 4998, 63, 13065, 8, 3065, 779, 16525, 16, 12, 18300, 17, 467, 359, 1391, 16, 12, 2729, 17, 2459, 489, 2860, 14, 2966, 63, 3669, 63, 6498, 1252, 1065, 342, 2541, 373, 16, 63, 637, 12, 373, 17, 63, 637, 275, 4043, 14, 1065, 779, 1391, 16, 12, 2729, 17, 566, 489, 291, 14, 7260, 779, 17, 14, 16, 12, 499, 14, 16, 467, 373, 16, 63, 637, 9, 489, 291, 14, 7260, 779, 20, 14, 16, 12, 650, 14, 16, 467, 373 ]
[ 1898, 6900, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 3481, 279, 2295, 367, 2165, 88, 7265, 4431, 27707, 5331, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 2680, 465, 980, 199, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4413, 63, 411, 199, 504, 3228, 14, 1548, 14, 4857, 492, 6674, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4156, 199, 504, 3228, 14, 1548, 14, 1483, 492, 12452, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3473, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 2073, 63, 1975, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 2860, 199, 504, 3228, 14, 1548, 14, 3246, 492, 511, 199, 504, 3228, 14, 1548, 14, 7588, 492, 1503, 27707, 199, 504, 3228, 14, 1548, 14, 7588, 492, 10645, 7265, 63, 350, 27707, 421, 199, 533, 2165, 88, 7265, 2767, 27707, 13946, 774, 8, 396, 14, 1746, 304, 819, 347, 886, 774, 26689, 7265, 2767, 27707, 7395, 16038, 2072, 8, 277, 12, 675, 63, 1927, 29, 797, 304, 272, 543, 291, 14, 396, 63, 1730, 342, 465, 4043, 26, 489, 2729, 16, 275, 2860, 14, 2773, 779, 16, 14, 16, 12, 378, 14, 16, 566, 489, 2729, 17, 275, 2860, 14, 2773, 779, 16, 14, 16, 12, 378, 14, 16, 566, 489, 18300, 16, 275, 4413, 63, 411, 14, 4083, 779, 16, 14, 17, 12, 378, 14, 18, 566, 489, 18300, 17, 275, 4413, 63, 411, 14, 4083, 779, 16, 14, 614, 12, 378, 14, 996, 566, 489, 2450, 275, 10645, 7265, 63, 350, 27707, 14, 26689, 7265, 2767, 27707, 13946, 8, 881, 650, 14, 16, 12, 881, 2536, 63, 21417, 63, 585, 29, 16, 14, 17, 12, 881, 634, 17, 63, 18948, 63, 21049, 29, 16, 14, 16, 12, 881, 634, 18, 63, 18948, 63, 21049, 29, 16, 14, 16, 9, 489, 1678, 275, 2450, 14, 4998, 63, 13065, 8, 3065, 779, 16525, 16, 12, 18300, 17, 467, 359, 1391, 16, 12, 2729, 17, 2459, 489, 2860, 14, 2966, 63, 3669, 63, 6498, 1252, 1065, 342, 2541, 373, 16, 63, 637, 12, 373, 17, 63, 637, 275, 4043, 14, 1065, 779, 1391, 16, 12, 2729, 17, 566, 489, 291, 14, 7260, 779, 16, 14, 16, 12, 378, 14, 16, 467, 373, 16, 63, 637, 9, 489, 291, 14, 7260, 779, 16, 14, 16, 12, 378, 14, 16, 467, 373, 17, 63, 637, 9, 2541, 327, 3378, 650, 7124, 2165, 88, 7265, 4431, 27707, 14, 489, 367, 485, 315, 1425, 8, 19, 304, 267, 1678, 14, 1065, 342, 2541, 373, 16, 63, 637, 12, 373, 17, 63, 637, 275, 4043, 14, 1065, 779, 1391, 16, 12, 2729, 17, 566, 489, 291, 14, 7260, 8, 1590, 14, 1144, 11468, 18, 14, 28384, 14520, 2766, 12, 446, 20, 14, 1398, 1876, 2426, 1046, 2522, 373, 16, 63, 637, 9, 489, 291, 14, 7260, 8, 1590, 14, 1144, 11468, 16, 14, 10681, 708, 19573, 12, 446, 16, 14, 29982, 2635, 11382, 2522, 373, 17, 63, 637, 9, 489, 2450, 63, 2936, 275, 2450, 14, 3669, 342, 489, 291, 14, 479, 32142, 3007, 8, 2992, 63, 2936, 59, 16, 1055, 354, 12, 2729, 16, 423, 5555, 63, 354, 9, 489, 291, 14, 479, 32142, 3007, 8, 2992, 63, 2936, 59, 17, 1055, 354, 12, 2729, 17, 423, 5555, 63, 354, 9, 489, 291, 14, 629, 8, 18, 12, 822, 8, 2992, 63, 2936, 430, 819, 347, 511, 26689, 7265, 2767, 27707, 7395, 16038, 2072, 8, 277, 304, 272, 291, 14, 1117, 774, 26689, 7265, 2767, 27707, 7395, 16038, 2072, 8, 1180, 63, 1927, 29, 797, 9, 819, 347, 511, 4031, 26689, 7265, 2767, 27707, 7395, 16038, 2072, 8, 277, 304, 272, 291, 14, 1117, 774, 26689, 7265, 2767, 27707, 7395, 16038, 2072, 8, 1180, 63, 1927, 29, 549, 9, 819, 347, 511, 26689, 7265, 2767, 27707, 7395, 16038, 2072, 18, 8, 277, 304, 272, 543, 291, 14, 396, 63, 1730, 342, 465, 4043, 26, 489, 2729, 16, 275, 2860, 14, 2773, 779, 17, 14, 16, 12, 499, 14, 16, 566, 489, 2729, 17, 275, 2860, 14, 2773, 779, 20, 14, 16, 12, 650, 14, 16, 566, 489, 18300, 16, 275, 4413, 63, 411, 14, 4083, 779, 16, 14, 17, 12, 378, 14, 18, 566, 489, 18300, 17, 275, 4413, 63, 411, 14, 4083, 779, 16, 14, 614, 12, 378, 14, 996, 566, 2541, 2450, 275, 10645, 7265, 63, 350, 27707, 14, 26689, 7265, 2767, 27707, 13946, 8, 881, 650, 14, 16, 12, 881, 2536, 63, 21417, 63, 585, 29, 16, 14, 17, 12, 881, 634, 17, 63, 18948, 63, 21049, 29, 16, 14, 16, 12, 881, 634, 18, 63, 18948, 63, 21049, 29, 16, 14, 16, 9, 489, 1678, 275, 2450, 14, 4998, 63, 13065, 8, 3065, 779, 16525, 16, 12, 18300, 17, 467, 359, 1391, 16, 12, 2729, 17, 2459, 489, 2860, 14, 2966, 63, 3669, 63, 6498, 1252, 1065, 342, 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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
theboocock/fine_mapping_pipeline
fine_mapping_pipeline/utils/zscores.py
2
3971
# Copyright (c) 2015 Boocock James <james.boocock@otago.ac.nz> # Author: Boocock James <james.boocock@otago.ac.nz> # # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import os from os import listdir import logging def get_relevant_zscore(chrom, population, directory): """ Scans the directory specified on the command-line by the user and checks for the specified chromosome. """ zscore_files = [f for f in listdir(directory)] chrom = 'chr' + chrom z_score_file = [f for f in zscore_files if chrom in f and population in f][0] return os.path.join(directory, z_score_file) def create_pos_hash_table(zscore_file): """ Create position hash table TODO: Fix indel and CNV being removed from the inital analysis. @param pos_file the Z scores file containing the positions from impg @return pos_hash a hash table that contains the line from impG """ pos_hash = {} with open(zscore_file) as p: for i, line in enumerate(p): line = line.strip() if i != 0: pos_hash[int(line.split()[1])] = [line.split()[4],line.split()[5]] return (pos_hash) def generate_zscore_and_vcf_output(output_directory, zscore_hash, vcf, locus, population, multiply_rsquare): """ Extract vcf regions that have overlap with Impg data. """ # output vcf is a temporary file that will be used downstream of this dataset. output_vcf = os.path.join(output_directory, locus + '.' + population + '.vcf') output_zscore = os.path.join(output_directory, locus + '.' + population) caviar_zscore = os.path.join(output_directory, locus + '.' + population + '.Z') with open(output_vcf, 'w') as out_vcf: with open(output_zscore, 'w') as out_zscore: with open(caviar_zscore, 'w') as out_caviar: for line in vcf.splitlines(): if "#" in line: out_vcf.write(line + '\n') else: chrom = line.split("\t")[0] pos = int(line.split('\t')[1]) if pos in zscore_hash.keys(): temp_z_score = zscore_hash[pos] rsid = line.split('\t')[2] out_vcf.write(line + '\n') if multiply_rsquare: out_zscore.write(chrom + " " + str(pos) + " " + rsid + " " + str(float(zscore_hash[pos][0]) * float(zscore_hash[pos][1])) +'\n') else: out_zscore.write(chrom + " " + str(pos) + " " + rsid + " " + zscore_hash[pos][0] +'\n') out_caviar.write(rsid+ ' ' + zscore_hash[pos][0] +'\n') return output_vcf
mit
[ 3, 1898, 334, 67, 9, 6900, 699, 1534, 331, 346, 1603, 14015, 665, 74, 14015, 14, 15056, 331, 346, 32, 357, 14315, 14, 645, 14, 15291, 30, 199, 3, 6529, 26, 699, 1534, 331, 346, 1603, 14015, 665, 74, 14015, 14, 15056, 331, 346, 32, 357, 14315, 14, 645, 14, 15291, 30, 199, 3, 221, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 282, 1331, 402, 199, 3, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 298, 10337, 1288, 370, 7962, 315, 199, 3, 314, 2290, 1928, 10588, 12, 5893, 1928, 12305, 314, 4481, 370, 199, 3, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 11207, 12, 13473, 12, 436, 15, 269, 12743, 6866, 402, 199, 3, 314, 2290, 12, 436, 370, 11291, 12103, 370, 12676, 314, 2290, 365, 13985, 370, 886, 880, 12, 199, 3, 5420, 370, 314, 2569, 3704, 26, 199, 3, 221, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 315, 1006, 199, 3, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 221, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 7168, 1549, 199, 3, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 3169, 12, 3092, 199, 3, 2381, 437, 3115, 3104, 2401, 13229, 14, 1621, 4825, 6461, 7000, 2334, 10610, 1549, 199, 3, 5877, 8164, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 5603, 12, 7061, 199, 3, 1621, 1261, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 5738, 1634, 1549, 1621, 199, 3, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 1621, 2334, 4141, 14, 199, 199, 646, 747, 199, 504, 747, 492, 27483, 199, 646, 2050, 199, 199, 318, 664, 63, 21906, 63, 90, 3397, 8, 23473, 12, 16423, 12, 2082, 304, 272, 408, 267, 13916, 796, 314, 2082, 2013, 641, 314, 1414, 13, 604, 701, 314, 922, 436, 5920, 367, 314, 2013, 20074, 26803, 14, 339, 408, 272, 1315, 3397, 63, 1725, 275, 359, 70, 367, 289, 315, 27483, 8, 3619, 1874, 272, 20074, 275, 283, 10194, 7, 435, 20074, 272, 1315, 63, 3397, 63, 493, 275, 359, 70, 367, 289, 315, 1315, 3397, 63, 1725, 340, 20074, 315, 289, 436, 16423, 315, 289, 1527, 16, 61, 272, 372, 747, 14, 515, 14, 904, 8, 3619, 12, 1315, 63, 3397, 63, 493, 9, 199, 199, 318, 1218, 63, 1712, 63, 2227, 63, 1224, 8, 90, 3397, 63, 493, 304, 272, 408, 267, 2790, 3421, 2631, 1817, 2728, 3254, 26, 14811, 315, 2264, 436, 445, 7312, 3769, 4829, 687, 314, 4205, 279, 11284, 14, 398, 768, 635, 2086, 63, 493, 314, 3107, 9342, 570, 3035, 314, 12266, 687, 1742, 71, 2728, 768, 1107, 2086, 63, 2227, 282, 2631, 1817, 626, 3509, 314, 1004, 687, 1742, 39, 339, 408, 272, 2086, 63, 2227, 275, 1052, 272, 543, 1551, 8, 90, 3397, 63, 493, 9, 465, 299, 26, 267, 367, 284, 12, 1004, 315, 3874, 8, 80, 304, 288, 1004, 275, 1004, 14, 1913, 342, 288, 340, 284, 1137, 378, 26, 355, 2086, 63, 2227, 59, 442, 8, 604, 14, 1294, 3430, 17, 12457, 275, 359, 604, 14, 1294, 3430, 20, 467, 604, 14, 1294, 3430, 21, 2677, 272, 372, 334, 1712, 63, 2227, 9, 199, 199, 318, 3550, 63, 90, 3397, 63, 460, 63, 27288, 63, 1199, 8, 1199, 63, 3619, 12, 221, 2490, 1315, 3397, 63, 2227, 12, 221, 2490, 373, 2177, 12, 2490, 4355, 527, 12, 2490, 16423, 12, 2490, 21699, 63, 2393, 5937, 304, 272, 408, 267, 12892, 373, 2177, 16150, 626, 1172, 15145, 543, 8362, 71, 666, 14, 339, 408, 272, 327, 1072, 373, 2177, 365, 282, 7937, 570, 626, 911, 506, 1202, 3224, 1745, 402, 642, 4789, 14, 272, 1072, 63, 27288, 275, 747, 14, 515, 14, 904, 8, 1199, 63, 3619, 12, 4355, 527, 435, 7815, 435, 16423, 435, 1987, 27288, 358, 272, 1072, 63, 90, 3397, 275, 747, 14, 515, 14, 904, 8, 1199, 63, 3619, 12, 4355, 527, 435, 7815, 435, 16423, 9, 272, 1704, 433, 285, 63, 90, 3397, 275, 747, 14, 515, 14, 904, 8, 1199, 63, 3619, 12, 4355, 527, 435, 7815, 435, 16423, 435, 1987, 58, 358, 272, 543, 1551, 8, 1199, 63, 27288, 12, 283, 87, 358, 465, 734, 63, 27288, 26, 267, 543, 1551, 8, 1199, 63, 90, 3397, 12, 283, 87, 358, 465, 734, 63, 90, 3397, 26, 288, 543, 1551, 8, 696, 433, 285, 63, 90, 3397, 12, 283, 87, 358, 465, 734, 63, 696, 433, 285, 26, 355, 367, 1004, 315, 373, 2177, 14, 7644, 837, 490, 340, 5426, 2, 315, 1004, 26, 717, 734, 63, 27288, 14, 952, 8, 604, 435, 1557, 78, 358, 490, 587, 26, 717, 20074, 275, 1004, 14, 1294, 4582, 84, 9981, 16, 61, 717, 2086, 275, 1109, 8, 604, 14, 1294, 2258, 84, 5832, 17, 566, 717, 340, 2086, 315, 1315, 3397, 63, 2227, 14, 1612, 837, 1169, 2388, 63, 90, 63, 3397, 275, 1315, 3397, 63, 2227, 59, 1712, 61, 1169, 519, 4148, 275, 1004, 14, 1294, 2258, 84, 5832, 18, 61, 1169, 734, 63, 27288, 14, 952, 8, 604, 435, 1557, 78, 358, 1169, 340, 21699, 63, 2393, 5937, 26, 221, 1816, 734, 63, 90, 3397, 14, 952, 8, 23473, 435, 298, 298, 435, 620, 8, 1712, 9, 435, 298, 298, 435, 519, 4148, 435, 298, 298, 435, 620, 8, 1609, 8, 90, 3397, 63, 2227, 59, 1712, 1527, 16, 566, 627, 2069, 8, 90, 3397, 63, 2227, 59, 1712, 1527, 17, 2459, 435, 1154, 78, 358, 1169, 587, 26, 1816, 734, 63, 90, 3397, 14, 952, 8, 23473, 435, 298, 298, 435, 620, 8, 1712, 9, 435, 298, 298, 435, 519, 4148, 435, 298, 298, 435, 1315, 3397, 63, 2227, 59, 1712, 1527, 16, 61, 435, 1154, 78, 358, 1169, 734, 63, 696, 433, 285, 14, 952, 8, 82, 4148, 11, 283, 283, 435, 1315, 3397, 63, 2227, 59, 1712, 1527, 16, 61, 435, 1154, 78, 358, 272, 372, 1072, 63, 27288, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1898, 334, 67, 9, 6900, 699, 1534, 331, 346, 1603, 14015, 665, 74, 14015, 14, 15056, 331, 346, 32, 357, 14315, 14, 645, 14, 15291, 30, 199, 3, 6529, 26, 699, 1534, 331, 346, 1603, 14015, 665, 74, 14015, 14, 15056, 331, 346, 32, 357, 14315, 14, 645, 14, 15291, 30, 199, 3, 221, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 282, 1331, 402, 199, 3, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 298, 10337, 1288, 370, 7962, 315, 199, 3, 314, 2290, 1928, 10588, 12, 5893, 1928, 12305, 314, 4481, 370, 199, 3, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 11207, 12, 13473, 12, 436, 15, 269, 12743, 6866, 402, 199, 3, 314, 2290, 12, 436, 370, 11291, 12103, 370, 12676, 314, 2290, 365, 13985, 370, 886, 880, 12, 199, 3, 5420, 370, 314, 2569, 3704, 26, 199, 3, 221, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 315, 1006, 199, 3, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 221, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 7168, 1549, 199, 3, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 3169, 12, 3092, 199, 3, 2381, 437, 3115, 3104, 2401, 13229, 14, 1621, 4825, 6461, 7000, 2334, 10610, 1549, 199, 3, 5877, 8164, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 5603, 12, 7061, 199, 3, 1621, 1261, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 5738, 1634, 1549, 1621, 199, 3, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 1621, 2334, 4141, 14, 199, 199, 646, 747, 199, 504, 747, 492, 27483, 199, 646, 2050, 199, 199, 318, 664, 63, 21906, 63, 90, 3397, 8, 23473, 12, 16423, 12, 2082, 304, 272, 408, 267, 13916, 796, 314, 2082, 2013, 641, 314, 1414, 13, 604, 701, 314, 922, 436, 5920, 367, 314, 2013, 20074, 26803, 14, 339, 408, 272, 1315, 3397, 63, 1725, 275, 359, 70, 367, 289, 315, 27483, 8, 3619, 1874, 272, 20074, 275, 283, 10194, 7, 435, 20074, 272, 1315, 63, 3397, 63, 493, 275, 359, 70, 367, 289, 315, 1315, 3397, 63, 1725, 340, 20074, 315, 289, 436, 16423, 315, 289, 1527, 16, 61, 272, 372, 747, 14, 515, 14, 904, 8, 3619, 12, 1315, 63, 3397, 63, 493, 9, 199, 199, 318, 1218, 63, 1712, 63, 2227, 63, 1224, 8, 90, 3397, 63, 493, 304, 272, 408, 267, 2790, 3421, 2631, 1817, 2728, 3254, 26, 14811, 315, 2264, 436, 445, 7312, 3769, 4829, 687, 314, 4205, 279, 11284, 14, 398, 768, 635, 2086, 63, 493, 314, 3107, 9342, 570, 3035, 314, 12266, 687, 1742, 71, 2728, 768, 1107, 2086, 63, 2227, 282, 2631, 1817, 626, 3509, 314, 1004, 687, 1742, 39, 339, 408, 272, 2086, 63, 2227, 275, 1052, 272, 543, 1551, 8, 90, 3397, 63, 493, 9, 465, 299, 26, 267, 367, 284, 12, 1004, 315, 3874, 8, 80, 304, 288, 1004, 275, 1004, 14, 1913, 342, 288, 340, 284, 1137, 378, 26, 355, 2086, 63, 2227, 59, 442, 8, 604, 14, 1294, 3430, 17, 12457, 275, 359, 604, 14, 1294, 3430, 20, 467, 604, 14, 1294, 3430, 21, 2677, 272, 372, 334, 1712, 63, 2227, 9, 199, 199, 318, 3550, 63, 90, 3397, 63, 460, 63, 27288, 63, 1199, 8, 1199, 63, 3619, 12, 221, 2490, 1315, 3397, 63, 2227, 12, 221, 2490, 373, 2177, 12, 2490, 4355, 527, 12, 2490, 16423, 12, 2490, 21699, 63, 2393, 5937, 304, 272, 408, 267, 12892, 373, 2177, 16150, 626, 1172, 15145, 543, 8362, 71, 666, 14, 339, 408, 272, 327, 1072, 373, 2177, 365, 282, 7937, 570, 626, 911, 506, 1202, 3224, 1745, 402, 642, 4789, 14, 272, 1072, 63, 27288, 275, 747, 14, 515, 14, 904, 8, 1199, 63, 3619, 12, 4355, 527, 435, 7815, 435, 16423, 435, 1987, 27288, 358, 272, 1072, 63, 90, 3397, 275, 747, 14, 515, 14, 904, 8, 1199, 63, 3619, 12, 4355, 527, 435, 7815, 435, 16423, 9, 272, 1704, 433, 285, 63, 90, 3397, 275, 747, 14, 515, 14, 904, 8, 1199, 63, 3619, 12, 4355, 527, 435, 7815, 435, 16423, 435, 1987, 58, 358, 272, 543, 1551, 8, 1199, 63, 27288, 12, 283, 87, 358, 465, 734, 63, 27288, 26, 267, 543, 1551, 8, 1199, 63, 90, 3397, 12, 283, 87, 358, 465, 734, 63, 90, 3397, 26, 288, 543, 1551, 8, 696, 433, 285, 63, 90, 3397, 12, 283, 87, 358, 465, 734, 63, 696, 433, 285, 26, 355, 367, 1004, 315, 373, 2177, 14, 7644, 837, 490, 340, 5426, 2, 315, 1004, 26, 717, 734, 63, 27288, 14, 952, 8, 604, 435, 1557, 78, 358, 490, 587, 26, 717, 20074, 275, 1004, 14, 1294, 4582, 84, 9981, 16, 61, 717, 2086, 275, 1109, 8, 604, 14, 1294, 2258, 84, 5832, 17, 566, 717, 340, 2086, 315, 1315, 3397, 63, 2227, 14, 1612, 837, 1169, 2388, 63, 90, 63, 3397, 275, 1315, 3397, 63, 2227, 59, 1712, 61, 1169, 519, 4148, 275, 1004, 14, 1294, 2258, 84, 5832, 18, 61, 1169, 734, 63, 27288, 14, 952, 8, 604, 435, 1557, 78, 358, 1169, 340, 21699, 63, 2393, 5937, 26, 221, 1816, 734, 63, 90, 3397, 14, 952, 8, 23473, 435, 298, 298, 435, 620, 8, 1712, 9, 435, 298, 298, 435, 519, 4148, 435, 298, 298, 435, 620, 8, 1609, 8, 90, 3397, 63, 2227, 59, 1712, 1527, 16, 566, 627, 2069, 8, 90, 3397, 63, 2227, 59, 1712, 1527, 17, 2459, 435, 1154, 78, 358, 1169, 587, 26, 1816, 734, 63, 90, 3397, 14, 952, 8, 23473, 435, 298, 298, 435, 620, 8, 1712, 9, 435, 298, 298, 435, 519, 4148, 435, 298, 298, 435, 1315, 3397, 63, 2227, 59, 1712, 1527, 16, 61, 435, 1154, 78, 358, 1169, 734, 63, 696, 433, 285, 14, 952, 8, 82, 4148, 11, 283, 283, 435, 1315, 3397, 63, 2227, 59, 1712, 1527, 16, 61, 435, 1154, 78, 358, 272, 372, 1072, 63, 27288, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
istresearch/readthedocs.org
readthedocs/rtd_tests/tests/test_bookmarks.py
32
4846
from django.test import TestCase from django.core.urlresolvers import reverse from django.contrib.auth.models import User import json from readthedocs.builds.constants import LATEST from readthedocs.projects.models import Project from readthedocs.bookmarks.models import Bookmark class TestBookmarks(TestCase): fixtures = ['eric', 'test_data'] def setUp(self): self.project = Project.objects.get(pk=1) self.client.login(username='eric', password='test') self.user = User.objects.get(pk=1) self.project.users.add(self.user) def __add_bookmark(self): post_data = { "project": self.project.slug, "version": LATEST, "page": "", "url": "", } response = self.client.post( reverse('bookmarks_add'), data=json.dumps(post_data), content_type="application/json" ) self.assertEqual(response.status_code, 201) self.assertContains(response, 'added', status_code=201) return Bookmark.objects.get(pk=1) def test_add_bookmark_denies_get_requests(self): response = self.client.get(reverse('bookmarks_add')) self.assertEqual(response.status_code, 405) self.assertContains(response, 'error', status_code=405) def test_add_bookmark(self): bookmark = self.__add_bookmark() self.assertEqual(bookmark.user, self.user) self.assertEqual(bookmark.project.slug, self.project.slug) self.assertEqual(Bookmark.objects.count(), 1) def test_add_bookmark_fails_bad_data(self): post_data = { "project": 'fail', "version": 'fail', "page": "", "url": "" } response = self.client.post( reverse('bookmarks_add'), data=json.dumps(post_data), content_type="text/javascript" ) self.assertEqual(response.status_code, 400) self.assertContains(response, 'error', status_code=400) def test_delete_bookmark_with_get_renders_confirmation_page(self): self.__add_bookmark() response = self.client.get( reverse('bookmark_remove', kwargs={'bookmark_pk': '1'}) ) self.assertEqual(response.status_code, 200) self.assertContains(response, 'You sure? O_o') def test_delete_bookmark_with_url(self): self.__add_bookmark() response = self.client.post( reverse('bookmark_remove', kwargs={'bookmark_pk': '1'}) ) self.assertRedirects(response, reverse('bookmark_list')) self.assertEqual(Bookmark.objects.count(), 0) def test_delete_bookmark_with_json(self): self.__add_bookmark() post_data = { "project": self.project.slug, "version": LATEST, "page": "", "url": "", } response = self.client.post( reverse('bookmark_remove_json'), data=json.dumps(post_data), content_type="application/json" ) self.assertEqual(response.status_code, 200) self.assertEqual(Bookmark.objects.count(), 0) def test_dont_delete_bookmarks_with_bad_json(self): self.__add_bookmark() post_data = {"bad project": self.project.slug} response = self.client.post( reverse('bookmark_remove_json'), data=json.dumps(post_data), content_type="application/json" ) self.assertEqual(response.status_code, 400) self.assertEqual(Bookmark.objects.count(), 1) self.assertContains(response, "Invalid parameters", status_code=400) def test_bookmark_exists_true_when_exists(self): bookmark = self.__add_bookmark() post_data = { 'project': bookmark.project.slug, 'version': bookmark.version.slug, 'page': bookmark.page } response = self.client.post( reverse('bookmark_exists'), data=json.dumps(post_data), content_type="application/json" ) self.assertEqual(response.status_code, 200) self.assertTrue(json.loads(response.content)['exists']) def test_bookmark_exists_404_when_does_not_exist(self): response = self.client.post( reverse('bookmark_exists'), data=json.dumps( {'project': 'dont-read-docs', 'version': '', 'page': ''} ), content_type="application/json" ) self.assertEqual(response.status_code, 404) self.assertFalse(json.loads(response.content)['exists']) def test_bookmark_exists_forbids_GET(self): response = self.client.get(reverse('bookmark_exists')) self.assertEqual(response.status_code, 405) self.assertNotContains(response, 'exists', status_code=405)
mit
[ 504, 1639, 14, 396, 492, 7640, 199, 504, 1639, 14, 1018, 14, 16522, 492, 3837, 199, 504, 1639, 14, 2828, 14, 1178, 14, 992, 492, 2876, 199, 646, 2022, 199, 199, 504, 1586, 22618, 14, 10838, 14, 5559, 492, 491, 619, 1719, 199, 504, 1586, 22618, 14, 6776, 14, 992, 492, 7290, 199, 504, 1586, 22618, 14, 25799, 14, 992, 492, 8944, 1657, 421, 199, 533, 1379, 8696, 10375, 8, 1746, 304, 272, 15188, 275, 788, 281, 530, 297, 283, 396, 63, 576, 418, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 1715, 275, 7290, 14, 1462, 14, 362, 8, 2051, 29, 17, 9, 267, 291, 14, 1258, 14, 2886, 8, 2473, 534, 281, 530, 297, 2505, 534, 396, 358, 267, 291, 14, 751, 275, 2876, 14, 1462, 14, 362, 8, 2051, 29, 17, 9, 267, 291, 14, 1715, 14, 3707, 14, 525, 8, 277, 14, 751, 9, 339, 347, 636, 525, 63, 17341, 8, 277, 304, 267, 2963, 63, 576, 275, 469, 288, 298, 1715, 582, 291, 14, 1715, 14, 5464, 12, 288, 298, 1023, 582, 491, 619, 1719, 12, 288, 298, 1606, 582, 4873, 288, 298, 633, 582, 4873, 267, 789, 398, 1177, 275, 291, 14, 1258, 14, 1932, 8, 288, 3837, 360, 25799, 63, 525, 659, 288, 666, 29, 1001, 14, 4180, 8, 1932, 63, 576, 395, 288, 1564, 63, 466, 628, 3578, 15, 1001, 2, 267, 776, 398, 291, 14, 629, 8, 1310, 14, 1205, 63, 600, 12, 1784, 9, 267, 291, 14, 9535, 8, 1310, 12, 283, 3270, 297, 2004, 63, 600, 29, 1797, 9, 267, 372, 8944, 1657, 14, 1462, 14, 362, 8, 2051, 29, 17, 9, 339, 347, 511, 63, 525, 63, 17341, 63, 848, 1500, 63, 362, 63, 6615, 8, 277, 304, 267, 1177, 275, 291, 14, 1258, 14, 362, 8, 4471, 360, 25799, 63, 525, 1333, 267, 291, 14, 629, 8, 1310, 14, 1205, 63, 600, 12, 25766, 9, 267, 291, 14, 9535, 8, 1310, 12, 283, 705, 297, 2004, 63, 600, 29, 15770, 9, 339, 347, 511, 63, 525, 63, 17341, 8, 277, 304, 267, 23799, 275, 291, 855, 525, 63, 17341, 342, 267, 291, 14, 629, 8, 17341, 14, 751, 12, 291, 14, 751, 9, 267, 291, 14, 629, 8, 17341, 14, 1715, 14, 5464, 12, 291, 14, 1715, 14, 5464, 9, 267, 291, 14, 629, 8, 8696, 1657, 14, 1462, 14, 835, 1062, 413, 9, 339, 347, 511, 63, 525, 63, 17341, 63, 15762, 63, 4087, 63, 576, 8, 277, 304, 267, 2963, 63, 576, 275, 469, 288, 298, 1715, 582, 283, 1633, 297, 298, 1023, 582, 283, 1633, 297, 298, 1606, 582, 4873, 298, 633, 582, 3087, 267, 789, 267, 1177, 275, 291, 14, 1258, 14, 1932, 8, 288, 3837, 360, 25799, 63, 525, 659, 288, 666, 29, 1001, 14, 4180, 8, 1932, 63, 576, 395, 288, 1564, 63, 466, 628, 505, 15, 9554, 2, 267, 776, 398, 291, 14, 629, 8, 1310, 14, 1205, 63, 600, 12, 8290, 9, 267, 291, 14, 9535, 8, 1310, 12, 283, 705, 297, 2004, 63, 600, 29, 5303, 9, 339, 347, 511, 63, 1807, 63, 17341, 63, 1045, 63, 362, 63, 3352, 83, 63, 20903, 63, 1606, 8, 277, 304, 267, 291, 855, 525, 63, 17341, 342, 267, 1177, 275, 291, 14, 1258, 14, 362, 8, 288, 3837, 360, 17341, 63, 2168, 297, 2074, 3713, 17341, 63, 2051, 356, 283, 17, 3071, 267, 776, 398, 291, 14, 629, 8, 1310, 14, 1205, 63, 600, 12, 1926, 9, 267, 291, 14, 9535, 8, 1310, 12, 283, 5556, 3238, 31, 593, 63, 79, 358, 339, 347, 511, 63, 1807, 63, 17341, 63, 1045, 63, 633, 8, 277, 304, 267, 291, 855, 525, 63, 17341, 342, 267, 1177, 275, 291, 14, 1258, 14, 1932, 8, 288, 3837, 360, 17341, 63, 2168, 297, 2074, 3713, 17341, 63, 2051, 356, 283, 17, 3071, 267, 776, 267, 291, 14, 17466, 8, 1310, 12, 3837, 360, 17341, 63, 513, 1333, 267, 291, 14, 629, 8, 8696, 1657, 14, 1462, 14, 835, 1062, 378, 9, 339, 347, 511, 63, 1807, 63, 17341, 63, 1045, 63, 1001, 8, 277, 304, 267, 291, 855, 525, 63, 17341, 342, 398, 2963, 63, 576, 275, 469, 288, 298, 1715, 582, 291, 14, 1715, 14, 5464, 12, 288, 298, 1023, 582, 491, 619, 1719, 12, 288, 298, 1606, 582, 4873, 288, 298, 633, 582, 4873, 267, 789, 398, 1177, 275, 291, 14, 1258, 14, 1932, 8, 288, 3837, 360, 17341, 63, 2168, 63, 1001, 659, 288, 666, 29, 1001, 14, 4180, 8, 1932, 63, 576, 395, 288, 1564, 63, 466, 628, 3578, 15, 1001, 2, 267, 776, 398, 291, 14, 629, 8, 1310, 14, 1205, 63, 600, 12, 1926, 9, 267, 291, 14, 629, 8, 8696, 1657, 14, 1462, 14, 835, 1062, 378, 9, 339, 347, 511, 63, 18671, 63, 1807, 63, 25799, 63, 1045, 63, 4087, 63, 1001, 8, 277, 304, 267, 291, 855, 525, 63, 17341, 342, 267, 2963, 63, 576, 275, 2420, 4087, 2199, 582, 291, 14, 1715, 14, 5464, 93, 398, 1177, 275, 291, 14, 1258, 14, 1932, 8, 288, 3837, 360, 17341, 63, 2168, 63, 1001, 659, 288, 666, 29, 1001, 14, 4180, 8, 1932, 63, 576, 395, 288, 1564, 63, 466, 628, 3578, 15, 1001, 2, 267, 776, 267, 291, 14, 629, 8, 1310, 14, 1205, 63, 600, 12, 8290, 9, 267, 291, 14, 629, 8, 8696, 1657, 14, 1462, 14, 835, 1062, 413, 9, 267, 291, 14, 9535, 8, 1310, 12, 298, 3364, 2633, 401, 2004, 63, 600, 29, 5303, 9, 339, 347, 511, 63, 17341, 63, 2444, 63, 2052, 63, 6526, 63, 2444, 8, 277, 304, 267, 23799, 275, 291, 855, 525, 63, 17341, 342, 267, 2963, 63, 576, 275, 469, 288, 283, 1715, 356, 23799, 14, 1715, 14, 5464, 12, 288, 283, 1023, 356, 23799, 14, 1023, 14, 5464, 12, 288, 283, 1606, 356, 23799, 14, 1606, 267, 789, 398, 1177, 275, 291, 14, 1258, 14, 1932, 8, 288, 3837, 360, 17341, 63, 2444, 659, 288, 666, 29, 1001, 14, 4180, 8, 1932, 63, 576, 395, 288, 1564, 63, 466, 628, 3578, 15, 1001, 2, 267, 776, 398, 291, 14, 629, 8, 1310, 14, 1205, 63, 600 ]
[ 1639, 14, 396, 492, 7640, 199, 504, 1639, 14, 1018, 14, 16522, 492, 3837, 199, 504, 1639, 14, 2828, 14, 1178, 14, 992, 492, 2876, 199, 646, 2022, 199, 199, 504, 1586, 22618, 14, 10838, 14, 5559, 492, 491, 619, 1719, 199, 504, 1586, 22618, 14, 6776, 14, 992, 492, 7290, 199, 504, 1586, 22618, 14, 25799, 14, 992, 492, 8944, 1657, 421, 199, 533, 1379, 8696, 10375, 8, 1746, 304, 272, 15188, 275, 788, 281, 530, 297, 283, 396, 63, 576, 418, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 1715, 275, 7290, 14, 1462, 14, 362, 8, 2051, 29, 17, 9, 267, 291, 14, 1258, 14, 2886, 8, 2473, 534, 281, 530, 297, 2505, 534, 396, 358, 267, 291, 14, 751, 275, 2876, 14, 1462, 14, 362, 8, 2051, 29, 17, 9, 267, 291, 14, 1715, 14, 3707, 14, 525, 8, 277, 14, 751, 9, 339, 347, 636, 525, 63, 17341, 8, 277, 304, 267, 2963, 63, 576, 275, 469, 288, 298, 1715, 582, 291, 14, 1715, 14, 5464, 12, 288, 298, 1023, 582, 491, 619, 1719, 12, 288, 298, 1606, 582, 4873, 288, 298, 633, 582, 4873, 267, 789, 398, 1177, 275, 291, 14, 1258, 14, 1932, 8, 288, 3837, 360, 25799, 63, 525, 659, 288, 666, 29, 1001, 14, 4180, 8, 1932, 63, 576, 395, 288, 1564, 63, 466, 628, 3578, 15, 1001, 2, 267, 776, 398, 291, 14, 629, 8, 1310, 14, 1205, 63, 600, 12, 1784, 9, 267, 291, 14, 9535, 8, 1310, 12, 283, 3270, 297, 2004, 63, 600, 29, 1797, 9, 267, 372, 8944, 1657, 14, 1462, 14, 362, 8, 2051, 29, 17, 9, 339, 347, 511, 63, 525, 63, 17341, 63, 848, 1500, 63, 362, 63, 6615, 8, 277, 304, 267, 1177, 275, 291, 14, 1258, 14, 362, 8, 4471, 360, 25799, 63, 525, 1333, 267, 291, 14, 629, 8, 1310, 14, 1205, 63, 600, 12, 25766, 9, 267, 291, 14, 9535, 8, 1310, 12, 283, 705, 297, 2004, 63, 600, 29, 15770, 9, 339, 347, 511, 63, 525, 63, 17341, 8, 277, 304, 267, 23799, 275, 291, 855, 525, 63, 17341, 342, 267, 291, 14, 629, 8, 17341, 14, 751, 12, 291, 14, 751, 9, 267, 291, 14, 629, 8, 17341, 14, 1715, 14, 5464, 12, 291, 14, 1715, 14, 5464, 9, 267, 291, 14, 629, 8, 8696, 1657, 14, 1462, 14, 835, 1062, 413, 9, 339, 347, 511, 63, 525, 63, 17341, 63, 15762, 63, 4087, 63, 576, 8, 277, 304, 267, 2963, 63, 576, 275, 469, 288, 298, 1715, 582, 283, 1633, 297, 298, 1023, 582, 283, 1633, 297, 298, 1606, 582, 4873, 298, 633, 582, 3087, 267, 789, 267, 1177, 275, 291, 14, 1258, 14, 1932, 8, 288, 3837, 360, 25799, 63, 525, 659, 288, 666, 29, 1001, 14, 4180, 8, 1932, 63, 576, 395, 288, 1564, 63, 466, 628, 505, 15, 9554, 2, 267, 776, 398, 291, 14, 629, 8, 1310, 14, 1205, 63, 600, 12, 8290, 9, 267, 291, 14, 9535, 8, 1310, 12, 283, 705, 297, 2004, 63, 600, 29, 5303, 9, 339, 347, 511, 63, 1807, 63, 17341, 63, 1045, 63, 362, 63, 3352, 83, 63, 20903, 63, 1606, 8, 277, 304, 267, 291, 855, 525, 63, 17341, 342, 267, 1177, 275, 291, 14, 1258, 14, 362, 8, 288, 3837, 360, 17341, 63, 2168, 297, 2074, 3713, 17341, 63, 2051, 356, 283, 17, 3071, 267, 776, 398, 291, 14, 629, 8, 1310, 14, 1205, 63, 600, 12, 1926, 9, 267, 291, 14, 9535, 8, 1310, 12, 283, 5556, 3238, 31, 593, 63, 79, 358, 339, 347, 511, 63, 1807, 63, 17341, 63, 1045, 63, 633, 8, 277, 304, 267, 291, 855, 525, 63, 17341, 342, 267, 1177, 275, 291, 14, 1258, 14, 1932, 8, 288, 3837, 360, 17341, 63, 2168, 297, 2074, 3713, 17341, 63, 2051, 356, 283, 17, 3071, 267, 776, 267, 291, 14, 17466, 8, 1310, 12, 3837, 360, 17341, 63, 513, 1333, 267, 291, 14, 629, 8, 8696, 1657, 14, 1462, 14, 835, 1062, 378, 9, 339, 347, 511, 63, 1807, 63, 17341, 63, 1045, 63, 1001, 8, 277, 304, 267, 291, 855, 525, 63, 17341, 342, 398, 2963, 63, 576, 275, 469, 288, 298, 1715, 582, 291, 14, 1715, 14, 5464, 12, 288, 298, 1023, 582, 491, 619, 1719, 12, 288, 298, 1606, 582, 4873, 288, 298, 633, 582, 4873, 267, 789, 398, 1177, 275, 291, 14, 1258, 14, 1932, 8, 288, 3837, 360, 17341, 63, 2168, 63, 1001, 659, 288, 666, 29, 1001, 14, 4180, 8, 1932, 63, 576, 395, 288, 1564, 63, 466, 628, 3578, 15, 1001, 2, 267, 776, 398, 291, 14, 629, 8, 1310, 14, 1205, 63, 600, 12, 1926, 9, 267, 291, 14, 629, 8, 8696, 1657, 14, 1462, 14, 835, 1062, 378, 9, 339, 347, 511, 63, 18671, 63, 1807, 63, 25799, 63, 1045, 63, 4087, 63, 1001, 8, 277, 304, 267, 291, 855, 525, 63, 17341, 342, 267, 2963, 63, 576, 275, 2420, 4087, 2199, 582, 291, 14, 1715, 14, 5464, 93, 398, 1177, 275, 291, 14, 1258, 14, 1932, 8, 288, 3837, 360, 17341, 63, 2168, 63, 1001, 659, 288, 666, 29, 1001, 14, 4180, 8, 1932, 63, 576, 395, 288, 1564, 63, 466, 628, 3578, 15, 1001, 2, 267, 776, 267, 291, 14, 629, 8, 1310, 14, 1205, 63, 600, 12, 8290, 9, 267, 291, 14, 629, 8, 8696, 1657, 14, 1462, 14, 835, 1062, 413, 9, 267, 291, 14, 9535, 8, 1310, 12, 298, 3364, 2633, 401, 2004, 63, 600, 29, 5303, 9, 339, 347, 511, 63, 17341, 63, 2444, 63, 2052, 63, 6526, 63, 2444, 8, 277, 304, 267, 23799, 275, 291, 855, 525, 63, 17341, 342, 267, 2963, 63, 576, 275, 469, 288, 283, 1715, 356, 23799, 14, 1715, 14, 5464, 12, 288, 283, 1023, 356, 23799, 14, 1023, 14, 5464, 12, 288, 283, 1606, 356, 23799, 14, 1606, 267, 789, 398, 1177, 275, 291, 14, 1258, 14, 1932, 8, 288, 3837, 360, 17341, 63, 2444, 659, 288, 666, 29, 1001, 14, 4180, 8, 1932, 63, 576, 395, 288, 1564, 63, 466, 628, 3578, 15, 1001, 2, 267, 776, 398, 291, 14, 629, 8, 1310, 14, 1205, 63, 600, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
kosgroup/odoo
addons/lunch/models/lunch.py
10
13201
# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. import datetime from odoo import api, fields, models, _ from odoo.exceptions import AccessError, ValidationError import odoo.addons.decimal_precision as dp class LunchOrder(models.Model): """ A lunch order contains one or more lunch order line(s). It is associated to a user for a given date. When creating a lunch order, applicable lunch alerts are displayed. """ _name = 'lunch.order' _description = 'Lunch Order' _order = 'date desc' def _default_previous_order_ids(self): prev_order = self.env['lunch.order.line'].search([('user_id', '=', self.env.uid), ('product_id.active', '!=', False)], limit=20, order='id desc') # If we return return prev_order.ids, we will have duplicates (identical orders). # Therefore, this following part removes duplicates based on product_id and note. return { (order.product_id, order.note): order.id for order in prev_order }.values() user_id = fields.Many2one('res.users', 'User', readonly=True, states={'new': [('readonly', False)]}, default=lambda self: self.env.uid) date = fields.Date('Date', required=True, readonly=True, states={'new': [('readonly', False)]}, default=fields.Date.context_today) order_line_ids = fields.One2many('lunch.order.line', 'order_id', 'Products', readonly=True, copy=True, states={'new': [('readonly', False)], False: [('readonly', False)]}) total = fields.Float(compute='_compute_total', string="Total", store=True) state = fields.Selection([('new', 'New'), ('confirmed', 'Received'), ('cancelled', 'Cancelled')], 'Status', readonly=True, index=True, copy=False, compute='_compute_order_state', store=True) alerts = fields.Text(compute='_compute_alerts_get', string="Alerts") previous_order_ids = fields.Many2many('lunch.order.line', compute='_compute_previous_order_ids', default=lambda self: self._default_previous_order_ids()) company_id = fields.Many2one('res.company', related='user_id.company_id', store=True) currency_id = fields.Many2one('res.currency', related='company_id.currency_id', readonly=True, store=True) cash_move_balance = fields.Monetary(compute='_compute_cash_move_balance', multi='cash_move_balance') balance_visible = fields.Boolean(compute='_compute_cash_move_balance', multi='cash_move_balance') @api.one @api.depends('order_line_ids') def _compute_total(self): """ get and sum the order lines' price """ self.total = sum( orderline.price for orderline in self.order_line_ids) @api.multi def name_get(self): return [(order.id, '%s %s' % (_('Lunch Order'), '#%d' % order.id)) for order in self] @api.depends('state') def _compute_alerts_get(self): """ get the alerts to display on the order form """ alert_msg = [alert.message for alert in self.env['lunch.alert'].search([]) if alert.display] if self.state == 'new': self.alerts = alert_msg and '\n'.join(alert_msg) or False @api.depends('user_id') def _compute_previous_order_ids(self): self.previous_order_ids = self._default_previous_order_ids() @api.one @api.depends('user_id') def _compute_cash_move_balance(self): domain = [('user_id', '=', self.user_id.id)] lunch_cash = self.env['lunch.cashmove'].read_group(domain, ['amount', 'user_id'], ['user_id']) if len(lunch_cash): self.cash_move_balance = lunch_cash[0]['amount'] self.balance_visible = (self.user_id == self.env.user) or self.user_has_groups('lunch.group_lunch_manager') @api.one @api.constrains('date') def _check_date(self): """ Prevents the user to create an order in the past """ date_order = datetime.datetime.strptime(self.date, '%Y-%m-%d') date_today = datetime.datetime.strptime(fields.Date.context_today(self), '%Y-%m-%d') if (date_order < date_today): raise ValidationError(_('The date of your order is in the past.')) @api.one @api.depends('order_line_ids.state') def _compute_order_state(self): """ Update the state of lunch.order based on its orderlines. Here is the logic: - if at least one order line is cancelled, the order is set as cancelled - if no line is cancelled but at least one line is not confirmed, the order is set as new - if all lines are confirmed, the order is set as confirmed """ if not self.order_line_ids: self.state = 'new' else: isConfirmed = True for orderline in self.order_line_ids: if orderline.state == 'cancelled': self.state = 'cancelled' return elif orderline.state == 'confirmed': continue else: isConfirmed = False if isConfirmed: self.state = 'confirmed' else: self.state = 'new' return class LunchOrderLine(models.Model): _name = 'lunch.order.line' _description = 'lunch order line' name = fields.Char(related='product_id.name', string="Product Name", readonly=True) order_id = fields.Many2one('lunch.order', 'Order', ondelete='cascade', required=True) product_id = fields.Many2one('lunch.product', 'Product', required=True) category_id = fields.Many2one('lunch.product.category', string='Product Category', related='product_id.category_id', readonly=True, store=True) date = fields.Date(string='Date', related='order_id.date', readonly=True, store=True) supplier = fields.Many2one('res.partner', string='Vendor', related='product_id.supplier', readonly=True, store=True) user_id = fields.Many2one('res.users', string='User', related='order_id.user_id', readonly=True, store=True) note = fields.Text('Note') price = fields.Float(related='product_id.price', readonly=True, store=True, digits=dp.get_precision('Account')) state = fields.Selection([('new', 'New'), ('confirmed', 'Received'), ('ordered', 'Ordered'), ('cancelled', 'Cancelled')], 'Status', readonly=True, index=True, default='new') cashmove = fields.One2many('lunch.cashmove', 'order_id', 'Cash Move') currency_id = fields.Many2one('res.currency', related='order_id.currency_id') @api.one def order(self): """ The order_line is ordered to the vendor but isn't received yet """ if self.user_has_groups("lunch.group_lunch_manager"): self.state = 'ordered' else: raise AccessError(_("Only your lunch manager processes the orders.")) @api.one def confirm(self): """ confirm one or more order line, update order status and create new cashmove """ if self.user_has_groups("lunch.group_lunch_manager"): if self.state != 'confirmed': values = { 'user_id': self.user_id.id, 'amount': -self.price, 'description': self.product_id.name, 'order_id': self.id, 'state': 'order', 'date': self.date, } self.env['lunch.cashmove'].create(values) self.state = 'confirmed' else: raise AccessError(_("Only your lunch manager sets the orders as received.")) @api.one def cancel(self): """ cancel one or more order.line, update order status and unlink existing cashmoves """ if self.user_has_groups("lunch.group_lunch_manager"): self.state = 'cancelled' self.cashmove.unlink() else: raise AccessError(_("Only your lunch manager cancels the orders.")) class LunchProduct(models.Model): """ Products available to order. A product is linked to a specific vendor. """ _name = 'lunch.product' _description = 'lunch product' name = fields.Char('Product', required=True) category_id = fields.Many2one('lunch.product.category', 'Category', required=True) description = fields.Text('Description') price = fields.Float('Price', digits=dp.get_precision('Account')) supplier = fields.Many2one('res.partner', 'Vendor') active = fields.Boolean(default=True) class LunchProductCategory(models.Model): """ Category of the product such as pizza, sandwich, pasta, chinese, burger... """ _name = 'lunch.product.category' _description = 'lunch product category' name = fields.Char('Category', required=True) class LunchCashMove(models.Model): """ Two types of cashmoves: payment (credit) or order (debit) """ _name = 'lunch.cashmove' _description = 'lunch cashmove' user_id = fields.Many2one('res.users', 'User', default=lambda self: self.env.uid) date = fields.Date('Date', required=True, default=fields.Date.context_today) amount = fields.Float('Amount', required=True, help='Can be positive (payment) or negative (order or payment if user wants to get his money back)') description = fields.Text('Description', help='Can be an order or a payment') order_id = fields.Many2one('lunch.order.line', 'Order', ondelete='cascade') state = fields.Selection([('order', 'Order'), ('payment', 'Payment')], 'Is an order or a payment', default='payment') @api.multi def name_get(self): return [(cashmove.id, '%s %s' % (_('Lunch Cashmove'), '#%d' % cashmove.id)) for cashmove in self] class LunchAlert(models.Model): """ Alerts to display during a lunch order. An alert can be specific to a given day, weekly or daily. The alert is displayed from start to end hour. """ _name = 'lunch.alert' _description = 'Lunch Alert' display = fields.Boolean(compute='_compute_display_get') message = fields.Text('Message', required=True) alert_type = fields.Selection([('specific', 'Specific Day'), ('week', 'Every Week'), ('days', 'Every Day')], string='Recurrency', required=True, index=True, default='specific') specific_day = fields.Date('Day', default=fields.Date.context_today) monday = fields.Boolean('Monday') tuesday = fields.Boolean('Tuesday') wednesday = fields.Boolean('Wednesday') thursday = fields.Boolean('Thursday') friday = fields.Boolean('Friday') saturday = fields.Boolean('Saturday') sunday = fields.Boolean('Sunday') start_hour = fields.Float('Between', oldname='active_from', required=True, default=7) end_hour = fields.Float('And', oldname='active_to', required=True, default=23) active = fields.Boolean(default=True) @api.multi def name_get(self): return [(alert.id, '%s %s' % (_('Alert'), '#%d' % alert.id)) for alert in self] @api.one def _compute_display_get(self): """ This method check if the alert can be displayed today if alert type is specific : compare specific_day(date) with today's date if alert type is week : check today is set as alert (checkbox true) eg. self['monday'] if alert type is day : True return : Message if can_display_alert is True else False """ days_codes = {'0': 'sunday', '1': 'monday', '2': 'tuesday', '3': 'wednesday', '4': 'thursday', '5': 'friday', '6': 'saturday'} can_display_alert = { 'specific': (self.specific_day == fields.Date.context_today(self)), 'week': self[days_codes[datetime.datetime.now().strftime('%w')]], 'days': True } if can_display_alert[self.alert_type]: mynow = fields.Datetime.context_timestamp(self, datetime.datetime.now()) hour_to = int(self.end_hour) min_to = int((self.end_hour - hour_to) * 60) to_alert = datetime.time(hour_to, min_to) hour_from = int(self.start_hour) min_from = int((self.start_hour - hour_from) * 60) from_alert = datetime.time(hour_from, min_from) if from_alert <= mynow.time() <= to_alert: self.display = True else: self.display = False
gpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 14320, 402, 28935, 14, 1666, 5113, 570, 367, 2615, 4248, 436, 32572, 2436, 14, 199, 199, 646, 2197, 199, 199, 504, 28811, 492, 2986, 12, 1504, 12, 1709, 12, 485, 199, 504, 28811, 14, 3924, 492, 11003, 547, 12, 8505, 199, 646, 28811, 14, 10788, 14, 6355, 63, 6833, 465, 12392, 421, 199, 533, 491, 4689, 4738, 8, 992, 14, 1685, 304, 272, 408, 272, 437, 634, 4689, 1865, 3509, 1373, 503, 1655, 634, 4689, 1865, 1004, 8, 83, 680, 2779, 365, 4568, 370, 282, 922, 367, 282, 1627, 272, 1434, 14, 3979, 6425, 282, 634, 4689, 1865, 12, 3964, 634, 4689, 31529, 787, 9080, 14, 272, 408, 272, 485, 354, 275, 283, 76, 4689, 14, 1648, 7, 272, 485, 1802, 275, 283, 44, 4689, 9240, 7, 272, 485, 1648, 275, 283, 602, 4328, 7, 339, 347, 485, 885, 63, 6352, 63, 1648, 63, 1580, 8, 277, 304, 267, 5071, 63, 1648, 275, 291, 14, 1813, 459, 76, 4689, 14, 1648, 14, 604, 2278, 1733, 8318, 751, 63, 344, 297, 6291, 291, 14, 1813, 14, 1535, 395, 661, 2558, 63, 344, 14, 2682, 297, 31326, 756, 4360, 2304, 29, 1165, 12, 1865, 534, 344, 4328, 358, 267, 327, 982, 781, 372, 372, 5071, 63, 1648, 14, 1580, 12, 781, 911, 1172, 15755, 334, 14576, 15460, 680, 267, 327, 21039, 12, 642, 2569, 1777, 14185, 15755, 4079, 641, 3336, 63, 344, 436, 5317, 14, 267, 372, 469, 288, 334, 1648, 14, 2558, 63, 344, 12, 1865, 14, 4610, 304, 1865, 14, 344, 288, 367, 1865, 315, 5071, 63, 1648, 267, 789, 14, 1459, 342, 339, 922, 63, 344, 275, 1504, 14, 4089, 18, 368, 360, 470, 14, 3707, 297, 283, 1899, 297, 6863, 29, 549, 12, 2892, 6363, 3713, 1222, 356, 4274, 6753, 297, 756, 26804, 2892, 849, 29, 2734, 291, 26, 291, 14, 1813, 14, 1535, 9, 272, 1434, 275, 1504, 14, 2506, 360, 2506, 297, 1415, 29, 549, 12, 6863, 29, 549, 12, 2432, 6363, 3713, 1222, 356, 4274, 6753, 297, 756, 26804, 2432, 849, 29, 955, 14, 2506, 14, 1100, 63, 8136, 9, 272, 1865, 63, 604, 63, 1580, 275, 1504, 14, 4395, 18, 3479, 360, 76, 4689, 14, 1648, 14, 604, 297, 283, 1648, 63, 344, 297, 283, 29631, 297, 3660, 6863, 29, 549, 12, 1331, 29, 549, 12, 3660, 6363, 3713, 1222, 356, 4274, 6753, 297, 756, 4360, 756, 26, 4274, 6753, 297, 756, 1874, 1552, 272, 3141, 275, 1504, 14, 5136, 8, 3357, 17574, 3357, 63, 2923, 297, 1059, 628, 7316, 401, 3877, 29, 549, 9, 272, 1174, 275, 1504, 14, 7713, 8318, 1222, 297, 283, 4665, 659, 2892, 661, 16391, 297, 283, 9392, 659, 2892, 661, 21924, 297, 283, 22127, 2665, 2490, 283, 3694, 297, 6863, 29, 549, 12, 1478, 29, 549, 12, 1331, 29, 797, 12, 2490, 4526, 17574, 3357, 63, 1648, 63, 929, 297, 3877, 29, 549, 9, 272, 31529, 275, 1504, 14, 1872, 8, 3357, 17574, 3357, 63, 24501, 63, 362, 297, 1059, 628, 33, 16676, 531, 272, 4136, 63, 1648, 63, 1580, 275, 1504, 14, 4089, 18, 3479, 360, 76, 4689, 14, 1648, 14, 604, 297, 4526, 17574, 3357, 63, 6352, 63, 1648, 63, 1580, 297, 5101, 849, 29, 2734, 291, 26, 291, 423, 885, 63, 6352, 63, 1648, 63, 1580, 1012, 272, 7233, 63, 344, 275, 1504, 14, 4089, 18, 368, 360, 470, 14, 4627, 297, 4048, 534, 751, 63, 344, 14, 4627, 63, 344, 297, 3877, 29, 549, 9, 272, 9952, 63, 344, 275, 1504, 14, 4089, 18, 368, 360, 470, 14, 4968, 297, 4048, 534, 4627, 63, 344, 14, 4968, 63, 344, 297, 6863, 29, 549, 12, 3877, 29, 549, 9, 272, 286, 1119, 63, 1185, 63, 7358, 275, 1504, 14, 45, 25759, 695, 8, 3357, 17574, 3357, 63, 20084, 63, 1185, 63, 7358, 297, 3510, 534, 20084, 63, 1185, 63, 7358, 358, 272, 14094, 63, 6604, 275, 1504, 14, 4082, 8, 3357, 17574, 3357, 63, 20084, 63, 1185, 63, 7358, 297, 3510, 534, 20084, 63, 1185, 63, 7358, 358, 339, 768, 1246, 14, 368, 272, 768, 1246, 14, 8912, 360, 1648, 63, 604, 63, 1580, 358, 272, 347, 485, 3357, 63, 2923, 8, 277, 304, 267, 408, 267, 664, 436, 3089, 314, 1865, 2385, 7, 8033, 267, 408, 267, 291, 14, 2923, 275, 3089, 8, 288, 1865, 604, 14, 4777, 367, 1865, 604, 315, 291, 14, 1648, 63, 604, 63, 1580, 9, 339, 768, 1246, 14, 3029, 272, 347, 536, 63, 362, 8, 277, 304, 267, 372, 3842, 1648, 14, 344, 12, 1543, 83, 450, 83, 7, 450, 21790, 44, 4689, 9240, 659, 3943, 5, 68, 7, 450, 1865, 14, 344, 430, 367, 1865, 315, 291, 61, 339, 768, 1246, 14, 8912, 360, 929, 358, 272, 347, 485, 3357, 63, 24501, 63, 362, 8, 277, 304, 267, 408, 267, 664, 314, 31529, 370, 2929, 641, 314, 1865, 1824, 267, 408, 267, 10459, 63, 1328, 275, 359, 9241, 14, 1188, 2151, 367, 10459, 315, 291, 14, 1813, 459, 76, 4689, 14, 9241, 2278, 1733, 4157, 2151, 340, 10459, 14, 2918, 61, 398, 340, 291, 14, 929, 508, 283, 1222, 356, 288, 291, 14, 24501, 275, 10459, 63, 1328, 436, 1557, 78, 1370, 904, 8, 9241, 63, 1328, 9, 503, 756, 339, 768, 1246, 14, 8912, 360, 751, 63, 344, 358, 272, 347, 485, 3357, 63, 6352, 63, 1648, 63, 1580, 8, 277, 304, 267, 291, 14, 6352, 63, 1648, 63, 1580, 275, 291, 423, 885, 63, 6352, 63, 1648, 63, 1580, 342, 339, 768, 1246, 14, 368, 272, 768, 1246, 14, 8912, 360, 751, 63, 344, 358, 272, 347, 485, 3357, 63, 20084, 63, 1185, 63, 7358, 8, 277, 304, 267, 2881, 275, 4274, 751, 63, 344, 297, 6291, 291, 14, 751, 63, 344, 14, 344, 1874, 267, 634, 4689, 63, 20084, 275, 291, 14, 1813, 459, 76, 4689, 14, 20084, 1185, 2278, 739, 63, 923, 8, 2261, 12, 788, 4606, 297, 283, 751, 63, 344, 995, 788, 751, 63, 344, 1105, 267, 340, 822, 8, 76, 4689, 63, 20084, 304, 288, 291, 14, 20084, 63, 1185, 63, 7358, 275, 634, 4689, 63, 20084, 59, 16, 2733, 4606, 418, 267, 291 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 14320, 402, 28935, 14, 1666, 5113, 570, 367, 2615, 4248, 436, 32572, 2436, 14, 199, 199, 646, 2197, 199, 199, 504, 28811, 492, 2986, 12, 1504, 12, 1709, 12, 485, 199, 504, 28811, 14, 3924, 492, 11003, 547, 12, 8505, 199, 646, 28811, 14, 10788, 14, 6355, 63, 6833, 465, 12392, 421, 199, 533, 491, 4689, 4738, 8, 992, 14, 1685, 304, 272, 408, 272, 437, 634, 4689, 1865, 3509, 1373, 503, 1655, 634, 4689, 1865, 1004, 8, 83, 680, 2779, 365, 4568, 370, 282, 922, 367, 282, 1627, 272, 1434, 14, 3979, 6425, 282, 634, 4689, 1865, 12, 3964, 634, 4689, 31529, 787, 9080, 14, 272, 408, 272, 485, 354, 275, 283, 76, 4689, 14, 1648, 7, 272, 485, 1802, 275, 283, 44, 4689, 9240, 7, 272, 485, 1648, 275, 283, 602, 4328, 7, 339, 347, 485, 885, 63, 6352, 63, 1648, 63, 1580, 8, 277, 304, 267, 5071, 63, 1648, 275, 291, 14, 1813, 459, 76, 4689, 14, 1648, 14, 604, 2278, 1733, 8318, 751, 63, 344, 297, 6291, 291, 14, 1813, 14, 1535, 395, 661, 2558, 63, 344, 14, 2682, 297, 31326, 756, 4360, 2304, 29, 1165, 12, 1865, 534, 344, 4328, 358, 267, 327, 982, 781, 372, 372, 5071, 63, 1648, 14, 1580, 12, 781, 911, 1172, 15755, 334, 14576, 15460, 680, 267, 327, 21039, 12, 642, 2569, 1777, 14185, 15755, 4079, 641, 3336, 63, 344, 436, 5317, 14, 267, 372, 469, 288, 334, 1648, 14, 2558, 63, 344, 12, 1865, 14, 4610, 304, 1865, 14, 344, 288, 367, 1865, 315, 5071, 63, 1648, 267, 789, 14, 1459, 342, 339, 922, 63, 344, 275, 1504, 14, 4089, 18, 368, 360, 470, 14, 3707, 297, 283, 1899, 297, 6863, 29, 549, 12, 2892, 6363, 3713, 1222, 356, 4274, 6753, 297, 756, 26804, 2892, 849, 29, 2734, 291, 26, 291, 14, 1813, 14, 1535, 9, 272, 1434, 275, 1504, 14, 2506, 360, 2506, 297, 1415, 29, 549, 12, 6863, 29, 549, 12, 2432, 6363, 3713, 1222, 356, 4274, 6753, 297, 756, 26804, 2432, 849, 29, 955, 14, 2506, 14, 1100, 63, 8136, 9, 272, 1865, 63, 604, 63, 1580, 275, 1504, 14, 4395, 18, 3479, 360, 76, 4689, 14, 1648, 14, 604, 297, 283, 1648, 63, 344, 297, 283, 29631, 297, 3660, 6863, 29, 549, 12, 1331, 29, 549, 12, 3660, 6363, 3713, 1222, 356, 4274, 6753, 297, 756, 4360, 756, 26, 4274, 6753, 297, 756, 1874, 1552, 272, 3141, 275, 1504, 14, 5136, 8, 3357, 17574, 3357, 63, 2923, 297, 1059, 628, 7316, 401, 3877, 29, 549, 9, 272, 1174, 275, 1504, 14, 7713, 8318, 1222, 297, 283, 4665, 659, 2892, 661, 16391, 297, 283, 9392, 659, 2892, 661, 21924, 297, 283, 22127, 2665, 2490, 283, 3694, 297, 6863, 29, 549, 12, 1478, 29, 549, 12, 1331, 29, 797, 12, 2490, 4526, 17574, 3357, 63, 1648, 63, 929, 297, 3877, 29, 549, 9, 272, 31529, 275, 1504, 14, 1872, 8, 3357, 17574, 3357, 63, 24501, 63, 362, 297, 1059, 628, 33, 16676, 531, 272, 4136, 63, 1648, 63, 1580, 275, 1504, 14, 4089, 18, 3479, 360, 76, 4689, 14, 1648, 14, 604, 297, 4526, 17574, 3357, 63, 6352, 63, 1648, 63, 1580, 297, 5101, 849, 29, 2734, 291, 26, 291, 423, 885, 63, 6352, 63, 1648, 63, 1580, 1012, 272, 7233, 63, 344, 275, 1504, 14, 4089, 18, 368, 360, 470, 14, 4627, 297, 4048, 534, 751, 63, 344, 14, 4627, 63, 344, 297, 3877, 29, 549, 9, 272, 9952, 63, 344, 275, 1504, 14, 4089, 18, 368, 360, 470, 14, 4968, 297, 4048, 534, 4627, 63, 344, 14, 4968, 63, 344, 297, 6863, 29, 549, 12, 3877, 29, 549, 9, 272, 286, 1119, 63, 1185, 63, 7358, 275, 1504, 14, 45, 25759, 695, 8, 3357, 17574, 3357, 63, 20084, 63, 1185, 63, 7358, 297, 3510, 534, 20084, 63, 1185, 63, 7358, 358, 272, 14094, 63, 6604, 275, 1504, 14, 4082, 8, 3357, 17574, 3357, 63, 20084, 63, 1185, 63, 7358, 297, 3510, 534, 20084, 63, 1185, 63, 7358, 358, 339, 768, 1246, 14, 368, 272, 768, 1246, 14, 8912, 360, 1648, 63, 604, 63, 1580, 358, 272, 347, 485, 3357, 63, 2923, 8, 277, 304, 267, 408, 267, 664, 436, 3089, 314, 1865, 2385, 7, 8033, 267, 408, 267, 291, 14, 2923, 275, 3089, 8, 288, 1865, 604, 14, 4777, 367, 1865, 604, 315, 291, 14, 1648, 63, 604, 63, 1580, 9, 339, 768, 1246, 14, 3029, 272, 347, 536, 63, 362, 8, 277, 304, 267, 372, 3842, 1648, 14, 344, 12, 1543, 83, 450, 83, 7, 450, 21790, 44, 4689, 9240, 659, 3943, 5, 68, 7, 450, 1865, 14, 344, 430, 367, 1865, 315, 291, 61, 339, 768, 1246, 14, 8912, 360, 929, 358, 272, 347, 485, 3357, 63, 24501, 63, 362, 8, 277, 304, 267, 408, 267, 664, 314, 31529, 370, 2929, 641, 314, 1865, 1824, 267, 408, 267, 10459, 63, 1328, 275, 359, 9241, 14, 1188, 2151, 367, 10459, 315, 291, 14, 1813, 459, 76, 4689, 14, 9241, 2278, 1733, 4157, 2151, 340, 10459, 14, 2918, 61, 398, 340, 291, 14, 929, 508, 283, 1222, 356, 288, 291, 14, 24501, 275, 10459, 63, 1328, 436, 1557, 78, 1370, 904, 8, 9241, 63, 1328, 9, 503, 756, 339, 768, 1246, 14, 8912, 360, 751, 63, 344, 358, 272, 347, 485, 3357, 63, 6352, 63, 1648, 63, 1580, 8, 277, 304, 267, 291, 14, 6352, 63, 1648, 63, 1580, 275, 291, 423, 885, 63, 6352, 63, 1648, 63, 1580, 342, 339, 768, 1246, 14, 368, 272, 768, 1246, 14, 8912, 360, 751, 63, 344, 358, 272, 347, 485, 3357, 63, 20084, 63, 1185, 63, 7358, 8, 277, 304, 267, 2881, 275, 4274, 751, 63, 344, 297, 6291, 291, 14, 751, 63, 344, 14, 344, 1874, 267, 634, 4689, 63, 20084, 275, 291, 14, 1813, 459, 76, 4689, 14, 20084, 1185, 2278, 739, 63, 923, 8, 2261, 12, 788, 4606, 297, 283, 751, 63, 344, 995, 788, 751, 63, 344, 1105, 267, 340, 822, 8, 76, 4689, 63, 20084, 304, 288, 291, 14, 20084, 63, 1185, 63, 7358, 275, 634, 4689, 63, 20084, 59, 16, 2733, 4606, 418, 267, 291, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
OnroerendErfgoed/skosprovider_heritagedata
skosprovider_heritagedata/utils.py
1
5488
# -*- coding: utf-8 -*- ''' Utility functions for :mod:`skosprovider_heritagedata`. ''' import requests from skosprovider.skos import ( Concept, Label, Note, ConceptScheme) from skosprovider.exceptions import ProviderUnavailableException import logging import sys import requests log = logging.getLogger(__name__) PY3 = sys.version_info[0] == 3 if PY3: # pragma: no cover binary_type = bytes else: # pragma: no cover binary_type = str import rdflib from rdflib.term import URIRef from rdflib.namespace import RDF, SKOS, DC, DCTERMS, RDFS PROV = rdflib.Namespace('http://www.w3.org/ns/prov#') def conceptscheme_from_uri(conceptscheme_uri, **kwargs): ''' Read a SKOS Conceptscheme from a :term:`URI` :param string conceptscheme_uri: URI of the conceptscheme. :rtype: skosprovider.skos.ConceptScheme ''' s = kwargs.get('session', requests.Session()) graph = uri_to_graph('%s.rdf' % (conceptscheme_uri), session=s) notes = [] labels = [] if graph is not False: for s, p, o in graph.triples((URIRef(conceptscheme_uri), RDFS.label, None)): label = Label(o.toPython(), "prefLabel", 'en') labels.append(label) for s, p, o in graph.triples((URIRef(conceptscheme_uri), DCTERMS.description, None)): note = Note(o.toPython(), "scopeNote", 'en') notes.append(note) # get the conceptscheme conceptscheme = ConceptScheme( conceptscheme_uri, labels=labels, notes=notes ) return conceptscheme def things_from_graph(graph, concept_scheme): ''' Read concepts and collections from a graph. :param rdflib.Graph graph: Graph to read from. :param skosprovider.skos.ConceptScheme concept_scheme: Conceptscheme the concepts and collections belong to. :rtype: :class:`list` ''' clist = [] for sub, pred, obj in graph.triples((None, RDF.type, SKOS.Concept)): uri = str(sub) con = Concept( id=_split_uri(uri, 1), uri=uri, concept_scheme = concept_scheme, labels = _create_from_subject_typelist(graph, sub, Label.valid_types), notes = _create_from_subject_typelist(graph, sub, Note.valid_types), broader = _create_from_subject_predicate(graph, sub, SKOS.broader), narrower = _create_from_subject_predicate(graph, sub, SKOS.narrower), related = _create_from_subject_predicate(graph, sub, SKOS.related), subordinate_arrays = [] ) clist.append(con) # at this moment, Heritagedata does not support SKOS.Collection # for sub, pred, obj in graph.triples((None, RDF.type, SKOS.Collection)): # uri = str(sub) # col = Collection(_split_uri(uri, 1), uri=uri) # col.members = _create_from_subject_predicate(sub, SKOS.member) # col.labels = _create_from_subject_typelist(sub, Label.valid_types) # col.notes = _create_from_subject_typelist(sub, Note.valid_types) # clist.append(col) return clist def _create_from_subject_typelist(graph, subject, typelist): list = [] for p in typelist: term = SKOS.term(p) list.extend(_create_from_subject_predicate(graph, subject, term)) return list def _create_from_subject_predicate(graph, subject, predicate): list = [] for s, p, o in graph.triples((subject, predicate, None)): type = predicate.split('#')[-1] if Label.is_valid_type(type): o = _create_label(o, type) elif Note.is_valid_type(type): o = _create_note(o, type) else: o = _split_uri(o, 1) if o: list.append(o) return list def _create_label(literal, type): language = literal.language if language is None: return 'und' # return undefined code when no language return Label(literal.toPython(), type, language) def _create_note(literal, type): if not Note.is_valid_type(type): raise ValueError('Type of Note is not valid.') return Note(text_(literal.value, encoding="utf-8"), type, _get_language_from_literal(literal)) def _get_language_from_literal(data): if data.language is None: return 'und' # return undefined code when no language return text_(data.language, encoding="utf-8") def _split_uri(uri, index): return uri.strip('/').rsplit('/', 1)[index] def uri_to_graph(uri, **kwargs): ''' :param string uri: :term:`URI` where the RDF data can be found. :rtype: rdflib.Graph :raises skosprovider.exceptions.ProviderUnavailableException: if the heritagedata.org services are down ''' s = kwargs.get('session', requests.Session()) graph = rdflib.Graph() try: res = s.get(uri) except requests.ConnectionError as e: raise ProviderUnavailableException("URI not available: %s" % uri) if res.status_code == 404: return False graph.parse(data=res.content) #heritagedata.org returns a empy page/graph when a resource does not exists (statsu_code 200). For this reason we return False if the graph is empty if len(graph) == 0: return False return graph def text_(s, encoding='latin-1', errors='strict'): """ If ``s`` is an instance of ``binary_type``, return ``s.decode(encoding, errors)``, otherwise return ``s``""" if isinstance(s, binary_type): return s.decode(encoding, errors) return s
mit
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 2344, 199, 17505, 3423, 367, 520, 1494, 1705, 1339, 736, 3780, 63, 4459, 474, 576, 2313, 199, 2344, 199, 199, 646, 4145, 199, 504, 2386, 736, 3780, 14, 1339, 736, 492, 334, 272, 1448, 716, 12, 272, 10354, 12, 272, 3390, 12, 272, 1448, 716, 19530, 9, 199, 504, 2386, 736, 3780, 14, 3924, 492, 18489, 28049, 1726, 199, 199, 646, 2050, 199, 646, 984, 199, 646, 4145, 199, 199, 793, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 4521, 19, 275, 984, 14, 1023, 63, 815, 59, 16, 61, 508, 650, 199, 199, 692, 7843, 19, 26, 221, 327, 11942, 26, 949, 8486, 272, 3366, 63, 466, 275, 2783, 199, 2836, 26, 221, 327, 11942, 26, 949, 8486, 272, 3366, 63, 466, 275, 620, 199, 199, 646, 18148, 773, 199, 504, 18148, 773, 14, 5125, 492, 9022, 2891, 199, 504, 18148, 773, 14, 3251, 492, 820, 3888, 12, 20062, 3100, 12, 30592, 12, 577, 1028, 540, 3053, 12, 820, 3888, 51, 199, 199, 2514, 54, 275, 18148, 773, 14, 8814, 360, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 561, 15, 20397, 3, 358, 199, 199, 318, 19834, 5512, 63, 504, 63, 2302, 8, 21318, 5512, 63, 2302, 12, 1011, 958, 304, 272, 1449, 272, 5574, 282, 20062, 3100, 1448, 716, 5512, 687, 282, 520, 5125, 1705, 7639, 64, 339, 520, 635, 1059, 19834, 5512, 63, 2302, 26, 9022, 402, 314, 19834, 5512, 14, 272, 520, 4500, 26, 2386, 736, 3780, 14, 1339, 736, 14, 32209, 19530, 272, 1449, 272, 308, 275, 2074, 14, 362, 360, 1730, 297, 4145, 14, 4434, 1012, 272, 3343, 275, 5108, 63, 475, 63, 2180, 3508, 83, 14, 17120, 7, 450, 334, 21318, 5512, 63, 2302, 395, 2351, 29, 83, 9, 339, 12681, 275, 942, 272, 3628, 275, 942, 339, 340, 3343, 365, 440, 756, 26, 267, 367, 308, 12, 299, 12, 312, 315, 3343, 14, 7254, 2978, 1332, 7639, 2891, 8, 21318, 5512, 63, 2302, 395, 820, 3888, 51, 14, 1302, 12, 488, 2298, 288, 1768, 275, 10354, 8, 79, 14, 475, 4718, 1062, 298, 13829, 4314, 401, 283, 287, 358, 288, 3628, 14, 740, 8, 1302, 9, 267, 367, 308, 12, 299, 12, 312, 315, 3343, 14, 7254, 2978, 1332, 7639, 2891, 8, 21318, 5512, 63, 2302, 395, 577, 1028, 540, 3053, 14, 1802, 12, 488, 2298, 288, 5317, 275, 3390, 8, 79, 14, 475, 4718, 1062, 298, 2645, 7443, 401, 283, 287, 358, 288, 12681, 14, 740, 8, 4610, 9, 339, 327, 664, 314, 19834, 5512, 272, 19834, 5512, 275, 1448, 716, 19530, 8, 267, 19834, 5512, 63, 2302, 12, 267, 3628, 29, 3512, 12, 267, 12681, 29, 5983, 272, 776, 272, 372, 19834, 5512, 421, 199, 318, 7645, 63, 504, 63, 2180, 8, 2180, 12, 19834, 63, 5512, 304, 272, 1449, 272, 5574, 19834, 83, 436, 5055, 687, 282, 3343, 14, 339, 520, 635, 18148, 773, 14, 4578, 3343, 26, 11513, 370, 1586, 687, 14, 272, 520, 635, 2386, 736, 3780, 14, 1339, 736, 14, 32209, 19530, 19834, 63, 5512, 26, 1448, 716, 5512, 314, 267, 19834, 83, 436, 5055, 13511, 370, 14, 272, 520, 4500, 26, 520, 533, 1705, 513, 64, 272, 1449, 272, 286, 513, 275, 942, 272, 367, 1007, 12, 8869, 12, 1559, 315, 3343, 14, 7254, 2978, 1332, 403, 12, 820, 3888, 14, 466, 12, 20062, 3100, 14, 32209, 2298, 267, 5108, 275, 620, 8, 954, 9, 267, 406, 275, 1448, 716, 8, 288, 1305, 3699, 1294, 63, 2302, 8, 2302, 12, 413, 395, 288, 5108, 29, 2302, 12, 288, 19834, 63, 5512, 275, 19834, 63, 5512, 12, 288, 3628, 275, 485, 981, 63, 504, 63, 5875, 63, 466, 513, 8, 2180, 12, 1007, 12, 10354, 14, 1078, 63, 1313, 395, 288, 12681, 275, 485, 981, 63, 504, 63, 5875, 63, 466, 513, 8, 2180, 12, 1007, 12, 3390, 14, 1078, 63, 1313, 395, 288, 330, 293, 669, 275, 485, 981, 63, 504, 63, 5875, 63, 14463, 8, 2180, 12, 1007, 12, 20062, 3100, 14, 20670, 669, 395, 288, 31530, 281, 275, 485, 981, 63, 504, 63, 5875, 63, 14463, 8, 2180, 12, 1007, 12, 20062, 3100, 14, 15485, 281, 395, 288, 4048, 275, 485, 981, 63, 504, 63, 5875, 63, 14463, 8, 2180, 12, 1007, 12, 20062, 3100, 14, 2407, 395, 288, 1007, 4055, 323, 63, 10095, 275, 942, 267, 776, 267, 286, 513, 14, 740, 8, 388, 9, 398, 327, 737, 642, 12427, 12, 18769, 390, 474, 576, 1630, 440, 2291, 20062, 3100, 14, 7768, 272, 327, 367, 1007, 12, 8869, 12, 1559, 315, 3343, 14, 7254, 2978, 1332, 403, 12, 820, 3888, 14, 466, 12, 20062, 3100, 14, 7768, 2298, 272, 327, 5108, 275, 620, 8, 954, 9, 272, 327, 258, 1048, 275, 18003, 1547, 1294, 63, 2302, 8, 2302, 12, 413, 395, 5108, 29, 2302, 9, 272, 327, 258, 1048, 14, 6334, 275, 485, 981, 63, 504, 63, 5875, 63, 14463, 8, 954, 12, 20062, 3100, 14, 1114, 9, 272, 327, 258, 1048, 14, 3512, 275, 485, 981, 63, 504, 63, 5875, 63, 466, 513, 8, 954, 12, 10354, 14, 1078, 63, 1313, 9, 272, 327, 258, 1048, 14, 5983, 275, 485, 981, 63, 504, 63, 5875, 63, 466, 513, 8, 954, 12, 3390, 14, 1078, 63, 1313, 9, 272, 327, 258, 286, 513, 14, 740, 8, 761, 9, 339, 372, 286, 513, 421, 199, 318, 485, 981, 63, 504, 63, 5875, 63, 466, 513, 8, 2180, 12, 5420, 12, 730, 513, 304, 272, 769, 275, 942, 272, 367, 299, 315, 730, 513, 26, 267, 6707, 275, 20062, 3100, 14, 5125, 8, 80, 9, 267, 769, 14, 2880, 1547, 981, 63, 504, 63, 5875, 63, 14463, 8, 2180, 12, 5420, 12, 6707, 430, 272, 372, 769, 421, 199, 318, 485, 981, 63, 504, 63, 5875, 63, 14463, 8, 2180, 12, 5420, 12, 11944, 304, 272, 769, 275, 942, 272, 367, 308, 12, 299, 12, 312, 315, 3343, 14, 7254, 2978, 1332, 5875, 12, 11944, 12, 488, 2298, 267, 730, 275, 11944, 14, 1294, 7863, 358, 1988, 17, 61, 267, 340, 10354, 14, 374, 63, 1078, 63, 466, 8, 466, 304, 288, 312, 275, 485, 981 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 2344, 199, 17505, 3423, 367, 520, 1494, 1705, 1339, 736, 3780, 63, 4459, 474, 576, 2313, 199, 2344, 199, 199, 646, 4145, 199, 504, 2386, 736, 3780, 14, 1339, 736, 492, 334, 272, 1448, 716, 12, 272, 10354, 12, 272, 3390, 12, 272, 1448, 716, 19530, 9, 199, 504, 2386, 736, 3780, 14, 3924, 492, 18489, 28049, 1726, 199, 199, 646, 2050, 199, 646, 984, 199, 646, 4145, 199, 199, 793, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 4521, 19, 275, 984, 14, 1023, 63, 815, 59, 16, 61, 508, 650, 199, 199, 692, 7843, 19, 26, 221, 327, 11942, 26, 949, 8486, 272, 3366, 63, 466, 275, 2783, 199, 2836, 26, 221, 327, 11942, 26, 949, 8486, 272, 3366, 63, 466, 275, 620, 199, 199, 646, 18148, 773, 199, 504, 18148, 773, 14, 5125, 492, 9022, 2891, 199, 504, 18148, 773, 14, 3251, 492, 820, 3888, 12, 20062, 3100, 12, 30592, 12, 577, 1028, 540, 3053, 12, 820, 3888, 51, 199, 199, 2514, 54, 275, 18148, 773, 14, 8814, 360, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 561, 15, 20397, 3, 358, 199, 199, 318, 19834, 5512, 63, 504, 63, 2302, 8, 21318, 5512, 63, 2302, 12, 1011, 958, 304, 272, 1449, 272, 5574, 282, 20062, 3100, 1448, 716, 5512, 687, 282, 520, 5125, 1705, 7639, 64, 339, 520, 635, 1059, 19834, 5512, 63, 2302, 26, 9022, 402, 314, 19834, 5512, 14, 272, 520, 4500, 26, 2386, 736, 3780, 14, 1339, 736, 14, 32209, 19530, 272, 1449, 272, 308, 275, 2074, 14, 362, 360, 1730, 297, 4145, 14, 4434, 1012, 272, 3343, 275, 5108, 63, 475, 63, 2180, 3508, 83, 14, 17120, 7, 450, 334, 21318, 5512, 63, 2302, 395, 2351, 29, 83, 9, 339, 12681, 275, 942, 272, 3628, 275, 942, 339, 340, 3343, 365, 440, 756, 26, 267, 367, 308, 12, 299, 12, 312, 315, 3343, 14, 7254, 2978, 1332, 7639, 2891, 8, 21318, 5512, 63, 2302, 395, 820, 3888, 51, 14, 1302, 12, 488, 2298, 288, 1768, 275, 10354, 8, 79, 14, 475, 4718, 1062, 298, 13829, 4314, 401, 283, 287, 358, 288, 3628, 14, 740, 8, 1302, 9, 267, 367, 308, 12, 299, 12, 312, 315, 3343, 14, 7254, 2978, 1332, 7639, 2891, 8, 21318, 5512, 63, 2302, 395, 577, 1028, 540, 3053, 14, 1802, 12, 488, 2298, 288, 5317, 275, 3390, 8, 79, 14, 475, 4718, 1062, 298, 2645, 7443, 401, 283, 287, 358, 288, 12681, 14, 740, 8, 4610, 9, 339, 327, 664, 314, 19834, 5512, 272, 19834, 5512, 275, 1448, 716, 19530, 8, 267, 19834, 5512, 63, 2302, 12, 267, 3628, 29, 3512, 12, 267, 12681, 29, 5983, 272, 776, 272, 372, 19834, 5512, 421, 199, 318, 7645, 63, 504, 63, 2180, 8, 2180, 12, 19834, 63, 5512, 304, 272, 1449, 272, 5574, 19834, 83, 436, 5055, 687, 282, 3343, 14, 339, 520, 635, 18148, 773, 14, 4578, 3343, 26, 11513, 370, 1586, 687, 14, 272, 520, 635, 2386, 736, 3780, 14, 1339, 736, 14, 32209, 19530, 19834, 63, 5512, 26, 1448, 716, 5512, 314, 267, 19834, 83, 436, 5055, 13511, 370, 14, 272, 520, 4500, 26, 520, 533, 1705, 513, 64, 272, 1449, 272, 286, 513, 275, 942, 272, 367, 1007, 12, 8869, 12, 1559, 315, 3343, 14, 7254, 2978, 1332, 403, 12, 820, 3888, 14, 466, 12, 20062, 3100, 14, 32209, 2298, 267, 5108, 275, 620, 8, 954, 9, 267, 406, 275, 1448, 716, 8, 288, 1305, 3699, 1294, 63, 2302, 8, 2302, 12, 413, 395, 288, 5108, 29, 2302, 12, 288, 19834, 63, 5512, 275, 19834, 63, 5512, 12, 288, 3628, 275, 485, 981, 63, 504, 63, 5875, 63, 466, 513, 8, 2180, 12, 1007, 12, 10354, 14, 1078, 63, 1313, 395, 288, 12681, 275, 485, 981, 63, 504, 63, 5875, 63, 466, 513, 8, 2180, 12, 1007, 12, 3390, 14, 1078, 63, 1313, 395, 288, 330, 293, 669, 275, 485, 981, 63, 504, 63, 5875, 63, 14463, 8, 2180, 12, 1007, 12, 20062, 3100, 14, 20670, 669, 395, 288, 31530, 281, 275, 485, 981, 63, 504, 63, 5875, 63, 14463, 8, 2180, 12, 1007, 12, 20062, 3100, 14, 15485, 281, 395, 288, 4048, 275, 485, 981, 63, 504, 63, 5875, 63, 14463, 8, 2180, 12, 1007, 12, 20062, 3100, 14, 2407, 395, 288, 1007, 4055, 323, 63, 10095, 275, 942, 267, 776, 267, 286, 513, 14, 740, 8, 388, 9, 398, 327, 737, 642, 12427, 12, 18769, 390, 474, 576, 1630, 440, 2291, 20062, 3100, 14, 7768, 272, 327, 367, 1007, 12, 8869, 12, 1559, 315, 3343, 14, 7254, 2978, 1332, 403, 12, 820, 3888, 14, 466, 12, 20062, 3100, 14, 7768, 2298, 272, 327, 5108, 275, 620, 8, 954, 9, 272, 327, 258, 1048, 275, 18003, 1547, 1294, 63, 2302, 8, 2302, 12, 413, 395, 5108, 29, 2302, 9, 272, 327, 258, 1048, 14, 6334, 275, 485, 981, 63, 504, 63, 5875, 63, 14463, 8, 954, 12, 20062, 3100, 14, 1114, 9, 272, 327, 258, 1048, 14, 3512, 275, 485, 981, 63, 504, 63, 5875, 63, 466, 513, 8, 954, 12, 10354, 14, 1078, 63, 1313, 9, 272, 327, 258, 1048, 14, 5983, 275, 485, 981, 63, 504, 63, 5875, 63, 466, 513, 8, 954, 12, 3390, 14, 1078, 63, 1313, 9, 272, 327, 258, 286, 513, 14, 740, 8, 761, 9, 339, 372, 286, 513, 421, 199, 318, 485, 981, 63, 504, 63, 5875, 63, 466, 513, 8, 2180, 12, 5420, 12, 730, 513, 304, 272, 769, 275, 942, 272, 367, 299, 315, 730, 513, 26, 267, 6707, 275, 20062, 3100, 14, 5125, 8, 80, 9, 267, 769, 14, 2880, 1547, 981, 63, 504, 63, 5875, 63, 14463, 8, 2180, 12, 5420, 12, 6707, 430, 272, 372, 769, 421, 199, 318, 485, 981, 63, 504, 63, 5875, 63, 14463, 8, 2180, 12, 5420, 12, 11944, 304, 272, 769, 275, 942, 272, 367, 308, 12, 299, 12, 312, 315, 3343, 14, 7254, 2978, 1332, 5875, 12, 11944, 12, 488, 2298, 267, 730, 275, 11944, 14, 1294, 7863, 358, 1988, 17, 61, 267, 340, 10354, 14, 374, 63, 1078, 63, 466, 8, 466, 304, 288, 312, 275, 485, 981, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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.9.33.2/root-ralink/usr/lib/python2.7/distutils/core.py
175
9093
"""distutils.core The only module that needs to be imported to use the Distutils; provides the 'setup' function (which is to be called from the setup script). Also indirectly provides the Distribution and Command classes, although they are really defined in distutils.dist and distutils.cmd. """ __revision__ = "$Id$" import sys import os from distutils.debug import DEBUG from distutils.errors import (DistutilsSetupError, DistutilsArgError, DistutilsError, CCompilerError) from distutils.util import grok_environment_error # Mainly import these so setup scripts can "from distutils.core import" them. from distutils.dist import Distribution from distutils.cmd import Command from distutils.config import PyPIRCCommand from distutils.extension import Extension # This is a barebones help message generated displayed when the user # runs the setup script with no arguments at all. More useful help # is generated with various --help options: global help, list commands, # and per-command help. USAGE = """\ usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: %(script)s --help [cmd1 cmd2 ...] or: %(script)s --help-commands or: %(script)s cmd --help """ def gen_usage(script_name): script = os.path.basename(script_name) return USAGE % {'script': script} # Some mild magic to control the behaviour of 'setup()' from 'run_setup()'. _setup_stop_after = None _setup_distribution = None # Legal keyword arguments for the setup() function setup_keywords = ('distclass', 'script_name', 'script_args', 'options', 'name', 'version', 'author', 'author_email', 'maintainer', 'maintainer_email', 'url', 'license', 'description', 'long_description', 'keywords', 'platforms', 'classifiers', 'download_url', 'requires', 'provides', 'obsoletes', ) # Legal keyword arguments for the Extension constructor extension_keywords = ('name', 'sources', 'include_dirs', 'define_macros', 'undef_macros', 'library_dirs', 'libraries', 'runtime_library_dirs', 'extra_objects', 'extra_compile_args', 'extra_link_args', 'swig_opts', 'export_symbols', 'depends', 'language') def setup(**attrs): """The gateway to the Distutils: do everything your setup script needs to do, in a highly flexible and user-driven way. Briefly: create a Distribution instance; find and parse config files; parse the command line; run each Distutils command found there, customized by the options supplied to 'setup()' (as keyword arguments), in config files, and on the command line. The Distribution instance might be an instance of a class supplied via the 'distclass' keyword argument to 'setup'; if no such class is supplied, then the Distribution class (in dist.py) is instantiated. All other arguments to 'setup' (except for 'cmdclass') are used to set attributes of the Distribution instance. The 'cmdclass' argument, if supplied, is a dictionary mapping command names to command classes. Each command encountered on the command line will be turned into a command class, which is in turn instantiated; any class found in 'cmdclass' is used in place of the default, which is (for command 'foo_bar') class 'foo_bar' in module 'distutils.command.foo_bar'. The command class must provide a 'user_options' attribute which is a list of option specifiers for 'distutils.fancy_getopt'. Any command-line options between the current and the next command are used to set attributes of the current command object. When the entire command-line has been successfully parsed, calls the 'run()' method on each command object in turn. This method will be driven entirely by the Distribution object (which each command object has a reference to, thanks to its constructor), and the command-specific options that became attributes of each command object. """ global _setup_stop_after, _setup_distribution # Determine the distribution class -- either caller-supplied or # our Distribution (see below). klass = attrs.get('distclass') if klass: del attrs['distclass'] else: klass = Distribution if 'script_name' not in attrs: attrs['script_name'] = os.path.basename(sys.argv[0]) if 'script_args' not in attrs: attrs['script_args'] = sys.argv[1:] # Create the Distribution instance, using the remaining arguments # (ie. everything except distclass) to initialize it try: _setup_distribution = dist = klass(attrs) except DistutilsSetupError, msg: if 'name' in attrs: raise SystemExit, "error in %s setup command: %s" % \ (attrs['name'], msg) else: raise SystemExit, "error in setup command: %s" % msg if _setup_stop_after == "init": return dist # Find and parse the config file(s): they will override options from # the setup script, but be overridden by the command line. dist.parse_config_files() if DEBUG: print "options (after parsing config files):" dist.dump_option_dicts() if _setup_stop_after == "config": return dist # Parse the command line and override config files; any # command-line errors are the end user's fault, so turn them into # SystemExit to suppress tracebacks. try: ok = dist.parse_command_line() except DistutilsArgError, msg: raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg if DEBUG: print "options (after parsing command line):" dist.dump_option_dicts() if _setup_stop_after == "commandline": return dist # And finally, run all the commands found on the command line. if ok: try: dist.run_commands() except KeyboardInterrupt: raise SystemExit, "interrupted" except (IOError, os.error), exc: error = grok_environment_error(exc) if DEBUG: sys.stderr.write(error + "\n") raise else: raise SystemExit, error except (DistutilsError, CCompilerError), msg: if DEBUG: raise else: raise SystemExit, "error: " + str(msg) return dist def run_setup(script_name, script_args=None, stop_after="run"): """Run a setup script in a somewhat controlled environment, and return the Distribution instance that drives things. This is useful if you need to find out the distribution meta-data (passed as keyword args from 'script' to 'setup()', or the contents of the config files or command-line. 'script_name' is a file that will be run with 'execfile()'; 'sys.argv[0]' will be replaced with 'script' for the duration of the call. 'script_args' is a list of strings; if supplied, 'sys.argv[1:]' will be replaced by 'script_args' for the duration of the call. 'stop_after' tells 'setup()' when to stop processing; possible values: init stop after the Distribution instance has been created and populated with the keyword arguments to 'setup()' config stop after config files have been parsed (and their data stored in the Distribution instance) commandline stop after the command-line ('sys.argv[1:]' or 'script_args') have been parsed (and the data stored in the Distribution) run [default] stop after all commands have been run (the same as if 'setup()' had been called in the usual way Returns the Distribution instance, which provides all information used to drive the Distutils. """ if stop_after not in ('init', 'config', 'commandline', 'run'): raise ValueError, "invalid value for 'stop_after': %r" % (stop_after,) global _setup_stop_after, _setup_distribution _setup_stop_after = stop_after save_argv = sys.argv g = {'__file__': script_name} l = {} try: try: sys.argv[0] = script_name if script_args is not None: sys.argv[1:] = script_args f = open(script_name) try: exec f.read() in g, l finally: f.close() finally: sys.argv = save_argv _setup_stop_after = None except SystemExit: # Hmm, should we do something if exiting with a non-zero code # (ie. error)? pass except: raise if _setup_distribution is None: raise RuntimeError, \ ("'distutils.core.setup()' was never called -- " "perhaps '%s' is not a Distutils setup script?") % \ script_name # I wonder if the setup script's namespace -- g and l -- would be of # any interest to callers? return _setup_distribution
gpl-2.0
[ 624, 13350, 14, 1018, 199, 199, 1918, 1454, 859, 626, 4839, 370, 506, 8439, 370, 675, 314, 12577, 27, 6571, 199, 1589, 283, 2758, 7, 805, 334, 6777, 365, 370, 506, 2797, 687, 314, 3272, 2884, 680, 221, 6121, 199, 29306, 590, 6571, 314, 11839, 436, 5817, 3992, 12, 22160, 2985, 787, 199, 29428, 3247, 315, 7065, 14, 2686, 436, 7065, 14, 1760, 14, 199, 624, 199, 199, 363, 5792, 363, 275, 7880, 1304, 17351, 199, 199, 646, 984, 199, 646, 747, 199, 199, 504, 7065, 14, 1757, 492, 10990, 199, 504, 7065, 14, 2550, 492, 334, 12012, 1208, 30221, 12, 12577, 6373, 547, 12, 2892, 12577, 547, 12, 445, 9131, 547, 9, 199, 504, 7065, 14, 1974, 492, 486, 29275, 63, 5418, 63, 705, 199, 199, 3, 11298, 590, 492, 3520, 880, 3272, 10554, 883, 298, 504, 7065, 14, 1018, 492, 2, 3062, 14, 199, 504, 7065, 14, 2686, 492, 11839, 199, 504, 7065, 14, 1760, 492, 5817, 199, 504, 7065, 14, 888, 492, 24330, 8205, 3110, 199, 504, 7065, 14, 3435, 492, 13282, 199, 199, 3, 961, 365, 282, 18753, 66, 4548, 1720, 1245, 4046, 9080, 1380, 314, 922, 199, 3, 7858, 314, 3272, 2884, 543, 949, 2368, 737, 1006, 14, 221, 16917, 2997, 1720, 199, 3, 365, 4046, 543, 7750, 1553, 3437, 1511, 26, 2288, 1720, 12, 769, 3718, 12, 199, 3, 436, 1126, 13, 1531, 1720, 14, 199, 20274, 275, 9638, 199, 3807, 26, 2818, 1579, 9, 83, 359, 2966, 63, 3291, 61, 2088, 17, 359, 1760, 17, 63, 3291, 61, 359, 1760, 18, 359, 1760, 18, 63, 3291, 61, 21214, 2043, 503, 26, 2818, 1579, 9, 83, 1553, 3437, 359, 1760, 17, 2088, 18, 21214, 2043, 503, 26, 2818, 1579, 9, 83, 1553, 3437, 13, 4405, 2043, 503, 26, 2818, 1579, 9, 83, 2088, 1553, 3437, 199, 624, 199, 199, 318, 3805, 63, 3807, 8, 1579, 63, 354, 304, 272, 2884, 275, 747, 14, 515, 14, 4846, 8, 1579, 63, 354, 9, 272, 372, 19635, 2962, 450, 791, 1579, 356, 2884, 93, 421, 199, 3, 6601, 333, 668, 10628, 370, 3304, 314, 13942, 402, 283, 2758, 11716, 687, 283, 1065, 63, 2758, 342, 1370, 199, 63, 2758, 63, 2379, 63, 4399, 275, 488, 199, 63, 2758, 63, 4972, 275, 488, 199, 199, 3, 16258, 279, 4252, 2368, 367, 314, 3272, 342, 805, 199, 2758, 63, 7511, 275, 661, 2686, 533, 297, 283, 1579, 63, 354, 297, 283, 1579, 63, 589, 297, 283, 1419, 297, 2116, 283, 354, 297, 283, 1023, 297, 283, 2502, 297, 283, 2502, 63, 2123, 297, 2116, 283, 26665, 297, 283, 26665, 63, 2123, 297, 283, 633, 297, 283, 1682, 297, 2116, 283, 1802, 297, 283, 2809, 63, 1802, 297, 283, 7511, 297, 2116, 283, 19601, 297, 283, 27628, 297, 283, 4249, 63, 633, 297, 2116, 283, 6537, 297, 283, 20121, 297, 283, 2873, 31750, 297, 2116, 776, 199, 199, 3, 16258, 279, 4252, 2368, 367, 314, 13282, 3787, 199, 3435, 63, 7511, 275, 661, 354, 297, 283, 4553, 297, 283, 2613, 63, 3220, 297, 1993, 283, 4640, 63, 16358, 297, 283, 25878, 63, 16358, 297, 1993, 283, 4342, 63, 3220, 297, 283, 10159, 297, 283, 7726, 63, 4342, 63, 3220, 297, 1993, 283, 2911, 63, 1462, 297, 283, 2911, 63, 2014, 63, 589, 297, 283, 2911, 63, 1073, 63, 589, 297, 1993, 283, 9676, 63, 3291, 297, 283, 3790, 63, 7450, 297, 283, 8912, 297, 283, 3671, 358, 199, 199, 318, 3272, 3682, 3288, 304, 272, 408, 1918, 10391, 370, 314, 12577, 26, 886, 8137, 2195, 3272, 2884, 4839, 272, 370, 886, 12, 315, 282, 4721, 590, 26841, 436, 922, 13, 17824, 1856, 4340, 14, 221, 699, 322, 2829, 590, 26, 1218, 282, 272, 11839, 1256, 27, 2342, 436, 2198, 1101, 1584, 27, 2198, 314, 1414, 272, 1004, 27, 1255, 1924, 12577, 1414, 1911, 2337, 12, 26707, 701, 314, 1511, 272, 6841, 370, 283, 2758, 11716, 334, 305, 4252, 2368, 395, 315, 1101, 1584, 12, 436, 641, 272, 314, 1414, 1004, 14, 339, 710, 11839, 1256, 5594, 506, 376, 1256, 402, 282, 1021, 6841, 4799, 272, 314, 283, 2686, 533, 7, 4252, 1423, 370, 283, 2758, 13619, 340, 949, 4066, 1021, 365, 272, 6841, 12, 2066, 314, 11839, 1021, 334, 262, 2917, 14, 647, 9, 365, 17544, 14, 272, 2900, 1163, 2368, 370, 283, 2758, 7, 334, 2590, 367, 283, 1760, 533, 358, 787, 1202, 370, 663, 272, 3004, 402, 314, 11839, 1256, 14, 339, 710, 283, 1760, 533, 7, 1423, 12, 340, 6841, 12, 365, 282, 2600, 4412, 1414, 272, 1561, 370, 1414, 3992, 14, 221, 7048, 1414, 14556, 641, 314, 1414, 1004, 272, 911, 506, 19136, 1901, 282, 1414, 1021, 12, 1314, 365, 315, 7485, 17544, 27, 1263, 272, 1021, 1911, 315, 283, 1760, 533, 7, 365, 1202, 315, 4192, 402, 314, 849, 12, 1314, 365, 272, 334, 509, 1414, 283, 1421, 63, 1700, 358, 1021, 283, 1421, 63, 1700, 7, 315, 859, 272, 283, 13350, 14, 1531, 14, 1421, 63, 1700, 1370, 221, 710, 1414, 1021, 1471, 5647, 282, 272, 283, 751, 63, 1419, 7, 2225, 1314, 365, 282, 769, 402, 945, 29558, 367, 272, 283, 13350, 14, 25352, 63, 18907, 1370, 221, 6184, 1414, 13, 604, 1511, 3382, 314, 1453, 272, 436, 314, 2163, 1414, 787, 1202, 370, 663, 3004, 402, 314, 1453, 1414, 272, 909, 14, 339, 3979, 314, 8039, 1414, 13, 604, 965, 2757, 8792, 4565, 12, 4882, 314, 272, 283, 1065, 11716, 1083, 641, 1924, 1414, 909, 315, 7485, 14, 221, 961, 1083, 911, 506, 272, 20921, 1856, 21926, 701, 314, 11839, 909, 334, 6777, 1924, 1414, 909, 272, 965, 282, 3659, 370, 12, 2419, 6080, 370, 2399, 3787, 395, 436, 314, 272, 1414, 13, 6100, 1511, 626, 506, 27467, 3004, 402, 1924, 1414, 272, 909, 14, 272, 408, 339, 2288, 485, 2758, 63, 2379, 63, 4399, 12, 485, 2758, 63, 4972, 339, 327, 14703, 314, 4084, 1021, 1553, 1902, 8025, 13, 22525, 503, 272, 327, 4154, 11839, 334, 3239, 5084, 680, 272, 8531, 275, 3290, 14, 362, 360, 2686, 533, 358, 272, 340, 8531, 26, 267, 2150, 3290, 459, 2686, 533, 418, 272, 587, 26, 267, 8531, 275, 11839, 339, 340, 283, 1579, 63, 354, 7, 440 ]
[ 13350, 14, 1018, 199, 199, 1918, 1454, 859, 626, 4839, 370, 506, 8439, 370, 675, 314, 12577, 27, 6571, 199, 1589, 283, 2758, 7, 805, 334, 6777, 365, 370, 506, 2797, 687, 314, 3272, 2884, 680, 221, 6121, 199, 29306, 590, 6571, 314, 11839, 436, 5817, 3992, 12, 22160, 2985, 787, 199, 29428, 3247, 315, 7065, 14, 2686, 436, 7065, 14, 1760, 14, 199, 624, 199, 199, 363, 5792, 363, 275, 7880, 1304, 17351, 199, 199, 646, 984, 199, 646, 747, 199, 199, 504, 7065, 14, 1757, 492, 10990, 199, 504, 7065, 14, 2550, 492, 334, 12012, 1208, 30221, 12, 12577, 6373, 547, 12, 2892, 12577, 547, 12, 445, 9131, 547, 9, 199, 504, 7065, 14, 1974, 492, 486, 29275, 63, 5418, 63, 705, 199, 199, 3, 11298, 590, 492, 3520, 880, 3272, 10554, 883, 298, 504, 7065, 14, 1018, 492, 2, 3062, 14, 199, 504, 7065, 14, 2686, 492, 11839, 199, 504, 7065, 14, 1760, 492, 5817, 199, 504, 7065, 14, 888, 492, 24330, 8205, 3110, 199, 504, 7065, 14, 3435, 492, 13282, 199, 199, 3, 961, 365, 282, 18753, 66, 4548, 1720, 1245, 4046, 9080, 1380, 314, 922, 199, 3, 7858, 314, 3272, 2884, 543, 949, 2368, 737, 1006, 14, 221, 16917, 2997, 1720, 199, 3, 365, 4046, 543, 7750, 1553, 3437, 1511, 26, 2288, 1720, 12, 769, 3718, 12, 199, 3, 436, 1126, 13, 1531, 1720, 14, 199, 20274, 275, 9638, 199, 3807, 26, 2818, 1579, 9, 83, 359, 2966, 63, 3291, 61, 2088, 17, 359, 1760, 17, 63, 3291, 61, 359, 1760, 18, 359, 1760, 18, 63, 3291, 61, 21214, 2043, 503, 26, 2818, 1579, 9, 83, 1553, 3437, 359, 1760, 17, 2088, 18, 21214, 2043, 503, 26, 2818, 1579, 9, 83, 1553, 3437, 13, 4405, 2043, 503, 26, 2818, 1579, 9, 83, 2088, 1553, 3437, 199, 624, 199, 199, 318, 3805, 63, 3807, 8, 1579, 63, 354, 304, 272, 2884, 275, 747, 14, 515, 14, 4846, 8, 1579, 63, 354, 9, 272, 372, 19635, 2962, 450, 791, 1579, 356, 2884, 93, 421, 199, 3, 6601, 333, 668, 10628, 370, 3304, 314, 13942, 402, 283, 2758, 11716, 687, 283, 1065, 63, 2758, 342, 1370, 199, 63, 2758, 63, 2379, 63, 4399, 275, 488, 199, 63, 2758, 63, 4972, 275, 488, 199, 199, 3, 16258, 279, 4252, 2368, 367, 314, 3272, 342, 805, 199, 2758, 63, 7511, 275, 661, 2686, 533, 297, 283, 1579, 63, 354, 297, 283, 1579, 63, 589, 297, 283, 1419, 297, 2116, 283, 354, 297, 283, 1023, 297, 283, 2502, 297, 283, 2502, 63, 2123, 297, 2116, 283, 26665, 297, 283, 26665, 63, 2123, 297, 283, 633, 297, 283, 1682, 297, 2116, 283, 1802, 297, 283, 2809, 63, 1802, 297, 283, 7511, 297, 2116, 283, 19601, 297, 283, 27628, 297, 283, 4249, 63, 633, 297, 2116, 283, 6537, 297, 283, 20121, 297, 283, 2873, 31750, 297, 2116, 776, 199, 199, 3, 16258, 279, 4252, 2368, 367, 314, 13282, 3787, 199, 3435, 63, 7511, 275, 661, 354, 297, 283, 4553, 297, 283, 2613, 63, 3220, 297, 1993, 283, 4640, 63, 16358, 297, 283, 25878, 63, 16358, 297, 1993, 283, 4342, 63, 3220, 297, 283, 10159, 297, 283, 7726, 63, 4342, 63, 3220, 297, 1993, 283, 2911, 63, 1462, 297, 283, 2911, 63, 2014, 63, 589, 297, 283, 2911, 63, 1073, 63, 589, 297, 1993, 283, 9676, 63, 3291, 297, 283, 3790, 63, 7450, 297, 283, 8912, 297, 283, 3671, 358, 199, 199, 318, 3272, 3682, 3288, 304, 272, 408, 1918, 10391, 370, 314, 12577, 26, 886, 8137, 2195, 3272, 2884, 4839, 272, 370, 886, 12, 315, 282, 4721, 590, 26841, 436, 922, 13, 17824, 1856, 4340, 14, 221, 699, 322, 2829, 590, 26, 1218, 282, 272, 11839, 1256, 27, 2342, 436, 2198, 1101, 1584, 27, 2198, 314, 1414, 272, 1004, 27, 1255, 1924, 12577, 1414, 1911, 2337, 12, 26707, 701, 314, 1511, 272, 6841, 370, 283, 2758, 11716, 334, 305, 4252, 2368, 395, 315, 1101, 1584, 12, 436, 641, 272, 314, 1414, 1004, 14, 339, 710, 11839, 1256, 5594, 506, 376, 1256, 402, 282, 1021, 6841, 4799, 272, 314, 283, 2686, 533, 7, 4252, 1423, 370, 283, 2758, 13619, 340, 949, 4066, 1021, 365, 272, 6841, 12, 2066, 314, 11839, 1021, 334, 262, 2917, 14, 647, 9, 365, 17544, 14, 272, 2900, 1163, 2368, 370, 283, 2758, 7, 334, 2590, 367, 283, 1760, 533, 358, 787, 1202, 370, 663, 272, 3004, 402, 314, 11839, 1256, 14, 339, 710, 283, 1760, 533, 7, 1423, 12, 340, 6841, 12, 365, 282, 2600, 4412, 1414, 272, 1561, 370, 1414, 3992, 14, 221, 7048, 1414, 14556, 641, 314, 1414, 1004, 272, 911, 506, 19136, 1901, 282, 1414, 1021, 12, 1314, 365, 315, 7485, 17544, 27, 1263, 272, 1021, 1911, 315, 283, 1760, 533, 7, 365, 1202, 315, 4192, 402, 314, 849, 12, 1314, 365, 272, 334, 509, 1414, 283, 1421, 63, 1700, 358, 1021, 283, 1421, 63, 1700, 7, 315, 859, 272, 283, 13350, 14, 1531, 14, 1421, 63, 1700, 1370, 221, 710, 1414, 1021, 1471, 5647, 282, 272, 283, 751, 63, 1419, 7, 2225, 1314, 365, 282, 769, 402, 945, 29558, 367, 272, 283, 13350, 14, 25352, 63, 18907, 1370, 221, 6184, 1414, 13, 604, 1511, 3382, 314, 1453, 272, 436, 314, 2163, 1414, 787, 1202, 370, 663, 3004, 402, 314, 1453, 1414, 272, 909, 14, 339, 3979, 314, 8039, 1414, 13, 604, 965, 2757, 8792, 4565, 12, 4882, 314, 272, 283, 1065, 11716, 1083, 641, 1924, 1414, 909, 315, 7485, 14, 221, 961, 1083, 911, 506, 272, 20921, 1856, 21926, 701, 314, 11839, 909, 334, 6777, 1924, 1414, 909, 272, 965, 282, 3659, 370, 12, 2419, 6080, 370, 2399, 3787, 395, 436, 314, 272, 1414, 13, 6100, 1511, 626, 506, 27467, 3004, 402, 1924, 1414, 272, 909, 14, 272, 408, 339, 2288, 485, 2758, 63, 2379, 63, 4399, 12, 485, 2758, 63, 4972, 339, 327, 14703, 314, 4084, 1021, 1553, 1902, 8025, 13, 22525, 503, 272, 327, 4154, 11839, 334, 3239, 5084, 680, 272, 8531, 275, 3290, 14, 362, 360, 2686, 533, 358, 272, 340, 8531, 26, 267, 2150, 3290, 459, 2686, 533, 418, 272, 587, 26, 267, 8531, 275, 11839, 339, 340, 283, 1579, 63, 354, 7, 440, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
tomprince/gemrb
gemrb/GUIScripts/bg2/GUICG22.py
3
7449
# -*-python-*- # GemRB - Infinity Engine Emulator # Copyright (C) 2003-2007 The GemRB Project # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # #character generation, class kit (GUICG22) import GemRB import CommonTables from ie_stats import * from GUIDefines import * KitWindow = 0 TextAreaControl = 0 DoneButton = 0 SchoolList = 0 ClassID = 0 TopIndex = 0 RowCount = 10 KitTable = 0 Init = 0 MyChar = 0 KitSelected = 0 #store clicked kit on redraw as number within RowCount EnhanceGUI = GemRB.GetVar("GUIEnhancements")&GE_SCROLLBARS #extra kit button and scroll bar toggle def OnLoad(): global KitWindow, TextAreaControl, DoneButton global SchoolList, ClassID global RowCount, TopIndex, KitTable, Init, MyChar GemRB.LoadWindowPack("GUICG", 640, 480) MyChar = GemRB.GetVar ("Slot") Race = GemRB.GetPlayerStat (MyChar, IE_RACE) RaceName = CommonTables.Races.GetRowName(CommonTables.Races.FindValue (3, Race) ) ClassID = GemRB.GetPlayerStat (MyChar, IE_CLASS) ClassName = CommonTables.Classes.GetRowName (GemRB.GetPlayerStat (MyChar, IE_HITPOINTS)) # barbarian hack KitTable = GemRB.LoadTable("kittable") KitTableName = KitTable.GetValue(ClassName, RaceName) KitTable = GemRB.LoadTable(KitTableName,1) SchoolList = GemRB.LoadTable("magesch") #there is a specialist mage window, but it is easier to use #the class kit window for both KitWindow = GemRB.LoadWindow(22) if ClassID == 1: Label = KitWindow.GetControl(0xfffffff) Label.SetText(595) for i in range(10): if i<4: Button = KitWindow.GetControl(i+1) else: Button = KitWindow.GetControl(i+5) Button.SetState(IE_GUI_BUTTON_DISABLED) Button.SetFlags(IE_GUI_BUTTON_RADIOBUTTON, OP_OR) if not KitTable: # sorcerer or monk RowCount = 1 else: if ClassID == 1: # mages RowCount = SchoolList.GetRowCount() else: RowCount = KitTable.GetRowCount() TopIndex = 0 GemRB.SetVar("TopIndex", 0) if EnhanceGUI: tmpRowCount = RowCount if RowCount>10: #create 11 kit button KitWindow.CreateButton (15, 18, 250, 271, 20) extrakit = KitWindow.GetControl(15) extrakit.SetState(IE_GUI_BUTTON_DISABLED) extrakit.SetFlags(IE_GUI_BUTTON_RADIOBUTTON, OP_OR) extrakit.SetSprites("GUICGBC",0, 0,1,2,3) RowCount = 11 if tmpRowCount>11: #create scroll bar KitWindow.CreateScrollBar(1000, 290, 50, 16, 220) ScrollBar = KitWindow.GetControl (1000) ScrollBar.SetSprites("GUISCRCW", 0, 0,1,2,3,5,4) ScrollBar.SetVarAssoc("TopIndex",tmpRowCount-10) ScrollBar.SetEvent(IE_GUI_SCROLLBAR_ON_CHANGE, RedrawKits) ScrollBar.SetDefaultScrollBar() elif not EnhanceGUI and RowCount>10: RowCount = 10 for i in range(RowCount): if i<4: Button = KitWindow.GetControl(i+1) else: Button = KitWindow.GetControl(i+5) Button.SetVarAssoc("ButtonPressed", i) Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, KitPress) BackButton = KitWindow.GetControl(8) BackButton.SetText(15416) BackButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR) DoneButton = KitWindow.GetControl(7) DoneButton.SetText(11973) DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT,OP_OR) TextAreaControl = KitWindow.GetControl(5) TextAreaControl.SetText(17247) DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress) BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, BackPress) Init = 1 RedrawKits() KitPress() KitWindow.SetVisible(WINDOW_VISIBLE) return def RedrawKits(): global TopIndex, Init, KitSelected TopIndex=GemRB.GetVar("TopIndex") EnabledButtons = [] for i in range(RowCount): if i<4: Button = KitWindow.GetControl(i+1) else: Button = KitWindow.GetControl(i+5) Button.SetState(IE_GUI_BUTTON_DISABLED) if not KitTable: if ClassID == 1: # TODO: check if this is ever reached Kit = GemRB.GetVar("MAGESCHOOL") KitName = SchoolList.GetValue(i+TopIndex, 0) Kit = SchoolList.GetValue (Kit, 3) else: Kit = 0 KitName = CommonTables.Classes.GetValue(GemRB.GetVar("Class")-1, 0) else: Kit = KitTable.GetValue (i+TopIndex,0) if ClassID == 1: KitName = SchoolList.GetValue (i+TopIndex, 0) if Kit == 0: KitName = SchoolList.GetValue (0, 0) Button.SetState(IE_GUI_BUTTON_ENABLED) if Init: #preselection of mage plain kit Button.SetState(IE_GUI_BUTTON_SELECTED) KitSelected = i+TopIndex Init=0 if Kit != "*": EnabledButtons.append(Kit-21) else: if Kit: KitName = CommonTables.KitList.GetValue(Kit, 1) else: KitName = CommonTables.Classes.GetValue(GemRB.GetVar("Class")-1, 0) Button.SetText(KitName) if not EnabledButtons or i+TopIndex in EnabledButtons: Button.SetState(IE_GUI_BUTTON_ENABLED) if Init and i+TopIndex>0: Button.SetState(IE_GUI_BUTTON_SELECTED) KitSelected = i+TopIndex Init=0 if Kit == "*": continue if Init and i+TopIndex==0: if EnabledButtons: GemRB.SetVar("ButtonPressed", EnabledButtons[0]) #but leave Init==1 else: GemRB.SetVar("ButtonPressed", 0) Button.SetState(IE_GUI_BUTTON_SELECTED) KitSelected = i+TopIndex Init=0 if not Init and i+TopIndex == KitSelected: #remark selection state on redraw Button.SetState(IE_GUI_BUTTON_SELECTED) return def KitPress(): global KitSelected ButtonPressed=GemRB.GetVar("ButtonPressed") KitSelected = ButtonPressed + TopIndex if not KitTable: if ClassID == 1: # TODO: this seems to be never reached Kit = GemRB.GetVar("MAGESCHOOL") Kit = SchoolList.GetValue (Kit, 3) else: Kit = 0 else: Kit = KitTable.GetValue (ButtonPressed+TopIndex, 0) if ClassID == 1: if ButtonPressed + TopIndex == 0: Kit = 0 else: Kit = ButtonPressed + TopIndex + 21 if ClassID == 1 and Kit != 0: GemRB.SetVar("MAGESCHOOL", Kit-21) # hack: -21 to make the generalist 0 else: GemRB.SetVar("MAGESCHOOL", 0) # so bards don't get schools if Kit == 0: KitDescription = CommonTables.Classes.GetValue(GemRB.GetVar("Class")-1, 1) else: KitDescription = CommonTables.KitList.GetValue(Kit, 3) TextAreaControl.SetText(KitDescription) DoneButton.SetState(IE_GUI_BUTTON_ENABLED) GemRB.SetVar("Class Kit", Kit) return def BackPress(): GemRB.SetVar("Class Kit", 0) # reverting the value so we are idempotent GemRB.SetVar("MAGESCHOOL", 0) if KitWindow: KitWindow.Unload() GemRB.SetNextScript("GUICG2") return def NextPress(): if KitWindow: KitWindow.Unload() #make gnomes always kitted KitIndex = GemRB.GetVar ("Class Kit") MageSchool = GemRB.GetVar ("MAGESCHOOL") if MageSchool and not KitIndex: SchoolTable = GemRB.LoadTable ("magesch") KitIndex = CommonTables.KitList.FindValue (6, SchoolTable.GetValue (MageSchool, 3) ) #save the kit KitValue = (0x4000 + KitIndex) KitName = CommonTables.KitList.GetValue (KitIndex, 0) GemRB.SetPlayerStat (MyChar, IE_KIT, KitValue) GemRB.SetNextScript("CharGen4") #abilities return
gpl-2.0
[ 3, 1882, 1548, 13, 1837, 199, 3, 5346, 77, 16567, 446, 1010, 9693, 12580, 662, 3703, 707, 199, 3, 1898, 334, 35, 9, 13004, 13, 9488, 710, 5346, 77, 16567, 7290, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 199, 3, 465, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 199, 3, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8026, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 4828, 11315, 13, 10067, 12, 8217, 14, 199, 3, 199, 3, 10856, 10152, 12, 1021, 1022, 390, 334, 17188, 948, 39, 1081, 9, 199, 199, 646, 5346, 77, 16567, 199, 646, 13964, 18845, 199, 504, 13446, 63, 3200, 492, 627, 199, 504, 17160, 23891, 492, 627, 199, 199, 14591, 4301, 275, 378, 199, 1872, 11043, 3717, 275, 378, 199, 10759, 4259, 275, 378, 199, 51, 15089, 1296, 275, 378, 199, 2543, 998, 275, 378, 199, 6105, 2681, 275, 378, 199, 5810, 2353, 275, 1616, 199, 14591, 3186, 275, 378, 199, 9346, 275, 378, 199, 5713, 1610, 275, 378, 199, 14591, 12461, 275, 378, 327, 1617, 28614, 1022, 390, 641, 295, 5485, 465, 1329, 4453, 15231, 2353, 199, 1327, 14666, 14438, 275, 5346, 77, 16567, 14, 1002, 5894, 480, 14438, 1327, 14666, 1470, 531, 6, 4962, 63, 26315, 13895, 51, 327, 2911, 1022, 390, 5528, 436, 13704, 4681, 19420, 199, 199, 318, 4068, 6200, 837, 199, 198, 2966, 1804, 390, 4301, 12, 4516, 11043, 3717, 12, 23541, 4259, 199, 198, 2966, 428, 15089, 1296, 12, 8089, 998, 199, 198, 2966, 15231, 2353, 12, 14132, 2681, 12, 1804, 390, 3186, 12, 21026, 12, 4932, 1610, 421, 198, 4240, 77, 16567, 14, 6200, 4301, 2305, 480, 17188, 948, 39, 401, 5049, 16, 12, 29504, 9, 199, 198, 5713, 1610, 275, 5346, 77, 16567, 14, 1002, 5894, 1689, 15183, 531, 199, 198, 1537, 301, 275, 5346, 77, 16567, 14, 1002, 10921, 11232, 334, 5713, 1610, 12, 15292, 63, 50, 4121, 9, 199, 198, 1537, 301, 985, 275, 13964, 18845, 14, 1537, 823, 14, 1002, 5810, 985, 8, 7844, 18845, 14, 1537, 823, 14, 6591, 1110, 334, 19, 12, 3898, 301, 9, 776, 421, 198, 2543, 998, 275, 5346, 77, 16567, 14, 1002, 10921, 11232, 334, 5713, 1610, 12, 15292, 63, 6885, 9, 199, 198, 23200, 275, 13964, 18845, 14, 15711, 14, 1002, 5810, 985, 334, 4240, 77, 16567, 14, 1002, 10921, 11232, 334, 5713, 1610, 12, 15292, 63, 40, 649, 7217, 51, 430, 327, 4681, 66, 15289, 11176, 421, 198, 14591, 3186, 275, 5346, 77, 16567, 14, 6200, 3186, 480, 6065, 1224, 531, 199, 198, 14591, 3186, 985, 275, 1804, 390, 3186, 14, 9334, 8, 23200, 12, 3898, 301, 985, 9, 199, 198, 14591, 3186, 275, 5346, 77, 16567, 14, 6200, 3186, 8, 14591, 3186, 985, 12, 17, 9, 421, 198, 51, 15089, 1296, 275, 5346, 77, 16567, 14, 6200, 3186, 480, 960, 15820, 531, 421, 198, 3, 16990, 365, 282, 4539, 631, 333, 474, 4353, 12, 1325, 652, 365, 14905, 370, 675, 199, 198, 3, 1589, 1021, 1022, 390, 4353, 367, 3865, 199, 198, 14591, 4301, 275, 5346, 77, 16567, 14, 6200, 4301, 8, 1081, 9, 199, 198, 692, 8089, 998, 508, 413, 26, 507, 198, 4314, 275, 1804, 390, 4301, 14, 1002, 3717, 8, 16, 3581, 4717, 70, 9, 507, 198, 4314, 14, 1084, 1872, 8, 16447, 9, 421, 198, 509, 284, 315, 1425, 8, 709, 304, 507, 198, 692, 284, 28, 20, 26, 686, 198, 4259, 275, 1804, 390, 4301, 14, 1002, 3717, 8, 73, 11, 17, 9, 507, 198, 2836, 26, 686, 198, 4259, 275, 1804, 390, 4301, 14, 1002, 3717, 8, 73, 11, 21, 9, 507, 198, 4259, 14, 1084, 2223, 8, 4332, 63, 14438, 63, 13272, 63, 16205, 9, 507, 198, 4259, 14, 1084, 6381, 8, 4332, 63, 14438, 63, 13272, 63, 19662, 2090, 13272, 12, 9827, 63, 726, 9, 421, 198, 692, 440, 1804, 390, 3186, 26, 327, 308, 269, 301, 3859, 503, 3485, 75, 507, 198, 5810, 2353, 275, 413, 199, 198, 2836, 26, 507, 198, 692, 8089, 998, 508, 413, 26, 327, 333, 7441, 686, 198, 5810, 2353, 275, 428, 15089, 1296, 14, 1002, 5810, 2353, 342, 507, 198, 2836, 26, 686, 198, 5810, 2353, 275, 1804, 390, 3186, 14, 1002, 5810, 2353, 342, 421, 198, 6105, 2681, 275, 378, 199, 198, 4240, 77, 16567, 14, 1084, 5894, 480, 6105, 2681, 401, 378, 9, 199, 198, 692, 3447, 14666, 14438, 26, 507, 198, 2791, 5810, 2353, 275, 15231, 2353, 507, 198, 692, 15231, 2353, 30, 709, 26, 327, 981, 4119, 1022, 390, 5528, 686, 198, 14591, 4301, 14, 2499, 4259, 334, 1046, 12, 6155, 12, 16074, 12, 499, 3172, 12, 3388, 9, 686, 198, 2911, 6065, 275, 1804, 390, 4301, 14, 1002, 3717, 8, 1046, 9, 686, 198, 2911, 6065, 14, 1084, 2223, 8, 4332, 63, 14438, 63, 13272, 63, 16205, 9, 686, 198, 2911, 6065, 14, 1084, 6381, 8, 4332, 63, 14438, 63, 13272, 63, 19662, 2090, 13272, 12, 9827, 63, 726, 9, 686, 198, 2911, 6065, 14, 1084, 51, 21483, 480, 17188, 948, 39, 6265, 401, 16, 12, 378, 12, 17, 12, 18, 12, 19, 9, 686, 198, 5810, 2353, 275, 4119, 507, 198, 692, 3529, 5810, 2353, 30, 845, 26, 327, 981, 13704, 4681, 686, 198, 14591, 4301, 14, 2499, 13127, 5281, 8, 5279, 12, 499, 2710, 12, 5238, 12, 3193, 12, 25647, 9, 686, 198, 13127, 5281, 275, 1804, 390, 4301, 14, 1002, 3717, 334, 5279, 9, 686, 198, 13127, 5281, 14, 1084, 51, 21483, 480 ]
[ 1882, 1548, 13, 1837, 199, 3, 5346, 77, 16567, 446, 1010, 9693, 12580, 662, 3703, 707, 199, 3, 1898, 334, 35, 9, 13004, 13, 9488, 710, 5346, 77, 16567, 7290, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 199, 3, 465, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 199, 3, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8026, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 4828, 11315, 13, 10067, 12, 8217, 14, 199, 3, 199, 3, 10856, 10152, 12, 1021, 1022, 390, 334, 17188, 948, 39, 1081, 9, 199, 199, 646, 5346, 77, 16567, 199, 646, 13964, 18845, 199, 504, 13446, 63, 3200, 492, 627, 199, 504, 17160, 23891, 492, 627, 199, 199, 14591, 4301, 275, 378, 199, 1872, 11043, 3717, 275, 378, 199, 10759, 4259, 275, 378, 199, 51, 15089, 1296, 275, 378, 199, 2543, 998, 275, 378, 199, 6105, 2681, 275, 378, 199, 5810, 2353, 275, 1616, 199, 14591, 3186, 275, 378, 199, 9346, 275, 378, 199, 5713, 1610, 275, 378, 199, 14591, 12461, 275, 378, 327, 1617, 28614, 1022, 390, 641, 295, 5485, 465, 1329, 4453, 15231, 2353, 199, 1327, 14666, 14438, 275, 5346, 77, 16567, 14, 1002, 5894, 480, 14438, 1327, 14666, 1470, 531, 6, 4962, 63, 26315, 13895, 51, 327, 2911, 1022, 390, 5528, 436, 13704, 4681, 19420, 199, 199, 318, 4068, 6200, 837, 199, 198, 2966, 1804, 390, 4301, 12, 4516, 11043, 3717, 12, 23541, 4259, 199, 198, 2966, 428, 15089, 1296, 12, 8089, 998, 199, 198, 2966, 15231, 2353, 12, 14132, 2681, 12, 1804, 390, 3186, 12, 21026, 12, 4932, 1610, 421, 198, 4240, 77, 16567, 14, 6200, 4301, 2305, 480, 17188, 948, 39, 401, 5049, 16, 12, 29504, 9, 199, 198, 5713, 1610, 275, 5346, 77, 16567, 14, 1002, 5894, 1689, 15183, 531, 199, 198, 1537, 301, 275, 5346, 77, 16567, 14, 1002, 10921, 11232, 334, 5713, 1610, 12, 15292, 63, 50, 4121, 9, 199, 198, 1537, 301, 985, 275, 13964, 18845, 14, 1537, 823, 14, 1002, 5810, 985, 8, 7844, 18845, 14, 1537, 823, 14, 6591, 1110, 334, 19, 12, 3898, 301, 9, 776, 421, 198, 2543, 998, 275, 5346, 77, 16567, 14, 1002, 10921, 11232, 334, 5713, 1610, 12, 15292, 63, 6885, 9, 199, 198, 23200, 275, 13964, 18845, 14, 15711, 14, 1002, 5810, 985, 334, 4240, 77, 16567, 14, 1002, 10921, 11232, 334, 5713, 1610, 12, 15292, 63, 40, 649, 7217, 51, 430, 327, 4681, 66, 15289, 11176, 421, 198, 14591, 3186, 275, 5346, 77, 16567, 14, 6200, 3186, 480, 6065, 1224, 531, 199, 198, 14591, 3186, 985, 275, 1804, 390, 3186, 14, 9334, 8, 23200, 12, 3898, 301, 985, 9, 199, 198, 14591, 3186, 275, 5346, 77, 16567, 14, 6200, 3186, 8, 14591, 3186, 985, 12, 17, 9, 421, 198, 51, 15089, 1296, 275, 5346, 77, 16567, 14, 6200, 3186, 480, 960, 15820, 531, 421, 198, 3, 16990, 365, 282, 4539, 631, 333, 474, 4353, 12, 1325, 652, 365, 14905, 370, 675, 199, 198, 3, 1589, 1021, 1022, 390, 4353, 367, 3865, 199, 198, 14591, 4301, 275, 5346, 77, 16567, 14, 6200, 4301, 8, 1081, 9, 199, 198, 692, 8089, 998, 508, 413, 26, 507, 198, 4314, 275, 1804, 390, 4301, 14, 1002, 3717, 8, 16, 3581, 4717, 70, 9, 507, 198, 4314, 14, 1084, 1872, 8, 16447, 9, 421, 198, 509, 284, 315, 1425, 8, 709, 304, 507, 198, 692, 284, 28, 20, 26, 686, 198, 4259, 275, 1804, 390, 4301, 14, 1002, 3717, 8, 73, 11, 17, 9, 507, 198, 2836, 26, 686, 198, 4259, 275, 1804, 390, 4301, 14, 1002, 3717, 8, 73, 11, 21, 9, 507, 198, 4259, 14, 1084, 2223, 8, 4332, 63, 14438, 63, 13272, 63, 16205, 9, 507, 198, 4259, 14, 1084, 6381, 8, 4332, 63, 14438, 63, 13272, 63, 19662, 2090, 13272, 12, 9827, 63, 726, 9, 421, 198, 692, 440, 1804, 390, 3186, 26, 327, 308, 269, 301, 3859, 503, 3485, 75, 507, 198, 5810, 2353, 275, 413, 199, 198, 2836, 26, 507, 198, 692, 8089, 998, 508, 413, 26, 327, 333, 7441, 686, 198, 5810, 2353, 275, 428, 15089, 1296, 14, 1002, 5810, 2353, 342, 507, 198, 2836, 26, 686, 198, 5810, 2353, 275, 1804, 390, 3186, 14, 1002, 5810, 2353, 342, 421, 198, 6105, 2681, 275, 378, 199, 198, 4240, 77, 16567, 14, 1084, 5894, 480, 6105, 2681, 401, 378, 9, 199, 198, 692, 3447, 14666, 14438, 26, 507, 198, 2791, 5810, 2353, 275, 15231, 2353, 507, 198, 692, 15231, 2353, 30, 709, 26, 327, 981, 4119, 1022, 390, 5528, 686, 198, 14591, 4301, 14, 2499, 4259, 334, 1046, 12, 6155, 12, 16074, 12, 499, 3172, 12, 3388, 9, 686, 198, 2911, 6065, 275, 1804, 390, 4301, 14, 1002, 3717, 8, 1046, 9, 686, 198, 2911, 6065, 14, 1084, 2223, 8, 4332, 63, 14438, 63, 13272, 63, 16205, 9, 686, 198, 2911, 6065, 14, 1084, 6381, 8, 4332, 63, 14438, 63, 13272, 63, 19662, 2090, 13272, 12, 9827, 63, 726, 9, 686, 198, 2911, 6065, 14, 1084, 51, 21483, 480, 17188, 948, 39, 6265, 401, 16, 12, 378, 12, 17, 12, 18, 12, 19, 9, 686, 198, 5810, 2353, 275, 4119, 507, 198, 692, 3529, 5810, 2353, 30, 845, 26, 327, 981, 13704, 4681, 686, 198, 14591, 4301, 14, 2499, 13127, 5281, 8, 5279, 12, 499, 2710, 12, 5238, 12, 3193, 12, 25647,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
CYBAI/servo
tests/wpt/web-platform-tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_static.py
28
2527
import unittest from ..backends import static # There aren't many tests here because it turns out to be way more convenient to # use test_serializer for the majority of cases class TestStatic(unittest.TestCase): def compile(self, input_text, input_data): return static.compile(input_text, input_data) def test_get_0(self): data = b""" key: value [Heading 1] other_key: if a == 1: value_1 if a == 2: value_2 value_3 """ manifest = self.compile(data, {"a": 2}) self.assertEqual(manifest.get("key"), "value") children = list(item for item in manifest.iterchildren()) self.assertEqual(len(children), 1) section = children[0] self.assertEqual(section.name, "Heading 1") self.assertEqual(section.get("other_key"), "value_2") self.assertEqual(section.get("key"), "value") def test_get_1(self): data = b""" key: value [Heading 1] other_key: if a == 1: value_1 if a == 2: value_2 value_3 """ manifest = self.compile(data, {"a": 3}) children = list(item for item in manifest.iterchildren()) section = children[0] self.assertEqual(section.get("other_key"), "value_3") def test_get_3(self): data = b"""key: if a == "1": value_1 if a[0] == "ab"[0]: value_2 """ manifest = self.compile(data, {"a": "1"}) self.assertEqual(manifest.get("key"), "value_1") manifest = self.compile(data, {"a": "ac"}) self.assertEqual(manifest.get("key"), "value_2") def test_get_4(self): data = b"""key: if not a: value_1 value_2 """ manifest = self.compile(data, {"a": True}) self.assertEqual(manifest.get("key"), "value_2") manifest = self.compile(data, {"a": False}) self.assertEqual(manifest.get("key"), "value_1") def test_api(self): data = b"""key: if a == 1.5: value_1 value_2 key_1: other_value """ manifest = self.compile(data, {"a": 1.5}) self.assertFalse(manifest.is_empty) self.assertEqual(manifest.root, manifest) self.assertTrue(manifest.has_key("key_1")) self.assertFalse(manifest.has_key("key_2")) self.assertEqual(set(manifest.iterkeys()), {"key", "key_1"}) self.assertEqual(set(manifest.itervalues()), {"value_1", "other_value"}) def test_is_empty_1(self): data = b""" [Section] [Subsection] """ manifest = self.compile(data, {}) self.assertTrue(manifest.is_empty)
mpl-2.0
[ 646, 2882, 199, 199, 504, 2508, 7765, 492, 2955, 199, 199, 3, 6006, 10621, 1133, 5002, 2295, 2348, 2952, 652, 25449, 734, 370, 506, 4340, 1655, 22700, 370, 199, 3, 675, 511, 63, 8349, 367, 314, 610, 74, 3822, 402, 5560, 421, 199, 533, 1379, 9278, 8, 2796, 14, 1746, 304, 272, 347, 6555, 8, 277, 12, 1324, 63, 505, 12, 1324, 63, 576, 304, 267, 372, 2955, 14, 2014, 8, 1210, 63, 505, 12, 1324, 63, 576, 9, 339, 347, 511, 63, 362, 63, 16, 8, 277, 304, 267, 666, 275, 330, 624, 199, 498, 26, 574, 199, 199, 59, 23818, 413, 61, 523, 1163, 63, 498, 26, 272, 340, 282, 508, 413, 26, 574, 63, 17, 272, 340, 282, 508, 499, 26, 574, 63, 18, 272, 574, 63, 19, 199, 624, 398, 7712, 275, 291, 14, 2014, 8, 576, 12, 2420, 65, 582, 499, 1552, 398, 291, 14, 629, 8, 6418, 14, 362, 480, 498, 1288, 298, 585, 531, 267, 4978, 275, 769, 8, 1053, 367, 1242, 315, 7712, 14, 1661, 3223, 1012, 267, 291, 14, 629, 8, 552, 8, 3223, 395, 413, 9, 267, 3420, 275, 4978, 59, 16, 61, 267, 291, 14, 629, 8, 2792, 14, 354, 12, 298, 23818, 413, 531, 398, 291, 14, 629, 8, 2792, 14, 362, 480, 1848, 63, 498, 1288, 298, 585, 63, 18, 531, 267, 291, 14, 629, 8, 2792, 14, 362, 480, 498, 1288, 298, 585, 531, 339, 347, 511, 63, 362, 63, 17, 8, 277, 304, 267, 666, 275, 330, 624, 199, 498, 26, 574, 199, 199, 59, 23818, 413, 61, 523, 1163, 63, 498, 26, 272, 340, 282, 508, 413, 26, 574, 63, 17, 272, 340, 282, 508, 499, 26, 574, 63, 18, 272, 574, 63, 19, 199, 624, 267, 7712, 275, 291, 14, 2014, 8, 576, 12, 2420, 65, 582, 650, 1552, 398, 4978, 275, 769, 8, 1053, 367, 1242, 315, 7712, 14, 1661, 3223, 1012, 267, 3420, 275, 4978, 59, 16, 61, 267, 291, 14, 629, 8, 2792, 14, 362, 480, 1848, 63, 498, 1288, 298, 585, 63, 19, 531, 339, 347, 511, 63, 362, 63, 19, 8, 277, 304, 267, 666, 275, 330, 624, 498, 26, 523, 340, 282, 508, 298, 17, 582, 574, 63, 17, 523, 340, 282, 59, 16, 61, 508, 298, 371, 22774, 16, 2189, 574, 63, 18, 199, 624, 267, 7712, 275, 291, 14, 2014, 8, 576, 12, 2420, 65, 582, 298, 17, 5984, 267, 291, 14, 629, 8, 6418, 14, 362, 480, 498, 1288, 298, 585, 63, 17, 531, 398, 7712, 275, 291, 14, 2014, 8, 576, 12, 2420, 65, 582, 298, 645, 5984, 267, 291, 14, 629, 8, 6418, 14, 362, 480, 498, 1288, 298, 585, 63, 18, 531, 339, 347, 511, 63, 362, 63, 20, 8, 277, 304, 267, 666, 275, 330, 624, 498, 26, 523, 340, 440, 282, 26, 574, 63, 17, 523, 574, 63, 18, 199, 624, 267, 7712, 275, 291, 14, 2014, 8, 576, 12, 2420, 65, 582, 715, 1552, 267, 291, 14, 629, 8, 6418, 14, 362, 480, 498, 1288, 298, 585, 63, 18, 531, 398, 7712, 275, 291, 14, 2014, 8, 576, 12, 2420, 65, 582, 756, 1552, 267, 291, 14, 629, 8, 6418, 14, 362, 480, 498, 1288, 298, 585, 63, 17, 531, 339, 347, 511, 63, 1246, 8, 277, 304, 267, 666, 275, 330, 624, 498, 26, 523, 340, 282, 508, 413, 14, 21, 26, 574, 63, 17, 523, 574, 63, 18, 199, 498, 63, 17, 26, 1163, 63, 585, 199, 624, 267, 7712, 275, 291, 14, 2014, 8, 576, 12, 2420, 65, 582, 413, 14, 21, 1552, 398, 291, 14, 3334, 8, 6418, 14, 374, 63, 1667, 9, 267, 291, 14, 629, 8, 6418, 14, 1231, 12, 7712, 9, 267, 291, 14, 1815, 8, 6418, 14, 1989, 63, 498, 480, 498, 63, 17, 2237, 267, 291, 14, 3334, 8, 6418, 14, 1989, 63, 498, 480, 498, 63, 18, 2237, 398, 291, 14, 629, 8, 409, 8, 6418, 14, 16007, 4000, 2420, 498, 401, 298, 498, 63, 17, 5984, 267, 291, 14, 629, 8, 409, 8, 6418, 14, 13012, 4000, 2420, 585, 63, 17, 401, 298, 1848, 63, 585, 5984, 339, 347, 511, 63, 374, 63, 1667, 63, 17, 8, 277, 304, 267, 666, 275, 330, 624, 199, 59, 8660, 61, 523, 359, 31839, 61, 199, 624, 267, 7712, 275, 291, 14, 2014, 8, 576, 12, 5009, 398, 291, 14, 1815, 8, 6418, 14, 374, 63, 1667, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2882, 199, 199, 504, 2508, 7765, 492, 2955, 199, 199, 3, 6006, 10621, 1133, 5002, 2295, 2348, 2952, 652, 25449, 734, 370, 506, 4340, 1655, 22700, 370, 199, 3, 675, 511, 63, 8349, 367, 314, 610, 74, 3822, 402, 5560, 421, 199, 533, 1379, 9278, 8, 2796, 14, 1746, 304, 272, 347, 6555, 8, 277, 12, 1324, 63, 505, 12, 1324, 63, 576, 304, 267, 372, 2955, 14, 2014, 8, 1210, 63, 505, 12, 1324, 63, 576, 9, 339, 347, 511, 63, 362, 63, 16, 8, 277, 304, 267, 666, 275, 330, 624, 199, 498, 26, 574, 199, 199, 59, 23818, 413, 61, 523, 1163, 63, 498, 26, 272, 340, 282, 508, 413, 26, 574, 63, 17, 272, 340, 282, 508, 499, 26, 574, 63, 18, 272, 574, 63, 19, 199, 624, 398, 7712, 275, 291, 14, 2014, 8, 576, 12, 2420, 65, 582, 499, 1552, 398, 291, 14, 629, 8, 6418, 14, 362, 480, 498, 1288, 298, 585, 531, 267, 4978, 275, 769, 8, 1053, 367, 1242, 315, 7712, 14, 1661, 3223, 1012, 267, 291, 14, 629, 8, 552, 8, 3223, 395, 413, 9, 267, 3420, 275, 4978, 59, 16, 61, 267, 291, 14, 629, 8, 2792, 14, 354, 12, 298, 23818, 413, 531, 398, 291, 14, 629, 8, 2792, 14, 362, 480, 1848, 63, 498, 1288, 298, 585, 63, 18, 531, 267, 291, 14, 629, 8, 2792, 14, 362, 480, 498, 1288, 298, 585, 531, 339, 347, 511, 63, 362, 63, 17, 8, 277, 304, 267, 666, 275, 330, 624, 199, 498, 26, 574, 199, 199, 59, 23818, 413, 61, 523, 1163, 63, 498, 26, 272, 340, 282, 508, 413, 26, 574, 63, 17, 272, 340, 282, 508, 499, 26, 574, 63, 18, 272, 574, 63, 19, 199, 624, 267, 7712, 275, 291, 14, 2014, 8, 576, 12, 2420, 65, 582, 650, 1552, 398, 4978, 275, 769, 8, 1053, 367, 1242, 315, 7712, 14, 1661, 3223, 1012, 267, 3420, 275, 4978, 59, 16, 61, 267, 291, 14, 629, 8, 2792, 14, 362, 480, 1848, 63, 498, 1288, 298, 585, 63, 19, 531, 339, 347, 511, 63, 362, 63, 19, 8, 277, 304, 267, 666, 275, 330, 624, 498, 26, 523, 340, 282, 508, 298, 17, 582, 574, 63, 17, 523, 340, 282, 59, 16, 61, 508, 298, 371, 22774, 16, 2189, 574, 63, 18, 199, 624, 267, 7712, 275, 291, 14, 2014, 8, 576, 12, 2420, 65, 582, 298, 17, 5984, 267, 291, 14, 629, 8, 6418, 14, 362, 480, 498, 1288, 298, 585, 63, 17, 531, 398, 7712, 275, 291, 14, 2014, 8, 576, 12, 2420, 65, 582, 298, 645, 5984, 267, 291, 14, 629, 8, 6418, 14, 362, 480, 498, 1288, 298, 585, 63, 18, 531, 339, 347, 511, 63, 362, 63, 20, 8, 277, 304, 267, 666, 275, 330, 624, 498, 26, 523, 340, 440, 282, 26, 574, 63, 17, 523, 574, 63, 18, 199, 624, 267, 7712, 275, 291, 14, 2014, 8, 576, 12, 2420, 65, 582, 715, 1552, 267, 291, 14, 629, 8, 6418, 14, 362, 480, 498, 1288, 298, 585, 63, 18, 531, 398, 7712, 275, 291, 14, 2014, 8, 576, 12, 2420, 65, 582, 756, 1552, 267, 291, 14, 629, 8, 6418, 14, 362, 480, 498, 1288, 298, 585, 63, 17, 531, 339, 347, 511, 63, 1246, 8, 277, 304, 267, 666, 275, 330, 624, 498, 26, 523, 340, 282, 508, 413, 14, 21, 26, 574, 63, 17, 523, 574, 63, 18, 199, 498, 63, 17, 26, 1163, 63, 585, 199, 624, 267, 7712, 275, 291, 14, 2014, 8, 576, 12, 2420, 65, 582, 413, 14, 21, 1552, 398, 291, 14, 3334, 8, 6418, 14, 374, 63, 1667, 9, 267, 291, 14, 629, 8, 6418, 14, 1231, 12, 7712, 9, 267, 291, 14, 1815, 8, 6418, 14, 1989, 63, 498, 480, 498, 63, 17, 2237, 267, 291, 14, 3334, 8, 6418, 14, 1989, 63, 498, 480, 498, 63, 18, 2237, 398, 291, 14, 629, 8, 409, 8, 6418, 14, 16007, 4000, 2420, 498, 401, 298, 498, 63, 17, 5984, 267, 291, 14, 629, 8, 409, 8, 6418, 14, 13012, 4000, 2420, 585, 63, 17, 401, 298, 1848, 63, 585, 5984, 339, 347, 511, 63, 374, 63, 1667, 63, 17, 8, 277, 304, 267, 666, 275, 330, 624, 199, 59, 8660, 61, 523, 359, 31839, 61, 199, 624, 267, 7712, 275, 291, 14, 2014, 8, 576, 12, 5009, 398, 291, 14, 1815, 8, 6418, 14, 374, 63, 1667, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
nvbn/python-social-auth
social/backends/yammer.py
3
1364
""" Yammer OAuth2 support """ from social.backends.oauth import BaseOAuth2 class YammerOAuth2(BaseOAuth2): name = 'yammer' AUTHORIZATION_URL = 'https://www.yammer.com/dialog/oauth' ACCESS_TOKEN_URL = 'https://www.yammer.com/oauth2/access_token' EXTRA_DATA = [ ('id', 'id'), ('expires', 'expires'), ('mugshot_url', 'mugshot_url') ] def get_user_id(self, details, response): return response['user']['id'] def get_user_details(self, response): username = response['user']['name'] first_name = response['user']['first_name'] last_name = response['user']['last_name'] full_name = response['user']['full_name'] email = response['user']['contact']['email_addresses'][0]['address'] mugshot_url = response['user']['mugshot_url'] return { 'username': username, 'email': email, 'fullname': full_name, 'first_name': first_name, 'last_name': last_name, 'picture_url': mugshot_url } class YammerStagingOAuth2(YammerOAuth2): name = 'yammer-staging' AUTHORIZATION_URL = 'https://www.staging.yammer.com/dialog/oauth' ACCESS_TOKEN_URL = 'https://www.staging.yammer.com/oauth2/access_token' REQUEST_TOKEN_URL = 'https://www.staging.yammer.com/oauth2/request_token'
bsd-3-clause
[ 624, 199, 57, 455, 2626, 11715, 18, 2291, 199, 624, 199, 504, 20295, 14, 7765, 14, 6126, 492, 3523, 12906, 18, 421, 199, 533, 1488, 455, 2626, 12906, 18, 8, 1563, 12906, 18, 304, 272, 536, 275, 283, 89, 455, 2626, 7, 272, 7560, 7123, 2594, 63, 2632, 275, 283, 2859, 921, 1544, 14, 89, 455, 2626, 14, 957, 15, 7196, 15, 6126, 7, 272, 437, 10203, 63, 8803, 63, 2632, 275, 283, 2859, 921, 1544, 14, 89, 455, 2626, 14, 957, 15, 6126, 18, 15, 2732, 63, 1418, 7, 272, 3651, 13954, 63, 3998, 275, 359, 267, 661, 344, 297, 283, 344, 659, 267, 661, 12342, 297, 283, 12342, 659, 267, 661, 6553, 458, 8885, 63, 633, 297, 283, 6553, 458, 8885, 63, 633, 358, 272, 1622, 339, 347, 664, 63, 751, 63, 344, 8, 277, 12, 2436, 12, 1177, 304, 267, 372, 1177, 459, 751, 2545, 344, 418, 339, 347, 664, 63, 751, 63, 5087, 8, 277, 12, 1177, 304, 267, 3434, 275, 1177, 459, 751, 2545, 354, 418, 267, 1642, 63, 354, 275, 1177, 459, 751, 2545, 2246, 63, 354, 418, 267, 2061, 63, 354, 275, 1177, 459, 751, 2545, 2019, 63, 354, 418, 267, 2615, 63, 354, 275, 1177, 459, 751, 2545, 2861, 63, 354, 418, 267, 3031, 275, 1177, 459, 751, 2545, 7811, 2545, 2123, 63, 7423, 3488, 16, 2733, 1562, 418, 267, 8504, 458, 8885, 63, 633, 275, 1177, 459, 751, 2545, 6553, 458, 8885, 63, 633, 418, 267, 372, 469, 288, 283, 2473, 356, 3434, 12, 288, 283, 2123, 356, 3031, 12, 288, 283, 9930, 356, 2615, 63, 354, 12, 288, 283, 2246, 63, 354, 356, 1642, 63, 354, 12, 288, 283, 2019, 63, 354, 356, 2061, 63, 354, 12, 288, 283, 12538, 63, 633, 356, 8504, 458, 8885, 63, 633, 267, 789, 421, 199, 533, 1488, 455, 2626, 51, 1450, 316, 12906, 18, 8, 57, 455, 2626, 12906, 18, 304, 272, 536, 275, 283, 89, 455, 2626, 13, 26840, 7, 272, 7560, 7123, 2594, 63, 2632, 275, 283, 2859, 921, 1544, 14, 26840, 14, 89, 455, 2626, 14, 957, 15, 7196, 15, 6126, 7, 272, 437, 10203, 63, 8803, 63, 2632, 275, 283, 2859, 921, 1544, 14, 26840, 14, 89, 455, 2626, 14, 957, 15, 6126, 18, 15, 2732, 63, 1418, 7, 272, 31325, 63, 8803, 63, 2632, 275, 283, 2859, 921, 1544, 14, 26840, 14, 89, 455, 2626, 14, 957, 15, 6126, 18, 15, 1069, 63, 1418, 7, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 199, 57, 455, 2626, 11715, 18, 2291, 199, 624, 199, 504, 20295, 14, 7765, 14, 6126, 492, 3523, 12906, 18, 421, 199, 533, 1488, 455, 2626, 12906, 18, 8, 1563, 12906, 18, 304, 272, 536, 275, 283, 89, 455, 2626, 7, 272, 7560, 7123, 2594, 63, 2632, 275, 283, 2859, 921, 1544, 14, 89, 455, 2626, 14, 957, 15, 7196, 15, 6126, 7, 272, 437, 10203, 63, 8803, 63, 2632, 275, 283, 2859, 921, 1544, 14, 89, 455, 2626, 14, 957, 15, 6126, 18, 15, 2732, 63, 1418, 7, 272, 3651, 13954, 63, 3998, 275, 359, 267, 661, 344, 297, 283, 344, 659, 267, 661, 12342, 297, 283, 12342, 659, 267, 661, 6553, 458, 8885, 63, 633, 297, 283, 6553, 458, 8885, 63, 633, 358, 272, 1622, 339, 347, 664, 63, 751, 63, 344, 8, 277, 12, 2436, 12, 1177, 304, 267, 372, 1177, 459, 751, 2545, 344, 418, 339, 347, 664, 63, 751, 63, 5087, 8, 277, 12, 1177, 304, 267, 3434, 275, 1177, 459, 751, 2545, 354, 418, 267, 1642, 63, 354, 275, 1177, 459, 751, 2545, 2246, 63, 354, 418, 267, 2061, 63, 354, 275, 1177, 459, 751, 2545, 2019, 63, 354, 418, 267, 2615, 63, 354, 275, 1177, 459, 751, 2545, 2861, 63, 354, 418, 267, 3031, 275, 1177, 459, 751, 2545, 7811, 2545, 2123, 63, 7423, 3488, 16, 2733, 1562, 418, 267, 8504, 458, 8885, 63, 633, 275, 1177, 459, 751, 2545, 6553, 458, 8885, 63, 633, 418, 267, 372, 469, 288, 283, 2473, 356, 3434, 12, 288, 283, 2123, 356, 3031, 12, 288, 283, 9930, 356, 2615, 63, 354, 12, 288, 283, 2246, 63, 354, 356, 1642, 63, 354, 12, 288, 283, 2019, 63, 354, 356, 2061, 63, 354, 12, 288, 283, 12538, 63, 633, 356, 8504, 458, 8885, 63, 633, 267, 789, 421, 199, 533, 1488, 455, 2626, 51, 1450, 316, 12906, 18, 8, 57, 455, 2626, 12906, 18, 304, 272, 536, 275, 283, 89, 455, 2626, 13, 26840, 7, 272, 7560, 7123, 2594, 63, 2632, 275, 283, 2859, 921, 1544, 14, 26840, 14, 89, 455, 2626, 14, 957, 15, 7196, 15, 6126, 7, 272, 437, 10203, 63, 8803, 63, 2632, 275, 283, 2859, 921, 1544, 14, 26840, 14, 89, 455, 2626, 14, 957, 15, 6126, 18, 15, 2732, 63, 1418, 7, 272, 31325, 63, 8803, 63, 2632, 275, 283, 2859, 921, 1544, 14, 26840, 14, 89, 455, 2626, 14, 957, 15, 6126, 18, 15, 1069, 63, 1418, 7, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
mr-ping/WebTesting
main.py
1
5059
#!/usr/bin/python import os import sys import argparse from log import Log from chat import Trend from chat import plot_trend as pl from settings import * def parse_args(): """ Parsing shell command arguments, and override appropriate params from setting module :return: None """ parser = argparse.ArgumentParser(version=VERSION) parser.add_argument('-u', action='store', dest='url') parser.add_argument('-f', action='store', dest='url_file') parser.add_argument('-t', action='store', dest='target_log_file') parser.add_argument('-l', action='store', dest='log_file') parser.add_argument('-p', action='store_true', dest='plotting', default=True) parser.add_argument('-m', action='store', dest='max_allowed_concurrent', type=int) parser.add_argument('-b', action='store', dest='base_concurrent', type=int) parser.add_argument('-s', action='store', dest='step_concurrent', type=int) result = parser.parse_args() if result.url: global url url = result.url if result.url_file: global url_file url_file = result.url_file if result.target_log_file: global target_file target_file = result.target_log_file if result.log_file: global log_file log_file = result.log_file if result.plotting: global plotting plotting = result.plotting if result.max_allowed_concurrent: global max_concurrent max_concurrent = result.max_allowed_concurrent if result.base_concurrent: global base_concurrent base_concurrent = result.base_concurrent if result.step_concurrent: global step_concurrent step_concurrent = result.step_concurrent def check_url_source(): """ Check out Obtaining url from commend line or urls file. :return: A flag that represent the source of urls. String' """ global plotting if not url_file and not url: plotting = False sys.stderr.write('You should figure out the url source.') elif url_file and url: plotting = False sys.stderr.write('Url source come from either url address or url file') elif url_file: exist = os.path.exists(url_file) if exist: return 'file' else: plotting = False sys.stderr.write('No such urls file.') elif url: return 'address' def test(base_concurrent): """ Main method to do the Testing. Looping siege tool until some conditions satisfied, and generate a new log file from siege log file. :param base_concurrent: number concurrent :return: None """ url_source = check_url_source() while True: for i in range(num_samples): if url_source == 'address': #os.system('siege -c {concurrent} -t {duration} -l {address}'\ os.system('siege -c {concurrent} -r {repeat} -l {address}'\ .format(address=url, concurrent=base_concurrent, #duration=duration)) repeat=repeat)) elif url_source == 'file': #os.system('siege -c {concurrent} -t {duration} -f {url_file} -l'\ os.system('siege -c {concurrent} -r {repeat} -f {url_file} -l'\ .format(url_file=url_file, concurrent=base_concurrent, #duration=duration)) repeat=repeat)) last = Log.get_last_logs(log_file, siege_log_line_length, 1,\ base_concurrent) Log.add_new_log(target_file, last) base_concurrent += step_concurrent log = Log(target_file) if log.get_last_arrive_rate(num_samples) < (1-fails_allowed) \ or base_concurrent > max_concurrent: break def plot(): """ Plotting chat using the data that analyzed from testing log. :return: None """ log = Log(target_file) trans_rate_dict = log.get_steps_trans_rate() arrive_rate_dict = log.get_steps_arrive_rate() resp_time_dict = log.get_steps_resp_time() trans_trend = Trend('Transaction Rate', 'simulated users', 'trans rate (trans/sec)', 'g', 1, 'bar', step_concurrent/2) trans_trend.get_points(trans_rate_dict) arrive_trend = Trend('Arrive Rate', 'simulated users', 'arrive rate', 'g', 2, 'line') arrive_trend.get_points(arrive_rate_dict) resp_trend = Trend('Resp Time', 'simulated users', 'time(sec)', 'r', 2, 'line') resp_trend.get_points(resp_time_dict) pl(trans_trend, resp_trend, arrive_trend) if __name__ == '__main__': parse_args() test(base_concurrent) if plotting: plot()
mit
[ 3381, 2647, 15, 1393, 15, 1548, 199, 646, 747, 199, 646, 984, 199, 646, 7534, 199, 199, 504, 943, 492, 5297, 199, 504, 21472, 492, 377, 16479, 199, 504, 21472, 492, 5137, 63, 84, 16479, 465, 1620, 199, 504, 2202, 492, 627, 421, 199, 318, 2198, 63, 589, 837, 272, 408, 272, 28747, 5218, 1414, 2368, 12, 436, 4278, 5827, 1862, 272, 687, 4260, 859, 339, 520, 1107, 26, 488, 272, 408, 272, 1798, 275, 7534, 14, 10730, 8, 1023, 29, 4612, 9, 272, 1798, 14, 525, 63, 2094, 3654, 85, 297, 1595, 534, 1617, 297, 2053, 534, 633, 358, 272, 1798, 14, 525, 63, 2094, 3654, 70, 297, 1595, 534, 1617, 297, 2053, 534, 633, 63, 493, 358, 272, 1798, 14, 525, 63, 2094, 3654, 84, 297, 1595, 534, 1617, 297, 2053, 534, 1375, 63, 793, 63, 493, 358, 272, 1798, 14, 525, 63, 2094, 3654, 76, 297, 1595, 534, 1617, 297, 2053, 534, 793, 63, 493, 358, 272, 1798, 14, 525, 63, 2094, 3654, 80, 297, 1595, 534, 1617, 63, 2052, 297, 2053, 534, 2798, 1337, 297, 849, 29, 549, 9, 272, 1798, 14, 525, 63, 2094, 3654, 77, 297, 1595, 534, 1617, 297, 2053, 534, 988, 63, 6541, 63, 27237, 297, 730, 29, 442, 9, 272, 1798, 14, 525, 63, 2094, 3654, 66, 297, 1595, 534, 1617, 297, 2053, 534, 1095, 63, 27237, 297, 730, 29, 442, 9, 272, 1798, 14, 525, 63, 2094, 3654, 83, 297, 1595, 534, 1617, 297, 2053, 534, 2926, 63, 27237, 297, 730, 29, 442, 9, 339, 754, 275, 1798, 14, 1122, 63, 589, 342, 339, 340, 754, 14, 633, 26, 267, 2288, 1166, 267, 1166, 275, 754, 14, 633, 272, 340, 754, 14, 633, 63, 493, 26, 267, 2288, 1166, 63, 493, 267, 1166, 63, 493, 275, 754, 14, 633, 63, 493, 272, 340, 754, 14, 1375, 63, 793, 63, 493, 26, 267, 2288, 1347, 63, 493, 267, 1347, 63, 493, 275, 754, 14, 1375, 63, 793, 63, 493, 272, 340, 754, 14, 793, 63, 493, 26, 267, 2288, 943, 63, 493, 267, 943, 63, 493, 275, 754, 14, 793, 63, 493, 272, 340, 754, 14, 2798, 1337, 26, 267, 2288, 25174, 267, 25174, 275, 754, 14, 2798, 1337, 272, 340, 754, 14, 988, 63, 6541, 63, 27237, 26, 267, 2288, 1390, 63, 27237, 267, 1390, 63, 27237, 275, 754, 14, 988, 63, 6541, 63, 27237, 272, 340, 754, 14, 1095, 63, 27237, 26, 267, 2288, 1300, 63, 27237, 267, 1300, 63, 27237, 275, 754, 14, 1095, 63, 27237, 272, 340, 754, 14, 2926, 63, 27237, 26, 267, 2288, 3650, 63, 27237, 267, 3650, 63, 27237, 275, 754, 14, 2926, 63, 27237, 4388, 199, 318, 1104, 63, 633, 63, 1365, 837, 272, 408, 272, 2670, 734, 17985, 24522, 1166, 687, 2414, 13419, 1004, 503, 8187, 570, 14, 339, 520, 1107, 26, 437, 3305, 626, 2954, 314, 1350, 402, 8187, 14, 2624, 7, 272, 408, 272, 2288, 25174, 272, 340, 440, 1166, 63, 493, 436, 440, 1166, 26, 267, 25174, 275, 756, 267, 984, 14, 3083, 14, 952, 360, 5556, 1077, 9658, 734, 314, 1166, 1350, 2659, 272, 916, 1166, 63, 493, 436, 1166, 26, 267, 25174, 275, 756, 267, 984, 14, 3083, 14, 952, 360, 6417, 1350, 11492, 687, 1902, 1166, 2287, 503, 1166, 570, 358, 272, 916, 1166, 63, 493, 26, 267, 2187, 275, 747, 14, 515, 14, 2444, 8, 633, 63, 493, 9, 267, 340, 2187, 26, 288, 372, 283, 493, 7, 267, 587, 26, 288, 25174, 275, 756, 288, 984, 14, 3083, 14, 952, 360, 1944, 4066, 8187, 570, 2659, 272, 916, 1166, 26, 267, 372, 283, 1562, 7, 421, 199, 318, 511, 8, 1095, 63, 27237, 304, 272, 408, 272, 11298, 1083, 370, 886, 314, 11940, 14, 272, 18175, 316, 308, 1873, 303, 4744, 5133, 2005, 3704, 23233, 12, 272, 436, 3550, 282, 892, 943, 570, 687, 308, 1873, 303, 943, 570, 14, 339, 520, 635, 1300, 63, 27237, 26, 1329, 23002, 272, 520, 1107, 26, 488, 272, 408, 272, 1166, 63, 1365, 275, 1104, 63, 633, 63, 1365, 342, 272, 1830, 715, 26, 267, 367, 284, 315, 1425, 8, 1507, 63, 3356, 304, 288, 340, 1166, 63, 1365, 508, 283, 1562, 356, 355, 327, 736, 14, 2253, 360, 23994, 303, 446, 67, 469, 27237, 93, 446, 84, 469, 5553, 93, 446, 76, 469, 1562, 93, 1154, 355, 747, 14, 2253, 360, 23994, 303, 446, 67, 469, 27237, 93, 446, 82, 469, 8755, 93, 446, 76, 469, 1562, 93, 1154, 717, 1275, 908, 8, 1562, 29, 633, 12, 1816, 23002, 29, 1095, 63, 27237, 12, 1816, 327, 5553, 29, 5553, 430, 1816, 11982, 29, 8755, 430, 288, 916, 1166, 63, 1365, 508, 283, 493, 356, 355, 327, 736, 14, 2253, 360, 23994, 303, 446, 67, 469, 27237, 93, 446, 84, 469, 5553, 93, 446, 70, 469, 633, 63, 493, 93, 446, 76, 1154, 355, 747, 14, 2253, 360, 23994, 303, 446, 67, 469, 27237, 93, 446, 82, 469, 8755, 93, 446, 70, 469, 633, 63, 493, 93, 446, 76, 1154, 717, 1275, 908, 8, 633, 63, 493, 29, 633, 63, 493, 12, 1816, 23002, 29, 1095, 63, 27237, 12, 1816, 327, 5553, 29, 5553, 430, 1816, 11982, 29, 8755, 430, 288, 2061, 275, 5297, 14, 362, 63, 2019, 63, 7270, 8, 793, 63, 493, 12, 308, 1873, 303, 63, 793, 63, 604, 63, 1267, 12, 413, 4202, 490, 1300, 63, 27237, 9, 288, 5297, 14, 525, 63, 1222, 63, 793, 8, 1375, 63, 493, 12, 2061, 9, 398, 1300, 63, 27237, 847, 3650, 63, 27237, 398, 943, 275, 5297, 8, 1375, 63, 493, 9, 267, 340, 943, 14, 362, 63, 2019, 63, 285, 6053, 63, 1866, 8, 1507, 63, 3356, 9, 665, 334, 17, 13, 15762, 63, 6541, 9, 971, 355, 503, 1300, 63, 27237, 690, 1390, 63, 27237, 26, 288, 2059, 199, 199, 318, 5137, 837, 272, 408, 272, 14794, 1337, 21472, 1808, 314, 666, 626, 5909, 7068, 687, 5343, 943, 14, 339, 520, 1107, 26, 488, 272, 408, 272, 943, 275, 5297, 8, 1375, 63, 493, 9, 272, 1752, 63, 1866, 63, 807, 275, 943, 14, 362, 63, 5895, 63, 1515, 63, 1866, 342, 272, 601, 6053, 63, 1866 ]
[ 2647, 15, 1393, 15, 1548, 199, 646, 747, 199, 646, 984, 199, 646, 7534, 199, 199, 504, 943, 492, 5297, 199, 504, 21472, 492, 377, 16479, 199, 504, 21472, 492, 5137, 63, 84, 16479, 465, 1620, 199, 504, 2202, 492, 627, 421, 199, 318, 2198, 63, 589, 837, 272, 408, 272, 28747, 5218, 1414, 2368, 12, 436, 4278, 5827, 1862, 272, 687, 4260, 859, 339, 520, 1107, 26, 488, 272, 408, 272, 1798, 275, 7534, 14, 10730, 8, 1023, 29, 4612, 9, 272, 1798, 14, 525, 63, 2094, 3654, 85, 297, 1595, 534, 1617, 297, 2053, 534, 633, 358, 272, 1798, 14, 525, 63, 2094, 3654, 70, 297, 1595, 534, 1617, 297, 2053, 534, 633, 63, 493, 358, 272, 1798, 14, 525, 63, 2094, 3654, 84, 297, 1595, 534, 1617, 297, 2053, 534, 1375, 63, 793, 63, 493, 358, 272, 1798, 14, 525, 63, 2094, 3654, 76, 297, 1595, 534, 1617, 297, 2053, 534, 793, 63, 493, 358, 272, 1798, 14, 525, 63, 2094, 3654, 80, 297, 1595, 534, 1617, 63, 2052, 297, 2053, 534, 2798, 1337, 297, 849, 29, 549, 9, 272, 1798, 14, 525, 63, 2094, 3654, 77, 297, 1595, 534, 1617, 297, 2053, 534, 988, 63, 6541, 63, 27237, 297, 730, 29, 442, 9, 272, 1798, 14, 525, 63, 2094, 3654, 66, 297, 1595, 534, 1617, 297, 2053, 534, 1095, 63, 27237, 297, 730, 29, 442, 9, 272, 1798, 14, 525, 63, 2094, 3654, 83, 297, 1595, 534, 1617, 297, 2053, 534, 2926, 63, 27237, 297, 730, 29, 442, 9, 339, 754, 275, 1798, 14, 1122, 63, 589, 342, 339, 340, 754, 14, 633, 26, 267, 2288, 1166, 267, 1166, 275, 754, 14, 633, 272, 340, 754, 14, 633, 63, 493, 26, 267, 2288, 1166, 63, 493, 267, 1166, 63, 493, 275, 754, 14, 633, 63, 493, 272, 340, 754, 14, 1375, 63, 793, 63, 493, 26, 267, 2288, 1347, 63, 493, 267, 1347, 63, 493, 275, 754, 14, 1375, 63, 793, 63, 493, 272, 340, 754, 14, 793, 63, 493, 26, 267, 2288, 943, 63, 493, 267, 943, 63, 493, 275, 754, 14, 793, 63, 493, 272, 340, 754, 14, 2798, 1337, 26, 267, 2288, 25174, 267, 25174, 275, 754, 14, 2798, 1337, 272, 340, 754, 14, 988, 63, 6541, 63, 27237, 26, 267, 2288, 1390, 63, 27237, 267, 1390, 63, 27237, 275, 754, 14, 988, 63, 6541, 63, 27237, 272, 340, 754, 14, 1095, 63, 27237, 26, 267, 2288, 1300, 63, 27237, 267, 1300, 63, 27237, 275, 754, 14, 1095, 63, 27237, 272, 340, 754, 14, 2926, 63, 27237, 26, 267, 2288, 3650, 63, 27237, 267, 3650, 63, 27237, 275, 754, 14, 2926, 63, 27237, 4388, 199, 318, 1104, 63, 633, 63, 1365, 837, 272, 408, 272, 2670, 734, 17985, 24522, 1166, 687, 2414, 13419, 1004, 503, 8187, 570, 14, 339, 520, 1107, 26, 437, 3305, 626, 2954, 314, 1350, 402, 8187, 14, 2624, 7, 272, 408, 272, 2288, 25174, 272, 340, 440, 1166, 63, 493, 436, 440, 1166, 26, 267, 25174, 275, 756, 267, 984, 14, 3083, 14, 952, 360, 5556, 1077, 9658, 734, 314, 1166, 1350, 2659, 272, 916, 1166, 63, 493, 436, 1166, 26, 267, 25174, 275, 756, 267, 984, 14, 3083, 14, 952, 360, 6417, 1350, 11492, 687, 1902, 1166, 2287, 503, 1166, 570, 358, 272, 916, 1166, 63, 493, 26, 267, 2187, 275, 747, 14, 515, 14, 2444, 8, 633, 63, 493, 9, 267, 340, 2187, 26, 288, 372, 283, 493, 7, 267, 587, 26, 288, 25174, 275, 756, 288, 984, 14, 3083, 14, 952, 360, 1944, 4066, 8187, 570, 2659, 272, 916, 1166, 26, 267, 372, 283, 1562, 7, 421, 199, 318, 511, 8, 1095, 63, 27237, 304, 272, 408, 272, 11298, 1083, 370, 886, 314, 11940, 14, 272, 18175, 316, 308, 1873, 303, 4744, 5133, 2005, 3704, 23233, 12, 272, 436, 3550, 282, 892, 943, 570, 687, 308, 1873, 303, 943, 570, 14, 339, 520, 635, 1300, 63, 27237, 26, 1329, 23002, 272, 520, 1107, 26, 488, 272, 408, 272, 1166, 63, 1365, 275, 1104, 63, 633, 63, 1365, 342, 272, 1830, 715, 26, 267, 367, 284, 315, 1425, 8, 1507, 63, 3356, 304, 288, 340, 1166, 63, 1365, 508, 283, 1562, 356, 355, 327, 736, 14, 2253, 360, 23994, 303, 446, 67, 469, 27237, 93, 446, 84, 469, 5553, 93, 446, 76, 469, 1562, 93, 1154, 355, 747, 14, 2253, 360, 23994, 303, 446, 67, 469, 27237, 93, 446, 82, 469, 8755, 93, 446, 76, 469, 1562, 93, 1154, 717, 1275, 908, 8, 1562, 29, 633, 12, 1816, 23002, 29, 1095, 63, 27237, 12, 1816, 327, 5553, 29, 5553, 430, 1816, 11982, 29, 8755, 430, 288, 916, 1166, 63, 1365, 508, 283, 493, 356, 355, 327, 736, 14, 2253, 360, 23994, 303, 446, 67, 469, 27237, 93, 446, 84, 469, 5553, 93, 446, 70, 469, 633, 63, 493, 93, 446, 76, 1154, 355, 747, 14, 2253, 360, 23994, 303, 446, 67, 469, 27237, 93, 446, 82, 469, 8755, 93, 446, 70, 469, 633, 63, 493, 93, 446, 76, 1154, 717, 1275, 908, 8, 633, 63, 493, 29, 633, 63, 493, 12, 1816, 23002, 29, 1095, 63, 27237, 12, 1816, 327, 5553, 29, 5553, 430, 1816, 11982, 29, 8755, 430, 288, 2061, 275, 5297, 14, 362, 63, 2019, 63, 7270, 8, 793, 63, 493, 12, 308, 1873, 303, 63, 793, 63, 604, 63, 1267, 12, 413, 4202, 490, 1300, 63, 27237, 9, 288, 5297, 14, 525, 63, 1222, 63, 793, 8, 1375, 63, 493, 12, 2061, 9, 398, 1300, 63, 27237, 847, 3650, 63, 27237, 398, 943, 275, 5297, 8, 1375, 63, 493, 9, 267, 340, 943, 14, 362, 63, 2019, 63, 285, 6053, 63, 1866, 8, 1507, 63, 3356, 9, 665, 334, 17, 13, 15762, 63, 6541, 9, 971, 355, 503, 1300, 63, 27237, 690, 1390, 63, 27237, 26, 288, 2059, 199, 199, 318, 5137, 837, 272, 408, 272, 14794, 1337, 21472, 1808, 314, 666, 626, 5909, 7068, 687, 5343, 943, 14, 339, 520, 1107, 26, 488, 272, 408, 272, 943, 275, 5297, 8, 1375, 63, 493, 9, 272, 1752, 63, 1866, 63, 807, 275, 943, 14, 362, 63, 5895, 63, 1515, 63, 1866, 342, 272, 601, 6053, 63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, 1, 1, 1, 1 ]
MikeLing/shogun
examples/undocumented/python/graphical/interactive_svm_demo.py
6
12586
""" Shogun demo, based on PyQT Demo by Eli Bendersky Christian Widmer Soeren Sonnenburg License: GPLv3 """ import numpy import sys, os, csv from PyQt4.QtCore import * from PyQt4.QtGui import * import matplotlib from matplotlib.colorbar import make_axes, Colorbar from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar from matplotlib.figure import Figure from shogun import * import util class Form(QMainWindow): def __init__(self, parent=None): super(Form, self).__init__(parent) self.setWindowTitle('SHOGUN interactive demo') self.data = DataHolder() self.series_list_model = QStandardItemModel() self.create_menu() self.create_main_frame() self.create_status_bar() self.on_show() def load_file(self, filename=None): filename = QFileDialog.getOpenFileName(self, 'Open a data file', '.', 'CSV files (*.csv);;All Files (*.*)') if filename: self.data.load_from_file(filename) self.fill_series_list(self.data.series_names()) self.status_text.setText("Loaded " + filename) def on_show(self): self.axes.clear() self.axes.grid(True) self.axes.plot(self.data.x1_pos, self.data.x2_pos, 'ro') self.axes.plot(self.data.x1_neg, self.data.x2_neg, 'bo') self.axes.set_xlim((-5,5)) self.axes.set_ylim((-5,5)) self.canvas.draw() self.fill_series_list(self.data.get_stats()) def on_about(self): msg = __doc__ QMessageBox.about(self, "About the demo", msg.strip()) def fill_series_list(self, names): self.series_list_model.clear() for name in names: item = QStandardItem(name) item.setCheckState(Qt.Unchecked) item.setCheckable(False) self.series_list_model.appendRow(item) def onclick(self, event): print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%(event.button, event.x, event.y, event.xdata, event.ydata) if event.button==1: label = 1.0 else: label = -1.0 self.data.add_example(event.xdata, event.ydata, label) self.on_show() def clear(self): self.data.clear() self.on_show() def enable_widgets(self): kernel_name = self.kernel_combo.currentText() if kernel_name == "LinearKernel": self.sigma.setDisabled(True) self.degree.setDisabled(True) elif kernel_name == "PolynomialKernel": self.sigma.setDisabled(True) self.degree.setEnabled(True) elif kernel_name == "GaussianKernel": self.sigma.setEnabled(True) self.degree.setDisabled(True) def train_svm(self): width = float(self.sigma.text()) degree = int(self.degree.text()) self.axes.clear() self.axes.grid(True) self.axes.plot(self.data.x1_pos, self.data.x2_pos, 'ro') self.axes.plot(self.data.x1_neg, self.data.x2_neg, 'bo') # train svm labels = self.data.get_labels() print type(labels) lab = BinaryLabels(labels) features = self.data.get_examples() train = RealFeatures(features) kernel_name = self.kernel_combo.currentText() print "current kernel is %s" % (kernel_name) if kernel_name == "LinearKernel": gk = LinearKernel(train, train) gk.set_normalizer(IdentityKernelNormalizer()) elif kernel_name == "PolynomialKernel": gk = PolyKernel(train, train, degree, True) gk.set_normalizer(IdentityKernelNormalizer()) elif kernel_name == "GaussianKernel": gk = GaussianKernel(train, train, width) cost = float(self.cost.text()) print "cost", cost svm = LibSVM(cost, gk, lab) svm.train() svm.set_epsilon(1e-2) x, y, z = util.compute_output_plot_isolines(svm, gk, train) plt=self.axes.pcolor(x, y, z) CS=self.axes.contour(x, y, z, [-1,0,1], linewidths=1, colors='black', hold=True) #CS=self.axes.contour(x, y, z, linewidths=1, colors='black', hold=True) #CS=self.axes.contour(x, y, z, 5, linewidths=1, colors='black', hold=True) matplotlib.pyplot.clabel(CS, inline=1, fontsize=10) self.axes.set_xlim((-5,5)) self.axes.set_ylim((-5,5)) cmap = matplotlib.cm.jet norm = matplotlib.colors.Normalize(numpy.min(z), numpy.max(z)) print CS.get_clim() if not self.cax: self.cax, kw = make_axes(self.axes) # ColorbarBase derives from ScalarMappable and puts a colorbar # in a specified axes, so it has everything needed for a # standalone colorbar. There are many more kwargs, but the # following gives a basic continuous colorbar with ticks # and labels. cb1 = matplotlib.colorbar.ColorbarBase(self.cax, cmap=cmap, norm=norm) self.canvas.draw() def create_main_frame(self): self.main_frame = QWidget() plot_frame = QWidget() self.dpi = 100 self.fig = Figure((6.0, 6.0), dpi=self.dpi) self.canvas = FigureCanvas(self.fig) self.canvas.setParent(self.main_frame) cid = self.canvas.mpl_connect('button_press_event', self.onclick) self.axes = self.fig.add_subplot(111) self.cax = None #self.mpl_toolbar = NavigationToolbar(self.canvas, self.main_frame) log_label = QLabel("Number of examples:") self.series_list_view = QListView() self.series_list_view.setModel(self.series_list_model) cost_label = QLabel('C') #self.cost = QSpinBox()#QLineEdit() self.cost = QLineEdit() self.cost.setText("1.0") #self.cost.setMinimum(1) spin_label2 = QLabel('sigma') self.sigma = QLineEdit() self.sigma.setText("1.2") #self.sigma.setMinimum(1) self.degree = QLineEdit() self.degree.setText("2") #self.sigma.setMinimum(1) spins_hbox = QHBoxLayout() spins_hbox.addWidget(cost_label) spins_hbox.addWidget(self.cost) spins_hbox.addWidget(spin_label2) spins_hbox.addWidget(self.sigma) spins_hbox.addWidget(self.degree) spins_hbox.addStretch(1) self.legend_cb = QCheckBox("Show Support Vectors") self.legend_cb.setChecked(False) self.show_button = QPushButton("&Train SVM") self.connect(self.show_button, SIGNAL('clicked()'), self.train_svm) self.clear_button = QPushButton("&Clear") self.connect(self.clear_button, SIGNAL('clicked()'), self.clear) self.kernel_combo = QComboBox() self.kernel_combo.insertItem(-1, "GaussianKernel") self.kernel_combo.insertItem(-1, "PolynomialKernel") self.kernel_combo.insertItem(-1, "LinearKernel") self.kernel_combo.maximumSize = QSize(300, 50) self.connect(self.kernel_combo, SIGNAL("currentIndexChanged(QString)"), self.enable_widgets) left_vbox = QVBoxLayout() left_vbox.addWidget(self.canvas) #left_vbox.addWidget(self.mpl_toolbar) right0_vbox = QVBoxLayout() right0_vbox.addWidget(log_label) right0_vbox.addWidget(self.series_list_view) #right0_vbox.addWidget(self.legend_cb) right0_vbox.addStretch(1) right2_vbox = QVBoxLayout() right2_label = QLabel("Settings") right2_vbox.addWidget(right2_label) right2_vbox.addWidget(self.show_button) right2_vbox.addWidget(self.kernel_combo) right2_vbox.addLayout(spins_hbox) right2_clearlabel = QLabel("Remove Data") right2_vbox.addWidget(right2_clearlabel) right2_vbox.addWidget(self.clear_button) right2_vbox.addStretch(1) right_vbox = QHBoxLayout() right_vbox.addLayout(right0_vbox) right_vbox.addLayout(right2_vbox) hbox = QVBoxLayout() hbox.addLayout(left_vbox) hbox.addLayout(right_vbox) self.main_frame.setLayout(hbox) self.setCentralWidget(self.main_frame) self.enable_widgets() def create_status_bar(self): self.status_text = QLabel("") self.statusBar().addWidget(self.status_text, 1) def create_menu(self): self.file_menu = self.menuBar().addMenu("&File") load_action = self.create_action("&Load file", shortcut="Ctrl+L", slot=self.load_file, tip="Load a file") quit_action = self.create_action("&Quit", slot=self.close, shortcut="Ctrl+Q", tip="Close the application") self.add_actions(self.file_menu, (load_action, None, quit_action)) self.help_menu = self.menuBar().addMenu("&Help") about_action = self.create_action("&About", shortcut='F1', slot=self.on_about, tip='About the demo') self.add_actions(self.help_menu, (about_action,)) def add_actions(self, target, actions): for action in actions: if action is None: target.addSeparator() else: target.addAction(action) def create_action( self, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, signal="triggered()"): action = QAction(text, self) if icon is not None: action.setIcon(QIcon(":/%s.png" % icon)) if shortcut is not None: action.setShortcut(shortcut) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) if slot is not None: self.connect(action, SIGNAL(signal), slot) if checkable: action.setCheckable(True) return action class DataHolder(object): """ Just a thin wrapper over a dictionary that holds integer data series. Each series has a name and a list of numbers as its data. The length of all series is assumed to be the same. The series can be read from a CSV file, where each line is a separate series. In each series, the first item in the line is the name, and the rest are data numbers. """ def __init__(self, filename=None): self.clear() self.load_from_file(filename) def clear(self): self.x1_pos = [] self.x2_pos = [] self.x1_neg = [] self.x2_neg = [] def get_stats(self): num_neg = len(self.x1_neg) num_pos = len(self.x1_pos) str_neg = "num negative examples: %i" % num_neg str_pos = "num positive examples: %i" % num_pos return (str_neg, str_pos) def get_labels(self): return numpy.array([1]*len(self.x1_pos) + [-1]*len(self.x1_neg), dtype=numpy.float64) def get_examples(self): num_pos = len(self.x1_pos) num_neg = len(self.x1_neg) examples = numpy.zeros((2,num_pos+num_neg)) for i in xrange(num_pos): examples[0,i] = self.x1_pos[i] examples[1,i] = self.x2_pos[i] for i in xrange(num_neg): examples[0,i+num_pos] = self.x1_neg[i] examples[1,i+num_pos] = self.x2_neg[i] return examples def add_example(self, x1, x2, label): if label==1: self.x1_pos.append(x1) self.x2_pos.append(x2) else: self.x1_neg.append(x1) self.x2_neg.append(x2) def load_from_file(self, filename=None): self.data = {} self.names = [] if filename: for line in csv.reader(open(filename, 'rb')): self.names.append(line[0]) self.data[line[0]] = map(int, line[1:]) self.datalen = len(line[1:]) def series_names(self): """ Names of the data series """ return self.names def series_len(self): """ Length of a data series """ return self.datalen def series_count(self): return len(self.data) def get_series_data(self, name): return self.data[name] def main(): app = QApplication(sys.argv) form = Form() form.show() app.exec_() if __name__ == "__main__": main() #~ dh = DataHolder('qt_mpl_data.csv') #~ print dh.data #~ print dh.get_series_data('1991 Sales') #~ print dh.series_names() #~ print dh.series_count()
gpl-3.0
[ 624, 199, 51, 526, 17924, 14779, 12, 4079, 641, 1611, 19229, 28939, 701, 662, 317, 699, 13747, 12267, 199, 199, 1049, 18824, 5653, 644, 344, 2626, 199, 5158, 69, 828, 428, 265, 78, 287, 29291, 199, 3761, 26, 14629, 86, 19, 199, 624, 199, 646, 2680, 199, 646, 984, 12, 747, 12, 7392, 199, 504, 14084, 20, 14, 10901, 492, 627, 199, 504, 14084, 20, 14, 10604, 492, 627, 199, 199, 646, 8027, 199, 504, 8027, 14, 30995, 492, 1852, 63, 6402, 12, 11581, 1700, 199, 504, 8027, 14, 7765, 14, 4620, 63, 8440, 20, 13452, 492, 16266, 15174, 49, 6166, 2721, 465, 16266, 15174, 199, 504, 8027, 14, 7765, 14, 4620, 63, 8440, 20, 13452, 492, 20721, 5360, 29630, 18, 19229, 465, 20721, 5360, 29630, 199, 504, 8027, 14, 8941, 492, 16266, 199, 199, 504, 930, 17924, 492, 627, 199, 646, 4884, 199, 199, 533, 8204, 8, 49, 16031, 304, 272, 347, 636, 826, 721, 277, 12, 1676, 29, 403, 304, 267, 1613, 8, 2821, 12, 291, 2843, 826, 721, 1708, 9, 267, 291, 14, 30601, 360, 51, 2979, 39, 1734, 12777, 14779, 358, 398, 291, 14, 576, 275, 3918, 22570, 342, 267, 291, 14, 5602, 63, 513, 63, 1238, 275, 1413, 9232, 2081, 1685, 342, 398, 291, 14, 981, 63, 4470, 342, 267, 291, 14, 981, 63, 973, 63, 1943, 342, 267, 291, 14, 981, 63, 1205, 63, 1700, 342, 398, 291, 14, 265, 63, 2384, 342, 339, 347, 2248, 63, 493, 8, 277, 12, 1788, 29, 403, 304, 267, 1788, 275, 1413, 25213, 14, 362, 4299, 7733, 8, 277, 12, 288, 283, 4299, 282, 666, 570, 297, 22608, 283, 19018, 1584, 334, 4856, 4737, 2736, 27, 2422, 16920, 19943, 2795, 5942, 398, 340, 1788, 26, 288, 291, 14, 576, 14, 912, 63, 504, 63, 493, 8, 1501, 9, 288, 291, 14, 4498, 63, 5602, 63, 513, 8, 277, 14, 576, 14, 5602, 63, 1247, 1012, 288, 291, 14, 1205, 63, 505, 14, 8341, 480, 19757, 298, 435, 1788, 9, 339, 347, 641, 63, 2384, 8, 277, 304, 267, 291, 14, 6402, 14, 3584, 342, 267, 291, 14, 6402, 14, 3825, 8, 549, 9, 267, 291, 14, 6402, 14, 2798, 8, 277, 14, 576, 14, 88, 17, 63, 1712, 12, 291, 14, 576, 14, 88, 18, 63, 1712, 12, 283, 293, 358, 267, 291, 14, 6402, 14, 2798, 8, 277, 14, 576, 14, 88, 17, 63, 8705, 12, 291, 14, 576, 14, 88, 18, 63, 8705, 12, 283, 656, 358, 267, 291, 14, 6402, 14, 409, 63, 18512, 18138, 21, 12, 21, 430, 267, 291, 14, 6402, 14, 409, 63, 18123, 18138, 21, 12, 21, 430, 267, 291, 14, 7682, 14, 5485, 342, 267, 291, 14, 4498, 63, 5602, 63, 513, 8, 277, 14, 576, 14, 362, 63, 3200, 1012, 2378, 347, 641, 63, 10254, 8, 277, 304, 267, 1499, 275, 636, 1301, 363, 267, 25159, 14, 10254, 8, 277, 12, 298, 18816, 314, 14779, 401, 1499, 14, 1913, 1012, 339, 347, 5554, 63, 5602, 63, 513, 8, 277, 12, 1561, 304, 267, 291, 14, 5602, 63, 513, 63, 1238, 14, 3584, 342, 398, 367, 536, 315, 1561, 26, 288, 1242, 275, 1413, 9232, 2081, 8, 354, 9, 288, 1242, 14, 409, 1799, 2223, 8, 4238, 14, 1358, 10718, 9, 288, 1242, 14, 409, 1799, 461, 8, 797, 9, 288, 291, 14, 5602, 63, 513, 63, 1238, 14, 740, 5810, 8, 1053, 9, 339, 347, 31156, 8, 277, 12, 1566, 304, 267, 870, 283, 3887, 2458, 68, 12, 671, 2458, 68, 12, 612, 2458, 68, 12, 671, 576, 2458, 70, 12, 612, 576, 2458, 70, 13328, 1430, 14, 3887, 12, 1566, 14, 88, 12, 1566, 14, 89, 12, 1566, 14, 31643, 12, 1566, 14, 89, 576, 9, 267, 340, 1566, 14, 3887, 389, 17, 26, 288, 1768, 275, 413, 14, 16, 267, 587, 26, 288, 1768, 275, 446, 17, 14, 16, 267, 291, 14, 576, 14, 525, 63, 2694, 8, 1430, 14, 31643, 12, 1566, 14, 89, 576, 12, 1768, 9, 267, 291, 14, 265, 63, 2384, 342, 2378, 347, 5436, 8, 277, 304, 267, 291, 14, 576, 14, 3584, 342, 267, 291, 14, 265, 63, 2384, 342, 339, 347, 4756, 63, 8583, 8, 277, 304, 267, 5114, 63, 354, 275, 291, 14, 4989, 63, 12650, 14, 1818, 1872, 342, 267, 340, 5114, 63, 354, 508, 298, 10608, 14127, 582, 288, 291, 14, 9412, 14, 409, 15049, 8, 549, 9, 288, 291, 14, 10956, 14, 409, 15049, 8, 549, 9, 267, 916, 5114, 63, 354, 508, 298, 5858, 8887, 14127, 582, 288, 291, 14, 9412, 14, 409, 15049, 8, 549, 9, 288, 291, 14, 10956, 14, 14329, 8, 549, 9, 267, 916, 5114, 63, 354, 508, 298, 26756, 14127, 582, 288, 291, 14, 9412, 14, 14329, 8, 549, 9, 288, 291, 14, 10956, 14, 409, 15049, 8, 549, 9, 339, 347, 3560, 63, 16820, 8, 277, 304, 398, 3462, 275, 2069, 8, 277, 14, 9412, 14, 505, 1012, 267, 13666, 275, 1109, 8, 277, 14, 10956, 14, 505, 1012, 398, 291, 14, 6402, 14, 3584, 342, 267, 291, 14, 6402, 14, 3825, 8, 549, 9, 267, 291, 14, 6402, 14, 2798, 8, 277, 14, 576, 14, 88, 17, 63, 1712, 12, 291, 14, 576, 14, 88, 18, 63, 1712, 12, 283, 293, 358, 267, 291, 14, 6402, 14, 2798, 8, 277, 14, 576, 14, 88, 17, 63, 8705, 12, 291, 14, 576, 14, 88, 18, 63, 8705, 12, 283, 656, 358, 398, 327, 3560, 23044, 267, 3628, 275, 291, 14, 576, 14, 362, 63, 3512, 342, 267, 870, 730, 8, 3512, 9, 267, 19888, 275, 14161, 14016, 8, 3512, 9, 267, 4534, 275, 291, 14, 576, 14, 362, 63, 8589, 342, 267, 3560, 275, 14849, 10807, 8, 3179, 9, 398, 5114, 63, 354, 275, 291, 14, 4989, 63, 12650, 14, 1818, 1872, 342, 267, 870, 298, 1818, 5114, 365, 450, 83, 2, 450, 334, 4989, 63, 354, 9, 398, 340, 5114, 63, 354, 508, 298, 10608, 14127, 582, 288, 486, 75, 275, 12489, 14127, 8, 2834, 12, 3560, 9, 288, 486, 75, 14, 409, 63, 3302, 1793, 8, 10193, 14127, 6241, 1793, 1012, 267, 916, 5114, 63, 354, 508, 298, 5858, 8887 ]
[ 199, 51, 526, 17924, 14779, 12, 4079, 641, 1611, 19229, 28939, 701, 662, 317, 699, 13747, 12267, 199, 199, 1049, 18824, 5653, 644, 344, 2626, 199, 5158, 69, 828, 428, 265, 78, 287, 29291, 199, 3761, 26, 14629, 86, 19, 199, 624, 199, 646, 2680, 199, 646, 984, 12, 747, 12, 7392, 199, 504, 14084, 20, 14, 10901, 492, 627, 199, 504, 14084, 20, 14, 10604, 492, 627, 199, 199, 646, 8027, 199, 504, 8027, 14, 30995, 492, 1852, 63, 6402, 12, 11581, 1700, 199, 504, 8027, 14, 7765, 14, 4620, 63, 8440, 20, 13452, 492, 16266, 15174, 49, 6166, 2721, 465, 16266, 15174, 199, 504, 8027, 14, 7765, 14, 4620, 63, 8440, 20, 13452, 492, 20721, 5360, 29630, 18, 19229, 465, 20721, 5360, 29630, 199, 504, 8027, 14, 8941, 492, 16266, 199, 199, 504, 930, 17924, 492, 627, 199, 646, 4884, 199, 199, 533, 8204, 8, 49, 16031, 304, 272, 347, 636, 826, 721, 277, 12, 1676, 29, 403, 304, 267, 1613, 8, 2821, 12, 291, 2843, 826, 721, 1708, 9, 267, 291, 14, 30601, 360, 51, 2979, 39, 1734, 12777, 14779, 358, 398, 291, 14, 576, 275, 3918, 22570, 342, 267, 291, 14, 5602, 63, 513, 63, 1238, 275, 1413, 9232, 2081, 1685, 342, 398, 291, 14, 981, 63, 4470, 342, 267, 291, 14, 981, 63, 973, 63, 1943, 342, 267, 291, 14, 981, 63, 1205, 63, 1700, 342, 398, 291, 14, 265, 63, 2384, 342, 339, 347, 2248, 63, 493, 8, 277, 12, 1788, 29, 403, 304, 267, 1788, 275, 1413, 25213, 14, 362, 4299, 7733, 8, 277, 12, 288, 283, 4299, 282, 666, 570, 297, 22608, 283, 19018, 1584, 334, 4856, 4737, 2736, 27, 2422, 16920, 19943, 2795, 5942, 398, 340, 1788, 26, 288, 291, 14, 576, 14, 912, 63, 504, 63, 493, 8, 1501, 9, 288, 291, 14, 4498, 63, 5602, 63, 513, 8, 277, 14, 576, 14, 5602, 63, 1247, 1012, 288, 291, 14, 1205, 63, 505, 14, 8341, 480, 19757, 298, 435, 1788, 9, 339, 347, 641, 63, 2384, 8, 277, 304, 267, 291, 14, 6402, 14, 3584, 342, 267, 291, 14, 6402, 14, 3825, 8, 549, 9, 267, 291, 14, 6402, 14, 2798, 8, 277, 14, 576, 14, 88, 17, 63, 1712, 12, 291, 14, 576, 14, 88, 18, 63, 1712, 12, 283, 293, 358, 267, 291, 14, 6402, 14, 2798, 8, 277, 14, 576, 14, 88, 17, 63, 8705, 12, 291, 14, 576, 14, 88, 18, 63, 8705, 12, 283, 656, 358, 267, 291, 14, 6402, 14, 409, 63, 18512, 18138, 21, 12, 21, 430, 267, 291, 14, 6402, 14, 409, 63, 18123, 18138, 21, 12, 21, 430, 267, 291, 14, 7682, 14, 5485, 342, 267, 291, 14, 4498, 63, 5602, 63, 513, 8, 277, 14, 576, 14, 362, 63, 3200, 1012, 2378, 347, 641, 63, 10254, 8, 277, 304, 267, 1499, 275, 636, 1301, 363, 267, 25159, 14, 10254, 8, 277, 12, 298, 18816, 314, 14779, 401, 1499, 14, 1913, 1012, 339, 347, 5554, 63, 5602, 63, 513, 8, 277, 12, 1561, 304, 267, 291, 14, 5602, 63, 513, 63, 1238, 14, 3584, 342, 398, 367, 536, 315, 1561, 26, 288, 1242, 275, 1413, 9232, 2081, 8, 354, 9, 288, 1242, 14, 409, 1799, 2223, 8, 4238, 14, 1358, 10718, 9, 288, 1242, 14, 409, 1799, 461, 8, 797, 9, 288, 291, 14, 5602, 63, 513, 63, 1238, 14, 740, 5810, 8, 1053, 9, 339, 347, 31156, 8, 277, 12, 1566, 304, 267, 870, 283, 3887, 2458, 68, 12, 671, 2458, 68, 12, 612, 2458, 68, 12, 671, 576, 2458, 70, 12, 612, 576, 2458, 70, 13328, 1430, 14, 3887, 12, 1566, 14, 88, 12, 1566, 14, 89, 12, 1566, 14, 31643, 12, 1566, 14, 89, 576, 9, 267, 340, 1566, 14, 3887, 389, 17, 26, 288, 1768, 275, 413, 14, 16, 267, 587, 26, 288, 1768, 275, 446, 17, 14, 16, 267, 291, 14, 576, 14, 525, 63, 2694, 8, 1430, 14, 31643, 12, 1566, 14, 89, 576, 12, 1768, 9, 267, 291, 14, 265, 63, 2384, 342, 2378, 347, 5436, 8, 277, 304, 267, 291, 14, 576, 14, 3584, 342, 267, 291, 14, 265, 63, 2384, 342, 339, 347, 4756, 63, 8583, 8, 277, 304, 267, 5114, 63, 354, 275, 291, 14, 4989, 63, 12650, 14, 1818, 1872, 342, 267, 340, 5114, 63, 354, 508, 298, 10608, 14127, 582, 288, 291, 14, 9412, 14, 409, 15049, 8, 549, 9, 288, 291, 14, 10956, 14, 409, 15049, 8, 549, 9, 267, 916, 5114, 63, 354, 508, 298, 5858, 8887, 14127, 582, 288, 291, 14, 9412, 14, 409, 15049, 8, 549, 9, 288, 291, 14, 10956, 14, 14329, 8, 549, 9, 267, 916, 5114, 63, 354, 508, 298, 26756, 14127, 582, 288, 291, 14, 9412, 14, 14329, 8, 549, 9, 288, 291, 14, 10956, 14, 409, 15049, 8, 549, 9, 339, 347, 3560, 63, 16820, 8, 277, 304, 398, 3462, 275, 2069, 8, 277, 14, 9412, 14, 505, 1012, 267, 13666, 275, 1109, 8, 277, 14, 10956, 14, 505, 1012, 398, 291, 14, 6402, 14, 3584, 342, 267, 291, 14, 6402, 14, 3825, 8, 549, 9, 267, 291, 14, 6402, 14, 2798, 8, 277, 14, 576, 14, 88, 17, 63, 1712, 12, 291, 14, 576, 14, 88, 18, 63, 1712, 12, 283, 293, 358, 267, 291, 14, 6402, 14, 2798, 8, 277, 14, 576, 14, 88, 17, 63, 8705, 12, 291, 14, 576, 14, 88, 18, 63, 8705, 12, 283, 656, 358, 398, 327, 3560, 23044, 267, 3628, 275, 291, 14, 576, 14, 362, 63, 3512, 342, 267, 870, 730, 8, 3512, 9, 267, 19888, 275, 14161, 14016, 8, 3512, 9, 267, 4534, 275, 291, 14, 576, 14, 362, 63, 8589, 342, 267, 3560, 275, 14849, 10807, 8, 3179, 9, 398, 5114, 63, 354, 275, 291, 14, 4989, 63, 12650, 14, 1818, 1872, 342, 267, 870, 298, 1818, 5114, 365, 450, 83, 2, 450, 334, 4989, 63, 354, 9, 398, 340, 5114, 63, 354, 508, 298, 10608, 14127, 582, 288, 486, 75, 275, 12489, 14127, 8, 2834, 12, 3560, 9, 288, 486, 75, 14, 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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
christoph-buente/phantomjs
src/qt/qtwebkit/Source/ThirdParty/gtest/test/gtest_env_var_test.py
233
3509
#!/usr/bin/env python # # Copyright 2008, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following disclaimer # in the documentation and/or other materials provided with the # distribution. # * Neither the name of Google Inc. nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """Verifies that Google Test correctly parses environment variables.""" __author__ = 'wan@google.com (Zhanyong Wan)' import os import gtest_test_utils IS_WINDOWS = os.name == 'nt' IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux' COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_env_var_test_') environ = os.environ.copy() def AssertEq(expected, actual): if expected != actual: print 'Expected: %s' % (expected,) print ' Actual: %s' % (actual,) raise AssertionError def SetEnvVar(env_var, value): """Sets the env variable to 'value'; unsets it when 'value' is None.""" if value is not None: environ[env_var] = value elif env_var in environ: del environ[env_var] def GetFlag(flag): """Runs gtest_env_var_test_ and returns its output.""" args = [COMMAND] if flag is not None: args += [flag] return gtest_test_utils.Subprocess(args, env=environ).output def TestFlag(flag, test_val, default_val): """Verifies that the given flag is affected by the corresponding env var.""" env_var = 'GTEST_' + flag.upper() SetEnvVar(env_var, test_val) AssertEq(test_val, GetFlag(flag)) SetEnvVar(env_var, None) AssertEq(default_val, GetFlag(flag)) class GTestEnvVarTest(gtest_test_utils.TestCase): def testEnvVarAffectsFlag(self): """Tests that environment variable should affect the corresponding flag.""" TestFlag('break_on_failure', '1', '0') TestFlag('color', 'yes', 'auto') TestFlag('filter', 'FooTest.Bar', '*') TestFlag('output', 'xml:tmp/foo.xml', '') TestFlag('print_time', '0', '1') TestFlag('repeat', '999', '1') TestFlag('throw_on_failure', '1', '0') TestFlag('death_test_style', 'threadsafe', 'fast') if IS_WINDOWS: TestFlag('catch_exceptions', '1', '0') if IS_LINUX: TestFlag('death_test_use_fork', '1', '0') TestFlag('stack_trace_depth', '0', '100') if __name__ == '__main__': gtest_test_utils.Main()
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 9079, 12, 4475, 3277, 14, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 258, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 258, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 199, 3, 4248, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 199, 3, 315, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 4084, 14, 199, 3, 258, 627, 11443, 314, 536, 402, 4475, 3277, 14, 6590, 314, 1561, 402, 2399, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 199, 3, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 199, 3, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 199, 3, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 199, 3, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 199, 3, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 624, 21168, 626, 4475, 1379, 6657, 19953, 3734, 2860, 1041, 199, 199, 363, 2502, 363, 275, 283, 20444, 32, 3098, 14, 957, 334, 12674, 1629, 951, 644, 290, 3171, 199, 199, 646, 747, 199, 646, 9088, 63, 396, 63, 1208, 421, 199, 1311, 63, 20509, 275, 747, 14, 354, 508, 283, 343, 7, 199, 1311, 63, 26030, 275, 747, 14, 354, 508, 283, 9228, 7, 436, 747, 14, 16040, 3430, 16, 61, 508, 283, 14091, 7, 199, 199, 10761, 275, 9088, 63, 396, 63, 1208, 14, 28967, 27602, 360, 8385, 63, 1813, 63, 1391, 63, 396, 15452, 199, 199, 2314, 275, 747, 14, 2314, 14, 1574, 342, 421, 199, 318, 10716, 19706, 8, 2062, 12, 3503, 304, 523, 340, 1420, 1137, 3503, 26, 272, 870, 283, 6964, 26, 450, 83, 7, 450, 334, 2062, 4258, 272, 870, 283, 221, 18982, 1061, 26, 450, 83, 7, 450, 334, 6514, 4258, 272, 746, 9070, 421, 199, 318, 30306, 8, 1813, 63, 1391, 12, 574, 304, 523, 408, 9899, 314, 2589, 1750, 370, 283, 585, 13619, 625, 2193, 652, 1380, 283, 585, 7, 365, 488, 1041, 819, 340, 574, 365, 440, 488, 26, 272, 6160, 59, 1813, 63, 1391, 61, 275, 574, 523, 916, 2589, 63, 1391, 315, 6160, 26, 272, 2150, 6160, 59, 1813, 63, 1391, 61, 421, 199, 318, 2372, 5318, 8, 4173, 304, 523, 408, 16291, 9088, 63, 1813, 63, 1391, 63, 396, 63, 436, 2529, 2399, 1072, 1041, 819, 1249, 275, 359, 10761, 61, 523, 340, 3305, 365, 440, 488, 26, 272, 1249, 847, 359, 4173, 61, 523, 372, 9088, 63, 396, 63, 1208, 14, 22299, 8, 589, 12, 2589, 29, 2314, 680, 1199, 421, 199, 318, 1379, 5318, 8, 4173, 12, 511, 63, 637, 12, 849, 63, 637, 304, 523, 408, 21168, 626, 314, 1627, 3305, 365, 16955, 701, 314, 5226, 2589, 2729, 1041, 819, 2589, 63, 1391, 275, 283, 16151, 8650, 435, 3305, 14, 4142, 342, 523, 30306, 8, 1813, 63, 1391, 12, 511, 63, 637, 9, 523, 10716, 19706, 8, 396, 63, 637, 12, 2372, 5318, 8, 4173, 430, 523, 30306, 8, 1813, 63, 1391, 12, 488, 9, 523, 10716, 19706, 8, 885, 63, 637, 12, 2372, 5318, 8, 4173, 430, 421, 199, 533, 598, 774, 19342, 774, 8, 8385, 63, 396, 63, 1208, 14, 1746, 304, 523, 347, 511, 19342, 33, 5551, 83, 5318, 8, 277, 304, 272, 408, 2925, 626, 3734, 1750, 1077, 12787, 314, 5226, 3305, 1041, 339, 1379, 5318, 360, 4785, 63, 265, 63, 5328, 297, 283, 17, 297, 283, 16, 358, 272, 1379, 5318, 360, 2326, 297, 283, 5066, 297, 283, 2495, 358, 272, 1379, 5318, 360, 1541, 297, 283, 24676, 14, 5281, 297, 6438, 358, 272, 1379, 5318, 360, 1199, 297, 283, 1652, 26, 2791, 15, 1421, 14, 1652, 297, 4074, 272, 1379, 5318, 360, 1361, 63, 521, 297, 283, 16, 297, 283, 17, 358, 272, 1379, 5318, 360, 8755, 297, 283, 5637, 297, 283, 17, 358, 272, 1379, 5318, 360, 11964, 63, 265, 63, 5328, 297, 283, 17, 297, 283, 16, 358, 272, 1379, 5318, 360, 23727, 63, 396, 63, 2487, 297, 283, 2671, 3489, 297, 283, 7015, 358, 339, 340, 2281, 63, 20509, 26, 489, 1379, 5318, 360, 9341, 63, 3924, 297, 283, 17, 297, 283, 16, 358, 339, 340, 2281, 63, 26030, 26, 489, 1379, 5318, 360, 23727, 63, 396, 63, 1180, 63, 11796, 297, 283, 17, 297, 283, 16, 358, 489, 1379, 5318, 360, 2340, 63, 3446, 63, 4631, 297, 283, 16, 297, 283, 1960, 358, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 523, 9088, 63, 396, 63, 1208, 14, 6756, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 9079, 12, 4475, 3277, 14, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 258, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 258, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 199, 3, 4248, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 199, 3, 315, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 4084, 14, 199, 3, 258, 627, 11443, 314, 536, 402, 4475, 3277, 14, 6590, 314, 1561, 402, 2399, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 199, 3, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 199, 3, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 199, 3, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 199, 3, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 199, 3, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 624, 21168, 626, 4475, 1379, 6657, 19953, 3734, 2860, 1041, 199, 199, 363, 2502, 363, 275, 283, 20444, 32, 3098, 14, 957, 334, 12674, 1629, 951, 644, 290, 3171, 199, 199, 646, 747, 199, 646, 9088, 63, 396, 63, 1208, 421, 199, 1311, 63, 20509, 275, 747, 14, 354, 508, 283, 343, 7, 199, 1311, 63, 26030, 275, 747, 14, 354, 508, 283, 9228, 7, 436, 747, 14, 16040, 3430, 16, 61, 508, 283, 14091, 7, 199, 199, 10761, 275, 9088, 63, 396, 63, 1208, 14, 28967, 27602, 360, 8385, 63, 1813, 63, 1391, 63, 396, 15452, 199, 199, 2314, 275, 747, 14, 2314, 14, 1574, 342, 421, 199, 318, 10716, 19706, 8, 2062, 12, 3503, 304, 523, 340, 1420, 1137, 3503, 26, 272, 870, 283, 6964, 26, 450, 83, 7, 450, 334, 2062, 4258, 272, 870, 283, 221, 18982, 1061, 26, 450, 83, 7, 450, 334, 6514, 4258, 272, 746, 9070, 421, 199, 318, 30306, 8, 1813, 63, 1391, 12, 574, 304, 523, 408, 9899, 314, 2589, 1750, 370, 283, 585, 13619, 625, 2193, 652, 1380, 283, 585, 7, 365, 488, 1041, 819, 340, 574, 365, 440, 488, 26, 272, 6160, 59, 1813, 63, 1391, 61, 275, 574, 523, 916, 2589, 63, 1391, 315, 6160, 26, 272, 2150, 6160, 59, 1813, 63, 1391, 61, 421, 199, 318, 2372, 5318, 8, 4173, 304, 523, 408, 16291, 9088, 63, 1813, 63, 1391, 63, 396, 63, 436, 2529, 2399, 1072, 1041, 819, 1249, 275, 359, 10761, 61, 523, 340, 3305, 365, 440, 488, 26, 272, 1249, 847, 359, 4173, 61, 523, 372, 9088, 63, 396, 63, 1208, 14, 22299, 8, 589, 12, 2589, 29, 2314, 680, 1199, 421, 199, 318, 1379, 5318, 8, 4173, 12, 511, 63, 637, 12, 849, 63, 637, 304, 523, 408, 21168, 626, 314, 1627, 3305, 365, 16955, 701, 314, 5226, 2589, 2729, 1041, 819, 2589, 63, 1391, 275, 283, 16151, 8650, 435, 3305, 14, 4142, 342, 523, 30306, 8, 1813, 63, 1391, 12, 511, 63, 637, 9, 523, 10716, 19706, 8, 396, 63, 637, 12, 2372, 5318, 8, 4173, 430, 523, 30306, 8, 1813, 63, 1391, 12, 488, 9, 523, 10716, 19706, 8, 885, 63, 637, 12, 2372, 5318, 8, 4173, 430, 421, 199, 533, 598, 774, 19342, 774, 8, 8385, 63, 396, 63, 1208, 14, 1746, 304, 523, 347, 511, 19342, 33, 5551, 83, 5318, 8, 277, 304, 272, 408, 2925, 626, 3734, 1750, 1077, 12787, 314, 5226, 3305, 1041, 339, 1379, 5318, 360, 4785, 63, 265, 63, 5328, 297, 283, 17, 297, 283, 16, 358, 272, 1379, 5318, 360, 2326, 297, 283, 5066, 297, 283, 2495, 358, 272, 1379, 5318, 360, 1541, 297, 283, 24676, 14, 5281, 297, 6438, 358, 272, 1379, 5318, 360, 1199, 297, 283, 1652, 26, 2791, 15, 1421, 14, 1652, 297, 4074, 272, 1379, 5318, 360, 1361, 63, 521, 297, 283, 16, 297, 283, 17, 358, 272, 1379, 5318, 360, 8755, 297, 283, 5637, 297, 283, 17, 358, 272, 1379, 5318, 360, 11964, 63, 265, 63, 5328, 297, 283, 17, 297, 283, 16, 358, 272, 1379, 5318, 360, 23727, 63, 396, 63, 2487, 297, 283, 2671, 3489, 297, 283, 7015, 358, 339, 340, 2281, 63, 20509, 26, 489, 1379, 5318, 360, 9341, 63, 3924, 297, 283, 17, 297, 283, 16, 358, 339, 340, 2281, 63, 26030, 26, 489, 1379, 5318, 360, 23727, 63, 396, 63, 1180, 63, 11796, 297, 283, 17, 297, 283, 16, 358, 489, 1379, 5318, 360, 2340, 63, 3446, 63, 4631, 297, 283, 16, 297, 283, 1960, 358, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 523, 9088, 63, 396, 63, 1208, 14, 6756, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
jcftang/ansible
lib/ansible/plugins/test/files.py
148
1347
# (c) 2015, Ansible, Inc # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # Make coding more python3-ish from __future__ import (absolute_import, division, print_function) __metaclass__ = type from os.path import isdir, isfile, isabs, exists, lexists, islink, samefile, ismount from ansible import errors class TestModule(object): ''' Ansible file jinja2 tests ''' def tests(self): return { # file testing 'is_dir' : isdir, 'is_file' : isfile, 'is_link' : islink, 'exists' : exists, 'link_exists' : lexists, # path testing 'is_abs' : isabs, 'is_same_file' : samefile, 'is_mount' : ismount, }
gpl-3.0
[ 3, 334, 67, 9, 6900, 12, 2622, 12, 3277, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 3, 4155, 2803, 1655, 2366, 19, 13, 2453, 199, 504, 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 9, 199, 363, 6577, 363, 275, 730, 199, 199, 504, 747, 14, 515, 492, 26004, 12, 29214, 12, 365, 2101, 12, 3495, 12, 7103, 1670, 12, 365, 1073, 12, 2011, 493, 12, 365, 3956, 199, 504, 3242, 492, 2552, 199, 199, 533, 1379, 2377, 8, 785, 304, 272, 1449, 2622, 570, 10321, 18, 2295, 1449, 339, 347, 2295, 8, 277, 304, 267, 372, 469, 288, 327, 570, 5343, 288, 283, 374, 63, 694, 7, 221, 520, 26004, 12, 288, 283, 374, 63, 493, 7, 520, 29214, 12, 288, 283, 374, 63, 1073, 7, 520, 365, 1073, 12, 288, 283, 2444, 7, 520, 3495, 12, 288, 283, 1073, 63, 2444, 7, 520, 7103, 1670, 12, 953, 327, 931, 5343, 288, 283, 374, 63, 2101, 7, 520, 365, 2101, 12, 288, 283, 374, 63, 7191, 63, 493, 7, 520, 2011, 493, 12, 288, 283, 374, 63, 3956, 7, 520, 365, 3956, 12, 267, 789, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 334, 67, 9, 6900, 12, 2622, 12, 3277, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 3, 4155, 2803, 1655, 2366, 19, 13, 2453, 199, 504, 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 9, 199, 363, 6577, 363, 275, 730, 199, 199, 504, 747, 14, 515, 492, 26004, 12, 29214, 12, 365, 2101, 12, 3495, 12, 7103, 1670, 12, 365, 1073, 12, 2011, 493, 12, 365, 3956, 199, 504, 3242, 492, 2552, 199, 199, 533, 1379, 2377, 8, 785, 304, 272, 1449, 2622, 570, 10321, 18, 2295, 1449, 339, 347, 2295, 8, 277, 304, 267, 372, 469, 288, 327, 570, 5343, 288, 283, 374, 63, 694, 7, 221, 520, 26004, 12, 288, 283, 374, 63, 493, 7, 520, 29214, 12, 288, 283, 374, 63, 1073, 7, 520, 365, 1073, 12, 288, 283, 2444, 7, 520, 3495, 12, 288, 283, 1073, 63, 2444, 7, 520, 7103, 1670, 12, 953, 327, 931, 5343, 288, 283, 374, 63, 2101, 7, 520, 365, 2101, 12, 288, 283, 374, 63, 7191, 63, 493, 7, 520, 2011, 493, 12, 288, 283, 374, 63, 3956, 7, 520, 365, 3956, 12, 267, 789, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
arnedesmedt/dotfiles
.config/sublime-text-3/Packages.symlinkfollow/pygments/all/pygments/lexers/dalvik.py
47
4420
# -*- coding: utf-8 -*- """ pygments.lexers.dalvik ~~~~~~~~~~~~~~~~~~~~~~ Pygments lexers for Dalvik VM-related languages. :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ import re from pygments.lexer import RegexLexer, include, bygroups from pygments.token import Keyword, Text, Comment, Name, String, Number, \ Punctuation __all__ = ['SmaliLexer'] class SmaliLexer(RegexLexer): """ For `Smali <http://code.google.com/p/smali/>`_ (Android/Dalvik) assembly code. .. versionadded:: 1.6 """ name = 'Smali' aliases = ['smali'] filenames = ['*.smali'] mimetypes = ['text/smali'] tokens = { 'root': [ include('comment'), include('label'), include('field'), include('method'), include('class'), include('directive'), include('access-modifier'), include('instruction'), include('literal'), include('punctuation'), include('type'), include('whitespace') ], 'directive': [ (r'^[ \t]*\.(class|super|implements|field|subannotation|annotation|' r'enum|method|registers|locals|array-data|packed-switch|' r'sparse-switch|catchall|catch|line|parameter|local|prologue|' r'epilogue|source)', Keyword), (r'^[ \t]*\.end (field|subannotation|annotation|method|array-data|' 'packed-switch|sparse-switch|parameter|local)', Keyword), (r'^[ \t]*\.restart local', Keyword), ], 'access-modifier': [ (r'(public|private|protected|static|final|synchronized|bridge|' r'varargs|native|abstract|strictfp|synthetic|constructor|' r'declared-synchronized|interface|enum|annotation|volatile|' r'transient)', Keyword), ], 'whitespace': [ (r'\n', Text), (r'\s+', Text), ], 'instruction': [ (r'\b[vp]\d+\b', Name.Builtin), # registers (r'\b[a-z][A-Za-z0-9/-]+\s+', Text), # instructions ], 'literal': [ (r'".*"', String), (r'0x[0-9A-Fa-f]+t?', Number.Hex), (r'[0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), (r'[0-9]+L?', Number.Integer), ], 'field': [ (r'(\$?\b)([\w$]*)(:)', bygroups(Punctuation, Name.Variable, Punctuation)), ], 'method': [ (r'<(?:cl)?init>', Name.Function), # constructor (r'(\$?\b)([\w$]*)(\()', bygroups(Punctuation, Name.Function, Punctuation)), ], 'label': [ (r':\w+', Name.Label), ], 'class': [ # class names in the form Lcom/namespace/ClassName; # I only want to color the ClassName part, so the namespace part is # treated as 'Text' (r'(L)((?:[\w$]+/)*)([\w$]+)(;)', bygroups(Keyword.Type, Text, Name.Class, Text)), ], 'punctuation': [ (r'->', Punctuation), (r'[{},():=.-]', Punctuation), ], 'type': [ (r'[ZBSCIJFDV\[]+', Keyword.Type), ], 'comment': [ (r'#.*?\n', Comment), ], } def analyse_text(text): score = 0 if re.search(r'^\s*\.class\s', text, re.MULTILINE): score += 0.5 if re.search(r'\b((check-cast|instance-of|throw-verification-error' r')\b|(-to|add|[ais]get|[ais]put|and|cmpl|const|div|' r'if|invoke|move|mul|neg|not|or|rem|return|rsub|shl|' r'shr|sub|ushr)[-/])|{|}', text, re.MULTILINE): score += 0.3 if re.search(r'(\.(catchall|epilogue|restart local|prologue)|' r'\b(array-data|class-change-error|declared-synchronized|' r'(field|inline|vtable)@0x[0-9a-fA-F]|generic-error|' r'illegal-class-access|illegal-field-access|' r'illegal-method-access|instantiation-error|no-error|' r'no-such-class|no-such-field|no-such-method|' r'packed-switch|sparse-switch))\b', text, re.MULTILINE): score += 0.6 return score
mit
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 272, 13277, 14, 12245, 14, 12390, 433, 75, 272, 18294, 2878, 1714, 339, 14493, 7103, 1192, 367, 577, 279, 433, 75, 7525, 13, 2407, 10815, 14, 339, 520, 7307, 26, 1898, 8315, 13, 7806, 701, 314, 14493, 8099, 12, 1937, 10610, 14, 272, 520, 1682, 26, 6289, 12, 1937, 5113, 367, 2436, 14, 199, 624, 199, 199, 646, 295, 199, 199, 504, 13277, 14, 11729, 492, 12939, 5838, 12, 2387, 12, 10259, 199, 504, 13277, 14, 1418, 492, 6431, 12, 4516, 12, 6819, 12, 2812, 12, 2624, 12, 4860, 12, 971, 272, 10357, 199, 199, 363, 452, 363, 275, 788, 51, 2174, 73, 5838, 418, 421, 199, 533, 428, 2174, 73, 5838, 8, 19856, 304, 272, 408, 272, 2104, 658, 51, 2174, 73, 665, 1014, 921, 600, 14, 3098, 14, 957, 15, 80, 15, 24460, 73, 3133, 18417, 334, 20762, 15, 36, 279, 433, 75, 9, 24869, 272, 1233, 14, 339, 2508, 7445, 447, 413, 14, 22, 272, 408, 272, 536, 275, 283, 51, 2174, 73, 7, 272, 5481, 275, 788, 24460, 73, 418, 272, 6203, 275, 17855, 24460, 73, 418, 272, 13290, 275, 788, 505, 15, 24460, 73, 418, 339, 4645, 275, 469, 267, 283, 1231, 356, 359, 288, 2387, 360, 3349, 659, 288, 2387, 360, 1302, 659, 288, 2387, 360, 698, 659, 288, 2387, 360, 765, 659, 288, 2387, 360, 533, 659, 288, 2387, 360, 15047, 659, 288, 2387, 360, 2732, 13, 18156, 659, 288, 2387, 360, 22880, 659, 288, 2387, 360, 8939, 659, 288, 2387, 360, 25181, 659, 288, 2387, 360, 466, 659, 288, 2387, 360, 8506, 358, 267, 2156, 267, 283, 15047, 356, 359, 288, 334, 82, 23811, 971, 84, 3672, 4537, 8, 533, 92, 4792, 92, 24900, 92, 698, 92, 954, 9340, 92, 9340, 5227, 1467, 519, 7, 4869, 92, 765, 92, 30792, 92, 9350, 92, 1144, 13, 576, 92, 12286, 13, 5656, 5227, 1467, 519, 1159, 1122, 13, 5656, 92, 9341, 452, 92, 9341, 92, 604, 92, 5329, 92, 1832, 92, 496, 793, 310, 5227, 1467, 519, 7, 28349, 310, 92, 1365, 3196, 6431, 395, 288, 334, 82, 23811, 971, 84, 3672, 4537, 500, 334, 698, 92, 954, 9340, 92, 9340, 92, 765, 92, 1144, 13, 576, 5227, 1467, 283, 12286, 13, 5656, 92, 4421, 13, 5656, 92, 5329, 92, 1832, 3196, 6431, 395, 288, 334, 82, 23811, 971, 84, 3672, 4537, 10506, 2257, 297, 6431, 395, 267, 2156, 267, 283, 2732, 13, 18156, 356, 359, 288, 334, 82, 6774, 3455, 92, 4239, 92, 6798, 92, 1986, 92, 5094, 92, 16473, 1759, 92, 9528, 5227, 1467, 519, 7, 27367, 92, 6106, 92, 6198, 92, 4768, 3997, 92, 9466, 21231, 92, 1880, 5227, 1467, 519, 5121, 825, 416, 581, 13, 16473, 1759, 92, 3266, 92, 4869, 92, 9340, 92, 32059, 5227, 1467, 519, 1133, 1312, 14928, 3196, 6431, 395, 267, 2156, 267, 283, 8506, 356, 359, 288, 334, 82, 1154, 78, 297, 4516, 395, 288, 334, 82, 1154, 83, 7386, 4516, 395, 267, 2156, 267, 283, 22880, 356, 359, 288, 334, 82, 1154, 66, 59, 11702, 7272, 68, 7896, 66, 297, 2812, 14, 12306, 395, 221, 327, 24493, 288, 334, 82, 1154, 66, 59, 65, 13, 90, 1527, 33, 13, 13163, 13, 90, 16, 13, 25, 15, 20253, 60, 83, 7386, 4516, 395, 221, 327, 15794, 267, 2156, 267, 283, 8939, 356, 359, 288, 334, 82, 7, 1674, 10, 6949, 2624, 395, 288, 334, 82, 7, 16, 88, 59, 16, 13, 25, 33, 13, 1906, 13, 70, 2807, 84, 7044, 4860, 14, 10373, 395, 288, 334, 82, 3894, 16, 13, 25, 3672, 27658, 16, 13, 25, 2807, 779, 20565, 1527, 16, 13, 25, 23763, 59, 2592, 61, 7044, 4860, 14, 5136, 395, 288, 334, 82, 3894, 16, 13, 25, 2807, 44, 7044, 4860, 14, 2674, 395, 267, 2156, 267, 283, 698, 356, 359, 288, 334, 82, 13445, 4, 8995, 66, 9, 16510, 87, 4, 3672, 5130, 26, 3196, 1467, 10259, 8, 48, 7771, 12, 2812, 14, 2773, 12, 10357, 1826, 267, 2156, 267, 283, 765, 356, 359, 288, 334, 82, 7601, 5169, 429, 5547, 826, 4206, 2812, 14, 3481, 395, 221, 327, 3787, 288, 334, 82, 13445, 4, 8995, 66, 9, 16510, 87, 4, 3672, 10127, 19633, 1467, 10259, 8, 48, 7771, 12, 2812, 14, 3481, 12, 10357, 1826, 267, 2156, 267, 283, 1302, 356, 359, 288, 334, 82, 356, 60, 87, 7386, 2812, 14, 4314, 395, 267, 2156, 267, 283, 533, 356, 359, 288, 327, 1021, 1561, 315, 314, 1824, 491, 957, 15, 3251, 15, 23200, 27, 288, 327, 473, 1454, 2934, 370, 3164, 314, 8089, 985, 1777, 12, 880, 314, 3231, 1777, 365, 288, 327, 10184, 465, 283, 1872, 7, 288, 334, 82, 6774, 44, 9, 17304, 26, 7023, 87, 4, 2807, 15, 3342, 9, 16510, 87, 4, 2807, 5130, 27, 3196, 355, 10259, 8, 10650, 14, 804, 12, 4516, 12, 2812, 14, 2543, 12, 4516, 1826, 267, 2156, 267, 283, 25181, 356, 359, 288, 334, 82, 12418, 4206, 10357, 395, 288, 334, 82, 3894, 27125, 837, 15856, 13, 4300, 10357, 395, 267, 2156, 267, 283, 466, 356, 359, 288, 334, 82, 3894, 58, 11087, 3553, 42, 38, 6741, 25621, 11529, 6431, 14, 804, 395, 267, 2156, 267, 283, 3349, 356, 359, 288, 334, 82, 11525, 21040, 78, 297, 6819, 395, 267, 2156, 272, 789, 339, 347, 21297, 63, 505, 8, 505, 304, 267, 5396, 275, 378, 267, 340, 295, 14, 1733, 8, 82, 15542, 83, 10, 4537, 533, 60, 83, 297, 1318, 12, 295, 14, 16661, 304, 288, 5396, 847, 378, 14, 21, 288, 340, 295, 14, 1733, 8, 82, 1154, 66, 1332, 1074, 13, 2931, 92, 842, 13, 1618, 92, 11964, 13, 16257, 13, 705, 7, 586, 519, 24431, 66, 92, 2801, 475, 92, 525, 17884, 65, 374, 61, 362, 17884, 65, 374, 61, 524, 92, 460, 92, 67, 2421, 92, 1297, 92, 3015, 5227, 586, 519, 7, 692, 92, 15195, 92, 1185, 92, 3703, 92, 8705, 92, 1397, 92, 269, 92, 13179, 92, 1107, 92, 82, 954, 92, 609, 76, 5227, 586, 519, 1159, 6271, 92, 954, 92, 2084, 82, 15786, 15, 566, 92, 91, 92, 7293, 1318, 12, 295, 14, 16661, 304, 355 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 272, 13277, 14, 12245, 14, 12390, 433, 75, 272, 18294, 2878, 1714, 339, 14493, 7103, 1192, 367, 577, 279, 433, 75, 7525, 13, 2407, 10815, 14, 339, 520, 7307, 26, 1898, 8315, 13, 7806, 701, 314, 14493, 8099, 12, 1937, 10610, 14, 272, 520, 1682, 26, 6289, 12, 1937, 5113, 367, 2436, 14, 199, 624, 199, 199, 646, 295, 199, 199, 504, 13277, 14, 11729, 492, 12939, 5838, 12, 2387, 12, 10259, 199, 504, 13277, 14, 1418, 492, 6431, 12, 4516, 12, 6819, 12, 2812, 12, 2624, 12, 4860, 12, 971, 272, 10357, 199, 199, 363, 452, 363, 275, 788, 51, 2174, 73, 5838, 418, 421, 199, 533, 428, 2174, 73, 5838, 8, 19856, 304, 272, 408, 272, 2104, 658, 51, 2174, 73, 665, 1014, 921, 600, 14, 3098, 14, 957, 15, 80, 15, 24460, 73, 3133, 18417, 334, 20762, 15, 36, 279, 433, 75, 9, 24869, 272, 1233, 14, 339, 2508, 7445, 447, 413, 14, 22, 272, 408, 272, 536, 275, 283, 51, 2174, 73, 7, 272, 5481, 275, 788, 24460, 73, 418, 272, 6203, 275, 17855, 24460, 73, 418, 272, 13290, 275, 788, 505, 15, 24460, 73, 418, 339, 4645, 275, 469, 267, 283, 1231, 356, 359, 288, 2387, 360, 3349, 659, 288, 2387, 360, 1302, 659, 288, 2387, 360, 698, 659, 288, 2387, 360, 765, 659, 288, 2387, 360, 533, 659, 288, 2387, 360, 15047, 659, 288, 2387, 360, 2732, 13, 18156, 659, 288, 2387, 360, 22880, 659, 288, 2387, 360, 8939, 659, 288, 2387, 360, 25181, 659, 288, 2387, 360, 466, 659, 288, 2387, 360, 8506, 358, 267, 2156, 267, 283, 15047, 356, 359, 288, 334, 82, 23811, 971, 84, 3672, 4537, 8, 533, 92, 4792, 92, 24900, 92, 698, 92, 954, 9340, 92, 9340, 5227, 1467, 519, 7, 4869, 92, 765, 92, 30792, 92, 9350, 92, 1144, 13, 576, 92, 12286, 13, 5656, 5227, 1467, 519, 1159, 1122, 13, 5656, 92, 9341, 452, 92, 9341, 92, 604, 92, 5329, 92, 1832, 92, 496, 793, 310, 5227, 1467, 519, 7, 28349, 310, 92, 1365, 3196, 6431, 395, 288, 334, 82, 23811, 971, 84, 3672, 4537, 500, 334, 698, 92, 954, 9340, 92, 9340, 92, 765, 92, 1144, 13, 576, 5227, 1467, 283, 12286, 13, 5656, 92, 4421, 13, 5656, 92, 5329, 92, 1832, 3196, 6431, 395, 288, 334, 82, 23811, 971, 84, 3672, 4537, 10506, 2257, 297, 6431, 395, 267, 2156, 267, 283, 2732, 13, 18156, 356, 359, 288, 334, 82, 6774, 3455, 92, 4239, 92, 6798, 92, 1986, 92, 5094, 92, 16473, 1759, 92, 9528, 5227, 1467, 519, 7, 27367, 92, 6106, 92, 6198, 92, 4768, 3997, 92, 9466, 21231, 92, 1880, 5227, 1467, 519, 5121, 825, 416, 581, 13, 16473, 1759, 92, 3266, 92, 4869, 92, 9340, 92, 32059, 5227, 1467, 519, 1133, 1312, 14928, 3196, 6431, 395, 267, 2156, 267, 283, 8506, 356, 359, 288, 334, 82, 1154, 78, 297, 4516, 395, 288, 334, 82, 1154, 83, 7386, 4516, 395, 267, 2156, 267, 283, 22880, 356, 359, 288, 334, 82, 1154, 66, 59, 11702, 7272, 68, 7896, 66, 297, 2812, 14, 12306, 395, 221, 327, 24493, 288, 334, 82, 1154, 66, 59, 65, 13, 90, 1527, 33, 13, 13163, 13, 90, 16, 13, 25, 15, 20253, 60, 83, 7386, 4516, 395, 221, 327, 15794, 267, 2156, 267, 283, 8939, 356, 359, 288, 334, 82, 7, 1674, 10, 6949, 2624, 395, 288, 334, 82, 7, 16, 88, 59, 16, 13, 25, 33, 13, 1906, 13, 70, 2807, 84, 7044, 4860, 14, 10373, 395, 288, 334, 82, 3894, 16, 13, 25, 3672, 27658, 16, 13, 25, 2807, 779, 20565, 1527, 16, 13, 25, 23763, 59, 2592, 61, 7044, 4860, 14, 5136, 395, 288, 334, 82, 3894, 16, 13, 25, 2807, 44, 7044, 4860, 14, 2674, 395, 267, 2156, 267, 283, 698, 356, 359, 288, 334, 82, 13445, 4, 8995, 66, 9, 16510, 87, 4, 3672, 5130, 26, 3196, 1467, 10259, 8, 48, 7771, 12, 2812, 14, 2773, 12, 10357, 1826, 267, 2156, 267, 283, 765, 356, 359, 288, 334, 82, 7601, 5169, 429, 5547, 826, 4206, 2812, 14, 3481, 395, 221, 327, 3787, 288, 334, 82, 13445, 4, 8995, 66, 9, 16510, 87, 4, 3672, 10127, 19633, 1467, 10259, 8, 48, 7771, 12, 2812, 14, 3481, 12, 10357, 1826, 267, 2156, 267, 283, 1302, 356, 359, 288, 334, 82, 356, 60, 87, 7386, 2812, 14, 4314, 395, 267, 2156, 267, 283, 533, 356, 359, 288, 327, 1021, 1561, 315, 314, 1824, 491, 957, 15, 3251, 15, 23200, 27, 288, 327, 473, 1454, 2934, 370, 3164, 314, 8089, 985, 1777, 12, 880, 314, 3231, 1777, 365, 288, 327, 10184, 465, 283, 1872, 7, 288, 334, 82, 6774, 44, 9, 17304, 26, 7023, 87, 4, 2807, 15, 3342, 9, 16510, 87, 4, 2807, 5130, 27, 3196, 355, 10259, 8, 10650, 14, 804, 12, 4516, 12, 2812, 14, 2543, 12, 4516, 1826, 267, 2156, 267, 283, 25181, 356, 359, 288, 334, 82, 12418, 4206, 10357, 395, 288, 334, 82, 3894, 27125, 837, 15856, 13, 4300, 10357, 395, 267, 2156, 267, 283, 466, 356, 359, 288, 334, 82, 3894, 58, 11087, 3553, 42, 38, 6741, 25621, 11529, 6431, 14, 804, 395, 267, 2156, 267, 283, 3349, 356, 359, 288, 334, 82, 11525, 21040, 78, 297, 6819, 395, 267, 2156, 272, 789, 339, 347, 21297, 63, 505, 8, 505, 304, 267, 5396, 275, 378, 267, 340, 295, 14, 1733, 8, 82, 15542, 83, 10, 4537, 533, 60, 83, 297, 1318, 12, 295, 14, 16661, 304, 288, 5396, 847, 378, 14, 21, 288, 340, 295, 14, 1733, 8, 82, 1154, 66, 1332, 1074, 13, 2931, 92, 842, 13, 1618, 92, 11964, 13, 16257, 13, 705, 7, 586, 519, 24431, 66, 92, 2801, 475, 92, 525, 17884, 65, 374, 61, 362, 17884, 65, 374, 61, 524, 92, 460, 92, 67, 2421, 92, 1297, 92, 3015, 5227, 586, 519, 7, 692, 92, 15195, 92, 1185, 92, 3703, 92, 8705, 92, 1397, 92, 269, 92, 13179, 92, 1107, 92, 82, 954, 92, 609, 76, 5227, 586, 519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