本文整理匯總了Python中ure.compile方法的典型用法代碼示例。如果您正苦於以下問題:Python ure.compile方法的具體用法?Python ure.compile怎麽用?Python ure.compile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ure
的用法示例。
在下文中一共展示了ure.compile方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import ure [as 別名]
# 或者: from ure import compile [as 別名]
def __init__(self, pkg, routes=None, serve_static=True):
if routes:
self.url_map = routes
else:
self.url_map = []
if pkg and pkg != "__main__":
self.pkg = pkg.split(".", 1)[0]
else:
self.pkg = None
if serve_static:
self.url_map.append((re.compile("^/(static/.+)"), self.handle_static))
self.mounts = []
self.inited = False
# Instantiated lazily
self.template_loader = None
self.headers_mode = "parse"
示例2: __init__
# 需要導入模塊: import ure [as 別名]
# 或者: from ure import compile [as 別名]
def __init__(self, url_pattern):
self.pattern = ''
self.args = []
use_regex = False
for segment in url_pattern.lstrip('/').split('/'):
if segment and segment[0] == '<':
if segment[-1] != '>':
raise ValueError('invalid URL pattern')
segment = segment[1:-1]
if ':' in segment:
type_, name = segment.rsplit(':', 1)
else:
type_ = 'string'
name = segment
if type_ == 'string':
pattern = '[^/]+'
elif type_ == 'int':
pattern = '\\d+'
elif type_ == 'path':
pattern = '.+'
elif type_.startswith('re:'):
pattern = type_[3:]
else:
raise ValueError('invalid URL segment type')
use_regex = True
self.pattern += '/({pattern})'.format(pattern=pattern)
self.args.append({'type': type_, 'name': name})
else:
self.pattern += '/{segment}'.format(segment=segment)
if use_regex:
self.pattern = re.compile('^' + self.pattern + '$')
示例3: get_signal_strength
# 需要導入模塊: import ure [as 別名]
# 或者: from ure import compile [as 別名]
def get_signal_strength(self):
csq_at = self.lte.send_at_cmd("AT+CSQ")
csq_line_regex = ure.compile("\n")
csq_line = csq_line_regex.split(csq_at)
csq_string_regex = ure.compile(" ")
csq_string = csq_string_regex.split(csq_line[1])
csq_comma = csq_string[1]
csq_num_regex = ure.compile(",")
csq_num = csq_num_regex.split(csq_comma)
csq = csq_num[0]
return csq