如何确定导入的来源?

时间:2013-10-21 03:49:07

标签: python class import

请原谅我的无知。我没有很好地阅读Python,我根本无法写它。

我正在尝试审核CVE-2013-1445的python项目。我相信找到了一个可能需要注意的源文件(以及其他改进机会)。该文件为util.py,其中包含以下行:

import base64

from Crypto.Hash import HMAC
from Crypto import Random
...

当我查看Python crypto docs时,我没有看到提及Random课程。仅限hashlibhmac

The modules described in this chapter implement various algorithms of a
cryptographic nature. They are available at the discretion of the
installation. On Unix systems, the crypt module may also be available.
Here’s an overview:

    15.1. hashlib — Secure hashes and message digests
    15.2. hmac — Keyed-Hashing for Message Authentication

...

Random究竟来自哪里?是原生还是第三方?

或者我的问题应该是Crypto来自哪里?如果Crypto是其第三方,我如何确定第三方库和类的包含方式/位置(与本机库和类相比)?

为了完整起见,我试图理解Python的Scopes和Namespaces,但这对我来说毫无意义(正如这个问题可能证明的那样)。例如,CryptoRandom没有明显的范围或命名空间(RandomCrypto之外)。

提前致谢。

2 个答案:

答案 0 :(得分:2)

您在询问文件的存储位置吗?模块具有名为__file__的属性,该属性列出了模块在磁盘上的路径。

>>> from Crypto import Random
>>> Random.__file__
'/home/ubuntu/.env/local/lib/python2.7/site-packages/Crypto/Random/__init__.pyc'

(在我的情况下,PyCrypto安装在我家的dir中的virtualenv)

答案 1 :(得分:2)

Crypto不是任何标准Python发行版的一部分。这就是为什么Python文档没有提到它;-)你可以在这里下载源代码:

https://www.dlitz.net/software/pycrypto/