gpt4 book ai didi

java - jython 无法列出错误

转载 作者:行者123 更新时间:2023-11-29 05:58:32 24 4
gpt4 key购买 nike

我正在尝试使用 Jython(在 mac osx lion 上)将 python 类转换为 Java 字节码

./jython -m compileall /Users/owengerig/Downloads/Code\ Downloads/cryptPYTHON.py

但是得到这个错误,它没有给出任何错误的迹象

Listing /Users/owengerig/Downloads/Code Downloads/cryptPYTHON.py ... Can't list /Users/owengerig/Downloads/Code Downloads/cryptPYTHON.py

我的 python 类是如何设置的(used this post as example):

from Crypto.Cipher import AES
import base64
import os

class Crypticle(CryptInterface):
"""Authenticated encryption class

* @param string $key base64-encoded encryption key
* @param integer $key_len length of raw key in bits

Encryption algorithm: AES-CBC
Signing algorithm: HMAC-SHA256
"""

AES_BLOCK_SIZE = 16

@JAVA
def __init__(self, key_string, key_size=192):
assert not key_size % 8
self.key = self.extract_key(key_string, key_size)
self.key_size = key_size

@classmethod
def generate_key_string(cls, key_size=192):
key = os.urandom(key_size / 8)
return base64.urlsafe_b64encode(str(key))

@classmethod
def extract_key(cls, key_string, key_size):
key = base64.urlsafe_b64decode(str(key_string))
assert len(key) == key_size / 8, "invalid key"
return key

@JAVA(String, String)
def encrypt(self, data):
"""encrypt data with AES-CBC"""
aes_key = self.key
pad = self.AES_BLOCK_SIZE - len(data) % self.AES_BLOCK_SIZE
data = data + pad * chr(pad)
iv_bytes = os.urandom(self.AES_BLOCK_SIZE)
cypher = AES.new(aes_key, AES.MODE_CBC, iv_bytes)
data = iv_bytes + cypher.encrypt(data)
data_str = base64.urlsafe_b64encode(str(data))
return data_str

@JAVA(String, String)
def decrypt(self, data_str):
"""decrypt data with AES-CBC"""
aes_key = self.key
data = base64.urlsafe_b64decode(data_str)
iv_bytes = data[:self.AES_BLOCK_SIZE]
data = data[self.AES_BLOCK_SIZE:]
cypher = AES.new(aes_key, AES.MODE_CBC, iv_bytes)
data = cypher.decrypt(data)
return data[:-ord(data[-1])]

也尝试了这段代码(根据下面的评论)但是出现了同样的错误:

class Employee(Object):
def __init__(self):
self.first = "Josh"
self.last = "Juneau"
self.id = "myempid"

def getEmployeeFirst(self):
return self.first

def getEmployeeLast(self):
return self.last

def getEmployeeId(self):
return self.id

最佳答案

-m compileall 采用目录,而不是文件名。所以你需要执行以下命令:

./jython -m compileall /Users/owengerig/Downloads/Code\ Downloads/

详细解释

如果打开jythondirectory/Lib/compileall.py:

try:
names = os.listdir(dir)
except os.error:
print "Can't list", dir
names = []

os.listdir() 如果没有将目录作为参数传递,则会抛出错误。由于这是用于编译命令行参数的函数,并且 main() 函数不检查参数是否为目录,因此这将失败。

        for dir in args:
if not compile_dir(dir, maxlevels, ddir,
force, rx, quiet):
success = 0

/详细解释

关于java - jython 无法列出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11090340/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com