# 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中的路由解析代码的更多相关文章

  1. bottle.py中的路由搜索优化

    # Now search regexp routes # ROUTES_REGEXP是一个字典,键是请求方法,值是[路由, 处理函数]的列表 # 例如:{"GET", [[路由1, ...

  2. WCF技术解剖2-TcpTracer路由解析代码

    TcpTrace路由解析,参考页面-http://www.cnblogs.com/artech/archive/2008/09/19/1294227.html. TcpTrace工具下载地址:http ...

  3. iOS 中的XML解析代码(SAX)

    1.XML解析(SAX) NSXMLParser SAX 大文件 1)打开文档 - (void)parserDidStartDocument:(NSXMLParser *)parser 2)开始查找起 ...

  4. bottle.py中的SimpleTemplate

    import re class SimpleTemplate(object): re_block = re.compile(r'^\s*%\s*((if|elif|else|try|except|fi ...

  5. AspNet Mvc 路由解析中添加.html 等后缀 出现404错误的解决办法

    使用Mvc 有时候我们希望,浏览地址以.html .htm 等后缀名进行结尾. 于是我们就在RouteConfig 中修改路由配置信息,修改后的代码如下 routes.IgnoreRoute(&quo ...

  6. 函数体中return下面的代码不执行,但是需要预解析

    //函数体中return下面的代码不执行,但是需要预解析 function fn(){ console.log(num);//undefined return function(){ }; var n ...

  7. html中可以写php代码,但是文件后缀名需要是.php而不是.html。否则php程序不会被解析执行。

    html中可以写php代码,但是文件后缀名需要是.php而不是.html.否则php程序不会被解析执行. <div class="goods_title"><?p ...

  8. MVC中的路由

    authour: chenboyi updatetime: 2015-05-02 16:10:04 friendly link:   目录 1,思维导图 2,MVC处理机制简图(讲解路由解析) 3,默 ...

  9. urls.py的配置[路由配置]

    urls.py的配置[路由配置] Get请求与Post请求的方式 get请求: (1)地址栏输入url (2)<a href="请求url">点击</a> ...

随机推荐

  1. 403 Access Denied :进入Tomcat的manager时拒绝访问

    解决办法: https://blog.csdn.net/Hello_World_QWP/article/details/79581174

  2. 又谈T检验

    今天有同学的论文被指摘了,就是又用了T检验,又用了ANOVA,reviewer直接说用ANOVA就行了.所以回想下了T检验. 简而言之,T检验就是用来比较均值的,样本均值和已知总体均值是否有差异.(也 ...

  3. ggplot

    安装:install.packages("ggplot2") 加载:library(ggplot2) Plot(图)= data(数据集)+ Aesthetics(美学映射)+ G ...

  4. UML与软件建模:第一次作业(用例图绘制)

    一.小结 用例图是UML用于描述软件功能的图形.用例图包括用例.参与者及其关系,用例图也可以包括注释和结束. 用例图的要素: (1)参与者,即与用例存在交互关系的系统外部实体; (2)用例,用来描述个 ...

  5. python运用PIL制作GIF

    与一.安装Pillow 安装地址:https://pypi.org/project/Pillow/#files 二.准备好图片,并从0开始命名,如下图: (ps:记得存图位置与新建的py文件在同一存放 ...

  6. caffe分类

    1.制作数据  标签   label.bat dir/s/on/b >.txt 2.制作lmdb     convert_lmdb.bat SET GLOG_logtostderr= E:\ca ...

  7. Arthur and Questions CodeForces - 518E (贪心模拟)

    大意: 给定序列$a$, 某些位置为'?', 求给'?'赋值使得序列$(a_1+a_2+...+a_k,a_2+a_3+...+a_{k+1},...)严格递增, 且$\sum|a_i|$最小. 化简 ...

  8. 关于node

    nodejs npm常用命令 npm是一个node包管理和分发工具,已经成为了非官方的发布node模块(包)的标准.有了npm,可以很快的找到特定服务要使用的包,进行下载.安装以及管理已经安装的包. ...

  9. wait和sleep的区别

    wait是线程永久等待,只有调用notify才能进行唤醒 sleep是等待指定的时间,自动唤醒

  10. Centos7中网络及设备相关配置

    centos7中,不再赞成使用ifconfig工具,取而代之的是nmcli工具,服务管理也是以systemctl工具取代了service,这些之前版本的工具虽然在centos7中还可以继续使用,只是出 ...