bottle.py中的路由解析代码
# Routing
def compile_route(route):
""" Compiles a route string and returns a precompiled RegexObject. Routes may contain regular expressions with named groups to support url parameters.
Example:
'/user/(?P<id>[0-9]+)' will match '/user/5' with {'id':'5'} A more human readable syntax is supported too.
Example:
'/user/:id/:action' will match '/user/5/kiss' with {'id':'5', 'action':'kiss'}
Placeholders match everything up to the next slash.
'/user/:id#[0-9]+#' will match '/user/5' but not '/user/tim'
Instead of "#" you can use any single special char other than "/"
"""
route = route.strip().lstrip('$^/ ').rstrip('$^ ')
# 将 /user/:id#[0-9]+#/ 转换为 /user/(?P<id>[0-9]+)/
route = re.sub(r':([a-zA-Z_]+)(?P<uniq>[^\w/])(?P<re>.+?)(?P=uniq)',r'(?P<\1>\g<re>)',route)
# 将 /user/:id/ 转换为 /user/(?P<id>[^/]+)/
route = re.sub(r':([a-zA-Z_]+)',r'(?P<\1>[^/]+)', route)
return re.compile('^/%s$' % route)
bottle.py中的路由解析代码的更多相关文章
- bottle.py中的路由搜索优化
# Now search regexp routes # ROUTES_REGEXP是一个字典,键是请求方法,值是[路由, 处理函数]的列表 # 例如:{"GET", [[路由1, ...
- WCF技术解剖2-TcpTracer路由解析代码
TcpTrace路由解析,参考页面-http://www.cnblogs.com/artech/archive/2008/09/19/1294227.html. TcpTrace工具下载地址:http ...
- iOS 中的XML解析代码(SAX)
1.XML解析(SAX) NSXMLParser SAX 大文件 1)打开文档 - (void)parserDidStartDocument:(NSXMLParser *)parser 2)开始查找起 ...
- bottle.py中的SimpleTemplate
import re class SimpleTemplate(object): re_block = re.compile(r'^\s*%\s*((if|elif|else|try|except|fi ...
- AspNet Mvc 路由解析中添加.html 等后缀 出现404错误的解决办法
使用Mvc 有时候我们希望,浏览地址以.html .htm 等后缀名进行结尾. 于是我们就在RouteConfig 中修改路由配置信息,修改后的代码如下 routes.IgnoreRoute(&quo ...
- 函数体中return下面的代码不执行,但是需要预解析
//函数体中return下面的代码不执行,但是需要预解析 function fn(){ console.log(num);//undefined return function(){ }; var n ...
- html中可以写php代码,但是文件后缀名需要是.php而不是.html。否则php程序不会被解析执行。
html中可以写php代码,但是文件后缀名需要是.php而不是.html.否则php程序不会被解析执行. <div class="goods_title"><?p ...
- MVC中的路由
authour: chenboyi updatetime: 2015-05-02 16:10:04 friendly link: 目录 1,思维导图 2,MVC处理机制简图(讲解路由解析) 3,默 ...
- urls.py的配置[路由配置]
urls.py的配置[路由配置] Get请求与Post请求的方式 get请求: (1)地址栏输入url (2)<a href="请求url">点击</a> ...
随机推荐
- deep learning的一些知识点
softmax loss: softmax: softmax的作用,将fc的输出映射成为(0,1)的概率,并将其差距拉大. cross entropy loss: y是样本的真实标签,为1 ...
- libcrypto.so.1.0.0: no version information available
openssl-1.0.1p源码安装后,依赖于openssl.so库的应用报错libcrypto.so.1.0.0: no version information available 解法:1. 创建 ...
- python 报错 TabError: inconsistent use of tabs and spaces in indentation
写python的时候如果出现如题的错误 TabError: inconsistent use of tabs and spaces in indentation 意为:制表符错误:缩进中制表符和空格使 ...
- 突破防盗链Referrer
//引用的源码网站的js<script src="https://raw.githack.com/jpgerek/referrer-killer/master/referrer-kil ...
- php上传文件,接口是java,go。
$uri = ‘https://www.xxx.com/api/xxxxx’; $ch = curl_init(); //加@符号curl就会把它当成是文件上传处理 $tmpName = $_FILE ...
- 小谈对Python的认知与期望
18级新生,在大学之前并未接触过程序语言编程,在众多语言编程中只对C语言有个名字上认知.在上个学期初次了解到Python语言,计算机老师表示Python是现在编程语言中如雨后春笋般的发展飞速的计算机语 ...
- 无服务器架构(Faas/Serverless)
摘要无服务器架构(Faas/Serverless),是软件架构领域的热门话题. AWS,Google Cloud和Azure - 在无服务器上投入了大量资金,已经在看到了大量专门针对Faas/Serv ...
- spoj mpoint
题解: 判断每一次加进来的时候有几个被破坏,几个添加 然后单调栈维护 代码: #include<bits/stdc++.h> using namespace std; ; ,now,oo= ...
- PHP用post来进行Soap请求
最近调了一个Soap请求C# webservice的项目.网上坑不少. 使用原生的SoapClient库请求也是失败.只好用post来进行模拟了.代码贴出来,给大家参考一下. <?php nam ...
- 使用 spring封装的javamail linux服务器发送邮件失败解决
原文参考:https://blog.csdn.net/a540891049/article/details/79385471 由于某些平台的linxu服务器为了安全起见 屏蔽了发送邮件的常用端口 25 ...