本文整理汇总了Python中pydoc.locate函数的典型用法代码示例。如果您正苦于以下问题:Python locate函数的具体用法?Python locate怎么用?Python locate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了locate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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()
示例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.')
示例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)
示例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.")
示例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)
示例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
示例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)
示例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
示例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
示例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)
示例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("{", "{{"))
示例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
示例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
示例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)