惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Threat Research - Cisco Blogs
A
Arctic Wolf
S
Securelist
O
OpenAI News
T
Threatpost
Forbes - Security
Forbes - Security
N
News and Events Feed by Topic
S
Secure Thoughts
H
Heimdal Security Blog
S
Security Affairs
P
Privacy International News Feed
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
Cyberwarzone
Cyberwarzone
N
News and Events Feed by Topic
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Palo Alto Networks Blog
S
Security @ Cisco Blogs
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
T
Tailwind CSS Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hacker News: Ask HN
Hacker News: Ask HN
T
Troy Hunt's Blog
S
SegmentFault 最新的问题
腾讯CDC
V
Visual Studio Blog
Last Week in AI
Last Week in AI
H
Hacker News: Front Page
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Project Zero
Project Zero
WordPress大学
WordPress大学
NISL@THU
NISL@THU
博客园 - 【当耐特】
博客园 - Franky
Webroot Blog
Webroot Blog
博客园_首页
T
Tenable Blog
雷峰网
雷峰网
Google Online Security Blog
Google Online Security Blog
阮一峰的网络日志
阮一峰的网络日志
V2EX - 技术
V2EX - 技术
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
Lohrmann on Cybersecurity
The Hacker News
The Hacker News

Python

用 GPT5.6 填了之前的坑:在线的 Python 编辑器和运行终端 - V2EX 为什么这段 cuda 的并行前缀算法不会数据竞争 - V2EX 怎么搞定纯 Python 代码解码 jpg 图片,要求无外部依赖 - V2EX 使用 kkRepo 搭建 Python PyPI 私服 - V2EX Python WebSocket 长连接到底怎么写才稳? - V2EX 小白求推荐人工智能学习的网课 humanize-text 一个开源的 AI 文本拟人化工具集 9.9 元起!跨境卖家疯抢的纯净住宅 IP 辣椒 HTTP,到底有多香? 从会议录音到知识库全自动:我把数百段录音做成了可 RAG 问答的 Wiki(附开源代码) CodexSaver:在不让 Codex 变笨的前提下,让它更便宜。 [开源] 我正在用 Python 复刻经典游戏红色警戒 2 有准确绘制缠论中枢的 Python 代码借鉴么 做了一个面向张量计算的语言,可从 Python 调用,支持显式索引和自动求导 - V2EX 把电脑伪装成电视,用 DLNA 投屏拿到视频号直播流地址 - V2EX 爬虫开发工作中,你们是如何基于 AI 进行提效的? - V2EX 发现 Python 一个有意思的小特性,发现很合适搞成面试题。问了 AI 都不行:),欢迎来挑战~ - V2EX 大型 Python 开源项目都不会对变量进行类型注解? - V2EX 使用 pycharm 开发 Python ,自定义代码风格,并实时提示 - V2EX 创造了 uv 的 Astral 公司被 OpenAI 收购 - V2EX 慎用 PyCharm Remote Development 功能 - V2EX Python 3.15 JIT 的最新进展,已经有大概 5%的性能提升了 - V2EX [开源] 做了个 feishu-docx,把飞书知识库变成 AI 更容易读写和管理的内容源,方便给 Agent 用 - V2EX 开源项目: clawOS 解决 openclaw 文件系统,一键安装 - V2EX 我用免费 A 股数据做了几个工具,欢迎一起开源! - V2EX 分享一个完全免费的中国 A 股数据获取库 - V2EX AI 应用(如 RAG)背景下,如何选择非关系型数据库 - V2EX Python 3.15 将引入一个很方便的语法: Unpacking in Comprehensions - V2EX clawOS 解决 openclaw 文件系统交互过于抽象问题 - V2EX [开源] pyruns - 给 Python 脚本加个 Web UI,管理批量实验任务 - V2EX 我开源了 Python 版本的 pi-mono(OpenClaw 的底层组件) - V2EX 5090 本地部署 Dify+Blender+ComfyUI,求老哥协助打通链路 - V2EX 求解, PyInstaller 为什么在 GithubAction 上打包后体积比在本地大 5 倍(Mac arm 端) - V2EX 使用 Python 一键发推 - V2EX 在 Python 中复现 Race Condition [踩坑] A 股开盘把 Python 搞挂了,怒切 Go 重写行情网关 (附 pprof 分析 + 源码) - V2EX 有个视频网站学习的时候不点暂停或者视频学完,就一直没有任何包,也没有心跳包,也不会更新视频学习进度学时。 - V2EX 基于 Pydantic-Resolve 和 FastAPI-Voyager 的 Clean Architecture 实践 -- 一套面向复杂业务场景的 Python Web 开发方法论 - V2EX 学习能力不是很强 现在需要学 py 有什么好的推荐吗? - V2EX Python 有没有 subprocess 的替代品,被 subprocess 折腾死了. - V2EX 问个汉字处理的问题 - V2EX 有哪些 Python 3.14 Free-Threading 多线程性能分析方案? - V2EX 招募一位 FastAPI 工程师,作为技术伙伴 为什么 Python 的包管理这么难用,比 node 的 npm 难用一万倍,每次进入项目都要手动执行一下 conda activate xxx,难道就没有默认的 Python 项目级别的依赖吗? - V2EX 网上找了个流出的 Python 程序,想过下是否被污染了 都有什么推荐的办法啊? 有感于 Golang,如何用 3~5 个问题,识别 Python 开发者的技术素养? - V2EX fastapi tortoise orm 前端管理框架有哪个好用的 - V2EX 小白求教个循环导入的问题 - V2EX 用 Python 写了个异步 MCP Filesystem,小而简,欢迎拍砖 Neovim 的代码检查、补全问题 - V2EX 请教一个关于电报机器人的问题 - V2EX 帮你选择最快的 pip 镜像,告别安装慢 - V2EX hishel 升级 1.0.0 导致使用 pdm 项目构建失败 - V2EX 开源一个 Python JA3 请求库。可以自定义 JA3 指纹并且内置 1200 多个 JA3 指纹。 Arm64 安装 PyQt5/6,只能选 conda 吗? - V2EX Python 爬虫微框架 web-craft - V2EX 请教各位佬们一个奇怪的后端相关的技术问题 - V2EX 迭代器的实际应用场景是什么? 小白求问,刚接触编程领域有什么速成的方式学习吗,学基础阶段并不太想去系统学习. - V2EX 𝜋thon ( Python 3.14) Python 3.14 已发布 fastapi-router-viz, 可视化你的 API 内依赖关系 yfinance 获取数据总是 too many request 无法获取价格啊 小白求问,应聘 AI 算法工程师这类岗位应该有什么基础知识
哪位朋友帮忙用 mac 测试下我的 Python 脚本 - V2EX
gosky · 2026-07-10 · via Python

