Archive for July, 2007

20 Modeling Feed Data Amodel is a way (Web site translator)

Tuesday, July 31st, 2007

20 Modeling Feed Data Amodel is a way of looking at information a couple of steps removed from the details of specific pieces of data. The aim of creating a model is to enable you to organize data in a logical fashion. Once you have a model for your data and you have a means of managing the data consistently, everything should slot into place. Your software will somehow reflect the shape of the model, which in turn reflects the kind of material that your application is designed to handle. The model itself may just be specified in regular human language what s found in most specifications. Alternatively the model can have a formal definition that enables it to be used alongside information expressed in other data languages. Certain modeling techniques can be used to automatically generate pieces of code for processing the data or storing it in a database. The specifications for Atom, RSS 1.0, and RSS 2.0 all imply models of one form or another into which the data fits. By acknowledging this and addressing the model up front, your software is likely to benefit from architectural consistency and there are less likely to be unwanted surprises further down the road. This chapter uses a loose definition of model that also refers to the syntax and grammar, and describes the following: . A conceptual model of a feed and its entries . What that model looks like in XML . How to model feeds in object-oriented languages . How to map the model to a relational database . What the model looks like in RDF Model or Syntax? What the model actually addresses is a whole other story. It may be a high-level object view, perhaps suitable for direct translation into a programming language. At another level it may be an abstraction of the meaning of the data in terms of formal logic. Another viewpoint that could also be (loosely) described as a model is how strings should be structured within a message, in other words the syntax and grammar.
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

def compress(self, data): zipBuffer = StringIO.StringIO() zipFile =

Monday, July 30th, 2007

def compress(self, data): zipBuffer = StringIO.StringIO() zipFile = gzip.GzipFile(mode = wb , fileobj = zipBuffer, compresslevel = 6) zipFile.write(data) zipFile.close() zipped = zipBuffer.getvalue() zipBuffer.close() self.content_length = len(zipped) return zipped Note that you will need to import the StringIO and gzip packages to use this method. It is trivial to add a call to this method on the data being served, but you also have to set up the code to check whether the client accepts gzipped data, and also return appropriate HTTP response codes not so trivial. You need to add code to look for a header in the HTTP request that will look something like this: Accept-Encoding: gzip Before compressing and returning the data, the server should add a header that looks like this: Content-Encoding: gzip Don t be afraid to insert lots of print statements to see what s happening in both the client and server code. 235 Systematic Overview
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Web design templates - Architectural Approaches The chapters that follow pick up

Monday, July 30th, 2007

Architectural Approaches The chapters that follow pick up on various aspects of RSS and Atom programming mentioned in the earlier sections of the book and those outlined in this chapter. Before moving on, be aware that there is a wide spectrum of approaches to development. Approaches range from the use of formal methodologies that demand significant up-front design, to more agile approaches that focus on continuous integration of new code into existing systems. This spectrum is reflected not only in the applications produced, but also to some extent in the design of Web formats and protocols. The Web is remarkably flexible in the way it can successfully support anything from the most rigid formal design to the most ill thought out five-minute hack. Most syndication development falls within these two extremes. In practice it s possible to apply virtually any developmental approach to any aspect of RSS and Atom programming. What you will see is plenty of architecture by implication, where the code comes before the design, although a lot of the time any successes are due in part to the implied architecture corresponding directly with existing solid architecture. Without some sense of an architecture, there can be hidden risks. On the other hand, you aren t likely to see much of the architecture astronautics found in some Web services development, nor are you likely to see many back-of-envelope doodles being adopted as specifications (at least until they ve had some testing in the field). Because it builds more on existing languages you will tend to see more big picture architecture around RSS 1.0 and related specifications, and more throw it against the wall and see what sticks around RSS 2.0. Atom has steered a course somewhere in between. Whatever your own personal preferences, you should at least familiarize yourself with the best-practice recommendations in Architecture of the World Wide Web (www.w3.org/TR/webarch/). Summary In this chapter you learned… . How most parts of syndication systems fall into one of four categories. . The general nature of subsystems in each of those categories. . The significance of state, resources, and representations on the Web. . The basics of HTTP client-server communication. . How syndication systems use a polling protocol. In the chapters that follow you will see a lot more of the internals of the different parts of syndication systems, beginning with a high-level view of the data modeling needed for working with all kinds of feed data. Exercise 1. The first example of HTTP server code in this chapter was InflexibleServer.py, which served up the same string whatever page was requested. You also saw ZippyClient.py, an HTTP client that knew how to manage data from a server that supported compression. Your task is to create a modified version of InflexibleServer.py to gzip its data before serving it, so ZippyClient.py can talk to it. To get you started, here is a method that will take a string and gzip it: 234 Chapter 19
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

