GithubHelp home page GithubHelp logo

mohammedazmy / pixel Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 144 KB

Another python XML library which uses SAX and your custom defined entities

License: GNU General Public License v3.0

Python 100.00%

pixel's Introduction

Pixel

Pixel is another XML framework used to integrate XML into your projects
it drops the need to load your XML structure into DOM objects and then 
populate your real entities.

The framework was designed with ease of use in mind so you can get started
as fast as possible. It's also designed to validate the loaded data to 
match your defined schema (as defined in your structures) using 
attribute, element and/or collection 

*NOTE: Please refer to the main.py file for more up to date example.

Usually your structure will look like something like that:


from pixel.xmlelement import XmlElement, element, collection, attribute
import pixel.loader

class Header(XmlElement):
    key = attribute(str)
    value = attribute(str)
    
class Body(XmlElement):
    title = element(str, True) #optional element
    text = element(str)
    
class Message(XmlElement):
    source = attribute(str)
    destination = attribute(str)
    id = attribute(int, True) #optional attribute.
    headers = collection(Header)
    body = element(Body)
    
    def send(self):
        print "Sendig message to %s" % self.destination

def main():
    message = Message()
    message.source = '[email protected]'
    message.destination = '[email protected]'
    message.id = 100
    message.body.text = 'Message body goes here'
    message.body.title = 'Message title'
    
    header1 = Header()
    header1.key = 'server-ip'
    header1.value = '127.0.0.1'
    
    header2 = Header()
    header2.key = 'priority'
    header2.value = 'HIGH'
    
    message.headers.append(header1)
    message.headers.append(header2)
    
    xml = str(message)
    print "--- The orignial message object xml ---"
    print xml
    #load message from xml
    
    loader = pixel.loader.PixelLoader(Message)
    loaded_message = loader.load(xml)
    
    print "--- The loaded message object xml ---"
    print str(loaded_message)
    
    print "--- doing some actions ---"
    loaded_message.send()
    

if __name__ == "__main__":
    main()

pixel's People

Stargazers

Muhamad Azmy avatar Jo De Boeck avatar

Watchers

Jo De Boeck avatar Muhamad Azmy avatar

Forkers

nasingfaund

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.