This file is indexed.

/usr/share/pyshared/freevo/util/amazon.py is in python-freevo 1.9.2b2-4.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
"""Python wrapper for AWS E-Commerce Serive APIs.

Based upon pyamazon (http://www.josephson.org/projects/pyamazon/) with
efforts to meet the latest AWS specification.

The Amazon's web APIs specication is described here:
http://www.amazon.com/webservices

You need a Amazon-provided license key to use these services.
Follow the link above to get one.  These functions will look in
several places (in this order) for the license key:
        - the "license_key" argument of each function
        - the module-level LICENSE_KEY variable (call setLicense once to set it)
        - an environment variable called AMAZON_LICENSE_KEY
        - foo would return the python object, XMLfoo returns the DOM object

License: Python Software Foundation License
"""

import os, urllib, string, inspect
import hmac,hashlib,base64
from time import strftime, gmtime
from xml.dom import minidom

__author__ = "Kun Xi < kunxi@kunxi.org >"
__version__ = "0.2.0"
__license__ = "Python Software Foundation"


"""Package-wide variables:
"""
LICENSE_KEY = None;
HTTP_PROXY = None
LOCALE = "us"
VERSION = "2009-07-12"

__supportedLocales = {
                None : "ecs.amazonaws.com",
                "us" : "ecs.amazonaws.com",
                "uk" : "ecs.amazonaws.co.uk",
                "de" : "ecs.amazonaws.de",
                "jp" : "ecs.amazonaws.jp",
                "fr" : "ecs.amazonaws.fr",
                "ca" : "ecs.amazonaws.ca"
        }

__licenseKeys = (
        (lambda key: key),
        (lambda key: LICENSE_KEY),
        (lambda key: os.environ.get('AWS_LICENSE_KEY', None))
   )

__secretKeys = (
        (lambda key: key),
        (lambda key: SECRET_KEY),
        (lambda key: os.environ.get('AWS_SECRET_KEY', None))
   )

class AWSException(Exception) :
    '''Base class for all AWS exceptions'''
    pass

class NoLicenseKey(AWSException) : pass
class NoSecretKey(AWSException) : pass
class BadLocale(AWSException) : pass
# Runtime exception
class ExactParameterRequirement(AWSException): pass
class ExceededMaximumParameterValues(AWSException): pass
class InsufficientParameterValues(AWSException): pass
class InternalError(AWSException): pass
class InvalidEnumeratedParameter(AWSException): pass
class InvalidISO8601Time(AWSException): pass
class InvalidOperationForMarketplace(AWSException): pass
class InvalidOperationParameter(AWSException): pass
class InvalidParameterCombination(AWSException): pass
class InvalidParameterValue(AWSException): pass
class InvalidResponseGroup(AWSException): pass
class InvalidServiceParameter(AWSException): pass
class InvalidSubscriptionId(AWSException): pass
class InvalidXSLTAddress(AWSException): pass
class MaximumParameterRequirement(AWSException): pass
class MinimumParameterRequirement(AWSException): pass
class MissingOperationParameter(AWSException): pass
class MissingParameterCombination(AWSException): pass
class MissingParameters(AWSException): pass
class MissingParameterValueCombination(AWSException): pass
class MissingServiceParameter(AWSException): pass
class ParameterOutOfRange(AWSException): pass
class ParameterRepeatedInRequest(AWSException): pass
class RestrictedParameterValueCombination(AWSException): pass
class XSLTTransformationError(AWSException): pass

class Bag :
    '''Wrapper class for DOM nodes'''
    pass



# Utilities functions
def setLocale(locale):
    """set locale

    if unsupported locale is set, BadLocale is raised."""
    global LOCALE
    if not __supportedLocales.has_key(locale):
        raise BadLocale, ("Unsupported locale. Locale must be one of: %s" %
                ', '.join([x for x in __supportedLocales.keys() if x]))
    LOCALE = locale


def getLocale():
    """get locale"""
    return LOCALE


