This file is indexed.

/usr/share/pyshared/gdata/finance/service.py is in python-gdata 2.0.14-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
#!/usr/bin/python
#
# Copyright (C) 2009 Tan Swee Heng
#
# 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.


"""Classes to interact with the Google Finance server."""


__author__ = 'thesweeheng@gmail.com'


import gdata.service
import gdata.finance
import atom


class PortfolioQuery(gdata.service.Query):
  """A query object for the list of a user's portfolios."""

  def returns(self):
    return self.get('returns', False)

  def set_returns(self, value):
    if value is 'true' or value is True:
      self['returns'] = 'true'

  returns = property(returns, set_returns, doc="The returns query parameter")

  def positions(self):
    return self.get('positions', False)

  def set_positions(self, value):
    if value is 'true' or value is True:
      self['positions'] = 'true'

  positions = property(positions, set_positions,
      doc="The positions query parameter")


class PositionQuery(gdata.service.Query):
  """A query object for the list of a user's positions in a portfolio."""

  def returns(self):
    return self.get('returns', False)

  def set_returns(self, value):
    if value is 'true' or value is True:
      self['returns'] = 'true'

  returns = property(returns, set_returns,
      doc="The returns query parameter")

  def transactions(self):
    return self.get('transactions', False)

  def set_transactions(self, value):
    if value is 'true' or value is True:
      self['transactions'] = 'true'

  transactions = property(transactions, set_transactions,
      doc="The transactions query parameter")