This is almost identical to the way this (Web server type)

Saturday, July 28th, 2007

This is almost identical to the way this entry would appear in a feed. Rather than identifying the particular procedures within an application to which the individual data values should be passed, the RESTful approach is to pass the relevant data to the server using an HTTP method applied to specific URI. To create a new blog entry the message above could be passed to a server-side blogging tool s edit URI using the HTTP POST method. Server Consumer The job of a Server Consumer in this categorization depends a lot on the kind of setup. A straightforward Web-based blogging system is likely to use a simple form to pass data from the author to the server software for creating a new post or editing an existing one. In such a scenario, there isn t really a clean separation between Client Producer and Server Consumer. However, the tool that creates the content and the server-side system that consumes it can be separate. From an RSS point of view, a typical kind of Server Consumer would be the piece of software that receives blog post data (probably over XML-RPC) and passes it back to backend storage /or to the components of the system, which then look after generation of the blog pages. As it happens, many of the popular Web-based blogging systems support creation and editing of posts both by direct HTML form interfaces as well as calls from remote XML-RPC clients. As well as the usual author-driven route to content creation, material can come from other sources. Strictly speaking these should perhaps be listed here as either Client or Server Producer, but as producers they aren t really systems in their own right. More to the point, it s the developer of the Server Consumer that deals with data from these sources. Weblog Comments Most content-management tools such as blogging systems support reader comments. In principle, the system requirements for this facility are identical to those needed for handling material from the original author. In practice, things can get more complicated when dealing with material submitted by third parties. An authentication system might be necessary, and if anonymous posters are allowed, there is a likelihood of receiving comments from automated systems designed for the purpose, such as comment spam. Trackback This technique is one of the more interesting innovations to come from the Weblogging world. Using trackback, if you refer to a post on someone else s blog on your own blog, and then a reference to your remarks can appear on that other person s blog. There is a standard way of implementing trackback based on the original specification, which was designed for the Movable Type blog authoring tool. Systems that support trackback assign every published item a particular URI to which a trackback ping can be posted. Data posted to that URI in the correct format shows up alongside the comments made locally about the item. The complication is that when you include a link in your blog post, your system has the URI of the entry itself, not the remote entry s trackback URI. However, systems that support trackback usually include a block of hidden markup as part of the entry, which contains machine-readable details of the entry, including its trackback URI. So when you link to someone s post, your blogging system visits that link, retrieves the trackback URI, and then posts an extract of your remarks to the other person s blog. We discuss trackback, and several other inter-system protocols, in greater depth in Chapter 31. 233 Systematic Overview
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

title My Interesting Post The code does reuse

Saturday, July 28th, 2007

title My Interesting Post The code does reuse the RSS element name 2004-11-05T20:30:00Z

Light your fireworks!

232 Chapter 19
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

feeds. All the same characteristics of content and (Web host)

Friday, July 27th, 2007