def setLicenseKey(license_key=None):
    """set license key

    license key can come from any number of locations;
    see module docs for search order.
    if no license key is specified, BadLocale is raised."""

    global LICENSE_KEY
    for get in __licenseKeys:
        rc = get(license_key)
        if rc:
            LICENSE_KEY = rc;
            return;
    raise NoLicenseKey, ("Please get the license key from  http://www.amazon.com/webservices")


def getLicenseKey():
    """get license key

    if no license key is specified, BadLocale is raised."""

    if not LICENSE_KEY:
        raise NoLicenseKey, ("Please get the license key from  http://www.amazon.com/webservices")
    return LICENSE_KEY


def setSecretKey(secret_key=None):
    """set secret key

From Aug 2009 Amazon requires all api request to be signed with a secret key.
    secret key can come from any number of locations;
    see module docs for search order.
    if no secret key is specified, error is raised."""

    global SECRET_KEY
    for get in __secretKeys:
        rc = get(secret_key)
        if rc:
            SECRET_KEY = rc;
            return;
    raise NoSecretKey, ("Please get the secret key from  http://aws.amazon.com/")


def getSecretKey():
    """get secret key

    if no secret key is specified, NoSecretKey is raised."""

    if not SECRET_KEY:
        raise NoSecretKey, ("Please get the secret key from  http://aws.amazon.com/")
    return SECRET_KEY


def getVersion():
    """get version"""
    return VERSION


def buildRequest(argv):
    """Build the REST request URL from argv,

    all key, value pairs in argv are quoted."""
    url = "https://" + __supportedLocales[getLocale()] + "/onca/xml?"
    argv['Service'] = 'AWSECommerceService' #add Service to url param to argv so it canbe sorted
    argv['Timestamp'] = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()) # add Timestamp url param to argv, this is required when using a signature
    sortedArgv = argv.items()
    sortedArgv.sort() #args must be sorted so both you and amazon generate the same hashed signature
    args = '&'.join(['%s=%s' % (k,urllib.quote(str(v))) for (k,v) in sortedArgv if v])
    paramsToEncode = '&'.join(['%s=%s' % (k,urllib.quote(str(v))) for (k,v) in sortedArgv if v])
    stringToSign = "GET"+"\n"+__supportedLocales[getLocale()]+"\n"+"/onca/xml"+"\n"+paramsToEncode.encode('utf-8')
    signature = urllib.quote(base64.b64encode(hmac.new(getSecretKey(), stringToSign, hashlib.sha256).digest()))
    return url + '&'.join(['%s=%s' % (k,urllib.quote(str(v))) for (k,v) in sortedArgv if v])+"&Signature="+signature


def buildException(els):
    """Build the exception from the returned DOM node

    Only the first exception is raised."""

    error = els[0]
    class_name = error.childNodes[0].firstChild.data[4:]
    msg = error.childNodes[1].firstChild.data

    e = globals()[ class_name ](msg)
    return e


def query(url):
    """Send the query url and return the DOM

    Exception is raised if there is errors"""
    u = urllib.FancyURLopener(HTTP_PROXY)
    usock = u.open(url)
    dom = minidom.parse(usock)
    usock.close()

    errors = dom.getElementsByTagName('Error')
    if errors:
        e = buildException(errors)
        raise e
    return dom


def rawObject(XMLSearch, arguments, kwItem, plugins=None):
    '''Return a unique object'''

    dom = XMLSearch(** arguments)
    return unmarshal(dom.getElementsByTagName(kwItem).item(0), plugins)


def rawIterator(XMLSearch, arguments, kwItems, plugins=None):
    '''Return list of objects'''

    dom = XMLSearch(** arguments)
    items = unmarshal(dom.getElementsByTagName(kwItems).item(0), plugins, wrappedIterator())
    return items

class wrappedIterator(list):
    '''Return inherited list object,

    we may add more attributes later'''

    pass


