{ "info": { "author": "Simon Black", "author_email": "simon.black.bug@gmail.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "=======\nEStruct\n=======\n\nEStruct provides an extended packaging/unpackaging library that that provided by the standard library's Struct module.\nIt provides packaging of conditional elements and arrays. The library was originally written by the author to simplify \npacking and unpacking binary data within mpeg4 file.\n\nTypical usage::\n\n\t#!/usr/bin/env python\n\t\n\tfrom estruct.estruct import EStruct\n\timport sys\n\tfrom datetime import date\n\t\n\tpackager = EStruct(\"Student\", \"Student.Name Student.Address Student.DOB\", \"![50s50sQ]\")\n\trecords=[]\n\twith open(sys.argv[1],\"rb\") as f:\n\t\trecords=packager.unpack(f.read())\n \t\n\tfor r in records:\n\t\tprint r.Student.Name, r.Student.Address, date.fromordinal(r.Student.DOB)\n\t\t\nEStruct is also hosted on GitHub at https://github.com/simblack/EStruct\n\n \t\t\nInstallation\n============\n::\n\n\tpip install EStruct\n\n\nEStruct object\n==============\n\nThe EStruct object __init__ method takes three parameters, the unpacked class name, the fields within the class and the packaging format.\n\n*EStruct.__init__(self, name, fields_string, format_string)*\n\nname\n----\n\nThis is simply the name of the object that is created when unpacking values.\n\nfields_string\n-------------\n\nThe fields string is a description that contains fields and sub fields.\nThe string needs to be a space separated list of fields. Nested structures can be created by using a dot notation '.', i.e.\nobject.field or object.sub_object.field.\n \nExample::\n\n 'f1 f2 f3.a1 f3.a2 f4 f5.a1.b1 f5.a1.b2 f5.a2.b1 f5.a2.b2'\n This would create the object with fields:\n f1,f2,f3,f4,f5\n f3 is of a type of an object with fields:\n a1, a2\n f5 is of a type of an object with fields:\n a1, a2 with both fields of an object of type with fields b1 and b2 \n\nformat_string\n-------------\n::\n\n format= byteorder + format_string\n byte_order= '@'|'='|'<'|'>'|'!'\n @ native byte-order native size native alignment\n = native byte-order standard size no alignment\n < little endian standard size no alignment\n > big endian standard size no alignment\n ! network standard size no alignment\n \n format_string= conditonal_format | array_format | normal_format | empty_format\n \n emptry_format=\n \n conditionl_format= '(' + condition + '?' + true_format + ':' + false_format + ')' \n condition= [python evaluation]\n true_format= format_string\n false_format= format_string\n An empty format_string implies that no field is required for packinging.\n \n array_format= count[format_string]\n \n count= empty_count | constant_count | field_count\n empty_count=\n constant_count= (0..9)*\n field_count= '{' + [field_name] + '}'\n \nThe *\\[field name\\]* is any field defined prior to this packing element.\nThe *\\[python evaluation\\]* is a valid python statement equating to a True or False result. \nAny field name prior to this packing element may be used. Also for evaulation of array's the index value *INDEX* may be used\nto specify the current index.\n \nExamples\n~~~~~~~~\nNetwork endian, 32 bit integers followed by a 64 but value if *f1==1* else another 32 bit integer::\n\n\t!II(f1==1?Q|I)\n\nNetwork endian, 32 bit integers followed by an array with the number of elements as specified in the field\n*f1*. The array elements are a 32 bit integer followed by a number of characters, where that number is set in \nthe field *f2\\[INDEX\\].a1*, the index is the current iteration of the outer array.::\n\n\t!I{f1}[I{f2[INDEX].a1}[c]]\n\n\t\nUnpacking\n=========\n\nThe unpack method is used to unpack binary data into an object\n \n*EStruct.unpack(self, data, **kargs)*\n\nKeyword arguments may also be passed if they are required for evaluations.\nThe method returns an object as described by the fields string of the constructor.\n\n::\n\n\tstruct=EStruct('Test','f1 f2','!I{f1}[I]')\n\t\n\tdata=[0,0,0,3,0,0,0,2,0,0,0,1,0,0,0,0]\n\tdata_str=\"\".join([chr(x) for x in data])\n\tobj=struct.unpack(data_str)\n\t\n\tprint obj.f1, obj.f2\n\t\t\n\nPacking\n=======\n\nThe pack method is used to pack values into a binary string\n\n*EStruct.pack(self, *args, **kargs)*\n\nThe correct number of arguments must be passed for packing, according to the packing format.\nKeyword arguments may also be passed if they are required for evaluations.\nThe method returns the packed binary string.\n\n::\n\n\tstruct=EStruct('Test','f1 f2','!I{f1}[I]')\n\tpacked_result=self.struct.pack(3,[2,1,0])\n\t\n\tprint packed_result.encode(\"hex\")", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/EStruct/", "keywords": null, "license": "LICENSE.txt", "maintainer": null, "maintainer_email": null, "name": "EStruct", "package_url": "https://pypi.org/project/EStruct/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/EStruct/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://pypi.python.org/pypi/EStruct/" }, "release_url": "https://pypi.org/project/EStruct/0.1.3/", "requires_dist": null, "requires_python": null, "summary": "Python package to extend the capabilities of the standard library's Struct package.", "version": "0.1.3" }, "last_serial": 883181, "releases": { "0.1.2": [ { "comment_text": "", "digests": { "md5": "b451863e4046033954141beb3212257a", "sha256": "56248949799210a62e7af21446bae53f690cb986c3bdaef0651897c1a9f8c60a" }, "downloads": -1, "filename": "EStruct-0.1.2.tar.gz", "has_sig": false, "md5_digest": "b451863e4046033954141beb3212257a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11575, "upload_time": "2013-10-04T11:20:42", "url": "https://files.pythonhosted.org/packages/6b/c4/e9039a8c320ffc3beeb03d569a7ebdd62db28ce3eb2316f4465403d9dd52/EStruct-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "e0f1247c02259b038b199251e376bebe", "sha256": "57c896307d1b8a200c43971a4aecc240df74157d8c29c95311728c5c720d110f" }, "downloads": -1, "filename": "EStruct-0.1.3.tar.gz", "has_sig": false, "md5_digest": "e0f1247c02259b038b199251e376bebe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13655, "upload_time": "2013-10-07T14:50:52", "url": "https://files.pythonhosted.org/packages/14/1f/9a84112a2f7a3a1447d4b544770ae5cfb7e38329301b256affda7c4152a7/EStruct-0.1.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e0f1247c02259b038b199251e376bebe", "sha256": "57c896307d1b8a200c43971a4aecc240df74157d8c29c95311728c5c720d110f" }, "downloads": -1, "filename": "EStruct-0.1.3.tar.gz", "has_sig": false, "md5_digest": "e0f1247c02259b038b199251e376bebe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13655, "upload_time": "2013-10-07T14:50:52", "url": "https://files.pythonhosted.org/packages/14/1f/9a84112a2f7a3a1447d4b544770ae5cfb7e38329301b256affda7c4152a7/EStruct-0.1.3.tar.gz" } ] }