当前位置: 首页>>代码示例>>Python>>正文


Python util.ustr函数代码示例

本文整理汇总了Python中py2neo.util.ustr函数的典型用法代码示例。如果您正苦于以下问题:Python ustr函数的具体用法?Python ustr怎么用?Python ustr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ustr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_path

 def create_path(self, path, name):
     node_names = []
     for i, node in enumerate(path.nodes):
         if isinstance(node, NodePointer):
             node_names.append(_(node.address))
             # Switch out node with object from elsewhere in entity list
             nodes = list(path.nodes)
             node = self.entities[node.address]
             if not isinstance(node, Node):
                 raise ValueError("Pointer does not refer to a node")
             nodes[i] = node
             path.__nodes = tuple(nodes)
         else:
             node_name = name + "n" + ustr(i)
             node_names.append(node_name)
             self.create_node(node, node_name)
     rel_names = []
     for i, rel in enumerate(path.rels):
         rel_name = name + "r" + ustr(i)
         rel_names.append(rel_name)
         if rel.bound:
             self.start_clause.append("{name}=rel({{{name}}})".format(name=rel_name))
             self.params[rel_name] = rel._id
         else:
             if rel.properties:
                 template = "({start})-[{name}:{type} {{{name}}}]->({end})"
                 self.params[rel_name] = rel.properties
             else:
                 template = "({start})-[{name}:{type}]->({end})"
             kwargs = {"start": node_names[i], "name": rel_name,
                       "type": cypher_escape(rel.type), "end": node_names[i + 1]}
             self.create_clause.append(template.format(**kwargs))
         self.return_clause.append(rel_name)
     return node_names, rel_names
开发者ID:noisyboiler,项目名称:py2neo,代码行数:34,代码来源:create.py

示例2: _create_path_nodes

 def _create_path_nodes(self, path, name, unique):
     node_names = []
     for i, node in enumerate(path.nodes):
         if isinstance(node, NodePointer):
             node_names.append(_(node.address))
             # Switch out node with object from elsewhere in entity list
             nodes = list(path.nodes)
             try:
                 target_node = self.entities[node.address]
             except IndexError:
                 raise IndexError("Node pointer {%s} out of range" % node.address)
             if not isinstance(target_node, Node):
                 raise ValueError("Pointer {%s} does not refer to a node" % node.address)
             nodes[i] = target_node
             path._Path__nodes = tuple(nodes)
         elif node in self:
             node_name = _(self.entities.index(node))
             node_names.append(node_name)
         elif unique and not node.bound:
             node_name = name + "n" + ustr(i)
             node_names.append(node_name)
             self.return_clause.append(node_name)
         else:
             node_name = name + "n" + ustr(i)
             node_names.append(node_name)
             self._create_node(node, node_name)
     return node_names
开发者ID:Sapphirine,项目名称:stackexchange,代码行数:27,代码来源:create.py

示例3: hydrate

 def hydrate(cls, data, batch):
     graph = getattr(batch, "graph", None)
     job_id = data["id"]
     uri = data["from"]
     status_code = data.get("status")
     location = data.get("location")
     if graph is None or batch[job_id].raw_result:
         body = data.get("body")
     else:
         body = None
         try:
             body = graph.hydrate(data.get("body"))
         except GraphError as error:
             message = "Batch job %s failed with %s\n%s" % (
                 job_id, error.__class__.__name__, ustr(error))
             raise_from(BatchError(message, batch, job_id, status_code, uri, location), error)
         else:
             # If Cypher results, reduce to single row or single value if possible
             if isinstance(body, RecordList):
                 num_rows = len(body)
                 if num_rows == 0:
                     body = None
                 elif num_rows == 1:
                     body = body[0]
                     num_columns = len(body)
                     if num_columns == 1:
                         body = body[0]
     return cls(batch, job_id, uri, status_code, location, body)
开发者ID:Spanarchie,项目名称:Heroku,代码行数:28,代码来源:core.py

