<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import atom . data <EOL> import gdata . client <EOL> import gdata . sites . data <EOL> import gdata . gauth <EOL> CONTENT_FEED_TEMPLATE = '<STR_LIT>' <EOL> REVISION_FEED_TEMPLATE = '<STR_LIT>' <EOL> ACTIVITY_FEED_TEMPLATE = '<STR_LIT>' <EOL> SITE_FEED_TEMPLATE = '<STR_LIT>' <EOL> ACL_FEED_TEMPLATE = '<STR_LIT>' <EOL> class SitesClient ( gdata . client . GDClient ) : <EOL> """<STR_LIT>""" <EOL> host = '<STR_LIT>' <EOL> domain = '<STR_LIT>' <EOL> api_version = '<STR_LIT>' <EOL> auth_service = '<STR_LIT>' <EOL> auth_scopes = gdata . gauth . AUTH_SCOPES [ '<STR_LIT>' ] <EOL> ssl = True <EOL> def __init__ ( self , site = None , domain = None , auth_token = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> gdata . client . GDClient . __init__ ( self , auth_token = auth_token , ** kwargs ) <EOL> self . site = site <EOL> if domain is not None : <EOL> self . domain = domain <EOL> def __make_kind_category ( self , label ) : <EOL> if label is None : <EOL> return None <EOL> return atom . data . Category ( <EOL> scheme = gdata . sites . data . SITES_KIND_SCHEME , <EOL> term = '<STR_LIT>' % ( gdata . sites . data . SITES_NAMESPACE , label ) , label = label ) <EOL> __MakeKindCategory = __make_kind_category <EOL> def __upload ( self , entry , media_source , auth_token = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> uri = self . make_content_feed_uri ( ) <EOL> return self . post ( entry , uri , media_source = media_source , <EOL> auth_token = auth_token , ** kwargs ) <EOL> def _get_file_content ( self , uri ) : <EOL> """<STR_LIT>""" <EOL> server_response = self . request ( '<STR_LIT:GET>' , uri ) <EOL> if server_response . status != <NUM_LIT:200> : <EOL> raise gdata . client . RequestError ( { '<STR_LIT:status>' : server_response . status , <EOL> '<STR_LIT>' : server_response . reason , <EOL> '<STR_LIT:body>' : server_response . read ( ) } ) <EOL> return server_response . read ( ) <EOL> _GetFileContent = _get_file_content <EOL> def make_content_feed_uri ( self ) : <EOL> return CONTENT_FEED_TEMPLATE % ( self . domain , self . site ) <EOL> MakeContentFeedUri = make_content_feed_uri <EOL> def make_revision_feed_uri ( self ) : <EOL> return REVISION_FEED_TEMPLATE % ( self . domain , self . site ) <EOL> MakeRevisionFeedUri = make_revision_feed_uri <EOL> def make_activity_feed_uri ( self ) : <EOL> return ACTIVITY_FEED_TEMPLATE % ( self . domain , self . site ) <EOL> MakeActivityFeedUri = make_activity_feed_uri <EOL> def make_site_feed_uri ( self , site_name = None ) : <EOL> if site_name is not None : <EOL> return ( SITE_FEED_TEMPLATE % self . domain ) + site_name <EOL> else : <EOL> return SITE_FEED_TEMPLATE % self . domain <EOL> MakeSiteFeedUri = make_site_feed_uri <EOL> def make_acl_feed_uri ( self ) : <EOL> return ACL_FEED_TEMPLATE % ( self . domain , self . site ) <EOL> MakeAclFeedUri = make_acl_feed_uri <EOL> def get_content_feed ( self , uri = None , auth_token = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if uri is None : <EOL> uri = self . make_content_feed_uri ( ) <EOL> return self . get_feed ( uri , desired_class = gdata . sites . data . ContentFeed , <EOL> auth_token = auth_token , ** kwargs ) <EOL> GetContentFeed = get_content_feed <EOL> def get_revision_feed ( self , entry_or_uri_or_id , auth_token = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> uri = self . make_revision_feed_uri ( ) <EOL> if isinstance ( entry_or_uri_or_id , gdata . sites . data . ContentEntry ) : <EOL> uri = entry_or_uri_or_id . FindRevisionLink ( ) <EOL> elif entry_or_uri_or_id . find ( '<STR_LIT:/>' ) == - <NUM_LIT:1> : <EOL> uri += entry_or_uri_or_id <EOL> else : <EOL> uri = entry_or_uri_or_id <EOL> return self . get_feed ( uri , desired_class = gdata . sites . data . RevisionFeed , <EOL> auth_token = auth_token , ** kwargs ) <EOL> GetRevisionFeed = get_revision_feed <EOL> def get_activity_feed ( self , uri = None , auth_token = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if uri is None : <EOL> uri = self . make_activity_feed_uri ( ) <EOL> return self . get_feed ( uri , desired_class = gdata . sites . data . ActivityFeed , <EOL> auth_token = auth_token , ** kwargs ) <EOL> GetActivityFeed = get_activity_feed <EOL> def get_site_feed ( self , uri = None , auth_token = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if uri is None : <EOL> uri = self . make_site_feed_uri ( ) <EOL> return self . get_feed ( uri , desired_class = gdata . sites . data . SiteFeed , <EOL> auth_token = auth_token , ** kwargs ) <EOL> GetSiteFeed = get_site_feed <EOL> def get_acl_feed ( self , uri = None , auth_token = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if uri is None : <EOL> uri = self . make_acl_feed_uri ( ) <EOL> return self . get_feed ( uri , desired_class = gdata . sites . data . AclFeed , <EOL> auth_token = auth_token , ** kwargs ) <EOL> GetAclFeed = get_acl_feed <EOL> def create_site ( self , title , description = None , source_site = None , <EOL> theme = None , uri = None , auth_token = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> new_entry = gdata . sites . data . SiteEntry ( title = atom . data . Title ( text = title ) ) <EOL> if description is not None : <EOL> new_entry . summary = gdata . sites . data . Summary ( text = description ) <EOL> if source_site is not None : <EOL> source_link = atom . data . Link ( rel = gdata . sites . data . SITES_SOURCE_LINK_REL , <EOL> type = '<STR_LIT>' , <EOL> href = source_site ) <EOL> new_entry . link . append ( source_link ) <EOL> if theme is not None : <EOL> new_entry . theme = gdata . sites . data . Theme ( text = theme ) <EOL> if uri is None : <EOL> uri = self . make_site_feed_uri ( ) <EOL> return self . post ( new_entry , uri , auth_token = auth_token , ** kwargs ) <EOL> CreateSite = create_site <EOL> def create_page ( self , kind , title , html = '<STR_LIT>' , page_name = None , parent = None , <EOL> auth_token = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> new_entry = gdata . sites . data . ContentEntry ( <EOL> title = atom . data . Title ( text = title ) , kind = kind , <EOL> content = gdata . sites . data . Content ( text = html ) ) <EOL> if page_name is not None : <EOL> new_entry . page_name = gdata . sites . data . PageName ( text = page_name ) <EOL> if isinstance ( parent , gdata . sites . data . ContentEntry ) : <EOL> parent_link = atom . data . Link ( rel = gdata . sites . data . SITES_PARENT_LINK_REL , <EOL> type = '<STR_LIT>' , <EOL> href = parent . GetSelfLink ( ) . href ) <EOL> new_entry . link . append ( parent_link ) <EOL> elif parent is not None : <EOL> parent_link = atom . data . Link ( rel = gdata . sites . data . SITES_PARENT_LINK_REL , <EOL> type = '<STR_LIT>' , <EOL> href = parent ) <EOL> new_entry . link . append ( parent_link ) <EOL> return self . post ( new_entry , self . make_content_feed_uri ( ) , <EOL> auth_token = auth_token , ** kwargs ) <EOL> CreatePage = create_page <EOL> def create_webattachment ( self , src , content_type , title , parent , <EOL> description = None , auth_token = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> new_entry = gdata . sites . data . ContentEntry ( <EOL> title = atom . data . Title ( text = title ) , kind = '<STR_LIT>' , <EOL> content = gdata . sites . data . Content ( src = src , type = content_type ) ) <EOL> if isinstance ( parent , gdata . sites . data . ContentEntry ) : <EOL> link = atom . data . Link ( rel = gdata . sites . data . SITES_PARENT_LINK_REL , <EOL> type = '<STR_LIT>' , <EOL> href = parent . GetSelfLink ( ) . href ) <EOL> elif parent is not None : <EOL> link = atom . data . Link ( rel = gdata . sites . data . SITES_PARENT_LINK_REL , <EOL> type = '<STR_LIT>' , href = parent ) <EOL> new_entry . link . append ( link ) <EOL> if description is not None : <EOL> new_entry . summary = gdata . sites . data . Summary ( type = '<STR_LIT:text>' , <EOL> text = description ) <EOL> return self . post ( new_entry , self . make_content_feed_uri ( ) , <EOL> auth_token = auth_token , ** kwargs ) <EOL> CreateWebAttachment = create_webattachment <EOL> def upload_attachment ( self , file_handle , parent , content_type = None , <EOL> title = None , description = None , folder_name = None , <EOL> auth_token = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( parent , gdata . sites . data . ContentEntry ) : <EOL> link = atom . data . Link ( rel = gdata . sites . data . SITES_PARENT_LINK_REL , <EOL> type = '<STR_LIT>' , <EOL> href = parent . GetSelfLink ( ) . href ) <EOL> else : <EOL> link = atom . data . Link ( rel = gdata . sites . data . SITES_PARENT_LINK_REL , <EOL> type = '<STR_LIT>' , <EOL> href = parent ) <EOL> if not isinstance ( file_handle , gdata . data . MediaSource ) : <EOL> ms = gdata . data . MediaSource ( file_path = file_handle , <EOL> content_type = content_type ) <EOL> else : <EOL> ms = file_handle <EOL> if title is None : <EOL> title = ms . file_name <EOL> new_entry = gdata . sites . data . ContentEntry ( kind = '<STR_LIT>' ) <EOL> new_entry . title = atom . data . Title ( text = title ) <EOL> new_entry . link . append ( link ) <EOL> if description is not None : <EOL> new_entry . summary = gdata . sites . data . Summary ( type = '<STR_LIT:text>' , <EOL> text = description ) <EOL> if parent . Kind ( ) == '<STR_LIT>' and folder_name is not None : <EOL> folder_category = atom . data . Category ( <EOL> scheme = gdata . sites . data . FOLDER_KIND_TERM , term = folder_name ) <EOL> new_entry . category . append ( folder_category ) <EOL> return self . __upload ( new_entry , ms , auth_token = auth_token , ** kwargs ) <EOL> UploadAttachment = upload_attachment <EOL> def download_attachment ( self , uri_or_entry , file_path ) : <EOL> """<STR_LIT>""" <EOL> uri = uri_or_entry <EOL> if isinstance ( uri_or_entry , gdata . sites . data . ContentEntry ) : <EOL> uri = uri_or_entry . content . src <EOL> f = open ( file_path , '<STR_LIT:wb>' ) <EOL> try : <EOL> f . write ( self . _get_file_content ( uri ) ) <EOL> except gdata . client . RequestError as e : <EOL> f . close ( ) <EOL> raise e <EOL> f . flush ( ) <EOL> f . close ( ) <EOL> DownloadAttachment = download_attachment </s>
