X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=pyderasn.py;h=7ca25aab5779972c785a10c46bb4da9df8933ed1;hb=44741873733949a977e18c0ae475fee04fa6e643;hp=516715a7f2e419a6d1070c03eee7f2c07bb1b895;hpb=44e10c60d857ea5e631927ac4b23365cc3b80698;p=pyderasn.git diff --git a/pyderasn.py b/pyderasn.py index 516715a..7ca25aa 100755 --- a/pyderasn.py +++ b/pyderasn.py @@ -355,6 +355,11 @@ Let's parse that output, human:: (and its derivatives), ``SET``, ``SET OF``, ``UTCTime``, ``GeneralizedTime`` could be BERed. +Also it could be helpful to add quick ASN.1 pprinting command in your +pdb's configuration file:: + + alias pp1 import pyderasn ;; print(pyderasn.pprint(%1, oid_maps=(locals().get("OID_STR_TO_NAME", {}),))) + .. _definedby: DEFINED BY @@ -1170,8 +1175,6 @@ from datetime import datetime from datetime import timedelta from io import BytesIO from math import ceil -from mmap import mmap -from mmap import PROT_READ from operator import attrgetter from string import ascii_letters from string import digits @@ -1201,7 +1204,7 @@ except ImportError: # pragma: no cover def colored(what, *args, **kwargs): return what -__version__ = "8.0" +__version__ = "8.1" __all__ = ( "agg_octet_string", @@ -1292,8 +1295,13 @@ def file_mmaped(fd): :param fd: file object :returns: memoryview over read-only mmap-ing of the whole file + + .. warning:: + + It is known to work under neither Python 2.x nor Windows. """ - return memoryview(mmap(fd.fileno(), 0, prot=PROT_READ)) + import mmap + return memoryview(mmap.mmap(fd.fileno(), length=0, prot=mmap.PROT_READ)) def pureint(value): @@ -7897,12 +7905,12 @@ def main(): # pragma: no cover help="Path to BER/CER/DER file you want to decode", ) args = parser.parse_args() - if PY2: + try: + raw = file_mmaped(args.RAWFile)[args.skip:] + except: args.RAWFile.seek(args.skip) raw = memoryview(args.RAWFile.read()) args.RAWFile.close() - else: - raw = file_mmaped(args.RAWFile)[args.skip:] oid_maps = ( [obj_by_path(_path) for _path in (args.oids or "").split(",")] if args.oids else ()