feeds. All the same characteristics of content and metadata that are handled by the rest of a syndication system are produced by the Client Producer. But in current implementations at least, the Client Producer is the odd one out of these four categories. It may not involve any of the syndication format standards. The Client Producer part of syndication systems may in effect be integrated with the backend, server-side of the system, with content being passed from an HTML form into the database using proprietary techniques. If the Client Producer is separate from the rest of the system, chances are it will use the Blogger API (unless it s a very recent piece of software). ABlogger API is a specification that uses the XML-RPC (Remote Procedure Call) protocol, introduced earlier in the chapter. More recent software might support the Atom API, which is based on a fundamentally different approach to Web communications. There is a range of techniques that can be used when it comes to a piece of software either advertising what protocol(s) it supports or trying to discover what is supported by a service. In particular, the term introspection has been used for the advertising within Atom, and autodiscovery for the trick of pointing to service endpoint addresses. Although syndication is arguably the most widely deployed Web service, aside from autodiscovery of feeds from HTML pages there is no standard cross-system approach for discovering what is available. The following sections should give you an overview of the protocol side of Client Producer subsystems, which are usually authoring applications. In Chapter 26, you will see some code that uses these protocols to post to weblogs. XML-RPC This protocol follows one traditional approach to client-server programming, in which program procedure calls are executed on a remote system rather than locally. XML is used to wrap the calls in a form that can be delivered over HTTP. The receiver of an XML-RPC message will unwrap the XML envelope to discover what parameters should be delivered to what programming procedures. XML-RPC is a predecessor of the SOAP protocol, which now plays a key role in Web services. Its adoption in the world of syndication began when Pyra Labs, the company that used to be behind the Blogger hosting service, released the Blogger API (Application Programming Interface) in 2001 as a specification for communicating between blogging clients (that is, Client Producers) and their server-side offerings. Although it was described as experimental and alpha, developers quickly seized it to fill a gap in requirements. Unfortunately it didn t fill the gap too well (for example, entry titles were missing), and the Blogger spec was followed a few months later by the MetaWeblog API from UserLand, which added more structure to the messages echoing the components of an RSS item in procedure calls. Implementations using the Blogger and MetaWeblog APIs generally use ready-made library code to enable the construction of the message at the producer and the interpretation of the message at the consumer. This is good news for developers, because the actual data sent in this fashion can be incredibly complex due to the way the data is built. For example, to specify the title of a new post, this has to be described in terms of a procedure call, giving its data type and value. These pieces of data will be wrapped in a struct structure corresponding to a parameter in the method call. Acomplete MetaWeblog API message is too long to include here, but the following listing contains the structural elements relating to the title: metaWeblog.newPost
231 Systematic Overview
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Next a library function is used to create (Web hosting packages)

Friday, July 27th, 2007

Next a library function is used to create an opener object, which is then used to open the communication channel: opener = urllib2.build_opener() message = opener.open(request) When opening the channel, the opener has passed the request to the server, and the message object contains the response headers and a pointer to the body of any data. The headers are checked to determine whether the Content-Encoding header has a value of gzip , and if it is an appropriate message is sent to the console: if message.headers.get( Content-encoding ) == gzip : print ZIPPED! The zipped content is then read from the message into a buffer, which is then used to construct a file-like object on which the compression classes can operate. There are limits to the kinds of objects the compression code can work on, which is why the StringIO class is needed. It s not very elegant, but it works. A GzipFile object is created, and the fileObject reads through it, as you can see in the following lines: zipped = message.read() fileObject = StringIO.StringIO(zipped) data = gzip.GzipFile(fileobj=fileObject).read() The data that is read from the GzipFile object is decompressed back into its original form. However we are still in a block that runs only if the content encoding header says the data is zipped. If it isn t, the data can be read directly from the source. Finally the decompressed or as-delivered data is then printed to the console: else: data = message.read() print data The Trade Off In most circumstances the benefits of delivering or receiving compressed feed data far outweigh the costs. However, you should keep in mind that there are costs, not only for the additional code complexity but also for the processing required. For limited devices such as mobile phones it may make sense to avoid the computational load and always collect the uncompressed version of feeds. Client Producer: Blogging APIs The Client Producer part of a syndication system is the part the user employs to create the raw material for syndication. In other words, it s the authoring tool. Usually these are quite separate from the parts of the system that do the actual feed syndication. What the Client Producer produces is the content and metadata that corresponds to a weblog post, or perhaps to modify or delete an existing post. The data from the client is often sent back to the server and stored in a database, and only later is it converted into the RSS or Atom format. The fact that the authoring part of a system may be a separate component doesn t change the fact that the data it is dealing with is usually exactly the same kind of content and metadata that is published in 230 Chapter 19
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

Figure 19-6 The source code for the client (Linux web host)

Thursday, July 26th, 2007