class pagedIterator:
    '''Return a page-based iterator'''

    def __init__(self, XMLSearch, arguments, kwPage, kwItems, plugins=None):
        """XMLSearch: the callback function that returns the DOM
        arguments: the arguments for XMLSearch
        kwPage, kwItems: Tag name of Page, Items to organize the object
        plugins: please check unmarshal
        """
        self.__search = XMLSearch
        self.__arguments = arguments
        self.__keywords ={'Page':kwPage, 'Items':kwItems}
        self.__plugins = plugins
        self.__page = arguments[kwPage] or 1
        self.__index = 0
        dom = self.__search(** self.__arguments)
        self.__items = unmarshal(dom.getElementsByTagName(kwItems).item(0), plugins, wrappedIterator())
        try:
            self.__len = int(dom.getElementsByTagName("TotalResults").item(0).firstChild.data)
        except AttributeError, e:
            self.__len = len(self.__items)

    def __len__(self):
        return self.__len

    def __iter__(self):
        return self

    def next(self):
        if self.__index < self.__len:
            self.__index = self.__index + 1
            return self.__getitem__(self.__index-1)
        else:
            raise StopIteration

    def __getitem__(self, key):
        try:
            num = int(key)
        except TypeError, e:
            raise e

        if num >= self.__len:
            raise IndexError

        page = num / 10 + 1
        index = num % 10
        if page != self.__page:
            self.__arguments[self.__keywords['Page']] = page
            dom = self.__search(** self.__arguments)
            self.__items = unmarshal(dom.getElementsByTagName(self.__keywords['Items']).item(0), self.__plugins, wrappedIterator())
            self.__page = page

        return self.__items[index]


def unmarshal(element, plugins=None, rc=None):
    """Return the Bag object with attributes populated using DOM element

    element: the root of the DOM element we are interested in
    plugins: callback functions to fine-tune the object structure
    rc: parent object, used in the recursive call

    This core function is inspired by Mark Pilgrim (f8dy@diveintomark.org)
    with some enhancement. Each node.tagName is evalued by plugins' callback
    functions:

            if plugins['isBypassed'] is true:
                    this elment is ignored
            if plugins['isPivoted'] is true:
                    this children of this elment is moved to grandparents
                    this object is ignored.
            if plugins['isCollective'] is true:
                    this elment is mapped to []
            if plugins['isCollected'] is true:
                    this children of elment is appended to grandparent
                    this object is ignored.
    """

    if(rc == None):
        rc = Bag()

    if(plugins == None):
        plugins = {}

    childElements = [e for e in element.childNodes if isinstance(e, minidom.Element)]

    if childElements:
        for child in childElements:
            key = child.tagName
            if hasattr(rc, key):
                if type(getattr(rc, key)) <> type([]):
                    setattr(rc, key, [getattr(rc, key)])
                setattr(rc, key, getattr(rc, key) + [unmarshal(child, plugins)])
            elif isinstance(child, minidom.Element):
                if plugins.has_key('isPivoted') and plugins['isPivoted'](child.tagName):
                    unmarshal(child, plugins, rc)
                elif plugins.has_key('isBypassed') and plugins['isBypassed'](child.tagName):
                    continue
                elif plugins.has_key('isCollective') and plugins['isCollective'](child.tagName):
                    setattr(rc, key, unmarshal(child, plugins, wrappedIterator([])))
                elif plugins.has_key('isCollected') and plugins['isCollected'](child.tagName):
                    rc.append(unmarshal(child, plugins))
                else:
                    setattr(rc, key, unmarshal(child, plugins))
    else:
        rc = "".join([e.data for e in element.childNodes if isinstance(e, minidom.Text)])
    return rc



# User interfaces

def ItemLookup(ItemId, IdType=None, SearchIndex=None, MerchantId=None, Condition=None, DeliveryMethod=None, ISPUPostalCode=None, OfferPage=None, ReviewPage=None, VariationPage=None, ResponseGroup=None, AWSAccessKeyId=None):
    '''ItemLookup in ECS'''

    argv = inspect.getargvalues(inspect.currentframe())[-1]
    plugins = {'isPivoted': lambda x: x == 'ItemAttributes',
            'isCollective': lambda x: x == 'Items',
            'isCollected': lambda x: x == 'Item'}
    return pagedIterator(XMLItemLookup, argv, 'OfferPage', 'Items', plugins)


