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


Python ujson.dump方法代码示例

本文整理汇总了Python中ujson.dump方法的典型用法代码示例。如果您正苦于以下问题:Python ujson.dump方法的具体用法?Python ujson.dump怎么用?Python ujson.dump使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ujson的用法示例。


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

示例1: setup_event_queue

# 需要导入模块: import ujson [as 别名]
# 或者: from ujson import dump [as 别名]
def setup_event_queue(port: int) -> None:
    if not settings.TEST_SUITE:
        load_event_queues(port)
        atexit.register(dump_event_queues, port)
        # Make sure we dump event queues even if we exit via signal
        signal.signal(signal.SIGTERM, lambda signum, stack: sys.exit(1))
        add_reload_hook(lambda: dump_event_queues(port))

    try:
        os.rename(persistent_queue_filename(port), persistent_queue_filename(port, last=True))
    except OSError:
        pass

    # Set up event queue garbage collection
    ioloop = tornado.ioloop.IOLoop.instance()
    pc = tornado.ioloop.PeriodicCallback(lambda: gc_event_queues(port),
                                         EVENT_QUEUE_GC_FREQ_MSECS, ioloop)
    pc.start()

    send_restart_events(immediate=settings.DEVELOPMENT) 
开发者ID:zulip,项目名称:zulip,代码行数:22,代码来源:event_queue.py

示例2: create_language_name_map

# 需要导入模块: import ujson [as 别名]
# 或者: from ujson import dump [as 别名]
def create_language_name_map(self) -> None:
        join = os.path.join
        deploy_root = settings.DEPLOY_ROOT
        path = join(deploy_root, 'locale', 'language_options.json')
        output_path = join(deploy_root, 'locale', 'language_name_map.json')

        with open(path) as reader:
            languages = ujson.load(reader)
            lang_list = []
            for lang_info in languages['languages']:
                lang_info['name'] = lang_info['name_local']
                del lang_info['name_local']
                lang_list.append(lang_info)

            lang_list.sort(key=lambda lang: lang['name'])

        with open(output_path, 'w') as output_file:
            ujson.dump({'name_map': lang_list}, output_file, indent=4, sort_keys=True)
            output_file.write('\n') 
开发者ID:zulip,项目名称:zulip,代码行数:21,代码来源:compilemessages.py

示例3: export_realm_icons

# 需要导入模块: import ujson [as 别名]
# 或者: from ujson import dump [as 别名]
def export_realm_icons(realm: Realm, local_dir: Path, output_dir: Path) -> None:
    records = []
    dir_relative_path = zerver.lib.upload.upload_backend.realm_avatar_and_logo_path(realm)
    icons_wildcard = os.path.join(local_dir, dir_relative_path, '*')
    for icon_absolute_path in glob.glob(icons_wildcard):
        icon_file_name = os.path.basename(icon_absolute_path)
        icon_relative_path = os.path.join(str(realm.id), icon_file_name)
        output_path = os.path.join(output_dir, icon_relative_path)
        os.makedirs(str(os.path.dirname(output_path)), exist_ok=True)
        shutil.copy2(str(icon_absolute_path), str(output_path))
        record = dict(realm_id=realm.id,
                      path=icon_relative_path,
                      s3_path=icon_relative_path)
        records.append(record)

    with open(os.path.join(output_dir, "records.json"), "w") as records_file:
        ujson.dump(records, records_file, indent=4) 
开发者ID:zulip,项目名称:zulip,代码行数:19,代码来源:export.py

示例4: archive_incident

# 需要导入模块: import ujson [as 别名]
# 或者: from ujson import dump [as 别名]
def archive_incident(incident_row, archive_path):
    incident = {field[1]: incident_row[i] for i, field in enumerate(incident_fields)}

    created = incident['created']
    incident_dir = os.path.join(archive_path, str(created.year), str(created.month), str(created.day), str(incident['incident_id']))

    try:
        os.makedirs(incident_dir)
    except OSError as e:
        if e.errno != errno.EEXIST:
            logger.exception('Failed creating %s DIR', incident_dir)
            return

    incident_file = os.path.join(incident_dir, 'incident_data.json')

    try:
        with open(incident_file, 'w') as handle:
            ujson.dump(incident, handle, indent=2)
    except IOError:
        logger.exception('Failed writing incident metadata to %s', incident_file) 
开发者ID:linkedin,项目名称:iris,代码行数:22,代码来源:retention.py

示例5: archive_message

# 需要导入模块: import ujson [as 别名]
# 或者: from ujson import dump [as 别名]
def archive_message(message_row, archive_path):
    message = {field[1]: message_row[i] for i, field in enumerate(message_fields)}

    created = message['created']
    incident_dir = os.path.join(archive_path, str(created.year), str(created.month), str(created.day), str(message['incident_id']))

    try:
        os.makedirs(incident_dir)
    except OSError as e:
        if e.errno != errno.EEXIST:
            logger.exception('Failed creating %s DIR', incident_dir)
            return

    message_file = os.path.join(incident_dir, 'message_%d.json' % message['message_id'])

    try:
        with open(message_file, 'w') as handle:
            ujson.dump(message, handle, indent=2)
    except IOError:
        logger.exception('Failed writing message to %s', message_file) 
开发者ID:linkedin,项目名称:iris,代码行数:22,代码来源:retention.py

示例6: archive_comment

