本文整理汇总了Python中pydoc.locate函数的典型用法代码示例。如果您正苦于以下问题:Python locate函数的具体用法?Python locate怎么用?Python locate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了locate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create_routine_wrapper_generator
def create_routine_wrapper_generator(rdbms):
"""
Factory for creating a Constants objects (i.e. objects for generating a class with wrapper methods for calling
stored routines in a database).
:param str rdbms: The target RDBMS (i.e. mysql or mssql).
:return: pystratum.RoutineWrapperGenerator.RoutineWrapperGenerator
"""
# Note: We load modules and classes dynamically such that on the end user's system only the required modules
# and other dependencies for the targeted RDBMS must be installed (and required modules and other
# dependencies for the other RDBMSs are not required).
if rdbms == 'mysql':
module = locate('pystratum.mysql.MySqlRoutineWrapperGenerator')
return module.MySqlRoutineWrapperGenerator()
if rdbms == 'mssql':
module = locate('pystratum.mssql.MsSqlRoutineWrapperGenerator')
return module.MsSqlRoutineWrapperGenerator()
if rdbms == 'pgsql':
module = locate('pystratum.pgsql.PgSqlRoutineWrapperGenerator')
return module.PgSqlRoutineWrapperGenerator()
raise Exception("Unknown RDBMS '%s'." % rdbms)
开发者ID:gitter-badger,项目名称:py-stratum,代码行数:25,代码来源:__init__.py
示例2: find_injectable_classes
def find_injectable_classes(search_paths, exclude_injectable_module_paths=None):
modules = set()
for path in search_paths:
for root, dirs, fnames in os.walk(path):
for fname in fnames:
if fname.endswith('.py'):
module_path = os.path.relpath(os.path.join(root, fname), path)
module = module_path.replace('/', '.')[:-3]
fpath = os.path.join(root, fname)
has_import = False
has_decorator = False
with open(fpath) as f:
for line in f:
if 'dart.context.locator' in line:
has_import = True
if '@injectable' in line:
has_decorator = True
if has_import and has_decorator:
break
if has_import and has_decorator and not path_excluded(module, exclude_injectable_module_paths):
modules.add(module)
for module in modules:
class_metadata = readmodule(module)
for class_name in class_metadata.keys():
# the line below will load the class, which causes the @injectable code to run,
# registering the class (assuming the module search was not a false positive)
locate(module + '.' + class_name)
classes_by_name = {cls.__name__: cls for cls in class_registry.classes}
for class_name in sorted(classes_by_name.keys()):
_logger.info('injectable class registered: %s' % class_name)
return classes_by_name.values()
开发者ID:RetailMeNotSandbox,项目名称:dart,代码行数:34,代码来源:locator.py
示例3: _unwrap_object
def _unwrap_object(obj, nested=False):
obj_type = obj['_type']
value = obj.get('value', None)
if obj_type == 'none':
return None
if obj_type in ('bool', 'str', 'int', 'float'):
return locate(obj_type)(value)
if obj_type == 'decimal':
return Decimal(value)
if obj_type == 'datetime':
return datetime.datetime.utcfromtimestamp(value)
if obj_type in ('list', 'dict'):
return locate(obj_type)(unwraps(value)) if nested else value
if obj_type in ('set', 'frozenset', 'tuple'):
if nested:
value = unwraps(value)
return locate(obj_type)(value)
if obj_type == 'frozendict':
if nested:
value = unwraps(value)
return frozendict(value)
raise ValueError(repr(obj) + ' cannot be decoded.')
开发者ID:kidig,项目名称:phuntic,代码行数:30,代码来源:__init__.py
示例4: create_constants
def create_constants(rdbms: str):
"""
Factory for creating a Constants objects (i.e. objects for creating constants based on column widths, and auto
increment columns and labels).
:param rdbms: The target RDBMS (i.e. mysql or mssql).
:rtype : pystratum.Constants.Constants
"""
# Note: We load modules and classes dynamically such that on the end user's system only the required modules
# and other dependencies for the targeted RDBMS must be installed (and required modules and other
# dependencies for the other RDBMSs are not required).
if rdbms == 'mysql':
module = locate('pystratum.mysql.MySqlConstants')
return module.MySqlConstants()
if rdbms == 'mssql':
module = locate('pystratum.mssql.MsSqlConstants')
return module.MsSqlConstants()
if rdbms == 'pgsql':
module = locate('pystratum.pgsql.PgSqlConstants')
return module.PgSqlConstants()
raise Exception("Unknown RDBMS '%s'." % rdbms)
开发者ID:gitter-badger,项目名称:py-stratum,代码行数:25,代码来源:__init__.py
示例5: cmd_htmldoc
def cmd_htmldoc(ch, cmd, arg):
"""Creates html documentation for all registered modules. html files will
be saved to html/pydocs/
"""
try:
os.makedirs(HTML_DOC_DIR)
except: pass
doc = pydoc.HTMLDoc()
for modname in suggested_reading:
todoc = pydoc.locate(modname)
if todoc != None:
fname = HTML_DOC_DIR + "/" + modname + ".html"
fl = file(fname, "w+")
fl.write(doc.page(modname, doc.document(todoc)))
fl.close()
builtin_index = doc.multicolumn([doc.modulelink(pydoc.locate(modname)) for modname in builtins], lambda x: x)
# build our index page. That includes things in pymodules/ and builtins
index_contents ="".join([doc.section("<big><strong>builtins</big></strong>",
'white', '#ee77aa', builtin_index),
doc.index("../lib/pymodules/")])
# go over all of our builtins and add them to the index
index = file(HTML_DOC_DIR + "/index.html", "w+")
index.write(doc.page("index", index_contents))
index.close()
ch.send("html documentation generated for all known modules.")
开发者ID:KaSt,项目名称:nereamud,代码行数:29,代码来源:doc.py
示例6: main
def main(argv):
if FLAGS.debug:
# Setting to '0': all tensorflow messages are logged.
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '0'
logging.basicConfig(level=logging.INFO)
# Extract the merged configs/dictionaries.
config = io_utils.parse_config(flags=FLAGS)
if config['model_params']['decode'] and config['model_params']['reset_model']:
print("Woops! You passed {decode: True, reset_model: True}."
" You can't chat with a reset bot! I'll set reset to False.")
config['model_params']['reset_model'] = False
# If loading from pretrained, double-check that certain values are correct.
# (This is not something a user need worry about -- done automatically)
if FLAGS.pretrained_dir is not None:
assert config['model_params']['decode'] \
and not config['model_params']['reset_model']
# Print out any non-default parameters given by user, so as to reassure
# them that everything is set up properly.
io_utils.print_non_defaults(config)
print("Setting up %s dataset." % config['dataset'])
dataset_class = locate(config['dataset']) or getattr(data, config['dataset'])
dataset = dataset_class(config['dataset_params'])
print("Creating", config['model'], ". . . ")
bot_class = locate(config['model']) or getattr(chatbot, config['model'])
bot = bot_class(dataset, config)
if not config['model_params']['decode']:
start_training(dataset, bot)
else:
start_chatting(bot)
开发者ID:laurii,项目名称:DeepChatModels,代码行数:35,代码来源:main.py
示例7: handle_chat
def handle_chat(message, protocol):
"""
:return: Weather or not the chat message was a valid command
"""
if message == 'You are already chatting in that group.':
return True
elif re.match(r'From Amelorate: ssh', message):
chat.say(message[20:])
return True
match = re.match(r'From .*:\s', message)
if match:
print(':c: ' + message[5:])
name = message[5:].split(': ')[0]
message = message[match.end():]
for command in COMMANDS['regex'].keys():
match = re.match(command + r'\s', message, re.IGNORECASE)
if match:
message = message[match.end():]
message = message[:-1]
locate('commands.' + COMMANDS['regex'][command] + '.call')(message, name, protocol, CONFIG, COMMANDS)
return True
chat.say('/msg ' + name + ' Sorry, that command was not recognized as valid.')
return False
else:
return False
开发者ID:Ameliorate,项目名称:DevotedBot,代码行数:26,代码来源:start.py
示例8: create_routine_loader
def create_routine_loader(rdbms):
"""
Factory for creating a Routine Loader objects (i.e. objects for loading stored routines into a RDBMS instance from
(pseudo) SQL files.
:param str rdbms: The target RDBMS (i.e. mysql or mssql).
:rtype: pystratum.RoutineLoader.RoutineLoader
"""
# Note: We load modules and classes dynamically such that on the end user's system only the required modules
# and other dependencies for the targeted RDBMS must be installed (and required modules and other
# dependencies for the other RDBMSs are not required).
if rdbms == 'mysql':
module = locate('pystratum.mysql.MySqlRoutineLoader')
return module.MySqlRoutineLoader()
if rdbms == 'mssql':
module = locate('pystratum.mssql.MsSqlRoutineLoader')
return module.MsSqlRoutineLoader()
if rdbms == 'pgsql':
module = locate('pystratum.pgsql.PgSqlRoutineLoader')
return module.PgSqlRoutineLoader()
raise Exception("Unknown RDBMS '%s'." % rdbms)
开发者ID:gitter-badger,项目名称:py-stratum,代码行数:25,代码来源:__init__.py
示例9: __call__
def __call__(self, environ, start_response):
session_store = locate(settings.SESSION_STORE)
if not session_store or not issubclass(session_store, SessionStore):
raise ValueError(
'SESSION_STORE must be a sub class of \'SessionStore\''
)
session_store = session_store()
auth_collection = locate(settings.AUTH_COLLECTION)
if not auth_collection or not issubclass(auth_collection, Collection):
raise ValueError(
'AUTH_COLLECTION must be a sub class of \'Collection\''
)
environ['session'] = session_store.new()
session_id = environ.get('HTTP_AUTHORIZATION', '')
if len(session_id.split('Token ')) == 2:
session_id = session_id.split('Token ')[1]
environ['session'] = session_store.get(session_id)
else:
cookies = environ.get('HTTP_COOKIE')
if cookies:
session_id = parse_cookie(cookies).get('session_id')
if session_id:
environ['session'] = session_store.get(session_id)
environ[auth_collection.__name__.lower()] = auth_collection.get({
'_id': deserialize(
environ['session'].get(auth_collection.__name__.lower(), '""')
)
})
def authentication(status, headers, exc_info=None):
headers.extend([
(
'Set-Cookie', dump_cookie(
'session_id', environ['session'].sid, 7 * 24 * 60 * 60,
)
),
(
'HTTP_AUTHORIZATION', 'Token {0}'.format(
environ['session'].sid
)
),
])
return start_response(status, headers, exc_info)
response = self.app(environ, authentication)
if environ['session'].should_save:
session_store.save(environ['session'])
return response
开发者ID:mathvaleriano,项目名称:mongorest,代码行数:59,代码来源:middlewares.py
示例10: locate_with_hint
def locate_with_hint(class_path, prefix_hints=[]):
module_or_class = locate(class_path)
if module_or_class is None:
# for hint in iscanr(lambda x, y: x + "." + y, prefix_hints):
# module_or_class = locate(hint + "." + class_path)
# if module_or_class:
# break
hint = ".".join(prefix_hints)
module_or_class = locate(hint + "." + class_path)
return module_or_class
开发者ID:QuantCollective,项目名称:maml_rl,代码行数:10,代码来源:resolve.py
示例11: treat_question
def treat_question(self, question, survey):
LOGGER.info("Treating, %s %s", question.pk, question.text)
options = self.tconf.get(survey_name=self.survey.name,
question_text=question.text)
multiple_charts = options.get("multiple_charts")
if not multiple_charts:
multiple_charts = {"": options.get("chart")}
question_synthesis = ""
i = 0
for chart_title, opts in multiple_charts.items():
i += 1
if chart_title:
# "" is False, by default we do not add section or anything
mct = options["multiple_chart_type"]
question_synthesis += "\%s{%s}" % (mct, chart_title)
tex_type = opts.get("type")
if tex_type == "raw":
question_synthesis += Question2TexRaw(question, **opts).tex()
elif tex_type == "sankey":
other_question_text = opts["question"]
other_question = Question.objects.get(text=other_question_text)
q2tex = Question2TexSankey(question)
question_synthesis += q2tex.tex(other_question)
elif tex_type in ["pie", "cloud", "square", "polar"]:
q2tex = Question2TexChart(question, latex_label=i, **opts)
question_synthesis += q2tex.tex()
elif locate(tex_type) is None:
msg = "{} '{}' {}".format(
_("We could not render a chart because the type"),
tex_type,
_("is not a standard type nor the path to an "
"importable valid Question2Tex child class. "
"Choose between 'raw', 'sankey', 'pie', 'cloud', "
"'square', 'polar' or 'package.path.MyQuestion2Tex"
"CustomClass'")
)
LOGGER.error(msg)
question_synthesis += msg
else:
q2tex_class = locate(tex_type)
# The use will probably know what type he should use in his
# custom class
opts["type"] = None
q2tex = q2tex_class(question, latex_label=i, **opts)
question_synthesis += q2tex.tex()
section_title = Question2Tex.html2latex(question.text)
return u"""
\\clearpage{}
\\section{%s}
\label{sec:%s}
%s
""" % (section_title, question.pk, question_synthesis)
开发者ID:Ben2pop,项目名称:SoftScores-Final,代码行数:55,代码来源:survey2tex.py
示例12: cmd_doc
def cmd_doc(ch, cmd, arg):
"""Return Python documentation for the specified module, class, function,
etc... for example:
> doc char.Char
Will return all available documentation for the Char class.
"""
if arg == "":
ch.page("\r\n".join(display.pagedlist({ "Topics" : suggested_reading },
header = "Suggested doc readings include:")))
else:
# just because sometimes I forget periods
arg = arg.replace(" ", ".")
# are we looking for a shortcut value?
if arg in shortcuts:
arg = shortcuts[arg]
# try to find what we're documenting
todoc = pydoc.locate(arg)
if todoc == None:
ch.send("Could not find Python documentation on: '%s'" % arg)
else:
doc = pydoc.TextDoc()
ch.page(doc.document(todoc).replace("{", "{{"))
开发者ID:KaSt,项目名称:nereamud,代码行数:26,代码来源:doc.py
示例13: open
def open(filename):
'''Import netCDF output file as OpenDrift object of correct class'''
import os
import logging
import pydoc
from netCDF4 import Dataset
if not os.path.exists(filename):
logging.info('File does not exist, trying to retrieve from URL')
import urllib
try:
urllib.urlretrieve(filename, 'opendrift_tmp.nc')
filename = 'opendrift_tmp.nc'
except:
raise ValueError('%s does not exist' % filename)
n = Dataset(filename)
try:
module_name = n.opendrift_module
class_name = n.opendrift_class
except:
raise ValueError(filename + ' does not contain '
'necessary global attributes '
'opendrift_module and opendrift_class')
n.close()
cls = pydoc.locate(module_name + '.' + class_name)
if cls is None:
from models import oceandrift3D
cls = oceandrift3D.OceanDrift3D
o = cls()
o.io_import_file(filename)
logging.info('Returning ' + str(type(o)) + ' object')
return o
开发者ID:p1heidary,项目名称:opendrift,代码行数:33,代码来源:__init__.py
示例14: plot
def plot(func):
try:
import click
except ImportError:
click = None
if click:
doc_strings = [f.__doc__ for f in _plot_helper._functions]
decorators = [click.command()]
chain = itertools.chain(*(s.split("\n") for s in doc_strings))
lines1, lines2 = itertools.tee(chain)
next(lines2, None)
for line1, line2 in itertools.izip(lines1, lines2):
if ':' in line1:
opt, t = [s.strip() for s in line1.split(":")]
decorators.append(click.option('--' + opt,
type=pydoc.locate(t),
help=line2.strip()))
decorators.append(wraps(func))
else:
decorators = [wraps(func)]
@_decorate_all(decorators)
def plotted_func(**kwargs):
fig, ax = plt.subplots()
name = func(fig, ax, **kwargs)
for helper in _plot_helper._functions:
helper(ax, **kwargs)
fig.savefig(name)
return plotted_func
开发者ID:baxen,项目名称:fishbowl,代码行数:30,代码来源:decorator.py
示例15: __init__
def __init__(
self, base_modules, destination_directory=".",
recursion=1, exclusions=(),
recursion_stops=(),
formatter = None
):
self.destinationDirectory = os.path.abspath(destination_directory)
self.exclusions = {}
self.warnings = []
self.baseSpecifiers = {}
self.completed = {}
self.recursionStops = {}
self.recursion = recursion
for stop in recursion_stops:
self.recursionStops[stop] = 1
self.pending = []
for exclusion in exclusions:
try:
self.exclusions[exclusion] = pydoc.locate(exclusion)
except pydoc.ErrorDuringImport:
self.warn('Unable to import the module {0} which was specified as an exclusion module'.format(
repr(exclusion))
)
self.formatter = formatter or DefaultFormatter()
for base in base_modules:
self.add_base(base)
开发者ID:ellepdesk,项目名称:pymodbus3,代码行数:26,代码来源:build.py
示例16: metadata
def metadata():
json_file = '../src/pytorch-metadata.json'
json_data = open(json_file).read()
json_root = json.loads(json_data)
schema_map = {}
for entry in json_root:
name = entry['name']
schema = entry['schema']
schema_map[name] = schema
for entry in json_root:
name = entry['name']
schema = entry['schema']
if 'package' in schema:
class_name = schema['package'] + '.' + name
# print(class_name)
class_definition = pydoc.locate(class_name)
if not class_definition:
raise Exception('\'' + class_name + '\' not found.')
docstring = class_definition.__doc__
if not docstring:
raise Exception('\'' + class_name + '\' missing __doc__.')
# print(docstring)
with io.open(json_file, 'w', newline='') as fout:
json_data = json.dumps(json_root, sort_keys=True, indent=2)
for line in json_data.splitlines():
line = line.rstrip()
if sys.version_info[0] < 3:
line = unicode(line)
fout.write(line)
fout.write('\n')
开发者ID:lutzroeder,项目名称:Netron,代码行数:34,代码来源:pytorch-script.py
示例17: serialize_model
def serialize_model(obj):
"""
Locates a models serializer and uses it to serialize a model instance
This allows us to search a document through all its important components.
If a attribute of model is important enough to make it to the model
serializer,
it means that the models should also be searched though that attribute
as well. This will take care for all the child models of a model if
they have been inlined in the serializer.
For this to work, a model's serializer name has to follow this convention
'<model_name>Serializer' Failing to do so the function will cause the
function throw a TypeError exception.
Only apps in local apps will be indexed.
"""
app_label = obj._meta.app_label
serializer_path = "{}{}{}{}".format(
app_label, ".serializers.", obj.__class__.__name__, 'Serializer')
serializer_cls = pydoc.locate(serializer_path)
if not serializer_cls:
LOGGER.info("Unable to locate a serializer for model {}".format(
obj.__class__))
else:
serialized_data = serializer_cls(obj).data
serialized_data = json.dumps(serialized_data, default=default)
return {
"data": serialized_data,
"instance_type": obj.__class__.__name__.lower(),
"instance_id": str(obj.id)
}
开发者ID:FelixOngati,项目名称:mfl_api,代码行数:31,代码来源:search_utils.py
示例18: index_instance
def index_instance(app_label, model_name, instance_id, index_name=INDEX_NAME):
indexed = False
elastic_api = ElasticAPI()
obj_path = "{0}.models.{1}".format(app_label, model_name)
obj = pydoc.locate(obj_path).objects.get(id=instance_id)
if not elastic_api._is_on:
ErrorQueue.objects.get_or_create(
object_pk=str(obj.pk),
app_label=obj._meta.app_label,
model_name=obj.__class__.__name__,
except_message="Elastic Search is not running",
error_type="SEARCH_INDEXING_ERROR"
)
return indexed
if confirm_model_is_indexable(obj.__class__):
data = serialize_model(obj)
if data:
elastic_api.index_document(index_name, data)
LOGGER.info("Indexed {0}".format(data))
indexed = True
else:
LOGGER.info(
"something unexpected occurred when indexing {} - {}"
.format(model_name, instance_id)
)
else:
LOGGER.info(
"Instance of model {} skipped for indexing as it should not be"
" indexed".format(obj.__class__))
return indexed
开发者ID:FelixOngati,项目名称:mfl_api,代码行数:31,代码来源:search_utils.py
示例19: decode_from_dict
def decode_from_dict(field_typestr, value):
if not value or not field_typestr:
return value
if field_typestr == 'datetime.datetime':
return dateutil.parser.parse(value)
if field_typestr == 'datetime.timedelta':
match = timedelta_re.match(value).groupdict()
for k, v in match.items():
match[k] = int(v) if v is not None else 0
return datetime.timedelta(**match)
if field_typestr == 'datetime.date':
return dateutil.parser.parse(value).date()
if field_typestr.startswith('dict'):
if field_typestr == 'dict':
return value
# ensure sensible keys
assert field_typestr[:9] == 'dict[str,'
dict_value_typestr = field_typestr[9:-1]
return {k: decode_from_dict(dict_value_typestr, v) for k, v in value.iteritems()}
if field_typestr.startswith('list'):
list_typestr = field_typestr[5:-1]
return [decode_from_dict(list_typestr, v) for v in value]
cls = locate(field_typestr)
if hasattr(cls, '__dictable_public_fields_with_defaults'):
return from_dict(cls, value)
return cls(value)
开发者ID:RetailMeNotSandbox,项目名称:dart,代码行数:30,代码来源:base.py
示例20: addBase
def addBase(self, specifier):
"""Set the base of the documentation set, only children of these modules will be documented"""
try:
self.baseSpecifiers[specifier] = pydoc.locate(specifier)
self.pending.append(specifier)
except pydoc.ErrorDuringImport, value:
self.warn("""Unable to import the module %s which was specified as a base module""" % (repr(specifier)))
开发者ID:mathivanane,项目名称:openwsn-sw,代码行数:7,代码来源:pydoc2.py
注:本文中的pydoc.locate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论