def XMLItemLookup(ItemId, IdType=None, SearchIndex=None, MerchantId=None, Condition=None, DeliveryMethod=None, ISPUPostalCode=None, OfferPage=None, ReviewPage=None, VariationPage=None, ResponseGroup=None, AWSAccessKeyId=None):
    '''DOM representation of ItemLookup in ECS'''

    Operation = "ItemLookup"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    return query(buildRequest(argv))


def ItemSearch(Keywords, SearchIndex="Blended", Availability=None, Title=None, Power=None, BrowseNode=None, Artist=None, Author=None, Actor=None, Director=None, AudienceRating=None, Manufacturer=None, MusicLabel=None, Composer=None, Publisher=None, Brand=None, Conductor=None, Orchestra=None, TextStream=None, ItemPage=None, Sort=None, City=None, Cuisine=None, Neighborhood=None, MinimumPrice=None, MaximumPrice=None, MerchantId=None, Condition=None, DeliveryMethod=None, ResponseGroup=None, AWSAccessKeyId=None, AssociateTag=None):
    '''ItemSearch in ECS'''

    argv = inspect.getargvalues(inspect.currentframe())[-1]
    plugins = {'isPivoted': lambda x: x == 'ItemAttributes',
            'isCollective': lambda x: x == 'Items',
            'isCollected': lambda x: x == 'Item'}
    return pagedIterator(XMLItemSearch, argv, "ItemPage", 'Items', plugins)


def XMLItemSearch(Keywords, SearchIndex="Blended", Availability=None, Title=None, Power=None, BrowseNode=None, Artist=None, Author=None, Actor=None, Director=None, AudienceRating=None, Manufacturer=None, MusicLabel=None, Composer=None, Publisher=None, Brand=None, Conductor=None, Orchestra=None, TextStream=None, ItemPage=None, Sort=None, City=None, Cuisine=None, Neighborhood=None, MinimumPrice=None, MaximumPrice=None, MerchantId=None, Condition=None, DeliveryMethod=None, ResponseGroup=None, AWSAccessKeyId=None, AssociateTag=None):
    '''DOM representation of ItemSearch in ECS'''

    Operation = "ItemSearch"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    return query(buildRequest(argv))


def SimilarityLookup(ItemId, SimilarityType=None, MerchantId=None, Condition=None, DeliveryMethod=None, ResponseGroup=None, AWSAccessKeyId=None):
    '''SimilarityLookup in ECS'''

    argv = inspect.getargvalues(inspect.currentframe())[-1]
    plugins = {'isPivoted': lambda x: x == 'ItemAttributes',
            'isCollective': lambda x: x == 'Items',
            'isCollected': lambda x: x == 'Item'}
    return rawIterator(XMLSimilarityLookup, argv, 'Items', plugins)


def XMLSimilarityLookup(ItemId, SimilarityType=None, MerchantId=None, Condition=None, DeliveryMethod=None, ResponseGroup=None, AWSAccessKeyId=None):
    '''DOM representation of SimilarityLookup in ECS'''

    Operation = "SimilarityLookup"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    return query(buildRequest(argv))


# List Operations

def ListLookup(ListType, ListId, ProductPage=None, ProductGroup=None, Sort=None, MerchantId=None, Condition=None, DeliveryMethod=None, ResponseGroup=None, AWSAccessKeyId=None):
    '''ListLookup in ECS'''

    argv = inspect.getargvalues(inspect.currentframe())[-1]
    plugins = {'isPivoted': lambda x: x == 'ItemAttributes',
            'isCollective': lambda x: x == 'Lists',
            'isCollected': lambda x: x == 'List'}
    return pagedIterator(XMLListLookup, argv, 'ProductPage', 'Lists', plugins)


