# 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. linux日常使用指令总结

    linux 日常指令总结(ubuntu): ls -lha 所有文件及权限 df -h 系统磁盘空间 du -sh 当前目录大小 du -ah --max-depth=1 显示目录下所有的文件和文件夹 ...

  2. 2019ccpc-HN省赛-A/C/F/I

    A.最大下降矩阵 时间限制: 1 Sec  内存限制: 512 MB提交: 508  解决: 107[提交] [状态] [讨论版] [命题人:外部导入] 题目描述 我们称一个矩阵是下降矩阵,当且仅当, ...

  3. python----常见练习题

    1. 冒泡排序 def bubble_sort(lists): len_list=len(lists) for i in range(len_list): for j in range(len_lis ...

  4. div+css的常规使用

    代码如下 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3 ...

  5. vscode 中 eslint 相关配置

    1.设置vue等文件有eslint提示 "eslint.validate": [ "javascript", "javascriptreact&quo ...

  6. nginx 出现504 Gateway Time-out的解决方法

    本文介绍nginx出现504 Gateway Time-out问题的原因,分析问题并提供解决方法. 1.问题分析nginx访问出现504 Gateway Time-out,一般是由于程序执行时间过长导 ...

  7. prefixspan是挖掘频繁子序列,子序列不一定是连续的,当心!!!

    序列模式挖掘是从序列数据库中发现频繁子序列作为模式. 子序列与频繁序列 了解了序列数据的概念,我们再来看看上面是子序列.子序列和我们数学上的子集的概念很类似,也就是说,如果某个序列A所有的项集在序列B ...

  8. linux 查找指定进程并kill

    ps -ef | grep  php | grep -v 'grep' | awk '{print $2}'| xargs kill -9

  9. maven 项目提示找不到javax.servlet.xxx问题解决

    1.https://search.maven.org/search?q=g:javax.servlet%20AND%20a:javax.servlet-api&core=gav 2.下载3.1 ...

  10. 装B命令行,常用Windows命令

    winver检查Windows版本 dxdiag检查DirectX信息 gpedit.msc 组策略   regedit.exe 注册表 Msconfig.exe 系统配置实用程序  lusrmgr. ...