本文整理汇总了Python中pyparsing.Combine.parseString方法的典型用法代码示例。如果您正苦于以下问题:Python Combine.parseString方法的具体用法?Python Combine.parseString怎么用?Python Combine.parseString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing.Combine
的用法示例。
在下文中一共展示了Combine.parseString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_ipv4_addr
# 需要导入模块: from pyparsing import Combine [as 别名]
# 或者: from pyparsing.Combine import parseString [as 别名]
def is_ipv4_addr(inputstr):
from pyparsing import Combine, Word, nums
ipAddress = Combine(Word(nums) + ('.' + Word(nums)) * 3)
try:
ipAddress.parseString(inputstr)
return True
except:
return False
示例2: urlsplit
# 需要导入模块: from pyparsing import Combine [as 别名]
# 或者: from pyparsing.Combine import parseString [as 别名]
def urlsplit(url, scheme='', allow_fragments=1):
"""Parse a URL into 5 components:
<scheme>://<netloc>/<path>?<query>#<fragment>
Return a 5-tuple: (scheme, netloc, path, query, fragment).
Note that we don't break the components up in smaller bits
(e.g. netloc is a single string) and we don't expand % escapes."""
global _urlBNF
key = url, scheme, allow_fragments
cached = _parse_cache.get(key, None)
if cached:
return cached
if len(_parse_cache) >= MAX_CACHE_SIZE: # avoid runaway growth
clear_cache()
if (_urlBNF is None):
scheme_chars = alphanums + "+-."
urlscheme = Word( scheme_chars )
netloc_chars = "".join( [ c for c in printables if c not in "/." ] )
netloc = Combine(delimitedList( Word( netloc_chars ), ".", combine=True ))
path_chars = "".join( [ c for c in printables if c not in "?" ] )
path = Word( path_chars )
query_chars = "".join( [ c for c in printables if c not in "#" ] )
query = Word( query_chars )
fragment = Word( printables+" " )
_urlBNF = Combine(Optional(urlscheme.setResultsName("scheme") + ":" ) +
Optional(Literal("//").suppress() + netloc, default="").setResultsName("netloc") +
Optional(path.setResultsName("path"), default="") +
Optional(Literal("?").suppress() + query, default="").setResultsName("query") +
Optional(Literal("#").suppress() + fragment, default="").setResultsName("fragment") )
tokens = _urlBNF.parseString( url )
tuple = (tokens.scheme or scheme), tokens.netloc[0], tokens.path, tokens.query[0], tokens.fragment[0]
_parse_cache[key] = tuple
return tuple