Figure 19-6 The source code for the client used here is relatively short and simple thanks again to the libraries that come with Python. The httplib and urllib2 libraries are used to look after the communication side of things, with the StringIO and gzip libraries providing the classes needed to carry out the decompression of the data stream. These are all declared in the imports at the start of the source: import httplib import urllib2 import StringIO import gzip Of course for the system to work, there will have to be compression server-side. An address that s known to support gzip and serve fairly big feed files is placed in the string URI: URI = http://thorne.id.au/feeds Although it s possible to use print statements to show what data is being passed around, HTTPConnection has a convenient debug option, which will send messages to the console: httplib.HTTPConnection.debuglevel = 1 Before the transaction can be initiated, the client has to prepare a request to pass to the server. The urllib2 library has a class Request which makes this fairly easy. Here a Request object is created, and then the value of its Accept-Encoding header is set to gzip : request = urllib2.Request(URI) request.add_header( Accept-Encoding , gzip ) GET/feeds HTTP/1.0 Client Accept-encoding: gzip Server Request HTTP/1.0 200 OK Content-encoding: gzip Response Data gunzip gzip Feed Feed 229 Systematic Overview
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Web design conference - D:rss-book19code>python ZippyClient.py connect: (thorne.id.au, 80) send: GET /feeds

Thursday, July 26th, 2007

D:rss-book19code>python ZippyClient.py connect: (thorne.id.au, 80) send: GET /feeds HTTP/1.0rnHost: thorne.id.aurnUser-agent: Python-urllib/2. 1rnAccept-encoding: gziprnrn reply: HTTP/1.0 200 OKrn header: Date: Thu, 24 Jun 2004 13:40:51 GMT header: Content-length: 61411 header: Content-encoding: gzip header: Content-type: text/html header: Server: TwistedWeb/1.2.0 ZIPPED! Note the values for Content-length (61411) and Content-encoding (gzip) returned by the server. 5. Now modify the source code again, this time to comment out this line by adding a # at the start: # request.add_header( Accept-Encoding , gzip ) 6. Again open a command window and type: python ZippyClient.py The result this time should be slightly different, something like this: D:rss-book19code>python ZippyClient.py connect: (thorne.id.au, 80) send: GET /feeds HTTP/1.0rnHost: thorne.id.aurnUser-agent: Python-urllib/2. 1rnrn reply: HTTP/1.0 200 OKrn header: Date: Thu, 24 Jun 2004 13:46:08 GMT header: Content-length: 204733 header: Content-type: text/html header: Server: TwistedWeb/1.2.0 Note the lack of gzip, and the considerably larger value of Content-length, 204733 bytes, which shows the gzip compression would save around three-fourths of the original bandwidth. How It Works The kind of data a client is prepared to accept is passed to the server in the header part of its request. When the server is told that the client can accept gzip compressed data, it may supply the material zipped. Note that this is all entirely optional. If the server does compress the feed data then the client will need to know so it can uncompress it. In this case the response header will have a value gzip in its Content-Encoding field. Figure 19-6 shows relevant parts of client-server HTTP dialog box where gzip is supported. Most Web servers offer very good support for compression, and it s pretty straightforward to support it on the client side too. 228 Chapter 19
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Try It (Web hosting uk) Out HTTP Client with gzip Compression

Wednesday, July 25th, 2007

Try It Out HTTP Client with gzip Compression The following listing is a little HTTP client that s aware of gzip compression: import httplib import urllib2 import StringIO import gzip URI = http://thorne.id.au/feeds httplib.HTTPConnection.debuglevel = 1 request = urllib2.Request(URI) request.add_header( Accept-Encoding , gzip ) opener = urllib2.build_opener() message = opener.open(request) print message.headers if message.headers.get( Content-encoding ) == gzip : print ZIPPED! zipped = message.read() fileObject = StringIO.StringIO(zipped) data = gzip.GzipFile(fileobj=fileObject).read() else: data = message.read() print data 1. Enter the code into a text editor, and save the file as ZippyClient.py. 2. Open a command window in the same directory as you saved ZippyClient.py and type the following: python ZippyClient.py A header message should appear, closely followed by a lot of text content. 3. Modify the last line of the source code to read: # print data 4. Again, open a command window in the same directory as you saved ZippyClient.py and type: python ZippyClient.py Now that the printing of the data has been commented out, the header should be easier to read. It should look something like this: 227 Systematic Overview
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.