def XMLListLookup(ListType, ListId, ProductPage=None, ProductGroup=None, Sort=None, MerchantId=None, Condition=None, DeliveryMethod=None, ResponseGroup=None, AWSAccessKeyId=None):
    '''DOM representation of ListLookup in ECS'''

    Operation = "ListLookup"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    return query(buildRequest(argv))


def ListSearch(ListType, Name=None, FirstName=None, LastName=None, Email=None, City=None, State=None, ListPage=None, ResponseGroup=None, AWSAccessKeyId=None):
    '''ListSearch in ECS'''

    argv = inspect.getargvalues(inspect.currentframe())[-1]
    plugins = {'isPivoted': lambda x: x == 'ItemAttributes',
            'isCollective': lambda x: x == 'Lists',
            'isCollected': lambda x: x == 'List'}
    return pagedIterator(XMLListSearch, argv, 'ListPage', 'Lists', plugins)


def XMLListSearch(ListType, Name=None, FirstName=None, LastName=None, Email=None, City=None, State=None, ListPage=None, ResponseGroup=None, AWSAccessKeyId=None):
    '''DOM representation of ListSearch in ECS'''

    Operation = "ListSearch"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    return query(buildRequest(argv))


#Remote Shopping Cart Operations
def CartCreate(Items, Quantities, ResponseGroup=None, AWSAccessKeyId=None):
    '''CartCreate in ECS'''

    argv = inspect.getargvalues(inspect.currentframe())[-1]
    return __cartOperation(XMLCartCreate, argv)


def XMLCartCreate(Items, Quantities, ResponseGroup=None, AWSAccessKeyId=None):
    '''DOM representation of CartCreate in ECS'''

    Operation = "CartCreate"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    for x in ('Items', 'Quantities'):
        del argv[x]

    __fromListToItems(argv, Items, 'ASIN', Quantities)
    return query(buildRequest(argv))


def CartAdd(Cart, Items, Quantities, ResponseGroup=None, AWSAccessKeyId=None):
    '''CartAdd in ECS'''

    argv = inspect.getargvalues(inspect.currentframe())[-1]
    return __cartOperation(XMLCartAdd, argv)


def XMLCartAdd(Cart, Items, Quantities, ResponseGroup=None, AWSAccessKeyId=None):
    '''DOM representation of CartAdd in ECS'''

    Operation = "CartAdd"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    CartId = Cart.CartId
    HMAC = Cart.HMAC
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    for x in ('Items', 'Cart', 'Quantities'):
        del argv[x]

    __fromListToItems(argv, Items, 'ASIN', Quantities)
    return query(buildRequest(argv))


def CartGet(Cart, ResponseGroup=None, AWSAccessKeyId=None):
    '''CartGet in ECS'''
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    return __cartOperation(XMLCartGet, argv)


def XMLCartGet(Cart, ResponseGroup=None, AWSAccessKeyId=None):
    '''DOM representation of CartGet in ECS'''

    Operation = "CartGet"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    CartId = Cart.CartId
    HMAC = Cart.HMAC
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    del argv['Cart']
    return query(buildRequest(argv))


def CartModify(Cart, Items, Actions, ResponseGroup=None, AWSAccessKeyId=None):
    '''CartModify in ECS'''

    argv = inspect.getargvalues(inspect.currentframe())[-1]
    return __cartOperation(XMLCartModify, argv)


def XMLCartModify(Cart, Items, Actions, ResponseGroup=None, AWSAccessKeyId=None):
    '''DOM representation of CartModify in ECS'''
    Operation = "CartModify"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    CartId = Cart.CartId
    HMAC = Cart.HMAC
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    for x in ('Cart', 'Items', 'Actions'):
        del argv[x]

    __fromListToItems(argv, Items, 'CartItemId', Actions)
    return query(buildRequest(argv))


def CartClear(Cart, ResponseGroup=None, AWSAccessKeyId=None):
    '''CartClear in ECS'''
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    return __cartOperation(XMLCartClear, argv)


