File: utils.py

package info (click to toggle)
googleplay-api 0.4.4%2Bgit20200310-2
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 3,628 kB
  • sloc: python: 836; sh: 22; makefile: 7
file content (78 lines) | stat: -rw-r--r-- 1,866 bytes parent folder | download | duplicates (2)
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
import struct
import sys
from google.protobuf.message import Message
from google.protobuf.json_format import MessageToDict
from . import googleplay_pb2

def parseProtobufObj(obj):
    return MessageToDict(obj, False, False, False)

def readInt(byteArray, start):
    """Read the byte array, starting from *start* position,
    as an 32-bit unsigned integer"""
    return struct.unpack("!L", byteArray[start:][0:4])[0]


def toBigInt(byteArray):
    """Convert the byte array to a BigInteger"""
    array = byteArray[::-1]  # reverse array
    out = 0
    for key, value in enumerate(array):
        decoded = struct.unpack("B", bytes([value]))[0]
        out = out | decoded << key * 8
    return out

def hasPrefetch(obj):
    try:
        return len(obj.preFetch) > 0
    except ValueError:
        return False

def hasListResponse(obj):
    try:
        return obj.HasField('listResponse')
    except ValueError:
        return False

def hasSearchResponse(obj):
    try:
        return obj.HasField('searchResponse')
    except ValueError:
        return False

def hasCluster(obj):
    try:
        return obj.HasField('cluster')
    except ValueError:
        return False

def hasTosContent(tocResponse):
    try:
        return tocResponse.HasField('tosContent')
    except ValueError:
        return False

def hasTosToken(tocResponse):
    try:
        return tocResponse.HasField('tosToken')
    except ValueError:
        return False

def hasCookie(tocResponse):
    try:
        return tocResponse.HasField('cookie')
    except ValueError:
        return False

def hasDoc(obj):
    # doc an be a single object or a
    # RepeatedComposite object
    try:
        existance = obj.HasField('doc')
    except ValueError:
        try:
            existance = len(obj.doc) > 0
        except TypeError:
            existance = False

    return existance