ÿØÿà JFIF    ÿÛ „  ( %"1!%)+...383,7(-.+  -+++--++++---+-+-----+---------------+---+-++7-----ÿÀ  ß â" ÿÄ     ÿÄ H    !1AQaq"‘¡2B±ÁÑð#R“Ò Tbr‚²á3csƒ’ÂñDS¢³$CÿÄ   ÿÄ %  !1AQa"23‘ÿÚ   ? ôÿ ¨pŸªáÿ —åYõõ\?àÒü©ŠÄï¨pŸªáÿ —åYõõ\?àÓü©ŠÄá 0Ÿªáÿ Ÿå[úƒ ú®ði~TÁbqÐ8OÕpÿ ƒOò¤Oè`–RÂáœá™êi€ßÉ< FtŸI“öÌ8úDf´°å}“¾œ6  öFá°y¥jñÇh†ˆ¢ã/ÃÐ:ªcÈ "Y¡ðÑl>ÿ ”ÏËte:qž\oäŠe÷󲍷˜HT4&ÿ ÓÐü6ö®¿øþßèô Ÿ•7Ñi’•j|“ñì>b…þS?*Óôÿ ÓÐü*h¥£ír¶ü UãS炟[AÐaè[ûª•õ&õj?†Éö+EzP—WeÒírJFt ‘BŒ†Ï‡%#tE Øz ¥OÛ«!1›üä±Í™%ºÍãö]°î(–:@<‹ŒÊö×òÆt¦ãº+‡¦%ÌÁ²h´OƒJŒtMÜ>ÀÜÊw3Y´•牋4ǍýʏTì>œú=Íwhyë,¾Ôò×õ¿ßÊa»«þˆѪQ|%6ž™A õ%:øj<>É—ÿ Å_ˆCbõ¥š±ý¯Ýƒï…¶|RëócÍf溪“t.СøTÿ *Ä¿-{†çàczůŽ_–^XþŒ±miB[X±d 1,é”zEù»& î9gœf™9Ð'.;—™i}!ôšåîqêÛ٤ёý£½ÆA–àôe"A$˝Úsäÿ ÷Û #°xŸëí(l »ý3—¥5m! rt`†0~'j2(]S¦¦kv,ÚÇ l¦øJA£Šƒ J3E8ÙiŽ:cÉžúeZ°€¯\®kÖ(79«Ž:¯X”¾³Š&¡* ….‰Ž(ÜíŸ2¥ª‡×Hi²TF¤ò[¨íÈRëÉ䢍mgÑ.Ÿ<öäS0í„ǹÁU´f#Vß;Õ–…P@3ío<ä-±»Ž.L|kªÀê›fÂ6@»eu‚|ÓaÞÆŸ…¨ááå>åŠ?cKü6ùTÍÆ”†sĤÚ;H2RÚ†õ\Ö·Ÿn'¾ ñ#ºI¤Å´%çÁ­‚â7›‹qT3Iï¨ÖÚ5I7Ë!ÅOóŸ¶øÝñØôת¦$Tcö‘[«Ö³šÒ';Aþ ¸èíg A2Z"i¸vdÄ÷.iõ®§)¿]¤À†–‡É&ä{V¶iŽ”.Ó×Õÿ û?h¬Mt–íª[ÿ Ñÿ ÌV(í}=ibÔ¡›¥¢±b Lô¥‡piη_Z<‡z§èŒ)iÖwiÇ 2hÙ3·=’d÷8éŽ1¦¸c¤µ€7›7Ø ð\á)} ¹fËí›pAÃL%âc2 í§æQz¿;T8sæ°qø)QFMð‰XŒÂ±N¢aF¨…8¯!U  Z©RÊ ÖPVÄÀÍin™Ì-GˆªÅËŠ›•zË}º±ŽÍFò¹}Uw×#ä5B¤{î}Ð<ÙD é©¤&‡ïDbàÁôMÁ." ¤‡ú*õ'VŽ|¼´Úgllº¼klz[Æüï÷Aób‡Eÿ dÑ»Xx9ÃÜ£ÁT/`¼¸vI±Ýµ·Ë‚“G³þ*Ÿû´r|*}<¨îºœ @¦mÄ’M¹”.œ«Y–|6ÏU¤jç¥ÕÞqO ˜kDÆÁ¨5ÿ š;ÐЦ¦€GÙk \ –Þ=â¼=SͧµªS°ÚÍpÜãQűÀõ¬?ÃÁ1Ñ•õZà?hóœ€ L¦l{Y*K˜Ù›zc˜–ˆâ ø+¾ ­-Ök¥%ùEÜA'}ˆ><ÊIè“bpÍ/qÞâvoX€w,\úªò6Z[XdÒæ­@Ö—€$òJí#é>'°Ú ôª˜<)4ryÙ£|óAÅn5žêŸyÒäMÝ2{"}‰–¤l÷ûWX\l¾Á¸góÉOÔ /óñB¤f¸çñ[.P˜ZsÊË*ßT܈§QN¢’¡¨§V¼(Üù*eÕ“”5T¨‹Âê¥FŒã½Dü[8'Ò¥a…Ú¶k7a *•›¼'Ò·\8¨ª\@\õ¢¦íq+DÙrmÎ…_ªæ»ŠÓœ¡¯’Ré9MÅ×D™lælffc+ŒÑ,ý™ÿ ¯þǤ=Å’Á7µ÷ÚÛ/“Ü€ñýã¼àí¾ÕÑ+ƒ,uµMâÀÄbm:ÒÎPæ{˜Gz[ƒ¯«® KHà`ߨŠéí¯P8Aq.C‰ à€kòpj´kN¶qô€…Õ,ÜNŠª-­{Zö’æû44‰sŽè‰îVíRœÕm" 6?³D9¡ÇTíÅꋇ`4«¸ÝÁô ï’ýorqКÇZ«x4Žâéþuïf¹µö[P ,Q£éaX±`PÉÍZ ¸äYúg üAx ’6Lê‚xÝÓ*äQ  Ï’¨hÍ =²,6ï#rÃ<¯–£»ƒ‹,–ê•€ aÛsñ'%Æ"®ÛüìBᝠHÚ3ß°©$“XnœÖ’î2ËTeûìxîß ¦å¿çÉ ðK§þ{‘t‚Ϋ¬jéîZ[ ”š7L¥4VÚCE×]m¤Øy”ä4-dz£œ§¸x.*ãÊÊ b÷•h:©‡¦s`BTÁRû¾g⻩‹jø sF¢àJøFl‘È•Xᓁà~*j¯ +(ÚÕ6-£¯÷GŠØy‚<Ç’.F‹Hœw(+)ÜÜâÈzÄäT§FߘãÏ;DmVœ3Àu@mÚüXÝü•3B¨òÌÁÛ<·ÃÜ z,Ì@õÅ·d2]ü8s÷IôÞ¯^Ç9¢u„~ëAŸï4«M? K]­ÅàPl@s_ p:°¬ZR”´›JC[CS.h‹ƒïËœ«Æ]–÷ó‚wR×k7X‰k›‘´ù¦=¡«‰¨¨Â')—71ó’c‡Ðúµ `é.{§p¹ój\Ž{1h{o±Ý=áUÊïGÖŒõ–-BÄm+AZX¶¡ ïHðæ¥JmÙ;…䡟ˆ¦ ° äšiÉg«$üMk5¤L“’çÊvïâï ,=f“"íἊ5ô¬x6{ɏžID0e¸vçmi'︧ºð9$ò¹÷*£’9ÿ ²TÔ…×>JV¥}Œ}$p[bÔ®*[jzS*8 ”·T›Í–ñUîƒwo$áè=LT™ç—~ô·¤ÈÚ$榍q‰„+´kFm)ž‹©i–ËqÞŠ‰à¶ü( ‚•§ •°ò·‡#5ª•µÊ﯅¡X¨šÁ*F#TXJÊ ušJVÍ&=iÄs1‚3•'fý§5Ñ<=[íÞ­ PÚ;ѱÌ_~Ä££8rÞ ²w;’hDT°>ÈG¬8Á²ÚzŽ®ò®qZcqJêäÞ-ö[ܘbň±çb“ж31²n×iƒðÕ;1¶þÉ ªX‰,ßqÏ$>•î íZ¥Z 1{ç൵+ƒÕµ¥°T$§K]á»Ûï*·¤tMI’ÂZbŽÕiÒ˜}bÓ0£ª5›¨ [5Ž^ÝœWøÂÝh° ¢OWun£¤5 a2Z.G2³YL]jåtì”ä ÁÓ‘%"©<Ôúʰsº UZvä‡ÄiÆÒM .÷V·™ø#kèýiíÌ–ª)µT[)BˆõÑ xB¾B€ÖT¨.¥~ð@VĶr#¸ü*åZNDŽH;âi ],©£öØpù(šºãö¼T.uCê•4@ÿ GÕÛ)Cx›®0ø#:ÏðFÒbR\(€€Ä®fã4Þ‰Fä¯HXƒÅ,†öEÑÔÜ]Öv²?tLÃvBY£ú6Êu5ÅAQ³1‘’¬x–HŒÐ‡ ^ ¸KwJôÖŽ5×CÚ¨vÜ«/B0$×k°=ðbÇ(Ï)w±A†Á† 11Í=èQšµ626ŒÜ/`G«µ<}—-Ö7KEHÈÉðóȤmݱû±·ø«Snmá=“䫚mݱŸ¡¶~ó·“äUóJæúòB|E LêŽy´jDÔ$G¢þÐñ7óR8ýÒ…Ç› WVe#·Ÿ p·Fx~•ݤF÷0Èÿ K¯æS<6’¡WШ; ´ÿ ¥Êø\Òuî†åÝ–VNœkÒ7oòX¨Á­Ø÷FÎÑä±g÷ÿ M~Çî=p,X´ ÝÌÚÅ‹’ÃjÖ.ØöÏñ qïQ¤ÓZE†° =6·]܈ s¸>v•Ž^Ý\wq9r‰Î\¸¡kURÒ$­*‹Nq?Þª*!sŠÆ:TU_u±T+øX¡ ®¹¡,ÄâÃBTsÜ$Ø›4m椴zÜK]’’›Pƒ @€#â˜`é¹=I‡fiV•Ôî“nRm+µFPOhÍ0B£ €+¬5c v•:P'ÒyÎ ‰V~‚Ó†ÖuókDoh$å\*ö%Ю=£«…aȼ½÷Û.-½VŒŠ¼'lyî±1¬3ó#ÞE¿ÔS¤gV£m›=§\û"—WU¤ÚǼÿ ÂnÁGŒÃ ‚õN D³õNÚíŒÕ;HôyÄÈ©P¹Ä{:?R‘Ô¨âF÷ø£bÅó® JS|‚R÷ivýáâ€Æé¡è³´IئÑT!§˜•ت‚¬â@q€wnïCWÄ@JU€ê¯m6]Ï:£âx'+ÒðXvÓ¦Úm=–´7œ $ì“B£~p%ÕŸUþ« N@¼üï~w˜ñø5®—'Ôe»¤5ã//€ž~‰Tþ›Å7•#¤× Íö pÄ$ùeåì*«ÓŠEØWEÈsßg ¦ûvžSsLpºÊW–âµEWöˬH; ™!CYõZ ÃÄf æ#1W. \uWâ\,\Çf j’<qTbên›Î[vxx£ë 'ö¨1›˜ÀM¼Pÿ H)ƒêêŒA7s,|F“ 꺸k³9Ìö*ç®;Ö!Ö$Eiž•¹ÒÚ†ýóéÝû¾ÕS®ó$’NÝäŸz¤5r¦ãÄÃD÷Üø!°ø‡Ô&@m™Ì^Ãä­d q5Lnÿ N;.6½·N|#ä"1Nƒx“ã<3('&ñßt  ~ªu”1Tb㫨9ê–›–bìd$ߣ=#ÕãÒmU¯eí$EFù5ýYô櫨æì™Ç—±ssM]·á¿0ÕåJRÓªîiƒ+O58ÖñªŠÒx" \µâá¨i’¤i —Ö ” M+M¤ë9‚‰A¦°Qõ¾ßøK~¼Ã‘g…Ö´~÷Ï[3GUœÒ½#…kàÔ®Ò”‰³·dWV‰IP‰Ú8u¹”E ÖqLj¾êÕCBš{A^Âß;–¨`¯¬ìö ˼ ×tìø.tƐm*n¨y4o&Àx¥n¦×î‡aupáÛj8¿m›è¶ã!o½;ß0y^ý×^EÑ¿ÒjzŒ­)vÚÑnÄL …^ªô× ‡—‚3k Îý­hï]içå–îÏ*÷ñþ»Ô CÒjøjÍznˆ´ ¹#b'Fô‹ ‰v¥'’à'T´ƒHýÍ%M‰ ƒ&ÆÇŒï1 ‘ –Þ ‰i¬s žR-Ÿ kЬá¬7:þ 0ŒÅÒÕ/aÙ¬ÃÝ#Úøœ ©aiVc‰. ¹¦ãµ” ›Yg¦›ÆÎýº°f³7ƒhá·¸­}&D9¡ÂsÉÙÞèŠõØàC™¨ñbFC|´Ü(ŸƒÚÒ-%»'a Ì¿)ËÇn¿úÿ ÞŽX…4ÊÅH^ôΑí@ù¹Eh¶“L8Çjù ¼ÎåVªóR©Ï5uà V4lZß®=€xÖŸ–ÑÈ ÷”¨°¾__yM1tÉ?uÆþIkÄgæ@þ[¢†°XÃJ£j·:nkÅ¢u ‘}âGzö­/IµèЬ¼48q¦F°ŽR¼=ûì{´¯RýicS ÕÛ íNtÍÙï£,w4rêì®»~x(©Uñ§#Ñ&œÕ¤>ÎåÍÓ9’Ö{9eV­[Öjâ²ãu]˜å2›qÑšÕJç0€sÄ|Êëè0튔bÁ>“{×_F`Ø©ºê:µä,v¤ðfc1±"«ÔÍän1#=· Âøv~H½ÐßA¾¿Ü€Óš]Õ; I¾÷ç‚Qi†î¹9ywÔKG˜áñ zQY—§ÃÕZ07§X‚ Áh;ÁM)iÌCH-¯T‘ë|A0{Ò½LÚ–TâÖkÜ’dÀ“rmm»”جPF³ÖcbE§T€ÒxKºû’Ó®7±²(\4ŽÃ¸Uu@j™yĵ;³µ!Á¢b.W¤=mõ´êµK k ¸K^ÜÛ#p*Ü14qkZç5ïë †°5Ï%ÍÛ<Õ¤×Ô¥ê†C Õ´¼ú$ƒÖ“”]Ù¬qÞÚ[4©ý!ûÏ—Áb쳐XµA¬â~`›Çr¸8ìùÝ䫦<>ä÷«?xs´ÇÑ /á;¹øüÊÈÙà{"@Žïzâ¬[âß‚ U_<ÇŸ½4èN˜ú61®qŠu ¦þF£»äJ_ˆÙÎ~ ÞAã–݄ϗrŠD;xTž‘ô`É«…suãO`?³à™ô Lý#Íc5öoæØ‚y´´÷«ZR§<&JÇ+éâô´€i!Àˆ0æAoàðLèÖ-2ŸõW.’t^–(KÁmHµV@xÜÇy®Ñø­â^:Ú3w· 7½¹°ñ¸â¹®:',«Mœ—n­Á+Ãbš LÈ‘ÄnRÓÅœ%¦²‰¨ùQ:¤f‚ "PÕtô¸…cæl…&˜Ú˜Ôkv‹ž+vŠ,=¢v­6—Xy*¥t£«<™:“aîϲ=¦6rO]XI¿Œ÷¤zÚ­›¶ 6÷”w\d ü~v®ˆÌk«^m<ÿ ¢‰Õ\)ùºŽ;… lîÙÅEŠ®cѾ@vnMÏ,¼“ñ•ŽBxðÃzãÇç%3ˆ"}Ù•Åî> BÉú;Ò]V+P˜F_´ßé> Øše|ï‡ÄOmFæÇ ãqÞ$/xÐx­z`ï9"œÜij‚!7.\Td…9M‡•iŽ‹¾‘50ÞŽn¥ß4ÉôO ¹*í^QêËÜÇÌ8=ާs‰'ÂëÙ«á%Pú[O †ÅP¯Vsް.‰,kc¶ ¬A9n˜XÎ-ÞšN["¹QÕ‰ƒMýÁߺXJæÍaLj¾×Ãmã¾ãÚ uñÒþåQô¦¥ /ÄUx:‚ÍÜ’ Đ©ØÝ3V¨‰ÕnÐ6ó*óúK­«…c ¯U òhsý­jóÔj#,ímŒRµ«lbïUTŒÑ8†Ä0œÏr`ð¡¬É Ї ë"À² ™ 6¥ f¶ ¢ÚoܱԷ-<Àî)†a¶ž'Ú»¨TXqØæ¶÷YÄHy˜9ÈIW­YÀuMFë ºÏ’AqÌ4·/Ú †ô'i$øä­=Ä Ý|öK×40è|È6p‘0§)o¥ctî§H+CA-“ xØ|ÐXАç l8íºð3Ø:³¤¬KX¯UÿÙ # -*- test-case-name: twisted.names.test.test_names -*- # Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Authoritative resolvers. """ from __future__ import absolute_import, division import os import time from twisted.names import dns, error, common from twisted.internet import defer from twisted.python import failure from twisted.python.compat import execfile, nativeString, _PY3 from twisted.python.filepath import FilePath def getSerial(filename='/tmp/twisted-names.serial'): """ Return a monotonically increasing (across program runs) integer. State is stored in the given file. If it does not exist, it is created with rw-/---/--- permissions. @param filename: Path to a file that is used to store the state across program runs. @type filename: L{str} @return: a monotonically increasing number @rtype: L{str} """ serial = time.strftime('%Y%m%d') o = os.umask(0o177) try: if not os.path.exists(filename): with open(filename, 'w') as f: f.write(serial + ' 0') finally: os.umask(o) with open(filename, 'r') as serialFile: lastSerial, zoneID = serialFile.readline().split() zoneID = (lastSerial == serial) and (int(zoneID) + 1) or 0 with open(filename, 'w') as serialFile: serialFile.write('%s %d' % (serial, zoneID)) serial = serial + ('%02d' % (zoneID,)) return serial class FileAuthority(common.ResolverBase): """ An Authority that is loaded from a file. @ivar _ADDITIONAL_PROCESSING_TYPES: Record types for which additional processing will be done. @ivar _ADDRESS_TYPES: Record types which are useful for inclusion in the additional section generated during additional processing. @ivar soa: A 2-tuple containing the SOA domain name as a L{bytes} and a L{dns.Record_SOA}. """ # See https://twistedmatrix.com/trac/ticket/6650 _ADDITIONAL_PROCESSING_TYPES = (dns.CNAME, dns.MX, dns.NS) _ADDRESS_TYPES = (dns.A, dns.AAAA) soa = None records = None def __init__(self, filename): common.ResolverBase.__init__(self) self.loadFile(filename) self._cache = {} def __setstate__(self, state): self.__dict__ = state def _additionalRecords(self, answer, authority, ttl): """ Find locally known information that could be useful to the consumer of the response and construct appropriate records to include in the I{additional} section of that response. Essentially, implement RFC 1034 section 4.3.2 step 6. @param answer: A L{list} of the records which will be included in the I{answer} section of the response. @param authority: A L{list} of the records which will be included in the I{authority} section of the response. @param ttl: The default TTL for records for which this is not otherwise specified. @return: A generator of L{dns.RRHeader} instances for inclusion in the I{additional} section. These instances represent extra information about the records in C{answer} and C{authority}. """ for record in answer + authority: if record.type in self._ADDITIONAL_PROCESSING_TYPES: name = record.payload.name.name for rec in self.records.get(name.lower(), ()): if rec.TYPE in self._ADDRESS_TYPES: yield dns.RRHeader( name, rec.TYPE, dns.IN, rec.ttl or ttl, rec, auth=True) def _lookup(self, name, cls, type, timeout=None): """ Determine a response to a particular DNS query. @param name: The name which is being queried and for which to lookup a response. @type name: L{bytes} @param cls: The class which is being queried. Only I{IN} is implemented here and this value is presently disregarded. @type cls: L{int} @param type: The type of records being queried. See the types defined in L{twisted.names.dns}. @type type: L{int} @param timeout: All processing is done locally and a result is available immediately, so the timeout value is ignored. @return: A L{Deferred} that fires with a L{tuple} of three sets of response records (to comprise the I{answer}, I{authority}, and I{additional} sections of a DNS response) or with a L{Failure} if there is a problem processing the query. """ cnames = [] results = [] authority = [] additional = [] default_ttl = max(self.soa[1].minimum, self.soa[1].expire) domain_records = self.records.get(name.lower()) if domain_records: for record in domain_records: if record.ttl is not None: ttl = record.ttl else: ttl = default_ttl if (record.TYPE == dns.NS and name.lower() != self.soa[0].lower()): # NS record belong to a child zone: this is a referral. As # NS records are authoritative in the child zone, ours here # are not. RFC 2181, section 6.1. authority.append( dns.RRHeader( name, record.TYPE, dns.IN, ttl, record, auth=False ) ) elif record.TYPE == type or type == dns.ALL_RECORDS: results.append( dns.RRHeader( name, record.TYPE, dns.IN, ttl, record, auth=True ) ) if record.TYPE == dns.CNAME: cnames.append( dns.RRHeader( name, record.TYPE, dns.IN, ttl, record, auth=True ) ) if not results: results = cnames # Sort of https://tools.ietf.org/html/rfc1034#section-4.3.2 . # See https://twistedmatrix.com/trac/ticket/6732 additionalInformation = self._additionalRecords( results, authority, default_ttl) if cnames: results.extend(additionalInformation) else: additional.extend(additionalInformation) if not results and not authority: # Empty response. Include SOA record to allow clients to cache # this response. RFC 1034, sections 3.7 and 4.3.4, and RFC 2181 # section 7.1. authority.append( dns.RRHeader( self.soa[0], dns.SOA, dns.IN, ttl, self.soa[1], auth=True ) ) return defer.succeed((results, authority, additional)) else: if dns._isSubdomainOf(name, self.soa[0]): # We may be the authority and we didn't find it. # XXX: The QNAME may also be in a delegated child zone. See # #6581 and #6580 return defer.fail( failure.Failure(dns.AuthoritativeDomainError(name)) ) else: # The QNAME is not a descendant of this zone. Fail with # DomainError so that the next chained authority or # resolver will be queried. return defer.fail(failure.Failure(error.DomainError(name))) def lookupZone(self, name, timeout=10): if self.soa[0].lower() == name.lower(): # Wee hee hee hooo yea default_ttl = max(self.soa[1].minimum, self.soa[1].expire) if self.soa[1].ttl is not None: soa_ttl = self.soa[1].ttl else: soa_ttl = default_ttl results = [ dns.RRHeader( self.soa[0], dns.SOA, dns.IN, soa_ttl, self.soa[1], auth=True ) ] for (k, r) in self.records.items(): for rec in r: if rec.ttl is not None: ttl = rec.ttl else: ttl = default_ttl if rec.TYPE != dns.SOA: results.append( dns.RRHeader( k, rec.TYPE, dns.IN, ttl, rec, auth=True ) ) results.append(results[0]) return defer.succeed((results, (), ())) return defer.fail(failure.Failure(dns.DomainError(name))) def _cbAllRecords(self, results): ans, auth, add = [], [], [] for res in results: if res[0]: ans.extend(res[1][0]) auth.extend(res[1][1]) add.extend(res[1][2]) return ans, auth, add class PySourceAuthority(FileAuthority): """ A FileAuthority that is built up from Python source code. """ def loadFile(self, filename): g, l = self.setupConfigNamespace(), {} execfile(filename, g, l) if 'zone' not in l: raise ValueError("No zone defined in " + filename) self.records = {} for rr in l['zone']: if isinstance(rr[1], dns.Record_SOA): self.soa = rr self.records.setdefault(rr[0].lower(), []).append(rr[1]) def wrapRecord(self, type): return lambda name, *arg, **kw: (name, type(*arg, **kw)) def setupConfigNamespace(self): r = {} items = dns.__dict__.iterkeys() for record in [x for x in items if x.startswith('Record_')]: type = getattr(dns, record) f = self.wrapRecord(type) r[record[len('Record_'):]] = f return r class BindAuthority(FileAuthority): """ An Authority that loads U{BIND zone files }. Supports only C{$ORIGIN} and C{$TTL} directives. """ def loadFile(self, filename): """ Load records from C{filename}. @param filename: file to read from @type filename: L{bytes} """ fp = FilePath(filename) # Not the best way to set an origin. It can be set using $ORIGIN # though. self.origin = nativeString(fp.basename() + b'.') lines = fp.getContent().splitlines(True) lines = self.stripComments(lines) lines = self.collapseContinuations(lines) self.parseLines(lines) def stripComments(self, lines): """ Strip comments from C{lines}. @param lines: lines to work on @type lines: iterable of L{bytes} @return: C{lines} sans comments. """ return ( a.find(b';') == -1 and a or a[:a.find(b';')] for a in [ b.strip() for b in lines ] ) def collapseContinuations(self, lines): """ Transform multiline statements into single lines. @param lines: lines to work on @type lines: iterable of L{bytes} @return: iterable of continuous lines """ l = [] state = 0 for line in lines: if state == 0: if line.find(b'(') == -1: l.append(line) else: l.append(line[:line.find(b'(')]) state = 1 else: if line.find(b')') != -1: l[-1] += b' ' + line[:line.find(b')')] state = 0 else: l[-1] += b' ' + line return filter(None, (line.split() for line in l)) def parseLines(self, lines): """ Parse C{lines}. @param lines: lines to work on @type lines: iterable of L{bytes} """ ttl = 60 * 60 * 3 origin = self.origin self.records = {} for line in lines: if line[0] == b'$TTL': ttl = dns.str2time(line[1]) elif line[0] == b'$ORIGIN': origin = line[1] elif line[0] == b'$INCLUDE': raise NotImplementedError('$INCLUDE directive not implemented') elif line[0] == b'$GENERATE': raise NotImplementedError( '$GENERATE directive not implemented' ) else: self.parseRecordLine(origin, ttl, line) # If the origin changed, reflect that within the instance. self.origin = origin def addRecord(self, owner, ttl, type, domain, cls, rdata): """ Add a record to our authority. Expand domain with origin if necessary. @param owner: origin? @type owner: L{bytes} @param ttl: time to live for the record @type ttl: L{int} @param domain: the domain for which the record is to be added @type domain: L{bytes} @param type: record type @type type: L{str} @param cls: record class @type cls: L{str} @param rdata: record data @type rdata: L{list} of L{bytes} """ if not domain.endswith(b'.'): domain = domain + b'.' + owner[:-1] else: domain = domain[:-1] f = getattr(self, 'class_%s' % (cls,), None) if f: f(ttl, type, domain, rdata) else: raise NotImplementedError( "Record class %r not supported" % (cls,) ) def class_IN(self, ttl, type, domain, rdata): """ Simulate a class IN and recurse into the actual class. @param ttl: time to live for the record @type ttl: L{int} @param type: record type @type type: str @param domain: the domain @type domain: bytes @param rdata: @type rdate: bytes """ record = getattr(dns, 'Record_%s' % (nativeString(type),), None) if record: r = record(*rdata) r.ttl = ttl self.records.setdefault(domain.lower(), []).append(r) if type == 'SOA': self.soa = (domain, r) else: raise NotImplementedError( "Record type %r not supported" % (nativeString(type),) ) def parseRecordLine(self, origin, ttl, line): """ Parse a C{line} from a zone file respecting C{origin} and C{ttl}. Add resulting records to authority. @param origin: starting point for the zone @type origin: L{bytes} @param ttl: time to live for the record @type ttl: L{int} @param line: zone file line to parse; split by word @type line: L{list} of L{bytes} """ if _PY3: queryClasses = set( qc.encode("ascii") for qc in dns.QUERY_CLASSES.values() ) queryTypes = set( qt.encode("ascii") for qt in dns.QUERY_TYPES.values() ) else: queryClasses = set(dns.QUERY_CLASSES.values()) queryTypes = set(dns.QUERY_TYPES.values()) markers = queryClasses | queryTypes cls = b'IN' owner = origin if line[0] == b'@': line = line[1:] owner = origin elif not line[0].isdigit() and line[0] not in markers: owner = line[0] line = line[1:] if line[0].isdigit() or line[0] in markers: domain = owner owner = origin else: domain = line[0] line = line[1:] if line[0] in queryClasses: cls = line[0] line = line[1:] if line[0].isdigit(): ttl = int(line[0]) line = line[1:] elif line[0].isdigit(): ttl = int(line[0]) line = line[1:] if line[0] in queryClasses: cls = line[0] line = line[1:] type = line[0] rdata = line[1:] self.addRecord( owner, ttl, nativeString(type), domain, nativeString(cls), rdata )