class FinanceService(gdata.service.GDataService):

  def __init__(self, email=None, password=None, source=None,
               server='finance.google.com', **kwargs):
    """Creates a client for the Finance service.

    Args:
      email: string (optional) The user's email address, used for
          authentication.
      password: string (optional) The user's password.
      source: string (optional) The name of the user's application.
      server: string (optional) The name of the server to which a connection
          will be opened. Default value: 'finance.google.com'.
      **kwargs: The other parameters to pass to gdata.service.GDataService
          constructor.
    """
    gdata.service.GDataService.__init__(self,
        email=email, password=password, service='finance', server=server,
        **kwargs)

  def GetPortfolioFeed(self, query=None):
    uri = '/finance/feeds/default/portfolios'
    if query:
      uri = PortfolioQuery(feed=uri, params=query).ToUri()
    return self.Get(uri, converter=gdata.finance.PortfolioFeedFromString)

  def GetPositionFeed(self, portfolio_entry=None, portfolio_id=None,
      query=None):
    """
    Args:
      portfolio_entry: PortfolioEntry (optional; see Notes)
      portfolio_id: string (optional; see Notes) This may be obtained
          from a PortfolioEntry's portfolio_id attribute.
      query: PortfolioQuery (optional)

    Notes:
      Either a PortfolioEntry OR a portfolio ID must be provided.
    """
    if portfolio_entry:
      uri = portfolio_entry.GetSelfLink().href + '/positions'
    elif portfolio_id:
      uri = '/finance/feeds/default/portfolios/%s/positions' % portfolio_id
    if query:
      uri = PositionQuery(feed=uri, params=query).ToUri()
    return self.Get(uri, converter=gdata.finance.PositionFeedFromString)

  def GetTransactionFeed(self, position_entry=None,
      portfolio_id=None, ticker_id=None):
    """
    Args:
      position_entry: PositionEntry (optional; see Notes)
      portfolio_id: string (optional; see Notes) This may be obtained
          from a PortfolioEntry's portfolio_id attribute.
      ticker_id: string (optional; see Notes) This may be obtained from
          a PositionEntry's ticker_id attribute. Alternatively it can
          be constructed using the security's exchange and symbol,
          e.g. 'NASDAQ:GOOG'

    Notes:
      Either a PositionEntry OR (a portfolio ID AND ticker ID) must
      be provided.
    """
    if position_entry:
      uri = position_entry.GetSelfLink().href + '/transactions'
    elif portfolio_id and ticker_id:
      uri = '/finance/feeds/default/portfolios/%s/positions/%s/transactions' \
          % (portfolio_id, ticker_id)
    return self.Get(uri, converter=gdata.finance.TransactionFeedFromString)

  def GetPortfolio(self, portfolio_id=None, query=None):
    uri = '/finance/feeds/default/portfolios/%s' % portfolio_id
    if query:
      uri = PortfolioQuery(feed=uri, params=query).ToUri()
    return self.Get(uri, converter=gdata.finance.PortfolioEntryFromString)

  def AddPortfolio(self, portfolio_entry=None):
    uri = '/finance/feeds/default/portfolios'
    return self.Post(portfolio_entry, uri,
        converter=gdata.finance.PortfolioEntryFromString)

  def UpdatePortfolio(self, portfolio_entry=None):
    uri = portfolio_entry.GetEditLink().href
    return self.Put(portfolio_entry, uri,
        converter=gdata.finance.PortfolioEntryFromString)

  def DeletePortfolio(self, portfolio_entry=None):
    uri = portfolio_entry.GetEditLink().href
    return self.Delete(uri)

  def GetPosition(self, portfolio_id=None, ticker_id=None, query=None):
    uri = '/finance/feeds/default/portfolios/%s/positions/%s' \
        % (portfolio_id, ticker_id)
    if query:
      uri = PositionQuery(feed=uri, params=query).ToUri()
    return self.Get(uri, converter=gdata.finance.PositionEntryFromString)

  def DeletePosition(self, position_entry=None,
      portfolio_id=None, ticker_id=None, transaction_feed=None):
    """A position is deleted by deleting all its transactions.

    Args:
      position_entry: PositionEntry (optional; see Notes)
      portfolio_id: string (optional; see Notes) This may be obtained
          from a PortfolioEntry's portfolio_id attribute.
      ticker_id: string (optional; see Notes) This may be obtained from
          a PositionEntry's ticker_id attribute. Alternatively it can
          be constructed using the security's exchange and symbol,
          e.g. 'NASDAQ:GOOG'
      transaction_feed: TransactionFeed (optional; see Notes)

    Notes:
      Either a PositionEntry OR (a portfolio ID AND ticker ID) OR
      a TransactionFeed must be provided.
    """
    if transaction_feed:
      feed = transaction_feed
    else:
      if position_entry:
        feed = self.GetTransactionFeed(position_entry=position_entry)
      elif portfolio_id and ticker_id:
        feed = self.GetTransactionFeed(
            portfolio_id=portfolio_id, ticker_id=ticker_id)
    for txn in feed.entry:
      self.DeleteTransaction(txn)
    return True

  def GetTransaction(self, portfolio_id=None, ticker_id=None,
      transaction_id=None):
    uri = '/finance/feeds/default/portfolios/%s/positions/%s/transactions/%s' \
        % (portfolio_id, ticker_id, transaction_id)
    return self.Get(uri, converter=gdata.finance.TransactionEntryFromString)

  def AddTransaction(self, transaction_entry=None, transaction_feed = None,
      position_entry=None, portfolio_id=None, ticker_id=None):
    """
    Args:
      transaction_entry: TransactionEntry (required)
      transaction_feed: TransactionFeed (optional; see Notes)
      position_entry: PositionEntry (optional; see Notes)
      portfolio_id: string (optional; see Notes) This may be obtained
          from a PortfolioEntry's portfolio_id attribute.
      ticker_id: string (optional; see Notes) This may be obtained from
          a PositionEntry's ticker_id attribute. Alternatively it can
          be constructed using the security's exchange and symbol,
          e.g. 'NASDAQ:GOOG'

    Notes:
      Either a TransactionFeed OR a PositionEntry OR (a portfolio ID AND
      ticker ID) must be provided.
    """
    if transaction_feed:
      uri = transaction_feed.GetPostLink().href
    elif position_entry:
      uri = position_entry.GetSelfLink().href + '/transactions'
    elif portfolio_id and ticker_id:
      uri = '/finance/feeds/default/portfolios/%s/positions/%s/transactions' \
          % (portfolio_id, ticker_id)
    return self.Post(transaction_entry, uri,
        converter=gdata.finance.TransactionEntryFromString)

  def UpdateTransaction(self, transaction_entry=None):
    uri = transaction_entry.GetEditLink().href
    return self.Put(transaction_entry, uri,
        converter=gdata.finance.TransactionEntryFromString)

  def DeleteTransaction(self, transaction_entry=None):
    uri = transaction_entry.GetEditLink().href
    return self.Delete(uri)