/usr/lib/python2.7/dist-packages/gdata/photos/__init__.py is in python-gdata 2.0.18+dfsg1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 | # -*-*- encoding: utf-8 -*-*-
#
# This is the base file for the PicasaWeb python client.
# It is used for lower level operations.
#
# $Id: __init__.py 148 2007-10-28 15:09:19Z havard.gulldahl $
#
# Copyright 2007 Håvard Gulldahl
# Portions (C) 2006 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This module provides a pythonic, gdata-centric interface to Google Photos
(a.k.a. Picasa Web Services.
It is modelled after the gdata/* interfaces from the gdata-python-client
project[1] by Google.
You'll find the user-friendly api in photos.service. Please see the
documentation or live help() system for available methods.
[1]: http://gdata-python-client.googlecode.com/
"""
__author__ = u'havard@gulldahl.no'# (Håvard Gulldahl)' #BUG: pydoc chokes on non-ascii chars in __author__
__license__ = 'Apache License v2'
__version__ = '$Revision: 164 $'[11:-2]
import re
try:
from xml.etree import cElementTree as ElementTree
except ImportError:
try:
import cElementTree as ElementTree
except ImportError:
try:
from xml.etree import ElementTree
except ImportError:
from elementtree import ElementTree
import atom
import gdata
# importing google photo submodules
import gdata.media as Media, gdata.exif as Exif, gdata.geo as Geo
# XML namespaces which are often used in Google Photo elements
PHOTOS_NAMESPACE = 'http://schemas.google.com/photos/2007'
MEDIA_NAMESPACE = 'http://search.yahoo.com/mrss/'
EXIF_NAMESPACE = 'http://schemas.google.com/photos/exif/2007'
OPENSEARCH_NAMESPACE = 'http://a9.com/-/spec/opensearchrss/1.0/'
GEO_NAMESPACE = 'http://www.w3.org/2003/01/geo/wgs84_pos#'
GML_NAMESPACE = 'http://www.opengis.net/gml'
GEORSS_NAMESPACE = 'http://www.georss.org/georss'
PHEED_NAMESPACE = 'http://www.pheed.com/pheed/'
BATCH_NAMESPACE = 'http://schemas.google.com/gdata/batch'
class PhotosBaseElement(atom.AtomBase):
"""Base class for elements in the PHOTO_NAMESPACE. To add new elements,
you only need to add the element tag name to self._tag
"""
_tag = ''
_namespace = PHOTOS_NAMESPACE
_children = atom.AtomBase._children.copy()
_attributes = atom.AtomBase._attributes.copy()
def __init__(self, name=None, extension_elements=None,
extension_attributes=None, text=None):
self.name = name
self.text = text
self.extension_elements = extension_elements or []
self.extension_attributes = extension_attributes or {}
#def __str__(self):
#return str(self.text)
#def __unicode__(self):
#return unicode(self.text)
def __int__(self):
return int(self.text)
def bool(self):
return self.text == 'true'
class GPhotosBaseFeed(gdata.GDataFeed, gdata.LinkFinder):
"Base class for all Feeds in gdata.photos"
_tag = 'feed'
_namespace = atom.ATOM_NAMESPACE
_attributes = gdata.GDataFeed._attributes.copy()
_children = gdata.GDataFeed._children.copy()
# We deal with Entry elements ourselves
del _children['{%s}entry' % atom.ATOM_NAMESPACE]
def __init__(self, author=None, category=None, contributor=None,
generator=None, icon=None, atom_id=None, link=None, logo=None,
rights=None, subtitle=None, title=None, updated=None,
entry=None, total_results=None, start_index=None,
items_per_page=None, extension_elements=None,
extension_attributes=None, text=None):
gdata.GDataFeed.__init__(self, author=author, category=category,
contributor=contributor, generator=generator,
icon=icon, atom_id=atom_id, link=link,
logo=logo, rights=rights, subtitle=subtitle,
title=title, updated=updated, entry=entry,
total_results=total_results,
start_index=start_index,
items_per_page=items_per_page,
extension_elements=extension_elements,
extension_attributes=extension_attributes,
text=text)
def kind(self):
"(string) Returns the kind"
try:
return self.category[0].term.split('#')[1]
except IndexError:
return None
def _feedUri(self, kind):
"Convenience method to return a uri to a feed of a special kind"
assert(kind in ('album', 'tag', 'photo', 'comment', 'user'))
here_href = self.GetSelfLink().href
if 'kind=%s' % kind in here_href:
return here_href
if not 'kind=' in here_href:
sep = '?'
if '?' in here_href: sep = '&'
return here_href + "%skind=%s" % (sep, kind)
rx = re.match('.*(kind=)(album|tag|photo|comment)', here_href)
return here_href[:rx.end(1)] + kind + here_href[rx.end(2):]
def _ConvertElementTreeToMember(self, child_tree):
"""Re-implementing the method from AtomBase, since we deal with
Entry elements specially"""
category = child_tree.find('{%s}category' % atom.ATOM_NAMESPACE)
if category is None:
return atom.AtomBase._ConvertElementTreeToMember(self, child_tree)
namespace, kind = category.get('term').split('#')
if namespace != PHOTOS_NAMESPACE:
return atom.AtomBase._ConvertElementTreeToMember(self, child_tree)
## TODO: is it safe to use getattr on gdata.photos?
entry_class = getattr(gdata.photos, '%sEntry' % kind.title())
if not hasattr(self, 'entry') or self.entry is None:
self.entry = []
self.entry.append(atom._CreateClassFromElementTree(
entry_class, child_tree))
class GPhotosBaseEntry(gdata.GDataEntry, gdata.LinkFinder):
"Base class for all Entry elements in gdata.photos"
_tag = 'entry'
_kind = ''
_namespace = atom.ATOM_NAMESPACE
_children = gdata.GDataEntry._children.copy()
_attributes = gdata.GDataEntry._attributes.copy()
def __init__(self, author=None, category=None, content=None,
atom_id=None, link=None, published=None,
title=None, updated=None,
extended_property=None,
extension_elements=None, extension_attributes=None, text=None):
gdata.GDataEntry.__init__(self, author=author, category=category,
content=content, atom_id=atom_id, link=link,
published=published, title=title,
updated=updated, text=text,
extension_elements=extension_elements,
extension_attributes=extension_attributes)
self.category.append(
atom.Category(scheme='http://schemas.google.com/g/2005#kind',
term = 'http://schemas.google.com/photos/2007#%s' % self._kind))
def kind(self):
"(string) Returns the kind"
try:
return self.category[0].term.split('#')[1]
except IndexError:
return None
def _feedUri(self, kind):
"Convenience method to get the uri to this entry's feed of the some kind"
try:
href = self.GetFeedLink().href
except AttributeError:
return None
sep = '?'
if '?' in href: sep = '&'
return '%s%skind=%s' % (href, sep, kind)
class PhotosBaseEntry(GPhotosBaseEntry):
pass
class PhotosBaseFeed(GPhotosBaseFeed):
pass
class GPhotosBaseData(object):
pass
class Access(PhotosBaseElement):
"""The Google Photo `Access' element.
The album's access level. Valid values are `public' or `private'.
In documentation, access level is also referred to as `visibility.'"""
_tag = 'access'
def AccessFromString(xml_string):
return atom.CreateClassFromXMLString(Access, xml_string)
class Albumid(PhotosBaseElement):
"The Google Photo `Albumid' element"
_tag = 'albumid'
def AlbumidFromString(xml_string):
return atom.CreateClassFromXMLString(Albumid, xml_string)
class BytesUsed(PhotosBaseElement):
"The Google Photo `BytesUsed' element"
_tag = 'bytesUsed'
def BytesUsedFromString(xml_string):
return atom.CreateClassFromXMLString(BytesUsed, xml_string)
class Client(PhotosBaseElement):
"The Google Photo `Client' element"
_tag = 'client'
def ClientFromString(xml_string):
return atom.CreateClassFromXMLString(Client, xml_string)
class Checksum(PhotosBaseElement):
"The Google Photo `Checksum' element"
_tag = 'checksum'
def ChecksumFromString(xml_string):
return atom.CreateClassFromXMLString(Checksum, xml_string)
class CommentCount(PhotosBaseElement):
"The Google Photo `CommentCount' element"
_tag = 'commentCount'
def CommentCountFromString(xml_string):
return atom.CreateClassFromXMLString(CommentCount, xml_string)
class CommentingEnabled(PhotosBaseElement):
"The Google Photo `CommentingEnabled' element"
_tag = 'commentingEnabled'
def CommentingEnabledFromString(xml_string):
return atom.CreateClassFromXMLString(CommentingEnabled, xml_string)
class Height(PhotosBaseElement):
"The Google Photo `Height' element"
_tag = 'height'
def HeightFromString(xml_string):
return atom.CreateClassFromXMLString(Height, xml_string)
class Id(PhotosBaseElement):
"The Google Photo `Id' element"
_tag = 'id'
def IdFromString(xml_string):
return atom.CreateClassFromXMLString(Id, xml_string)
class Location(PhotosBaseElement):
"The Google Photo `Location' element"
_tag = 'location'
def LocationFromString(xml_string):
return atom.CreateClassFromXMLString(Location, xml_string)
class MaxPhotosPerAlbum(PhotosBaseElement):
"The Google Photo `MaxPhotosPerAlbum' element"
_tag = 'maxPhotosPerAlbum'
def MaxPhotosPerAlbumFromString(xml_string):
return atom.CreateClassFromXMLString(MaxPhotosPerAlbum, xml_string)
class Name(PhotosBaseElement):
"The Google Photo `Name' element"
_tag = 'name'
def NameFromString(xml_string):
return atom.CreateClassFromXMLString(Name, xml_string)
class Nickname(PhotosBaseElement):
"The Google Photo `Nickname' element"
_tag = 'nickname'
def NicknameFromString(xml_string):
return atom.CreateClassFromXMLString(Nickname, xml_string)
class Numphotos(PhotosBaseElement):
"The Google Photo `Numphotos' element"
_tag = 'numphotos'
def NumphotosFromString(xml_string):
return atom.CreateClassFromXMLString(Numphotos, xml_string)
class Numphotosremaining(PhotosBaseElement):
"The Google Photo `Numphotosremaining' element"
_tag = 'numphotosremaining'
def NumphotosremainingFromString(xml_string):
return atom.CreateClassFromXMLString(Numphotosremaining, xml_string)
class Position(PhotosBaseElement):
"The Google Photo `Position' element"
_tag = 'position'
def PositionFromString(xml_string):
return atom.CreateClassFromXMLString(Position, xml_string)
class Photoid(PhotosBaseElement):
"The Google Photo `Photoid' element"
_tag = 'photoid'
def PhotoidFromString(xml_string):
return atom.CreateClassFromXMLString(Photoid, xml_string)
class Quotacurrent(PhotosBaseElement):
"The Google Photo `Quotacurrent' element"
_tag = 'quotacurrent'
def QuotacurrentFromString(xml_string):
return atom.CreateClassFromXMLString(Quotacurrent, xml_string)
class Quotalimit(PhotosBaseElement):
"The Google Photo `Quotalimit' element"
_tag = 'quotalimit'
def QuotalimitFromString(xml_string):
return atom.CreateClassFromXMLString(Quotalimit, xml_string)
class Rotation(PhotosBaseElement):
"The Google Photo `Rotation' element"
_tag = 'rotation'
def RotationFromString(xml_string):
return atom.CreateClassFromXMLString(Rotation, xml_string)
class Size(PhotosBaseElement):
"The Google Photo `Size' element"
_tag = 'size'
def SizeFromString(xml_string):
return atom.CreateClassFromXMLString(Size, xml_string)
class Snippet(PhotosBaseElement):
"""The Google Photo `snippet' element.
When searching, the snippet element will contain a
string with the word you're looking for, highlighted in html markup
E.g. when your query is `hafjell', this element may contain:
`... here at <b>Hafjell</b>.'
You'll find this element in searches -- that is, feeds that combine the
`kind=photo' and `q=yoursearch' parameters in the request.
See also gphoto:truncated and gphoto:snippettype.
"""
_tag = 'snippet'
def SnippetFromString(xml_string):
return atom.CreateClassFromXMLString(Snippet, xml_string)
class Snippettype(PhotosBaseElement):
"""The Google Photo `Snippettype' element
When searching, this element will tell you the type of element that matches.
You'll find this element in searches -- that is, feeds that combine the
`kind=photo' and `q=yoursearch' parameters in the request.
See also gphoto:snippet and gphoto:truncated.
Possible values and their interpretation:
o ALBUM_TITLE - The album title matches
o PHOTO_TAGS - The match is a tag/keyword
o PHOTO_DESCRIPTION - The match is in the photo's description
If you discover a value not listed here, please submit a patch to update this docstring.
"""
_tag = 'snippettype'
def SnippettypeFromString(xml_string):
return atom.CreateClassFromXMLString(Snippettype, xml_string)
class Thumbnail(PhotosBaseElement):
"""The Google Photo `Thumbnail' element
Used to display user's photo thumbnail (hackergotchi).
(Not to be confused with the <media:thumbnail> element, which gives you
small versions of the photo object.)"""
_tag = 'thumbnail'
def ThumbnailFromString(xml_string):
return atom.CreateClassFromXMLString(Thumbnail, xml_string)
class Timestamp(PhotosBaseElement):
"""The Google Photo `Timestamp' element
Represented as the number of milliseconds since January 1st, 1970.
Take a look at the convenience methods .isoformat() and .datetime():
photo_epoch = Time.text # 1180294337000
photo_isostring = Time.isoformat() # '2007-05-27T19:32:17.000Z'
Alternatively:
photo_datetime = Time.datetime() # (requires python >= 2.3)
"""
_tag = 'timestamp'
def isoformat(self):
"""(string) Return the timestamp as a ISO 8601 formatted string,
e.g. '2007-05-27T19:32:17.000Z'
"""
import time
epoch = float(self.text)/1000
return time.strftime('%Y-%m-%dT%H:%M:%S.000Z', time.gmtime(epoch))
def datetime(self):
"""(datetime.datetime) Return the timestamp as a datetime.datetime object
Requires python 2.3
"""
import datetime
epoch = float(self.text)/1000
return datetime.datetime.fromtimestamp(epoch)
def TimestampFromString(xml_string):
return atom.CreateClassFromXMLString(Timestamp, xml_string)
class Truncated(PhotosBaseElement):
"""The Google Photo `Truncated' element
You'll find this element in searches -- that is, feeds that combine the
`kind=photo' and `q=yoursearch' parameters in the request.
See also gphoto:snippet and gphoto:snippettype.
Possible values and their interpretation:
0 -- unknown
"""
_tag = 'Truncated'
def TruncatedFromString(xml_string):
return atom.CreateClassFromXMLString(Truncated, xml_string)
class User(PhotosBaseElement):
"The Google Photo `User' element"
_tag = 'user'
def UserFromString(xml_string):
return atom.CreateClassFromXMLString(User, xml_string)
class Version(PhotosBaseElement):
"The Google Photo `Version' element"
_tag = 'version'
def VersionFromString(xml_string):
return atom.CreateClassFromXMLString(Version, xml_string)
class Width(PhotosBaseElement):
"The Google Photo `Width' element"
_tag = 'width'
def WidthFromString(xml_string):
return atom.CreateClassFromXMLString(Width, xml_string)
class Weight(PhotosBaseElement):
"""The Google Photo `Weight' element.
The weight of the tag is the number of times the tag
appears in the collection of tags currently being viewed.
The default weight is 1, in which case this tags is omitted."""
_tag = 'weight'
def WeightFromString(xml_string):
return atom.CreateClassFromXMLString(Weight, xml_string)
class CommentAuthor(atom.Author):
"""The Atom `Author' element in CommentEntry entries is augmented to
contain elements from the PHOTOS_NAMESPACE
http://groups.google.com/group/Google-Picasa-Data-API/msg/819b0025b5ff5e38
"""
_children = atom.Author._children.copy()
_children['{%s}user' % PHOTOS_NAMESPACE] = ('user', User)
_children['{%s}nickname' % PHOTOS_NAMESPACE] = ('nickname', Nickname)
_children['{%s}thumbnail' % PHOTOS_NAMESPACE] = ('thumbnail', Thumbnail)
def CommentAuthorFromString(xml_string):
return atom.CreateClassFromXMLString(CommentAuthor, xml_string)
########################## ################################
class AlbumData(object):
_children = {}
_children['{%s}id' % PHOTOS_NAMESPACE] = ('gphoto_id', Id)
_children['{%s}name' % PHOTOS_NAMESPACE] = ('name', Name)
_children['{%s}location' % PHOTOS_NAMESPACE] = ('location', Location)
_children['{%s}access' % PHOTOS_NAMESPACE] = ('access', Access)
_children['{%s}bytesUsed' % PHOTOS_NAMESPACE] = ('bytesUsed', BytesUsed)
_children['{%s}timestamp' % PHOTOS_NAMESPACE] = ('timestamp', Timestamp)
_children['{%s}numphotos' % PHOTOS_NAMESPACE] = ('numphotos', Numphotos)
_children['{%s}numphotosremaining' % PHOTOS_NAMESPACE] = \
('numphotosremaining', Numphotosremaining)
_children['{%s}user' % PHOTOS_NAMESPACE] = ('user', User)
_children['{%s}nickname' % PHOTOS_NAMESPACE] = ('nickname', Nickname)
_children['{%s}commentingEnabled' % PHOTOS_NAMESPACE] = \
('commentingEnabled', CommentingEnabled)
_children['{%s}commentCount' % PHOTOS_NAMESPACE] = \
('commentCount', CommentCount)
## NOTE: storing media:group as self.media, to create a self-explaining api
gphoto_id = None
name = None
location = None
access = None
bytesUsed = None
timestamp = None
numphotos = None
numphotosremaining = None
user = None
nickname = None
commentingEnabled = None
commentCount = None
class AlbumEntry(GPhotosBaseEntry, AlbumData):
"""All metadata for a Google Photos Album
Take a look at AlbumData for metadata accessible as attributes to this object.
Notes:
To avoid name clashes, and to create a more sensible api, some
objects have names that differ from the original elements:
o media:group -> self.media,
o geo:where -> self.geo,
o photo:id -> self.gphoto_id
"""
_kind = 'album'
_children = GPhotosBaseEntry._children.copy()
_children.update(AlbumData._children.copy())
# child tags only for Album entries, not feeds
_children['{%s}where' % GEORSS_NAMESPACE] = ('geo', Geo.Where)
_children['{%s}group' % MEDIA_NAMESPACE] = ('media', Media.Group)
media = Media.Group()
geo = Geo.Where()
def __init__(self, author=None, category=None, content=None,
atom_id=None, link=None, published=None,
title=None, updated=None,
#GPHOTO NAMESPACE:
gphoto_id=None, name=None, location=None, access=None,
timestamp=None, numphotos=None, user=None, nickname=None,
commentingEnabled=None, commentCount=None, thumbnail=None,
# MEDIA NAMESPACE:
media=None,
# GEORSS NAMESPACE:
geo=None,
extended_property=None,
extension_elements=None, extension_attributes=None, text=None):
GPhotosBaseEntry.__init__(self, author=author, category=category,
content=content, atom_id=atom_id, link=link,
published=published, title=title,
updated=updated, text=text,
extension_elements=extension_elements,
extension_attributes=extension_attributes)
## NOTE: storing photo:id as self.gphoto_id, to avoid name clash with atom:id
self.gphoto_id = gphoto_id
self.name = name
self.location = location
self.access = access
self.timestamp = timestamp
self.numphotos = numphotos
self.user = user
self.nickname = nickname
self.commentingEnabled = commentingEnabled
self.commentCount = commentCount
self.thumbnail = thumbnail
self.extended_property = extended_property or []
self.text = text
## NOTE: storing media:group as self.media, and geo:where as geo,
## to create a self-explaining api
self.media = media or Media.Group()
self.geo = geo or Geo.Where()
def GetAlbumId(self):
"Return the id of this album"
return self.GetFeedLink().href.split('/')[-1]
def GetPhotosUri(self):
"(string) Return the uri to this albums feed of the PhotoEntry kind"
return self._feedUri('photo')
def GetCommentsUri(self):
"(string) Return the uri to this albums feed of the CommentEntry kind"
return self._feedUri('comment')
def GetTagsUri(self):
"(string) Return the uri to this albums feed of the TagEntry kind"
return self._feedUri('tag')
def AlbumEntryFromString(xml_string):
return atom.CreateClassFromXMLString(AlbumEntry, xml_string)
class AlbumFeed(GPhotosBaseFeed, AlbumData):
"""All metadata for a Google Photos Album, including its sub-elements
This feed represents an album as the container for other objects.
A Album feed contains entries of
PhotoEntry, CommentEntry or TagEntry,
depending on the `kind' parameter in the original query.
Take a look at AlbumData for accessible attributes.
"""
_children = GPhotosBaseFeed._children.copy()
_children.update(AlbumData._children.copy())
def GetPhotosUri(self):
"(string) Return the uri to the same feed, but of the PhotoEntry kind"
return self._feedUri('photo')
def GetTagsUri(self):
"(string) Return the uri to the same feed, but of the TagEntry kind"
return self._feedUri('tag')
def GetCommentsUri(self):
"(string) Return the uri to the same feed, but of the CommentEntry kind"
return self._feedUri('comment')
def AlbumFeedFromString(xml_string):
return atom.CreateClassFromXMLString(AlbumFeed, xml_string)
class PhotoData(object):
_children = {}
## NOTE: storing photo:id as self.gphoto_id, to avoid name clash with atom:id
_children['{%s}id' % PHOTOS_NAMESPACE] = ('gphoto_id', Id)
_children['{%s}albumid' % PHOTOS_NAMESPACE] = ('albumid', Albumid)
_children['{%s}checksum' % PHOTOS_NAMESPACE] = ('checksum', Checksum)
_children['{%s}client' % PHOTOS_NAMESPACE] = ('client', Client)
_children['{%s}height' % PHOTOS_NAMESPACE] = ('height', Height)
_children['{%s}position' % PHOTOS_NAMESPACE] = ('position', Position)
_children['{%s}rotation' % PHOTOS_NAMESPACE] = ('rotation', Rotation)
_children['{%s}size' % PHOTOS_NAMESPACE] = ('size', Size)
_children['{%s}timestamp' % PHOTOS_NAMESPACE] = ('timestamp', Timestamp)
_children['{%s}version' % PHOTOS_NAMESPACE] = ('version', Version)
_children['{%s}width' % PHOTOS_NAMESPACE] = ('width', Width)
_children['{%s}commentingEnabled' % PHOTOS_NAMESPACE] = \
('commentingEnabled', CommentingEnabled)
_children['{%s}commentCount' % PHOTOS_NAMESPACE] = \
('commentCount', CommentCount)
## NOTE: storing media:group as self.media, exif:tags as self.exif, and
## geo:where as self.geo, to create a self-explaining api
_children['{%s}tags' % EXIF_NAMESPACE] = ('exif', Exif.Tags)
_children['{%s}where' % GEORSS_NAMESPACE] = ('geo', Geo.Where)
_children['{%s}group' % MEDIA_NAMESPACE] = ('media', Media.Group)
# These elements show up in search feeds
_children['{%s}snippet' % PHOTOS_NAMESPACE] = ('snippet', Snippet)
_children['{%s}snippettype' % PHOTOS_NAMESPACE] = ('snippettype', Snippettype)
_children['{%s}truncated' % PHOTOS_NAMESPACE] = ('truncated', Truncated)
gphoto_id = None
albumid = None
checksum = None
client = None
height = None
position = None
rotation = None
size = None
timestamp = None
version = None
width = None
commentingEnabled = None
commentCount = None
snippet=None
snippettype=None
truncated=None
media = Media.Group()
geo = Geo.Where()
tags = Exif.Tags()
class PhotoEntry(GPhotosBaseEntry, PhotoData):
"""All metadata for a Google Photos Photo
Take a look at PhotoData for metadata accessible as attributes to this object.
Notes:
To avoid name clashes, and to create a more sensible api, some
objects have names that differ from the original elements:
o media:group -> self.media,
o exif:tags -> self.exif,
o geo:where -> self.geo,
o photo:id -> self.gphoto_id
"""
_kind = 'photo'
_children = GPhotosBaseEntry._children.copy()
_children.update(PhotoData._children.copy())
def __init__(self, author=None, category=None, content=None,
atom_id=None, link=None, published=None,
title=None, updated=None, text=None,
# GPHOTO NAMESPACE:
gphoto_id=None, albumid=None, checksum=None, client=None, height=None,
position=None, rotation=None, size=None, timestamp=None, version=None,
width=None, commentCount=None, commentingEnabled=None,
# MEDIARSS NAMESPACE:
media=None,
# EXIF_NAMESPACE:
exif=None,
# GEORSS NAMESPACE:
geo=None,
extension_elements=None, extension_attributes=None):
GPhotosBaseEntry.__init__(self, author=author, category=category,
content=content,
atom_id=atom_id, link=link, published=published,
title=title, updated=updated, text=text,
extension_elements=extension_elements,
extension_attributes=extension_attributes)
## NOTE: storing photo:id as self.gphoto_id, to avoid name clash with atom:id
self.gphoto_id = gphoto_id
self.albumid = albumid
self.checksum = checksum
self.client = client
self.height = height
self.position = position
self.rotation = rotation
self.size = size
self.timestamp = timestamp
self.version = version
self.width = width
self.commentingEnabled = commentingEnabled
self.commentCount = commentCount
## NOTE: storing media:group as self.media, to create a self-explaining api
self.media = media or Media.Group()
self.exif = exif or Exif.Tags()
self.geo = geo or Geo.Where()
def GetPostLink(self):
"Return the uri to this photo's `POST' link (use it for updates of the object)"
return self.GetFeedLink()
def GetCommentsUri(self):
"Return the uri to this photo's feed of CommentEntry comments"
return self._feedUri('comment')
def GetTagsUri(self):
"Return the uri to this photo's feed of TagEntry tags"
return self._feedUri('tag')
def GetAlbumUri(self):
"""Return the uri to the AlbumEntry containing this photo"""
href = self.GetSelfLink().href
return href[:href.find('/photoid')]
def PhotoEntryFromString(xml_string):
return atom.CreateClassFromXMLString(PhotoEntry, xml_string)
class PhotoFeed(GPhotosBaseFeed, PhotoData):
"""All metadata for a Google Photos Photo, including its sub-elements
This feed represents a photo as the container for other objects.
A Photo feed contains entries of
CommentEntry or TagEntry,
depending on the `kind' parameter in the original query.
Take a look at PhotoData for metadata accessible as attributes to this object.
"""
_children = GPhotosBaseFeed._children.copy()
_children.update(PhotoData._children.copy())
def GetTagsUri(self):
"(string) Return the uri to the same feed, but of the TagEntry kind"
return self._feedUri('tag')
def GetCommentsUri(self):
"(string) Return the uri to the same feed, but of the CommentEntry kind"
return self._feedUri('comment')
def PhotoFeedFromString(xml_string):
return atom.CreateClassFromXMLString(PhotoFeed, xml_string)
class TagData(GPhotosBaseData):
_children = {}
_children['{%s}weight' % PHOTOS_NAMESPACE] = ('weight', Weight)
weight=None
class TagEntry(GPhotosBaseEntry, TagData):
"""All metadata for a Google Photos Tag
The actual tag is stored in the .title.text attribute
"""
_kind = 'tag'
_children = GPhotosBaseEntry._children.copy()
_children.update(TagData._children.copy())
def __init__(self, author=None, category=None, content=None,
atom_id=None, link=None, published=None,
title=None, updated=None,
# GPHOTO NAMESPACE:
weight=None,
extended_property=None,
extension_elements=None, extension_attributes=None, text=None):
GPhotosBaseEntry.__init__(self, author=author, category=category,
content=content,
atom_id=atom_id, link=link, published=published,
title=title, updated=updated, text=text,
extension_elements=extension_elements,
extension_attributes=extension_attributes)
self.weight = weight
def GetAlbumUri(self):
"""Return the uri to the AlbumEntry containing this tag"""
href = self.GetSelfLink().href
pos = href.find('/photoid')
if pos == -1:
return None
return href[:pos]
def GetPhotoUri(self):
"""Return the uri to the PhotoEntry containing this tag"""
href = self.GetSelfLink().href
pos = href.find('/tag')
if pos == -1:
return None
return href[:pos]
def TagEntryFromString(xml_string):
return atom.CreateClassFromXMLString(TagEntry, xml_string)
class TagFeed(GPhotosBaseFeed, TagData):
"""All metadata for a Google Photos Tag, including its sub-elements"""
_children = GPhotosBaseFeed._children.copy()
_children.update(TagData._children.copy())
def TagFeedFromString(xml_string):
return atom.CreateClassFromXMLString(TagFeed, xml_string)
class CommentData(GPhotosBaseData):
_children = {}
## NOTE: storing photo:id as self.gphoto_id, to avoid name clash with atom:id
_children['{%s}id' % PHOTOS_NAMESPACE] = ('gphoto_id', Id)
_children['{%s}albumid' % PHOTOS_NAMESPACE] = ('albumid', Albumid)
_children['{%s}photoid' % PHOTOS_NAMESPACE] = ('photoid', Photoid)
_children['{%s}author' % atom.ATOM_NAMESPACE] = ('author', [CommentAuthor,])
gphoto_id=None
albumid=None
photoid=None
author=None
class CommentEntry(GPhotosBaseEntry, CommentData):
"""All metadata for a Google Photos Comment
The comment is stored in the .content.text attribute,
with a content type in .content.type.
"""
_kind = 'comment'
_children = GPhotosBaseEntry._children.copy()
_children.update(CommentData._children.copy())
def __init__(self, author=None, category=None, content=None,
atom_id=None, link=None, published=None,
title=None, updated=None,
# GPHOTO NAMESPACE:
gphoto_id=None, albumid=None, photoid=None,
extended_property=None,
extension_elements=None, extension_attributes=None, text=None):
GPhotosBaseEntry.__init__(self, author=author, category=category,
content=content,
atom_id=atom_id, link=link, published=published,
title=title, updated=updated,
extension_elements=extension_elements,
extension_attributes=extension_attributes,
text=text)
self.gphoto_id = gphoto_id
self.albumid = albumid
self.photoid = photoid
def GetCommentId(self):
"""Return the globally unique id of this comment"""
return self.GetSelfLink().href.split('/')[-1]
def GetAlbumUri(self):
"""Return the uri to the AlbumEntry containing this comment"""
href = self.GetSelfLink().href
return href[:href.find('/photoid')]
def GetPhotoUri(self):
"""Return the uri to the PhotoEntry containing this comment"""
href = self.GetSelfLink().href
return href[:href.find('/commentid')]
def CommentEntryFromString(xml_string):
return atom.CreateClassFromXMLString(CommentEntry, xml_string)
class CommentFeed(GPhotosBaseFeed, CommentData):
"""All metadata for a Google Photos Comment, including its sub-elements"""
_children = GPhotosBaseFeed._children.copy()
_children.update(CommentData._children.copy())
def CommentFeedFromString(xml_string):
return atom.CreateClassFromXMLString(CommentFeed, xml_string)
class UserData(GPhotosBaseData):
_children = {}
_children['{%s}maxPhotosPerAlbum' % PHOTOS_NAMESPACE] = ('maxPhotosPerAlbum', MaxPhotosPerAlbum)
_children['{%s}nickname' % PHOTOS_NAMESPACE] = ('nickname', Nickname)
_children['{%s}quotalimit' % PHOTOS_NAMESPACE] = ('quotalimit', Quotalimit)
_children['{%s}quotacurrent' % PHOTOS_NAMESPACE] = ('quotacurrent', Quotacurrent)
_children['{%s}thumbnail' % PHOTOS_NAMESPACE] = ('thumbnail', Thumbnail)
_children['{%s}user' % PHOTOS_NAMESPACE] = ('user', User)
_children['{%s}id' % PHOTOS_NAMESPACE] = ('gphoto_id', Id)
maxPhotosPerAlbum=None
nickname=None
quotalimit=None
quotacurrent=None
thumbnail=None
user=None
gphoto_id=None
class UserEntry(GPhotosBaseEntry, UserData):
"""All metadata for a Google Photos User
This entry represents an album owner and all appropriate metadata.
Take a look at at the attributes of the UserData for metadata available.
"""
_children = GPhotosBaseEntry._children.copy()
_children.update(UserData._children.copy())
_kind = 'user'
def __init__(self, author=None, category=None, content=None,
atom_id=None, link=None, published=None,
title=None, updated=None,
# GPHOTO NAMESPACE:
gphoto_id=None, maxPhotosPerAlbum=None, nickname=None, quotalimit=None,
quotacurrent=None, thumbnail=None, user=None,
extended_property=None,
extension_elements=None, extension_attributes=None, text=None):
GPhotosBaseEntry.__init__(self, author=author, category=category,
content=content,
atom_id=atom_id, link=link, published=published,
title=title, updated=updated,
extension_elements=extension_elements,
extension_attributes=extension_attributes,
text=text)
self.gphoto_id=gphoto_id
self.maxPhotosPerAlbum=maxPhotosPerAlbum
self.nickname=nickname
self.quotalimit=quotalimit
self.quotacurrent=quotacurrent
self.thumbnail=thumbnail
self.user=user
def GetAlbumsUri(self):
"(string) Return the uri to this user's feed of the AlbumEntry kind"
return self._feedUri('album')
def GetPhotosUri(self):
"(string) Return the uri to this user's feed of the PhotoEntry kind"
return self._feedUri('photo')
def GetCommentsUri(self):
"(string) Return the uri to this user's feed of the CommentEntry kind"
return self._feedUri('comment')
def GetTagsUri(self):
"(string) Return the uri to this user's feed of the TagEntry kind"
return self._feedUri('tag')
def UserEntryFromString(xml_string):
return atom.CreateClassFromXMLString(UserEntry, xml_string)
class UserFeed(GPhotosBaseFeed, UserData):
"""Feed for a User in the google photos api.
This feed represents a user as the container for other objects.
A User feed contains entries of
AlbumEntry, PhotoEntry, CommentEntry, UserEntry or TagEntry,
depending on the `kind' parameter in the original query.
The user feed itself also contains all of the metadata available
as part of a UserData object."""
_children = GPhotosBaseFeed._children.copy()
_children.update(UserData._children.copy())
def GetAlbumsUri(self):
"""Get the uri to this feed, but with entries of the AlbumEntry kind."""
return self._feedUri('album')
def GetTagsUri(self):
"""Get the uri to this feed, but with entries of the TagEntry kind."""
return self._feedUri('tag')
def GetPhotosUri(self):
"""Get the uri to this feed, but with entries of the PhotosEntry kind."""
return self._feedUri('photo')
def GetCommentsUri(self):
"""Get the uri to this feed, but with entries of the CommentsEntry kind."""
return self._feedUri('comment')
def UserFeedFromString(xml_string):
return atom.CreateClassFromXMLString(UserFeed, xml_string)
def AnyFeedFromString(xml_string):
"""Creates an instance of the appropriate feed class from the
xml string contents.
Args:
xml_string: str A string which contains valid XML. The root element
of the XML string should match the tag and namespace of the desired
class.
Returns:
An instance of the target class with members assigned according to the
contents of the XML - or a basic gdata.GDataFeed instance if it is
impossible to determine the appropriate class (look for extra elements
in GDataFeed's .FindExtensions() and extension_elements[] ).
"""
tree = ElementTree.fromstring(xml_string)
category = tree.find('{%s}category' % atom.ATOM_NAMESPACE)
if category is None:
# TODO: is this the best way to handle this?
return atom._CreateClassFromElementTree(GPhotosBaseFeed, tree)
namespace, kind = category.get('term').split('#')
if namespace != PHOTOS_NAMESPACE:
# TODO: is this the best way to handle this?
return atom._CreateClassFromElementTree(GPhotosBaseFeed, tree)
## TODO: is getattr safe this way?
feed_class = getattr(gdata.photos, '%sFeed' % kind.title())
return atom._CreateClassFromElementTree(feed_class, tree)
def AnyEntryFromString(xml_string):
"""Creates an instance of the appropriate entry class from the
xml string contents.
Args:
xml_string: str A string which contains valid XML. The root element
of the XML string should match the tag and namespace of the desired
class.
Returns:
An instance of the target class with members assigned according to the
contents of the XML - or a basic gdata.GDataEndry instance if it is
impossible to determine the appropriate class (look for extra elements
in GDataEntry's .FindExtensions() and extension_elements[] ).
"""
tree = ElementTree.fromstring(xml_string)
category = tree.find('{%s}category' % atom.ATOM_NAMESPACE)
if category is None:
# TODO: is this the best way to handle this?
return atom._CreateClassFromElementTree(GPhotosBaseEntry, tree)
namespace, kind = category.get('term').split('#')
if namespace != PHOTOS_NAMESPACE:
# TODO: is this the best way to handle this?
return atom._CreateClassFromElementTree(GPhotosBaseEntry, tree)
## TODO: is getattr safe this way?
feed_class = getattr(gdata.photos, '%sEntry' % kind.title())
return atom._CreateClassFromElementTree(feed_class, tree)
|