def XMLCartClear(Cart, ResponseGroup=None, AWSAccessKeyId=None):
    '''DOM representation of CartClear in ECS'''

    Operation = "CartClear"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    CartId = Cart.CartId
    HMAC = Cart.HMAC
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    del argv['Cart']

    return query(buildRequest(argv))


def __fromListToItems(argv, items, id, actions):
    '''Convert list to AWS REST arguments'''

    for i in range(len(items)):
        argv["Item.%d.%s" % (i+1, id)] = getattr(items[i], id);
        action = actions[i]
        if isinstance(action, int):
            argv["Item.%d.Quantity" % (i+1)] = action
        else:
            argv["Item.%d.Action" % (i+1)] = action


def __cartOperation(XMLSearch, arguments):
    '''Generic cart operation'''

    plugins = {'isBypassed': lambda x: x == 'Request',
            'isCollective': lambda x: x in ('CartItems', 'SavedForLaterItems'),
            'isCollected': lambda x: x in ('CartItem', 'SavedForLaterItem') }
    return rawObject(XMLSearch, arguments, 'Cart', plugins)


# Seller Operation
def SellerLookup(Sellers, ResponseGroup=None, AWSAccessKeyId=None):
    '''SellerLookup in AWS'''

    argv = inspect.getargvalues(inspect.currentframe())[-1]
    plugins = {'isBypassed': lambda x: x == 'Request',
            'isCollective': lambda x: x == 'Sellers',
            'isCollected': lambda x: x == 'Seller'}
    return rawIterator(XMLSellerLookup, argv, 'Sellers', plugins)


def XMLSellerLookup(Sellers, ResponseGroup=None, AWSAccessKeyId=None):
    '''DOM representation of SellerLookup in AWS'''

    Operation = "SellerLookup"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    SellerId = ",".join(Sellers)
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    del argv['Sellers']
    return query(buildRequest(argv))


def SellerListingLookup(SellerId, Id, IdType="Listing", ResponseGroup=None, AWSAccessKeyId=None):
    '''SellerListingLookup in AWS

    Notice: although the repsonse includes TotalPage, TotalResults,
    there is no ListingPage in the request, so we have to use rawIterator
    instead of pagedIterator. Hope Amazaon would fix this inconsistance'''

    argv = inspect.getargvalues(inspect.currentframe())[-1]
    plugins = {'isBypassed': lambda x: x == 'Request',
            'isCollective': lambda x: x == 'SellerListings',
            'isCollected': lambda x: x == 'SellerListing'}
    return rawIterator(XMLSellerListingLookup, argv, "SellerListings", plugins)


def XMLSellerListingLookup(SellerId, Id, IdType="Listing", ResponseGroup=None, AWSAccessKeyId=None):
    '''DOM representation of SellerListingLookup in AWS'''

    Operation = "SellerListingLookup"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    return query(buildRequest(argv))


def SellerListingSearch(SellerId, Title=None, Sort=None, ListingPage=None, OfferStatus=None, ResponseGroup=None, AWSAccessKeyId=None):
    '''SellerListingSearch in AWS'''

    argv = inspect.getargvalues(inspect.currentframe())[-1]
    plugins = {'isBypassed': lambda x: x == 'Request',
            'isCollective': lambda x: x == 'SellerListings',
            'isCollected': lambda x: x == 'SellerListing'}
    return pagedIterator(XMLSellerListingSearch, argv, "ListingPage", "SellerListings", plugins)


def XMLSellerListingSearch(SellerId, Title=None, Sort=None, ListingPage=None, OfferStatus=None, ResponseGroup=None, AWSAccessKeyId=None):
    '''DOM representation of SellerListingSearch in AWS'''

    Operation = "SellerListingSearch"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    return query(buildRequest(argv))


