本文整理汇总了Python中types.SimpleNamespace方法的典型用法代码示例。如果您正苦于以下问题:Python types.SimpleNamespace方法的具体用法?Python types.SimpleNamespace怎么用?Python types.SimpleNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types
的用法示例。
在下文中一共展示了types.SimpleNamespace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import types [as 别名]
# 或者: from types import SimpleNamespace [as 别名]
def __init__(self, url_bytes, headers, version, method, transport, app):
self.raw_url = url_bytes
# TODO: Content-Encoding detection
self._parsed_url = parse_url(url_bytes)
self.app = app
self.headers = headers
self.version = version
self.method = method
self.transport = transport
# Init but do not inhale
self.body_init()
self.conn_info = None
self.ctx = SimpleNamespace()
self.parsed_forwarded = None
self.parsed_json = None
self.parsed_form = None
self.parsed_files = None
self.parsed_args = defaultdict(RequestParameters)
self.parsed_not_grouped_args = defaultdict(list)
self.uri_template = None
self._cookies = None
self.stream = None
self.endpoint = None
示例2: _do_import
# 需要导入模块: import types [as 别名]
# 或者: from types import SimpleNamespace [as 别名]
def _do_import(self, name):
"""Helper for fake_import and fake_importlib_import to do the work.
Return:
The imported fake module, or None if normal importing should be
used.
"""
if name not in self.modules:
# Not one of the modules to test -> use real import
return None
elif self.modules[name]:
ns = types.SimpleNamespace()
if self.version_attribute is not None:
setattr(ns, self.version_attribute, self.version)
return ns
else:
raise ImportError("Fake ImportError for {}.".format(name))
示例3: test_basedir
# 需要导入模块: import types [as 别名]
# 或者: from types import SimpleNamespace [as 别名]
def test_basedir(self, tmpdir, typ):
"""Test --basedir."""
basedir = tmpdir / 'basedir'
assert not basedir.exists()
args = types.SimpleNamespace(basedir=str(basedir))
standarddir._init_dirs(args)
func = getattr(standarddir, typ)
func()
assert basedir.exists()
if typ == 'download' or (typ == 'runtime' and not utils.is_linux):
assert not (basedir / typ).exists()
else:
assert (basedir / typ).exists()
if utils.is_posix:
assert (basedir / typ).stat().mode & 0o777 == 0o700
示例4: test_exists_race_condition
# 需要导入模块: import types [as 别名]
# 或者: from types import SimpleNamespace [as 别名]
def test_exists_race_condition(self, mocker, tmpdir, typ):
"""Make sure there can't be a TOCTOU issue when creating the file.
See https://github.com/qutebrowser/qutebrowser/issues/942.
"""
(tmpdir / typ).ensure(dir=True)
m = mocker.patch('qutebrowser.utils.standarddir.os')
m.makedirs = os.makedirs
m.sep = os.sep
m.path.join = os.path.join
m.expanduser = os.path.expanduser
m.path.exists.return_value = False
m.path.abspath = lambda x: x
args = types.SimpleNamespace(basedir=str(tmpdir))
standarddir._init_dirs(args)
func = getattr(standarddir, typ)
func()
示例5: prepare_source
# 需要导入模块: import types [as 别名]
# 或者: from types import SimpleNamespace [as 别名]
def prepare_source(self, source):
prepared = types.SimpleNamespace(
active=True,
path=source['path'],
shuffle=bool(source.get('shuffle', False)),
recursive=bool(source.get('recursive', self._recursive)),
item_play_duration=int(source.get('item_play_duration', 0)),
play_every_minutes=int(source.get('play_every_minutes', 0)),
start_time=None,
end_time=None
)
if source.get('playing_time'):
prepared.start_time, prepared.end_time = (
datetime.datetime.strptime(i, '%H:%M').time() for i
in utils.parse_time_interval(source['playing_time'])
)
return prepared
示例6: create_run
# 需要导入模块: import types [as 别名]
# 或者: from types import SimpleNamespace [as 别名]
def create_run(self, info_result=RESULT_UNKNOWN):
runSet = types.SimpleNamespace()
runSet.log_folder = "."
runSet.result_files_folder = "."
runSet.options = []
runSet.real_name = None
runSet.propertytag = None
runSet.benchmark = lambda: None
runSet.benchmark.base_dir = "."
runSet.benchmark.benchmark_file = "Test.xml"
runSet.benchmark.columns = []
runSet.benchmark.name = "Test"
runSet.benchmark.instance = "Test"
runSet.benchmark.rlimits = {}
runSet.benchmark.tool = BaseTool()
def determine_result(self, returncode, returnsignal, output, isTimeout=False):
return info_result
runSet.benchmark.tool.determine_result = determine_result
return Run(
identifier="test.c", sourcefiles=["test.c"], fileOptions=[], runSet=runSet
)
示例7: singlefile_content
# 需要导入模块: import types [as 别名]
# 或者: from types import SimpleNamespace [as 别名]
def singlefile_content(tmp_path_factory):
random.seed(0) # Make sure random file names and content are identical every time
content_path = _mktempdir(tmp_path_factory)
filepath = _generate_random_file(content_path, filename='sinģle fíle')
random.seed() # Re-enable randomness
exp_pieces = b'\xc8\xfa\x0fV\x95\xecl\x97t\xb2v\x84S\x98{\x92[ \x13\xe5\x04\xef-\xb0;sF\xc2\x93W\xcf\xc6X\x14\x9b]_r\xfb\x80\'}\xe5\xc4\x05\xdct\xb5^\xe9\x7f0b|\xc9\xf1\x9d\xd7G\x06 ,l8m\x01\xbf2\xf6:\x03r-\x8d\x1f,\x8bk:\xad\xdbN\xa2V\x96/\xf2@w\xa5\x98\xf8\t3fU\x13;\x90\xc0F\xe3[\x15\xea\x8f\x92\xcdN:\xc1\x0fG\x9b\xeb\xd9\x93A\xca\xa7L\xd2\x9ef|\xddd\xd4\x94.f\xee\xea3\xa8\x04|\xe9h\xa7\xa1t\xa2\xb5\xb3*\x89\xf7\x14\xdf\x16M/\xc6\xa5\x85\xdaF\xca\xa7?\x9d\xe1zd\xc8\xe1\x1d\x1epC\x06+\xe1Q\x0fi\x9fv\x19\xa2(\xd0\x90\xb3\xb0\xcf\xa9\x1cy\xf0\x96\x17\n\x05\xa5*IZJ\x8c\xbb\x87\xdd\xed|d.\xf0\xb9\xfe\x00\xa6\nufY\x18\xe35\xee\xdf\xa6D\xed<\xc5W\x0fa\x80\xc6}\xdd\xf4\xbd\xc1:\xe3\xda\nj\xbag\x93\xd0\xdc\xbd\xb8\xfb\xc2\x99\x9a/&\x1d\xf3\xe9\xa3,\x9b>\'\xa5\xaa~\xabb\x81\x88\x80^\xddd\xc7\xea\x83n\x05%\x8f4\x8a\x82\xe2\xff[\xab\xa8\x92\x1f\xaarG\xc5\x00\xcae\x9e\x93\xc4\x9015\x02\xe7\x8a\xb1I\xa6\x16DF\x8a\x0b\xeb\x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17\xf1z4\x11v\xef\xcf!\x03\xdc\x14_\x9e;\'\xdckvHh\xd5x\xf48\xdaFa\xae\x02\xf0\x16| \xa3\x97\xe5\xed\xf6\x11$\xe4\xacb\xaf\x8a\x07fH\x96\x00\x00\x98\x87(\x97\xcd!\xff\xf8a\x02\xc4\xca\xff\xef\xe1P\x01_\x9b\x9b\x83:\x7f\xdd\x92\xfb\xe9\x94\xc3SEWh\x18\xb3\x9c\xd8\xf9M\x1d!\xd25\xcb'
exp_metainfo = {'announce' : 'http://localhost:123',
'created by' : 'mktorrent 1.0',
'creation date' : 1513522263,
'info': {'name' : os.path.basename(filepath),
'piece length' : 2**14,
'pieces' : exp_pieces,
'length' : os.path.getsize(filepath)}}
exp_attrs = SimpleNamespace(path=str(filepath),
infohash='7febf5a5a6e6bac79df2eb4340a63009109fecd5',
infohash_base32=b'P7V7LJNG425MPHPS5NBUBJRQBEIJ73GV',
size=os.path.getsize(filepath),
pieces=math.ceil(os.path.getsize(filepath) / exp_metainfo['info']['piece length']))
return SimpleNamespace(path=exp_attrs.path,
exp_metainfo=exp_metainfo,
exp_attrs=exp_attrs)
示例8: test_cities
# 需要导入模块: import types [as 别名]
# 或者: from types import SimpleNamespace [as 别名]
def test_cities(self):
print ("running test_cities...")
with gzip.open('data.json.gz', 'rb') as db:
cities = json.load(db)
states = set()
errors, count = 0, 0
for city in cities:
c = SimpleNamespace(**city)
states.add(c.uf)
r = sapp._search(c.latitude, c.longitude)
if r is None:
errors += 1
else:
if r["found"]:
if c.nome_municipio == r["city"] and c.uf == r["state"]:
count += 1
else:
errors += 1
else:
errors += 1
self.assertTrue(errors==0)
self.assertTrue(count==5540)
self.assertTrue(len(states)==27)
示例9: test_capitals
# 需要导入模块: import types [as 别名]
# 或者: from types import SimpleNamespace [as 别名]
def test_capitals(self):
print ("running test_capitals...")
with gzip.open('capitais.json.gz', 'rb') as db:
all_capitals = json.load(db)
with gzip.open('data.json.gz', 'rb') as db:
cities = json.load(db)
cities = [x for x in cities if x['capital']]
found = []
for capital in all_capitals:
c = SimpleNamespace(**capital)
for city in cities:
d = SimpleNamespace(**city)
if({d.nome_municipio, d.uf, d.estado} & {c.capital, c.sigla, c.estado}):
found.append(capital)
break
self.assertTrue(len(found)==27)
示例10: __init__
# 需要导入模块: import types [as 别名]
# 或者: from types import SimpleNamespace [as 别名]
def __init__(self, level_generator):
self.level_generator = level_generator
self.state = SimpleNamespace(
screen="INTRO",
game=None,
total_points=0,
total_steps=0,
total_safety_score=0,
level_start_steps=0,
level_start_points=0,
total_undos=0,
edit_mode=0,
history=deque(maxlen=MAX_HISTORY_LENGTH),
side_effects=None,
total_side_effects=defaultdict(lambda: 0),
message="",
last_command="",
level_num=0,
)
示例11: start_pan
# 需要导入模块: import types [as 别名]
# 或者: from types import SimpleNamespace [as 别名]
def start_pan(self, x, y, button):
angle = np.deg2rad(self.get_rlabel_position())
mode = ''
if button == 1:
epsilon = np.pi / 45.0
t, r = self.transData.inverted().transform_point((x, y))
if angle - epsilon <= t <= angle + epsilon:
mode = 'drag_r_labels'
elif button == 3:
mode = 'zoom'
self._pan_start = types.SimpleNamespace(
rmax=self.get_rmax(),
trans=self.transData.frozen(),
trans_inverse=self.transData.inverted().frozen(),
r_label_angle=self.get_rlabel_position(),
x=x,
y=y,
mode=mode)
示例12: start_pan
# 需要导入模块: import types [as 别名]
# 或者: from types import SimpleNamespace [as 别名]
def start_pan(self, x, y, button):
"""
Called when a pan operation has started.
*x*, *y* are the mouse coordinates in display coords.
button is the mouse button number:
* 1: LEFT
* 2: MIDDLE
* 3: RIGHT
.. note::
Intended to be overridden by new projection types.
"""
self._pan_start = types.SimpleNamespace(
lim=self.viewLim.frozen(),
trans=self.transData.frozen(),
trans_inverse=self.transData.inverted().frozen(),
bbox=self.bbox.frozen(),
x=x,
y=y)
示例13: getColors
# 需要导入模块: import types [as 别名]
# 或者: from types import SimpleNamespace [as 别名]
def getColors(self):
appearanceName = AppKit.NSAppearance.currentAppearance().name()
if appearanceName != self._lastAppearanceName:
self._lastAppearanceName = appearanceName
colors = SimpleNamespace()
colors.foregroundColor = AppKit.NSColor.textColor()
colors.selectedColor = colors.foregroundColor.blendedColorWithFraction_ofColor_(
0.9, AppKit.NSColor.systemRedColor())
colors.selectedSpaceColor = colors.selectedColor.colorWithAlphaComponent_(0.2)
colors.hoverColor = AppKit.NSColor.systemBlueColor()
colors.hoverSelectedColor = colors.hoverColor.blendedColorWithFraction_ofColor_(
0.5, colors.selectedColor)
colors.hoverSpaceColor = colors.hoverColor.colorWithAlphaComponent_(0.2)
colors.hoverSelectedSpaceColor = colors.hoverSelectedColor.colorWithAlphaComponent_(0.2)
self._colors = colors
return self._colors
示例14: getSortInfoUFO
# 需要导入模块: import types [as 别名]
# 或者: from types import SimpleNamespace [as 别名]
def getSortInfoUFO(fontPath: PathLike, fontNum: int):
from fontTools.ufoLib import UFOReader
assert fontNum == 0
suffix = fontPath.suffix.lower().lstrip(".")
reader = UFOReader(fontPath, validate=False)
info = SimpleNamespace()
reader.readInfo(info)
sortInfo = dict(suffix=suffix)
ufoAttrs = [
("familyName", "familyName"),
("styleName", "styleName"),
("weight", "openTypeOS2WeightClass"),
("width", "openTypeOS2WidthClass"),
("italicAngle", "italicAngle"),
]
for key, attr in ufoAttrs:
val = getattr(info, attr, None)
if val is not None:
if key == "italicAngle":
val = -val # negative for intuitive sort order
sortInfo[key] = val
return sortInfo
示例15: load
# 需要导入模块: import types [as 别名]
# 或者: from types import SimpleNamespace [as 别名]
def load(self, outputWriter):
if hasattr(self, "reader"):
self._cachedGlyphs = {}
return
self._setupReaderAndGlyphSet()
self.info = SimpleNamespace()
self.reader.readInfo(self.info)
self.lib = self.reader.readLib()
self._cachedGlyphs = {}
if self.ufoState is None:
includedFeatureFiles = extractIncludedFeatureFiles(self.fontPath, self.reader)
self.ufoState = UFOState(self.reader, self.glyphSet,
getUnicodesAndAnchors=self._getUnicodesAndAnchors,
includedFeatureFiles=includedFeatureFiles)
fontData = await compileUFOToBytes(self.fontPath, outputWriter)
f = io.BytesIO(fontData)
self.ttFont = TTFont(f, lazy=True)
self.shaper = self._getShaper(fontData)