把输出贴给我
如果有异常,如果能附带帮忙 fix 更好

import signal
import subprocess
from typing import OrderedDict

APP_NAME = "Hello"


class CalledProcessError(subprocess.CalledProcessError):
    """
    `subprocess.CalledProcessError` does not print `stderr` and `output`.
    """

    def __str__(self):
        if self.returncode and self.returncode < 0:
            try:
                return "Command '%s' died with %r." % (
                    self.cmd,
                    signal.Signals(-self.returncode),
                )
            except ValueError:
                return "Command '%s' died with unknown signal %d." % (
                    self.cmd,
                    -self.returncode,
                )
        else:
            return (
                "Command '%s' returned non-zero exit status %d. stderr: '%s'. output: '%s'"
                % (self.cmd, self.returncode, self.stderr.strip(), self.output.strip())
            )


class DecryptError(Exception): ...


class DarwinCryptex:
    scheme = "security"

    def encrypt(self, attrs: OrderedDict[str, str], plaintext: str) -> str:
        account = "-".join([f"{k}:{v}" for k, v in attrs.items()])
        cmd = [
            "security",
            "add-generic-password",
            "-a",
            account,
            "-s",
            APP_NAME,
            "-w",
            plaintext,
            "-U",
        ]
        r = subprocess.run(
            cmd,
            capture_output=True,
            encoding="utf-8",
            text=True,
            timeout=5,
        )
        if r.returncode != 0:
            raise CalledProcessError(
                r.returncode, cmd, output=r.stdout, stderr=r.stderr
            )
        return "******"

    def decrypt(self, attrs: OrderedDict[str, str], ciphertext: str) -> str:
        account = "-".join([f"{k}:{v}" for k, v in attrs.items()])
        cmd = [
            "security",
            "find-generic-password",
            "-a",
            account,
            "-s",
            APP_NAME,
            "-w",
        ]
        r = subprocess.run(
            cmd,
            capture_output=True,
            encoding="utf-8",
            text=True,
            timeout=5,
        )
        if r.returncode == 0:
            return r.stdout.strip()
        elif r.returncode == 44:
            raise DecryptError()
        else:
            raise CalledProcessError(
                r.returncode, cmd, output=r.stdout, stderr=r.stderr
            )

    def clean(self, attrs: OrderedDict[str, str]):
        account = "-".join([f"{k}:{v}" for k, v in attrs.items()])
        cmd = ["security", "delete-generic-password", "-a", account, "-s", APP_NAME]
        r = subprocess.run(
            cmd, capture_output=True, encoding="utf-8", text=True, timeout=5
        )
        if r.returncode not in (0, 44):
            raise CalledProcessError(
                r.returncode, cmd, output=r.stdout, stderr=r.stderr
            )


cryptex = DarwinCryptex()
attrs: OrderedDict[str, str] = OrderedDict(
    [
        ("app", "test"),
        ("section", "hello"),
        ("key", "你好"),
    ]
)
plaintext = "Hello world! 你好,世界!"

try:
    ciphertext = cryptex.encrypt(attrs, plaintext)
    decrypted = cryptex.decrypt(attrs, ciphertext)
    assert decrypted == plaintext

    mismatch_attrs = attrs.copy()
    mismatch_attrs["needless"] = "有毒"
    try:
        cryptex.decrypt(mismatch_attrs, ciphertext)
    except DecryptError:
        pass
    else:
        raise AssertionError("Expected DecryptError")
finally:
    cryptex.clean(attrs)