示例4: append

    def append(self, statement, parameters=None, **kwparameters):
        """ Add a statement to the current queue of statements to be
        executed.

        :arg statement: the statement to append
        :arg parameters: a dictionary of execution parameters
        """
        self.__assert_unfinished()

        s = ustr(statement)
        p = {}

        def add_parameters(params):
            if params:
                for key, value in dict(params).items():
                    if isinstance(value, (Node, Rel, Relationship)):
                        value = value._id
                    p[key] = value

        try:
            add_parameters(statement.parameters)
        except AttributeError:
            pass
        add_parameters(dict(parameters or {}, **kwparameters))

        # OrderedDict is used here to avoid statement/parameters ordering bug
        log.info("append %r %r", s, p)
        self.statements.append(OrderedDict([
            ("statement", s),
            ("parameters", p),
            ("resultDataContents", ["REST"]),
        ]))
开发者ID:bartaelterman,项目名称:snippets,代码行数:32,代码来源:core.py

示例5: main

def main():
    script, args = sys.argv[0], sys.argv[1:]
    if len(args) < 2 or len(args) > 3:
        _help(script)
        return
    try:
        service_root = ServiceRoot(NEO4J_URI)
        user_name = args[0]
        password = args[1]
        user_manager = UserManager.for_user(service_root, user_name, password)
        if len(args) == 2:
            # Check password
            if user_manager.password_change_required:
                print("Password change required")
            else:
                print("Password change not required")
        else:
            # Change password
            password_manager = user_manager.password_manager
            new_password = args[2]
            if password_manager.change(new_password):
                print("Password change succeeded")
            else:
                print("Password change failed")
                sys.exit(2)
    except Exception as error:
        sys.stderr.write("%s: %s\n" % (error.__class__.__name__, ustr(error)))
        sys.exit(1)
开发者ID:BlackieXS,项目名称:helping_system,代码行数:28,代码来源:password.py

示例6: _node_remove_labels

def _node_remove_labels(self, *labels):
    from py2neo.batch import WriteBatch
    labels = [ustr(label) for label in set(flatten(labels))]
    batch = WriteBatch(self.graph)
    for label in labels:
        batch.remove_label(self, label)
    batch.run()
开发者ID:bartaelterman,项目名称:snippets,代码行数:7,代码来源:deprecated.py

示例7: _create_path

 def _create_path(self, path, name, unique):
     node_names = self._create_path_nodes(path, name, unique)
     rel_names = []
     for i, rel in enumerate(path.rels):
         rel_name = name + "r" + ustr(i)
         rel_names.append(rel_name)
         if rel.bound:
             self.start_clause.append("{name}=rel({{{name}}})".format(name=rel_name))
             self.parameters[rel_name] = rel._id
         else:
             if rel.properties:
                 template = "{start}-[{name}:{type} {{{name}}}]->{end}"
                 self.parameters[rel_name] = rel.properties
             else:
                 template = "{start}-[{name}:{type}]->{end}"
             start_index, end_index = i, i + 1
             if isinstance(rel,  Rev):
                 start_index, end_index = end_index, start_index
             start_node = path.nodes[start_index]
             end_node = path.nodes[end_index]
             start = self._node_pattern(start_node, node_names[start_index],
                                        full=(unique and not start_node.bound and start_node not in self))
             end = self._node_pattern(end_node, node_names[end_index],
                                      full=(unique and not end_node.bound and end_node not in self))
             kwargs = {"start": start, "name": rel_name,
                       "type": cypher_escape(rel.type), "end": end}
             if unique:
                 self.create_unique_clause.append(template.format(**kwargs))
             else:
                 self.create_clause.append(template.format(**kwargs))
         self.return_clause.append(rel_name)
     return node_names, rel_names
开发者ID:Sapphirine,项目名称:stackexchange,代码行数:32,代码来源:create.py

示例8: _node_set_labels

def _node_set_labels(self, *labels):
    """ Replace all labels on this node.

    :param labels: one or more text labels
    """
    labels = [ustr(label) for label in set(flatten(labels))]
    self.labels.clear()
    self.labels.add(*labels)
开发者ID:allofthesepeople,项目名称:py2neo,代码行数:8,代码来源:deprecated.py

示例9: __repr__

 def __repr__(self):
     column_widths = list(map(len, self.columns))
     for record in self.data:
         for i, (column, value) in enumerate(record):
             column_widths[i] = max(column_widths[i], len(ustr(value)))
     out = [" " + " | ".join(
         column.ljust(column_widths[i])
         for i, column in enumerate(self.columns)
     ) + " "]
     out += ["-" + "-+-".join(
         "-" * column_widths[i]
         for i, column in enumerate(self.columns)
     ) + "-"]
     for record in self.data:
         out.append(" " + " | ".join(ustr(value).ljust(column_widths[i])
                                     for i, (column, value) in enumerate(record)) + " ")
     out = "\n".join(out)
     return out
