PageRenderTime 25ms CodeModel.GetById 13ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/gdata/codesearch/__init__.py

http://radioappz.googlecode.com/
Python | 136 lines | 73 code | 28 blank | 35 comment | 7 complexity | 87055f8a58d4dbfe5c8c71a034505dc4 MD5 | raw file
  1# -*- coding: utf-8 -*-
  2#
  3# Copyright (c) 2007 Benoit Chesneau <benoitc@metavers.net>
  4#
  5# Permission to use, copy, modify, and distribute this software for any
  6# purpose with or without fee is hereby granted, provided that the above
  7# copyright notice and this permission notice appear in all copies.
  8#
  9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 10# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 11# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 12# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 13# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 14# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 16
 17
 18"""Contains extensions to Atom objects used by Google Codesearch"""
 19
 20__author__ = 'Benoit Chesneau'
 21
 22
 23import atom
 24import gdata
 25
 26
 27CODESEARCH_NAMESPACE='http://schemas.google.com/codesearch/2006'
 28CODESEARCH_TEMPLATE='{http://shema.google.com/codesearch/2006}%s'
 29
 30
 31class Match(atom.AtomBase):
 32    """ The Google Codesearch match element """
 33    _tag = 'match'
 34    _namespace = CODESEARCH_NAMESPACE
 35    _children = atom.AtomBase._children.copy()
 36    _attributes = atom.AtomBase._attributes.copy()
 37    _attributes['lineNumber'] = 'line_number'
 38    _attributes['type'] = 'type'
 39
 40    def __init__(self, line_number=None, type=None, extension_elements=None,
 41            extension_attributes=None, text=None):
 42        self.text = text
 43        self.type = type
 44        self.line_number = line_number 
 45        self.extension_elements = extension_elements or []
 46        self.extension_attributes = extension_attributes or {}
 47
 48
 49class File(atom.AtomBase):
 50    """ The Google Codesearch file element"""
 51    _tag = 'file'
 52    _namespace = CODESEARCH_NAMESPACE
 53    _children = atom.AtomBase._children.copy()
 54    _attributes = atom.AtomBase._attributes.copy()
 55    _attributes['name'] = 'name'
 56
 57    def __init__(self, name=None, extension_elements=None,
 58            extension_attributes=None, text=None):
 59        self.text = text
 60        self.name = name
 61        self.extension_elements = extension_elements or []
 62        self.extension_attributes = extension_attributes or {}
 63
 64
 65class Package(atom.AtomBase):
 66    """ The Google Codesearch package element"""
 67    _tag = 'package'
 68    _namespace = CODESEARCH_NAMESPACE
 69    _children = atom.AtomBase._children.copy()
 70    _attributes = atom.AtomBase._attributes.copy()
 71    _attributes['name'] = 'name'
 72    _attributes['uri'] = 'uri'
 73
 74    def __init__(self, name=None, uri=None, extension_elements=None,
 75            extension_attributes=None, text=None):
 76        self.text = text
 77        self.name = name
 78        self.uri = uri
 79        self.extension_elements = extension_elements or []
 80        self.extension_attributes = extension_attributes or {}
 81
 82
 83class CodesearchEntry(gdata.GDataEntry):
 84    """ Google codesearch atom entry"""
 85    _tag = gdata.GDataEntry._tag
 86    _namespace = gdata.GDataEntry._namespace
 87    _children = gdata.GDataEntry._children.copy()
 88    _attributes = gdata.GDataEntry._attributes.copy()
 89    
 90    _children['{%s}file' % CODESEARCH_NAMESPACE] = ('file', File)
 91    _children['{%s}package' % CODESEARCH_NAMESPACE] = ('package', Package)
 92    _children['{%s}match' % CODESEARCH_NAMESPACE] = ('match', [Match])
 93    
 94    def __init__(self, author=None, category=None, content=None,
 95            atom_id=None, link=None, published=None, 
 96            title=None, updated=None, 
 97            match=None, 
 98            extension_elements=None, extension_attributes=None, text=None):
 99        
100        gdata.GDataEntry.__init__(self, author=author, category=category, 
101                content=content, atom_id=atom_id, link=link, 
102                published=published, title=title, 
103                updated=updated, text=None)
104
105        self.match = match or []
106
107
108def CodesearchEntryFromString(xml_string):
109    """Converts an XML string into a CodesearchEntry object.
110
111    Args:
112        xml_string: string The XML describing a Codesearch feed entry.
113
114    Returns:
115        A CodesearchEntry object corresponding to the given XML.
116    """
117    return atom.CreateClassFromXMLString(CodesearchEntry, xml_string)
118
119
120class CodesearchFeed(gdata.GDataFeed):
121    """feed containing list of Google codesearch Items"""
122    _tag = gdata.GDataFeed._tag
123    _namespace = gdata.GDataFeed._namespace
124    _children = gdata.GDataFeed._children.copy()
125    _attributes = gdata.GDataFeed._attributes.copy()
126    _children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', [CodesearchEntry])
127
128    
129def CodesearchFeedFromString(xml_string):
130    """Converts an XML string into a CodesearchFeed object.
131    Args:
132    xml_string: string The XML describing a Codesearch feed.
133    Returns:
134    A CodeseartchFeed object corresponding to the given XML.
135    """
136    return atom.CreateClassFromXMLString(CodesearchFeed, xml_string)