# 需要导入模块: import ujson [as 别名]
# 或者: from ujson import dump [as 别名]
def archive_comment(comment_row, archive_path):
    comment = {field[1]: comment_row[i] for i, field in enumerate(comment_fields)}

    created = comment['created']
    incident_dir = os.path.join(archive_path, str(created.year), str(created.month), str(created.day), str(comment['incident_id']))

    try:
        os.makedirs(incident_dir)
    except OSError as e:
        if e.errno != errno.EEXIST:
            logger.exception('Failed creating %s DIR', incident_dir)
            return

    comment_file = os.path.join(incident_dir, 'comment_%d.json' % comment['comment_id'])

    try:
        with open(comment_file, 'w') as handle:
            ujson.dump(comment, handle, indent=2)
    except IOError:
        logger.exception('Failed writing comment to %s', comment_file) 
开发者ID:linkedin,项目名称:iris,代码行数:22,代码来源:retention.py

示例7: pickle

# 需要导入模块: import ujson [as 别名]
# 或者: from ujson import dump [as 别名]
def pickle(self, path=None, name=None):
        """
        Pickles Credentials

        Arguments:

            path (str): path of the directory to store pickle in

            name (str): name of the file.
        """
        if path is None:
            path = os.path.dirname(os.path.abspath(__file__))
        if name is None:
            name = DEFAULT_FILENAME_BASE + self.__class__.__name__ + "_pickle"
        path = os.path.join(path, name)
        with open(path, "wb") as creds_file:
            pickle.dump(self, creds_file, pickle.HIGHEST_PROTOCOL) 
开发者ID:omarryhan,项目名称:pyfy,代码行数:19,代码来源:creds.py

示例8: save_as_json

# 需要导入模块: import ujson [as 别名]
# 或者: from ujson import dump [as 别名]
def save_as_json(self, path=None, name=None):
        """
        Saves credentials as a json file

        Arguments:

            path (str): path of the directory you want to save the file in

            name (str): name of the file.
        """
        if path is None:
            path = os.path.dirname(os.path.abspath(__file__))
        if name is None:
            name = DEFAULT_FILENAME_BASE + self.__class__.__name__ + ".json"
        path = os.path.join(path, name)
        with open(path, "w") as outfile:
            out_dict = self.__dict__.copy()
            if 'expiry' in out_dict and out_dict['expiry'] is not None:
                del out_dict['expiry']

            if "ujson" in sys.modules:
                json.dump(out_dict, outfile)
            else:
                json.dump(out_dict, outfile, default=str) 
开发者ID:omarryhan,项目名称:pyfy,代码行数:26,代码来源:creds.py

示例9: shutdown

# 需要导入模块: import ujson [as 别名]
# 或者: from ujson import dump [as 别名]
def shutdown(self):
        with open("savedata/prefixes.json", 'w') as prf:
            json.dump(self.prefixes, prf)

        await self.session.close() 
开发者ID:henry232323,项目名称:RPGBot,代码行数:7,代码来源:RPGBot.py

示例10: save

# 需要导入模块: import ujson [as 别名]
# 或者: from ujson import dump [as 别名]
def save(filename, obj, message=None):
    if message is not None:
        print("Saving {}...".format(message))
        with open(filename, "w") as fh:
            json.dump(obj, fh) 
开发者ID:HKUST-KnowComp,项目名称:R-Net,代码行数:7,代码来源:prepro.py

示例11: __init__

# 需要导入模块: import ujson [as 别名]
# 或者: from ujson import dump [as 别名]
def __init__(self, output, root):
        """
        :type output: io.RawIOBase
        :type root: str
        """

        self.output = output
        self.depth = 0

        self.output.write('[1,0,')
        json.dump({'progname': 'ncdu-s3', 'progver': '0.1', 'timestamp': int(time.time())}, self.output)

        # ncdu data format must begin with a directory
        self.dir_enter(root) 
开发者ID:EverythingMe,项目名称:ncdu-s3,代码行数:16,代码来源:ncdu_data_writer.py

示例12: dir_enter

# 需要导入模块: import ujson [as 别名]
# 或者: from ujson import dump [as 别名]
def dir_enter(self, name):
        """
        :type name: str
        """

        self.depth += 1

        self.output.write(",\n")

        self.output.write('[')
        json.dump({'name': name}, self.output) 
开发者ID:EverythingMe,项目名称:ncdu-s3,代码行数:13,代码来源:ncdu_data_writer.py

示例13: file_entry

# 需要导入模块: import ujson [as 别名]
# 或者: from ujson import dump [as 别名]
def file_entry(self, name, size):
        """
        :type name: str
        :type size: int
        """

        self.output.write(",\n")

        json.dump({'name': name, 'dsize': size}, self.output) 
开发者ID:EverythingMe,项目名称:ncdu-s3,代码行数:11,代码来源:ncdu_data_writer.py

示例14: create_converted_data_files

# 需要导入模块: import ujson [as 别名]
# 或者: from ujson import dump [as 别名]
def create_converted_data_files(data: Any, output_dir: str, file_path: str) -> None:
    output_file = output_dir + file_path
    os.makedirs(os.path.dirname(output_file), exist_ok=True)
    with open(output_file, 'w') as fp:
        ujson.dump(data, fp, indent=4) 
开发者ID:zulip,项目名称:zulip,代码行数:7,代码来源:import_util.py

示例15: dump_event_queues

# 需要导入模块: import ujson [as 别名]
# 或者: from ujson import dump [as 别名]
def dump_event_queues(port: int) -> None:
    start = time.time()

    with open(persistent_queue_filename(port), "w") as stored_queues:
        ujson.dump([(qid, client.to_dict()) for (qid, client) in clients.items()],
                   stored_queues)

    logging.info('Tornado %d dumped %d event queues in %.3fs',
                 port, len(clients), time.time() - start) 
开发者ID:zulip,项目名称:zulip,代码行数:11,代码来源:event_queue.py


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