本文整理汇总了Python中Parsing类的典型用法代码示例。如果您正苦于以下问题:Python Parsing类的具体用法?Python Parsing怎么用?Python Parsing使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Parsing类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parseKVs
def parseKVs(self, kvl):
""" Convert some form of keys to an OrderedDict.
We are trying to be ridiculously flexible here. Take:
- a string, which we parse as it came from an ICC.
- a list, which we parse either as a list of key=value strings or of (key, value) duples.
"""
if isinstance(kvl, str):
return Parsing.parseKVs(kvl)
od = collections.OrderedDict()
if kvl is not None:
for i in kvl:
if isinstance(i, str):
k, v, junk = Parsing.parseKV(i)
od[k] = v
elif type(i) in (list, tuple) and len(i) == 2:
k, v, junk = Parsing.parseKV("%s=%s" % i)
else:
CPL.log('Reply', 'kvl item is not a string: %r' % (i))
raise Exception("kvl == %r" % (i))
return od
示例2: parse_from_strings
def parse_from_strings(name, code, pxds=None, level=None, initial_pos=None,
context=None, allow_struct_enum_decorator=False):
"""
Utility method to parse a (unicode) string of code. This is mostly
used for internal Cython compiler purposes (creating code snippets
that transforms should emit, as well as unit testing).
code - a unicode string containing Cython (module-level) code
name - a descriptive name for the code source (to use in error messages etc.)
RETURNS
The tree, i.e. a ModuleNode. The ModuleNode's scope attribute is
set to the scope used when parsing.
"""
if pxds is None:
pxds = {}
if context is None:
context = StringParseContext(name)
# Since source files carry an encoding, it makes sense in this context
# to use a unicode string so that code fragments don't have to bother
# with encoding. This means that test code passed in should not have an
# encoding header.
assert isinstance(code, unicode), "unicode code snippets only please"
encoding = "UTF-8"
module_name = name
if initial_pos is None:
initial_pos = (name, 1, 0)
code_source = StringSourceDescriptor(name, code)
scope = context.find_module(module_name, pos = initial_pos, need_pxd = 0)
buf = StringIO(code)
scanner = PyrexScanner(buf, code_source, source_encoding = encoding,
scope = scope, context = context, initial_pos = initial_pos)
ctx = Parsing.Ctx(allow_struct_enum_decorator=allow_struct_enum_decorator)
if level is None:
tree = Parsing.p_module(scanner, 0, module_name, ctx=ctx)
tree.scope = scope
tree.is_pxd = False
else:
tree = Parsing.p_code(scanner, level=level, ctx=ctx)
tree.scope = scope
return tree
示例3: parse
def parse(self, source_filename, scope, pxd):
# Parse the given source file and return a parse tree.
f = open(source_filename, "rU")
s = PyrexScanner(f, source_filename, scope = scope, context = self)
try:
tree = Parsing.p_module(s, pxd)
finally:
f.close()
if Errors.num_errors > 0:
raise CompileError
return tree
示例4: parse
def parse(self, source_desc, scope, pxd, full_module_name):
if not isinstance(source_desc, FileSourceDescriptor):
raise RuntimeError("Only file sources for code supported")
source_filename = Utils.encode_filename(source_desc.filename)
# Parse the given source file and return a parse tree.
try:
f = Utils.open_source_file(source_filename, "rU")
try:
s = PyrexScanner(f, source_desc, source_encoding = f.encoding,
scope = scope, context = self)
tree = Parsing.p_module(s, pxd, full_module_name)
finally:
f.close()
except UnicodeDecodeError, msg:
#import traceback
#traceback.print_exc()
error((source_desc, 0, 0), "Decoding error, missing or incorrect coding=<encoding-name> at top of source (%s)" % msg)
示例5: parse
def parse(self, source_desc, scope, pxd, full_module_name):
if not isinstance(source_desc, FileSourceDescriptor):
raise RuntimeError("Only file sources for code supported")
source_filename = source_desc.filename
scope.cpp = self.cpp
# Parse the given source file and return a parse tree.
num_errors = Errors.num_errors
try:
f = Utils.open_source_file(source_filename, "rU")
try:
import Parsing
s = PyrexScanner(f, source_desc, source_encoding=f.encoding, scope=scope, context=self)
tree = Parsing.p_module(s, pxd, full_module_name)
finally:
f.close()
except UnicodeDecodeError, e:
# import traceback
# traceback.print_exc()
line = 1
column = 0
msg = e.args[-1]
position = e.args[2]
encoding = e.args[0]
f = open(source_filename, "rb")
try:
byte_data = f.read()
finally:
f.close()
# FIXME: make this at least a little less inefficient
for idx, c in enumerate(byte_data):
if c in (ord("\n"), "\n"):
line += 1
column = 0
if idx == position:
break
column += 1
error(
(source_desc, line, column),
"Decoding error, missing or incorrect coding=<encoding-name> "
"at top of source (cannot decode with encoding %r: %s)" % (encoding, msg),
)
示例6: match
def match(self, opts):
""" Searches an OrderedDict for matches.
Args:
argv - an OrderedDict of options.
opts - a list of duples to match against. The duple parts are the option name
and a converter. If the converter is None, the option takes no argument.
Returns:
matches - an OrderedDict of the matched options, with converted arguments.
unmatched - a list of unmatched options from opts.
leftovers - an OrderedDict of unmatched options from argv.
Raises:
Error - Any parsing or conversion error.
"""
self.parseArgs()
return Parsing.match(self.argDict, opts)
示例7: print
import sys
import os
import Parsing
import Common
# Parse the arguments and fill into search_paramaters
search_paramaters = Common.SearchParamaters()
search_paramaters = Parsing.parse_labels(sys.argv)
if(len(search_paramaters.search_phrases) == 0):
print("ERROR: Must include phrase to search for at the end of the run command")
sys.exit()
ip_folders = list()
ip_file = open(search_paramaters.ips_filename, 'r')
for line in ip_file:
ip_folders.append(line.strip());
occurence_count = 0
for first_two_quadrants in ip_folders:
for third_quadrant in range(0, 255):
for fourth_quadrant in range(0, 255):
path_to_file = first_two_quadrants + '/' + first_two_quadrants + "." + str(third_quadrant) + "." + str(fourth_quadrant)
if os.path.exists(path_to_file):
enc = 'utf-8'
webpage = open(path_to_file, 'r', encoding = enc)
try:
found = False
for line in webpage:
示例8: print
import FileNameReading, Parsing, Structure, Functions, Clean
import matplotlib.pyplot as plt
import datetime
import numpy as np
# dictionary that contains all the filenames
filenames = FileNameReading.get_file_names()
all_sensors = []
for i in filenames.keys():
current_sensor = []
data = Parsing.parse(i)
print("Current file being read is " + i)
data = Clean.remove_empty(data)
for row in data:
for k, v in row.items():
if k == "Timestamp":
line = row[k].split(' ')
second_value = line[1].split('A') or line[1].split('P')
row[k] = ((line[0]), (second_value[0]))
# row[k] = (v, str(v))
current_sensor.append(row)
# datetime.datetime.strptime()
all_sensors.append(current_sensor)
# print(all_sensors)
x = []
示例9: parseArgs
def parseArgs(self):
""" Parse a raw command string into an OrderedDict in .argDict. """
if not self.argDict:
self.argDict = Parsing.parseArgs(self.cmd)
示例10: print
import numpy as np
import Parsing
import matplotlib.pyplot as plt
from scipy.spatial import Voronoi, voronoi_plot_2d, Delaunay
from scipy.spatial import KDTree, tsearch
data = Parsing.parse("individual_sensors_data.csv")
# print(data)
long = []
lat = []
cur = []
for y in data:
for k, v in y.items():
if v == "I35 N":
cur.append(y)
for x in cur:
for k, v in x.items():
if k == "Longitude":
long.append(float(v))
elif k == "Latitude":
lat.append(float(v))
# print(lat)
# print(long)