ue_pe_web/scripts/03_server/docs/search.js
Boris Baldassari 59eec96236 Update docs.
2024-03-06 18:33:41 +01:00

46 lines
52 KiB
JavaScript

window.pdocSearch = (function(){
/** elasticlunr - http://weixsong.github.io * Copyright (C) 2017 Oliver Nightingale * Copyright (C) 2017 Wei Song * MIT Licensed */!function(){function e(e){if(null===e||"object"!=typeof e)return e;var t=e.constructor();for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}var t=function(e){var n=new t.Index;return n.pipeline.add(t.trimmer,t.stopWordFilter,t.stemmer),e&&e.call(n,n),n};t.version="0.9.5",lunr=t,t.utils={},t.utils.warn=function(e){return function(t){e.console&&console.warn&&console.warn(t)}}(this),t.utils.toString=function(e){return void 0===e||null===e?"":e.toString()},t.EventEmitter=function(){this.events={}},t.EventEmitter.prototype.addListener=function(){var e=Array.prototype.slice.call(arguments),t=e.pop(),n=e;if("function"!=typeof t)throw new TypeError("last argument must be a function");n.forEach(function(e){this.hasHandler(e)||(this.events[e]=[]),this.events[e].push(t)},this)},t.EventEmitter.prototype.removeListener=function(e,t){if(this.hasHandler(e)){var n=this.events[e].indexOf(t);-1!==n&&(this.events[e].splice(n,1),0==this.events[e].length&&delete this.events[e])}},t.EventEmitter.prototype.emit=function(e){if(this.hasHandler(e)){var t=Array.prototype.slice.call(arguments,1);this.events[e].forEach(function(e){e.apply(void 0,t)},this)}},t.EventEmitter.prototype.hasHandler=function(e){return e in this.events},t.tokenizer=function(e){if(!arguments.length||null===e||void 0===e)return[];if(Array.isArray(e)){var n=e.filter(function(e){return null===e||void 0===e?!1:!0});n=n.map(function(e){return t.utils.toString(e).toLowerCase()});var i=[];return n.forEach(function(e){var n=e.split(t.tokenizer.seperator);i=i.concat(n)},this),i}return e.toString().trim().toLowerCase().split(t.tokenizer.seperator)},t.tokenizer.defaultSeperator=/[\s\-]+/,t.tokenizer.seperator=t.tokenizer.defaultSeperator,t.tokenizer.setSeperator=function(e){null!==e&&void 0!==e&&"object"==typeof e&&(t.tokenizer.seperator=e)},t.tokenizer.resetSeperator=function(){t.tokenizer.seperator=t.tokenizer.defaultSeperator},t.tokenizer.getSeperator=function(){return t.tokenizer.seperator},t.Pipeline=function(){this._queue=[]},t.Pipeline.registeredFunctions={},t.Pipeline.registerFunction=function(e,n){n in t.Pipeline.registeredFunctions&&t.utils.warn("Overwriting existing registered function: "+n),e.label=n,t.Pipeline.registeredFunctions[n]=e},t.Pipeline.getRegisteredFunction=function(e){return e in t.Pipeline.registeredFunctions!=!0?null:t.Pipeline.registeredFunctions[e]},t.Pipeline.warnIfFunctionNotRegistered=function(e){var n=e.label&&e.label in this.registeredFunctions;n||t.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},t.Pipeline.load=function(e){var n=new t.Pipeline;return e.forEach(function(e){var i=t.Pipeline.getRegisteredFunction(e);if(!i)throw new Error("Cannot load un-registered function: "+e);n.add(i)}),n},t.Pipeline.prototype.add=function(){var e=Array.prototype.slice.call(arguments);e.forEach(function(e){t.Pipeline.warnIfFunctionNotRegistered(e),this._queue.push(e)},this)},t.Pipeline.prototype.after=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._queue.indexOf(e);if(-1===i)throw new Error("Cannot find existingFn");this._queue.splice(i+1,0,n)},t.Pipeline.prototype.before=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._queue.indexOf(e);if(-1===i)throw new Error("Cannot find existingFn");this._queue.splice(i,0,n)},t.Pipeline.prototype.remove=function(e){var t=this._queue.indexOf(e);-1!==t&&this._queue.splice(t,1)},t.Pipeline.prototype.run=function(e){for(var t=[],n=e.length,i=this._queue.length,o=0;n>o;o++){for(var r=e[o],s=0;i>s&&(r=this._queue[s](r,o,e),void 0!==r&&null!==r);s++);void 0!==r&&null!==r&&t.push(r)}return t},t.Pipeline.prototype.reset=function(){this._queue=[]},t.Pipeline.prototype.get=function(){return this._queue},t.Pipeline.prototype.toJSON=function(){return this._queue.map(function(e){return t.Pipeline.warnIfFunctionNotRegistered(e),e.label})},t.Index=function(){this._fields=[],this._ref="id",this.pipeline=new t.Pipeline,this.documentStore=new t.DocumentStore,this.index={},this.eventEmitter=new t.EventEmitter,this._idfCache={},this.on("add","remove","update",function(){this._idfCache={}}.bind(this))},t.Index.prototype.on=function(){var e=Array.prototype.slice.call(arguments);return this.eventEmitter.addListener.apply(this.eventEmitter,e)},t.Index.prototype.off=function(e,t){return this.eventEmitter.removeListener(e,t)},t.Index.load=function(e){e.version!==t.version&&t.utils.warn("version mismatch: current "+t.version+" importing "+e.version);var n=new this;n._fields=e.fields,n._ref=e.ref,n.documentStore=t.DocumentStore.load(e.documentStore),n.pipeline=t.Pipeline.load(e.pipeline),n.index={};for(var i in e.index)n.index[i]=t.InvertedIndex.load(e.index[i]);return n},t.Index.prototype.addField=function(e){return this._fields.push(e),this.index[e]=new t.InvertedIndex,this},t.Index.prototype.setRef=function(e){return this._ref=e,this},t.Index.prototype.saveDocument=function(e){return this.documentStore=new t.DocumentStore(e),this},t.Index.prototype.addDoc=function(e,n){if(e){var n=void 0===n?!0:n,i=e[this._ref];this.documentStore.addDoc(i,e),this._fields.forEach(function(n){var o=this.pipeline.run(t.tokenizer(e[n]));this.documentStore.addFieldLength(i,n,o.length);var r={};o.forEach(function(e){e in r?r[e]+=1:r[e]=1},this);for(var s in r){var u=r[s];u=Math.sqrt(u),this.index[n].addToken(s,{ref:i,tf:u})}},this),n&&this.eventEmitter.emit("add",e,this)}},t.Index.prototype.removeDocByRef=function(e){if(e&&this.documentStore.isDocStored()!==!1&&this.documentStore.hasDoc(e)){var t=this.documentStore.getDoc(e);this.removeDoc(t,!1)}},t.Index.prototype.removeDoc=function(e,n){if(e){var n=void 0===n?!0:n,i=e[this._ref];this.documentStore.hasDoc(i)&&(this.documentStore.removeDoc(i),this._fields.forEach(function(n){var o=this.pipeline.run(t.tokenizer(e[n]));o.forEach(function(e){this.index[n].removeToken(e,i)},this)},this),n&&this.eventEmitter.emit("remove",e,this))}},t.Index.prototype.updateDoc=function(e,t){var t=void 0===t?!0:t;this.removeDocByRef(e[this._ref],!1),this.addDoc(e,!1),t&&this.eventEmitter.emit("update",e,this)},t.Index.prototype.idf=function(e,t){var n="@"+t+"/"+e;if(Object.prototype.hasOwnProperty.call(this._idfCache,n))return this._idfCache[n];var i=this.index[t].getDocFreq(e),o=1+Math.log(this.documentStore.length/(i+1));return this._idfCache[n]=o,o},t.Index.prototype.getFields=function(){return this._fields.slice()},t.Index.prototype.search=function(e,n){if(!e)return[];e="string"==typeof e?{any:e}:JSON.parse(JSON.stringify(e));var i=null;null!=n&&(i=JSON.stringify(n));for(var o=new t.Configuration(i,this.getFields()).get(),r={},s=Object.keys(e),u=0;u<s.length;u++){var a=s[u];r[a]=this.pipeline.run(t.tokenizer(e[a]))}var l={};for(var c in o){var d=r[c]||r.any;if(d){var f=this.fieldSearch(d,c,o),h=o[c].boost;for(var p in f)f[p]=f[p]*h;for(var p in f)p in l?l[p]+=f[p]:l[p]=f[p]}}var v,g=[];for(var p in l)v={ref:p,score:l[p]},this.documentStore.hasDoc(p)&&(v.doc=this.documentStore.getDoc(p)),g.push(v);return g.sort(function(e,t){return t.score-e.score}),g},t.Index.prototype.fieldSearch=function(e,t,n){var i=n[t].bool,o=n[t].expand,r=n[t].boost,s=null,u={};return 0!==r?(e.forEach(function(e){var n=[e];1==o&&(n=this.index[t].expandToken(e));var r={};n.forEach(function(n){var o=this.index[t].getDocs(n),a=this.idf(n,t);if(s&&"AND"==i){var l={};for(var c in s)c in o&&(l[c]=o[c]);o=l}n==e&&this.fieldSearchStats(u,n,o);for(var c in o){var d=this.index[t].getTermFrequency(n,c),f=this.documentStore.getFieldLength(c,t),h=1;0!=f&&(h=1/Math.sqrt(f));var p=1;n!=e&&(p=.15*(1-(n.length-e.length)/n.length));var v=d*a*h*p;c in r?r[c]+=v:r[c]=v}},this),s=this.mergeScores(s,r,i)},this),s=this.coordNorm(s,u,e.length)):void 0},t.Index.prototype.mergeScores=function(e,t,n){if(!e)return t;if("AND"==n){var i={};for(var o in t)o in e&&(i[o]=e[o]+t[o]);return i}for(var o in t)o in e?e[o]+=t[o]:e[o]=t[o];return e},t.Index.prototype.fieldSearchStats=function(e,t,n){for(var i in n)i in e?e[i].push(t):e[i]=[t]},t.Index.prototype.coordNorm=function(e,t,n){for(var i in e)if(i in t){var o=t[i].length;e[i]=e[i]*o/n}return e},t.Index.prototype.toJSON=function(){var e={};return this._fields.forEach(function(t){e[t]=this.index[t].toJSON()},this),{version:t.version,fields:this._fields,ref:this._ref,documentStore:this.documentStore.toJSON(),index:e,pipeline:this.pipeline.toJSON()}},t.Index.prototype.use=function(e){var t=Array.prototype.slice.call(arguments,1);t.unshift(this),e.apply(this,t)},t.DocumentStore=function(e){this._save=null===e||void 0===e?!0:e,this.docs={},this.docInfo={},this.length=0},t.DocumentStore.load=function(e){var t=new this;return t.length=e.length,t.docs=e.docs,t.docInfo=e.docInfo,t._save=e.save,t},t.DocumentStore.prototype.isDocStored=function(){return this._save},t.DocumentStore.prototype.addDoc=function(t,n){this.hasDoc(t)||this.length++,this.docs[t]=this._save===!0?e(n):null},t.DocumentStore.prototype.getDoc=function(e){return this.hasDoc(e)===!1?null:this.docs[e]},t.DocumentStore.prototype.hasDoc=function(e){return e in this.docs},t.DocumentStore.prototype.removeDoc=function(e){this.hasDoc(e)&&(delete this.docs[e],delete this.docInfo[e],this.length--)},t.DocumentStore.prototype.addFieldLength=function(e,t,n){null!==e&&void 0!==e&&0!=this.hasDoc(e)&&(this.docInfo[e]||(this.docInfo[e]={}),this.docInfo[e][t]=n)},t.DocumentStore.prototype.updateFieldLength=function(e,t,n){null!==e&&void 0!==e&&0!=this.hasDoc(e)&&this.addFieldLength(e,t,n)},t.DocumentStore.prototype.getFieldLength=function(e,t){return null===e||void 0===e?0:e in this.docs&&t in this.docInfo[e]?this.docInfo[e][t]:0},t.DocumentStore.prototype.toJSON=function(){return{docs:this.docs,docInfo:this.docInfo,length:this.length,save:this._save}},t.stemmer=function(){var e={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},t={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},n="[^aeiou]",i="[aeiouy]",o=n+"[^aeiouy]*",r=i+"[aeiou]*",s="^("+o+")?"+r+o,u="^("+o+")?"+r+o+"("+r+")?$",a="^("+o+")?"+r+o+r+o,l="^("+o+")?"+i,c=new RegExp(s),d=new RegExp(a),f=new RegExp(u),h=new RegExp(l),p=/^(.+?)(ss|i)es$/,v=/^(.+?)([^s])s$/,g=/^(.+?)eed$/,m=/^(.+?)(ed|ing)$/,y=/.$/,S=/(at|bl|iz)$/,x=new RegExp("([^aeiouylsz])\\1$"),w=new RegExp("^"+o+i+"[^aeiouwxy]$"),I=/^(.+?[^aeiou])y$/,b=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,E=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,D=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,F=/^(.+?)(s|t)(ion)$/,_=/^(.+?)e$/,P=/ll$/,k=new RegExp("^"+o+i+"[^aeiouwxy]$"),z=function(n){var i,o,r,s,u,a,l;if(n.length<3)return n;if(r=n.substr(0,1),"y"==r&&(n=r.toUpperCase()+n.substr(1)),s=p,u=v,s.test(n)?n=n.replace(s,"$1$2"):u.test(n)&&(n=n.replace(u,"$1$2")),s=g,u=m,s.test(n)){var z=s.exec(n);s=c,s.test(z[1])&&(s=y,n=n.replace(s,""))}else if(u.test(n)){var z=u.exec(n);i=z[1],u=h,u.test(i)&&(n=i,u=S,a=x,l=w,u.test(n)?n+="e":a.test(n)?(s=y,n=n.replace(s,"")):l.test(n)&&(n+="e"))}if(s=I,s.test(n)){var z=s.exec(n);i=z[1],n=i+"i"}if(s=b,s.test(n)){var z=s.exec(n);i=z[1],o=z[2],s=c,s.test(i)&&(n=i+e[o])}if(s=E,s.test(n)){var z=s.exec(n);i=z[1],o=z[2],s=c,s.test(i)&&(n=i+t[o])}if(s=D,u=F,s.test(n)){var z=s.exec(n);i=z[1],s=d,s.test(i)&&(n=i)}else if(u.test(n)){var z=u.exec(n);i=z[1]+z[2],u=d,u.test(i)&&(n=i)}if(s=_,s.test(n)){var z=s.exec(n);i=z[1],s=d,u=f,a=k,(s.test(i)||u.test(i)&&!a.test(i))&&(n=i)}return s=P,u=d,s.test(n)&&u.test(n)&&(s=y,n=n.replace(s,"")),"y"==r&&(n=r.toLowerCase()+n.substr(1)),n};return z}(),t.Pipeline.registerFunction(t.stemmer,"stemmer"),t.stopWordFilter=function(e){return e&&t.stopWordFilter.stopWords[e]!==!0?e:void 0},t.clearStopWords=function(){t.stopWordFilter.stopWords={}},t.addStopWords=function(e){null!=e&&Array.isArray(e)!==!1&&e.forEach(function(e){t.stopWordFilter.stopWords[e]=!0},this)},t.resetStopWords=function(){t.stopWordFilter.stopWords=t.defaultStopWords},t.defaultStopWords={"":!0,a:!0,able:!0,about:!0,across:!0,after:!0,all:!0,almost:!0,also:!0,am:!0,among:!0,an:!0,and:!0,any:!0,are:!0,as:!0,at:!0,be:!0,because:!0,been:!0,but:!0,by:!0,can:!0,cannot:!0,could:!0,dear:!0,did:!0,"do":!0,does:!0,either:!0,"else":!0,ever:!0,every:!0,"for":!0,from:!0,get:!0,got:!0,had:!0,has:!0,have:!0,he:!0,her:!0,hers:!0,him:!0,his:!0,how:!0,however:!0,i:!0,"if":!0,"in":!0,into:!0,is:!0,it:!0,its:!0,just:!0,least:!0,let:!0,like:!0,likely:!0,may:!0,me:!0,might:!0,most:!0,must:!0,my:!0,neither:!0,no:!0,nor:!0,not:!0,of:!0,off:!0,often:!0,on:!0,only:!0,or:!0,other:!0,our:!0,own:!0,rather:!0,said:!0,say:!0,says:!0,she:!0,should:!0,since:!0,so:!0,some:!0,than:!0,that:!0,the:!0,their:!0,them:!0,then:!0,there:!0,these:!0,they:!0,"this":!0,tis:!0,to:!0,too:!0,twas:!0,us:!0,wants:!0,was:!0,we:!0,were:!0,what:!0,when:!0,where:!0,which:!0,"while":!0,who:!0,whom:!0,why:!0,will:!0,"with":!0,would:!0,yet:!0,you:!0,your:!0},t.stopWordFilter.stopWords=t.defaultStopWords,t.Pipeline.registerFunction(t.stopWordFilter,"stopWordFilter"),t.trimmer=function(e){if(null===e||void 0===e)throw new Error("token should not be undefined");return e.replace(/^\W+/,"").replace(/\W+$/,"")},t.Pipeline.registerFunction(t.trimmer,"trimmer"),t.InvertedIndex=function(){this.root={docs:{},df:0}},t.InvertedIndex.load=function(e){var t=new this;return t.root=e.root,t},t.InvertedIndex.prototype.addToken=function(e,t,n){for(var n=n||this.root,i=0;i<=e.length-1;){var o=e[i];o in n||(n[o]={docs:{},df:0}),i+=1,n=n[o]}var r=t.ref;n.docs[r]?n.docs[r]={tf:t.tf}:(n.docs[r]={tf:t.tf},n.df+=1)},t.InvertedIndex.prototype.hasToken=function(e){if(!e)return!1;for(var t=this.root,n=0;n<e.length;n++){if(!t[e[n]])return!1;t=t[e[n]]}return!0},t.InvertedIndex.prototype.getNode=function(e){if(!e)return null;for(var t=this.root,n=0;n<e.length;n++){if(!t[e[n]])return null;t=t[e[n]]}return t},t.InvertedIndex.prototype.getDocs=function(e){var t=this.getNode(e);return null==t?{}:t.docs},t.InvertedIndex.prototype.getTermFrequency=function(e,t){var n=this.getNode(e);return null==n?0:t in n.docs?n.docs[t].tf:0},t.InvertedIndex.prototype.getDocFreq=function(e){var t=this.getNode(e);return null==t?0:t.df},t.InvertedIndex.prototype.removeToken=function(e,t){if(e){var n=this.getNode(e);null!=n&&t in n.docs&&(delete n.docs[t],n.df-=1)}},t.InvertedIndex.prototype.expandToken=function(e,t,n){if(null==e||""==e)return[];var t=t||[];if(void 0==n&&(n=this.getNode(e),null==n))return t;n.df>0&&t.push(e);for(var i in n)"docs"!==i&&"df"!==i&&this.expandToken(e+i,t,n[i]);return t},t.InvertedIndex.prototype.toJSON=function(){return{root:this.root}},t.Configuration=function(e,n){var e=e||"";if(void 0==n||null==n)throw new Error("fields should not be null");this.config={};var i;try{i=JSON.parse(e),this.buildUserConfig(i,n)}catch(o){t.utils.warn("user configuration parse failed, will use default configuration"),this.buildDefaultConfig(n)}},t.Configuration.prototype.buildDefaultConfig=function(e){this.reset(),e.forEach(function(e){this.config[e]={boost:1,bool:"OR",expand:!1}},this)},t.Configuration.prototype.buildUserConfig=function(e,n){var i="OR",o=!1;if(this.reset(),"bool"in e&&(i=e.bool||i),"expand"in e&&(o=e.expand||o),"fields"in e)for(var r in e.fields)if(n.indexOf(r)>-1){var s=e.fields[r],u=o;void 0!=s.expand&&(u=s.expand),this.config[r]={boost:s.boost||0===s.boost?s.boost:1,bool:s.bool||i,expand:u}}else t.utils.warn("field name in user configuration not found in index instance fields");else this.addAllFields2UserConfig(i,o,n)},t.Configuration.prototype.addAllFields2UserConfig=function(e,t,n){n.forEach(function(n){this.config[n]={boost:1,bool:e,expand:t}},this)},t.Configuration.prototype.get=function(){return this.config},t.Configuration.prototype.reset=function(){this.config={}},lunr.SortedSet=function(){this.length=0,this.elements=[]},lunr.SortedSet.load=function(e){var t=new this;return t.elements=e,t.length=e.length,t},lunr.SortedSet.prototype.add=function(){var e,t;for(e=0;e<arguments.length;e++)t=arguments[e],~this.indexOf(t)||this.elements.splice(this.locationFor(t),0,t);this.length=this.elements.length},lunr.SortedSet.prototype.toArray=function(){return this.elements.slice()},lunr.SortedSet.prototype.map=function(e,t){return this.elements.map(e,t)},lunr.SortedSet.prototype.forEach=function(e,t){return this.elements.forEach(e,t)},lunr.SortedSet.prototype.indexOf=function(e){for(var t=0,n=this.elements.length,i=n-t,o=t+Math.floor(i/2),r=this.elements[o];i>1;){if(r===e)return o;e>r&&(t=o),r>e&&(n=o),i=n-t,o=t+Math.floor(i/2),r=this.elements[o]}return r===e?o:-1},lunr.SortedSet.prototype.locationFor=function(e){for(var t=0,n=this.elements.length,i=n-t,o=t+Math.floor(i/2),r=this.elements[o];i>1;)e>r&&(t=o),r>e&&(n=o),i=n-t,o=t+Math.floor(i/2),r=this.elements[o];return r>e?o:e>r?o+1:void 0},lunr.SortedSet.prototype.intersect=function(e){for(var t=new lunr.SortedSet,n=0,i=0,o=this.length,r=e.length,s=this.elements,u=e.elements;;){if(n>o-1||i>r-1)break;s[n]!==u[i]?s[n]<u[i]?n++:s[n]>u[i]&&i++:(t.add(s[n]),n++,i++)}return t},lunr.SortedSet.prototype.clone=function(){var e=new lunr.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},lunr.SortedSet.prototype.union=function(e){var t,n,i;this.length>=e.length?(t=this,n=e):(t=e,n=this),i=t.clone();for(var o=0,r=n.toArray();o<r.length;o++)i.add(r[o]);return i},lunr.SortedSet.prototype.toJSON=function(){return this.toArray()},function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():e.elasticlunr=t()}(this,function(){return t})}();
/** pdoc search index */const docs = [{"fullname": "tests", "modulename": "tests", "kind": "module", "doc": "<p></p>\n"}, {"fullname": "tests.test_file", "modulename": "tests.test_file", "kind": "module", "doc": "<p>Script to test the myserver module.</p>\n"}, {"fullname": "tests.test_file.test_resolve_path", "modulename": "tests.test_file", "qualname": "test_resolve_path", "kind": "function", "doc": "<p>Tests the resolve_path() function with some normal use cases.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_file.test_resolve_path_weirdos", "modulename": "tests.test_file", "qualname": "test_resolve_path_weirdos", "kind": "function", "doc": "<p>Tests the resolve_path() function with some abnormal use cases.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_file.test_get_resource", "modulename": "tests.test_file", "qualname": "test_get_resource", "kind": "function", "doc": "<p>Tests the get_resource() function by checking the content of the returned file.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_file.test_get_resource_image", "modulename": "tests.test_file", "qualname": "test_get_resource_image", "kind": "function", "doc": "<p>Tests the get_resource() function by checking the content of an image.</p>\n\n<p>For an image, check we get the magic numbers for a JPEG.\nSee <a href=\"https://gist.github.com/leommoore/f9e57ba2aa4bf197ebc5\">https://gist.github.com/leommoore/f9e57ba2aa4bf197ebc5</a> for a complete list.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_http_request", "modulename": "tests.test_http_request", "kind": "module", "doc": "<p>Script to test the server.py module.</p>\n"}, {"fullname": "tests.test_http_request.testdata_request_head", "modulename": "tests.test_http_request", "qualname": "testdata_request_head", "kind": "variable", "doc": "<p></p>\n", "default_value": "[(&#x27;GET / HTTP/1.1&#x27;, {&#x27;verb&#x27;: &#x27;GET&#x27;, &#x27;resource&#x27;: &#x27;/&#x27;}), (&#x27;options /assets/style.css HTTP/1.1&#x27;, {&#x27;verb&#x27;: &#x27;OPTIONS&#x27;, &#x27;resource&#x27;: &#x27;/assets/style.css&#x27;})]"}, {"fullname": "tests.test_http_request.test_parse_request_head", "modulename": "tests.test_http_request", "qualname": "test_parse_request_head", "kind": "function", "doc": "<p></p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">head</span><span class=\"p\">:</span> <span class=\"nb\">str</span>, </span><span class=\"param\"><span class=\"n\">expected</span><span class=\"p\">:</span> <span class=\"nb\">dict</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_http_request.test_parse_request_head_invalid", "modulename": "tests.test_http_request", "qualname": "test_parse_request_head_invalid", "kind": "function", "doc": "<p></p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_http_request.testdata_request_params", "modulename": "tests.test_http_request", "qualname": "testdata_request_params", "kind": "variable", "doc": "<p></p>\n", "default_value": "[([], {}), ([&#x27;Host: example.org&#x27;, &#x27;User-Agent: curl/7.81.0&#x27;, &#x27;Accept: */*&#x27;], {&#x27;Host&#x27;: &#x27;example.org&#x27;, &#x27;User-Agent&#x27;: &#x27;curl/7.81.0&#x27;, &#x27;Accept&#x27;: &#x27;*/*&#x27;}), ([&#x27; Host: example.org &#x27;, &#x27;Accept-Encoding: gzip, deflate, br&#x27;], {&#x27;Host&#x27;: &#x27;example.org&#x27;, &#x27;Accept-Encoding&#x27;: &#x27;gzip, deflate, br&#x27;})]"}, {"fullname": "tests.test_http_request.test_parse_request_params", "modulename": "tests.test_http_request", "qualname": "test_parse_request_params", "kind": "function", "doc": "<p></p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">params</span><span class=\"p\">:</span> <span class=\"nb\">list</span><span class=\"p\">[</span><span class=\"nb\">str</span><span class=\"p\">]</span>, </span><span class=\"param\"><span class=\"n\">expected</span><span class=\"p\">:</span> <span class=\"nb\">dict</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_http_request.testdata_request_params_invalid", "modulename": "tests.test_http_request", "qualname": "testdata_request_params_invalid", "kind": "variable", "doc": "<p></p>\n", "default_value": "[[&#x27;Host example.org&#x27;], [&#x27;: example.org&#x27;], [&#x27;Truc: &#x27;]]"}, {"fullname": "tests.test_http_request.test_parse_request_params_invalid", "modulename": "tests.test_http_request", "qualname": "test_parse_request_params_invalid", "kind": "function", "doc": "<p></p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">params</span><span class=\"p\">:</span> <span class=\"nb\">list</span><span class=\"p\">[</span><span class=\"nb\">str</span><span class=\"p\">]</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_http_request.testdata_request", "modulename": "tests.test_http_request", "qualname": "testdata_request", "kind": "variable", "doc": "<p></p>\n", "default_value": "[(b&#x27;GET /index.html HTTP/1.1\\nHost: example.org\\nUser-Agent: curl/7.81.0\\nAccept: */*\\n\\n&#x27;, {&#x27;head&#x27;: {&#x27;verb&#x27;: &#x27;GET&#x27;, &#x27;resource&#x27;: &#x27;/index.html&#x27;}, &#x27;params&#x27;: {&#x27;Host&#x27;: &#x27;example.org&#x27;, &#x27;User-Agent&#x27;: &#x27;curl/7.81.0&#x27;, &#x27;Accept&#x27;: &#x27;*/*&#x27;}}), (b&#x27;\\n\\nOPTIONS /assets/style.css HTTP/1.1\\n\\n&#x27;, {&#x27;head&#x27;: {&#x27;verb&#x27;: &#x27;OPTIONS&#x27;, &#x27;resource&#x27;: &#x27;/assets/style.css&#x27;}, &#x27;params&#x27;: {}})]"}, {"fullname": "tests.test_http_request.test_parse_request", "modulename": "tests.test_http_request", "qualname": "test_parse_request", "kind": "function", "doc": "<p></p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">buf</span><span class=\"p\">:</span> <span class=\"nb\">bytes</span>, </span><span class=\"param\"><span class=\"n\">expected</span><span class=\"p\">:</span> <span class=\"nb\">dict</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_http_request.testdata_request_invalid", "modulename": "tests.test_http_request", "qualname": "testdata_request_invalid", "kind": "variable", "doc": "<p></p>\n", "default_value": "[b&#x27;Host: example.org\\nUser-Agent: curl/7.81.0\\n\\n&#x27;, b&#x27;\\nGET HTTP/1.1\\n\\n&#x27;, b&#x27;GET / HTTP/1.1\\nHost example.org\\n\\nGET / HTTP/1.1\\nHost: example.org\\n\\nUser-Agent: curl/7.81.0\\n\\n&#x27;]"}, {"fullname": "tests.test_http_request.test_parse_request_invalid", "modulename": "tests.test_http_request", "qualname": "test_parse_request_invalid", "kind": "function", "doc": "<p></p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">buf</span><span class=\"p\">:</span> <span class=\"nb\">bytes</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_log", "modulename": "tests.test_log", "kind": "module", "doc": "<p>Script to test the myserver module.</p>\n"}, {"fullname": "tests.test_log.test_log", "modulename": "tests.test_log", "qualname": "test_log", "kind": "function", "doc": "<p>Tests the log() function by capturing stdout.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_log.test_log_address", "modulename": "tests.test_log", "qualname": "test_log_address", "kind": "function", "doc": "<p>Tests the log_address() function by capturing stdout.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_log.test_log_request", "modulename": "tests.test_log", "qualname": "test_log_request", "kind": "function", "doc": "<p>Tests the log_request() function by capturing stdout.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_log.test_log_request_useragent", "modulename": "tests.test_log", "qualname": "test_log_request_useragent", "kind": "function", "doc": "<p>Tests the log_request() function by capturing stdout.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_log.test_log_request_failed_assert", "modulename": "tests.test_log", "qualname": "test_log_request_failed_assert", "kind": "function", "doc": "<p>Tests if the log_request() function properly fails when wrong\nparameters are provided.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_log.test_log_reply", "modulename": "tests.test_log", "qualname": "test_log_reply", "kind": "function", "doc": "<p>Tests the log_reply() function by checking its output.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_log.test_log_reply_useragent", "modulename": "tests.test_log", "qualname": "test_log_reply_useragent", "kind": "function", "doc": "<p>Tests the log_reply() function by checking its output.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_server", "modulename": "tests.test_server", "kind": "module", "doc": "<p>Script to test the server.py module.</p>\n"}, {"fullname": "tests.test_server.HTTP_PORT", "modulename": "tests.test_server", "qualname": "HTTP_PORT", "kind": "variable", "doc": "<p>The port to use during the tests, both for the server and client.</p>\n", "default_value": "12345"}, {"fullname": "tests.test_server.start_server", "modulename": "tests.test_server", "qualname": "start_server", "kind": "function", "doc": "<p>Automatically starts and stops the server when running the tests.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "tests.test_server.test_serve", "modulename": "tests.test_server", "qualname": "test_serve", "kind": "function", "doc": "<p>Tests the serve() function by using the requests module.</p>\n\n<p>Uses the start_server fixture to start and stop the serverduring the tests.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "src", "modulename": "src", "kind": "module", "doc": "<p></p>\n"}, {"fullname": "src.myserver", "modulename": "src.myserver", "kind": "module", "doc": "<p>A package for learning network programming in Python.</p>\n\n<p>This module (file) defines the directory as a Python module.</p>\n"}, {"fullname": "src.myserver.cli", "modulename": "src.myserver.cli", "kind": "module", "doc": "<p>A package for learning network programming in Python.</p>\n\n<p>This module (file) manages the command line interface to control the server.</p>\n"}, {"fullname": "src.myserver.cli.parse_args", "modulename": "src.myserver.cli", "qualname": "parse_args", "kind": "function", "doc": "<p>Parses arguments from command line.</p>\n\n<h2 id=\"parameters\">Parameters</h2>\n\n<ul>\n<li>argv: list[str]\nThe list of arguments to parse.</li>\n</ul>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>argparse.Namespace\n The list of parameters and their values.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">argv</span><span class=\"p\">:</span> <span class=\"nb\">list</span><span class=\"p\">[</span><span class=\"nb\">str</span><span class=\"p\">]</span></span><span class=\"return-annotation\">) -> <span class=\"n\">argparse</span><span class=\"o\">.</span><span class=\"n\">Namespace</span>:</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.cli.main", "modulename": "src.myserver.cli", "qualname": "main", "kind": "function", "doc": "<p></p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.date", "modulename": "src.myserver.date", "kind": "module", "doc": "<p>A package for learning network programming in Python.</p>\n\n<p>This module (file) manages date related-utilities.</p>\n"}, {"fullname": "src.myserver.date.now_rfc2616", "modulename": "src.myserver.date", "qualname": "now_rfc2616", "kind": "function", "doc": "<p></p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.file", "modulename": "src.myserver.file", "kind": "module", "doc": "<p>A package for learning network programming in Python.</p>\n\n<p>This module (file) manages operations relative to the file system.</p>\n"}, {"fullname": "src.myserver.file.resolve_location", "modulename": "src.myserver.file", "qualname": "resolve_location", "kind": "function", "doc": "<p>Returns the path of a resource relative to the root and its extension.</p>\n\n<p>Returns (\"\", \"\") if the concatenated path does not exist.</p>\n\n<p>\"index.html\" is appended to directory paths.</p>\n\n<h2 id=\"parameters\">Parameters</h2>\n\n<p>res: str \n The queried resource path.\nroot: str \n The root directory where to look into for res.</p>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>str\n The full disk path of the resource if it exists, or \"\".\nstr\n The extension of the resource if it exists, or \"\".</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">res</span><span class=\"p\">:</span> <span class=\"nb\">str</span>, </span><span class=\"param\"><span class=\"n\">root</span><span class=\"p\">:</span> <span class=\"nb\">str</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.file.resolve_path", "modulename": "src.myserver.file", "qualname": "resolve_path", "kind": "function", "doc": "<p>Returns the full disk path of a resource relative to the root.</p>\n\n<p>Returns \"\" if the concatenated path does not exist.</p>\n\n<p>\"index.html\" is appended to directory paths.</p>\n\n<h2 id=\"parameters\">Parameters</h2>\n\n<p>res: str \n The queried resource path.\nroot: str \n The root directory where to look into for res.</p>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>str\n The full disk path of the resource if it exists, or \"\".</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">res</span><span class=\"p\">:</span> <span class=\"nb\">str</span>, </span><span class=\"param\"><span class=\"n\">root</span><span class=\"p\">:</span> <span class=\"nb\">str</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.file.get_resource", "modulename": "src.myserver.file", "qualname": "get_resource", "kind": "function", "doc": "<p>Returns a resource at res_path, its content type and an HTTP code.</p>\n\n<h2 id=\"parameters\">Parameters</h2>\n\n<ul>\n<li>res_path: str\nRequested resource string.</li>\n</ul>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>bytes\n The resource content if it exists (code == 200).\nint \n A HTTP status code.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">res_path</span><span class=\"p\">:</span> <span class=\"nb\">str</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.http", "modulename": "src.myserver.http", "kind": "module", "doc": "<p>A package for learning network programming in Python.</p>\n\n<p>This module (file) provides information relative to the HTTP specification.</p>\n"}, {"fullname": "src.myserver.http.get_http_code", "modulename": "src.myserver.http", "qualname": "get_http_code", "kind": "function", "doc": "<p>Returns a dict corresponding to the HTTP status code.</p>\n\n<p>See also : <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Status\">https://developer.mozilla.org/en-US/docs/Web/HTTP/Status</a></p>\n\n<h2 id=\"parameters\">Parameters</h2>\n\n<ul>\n<li>code: int \nAn HTTP code.</li>\n</ul>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>dict \n Information about the HTTP code, containing fileds:\n - header: str \n The code string to put in an HTTP reply header.\n - html: str \n The HTML to reply as HTTP content.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">code</span><span class=\"p\">:</span> <span class=\"nb\">int</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.http.file_extension_to_content_type", "modulename": "src.myserver.http", "qualname": "file_extension_to_content_type", "kind": "variable", "doc": "<p></p>\n", "default_value": "{&#x27;webm&#x27;: &#x27;video/webm&#x27;, &#x27;mp3&#x27;: &#x27;audio/mpeg&#x27;, &#x27;wasm&#x27;: &#x27;application/wasm&#x27;, &#x27;crx&#x27;: &#x27;application/x-chrome-extension&#x27;, &#x27;xhtml&#x27;: &#x27;application/xhtml+xml&#x27;, &#x27;xht&#x27;: &#x27;application/xhtml+xml&#x27;, &#x27;xhtm&#x27;: &#x27;application/xhtml+xml&#x27;, &#x27;flac&#x27;: &#x27;audio/flac&#x27;, &#x27;ogg&#x27;: &#x27;audio/ogg&#x27;, &#x27;oga&#x27;: &#x27;audio/ogg&#x27;, &#x27;opus&#x27;: &#x27;audio/ogg&#x27;, &#x27;wav&#x27;: &#x27;audio/wav&#x27;, &#x27;m4a&#x27;: &#x27;audio/x-m4a&#x27;, &#x27;avif&#x27;: &#x27;image/avif&#x27;, &#x27;gif&#x27;: &#x27;image/gif&#x27;, &#x27;jpeg&#x27;: &#x27;image/jpeg&#x27;, &#x27;jpg&#x27;: &#x27;image/jpeg&#x27;, &#x27;png&#x27;: &#x27;image/png&#x27;, &#x27;apng&#x27;: &#x27;image/apng&#x27;, &#x27;svg&#x27;: &#x27;image/svg+xml&#x27;, &#x27;svgz&#x27;: &#x27;image/svg+xml&#x27;, &#x27;webp&#x27;: &#x27;image/webp&#x27;, &#x27;mht&#x27;: &#x27;multipart/related&#x27;, &#x27;mhtml&#x27;: &#x27;multipart/related&#x27;, &#x27;css&#x27;: &#x27;text/css&#x27;, &#x27;html&#x27;: &#x27;text/html&#x27;, &#x27;htm&#x27;: &#x27;text/html&#x27;, &#x27;shtml&#x27;: &#x27;text/html&#x27;, &#x27;shtm&#x27;: &#x27;text/html&#x27;, &#x27;js&#x27;: &#x27;text/javascript&#x27;, &#x27;mjs&#x27;: &#x27;text/javascript&#x27;, &#x27;xml&#x27;: &#x27;text/xml&#x27;, &#x27;mp4&#x27;: &#x27;video/mp4&#x27;, &#x27;m4v&#x27;: &#x27;video/mp4&#x27;, &#x27;ogv&#x27;: &#x27;video/ogg&#x27;, &#x27;ogm&#x27;: &#x27;video/ogg&#x27;, &#x27;csv&#x27;: &#x27;text/csv&#x27;, &#x27;ico&#x27;: &#x27;image/vnd.microsoft.icon&#x27;}"}, {"fullname": "src.myserver.http.get_http_content_type", "modulename": "src.myserver.http", "qualname": "get_http_content_type", "kind": "function", "doc": "<p>Returns the HTTP Content-Type corresponding to a file extension.</p>\n\n<p>Returns \"application/octet-stream\" when the extension is unknown.</p>\n\n<h2 id=\"parameters\">Parameters</h2>\n\n<ul>\n<li>extension: str\nA file extension.</li>\n</ul>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>str \n An HTTP Content-Type</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">extension</span><span class=\"p\">:</span> <span class=\"nb\">str</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.http_request", "modulename": "src.myserver.http_request", "kind": "module", "doc": "<p>A package for learning network programming in Python.</p>\n\n<p>This module (file) manages the parsing of HTTP requests.</p>\n"}, {"fullname": "src.myserver.http_request.parse_request", "modulename": "src.myserver.http_request", "qualname": "parse_request", "kind": "function", "doc": "<p>Parses a full HTTP request bytes buffer into a dict. </p>\n\n<p>The parsed request dict contains two keys:</p>\n\n<ul>\n<li>head: dict[str, str]\nInformation on the HTTP request header (i.e. the first request line);\noutput of <code>parse_request_head</code>.</li>\n<li>params: dict[str, str]\nList of the HTTP parameters (i.e. the following lines); \noutput of <code>parse_request_params</code>.</li>\n</ul>\n\n<h2 id=\"parameters\">Parameters</h2>\n\n<ul>\n<li>buf: bytes \nThe HTTP request buffer.</li>\n</ul>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>dict[str, dict]\n The parsed content of the HTTP request.</p>\n\n<h2 id=\"raises\">Raises</h2>\n\n<p>ValueError\n The request is not valid HTTP.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">buf</span><span class=\"p\">:</span> <span class=\"nb\">bytes</span></span><span class=\"return-annotation\">) -> <span class=\"nb\">dict</span><span class=\"p\">[</span><span class=\"nb\">str</span><span class=\"p\">,</span> <span class=\"nb\">dict</span><span class=\"p\">]</span>:</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.http_request.parse_request_head", "modulename": "src.myserver.http_request", "qualname": "parse_request_head", "kind": "function", "doc": "<p>Parses a HTTP request header string (its first line) into a dict.</p>\n\n<p>The parsed request dict contains two keys:</p>\n\n<ul>\n<li>verb: str\nThe _uppercase_ verb of the request, i.e. the first word of the line;\nfor example: \"GET\".</li>\n<li>resource: str\nThe requested resource, i.e. the second \"word\" of the line;\nfor example: \"/index.html\".</li>\n</ul>\n\n<h2 id=\"parameters\">Parameters</h2>\n\n<ul>\n<li>line: str\nThe HTTP request header (the first line of a full HTTP request).</li>\n</ul>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>dict[str, str]\n The parsed content of the HTTP request header.</p>\n\n<h2 id=\"raises\">Raises</h2>\n\n<p>ValueError\n The request header is not valid HTTP.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">line</span><span class=\"p\">:</span> <span class=\"nb\">str</span></span><span class=\"return-annotation\">) -> <span class=\"nb\">dict</span><span class=\"p\">[</span><span class=\"nb\">str</span><span class=\"p\">,</span> <span class=\"nb\">str</span><span class=\"p\">]</span>:</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.http_request.parse_request_params", "modulename": "src.myserver.http_request", "qualname": "parse_request_params", "kind": "function", "doc": "<p>Parses HTTP request parameters (a list of lines) into a dict.</p>\n\n<p>The parsed request dict contains one key/value pair per line, with the \ndict key being the left part of the line (the parameter key), and the \ndict value being the right part of the line (the parameter value).</p>\n\n<p>The function strips leading and trailing spaces: \" Host: a.org \" becomes\n<code>{\"Host\": \"a.org\"}</code>.</p>\n\n<h2 id=\"parameters\">Parameters</h2>\n\n<ul>\n<li>lines: list[str]\nHTTP parameters (one list item per line)</li>\n</ul>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>dict[str, str]\n Dictionary of the parameters</p>\n\n<h2 id=\"raises\">Raises</h2>\n\n<p>ValueError\n The provided lines are not valid HTTP.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">lines</span><span class=\"p\">:</span> <span class=\"nb\">list</span><span class=\"p\">[</span><span class=\"nb\">str</span><span class=\"p\">]</span></span><span class=\"return-annotation\">) -> <span class=\"nb\">dict</span><span class=\"p\">[</span><span class=\"nb\">str</span><span class=\"p\">,</span> <span class=\"nb\">str</span><span class=\"p\">]</span>:</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.log", "modulename": "src.myserver.log", "kind": "module", "doc": "<p>A package for learning network programming in Python.</p>\n\n<p>This module (file) manages the HTTP logging messages.</p>\n"}, {"fullname": "src.myserver.log.log", "modulename": "src.myserver.log", "qualname": "log", "kind": "function", "doc": "<p>Logs a message to stdout, with a timestamp.</p>\n\n<p>Output is: <code>timestamp - message</code>.</p>\n\n<h2 id=\"parameters\">Parameters</h2>\n\n<ul>\n<li>msg : str \nThe message string to print.</li>\n</ul>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">msg</span><span class=\"p\">:</span> <span class=\"nb\">str</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.log.log_address", "modulename": "src.myserver.log", "qualname": "log_address", "kind": "function", "doc": "<p>Logs a message to stdout, with a timestamp and an address (host:port).</p>\n\n<p>Output is: <code>timestamp - host:port - message</code>.</p>\n\n<h2 id=\"parameters\">Parameters</h2>\n\n<ul>\n<li>addr: tuple[str, int]\nThe address to print, as a tuple (host, port)</li>\n<li>msg: str\nThe message string to print.</li>\n</ul>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">addr</span><span class=\"p\">:</span> <span class=\"nb\">tuple</span><span class=\"p\">[</span><span class=\"nb\">str</span><span class=\"p\">,</span> <span class=\"nb\">int</span><span class=\"p\">]</span>, </span><span class=\"param\"><span class=\"n\">msg</span><span class=\"p\">:</span> <span class=\"nb\">str</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.log.log_request", "modulename": "src.myserver.log", "qualname": "log_request", "kind": "function", "doc": "<p>Logs a request message to stdout, with a timestamp and an address (host:port).</p>\n\n<p>Output is: <code>timestamp - host:port - message</code>.</p>\n\n<h2 id=\"parameters\">Parameters</h2>\n\n<ul>\n<li>addr: tuple[str, int]\nThe address to print, as a tuple (host, port)</li>\n<li>req: dict[str, dict]\nThe request to print.</li>\n</ul>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">addr</span><span class=\"p\">:</span> <span class=\"nb\">tuple</span><span class=\"p\">[</span><span class=\"nb\">str</span><span class=\"p\">,</span> <span class=\"nb\">int</span><span class=\"p\">]</span>, </span><span class=\"param\"><span class=\"n\">req</span><span class=\"p\">:</span> <span class=\"nb\">dict</span><span class=\"p\">[</span><span class=\"nb\">str</span><span class=\"p\">,</span> <span class=\"nb\">dict</span><span class=\"p\">]</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.log.log_reply", "modulename": "src.myserver.log", "qualname": "log_reply", "kind": "function", "doc": "<p>Logs an HTTP reply to stdout, with timestamp, address (host:port), code, UA.</p>\n\n<p>Output is: <code>timestamp - host:port - HTTP-verb HTTP-resource - code - message</code>.</p>\n\n<h2 id=\"parameters\">Parameters</h2>\n\n<ul>\n<li>addr: tuple[str, int]\nThe address to print, as a tuple (host, port)</li>\n<li>req: dict[str, dict]\nThe request to print.</li>\n<li>code: int\nThe replied code to print.</li>\n</ul>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">addr</span><span class=\"p\">:</span> <span class=\"nb\">tuple</span><span class=\"p\">[</span><span class=\"nb\">str</span><span class=\"p\">,</span> <span class=\"nb\">int</span><span class=\"p\">]</span>, </span><span class=\"param\"><span class=\"n\">req</span><span class=\"p\">:</span> <span class=\"nb\">dict</span><span class=\"p\">[</span><span class=\"nb\">str</span><span class=\"p\">,</span> <span class=\"nb\">dict</span><span class=\"p\">]</span>, </span><span class=\"param\"><span class=\"n\">code</span><span class=\"p\">:</span> <span class=\"nb\">int</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.server", "modulename": "src.myserver.server", "kind": "module", "doc": "<p>A package for learning network programming in Python.</p>\n\n<p>This part manages the socket connections and multi-threading of clients.</p>\n"}, {"fullname": "src.myserver.server.serve", "modulename": "src.myserver.server", "qualname": "serve", "kind": "function", "doc": "<p>Serves http request connections for clients.</p>\n\n<p>This function creates the network socket, listens, and as soon as it receives\na request (connection), calls the <code>~myserver.handle_client()()</code>.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">port</span><span class=\"p\">:</span> <span class=\"nb\">int</span>, </span><span class=\"param\"><span class=\"n\">root</span><span class=\"p\">:</span> <span class=\"nb\">str</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.server.handle_client", "modulename": "src.myserver.server", "qualname": "handle_client", "kind": "function", "doc": "<p>Manages a single connection from a client.</p>\n\n<p>In details, we:</p>\n\n<ul>\n<li>read data from the socket provided,</li>\n<li>parse this data to build the request and headers,</li>\n<li>call the handle_request() function,\n[* optionally write something in the log,]</li>\n<li>close the connection.</li>\n</ul>\n\n<h2 id=\"parameters\">Parameters</h2>\n\n<ul>\n<li>c: socket.socket\nThe socket to communicate with the client.</li>\n<li>addr: tuple[str, int]\nThe IP address and port of the client, as returned by the accept command.</li>\n<li>root: str\nThe path to the local directory to serve.</li>\n</ul>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">c</span><span class=\"p\">:</span> <span class=\"n\">socket</span><span class=\"o\">.</span><span class=\"n\">socket</span>, </span><span class=\"param\"><span class=\"n\">addr</span><span class=\"p\">:</span> <span class=\"nb\">tuple</span><span class=\"p\">[</span><span class=\"nb\">str</span><span class=\"p\">,</span> <span class=\"nb\">int</span><span class=\"p\">]</span>, </span><span class=\"param\"><span class=\"n\">root</span><span class=\"p\">:</span> <span class=\"nb\">str</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.server.prepare_resource", "modulename": "src.myserver.server", "qualname": "prepare_resource", "kind": "function", "doc": "<p>Retrieves the content of the resource and sets the status code.</p>\n\n<h2 id=\"parameters\">Parameters</h2>\n\n<ul>\n<li>root: str\nThe path to the local directory to serve.</li>\n<li>req: dict[str, dict]\nThe request to proceed.</li>\n</ul>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>tuple \n The reply for the request, including the data and status code.\n - data: str\n The data (header + content) to reply on the socket.\n - code: int\n The status code for the reply.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">root</span><span class=\"p\">:</span> <span class=\"nb\">str</span>, </span><span class=\"param\"><span class=\"n\">req</span><span class=\"p\">:</span> <span class=\"nb\">dict</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}, {"fullname": "src.myserver.server.prepare_reply", "modulename": "src.myserver.server", "qualname": "prepare_reply", "kind": "function", "doc": "<p>Generates the proper answer, including the HTTP headers and content of the\nwebpage, and the status code.</p>\n\n<p>For more information about:</p>\n\n<ul>\n<li>Content type, see <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types\">https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types</a></li>\n<li>Status code, see <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Status\">https://developer.mozilla.org/en-US/docs/Web/HTTP/Status</a></li>\n</ul>\n\n<h2 id=\"parameters\">Parameters</h2>\n\n<ul>\n<li>content: bytes\nThe raw data for the resource.</li>\n<li>content_type: str\nThe content type for the resource.</li>\n<li>code: int\nThe status code.</li>\n</ul>\n\n<h2 id=\"returns\">Returns</h2>\n\n<p>tuple \n The reply for the request, including the data and status code.\n - data: str\n The data (header + content) to reply on the socket.\n - code: int\n The status code for the reply.</p>\n", "signature": "<span class=\"signature pdoc-code condensed\">(<span class=\"param\"><span class=\"n\">content</span><span class=\"p\">:</span> <span class=\"nb\">bytes</span>, </span><span class=\"param\"><span class=\"n\">content_type</span><span class=\"p\">:</span> <span class=\"nb\">str</span>, </span><span class=\"param\"><span class=\"n\">code</span><span class=\"p\">:</span> <span class=\"nb\">int</span></span><span class=\"return-annotation\">):</span></span>", "funcdef": "def"}];
// mirrored in build-search-index.js (part 1)
// Also split on html tags. this is a cheap heuristic, but good enough.
elasticlunr.tokenizer.setSeperator(/[\s\-.;&_'"=,()]+|<[^>]*>/);
let searchIndex;
if (docs._isPrebuiltIndex) {
console.info("using precompiled search index");
searchIndex = elasticlunr.Index.load(docs);
} else {
console.time("building search index");
// mirrored in build-search-index.js (part 2)
searchIndex = elasticlunr(function () {
this.pipeline.remove(elasticlunr.stemmer);
this.pipeline.remove(elasticlunr.stopWordFilter);
this.addField("qualname");
this.addField("fullname");
this.addField("annotation");
this.addField("default_value");
this.addField("signature");
this.addField("bases");
this.addField("doc");
this.setRef("fullname");
});
for (let doc of docs) {
searchIndex.addDoc(doc);
}
console.timeEnd("building search index");
}
return (term) => searchIndex.search(term, {
fields: {
qualname: {boost: 4},
fullname: {boost: 2},
annotation: {boost: 2},
default_value: {boost: 2},
signature: {boost: 2},
bases: {boost: 2},
doc: {boost: 1},
},
expand: true
});
})();