开发者ID:JohannesOos,项目名称:py2neo,代码行数:18,代码来源:core.py

示例10: _node_add_labels

def _node_add_labels(self, *labels):
    labels = [ustr(label) for label in set(flatten(labels))]
    self.labels.update(labels)
    try:
        self.labels.push()
    except GraphError as err:
        if err.response.status_code == BAD_REQUEST and err.cause.exception == 'ConstraintViolationException':
            raise ValueError(err.cause.message)
        else:
            raise
开发者ID:bartaelterman,项目名称:snippets,代码行数:10,代码来源:deprecated.py

示例11: _jsonify

 def _jsonify(cls, value):
     if isinstance(value, list):
         out = "[" + ", ".join(cls._jsonify(i) for i in value) + "]"
     elif hasattr(value, "uri") and hasattr(value, "_properties"):
         metadata = {
             "uri": ustr(value.uri),
             "properties": value._properties,
         }
         try:
             metadata.update({
                 "start": ustr(value.start_node.uri),
                 "type": ustr(value.type),
                 "end": ustr(value.end_node.uri),
             })
         except AttributeError:
             pass
         out = json.dumps(metadata, ensure_ascii=False)
     else:
         out = json.dumps(value, ensure_ascii=False)
     return out
开发者ID:EricEllett,项目名称:py2neo,代码行数:20,代码来源:__init__.py

示例12: create_path

 def create_path(self, name, path):
     node_names = [None] * len(path.nodes)
     rel_names = [None] * len(path.rels)
     for i, node in enumerate(path.nodes):
         if isinstance(node, NodePointer):
             node_names[i] = _(node.address)
             # Switch out node with object from elsewhere in entity list
             nodes = list(path.nodes)
             node = self.entities[node.address]
             if not isinstance(node, Node):
                 raise ValueError("Pointer does not refer to a node")
             nodes[i] = node
             path.__nodes = tuple(nodes)
         else:
             node_names[i] = name + "n" + ustr(i)
             self.create_node(node_names[i], node)
     for i, rel in enumerate(path.rels):
         rel_names[i] = name + "r" + ustr(i)
         self.create_rel(rel_names[i], rel, node_names[i], node_names[i + 1])
     return node_names, rel_names
开发者ID:allofthesepeople,项目名称:py2neo,代码行数:20,代码来源:create.py

示例13: write_identifier

 def write_identifier(self, identifier):
     """ Write an identifier.
     """
     if not identifier:
         raise ValueError("Invalid identifier")
     identifier = ustr(identifier)
     safe = all(ch in self.safe_chars for ch in identifier)
     if not safe:
         self.file.write(json.dumps(identifier))
     else:
         self.file.write(identifier)
开发者ID:BlackieXS,项目名称:helping_system,代码行数:11,代码来源:writer.py

示例14: _node_remove_labels

def _node_remove_labels(self, *labels):
    """ Remove one or more labels from this node.

    :param labels: one or more text labels
    """
    from py2neo.batch import WriteBatch
    labels = [ustr(label) for label in set(flatten(labels))]
    batch = WriteBatch(self.graph)
    for label in labels:
        batch.remove_label(self, label)
    batch.run()
开发者ID:allofthesepeople,项目名称:py2neo,代码行数:11,代码来源:deprecated.py

示例15: _stringify

 def _stringify(cls, value, quoted=False):
     if value is None:
         if quoted:
             return "null"
         else:
             return ""
     elif isinstance(value, list):
         out = " ".join(
             cls._stringify(item, quoted=False)
             for item in value
         )
         if quoted:
             out = json.dumps(out, separators=(',', ':'), ensure_ascii=False)
     else:
         if quoted:
             try:
                 out = json.dumps(value, ensure_ascii=False)
             except TypeError:
                 out = json.dumps(ustr(value), ensure_ascii=False)
         else:
             out = ustr(value)
     return out
开发者ID:EricEllett,项目名称:py2neo,代码行数:22,代码来源:__init__.py


注:本文中的py2neo.util.ustr函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。