def CustomerContentSearch(Name=None, Email=None, CustomerPage=1, ResponseGroup=None, AWSAccessKeyId=None):
    '''CustomerContentSearch in AWS'''

    argv = inspect.getargvalues(inspect.currentframe())[-1]
    plugins = {'isBypassed': lambda x: x == 'Request',
            'isCollective': lambda x: x in ('Customers', 'CustomerReviews'),
            'isCollected': lambda x: x in ('Customer', 'Review')}
    return rawIterator(XMLCustomerContentSearch, argv, 'Customers', plugins)


def XMLCustomerContentSearch(Name=None, Email=None, CustomerPage=1, ResponseGroup=None, AWSAccessKeyId=None):
    '''DOM representation of CustomerContentSearch in AWS'''

    Operation = "CustomerContentSearch"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    for x in ('Name', 'Email'):
        if not argv[x]:
            del argv[x]
    return query(buildRequest(argv))


def CustomerContentLookup(CustomerId, ReviewPage=1, ResponseGroup=None, AWSAccessKeyId=None):
    '''CustomerContentLookup in AWS'''

    argv = inspect.getargvalues(inspect.currentframe())[-1]
    plugins = {'isBypassed': lambda x: x == 'Request',
            'isCollective': lambda x: x == 'Customers',
            'isCollected': lambda x: x == 'Customer'}
    return rawIterator(XMLCustomerContentLookup, argv, 'Customers', plugins)


def XMLCustomerContentLookup(CustomerId, ReviewPage=1, ResponseGroup=None, AWSAccessKeyId=None):
    '''DOM representation of CustomerContentLookup in AWS'''

    Operation = "CustomerContentLookup"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    return query(buildRequest(argv))


# BrowseNode
def BrowseNodeLookup(BrowseNodeId, ResponseGroup=None, AWSAccessKeyId=None):
    '''BrowseNodeLookup in AWS'''

    argv = inspect.getargvalues(inspect.currentframe())[-1]
    plugins = {'isBypassed': lambda x: x == 'Request',
            'isCollective': lambda x: x == 'Children',
            'isCollected': lambda x: x == 'BrowseNode'}
    return rawIterator(XMLBrowseNodeLookup, argv, 'BrowseNodes', plugins)


def XMLBrowseNodeLookup(BrowseNodeId, ResponseGroup=None, AWSAccessKeyId=None):
    '''DOM representation of BrowseNodeLookup in AWS'''

    Operation = "BrowseNodeLookup"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    return query(buildRequest(argv))


# Help
def Help(HelpType, About, ResponseGroup=None, AWSAccessKeyId=None):
    '''Help in AWS'''

    argv = inspect.getargvalues(inspect.currentframe())[-1]
    plugins = {'isBypassed': lambda x: x == 'Request',
            'isCollective': lambda x: x in ('RequiredParameters',
                    'AvailableParameters', 'DefaultResponseGroups',
                    'AvailableResponseGroups'),
            'isCollected': lambda x: x in ('Parameter', 'ResponseGroup') }
    return rawObject(XMLHelp, argv, 'Information', plugins)


def XMLHelp(HelpType, About, ResponseGroup=None, AWSAccessKeyId=None):
    '''DOM representation of Help in AWS'''

    Operation = "Help"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    return query(buildRequest(argv))


# Transaction
def TransactionLookup(TransactionId, ResponseGroup=None, AWSAccessKeyId=None):
    '''TransactionLookup in AWS'''

    argv = inspect.getargvalues(inspect.currentframe())[-1]
    plugins = {'isBypassed': lambda x: x == 'Request',
            'isCollective': lambda x: x in ('Transactions', 'TransactionItems', 'Shipments'),
            'isCollected': lambda x: x in ('Transaction', 'TransactionItem', 'Shipment')}

    return rawIterator(XMLTransactionLookup, argv, 'Transactions', plugins)


def XMLTransactionLookup(TransactionId, ResponseGroup=None, AWSAccessKeyId=None):
    '''DOM representation of TransactionLookup in AWS'''

    Operation = "TransactionLookup"
    AWSAccessKeyId = AWSAccessKeyId or LICENSE_KEY
    argv = inspect.getargvalues(inspect.currentframe())[-1]
    return query(buildRequest(argv))