Skip to content

Instantly share code, notes, and snippets.

@jdowner
Last active October 6, 2016 13:06
Show Gist options
  • Save jdowner/dfdac28f4baaea030fb9f29d854be5db to your computer and use it in GitHub Desktop.
Save jdowner/dfdac28f4baaea030fb9f29d854be5db to your computer and use it in GitHub Desktop.
struct augmentation
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
installed-files.txt
bin/gistc
tests/gnupg/*
The MIT License (MIT)
Copyright (c) 2015 Joshua Downer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
This script is used to augment the information in the struct module.
The intended usage is,
import struct
import struct_augment
This will augment the struct module with additional information in the module
where is it imported.
"""
import struct
setattr(struct, "characters", {'x', 'c', 'b', 'B', '?', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd', 's', 'p', 'P'})
setattr(struct, "SIZE_PAD_BYTE" , struct.calcsize("x"))
setattr(struct, "SIZE_CHAR" , struct.calcsize("c"))
setattr(struct, "SIZE_SIGNED_CHAR" , struct.calcsize("b"))
setattr(struct, "SIZE_UNSIGNED_CHAR" , struct.calcsize("B"))
setattr(struct, "SIZE_BOOL" , struct.calcsize("?"))
setattr(struct, "SIZE_SHORT" , struct.calcsize("h"))
setattr(struct, "SIZE_UNSIGNED_SHORT" , struct.calcsize("H"))
setattr(struct, "SIZE_INT" , struct.calcsize("i"))
setattr(struct, "SIZE_UNSIGNED_INT" , struct.calcsize("I"))
setattr(struct, "SIZE_LONG" , struct.calcsize("l"))
setattr(struct, "SIZE_UNSIGNED_LONG" , struct.calcsize("L"))
setattr(struct, "SIZE_LONG_LONG" , struct.calcsize("q"))
setattr(struct, "SIZE_UNSIGNED_LONG_LONG", struct.calcsize("Q"))
setattr(struct, "SIZE_FLOAT" , struct.calcsize("f"))
setattr(struct, "SIZE_DOUBLE" , struct.calcsize("d"))
setattr(struct, "SIZE_VOID_POINTER" , struct.calcsize("P"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment