repo_name
stringlengths 6
100
| path
stringlengths 4
294
| copies
stringclasses 981
values | size
stringlengths 4
6
| content
stringlengths 606
896k
| license
stringclasses 15
values | input_ids
listlengths 1.02k
1.02k
| labels
listlengths 1.02k
1.02k
| attention_mask
listlengths 1.02k
1.02k
|
|---|---|---|---|---|---|---|---|---|
bhargav2408/python-for-android
|
python3-alpha/extra_modules/gdata/spreadsheet/service.py
|
47
|
16862
|
#!/usr/bin/python
#
# Copyright (C) 2007 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.
"""SpreadsheetsService extends the GDataService to streamline Google
Spreadsheets operations.
SpreadsheetService: Provides methods to query feeds and manipulate items.
Extends GDataService.
DictionaryToParamList: Function which converts a dictionary into a list of
URL arguments (represented as strings). This is a
utility function used in CRUD operations.
"""
__author__ = 'api.laurabeth@gmail.com (Laura Beth Lincoln)'
import gdata
import atom.service
import gdata.service
import gdata.spreadsheet
import atom
class Error(Exception):
"""Base class for exceptions in this module."""
pass
class RequestError(Error):
pass
class SpreadsheetsService(gdata.service.GDataService):
"""Client for the Google Spreadsheets service."""
def __init__(self, email=None, password=None, source=None,
server='spreadsheets.google.com', additional_headers=None,
**kwargs):
"""Creates a client for the Google Spreadsheets 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: 'spreadsheets.google.com'.
**kwargs: The other parameters to pass to gdata.service.GDataService
constructor.
"""
gdata.service.GDataService.__init__(
self, email=email, password=password, service='wise', source=source,
server=server, additional_headers=additional_headers, **kwargs)
def GetSpreadsheetsFeed(self, key=None, query=None, visibility='private',
projection='full'):
"""Gets a spreadsheets feed or a specific entry if a key is defined
Args:
key: string (optional) The spreadsheet key defined in /ccc?key=
query: DocumentQuery (optional) Query parameters
Returns:
If there is no key, then a SpreadsheetsSpreadsheetsFeed.
If there is a key, then a SpreadsheetsSpreadsheet.
"""
base_uri = 'https://%s/feeds/spreadsheets' % self.server
uri = ('%s/%s/%s'
% (base_uri, visibility, projection))
if key is not None:
uri = '%s/%s' % (uri, key)
if query != None:
query.feed = base_uri
query.visibility = visibility
query.projection = projection
uri = query.ToUri()
if key:
return self.Get(uri,
converter=gdata.spreadsheet.SpreadsheetsSpreadsheetFromString)
else:
return self.Get(uri,
converter=gdata.spreadsheet.SpreadsheetsSpreadsheetsFeedFromString)
def GetWorksheetsFeed(self, key, wksht_id=None, query=None,
visibility='private', projection='full'):
"""Gets a worksheets feed or a specific entry if a wksht is defined
Args:
key: string The spreadsheet key defined in /ccc?key=
wksht_id: string (optional) The id for a specific worksheet entry
query: DocumentQuery (optional) Query parameters
Returns:
If there is no wksht_id, then a SpreadsheetsWorksheetsFeed.
If there is a wksht_id, then a SpreadsheetsWorksheet.
"""
uri = ('https://%s/feeds/worksheets/%s/%s/%s'
% (self.server, key, visibility, projection))
if wksht_id != None:
uri = '%s/%s' % (uri, wksht_id)
if query != None:
query.feed = uri
uri = query.ToUri()
if wksht_id:
return self.Get(uri,
converter=gdata.spreadsheet.SpreadsheetsWorksheetFromString)
else:
return self.Get(uri,
converter=gdata.spreadsheet.SpreadsheetsWorksheetsFeedFromString)
def AddWorksheet(self, title, row_count, col_count, key):
"""Creates a new worksheet in the desired spreadsheet.
The new worksheet is appended to the end of the list of worksheets. The
new worksheet will only have the available number of columns and cells
specified.
Args:
title: str The title which will be displayed in the list of worksheets.
row_count: int or str The number of rows in the new worksheet.
col_count: int or str The number of columns in the new worksheet.
key: str The spreadsheet key to the spreadsheet to which the new
worksheet should be added.
Returns:
A SpreadsheetsWorksheet if the new worksheet was created succesfully.
"""
new_worksheet = gdata.spreadsheet.SpreadsheetsWorksheet(
title=atom.Title(text=title),
row_count=gdata.spreadsheet.RowCount(text=str(row_count)),
col_count=gdata.spreadsheet.ColCount(text=str(col_count)))
return self.Post(new_worksheet,
'https://%s/feeds/worksheets/%s/private/full' % (self.server, key),
converter=gdata.spreadsheet.SpreadsheetsWorksheetFromString)
def UpdateWorksheet(self, worksheet_entry, url=None):
"""Changes the size and/or title of the desired worksheet.
Args:
worksheet_entry: SpreadsheetWorksheet The new contents of the
worksheet.
url: str (optional) The URL to which the edited worksheet entry should
be sent. If the url is None, the edit URL from the worksheet will
be used.
Returns:
A SpreadsheetsWorksheet with the new information about the worksheet.
"""
target_url = url or worksheet_entry.GetEditLink().href
return self.Put(worksheet_entry, target_url,
converter=gdata.spreadsheet.SpreadsheetsWorksheetFromString)
def DeleteWorksheet(self, worksheet_entry=None, url=None):
"""Removes the desired worksheet from the spreadsheet
Args:
worksheet_entry: SpreadsheetWorksheet (optional) The worksheet to
be deleted. If this is none, then the DELETE reqest is sent to
the url specified in the url parameter.
url: str (optaional) The URL to which the DELETE request should be
sent. If left as None, the worksheet's edit URL is used.
Returns:
True if the worksheet was deleted successfully.
"""
if url:
target_url = url
else:
target_url = worksheet_entry.GetEditLink().href
return self.Delete(target_url)
def GetCellsFeed(self, key, wksht_id='default', cell=None, query=None,
visibility='private', projection='full'):
"""Gets a cells feed or a specific entry if a cell is defined
Args:
key: string The spreadsheet key defined in /ccc?key=
wksht_id: string The id for a specific worksheet entry
cell: string (optional) The R1C1 address of the cell
query: DocumentQuery (optional) Query parameters
Returns:
If there is no cell, then a SpreadsheetsCellsFeed.
If there is a cell, then a SpreadsheetsCell.
"""
uri = ('https://%s/feeds/cells/%s/%s/%s/%s'
% (self.server, key, wksht_id, visibility, projection))
if cell != None:
uri = '%s/%s' % (uri, cell)
if query != None:
query.feed = uri
uri = query.ToUri()
if cell:
return self.Get(uri,
converter=gdata.spreadsheet.SpreadsheetsCellFromString)
else:
return self.Get(uri,
converter=gdata.spreadsheet.SpreadsheetsCellsFeedFromString)
def GetListFeed(self, key, wksht_id='default', row_id=None, query=None,
visibility='private', projection='full'):
"""Gets a list feed or a specific entry if a row_id is defined
Args:
key: string The spreadsheet key defined in /ccc?key=
wksht_id: string The id for a specific worksheet entry
row_id: string (optional) The row_id of a row in the list
query: DocumentQuery (optional) Query parameters
Returns:
If there is no row_id, then a SpreadsheetsListFeed.
If there is a row_id, then a SpreadsheetsList.
"""
uri = ('https://%s/feeds/list/%s/%s/%s/%s'
% (self.server, key, wksht_id, visibility, projection))
if row_id is not None:
uri = '%s/%s' % (uri, row_id)
if query is not None:
query.feed = uri
uri = query.ToUri()
if row_id:
return self.Get(uri,
converter=gdata.spreadsheet.SpreadsheetsListFromString)
else:
return self.Get(uri,
converter=gdata.spreadsheet.SpreadsheetsListFeedFromString)
def UpdateCell(self, row, col, inputValue, key, wksht_id='default'):
"""Updates an existing cell.
Args:
row: int The row the cell to be editted is in
col: int The column the cell to be editted is in
inputValue: str the new value of the cell
key: str The key of the spreadsheet in which this cell resides.
wksht_id: str The ID of the worksheet which holds this cell.
Returns:
The updated cell entry
"""
row = str(row)
col = str(col)
# make the new cell
new_cell = gdata.spreadsheet.Cell(row=row, col=col, inputValue=inputValue)
# get the edit uri and PUT
cell = 'R%sC%s' % (row, col)
entry = self.GetCellsFeed(key, wksht_id, cell)
for a_link in entry.link:
if a_link.rel == 'edit':
entry.cell = new_cell
return self.Put(entry, a_link.href,
converter=gdata.spreadsheet.SpreadsheetsCellFromString)
def _GenerateCellsBatchUrl(self, spreadsheet_key, worksheet_id):
return ('https://spreadsheets.google.com/feeds/cells/%s/%s/'
'private/full/batch' % (spreadsheet_key, worksheet_id))
def ExecuteBatch(self, batch_feed, url=None, spreadsheet_key=None,
worksheet_id=None,
converter=gdata.spreadsheet.SpreadsheetsCellsFeedFromString):
"""Sends a batch request feed to the server.
The batch request needs to be sent to the batch URL for a particular
worksheet. You can specify the worksheet by providing the spreadsheet_key
and worksheet_id, or by sending the URL from the cells feed's batch link.
Args:
batch_feed: gdata.spreadsheet.SpreadsheetsCellFeed A feed containing
BatchEntry elements which contain the desired CRUD operation and
any necessary data to modify a cell.
url: str (optional) The batch URL for the cells feed to which these
changes should be applied. This can be found by calling
cells_feed.GetBatchLink().href.
spreadsheet_key: str (optional) Used to generate the batch request URL
if the url argument is None. If using the spreadsheet key to
generate the URL, the worksheet id is also required.
worksheet_id: str (optional) Used if the url is not provided, it is
oart of the batch feed target URL. This is used with the spreadsheet
key.
converter: Function (optional) Function to be executed on the server's
response. This function should take one string as a parameter. The
default value is SpreadsheetsCellsFeedFromString which will turn the result
into a gdata.spreadsheet.SpreadsheetsCellsFeed object.
Returns:
A gdata.BatchFeed containing the results.
"""
if url is None:
url = self._GenerateCellsBatchUrl(spreadsheet_key, worksheet_id)
return self.Post(batch_feed, url, converter=converter)
def InsertRow(self, row_data, key, wksht_id='default'):
"""Inserts a new row with the provided data
Args:
uri: string The post uri of the list feed
row_data: dict A dictionary of column header to row data
Returns:
The inserted row
"""
new_entry = gdata.spreadsheet.SpreadsheetsList()
for k, v in row_data.items():
new_custom = gdata.spreadsheet.Custom()
new_custom.column = k
new_custom.text = v
new_entry.custom[new_custom.column] = new_custom
# Generate the post URL for the worksheet which will receive the new entry.
post_url = 'https://spreadsheets.google.com/feeds/list/%s/%s/private/full'%(
key, wksht_id)
return self.Post(new_entry, post_url,
converter=gdata.spreadsheet.SpreadsheetsListFromString)
def UpdateRow(self, entry, new_row_data):
"""Updates a row with the provided data
If you want to add additional information to a row, it is often
easier to change the values in entry.custom, then use the Put
method instead of UpdateRow. This UpdateRow method will replace
the contents of the row with new_row_data - it will change all columns
not just the columns specified in the new_row_data dict.
Args:
entry: gdata.spreadsheet.SpreadsheetsList The entry to be updated
new_row_data: dict A dictionary of column header to row data
Returns:
The updated row
"""
entry.custom = {}
for k, v in new_row_data.items():
new_custom = gdata.spreadsheet.Custom()
new_custom.column = k
new_custom.text = v
entry.custom[k] = new_custom
for a_link in entry.link:
if a_link.rel == 'edit':
return self.Put(entry, a_link.href,
converter=gdata.spreadsheet.SpreadsheetsListFromString)
def DeleteRow(self, entry):
"""Deletes a row, the provided entry
Args:
entry: gdata.spreadsheet.SpreadsheetsList The row to be deleted
Returns:
The delete response
"""
for a_link in entry.link:
if a_link.rel == 'edit':
return self.Delete(a_link.href)
class DocumentQuery(gdata.service.Query):
def _GetTitleQuery(self):
return self['title']
def _SetTitleQuery(self, document_query):
self['title'] = document_query
title = property(_GetTitleQuery, _SetTitleQuery,
doc="""The title query parameter""")
def _GetTitleExactQuery(self):
return self['title-exact']
def _SetTitleExactQuery(self, document_query):
self['title-exact'] = document_query
title_exact = property(_GetTitleExactQuery, _SetTitleExactQuery,
doc="""The title-exact query parameter""")
class CellQuery(gdata.service.Query):
def _GetMinRowQuery(self):
return self['min-row']
def _SetMinRowQuery(self, cell_query):
self['min-row'] = cell_query
min_row = property(_GetMinRowQuery, _SetMinRowQuery,
doc="""The min-row query parameter""")
def _GetMaxRowQuery(self):
return self['max-row']
def _SetMaxRowQuery(self, cell_query):
self['max-row'] = cell_query
max_row = property(_GetMaxRowQuery, _SetMaxRowQuery,
doc="""The max-row query parameter""")
def _GetMinColQuery(self):
return self['min-col']
def _SetMinColQuery(self, cell_query):
self['min-col'] = cell_query
min_col = property(_GetMinColQuery, _SetMinColQuery,
doc="""The min-col query parameter""")
def _GetMaxColQuery(self):
return self['max-col']
def _SetMaxColQuery(self, cell_query):
self['max-col'] = cell_query
max_col = property(_GetMaxColQuery, _SetMaxColQuery,
doc="""The max-col query parameter""")
def _GetRangeQuery(self):
return self['range']
def _SetRangeQuery(self, cell_query):
self['range'] = cell_query
range = property(_GetRangeQuery, _SetRangeQuery,
doc="""The range query parameter""")
def _GetReturnEmptyQuery(self):
return self['return-empty']
def _SetReturnEmptyQuery(self, cell_query):
self['return-empty'] = cell_query
return_empty = property(_GetReturnEmptyQuery, _SetReturnEmptyQuery,
doc="""The return-empty query parameter""")
class ListQuery(gdata.service.Query):
def _GetSpreadsheetQuery(self):
return self['sq']
def _SetSpreadsheetQuery(self, list_query):
self['sq'] = list_query
sq = property(_GetSpreadsheetQuery, _SetSpreadsheetQuery,
doc="""The sq query parameter""")
def _GetOrderByQuery(self):
return self['orderby']
def _SetOrderByQuery(self, list_query):
self['orderby'] = list_query
orderby = property(_GetOrderByQuery, _SetOrderByQuery,
doc="""The orderby query parameter""")
def _GetReverseQuery(self):
return self['reverse']
def _SetReverseQuery(self, list_query):
self['reverse'] = list_query
reverse = property(_GetReverseQuery, _SetReverseQuery,
doc="""The reverse query parameter""")
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
35,
9,
10219,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
30693,
83,
3167,
16879,
314,
598,
1451,
3167,
370,
2547,
604,
4475,
199,
30693,
83,
5331,
14,
819,
428,
12032,
3167,
26,
21552,
3102,
370,
1827,
22295,
436,
27232,
2974,
14,
1993,
11524,
795,
598,
1451,
3167,
14,
819,
11932,
1378,
4098,
1296,
26,
6801,
1314,
15373,
282,
2600,
1901,
282,
769,
402,
586,
2851,
2368,
334,
264,
10317,
465,
3326,
680,
961,
365,
282,
586,
11420,
805,
1202,
315,
17101,
3383,
5331,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
1246,
14,
416,
300,
7570,
273,
32,
6799,
14,
957,
334,
7833,
12417,
6423,
273,
29730,
761,
78,
3171,
421,
199,
646,
11006,
199,
646,
6222,
14,
1364,
199,
646,
11006,
14,
1364,
199,
646,
11006,
14,
19930,
199,
646,
6222,
421,
199,
533,
4520,
8,
1726,
304,
523,
408,
1563,
1021,
367,
4967,
315,
642,
859,
1041,
523,
986,
421,
199,
533,
4784,
547,
8,
547,
304,
523,
986,
421,
199,
533,
428,
12032,
83,
3167,
8,
15275,
14,
1364,
14,
27413,
3167,
304,
523,
408,
3041,
367,
314,
4475,
428,
12032,
83,
2435,
1041,
819,
347,
636,
826,
721,
277,
12,
3031,
29,
403,
12,
2505,
29,
403,
12,
1350,
29,
403,
12,
2049,
1654,
534,
19930,
83,
14,
3098,
14,
957,
297,
4722,
63,
2139,
29,
403,
12,
2049,
1011,
958,
304,
272,
408,
10607,
282,
1890,
367,
314,
4475,
428,
12032,
83,
2435,
14,
339,
3033,
26,
489,
3031,
26,
1059,
334,
4144,
9,
710,
922,
1159,
3031,
2287,
12,
1202,
367,
881,
6299,
14,
489,
2505,
26,
1059,
334,
4144,
9,
710,
922,
1159,
2505,
14,
489,
1350,
26,
1059,
334,
4144,
9,
710,
536,
402,
314,
922,
1159,
4223,
14,
489,
1654,
26,
1059,
334,
4144,
9,
710,
536,
402,
314,
1654,
370,
1314,
282,
1950,
881,
911,
506,
12123,
14,
3758,
574,
26,
283,
19930,
83,
14,
3098,
14,
957,
1370,
489,
1011,
958,
26,
710,
1163,
2633,
370,
986,
370,
11006,
14,
1364,
14,
27413,
3167,
881,
3787,
14,
272,
408,
272,
11006,
14,
1364,
14,
27413,
3167,
855,
826,
721,
267,
291,
12,
3031,
29,
2123,
12,
2505,
29,
2060,
12,
2435,
534,
2605,
297,
1350,
29,
1365,
12,
267,
1654,
29,
1000,
12,
4722,
63,
2139,
29,
8460,
63,
2139,
12,
1011,
958,
9,
819,
347,
2372,
30693,
83,
7658,
8,
277,
12,
790,
29,
403,
12,
1827,
29,
403,
12,
6887,
534,
4239,
297,
15166,
14777,
534,
2861,
735,
272,
408,
14426,
282,
27076,
83,
4733,
503,
282,
2488,
2397,
340,
282,
790,
365,
3247,
272,
3033,
26,
489,
790,
26,
1059,
334,
4144,
9,
710,
27076,
790,
3247,
315,
1182,
19504,
31,
498,
29,
489,
1827,
26,
7543,
3227,
334,
4144,
9,
8133,
2633,
2126,
272,
1803,
26,
489,
982,
2337,
365,
949,
790,
12,
2066,
282,
428,
12032,
83,
30693,
83,
7658,
14,
489,
982,
2337,
365,
282,
790,
12,
2066,
282,
428,
12032,
83,
30693,
14,
272,
408,
2286,
1300,
63,
2302,
275,
283,
2859,
13827,
83,
15,
11522,
15,
19930,
83,
7,
450,
291,
14,
1000,
272,
5108,
275,
16651,
83,
3149,
83,
3149,
83,
7,
221,
1779,
450,
334,
1095,
63,
2302,
12,
6887,
12,
14777,
430,
2286,
340,
790,
365,
440,
488,
26,
489,
5108,
275,
1543,
83,
3149,
83,
7,
450,
334,
2302,
12,
790,
9,
2126,
272,
340,
1827,
1137,
488,
26,
489,
1827,
14,
3871,
275,
1300,
63,
2302,
489,
1827,
14,
11269,
275,
6887,
489,
1827,
14,
16539,
275,
14777,
489,
5108,
275,
1827,
14,
1378,
14014,
342,
339,
340,
790,
26,
489,
372,
291,
14,
1002,
8,
2302,
12,
23664,
11109,
29,
15275,
14,
19930,
14,
30693,
83,
30693,
7671,
9,
272,
587,
26,
489,
372,
291,
14,
1002,
8,
2302,
12,
881,
11109,
29,
15275,
14,
19930,
14,
30693,
83,
30693,
83,
7658,
7671,
9,
12244,
347,
2372,
6517,
24376,
7658,
8,
277,
12,
790,
12,
336,
6080,
517,
63,
344,
29,
403,
12,
1827,
29,
403,
12,
15166,
6887,
534,
4239,
297,
14777,
534,
2861,
735,
272,
408,
14426,
282,
21127,
83,
4733,
503,
282,
2488,
2397,
340,
282,
336,
6080,
517,
365,
3247,
272,
3033,
26,
489,
790,
26,
1059,
710,
27076,
790,
3247,
315,
1182,
19504,
31,
498,
29,
489,
336,
6080,
517,
63,
344,
26,
1059,
334,
4144,
9,
710,
1305,
367,
282,
2488,
21127,
2397,
489,
1827,
26,
7543,
3227,
334,
4144,
9,
8133,
2633,
2126,
272,
1803,
26,
489,
982,
2337,
365,
949,
336,
6080,
517,
63,
344,
12,
2066,
282,
428,
12032,
83,
6517,
24376,
7658,
14,
489,
982,
2337,
365,
282,
336,
6080,
517,
63,
344,
12,
2066,
282,
428,
12032,
83,
6517,
5069,
14,
272,
408,
2286,
5108,
275,
661,
2859,
13827,
83,
15,
11522,
15,
800,
24376,
3149,
83,
3149,
83,
3149,
83,
7,
221,
1779,
450,
334,
277,
14,
1000,
12,
790,
12,
6887,
12,
14777,
430,
2286,
340,
336,
6080,
517,
63,
344,
1137,
488,
26,
489,
5108,
275,
1543,
83,
3149,
83,
7,
450,
334,
2302,
12,
336,
6080,
517,
63,
344,
9,
2126,
272,
340,
1827,
1137,
488,
26,
489,
1827,
14,
3871,
275,
5108,
489,
5108,
275,
1827,
14,
1378,
14014,
342,
339,
340,
336,
6080,
517,
63,
344,
26,
489,
372,
291,
14,
1002,
8,
2302,
12,
23664,
11109,
29
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
35,
9,
10219,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
30693,
83,
3167,
16879,
314,
598,
1451,
3167,
370,
2547,
604,
4475,
199,
30693,
83,
5331,
14,
819,
428,
12032,
3167,
26,
21552,
3102,
370,
1827,
22295,
436,
27232,
2974,
14,
1993,
11524,
795,
598,
1451,
3167,
14,
819,
11932,
1378,
4098,
1296,
26,
6801,
1314,
15373,
282,
2600,
1901,
282,
769,
402,
586,
2851,
2368,
334,
264,
10317,
465,
3326,
680,
961,
365,
282,
586,
11420,
805,
1202,
315,
17101,
3383,
5331,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
1246,
14,
416,
300,
7570,
273,
32,
6799,
14,
957,
334,
7833,
12417,
6423,
273,
29730,
761,
78,
3171,
421,
199,
646,
11006,
199,
646,
6222,
14,
1364,
199,
646,
11006,
14,
1364,
199,
646,
11006,
14,
19930,
199,
646,
6222,
421,
199,
533,
4520,
8,
1726,
304,
523,
408,
1563,
1021,
367,
4967,
315,
642,
859,
1041,
523,
986,
421,
199,
533,
4784,
547,
8,
547,
304,
523,
986,
421,
199,
533,
428,
12032,
83,
3167,
8,
15275,
14,
1364,
14,
27413,
3167,
304,
523,
408,
3041,
367,
314,
4475,
428,
12032,
83,
2435,
1041,
819,
347,
636,
826,
721,
277,
12,
3031,
29,
403,
12,
2505,
29,
403,
12,
1350,
29,
403,
12,
2049,
1654,
534,
19930,
83,
14,
3098,
14,
957,
297,
4722,
63,
2139,
29,
403,
12,
2049,
1011,
958,
304,
272,
408,
10607,
282,
1890,
367,
314,
4475,
428,
12032,
83,
2435,
14,
339,
3033,
26,
489,
3031,
26,
1059,
334,
4144,
9,
710,
922,
1159,
3031,
2287,
12,
1202,
367,
881,
6299,
14,
489,
2505,
26,
1059,
334,
4144,
9,
710,
922,
1159,
2505,
14,
489,
1350,
26,
1059,
334,
4144,
9,
710,
536,
402,
314,
922,
1159,
4223,
14,
489,
1654,
26,
1059,
334,
4144,
9,
710,
536,
402,
314,
1654,
370,
1314,
282,
1950,
881,
911,
506,
12123,
14,
3758,
574,
26,
283,
19930,
83,
14,
3098,
14,
957,
1370,
489,
1011,
958,
26,
710,
1163,
2633,
370,
986,
370,
11006,
14,
1364,
14,
27413,
3167,
881,
3787,
14,
272,
408,
272,
11006,
14,
1364,
14,
27413,
3167,
855,
826,
721,
267,
291,
12,
3031,
29,
2123,
12,
2505,
29,
2060,
12,
2435,
534,
2605,
297,
1350,
29,
1365,
12,
267,
1654,
29,
1000,
12,
4722,
63,
2139,
29,
8460,
63,
2139,
12,
1011,
958,
9,
819,
347,
2372,
30693,
83,
7658,
8,
277,
12,
790,
29,
403,
12,
1827,
29,
403,
12,
6887,
534,
4239,
297,
15166,
14777,
534,
2861,
735,
272,
408,
14426,
282,
27076,
83,
4733,
503,
282,
2488,
2397,
340,
282,
790,
365,
3247,
272,
3033,
26,
489,
790,
26,
1059,
334,
4144,
9,
710,
27076,
790,
3247,
315,
1182,
19504,
31,
498,
29,
489,
1827,
26,
7543,
3227,
334,
4144,
9,
8133,
2633,
2126,
272,
1803,
26,
489,
982,
2337,
365,
949,
790,
12,
2066,
282,
428,
12032,
83,
30693,
83,
7658,
14,
489,
982,
2337,
365,
282,
790,
12,
2066,
282,
428,
12032,
83,
30693,
14,
272,
408,
2286,
1300,
63,
2302,
275,
283,
2859,
13827,
83,
15,
11522,
15,
19930,
83,
7,
450,
291,
14,
1000,
272,
5108,
275,
16651,
83,
3149,
83,
3149,
83,
7,
221,
1779,
450,
334,
1095,
63,
2302,
12,
6887,
12,
14777,
430,
2286,
340,
790,
365,
440,
488,
26,
489,
5108,
275,
1543,
83,
3149,
83,
7,
450,
334,
2302,
12,
790,
9,
2126,
272,
340,
1827,
1137,
488,
26,
489,
1827,
14,
3871,
275,
1300,
63,
2302,
489,
1827,
14,
11269,
275,
6887,
489,
1827,
14,
16539,
275,
14777,
489,
5108,
275,
1827,
14,
1378,
14014,
342,
339,
340,
790,
26,
489,
372,
291,
14,
1002,
8,
2302,
12,
23664,
11109,
29,
15275,
14,
19930,
14,
30693,
83,
30693,
7671,
9,
272,
587,
26,
489,
372,
291,
14,
1002,
8,
2302,
12,
881,
11109,
29,
15275,
14,
19930,
14,
30693,
83,
30693,
83,
7658,
7671,
9,
12244,
347,
2372,
6517,
24376,
7658,
8,
277,
12,
790,
12,
336,
6080,
517,
63,
344,
29,
403,
12,
1827,
29,
403,
12,
15166,
6887,
534,
4239,
297,
14777,
534,
2861,
735,
272,
408,
14426,
282,
21127,
83,
4733,
503,
282,
2488,
2397,
340,
282,
336,
6080,
517,
365,
3247,
272,
3033,
26,
489,
790,
26,
1059,
710,
27076,
790,
3247,
315,
1182,
19504,
31,
498,
29,
489,
336,
6080,
517,
63,
344,
26,
1059,
334,
4144,
9,
710,
1305,
367,
282,
2488,
21127,
2397,
489,
1827,
26,
7543,
3227,
334,
4144,
9,
8133,
2633,
2126,
272,
1803,
26,
489,
982,
2337,
365,
949,
336,
6080,
517,
63,
344,
12,
2066,
282,
428,
12032,
83,
6517,
24376,
7658,
14,
489,
982,
2337,
365,
282,
336,
6080,
517,
63,
344,
12,
2066,
282,
428,
12032,
83,
6517,
5069,
14,
272,
408,
2286,
5108,
275,
661,
2859,
13827,
83,
15,
11522,
15,
800,
24376,
3149,
83,
3149,
83,
3149,
83,
7,
221,
1779,
450,
334,
277,
14,
1000,
12,
790,
12,
6887,
12,
14777,
430,
2286,
340,
336,
6080,
517,
63,
344,
1137,
488,
26,
489,
5108,
275,
1543,
83,
3149,
83,
7,
450,
334,
2302,
12,
336,
6080,
517,
63,
344,
9,
2126,
272,
340,
1827,
1137,
488,
26,
489,
1827,
14,
3871,
275,
5108,
489,
5108,
275,
1827,
14,
1378,
14014,
342,
339,
340,
336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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
hdmetor/scikit-learn
|
examples/text/hashing_vs_dict_vectorizer.py
|
284
|
3265
|
"""
===========================================
FeatureHasher and DictVectorizer Comparison
===========================================
Compares FeatureHasher and DictVectorizer by using both to vectorize
text documents.
The example demonstrates syntax and speed only; it doesn't actually do
anything useful with the extracted vectors. See the example scripts
{document_classification_20newsgroups,clustering}.py for actual learning
on text documents.
A discrepancy between the number of terms reported for DictVectorizer and
for FeatureHasher is to be expected due to hash collisions.
"""
# Author: Lars Buitinck <L.J.Buitinck@uva.nl>
# License: BSD 3 clause
from __future__ import print_function
from collections import defaultdict
import re
import sys
from time import time
import numpy as np
from sklearn.datasets import fetch_20newsgroups
from sklearn.feature_extraction import DictVectorizer, FeatureHasher
def n_nonzero_columns(X):
"""Returns the number of non-zero columns in a CSR matrix X."""
return len(np.unique(X.nonzero()[1]))
def tokens(doc):
"""Extract tokens from doc.
This uses a simple regex to break strings into tokens. For a more
principled approach, see CountVectorizer or TfidfVectorizer.
"""
return (tok.lower() for tok in re.findall(r"\w+", doc))
def token_freqs(doc):
"""Extract a dict mapping tokens from doc to their frequencies."""
freq = defaultdict(int)
for tok in tokens(doc):
freq[tok] += 1
return freq
categories = [
'alt.atheism',
'comp.graphics',
'comp.sys.ibm.pc.hardware',
'misc.forsale',
'rec.autos',
'sci.space',
'talk.religion.misc',
]
# Uncomment the following line to use a larger set (11k+ documents)
#categories = None
print(__doc__)
print("Usage: %s [n_features_for_hashing]" % sys.argv[0])
print(" The default number of features is 2**18.")
print()
try:
n_features = int(sys.argv[1])
except IndexError:
n_features = 2 ** 18
except ValueError:
print("not a valid number of features: %r" % sys.argv[1])
sys.exit(1)
print("Loading 20 newsgroups training data")
raw_data = fetch_20newsgroups(subset='train', categories=categories).data
data_size_mb = sum(len(s.encode('utf-8')) for s in raw_data) / 1e6
print("%d documents - %0.3fMB" % (len(raw_data), data_size_mb))
print()
print("DictVectorizer")
t0 = time()
vectorizer = DictVectorizer()
vectorizer.fit_transform(token_freqs(d) for d in raw_data)
duration = time() - t0
print("done in %fs at %0.3fMB/s" % (duration, data_size_mb / duration))
print("Found %d unique terms" % len(vectorizer.get_feature_names()))
print()
print("FeatureHasher on frequency dicts")
t0 = time()
hasher = FeatureHasher(n_features=n_features)
X = hasher.transform(token_freqs(d) for d in raw_data)
duration = time() - t0
print("done in %fs at %0.3fMB/s" % (duration, data_size_mb / duration))
print("Found %d unique terms" % n_nonzero_columns(X))
print()
print("FeatureHasher on raw tokens")
t0 = time()
hasher = FeatureHasher(n_features=n_features, input_type="string")
X = hasher.transform(tokens(d) for d in raw_data)
duration = time() - t0
print("done in %fs at %0.3fMB/s" % (duration, data_size_mb / duration))
print("Found %d unique terms" % n_nonzero_columns(X))
|
bsd-3-clause
|
[
624,
199,
2486,
21326,
199,
5968,
13415,
436,
7448,
26165,
3599,
5447,
199,
2486,
21326,
199,
199,
2404,
11044,
13407,
13415,
436,
7448,
26165,
701,
1808,
3865,
370,
5477,
794,
199,
505,
8247,
14,
199,
199,
1918,
2893,
23789,
31216,
6302,
436,
8112,
1454,
27,
652,
3181,
1133,
5965,
886,
199,
25058,
2997,
543,
314,
12509,
11102,
14,
1666,
314,
2893,
10554,
199,
91,
3554,
63,
14368,
63,
1165,
13224,
2634,
12,
25802,
5565,
647,
367,
3503,
9328,
199,
265,
1318,
8247,
14,
199,
199,
33,
4339,
1155,
9844,
3382,
314,
1329,
402,
2895,
14581,
367,
7448,
26165,
436,
199,
509,
13407,
13415,
365,
370,
506,
1420,
7037,
370,
2631,
30063,
14,
199,
624,
199,
199,
3,
6529,
26,
491,
4291,
4779,
390,
262,
346,
665,
44,
14,
42,
14,
1713,
390,
262,
346,
32,
85,
3042,
14,
7530,
30,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
5055,
492,
10018,
199,
646,
295,
199,
646,
984,
199,
504,
900,
492,
900,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
6357,
14,
12281,
492,
5267,
63,
1165,
13224,
2634,
199,
504,
6357,
14,
4445,
63,
24020,
492,
7448,
26165,
12,
13407,
13415,
421,
199,
318,
302,
63,
10262,
63,
3406,
8,
56,
304,
272,
408,
3407,
314,
1329,
402,
2222,
13,
4262,
4362,
315,
282,
16449,
3634,
1323,
1041,
272,
372,
822,
8,
1590,
14,
3235,
8,
56,
14,
10262,
3430,
17,
2459,
421,
199,
318,
4645,
8,
1301,
304,
272,
408,
12147,
4645,
687,
1382,
14,
339,
961,
4440,
282,
3486,
5163,
370,
2059,
3326,
1901,
4645,
14,
2104,
282,
1655,
272,
5448,
10352,
1146,
18140,
12,
1937,
14826,
26165,
503,
377,
23274,
26165,
14,
272,
408,
272,
372,
334,
9305,
14,
2325,
342,
367,
8431,
315,
295,
14,
6452,
8,
82,
3212,
87,
22758,
1382,
430,
421,
199,
318,
1526,
63,
28557,
8,
1301,
304,
272,
408,
12147,
282,
1211,
4412,
4645,
687,
1382,
370,
3932,
22411,
1041,
272,
9220,
275,
10018,
8,
442,
9,
272,
367,
8431,
315,
4645,
8,
1301,
304,
267,
9220,
59,
9305,
61,
847,
413,
272,
372,
9220,
421,
199,
8906,
275,
359,
272,
283,
4478,
14,
65,
1589,
19185,
297,
272,
283,
863,
14,
15707,
297,
272,
283,
863,
14,
1274,
14,
19870,
14,
2352,
14,
16529,
297,
272,
283,
9923,
14,
509,
8515,
297,
272,
283,
2761,
14,
29764,
297,
272,
283,
9907,
14,
2638,
297,
272,
283,
21890,
14,
264,
17506,
1636,
14,
9923,
297,
199,
61,
199,
3,
1910,
3349,
314,
2569,
1004,
370,
675,
282,
12142,
663,
334,
845,
75,
11,
8247,
9,
199,
3,
8906,
275,
488,
199,
199,
1361,
3460,
1301,
3368,
199,
1361,
480,
7692,
26,
450,
83,
359,
78,
63,
3179,
63,
509,
63,
2227,
316,
8480,
450,
984,
14,
3020,
59,
16,
566,
199,
1361,
480,
259,
710,
849,
1329,
402,
4534,
365,
499,
538,
1085,
2685,
199,
1361,
342,
199,
199,
893,
26,
272,
302,
63,
3179,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
2590,
7888,
26,
272,
302,
63,
3179,
275,
499,
1011,
6155,
199,
2590,
1722,
26,
272,
870,
480,
1397,
282,
1686,
1329,
402,
4534,
26,
450,
82,
2,
450,
984,
14,
3020,
59,
17,
566,
272,
984,
14,
2224,
8,
17,
9,
421,
199,
1361,
480,
19236,
3388,
19497,
2634,
6093,
666,
531,
199,
1773,
63,
576,
275,
5267,
63,
1165,
13224,
2634,
8,
9401,
534,
2834,
297,
9695,
29,
8906,
680,
576,
199,
576,
63,
890,
63,
887,
275,
3089,
8,
552,
8,
83,
14,
2143,
360,
1624,
13,
24,
1333,
367,
308,
315,
3066,
63,
576,
9,
1182,
413,
69,
22,
199,
1361,
3647,
68,
8247,
446,
450,
16,
14,
19,
70,
4567,
2,
450,
334,
552,
8,
1773,
63,
576,
395,
666,
63,
890,
63,
887,
430,
199,
1361,
342,
199,
199,
1361,
480,
2141,
26165,
531,
199,
84,
16,
275,
900,
342,
199,
4106,
1793,
275,
7448,
26165,
342,
199,
4106,
1793,
14,
3269,
63,
4711,
8,
1418,
63,
28557,
8,
68,
9,
367,
366,
315,
3066,
63,
576,
9,
199,
5553,
275,
900,
342,
446,
307,
16,
199,
1361,
480,
4456,
315,
450,
2319,
737,
450,
16,
14,
19,
70,
4567,
15,
83,
2,
450,
334,
5553,
12,
666,
63,
890,
63,
887,
1182,
7373,
430,
199,
1361,
480,
3601,
450,
68,
3747,
2895,
2,
450,
822,
8,
4106,
1793,
14,
362,
63,
4445,
63,
1247,
4059,
199,
1361,
342,
199,
199,
1361,
480,
5968,
13415,
641,
9857,
10809,
531,
199,
84,
16,
275,
900,
342,
199,
28885,
275,
13407,
13415,
8,
78,
63,
3179,
29,
78,
63,
3179,
9,
199,
56,
275,
19009,
14,
4711,
8,
1418,
63,
28557,
8,
68,
9,
367,
366,
315,
3066,
63,
576,
9,
199,
5553,
275,
900,
342,
446,
307,
16,
199,
1361,
480,
4456,
315,
450,
2319,
737,
450,
16,
14,
19,
70,
4567,
15,
83,
2,
450,
334,
5553,
12,
666,
63,
890,
63,
887,
1182,
7373,
430,
199,
1361,
480,
3601,
450,
68,
3747,
2895,
2,
450,
302,
63,
10262,
63,
3406,
8,
56,
430,
199,
1361,
342,
199,
199,
1361,
480,
5968,
13415,
641,
3066,
4645,
531,
199,
84,
16,
275,
900,
342,
199,
28885,
275,
13407,
13415,
8,
78,
63,
3179,
29,
78,
63,
3179,
12,
1324,
63,
466,
628,
875,
531,
199,
56,
275,
19009,
14,
4711,
8,
4504,
8,
68,
9,
367,
366,
315,
3066,
63,
576,
9,
199,
5553,
275,
900,
342,
446,
307,
16,
199,
1361,
480,
4456,
315,
450,
2319,
737,
450,
16,
14,
19,
70,
4567,
15,
83,
2,
450,
334,
5553,
12,
666,
63,
890,
63,
887,
1182,
7373,
430,
199,
1361,
480,
3601,
450,
68,
3747,
2895,
2,
450,
302,
63,
10262,
63,
3406,
8,
56,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
2486,
21326,
199,
5968,
13415,
436,
7448,
26165,
3599,
5447,
199,
2486,
21326,
199,
199,
2404,
11044,
13407,
13415,
436,
7448,
26165,
701,
1808,
3865,
370,
5477,
794,
199,
505,
8247,
14,
199,
199,
1918,
2893,
23789,
31216,
6302,
436,
8112,
1454,
27,
652,
3181,
1133,
5965,
886,
199,
25058,
2997,
543,
314,
12509,
11102,
14,
1666,
314,
2893,
10554,
199,
91,
3554,
63,
14368,
63,
1165,
13224,
2634,
12,
25802,
5565,
647,
367,
3503,
9328,
199,
265,
1318,
8247,
14,
199,
199,
33,
4339,
1155,
9844,
3382,
314,
1329,
402,
2895,
14581,
367,
7448,
26165,
436,
199,
509,
13407,
13415,
365,
370,
506,
1420,
7037,
370,
2631,
30063,
14,
199,
624,
199,
199,
3,
6529,
26,
491,
4291,
4779,
390,
262,
346,
665,
44,
14,
42,
14,
1713,
390,
262,
346,
32,
85,
3042,
14,
7530,
30,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
5055,
492,
10018,
199,
646,
295,
199,
646,
984,
199,
504,
900,
492,
900,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
6357,
14,
12281,
492,
5267,
63,
1165,
13224,
2634,
199,
504,
6357,
14,
4445,
63,
24020,
492,
7448,
26165,
12,
13407,
13415,
421,
199,
318,
302,
63,
10262,
63,
3406,
8,
56,
304,
272,
408,
3407,
314,
1329,
402,
2222,
13,
4262,
4362,
315,
282,
16449,
3634,
1323,
1041,
272,
372,
822,
8,
1590,
14,
3235,
8,
56,
14,
10262,
3430,
17,
2459,
421,
199,
318,
4645,
8,
1301,
304,
272,
408,
12147,
4645,
687,
1382,
14,
339,
961,
4440,
282,
3486,
5163,
370,
2059,
3326,
1901,
4645,
14,
2104,
282,
1655,
272,
5448,
10352,
1146,
18140,
12,
1937,
14826,
26165,
503,
377,
23274,
26165,
14,
272,
408,
272,
372,
334,
9305,
14,
2325,
342,
367,
8431,
315,
295,
14,
6452,
8,
82,
3212,
87,
22758,
1382,
430,
421,
199,
318,
1526,
63,
28557,
8,
1301,
304,
272,
408,
12147,
282,
1211,
4412,
4645,
687,
1382,
370,
3932,
22411,
1041,
272,
9220,
275,
10018,
8,
442,
9,
272,
367,
8431,
315,
4645,
8,
1301,
304,
267,
9220,
59,
9305,
61,
847,
413,
272,
372,
9220,
421,
199,
8906,
275,
359,
272,
283,
4478,
14,
65,
1589,
19185,
297,
272,
283,
863,
14,
15707,
297,
272,
283,
863,
14,
1274,
14,
19870,
14,
2352,
14,
16529,
297,
272,
283,
9923,
14,
509,
8515,
297,
272,
283,
2761,
14,
29764,
297,
272,
283,
9907,
14,
2638,
297,
272,
283,
21890,
14,
264,
17506,
1636,
14,
9923,
297,
199,
61,
199,
3,
1910,
3349,
314,
2569,
1004,
370,
675,
282,
12142,
663,
334,
845,
75,
11,
8247,
9,
199,
3,
8906,
275,
488,
199,
199,
1361,
3460,
1301,
3368,
199,
1361,
480,
7692,
26,
450,
83,
359,
78,
63,
3179,
63,
509,
63,
2227,
316,
8480,
450,
984,
14,
3020,
59,
16,
566,
199,
1361,
480,
259,
710,
849,
1329,
402,
4534,
365,
499,
538,
1085,
2685,
199,
1361,
342,
199,
199,
893,
26,
272,
302,
63,
3179,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
2590,
7888,
26,
272,
302,
63,
3179,
275,
499,
1011,
6155,
199,
2590,
1722,
26,
272,
870,
480,
1397,
282,
1686,
1329,
402,
4534,
26,
450,
82,
2,
450,
984,
14,
3020,
59,
17,
566,
272,
984,
14,
2224,
8,
17,
9,
421,
199,
1361,
480,
19236,
3388,
19497,
2634,
6093,
666,
531,
199,
1773,
63,
576,
275,
5267,
63,
1165,
13224,
2634,
8,
9401,
534,
2834,
297,
9695,
29,
8906,
680,
576,
199,
576,
63,
890,
63,
887,
275,
3089,
8,
552,
8,
83,
14,
2143,
360,
1624,
13,
24,
1333,
367,
308,
315,
3066,
63,
576,
9,
1182,
413,
69,
22,
199,
1361,
3647,
68,
8247,
446,
450,
16,
14,
19,
70,
4567,
2,
450,
334,
552,
8,
1773,
63,
576,
395,
666,
63,
890,
63,
887,
430,
199,
1361,
342,
199,
199,
1361,
480,
2141,
26165,
531,
199,
84,
16,
275,
900,
342,
199,
4106,
1793,
275,
7448,
26165,
342,
199,
4106,
1793,
14,
3269,
63,
4711,
8,
1418,
63,
28557,
8,
68,
9,
367,
366,
315,
3066,
63,
576,
9,
199,
5553,
275,
900,
342,
446,
307,
16,
199,
1361,
480,
4456,
315,
450,
2319,
737,
450,
16,
14,
19,
70,
4567,
15,
83,
2,
450,
334,
5553,
12,
666,
63,
890,
63,
887,
1182,
7373,
430,
199,
1361,
480,
3601,
450,
68,
3747,
2895,
2,
450,
822,
8,
4106,
1793,
14,
362,
63,
4445,
63,
1247,
4059,
199,
1361,
342,
199,
199,
1361,
480,
5968,
13415,
641,
9857,
10809,
531,
199,
84,
16,
275,
900,
342,
199,
28885,
275,
13407,
13415,
8,
78,
63,
3179,
29,
78,
63,
3179,
9,
199,
56,
275,
19009,
14,
4711,
8,
1418,
63,
28557,
8,
68,
9,
367,
366,
315,
3066,
63,
576,
9,
199,
5553,
275,
900,
342,
446,
307,
16,
199,
1361,
480,
4456,
315,
450,
2319,
737,
450,
16,
14,
19,
70,
4567,
15,
83,
2,
450,
334,
5553,
12,
666,
63,
890,
63,
887,
1182,
7373,
430,
199,
1361,
480,
3601,
450,
68,
3747,
2895,
2,
450,
302,
63,
10262,
63,
3406,
8,
56,
430,
199,
1361,
342,
199,
199,
1361,
480,
5968,
13415,
641,
3066,
4645,
531,
199,
84,
16,
275,
900,
342,
199,
28885,
275,
13407,
13415,
8,
78,
63,
3179,
29,
78,
63,
3179,
12,
1324,
63,
466,
628,
875,
531,
199,
56,
275,
19009,
14,
4711,
8,
4504,
8,
68,
9,
367,
366,
315,
3066,
63,
576,
9,
199,
5553,
275,
900,
342,
446,
307,
16,
199,
1361,
480,
4456,
315,
450,
2319,
737,
450,
16,
14,
19,
70,
4567,
15,
83,
2,
450,
334,
5553,
12,
666,
63,
890,
63,
887,
1182,
7373,
430,
199,
1361,
480,
3601,
450,
68,
3747,
2895,
2,
450,
302,
63,
10262,
63,
3406,
8,
56,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
xmindltd/xmind-sdk-python
|
xmind/core/saver.py
|
5
|
1401
|
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""
xmind.core.saver
~~~~~~~~~~~~~~~~~
:copyright:
:license:
"""
__author__ = "aiqi@xmind.net <Woody Ai>"
import codecs
from . import const
from .. import utils
class WorkbookSaver(object):
def __init__(self, workbook):
""" Save `WorkbookDocument` as XMind file.
:param workbook: `WorkbookDocument` object
"""
self._workbook = workbook
def _get_content(self):
content_path = utils.join_path(utils.temp_dir(), const.CONTENT_XML)
with codecs.open(content_path, "w", encoding="utf-8") as f:
self._workbook.output(f)
return content_path
def save(self, path=None):
"""
Save the workbook to the given path. If the path is not given, then
will save to the path set in workbook.
"""
path = path or self._workbook.get_path()
if not path:
raise Exception("Please specify a filename for the XMind file")
path = utils.get_abs_path(path)
file_name, ext = utils.split_ext(path)
if ext != const.XMIND_EXT:
raise Exception("XMind filenames require a '%s' extension" % const.XMIND_EXT)
content = self._get_content()
f=utils.compress(path)
f.write(content, const.CONTENT_XML)
def main():
pass
if __name__ == "__main__":
main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
13,
1837,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
272,
17725,
688,
14,
1018,
14,
21166,
272,
18294,
94,
339,
520,
7307,
26,
272,
520,
1682,
26,
199,
199,
624,
199,
199,
363,
2502,
363,
275,
298,
5789,
23104,
32,
10198,
688,
14,
846,
665,
26724,
1351,
437,
73,
4335,
199,
199,
646,
6010,
199,
199,
504,
1275,
492,
950,
199,
504,
2508,
492,
3778,
421,
199,
533,
9361,
2706,
20829,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1736,
2706,
304,
267,
408,
11063,
658,
6517,
2706,
5564,
64,
465,
1323,
45,
688,
570,
14,
398,
520,
635,
1736,
2706,
26,
658,
6517,
2706,
5564,
64,
909,
398,
408,
267,
291,
423,
30765,
275,
1736,
2706,
339,
347,
485,
362,
63,
1317,
8,
277,
304,
267,
1564,
63,
515,
275,
3778,
14,
904,
63,
515,
8,
1208,
14,
808,
63,
694,
1062,
950,
14,
9663,
63,
4317,
9,
398,
543,
6010,
14,
1490,
8,
1317,
63,
515,
12,
298,
87,
401,
2644,
628,
1624,
13,
24,
531,
465,
289,
26,
288,
291,
423,
30765,
14,
1199,
8,
70,
9,
398,
372,
1564,
63,
515,
339,
347,
3354,
8,
277,
12,
931,
29,
403,
304,
267,
408,
267,
11063,
314,
1736,
2706,
370,
314,
1627,
931,
14,
982,
314,
931,
365,
440,
1627,
12,
2066,
267,
911,
3354,
370,
314,
931,
663,
315,
1736,
2706,
14,
267,
408,
267,
931,
275,
931,
503,
291,
423,
30765,
14,
362,
63,
515,
342,
398,
340,
440,
931,
26,
288,
746,
2186,
480,
8254,
4165,
282,
1788,
367,
314,
1323,
45,
688,
570,
531,
398,
931,
275,
3778,
14,
362,
63,
2101,
63,
515,
8,
515,
9,
398,
570,
63,
354,
12,
1599,
275,
3778,
14,
1294,
63,
832,
8,
515,
9,
398,
340,
1599,
1137,
950,
14,
13901,
3192,
63,
2472,
26,
288,
746,
2186,
480,
13901,
688,
6203,
4409,
282,
1543,
83,
7,
3329,
2,
450,
950,
14,
13901,
3192,
63,
2472,
9,
398,
1564,
275,
291,
423,
362,
63,
1317,
342,
398,
289,
29,
1208,
14,
6447,
8,
515,
9,
267,
289,
14,
952,
8,
1317,
12,
950,
14,
9663,
63,
4317,
9,
421,
199,
318,
2446,
837,
272,
986,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
13,
1837,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
272,
17725,
688,
14,
1018,
14,
21166,
272,
18294,
94,
339,
520,
7307,
26,
272,
520,
1682,
26,
199,
199,
624,
199,
199,
363,
2502,
363,
275,
298,
5789,
23104,
32,
10198,
688,
14,
846,
665,
26724,
1351,
437,
73,
4335,
199,
199,
646,
6010,
199,
199,
504,
1275,
492,
950,
199,
504,
2508,
492,
3778,
421,
199,
533,
9361,
2706,
20829,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1736,
2706,
304,
267,
408,
11063,
658,
6517,
2706,
5564,
64,
465,
1323,
45,
688,
570,
14,
398,
520,
635,
1736,
2706,
26,
658,
6517,
2706,
5564,
64,
909,
398,
408,
267,
291,
423,
30765,
275,
1736,
2706,
339,
347,
485,
362,
63,
1317,
8,
277,
304,
267,
1564,
63,
515,
275,
3778,
14,
904,
63,
515,
8,
1208,
14,
808,
63,
694,
1062,
950,
14,
9663,
63,
4317,
9,
398,
543,
6010,
14,
1490,
8,
1317,
63,
515,
12,
298,
87,
401,
2644,
628,
1624,
13,
24,
531,
465,
289,
26,
288,
291,
423,
30765,
14,
1199,
8,
70,
9,
398,
372,
1564,
63,
515,
339,
347,
3354,
8,
277,
12,
931,
29,
403,
304,
267,
408,
267,
11063,
314,
1736,
2706,
370,
314,
1627,
931,
14,
982,
314,
931,
365,
440,
1627,
12,
2066,
267,
911,
3354,
370,
314,
931,
663,
315,
1736,
2706,
14,
267,
408,
267,
931,
275,
931,
503,
291,
423,
30765,
14,
362,
63,
515,
342,
398,
340,
440,
931,
26,
288,
746,
2186,
480,
8254,
4165,
282,
1788,
367,
314,
1323,
45,
688,
570,
531,
398,
931,
275,
3778,
14,
362,
63,
2101,
63,
515,
8,
515,
9,
398,
570,
63,
354,
12,
1599,
275,
3778,
14,
1294,
63,
832,
8,
515,
9,
398,
340,
1599,
1137,
950,
14,
13901,
3192,
63,
2472,
26,
288,
746,
2186,
480,
13901,
688,
6203,
4409,
282,
1543,
83,
7,
3329,
2,
450,
950,
14,
13901,
3192,
63,
2472,
9,
398,
1564,
275,
291,
423,
362,
63,
1317,
342,
398,
289,
29,
1208,
14,
6447,
8,
515,
9,
267,
289,
14,
952,
8,
1317,
12,
950,
14,
9663,
63,
4317,
9,
421,
199,
318,
2446,
837,
272,
986,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
bguillot/OpenUpgrade
|
addons/fleet/fleet.py
|
33
|
47691
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, osv
import time
import datetime
from openerp import tools
from openerp.osv.orm import except_orm
from openerp.tools.translate import _
from dateutil.relativedelta import relativedelta
def str_to_datetime(strdate):
return datetime.datetime.strptime(strdate, tools.DEFAULT_SERVER_DATE_FORMAT)
class fleet_vehicle_cost(osv.Model):
_name = 'fleet.vehicle.cost'
_description = 'Cost related to a vehicle'
_order = 'date desc, vehicle_id asc'
def _get_odometer(self, cr, uid, ids, odometer_id, arg, context):
res = dict.fromkeys(ids, False)
for record in self.browse(cr,uid,ids,context=context):
if record.odometer_id:
res[record.id] = record.odometer_id.value
return res
def _set_odometer(self, cr, uid, id, name, value, args=None, context=None):
if not value:
raise except_orm(_('Operation not allowed!'), _('Emptying the odometer value of a vehicle is not allowed.'))
date = self.browse(cr, uid, id, context=context).date
if not(date):
date = fields.date.context_today(self, cr, uid, context=context)
vehicle_id = self.browse(cr, uid, id, context=context).vehicle_id
data = {'value': value, 'date': date, 'vehicle_id': vehicle_id.id}
odometer_id = self.pool.get('fleet.vehicle.odometer').create(cr, uid, data, context=context)
return self.write(cr, uid, id, {'odometer_id': odometer_id}, context=context)
def _year_get_fnc(self, cr, uid, ids, name, unknow_none, context=None):
res = {}
for record in self.browse(cr, uid, ids, context=context):
if (record.date):
res[record.id] = str(time.strptime(record.date, tools.DEFAULT_SERVER_DATE_FORMAT).tm_year)
else:
res[record.id] = _('Unknown')
return res
_columns = {
'name': fields.related('vehicle_id', 'name', type="char", string='Name', store=True),
'vehicle_id': fields.many2one('fleet.vehicle', 'Vehicle', required=True, help='Vehicle concerned by this log'),
'cost_subtype_id': fields.many2one('fleet.service.type', 'Type', help='Cost type purchased with this cost'),
'amount': fields.float('Total Price'),
'cost_type': fields.selection([('contract', 'Contract'), ('services','Services'), ('fuel','Fuel'), ('other','Other')], 'Category of the cost', help='For internal purpose only', required=True),
'parent_id': fields.many2one('fleet.vehicle.cost', 'Parent', help='Parent cost to this current cost'),
'cost_ids': fields.one2many('fleet.vehicle.cost', 'parent_id', 'Included Services'),
'odometer_id': fields.many2one('fleet.vehicle.odometer', 'Odometer', help='Odometer measure of the vehicle at the moment of this log'),
'odometer': fields.function(_get_odometer, fnct_inv=_set_odometer, type='float', string='Odometer Value', help='Odometer measure of the vehicle at the moment of this log'),
'odometer_unit': fields.related('vehicle_id', 'odometer_unit', type="char", string="Unit", readonly=True),
'date' :fields.date('Date',help='Date when the cost has been executed'),
'contract_id': fields.many2one('fleet.vehicle.log.contract', 'Contract', help='Contract attached to this cost'),
'auto_generated': fields.boolean('Automatically Generated', readonly=True, required=True),
'year': fields.function(_year_get_fnc, type="char", string='Year', store=True),
}
_defaults ={
'cost_type': 'other',
}
def create(self, cr, uid, data, context=None):
#make sure that the data are consistent with values of parent and contract records given
if 'parent_id' in data and data['parent_id']:
parent = self.browse(cr, uid, data['parent_id'], context=context)
data['vehicle_id'] = parent.vehicle_id.id
data['date'] = parent.date
data['cost_type'] = parent.cost_type
if 'contract_id' in data and data['contract_id']:
contract = self.pool.get('fleet.vehicle.log.contract').browse(cr, uid, data['contract_id'], context=context)
data['vehicle_id'] = contract.vehicle_id.id
data['cost_subtype_id'] = contract.cost_subtype_id.id
data['cost_type'] = contract.cost_type
if 'odometer' in data and not data['odometer']:
#if received value for odometer is 0, then remove it from the data as it would result to the creation of a
#odometer log with 0, which is to be avoided
del(data['odometer'])
return super(fleet_vehicle_cost, self).create(cr, uid, data, context=context)
class fleet_vehicle_tag(osv.Model):
_name = 'fleet.vehicle.tag'
_columns = {
'name': fields.char('Name', required=True, translate=True),
}
class fleet_vehicle_state(osv.Model):
_name = 'fleet.vehicle.state'
_order = 'sequence asc'
_columns = {
'name': fields.char('Name', required=True),
'sequence': fields.integer('Sequence', help="Used to order the note stages")
}
_sql_constraints = [('fleet_state_name_unique','unique(name)', 'State name already exists')]
class fleet_vehicle_model(osv.Model):
def _model_name_get_fnc(self, cr, uid, ids, field_name, arg, context=None):
res = {}
for record in self.browse(cr, uid, ids, context=context):
name = record.modelname
if record.brand_id.name:
name = record.brand_id.name + ' / ' + name
res[record.id] = name
return res
def on_change_brand(self, cr, uid, ids, model_id, context=None):
if not model_id:
return {'value': {'image_medium': False}}
brand = self.pool.get('fleet.vehicle.model.brand').browse(cr, uid, model_id, context=context)
return {
'value': {
'image_medium': brand.image,
}
}
_name = 'fleet.vehicle.model'
_description = 'Model of a vehicle'
_order = 'name asc'
_columns = {
'name': fields.function(_model_name_get_fnc, type="char", string='Name', store=True),
'modelname': fields.char('Model name', size=32, required=True),
'brand_id': fields.many2one('fleet.vehicle.model.brand', 'Model Brand', required=True, help='Brand of the vehicle'),
'vendors': fields.many2many('res.partner', 'fleet_vehicle_model_vendors', 'model_id', 'partner_id', string='Vendors'),
'image': fields.related('brand_id', 'image', type="binary", string="Logo"),
'image_medium': fields.related('brand_id', 'image_medium', type="binary", string="Logo (medium)"),
'image_small': fields.related('brand_id', 'image_small', type="binary", string="Logo (small)"),
}
class fleet_vehicle_model_brand(osv.Model):
_name = 'fleet.vehicle.model.brand'
_description = 'Brand model of the vehicle'
_order = 'name asc'
def _get_image(self, cr, uid, ids, name, args, context=None):
result = dict.fromkeys(ids, False)
for obj in self.browse(cr, uid, ids, context=context):
result[obj.id] = tools.image_get_resized_images(obj.image)
return result
def _set_image(self, cr, uid, id, name, value, args, context=None):
return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context)
_columns = {
'name': fields.char('Brand Name', size=64, required=True),
'image': fields.binary("Logo",
help="This field holds the image used as logo for the brand, limited to 1024x1024px."),
'image_medium': fields.function(_get_image, fnct_inv=_set_image,
string="Medium-sized photo", type="binary", multi="_get_image",
store = {
'fleet.vehicle.model.brand': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),
},
help="Medium-sized logo of the brand. It is automatically "\
"resized as a 128x128px image, with aspect ratio preserved. "\
"Use this field in form views or some kanban views."),
'image_small': fields.function(_get_image, fnct_inv=_set_image,
string="Smal-sized photo", type="binary", multi="_get_image",
store = {
'fleet.vehicle.model.brand': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),
},
help="Small-sized photo of the brand. It is automatically "\
"resized as a 64x64px image, with aspect ratio preserved. "\
"Use this field anywhere a small image is required."),
}
class fleet_vehicle(osv.Model):
_inherit = 'mail.thread'
def _vehicle_name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None):
res = {}
for record in self.browse(cr, uid, ids, context=context):
res[record.id] = record.model_id.brand_id.name + '/' + record.model_id.modelname + ' / ' + record.license_plate
return res
def return_action_to_open(self, cr, uid, ids, context=None):
""" This opens the xml view specified in xml_id for the current vehicle """
if context is None:
context = {}
if context.get('xml_id'):
res = self.pool.get('ir.actions.act_window').for_xml_id(cr, uid ,'fleet', context['xml_id'], context=context)
res['context'] = context
res['context'].update({'default_vehicle_id': ids[0]})
res['domain'] = [('vehicle_id','=', ids[0])]
return res
return False
def act_show_log_cost(self, cr, uid, ids, context=None):
""" This opens log view to view and add new log for this vehicle, groupby default to only show effective costs
@return: the costs log view
"""
if context is None:
context = {}
res = self.pool.get('ir.actions.act_window').for_xml_id(cr, uid ,'fleet','fleet_vehicle_costs_act', context=context)
res['context'] = context
res['context'].update({
'default_vehicle_id': ids[0],
'search_default_parent_false': True
})
res['domain'] = [('vehicle_id','=', ids[0])]
return res
def _get_odometer(self, cr, uid, ids, odometer_id, arg, context):
res = dict.fromkeys(ids, 0)
for record in self.browse(cr,uid,ids,context=context):
ids = self.pool.get('fleet.vehicle.odometer').search(cr, uid, [('vehicle_id', '=', record.id)], limit=1, order='value desc')
if len(ids) > 0:
res[record.id] = self.pool.get('fleet.vehicle.odometer').browse(cr, uid, ids[0], context=context).value
return res
def _set_odometer(self, cr, uid, id, name, value, args=None, context=None):
if value:
date = fields.date.context_today(self, cr, uid, context=context)
data = {'value': value, 'date': date, 'vehicle_id': id}
return self.pool.get('fleet.vehicle.odometer').create(cr, uid, data, context=context)
def _search_get_overdue_contract_reminder(self, cr, uid, obj, name, args, context):
res = []
for field, operator, value in args:
assert operator in ('=', '!=', '<>') and value in (True, False), 'Operation not supported'
if (operator == '=' and value == True) or (operator in ('<>', '!=') and value == False):
search_operator = 'in'
else:
search_operator = 'not in'
today = fields.date.context_today(self, cr, uid, context=context)
cr.execute('select cost.vehicle_id, count(contract.id) as contract_number FROM fleet_vehicle_cost cost left join fleet_vehicle_log_contract contract on contract.cost_id = cost.id WHERE contract.expiration_date is not null AND contract.expiration_date < %s AND contract.state IN (\'open\', \'toclose\') GROUP BY cost.vehicle_id', (today,))
res_ids = [x[0] for x in cr.fetchall()]
res.append(('id', search_operator, res_ids))
return res
def _search_contract_renewal_due_soon(self, cr, uid, obj, name, args, context):
res = []
for field, operator, value in args:
assert operator in ('=', '!=', '<>') and value in (True, False), 'Operation not supported'
if (operator == '=' and value == True) or (operator in ('<>', '!=') and value == False):
search_operator = 'in'
else:
search_operator = 'not in'
today = fields.date.context_today(self, cr, uid, context=context)
datetime_today = datetime.datetime.strptime(today, tools.DEFAULT_SERVER_DATE_FORMAT)
limit_date = str((datetime_today + relativedelta(days=+15)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT))
cr.execute('select cost.vehicle_id, count(contract.id) as contract_number FROM fleet_vehicle_cost cost left join fleet_vehicle_log_contract contract on contract.cost_id = cost.id WHERE contract.expiration_date is not null AND contract.expiration_date > %s AND contract.expiration_date < %s AND contract.state IN (\'open\', \'toclose\') GROUP BY cost.vehicle_id', (today, limit_date))
res_ids = [x[0] for x in cr.fetchall()]
res.append(('id', search_operator, res_ids))
return res
def _get_contract_reminder_fnc(self, cr, uid, ids, field_names, unknow_none, context=None):
res= {}
for record in self.browse(cr, uid, ids, context=context):
overdue = False
due_soon = False
total = 0
name = ''
for element in record.log_contracts:
if element.state in ('open', 'toclose') and element.expiration_date:
current_date_str = fields.date.context_today(self, cr, uid, context=context)
due_time_str = element.expiration_date
current_date = str_to_datetime(current_date_str)
due_time = str_to_datetime(due_time_str)
diff_time = (due_time-current_date).days
if diff_time < 0:
overdue = True
total += 1
if diff_time < 15 and diff_time >= 0:
due_soon = True;
total += 1
if overdue or due_soon:
ids = self.pool.get('fleet.vehicle.log.contract').search(cr,uid,[('vehicle_id', '=', record.id), ('state', 'in', ('open', 'toclose'))], limit=1, order='expiration_date asc')
if len(ids) > 0:
#we display only the name of the oldest overdue/due soon contract
name=(self.pool.get('fleet.vehicle.log.contract').browse(cr, uid, ids[0], context=context).cost_subtype_id.name)
res[record.id] = {
'contract_renewal_overdue': overdue,
'contract_renewal_due_soon': due_soon,
'contract_renewal_total': (total - 1), #we remove 1 from the real total for display purposes
'contract_renewal_name': name,
}
return res
def _get_default_state(self, cr, uid, context):
try:
model, model_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'fleet', 'vehicle_state_active')
except ValueError:
model_id = False
return model_id
def _count_all(self, cr, uid, ids, field_name, arg, context=None):
Odometer = self.pool['fleet.vehicle.odometer']
LogFuel = self.pool['fleet.vehicle.log.fuel']
LogService = self.pool['fleet.vehicle.log.services']
LogContract = self.pool['fleet.vehicle.log.contract']
Cost = self.pool['fleet.vehicle.cost']
return {
vehicle_id: {
'odometer_count': Odometer.search_count(cr, uid, [('vehicle_id', '=', vehicle_id)], context=context),
'fuel_logs_count': LogFuel.search_count(cr, uid, [('vehicle_id', '=', vehicle_id)], context=context),
'service_count': LogService.search_count(cr, uid, [('vehicle_id', '=', vehicle_id)], context=context),
'contract_count': LogContract.search_count(cr, uid, [('vehicle_id', '=', vehicle_id)], context=context),
'cost_count': Cost.search_count(cr, uid, [('vehicle_id', '=', vehicle_id), ('parent_id', '=', False)], context=context)
}
for vehicle_id in ids
}
_name = 'fleet.vehicle'
_description = 'Information on a vehicle'
_order= 'license_plate asc'
_columns = {
'name': fields.function(_vehicle_name_get_fnc, type="char", string='Name', store=True),
'company_id': fields.many2one('res.company', 'Company'),
'license_plate': fields.char('License Plate', size=32, required=True, help='License plate number of the vehicle (ie: plate number for a car)'),
'vin_sn': fields.char('Chassis Number', size=32, help='Unique number written on the vehicle motor (VIN/SN number)'),
'driver_id': fields.many2one('res.partner', 'Driver', help='Driver of the vehicle'),
'model_id': fields.many2one('fleet.vehicle.model', 'Model', required=True, help='Model of the vehicle'),
'log_fuel': fields.one2many('fleet.vehicle.log.fuel', 'vehicle_id', 'Fuel Logs'),
'log_services': fields.one2many('fleet.vehicle.log.services', 'vehicle_id', 'Services Logs'),
'log_contracts': fields.one2many('fleet.vehicle.log.contract', 'vehicle_id', 'Contracts'),
'cost_count': fields.function(_count_all, type='integer', string="Costs" , multi=True),
'contract_count': fields.function(_count_all, type='integer', string='Contracts', multi=True),
'service_count': fields.function(_count_all, type='integer', string='Services', multi=True),
'fuel_logs_count': fields.function(_count_all, type='integer', string='Fuel Logs', multi=True),
'odometer_count': fields.function(_count_all, type='integer', string='Odometer', multi=True),
'acquisition_date': fields.date('Acquisition Date', required=False, help='Date when the vehicle has been bought'),
'color': fields.char('Color', size=32, help='Color of the vehicle'),
'state_id': fields.many2one('fleet.vehicle.state', 'State', help='Current state of the vehicle', ondelete="set null"),
'location': fields.char('Location', size=128, help='Location of the vehicle (garage, ...)'),
'seats': fields.integer('Seats Number', help='Number of seats of the vehicle'),
'doors': fields.integer('Doors Number', help='Number of doors of the vehicle'),
'tag_ids' :fields.many2many('fleet.vehicle.tag', 'fleet_vehicle_vehicle_tag_rel', 'vehicle_tag_id','tag_id', 'Tags'),
'odometer': fields.function(_get_odometer, fnct_inv=_set_odometer, type='float', string='Last Odometer', help='Odometer measure of the vehicle at the moment of this log'),
'odometer_unit': fields.selection([('kilometers', 'Kilometers'),('miles','Miles')], 'Odometer Unit', help='Unit of the odometer ',required=True),
'transmission': fields.selection([('manual', 'Manual'), ('automatic', 'Automatic')], 'Transmission', help='Transmission Used by the vehicle'),
'fuel_type': fields.selection([('gasoline', 'Gasoline'), ('diesel', 'Diesel'), ('electric', 'Electric'), ('hybrid', 'Hybrid')], 'Fuel Type', help='Fuel Used by the vehicle'),
'horsepower': fields.integer('Horsepower'),
'horsepower_tax': fields.float('Horsepower Taxation'),
'power': fields.integer('Power', help='Power in kW of the vehicle'),
'co2': fields.float('CO2 Emissions', help='CO2 emissions of the vehicle'),
'image': fields.related('model_id', 'image', type="binary", string="Logo"),
'image_medium': fields.related('model_id', 'image_medium', type="binary", string="Logo (medium)"),
'image_small': fields.related('model_id', 'image_small', type="binary", string="Logo (small)"),
'contract_renewal_due_soon': fields.function(_get_contract_reminder_fnc, fnct_search=_search_contract_renewal_due_soon, type="boolean", string='Has Contracts to renew', multi='contract_info'),
'contract_renewal_overdue': fields.function(_get_contract_reminder_fnc, fnct_search=_search_get_overdue_contract_reminder, type="boolean", string='Has Contracts Overdued', multi='contract_info'),
'contract_renewal_name': fields.function(_get_contract_reminder_fnc, type="text", string='Name of contract to renew soon', multi='contract_info'),
'contract_renewal_total': fields.function(_get_contract_reminder_fnc, type="integer", string='Total of contracts due or overdue minus one', multi='contract_info'),
'car_value': fields.float('Car Value', help='Value of the bought vehicle'),
}
_defaults = {
'doors': 5,
'odometer_unit': 'kilometers',
'state_id': _get_default_state,
}
def copy(self, cr, uid, id, default=None, context=None):
if not default:
default = {}
default.update({
'log_fuel':[],
'log_contracts':[],
'log_services':[],
'tag_ids':[],
'vin_sn':'',
})
return super(fleet_vehicle, self).copy(cr, uid, id, default, context=context)
def on_change_model(self, cr, uid, ids, model_id, context=None):
if not model_id:
return {}
model = self.pool.get('fleet.vehicle.model').browse(cr, uid, model_id, context=context)
return {
'value': {
'image_medium': model.image,
}
}
def create(self, cr, uid, data, context=None):
if not context:
context = {}
context.update({'mail_create_nolog': True})
vehicle_id = super(fleet_vehicle, self).create(cr, uid, data, context=context)
vehicle = self.browse(cr, uid, vehicle_id, context=context)
self.message_post(cr, uid, [vehicle_id], body=_('%s %s has been added to the fleet!') % (vehicle.model_id.name,vehicle.license_plate), context=context)
return vehicle_id
def write(self, cr, uid, ids, vals, context=None):
"""
This function write an entry in the openchatter whenever we change important information
on the vehicle like the model, the drive, the state of the vehicle or its license plate
"""
for vehicle in self.browse(cr, uid, ids, context):
changes = []
if 'model_id' in vals and vehicle.model_id.id != vals['model_id']:
value = self.pool.get('fleet.vehicle.model').browse(cr,uid,vals['model_id'],context=context).name
oldmodel = vehicle.model_id.name or _('None')
changes.append(_("Model: from '%s' to '%s'") %(oldmodel, value))
if 'driver_id' in vals and vehicle.driver_id.id != vals['driver_id']:
value = self.pool.get('res.partner').browse(cr,uid,vals['driver_id'],context=context).name
olddriver = (vehicle.driver_id.name) or _('None')
changes.append(_("Driver: from '%s' to '%s'") %(olddriver, value))
if 'state_id' in vals and vehicle.state_id.id != vals['state_id']:
value = self.pool.get('fleet.vehicle.state').browse(cr,uid,vals['state_id'],context=context).name
oldstate = vehicle.state_id.name or _('None')
changes.append(_("State: from '%s' to '%s'") %(oldstate, value))
if 'license_plate' in vals and vehicle.license_plate != vals['license_plate']:
old_license_plate = vehicle.license_plate or _('None')
changes.append(_("License Plate: from '%s' to '%s'") %(old_license_plate, vals['license_plate']))
if len(changes) > 0:
self.message_post(cr, uid, [vehicle.id], body=", ".join(changes), context=context)
vehicle_id = super(fleet_vehicle,self).write(cr, uid, ids, vals, context)
return True
class fleet_vehicle_odometer(osv.Model):
_name='fleet.vehicle.odometer'
_description='Odometer log for a vehicle'
_order='date desc'
def _vehicle_log_name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None):
res = {}
for record in self.browse(cr, uid, ids, context=context):
name = record.vehicle_id.name
if record.date:
name = name+ ' / '+ str(record.date)
res[record.id] = name
return res
def on_change_vehicle(self, cr, uid, ids, vehicle_id, context=None):
if not vehicle_id:
return {}
odometer_unit = self.pool.get('fleet.vehicle').browse(cr, uid, vehicle_id, context=context).odometer_unit
return {
'value': {
'unit': odometer_unit,
}
}
_columns = {
'name': fields.function(_vehicle_log_name_get_fnc, type="char", string='Name', store=True),
'date': fields.date('Date'),
'value': fields.float('Odometer Value', group_operator="max"),
'vehicle_id': fields.many2one('fleet.vehicle', 'Vehicle', required=True),
'unit': fields.related('vehicle_id', 'odometer_unit', type="char", string="Unit", readonly=True),
}
_defaults = {
'date': fields.date.context_today,
}
class fleet_vehicle_log_fuel(osv.Model):
def on_change_vehicle(self, cr, uid, ids, vehicle_id, context=None):
if not vehicle_id:
return {}
vehicle = self.pool.get('fleet.vehicle').browse(cr, uid, vehicle_id, context=context)
odometer_unit = vehicle.odometer_unit
driver = vehicle.driver_id.id
return {
'value': {
'odometer_unit': odometer_unit,
'purchaser_id': driver,
}
}
def on_change_liter(self, cr, uid, ids, liter, price_per_liter, amount, context=None):
#need to cast in float because the value receveid from web client maybe an integer (Javascript and JSON do not
#make any difference between 3.0 and 3). This cause a problem if you encode, for example, 2 liters at 1.5 per
#liter => total is computed as 3.0, then trigger an onchange that recomputes price_per_liter as 3/2=1 (instead
#of 3.0/2=1.5)
#If there is no change in the result, we return an empty dict to prevent an infinite loop due to the 3 intertwine
#onchange. And in order to verify that there is no change in the result, we have to limit the precision of the
#computation to 2 decimal
liter = float(liter)
price_per_liter = float(price_per_liter)
amount = float(amount)
if liter > 0 and price_per_liter > 0 and round(liter*price_per_liter,2) != amount:
return {'value' : {'amount' : round(liter * price_per_liter,2),}}
elif amount > 0 and liter > 0 and round(amount/liter,2) != price_per_liter:
return {'value' : {'price_per_liter' : round(amount / liter,2),}}
elif amount > 0 and price_per_liter > 0 and round(amount/price_per_liter,2) != liter:
return {'value' : {'liter' : round(amount / price_per_liter,2),}}
else :
return {}
def on_change_price_per_liter(self, cr, uid, ids, liter, price_per_liter, amount, context=None):
#need to cast in float because the value receveid from web client maybe an integer (Javascript and JSON do not
#make any difference between 3.0 and 3). This cause a problem if you encode, for example, 2 liters at 1.5 per
#liter => total is computed as 3.0, then trigger an onchange that recomputes price_per_liter as 3/2=1 (instead
#of 3.0/2=1.5)
#If there is no change in the result, we return an empty dict to prevent an infinite loop due to the 3 intertwine
#onchange. And in order to verify that there is no change in the result, we have to limit the precision of the
#computation to 2 decimal
liter = float(liter)
price_per_liter = float(price_per_liter)
amount = float(amount)
if liter > 0 and price_per_liter > 0 and round(liter*price_per_liter,2) != amount:
return {'value' : {'amount' : round(liter * price_per_liter,2),}}
elif amount > 0 and price_per_liter > 0 and round(amount/price_per_liter,2) != liter:
return {'value' : {'liter' : round(amount / price_per_liter,2),}}
elif amount > 0 and liter > 0 and round(amount/liter,2) != price_per_liter:
return {'value' : {'price_per_liter' : round(amount / liter,2),}}
else :
return {}
def on_change_amount(self, cr, uid, ids, liter, price_per_liter, amount, context=None):
#need to cast in float because the value receveid from web client maybe an integer (Javascript and JSON do not
#make any difference between 3.0 and 3). This cause a problem if you encode, for example, 2 liters at 1.5 per
#liter => total is computed as 3.0, then trigger an onchange that recomputes price_per_liter as 3/2=1 (instead
#of 3.0/2=1.5)
#If there is no change in the result, we return an empty dict to prevent an infinite loop due to the 3 intertwine
#onchange. And in order to verify that there is no change in the result, we have to limit the precision of the
#computation to 2 decimal
liter = float(liter)
price_per_liter = float(price_per_liter)
amount = float(amount)
if amount > 0 and liter > 0 and round(amount/liter,2) != price_per_liter:
return {'value': {'price_per_liter': round(amount / liter,2),}}
elif amount > 0 and price_per_liter > 0 and round(amount/price_per_liter,2) != liter:
return {'value': {'liter': round(amount / price_per_liter,2),}}
elif liter > 0 and price_per_liter > 0 and round(liter*price_per_liter,2) != amount:
return {'value': {'amount': round(liter * price_per_liter,2),}}
else :
return {}
def _get_default_service_type(self, cr, uid, context):
try:
model, model_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'fleet', 'type_service_refueling')
except ValueError:
model_id = False
return model_id
_name = 'fleet.vehicle.log.fuel'
_description = 'Fuel log for vehicles'
_inherits = {'fleet.vehicle.cost': 'cost_id'}
_columns = {
'liter': fields.float('Liter'),
'price_per_liter': fields.float('Price Per Liter'),
'purchaser_id': fields.many2one('res.partner', 'Purchaser', domain="['|',('customer','=',True),('employee','=',True)]"),
'inv_ref': fields.char('Invoice Reference', size=64),
'vendor_id': fields.many2one('res.partner', 'Supplier', domain="[('supplier','=',True)]"),
'notes': fields.text('Notes'),
'cost_id': fields.many2one('fleet.vehicle.cost', 'Cost', required=True, ondelete='cascade'),
'cost_amount': fields.related('cost_id', 'amount', string='Amount', type='float', store=True), #we need to keep this field as a related with store=True because the graph view doesn't support (1) to address fields from inherited table and (2) fields that aren't stored in database
}
_defaults = {
'date': fields.date.context_today,
'cost_subtype_id': _get_default_service_type,
'cost_type': 'fuel',
}
class fleet_vehicle_log_services(osv.Model):
def on_change_vehicle(self, cr, uid, ids, vehicle_id, context=None):
if not vehicle_id:
return {}
vehicle = self.pool.get('fleet.vehicle').browse(cr, uid, vehicle_id, context=context)
odometer_unit = vehicle.odometer_unit
driver = vehicle.driver_id.id
return {
'value': {
'odometer_unit': odometer_unit,
'purchaser_id': driver,
}
}
def _get_default_service_type(self, cr, uid, context):
try:
model, model_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'fleet', 'type_service_service_8')
except ValueError:
model_id = False
return model_id
_inherits = {'fleet.vehicle.cost': 'cost_id'}
_name = 'fleet.vehicle.log.services'
_description = 'Services for vehicles'
_columns = {
'purchaser_id': fields.many2one('res.partner', 'Purchaser', domain="['|',('customer','=',True),('employee','=',True)]"),
'inv_ref': fields.char('Invoice Reference', size=64),
'vendor_id': fields.many2one('res.partner', 'Supplier', domain="[('supplier','=',True)]"),
'cost_amount': fields.related('cost_id', 'amount', string='Amount', type='float', store=True), #we need to keep this field as a related with store=True because the graph view doesn't support (1) to address fields from inherited table and (2) fields that aren't stored in database
'notes': fields.text('Notes'),
'cost_id': fields.many2one('fleet.vehicle.cost', 'Cost', required=True, ondelete='cascade'),
}
_defaults = {
'date': fields.date.context_today,
'cost_subtype_id': _get_default_service_type,
'cost_type': 'services'
}
class fleet_service_type(osv.Model):
_name = 'fleet.service.type'
_description = 'Type of services available on a vehicle'
_columns = {
'name': fields.char('Name', required=True, translate=True),
'category': fields.selection([('contract', 'Contract'), ('service', 'Service'), ('both', 'Both')], 'Category', required=True, help='Choose wheter the service refer to contracts, vehicle services or both'),
}
class fleet_vehicle_log_contract(osv.Model):
def scheduler_manage_auto_costs(self, cr, uid, context=None):
#This method is called by a cron task
#It creates costs for contracts having the "recurring cost" field setted, depending on their frequency
#For example, if a contract has a reccuring cost of 200 with a weekly frequency, this method creates a cost of 200 on the first day of each week, from the date of the last recurring costs in the database to today
#If the contract has not yet any recurring costs in the database, the method generates the recurring costs from the start_date to today
#The created costs are associated to a contract thanks to the many2one field contract_id
#If the contract has no start_date, no cost will be created, even if the contract has recurring costs
vehicle_cost_obj = self.pool.get('fleet.vehicle.cost')
d = datetime.datetime.strptime(fields.date.context_today(self, cr, uid, context=context), tools.DEFAULT_SERVER_DATE_FORMAT).date()
contract_ids = self.pool.get('fleet.vehicle.log.contract').search(cr, uid, [('state','!=','closed')], offset=0, limit=None, order=None,context=None, count=False)
deltas = {'yearly': relativedelta(years=+1), 'monthly': relativedelta(months=+1), 'weekly': relativedelta(weeks=+1), 'daily': relativedelta(days=+1)}
for contract in self.pool.get('fleet.vehicle.log.contract').browse(cr, uid, contract_ids, context=context):
if not contract.start_date or contract.cost_frequency == 'no':
continue
found = False
last_cost_date = contract.start_date
if contract.generated_cost_ids:
last_autogenerated_cost_id = vehicle_cost_obj.search(cr, uid, ['&', ('contract_id','=',contract.id), ('auto_generated','=',True)], offset=0, limit=1, order='date desc',context=context, count=False)
if last_autogenerated_cost_id:
found = True
last_cost_date = vehicle_cost_obj.browse(cr, uid, last_autogenerated_cost_id[0], context=context).date
startdate = datetime.datetime.strptime(last_cost_date, tools.DEFAULT_SERVER_DATE_FORMAT).date()
if found:
startdate += deltas.get(contract.cost_frequency)
while (startdate <= d) & (startdate <= datetime.datetime.strptime(contract.expiration_date, tools.DEFAULT_SERVER_DATE_FORMAT).date()):
data = {
'amount': contract.cost_generated,
'date': startdate.strftime(tools.DEFAULT_SERVER_DATE_FORMAT),
'vehicle_id': contract.vehicle_id.id,
'cost_subtype_id': contract.cost_subtype_id.id,
'contract_id': contract.id,
'auto_generated': True
}
cost_id = self.pool.get('fleet.vehicle.cost').create(cr, uid, data, context=context)
startdate += deltas.get(contract.cost_frequency)
return True
def scheduler_manage_contract_expiration(self, cr, uid, context=None):
#This method is called by a cron task
#It manages the state of a contract, possibly by posting a message on the vehicle concerned and updating its status
datetime_today = datetime.datetime.strptime(fields.date.context_today(self, cr, uid, context=context), tools.DEFAULT_SERVER_DATE_FORMAT)
limit_date = (datetime_today + relativedelta(days=+15)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
ids = self.search(cr, uid, ['&', ('state', '=', 'open'), ('expiration_date', '<', limit_date)], offset=0, limit=None, order=None, context=context, count=False)
res = {}
for contract in self.browse(cr, uid, ids, context=context):
if contract.vehicle_id.id in res:
res[contract.vehicle_id.id] += 1
else:
res[contract.vehicle_id.id] = 1
for vehicle, value in res.items():
self.pool.get('fleet.vehicle').message_post(cr, uid, vehicle, body=_('%s contract(s) need(s) to be renewed and/or closed!') % (str(value)), context=context)
return self.write(cr, uid, ids, {'state': 'toclose'}, context=context)
def run_scheduler(self, cr, uid, context=None):
self.scheduler_manage_auto_costs(cr, uid, context=context)
self.scheduler_manage_contract_expiration(cr, uid, context=context)
return True
def _vehicle_contract_name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None):
res = {}
for record in self.browse(cr, uid, ids, context=context):
name = record.vehicle_id.name
if record.cost_subtype_id.name:
name += ' / '+ record.cost_subtype_id.name
if record.date:
name += ' / '+ record.date
res[record.id] = name
return res
def on_change_vehicle(self, cr, uid, ids, vehicle_id, context=None):
if not vehicle_id:
return {}
odometer_unit = self.pool.get('fleet.vehicle').browse(cr, uid, vehicle_id, context=context).odometer_unit
return {
'value': {
'odometer_unit': odometer_unit,
}
}
def compute_next_year_date(self, strdate):
oneyear = datetime.timedelta(days=365)
curdate = str_to_datetime(strdate)
return datetime.datetime.strftime(curdate + oneyear, tools.DEFAULT_SERVER_DATE_FORMAT)
def on_change_start_date(self, cr, uid, ids, strdate, enddate, context=None):
if (strdate):
return {'value': {'expiration_date': self.compute_next_year_date(strdate),}}
return {}
def get_days_left(self, cr, uid, ids, prop, unknow_none, context=None):
"""return a dict with as value for each contract an integer
if contract is in an open state and is overdue, return 0
if contract is in a closed state, return -1
otherwise return the number of days before the contract expires
"""
res = {}
for record in self.browse(cr, uid, ids, context=context):
if (record.expiration_date and (record.state == 'open' or record.state == 'toclose')):
today = str_to_datetime(time.strftime(tools.DEFAULT_SERVER_DATE_FORMAT))
renew_date = str_to_datetime(record.expiration_date)
diff_time = (renew_date-today).days
res[record.id] = diff_time > 0 and diff_time or 0
else:
res[record.id] = -1
return res
def act_renew_contract(self, cr, uid, ids, context=None):
assert len(ids) == 1, "This operation should only be done for 1 single contract at a time, as it it suppose to open a window as result"
for element in self.browse(cr, uid, ids, context=context):
#compute end date
startdate = str_to_datetime(element.start_date)
enddate = str_to_datetime(element.expiration_date)
diffdate = (enddate - startdate)
default = {
'date': fields.date.context_today(self, cr, uid, context=context),
'start_date': datetime.datetime.strftime(str_to_datetime(element.expiration_date) + datetime.timedelta(days=1), tools.DEFAULT_SERVER_DATE_FORMAT),
'expiration_date': datetime.datetime.strftime(enddate + diffdate, tools.DEFAULT_SERVER_DATE_FORMAT),
}
newid = super(fleet_vehicle_log_contract, self).copy(cr, uid, element.id, default, context=context)
mod, modid = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'fleet', 'fleet_vehicle_log_contract_form')
return {
'name':_("Renew Contract"),
'view_mode': 'form',
'view_id': modid,
'view_type': 'tree,form',
'res_model': 'fleet.vehicle.log.contract',
'type': 'ir.actions.act_window',
'nodestroy': True,
'domain': '[]',
'res_id': newid,
'context': {'active_id':newid},
}
def _get_default_contract_type(self, cr, uid, context=None):
try:
model, model_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'fleet', 'type_contract_leasing')
except ValueError:
model_id = False
return model_id
def on_change_indic_cost(self, cr, uid, ids, cost_ids, context=None):
totalsum = 0.0
for element in cost_ids:
if element and len(element) == 3 and element[2] is not False:
totalsum += element[2].get('amount', 0.0)
return {
'value': {
'sum_cost': totalsum,
}
}
def _get_sum_cost(self, cr, uid, ids, field_name, arg, context=None):
res = {}
for contract in self.browse(cr, uid, ids, context=context):
totalsum = 0
for cost in contract.cost_ids:
totalsum += cost.amount
res[contract.id] = totalsum
return res
_inherits = {'fleet.vehicle.cost': 'cost_id'}
_name = 'fleet.vehicle.log.contract'
_description = 'Contract information on a vehicle'
_order='state desc,expiration_date'
_columns = {
'name': fields.function(_vehicle_contract_name_get_fnc, type="text", string='Name', store=True),
'start_date': fields.date('Contract Start Date', help='Date when the coverage of the contract begins'),
'expiration_date': fields.date('Contract Expiration Date', help='Date when the coverage of the contract expirates (by default, one year after begin date)'),
'days_left': fields.function(get_days_left, type='integer', string='Warning Date'),
'insurer_id' :fields.many2one('res.partner', 'Supplier'),
'purchaser_id': fields.many2one('res.partner', 'Contractor', help='Person to which the contract is signed for'),
'ins_ref': fields.char('Contract Reference', size=64),
'state': fields.selection([('open', 'In Progress'), ('toclose','To Close'), ('closed', 'Terminated')], 'Status', readonly=True, help='Choose wheter the contract is still valid or not'),
'notes': fields.text('Terms and Conditions', help='Write here all supplementary informations relative to this contract'),
'cost_generated': fields.float('Recurring Cost Amount', help="Costs paid at regular intervals, depending on the cost frequency. If the cost frequency is set to unique, the cost will be logged at the start date"),
'cost_frequency': fields.selection([('no','No'), ('daily', 'Daily'), ('weekly','Weekly'), ('monthly','Monthly'), ('yearly','Yearly')], 'Recurring Cost Frequency', help='Frequency of the recuring cost', required=True),
'generated_cost_ids': fields.one2many('fleet.vehicle.cost', 'contract_id', 'Generated Costs', ondelete='cascade'),
'sum_cost': fields.function(_get_sum_cost, type='float', string='Indicative Costs Total'),
'cost_id': fields.many2one('fleet.vehicle.cost', 'Cost', required=True, ondelete='cascade'),
'cost_amount': fields.related('cost_id', 'amount', string='Amount', type='float', store=True), #we need to keep this field as a related with store=True because the graph view doesn't support (1) to address fields from inherited table and (2) fields that aren't stored in database
}
_defaults = {
'purchaser_id': lambda self, cr, uid, ctx: self.pool.get('res.users').browse(cr, uid, uid, context=ctx).partner_id.id or False,
'date': fields.date.context_today,
'start_date': fields.date.context_today,
'state':'open',
'expiration_date': lambda self, cr, uid, ctx: self.compute_next_year_date(fields.date.context_today(self, cr, uid, context=ctx)),
'cost_frequency': 'no',
'cost_subtype_id': _get_default_contract_type,
'cost_type': 'contract',
}
def copy(self, cr, uid, id, default=None, context=None):
if default is None:
default = {}
today = fields.date.context_today(self, cr, uid, context=context)
default['date'] = today
default['start_date'] = today
default['expiration_date'] = self.compute_next_year_date(today)
default['ins_ref'] = ''
default['state'] = 'open'
default['notes'] = ''
return super(fleet_vehicle_log_contract, self).copy(cr, uid, id, default, context=context)
def contract_close(self, cr, uid, ids, context=None):
return self.write(cr, uid, ids, {'state': 'closed'}, context=context)
def contract_open(self, cr, uid, ids, context=None):
return self.write(cr, uid, ids, {'state': 'open'}, context=context)
class fleet_contract_state(osv.Model):
_name = 'fleet.contract.state'
_description = 'Contains the different possible status of a leasing contract'
_columns = {
'name':fields.char('Contract Status', size=64, required=True),
}
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
646,
900,
199,
646,
2197,
199,
504,
5166,
492,
7249,
199,
504,
5166,
14,
4795,
14,
1025,
492,
871,
63,
1025,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
504,
22208,
14,
32300,
492,
20599,
199,
199,
318,
620,
63,
475,
63,
2083,
8,
495,
602,
304,
272,
372,
2197,
14,
2083,
14,
9866,
8,
495,
602,
12,
7249,
14,
3472,
63,
6613,
63,
5390,
63,
4807,
9,
199,
199,
533,
289,
274,
386,
63,
20073,
63,
6336,
8,
4795,
14,
1685,
304,
272,
485,
354,
275,
283,
21599,
386,
14,
20073,
14,
6336,
7,
272,
485,
1802,
275,
283,
15568,
4048,
370,
282,
27616,
7,
272,
485,
1648,
275,
283,
602,
4328,
12,
27616,
63,
344,
16635,
7,
339,
347,
485,
362,
63,
364,
1377,
351,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
312,
1117,
10011,
63,
344,
12,
1680,
12,
1067,
304,
267,
522,
275,
1211,
14,
19164,
8,
1580,
12,
756,
9,
267,
367,
2777,
315,
291,
14,
4570,
8,
1556,
12,
1535,
12,
1580,
12,
1100,
29,
1100,
304,
288,
340,
2777,
14,
364,
1377,
351,
63,
344,
26,
355,
522,
59,
3059,
14,
344,
61,
275,
2777,
14,
364,
1377,
351,
63,
344,
14,
585,
267,
372,
522,
339,
347,
485,
409,
63,
364,
1377,
351,
8,
277,
12,
2467,
12,
1747,
12,
1305,
12,
536,
12,
574,
12,
1249,
29,
403,
12,
1067,
29,
403,
304,
267,
340,
440,
574,
26,
288,
746,
871,
63,
1025,
6723,
6044,
440,
4370,
15659,
4018,
4699,
316,
314,
312,
1117,
10011,
574,
402,
282,
27616,
365,
440,
4370,
12459,
267,
1434,
275,
291,
14,
4570,
8,
1556,
12,
1747,
12,
1305,
12,
1067,
29,
1100,
680,
602,
267,
340,
440,
8,
602,
304,
288,
1434,
275,
1504,
14,
602,
14,
1100,
63,
8136,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
1100,
9,
267,
27616,
63,
344,
275,
291,
14,
4570,
8,
1556,
12,
1747,
12,
1305,
12,
1067,
29,
1100,
680,
20073,
63,
344,
267,
666,
275,
791,
585,
356,
574,
12,
283,
602,
356,
1434,
12,
283,
20073,
63,
344,
356,
27616,
63,
344,
14,
344,
93,
267,
312,
1117,
10011,
63,
344,
275,
291,
14,
2293,
14,
362,
360,
21599,
386,
14,
20073,
14,
364,
1377,
351,
1959,
981,
8,
1556,
12,
1747,
12,
666,
12,
1067,
29,
1100,
9,
267,
372,
291,
14,
952,
8,
1556,
12,
1747,
12,
1305,
12,
791,
364,
1377,
351,
63,
344,
356,
312,
1117,
10011,
63,
344,
1386,
1067,
29,
1100,
9,
339,
347,
485,
3403,
63,
362,
63,
2324,
67,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
625,
14996,
63,
3592,
12,
1067,
29,
403,
304,
267,
522,
275,
1052,
267,
367,
2777,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
340,
334,
3059,
14,
602,
304,
355,
522,
59,
3059,
14,
344,
61,
275,
620,
8,
521,
14,
9866,
8,
3059,
14,
602,
12,
7249,
14,
3472,
63,
6613,
63,
5390,
63,
4807,
680,
7574,
63,
3403,
9,
288,
587,
26,
355,
522,
59,
3059,
14,
344,
61,
275,
4018,
5912,
358,
267,
372,
522,
339,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
2407,
360,
20073,
63,
344,
297,
283,
354,
297,
730,
628,
1560,
401,
1059,
534,
985,
297,
3877,
29,
549,
395,
267,
283,
20073,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
21599,
386,
14,
20073,
297,
283,
15169,
13438,
297,
1415,
29,
549,
12,
1720,
534,
15169,
13438,
406,
2247,
7439,
701,
642,
943,
659,
267,
283,
6336,
63,
10512,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
21599,
386,
14,
1364,
14,
466,
297,
283,
804,
297,
1720,
534,
15568,
730,
15932,
68,
543,
642,
7918,
659,
267,
283,
4606,
356,
1504,
14,
1609,
360,
7316,
20276,
659,
267,
283,
6336,
63,
466,
356,
1504,
14,
5592,
8318,
14624,
297,
283,
714,
6908,
659,
661,
5950,
1673,
15803,
659,
661,
70,
13086,
1673,
38,
13086,
659,
661,
1848,
1673,
8632,
2665,
283,
7841,
402,
314,
7918,
297,
1720,
534,
1858,
5007,
12016,
1454,
297,
1415,
29,
549,
395,
267,
283,
1708,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
21599,
386,
14,
20073,
14,
6336,
297,
283,
6652,
297,
1720,
534,
6652,
7918,
370,
642,
1453,
7918,
659,
267,
283,
6336,
63,
1580,
356,
1504,
14,
368,
18,
3479,
360,
21599,
386,
14,
20073,
14,
6336,
297,
283,
1708,
63,
344,
297,
283,
607,
3331,
21813,
659,
267,
283,
364,
1377,
351,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
21599,
386,
14,
20073,
14,
364,
1377,
351,
297,
283,
47,
1117,
10011,
297,
1720,
534,
47,
1117,
10011,
9775,
402,
314,
27616,
737,
314,
12427,
402,
642,
943,
659,
267,
283,
364,
1377,
351,
356,
1504,
14,
1593,
1547,
362
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
646,
900,
199,
646,
2197,
199,
504,
5166,
492,
7249,
199,
504,
5166,
14,
4795,
14,
1025,
492,
871,
63,
1025,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
504,
22208,
14,
32300,
492,
20599,
199,
199,
318,
620,
63,
475,
63,
2083,
8,
495,
602,
304,
272,
372,
2197,
14,
2083,
14,
9866,
8,
495,
602,
12,
7249,
14,
3472,
63,
6613,
63,
5390,
63,
4807,
9,
199,
199,
533,
289,
274,
386,
63,
20073,
63,
6336,
8,
4795,
14,
1685,
304,
272,
485,
354,
275,
283,
21599,
386,
14,
20073,
14,
6336,
7,
272,
485,
1802,
275,
283,
15568,
4048,
370,
282,
27616,
7,
272,
485,
1648,
275,
283,
602,
4328,
12,
27616,
63,
344,
16635,
7,
339,
347,
485,
362,
63,
364,
1377,
351,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
312,
1117,
10011,
63,
344,
12,
1680,
12,
1067,
304,
267,
522,
275,
1211,
14,
19164,
8,
1580,
12,
756,
9,
267,
367,
2777,
315,
291,
14,
4570,
8,
1556,
12,
1535,
12,
1580,
12,
1100,
29,
1100,
304,
288,
340,
2777,
14,
364,
1377,
351,
63,
344,
26,
355,
522,
59,
3059,
14,
344,
61,
275,
2777,
14,
364,
1377,
351,
63,
344,
14,
585,
267,
372,
522,
339,
347,
485,
409,
63,
364,
1377,
351,
8,
277,
12,
2467,
12,
1747,
12,
1305,
12,
536,
12,
574,
12,
1249,
29,
403,
12,
1067,
29,
403,
304,
267,
340,
440,
574,
26,
288,
746,
871,
63,
1025,
6723,
6044,
440,
4370,
15659,
4018,
4699,
316,
314,
312,
1117,
10011,
574,
402,
282,
27616,
365,
440,
4370,
12459,
267,
1434,
275,
291,
14,
4570,
8,
1556,
12,
1747,
12,
1305,
12,
1067,
29,
1100,
680,
602,
267,
340,
440,
8,
602,
304,
288,
1434,
275,
1504,
14,
602,
14,
1100,
63,
8136,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
1100,
9,
267,
27616,
63,
344,
275,
291,
14,
4570,
8,
1556,
12,
1747,
12,
1305,
12,
1067,
29,
1100,
680,
20073,
63,
344,
267,
666,
275,
791,
585,
356,
574,
12,
283,
602,
356,
1434,
12,
283,
20073,
63,
344,
356,
27616,
63,
344,
14,
344,
93,
267,
312,
1117,
10011,
63,
344,
275,
291,
14,
2293,
14,
362,
360,
21599,
386,
14,
20073,
14,
364,
1377,
351,
1959,
981,
8,
1556,
12,
1747,
12,
666,
12,
1067,
29,
1100,
9,
267,
372,
291,
14,
952,
8,
1556,
12,
1747,
12,
1305,
12,
791,
364,
1377,
351,
63,
344,
356,
312,
1117,
10011,
63,
344,
1386,
1067,
29,
1100,
9,
339,
347,
485,
3403,
63,
362,
63,
2324,
67,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
625,
14996,
63,
3592,
12,
1067,
29,
403,
304,
267,
522,
275,
1052,
267,
367,
2777,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
340,
334,
3059,
14,
602,
304,
355,
522,
59,
3059,
14,
344,
61,
275,
620,
8,
521,
14,
9866,
8,
3059,
14,
602,
12,
7249,
14,
3472,
63,
6613,
63,
5390,
63,
4807,
680,
7574,
63,
3403,
9,
288,
587,
26,
355,
522,
59,
3059,
14,
344,
61,
275,
4018,
5912,
358,
267,
372,
522,
339,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
2407,
360,
20073,
63,
344,
297,
283,
354,
297,
730,
628,
1560,
401,
1059,
534,
985,
297,
3877,
29,
549,
395,
267,
283,
20073,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
21599,
386,
14,
20073,
297,
283,
15169,
13438,
297,
1415,
29,
549,
12,
1720,
534,
15169,
13438,
406,
2247,
7439,
701,
642,
943,
659,
267,
283,
6336,
63,
10512,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
21599,
386,
14,
1364,
14,
466,
297,
283,
804,
297,
1720,
534,
15568,
730,
15932,
68,
543,
642,
7918,
659,
267,
283,
4606,
356,
1504,
14,
1609,
360,
7316,
20276,
659,
267,
283,
6336,
63,
466,
356,
1504,
14,
5592,
8318,
14624,
297,
283,
714,
6908,
659,
661,
5950,
1673,
15803,
659,
661,
70,
13086,
1673,
38,
13086,
659,
661,
1848,
1673,
8632,
2665,
283,
7841,
402,
314,
7918,
297,
1720,
534,
1858,
5007,
12016,
1454,
297,
1415,
29,
549,
395,
267,
283,
1708,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
21599,
386,
14,
20073,
14,
6336,
297,
283,
6652,
297,
1720,
534,
6652,
7918,
370,
642,
1453,
7918,
659,
267,
283,
6336,
63,
1580,
356,
1504,
14,
368,
18,
3479,
360,
21599,
386,
14,
20073,
14,
6336,
297,
283,
1708,
63,
344,
297,
283,
607,
3331,
21813,
659,
267,
283,
364,
1377,
351,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
21599,
386,
14,
20073,
14,
364,
1377,
351,
297,
283,
47,
1117,
10011,
297,
1720,
534,
47,
1117,
10011,
9775,
402,
314,
27616,
737,
314,
12427,
402,
642,
943,
659,
267,
283,
364,
1377,
351,
356,
1504,
14,
1593,
1547,
362,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
nhomar/odoo
|
addons/pad/py_etherpad/__init__.py
|
505
|
7804
|
"""Module to talk to EtherpadLite API."""
import json
import urllib
import urllib2
class EtherpadLiteClient:
"""Client to talk to EtherpadLite API."""
API_VERSION = 1 # TODO probably 1.1 sometime soon
CODE_OK = 0
CODE_INVALID_PARAMETERS = 1
CODE_INTERNAL_ERROR = 2
CODE_INVALID_FUNCTION = 3
CODE_INVALID_API_KEY = 4
TIMEOUT = 20
apiKey = ""
baseUrl = "http://localhost:9001/api"
def __init__(self, apiKey=None, baseUrl=None):
if apiKey:
self.apiKey = apiKey
if baseUrl:
self.baseUrl = baseUrl
def call(self, function, arguments=None):
"""Create a dictionary of all parameters"""
url = '%s/%d/%s' % (self.baseUrl, self.API_VERSION, function)
params = arguments or {}
params.update({'apikey': self.apiKey})
data = urllib.urlencode(params, True)
try:
opener = urllib2.build_opener()
request = urllib2.Request(url=url, data=data)
response = opener.open(request, timeout=self.TIMEOUT)
result = response.read()
response.close()
except urllib2.HTTPError:
raise
result = json.loads(result)
if result is None:
raise ValueError("JSON response could not be decoded")
return self.handleResult(result)
def handleResult(self, result):
"""Handle API call result"""
if 'code' not in result:
raise Exception("API response has no code")
if 'message' not in result:
raise Exception("API response has no message")
if 'data' not in result:
result['data'] = None
if result['code'] == self.CODE_OK:
return result['data']
elif result['code'] == self.CODE_INVALID_PARAMETERS or result['code'] == self.CODE_INVALID_API_KEY:
raise ValueError(result['message'])
elif result['code'] == self.CODE_INTERNAL_ERROR:
raise Exception(result['message'])
elif result['code'] == self.CODE_INVALID_FUNCTION:
raise Exception(result['message'])
else:
raise Exception("An unexpected error occurred whilst handling the response")
# GROUPS
# Pads can belong to a group. There will always be public pads that do not belong to a group (or we give this group the id 0)
def createGroup(self):
"""creates a new group"""
return self.call("createGroup")
def createGroupIfNotExistsFor(self, groupMapper):
"""this functions helps you to map your application group ids to etherpad lite group ids"""
return self.call("createGroupIfNotExistsFor", {
"groupMapper": groupMapper
})
def deleteGroup(self, groupID):
"""deletes a group"""
return self.call("deleteGroup", {
"groupID": groupID
})
def listPads(self, groupID):
"""returns all pads of this group"""
return self.call("listPads", {
"groupID": groupID
})
def createGroupPad(self, groupID, padName, text=''):
"""creates a new pad in this group"""
params = {
"groupID": groupID,
"padName": padName,
}
if text:
params['text'] = text
return self.call("createGroupPad", params)
# AUTHORS
# Theses authors are bind to the attributes the users choose (color and name).
def createAuthor(self, name=''):
"""creates a new author"""
params = {}
if name:
params['name'] = name
return self.call("createAuthor", params)
def createAuthorIfNotExistsFor(self, authorMapper, name=''):
"""this functions helps you to map your application author ids to etherpad lite author ids"""
params = {
'authorMapper': authorMapper
}
if name:
params['name'] = name
return self.call("createAuthorIfNotExistsFor", params)
# SESSIONS
# Sessions can be created between a group and a author. This allows
# an author to access more than one group. The sessionID will be set as
# a cookie to the client and is valid until a certain date.
def createSession(self, groupID, authorID, validUntil):
"""creates a new session"""
return self.call("createSession", {
"groupID": groupID,
"authorID": authorID,
"validUntil": validUntil
})
def deleteSession(self, sessionID):
"""deletes a session"""
return self.call("deleteSession", {
"sessionID": sessionID
})
def getSessionInfo(self, sessionID):
"""returns informations about a session"""
return self.call("getSessionInfo", {
"sessionID": sessionID
})
def listSessionsOfGroup(self, groupID):
"""returns all sessions of a group"""
return self.call("listSessionsOfGroup", {
"groupID": groupID
})
def listSessionsOfAuthor(self, authorID):
"""returns all sessions of an author"""
return self.call("listSessionsOfAuthor", {
"authorID": authorID
})
# PAD CONTENT
# Pad content can be updated and retrieved through the API
def getText(self, padID, rev=None):
"""returns the text of a pad"""
params = {"padID": padID}
if rev is not None:
params['rev'] = rev
return self.call("getText", params)
# introduced with pull request merge
def getHtml(self, padID, rev=None):
"""returns the html of a pad"""
params = {"padID": padID}
if rev is not None:
params['rev'] = rev
return self.call("getHTML", params)
def setText(self, padID, text):
"""sets the text of a pad"""
return self.call("setText", {
"padID": padID,
"text": text
})
def setHtml(self, padID, html):
"""sets the text of a pad from html"""
return self.call("setHTML", {
"padID": padID,
"html": html
})
# PAD
# Group pads are normal pads, but with the name schema
# GROUPID$PADNAME. A security manager controls access of them and its
# forbidden for normal pads to include a in the name.
def createPad(self, padID, text=''):
"""creates a new pad"""
params = {
"padID": padID,
}
if text:
params['text'] = text
return self.call("createPad", params)
def getRevisionsCount(self, padID):
"""returns the number of revisions of this pad"""
return self.call("getRevisionsCount", {
"padID": padID
})
def deletePad(self, padID):
"""deletes a pad"""
return self.call("deletePad", {
"padID": padID
})
def getReadOnlyID(self, padID):
"""returns the read only link of a pad"""
return self.call("getReadOnlyID", {
"padID": padID
})
def setPublicStatus(self, padID, publicStatus):
"""sets a boolean for the public status of a pad"""
return self.call("setPublicStatus", {
"padID": padID,
"publicStatus": publicStatus
})
def getPublicStatus(self, padID):
"""return true of false"""
return self.call("getPublicStatus", {
"padID": padID
})
def setPassword(self, padID, password):
"""returns ok or a error message"""
return self.call("setPassword", {
"padID": padID,
"password": password
})
def isPasswordProtected(self, padID):
"""returns true or false"""
return self.call("isPasswordProtected", {
"padID": padID
})
|
agpl-3.0
|
[
624,
2377,
370,
22811,
370,
662,
728,
6226,
19375,
3261,
1041,
199,
199,
646,
2022,
199,
646,
4011,
199,
646,
4011,
18,
421,
199,
533,
662,
728,
6226,
19375,
3041,
26,
272,
408,
3041,
370,
22811,
370,
662,
728,
6226,
19375,
3261,
1041,
272,
3261,
63,
4612,
275,
413,
221,
327,
3254,
8646,
413,
14,
17,
2005,
521,
18930,
339,
22547,
63,
3593,
275,
378,
272,
22547,
63,
9692,
63,
24014,
275,
413,
272,
22547,
63,
17681,
63,
3170,
275,
499,
272,
22547,
63,
9692,
63,
15476,
275,
650,
272,
22547,
63,
9692,
63,
3735,
63,
3078,
275,
841,
272,
29998,
275,
3388,
339,
2986,
1197,
275,
3087,
272,
1300,
6417,
275,
298,
1014,
921,
5967,
26,
25,
4587,
15,
1246,
2,
339,
347,
636,
826,
721,
277,
12,
2986,
1197,
29,
403,
12,
1300,
6417,
29,
403,
304,
267,
340,
2986,
1197,
26,
288,
291,
14,
1246,
1197,
275,
2986,
1197,
398,
340,
1300,
6417,
26,
288,
291,
14,
1095,
6417,
275,
1300,
6417,
339,
347,
1240,
8,
277,
12,
805,
12,
2368,
29,
403,
304,
267,
408,
2499,
282,
2600,
402,
1006,
2633,
624,
267,
1166,
275,
1543,
83,
3149,
68,
3149,
83,
7,
450,
334,
277,
14,
1095,
6417,
12,
291,
14,
3735,
63,
4612,
12,
805,
9,
398,
1862,
275,
2368,
503,
1052,
267,
1862,
14,
873,
3252,
28181,
356,
291,
14,
1246,
1197,
1552,
267,
666,
275,
4011,
14,
10738,
8,
1162,
12,
715,
9,
398,
862,
26,
288,
16088,
275,
4011,
18,
14,
1506,
63,
11637,
342,
288,
1056,
275,
4011,
18,
14,
2017,
8,
633,
29,
633,
12,
666,
29,
576,
9,
288,
1177,
275,
16088,
14,
1490,
8,
1069,
12,
2653,
29,
277,
14,
8899,
9,
288,
754,
275,
1177,
14,
739,
342,
288,
1177,
14,
1600,
342,
267,
871,
4011,
18,
14,
12815,
26,
288,
746,
398,
754,
275,
2022,
14,
3640,
8,
1099,
9,
267,
340,
754,
365,
488,
26,
288,
746,
1722,
480,
6243,
1177,
4293,
440,
506,
11203,
531,
398,
372,
291,
14,
2479,
2889,
8,
1099,
9,
339,
347,
2429,
2889,
8,
277,
12,
754,
304,
267,
408,
5940,
3261,
1240,
754,
624,
267,
340,
283,
600,
7,
440,
315,
754,
26,
288,
746,
2186,
480,
3735,
1177,
965,
949,
1233,
531,
267,
340,
283,
1188,
7,
440,
315,
754,
26,
288,
746,
2186,
480,
3735,
1177,
965,
949,
1245,
531,
398,
340,
283,
576,
7,
440,
315,
754,
26,
288,
754,
459,
576,
418,
275,
488,
398,
340,
754,
459,
600,
418,
508,
291,
14,
6012,
63,
3593,
26,
288,
372,
754,
459,
576,
418,
267,
916,
754,
459,
600,
418,
508,
291,
14,
6012,
63,
9692,
63,
24014,
503,
754,
459,
600,
418,
508,
291,
14,
6012,
63,
9692,
63,
3735,
63,
3078,
26,
288,
746,
1722,
8,
1099,
459,
1188,
1105,
267,
916,
754,
459,
600,
418,
508,
291,
14,
6012,
63,
17681,
63,
3170,
26,
288,
746,
2186,
8,
1099,
459,
1188,
1105,
267,
916,
754,
459,
600,
418,
508,
291,
14,
6012,
63,
9692,
63,
15476,
26,
288,
746,
2186,
8,
1099,
459,
1188,
1105,
267,
587,
26,
288,
746,
2186,
480,
2493,
10537,
1125,
8920,
704,
382,
270,
7252,
314,
1177,
531,
339,
327,
15443,
51,
272,
327,
510,
9402,
883,
13511,
370,
282,
1572,
14,
6006,
911,
3544,
506,
4575,
6567,
83,
626,
886,
440,
13511,
370,
282,
1572,
334,
269,
781,
8120,
642,
1572,
314,
1305,
378,
9,
339,
347,
1218,
2448,
8,
277,
304,
267,
408,
28219,
282,
892,
1572,
624,
267,
372,
291,
14,
1250,
480,
981,
2448,
531,
339,
347,
1218,
2448,
3917,
25095,
1858,
8,
277,
12,
1572,
11880,
304,
267,
408,
3749,
3423,
22577,
1265,
370,
2341,
2195,
4223,
1572,
2762,
370,
30201,
6226,
1212,
266,
1572,
2762,
624,
267,
372,
291,
14,
1250,
480,
981,
2448,
3917,
25095,
1858,
401,
469,
288,
298,
923,
11880,
582,
1572,
11880,
267,
3828,
339,
347,
3145,
2448,
8,
277,
12,
1572,
998,
304,
267,
408,
26289,
282,
1572,
624,
267,
372,
291,
14,
1250,
480,
1807,
2448,
401,
469,
288,
298,
923,
998,
582,
1572,
998,
267,
3828,
339,
347,
769,
48,
9402,
8,
277,
12,
1572,
998,
304,
267,
408,
5808,
1006,
6567,
83,
402,
642,
1572,
624,
267,
372,
291,
14,
1250,
480,
513,
48,
9402,
401,
469,
288,
298,
923,
998,
582,
1572,
998,
267,
3828,
339,
347,
1218,
2448,
18584,
8,
277,
12,
1572,
998,
12,
6567,
985,
12,
1318,
9280,
267,
408,
28219,
282,
892,
6567,
315,
642,
1572,
624,
267,
1862,
275,
469,
288,
298,
923,
998,
582,
1572,
998,
12,
288,
298,
6226,
985,
582,
6567,
985,
12,
267,
789,
267,
340,
1318,
26,
288,
1862,
459,
505,
418,
275,
1318,
267,
372,
291,
14,
1250,
480,
981,
2448,
18584,
401,
1862,
9,
339,
327,
10610,
272,
327,
710,
874,
11462,
787,
5398,
370,
314,
3004,
314,
4390,
11496,
334,
2326,
436,
536,
680,
339,
347,
1218,
5949,
8,
277,
12,
536,
9280,
267,
408,
28219,
282,
892,
4132,
624,
267,
1862,
275,
1052,
267,
340,
536,
26,
288,
1862,
459,
354,
418,
275,
536,
267,
372,
291,
14,
1250,
480,
981,
5949,
401,
1862,
9,
339,
347,
1218,
5949,
3917,
25095,
1858,
8,
277,
12,
4132,
11880,
12,
536,
9280,
267,
408,
3749,
3423,
22577,
1265,
370,
2341,
2195,
4223,
4132,
2762,
370,
30201,
6226,
1212,
266,
4132,
2762,
624,
267,
1862,
275,
469,
288,
283,
2502,
11880,
356,
4132,
11880,
267,
789,
267,
340,
536,
26,
288,
1862,
459,
354,
418,
275,
536,
267,
372,
291,
14,
1250,
480,
981,
5949,
3917,
25095,
1858,
401,
1862,
9,
339,
327,
428,
1608,
2823,
272,
327,
428,
30414,
883,
506,
2737,
3382,
282,
1572,
436,
282,
4132,
14,
961,
6127,
272,
327,
376,
4132,
370,
2879,
1655,
2419,
1373,
1572,
14,
710,
2351,
998,
911,
506,
663,
465,
272,
327,
282,
5494,
370,
314,
1890,
436,
365,
1686,
5133,
282,
9842,
1434,
14,
339,
347,
1218,
4434,
8,
277,
12,
1572,
998,
12,
4132,
998,
12,
1686,
18667,
304,
267,
408,
28219,
282,
892,
2351,
624,
267,
372,
291,
14,
1250,
480,
981,
4434,
401,
469,
288,
298,
923,
998,
582,
1572,
998
] |
[
2377,
370,
22811,
370,
662,
728,
6226,
19375,
3261,
1041,
199,
199,
646,
2022,
199,
646,
4011,
199,
646,
4011,
18,
421,
199,
533,
662,
728,
6226,
19375,
3041,
26,
272,
408,
3041,
370,
22811,
370,
662,
728,
6226,
19375,
3261,
1041,
272,
3261,
63,
4612,
275,
413,
221,
327,
3254,
8646,
413,
14,
17,
2005,
521,
18930,
339,
22547,
63,
3593,
275,
378,
272,
22547,
63,
9692,
63,
24014,
275,
413,
272,
22547,
63,
17681,
63,
3170,
275,
499,
272,
22547,
63,
9692,
63,
15476,
275,
650,
272,
22547,
63,
9692,
63,
3735,
63,
3078,
275,
841,
272,
29998,
275,
3388,
339,
2986,
1197,
275,
3087,
272,
1300,
6417,
275,
298,
1014,
921,
5967,
26,
25,
4587,
15,
1246,
2,
339,
347,
636,
826,
721,
277,
12,
2986,
1197,
29,
403,
12,
1300,
6417,
29,
403,
304,
267,
340,
2986,
1197,
26,
288,
291,
14,
1246,
1197,
275,
2986,
1197,
398,
340,
1300,
6417,
26,
288,
291,
14,
1095,
6417,
275,
1300,
6417,
339,
347,
1240,
8,
277,
12,
805,
12,
2368,
29,
403,
304,
267,
408,
2499,
282,
2600,
402,
1006,
2633,
624,
267,
1166,
275,
1543,
83,
3149,
68,
3149,
83,
7,
450,
334,
277,
14,
1095,
6417,
12,
291,
14,
3735,
63,
4612,
12,
805,
9,
398,
1862,
275,
2368,
503,
1052,
267,
1862,
14,
873,
3252,
28181,
356,
291,
14,
1246,
1197,
1552,
267,
666,
275,
4011,
14,
10738,
8,
1162,
12,
715,
9,
398,
862,
26,
288,
16088,
275,
4011,
18,
14,
1506,
63,
11637,
342,
288,
1056,
275,
4011,
18,
14,
2017,
8,
633,
29,
633,
12,
666,
29,
576,
9,
288,
1177,
275,
16088,
14,
1490,
8,
1069,
12,
2653,
29,
277,
14,
8899,
9,
288,
754,
275,
1177,
14,
739,
342,
288,
1177,
14,
1600,
342,
267,
871,
4011,
18,
14,
12815,
26,
288,
746,
398,
754,
275,
2022,
14,
3640,
8,
1099,
9,
267,
340,
754,
365,
488,
26,
288,
746,
1722,
480,
6243,
1177,
4293,
440,
506,
11203,
531,
398,
372,
291,
14,
2479,
2889,
8,
1099,
9,
339,
347,
2429,
2889,
8,
277,
12,
754,
304,
267,
408,
5940,
3261,
1240,
754,
624,
267,
340,
283,
600,
7,
440,
315,
754,
26,
288,
746,
2186,
480,
3735,
1177,
965,
949,
1233,
531,
267,
340,
283,
1188,
7,
440,
315,
754,
26,
288,
746,
2186,
480,
3735,
1177,
965,
949,
1245,
531,
398,
340,
283,
576,
7,
440,
315,
754,
26,
288,
754,
459,
576,
418,
275,
488,
398,
340,
754,
459,
600,
418,
508,
291,
14,
6012,
63,
3593,
26,
288,
372,
754,
459,
576,
418,
267,
916,
754,
459,
600,
418,
508,
291,
14,
6012,
63,
9692,
63,
24014,
503,
754,
459,
600,
418,
508,
291,
14,
6012,
63,
9692,
63,
3735,
63,
3078,
26,
288,
746,
1722,
8,
1099,
459,
1188,
1105,
267,
916,
754,
459,
600,
418,
508,
291,
14,
6012,
63,
17681,
63,
3170,
26,
288,
746,
2186,
8,
1099,
459,
1188,
1105,
267,
916,
754,
459,
600,
418,
508,
291,
14,
6012,
63,
9692,
63,
15476,
26,
288,
746,
2186,
8,
1099,
459,
1188,
1105,
267,
587,
26,
288,
746,
2186,
480,
2493,
10537,
1125,
8920,
704,
382,
270,
7252,
314,
1177,
531,
339,
327,
15443,
51,
272,
327,
510,
9402,
883,
13511,
370,
282,
1572,
14,
6006,
911,
3544,
506,
4575,
6567,
83,
626,
886,
440,
13511,
370,
282,
1572,
334,
269,
781,
8120,
642,
1572,
314,
1305,
378,
9,
339,
347,
1218,
2448,
8,
277,
304,
267,
408,
28219,
282,
892,
1572,
624,
267,
372,
291,
14,
1250,
480,
981,
2448,
531,
339,
347,
1218,
2448,
3917,
25095,
1858,
8,
277,
12,
1572,
11880,
304,
267,
408,
3749,
3423,
22577,
1265,
370,
2341,
2195,
4223,
1572,
2762,
370,
30201,
6226,
1212,
266,
1572,
2762,
624,
267,
372,
291,
14,
1250,
480,
981,
2448,
3917,
25095,
1858,
401,
469,
288,
298,
923,
11880,
582,
1572,
11880,
267,
3828,
339,
347,
3145,
2448,
8,
277,
12,
1572,
998,
304,
267,
408,
26289,
282,
1572,
624,
267,
372,
291,
14,
1250,
480,
1807,
2448,
401,
469,
288,
298,
923,
998,
582,
1572,
998,
267,
3828,
339,
347,
769,
48,
9402,
8,
277,
12,
1572,
998,
304,
267,
408,
5808,
1006,
6567,
83,
402,
642,
1572,
624,
267,
372,
291,
14,
1250,
480,
513,
48,
9402,
401,
469,
288,
298,
923,
998,
582,
1572,
998,
267,
3828,
339,
347,
1218,
2448,
18584,
8,
277,
12,
1572,
998,
12,
6567,
985,
12,
1318,
9280,
267,
408,
28219,
282,
892,
6567,
315,
642,
1572,
624,
267,
1862,
275,
469,
288,
298,
923,
998,
582,
1572,
998,
12,
288,
298,
6226,
985,
582,
6567,
985,
12,
267,
789,
267,
340,
1318,
26,
288,
1862,
459,
505,
418,
275,
1318,
267,
372,
291,
14,
1250,
480,
981,
2448,
18584,
401,
1862,
9,
339,
327,
10610,
272,
327,
710,
874,
11462,
787,
5398,
370,
314,
3004,
314,
4390,
11496,
334,
2326,
436,
536,
680,
339,
347,
1218,
5949,
8,
277,
12,
536,
9280,
267,
408,
28219,
282,
892,
4132,
624,
267,
1862,
275,
1052,
267,
340,
536,
26,
288,
1862,
459,
354,
418,
275,
536,
267,
372,
291,
14,
1250,
480,
981,
5949,
401,
1862,
9,
339,
347,
1218,
5949,
3917,
25095,
1858,
8,
277,
12,
4132,
11880,
12,
536,
9280,
267,
408,
3749,
3423,
22577,
1265,
370,
2341,
2195,
4223,
4132,
2762,
370,
30201,
6226,
1212,
266,
4132,
2762,
624,
267,
1862,
275,
469,
288,
283,
2502,
11880,
356,
4132,
11880,
267,
789,
267,
340,
536,
26,
288,
1862,
459,
354,
418,
275,
536,
267,
372,
291,
14,
1250,
480,
981,
5949,
3917,
25095,
1858,
401,
1862,
9,
339,
327,
428,
1608,
2823,
272,
327,
428,
30414,
883,
506,
2737,
3382,
282,
1572,
436,
282,
4132,
14,
961,
6127,
272,
327,
376,
4132,
370,
2879,
1655,
2419,
1373,
1572,
14,
710,
2351,
998,
911,
506,
663,
465,
272,
327,
282,
5494,
370,
314,
1890,
436,
365,
1686,
5133,
282,
9842,
1434,
14,
339,
347,
1218,
4434,
8,
277,
12,
1572,
998,
12,
4132,
998,
12,
1686,
18667,
304,
267,
408,
28219,
282,
892,
2351,
624,
267,
372,
291,
14,
1250,
480,
981,
4434,
401,
469,
288,
298,
923,
998,
582,
1572,
998,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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
|
6074
|
# Copyright (C) 2012 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import optparse
import StringIO
import unittest2 as unittest
from webkitpy.common.host_mock import MockHost
from webkitpy.layout_tests import lint_test_expectations
class FakePort(object):
def __init__(self, host, name, path):
self.host = host
self.name = name
self.path = path
def test_configuration(self):
return None
def expectations_dict(self):
self.host.ports_parsed.append(self.name)
return {self.path: ''}
def skipped_layout_tests(self, _):
return set([])
def all_test_configurations(self):
return []
def configuration_specifier_macros(self):
return []
def get_option(self, _, val):
return val
def path_to_generic_test_expectations_file(self):
return ''
class FakeFactory(object):
def __init__(self, host, ports):
self.host = host
self.ports = {}
for port in ports:
self.ports[port.name] = port
def get(self, port_name, *args, **kwargs): # pylint: disable=W0613,E0202
return self.ports[port_name]
def all_port_names(self, platform=None): # pylint: disable=W0613,E0202
return sorted(self.ports.keys())
class LintTest(unittest.TestCase):
def test_all_configurations(self):
host = MockHost()
host.ports_parsed = []
host.port_factory = FakeFactory(host, (FakePort(host, 'a', 'path-to-a'),
FakePort(host, 'b', 'path-to-b'),
FakePort(host, 'b-win', 'path-to-b')))
logging_stream = StringIO.StringIO()
options = optparse.Values({'platform': None})
res = lint_test_expectations.lint(host, options, logging_stream)
self.assertEqual(res, 0)
self.assertEqual(host.ports_parsed, ['a', 'b', 'b-win'])
def test_lint_test_files(self):
logging_stream = StringIO.StringIO()
options = optparse.Values({'platform': 'test-mac-leopard'})
host = MockHost()
# pylint appears to complain incorrectly about the method overrides pylint: disable=E0202,C0322
# FIXME: incorrect complaints about spacing pylint: disable=C0322
host.port_factory.all_port_names = lambda platform=None: [platform]
res = lint_test_expectations.lint(host, options, logging_stream)
self.assertEqual(res, 0)
self.assertIn('Lint succeeded', logging_stream.getvalue())
def test_lint_test_files__errors(self):
options = optparse.Values({'platform': 'test', 'debug_rwt_logging': False})
host = MockHost()
# FIXME: incorrect complaints about spacing pylint: disable=C0322
port = host.port_factory.get(options.platform, options=options)
port.expectations_dict = lambda: {'foo': '-- syntax error1', 'bar': '-- syntax error2'}
host.port_factory.get = lambda platform, options=None: port
host.port_factory.all_port_names = lambda platform=None: [port.name()]
logging_stream = StringIO.StringIO()
res = lint_test_expectations.lint(host, options, logging_stream)
self.assertEqual(res, -1)
self.assertIn('Lint failed', logging_stream.getvalue())
self.assertIn('foo:1', logging_stream.getvalue())
self.assertIn('bar:1', logging_stream.getvalue())
class MainTest(unittest.TestCase):
def test_success(self):
orig_lint_fn = lint_test_expectations.lint
# unused args pylint: disable=W0613
def interrupting_lint(host, options, logging_stream):
raise KeyboardInterrupt
def successful_lint(host, options, logging_stream):
return 0
def exception_raising_lint(host, options, logging_stream):
assert False
stdout = StringIO.StringIO()
stderr = StringIO.StringIO()
try:
lint_test_expectations.lint = interrupting_lint
res = lint_test_expectations.main([], stdout, stderr)
self.assertEqual(res, lint_test_expectations.INTERRUPTED_EXIT_STATUS)
lint_test_expectations.lint = successful_lint
res = lint_test_expectations.main(['--platform', 'test'], stdout, stderr)
self.assertEqual(res, 0)
lint_test_expectations.lint = exception_raising_lint
res = lint_test_expectations.main([], stdout, stderr)
self.assertEqual(res, lint_test_expectations.EXCEPTIONAL_EXIT_STATUS)
finally:
lint_test_expectations.lint = orig_lint_fn
|
bsd-3-clause
|
[
3,
1898,
334,
35,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
8691,
199,
646,
5228,
199,
646,
2882,
18,
465,
2882,
199,
199,
504,
18007,
14,
2330,
14,
1102,
63,
1805,
492,
4420,
4965,
199,
504,
18007,
14,
4209,
63,
2219,
492,
24620,
63,
396,
63,
15752,
421,
199,
533,
7777,
4313,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1591,
12,
536,
12,
931,
304,
267,
291,
14,
1102,
275,
1591,
267,
291,
14,
354,
275,
536,
267,
291,
14,
515,
275,
931,
339,
347,
511,
63,
4758,
8,
277,
304,
267,
372,
488,
339,
347,
21851,
63,
807,
8,
277,
304,
267,
291,
14,
1102,
14,
5203,
63,
6751,
14,
740,
8,
277,
14,
354,
9,
267,
372,
469,
277,
14,
515,
26,
28174,
339,
347,
9645,
63,
4209,
63,
2219,
8,
277,
12,
27574,
267,
372,
663,
4157,
339,
347,
1006,
63,
396,
63,
10057,
8,
277,
304,
267,
372,
942,
339,
347,
2897,
63,
20723,
63,
16358,
8,
277,
304,
267,
372,
942,
339,
347,
664,
63,
1422,
8,
277,
12,
5501,
1139,
304,
267,
372,
1139,
339,
347,
931,
63,
475,
63,
6767,
63,
396,
63,
15752,
63,
493,
8,
277,
304,
267,
372,
2125,
199,
199,
533,
7777,
2927,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1591,
12,
8873,
304,
267,
291,
14,
1102,
275,
1591,
267,
291,
14,
5203,
275,
1052,
267,
367,
1844,
315,
8873,
26,
288,
291,
14,
5203,
59,
719,
14,
354,
61,
275,
1844,
339,
347,
664,
8,
277,
12,
1844,
63,
354,
12,
627,
589,
12,
1011,
958,
304,
221,
327,
4287,
26,
3507,
29,
55,
1690,
969,
12,
37,
996,
996,
267,
372,
291,
14,
5203,
59,
719,
63,
354,
61,
339,
347,
1006,
63,
719,
63,
1247,
8,
277,
12,
4298,
29,
403,
304,
221,
327,
4287,
26,
3507,
29,
55,
1690,
969,
12,
37,
996,
996,
267,
372,
3355,
8,
277,
14,
5203,
14,
1612,
1012,
421,
199,
533,
491,
442,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
452,
63,
10057,
8,
277,
304,
267,
1591,
275,
4420,
4965,
342,
267,
1591,
14,
5203,
63,
6751,
275,
942,
267,
1591,
14,
719,
63,
3702,
275,
7777,
2927,
8,
1102,
12,
334,
8249,
4313,
8,
1102,
12,
283,
65,
297,
283,
515,
13,
475,
13,
65,
659,
6901,
7777,
4313,
8,
1102,
12,
283,
66,
297,
283,
515,
13,
475,
13,
66,
659,
6901,
7777,
4313,
8,
1102,
12,
283,
66,
13,
2676,
297,
283,
515,
13,
475,
13,
66,
7058,
398,
2050,
63,
1745,
275,
5228,
14,
6424,
342,
267,
1511,
275,
8691,
14,
6550,
3252,
3246,
356,
488,
1552,
267,
522,
275,
24620,
63,
396,
63,
15752,
14,
3854,
8,
1102,
12,
1511,
12,
2050,
63,
1745,
9,
267,
291,
14,
629,
8,
470,
12,
378,
9,
267,
291,
14,
629,
8,
1102,
14,
5203,
63,
6751,
12,
788,
65,
297,
283,
66,
297,
283,
66,
13,
2676,
1105,
339,
347,
511,
63,
3854,
63,
396,
63,
1725,
8,
277,
304,
267,
2050,
63,
1745,
275,
5228,
14,
6424,
342,
267,
1511,
275,
8691,
14,
6550,
3252,
3246,
356,
283,
396,
13,
3088,
13,
274,
411,
1005,
3071,
267,
1591,
275,
4420,
4965,
342,
398,
327,
4287,
11337,
370,
24105,
22743,
3595,
314,
1083,
10580,
4287,
26,
3507,
29,
37,
996,
996,
12,
35,
16,
15858,
267,
327,
7600,
26,
8927,
32493,
13141,
3595,
19621,
4287,
26,
3507,
29,
35,
16,
15858,
267,
1591,
14,
719,
63,
3702,
14,
452,
63,
719,
63,
1247,
275,
2400,
4298,
29,
403,
26,
359,
3246,
61,
398,
522,
275,
24620,
63,
396,
63,
15752,
14,
3854,
8,
1102,
12,
1511,
12,
2050,
63,
1745,
9,
398,
291,
14,
629,
8,
470,
12,
378,
9,
267,
291,
14,
4080,
360,
44,
442,
19268,
297,
2050,
63,
1745,
14,
7150,
1012,
339,
347,
511,
63,
3854,
63,
396,
63,
1725,
363,
2550,
8,
277,
304,
267,
1511,
275,
8691,
14,
6550,
3252,
3246,
356,
283,
396,
297,
283,
1757,
63,
82,
9115,
63,
4806,
356,
756,
1552,
267,
1591,
275,
4420,
4965,
342,
398,
327,
7600,
26,
8927,
32493,
13141,
3595,
19621,
4287,
26,
3507,
29,
35,
16,
15858,
267,
1844,
275,
1591,
14,
719,
63,
3702,
14,
362,
8,
1419,
14,
3246
] |
[
1898,
334,
35,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
8691,
199,
646,
5228,
199,
646,
2882,
18,
465,
2882,
199,
199,
504,
18007,
14,
2330,
14,
1102,
63,
1805,
492,
4420,
4965,
199,
504,
18007,
14,
4209,
63,
2219,
492,
24620,
63,
396,
63,
15752,
421,
199,
533,
7777,
4313,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1591,
12,
536,
12,
931,
304,
267,
291,
14,
1102,
275,
1591,
267,
291,
14,
354,
275,
536,
267,
291,
14,
515,
275,
931,
339,
347,
511,
63,
4758,
8,
277,
304,
267,
372,
488,
339,
347,
21851,
63,
807,
8,
277,
304,
267,
291,
14,
1102,
14,
5203,
63,
6751,
14,
740,
8,
277,
14,
354,
9,
267,
372,
469,
277,
14,
515,
26,
28174,
339,
347,
9645,
63,
4209,
63,
2219,
8,
277,
12,
27574,
267,
372,
663,
4157,
339,
347,
1006,
63,
396,
63,
10057,
8,
277,
304,
267,
372,
942,
339,
347,
2897,
63,
20723,
63,
16358,
8,
277,
304,
267,
372,
942,
339,
347,
664,
63,
1422,
8,
277,
12,
5501,
1139,
304,
267,
372,
1139,
339,
347,
931,
63,
475,
63,
6767,
63,
396,
63,
15752,
63,
493,
8,
277,
304,
267,
372,
2125,
199,
199,
533,
7777,
2927,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1591,
12,
8873,
304,
267,
291,
14,
1102,
275,
1591,
267,
291,
14,
5203,
275,
1052,
267,
367,
1844,
315,
8873,
26,
288,
291,
14,
5203,
59,
719,
14,
354,
61,
275,
1844,
339,
347,
664,
8,
277,
12,
1844,
63,
354,
12,
627,
589,
12,
1011,
958,
304,
221,
327,
4287,
26,
3507,
29,
55,
1690,
969,
12,
37,
996,
996,
267,
372,
291,
14,
5203,
59,
719,
63,
354,
61,
339,
347,
1006,
63,
719,
63,
1247,
8,
277,
12,
4298,
29,
403,
304,
221,
327,
4287,
26,
3507,
29,
55,
1690,
969,
12,
37,
996,
996,
267,
372,
3355,
8,
277,
14,
5203,
14,
1612,
1012,
421,
199,
533,
491,
442,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
452,
63,
10057,
8,
277,
304,
267,
1591,
275,
4420,
4965,
342,
267,
1591,
14,
5203,
63,
6751,
275,
942,
267,
1591,
14,
719,
63,
3702,
275,
7777,
2927,
8,
1102,
12,
334,
8249,
4313,
8,
1102,
12,
283,
65,
297,
283,
515,
13,
475,
13,
65,
659,
6901,
7777,
4313,
8,
1102,
12,
283,
66,
297,
283,
515,
13,
475,
13,
66,
659,
6901,
7777,
4313,
8,
1102,
12,
283,
66,
13,
2676,
297,
283,
515,
13,
475,
13,
66,
7058,
398,
2050,
63,
1745,
275,
5228,
14,
6424,
342,
267,
1511,
275,
8691,
14,
6550,
3252,
3246,
356,
488,
1552,
267,
522,
275,
24620,
63,
396,
63,
15752,
14,
3854,
8,
1102,
12,
1511,
12,
2050,
63,
1745,
9,
267,
291,
14,
629,
8,
470,
12,
378,
9,
267,
291,
14,
629,
8,
1102,
14,
5203,
63,
6751,
12,
788,
65,
297,
283,
66,
297,
283,
66,
13,
2676,
1105,
339,
347,
511,
63,
3854,
63,
396,
63,
1725,
8,
277,
304,
267,
2050,
63,
1745,
275,
5228,
14,
6424,
342,
267,
1511,
275,
8691,
14,
6550,
3252,
3246,
356,
283,
396,
13,
3088,
13,
274,
411,
1005,
3071,
267,
1591,
275,
4420,
4965,
342,
398,
327,
4287,
11337,
370,
24105,
22743,
3595,
314,
1083,
10580,
4287,
26,
3507,
29,
37,
996,
996,
12,
35,
16,
15858,
267,
327,
7600,
26,
8927,
32493,
13141,
3595,
19621,
4287,
26,
3507,
29,
35,
16,
15858,
267,
1591,
14,
719,
63,
3702,
14,
452,
63,
719,
63,
1247,
275,
2400,
4298,
29,
403,
26,
359,
3246,
61,
398,
522,
275,
24620,
63,
396,
63,
15752,
14,
3854,
8,
1102,
12,
1511,
12,
2050,
63,
1745,
9,
398,
291,
14,
629,
8,
470,
12,
378,
9,
267,
291,
14,
4080,
360,
44,
442,
19268,
297,
2050,
63,
1745,
14,
7150,
1012,
339,
347,
511,
63,
3854,
63,
396,
63,
1725,
363,
2550,
8,
277,
304,
267,
1511,
275,
8691,
14,
6550,
3252,
3246,
356,
283,
396,
297,
283,
1757,
63,
82,
9115,
63,
4806,
356,
756,
1552,
267,
1591,
275,
4420,
4965,
342,
398,
327,
7600,
26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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
peiyuwang/pants
|
tests/python/pants_test/backend/jvm/tasks/test_jvm_platform_analysis_integration.py
|
21
|
4718
|
# coding=utf-8
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)
import os
from contextlib import contextmanager
from textwrap import dedent
from pants.util.contextutil import temporary_dir
from pants_test.pants_run_integration_test import PantsRunIntegrationTest
class JvmPlatformAnalysisIntegrationTest(PantsRunIntegrationTest):
"""Make sure jvm-platform-analysis runs properly, especially with respect to caching behavior."""
class JavaSandbox(object):
"""Testing sandbox for making temporary java_library targets."""
def __init__(self, test, workdir, javadir):
self.javadir = javadir
self.workdir = workdir
self.test = test
if not os.path.exists(self.workdir):
os.makedirs(self.workdir)
@property
def build_file_path(self):
return os.path.join(self.javadir, 'BUILD')
def write_build_file(self, contents):
with open(self.build_file_path, 'w') as f:
f.write(contents)
def spec(self, name):
return '{}:{}'.format(self.javadir, name)
def clean_all(self):
return self.test.run_pants_with_workdir(['clean-all'], workdir=self.workdir)
def jvm_platform_validate(self, *targets):
return self.test.run_pants_with_workdir(['jvm-platform-validate', '--check=fatal']
+ map(self.spec, targets),
workdir=self.workdir)
@contextmanager
def setup_sandbox(self):
with temporary_dir('.') as sourcedir:
with self.temporary_workdir() as workdir:
javadir = os.path.join(sourcedir, 'src', 'java')
os.makedirs(javadir)
yield self.JavaSandbox(self, workdir, javadir)
@property
def _good_one_two(self):
return dedent("""
java_library(name='one',
platform='1.7',
)
java_library(name='two',
platform='1.8',
)
""")
@property
def _bad_one_two(self):
return dedent("""
java_library(name='one',
platform='1.7',
dependencies=[':two'],
)
java_library(name='two',
platform='1.8',
)
""")
def test_good_targets_works_fresh(self):
with self.setup_sandbox() as sandbox:
sandbox.write_build_file(self._good_one_two)
self.assert_success(sandbox.clean_all())
self.assert_success(sandbox.jvm_platform_validate('one', 'two'))
def test_bad_targets_fails_fresh(self):
with self.setup_sandbox() as sandbox:
sandbox.write_build_file(self._bad_one_two)
self.assert_success(sandbox.clean_all())
self.assert_failure(sandbox.jvm_platform_validate('one', 'two'))
def test_good_then_bad(self):
with self.setup_sandbox() as sandbox:
sandbox.write_build_file(self._good_one_two)
self.assert_success(sandbox.clean_all())
self.assert_success(sandbox.jvm_platform_validate('one', 'two'))
sandbox.write_build_file(self._bad_one_two)
self.assert_failure(sandbox.jvm_platform_validate('one', 'two'))
def test_bad_then_good(self):
with self.setup_sandbox() as sandbox:
sandbox.write_build_file(self._bad_one_two)
self.assert_success(sandbox.clean_all())
self.assert_failure(sandbox.jvm_platform_validate('one', 'two'))
sandbox.write_build_file(self._good_one_two)
self.assert_success(sandbox.jvm_platform_validate('one', 'two'))
def test_good_caching(self):
# Make sure targets are cached after a good run.
with self.setup_sandbox() as sandbox:
sandbox.write_build_file(self._good_one_two)
self.assert_success(sandbox.clean_all())
first_run = sandbox.jvm_platform_validate('one', 'two')
self.assert_success(first_run)
self.assertIn('Invalidated 2 targets', first_run.stdout_data)
second_run = sandbox.jvm_platform_validate('one', 'two')
self.assert_success(second_run)
self.assertNotIn('Invalidated 2 targets', second_run.stdout_data)
def test_bad_caching(self):
# Make sure targets aren't cached after a bad run.
with self.setup_sandbox() as sandbox:
sandbox.write_build_file(self._bad_one_two)
self.assert_success(sandbox.clean_all())
first_run = sandbox.jvm_platform_validate('one', 'two')
self.assert_failure(first_run)
self.assertIn('Invalidated 2 targets', first_run.stdout_data)
second_run = sandbox.jvm_platform_validate('one', 'two')
self.assert_failure(second_run)
self.assertIn('Invalidated 2 targets', second_run.stdout_data)
|
apache-2.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
3,
1898,
6900,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
16952,
12,
6032,
63,
14129,
12,
870,
63,
1593,
12,
717,
2649,
63,
5955,
12,
543,
63,
6242,
9,
199,
199,
646,
747,
199,
504,
15502,
492,
27608,
199,
504,
13390,
492,
22622,
199,
199,
504,
18081,
14,
1974,
14,
1100,
1974,
492,
7937,
63,
694,
199,
504,
18081,
63,
396,
14,
21970,
63,
1065,
63,
15092,
63,
396,
492,
510,
2285,
2540,
20405,
774,
421,
199,
533,
1603,
2611,
10397,
13182,
20405,
774,
8,
27565,
2540,
20405,
774,
304,
523,
408,
5483,
3238,
1335,
2611,
13,
3246,
13,
10466,
7858,
7684,
12,
24002,
543,
14021,
370,
13627,
5953,
1041,
819,
1021,
9586,
29155,
8,
785,
304,
272,
408,
9029,
19699,
367,
10663,
7937,
12120,
63,
4342,
4545,
1041,
339,
347,
636,
826,
721,
277,
12,
511,
12,
1736,
694,
12,
12120,
694,
304,
489,
291,
14,
6138,
694,
275,
12120,
694,
489,
291,
14,
19132,
275,
1736,
694,
489,
291,
14,
396,
275,
511,
489,
340,
440,
747,
14,
515,
14,
2444,
8,
277,
14,
19132,
304,
267,
747,
14,
8347,
8,
277,
14,
19132,
9,
339,
768,
1829,
272,
347,
1900,
63,
493,
63,
515,
8,
277,
304,
489,
372,
747,
14,
515,
14,
904,
8,
277,
14,
6138,
694,
12,
283,
8248,
358,
339,
347,
2218,
63,
1506,
63,
493,
8,
277,
12,
4072,
304,
489,
543,
1551,
8,
277,
14,
1506,
63,
493,
63,
515,
12,
283,
87,
358,
465,
289,
26,
267,
289,
14,
952,
8,
4407,
9,
339,
347,
3158,
8,
277,
12,
536,
304,
489,
372,
9005,
26,
11123,
908,
8,
277,
14,
6138,
694,
12,
536,
9,
339,
347,
3633,
63,
452,
8,
277,
304,
489,
372,
291,
14,
396,
14,
1065,
63,
21970,
63,
1045,
63,
19132,
2941,
3118,
13,
452,
995,
1736,
694,
29,
277,
14,
19132,
9,
339,
347,
1335,
2611,
63,
3246,
63,
3502,
8,
277,
12,
627,
4684,
304,
489,
372,
291,
14,
396,
14,
1065,
63,
21970,
63,
1045,
63,
19132,
2941,
15813,
13,
3246,
13,
3502,
297,
2850,
1074,
29,
16208,
418,
6343,
435,
2341,
8,
277,
14,
1650,
12,
4545,
395,
6343,
1736,
694,
29,
277,
14,
19132,
9,
819,
768,
14237,
523,
347,
3272,
63,
16647,
8,
277,
304,
272,
543,
7937,
63,
694,
7563,
465,
1350,
694,
26,
489,
543,
291,
14,
13555,
63,
19132,
342,
465,
1736,
694,
26,
267,
12120,
694,
275,
747,
14,
515,
14,
904,
8,
1365,
694,
12,
283,
2164,
297,
283,
6138,
358,
267,
747,
14,
8347,
8,
6138,
694,
9,
267,
1995,
291,
14,
12576,
29155,
8,
277,
12,
1736,
694,
12,
12120,
694,
9,
819,
768,
1829,
523,
347,
485,
8302,
63,
368,
63,
5601,
8,
277,
304,
272,
372,
22622,
4852,
489,
12120,
63,
4342,
8,
354,
534,
368,
297,
267,
4298,
534,
17,
14,
23,
297,
489,
776,
2541,
12120,
63,
4342,
8,
354,
534,
5601,
297,
267,
4298,
534,
17,
14,
24,
297,
489,
776,
272,
7857,
819,
768,
1829,
523,
347,
485,
4087,
63,
368,
63,
5601,
8,
277,
304,
272,
372,
22622,
4852,
489,
12120,
63,
4342,
8,
354,
534,
368,
297,
267,
4298,
534,
17,
14,
23,
297,
267,
5124,
1524,
356,
5601,
995,
489,
776,
2541,
12120,
63,
4342,
8,
354,
534,
5601,
297,
267,
4298,
534,
17,
14,
24,
297,
489,
776,
272,
7857,
819,
347,
511,
63,
8302,
63,
4684,
63,
12243,
63,
25488,
8,
277,
304,
272,
543,
291,
14,
2758,
63,
16647,
342,
465,
19699,
26,
489,
19699,
14,
952,
63,
1506,
63,
493,
8,
277,
423,
8302,
63,
368,
63,
5601,
9,
489,
291,
14,
479,
63,
3742,
8,
16647,
14,
3118,
63,
452,
1012,
489,
291,
14,
479,
63,
3742,
8,
16647,
14,
15813,
63,
3246,
63,
3502,
360,
368,
297,
283,
5601,
1333,
819,
347,
511,
63,
4087,
63,
4684,
63,
15762,
63,
25488,
8,
277,
304,
272,
543,
291,
14,
2758,
63,
16647,
342,
465,
19699,
26,
489,
19699,
14,
952,
63,
1506,
63,
493,
8,
277,
423,
4087,
63,
368,
63,
5601,
9,
489,
291,
14,
479,
63,
3742,
8,
16647,
14,
3118,
63,
452,
1012,
489,
291,
14,
479,
63,
5328,
8,
16647,
14,
15813,
63,
3246,
63,
3502,
360,
368,
297,
283,
5601,
1333,
819,
347,
511,
63,
8302,
63,
12726,
63,
4087,
8,
277,
304,
272,
543,
291,
14,
2758,
63,
16647,
342,
465,
19699,
26,
489,
19699,
14,
952,
63,
1506,
63,
493,
8,
277,
423,
8302,
63,
368,
63,
5601,
9,
489,
291,
14,
479,
63,
3742,
8,
16647,
14,
3118,
63,
452,
1012,
489,
291,
14,
479,
63,
3742,
8,
16647,
14,
15813,
63,
3246,
63,
3502,
360,
368,
297,
283,
5601,
1333,
489,
19699,
14,
952,
63,
1506,
63,
493,
8,
277,
423,
4087,
63,
368,
63,
5601,
9,
489,
291,
14,
479,
63,
5328,
8,
16647,
14,
15813,
63,
3246,
63,
3502,
360,
368,
297,
283,
5601,
1333,
819,
347,
511,
63,
4087,
63,
12726,
63,
8302,
8,
277,
304,
272,
543,
291,
14,
2758,
63,
16647,
342,
465,
19699,
26,
489,
19699,
14,
952,
63,
1506,
63,
493,
8,
277,
423,
4087,
63,
368,
63,
5601,
9,
489,
291,
14,
479,
63,
3742,
8,
16647,
14,
3118,
63,
452,
1012,
489,
291,
14,
479,
63,
5328,
8,
16647,
14,
15813,
63,
3246,
63,
3502,
360,
368,
297,
283,
5601,
1333,
489,
19699,
14,
952,
63,
1506,
63,
493,
8,
277,
423,
8302,
63,
368,
63,
5601,
9,
489,
291,
14,
479,
63,
3742,
8,
16647,
14,
15813,
63,
3246,
63,
3502,
360,
368,
297,
283,
5601,
1333,
819,
347,
511,
63,
8302,
63,
22738,
8,
277,
304,
272,
327,
4155,
3238,
4545,
787,
6328,
2410,
282,
6954,
1255,
14,
272,
543,
291,
14,
2758,
63,
16647,
342,
465,
19699,
26,
489,
19699,
14,
952,
63,
1506,
63,
493,
8,
277,
423,
8302,
63,
368,
63,
5601,
9,
489,
291,
14,
479,
63,
3742
] |
[
2803,
29,
1624,
13,
24,
199,
3,
1898,
6900,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
16952,
12,
6032,
63,
14129,
12,
870,
63,
1593,
12,
717,
2649,
63,
5955,
12,
543,
63,
6242,
9,
199,
199,
646,
747,
199,
504,
15502,
492,
27608,
199,
504,
13390,
492,
22622,
199,
199,
504,
18081,
14,
1974,
14,
1100,
1974,
492,
7937,
63,
694,
199,
504,
18081,
63,
396,
14,
21970,
63,
1065,
63,
15092,
63,
396,
492,
510,
2285,
2540,
20405,
774,
421,
199,
533,
1603,
2611,
10397,
13182,
20405,
774,
8,
27565,
2540,
20405,
774,
304,
523,
408,
5483,
3238,
1335,
2611,
13,
3246,
13,
10466,
7858,
7684,
12,
24002,
543,
14021,
370,
13627,
5953,
1041,
819,
1021,
9586,
29155,
8,
785,
304,
272,
408,
9029,
19699,
367,
10663,
7937,
12120,
63,
4342,
4545,
1041,
339,
347,
636,
826,
721,
277,
12,
511,
12,
1736,
694,
12,
12120,
694,
304,
489,
291,
14,
6138,
694,
275,
12120,
694,
489,
291,
14,
19132,
275,
1736,
694,
489,
291,
14,
396,
275,
511,
489,
340,
440,
747,
14,
515,
14,
2444,
8,
277,
14,
19132,
304,
267,
747,
14,
8347,
8,
277,
14,
19132,
9,
339,
768,
1829,
272,
347,
1900,
63,
493,
63,
515,
8,
277,
304,
489,
372,
747,
14,
515,
14,
904,
8,
277,
14,
6138,
694,
12,
283,
8248,
358,
339,
347,
2218,
63,
1506,
63,
493,
8,
277,
12,
4072,
304,
489,
543,
1551,
8,
277,
14,
1506,
63,
493,
63,
515,
12,
283,
87,
358,
465,
289,
26,
267,
289,
14,
952,
8,
4407,
9,
339,
347,
3158,
8,
277,
12,
536,
304,
489,
372,
9005,
26,
11123,
908,
8,
277,
14,
6138,
694,
12,
536,
9,
339,
347,
3633,
63,
452,
8,
277,
304,
489,
372,
291,
14,
396,
14,
1065,
63,
21970,
63,
1045,
63,
19132,
2941,
3118,
13,
452,
995,
1736,
694,
29,
277,
14,
19132,
9,
339,
347,
1335,
2611,
63,
3246,
63,
3502,
8,
277,
12,
627,
4684,
304,
489,
372,
291,
14,
396,
14,
1065,
63,
21970,
63,
1045,
63,
19132,
2941,
15813,
13,
3246,
13,
3502,
297,
2850,
1074,
29,
16208,
418,
6343,
435,
2341,
8,
277,
14,
1650,
12,
4545,
395,
6343,
1736,
694,
29,
277,
14,
19132,
9,
819,
768,
14237,
523,
347,
3272,
63,
16647,
8,
277,
304,
272,
543,
7937,
63,
694,
7563,
465,
1350,
694,
26,
489,
543,
291,
14,
13555,
63,
19132,
342,
465,
1736,
694,
26,
267,
12120,
694,
275,
747,
14,
515,
14,
904,
8,
1365,
694,
12,
283,
2164,
297,
283,
6138,
358,
267,
747,
14,
8347,
8,
6138,
694,
9,
267,
1995,
291,
14,
12576,
29155,
8,
277,
12,
1736,
694,
12,
12120,
694,
9,
819,
768,
1829,
523,
347,
485,
8302,
63,
368,
63,
5601,
8,
277,
304,
272,
372,
22622,
4852,
489,
12120,
63,
4342,
8,
354,
534,
368,
297,
267,
4298,
534,
17,
14,
23,
297,
489,
776,
2541,
12120,
63,
4342,
8,
354,
534,
5601,
297,
267,
4298,
534,
17,
14,
24,
297,
489,
776,
272,
7857,
819,
768,
1829,
523,
347,
485,
4087,
63,
368,
63,
5601,
8,
277,
304,
272,
372,
22622,
4852,
489,
12120,
63,
4342,
8,
354,
534,
368,
297,
267,
4298,
534,
17,
14,
23,
297,
267,
5124,
1524,
356,
5601,
995,
489,
776,
2541,
12120,
63,
4342,
8,
354,
534,
5601,
297,
267,
4298,
534,
17,
14,
24,
297,
489,
776,
272,
7857,
819,
347,
511,
63,
8302,
63,
4684,
63,
12243,
63,
25488,
8,
277,
304,
272,
543,
291,
14,
2758,
63,
16647,
342,
465,
19699,
26,
489,
19699,
14,
952,
63,
1506,
63,
493,
8,
277,
423,
8302,
63,
368,
63,
5601,
9,
489,
291,
14,
479,
63,
3742,
8,
16647,
14,
3118,
63,
452,
1012,
489,
291,
14,
479,
63,
3742,
8,
16647,
14,
15813,
63,
3246,
63,
3502,
360,
368,
297,
283,
5601,
1333,
819,
347,
511,
63,
4087,
63,
4684,
63,
15762,
63,
25488,
8,
277,
304,
272,
543,
291,
14,
2758,
63,
16647,
342,
465,
19699,
26,
489,
19699,
14,
952,
63,
1506,
63,
493,
8,
277,
423,
4087,
63,
368,
63,
5601,
9,
489,
291,
14,
479,
63,
3742,
8,
16647,
14,
3118,
63,
452,
1012,
489,
291,
14,
479,
63,
5328,
8,
16647,
14,
15813,
63,
3246,
63,
3502,
360,
368,
297,
283,
5601,
1333,
819,
347,
511,
63,
8302,
63,
12726,
63,
4087,
8,
277,
304,
272,
543,
291,
14,
2758,
63,
16647,
342,
465,
19699,
26,
489,
19699,
14,
952,
63,
1506,
63,
493,
8,
277,
423,
8302,
63,
368,
63,
5601,
9,
489,
291,
14,
479,
63,
3742,
8,
16647,
14,
3118,
63,
452,
1012,
489,
291,
14,
479,
63,
3742,
8,
16647,
14,
15813,
63,
3246,
63,
3502,
360,
368,
297,
283,
5601,
1333,
489,
19699,
14,
952,
63,
1506,
63,
493,
8,
277,
423,
4087,
63,
368,
63,
5601,
9,
489,
291,
14,
479,
63,
5328,
8,
16647,
14,
15813,
63,
3246,
63,
3502,
360,
368,
297,
283,
5601,
1333,
819,
347,
511,
63,
4087,
63,
12726,
63,
8302,
8,
277,
304,
272,
543,
291,
14,
2758,
63,
16647,
342,
465,
19699,
26,
489,
19699,
14,
952,
63,
1506,
63,
493,
8,
277,
423,
4087,
63,
368,
63,
5601,
9,
489,
291,
14,
479,
63,
3742,
8,
16647,
14,
3118,
63,
452,
1012,
489,
291,
14,
479,
63,
5328,
8,
16647,
14,
15813,
63,
3246,
63,
3502,
360,
368,
297,
283,
5601,
1333,
489,
19699,
14,
952,
63,
1506,
63,
493,
8,
277,
423,
8302,
63,
368,
63,
5601,
9,
489,
291,
14,
479,
63,
3742,
8,
16647,
14,
15813,
63,
3246,
63,
3502,
360,
368,
297,
283,
5601,
1333,
819,
347,
511,
63,
8302,
63,
22738,
8,
277,
304,
272,
327,
4155,
3238,
4545,
787,
6328,
2410,
282,
6954,
1255,
14,
272,
543,
291,
14,
2758,
63,
16647,
342,
465,
19699,
26,
489,
19699,
14,
952,
63,
1506,
63,
493,
8,
277,
423,
8302,
63,
368,
63,
5601,
9,
489,
291,
14,
479,
63,
3742,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
jcai19/smm_gem5
|
tests/configs/memtest-ruby.py
|
9
|
4768
|
# Copyright (c) 2006-2007 The Regents of The University of Michigan
# Copyright (c) 2010 Advanced Micro Devices, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors: Ron Dreslinski
import m5
from m5.objects import *
from m5.defines import buildEnv
from m5.util import addToPath
import os, optparse, sys
# Get paths we might need
config_path = os.path.dirname(os.path.abspath(__file__))
config_root = os.path.dirname(config_path)
m5_root = os.path.dirname(config_root)
addToPath(config_root+'/configs/common')
addToPath(config_root+'/configs/ruby')
addToPath(config_root+'/configs/topologies')
import Ruby
import Options
parser = optparse.OptionParser()
Options.addCommonOptions(parser)
# Add the ruby specific and protocol specific options
Ruby.define_options(parser)
(options, args) = parser.parse_args()
#
# Set the default cache size and associativity to be very small to encourage
# races between requests and writebacks.
#
options.l1d_size="256B"
options.l1i_size="256B"
options.l2_size="512B"
options.l3_size="1kB"
options.l1d_assoc=2
options.l1i_assoc=2
options.l2_assoc=2
options.l3_assoc=2
options.ports=32
#MAX CORES IS 8 with the fals sharing method
nb_cores = 8
# ruby does not support atomic, functional, or uncacheable accesses
cpus = [ MemTest(atomic=False, percent_functional=50,
percent_uncacheable=0, suppress_func_warnings=True) \
for i in xrange(nb_cores) ]
# overwrite options.num_cpus with the nb_cores value
options.num_cpus = nb_cores
# system simulated
system = System(cpu = cpus,
funcmem = SimpleMemory(in_addr_map = False),
physmem = SimpleMemory(null = True),
funcbus = NoncoherentXBar())
# Dummy voltage domain for all our clock domains
system.voltage_domain = VoltageDomain()
system.clk_domain = SrcClockDomain(clock = '1GHz',
voltage_domain = system.voltage_domain)
# Create a seperate clock domain for components that should run at
# CPUs frequency
system.cpu_clk_domain = SrcClockDomain(clock = '2GHz',
voltage_domain = system.voltage_domain)
# All cpus are associated with cpu_clk_domain
for cpu in cpus:
cpu.clk_domain = system.cpu_clk_domain
system.mem_ranges = AddrRange('256MB')
Ruby.create_system(options, system)
# Create a separate clock domain for Ruby
system.ruby.clk_domain = SrcClockDomain(clock = options.ruby_clock,
voltage_domain = system.voltage_domain)
assert(len(cpus) == len(system.ruby._cpu_ports))
for (i, ruby_port) in enumerate(system.ruby._cpu_ports):
#
# Tie the cpu test and functional ports to the ruby cpu ports and
# physmem, respectively
#
cpus[i].test = ruby_port.slave
cpus[i].functional = system.funcbus.slave
#
# Since the memtester is incredibly bursty, increase the deadlock
# threshold to 1 million cycles
#
ruby_port.deadlock_threshold = 1000000
# connect reference memory to funcbus
system.funcmem.port = system.funcbus.master
# -----------------------
# run simulation
# -----------------------
root = Root(full_system = False, system = system)
root.system.mem_mode = 'timing'
# Not much point in this being higher than the L1 latency
m5.ticks.setGlobalFrequency('1ns')
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
8315,
13,
9488,
710,
5044,
24871,
402,
710,
15904,
402,
603,
1158,
528,
290,
199,
3,
1898,
334,
67,
9,
7129,
32445,
27022,
12272,
83,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
32472,
577,
470,
472,
10728,
199,
199,
646,
333,
21,
199,
504,
333,
21,
14,
1462,
492,
627,
199,
504,
333,
21,
14,
14334,
492,
1900,
7744,
199,
504,
333,
21,
14,
1974,
492,
1050,
1378,
2042,
199,
646,
747,
12,
8691,
12,
984,
199,
199,
3,
2372,
3792,
781,
5594,
1929,
199,
888,
63,
515,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
888,
63,
1231,
275,
747,
14,
515,
14,
3475,
8,
888,
63,
515,
9,
199,
77,
21,
63,
1231,
275,
747,
14,
515,
14,
3475,
8,
888,
63,
1231,
9,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
2330,
358,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
21952,
358,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
16851,
15241,
358,
199,
199,
646,
820,
10972,
199,
646,
8394,
199,
199,
2087,
275,
8691,
14,
14553,
342,
199,
4558,
14,
525,
7844,
4558,
8,
2087,
9,
199,
199,
3,
2654,
314,
31855,
2488,
436,
4113,
2488,
1511,
199,
50,
10972,
14,
4640,
63,
1419,
8,
2087,
9,
199,
199,
8,
1419,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
3,
199,
3,
2494,
314,
849,
2581,
1568,
436,
4035,
2159,
18936,
370,
506,
7437,
7425,
370,
655,
25715,
474,
199,
3,
660,
823,
3382,
4145,
436,
2218,
894,
83,
14,
199,
3,
199,
1419,
14,
76,
17,
68,
63,
890,
628,
3912,
34,
2,
199,
1419,
14,
76,
17,
73,
63,
890,
628,
3912,
34,
2,
199,
1419,
14,
76,
18,
63,
890,
628,
7736,
34,
2,
199,
1419,
14,
76,
19,
63,
890,
628,
17,
75,
34,
2,
199,
1419,
14,
76,
17,
68,
63,
16824,
29,
18,
199,
1419,
14,
76,
17,
73,
63,
16824,
29,
18,
199,
1419,
14,
76,
18,
63,
16824,
29,
18,
199,
1419,
14,
76,
19,
63,
16824,
29,
18,
199,
1419,
14,
5203,
29,
708,
199,
199,
3,
4283,
18886,
654,
2281,
1695,
543,
314,
289,
2551,
26994,
1083,
199,
4994,
63,
4630,
275,
1695,
199,
199,
3,
31855,
1630,
440,
2291,
15374,
12,
22380,
12,
503,
625,
1637,
461,
1066,
5804,
199,
8896,
275,
359,
30465,
774,
8,
10910,
29,
797,
12,
8878,
63,
15481,
29,
1400,
12,
326,
8878,
63,
324,
1637,
461,
29,
16,
12,
15678,
63,
1532,
63,
5451,
29,
549,
9,
971,
268,
367,
284,
315,
4945,
8,
4994,
63,
4630,
9,
1622,
199,
199,
3,
8970,
1511,
14,
1507,
63,
8896,
543,
314,
8526,
63,
4630,
574,
199,
1419,
14,
1507,
63,
8896,
275,
8526,
63,
4630,
523,
199,
3,
2656,
4389,
8097,
199,
2253,
275,
6187,
8,
3541,
275,
24174,
12,
355,
2562,
5286,
275,
5870,
8628,
8,
262,
63,
2697,
63,
1130,
275,
756,
395,
355,
3945,
588,
5286,
275,
5870,
8628,
8,
2307,
275,
715,
395,
355,
2562,
5610,
275,
10172,
331,
426,
640,
56,
5281,
1012,
199,
3,
9762,
29943,
2881,
367,
1006,
4154,
12516,
14006,
199,
2253,
14,
27543,
63,
2261,
275,
16171,
15028,
7705,
342,
199,
2253,
14,
429,
75,
63,
2261,
275,
428,
1195,
17387,
7705,
8,
9597,
275,
283,
17,
39,
13026,
297,
3521,
29943,
63,
2261,
275,
2656,
14,
27543,
63,
2261,
9,
199,
199,
3,
2790,
282,
542,
529,
323,
12516,
2881,
367,
7323,
626,
1077,
1255,
737,
199,
3,
28504,
9857,
199,
2253,
14,
3541,
63,
429,
75,
63,
2261,
275,
428,
1195,
17387,
7705,
8,
9597,
275,
283,
18,
39,
13026,
297,
4318,
29943,
63,
2261,
275,
2656,
14,
27543,
63,
2261,
9,
199,
199,
3,
2900,
24174,
787,
4568,
543,
5033,
63,
429,
75,
63,
2261,
199,
509,
5033,
315,
24174,
26,
272,
5033,
14,
429,
75,
63,
2261,
275,
2656,
14,
3541,
63,
429,
75,
63,
2261,
199,
199,
2253,
14,
5286,
63,
8404,
275,
2654,
82,
4709,
360,
3912,
4567,
358,
199,
199,
50,
10972,
14,
981,
63,
2253,
8,
1419,
12,
2656,
9,
199,
199,
3,
2790,
282,
7396,
12516,
2881,
367,
820,
10972,
199,
2253,
14,
21952,
14,
429,
75,
63,
2261,
275,
428,
1195,
17387,
7705,
8
] |
[
1898,
334,
67,
9,
8315,
13,
9488,
710,
5044,
24871,
402,
710,
15904,
402,
603,
1158,
528,
290,
199,
3,
1898,
334,
67,
9,
7129,
32445,
27022,
12272,
83,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
32472,
577,
470,
472,
10728,
199,
199,
646,
333,
21,
199,
504,
333,
21,
14,
1462,
492,
627,
199,
504,
333,
21,
14,
14334,
492,
1900,
7744,
199,
504,
333,
21,
14,
1974,
492,
1050,
1378,
2042,
199,
646,
747,
12,
8691,
12,
984,
199,
199,
3,
2372,
3792,
781,
5594,
1929,
199,
888,
63,
515,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
888,
63,
1231,
275,
747,
14,
515,
14,
3475,
8,
888,
63,
515,
9,
199,
77,
21,
63,
1231,
275,
747,
14,
515,
14,
3475,
8,
888,
63,
1231,
9,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
2330,
358,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
21952,
358,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
16851,
15241,
358,
199,
199,
646,
820,
10972,
199,
646,
8394,
199,
199,
2087,
275,
8691,
14,
14553,
342,
199,
4558,
14,
525,
7844,
4558,
8,
2087,
9,
199,
199,
3,
2654,
314,
31855,
2488,
436,
4113,
2488,
1511,
199,
50,
10972,
14,
4640,
63,
1419,
8,
2087,
9,
199,
199,
8,
1419,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
3,
199,
3,
2494,
314,
849,
2581,
1568,
436,
4035,
2159,
18936,
370,
506,
7437,
7425,
370,
655,
25715,
474,
199,
3,
660,
823,
3382,
4145,
436,
2218,
894,
83,
14,
199,
3,
199,
1419,
14,
76,
17,
68,
63,
890,
628,
3912,
34,
2,
199,
1419,
14,
76,
17,
73,
63,
890,
628,
3912,
34,
2,
199,
1419,
14,
76,
18,
63,
890,
628,
7736,
34,
2,
199,
1419,
14,
76,
19,
63,
890,
628,
17,
75,
34,
2,
199,
1419,
14,
76,
17,
68,
63,
16824,
29,
18,
199,
1419,
14,
76,
17,
73,
63,
16824,
29,
18,
199,
1419,
14,
76,
18,
63,
16824,
29,
18,
199,
1419,
14,
76,
19,
63,
16824,
29,
18,
199,
1419,
14,
5203,
29,
708,
199,
199,
3,
4283,
18886,
654,
2281,
1695,
543,
314,
289,
2551,
26994,
1083,
199,
4994,
63,
4630,
275,
1695,
199,
199,
3,
31855,
1630,
440,
2291,
15374,
12,
22380,
12,
503,
625,
1637,
461,
1066,
5804,
199,
8896,
275,
359,
30465,
774,
8,
10910,
29,
797,
12,
8878,
63,
15481,
29,
1400,
12,
326,
8878,
63,
324,
1637,
461,
29,
16,
12,
15678,
63,
1532,
63,
5451,
29,
549,
9,
971,
268,
367,
284,
315,
4945,
8,
4994,
63,
4630,
9,
1622,
199,
199,
3,
8970,
1511,
14,
1507,
63,
8896,
543,
314,
8526,
63,
4630,
574,
199,
1419,
14,
1507,
63,
8896,
275,
8526,
63,
4630,
523,
199,
3,
2656,
4389,
8097,
199,
2253,
275,
6187,
8,
3541,
275,
24174,
12,
355,
2562,
5286,
275,
5870,
8628,
8,
262,
63,
2697,
63,
1130,
275,
756,
395,
355,
3945,
588,
5286,
275,
5870,
8628,
8,
2307,
275,
715,
395,
355,
2562,
5610,
275,
10172,
331,
426,
640,
56,
5281,
1012,
199,
3,
9762,
29943,
2881,
367,
1006,
4154,
12516,
14006,
199,
2253,
14,
27543,
63,
2261,
275,
16171,
15028,
7705,
342,
199,
2253,
14,
429,
75,
63,
2261,
275,
428,
1195,
17387,
7705,
8,
9597,
275,
283,
17,
39,
13026,
297,
3521,
29943,
63,
2261,
275,
2656,
14,
27543,
63,
2261,
9,
199,
199,
3,
2790,
282,
542,
529,
323,
12516,
2881,
367,
7323,
626,
1077,
1255,
737,
199,
3,
28504,
9857,
199,
2253,
14,
3541,
63,
429,
75,
63,
2261,
275,
428,
1195,
17387,
7705,
8,
9597,
275,
283,
18,
39,
13026,
297,
4318,
29943,
63,
2261,
275,
2656,
14,
27543,
63,
2261,
9,
199,
199,
3,
2900,
24174,
787,
4568,
543,
5033,
63,
429,
75,
63,
2261,
199,
509,
5033,
315,
24174,
26,
272,
5033,
14,
429,
75,
63,
2261,
275,
2656,
14,
3541,
63,
429,
75,
63,
2261,
199,
199,
2253,
14,
5286,
63,
8404,
275,
2654,
82,
4709,
360,
3912,
4567,
358,
199,
199,
50,
10972,
14,
981,
63,
2253,
8,
1419,
12,
2656,
9,
199,
199,
3,
2790,
282,
7396,
12516,
2881,
367,
820,
10972,
199,
2253,
14,
21952,
14,
429,
75,
63,
2261,
275,
428,
1195,
17387,
7705,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
abhiatgithub/shogun-toolbox
|
examples/undocumented/python_modular/graphical/converter_fastica_bss.py
|
36
|
1108
|
"""
Blind Source Separation using the FastICA Algorithm with Shogun
Based on the example from scikit-learn
http://scikit-learn.org/
Kevin Hughes 2013
"""
import numpy as np
import pylab as pl
from shogun.Features import RealFeatures
from shogun.Converter import FastICA
# Generate sample data
np.random.seed(0)
n_samples = 2000
time = np.linspace(0, 10, n_samples)
# Source Signals
s1 = np.sin(2 * time) # sin wave
s2 = np.sign(np.sin(3 * time)) # square wave
S = np.c_[s1, s2]
S += 0.2 * np.random.normal(size=S.shape) # add noise
# Standardize data
S /= S.std(axis=0)
S = S.T
# Mixing Matrix
A = np.array([[1, 0.5], [0.5, 1]])
# Mix Signals
X = np.dot(A,S)
mixed_signals = RealFeatures(X)
# Separating
ica = FastICA()
signals = ica.apply(mixed_signals)
S_ = signals.get_feature_matrix()
A_ = ica.get_mixing_matrix();
# Plot results
pl.figure()
pl.subplot(3, 1, 1)
pl.plot(S.T)
pl.title('True Sources')
pl.subplot(3, 1, 2)
pl.plot(X.T)
pl.title('Mixed Sources')
pl.subplot(3, 1, 3)
pl.plot(S_.T)
pl.title('Estimated Sources')
pl.subplots_adjust(0.09, 0.04, 0.94, 0.94, 0.26, 0.36)
pl.show()
|
gpl-3.0
|
[
624,
199,
34,
24491,
5800,
27504,
425,
1808,
314,
22613,
948,
33,
23823,
543,
428,
526,
17924,
199,
199,
20409,
641,
314,
2893,
687,
6276,
6065,
13,
4643,
199,
1014,
921,
551,
3258,
390,
13,
4643,
14,
1308,
15,
199,
199,
1136,
11908,
869,
3080,
397,
6171,
199,
624,
421,
199,
646,
2680,
465,
980,
199,
646,
19199,
465,
1620,
199,
199,
504,
930,
17924,
14,
10807,
221,
492,
14849,
10807,
199,
504,
930,
17924,
14,
11907,
492,
22613,
948,
33,
199,
199,
3,
7958,
2690,
666,
199,
1590,
14,
2355,
14,
5176,
8,
16,
9,
199,
78,
63,
3356,
275,
12293,
199,
521,
275,
980,
14,
11649,
8,
16,
12,
1616,
12,
302,
63,
3356,
9,
199,
199,
3,
5800,
6632,
2551,
199,
83,
17,
275,
980,
14,
5911,
8,
18,
627,
900,
9,
221,
327,
9829,
12204,
199,
83,
18,
275,
980,
14,
1037,
8,
1590,
14,
5911,
8,
19,
627,
900,
430,
221,
327,
12386,
12204,
199,
51,
275,
980,
14,
67,
9925,
83,
17,
12,
308,
18,
61,
199,
51,
847,
378,
14,
18,
627,
980,
14,
2355,
14,
3302,
8,
890,
29,
51,
14,
1392,
9,
221,
327,
1050,
11145,
199,
199,
3,
1933,
460,
18980,
806,
666,
199,
51,
12257,
428,
14,
1516,
8,
3127,
29,
16,
9,
199,
51,
275,
428,
14,
52,
199,
199,
3,
603,
1148,
316,
8449,
199,
33,
275,
980,
14,
1144,
4038,
17,
12,
378,
14,
21,
467,
359,
16,
14,
21,
12,
413,
3934,
199,
199,
3,
603,
1148,
6632,
2551,
199,
56,
275,
980,
14,
3287,
8,
33,
12,
51,
9,
199,
10455,
63,
10458,
275,
14849,
10807,
8,
56,
9,
199,
199,
3,
27504,
1958,
199,
24027,
275,
22613,
948,
33,
342,
199,
10458,
275,
284,
696,
14,
4998,
8,
10455,
63,
10458,
9,
199,
51,
63,
275,
10166,
14,
362,
63,
4445,
63,
3642,
342,
199,
33,
63,
275,
284,
696,
14,
362,
63,
13979,
316,
63,
3642,
7303,
199,
199,
3,
14794,
2058,
199,
1168,
14,
8941,
342,
199,
1168,
14,
13334,
8,
19,
12,
413,
12,
413,
9,
199,
1168,
14,
2798,
8,
51,
14,
52,
9,
199,
1168,
14,
1213,
360,
549,
5800,
83,
358,
199,
1168,
14,
13334,
8,
19,
12,
413,
12,
499,
9,
199,
1168,
14,
2798,
8,
56,
14,
52,
9,
199,
1168,
14,
1213,
360,
17899,
5800,
83,
358,
199,
1168,
14,
13334,
8,
19,
12,
413,
12,
650,
9,
199,
1168,
14,
2798,
8,
51,
3754,
52,
9,
199,
1168,
14,
1213,
360,
9169,
12754,
5800,
83,
358,
199,
1168,
14,
21430,
63,
10917,
8,
16,
14,
1643,
12,
378,
14,
966,
12,
378,
14,
2635,
12,
378,
14,
2635,
12,
378,
14,
1479,
12,
378,
14,
1344,
9,
199,
1168,
14,
2384,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
34,
24491,
5800,
27504,
425,
1808,
314,
22613,
948,
33,
23823,
543,
428,
526,
17924,
199,
199,
20409,
641,
314,
2893,
687,
6276,
6065,
13,
4643,
199,
1014,
921,
551,
3258,
390,
13,
4643,
14,
1308,
15,
199,
199,
1136,
11908,
869,
3080,
397,
6171,
199,
624,
421,
199,
646,
2680,
465,
980,
199,
646,
19199,
465,
1620,
199,
199,
504,
930,
17924,
14,
10807,
221,
492,
14849,
10807,
199,
504,
930,
17924,
14,
11907,
492,
22613,
948,
33,
199,
199,
3,
7958,
2690,
666,
199,
1590,
14,
2355,
14,
5176,
8,
16,
9,
199,
78,
63,
3356,
275,
12293,
199,
521,
275,
980,
14,
11649,
8,
16,
12,
1616,
12,
302,
63,
3356,
9,
199,
199,
3,
5800,
6632,
2551,
199,
83,
17,
275,
980,
14,
5911,
8,
18,
627,
900,
9,
221,
327,
9829,
12204,
199,
83,
18,
275,
980,
14,
1037,
8,
1590,
14,
5911,
8,
19,
627,
900,
430,
221,
327,
12386,
12204,
199,
51,
275,
980,
14,
67,
9925,
83,
17,
12,
308,
18,
61,
199,
51,
847,
378,
14,
18,
627,
980,
14,
2355,
14,
3302,
8,
890,
29,
51,
14,
1392,
9,
221,
327,
1050,
11145,
199,
199,
3,
1933,
460,
18980,
806,
666,
199,
51,
12257,
428,
14,
1516,
8,
3127,
29,
16,
9,
199,
51,
275,
428,
14,
52,
199,
199,
3,
603,
1148,
316,
8449,
199,
33,
275,
980,
14,
1144,
4038,
17,
12,
378,
14,
21,
467,
359,
16,
14,
21,
12,
413,
3934,
199,
199,
3,
603,
1148,
6632,
2551,
199,
56,
275,
980,
14,
3287,
8,
33,
12,
51,
9,
199,
10455,
63,
10458,
275,
14849,
10807,
8,
56,
9,
199,
199,
3,
27504,
1958,
199,
24027,
275,
22613,
948,
33,
342,
199,
10458,
275,
284,
696,
14,
4998,
8,
10455,
63,
10458,
9,
199,
51,
63,
275,
10166,
14,
362,
63,
4445,
63,
3642,
342,
199,
33,
63,
275,
284,
696,
14,
362,
63,
13979,
316,
63,
3642,
7303,
199,
199,
3,
14794,
2058,
199,
1168,
14,
8941,
342,
199,
1168,
14,
13334,
8,
19,
12,
413,
12,
413,
9,
199,
1168,
14,
2798,
8,
51,
14,
52,
9,
199,
1168,
14,
1213,
360,
549,
5800,
83,
358,
199,
1168,
14,
13334,
8,
19,
12,
413,
12,
499,
9,
199,
1168,
14,
2798,
8,
56,
14,
52,
9,
199,
1168,
14,
1213,
360,
17899,
5800,
83,
358,
199,
1168,
14,
13334,
8,
19,
12,
413,
12,
650,
9,
199,
1168,
14,
2798,
8,
51,
3754,
52,
9,
199,
1168,
14,
1213,
360,
9169,
12754,
5800,
83,
358,
199,
1168,
14,
21430,
63,
10917,
8,
16,
14,
1643,
12,
378,
14,
966,
12,
378,
14,
2635,
12,
378,
14,
2635,
12,
378,
14,
1479,
12,
378,
14,
1344,
9,
199,
1168,
14,
2384,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
proxysh/Safejumper-for-Mac
|
buildmac/Resources/env/lib/python2.7/encodings/uu_codec.py
|
57
|
3772
|
""" Python 'uu_codec' Codec - UU content transfer encoding
Unlike most of the other codecs which target Unicode, this codec
will return Python string objects for both encode and decode.
Written by Marc-Andre Lemburg (mal@lemburg.com). Some details were
adapted from uu.py which was written by Lance Ellinghouse and
modified by Jack Jansen and Fredrik Lundh.
"""
import codecs, binascii
### Codec APIs
def uu_encode(input,errors='strict',filename='<data>',mode=0666):
""" Encodes the object input and returns a tuple (output
object, length consumed).
errors defines the error handling to apply. It defaults to
'strict' handling which is the only currently supported
error handling for this codec.
"""
assert errors == 'strict'
from cStringIO import StringIO
from binascii import b2a_uu
# using str() because of cStringIO's Unicode undesired Unicode behavior.
infile = StringIO(str(input))
outfile = StringIO()
read = infile.read
write = outfile.write
# Encode
write('begin %o %s\n' % (mode & 0777, filename))
chunk = read(45)
while chunk:
write(b2a_uu(chunk))
chunk = read(45)
write(' \nend\n')
return (outfile.getvalue(), len(input))
def uu_decode(input,errors='strict'):
""" Decodes the object input and returns a tuple (output
object, length consumed).
input must be an object which provides the bf_getreadbuf
buffer slot. Python strings, buffer objects and memory
mapped files are examples of objects providing this slot.
errors defines the error handling to apply. It defaults to
'strict' handling which is the only currently supported
error handling for this codec.
Note: filename and file mode information in the input data is
ignored.
"""
assert errors == 'strict'
from cStringIO import StringIO
from binascii import a2b_uu
infile = StringIO(str(input))
outfile = StringIO()
readline = infile.readline
write = outfile.write
# Find start of encoded data
while 1:
s = readline()
if not s:
raise ValueError, 'Missing "begin" line in input data'
if s[:5] == 'begin':
break
# Decode
while 1:
s = readline()
if not s or \
s == 'end\n':
break
try:
data = a2b_uu(s)
except binascii.Error, v:
# Workaround for broken uuencoders by /Fredrik Lundh
nbytes = (((ord(s[0])-32) & 63) * 4 + 5) // 3
data = a2b_uu(s[:nbytes])
#sys.stderr.write("Warning: %s\n" % str(v))
write(data)
if not s:
raise ValueError, 'Truncated input data'
return (outfile.getvalue(), len(input))
class Codec(codecs.Codec):
def encode(self,input,errors='strict'):
return uu_encode(input,errors)
def decode(self,input,errors='strict'):
return uu_decode(input,errors)
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input, final=False):
return uu_encode(input, self.errors)[0]
class IncrementalDecoder(codecs.IncrementalDecoder):
def decode(self, input, final=False):
return uu_decode(input, self.errors)[0]
class StreamWriter(Codec,codecs.StreamWriter):
pass
class StreamReader(Codec,codecs.StreamReader):
pass
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='uu',
encode=uu_encode,
decode=uu_decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
_is_text_encoding=False,
)
|
gpl-2.0
|
[
624,
2018,
283,
17031,
63,
9276,
7,
13732,
446,
738,
53,
1564,
9307,
2644,
339,
25059,
4750,
402,
314,
1163,
6010,
1314,
1347,
6140,
12,
642,
9076,
272,
911,
372,
2018,
1059,
2251,
367,
3865,
3752,
436,
4849,
14,
339,
27694,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
6601,
2436,
4898,
272,
26266,
687,
399,
85,
14,
647,
1314,
1990,
5313,
701,
491,
554,
662,
10564,
6740,
436,
272,
6042,
701,
1603,
564,
17474,
2464,
436,
481,
581,
25844,
491,
725,
72,
14,
199,
199,
624,
199,
646,
6010,
12,
14755,
199,
199,
5680,
13732,
15913,
199,
199,
318,
399,
85,
63,
2143,
8,
1210,
12,
2550,
534,
4768,
297,
1501,
15829,
576,
4206,
632,
29,
16,
11829,
304,
339,
408,
3447,
6021,
314,
909,
1324,
436,
2529,
282,
2008,
334,
1199,
267,
909,
12,
2582,
16949,
680,
398,
2552,
7890,
314,
1125,
7252,
370,
4838,
14,
2779,
4243,
370,
267,
283,
4768,
7,
7252,
1314,
365,
314,
1454,
5544,
3748,
267,
1125,
7252,
367,
642,
9076,
14,
339,
408,
272,
702,
2552,
508,
283,
4768,
7,
272,
687,
15073,
492,
5228,
272,
687,
14755,
492,
330,
18,
65,
63,
17031,
272,
327,
1808,
620,
342,
2952,
402,
15073,
1159,
6140,
625,
16035,
6140,
5953,
14,
272,
14734,
275,
5228,
8,
495,
8,
1210,
430,
272,
4386,
275,
5228,
342,
272,
1586,
275,
14734,
14,
739,
272,
2218,
275,
4386,
14,
952,
339,
327,
19244,
272,
2218,
360,
5037,
450,
79,
450,
83,
60,
78,
7,
450,
334,
632,
1253,
378,
11956,
12,
1788,
430,
272,
3728,
275,
1586,
8,
2322,
9,
272,
1830,
3728,
26,
267,
2218,
8,
66,
18,
65,
63,
17031,
8,
4604,
430,
267,
3728,
275,
1586,
8,
2322,
9,
272,
2218,
360,
971,
78,
500,
60,
78,
358,
339,
372,
334,
4984,
14,
7150,
1062,
822,
8,
1210,
430,
199,
199,
318,
399,
85,
63,
2708,
8,
1210,
12,
2550,
534,
4768,
735,
339,
408,
1487,
6021,
314,
909,
1324,
436,
2529,
282,
2008,
334,
1199,
267,
909,
12,
2582,
16949,
680,
398,
1324,
1471,
506,
376,
909,
1314,
6571,
314,
18839,
63,
362,
739,
1436,
267,
3335,
9348,
14,
2018,
3326,
12,
3335,
2251,
436,
4402,
267,
9994,
1584,
787,
7251,
402,
2251,
13070,
642,
9348,
14,
398,
2552,
7890,
314,
1125,
7252,
370,
4838,
14,
2779,
4243,
370,
267,
283,
4768,
7,
7252,
1314,
365,
314,
1454,
5544,
3748,
267,
1125,
7252,
367,
642,
9076,
14,
398,
3390,
26,
1788,
436,
570,
818,
2556,
315,
314,
1324,
666,
365,
267,
5525,
14,
339,
408,
272,
702,
2552,
508,
283,
4768,
7,
272,
687,
15073,
492,
5228,
272,
687,
14755,
492,
282,
18,
66,
63,
17031,
272,
14734,
275,
5228,
8,
495,
8,
1210,
430,
272,
4386,
275,
5228,
342,
272,
14441,
275,
14734,
14,
6407,
272,
2218,
275,
4386,
14,
952,
339,
327,
6668,
1343,
402,
5737,
666,
272,
1830,
413,
26,
267,
308,
275,
14441,
342,
267,
340,
440,
308,
26,
288,
746,
1722,
12,
283,
7718,
298,
5037,
2,
1004,
315,
1324,
666,
7,
267,
340,
308,
1491,
21,
61,
508,
283,
5037,
356,
288,
2059,
339,
327,
22462,
272,
1830,
413,
26,
267,
308,
275,
14441,
342,
267,
340,
440,
308,
503,
971,
1779,
308,
508,
283,
500,
60,
78,
356,
288,
2059,
267,
862,
26,
288,
666,
275,
282,
18,
66,
63,
17031,
8,
83,
9,
267,
871,
14755,
14,
547,
12,
373,
26,
288,
327,
9361,
11659,
367,
10529,
399,
85,
9347,
83,
701,
1182,
38,
581,
25844,
491,
725,
72,
288,
302,
2394,
275,
20337,
2181,
8,
83,
59,
16,
566,
13,
708,
9,
1253,
13668,
9,
627,
841,
435,
959,
9,
5001,
650,
288,
666,
275,
282,
18,
66,
63,
17031,
8,
83,
1491,
31417,
566,
288,
327,
1274,
14,
3083,
14,
952,
480,
3849,
26,
450,
83,
60,
78,
2,
450,
620,
8,
86,
430,
267,
2218,
8,
576,
9,
272,
340,
440,
308,
26,
267,
746,
1722,
12,
283,
20460,
3153,
1324,
666,
7,
339,
372,
334,
4984,
14,
7150,
1062,
822,
8,
1210,
430,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
399,
85,
63,
2143,
8,
1210,
12,
2550,
9,
339,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
399,
85,
63,
2708,
8,
1210,
12,
2550,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
399,
85,
63,
2143,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
399,
85,
63,
2708,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
17031,
297,
267,
3752,
29,
17031,
63,
2143,
12,
267,
4849,
29,
17031,
63,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
267,
485,
374,
63,
505,
63,
2991,
29,
797,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2018,
283,
17031,
63,
9276,
7,
13732,
446,
738,
53,
1564,
9307,
2644,
339,
25059,
4750,
402,
314,
1163,
6010,
1314,
1347,
6140,
12,
642,
9076,
272,
911,
372,
2018,
1059,
2251,
367,
3865,
3752,
436,
4849,
14,
339,
27694,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
6601,
2436,
4898,
272,
26266,
687,
399,
85,
14,
647,
1314,
1990,
5313,
701,
491,
554,
662,
10564,
6740,
436,
272,
6042,
701,
1603,
564,
17474,
2464,
436,
481,
581,
25844,
491,
725,
72,
14,
199,
199,
624,
199,
646,
6010,
12,
14755,
199,
199,
5680,
13732,
15913,
199,
199,
318,
399,
85,
63,
2143,
8,
1210,
12,
2550,
534,
4768,
297,
1501,
15829,
576,
4206,
632,
29,
16,
11829,
304,
339,
408,
3447,
6021,
314,
909,
1324,
436,
2529,
282,
2008,
334,
1199,
267,
909,
12,
2582,
16949,
680,
398,
2552,
7890,
314,
1125,
7252,
370,
4838,
14,
2779,
4243,
370,
267,
283,
4768,
7,
7252,
1314,
365,
314,
1454,
5544,
3748,
267,
1125,
7252,
367,
642,
9076,
14,
339,
408,
272,
702,
2552,
508,
283,
4768,
7,
272,
687,
15073,
492,
5228,
272,
687,
14755,
492,
330,
18,
65,
63,
17031,
272,
327,
1808,
620,
342,
2952,
402,
15073,
1159,
6140,
625,
16035,
6140,
5953,
14,
272,
14734,
275,
5228,
8,
495,
8,
1210,
430,
272,
4386,
275,
5228,
342,
272,
1586,
275,
14734,
14,
739,
272,
2218,
275,
4386,
14,
952,
339,
327,
19244,
272,
2218,
360,
5037,
450,
79,
450,
83,
60,
78,
7,
450,
334,
632,
1253,
378,
11956,
12,
1788,
430,
272,
3728,
275,
1586,
8,
2322,
9,
272,
1830,
3728,
26,
267,
2218,
8,
66,
18,
65,
63,
17031,
8,
4604,
430,
267,
3728,
275,
1586,
8,
2322,
9,
272,
2218,
360,
971,
78,
500,
60,
78,
358,
339,
372,
334,
4984,
14,
7150,
1062,
822,
8,
1210,
430,
199,
199,
318,
399,
85,
63,
2708,
8,
1210,
12,
2550,
534,
4768,
735,
339,
408,
1487,
6021,
314,
909,
1324,
436,
2529,
282,
2008,
334,
1199,
267,
909,
12,
2582,
16949,
680,
398,
1324,
1471,
506,
376,
909,
1314,
6571,
314,
18839,
63,
362,
739,
1436,
267,
3335,
9348,
14,
2018,
3326,
12,
3335,
2251,
436,
4402,
267,
9994,
1584,
787,
7251,
402,
2251,
13070,
642,
9348,
14,
398,
2552,
7890,
314,
1125,
7252,
370,
4838,
14,
2779,
4243,
370,
267,
283,
4768,
7,
7252,
1314,
365,
314,
1454,
5544,
3748,
267,
1125,
7252,
367,
642,
9076,
14,
398,
3390,
26,
1788,
436,
570,
818,
2556,
315,
314,
1324,
666,
365,
267,
5525,
14,
339,
408,
272,
702,
2552,
508,
283,
4768,
7,
272,
687,
15073,
492,
5228,
272,
687,
14755,
492,
282,
18,
66,
63,
17031,
272,
14734,
275,
5228,
8,
495,
8,
1210,
430,
272,
4386,
275,
5228,
342,
272,
14441,
275,
14734,
14,
6407,
272,
2218,
275,
4386,
14,
952,
339,
327,
6668,
1343,
402,
5737,
666,
272,
1830,
413,
26,
267,
308,
275,
14441,
342,
267,
340,
440,
308,
26,
288,
746,
1722,
12,
283,
7718,
298,
5037,
2,
1004,
315,
1324,
666,
7,
267,
340,
308,
1491,
21,
61,
508,
283,
5037,
356,
288,
2059,
339,
327,
22462,
272,
1830,
413,
26,
267,
308,
275,
14441,
342,
267,
340,
440,
308,
503,
971,
1779,
308,
508,
283,
500,
60,
78,
356,
288,
2059,
267,
862,
26,
288,
666,
275,
282,
18,
66,
63,
17031,
8,
83,
9,
267,
871,
14755,
14,
547,
12,
373,
26,
288,
327,
9361,
11659,
367,
10529,
399,
85,
9347,
83,
701,
1182,
38,
581,
25844,
491,
725,
72,
288,
302,
2394,
275,
20337,
2181,
8,
83,
59,
16,
566,
13,
708,
9,
1253,
13668,
9,
627,
841,
435,
959,
9,
5001,
650,
288,
666,
275,
282,
18,
66,
63,
17031,
8,
83,
1491,
31417,
566,
288,
327,
1274,
14,
3083,
14,
952,
480,
3849,
26,
450,
83,
60,
78,
2,
450,
620,
8,
86,
430,
267,
2218,
8,
576,
9,
272,
340,
440,
308,
26,
267,
746,
1722,
12,
283,
20460,
3153,
1324,
666,
7,
339,
372,
334,
4984,
14,
7150,
1062,
822,
8,
1210,
430,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
399,
85,
63,
2143,
8,
1210,
12,
2550,
9,
339,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
399,
85,
63,
2708,
8,
1210,
12,
2550,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
399,
85,
63,
2143,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
399,
85,
63,
2708,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
17031,
297,
267,
3752,
29,
17031,
63,
2143,
12,
267,
4849,
29,
17031,
63,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
267,
485,
374,
63,
505,
63,
2991,
29,
797,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
sebrandon1/nova
|
nova/api/openstack/compute/server_migrations.py
|
7
|
7291
|
# Copyright 2016 OpenStack Foundation
# All Rights Reserved.
#
# 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.
from webob import exc
from nova.api.openstack import common
from nova.api.openstack.compute.schemas import server_migrations
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api import validation
from nova import compute
from nova import exception
from nova.i18n import _
from nova.policies import servers_migrations as sm_policies
ALIAS = 'servers:migrations'
def output(migration):
"""Returns the desired output of the API from an object.
From a Migrations's object this method returns the primitive
object with the only necessary and expected fields.
"""
return {
"created_at": migration.created_at,
"dest_compute": migration.dest_compute,
"dest_host": migration.dest_host,
"dest_node": migration.dest_node,
"disk_processed_bytes": migration.disk_processed,
"disk_remaining_bytes": migration.disk_remaining,
"disk_total_bytes": migration.disk_total,
"id": migration.id,
"memory_processed_bytes": migration.memory_processed,
"memory_remaining_bytes": migration.memory_remaining,
"memory_total_bytes": migration.memory_total,
"server_uuid": migration.instance_uuid,
"source_compute": migration.source_compute,
"source_node": migration.source_node,
"status": migration.status,
"updated_at": migration.updated_at
}
class ServerMigrationsController(wsgi.Controller):
"""The server migrations API controller for the OpenStack API."""
def __init__(self):
self.compute_api = compute.API()
super(ServerMigrationsController, self).__init__()
@wsgi.Controller.api_version("2.22")
@wsgi.response(202)
@extensions.expected_errors((400, 403, 404, 409))
@wsgi.action('force_complete')
@validation.schema(server_migrations.force_complete)
def _force_complete(self, req, id, server_id, body):
context = req.environ['nova.context']
context.can(sm_policies.POLICY_ROOT % 'force_complete')
instance = common.get_instance(self.compute_api, context, server_id)
try:
self.compute_api.live_migrate_force_complete(context, instance, id)
except exception.InstanceNotFound as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except (exception.MigrationNotFoundByStatus,
exception.InvalidMigrationState,
exception.MigrationNotFoundForInstance) as e:
raise exc.HTTPBadRequest(explanation=e.format_message())
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(
state_error, 'force_complete', server_id)
@wsgi.Controller.api_version("2.23")
@extensions.expected_errors(404)
def index(self, req, server_id):
"""Return all migrations of an instance in progress."""
context = req.environ['nova.context']
context.can(sm_policies.POLICY_ROOT % 'index')
# NOTE(Shaohe Feng) just check the instance is available. To keep
# consistency with other API, check it before get migrations.
common.get_instance(self.compute_api, context, server_id)
migrations = self.compute_api.get_migrations_in_progress_by_instance(
context, server_id, 'live-migration')
return {'migrations': [output(migration) for migration in migrations]}
@wsgi.Controller.api_version("2.23")
@extensions.expected_errors(404)
def show(self, req, server_id, id):
"""Return the migration of an instance in progress by id."""
context = req.environ['nova.context']
context.can(sm_policies.POLICY_ROOT % 'show')
# NOTE(Shaohe Feng) just check the instance is available. To keep
# consistency with other API, check it before get migrations.
common.get_instance(self.compute_api, context, server_id)
try:
migration = self.compute_api.get_migration_by_id_and_instance(
context, id, server_id)
except exception.MigrationNotFoundForInstance:
msg = _("In-progress live migration %(id)s is not found for"
" server %(uuid)s.") % {"id": id, "uuid": server_id}
raise exc.HTTPNotFound(explanation=msg)
if migration.get("migration_type") != "live-migration":
msg = _("Migration %(id)s for server %(uuid)s is not"
" live-migration.") % {"id": id, "uuid": server_id}
raise exc.HTTPNotFound(explanation=msg)
# TODO(Shaohe Feng) we should share the in-progress list.
in_progress = ['queued', 'preparing', 'running', 'post-migrating']
if migration.get("status") not in in_progress:
msg = _("Live migration %(id)s for server %(uuid)s is not in"
" progress.") % {"id": id, "uuid": server_id}
raise exc.HTTPNotFound(explanation=msg)
return {'migration': output(migration)}
@wsgi.Controller.api_version("2.24")
@wsgi.response(202)
@extensions.expected_errors((400, 404, 409))
def delete(self, req, server_id, id):
"""Abort an in progress migration of an instance."""
context = req.environ['nova.context']
context.can(sm_policies.POLICY_ROOT % 'delete')
instance = common.get_instance(self.compute_api, context, server_id)
try:
self.compute_api.live_migrate_abort(context, instance, id)
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(
state_error, "abort live migration", server_id)
except exception.MigrationNotFoundForInstance as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InvalidMigrationState as e:
raise exc.HTTPBadRequest(explanation=e.format_message())
class ServerMigrations(extensions.V21APIExtensionBase):
"""Server Migrations API."""
name = "ServerMigrations"
alias = 'server-migrations'
version = 1
def get_resources(self):
parent = {'member_name': 'server',
'collection_name': 'servers'}
member_actions = {'action': 'POST'}
resources = [extensions.ResourceExtension(
'migrations', ServerMigrationsController(),
parent=parent, member_actions=member_actions)]
return resources
def get_controller_extensions(self):
return []
|
apache-2.0
|
[
3,
1898,
7800,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
14568,
492,
3178,
199,
199,
504,
5913,
14,
1246,
14,
8512,
492,
2863,
199,
504,
5913,
14,
1246,
14,
8512,
14,
3357,
14,
9482,
492,
1654,
63,
7685,
199,
504,
5913,
14,
1246,
14,
8512,
492,
5478,
199,
504,
5913,
14,
1246,
14,
8512,
492,
12464,
199,
504,
5913,
14,
1246,
492,
6411,
199,
504,
5913,
492,
4526,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
199,
504,
5913,
14,
11767,
492,
8037,
63,
7685,
465,
4383,
63,
11767,
421,
199,
12644,
275,
283,
5871,
26,
7685,
7,
421,
199,
318,
1072,
8,
8998,
304,
272,
408,
3407,
314,
6387,
1072,
402,
314,
3261,
687,
376,
909,
14,
339,
11606,
282,
28195,
3801,
1159,
909,
642,
1083,
2529,
314,
18944,
272,
909,
543,
314,
1454,
5784,
436,
1420,
1504,
14,
272,
408,
272,
372,
469,
267,
298,
3966,
63,
292,
582,
8367,
14,
3966,
63,
292,
12,
267,
298,
2614,
63,
3357,
582,
8367,
14,
2614,
63,
3357,
12,
267,
298,
2614,
63,
1102,
582,
8367,
14,
2614,
63,
1102,
12,
267,
298,
2614,
63,
932,
582,
8367,
14,
2614,
63,
932,
12,
267,
298,
4032,
63,
7292,
63,
2394,
582,
8367,
14,
4032,
63,
7292,
12,
267,
298,
4032,
63,
11266,
63,
2394,
582,
8367,
14,
4032,
63,
11266,
12,
267,
298,
4032,
63,
2923,
63,
2394,
582,
8367,
14,
4032,
63,
2923,
12,
267,
298,
344,
582,
8367,
14,
344,
12,
267,
298,
4844,
63,
7292,
63,
2394,
582,
8367,
14,
4844,
63,
7292,
12,
267,
298,
4844,
63,
11266,
63,
2394,
582,
8367,
14,
4844,
63,
11266,
12,
267,
298,
4844,
63,
2923,
63,
2394,
582,
8367,
14,
4844,
63,
2923,
12,
267,
298,
1000,
63,
2580,
582,
8367,
14,
842,
63,
2580,
12,
267,
298,
1365,
63,
3357,
582,
8367,
14,
1365,
63,
3357,
12,
267,
298,
1365,
63,
932,
582,
8367,
14,
1365,
63,
932,
12,
267,
298,
1205,
582,
8367,
14,
1205,
12,
267,
298,
5334,
63,
292,
582,
8367,
14,
5334,
63,
292,
272,
789,
421,
199,
533,
7146,
19322,
3801,
7506,
8,
6508,
14,
7506,
304,
272,
408,
1918,
1654,
6180,
3261,
7614,
367,
314,
14260,
3261,
1041,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
3357,
63,
1246,
275,
4526,
14,
3735,
342,
267,
1613,
8,
3120,
19322,
3801,
7506,
12,
291,
2843,
826,
4533,
339,
768,
6508,
14,
7506,
14,
1246,
63,
1023,
480,
18,
14,
1081,
531,
272,
768,
6508,
14,
1310,
8,
4999,
9,
272,
768,
5359,
14,
2062,
63,
2550,
1332,
5303,
12,
13269,
12,
7901,
12,
21292,
430,
272,
768,
6508,
14,
1287,
360,
3990,
63,
4883,
358,
272,
768,
6136,
14,
3629,
8,
1000,
63,
7685,
14,
3990,
63,
4883,
9,
272,
347,
485,
3990,
63,
4883,
8,
277,
12,
2648,
12,
1305,
12,
1654,
63,
344,
12,
2396,
304,
267,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
267,
1067,
14,
2425,
8,
3300,
63,
11767,
14,
15976,
63,
5441,
450,
283,
3990,
63,
4883,
358,
398,
1256,
275,
2863,
14,
362,
63,
842,
8,
277,
14,
3357,
63,
1246,
12,
1067,
12,
1654,
63,
344,
9,
267,
862,
26,
288,
291,
14,
3357,
63,
1246,
14,
6442,
63,
8462,
63,
3990,
63,
4883,
8,
1100,
12,
1256,
12,
1305,
9,
267,
871,
1919,
14,
3244,
4667,
465,
325,
26,
288,
746,
3178,
14,
26553,
8,
15228,
29,
69,
14,
908,
63,
1188,
1012,
267,
871,
334,
1971,
14,
9816,
4667,
2175,
3694,
12,
355,
1919,
14,
3364,
9816,
2223,
12,
355,
1919,
14,
9816,
4667,
1858,
3244,
9,
465,
325,
26,
288,
746,
3178,
14,
21070,
8,
15228,
29,
69,
14,
908,
63,
1188,
1012,
267,
871,
1919,
14,
3244,
1831,
22408,
465,
325,
26,
288,
746,
3178,
14,
2856,
15919,
8,
15228,
29,
69,
14,
908,
63,
1188,
1012,
267,
871,
1919,
14,
3244,
3364,
2223,
465,
1174,
63,
705,
26,
288,
2863,
14,
3730,
63,
1014,
63,
15207,
63,
509,
63,
842,
63,
3197,
63,
929,
8,
355,
1174,
63,
705,
12,
283,
3990,
63,
4883,
297,
1654,
63,
344,
9,
339,
768,
6508,
14,
7506,
14,
1246,
63,
1023,
480,
18,
14,
1789,
531,
272,
768,
5359,
14,
2062,
63,
2550,
8,
5188,
9,
272,
347,
1478,
8,
277,
12,
2648,
12,
1654,
63,
344,
304,
267,
408,
1767,
1006,
6180,
402,
376,
1256,
315,
6696,
1041,
267,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
267,
1067,
14,
2425,
8,
3300,
63,
11767,
14,
15976,
63,
5441,
450,
283,
1080,
358,
398,
327,
6944,
8,
23527,
79,
426,
481,
7420,
9,
2951,
1104,
314,
1256,
365,
2808,
14,
4005,
4215,
267,
327,
17754,
543,
1163,
3261,
12,
1104,
652,
2544,
664,
6180,
14,
267,
2863,
14,
362,
63,
842,
8,
277,
14,
3357,
63,
1246,
12,
1067,
12,
1654,
63,
344,
9,
398,
6180,
275,
291,
14,
3357,
63,
1246,
14,
362,
63,
7685,
63,
262,
63,
5734,
63,
991,
63,
842,
8,
355,
1067,
12,
1654,
63,
344,
12,
283,
6442,
13,
8998,
358,
398,
372,
791,
7685,
356,
359,
1199,
8,
8998,
9,
367,
8367,
315,
6180,
9420,
339,
768,
6508,
14,
7506,
14,
1246,
63,
1023,
480,
18,
14,
1789,
531,
272,
768,
5359,
14
] |
[
1898,
7800,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
14568,
492,
3178,
199,
199,
504,
5913,
14,
1246,
14,
8512,
492,
2863,
199,
504,
5913,
14,
1246,
14,
8512,
14,
3357,
14,
9482,
492,
1654,
63,
7685,
199,
504,
5913,
14,
1246,
14,
8512,
492,
5478,
199,
504,
5913,
14,
1246,
14,
8512,
492,
12464,
199,
504,
5913,
14,
1246,
492,
6411,
199,
504,
5913,
492,
4526,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
199,
504,
5913,
14,
11767,
492,
8037,
63,
7685,
465,
4383,
63,
11767,
421,
199,
12644,
275,
283,
5871,
26,
7685,
7,
421,
199,
318,
1072,
8,
8998,
304,
272,
408,
3407,
314,
6387,
1072,
402,
314,
3261,
687,
376,
909,
14,
339,
11606,
282,
28195,
3801,
1159,
909,
642,
1083,
2529,
314,
18944,
272,
909,
543,
314,
1454,
5784,
436,
1420,
1504,
14,
272,
408,
272,
372,
469,
267,
298,
3966,
63,
292,
582,
8367,
14,
3966,
63,
292,
12,
267,
298,
2614,
63,
3357,
582,
8367,
14,
2614,
63,
3357,
12,
267,
298,
2614,
63,
1102,
582,
8367,
14,
2614,
63,
1102,
12,
267,
298,
2614,
63,
932,
582,
8367,
14,
2614,
63,
932,
12,
267,
298,
4032,
63,
7292,
63,
2394,
582,
8367,
14,
4032,
63,
7292,
12,
267,
298,
4032,
63,
11266,
63,
2394,
582,
8367,
14,
4032,
63,
11266,
12,
267,
298,
4032,
63,
2923,
63,
2394,
582,
8367,
14,
4032,
63,
2923,
12,
267,
298,
344,
582,
8367,
14,
344,
12,
267,
298,
4844,
63,
7292,
63,
2394,
582,
8367,
14,
4844,
63,
7292,
12,
267,
298,
4844,
63,
11266,
63,
2394,
582,
8367,
14,
4844,
63,
11266,
12,
267,
298,
4844,
63,
2923,
63,
2394,
582,
8367,
14,
4844,
63,
2923,
12,
267,
298,
1000,
63,
2580,
582,
8367,
14,
842,
63,
2580,
12,
267,
298,
1365,
63,
3357,
582,
8367,
14,
1365,
63,
3357,
12,
267,
298,
1365,
63,
932,
582,
8367,
14,
1365,
63,
932,
12,
267,
298,
1205,
582,
8367,
14,
1205,
12,
267,
298,
5334,
63,
292,
582,
8367,
14,
5334,
63,
292,
272,
789,
421,
199,
533,
7146,
19322,
3801,
7506,
8,
6508,
14,
7506,
304,
272,
408,
1918,
1654,
6180,
3261,
7614,
367,
314,
14260,
3261,
1041,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
3357,
63,
1246,
275,
4526,
14,
3735,
342,
267,
1613,
8,
3120,
19322,
3801,
7506,
12,
291,
2843,
826,
4533,
339,
768,
6508,
14,
7506,
14,
1246,
63,
1023,
480,
18,
14,
1081,
531,
272,
768,
6508,
14,
1310,
8,
4999,
9,
272,
768,
5359,
14,
2062,
63,
2550,
1332,
5303,
12,
13269,
12,
7901,
12,
21292,
430,
272,
768,
6508,
14,
1287,
360,
3990,
63,
4883,
358,
272,
768,
6136,
14,
3629,
8,
1000,
63,
7685,
14,
3990,
63,
4883,
9,
272,
347,
485,
3990,
63,
4883,
8,
277,
12,
2648,
12,
1305,
12,
1654,
63,
344,
12,
2396,
304,
267,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
267,
1067,
14,
2425,
8,
3300,
63,
11767,
14,
15976,
63,
5441,
450,
283,
3990,
63,
4883,
358,
398,
1256,
275,
2863,
14,
362,
63,
842,
8,
277,
14,
3357,
63,
1246,
12,
1067,
12,
1654,
63,
344,
9,
267,
862,
26,
288,
291,
14,
3357,
63,
1246,
14,
6442,
63,
8462,
63,
3990,
63,
4883,
8,
1100,
12,
1256,
12,
1305,
9,
267,
871,
1919,
14,
3244,
4667,
465,
325,
26,
288,
746,
3178,
14,
26553,
8,
15228,
29,
69,
14,
908,
63,
1188,
1012,
267,
871,
334,
1971,
14,
9816,
4667,
2175,
3694,
12,
355,
1919,
14,
3364,
9816,
2223,
12,
355,
1919,
14,
9816,
4667,
1858,
3244,
9,
465,
325,
26,
288,
746,
3178,
14,
21070,
8,
15228,
29,
69,
14,
908,
63,
1188,
1012,
267,
871,
1919,
14,
3244,
1831,
22408,
465,
325,
26,
288,
746,
3178,
14,
2856,
15919,
8,
15228,
29,
69,
14,
908,
63,
1188,
1012,
267,
871,
1919,
14,
3244,
3364,
2223,
465,
1174,
63,
705,
26,
288,
2863,
14,
3730,
63,
1014,
63,
15207,
63,
509,
63,
842,
63,
3197,
63,
929,
8,
355,
1174,
63,
705,
12,
283,
3990,
63,
4883,
297,
1654,
63,
344,
9,
339,
768,
6508,
14,
7506,
14,
1246,
63,
1023,
480,
18,
14,
1789,
531,
272,
768,
5359,
14,
2062,
63,
2550,
8,
5188,
9,
272,
347,
1478,
8,
277,
12,
2648,
12,
1654,
63,
344,
304,
267,
408,
1767,
1006,
6180,
402,
376,
1256,
315,
6696,
1041,
267,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
267,
1067,
14,
2425,
8,
3300,
63,
11767,
14,
15976,
63,
5441,
450,
283,
1080,
358,
398,
327,
6944,
8,
23527,
79,
426,
481,
7420,
9,
2951,
1104,
314,
1256,
365,
2808,
14,
4005,
4215,
267,
327,
17754,
543,
1163,
3261,
12,
1104,
652,
2544,
664,
6180,
14,
267,
2863,
14,
362,
63,
842,
8,
277,
14,
3357,
63,
1246,
12,
1067,
12,
1654,
63,
344,
9,
398,
6180,
275,
291,
14,
3357,
63,
1246,
14,
362,
63,
7685,
63,
262,
63,
5734,
63,
991,
63,
842,
8,
355,
1067,
12,
1654,
63,
344,
12,
283,
6442,
13,
8998,
358,
398,
372,
791,
7685,
356,
359,
1199,
8,
8998,
9,
367,
8367,
315,
6180,
9420,
339,
768,
6508,
14,
7506,
14,
1246,
63,
1023,
480,
18,
14,
1789,
531,
272,
768,
5359,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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usage:
ngxtop [options]
ngxtop [options] (print|top|avg|sum) <var> ...
ngxtop info
ngxtop [options] query <query> ...
Options:
-l <file>, --access-log <file> access log file to parse.
-f <format>, --log-format <format> log format as specify in log_format directive. [default: combined]
--no-follow ngxtop default behavior is to ignore current lines in log
and only watch for new lines as they are written to the access log.
Use this flag to tell ngxtop to process the current content of the access log instead.
-t <seconds>, --interval <seconds> report interval when running in follow mode [default: 2.0]
-g <var>, --group-by <var> group by variable [default: request_path]
-w <var>, --having <expr> having clause [default: 1]
-o <var>, --order-by <var> order of output for default query [default: count]
-n <number>, --limit <number> limit the number of records included in report for top command [default: 10]
-a <exp> ..., --a <exp> ... add exp (must be aggregation exp: sum, avg, min, max, etc.) into output
-v, --verbose more verbose output
-d, --debug print every line and parsed record
-h, --help print this help message.
--version print version information.
Advanced / experimental options:
-c <file>, --config <file> allow ngxtop to parse nginx config file for log format and location.
-i <filter-expression>, --filter <filter-expression> filter in, records satisfied given expression are processed.
-p <filter-expression>, --pre-filter <filter-expression> in-filter expression to check in pre-parsing phase.
Examples:
All examples read nginx config file for access log location and format.
If you want to specify the access log file and / or log format, use the -f and -a options.
"top" like view of nginx requests
$ ngxtop
Top 10 requested path with status 404:
$ ngxtop top request_path --filter 'status == 404'
Top 10 requests with highest total bytes sent
$ ngxtop --order-by 'avg(bytes_sent) * count'
Top 10 remote address, e.g., who's hitting you the most
$ ngxtop --group-by remote_addr
Print requests with 4xx or 5xx status, together with status and http referer
$ ngxtop -i 'status >= 400' print request status http_referer
Average body bytes sent of 200 responses of requested path begin with 'foo':
$ ngxtop avg bytes_sent --filter 'status == 200 and request_path.startswith("foo")'
Analyze apache access log from remote machine using 'common' log format
$ ssh remote tail -f /var/log/apache2/access.log | ngxtop -f common
"""
from __future__ import print_function
import atexit
from contextlib import closing
import curses
import logging
import os
import sqlite3
import time
import sys
import signal
try:
import urlparse
except ImportError:
import urllib.parse as urlparse
from docopt import docopt
import tabulate
from .config_parser import detect_log_config, detect_config_path, extract_variables, build_pattern
from .utils import error_exit
DEFAULT_QUERIES = [
('Summary:',
'''SELECT
count(1) AS count,
avg(bytes_sent) AS avg_bytes_sent,
count(CASE WHEN status_type = 2 THEN 1 END) AS '2xx',
count(CASE WHEN status_type = 3 THEN 1 END) AS '3xx',
count(CASE WHEN status_type = 4 THEN 1 END) AS '4xx',
count(CASE WHEN status_type = 5 THEN 1 END) AS '5xx'
FROM log
ORDER BY %(--order-by)s DESC
LIMIT %(--limit)s'''),
('Detailed:',
'''SELECT
%(--group-by)s,
count(1) AS count,
avg(bytes_sent) AS avg_bytes_sent,
count(CASE WHEN status_type = 2 THEN 1 END) AS '2xx',
count(CASE WHEN status_type = 3 THEN 1 END) AS '3xx',
count(CASE WHEN status_type = 4 THEN 1 END) AS '4xx',
count(CASE WHEN status_type = 5 THEN 1 END) AS '5xx'
FROM log
GROUP BY %(--group-by)s
HAVING %(--having)s
ORDER BY %(--order-by)s DESC
LIMIT %(--limit)s''')
]
DEFAULT_FIELDS = set(['status_type', 'bytes_sent'])
# ======================
# generator utilities
# ======================
def follow(the_file):
"""
Follow a given file and yield new lines when they are available, like `tail -f`.
"""
with open(the_file) as f:
f.seek(0, 2) # seek to eof
while True:
line = f.readline()
if not line:
time.sleep(0.1) # sleep briefly before trying again
continue
yield line
def map_field(field, func, dict_sequence):
"""
Apply given function to value of given key in every dictionary in sequence and
set the result as new value for that key.
"""
for item in dict_sequence:
try:
item[field] = func(item.get(field, None))
yield item
except ValueError:
pass
def add_field(field, func, dict_sequence):
"""
Apply given function to the record and store result in given field of current record.
Do nothing if record already contains given field.
"""
for item in dict_sequence:
if field not in item:
item[field] = func(item)
yield item
def trace(sequence, phase=''):
for item in sequence:
logging.debug('%s:\n%s', phase, item)
yield item
# ======================
# Access log parsing
# ======================
def parse_request_path(record):
if 'request_uri' in record:
uri = record['request_uri']
elif 'request' in record:
uri = ' '.join(record['request'].split(' ')[1:-1])
else:
uri = None
return urlparse.urlparse(uri).path if uri else None
def parse_status_type(record):
return record['status'] // 100 if 'status' in record else None
def to_int(value):
return int(value) if value and value != '-' else 0
def to_float(value):
return float(value) if value and value != '-' else 0.0
def parse_log(lines, pattern):
matches = (pattern.match(l) for l in lines)
records = (m.groupdict() for m in matches if m is not None)
records = map_field('status', to_int, records)
records = add_field('status_type', parse_status_type, records)
records = add_field('bytes_sent', lambda r: r['body_bytes_sent'], records)
records = map_field('bytes_sent', to_int, records)
records = map_field('request_time', to_float, records)
records = add_field('request_path', parse_request_path, records)
return records
# =================================
# Records and statistic processor
# =================================
class SQLProcessor(object):
def __init__(self, report_queries, fields, index_fields=None):
self.begin = False
self.report_queries = report_queries
self.index_fields = index_fields if index_fields is not None else []
self.column_list = ','.join(fields)
self.holder_list = ','.join(':%s' % var for var in fields)
self.conn = sqlite3.connect(':memory:')
self.init_db()
def process(self, records):
self.begin = time.time()
insert = 'insert into log (%s) values (%s)' % (self.column_list, self.holder_list)
logging.info('sqlite insert: %s', insert)
with closing(self.conn.cursor()) as cursor:
for r in records:
cursor.execute(insert, r)
def report(self):
if not self.begin:
return ''
count = self.count()
duration = time.time() - self.begin
status = 'running for %.0f seconds, %d records processed: %.2f req/sec'
output = [status % (duration, count, count / duration)]
with closing(self.conn.cursor()) as cursor:
for query in self.report_queries:
if isinstance(query, tuple):
label, query = query
else:
label = ''
cursor.execute(query)
columns = (d[0] for d in cursor.description)
result = tabulate.tabulate(cursor.fetchall(), headers=columns, tablefmt='orgtbl', floatfmt='.3f')
output.append('%s\n%s' % (label, result))
return '\n\n'.join(output)
def init_db(self):
create_table = 'create table log (%s)' % self.column_list
with closing(self.conn.cursor()) as cursor:
logging.info('sqlite init: %s', create_table)
cursor.execute(create_table)
for idx, field in enumerate(self.index_fields):
sql = 'create index log_idx%d on log (%s)' % (idx, field)
logging.info('sqlite init: %s', sql)
cursor.execute(sql)
def count(self):
with closing(self.conn.cursor()) as cursor:
cursor.execute('select count(1) from log')
return cursor.fetchone()[0]
# ===============
# Log processing
# ===============
def process_log(lines, pattern, processor, arguments):
pre_filer_exp = arguments['--pre-filter']
if pre_filer_exp:
lines = (line for line in lines if eval(pre_filer_exp, {}, dict(line=line)))
records = parse_log(lines, pattern)
filter_exp = arguments['--filter']
if filter_exp:
records = (r for r in records if eval(filter_exp, {}, r))
processor.process(records)
print(processor.report()) # this will only run when start in --no-follow mode
def build_processor(arguments):
fields = arguments['<var>']
if arguments['print']:
label = ', '.join(fields) + ':'
selections = ', '.join(fields)
query = 'select %s from log group by %s' % (selections, selections)
report_queries = [(label, query)]
elif arguments['top']:
limit = int(arguments['--limit'])
report_queries = []
for var in fields:
label = 'top %s' % var
query = 'select %s, count(1) as count from log group by %s order by count desc limit %d' % (var, var, limit)
report_queries.append((label, query))
elif arguments['avg']:
label = 'average %s' % fields
selections = ', '.join('avg(%s)' % var for var in fields)
query = 'select %s from log' % selections
report_queries = [(label, query)]
elif arguments['sum']:
label = 'sum %s' % fields
selections = ', '.join('sum(%s)' % var for var in fields)
query = 'select %s from log' % selections
report_queries = [(label, query)]
elif arguments['query']:
report_queries = arguments['<query>']
fields = arguments['<fields>']
else:
report_queries = [(name, query % arguments) for name, query in DEFAULT_QUERIES]
fields = DEFAULT_FIELDS.union(set([arguments['--group-by']]))
for label, query in report_queries:
logging.info('query for "%s":\n %s', label, query)
processor_fields = []
for field in fields:
processor_fields.extend(field.split(','))
processor = SQLProcessor(report_queries, processor_fields)
return processor
def build_source(access_log, arguments):
# constructing log source
if access_log == 'stdin':
lines = sys.stdin
elif arguments['--no-follow']:
lines = open(access_log)
else:
lines = follow(access_log)
return lines
def setup_reporter(processor, arguments):
if arguments['--no-follow']:
return
scr = curses.initscr()
atexit.register(curses.endwin)
def print_report(sig, frame):
output = processor.report()
scr.erase()
try:
scr.addstr(output)
except curses.error:
pass
scr.refresh()
signal.signal(signal.SIGALRM, print_report)
interval = float(arguments['--interval'])
signal.setitimer(signal.ITIMER_REAL, 0.1, interval)
def process(arguments):
access_log = arguments['--access-log']
log_format = arguments['--log-format']
if access_log is None and not sys.stdin.isatty():
# assume logs can be fetched directly from stdin when piped
access_log = 'stdin'
if access_log is None:
access_log, log_format = detect_log_config(arguments)
logging.info('access_log: %s', access_log)
logging.info('log_format: %s', log_format)
if access_log != 'stdin' and not os.path.exists(access_log):
error_exit('access log file "%s" does not exist' % access_log)
if arguments['info']:
print('nginx configuration file:\n ', detect_config_path())
print('access log file:\n ', access_log)
print('access log format:\n ', log_format)
print('available variables:\n ', ', '.join(sorted(extract_variables(log_format))))
return
source = build_source(access_log, arguments)
pattern = build_pattern(log_format)
processor = build_processor(arguments)
setup_reporter(processor, arguments)
process_log(source, pattern, processor, arguments)
def main():
args = docopt(__doc__, version='xstat 0.1')
log_level = logging.WARNING
if args['--verbose']:
log_level = logging.INFO
if args['--debug']:
log_level = logging.DEBUG
logging.basicConfig(level=log_level, format='%(levelname)s: %(message)s')
logging.debug('arguments:\n%s', args)
try:
process(args)
except KeyboardInterrupt:
sys.exit(0)
if __name__ == '__main__':
main()
|
mit
|
[
624,
2753,
400,
411,
446,
1503,
13,
20402,
1827,
367,
302,
19101,
2879,
943,
14,
199,
199,
7692,
26,
272,
28810,
400,
411,
359,
1419,
61,
272,
28810,
400,
411,
359,
1419,
61,
334,
1361,
92,
2119,
92,
8595,
92,
1838,
9,
665,
1391,
30,
2263,
272,
28810,
400,
411,
2256,
272,
28810,
400,
411,
359,
1419,
61,
1827,
665,
1131,
30,
2263,
199,
199,
4558,
26,
272,
446,
76,
665,
493,
6244,
1553,
2732,
13,
793,
665,
493,
30,
221,
2879,
943,
570,
370,
2198,
14,
272,
446,
70,
665,
908,
6244,
1553,
793,
13,
908,
665,
908,
30,
221,
943,
1475,
465,
4165,
315,
943,
63,
908,
13613,
14,
359,
885,
26,
12149,
61,
272,
1553,
889,
13,
7207,
221,
28810,
400,
411,
849,
5953,
365,
370,
3686,
1453,
2385,
315,
943,
2151,
436,
1454,
9626,
367,
892,
2385,
465,
2985,
787,
5313,
370,
314,
2879,
943,
14,
2151,
3645,
642,
3305,
370,
11480,
28810,
400,
411,
370,
2112,
314,
1453,
1564,
402,
314,
2879,
943,
3140,
14,
272,
446,
84,
665,
4515,
6244,
1553,
4284,
665,
4515,
30,
221,
3622,
6252,
1380,
3879,
315,
2035,
818,
359,
885,
26,
499,
14,
16,
61,
339,
446,
71,
665,
1391,
6244,
1553,
923,
13,
991,
665,
1391,
30,
221,
1572,
701,
1750,
359,
885,
26,
1056,
63,
515,
61,
272,
446,
87,
665,
1391,
6244,
1553,
31569,
665,
3684,
30,
221,
9445,
8502,
359,
885,
26,
413,
61,
272,
446,
79,
665,
1391,
6244,
1553,
1648,
13,
991,
665,
1391,
30,
221,
1865,
402,
1072,
367,
849,
1827,
359,
885,
26,
2338,
61,
272,
446,
78,
665,
1955,
6244,
1553,
3097,
665,
1955,
30,
221,
2304,
314,
1329,
402,
5767,
5120,
315,
3622,
367,
2746,
1414,
359,
885,
26,
1616,
61,
272,
446,
65,
665,
1474,
30,
14263,
1553,
65,
665,
1474,
30,
2263,
221,
1050,
1437,
334,
7790,
506,
18384,
1437,
26,
3089,
12,
12402,
12,
1748,
12,
1390,
12,
5423,
4959,
1901,
1072,
339,
446,
86,
12,
1553,
3832,
221,
1655,
3376,
1072,
272,
446,
68,
12,
1553,
1757,
221,
870,
4036,
1004,
436,
4565,
2777,
272,
446,
72,
12,
1553,
3437,
221,
870,
642,
1720,
1245,
14,
272,
1553,
1023,
221,
870,
1015,
2556,
14,
339,
32445,
1182,
22820,
1511,
26,
272,
446,
67,
665,
493,
6244,
1553,
888,
665,
493,
30,
221,
2040,
28810,
400,
411,
370,
2198,
302,
19101,
1101,
570,
367,
943,
1475,
436,
2909,
14,
272,
446,
73,
665,
1541,
13,
5599,
6244,
1553,
1541,
665,
1541,
13,
5599,
30,
221,
2457,
315,
12,
5767,
23233,
1627,
3965,
787,
7686,
14,
272,
446,
80,
665,
1541,
13,
5599,
6244,
1553,
657,
13,
1541,
665,
1541,
13,
5599,
30,
315,
13,
1541,
3965,
370,
1104,
315,
876,
13,
11059,
7669,
14,
199,
199,
22787,
26,
272,
2900,
7251,
1586,
302,
19101,
1101,
570,
367,
2879,
943,
2909,
436,
1475,
14,
272,
982,
1265,
2934,
370,
4165,
314,
2879,
943,
570,
436,
1182,
503,
943,
1475,
12,
675,
314,
446,
70,
436,
446,
65,
1511,
14,
339,
298,
2119,
2,
2839,
2455,
402,
302,
19101,
4145,
272,
2672,
28810,
400,
411,
339,
14132,
1616,
5839,
931,
543,
2004,
7901,
26,
272,
2672,
28810,
400,
411,
2746,
1056,
63,
515,
1553,
1541,
283,
1205,
508,
7901,
7,
339,
14132,
1616,
4145,
543,
15356,
3141,
2783,
4847,
272,
2672,
28810,
400,
411,
1553,
1648,
13,
991,
283,
8595,
8,
2394,
63,
1150,
9,
627,
2338,
7,
339,
14132,
1616,
3982,
2287,
12,
325,
14,
71,
2020,
3963,
1159,
9793,
1337,
1265,
314,
4750,
272,
2672,
28810,
400,
411,
1553,
923,
13,
991,
3982,
63,
2697,
339,
9101,
4145,
543,
841,
2154,
503,
959,
2154,
2004,
12,
10451,
543,
2004,
436,
1455,
25104,
272,
2672,
28810,
400,
411,
446,
73,
283,
1205,
2356,
8290,
7,
870,
1056,
2004,
1455,
63,
20996,
339,
437,
3652,
2396,
2783,
4847,
402,
1926,
9320,
402,
5839,
931,
5386,
543,
283,
1421,
356,
272,
2672,
28810,
400,
411,
12402,
2783,
63,
1150,
1553,
1541,
283,
1205,
508,
1926,
436,
1056,
63,
515,
14,
2460,
480,
1421,
32292,
339,
14279,
806,
17098,
2879,
943,
687,
3982,
6844,
1808,
283,
2330,
7,
943,
1475,
272,
2672,
8635,
3982,
9483,
446,
70,
1182,
1391,
15,
793,
15,
3796,
18,
15,
2732,
14,
793,
1204,
28810,
400,
411,
446,
70,
2863,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
19840,
199,
504,
15502,
492,
11261,
199,
646,
15429,
199,
646,
2050,
199,
646,
747,
199,
646,
11723,
19,
199,
646,
900,
199,
646,
984,
199,
646,
4673,
199,
199,
893,
26,
272,
492,
7097,
199,
2590,
3545,
26,
272,
492,
4011,
14,
1122,
465,
7097,
199,
199,
504,
886,
32626,
492,
886,
32626,
199,
646,
5174,
5434,
199,
199,
504,
1275,
888,
63,
2087,
492,
9696,
63,
793,
63,
888,
12,
9696,
63,
888,
63,
515,
12,
5536,
63,
3669,
12,
1900,
63,
3401,
199,
504,
1275,
1208,
492,
1125,
63,
2224,
421,
199,
3472,
63,
2328,
540,
2563,
275,
359,
272,
661,
10407,
6536,
1362,
1449,
4859,
2126,
2338,
8,
17,
9,
27503,
4319,
2338,
12,
2126,
12402,
8,
2394,
63,
1150,
9,
17907,
4319,
12402,
63,
2394,
63,
1150,
12,
2126,
2338,
8,
11320,
27802,
2004,
63,
466,
275,
499,
27299,
413,
7729,
9,
4319,
283,
18,
2154,
297,
2126,
2338,
8,
11320,
27802,
2004,
63,
466,
275,
650,
27299,
413,
7729,
9,
4319,
283,
19,
2154,
297,
2126,
2338,
8,
11320,
27802,
2004,
63,
466,
275,
841,
27299,
413,
7729,
9,
4319,
283,
20,
2154,
297,
2126,
2338,
8,
11320,
27802,
2004,
63,
466,
275,
959,
27299,
413,
7729,
9,
4319,
283,
21,
2154,
7,
1362,
4442,
943,
1362,
16044,
6515,
2818,
306,
1648,
13,
991,
9,
83,
23915,
1362,
5138,
2818,
306,
3097,
9,
83,
891,
659,
339,
661,
36,
1841,
1672,
6536,
1362,
1449,
4859,
2126,
2818,
306,
923,
13,
991,
9,
83,
12,
2126,
2338,
8,
17,
9,
27503,
4319,
2338,
12,
2126,
12402,
8,
2394,
63,
1150,
9,
17907,
4319,
12402,
63,
2394,
63,
1150,
12,
2126,
2338,
8,
11320,
27802,
2004,
63,
466,
275,
499,
27299,
413,
7729,
9,
4319,
283,
18,
2154,
297,
2126,
2338,
8
] |
[
2753,
400,
411,
446,
1503,
13,
20402,
1827,
367,
302,
19101,
2879,
943,
14,
199,
199,
7692,
26,
272,
28810,
400,
411,
359,
1419,
61,
272,
28810,
400,
411,
359,
1419,
61,
334,
1361,
92,
2119,
92,
8595,
92,
1838,
9,
665,
1391,
30,
2263,
272,
28810,
400,
411,
2256,
272,
28810,
400,
411,
359,
1419,
61,
1827,
665,
1131,
30,
2263,
199,
199,
4558,
26,
272,
446,
76,
665,
493,
6244,
1553,
2732,
13,
793,
665,
493,
30,
221,
2879,
943,
570,
370,
2198,
14,
272,
446,
70,
665,
908,
6244,
1553,
793,
13,
908,
665,
908,
30,
221,
943,
1475,
465,
4165,
315,
943,
63,
908,
13613,
14,
359,
885,
26,
12149,
61,
272,
1553,
889,
13,
7207,
221,
28810,
400,
411,
849,
5953,
365,
370,
3686,
1453,
2385,
315,
943,
2151,
436,
1454,
9626,
367,
892,
2385,
465,
2985,
787,
5313,
370,
314,
2879,
943,
14,
2151,
3645,
642,
3305,
370,
11480,
28810,
400,
411,
370,
2112,
314,
1453,
1564,
402,
314,
2879,
943,
3140,
14,
272,
446,
84,
665,
4515,
6244,
1553,
4284,
665,
4515,
30,
221,
3622,
6252,
1380,
3879,
315,
2035,
818,
359,
885,
26,
499,
14,
16,
61,
339,
446,
71,
665,
1391,
6244,
1553,
923,
13,
991,
665,
1391,
30,
221,
1572,
701,
1750,
359,
885,
26,
1056,
63,
515,
61,
272,
446,
87,
665,
1391,
6244,
1553,
31569,
665,
3684,
30,
221,
9445,
8502,
359,
885,
26,
413,
61,
272,
446,
79,
665,
1391,
6244,
1553,
1648,
13,
991,
665,
1391,
30,
221,
1865,
402,
1072,
367,
849,
1827,
359,
885,
26,
2338,
61,
272,
446,
78,
665,
1955,
6244,
1553,
3097,
665,
1955,
30,
221,
2304,
314,
1329,
402,
5767,
5120,
315,
3622,
367,
2746,
1414,
359,
885,
26,
1616,
61,
272,
446,
65,
665,
1474,
30,
14263,
1553,
65,
665,
1474,
30,
2263,
221,
1050,
1437,
334,
7790,
506,
18384,
1437,
26,
3089,
12,
12402,
12,
1748,
12,
1390,
12,
5423,
4959,
1901,
1072,
339,
446,
86,
12,
1553,
3832,
221,
1655,
3376,
1072,
272,
446,
68,
12,
1553,
1757,
221,
870,
4036,
1004,
436,
4565,
2777,
272,
446,
72,
12,
1553,
3437,
221,
870,
642,
1720,
1245,
14,
272,
1553,
1023,
221,
870,
1015,
2556,
14,
339,
32445,
1182,
22820,
1511,
26,
272,
446,
67,
665,
493,
6244,
1553,
888,
665,
493,
30,
221,
2040,
28810,
400,
411,
370,
2198,
302,
19101,
1101,
570,
367,
943,
1475,
436,
2909,
14,
272,
446,
73,
665,
1541,
13,
5599,
6244,
1553,
1541,
665,
1541,
13,
5599,
30,
221,
2457,
315,
12,
5767,
23233,
1627,
3965,
787,
7686,
14,
272,
446,
80,
665,
1541,
13,
5599,
6244,
1553,
657,
13,
1541,
665,
1541,
13,
5599,
30,
315,
13,
1541,
3965,
370,
1104,
315,
876,
13,
11059,
7669,
14,
199,
199,
22787,
26,
272,
2900,
7251,
1586,
302,
19101,
1101,
570,
367,
2879,
943,
2909,
436,
1475,
14,
272,
982,
1265,
2934,
370,
4165,
314,
2879,
943,
570,
436,
1182,
503,
943,
1475,
12,
675,
314,
446,
70,
436,
446,
65,
1511,
14,
339,
298,
2119,
2,
2839,
2455,
402,
302,
19101,
4145,
272,
2672,
28810,
400,
411,
339,
14132,
1616,
5839,
931,
543,
2004,
7901,
26,
272,
2672,
28810,
400,
411,
2746,
1056,
63,
515,
1553,
1541,
283,
1205,
508,
7901,
7,
339,
14132,
1616,
4145,
543,
15356,
3141,
2783,
4847,
272,
2672,
28810,
400,
411,
1553,
1648,
13,
991,
283,
8595,
8,
2394,
63,
1150,
9,
627,
2338,
7,
339,
14132,
1616,
3982,
2287,
12,
325,
14,
71,
2020,
3963,
1159,
9793,
1337,
1265,
314,
4750,
272,
2672,
28810,
400,
411,
1553,
923,
13,
991,
3982,
63,
2697,
339,
9101,
4145,
543,
841,
2154,
503,
959,
2154,
2004,
12,
10451,
543,
2004,
436,
1455,
25104,
272,
2672,
28810,
400,
411,
446,
73,
283,
1205,
2356,
8290,
7,
870,
1056,
2004,
1455,
63,
20996,
339,
437,
3652,
2396,
2783,
4847,
402,
1926,
9320,
402,
5839,
931,
5386,
543,
283,
1421,
356,
272,
2672,
28810,
400,
411,
12402,
2783,
63,
1150,
1553,
1541,
283,
1205,
508,
1926,
436,
1056,
63,
515,
14,
2460,
480,
1421,
32292,
339,
14279,
806,
17098,
2879,
943,
687,
3982,
6844,
1808,
283,
2330,
7,
943,
1475,
272,
2672,
8635,
3982,
9483,
446,
70,
1182,
1391,
15,
793,
15,
3796,
18,
15,
2732,
14,
793,
1204,
28810,
400,
411,
446,
70,
2863,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
19840,
199,
504,
15502,
492,
11261,
199,
646,
15429,
199,
646,
2050,
199,
646,
747,
199,
646,
11723,
19,
199,
646,
900,
199,
646,
984,
199,
646,
4673,
199,
199,
893,
26,
272,
492,
7097,
199,
2590,
3545,
26,
272,
492,
4011,
14,
1122,
465,
7097,
199,
199,
504,
886,
32626,
492,
886,
32626,
199,
646,
5174,
5434,
199,
199,
504,
1275,
888,
63,
2087,
492,
9696,
63,
793,
63,
888,
12,
9696,
63,
888,
63,
515,
12,
5536,
63,
3669,
12,
1900,
63,
3401,
199,
504,
1275,
1208,
492,
1125,
63,
2224,
421,
199,
3472,
63,
2328,
540,
2563,
275,
359,
272,
661,
10407,
6536,
1362,
1449,
4859,
2126,
2338,
8,
17,
9,
27503,
4319,
2338,
12,
2126,
12402,
8,
2394,
63,
1150,
9,
17907,
4319,
12402,
63,
2394,
63,
1150,
12,
2126,
2338,
8,
11320,
27802,
2004,
63,
466,
275,
499,
27299,
413,
7729,
9,
4319,
283,
18,
2154,
297,
2126,
2338,
8,
11320,
27802,
2004,
63,
466,
275,
650,
27299,
413,
7729,
9,
4319,
283,
19,
2154,
297,
2126,
2338,
8,
11320,
27802,
2004,
63,
466,
275,
841,
27299,
413,
7729,
9,
4319,
283,
20,
2154,
297,
2126,
2338,
8,
11320,
27802,
2004,
63,
466,
275,
959,
27299,
413,
7729,
9,
4319,
283,
21,
2154,
7,
1362,
4442,
943,
1362,
16044,
6515,
2818,
306,
1648,
13,
991,
9,
83,
23915,
1362,
5138,
2818,
306,
3097,
9,
83,
891,
659,
339,
661,
36,
1841,
1672,
6536,
1362,
1449,
4859,
2126,
2818,
306,
923,
13,
991,
9,
83,
12,
2126,
2338,
8,
17,
9,
27503,
4319,
2338,
12,
2126,
12402,
8,
2394,
63,
1150,
9,
17907,
4319,
12402,
63,
2394,
63,
1150,
12,
2126,
2338,
8,
11320,
27802,
2004,
63,
466,
275,
499,
27299,
413,
7729,
9,
4319,
283,
18,
2154,
297,
2126,
2338,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
bl8/bockbuild
|
profiles/monodevelop-mac-dev/monodevelop-mac-dev.py
|
2
|
1573
|
#!/usr/bin/python -B
import os
import sys
sys.path.append ('../..')
from bockbuild.darwinprofile import DarwinProfile
from packages import MonoDevelopMacDevPackages
abs_pathself = os.path.realpath (os.path.abspath (sys.argv[0]))
class MonoDevelopMacDevProfile (DarwinProfile, MonoDevelopMacDevPackages):
def __init__ (self):
DarwinProfile.__init__ (self)
MonoDevelopMacDevPackages.__init__ (self)
self.gcc_flags.extend ([ '-g' ])
self_dir = os.path.dirname (abs_pathself)
MonoDevelopMacDevProfile ().build ()
profname = "md-dev-env"
dir = os.path.dirname (abs_pathself)
envscript = '''#!/bin/sh
PROFNAME="%s"
INSTALLDIR=%s/build-root/_install
export DYLD_FALLBACK_LIBRARY_PATH="$INSTALLDIR/lib:/lib:/usr/lib:$DYLD_FALLBACK_LIBRARY_PATH"
export C_INCLUDE_PATH="$INSTALLDIR/include:$C_INCLUDE_PATH"
export ACLOCAL_PATH="$INSTALLDIR/share/aclocal:$ACLOCAL_PATH"
export ACLOCAL_FLAGS="-I $INSTALLDIR/share/aclocal $ACLOCAL_FLAGS"
export PKG_CONFIG_PATH="$INSTALLDIR/lib/pkgconfig:$INSTALLDIR/lib64/pkgconfig:$INSTALLDIR/share/pkgconfig:$PKG_CONFIG_PATH"
#export CONFIG_SITE="$INSTALLDIR/$PROFNAME-config.site"
export MONO_GAC_PREFIX="$INSTALLDIR:MONO_GAC_PREFIX"
export MONO_ADDINS_REGISTRY="$INSTALLDIR/addinreg"
export PATH="$INSTALLDIR/bin:$PATH"
export MONO_INSTALL_PREFIX="$INSTALLDIR"
#mkdir -p "$INSTALLDIR"
#echo "test \"\$prefix\" = NONE && prefix=\"$INSTALLDIR\"" > $CONFIG_SITE
PS1="[$PROFNAME] \w @ "
''' % ( profname, dir )
print os.path.join (dir, profname)
with open(os.path.join (dir, profname), 'w') as f:
f.write (envscript)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
446,
34,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
661,
5093,
703,
358,
199,
199,
504,
330,
766,
1506,
14,
13245,
2913,
492,
577,
22822,
5736,
199,
504,
6117,
492,
10953,
79,
872,
7549,
3399,
12680,
25135,
199,
199,
2101,
63,
515,
277,
275,
747,
14,
515,
14,
11091,
334,
736,
14,
515,
14,
4832,
334,
1274,
14,
3020,
59,
16,
2459,
199,
199,
533,
10953,
79,
872,
7549,
3399,
12680,
5736,
334,
31065,
5736,
12,
10953,
79,
872,
7549,
3399,
12680,
25135,
304,
199,
198,
318,
636,
826,
363,
334,
277,
304,
507,
198,
31065,
5736,
855,
826,
363,
334,
277,
9,
507,
198,
6671,
79,
872,
7549,
3399,
12680,
25135,
855,
826,
363,
334,
277,
9,
9068,
198,
277,
14,
13112,
63,
2469,
14,
2880,
7287,
2475,
71,
7,
4794,
9068,
198,
277,
63,
694,
275,
747,
14,
515,
14,
3475,
334,
2101,
63,
515,
277,
9,
199,
199,
6671,
79,
872,
7549,
3399,
12680,
5736,
334,
680,
1506,
6248,
199,
199,
496,
5252,
275,
298,
1064,
13,
2374,
13,
1813,
2,
199,
694,
275,
747,
14,
515,
14,
3475,
334,
2101,
63,
515,
277,
9,
199,
199,
1813,
1579,
275,
1449,
3381,
1393,
15,
609,
199,
2514,
38,
2339,
5961,
83,
2,
199,
16811,
3022,
2458,
83,
15,
1506,
13,
1231,
15607,
3174,
199,
3790,
577,
57,
6533,
63,
38,
1761,
7111,
63,
16983,
63,
3243,
628,
4,
16811,
3022,
15,
773,
11254,
773,
11254,
2647,
15,
773,
26,
4,
11446,
6533,
63,
38,
1761,
7111,
63,
16983,
63,
3243,
2,
199,
3790,
445,
63,
18171,
63,
3243,
628,
4,
16811,
3022,
15,
2613,
26,
4,
35,
63,
18171,
63,
3243,
2,
199,
3790,
6570,
7486,
63,
3243,
628,
4,
16811,
3022,
15,
6251,
15,
645,
1832,
26,
4,
1348,
7486,
63,
3243,
2,
199,
3790,
6570,
7486,
63,
4831,
27295,
41,
2672,
16811,
3022,
15,
6251,
15,
645,
1832,
2672,
1348,
7486,
63,
4831,
2,
199,
3790,
30281,
63,
5569,
63,
3243,
628,
4,
16811,
3022,
15,
773,
15,
4600,
888,
26,
4,
16811,
3022,
15,
773,
772,
15,
4600,
888,
26,
4,
16811,
3022,
15,
6251,
15,
4600,
888,
26,
4,
18150,
63,
5569,
63,
3243,
2,
199,
3,
3790,
15869,
63,
7917,
628,
4,
16811,
3022,
21792,
2514,
38,
2339,
13,
888,
14,
2124,
2,
199,
3790,
603,
615,
47,
63,
39,
1348,
63,
6351,
628,
4,
16811,
3022,
26,
11710,
47,
63,
39,
1348,
63,
6351,
2,
199,
3790,
603,
615,
47,
63,
9732,
10789,
63,
25304,
57,
628,
4,
16811,
3022,
15,
525,
262,
1135,
2,
199,
3790,
15097,
628,
4,
16811,
3022,
15,
1393,
26,
4,
3243,
2,
199,
3790,
603,
615,
47,
63,
16811,
63,
6351,
628,
4,
16811,
3022,
2,
199,
199,
3,
8215,
446,
80,
7880,
16811,
3022,
2,
199,
3,
7878,
298,
396,
971,
3212,
4,
1861,
4451,
275,
653,
4817,
10883,
2403,
8178,
4,
16811,
3022,
18781,
690,
2672,
5569,
63,
7917,
199,
199,
5067,
17,
628,
59,
4,
2514,
38,
2339,
61,
971,
87,
768,
298,
199,
2344,
450,
334,
557,
5252,
12,
2935,
776,
199,
199,
1361,
747,
14,
515,
14,
904,
334,
694,
12,
557,
5252,
9,
199,
199,
1045,
1551,
8,
736,
14,
515,
14,
904,
334,
694,
12,
557,
5252,
395,
283,
87,
358,
465,
289,
26,
2126,
289,
14,
952,
334,
1813,
1579,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
446,
34,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
661,
5093,
703,
358,
199,
199,
504,
330,
766,
1506,
14,
13245,
2913,
492,
577,
22822,
5736,
199,
504,
6117,
492,
10953,
79,
872,
7549,
3399,
12680,
25135,
199,
199,
2101,
63,
515,
277,
275,
747,
14,
515,
14,
11091,
334,
736,
14,
515,
14,
4832,
334,
1274,
14,
3020,
59,
16,
2459,
199,
199,
533,
10953,
79,
872,
7549,
3399,
12680,
5736,
334,
31065,
5736,
12,
10953,
79,
872,
7549,
3399,
12680,
25135,
304,
199,
198,
318,
636,
826,
363,
334,
277,
304,
507,
198,
31065,
5736,
855,
826,
363,
334,
277,
9,
507,
198,
6671,
79,
872,
7549,
3399,
12680,
25135,
855,
826,
363,
334,
277,
9,
9068,
198,
277,
14,
13112,
63,
2469,
14,
2880,
7287,
2475,
71,
7,
4794,
9068,
198,
277,
63,
694,
275,
747,
14,
515,
14,
3475,
334,
2101,
63,
515,
277,
9,
199,
199,
6671,
79,
872,
7549,
3399,
12680,
5736,
334,
680,
1506,
6248,
199,
199,
496,
5252,
275,
298,
1064,
13,
2374,
13,
1813,
2,
199,
694,
275,
747,
14,
515,
14,
3475,
334,
2101,
63,
515,
277,
9,
199,
199,
1813,
1579,
275,
1449,
3381,
1393,
15,
609,
199,
2514,
38,
2339,
5961,
83,
2,
199,
16811,
3022,
2458,
83,
15,
1506,
13,
1231,
15607,
3174,
199,
3790,
577,
57,
6533,
63,
38,
1761,
7111,
63,
16983,
63,
3243,
628,
4,
16811,
3022,
15,
773,
11254,
773,
11254,
2647,
15,
773,
26,
4,
11446,
6533,
63,
38,
1761,
7111,
63,
16983,
63,
3243,
2,
199,
3790,
445,
63,
18171,
63,
3243,
628,
4,
16811,
3022,
15,
2613,
26,
4,
35,
63,
18171,
63,
3243,
2,
199,
3790,
6570,
7486,
63,
3243,
628,
4,
16811,
3022,
15,
6251,
15,
645,
1832,
26,
4,
1348,
7486,
63,
3243,
2,
199,
3790,
6570,
7486,
63,
4831,
27295,
41,
2672,
16811,
3022,
15,
6251,
15,
645,
1832,
2672,
1348,
7486,
63,
4831,
2,
199,
3790,
30281,
63,
5569,
63,
3243,
628,
4,
16811,
3022,
15,
773,
15,
4600,
888,
26,
4,
16811,
3022,
15,
773,
772,
15,
4600,
888,
26,
4,
16811,
3022,
15,
6251,
15,
4600,
888,
26,
4,
18150,
63,
5569,
63,
3243,
2,
199,
3,
3790,
15869,
63,
7917,
628,
4,
16811,
3022,
21792,
2514,
38,
2339,
13,
888,
14,
2124,
2,
199,
3790,
603,
615,
47,
63,
39,
1348,
63,
6351,
628,
4,
16811,
3022,
26,
11710,
47,
63,
39,
1348,
63,
6351,
2,
199,
3790,
603,
615,
47,
63,
9732,
10789,
63,
25304,
57,
628,
4,
16811,
3022,
15,
525,
262,
1135,
2,
199,
3790,
15097,
628,
4,
16811,
3022,
15,
1393,
26,
4,
3243,
2,
199,
3790,
603,
615,
47,
63,
16811,
63,
6351,
628,
4,
16811,
3022,
2,
199,
199,
3,
8215,
446,
80,
7880,
16811,
3022,
2,
199,
3,
7878,
298,
396,
971,
3212,
4,
1861,
4451,
275,
653,
4817,
10883,
2403,
8178,
4,
16811,
3022,
18781,
690,
2672,
5569,
63,
7917,
199,
199,
5067,
17,
628,
59,
4,
2514,
38,
2339,
61,
971,
87,
768,
298,
199,
2344,
450,
334,
557,
5252,
12,
2935,
776,
199,
199,
1361,
747,
14,
515,
14,
904,
334,
694,
12,
557,
5252,
9,
199,
199,
1045,
1551,
8,
736,
14,
515,
14,
904,
334,
694,
12,
557,
5252,
395,
283,
87,
358,
465,
289,
26,
2126,
289,
14,
952,
334,
1813,
1579,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ff94315/hiwifi-openwrt-HC5661-HC5761
|
staging_dir/host/lib64/scons-2.1.0/SCons/PathList.py
|
21
|
8422
|
#
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
__revision__ = "src/engine/SCons/PathList.py 5357 2011/09/09 21:31:03 bdeegan"
__doc__ = """SCons.PathList
A module for handling lists of directory paths (the sort of things
that get set as CPPPATH, LIBPATH, etc.) with as much caching of data and
efficiency as we can while still keeping the evaluation delayed so that we
Do the Right Thing (almost) regardless of how the variable is specified.
"""
import os
import SCons.Memoize
import SCons.Node
import SCons.Util
#
# Variables to specify the different types of entries in a PathList object:
#
TYPE_STRING_NO_SUBST = 0 # string with no '$'
TYPE_STRING_SUBST = 1 # string containing '$'
TYPE_OBJECT = 2 # other object
def node_conv(obj):
"""
This is the "string conversion" routine that we have our substitutions
use to return Nodes, not strings. This relies on the fact that an
EntryProxy object has a get() method that returns the underlying
Node that it wraps, which is a bit of architectural dependence
that we might need to break or modify in the future in response to
additional requirements.
"""
try:
get = obj.get
except AttributeError:
if isinstance(obj, SCons.Node.Node) or SCons.Util.is_Sequence( obj ):
result = obj
else:
result = str(obj)
else:
result = get()
return result
class _PathList(object):
"""
An actual PathList object.
"""
def __init__(self, pathlist):
"""
Initializes a PathList object, canonicalizing the input and
pre-processing it for quicker substitution later.
The stored representation of the PathList is a list of tuples
containing (type, value), where the "type" is one of the TYPE_*
variables defined above. We distinguish between:
strings that contain no '$' and therefore need no
delayed-evaluation string substitution (we expect that there
will be many of these and that we therefore get a pretty
big win from avoiding string substitution)
strings that contain '$' and therefore need substitution
(the hard case is things like '${TARGET.dir}/include',
which require re-evaluation for every target + source)
other objects (which may be something like an EntryProxy
that needs a method called to return a Node)
Pre-identifying the type of each element in the PathList up-front
and storing the type in the list of tuples is intended to reduce
the amount of calculation when we actually do the substitution
over and over for each target.
"""
if SCons.Util.is_String(pathlist):
pathlist = pathlist.split(os.pathsep)
elif not SCons.Util.is_Sequence(pathlist):
pathlist = [pathlist]
pl = []
for p in pathlist:
try:
index = p.find('$')
except (AttributeError, TypeError):
type = TYPE_OBJECT
else:
if index == -1:
type = TYPE_STRING_NO_SUBST
else:
type = TYPE_STRING_SUBST
pl.append((type, p))
self.pathlist = tuple(pl)
def __len__(self): return len(self.pathlist)
def __getitem__(self, i): return self.pathlist[i]
def subst_path(self, env, target, source):
"""
Performs construction variable substitution on a pre-digested
PathList for a specific target and source.
"""
result = []
for type, value in self.pathlist:
if type == TYPE_STRING_SUBST:
value = env.subst(value, target=target, source=source,
conv=node_conv)
if SCons.Util.is_Sequence(value):
result.extend(value)
continue
elif type == TYPE_OBJECT:
value = node_conv(value)
if value:
result.append(value)
return tuple(result)
class PathListCache(object):
"""
A class to handle caching of PathList lookups.
This class gets instantiated once and then deleted from the namespace,
so it's used as a Singleton (although we don't enforce that in the
usual Pythonic ways). We could have just made the cache a dictionary
in the module namespace, but putting it in this class allows us to
use the same Memoizer pattern that we use elsewhere to count cache
hits and misses, which is very valuable.
Lookup keys in the cache are computed by the _PathList_key() method.
Cache lookup should be quick, so we don't spend cycles canonicalizing
all forms of the same lookup key. For example, 'x:y' and ['x',
'y'] logically represent the same list, but we don't bother to
split string representations and treat those two equivalently.
(Note, however, that we do, treat lists and tuples the same.)
The main type of duplication we're trying to catch will come from
looking up the same path list from two different clones of the
same construction environment. That is, given
env2 = env1.Clone()
both env1 and env2 will have the same CPPPATH value, and we can
cheaply avoid re-parsing both values of CPPPATH by using the
common value from this cache.
"""
if SCons.Memoize.use_memoizer:
__metaclass__ = SCons.Memoize.Memoized_Metaclass
memoizer_counters = []
def __init__(self):
self._memo = {}
def _PathList_key(self, pathlist):
"""
Returns the key for memoization of PathLists.
Note that we want this to be pretty quick, so we don't completely
canonicalize all forms of the same list. For example,
'dir1:$ROOT/dir2' and ['$ROOT/dir1', 'dir'] may logically
represent the same list if you're executing from $ROOT, but
we're not going to bother splitting strings into path elements,
or massaging strings into Nodes, to identify that equivalence.
We just want to eliminate obvious redundancy from the normal
case of re-using exactly the same cloned value for a path.
"""
if SCons.Util.is_Sequence(pathlist):
pathlist = tuple(SCons.Util.flatten(pathlist))
return pathlist
memoizer_counters.append(SCons.Memoize.CountDict('PathList', _PathList_key))
def PathList(self, pathlist):
"""
Returns the cached _PathList object for the specified pathlist,
creating and caching a new object as necessary.
"""
pathlist = self._PathList_key(pathlist)
try:
memo_dict = self._memo['PathList']
except KeyError:
memo_dict = {}
self._memo['PathList'] = memo_dict
else:
try:
return memo_dict[pathlist]
except KeyError:
pass
result = _PathList(pathlist)
memo_dict[pathlist] = result
return result
PathList = PathListCache().PathList
del PathListCache
# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
|
gpl-2.0
|
[
3,
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
2042,
1296,
14,
647,
959,
13155,
7760,
15,
1643,
15,
1643,
7829,
26,
2192,
26,
1644,
330,
271,
5902,
290,
2,
199,
199,
363,
1301,
363,
275,
408,
18521,
14,
2042,
1296,
199,
199,
33,
859,
367,
7252,
5548,
402,
2082,
3792,
334,
1589,
4069,
402,
7645,
199,
9099,
664,
663,
465,
28635,
3243,
12,
25764,
3243,
12,
5423,
4959,
543,
465,
8298,
13627,
402,
666,
436,
199,
2829,
17750,
465,
781,
883,
1830,
5139,
22181,
314,
11735,
24725,
880,
626,
781,
199,
2585,
314,
20854,
3868,
316,
334,
4398,
9,
15270,
402,
4212,
314,
1750,
365,
2013,
14,
199,
199,
624,
199,
199,
646,
747,
199,
199,
646,
8218,
14,
1352,
573,
794,
199,
646,
8218,
14,
1716,
199,
646,
8218,
14,
9562,
199,
199,
3,
199,
3,
17198,
370,
4165,
314,
3365,
2943,
402,
4811,
315,
282,
6912,
1296,
909,
26,
199,
3,
199,
199,
2711,
63,
5353,
63,
2826,
63,
6348,
840,
275,
378,
263,
327,
1059,
543,
949,
25271,
199,
2711,
63,
5353,
63,
6348,
840,
275,
413,
3698,
327,
1059,
3035,
25271,
199,
2711,
63,
9868,
275,
499,
463,
327,
1163,
909,
199,
199,
318,
1031,
63,
5598,
8,
1113,
304,
272,
408,
272,
961,
365,
314,
298,
875,
8603,
2,
12981,
626,
781,
1172,
4154,
20873,
272,
675,
370,
372,
23836,
12,
440,
3326,
14,
221,
961,
25749,
641,
314,
10572,
626,
376,
272,
11855,
4936,
909,
965,
282,
664,
342,
1083,
626,
2529,
314,
8793,
272,
5013,
626,
652,
14018,
12,
1314,
365,
282,
4546,
402,
3819,
1175,
319,
4889,
477,
29578,
272,
626,
781,
5594,
1929,
370,
2059,
503,
2811,
315,
314,
6466,
315,
1177,
370,
272,
4722,
9760,
14,
272,
408,
272,
862,
26,
267,
664,
275,
1559,
14,
362,
272,
871,
4281,
26,
267,
340,
1228,
8,
1113,
12,
8218,
14,
1716,
14,
1716,
9,
503,
8218,
14,
9562,
14,
374,
63,
5826,
8,
1559,
3461,
288,
754,
275,
1559,
267,
587,
26,
288,
754,
275,
620,
8,
1113,
9,
272,
587,
26,
267,
754,
275,
664,
342,
272,
372,
754,
199,
199,
533,
485,
2042,
1296,
8,
785,
304,
272,
408,
272,
1626,
3503,
6912,
1296,
909,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
931,
513,
304,
267,
408,
267,
6026,
6491,
282,
6912,
1296,
909,
12,
11358,
9147,
314,
1324,
436,
267,
876,
13,
6338,
652,
367,
12530,
281,
20584,
2945,
14,
398,
710,
5489,
6025,
402,
314,
6912,
1296,
365,
282,
769,
402,
6346,
267,
3035,
334,
466,
12,
574,
395,
2382,
314,
298,
466,
2,
365,
1373,
402,
314,
11511,
15192,
267,
2860,
3247,
3432,
14,
221,
2136,
22237,
3382,
26,
953,
3326,
626,
1395,
949,
25271,
436,
16119,
1929,
949,
288,
24725,
13,
19154,
1059,
20584,
334,
1129,
4282,
626,
2337,
288,
911,
506,
5002,
402,
3520,
436,
626,
781,
16119,
664,
282,
7268,
288,
7282,
4747,
687,
5126,
316,
1059,
20584,
9,
953,
3326,
626,
1395,
25271,
436,
16119,
1929,
20584,
288,
334,
1589,
7508,
1930,
365,
7645,
2839,
20044,
9268,
14,
694,
5995,
2613,
297,
288,
1314,
4409,
295,
13,
19154,
367,
4036,
1347,
435,
1350,
9,
953,
1163,
2251,
334,
6777,
1443,
506,
6020,
2839,
376,
11855,
4936,
288,
626,
4839,
282,
1083,
2797,
370,
372,
282,
5013,
9,
398,
5543,
13,
22232,
316,
314,
730,
402,
1924,
1819,
315,
314,
6912,
1296,
1536,
13,
14708,
267,
436,
16915,
314,
730,
315,
314,
769,
402,
6346,
365,
11619,
370,
7114,
267,
314,
5982,
402,
15232,
1380,
781,
5965,
886,
314,
20584,
267,
1806,
436,
1806,
367,
1924,
1347,
14,
267,
408,
267,
340,
8218,
14,
9562,
14,
374,
63,
1558,
8,
515,
513,
304,
288,
931,
513,
275,
931,
513,
14,
1294,
8,
736,
14,
17843,
9,
267,
916,
440,
8218,
14,
9562,
14,
374,
63,
5826,
8,
515,
513,
304,
288,
931,
513,
275,
359,
515,
513,
61,
398,
1620,
275,
942,
267,
367,
299,
315,
931,
513,
26,
288,
862,
26,
355,
1478,
275,
299,
14,
1623,
360,
9988,
288,
871,
334,
10227,
12,
3146,
304,
355,
730,
275,
11511,
63,
9868,
288,
587,
26,
355,
340,
1478,
508,
446,
17,
26,
490,
730,
275,
11511,
63,
5353,
63,
2826,
63,
6348,
840,
355,
587,
26,
490,
730,
275,
11511,
63,
5353,
63,
6348,
840,
288,
1620,
14,
740,
1332,
466,
12,
299,
430,
398,
291,
14,
515,
513,
275,
2008,
8,
1168,
9,
339,
347,
636,
552,
721,
277,
304,
372,
822,
8,
277,
14,
515,
513,
9,
339,
347,
636,
6095,
721
] |
[
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
2042,
1296,
14,
647,
959,
13155,
7760,
15,
1643,
15,
1643,
7829,
26,
2192,
26,
1644,
330,
271,
5902,
290,
2,
199,
199,
363,
1301,
363,
275,
408,
18521,
14,
2042,
1296,
199,
199,
33,
859,
367,
7252,
5548,
402,
2082,
3792,
334,
1589,
4069,
402,
7645,
199,
9099,
664,
663,
465,
28635,
3243,
12,
25764,
3243,
12,
5423,
4959,
543,
465,
8298,
13627,
402,
666,
436,
199,
2829,
17750,
465,
781,
883,
1830,
5139,
22181,
314,
11735,
24725,
880,
626,
781,
199,
2585,
314,
20854,
3868,
316,
334,
4398,
9,
15270,
402,
4212,
314,
1750,
365,
2013,
14,
199,
199,
624,
199,
199,
646,
747,
199,
199,
646,
8218,
14,
1352,
573,
794,
199,
646,
8218,
14,
1716,
199,
646,
8218,
14,
9562,
199,
199,
3,
199,
3,
17198,
370,
4165,
314,
3365,
2943,
402,
4811,
315,
282,
6912,
1296,
909,
26,
199,
3,
199,
199,
2711,
63,
5353,
63,
2826,
63,
6348,
840,
275,
378,
263,
327,
1059,
543,
949,
25271,
199,
2711,
63,
5353,
63,
6348,
840,
275,
413,
3698,
327,
1059,
3035,
25271,
199,
2711,
63,
9868,
275,
499,
463,
327,
1163,
909,
199,
199,
318,
1031,
63,
5598,
8,
1113,
304,
272,
408,
272,
961,
365,
314,
298,
875,
8603,
2,
12981,
626,
781,
1172,
4154,
20873,
272,
675,
370,
372,
23836,
12,
440,
3326,
14,
221,
961,
25749,
641,
314,
10572,
626,
376,
272,
11855,
4936,
909,
965,
282,
664,
342,
1083,
626,
2529,
314,
8793,
272,
5013,
626,
652,
14018,
12,
1314,
365,
282,
4546,
402,
3819,
1175,
319,
4889,
477,
29578,
272,
626,
781,
5594,
1929,
370,
2059,
503,
2811,
315,
314,
6466,
315,
1177,
370,
272,
4722,
9760,
14,
272,
408,
272,
862,
26,
267,
664,
275,
1559,
14,
362,
272,
871,
4281,
26,
267,
340,
1228,
8,
1113,
12,
8218,
14,
1716,
14,
1716,
9,
503,
8218,
14,
9562,
14,
374,
63,
5826,
8,
1559,
3461,
288,
754,
275,
1559,
267,
587,
26,
288,
754,
275,
620,
8,
1113,
9,
272,
587,
26,
267,
754,
275,
664,
342,
272,
372,
754,
199,
199,
533,
485,
2042,
1296,
8,
785,
304,
272,
408,
272,
1626,
3503,
6912,
1296,
909,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
931,
513,
304,
267,
408,
267,
6026,
6491,
282,
6912,
1296,
909,
12,
11358,
9147,
314,
1324,
436,
267,
876,
13,
6338,
652,
367,
12530,
281,
20584,
2945,
14,
398,
710,
5489,
6025,
402,
314,
6912,
1296,
365,
282,
769,
402,
6346,
267,
3035,
334,
466,
12,
574,
395,
2382,
314,
298,
466,
2,
365,
1373,
402,
314,
11511,
15192,
267,
2860,
3247,
3432,
14,
221,
2136,
22237,
3382,
26,
953,
3326,
626,
1395,
949,
25271,
436,
16119,
1929,
949,
288,
24725,
13,
19154,
1059,
20584,
334,
1129,
4282,
626,
2337,
288,
911,
506,
5002,
402,
3520,
436,
626,
781,
16119,
664,
282,
7268,
288,
7282,
4747,
687,
5126,
316,
1059,
20584,
9,
953,
3326,
626,
1395,
25271,
436,
16119,
1929,
20584,
288,
334,
1589,
7508,
1930,
365,
7645,
2839,
20044,
9268,
14,
694,
5995,
2613,
297,
288,
1314,
4409,
295,
13,
19154,
367,
4036,
1347,
435,
1350,
9,
953,
1163,
2251,
334,
6777,
1443,
506,
6020,
2839,
376,
11855,
4936,
288,
626,
4839,
282,
1083,
2797,
370,
372,
282,
5013,
9,
398,
5543,
13,
22232,
316,
314,
730,
402,
1924,
1819,
315,
314,
6912,
1296,
1536,
13,
14708,
267,
436,
16915,
314,
730,
315,
314,
769,
402,
6346,
365,
11619,
370,
7114,
267,
314,
5982,
402,
15232,
1380,
781,
5965,
886,
314,
20584,
267,
1806,
436,
1806,
367,
1924,
1347,
14,
267,
408,
267,
340,
8218,
14,
9562,
14,
374,
63,
1558,
8,
515,
513,
304,
288,
931,
513,
275,
931,
513,
14,
1294,
8,
736,
14,
17843,
9,
267,
916,
440,
8218,
14,
9562,
14,
374,
63,
5826,
8,
515,
513,
304,
288,
931,
513,
275,
359,
515,
513,
61,
398,
1620,
275,
942,
267,
367,
299,
315,
931,
513,
26,
288,
862,
26,
355,
1478,
275,
299,
14,
1623,
360,
9988,
288,
871,
334,
10227,
12,
3146,
304,
355,
730,
275,
11511,
63,
9868,
288,
587,
26,
355,
340,
1478,
508,
446,
17,
26,
490,
730,
275,
11511,
63,
5353,
63,
2826,
63,
6348,
840,
355,
587,
26,
490,
730,
275,
11511,
63,
5353,
63,
6348,
840,
288,
1620,
14,
740,
1332,
466,
12,
299,
430,
398,
291,
14,
515,
513,
275,
2008,
8,
1168,
9,
339,
347,
636,
552,
721,
277,
304,
372,
822,
8,
277,
14,
515,
513,
9,
339,
347,
636,
6095,
721,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
cmende/pytelefoob0t
|
plugins/8ball/__init__.py
|
1
|
1199
|
# Copyright 2017 Christoph Mende
#
# 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.
import random
choices = [
'It is certain',
'It is decidedly so',
'Without a doubt',
'Yes definitely',
'You may rely on it',
'As I see it, yes',
'Most likely',
'Outlook good',
'Yes',
'Signs point to yes',
'Reply hazy try again',
'Ask again later',
'Better not tell you now',
'Cannot predict now',
'Concentrate and ask again',
'Don\'t count on it',
'My reply is no',
'My sources say no',
'Outlook not so good',
'Very doubtful'
]
def eightball(user, args):
return random.choice(choices)
commands = {
'8ball': eightball
}
|
apache-2.0
|
[
3,
221,
1898,
9708,
2799,
322,
2379,
72,
603,
287,
271,
199,
3,
199,
3,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
199,
646,
2196,
199,
199,
4577,
275,
359,
272,
283,
7940,
365,
9842,
297,
272,
283,
7940,
365,
12985,
770,
590,
880,
297,
272,
283,
12450,
282,
28584,
84,
297,
272,
283,
12555,
28088,
590,
297,
272,
283,
5556,
1443,
19687,
641,
652,
297,
272,
283,
2822,
473,
1937,
652,
12,
9456,
297,
272,
283,
24625,
12060,
297,
272,
283,
2204,
11660,
6954,
297,
272,
283,
12555,
297,
272,
283,
11575,
561,
2376,
370,
9456,
297,
272,
283,
14166,
18251,
3605,
862,
4020,
297,
272,
283,
25525,
4020,
2945,
297,
272,
283,
24472,
351,
440,
11480,
1265,
3063,
297,
272,
283,
6612,
12610,
3063,
297,
272,
283,
714,
2497,
454,
323,
436,
7198,
4020,
297,
272,
283,
16932,
3985,
84,
2338,
641,
652,
297,
272,
283,
5713,
9351,
365,
949,
297,
272,
283,
5713,
5274,
14722,
949,
297,
272,
283,
2204,
11660,
440,
880,
6954,
297,
272,
283,
54,
994,
28584,
84,
1893,
7,
199,
61,
199,
199,
318,
325,
1070,
8571,
8,
751,
12,
1249,
304,
272,
372,
2196,
14,
5095,
8,
4577,
9,
199,
199,
4405,
275,
469,
272,
283,
24,
8571,
356,
325,
1070,
8571,
199,
93,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
221,
1898,
9708,
2799,
322,
2379,
72,
603,
287,
271,
199,
3,
199,
3,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
199,
646,
2196,
199,
199,
4577,
275,
359,
272,
283,
7940,
365,
9842,
297,
272,
283,
7940,
365,
12985,
770,
590,
880,
297,
272,
283,
12450,
282,
28584,
84,
297,
272,
283,
12555,
28088,
590,
297,
272,
283,
5556,
1443,
19687,
641,
652,
297,
272,
283,
2822,
473,
1937,
652,
12,
9456,
297,
272,
283,
24625,
12060,
297,
272,
283,
2204,
11660,
6954,
297,
272,
283,
12555,
297,
272,
283,
11575,
561,
2376,
370,
9456,
297,
272,
283,
14166,
18251,
3605,
862,
4020,
297,
272,
283,
25525,
4020,
2945,
297,
272,
283,
24472,
351,
440,
11480,
1265,
3063,
297,
272,
283,
6612,
12610,
3063,
297,
272,
283,
714,
2497,
454,
323,
436,
7198,
4020,
297,
272,
283,
16932,
3985,
84,
2338,
641,
652,
297,
272,
283,
5713,
9351,
365,
949,
297,
272,
283,
5713,
5274,
14722,
949,
297,
272,
283,
2204,
11660,
440,
880,
6954,
297,
272,
283,
54,
994,
28584,
84,
1893,
7,
199,
61,
199,
199,
318,
325,
1070,
8571,
8,
751,
12,
1249,
304,
272,
372,
2196,
14,
5095,
8,
4577,
9,
199,
199,
4405,
275,
469,
272,
283,
24,
8571,
356,
325,
1070,
8571,
199,
93,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
greyhwndz/rethinkdb
|
external/v8_3.30.33.16/build/gyp/pylib/gyp/generator/eclipse.py
|
437
|
11894
|
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""GYP backend that generates Eclipse CDT settings files.
This backend DOES NOT generate Eclipse CDT projects. Instead, it generates XML
files that can be imported into an Eclipse CDT project. The XML file contains a
list of include paths and symbols (i.e. defines).
Because a full .cproject definition is not created by this generator, it's not
possible to properly define the include dirs and symbols for each file
individually. Instead, one set of includes/symbols is generated for the entire
project. This works fairly well (and is a vast improvement in general), but may
still result in a few indexer issues here and there.
This generator has no automated tests, so expect it to be broken.
"""
from xml.sax.saxutils import escape
import os.path
import subprocess
import gyp
import gyp.common
import gyp.msvs_emulation
import shlex
generator_wants_static_library_dependencies_adjusted = False
generator_default_variables = {
}
for dirname in ['INTERMEDIATE_DIR', 'PRODUCT_DIR', 'LIB_DIR', 'SHARED_LIB_DIR']:
# Some gyp steps fail if these are empty(!).
generator_default_variables[dirname] = 'dir'
for unused in ['RULE_INPUT_PATH', 'RULE_INPUT_ROOT', 'RULE_INPUT_NAME',
'RULE_INPUT_DIRNAME', 'RULE_INPUT_EXT',
'EXECUTABLE_PREFIX', 'EXECUTABLE_SUFFIX',
'STATIC_LIB_PREFIX', 'STATIC_LIB_SUFFIX',
'SHARED_LIB_PREFIX', 'SHARED_LIB_SUFFIX',
'CONFIGURATION_NAME']:
generator_default_variables[unused] = ''
# Include dirs will occasionally use the SHARED_INTERMEDIATE_DIR variable as
# part of the path when dealing with generated headers. This value will be
# replaced dynamically for each configuration.
generator_default_variables['SHARED_INTERMEDIATE_DIR'] = \
'$SHARED_INTERMEDIATE_DIR'
def CalculateVariables(default_variables, params):
generator_flags = params.get('generator_flags', {})
for key, val in generator_flags.items():
default_variables.setdefault(key, val)
flavor = gyp.common.GetFlavor(params)
default_variables.setdefault('OS', flavor)
if flavor == 'win':
# Copy additional generator configuration data from VS, which is shared
# by the Eclipse generator.
import gyp.generator.msvs as msvs_generator
generator_additional_non_configuration_keys = getattr(msvs_generator,
'generator_additional_non_configuration_keys', [])
generator_additional_path_sections = getattr(msvs_generator,
'generator_additional_path_sections', [])
gyp.msvs_emulation.CalculateCommonVariables(default_variables, params)
def CalculateGeneratorInputInfo(params):
"""Calculate the generator specific info that gets fed to input (called by
gyp)."""
generator_flags = params.get('generator_flags', {})
if generator_flags.get('adjust_static_libraries', False):
global generator_wants_static_library_dependencies_adjusted
generator_wants_static_library_dependencies_adjusted = True
def GetAllIncludeDirectories(target_list, target_dicts,
shared_intermediate_dirs, config_name, params):
"""Calculate the set of include directories to be used.
Returns:
A list including all the include_dir's specified for every target followed
by any include directories that were added as cflag compiler options.
"""
gyp_includes_set = set()
compiler_includes_list = []
flavor = gyp.common.GetFlavor(params)
if flavor == 'win':
generator_flags = params.get('generator_flags', {})
for target_name in target_list:
target = target_dicts[target_name]
if config_name in target['configurations']:
config = target['configurations'][config_name]
# Look for any include dirs that were explicitly added via cflags. This
# may be done in gyp files to force certain includes to come at the end.
# TODO(jgreenwald): Change the gyp files to not abuse cflags for this, and
# remove this.
if flavor == 'win':
msvs_settings = gyp.msvs_emulation.MsvsSettings(target, generator_flags)
cflags = msvs_settings.GetCflags(config_name)
else:
cflags = config['cflags']
for cflag in cflags:
include_dir = ''
if cflag.startswith('-I'):
include_dir = cflag[2:]
if include_dir and not include_dir in compiler_includes_list:
compiler_includes_list.append(include_dir)
# Find standard gyp include dirs.
if config.has_key('include_dirs'):
include_dirs = config['include_dirs']
for shared_intermediate_dir in shared_intermediate_dirs:
for include_dir in include_dirs:
include_dir = include_dir.replace('$SHARED_INTERMEDIATE_DIR',
shared_intermediate_dir)
if not os.path.isabs(include_dir):
base_dir = os.path.dirname(target_name)
include_dir = base_dir + '/' + include_dir
include_dir = os.path.abspath(include_dir)
if not include_dir in gyp_includes_set:
gyp_includes_set.add(include_dir)
# Generate a list that has all the include dirs.
all_includes_list = list(gyp_includes_set)
all_includes_list.sort()
for compiler_include in compiler_includes_list:
if not compiler_include in gyp_includes_set:
all_includes_list.append(compiler_include)
# All done.
return all_includes_list
def GetCompilerPath(target_list, target_dicts, data):
"""Determine a command that can be used to invoke the compiler.
Returns:
If this is a gyp project that has explicit make settings, try to determine
the compiler from that. Otherwise, see if a compiler was specified via the
CC_target environment variable.
"""
# First, see if the compiler is configured in make's settings.
build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])
make_global_settings_dict = data[build_file].get('make_global_settings', {})
for key, value in make_global_settings_dict:
if key in ['CC', 'CXX']:
return value
# Check to see if the compiler was specified as an environment variable.
for key in ['CC_target', 'CC', 'CXX']:
compiler = os.environ.get(key)
if compiler:
return compiler
return 'gcc'
def GetAllDefines(target_list, target_dicts, data, config_name, params):
"""Calculate the defines for a project.
Returns:
A dict that includes explict defines declared in gyp files along with all of
the default defines that the compiler uses.
"""
# Get defines declared in the gyp files.
all_defines = {}
flavor = gyp.common.GetFlavor(params)
if flavor == 'win':
generator_flags = params.get('generator_flags', {})
for target_name in target_list:
target = target_dicts[target_name]
if flavor == 'win':
msvs_settings = gyp.msvs_emulation.MsvsSettings(target, generator_flags)
extra_defines = msvs_settings.GetComputedDefines(config_name)
else:
extra_defines = []
if config_name in target['configurations']:
config = target['configurations'][config_name]
target_defines = config['defines']
else:
target_defines = []
for define in target_defines + extra_defines:
split_define = define.split('=', 1)
if len(split_define) == 1:
split_define.append('1')
if split_define[0].strip() in all_defines:
# Already defined
continue
all_defines[split_define[0].strip()] = split_define[1].strip()
# Get default compiler defines (if possible).
if flavor == 'win':
return all_defines # Default defines already processed in the loop above.
cc_target = GetCompilerPath(target_list, target_dicts, data)
if cc_target:
command = shlex.split(cc_target)
command.extend(['-E', '-dM', '-'])
cpp_proc = subprocess.Popen(args=command, cwd='.',
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
cpp_output = cpp_proc.communicate()[0]
cpp_lines = cpp_output.split('\n')
for cpp_line in cpp_lines:
if not cpp_line.strip():
continue
cpp_line_parts = cpp_line.split(' ', 2)
key = cpp_line_parts[1]
if len(cpp_line_parts) >= 3:
val = cpp_line_parts[2]
else:
val = '1'
all_defines[key] = val
return all_defines
def WriteIncludePaths(out, eclipse_langs, include_dirs):
"""Write the includes section of a CDT settings export file."""
out.write(' <section name="org.eclipse.cdt.internal.ui.wizards.' \
'settingswizards.IncludePaths">\n')
out.write(' <language name="holder for library settings"></language>\n')
for lang in eclipse_langs:
out.write(' <language name="%s">\n' % lang)
for include_dir in include_dirs:
out.write(' <includepath workspace_path="false">%s</includepath>\n' %
include_dir)
out.write(' </language>\n')
out.write(' </section>\n')
def WriteMacros(out, eclipse_langs, defines):
"""Write the macros section of a CDT settings export file."""
out.write(' <section name="org.eclipse.cdt.internal.ui.wizards.' \
'settingswizards.Macros">\n')
out.write(' <language name="holder for library settings"></language>\n')
for lang in eclipse_langs:
out.write(' <language name="%s">\n' % lang)
for key in sorted(defines.iterkeys()):
out.write(' <macro><name>%s</name><value>%s</value></macro>\n' %
(escape(key), escape(defines[key])))
out.write(' </language>\n')
out.write(' </section>\n')
def GenerateOutputForConfig(target_list, target_dicts, data, params,
config_name):
options = params['options']
generator_flags = params.get('generator_flags', {})
# build_dir: relative path from source root to our output files.
# e.g. "out/Debug"
build_dir = os.path.join(generator_flags.get('output_dir', 'out'),
config_name)
toplevel_build = os.path.join(options.toplevel_dir, build_dir)
# Ninja uses out/Debug/gen while make uses out/Debug/obj/gen as the
# SHARED_INTERMEDIATE_DIR. Include both possible locations.
shared_intermediate_dirs = [os.path.join(toplevel_build, 'obj', 'gen'),
os.path.join(toplevel_build, 'gen')]
out_name = os.path.join(toplevel_build, 'eclipse-cdt-settings.xml')
gyp.common.EnsureDirExists(out_name)
out = open(out_name, 'w')
out.write('<?xml version="1.0" encoding="UTF-8"?>\n')
out.write('<cdtprojectproperties>\n')
eclipse_langs = ['C++ Source File', 'C Source File', 'Assembly Source File',
'GNU C++', 'GNU C', 'Assembly']
include_dirs = GetAllIncludeDirectories(target_list, target_dicts,
shared_intermediate_dirs, config_name,
params)
WriteIncludePaths(out, eclipse_langs, include_dirs)
defines = GetAllDefines(target_list, target_dicts, data, config_name, params)
WriteMacros(out, eclipse_langs, defines)
out.write('</cdtprojectproperties>\n')
out.close()
def GenerateOutput(target_list, target_dicts, data, params):
"""Generate an XML settings file that can be imported into a CDT project."""
if params['options'].generator_output:
raise NotImplementedError, "--generator_output not implemented for eclipse"
user_config = params.get('generator_flags', {}).get('config', None)
if user_config:
GenerateOutputForConfig(target_list, target_dicts, data, params,
user_config)
else:
config_names = target_dicts[target_list[0]]['configurations'].keys()
for config_name in config_names:
GenerateOutputForConfig(target_list, target_dicts, data, params,
config_name)
|
agpl-3.0
|
[
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
14884,
4865,
626,
12821,
662,
7548,
261,
445,
7438,
2202,
1584,
14,
199,
199,
2765,
4865,
3506,
654,
2845,
3550,
662,
7548,
261,
445,
7438,
11336,
14,
15345,
12,
652,
12821,
4692,
199,
1725,
626,
883,
506,
8439,
1901,
376,
662,
7548,
261,
445,
7438,
2199,
14,
710,
4692,
570,
3509,
282,
199,
513,
402,
2387,
3792,
436,
6698,
334,
73,
14,
69,
14,
7890,
680,
199,
199,
3655,
2651,
282,
2615,
1275,
67,
1715,
5492,
365,
440,
2737,
701,
642,
4306,
12,
652,
1159,
440,
199,
13893,
370,
7684,
5627,
314,
2387,
7606,
436,
6698,
367,
1924,
570,
199,
262,
14715,
3163,
14,
221,
15345,
12,
1373,
663,
402,
6952,
15,
7450,
365,
4046,
367,
314,
8039,
199,
1715,
14,
221,
961,
5419,
28092,
590,
5521,
334,
460,
365,
282,
373,
1810,
19053,
434,
315,
8605,
395,
1325,
1443,
199,
32310,
754,
315,
282,
9284,
23093,
10876,
2348,
436,
2337,
14,
199,
199,
2765,
4306,
965,
949,
6384,
23513,
2295,
12,
880,
4282,
652,
370,
506,
10529,
14,
199,
624,
199,
199,
504,
2748,
14,
14338,
14,
14338,
1208,
492,
4772,
199,
646,
747,
14,
515,
199,
646,
3873,
199,
646,
4902,
199,
646,
4902,
14,
2330,
199,
646,
4902,
14,
8338,
63,
20526,
199,
646,
16701,
199,
199,
4679,
63,
28789,
63,
1986,
63,
4342,
63,
5714,
63,
23395,
275,
756,
199,
199,
4679,
63,
885,
63,
3669,
275,
469,
199,
93,
199,
199,
509,
9017,
315,
788,
23227,
63,
3022,
297,
283,
14853,
63,
3022,
297,
283,
5617,
63,
3022,
297,
283,
13772,
63,
5617,
63,
3022,
2565,
523,
327,
6601,
4902,
7124,
2449,
340,
3520,
787,
2701,
8,
1,
680,
523,
4306,
63,
885,
63,
3669,
59,
3475,
61,
275,
283,
694,
7,
199,
199,
509,
9563,
315,
788,
13578,
63,
7321,
63,
3243,
297,
283,
13578,
63,
7321,
63,
5441,
297,
283,
13578,
63,
7321,
63,
2339,
297,
2049,
283,
13578,
63,
7321,
63,
3022,
2339,
297,
283,
13578,
63,
7321,
63,
2472,
297,
2049,
283,
21623,
63,
6351,
297,
283,
21623,
63,
12273,
297,
2049,
283,
10449,
63,
5617,
63,
6351,
297,
283,
10449,
63,
5617,
63,
12273,
297,
2049,
283,
13772,
63,
5617,
63,
6351,
297,
283,
13772,
63,
5617,
63,
12273,
297,
2049,
283,
22212,
63,
2339,
2565,
523,
4306,
63,
885,
63,
3669,
59,
8618,
61,
275,
2125,
199,
199,
3,
15783,
7606,
911,
14706,
305,
1636,
1183,
675,
314,
4410,
689,
1149,
63,
23227,
63,
3022,
1750,
465,
199,
3,
1777,
402,
314,
931,
1380,
23654,
543,
4046,
2323,
14,
221,
961,
574,
911,
506,
199,
3,
8717,
18774,
367,
1924,
2897,
14,
199,
4679,
63,
885,
63,
3669,
459,
13772,
63,
23227,
63,
3022,
418,
275,
971,
272,
4505,
13772,
63,
23227,
63,
3022,
7,
421,
199,
318,
12707,
11458,
8,
885,
63,
3669,
12,
1862,
304,
523,
4306,
63,
2469,
275,
1862,
14,
362,
360,
4679,
63,
2469,
297,
5009,
523,
367,
790,
12,
1139,
315,
4306,
63,
2469,
14,
1744,
837,
272,
849,
63,
3669,
14,
5486,
8,
498,
12,
1139,
9,
523,
8541,
275,
4902,
14,
2330,
14,
1002,
16739,
8,
1162,
9,
523,
849,
63,
3669,
14,
5486,
360,
3100,
297,
8541,
9,
523,
340,
8541,
508,
283,
2676,
356,
272,
327,
11247,
4722,
4306,
2897,
666,
687,
21685,
12,
1314,
365,
5709,
272,
327,
701,
314,
662,
7548,
261,
4306,
14,
272,
492,
4902,
14,
4679,
14,
8338,
465,
13795,
63,
4679,
272,
4306,
63,
8460,
63,
2865,
63,
4758,
63,
1612,
275,
2519,
8,
8338,
63,
4679,
12,
267,
283,
4679,
63,
8460,
63,
2865,
63,
4758,
63,
1612,
297,
3073,
272,
4306,
63,
8460,
63,
515,
63,
7786,
275,
2519,
8,
8338,
63,
4679,
12,
267,
283,
4679,
63,
8460,
63,
515,
63,
7786,
297,
3073,
339,
4902,
14,
8338,
63,
20526,
14,
14860,
7844,
11458,
8,
885,
63,
3669,
12,
1862,
9,
421,
199,
318,
12707,
7599,
3205,
2354,
8,
1162,
304,
523,
408,
14860,
314,
4306,
2488,
2256,
626,
7545,
23036,
370,
1324,
334,
3527,
701,
523,
4902,
10477,
523,
4306,
63,
2469,
275,
1862,
14,
362,
360,
4679,
63,
2469,
297,
5009,
523,
340,
4306,
63,
2469,
14,
362,
360,
10917,
63,
1986,
63,
10159,
297,
756,
304,
272,
2288,
4306,
63,
28789,
63,
1986,
63,
4342,
63,
5714,
63,
23395,
272,
4306,
63,
28789,
63,
1986,
63,
4342,
63,
5714,
63,
23395,
275,
715,
421,
199,
318,
2372,
2422,
23838,
8,
1375,
63,
513,
12,
1347,
63,
7892,
12,
2490,
5709,
63,
15940,
63,
3220,
12,
1101,
63,
354,
12,
1862,
304,
523,
408,
14860,
314,
663,
402,
2387,
6602,
370,
506,
1202,
14,
819,
1803,
26,
272,
437,
769,
5893,
1006,
314,
2387,
63,
694,
1159,
2013,
367,
4036,
1347,
9437,
272,
701,
1263,
2387,
6602,
626,
4898,
3483,
465,
3980,
1823,
6365,
1511,
14,
523,
408,
819,
4902,
63,
9441,
63,
409,
275,
663,
342,
523,
6365,
63,
9441,
63,
513,
275,
942,
819,
8541,
275,
4902,
14,
2330,
14,
1002,
16739,
8,
1162,
9,
523,
340,
8541,
508,
283,
2676,
356,
272,
4306,
63,
2469,
275,
1862,
14,
362,
360,
4679,
63,
2469,
297,
5009,
523,
367,
1347,
63,
354,
315,
1347,
63,
513,
26,
272,
1347,
275,
1347,
63,
7892,
59,
1375,
63,
354,
61,
272,
340,
1101,
63,
354,
315,
1347,
459,
10057,
2565,
489,
1101,
275,
1347,
459,
10057,
3488,
888,
63,
354,
61,
2541,
327,
12077,
367,
1263,
2387,
7606,
626,
4898,
7662,
3483,
4799,
13426,
14,
961,
489,
327,
1443,
506,
4224,
315,
4902,
1584,
370,
3542,
9842,
6952,
370,
11492,
737,
314,
1284,
14,
489,
327,
3254,
8,
74,
7731,
20877,
68,
304,
7743,
314,
4902,
1584,
370,
440,
282,
464,
261,
13426,
367,
642,
12,
436,
489,
327,
2813,
642,
14,
489,
340,
8541,
508,
283,
2676,
356,
267,
13795,
63,
1751,
275,
4902,
14,
8338,
63,
20526,
14,
45,
2772,
83,
5268,
8,
1375,
12,
4306,
63,
2469,
9
] |
[
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
14884,
4865,
626,
12821,
662,
7548,
261,
445,
7438,
2202,
1584,
14,
199,
199,
2765,
4865,
3506,
654,
2845,
3550,
662,
7548,
261,
445,
7438,
11336,
14,
15345,
12,
652,
12821,
4692,
199,
1725,
626,
883,
506,
8439,
1901,
376,
662,
7548,
261,
445,
7438,
2199,
14,
710,
4692,
570,
3509,
282,
199,
513,
402,
2387,
3792,
436,
6698,
334,
73,
14,
69,
14,
7890,
680,
199,
199,
3655,
2651,
282,
2615,
1275,
67,
1715,
5492,
365,
440,
2737,
701,
642,
4306,
12,
652,
1159,
440,
199,
13893,
370,
7684,
5627,
314,
2387,
7606,
436,
6698,
367,
1924,
570,
199,
262,
14715,
3163,
14,
221,
15345,
12,
1373,
663,
402,
6952,
15,
7450,
365,
4046,
367,
314,
8039,
199,
1715,
14,
221,
961,
5419,
28092,
590,
5521,
334,
460,
365,
282,
373,
1810,
19053,
434,
315,
8605,
395,
1325,
1443,
199,
32310,
754,
315,
282,
9284,
23093,
10876,
2348,
436,
2337,
14,
199,
199,
2765,
4306,
965,
949,
6384,
23513,
2295,
12,
880,
4282,
652,
370,
506,
10529,
14,
199,
624,
199,
199,
504,
2748,
14,
14338,
14,
14338,
1208,
492,
4772,
199,
646,
747,
14,
515,
199,
646,
3873,
199,
646,
4902,
199,
646,
4902,
14,
2330,
199,
646,
4902,
14,
8338,
63,
20526,
199,
646,
16701,
199,
199,
4679,
63,
28789,
63,
1986,
63,
4342,
63,
5714,
63,
23395,
275,
756,
199,
199,
4679,
63,
885,
63,
3669,
275,
469,
199,
93,
199,
199,
509,
9017,
315,
788,
23227,
63,
3022,
297,
283,
14853,
63,
3022,
297,
283,
5617,
63,
3022,
297,
283,
13772,
63,
5617,
63,
3022,
2565,
523,
327,
6601,
4902,
7124,
2449,
340,
3520,
787,
2701,
8,
1,
680,
523,
4306,
63,
885,
63,
3669,
59,
3475,
61,
275,
283,
694,
7,
199,
199,
509,
9563,
315,
788,
13578,
63,
7321,
63,
3243,
297,
283,
13578,
63,
7321,
63,
5441,
297,
283,
13578,
63,
7321,
63,
2339,
297,
2049,
283,
13578,
63,
7321,
63,
3022,
2339,
297,
283,
13578,
63,
7321,
63,
2472,
297,
2049,
283,
21623,
63,
6351,
297,
283,
21623,
63,
12273,
297,
2049,
283,
10449,
63,
5617,
63,
6351,
297,
283,
10449,
63,
5617,
63,
12273,
297,
2049,
283,
13772,
63,
5617,
63,
6351,
297,
283,
13772,
63,
5617,
63,
12273,
297,
2049,
283,
22212,
63,
2339,
2565,
523,
4306,
63,
885,
63,
3669,
59,
8618,
61,
275,
2125,
199,
199,
3,
15783,
7606,
911,
14706,
305,
1636,
1183,
675,
314,
4410,
689,
1149,
63,
23227,
63,
3022,
1750,
465,
199,
3,
1777,
402,
314,
931,
1380,
23654,
543,
4046,
2323,
14,
221,
961,
574,
911,
506,
199,
3,
8717,
18774,
367,
1924,
2897,
14,
199,
4679,
63,
885,
63,
3669,
459,
13772,
63,
23227,
63,
3022,
418,
275,
971,
272,
4505,
13772,
63,
23227,
63,
3022,
7,
421,
199,
318,
12707,
11458,
8,
885,
63,
3669,
12,
1862,
304,
523,
4306,
63,
2469,
275,
1862,
14,
362,
360,
4679,
63,
2469,
297,
5009,
523,
367,
790,
12,
1139,
315,
4306,
63,
2469,
14,
1744,
837,
272,
849,
63,
3669,
14,
5486,
8,
498,
12,
1139,
9,
523,
8541,
275,
4902,
14,
2330,
14,
1002,
16739,
8,
1162,
9,
523,
849,
63,
3669,
14,
5486,
360,
3100,
297,
8541,
9,
523,
340,
8541,
508,
283,
2676,
356,
272,
327,
11247,
4722,
4306,
2897,
666,
687,
21685,
12,
1314,
365,
5709,
272,
327,
701,
314,
662,
7548,
261,
4306,
14,
272,
492,
4902,
14,
4679,
14,
8338,
465,
13795,
63,
4679,
272,
4306,
63,
8460,
63,
2865,
63,
4758,
63,
1612,
275,
2519,
8,
8338,
63,
4679,
12,
267,
283,
4679,
63,
8460,
63,
2865,
63,
4758,
63,
1612,
297,
3073,
272,
4306,
63,
8460,
63,
515,
63,
7786,
275,
2519,
8,
8338,
63,
4679,
12,
267,
283,
4679,
63,
8460,
63,
515,
63,
7786,
297,
3073,
339,
4902,
14,
8338,
63,
20526,
14,
14860,
7844,
11458,
8,
885,
63,
3669,
12,
1862,
9,
421,
199,
318,
12707,
7599,
3205,
2354,
8,
1162,
304,
523,
408,
14860,
314,
4306,
2488,
2256,
626,
7545,
23036,
370,
1324,
334,
3527,
701,
523,
4902,
10477,
523,
4306,
63,
2469,
275,
1862,
14,
362,
360,
4679,
63,
2469,
297,
5009,
523,
340,
4306,
63,
2469,
14,
362,
360,
10917,
63,
1986,
63,
10159,
297,
756,
304,
272,
2288,
4306,
63,
28789,
63,
1986,
63,
4342,
63,
5714,
63,
23395,
272,
4306,
63,
28789,
63,
1986,
63,
4342,
63,
5714,
63,
23395,
275,
715,
421,
199,
318,
2372,
2422,
23838,
8,
1375,
63,
513,
12,
1347,
63,
7892,
12,
2490,
5709,
63,
15940,
63,
3220,
12,
1101,
63,
354,
12,
1862,
304,
523,
408,
14860,
314,
663,
402,
2387,
6602,
370,
506,
1202,
14,
819,
1803,
26,
272,
437,
769,
5893,
1006,
314,
2387,
63,
694,
1159,
2013,
367,
4036,
1347,
9437,
272,
701,
1263,
2387,
6602,
626,
4898,
3483,
465,
3980,
1823,
6365,
1511,
14,
523,
408,
819,
4902,
63,
9441,
63,
409,
275,
663,
342,
523,
6365,
63,
9441,
63,
513,
275,
942,
819,
8541,
275,
4902,
14,
2330,
14,
1002,
16739,
8,
1162,
9,
523,
340,
8541,
508,
283,
2676,
356,
272,
4306,
63,
2469,
275,
1862,
14,
362,
360,
4679,
63,
2469,
297,
5009,
523,
367,
1347,
63,
354,
315,
1347,
63,
513,
26,
272,
1347,
275,
1347,
63,
7892,
59,
1375,
63,
354,
61,
272,
340,
1101,
63,
354,
315,
1347,
459,
10057,
2565,
489,
1101,
275,
1347,
459,
10057,
3488,
888,
63,
354,
61,
2541,
327,
12077,
367,
1263,
2387,
7606,
626,
4898,
7662,
3483,
4799,
13426,
14,
961,
489,
327,
1443,
506,
4224,
315,
4902,
1584,
370,
3542,
9842,
6952,
370,
11492,
737,
314,
1284,
14,
489,
327,
3254,
8,
74,
7731,
20877,
68,
304,
7743,
314,
4902,
1584,
370,
440,
282,
464,
261,
13426,
367,
642,
12,
436,
489,
327,
2813,
642,
14,
489,
340,
8541,
508,
283,
2676,
356,
267,
13795,
63,
1751,
275,
4902,
14,
8338,
63,
20526,
14,
45,
2772,
83,
5268,
8,
1375,
12,
4306,
63,
2469,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
shanksauce/mintr
|
mintr/__init__.py
|
1
|
1862
|
import requests
import time
import re
from pprint import pprint
auth_headers = {}
def _validate_credentials(fn):
def wrapper(*args):
def is_not_populated(d,r):
return reduce(
lambda x,y: x or y,
map(lambda k: k not in d or not d[k], r)
)
if is_not_populated(auth_headers, ('cookie', 'token')):
raise Exception('Login first')
return fn(*args)
return wrapper
def login(username, password):
if username is None or password is None:
raise Exception('Use valid credentials')
a = requests.get('https://wwws.mint.com/login.event')
session_id = a.cookies.get('MINTJSESSIONID')
route_id = a.cookies.get('ROUTEID')
b = requests.post(
'https://wwws.mint.com/loginUserSubmit.xevent',
cookies = a.cookies,
headers = {
'Accept': 'application/json',
'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie': 'MINTJSESSIONID={0}; ROUTEID={1}'.format(session_id,
route_id)
},
data = {
'username': username,
'password': password,
'task': 'L'
}
)
csrf_token = b.json()['CSRFToken']
match = re.search('MINTJSESSIONID=(.*?);', b.headers['set-cookie'])
if match is None:
raise Exception('No MINTJSESSIONID')
b_session_id = match.groups(0)[0]
#@_validate_credentials
def get_account_summaries(jwt=None):
if jwt is None:
return {}
try:
d = requests.get(
'https://mint.finance.intuit.com/v1/accounts?limit=1000',
headers = {'Authorization': 'Bearer ' + jwt}
)
accounts = dict(map(
lambda x: (
x['fiName'] + ' ' + x['cpAccountName'],
x['currentBalance']
),
filter(
lambda x: x['accountStatus'] == 'ACTIVE' and x['currentBalance'] > 0,
d.json()['Account']
)
))
return accounts
except Exception as ex:
return {}
|
mit
|
[
646,
4145,
199,
646,
900,
199,
646,
295,
199,
504,
10933,
492,
10933,
199,
199,
1178,
63,
2139,
275,
1052,
199,
199,
318,
485,
3502,
63,
6942,
8,
2324,
304,
523,
347,
4975,
2031,
589,
304,
272,
347,
365,
63,
1397,
63,
21440,
8,
68,
12,
82,
304,
489,
372,
7114,
8,
267,
2400,
671,
12,
89,
26,
671,
503,
612,
12,
267,
2341,
8,
2734,
1022,
26,
1022,
440,
315,
366,
503,
440,
366,
59,
75,
467,
519,
9,
489,
776,
272,
340,
365,
63,
1397,
63,
21440,
8,
1178,
63,
2139,
12,
661,
5306,
297,
283,
1418,
8109,
489,
746,
2186,
360,
8880,
1642,
358,
272,
372,
4325,
2031,
589,
9,
523,
372,
4975,
421,
199,
318,
4676,
8,
2473,
12,
2505,
304,
523,
340,
3434,
365,
488,
503,
2505,
365,
488,
26,
272,
746,
2186,
360,
6119,
1686,
6235,
358,
819,
282,
275,
4145,
14,
362,
360,
2859,
921,
1544,
83,
14,
77,
442,
14,
957,
15,
2886,
14,
1430,
358,
523,
2351,
63,
344,
275,
282,
14,
7792,
14,
362,
360,
45,
2919,
11378,
9577,
998,
358,
523,
7475,
63,
344,
275,
282,
14,
7792,
14,
362,
360,
1092,
4586,
998,
358,
819,
330,
275,
4145,
14,
1932,
8,
272,
283,
2859,
921,
1544,
83,
14,
77,
442,
14,
957,
15,
2886,
1899,
17187,
14,
88,
1430,
297,
272,
10049,
275,
282,
14,
7792,
12,
272,
2323,
275,
469,
489,
283,
8422,
356,
283,
3578,
15,
1001,
297,
489,
283,
2714,
13,
466,
356,
283,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
27,
5960,
29,
6610,
13,
24,
297,
489,
283,
7810,
356,
283,
45,
2919,
11378,
9577,
998,
3126,
16,
12084,
820,
1877,
37,
998,
3126,
17,
5285,
908,
8,
1730,
63,
344,
12,
267,
7475,
63,
344,
9,
272,
1660,
272,
666,
275,
469,
489,
283,
2473,
356,
3434,
12,
489,
283,
2060,
356,
2505,
12,
489,
283,
1765,
356,
283,
44,
7,
272,
789,
523,
776,
819,
19213,
63,
1418,
275,
330,
14,
1001,
12047,
32085,
2161,
2858,
418,
819,
1336,
275,
295,
14,
1733,
360,
45,
2919,
11378,
9577,
998,
2687,
6697,
27853,
330,
14,
2139,
459,
409,
13,
5306,
1105,
523,
340,
1336,
365,
488,
26,
272,
746,
2186,
360,
1944,
603,
2919,
11378,
9577,
998,
358,
523,
330,
63,
1730,
63,
344,
275,
1336,
14,
2634,
8,
16,
2788,
16,
61,
421,
199,
17577,
63,
3502,
63,
6942,
199,
318,
664,
63,
2048,
63,
19883,
8,
30033,
29,
403,
304,
523,
340,
1335,
9115,
365,
488,
26,
272,
372,
1052,
523,
862,
26,
272,
366,
275,
4145,
14,
362,
8,
489,
283,
2859,
921,
77,
442,
14,
2408,
554,
14,
442,
4993,
14,
957,
15,
86,
17,
15,
8370,
31,
3097,
29,
5279,
297,
489,
2323,
275,
791,
11626,
356,
283,
3655,
21462,
283,
435,
1335,
9115,
93,
272,
776,
272,
12639,
275,
1211,
8,
1130,
8,
489,
2400,
671,
26,
334,
267,
671,
459,
329,
985,
418,
435,
283,
283,
435,
671,
459,
1850,
6009,
985,
995,
267,
671,
459,
1818,
27106,
418,
489,
2318,
489,
2457,
8,
267,
2400,
671,
26,
671,
459,
2048,
3694,
418,
508,
283,
10401,
7,
436,
671,
459,
1818,
27106,
418,
690,
378,
12,
267,
366,
14,
1001,
12047,
6009,
418,
489,
776,
272,
5082,
272,
372,
12639,
523,
871,
2186,
465,
444,
26,
272,
372,
1052,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4145,
199,
646,
900,
199,
646,
295,
199,
504,
10933,
492,
10933,
199,
199,
1178,
63,
2139,
275,
1052,
199,
199,
318,
485,
3502,
63,
6942,
8,
2324,
304,
523,
347,
4975,
2031,
589,
304,
272,
347,
365,
63,
1397,
63,
21440,
8,
68,
12,
82,
304,
489,
372,
7114,
8,
267,
2400,
671,
12,
89,
26,
671,
503,
612,
12,
267,
2341,
8,
2734,
1022,
26,
1022,
440,
315,
366,
503,
440,
366,
59,
75,
467,
519,
9,
489,
776,
272,
340,
365,
63,
1397,
63,
21440,
8,
1178,
63,
2139,
12,
661,
5306,
297,
283,
1418,
8109,
489,
746,
2186,
360,
8880,
1642,
358,
272,
372,
4325,
2031,
589,
9,
523,
372,
4975,
421,
199,
318,
4676,
8,
2473,
12,
2505,
304,
523,
340,
3434,
365,
488,
503,
2505,
365,
488,
26,
272,
746,
2186,
360,
6119,
1686,
6235,
358,
819,
282,
275,
4145,
14,
362,
360,
2859,
921,
1544,
83,
14,
77,
442,
14,
957,
15,
2886,
14,
1430,
358,
523,
2351,
63,
344,
275,
282,
14,
7792,
14,
362,
360,
45,
2919,
11378,
9577,
998,
358,
523,
7475,
63,
344,
275,
282,
14,
7792,
14,
362,
360,
1092,
4586,
998,
358,
819,
330,
275,
4145,
14,
1932,
8,
272,
283,
2859,
921,
1544,
83,
14,
77,
442,
14,
957,
15,
2886,
1899,
17187,
14,
88,
1430,
297,
272,
10049,
275,
282,
14,
7792,
12,
272,
2323,
275,
469,
489,
283,
8422,
356,
283,
3578,
15,
1001,
297,
489,
283,
2714,
13,
466,
356,
283,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
27,
5960,
29,
6610,
13,
24,
297,
489,
283,
7810,
356,
283,
45,
2919,
11378,
9577,
998,
3126,
16,
12084,
820,
1877,
37,
998,
3126,
17,
5285,
908,
8,
1730,
63,
344,
12,
267,
7475,
63,
344,
9,
272,
1660,
272,
666,
275,
469,
489,
283,
2473,
356,
3434,
12,
489,
283,
2060,
356,
2505,
12,
489,
283,
1765,
356,
283,
44,
7,
272,
789,
523,
776,
819,
19213,
63,
1418,
275,
330,
14,
1001,
12047,
32085,
2161,
2858,
418,
819,
1336,
275,
295,
14,
1733,
360,
45,
2919,
11378,
9577,
998,
2687,
6697,
27853,
330,
14,
2139,
459,
409,
13,
5306,
1105,
523,
340,
1336,
365,
488,
26,
272,
746,
2186,
360,
1944,
603,
2919,
11378,
9577,
998,
358,
523,
330,
63,
1730,
63,
344,
275,
1336,
14,
2634,
8,
16,
2788,
16,
61,
421,
199,
17577,
63,
3502,
63,
6942,
199,
318,
664,
63,
2048,
63,
19883,
8,
30033,
29,
403,
304,
523,
340,
1335,
9115,
365,
488,
26,
272,
372,
1052,
523,
862,
26,
272,
366,
275,
4145,
14,
362,
8,
489,
283,
2859,
921,
77,
442,
14,
2408,
554,
14,
442,
4993,
14,
957,
15,
86,
17,
15,
8370,
31,
3097,
29,
5279,
297,
489,
2323,
275,
791,
11626,
356,
283,
3655,
21462,
283,
435,
1335,
9115,
93,
272,
776,
272,
12639,
275,
1211,
8,
1130,
8,
489,
2400,
671,
26,
334,
267,
671,
459,
329,
985,
418,
435,
283,
283,
435,
671,
459,
1850,
6009,
985,
995,
267,
671,
459,
1818,
27106,
418,
489,
2318,
489,
2457,
8,
267,
2400,
671,
26,
671,
459,
2048,
3694,
418,
508,
283,
10401,
7,
436,
671,
459,
1818,
27106,
418,
690,
378,
12,
267,
366,
14,
1001,
12047,
6009,
418,
489,
776,
272,
5082,
272,
372,
12639,
523,
871,
2186,
465,
444,
26,
272,
372,
1052,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
npuichigo/ttsflow
|
third_party/tensorflow/tensorflow/contrib/framework/python/ops/checkpoint_ops_test.py
|
23
|
34323
|
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# 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.
# ==============================================================================
"""Functional tests for the op to generate vocab remapping."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import numpy as np
from tensorflow.contrib import framework as contrib_framework
from tensorflow.contrib.framework.python.ops import checkpoint_ops
from tensorflow.contrib.framework.python.ops import gen_checkpoint_ops
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import errors
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import partitioned_variables
from tensorflow.python.ops import variable_scope
from tensorflow.python.ops import variables
from tensorflow.python.platform import flags
from tensorflow.python.platform import test
from tensorflow.python.training import saver
FLAGS = flags.FLAGS
_TESTDATA_PATH = 'contrib/framework/testdata'
class GenerateVocabRemappingTest(test.TestCase):
"""Tests for the generate_vocab_remapping() method."""
def setUp(self):
self.new_vocab_file = os.path.join(
test.test_src_dir_path(_TESTDATA_PATH), 'keyword_shifted.txt')
self.old_vocab_file = os.path.join(
test.test_src_dir_path(_TESTDATA_PATH), 'keyword.txt')
def test_generate_remapping_with_no_vocab_changes(self):
"""Tests where vocab does not change at all."""
remapping, num_present = gen_checkpoint_ops.generate_vocab_remapping(
new_vocab_file=self.old_vocab_file,
old_vocab_file=self.old_vocab_file,
num_new_vocab=3,
new_vocab_offset=0)
expected_remapping = range(0, 3)
expected_num_present = 3
with self.test_session():
self.assertAllEqual(expected_remapping, remapping.eval())
self.assertAllEqual(expected_num_present, num_present.eval())
def test_generate_remapping_with_shifted_vocab(self):
"""Tests where vocab is the same, but shifted / ordered differently."""
remapping, num_present = gen_checkpoint_ops.generate_vocab_remapping(
new_vocab_file=self.new_vocab_file,
old_vocab_file=self.old_vocab_file,
num_new_vocab=3,
new_vocab_offset=0)
expected_remapping = [2, 0, 1]
expected_num_present = 3
with self.test_session():
self.assertAllEqual(expected_remapping, remapping.eval())
self.assertAllEqual(expected_num_present, num_present.eval())
def test_generate_remapping_with_offset(self):
"""Tests offset and num_new_vocab logic."""
remapping, num_present = gen_checkpoint_ops.generate_vocab_remapping(
new_vocab_file=self.new_vocab_file,
old_vocab_file=self.old_vocab_file,
num_new_vocab=1,
new_vocab_offset=1)
expected_remapping = [0]
expected_num_present = 1
with self.test_session():
self.assertAllEqual(expected_remapping, remapping.eval())
self.assertAllEqual(expected_num_present, num_present.eval())
class LoadAndRemapMatrixTest(test.TestCase):
"""Tests for the load_and_remap_matrix() op."""
def setUp(self):
ops.reset_default_graph()
self.old_num_rows = 5
self.old_num_cols = 16
self.matrix_value = np.reshape(
range(0, self.old_num_rows * self.old_num_cols), (self.old_num_rows,
self.old_num_cols))
with variable_scope.variable_scope('some_scope'):
matrix = variable_scope.get_variable(
'matrix',
dtype=dtypes.float32,
initializer=constant_op.constant(
self.matrix_value, dtype=dtypes.float32))
self.old_tensor_name = 'some_scope/matrix'
save = saver.Saver([matrix])
with self.test_session() as sess:
variables.global_variables_initializer().run()
self.bundle_file = os.path.join(test.get_temp_dir(), 'bundle_checkpoint')
save.save(sess, self.bundle_file)
def test_load_and_remap_no_missing(self):
"""Tests the op's load and remap where there are no missing entries."""
# No column remapping, new weight matrix has second row, then first row.
row_remapping = [1, 0]
remapped_matrix = gen_checkpoint_ops.load_and_remap_matrix(
ckpt_path=[self.bundle_file],
old_tensor_name=self.old_tensor_name,
row_remapping=row_remapping,
col_remapping=[],
initializing_values=[],
num_rows=2,
num_cols=self.old_num_cols)
with self.test_session():
self.assertAllClose(self.matrix_value[row_remapping],
remapped_matrix.eval())
# No row remapping, new weight matrix has third col, then first col.
row_remapping = list(range(self.old_num_rows))
col_remapping = [2, 0]
remapped_matrix = gen_checkpoint_ops.load_and_remap_matrix(
ckpt_path=[self.bundle_file],
old_tensor_name=self.old_tensor_name,
row_remapping=row_remapping,
col_remapping=col_remapping,
initializing_values=[],
num_rows=len(row_remapping),
num_cols=len(col_remapping))
with self.test_session():
self.assertAllClose(self.matrix_value[row_remapping][:, col_remapping],
remapped_matrix.eval())
# Both row and column remappings.
row_remapping = [1, 0, 4]
col_remapping = [1, 15]
remapped_matrix = gen_checkpoint_ops.load_and_remap_matrix(
ckpt_path=[self.bundle_file],
old_tensor_name=self.old_tensor_name,
row_remapping=row_remapping,
col_remapping=col_remapping,
initializing_values=[],
num_rows=len(row_remapping),
num_cols=len(col_remapping))
with self.test_session():
self.assertAllClose(self.matrix_value[row_remapping][:, col_remapping],
remapped_matrix.eval())
def test_load_and_remap_with_init(self):
"""Tests the op's load and remap where there are missing entries."""
init_val = 42
remapped_matrix = gen_checkpoint_ops.load_and_remap_matrix(
ckpt_path=[self.bundle_file],
old_tensor_name=self.old_tensor_name,
row_remapping=[2, -1, 0],
col_remapping=[1, -1],
initializing_values=[init_val] * 4,
num_rows=3,
num_cols=2)
expected_remapped_matrix = np.reshape(
[33, init_val, init_val, init_val, 1, init_val], [3, 2])
with self.test_session():
self.assertAllClose(expected_remapped_matrix, remapped_matrix.eval())
def test_load_and_remap_all_missing_rows(self):
"""Tests when all the rows are missing and need to be initialized."""
num_rows = 7
initializing_values = [42] * num_rows * self.old_num_cols
remapped_matrix = gen_checkpoint_ops.load_and_remap_matrix(
ckpt_path=[self.bundle_file],
old_tensor_name=self.old_tensor_name,
row_remapping=[-1] * num_rows,
col_remapping=[],
initializing_values=initializing_values,
num_rows=num_rows,
num_cols=self.old_num_cols)
with self.test_session():
self.assertAllClose(
np.reshape(initializing_values, (num_rows, self.old_num_cols)),
remapped_matrix.eval())
def test_load_and_remap_all_missing_rows_and_cols(self):
"""Tests when all the rows & cols are missing and need to be initialized."""
num_rows = 7
num_cols = 4
initializing_values = [42] * num_rows * num_cols
remapped_matrix = gen_checkpoint_ops.load_and_remap_matrix(
ckpt_path=[self.bundle_file],
old_tensor_name=self.old_tensor_name,
row_remapping=[-1] * num_rows,
col_remapping=[-1] * num_cols,
initializing_values=initializing_values,
num_rows=num_rows,
num_cols=num_cols)
with self.test_session():
self.assertAllClose(
np.reshape(initializing_values, (num_rows, num_cols)),
remapped_matrix.eval())
def test_load_and_remap_invalid_remapping(self):
"""Tests that errors are raised when an ID maps to multiple new IDs.
(This should usually not happen when using public APIs).
"""
invalid_remapping = [1, 0, 0, 0, 1, 2]
# Invalid row remapping.
remapped_matrix = gen_checkpoint_ops.load_and_remap_matrix(
ckpt_path=[self.bundle_file],
old_tensor_name=self.old_tensor_name,
row_remapping=invalid_remapping,
col_remapping=[],
initializing_values=[],
num_rows=len(invalid_remapping),
num_cols=self.old_num_cols)
with self.test_session(), self.assertRaises(errors.UnimplementedError):
remapped_matrix.eval()
# Invalid column remapping.
remapped_matrix = gen_checkpoint_ops.load_and_remap_matrix(
ckpt_path=[self.bundle_file],
old_tensor_name=self.old_tensor_name,
row_remapping=list(range(self.old_num_rows)),
col_remapping=invalid_remapping,
initializing_values=[],
num_rows=self.old_num_rows,
num_cols=len(invalid_remapping))
with self.test_session(), self.assertRaises(errors.UnimplementedError):
remapped_matrix.eval()
def test_load_and_remap_incorrect_initializing_values(self):
"""Tests that errors are raised with incorrect number of init values."""
remapped_matrix = gen_checkpoint_ops.load_and_remap_matrix(
ckpt_path=[self.bundle_file],
old_tensor_name=self.old_tensor_name,
row_remapping=[2, -1, 0],
col_remapping=[1, -1],
# Too few initializing values - there should be 4. For some reason,
# initializing_values must contain no element (instead of 3 or fewer) to
# ensure that a seg fault would reliably occur if the check raising the
# InvalidArgumentError were not present.
initializing_values=[],
num_rows=3,
num_cols=2)
with self.test_session(), self.assertRaises(errors.InvalidArgumentError):
remapped_matrix.eval()
remapped_matrix = gen_checkpoint_ops.load_and_remap_matrix(
ckpt_path=[self.bundle_file],
old_tensor_name=self.old_tensor_name,
row_remapping=[2, -1, 0],
col_remapping=[1, -1],
# Too many initializing values - there should be 4.
initializing_values=[0] * 5,
num_rows=3,
num_cols=2)
with self.test_session(), self.assertRaises(errors.InvalidArgumentError):
remapped_matrix.eval()
class LoadAndRemapMatrixWithMaxRowsTest(test.TestCase):
"""Tests for the load_and_remap_matrix() op.
(Specifically focused on the max_rows_in_memory arg and its effects on
TensorBundle's BundleReader and TensorSlice logic).
"""
def _test_loading_variable_with_max_rows(self, np_value, partitioner,
max_rows_in_memory):
"""Helper function for various tests using max_rows_in_memory."""
ops.reset_default_graph()
old_tensor_name = 'matrix_to_load_and_remap'
matrix = variable_scope.get_variable(
old_tensor_name,
dtype=dtypes.float32,
initializer=constant_op.constant(np_value, dtype=dtypes.float32),
partitioner=partitioner)
with self.test_session() as sess:
ckpt_path = os.path.join(test.get_temp_dir(), 'temp_ckpt')
save = saver.Saver([matrix])
variables.global_variables_initializer().run()
save.save(sess, ckpt_path)
num_rows, num_cols = np_value.shape
# Tests loading the entire tensor (except reversed).
remapped_matrix = gen_checkpoint_ops.load_and_remap_matrix(
ckpt_path=ckpt_path,
old_tensor_name=old_tensor_name,
# Simply reverses the rows of the matrix.
row_remapping=list(range(num_rows - 1, -1, -1)),
col_remapping=[],
initializing_values=[],
num_rows=num_rows,
num_cols=num_cols,
max_rows_in_memory=max_rows_in_memory)
self.assertAllClose(np_value[::-1], remapped_matrix.eval())
# Tests loading the tensor (except for the first and last rows), with
# uninitialized values. Requires num_rows to be at least 3 since we're
# skipping the first and last rows.
self.assertGreater(num_rows, 2)
prefix_rows = 2
suffix_rows = 3
remapped_matrix = gen_checkpoint_ops.load_and_remap_matrix(
ckpt_path=ckpt_path,
old_tensor_name=old_tensor_name,
# Reverses the rows of the matrix, then prepends and appends
# uninitialized rows.
row_remapping=([-1] * prefix_rows + list(range(1, num_rows - 1)) +
[-1] * suffix_rows),
col_remapping=[],
initializing_values=[42] * (prefix_rows + suffix_rows) * num_cols,
num_rows=num_rows - 2 + prefix_rows + suffix_rows,
num_cols=num_cols,
max_rows_in_memory=max_rows_in_memory)
self.assertAllClose(
np.vstack([
np.tile(42, [prefix_rows, num_cols]), np_value[1:-1],
np.tile(42, [suffix_rows, num_cols])
]), remapped_matrix.eval())
# Tests when everything is taken from initializing_values.
new_rows = 7
initializing_values = [42] * new_rows * num_cols
remapped_matrix = gen_checkpoint_ops.load_and_remap_matrix(
ckpt_path=ckpt_path,
old_tensor_name=old_tensor_name,
# Nothing is loaded from the old tensor.
row_remapping=[-1] * new_rows,
col_remapping=[],
initializing_values=initializing_values,
num_rows=new_rows,
num_cols=num_cols,
max_rows_in_memory=max_rows_in_memory)
self.assertAllClose(
np.reshape(initializing_values, (new_rows, num_cols)),
remapped_matrix.eval())
def test_loading_rows_divisible_by_max_rows(self):
"""Tests loading normal var when rows are evenly divisible by max_rows."""
self._test_loading_variable_with_max_rows(
np_value=np.reshape(list(range(0, 36)), (9, 4)),
partitioner=None,
# 9 is evenly divisible by 3.
max_rows_in_memory=3)
def test_loading_rows_not_divisible_by_max_rows(self):
"""Tests loading normal var when rows aren't divisible by max_rows."""
self._test_loading_variable_with_max_rows(
np_value=np.reshape(list(range(0, 36)), (9, 4)),
partitioner=None,
# 9 is not evenly divisible by 4.
max_rows_in_memory=4)
def test_loading_rows_less_than_max_rows(self):
"""Tests loading normal var as a single slice.
(When the specified max_rows_in_memory is larger than the number of rows)
"""
self._test_loading_variable_with_max_rows(
np_value=np.reshape(list(range(0, 36)), (9, 4)),
partitioner=None,
# 10 > 9.
max_rows_in_memory=10)
def test_loading_no_max_rows(self):
"""Tests loading normal var as a single slice with no valid max_rows."""
self._test_loading_variable_with_max_rows(
np_value=np.reshape(list(range(0, 18)), (6, 3)),
partitioner=None,
max_rows_in_memory=-1)
def test_loading_partitions_equals_max_rows(self):
"""Tests loading partitioned var sliced on partition boundary."""
self._test_loading_variable_with_max_rows(
np_value=np.reshape(list(range(0, 36)), (9, 4)),
partitioner=partitioned_variables.fixed_size_partitioner(3),
# With a tensor of shape [9, 3] and 3 partitions, each partition has
# exactly 3 rows.
max_rows_in_memory=3)
def test_loading_partitions_greater_than_max_rows(self):
"""Tests loading partitioned var with more slices than partitions."""
self._test_loading_variable_with_max_rows(
np_value=np.reshape(list(range(0, 36)), (9, 4)),
partitioner=partitioned_variables.fixed_size_partitioner(3),
# Even though each partition has 3 rows, we'll only load the tensor one
# row at a time.
max_rows_in_memory=1)
def test_loading_partitions_less_than_max_rows(self):
"""Tests loading partitioned var as a single slice.
(When the specified max_rows_in_memory is larger than the number of rows)
"""
self._test_loading_variable_with_max_rows(
np_value=np.reshape(list(range(0, 36)), (9, 4)),
partitioner=partitioned_variables.fixed_size_partitioner(3),
max_rows_in_memory=10)
def test_loading_partitions_no_max_rows(self):
"""Tests loading partitioned var as single slice with no valid max_rows."""
self._test_loading_variable_with_max_rows(
np_value=np.reshape(list(range(0, 36)), (9, 4)),
partitioner=partitioned_variables.fixed_size_partitioner(3),
max_rows_in_memory=-1)
class LoadAndRemapWrappersTest(test.TestCase):
"""Tests for the functionality of the Python wrappers."""
def setUp(self):
self.bundle_file = os.path.join(
test.test_src_dir_path(_TESTDATA_PATH), 'bundle_checkpoint')
self.new_feature_vocab_file = os.path.join(
test.test_src_dir_path(_TESTDATA_PATH), 'bundle_checkpoint_vocab.txt')
self.old_feature_vocab_file = os.path.join(
test.test_src_dir_path(_TESTDATA_PATH),
'bundle_checkpoint_vocab_with_oov.txt')
self.new_class_vocab_file = os.path.join(
test.test_src_dir_path(_TESTDATA_PATH), 'keyword_new.txt')
self.old_class_vocab_file = os.path.join(
test.test_src_dir_path(_TESTDATA_PATH), 'keyword.txt')
self.init_val = 42
def _init_val_initializer(shape, dtype=None, partition_info=None):
del dtype, partition_info # Unused by this unit-testing initializer.
return array_ops.tile(
constant_op.constant([[self.init_val]], dtype=dtypes.float32), shape)
self.initializer = _init_val_initializer
def test_load_and_remap_matrix(self):
"""Tests the end-to-end loading / remapping of weights."""
# _load_and_remap_matrix() is the generalized wrapper that takes in row and
# column vocabulary files, calls the relevant remappings, and returns the
# weight matrix. Take this example to be linear multi-class by providing
# both row and column vocabularies.
remapped_matrix = checkpoint_ops._load_and_remap_matrix(
new_row_vocab_file=self.new_feature_vocab_file,
old_row_vocab_file=self.old_feature_vocab_file,
num_rows_to_load=4,
new_col_vocab_file=self.new_class_vocab_file,
old_col_vocab_file=self.old_class_vocab_file,
new_col_vocab_size=4,
old_tensor_name='some_scope/embeddings',
ckpt_path=[self.bundle_file],
new_row_vocab_offset=1,
initializer=self.initializer,
num_row_oov_buckets=1,
num_col_oov_buckets=1)
# [4 in vocab + 1 oov features, 4 in vocab + 1 oov classes]. The offset
# means we read
expected_remapped_matrix = np.concatenate(
[
np.reshape([18, 34, 50, self.init_val, self.init_val], [5, 1]),
np.reshape([16, 32, 48, self.init_val, self.init_val], [5, 1]),
np.reshape([self.init_val] * 5, [5, 1]),
np.reshape([17, 33, 49, self.init_val, self.init_val], [5, 1]),
np.reshape([self.init_val] * 5, [5, 1])
],
axis=1)
with self.test_session():
self.assertAllClose(expected_remapped_matrix, remapped_matrix.eval())
def test_load_and_remap_output_layer_weight_initializer_linear(self):
"""Tests for the output layer initializer in the linear multi-class case."""
loading_initializer = (contrib_framework.load_and_remap_matrix_initializer(
new_row_vocab_size=5,
new_col_vocab_file=self.new_class_vocab_file,
old_col_vocab_file=self.old_class_vocab_file,
new_col_vocab_size=4,
old_tensor_name='some_scope/embeddings',
ckpt_path=[self.bundle_file],
new_row_vocab_file=self.new_feature_vocab_file,
old_row_vocab_file=self.old_feature_vocab_file,
num_row_oov_buckets=1,
num_col_oov_buckets=1,
initializer=self.initializer))
expected_remapped_matrix = np.concatenate(
[
np.reshape([2, 18, 34, 50, self.init_val, self.init_val], [6, 1]),
np.reshape([0, 16, 32, 48, self.init_val, self.init_val], [6, 1]),
np.reshape([self.init_val] * 6, [6, 1]),
np.reshape([1, 17, 33, 49, self.init_val, self.init_val], [6, 1]),
np.reshape([self.init_val] * 6, [6, 1])
],
axis=1)
# The new weight matrix is of size
# [5 feature vocab + 1 feature OOV, 4 class vocab + 1 class OOV]. Use a
# partitioned variable to confirm that the offset logic works.
remapped_matrix = variable_scope.get_variable(
name='linear/obtained_weight_matrix',
shape=[6, 5],
initializer=loading_initializer,
partitioner=partitioned_variables.fixed_size_partitioner(2))
with self.test_session():
variables.global_variables_initializer().run()
self.assertAllClose(expected_remapped_matrix,
remapped_matrix.as_tensor().eval())
def test_load_and_remap_output_layer_weight_initializer_dnn_output(self):
"""Tests for the output layer initializer in the DNN output case."""
loading_initializer = (contrib_framework.load_and_remap_matrix_initializer(
new_row_vocab_size=5,
new_col_vocab_file=self.new_class_vocab_file,
old_col_vocab_file=self.old_class_vocab_file,
new_col_vocab_size=4,
old_tensor_name='some_scope/embeddings',
ckpt_path=[self.bundle_file],
num_col_oov_buckets=1,
initializer=self.initializer))
expected_remapped_matrix = np.concatenate(
[
np.reshape([2, 18, 34, 50, 66], [5, 1]),
np.reshape([0, 16, 32, 48, 64], [5, 1]),
np.reshape([self.init_val] * 5, [5, 1]),
np.reshape([1, 17, 33, 49, 65], [5, 1]),
np.reshape([self.init_val] * 5, [5, 1])
],
axis=1)
# The new weight matrix is of size
# [5-sized input layer, 4 class vocab + 1 class OOV].
remapped_matrix = variable_scope.get_variable(
name='dnn_output/obtained_weight_matrix',
shape=[5, 5],
initializer=loading_initializer,
partitioner=partitioned_variables.fixed_size_partitioner(2))
with self.test_session():
variables.global_variables_initializer().run()
self.assertAllClose(expected_remapped_matrix,
remapped_matrix.as_tensor().eval())
def test_initializer_with_oov_only_partition(self):
"""Tests for the output layer initializer where one partition is all OOV."""
loading_initializer = (contrib_framework.load_and_remap_matrix_initializer(
new_row_vocab_size=5,
new_col_vocab_file=self.new_class_vocab_file,
old_col_vocab_file=self.old_class_vocab_file,
new_col_vocab_size=4,
old_tensor_name='some_scope/embeddings',
ckpt_path=[self.bundle_file],
new_row_vocab_file=self.new_feature_vocab_file,
old_row_vocab_file=self.old_feature_vocab_file,
num_row_oov_buckets=5,
num_col_oov_buckets=1,
initializer=self.initializer))
expected_remapped_matrix = np.concatenate(
[
np.reshape([2, 18, 34, 50] + [self.init_val] * 6, [10, 1]),
np.reshape([0, 16, 32, 48] + [self.init_val] * 6, [10, 1]),
np.reshape([self.init_val] * 10, [10, 1]),
np.reshape([1, 17, 33, 49] + [self.init_val] * 6, [10, 1]),
np.reshape([self.init_val] * 10, [10, 1]),
],
axis=1)
# The new weight matrix is of size
# [5 feature vocab + 5 feature OOV, 4 class vocab + 1 class OOV]. The
# second partition has only OOV.
remapped_matrix = variable_scope.get_variable(
name='linear_all_oov/obtained_weight_matrix',
shape=[10, 5],
initializer=loading_initializer,
partitioner=partitioned_variables.fixed_size_partitioner(2))
with self.test_session():
variables.global_variables_initializer().run()
self.assertAllClose(expected_remapped_matrix,
remapped_matrix.as_tensor().eval())
def test_load_and_remap_linear_multiclass_initializer_default_init(self):
"""Tests where the zeros_initializer default is used for linear."""
loading_initializer = (contrib_framework.load_and_remap_matrix_initializer(
new_row_vocab_size=5,
new_col_vocab_file=self.new_class_vocab_file,
old_col_vocab_file=self.old_class_vocab_file,
new_col_vocab_size=4,
old_tensor_name='some_scope/embeddings',
ckpt_path=[self.bundle_file],
new_row_vocab_file=self.new_feature_vocab_file,
old_row_vocab_file=self.old_feature_vocab_file,
num_row_oov_buckets=1,
num_col_oov_buckets=1))
expected_remapped_matrix = np.concatenate(
[
np.reshape([2, 18, 34, 50, 0, 0], [6, 1]),
np.reshape([0, 16, 32, 48, 0, 0], [6, 1]),
np.reshape([0] * 6, [6, 1]),
np.reshape([1, 17, 33, 49, 0, 0], [6, 1]),
np.reshape([0] * 6, [6, 1])
],
axis=1)
remapped_matrix = variable_scope.get_variable(
name='linear_init_fallback/obtained_weight_matrix',
shape=[6, 5],
initializer=loading_initializer,
partitioner=partitioned_variables.fixed_size_partitioner(2))
with self.test_session():
variables.global_variables_initializer().run()
self.assertAllClose(expected_remapped_matrix,
remapped_matrix.as_tensor().eval())
def test_load_embedding_initializer(self):
"""Tests for the load_embedding_initializer wrapper."""
embedding_loading_initializer = (
contrib_framework.load_embedding_initializer(
new_vocab_file=self.new_feature_vocab_file,
old_vocab_file=self.old_feature_vocab_file,
new_vocab_size=5,
embedding_dim=16,
embedding_tensor_name='some_scope/embeddings',
ckpt_path=[self.bundle_file],
num_oov_buckets=1,
initializer=self.initializer))
expected_remapped_embeddings = np.concatenate(
[
np.reshape(range(64), [4, 16]),
np.reshape([self.init_val] * 32, [2, 16]),
],
axis=0)
# The new weight matrix is of size
# [5 feature vocab + 1 feature OOV, 16 (embedding dimension)], where the
# last vocab row (2nd last row) is newly initialized (wasn't found in
# previous vocab) and the actual last row is OOV and also newly initialized.
# Use a partitioned variable to confirm that the offset logic works.
remapped_embeddings = variable_scope.get_variable(
name='embedding/obtained_embedding_matrix',
shape=[6, 16],
initializer=embedding_loading_initializer,
partitioner=partitioned_variables.fixed_size_partitioner(2))
with self.test_session():
variables.global_variables_initializer().run()
self.assertAllClose(expected_remapped_embeddings,
remapped_embeddings.as_tensor().eval())
class LoadMulticlassBiasTest(test.TestCase):
"""Tests for the load_linear_multiclass_bias_initializer functionality."""
def setUp(self):
ops.reset_default_graph()
dim = 1
num = 3
with ops.name_scope('some_scope'):
# Basically from 0 to dim*num-1.
flat_data = math_ops.linspace(0.0, dim * num - 1, dim * num)
bias = variables.Variable(
array_ops.reshape(flat_data, (num, dim)), name='bias')
save = saver.Saver([bias])
with self.test_session() as sess:
variables.global_variables_initializer().run()
self.bundle_file = os.path.join(test.get_temp_dir(), 'bias_checkpoint')
save.save(sess, self.bundle_file)
self.new_class_vocab_file = os.path.join(
test.test_src_dir_path(_TESTDATA_PATH), 'keyword_new.txt')
self.old_class_vocab_file = os.path.join(
test.test_src_dir_path(_TESTDATA_PATH), 'keyword.txt')
self.init_val = 42
def _init_val_initializer(shape, dtype=None, partition_info=None):
del dtype, partition_info # Unused by this unit-testing initializer.
return array_ops.tile(
constant_op.constant([[self.init_val]], dtype=dtypes.float32), shape)
self.initializer = _init_val_initializer
def test_load_linear_multiclass_bias_initializer(self):
"""Tests for the bias initializer wrapper."""
bias_loading_initializer = (
contrib_framework.load_linear_multiclass_bias_initializer(
new_class_vocab_file=self.new_class_vocab_file,
old_class_vocab_file=self.old_class_vocab_file,
new_class_vocab_size=4,
bias_tensor_name='some_scope/bias',
ckpt_path=[self.bundle_file],
num_class_oov_buckets=1,
initializer=self.initializer))
expected_remapped_bias_vector = np.reshape(
[2, 0, self.init_val, 1, self.init_val], [5, 1])
# The new bias vector is of size [4 class vocab + 1 class OOV, 1].
remapped_bias_vector = variable_scope.get_variable(
name='bias/obtained_bias_vector',
shape=[5, 1],
initializer=bias_loading_initializer,
partitioner=partitioned_variables.fixed_size_partitioner(3))
with self.test_session():
variables.global_variables_initializer().run()
self.assertAllClose(expected_remapped_bias_vector,
remapped_bias_vector.as_tensor().eval())
class LoadVariableSlotTest(test.TestCase):
"""Tests for the load_variable_slot_initializer functionality."""
def setUp(self):
ops.reset_default_graph()
dim = 1
num = 3
with ops.name_scope('some_scope'):
# Basically from 0 to dim*num-1.
flat_data = math_ops.linspace(0.0, dim * num - 1, dim * num)
accum = variables.Variable(
array_ops.reshape(flat_data, (num, dim)), name='accum')
save = saver.Saver([accum])
with self.test_session() as sess:
variables.global_variables_initializer().run()
self.bundle_file = os.path.join(test.get_temp_dir(), 'accum_checkpoint')
save.save(sess, self.bundle_file)
self.new_class_vocab_file = os.path.join(
test.test_src_dir_path(_TESTDATA_PATH), 'keyword_new.txt')
self.old_class_vocab_file = os.path.join(
test.test_src_dir_path(_TESTDATA_PATH), 'keyword.txt')
self.init_val = 42
def _init_val_initializer(shape, dtype=None, partition_info=None):
del dtype, partition_info # Unused by this unit-testing initializer.
return array_ops.tile(
constant_op.constant([[self.init_val]], dtype=dtypes.float32), shape)
self.initializer = _init_val_initializer
def test_load_variable_slot_initializer(self):
"""Tests for the slot initializer wrapper."""
# We have an initializer for each of two partitioned variables, which will
# be [3, 1] and [2, 1]. The partitioning information is passed here in
# initializer construction, as opposed to through a variable scope during
# variable creation.
variable_slot_initializer_part_0 = (
contrib_framework.load_variable_slot_initializer(
new_row_vocab_file=self.new_class_vocab_file,
old_row_vocab_file=self.old_class_vocab_file,
new_row_vocab_size=4,
new_col_vocab_size=1,
primary_partition_info=variable_scope._PartitionInfo(
full_shape=[5, 1], var_offset=[0, 0]),
old_tensor_name='some_scope/accum',
ckpt_path=[self.bundle_file],
num_row_oov_buckets=1,
initializer=self.initializer))
variable_slot_initializer_part_1 = (
contrib_framework.load_variable_slot_initializer(
new_row_vocab_file=self.new_class_vocab_file,
old_row_vocab_file=self.old_class_vocab_file,
new_row_vocab_size=4,
new_col_vocab_size=1,
primary_partition_info=variable_scope._PartitionInfo(
full_shape=[5, 1], var_offset=[3, 0]),
old_tensor_name='some_scope/accum',
ckpt_path=[self.bundle_file],
num_row_oov_buckets=1,
initializer=self.initializer))
expected_remapped_accum_vector_part_0 = np.reshape([2, 0, self.init_val],
[3, 1])
expected_remapped_accum_vector_part_1 = np.reshape([1, self.init_val],
[2, 1])
# Since there is no variable scope here, partition_info will be None, so
# if variable_slot_initializer_part_0 and variable_slot_initializer_part_1
# were instead instances of load_and_remap_matrix_initializer, the part_0
# obtained vector would still be [2, 0, self.init_val], but the part_1
# obtained vector would be [2, 0], since the partition_info would default to
# assuming a single partition.
remapped_accum_vector_part_0 = variable_scope.get_variable(
name='accum/obtained_accum_vector_part_0',
shape=[3, 1],
initializer=variable_slot_initializer_part_0)
remapped_accum_vector_part_1 = variable_scope.get_variable(
name='accum/obtained_accum_vector_part_1',
shape=[2, 1],
initializer=variable_slot_initializer_part_1)
with self.test_session():
variables.global_variables_initializer().run()
self.assertAllClose(expected_remapped_accum_vector_part_0,
remapped_accum_vector_part_0.eval())
self.assertAllClose(expected_remapped_accum_vector_part_1,
remapped_accum_vector_part_1.eval())
if __name__ == '__main__':
test.main()
|
apache-2.0
|
[
3,
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
3481,
279,
2295,
367,
314,
1687,
370,
3550,
11181,
295,
4745,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
747,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
2828,
492,
10059,
465,
5914,
63,
4857,
199,
504,
3228,
14,
2828,
14,
4857,
14,
1548,
14,
1483,
492,
9997,
63,
1483,
199,
504,
3228,
14,
2828,
14,
4857,
14,
1548,
14,
1483,
492,
3805,
63,
10109,
63,
1483,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
27105,
63,
3669,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1750,
63,
2645,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
3285,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
7588,
492,
17559,
199,
199,
4831,
275,
3285,
14,
4831,
199,
63,
2864,
3998,
63,
3243,
275,
283,
2828,
15,
4857,
15,
18481,
7,
421,
199,
533,
7958,
54,
6607,
497,
4745,
774,
8,
396,
14,
1746,
304,
523,
408,
2925,
367,
314,
3550,
63,
9953,
63,
264,
4745,
342,
1083,
1041,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
1222,
63,
9953,
63,
493,
275,
747,
14,
515,
14,
904,
8,
267,
511,
14,
396,
63,
2164,
63,
694,
63,
515,
1547,
2864,
3998,
63,
3243,
395,
283,
6691,
63,
26063,
471,
14,
2424,
358,
272,
291,
14,
1753,
63,
9953,
63,
493,
275,
747,
14,
515,
14,
904,
8,
267,
511,
14,
396,
63,
2164,
63,
694,
63,
515,
1547,
2864,
3998,
63,
3243,
395,
283,
6691,
14,
2424,
358,
819,
347,
511,
63,
4208,
63,
264,
4745,
63,
1045,
63,
889,
63,
9953,
63,
6627,
8,
277,
304,
272,
408,
2925,
2382,
11181,
1630,
440,
1570,
737,
1006,
1041,
272,
295,
4745,
12,
1967,
63,
1881,
275,
3805,
63,
10109,
63,
1483,
14,
4208,
63,
9953,
63,
264,
4745,
8,
267,
892,
63,
9953,
63,
493,
29,
277,
14,
1753,
63,
9953,
63,
493,
12,
267,
2269,
63,
9953,
63,
493,
29,
277,
14,
1753,
63,
9953,
63,
493,
12,
267,
1967,
63,
1222,
63,
9953,
29,
19,
12,
267,
892,
63,
9953,
63,
2743,
29,
16,
9,
272,
1420,
63,
264,
4745,
275,
1425,
8,
16,
12,
650,
9,
272,
1420,
63,
1507,
63,
1881,
275,
650,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
291,
14,
7069,
8,
2062,
63,
264,
4745,
12,
295,
4745,
14,
2579,
1012,
489,
291,
14,
7069,
8,
2062,
63,
1507,
63,
1881,
12,
1967,
63,
1881,
14,
2579,
1012,
819,
347,
511,
63,
4208,
63,
264,
4745,
63,
1045,
63,
26063,
471,
63,
9953,
8,
277,
304,
272,
408,
2925,
2382,
11181,
365,
314,
2011,
12,
1325,
31915,
1182,
7741,
23142,
1041,
272,
295,
4745,
12,
1967,
63,
1881,
275,
3805,
63,
10109,
63,
1483,
14,
4208,
63,
9953,
63,
264,
4745,
8,
267,
892,
63,
9953,
63,
493,
29,
277,
14,
1222,
63,
9953,
63,
493,
12,
267,
2269,
63,
9953,
63,
493,
29,
277,
14,
1753,
63,
9953,
63,
493,
12,
267,
1967,
63,
1222,
63,
9953,
29,
19,
12,
267,
892,
63,
9953,
63,
2743,
29,
16,
9,
272,
1420,
63,
264,
4745,
275,
359,
18,
12,
378,
12,
413,
61,
272,
1420,
63,
1507,
63,
1881,
275,
650,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
291,
14,
7069,
8,
2062,
63,
264,
4745,
12,
295,
4745,
14,
2579,
1012,
489,
291,
14,
7069,
8,
2062,
63,
1507,
63,
1881,
12,
1967,
63,
1881,
14,
2579,
1012,
819,
347,
511,
63,
4208,
63,
264,
4745,
63,
1045,
63,
2743,
8,
277,
304,
272,
408,
2925,
3268,
436,
1967,
63,
1222,
63,
9953,
9661,
1041,
272,
295,
4745,
12,
1967,
63,
1881,
275,
3805,
63,
10109,
63,
1483,
14,
4208,
63,
9953,
63,
264,
4745,
8,
267,
892,
63,
9953,
63,
493,
29,
277,
14,
1222,
63,
9953,
63,
493,
12,
267,
2269,
63,
9953,
63,
493,
29,
277,
14,
1753,
63,
9953,
63,
493,
12,
267,
1967,
63,
1222,
63,
9953,
29,
17,
12,
267,
892,
63,
9953,
63,
2743,
29,
17,
9,
272,
1420,
63,
264,
4745,
275,
359,
16,
61,
272,
1420,
63,
1507,
63,
1881,
275,
413,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
291,
14,
7069,
8,
2062,
63,
264,
4745,
12,
295,
4745,
14,
2579,
1012,
489,
291,
14,
7069,
8,
2062,
63,
1507,
63,
1881,
12,
1967,
63,
1881,
14,
2579,
1012,
421,
199,
533,
7190,
3325,
497,
1130,
6443,
774,
8,
396,
14,
1746,
304,
523,
408,
2925,
367,
314,
2248,
63,
460,
63,
25340,
63,
3642,
342,
1687,
1041,
819,
347,
3613,
8,
277,
304,
272,
4156,
14,
3958,
63,
885,
63,
2180,
342,
272,
291,
14,
1753,
63,
1507,
63,
3838,
275,
959,
272,
291,
14,
1753,
63,
1507,
63,
4574,
275,
3193
] |
[
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
3481,
279,
2295,
367,
314,
1687,
370,
3550,
11181,
295,
4745,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
747,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
2828,
492,
10059,
465,
5914,
63,
4857,
199,
504,
3228,
14,
2828,
14,
4857,
14,
1548,
14,
1483,
492,
9997,
63,
1483,
199,
504,
3228,
14,
2828,
14,
4857,
14,
1548,
14,
1483,
492,
3805,
63,
10109,
63,
1483,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
27105,
63,
3669,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1750,
63,
2645,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
3285,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
7588,
492,
17559,
199,
199,
4831,
275,
3285,
14,
4831,
199,
63,
2864,
3998,
63,
3243,
275,
283,
2828,
15,
4857,
15,
18481,
7,
421,
199,
533,
7958,
54,
6607,
497,
4745,
774,
8,
396,
14,
1746,
304,
523,
408,
2925,
367,
314,
3550,
63,
9953,
63,
264,
4745,
342,
1083,
1041,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
1222,
63,
9953,
63,
493,
275,
747,
14,
515,
14,
904,
8,
267,
511,
14,
396,
63,
2164,
63,
694,
63,
515,
1547,
2864,
3998,
63,
3243,
395,
283,
6691,
63,
26063,
471,
14,
2424,
358,
272,
291,
14,
1753,
63,
9953,
63,
493,
275,
747,
14,
515,
14,
904,
8,
267,
511,
14,
396,
63,
2164,
63,
694,
63,
515,
1547,
2864,
3998,
63,
3243,
395,
283,
6691,
14,
2424,
358,
819,
347,
511,
63,
4208,
63,
264,
4745,
63,
1045,
63,
889,
63,
9953,
63,
6627,
8,
277,
304,
272,
408,
2925,
2382,
11181,
1630,
440,
1570,
737,
1006,
1041,
272,
295,
4745,
12,
1967,
63,
1881,
275,
3805,
63,
10109,
63,
1483,
14,
4208,
63,
9953,
63,
264,
4745,
8,
267,
892,
63,
9953,
63,
493,
29,
277,
14,
1753,
63,
9953,
63,
493,
12,
267,
2269,
63,
9953,
63,
493,
29,
277,
14,
1753,
63,
9953,
63,
493,
12,
267,
1967,
63,
1222,
63,
9953,
29,
19,
12,
267,
892,
63,
9953,
63,
2743,
29,
16,
9,
272,
1420,
63,
264,
4745,
275,
1425,
8,
16,
12,
650,
9,
272,
1420,
63,
1507,
63,
1881,
275,
650,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
291,
14,
7069,
8,
2062,
63,
264,
4745,
12,
295,
4745,
14,
2579,
1012,
489,
291,
14,
7069,
8,
2062,
63,
1507,
63,
1881,
12,
1967,
63,
1881,
14,
2579,
1012,
819,
347,
511,
63,
4208,
63,
264,
4745,
63,
1045,
63,
26063,
471,
63,
9953,
8,
277,
304,
272,
408,
2925,
2382,
11181,
365,
314,
2011,
12,
1325,
31915,
1182,
7741,
23142,
1041,
272,
295,
4745,
12,
1967,
63,
1881,
275,
3805,
63,
10109,
63,
1483,
14,
4208,
63,
9953,
63,
264,
4745,
8,
267,
892,
63,
9953,
63,
493,
29,
277,
14,
1222,
63,
9953,
63,
493,
12,
267,
2269,
63,
9953,
63,
493,
29,
277,
14,
1753,
63,
9953,
63,
493,
12,
267,
1967,
63,
1222,
63,
9953,
29,
19,
12,
267,
892,
63,
9953,
63,
2743,
29,
16,
9,
272,
1420,
63,
264,
4745,
275,
359,
18,
12,
378,
12,
413,
61,
272,
1420,
63,
1507,
63,
1881,
275,
650,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
291,
14,
7069,
8,
2062,
63,
264,
4745,
12,
295,
4745,
14,
2579,
1012,
489,
291,
14,
7069,
8,
2062,
63,
1507,
63,
1881,
12,
1967,
63,
1881,
14,
2579,
1012,
819,
347,
511,
63,
4208,
63,
264,
4745,
63,
1045,
63,
2743,
8,
277,
304,
272,
408,
2925,
3268,
436,
1967,
63,
1222,
63,
9953,
9661,
1041,
272,
295,
4745,
12,
1967,
63,
1881,
275,
3805,
63,
10109,
63,
1483,
14,
4208,
63,
9953,
63,
264,
4745,
8,
267,
892,
63,
9953,
63,
493,
29,
277,
14,
1222,
63,
9953,
63,
493,
12,
267,
2269,
63,
9953,
63,
493,
29,
277,
14,
1753,
63,
9953,
63,
493,
12,
267,
1967,
63,
1222,
63,
9953,
29,
17,
12,
267,
892,
63,
9953,
63,
2743,
29,
17,
9,
272,
1420,
63,
264,
4745,
275,
359,
16,
61,
272,
1420,
63,
1507,
63,
1881,
275,
413,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
291,
14,
7069,
8,
2062,
63,
264,
4745,
12,
295,
4745,
14,
2579,
1012,
489,
291,
14,
7069,
8,
2062,
63,
1507,
63,
1881,
12,
1967,
63,
1881,
14,
2579,
1012,
421,
199,
533,
7190,
3325,
497,
1130,
6443,
774,
8,
396,
14,
1746,
304,
523,
408,
2925,
367,
314,
2248,
63,
460,
63,
25340,
63,
3642,
342,
1687,
1041,
819,
347,
3613,
8,
277,
304,
272,
4156,
14,
3958,
63,
885,
63,
2180,
342,
272,
291,
14,
1753,
63,
1507,
63,
3838,
275,
959,
272,
291,
14,
1753,
63,
1507,
63,
4574,
275,
3193,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ashray/VTK-EVM
|
ThirdParty/Twisted/twisted/internet/test/test_pollingfile.py
|
41
|
1276
|
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Tests for L{twisted.internet._pollingfile}.
"""
from twisted.python.runtime import platform
from twisted.trial.unittest import TestCase
if platform.isWindows():
from twisted.internet import _pollingfile
else:
_pollingfile = None
class TestPollableWritePipe(TestCase):
"""
Tests for L{_pollingfile._PollableWritePipe}.
"""
def test_writeUnicode(self):
"""
L{_pollingfile._PollableWritePipe.write} raises a C{TypeError} if an
attempt is made to append unicode data to the output buffer.
"""
p = _pollingfile._PollableWritePipe(1, lambda: None)
self.assertRaises(TypeError, p.write, u"test")
def test_writeSequenceUnicode(self):
"""
L{_pollingfile._PollableWritePipe.writeSequence} raises a C{TypeError}
if unicode data is part of the data sequence to be appended to the
output buffer.
"""
p = _pollingfile._PollableWritePipe(1, lambda: None)
self.assertRaises(TypeError, p.writeSequence, [u"test"])
self.assertRaises(TypeError, p.writeSequence, (u"test", ))
if _pollingfile is None:
TestPollableWritePipe.skip = "Test will run only on Windows."
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
2925,
367,
491,
91,
12145,
14,
4901,
423,
17154,
493,
5565,
199,
624,
199,
199,
504,
7390,
14,
1548,
14,
7726,
492,
4298,
199,
504,
7390,
14,
14443,
14,
2796,
492,
7640,
199,
199,
692,
4298,
14,
374,
8647,
837,
272,
687,
7390,
14,
4901,
492,
485,
17154,
493,
199,
2836,
26,
272,
485,
17154,
493,
275,
488,
4388,
199,
533,
1379,
24022,
461,
3534,
11867,
8,
1746,
304,
272,
408,
272,
6496,
367,
491,
26975,
17154,
493,
423,
24022,
461,
3534,
11867,
5565,
272,
408,
339,
347,
511,
63,
952,
7087,
8,
277,
304,
267,
408,
267,
491,
26975,
17154,
493,
423,
24022,
461,
3534,
11867,
14,
952,
93,
6534,
282,
445,
91,
4333,
93,
340,
376,
267,
7427,
365,
6326,
370,
5666,
2649,
666,
370,
314,
1072,
3335,
14,
267,
408,
267,
299,
275,
485,
17154,
493,
423,
24022,
461,
3534,
11867,
8,
17,
12,
2400,
26,
488,
9,
267,
291,
14,
1855,
8,
4333,
12,
299,
14,
952,
12,
399,
2,
396,
531,
2378,
347,
511,
63,
952,
5826,
7087,
8,
277,
304,
267,
408,
267,
491,
26975,
17154,
493,
423,
24022,
461,
3534,
11867,
14,
952,
5826,
93,
6534,
282,
445,
91,
4333,
93,
267,
340,
2649,
666,
365,
1777,
402,
314,
666,
3414,
370,
506,
11544,
370,
314,
267,
1072,
3335,
14,
267,
408,
267,
299,
275,
485,
17154,
493,
423,
24022,
461,
3534,
11867,
8,
17,
12,
2400,
26,
488,
9,
267,
291,
14,
1855,
8,
4333,
12,
299,
14,
952,
5826,
12,
359,
85,
2,
396,
3135,
267,
291,
14,
1855,
8,
4333,
12,
299,
14,
952,
5826,
12,
334,
85,
2,
396,
401,
5082,
6905,
199,
692,
485,
17154,
493,
365,
488,
26,
272,
1379,
24022,
461,
3534,
11867,
14,
2759,
275,
298,
774,
911,
1255,
1454,
641,
5417,
2122,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
2925,
367,
491,
91,
12145,
14,
4901,
423,
17154,
493,
5565,
199,
624,
199,
199,
504,
7390,
14,
1548,
14,
7726,
492,
4298,
199,
504,
7390,
14,
14443,
14,
2796,
492,
7640,
199,
199,
692,
4298,
14,
374,
8647,
837,
272,
687,
7390,
14,
4901,
492,
485,
17154,
493,
199,
2836,
26,
272,
485,
17154,
493,
275,
488,
4388,
199,
533,
1379,
24022,
461,
3534,
11867,
8,
1746,
304,
272,
408,
272,
6496,
367,
491,
26975,
17154,
493,
423,
24022,
461,
3534,
11867,
5565,
272,
408,
339,
347,
511,
63,
952,
7087,
8,
277,
304,
267,
408,
267,
491,
26975,
17154,
493,
423,
24022,
461,
3534,
11867,
14,
952,
93,
6534,
282,
445,
91,
4333,
93,
340,
376,
267,
7427,
365,
6326,
370,
5666,
2649,
666,
370,
314,
1072,
3335,
14,
267,
408,
267,
299,
275,
485,
17154,
493,
423,
24022,
461,
3534,
11867,
8,
17,
12,
2400,
26,
488,
9,
267,
291,
14,
1855,
8,
4333,
12,
299,
14,
952,
12,
399,
2,
396,
531,
2378,
347,
511,
63,
952,
5826,
7087,
8,
277,
304,
267,
408,
267,
491,
26975,
17154,
493,
423,
24022,
461,
3534,
11867,
14,
952,
5826,
93,
6534,
282,
445,
91,
4333,
93,
267,
340,
2649,
666,
365,
1777,
402,
314,
666,
3414,
370,
506,
11544,
370,
314,
267,
1072,
3335,
14,
267,
408,
267,
299,
275,
485,
17154,
493,
423,
24022,
461,
3534,
11867,
8,
17,
12,
2400,
26,
488,
9,
267,
291,
14,
1855,
8,
4333,
12,
299,
14,
952,
5826,
12,
359,
85,
2,
396,
3135,
267,
291,
14,
1855,
8,
4333,
12,
299,
14,
952,
5826,
12,
334,
85,
2,
396,
401,
5082,
6905,
199,
692,
485,
17154,
493,
365,
488,
26,
272,
1379,
24022,
461,
3534,
11867,
14,
2759,
275,
298,
774,
911,
1255,
1454,
641,
5417,
2122,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
davidtrem/ThunderStorm
|
thunderstorm/lightning/utils.py
|
1
|
5027
|
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2013 Trémouilles David
#This file is part of Thunderstorm.
#
#ThunderStrom is free software: you can redistribute it and/or modify
#it under the terms of the GNU Lesser General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#ThunderStorm is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public License
#along with ThunderStorm. If not, see <http://www.gnu.org/licenses/>.
"""
Various utility functions
"""
import matplotlib
from weakref import WeakValueDictionary
from weakref import WeakKeyDictionary
import warnings
class UniversalCursors(object):
def __init__(self):
self.all_cursor_orient = WeakKeyDictionary()
self.all_canvas = WeakValueDictionary()
self.all_axes = WeakValueDictionary()
self.backgrounds = {}
self.visible = True
self.needclear = False
def _onmove(self, event):
for canvas in self.all_canvas.values():
if not canvas.widgetlock.available(self):
return
if event.inaxes is None or not self.visible:
if self.needclear:
self._update(event)
for canvas in self.all_canvas.values():
canvas.draw()
self.needclear = False
return
self._update(event)
def _update(self, event):
# 1/ Reset background
for canvas in self.all_canvas.values():
canvas.restore_region(self.backgrounds[id(canvas)])
# 2/ update cursors
for cursors in self.all_cursor_orient.keys():
orient = self.all_cursor_orient[cursors]
if (event.inaxes in [line.get_axes() for line in cursors]
and self.visible):
visible = True
self.needclear = True
else:
visible = False
for line in cursors:
if orient == 'vertical':
line.set_xdata((event.xdata, event.xdata))
if orient == 'horizontal':
line.set_ydata((event.ydata, event.ydata))
line.set_visible(visible)
ax = line.get_axes()
ax.draw_artist(line)
# 3/ update canvas
for canvas in self.all_canvas.values():
canvas.blit(canvas.figure.bbox)
def _clear(self, event):
"""clear the cursor"""
self.backgrounds = {}
for canvas in self.all_canvas.values():
self.backgrounds[id(canvas)] = (
canvas.copy_from_bbox(canvas.figure.bbox))
for cursor in self.all_cursor_orient.keys():
for line in cursor:
line.set_visible(False)
def add_cursor(self, axes=(), orient='vertical', **lineprops):
class CursorList(list):
def __hash__(self):
return hash(tuple(self))
cursors = CursorList() # Required to keep weakref
for ax in axes:
self.all_axes[id(ax)] = ax
ax_canvas = ax.get_figure().canvas
if ax_canvas not in self.all_canvas.values():
#if not ax_canvas.supports_blit:
# warnings.warn("Must use canvas that support blit")
# return
self.all_canvas[id(ax_canvas)] = ax_canvas
ax_canvas.mpl_connect('motion_notify_event', self._onmove)
ax_canvas.mpl_connect('draw_event', self._clear)
if orient == 'vertical':
line = ax.axvline(ax.get_xbound()[0], visible=False,
animated=True, **lineprops)
if orient == 'horizontal':
line = ax.axhline(ax.get_ybound()[0], visible=False,
animated=True, **lineprops)
cursors.append(line)
self.all_cursor_orient[cursors] = orient
return cursors
def autoscale_visible_lines(axs):
"""
Function to autoscale only on visible lines.
"""
mplt_ver = [int(elem) for elem in matplotlib.__version__.split('.')[0:2]]
ignore = True
for line in (axs.lines):
if not line.get_visible():
continue # jump to next line if this one is not visible
if mplt_ver[0] == 0 and mplt_ver[1] < 98:
axs.dataLim.update_numerix(line.get_xdata(),
line.get_ydata(),
ignore)
else:
axs.dataLim.update_from_data_xy(line.get_xydata(),
ignore)
ignore = False
axs.autoscale_view()
return None
def neg_bool_list(a_list):
return [not elem for elem in a_list]
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
35,
9,
7129,
13,
6965,
28814,
5741,
573,
85,
382,
2978,
20232,
199,
199,
3,
2765,
570,
365,
1777,
402,
3868,
7138,
26949,
14,
199,
3,
199,
3,
2719,
7138,
933,
417,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
390,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
199,
3,
1589,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2719,
7138,
933,
1025,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
17732,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
21632,
543,
3868,
7138,
933,
1025,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
199,
9958,
1785,
11420,
3423,
199,
624,
199,
199,
646,
8027,
199,
504,
13852,
492,
28224,
1110,
11728,
199,
504,
13852,
492,
28224,
1197,
11728,
199,
199,
646,
3598,
421,
199,
533,
29347,
3864,
83,
1384,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
452,
63,
3937,
63,
19676,
275,
28224,
1197,
11728,
342,
267,
291,
14,
452,
63,
7682,
275,
28224,
1110,
11728,
342,
267,
291,
14,
452,
63,
6402,
275,
28224,
1110,
11728,
342,
267,
291,
14,
7451,
83,
275,
1052,
267,
291,
14,
6604,
275,
715,
267,
291,
14,
9321,
3584,
275,
756,
339,
347,
485,
265,
1185,
8,
277,
12,
1566,
304,
267,
367,
10218,
315,
291,
14,
452,
63,
7682,
14,
1459,
837,
288,
340,
440,
10218,
14,
3440,
831,
14,
4561,
8,
277,
304,
355,
372,
267,
340,
1566,
14,
262,
6402,
365,
488,
503,
440,
291,
14,
6604,
26,
288,
340,
291,
14,
9321,
3584,
26,
355,
291,
423,
873,
8,
1430,
9,
355,
367,
10218,
315,
291,
14,
452,
63,
7682,
14,
1459,
837,
490,
10218,
14,
5485,
342,
355,
291,
14,
9321,
3584,
275,
756,
288,
372,
267,
291,
423,
873,
8,
1430,
9,
339,
347,
485,
873,
8,
277,
12,
1566,
304,
267,
327,
413,
15,
15510,
8020,
267,
367,
10218,
315,
291,
14,
452,
63,
7682,
14,
1459,
837,
288,
10218,
14,
8011,
63,
4551,
8,
277,
14,
7451,
83,
59,
344,
8,
7682,
3948,
267,
327,
499,
15,
1678,
18809,
1384,
267,
367,
18809,
1384,
315,
291,
14,
452,
63,
3937,
63,
19676,
14,
1612,
837,
288,
25626,
275,
291,
14,
452,
63,
3937,
63,
19676,
59,
17255,
1384,
61,
288,
340,
334,
1430,
14,
262,
6402,
315,
359,
604,
14,
362,
63,
6402,
342,
367,
1004,
315,
18809,
1384,
61,
490,
436,
291,
14,
6604,
304,
355,
8917,
275,
715,
355,
291,
14,
9321,
3584,
275,
715,
288,
587,
26,
355,
8917,
275,
756,
288,
367,
1004,
315,
18809,
1384,
26,
355,
340,
25626,
508,
283,
7870,
356,
490,
1004,
14,
409,
63,
31643,
1332,
1430,
14,
31643,
12,
1566,
14,
31643,
430,
355,
340,
25626,
508,
283,
11392,
356,
490,
1004,
14,
409,
63,
89,
576,
1332,
1430,
14,
89,
576,
12,
1566,
14,
89,
576,
430,
355,
1004,
14,
409,
63,
6604,
8,
6604,
9,
355,
2185,
275,
1004,
14,
362,
63,
6402,
342,
355,
2185,
14,
5485,
63,
11215,
8,
604,
9,
267,
327,
650,
15,
1678,
10218,
267,
367,
10218,
315,
291,
14,
452,
63,
7682,
14,
1459,
837,
288,
10218,
14,
15574,
8,
7682,
14,
8941,
14,
11246,
9,
339,
347,
485,
3584,
8,
277,
12,
1566,
304,
267,
408,
3584,
314,
3920,
624,
267,
291,
14,
7451,
83,
275,
1052,
267,
367,
10218,
315,
291,
14,
452,
63,
7682,
14,
1459,
837,
288,
291,
14,
7451,
83,
59,
344,
8,
7682,
1874,
275,
334,
355,
10218,
14,
1574,
63,
504,
63,
11246,
8,
7682,
14,
8941,
14,
11246,
430,
267,
367,
3920,
315,
291,
14,
452,
63,
3937,
63,
19676,
14,
1612,
837,
288,
367,
1004,
315,
3920,
26,
355,
1004,
14,
409,
63,
6604,
8,
797,
9,
339,
347,
1050,
63,
3937,
8,
277,
12,
7824,
16729,
25626,
534,
7870,
297,
1011,
604,
6750,
304,
267,
1021,
20385,
1296,
8,
513,
304,
288,
347,
636,
2227,
721,
277,
304,
355,
372,
2631,
8,
2960,
8,
277,
430,
267,
18809,
1384,
275,
20385,
1296,
342,
221,
327,
11105,
370,
4215,
13852,
267,
367,
2185,
315,
7824,
26,
288,
291,
14,
452,
63,
6402,
59,
344,
8,
1219,
1874,
275,
2185,
288,
2185,
63,
7682,
275,
2185,
14,
362,
63,
8941,
1252,
7682,
288,
340,
2185,
63,
7682,
440,
315,
291,
14,
452,
63,
7682,
14,
1459,
837,
355,
327,
692,
440,
2185,
63,
7682,
14,
9823,
63,
15574,
26,
355,
327,
259,
3598,
14,
4050,
480,
13757,
675,
10218,
626,
2291,
330,
1051,
531,
355,
327,
259,
372,
355,
291,
14,
452,
63,
7682,
59,
344,
8,
1219,
63,
7682,
1874,
275,
2185,
63,
7682,
355,
2185,
63,
7682,
14,
2421,
63,
2242,
360,
15335,
63,
6814,
63,
1430,
297,
291,
423,
265,
1185,
9,
355,
2185,
63,
7682,
14,
2421,
63,
2242,
360,
5485,
63,
1430,
297,
291,
423,
3584,
9,
288,
340,
25626,
508,
283,
7870,
356,
355,
1004,
275,
2185,
14,
1219,
86,
604,
8,
1219,
14,
362,
63,
88,
3556,
3430,
16,
467,
8917,
29,
797,
12,
3303,
376,
12754,
29,
549,
12,
1011,
604,
6750,
9,
288,
340,
25626,
508,
283,
11392,
356,
355,
1004,
275,
2185,
14,
1219,
32625,
8,
1219,
14,
362,
63,
89,
3556,
3430,
16,
467,
8917,
29,
797,
12,
3303,
376,
12754,
29,
549,
12,
1011,
604,
6750,
9,
288,
18809,
1384,
14,
740,
8,
604,
9,
267,
291,
14,
452,
63,
3937,
63,
19676,
59,
17255,
1384,
61,
275,
25626,
267,
372,
18809,
1384,
421,
199,
318,
2599,
3467,
63,
6604,
63,
1278,
8,
1219,
83,
304,
272,
408
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
35,
9,
7129,
13,
6965,
28814,
5741,
573,
85,
382,
2978,
20232,
199,
199,
3,
2765,
570,
365,
1777,
402,
3868,
7138,
26949,
14,
199,
3,
199,
3,
2719,
7138,
933,
417,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
390,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
199,
3,
1589,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2719,
7138,
933,
1025,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
17732,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
21632,
543,
3868,
7138,
933,
1025,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
199,
9958,
1785,
11420,
3423,
199,
624,
199,
199,
646,
8027,
199,
504,
13852,
492,
28224,
1110,
11728,
199,
504,
13852,
492,
28224,
1197,
11728,
199,
199,
646,
3598,
421,
199,
533,
29347,
3864,
83,
1384,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
452,
63,
3937,
63,
19676,
275,
28224,
1197,
11728,
342,
267,
291,
14,
452,
63,
7682,
275,
28224,
1110,
11728,
342,
267,
291,
14,
452,
63,
6402,
275,
28224,
1110,
11728,
342,
267,
291,
14,
7451,
83,
275,
1052,
267,
291,
14,
6604,
275,
715,
267,
291,
14,
9321,
3584,
275,
756,
339,
347,
485,
265,
1185,
8,
277,
12,
1566,
304,
267,
367,
10218,
315,
291,
14,
452,
63,
7682,
14,
1459,
837,
288,
340,
440,
10218,
14,
3440,
831,
14,
4561,
8,
277,
304,
355,
372,
267,
340,
1566,
14,
262,
6402,
365,
488,
503,
440,
291,
14,
6604,
26,
288,
340,
291,
14,
9321,
3584,
26,
355,
291,
423,
873,
8,
1430,
9,
355,
367,
10218,
315,
291,
14,
452,
63,
7682,
14,
1459,
837,
490,
10218,
14,
5485,
342,
355,
291,
14,
9321,
3584,
275,
756,
288,
372,
267,
291,
423,
873,
8,
1430,
9,
339,
347,
485,
873,
8,
277,
12,
1566,
304,
267,
327,
413,
15,
15510,
8020,
267,
367,
10218,
315,
291,
14,
452,
63,
7682,
14,
1459,
837,
288,
10218,
14,
8011,
63,
4551,
8,
277,
14,
7451,
83,
59,
344,
8,
7682,
3948,
267,
327,
499,
15,
1678,
18809,
1384,
267,
367,
18809,
1384,
315,
291,
14,
452,
63,
3937,
63,
19676,
14,
1612,
837,
288,
25626,
275,
291,
14,
452,
63,
3937,
63,
19676,
59,
17255,
1384,
61,
288,
340,
334,
1430,
14,
262,
6402,
315,
359,
604,
14,
362,
63,
6402,
342,
367,
1004,
315,
18809,
1384,
61,
490,
436,
291,
14,
6604,
304,
355,
8917,
275,
715,
355,
291,
14,
9321,
3584,
275,
715,
288,
587,
26,
355,
8917,
275,
756,
288,
367,
1004,
315,
18809,
1384,
26,
355,
340,
25626,
508,
283,
7870,
356,
490,
1004,
14,
409,
63,
31643,
1332,
1430,
14,
31643,
12,
1566,
14,
31643,
430,
355,
340,
25626,
508,
283,
11392,
356,
490,
1004,
14,
409,
63,
89,
576,
1332,
1430,
14,
89,
576,
12,
1566,
14,
89,
576,
430,
355,
1004,
14,
409,
63,
6604,
8,
6604,
9,
355,
2185,
275,
1004,
14,
362,
63,
6402,
342,
355,
2185,
14,
5485,
63,
11215,
8,
604,
9,
267,
327,
650,
15,
1678,
10218,
267,
367,
10218,
315,
291,
14,
452,
63,
7682,
14,
1459,
837,
288,
10218,
14,
15574,
8,
7682,
14,
8941,
14,
11246,
9,
339,
347,
485,
3584,
8,
277,
12,
1566,
304,
267,
408,
3584,
314,
3920,
624,
267,
291,
14,
7451,
83,
275,
1052,
267,
367,
10218,
315,
291,
14,
452,
63,
7682,
14,
1459,
837,
288,
291,
14,
7451,
83,
59,
344,
8,
7682,
1874,
275,
334,
355,
10218,
14,
1574,
63,
504,
63,
11246,
8,
7682,
14,
8941,
14,
11246,
430,
267,
367,
3920,
315,
291,
14,
452,
63,
3937,
63,
19676,
14,
1612,
837,
288,
367,
1004,
315,
3920,
26,
355,
1004,
14,
409,
63,
6604,
8,
797,
9,
339,
347,
1050,
63,
3937,
8,
277,
12,
7824,
16729,
25626,
534,
7870,
297,
1011,
604,
6750,
304,
267,
1021,
20385,
1296,
8,
513,
304,
288,
347,
636,
2227,
721,
277,
304,
355,
372,
2631,
8,
2960,
8,
277,
430,
267,
18809,
1384,
275,
20385,
1296,
342,
221,
327,
11105,
370,
4215,
13852,
267,
367,
2185,
315,
7824,
26,
288,
291,
14,
452,
63,
6402,
59,
344,
8,
1219,
1874,
275,
2185,
288,
2185,
63,
7682,
275,
2185,
14,
362,
63,
8941,
1252,
7682,
288,
340,
2185,
63,
7682,
440,
315,
291,
14,
452,
63,
7682,
14,
1459,
837,
355,
327,
692,
440,
2185,
63,
7682,
14,
9823,
63,
15574,
26,
355,
327,
259,
3598,
14,
4050,
480,
13757,
675,
10218,
626,
2291,
330,
1051,
531,
355,
327,
259,
372,
355,
291,
14,
452,
63,
7682,
59,
344,
8,
1219,
63,
7682,
1874,
275,
2185,
63,
7682,
355,
2185,
63,
7682,
14,
2421,
63,
2242,
360,
15335,
63,
6814,
63,
1430,
297,
291,
423,
265,
1185,
9,
355,
2185,
63,
7682,
14,
2421,
63,
2242,
360,
5485,
63,
1430,
297,
291,
423,
3584,
9,
288,
340,
25626,
508,
283,
7870,
356,
355,
1004,
275,
2185,
14,
1219,
86,
604,
8,
1219,
14,
362,
63,
88,
3556,
3430,
16,
467,
8917,
29,
797,
12,
3303,
376,
12754,
29,
549,
12,
1011,
604,
6750,
9,
288,
340,
25626,
508,
283,
11392,
356,
355,
1004,
275,
2185,
14,
1219,
32625,
8,
1219,
14,
362,
63,
89,
3556,
3430,
16,
467,
8917,
29,
797,
12,
3303,
376,
12754,
29,
549,
12,
1011,
604,
6750,
9,
288,
18809,
1384,
14,
740,
8,
604,
9,
267,
291,
14,
452,
63,
3937,
63,
19676,
59,
17255,
1384,
61,
275,
25626,
267,
372,
18809,
1384,
421,
199,
318,
2599,
3467,
63,
6604,
63,
1278,
8,
1219,
83,
304,
272,
408,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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logbook component."""
# pylint: disable=protected-access,invalid-name
import logging
from datetime import timedelta, datetime
import unittest
import pytest
import voluptuous as vol
from homeassistant.components import sun
import homeassistant.core as ha
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_SERVICE,
ATTR_NAME,
EVENT_STATE_CHANGED,
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP,
EVENT_AUTOMATION_TRIGGERED,
EVENT_SCRIPT_STARTED,
ATTR_HIDDEN,
STATE_NOT_HOME,
STATE_ON,
STATE_OFF,
)
import homeassistant.util.dt as dt_util
from homeassistant.components import logbook, recorder
from homeassistant.components.alexa.smart_home import EVENT_ALEXA_SMART_HOME
from homeassistant.components.homekit.const import (
ATTR_DISPLAY_NAME,
ATTR_VALUE,
DOMAIN as DOMAIN_HOMEKIT,
EVENT_HOMEKIT_CHANGED,
)
from homeassistant.setup import setup_component, async_setup_component
from tests.common import init_recorder_component, get_test_home_assistant
_LOGGER = logging.getLogger(__name__)
class TestComponentLogbook(unittest.TestCase):
"""Test the History component."""
EMPTY_CONFIG = logbook.CONFIG_SCHEMA({logbook.DOMAIN: {}})
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
init_recorder_component(self.hass) # Force an in memory DB
assert setup_component(self.hass, logbook.DOMAIN, self.EMPTY_CONFIG)
self.hass.start()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
def test_service_call_create_logbook_entry(self):
"""Test if service call create log book entry."""
calls = []
@ha.callback
def event_listener(event):
"""Append on event."""
calls.append(event)
self.hass.bus.listen(logbook.EVENT_LOGBOOK_ENTRY, event_listener)
self.hass.services.call(
logbook.DOMAIN,
"log",
{
logbook.ATTR_NAME: "Alarm",
logbook.ATTR_MESSAGE: "is triggered",
logbook.ATTR_DOMAIN: "switch",
logbook.ATTR_ENTITY_ID: "switch.test_switch",
},
True,
)
# Logbook entry service call results in firing an event.
# Our service call will unblock when the event listeners have been
# scheduled. This means that they may not have been processed yet.
self.hass.block_till_done()
self.hass.data[recorder.DATA_INSTANCE].block_till_done()
events = list(
logbook._get_events(
self.hass,
{},
dt_util.utcnow() - timedelta(hours=1),
dt_util.utcnow() + timedelta(hours=1),
)
)
assert len(events) == 2
assert 1 == len(calls)
last_call = calls[-1]
assert "Alarm" == last_call.data.get(logbook.ATTR_NAME)
assert "is triggered" == last_call.data.get(logbook.ATTR_MESSAGE)
assert "switch" == last_call.data.get(logbook.ATTR_DOMAIN)
assert "switch.test_switch" == last_call.data.get(logbook.ATTR_ENTITY_ID)
def test_service_call_create_log_book_entry_no_message(self):
"""Test if service call create log book entry without message."""
calls = []
@ha.callback
def event_listener(event):
"""Append on event."""
calls.append(event)
self.hass.bus.listen(logbook.EVENT_LOGBOOK_ENTRY, event_listener)
with pytest.raises(vol.Invalid):
self.hass.services.call(logbook.DOMAIN, "log", {}, True)
# Logbook entry service call results in firing an event.
# Our service call will unblock when the event listeners have been
# scheduled. This means that they may not have been processed yet.
self.hass.block_till_done()
assert 0 == len(calls)
def test_humanify_filter_sensor(self):
"""Test humanify filter too frequent sensor values."""
entity_id = "sensor.bla"
pointA = dt_util.utcnow().replace(minute=2)
pointB = pointA.replace(minute=5)
pointC = pointA + timedelta(minutes=logbook.GROUP_BY_MINUTES)
eventA = self.create_state_changed_event(pointA, entity_id, 10)
eventB = self.create_state_changed_event(pointB, entity_id, 20)
eventC = self.create_state_changed_event(pointC, entity_id, 30)
entries = list(logbook.humanify(self.hass, (eventA, eventB, eventC)))
assert 2 == len(entries)
self.assert_entry(
entries[0], pointB, "bla", domain="sensor", entity_id=entity_id
)
self.assert_entry(
entries[1], pointC, "bla", domain="sensor", entity_id=entity_id
)
def test_filter_continuous_sensor_values(self):
"""Test remove continuous sensor events from logbook."""
entity_id = "sensor.bla"
pointA = dt_util.utcnow()
attributes = {"unit_of_measurement": "foo"}
eventA = self.create_state_changed_event(pointA, entity_id, 10, attributes)
entries = list(logbook.humanify(self.hass, (eventA,)))
assert 0 == len(entries)
def test_exclude_new_entities(self):
"""Test if events are excluded on first update."""
entity_id = "sensor.bla"
entity_id2 = "sensor.blu"
pointA = dt_util.utcnow()
pointB = pointA + timedelta(minutes=logbook.GROUP_BY_MINUTES)
eventA = self.create_state_changed_event(pointA, entity_id, 10)
eventB = self.create_state_changed_event(pointB, entity_id2, 20)
eventA.data["old_state"] = None
entities_filter = logbook._generate_filter_from_config({})
events = [
e
for e in (ha.Event(EVENT_HOMEASSISTANT_STOP), eventA, eventB)
if logbook._keep_event(e, entities_filter)
]
entries = list(logbook.humanify(self.hass, events))
assert 2 == len(entries)
self.assert_entry(
entries[0], name="Home Assistant", message="stopped", domain=ha.DOMAIN
)
self.assert_entry(
entries[1], pointB, "blu", domain="sensor", entity_id=entity_id2
)
def test_exclude_removed_entities(self):
"""Test if events are excluded on last update."""
entity_id = "sensor.bla"
entity_id2 = "sensor.blu"
pointA = dt_util.utcnow()
pointB = pointA + timedelta(minutes=logbook.GROUP_BY_MINUTES)
eventA = self.create_state_changed_event(pointA, entity_id, 10)
eventB = self.create_state_changed_event(pointB, entity_id2, 20)
eventA.data["new_state"] = None
entities_filter = logbook._generate_filter_from_config({})
events = [
e
for e in (ha.Event(EVENT_HOMEASSISTANT_STOP), eventA, eventB)
if logbook._keep_event(e, entities_filter)
]
entries = list(logbook.humanify(self.hass, events))
assert 2 == len(entries)
self.assert_entry(
entries[0], name="Home Assistant", message="stopped", domain=ha.DOMAIN
)
self.assert_entry(
entries[1], pointB, "blu", domain="sensor", entity_id=entity_id2
)
def test_exclude_events_hidden(self):
"""Test if events are excluded if entity is hidden."""
entity_id = "sensor.bla"
entity_id2 = "sensor.blu"
pointA = dt_util.utcnow()
pointB = pointA + timedelta(minutes=logbook.GROUP_BY_MINUTES)
eventA = self.create_state_changed_event(
pointA, entity_id, 10, {ATTR_HIDDEN: "true"}
)
eventB = self.create_state_changed_event(pointB, entity_id2, 20)
entities_filter = logbook._generate_filter_from_config({})
events = [
e
for e in (ha.Event(EVENT_HOMEASSISTANT_STOP), eventA, eventB)
if logbook._keep_event(e, entities_filter)
]
entries = list(logbook.humanify(self.hass, events))
assert 2 == len(entries)
self.assert_entry(
entries[0], name="Home Assistant", message="stopped", domain=ha.DOMAIN
)
self.assert_entry(
entries[1], pointB, "blu", domain="sensor", entity_id=entity_id2
)
def test_exclude_events_entity(self):
"""Test if events are filtered if entity is excluded in config."""
entity_id = "sensor.bla"
entity_id2 = "sensor.blu"
pointA = dt_util.utcnow()
pointB = pointA + timedelta(minutes=logbook.GROUP_BY_MINUTES)
eventA = self.create_state_changed_event(pointA, entity_id, 10)
eventB = self.create_state_changed_event(pointB, entity_id2, 20)
config = logbook.CONFIG_SCHEMA(
{
ha.DOMAIN: {},
logbook.DOMAIN: {
logbook.CONF_EXCLUDE: {logbook.CONF_ENTITIES: [entity_id]}
},
}
)
entities_filter = logbook._generate_filter_from_config(config[logbook.DOMAIN])
events = [
e
for e in (ha.Event(EVENT_HOMEASSISTANT_STOP), eventA, eventB)
if logbook._keep_event(e, entities_filter)
]
entries = list(logbook.humanify(self.hass, events))
assert 2 == len(entries)
self.assert_entry(
entries[0], name="Home Assistant", message="stopped", domain=ha.DOMAIN
)
self.assert_entry(
entries[1], pointB, "blu", domain="sensor", entity_id=entity_id2
)
def test_exclude_events_domain(self):
"""Test if events are filtered if domain is excluded in config."""
entity_id = "switch.bla"
entity_id2 = "sensor.blu"
pointA = dt_util.utcnow()
pointB = pointA + timedelta(minutes=logbook.GROUP_BY_MINUTES)
eventA = self.create_state_changed_event(pointA, entity_id, 10)
eventB = self.create_state_changed_event(pointB, entity_id2, 20)
config = logbook.CONFIG_SCHEMA(
{
ha.DOMAIN: {},
logbook.DOMAIN: {
logbook.CONF_EXCLUDE: {
logbook.CONF_DOMAINS: ["switch", "alexa", DOMAIN_HOMEKIT]
}
},
}
)
entities_filter = logbook._generate_filter_from_config(config[logbook.DOMAIN])
events = [
e
for e in (
ha.Event(EVENT_HOMEASSISTANT_START),
ha.Event(EVENT_ALEXA_SMART_HOME),
ha.Event(EVENT_HOMEKIT_CHANGED),
eventA,
eventB,
)
if logbook._keep_event(e, entities_filter)
]
entries = list(logbook.humanify(self.hass, events))
assert 2 == len(entries)
self.assert_entry(
entries[0], name="Home Assistant", message="started", domain=ha.DOMAIN
)
self.assert_entry(
entries[1], pointB, "blu", domain="sensor", entity_id=entity_id2
)
def test_exclude_automation_events(self):
"""Test if automation entries can be excluded by entity_id."""
name = "My Automation Rule"
domain = "automation"
entity_id = "automation.my_automation_rule"
entity_id2 = "automation.my_automation_rule_2"
entity_id2 = "sensor.blu"
eventA = ha.Event(
logbook.EVENT_AUTOMATION_TRIGGERED,
{logbook.ATTR_NAME: name, logbook.ATTR_ENTITY_ID: entity_id},
)
eventB = ha.Event(
logbook.EVENT_AUTOMATION_TRIGGERED,
{logbook.ATTR_NAME: name, logbook.ATTR_ENTITY_ID: entity_id2},
)
config = logbook.CONFIG_SCHEMA(
{
ha.DOMAIN: {},
logbook.DOMAIN: {
logbook.CONF_EXCLUDE: {logbook.CONF_ENTITIES: [entity_id]}
},
}
)
entities_filter = logbook._generate_filter_from_config(config[logbook.DOMAIN])
events = [
e
for e in (ha.Event(EVENT_HOMEASSISTANT_STOP), eventA, eventB)
if logbook._keep_event(e, entities_filter)
]
entries = list(logbook.humanify(self.hass, events))
assert 2 == len(entries)
self.assert_entry(
entries[0], name="Home Assistant", message="stopped", domain=ha.DOMAIN
)
self.assert_entry(entries[1], name=name, domain=domain, entity_id=entity_id2)
def test_exclude_script_events(self):
"""Test if script start can be excluded by entity_id."""
name = "My Script Rule"
domain = "script"
entity_id = "script.my_script"
entity_id2 = "script.my_script_2"
entity_id2 = "sensor.blu"
eventA = ha.Event(
logbook.EVENT_SCRIPT_STARTED,
{logbook.ATTR_NAME: name, logbook.ATTR_ENTITY_ID: entity_id},
)
eventB = ha.Event(
logbook.EVENT_SCRIPT_STARTED,
{logbook.ATTR_NAME: name, logbook.ATTR_ENTITY_ID: entity_id2},
)
config = logbook.CONFIG_SCHEMA(
{
ha.DOMAIN: {},
logbook.DOMAIN: {
logbook.CONF_EXCLUDE: {logbook.CONF_ENTITIES: [entity_id]}
},
}
)
entities_filter = logbook._generate_filter_from_config(config[logbook.DOMAIN])
events = [
e
for e in (ha.Event(EVENT_HOMEASSISTANT_STOP), eventA, eventB)
if logbook._keep_event(e, entities_filter)
]
entries = list(logbook.humanify(self.hass, events))
assert 2 == len(entries)
self.assert_entry(
entries[0], name="Home Assistant", message="stopped", domain=ha.DOMAIN
)
self.assert_entry(entries[1], name=name, domain=domain, entity_id=entity_id2)
def test_include_events_entity(self):
"""Test if events are filtered if entity is included in config."""
entity_id = "sensor.bla"
entity_id2 = "sensor.blu"
pointA = dt_util.utcnow()
pointB = pointA + timedelta(minutes=logbook.GROUP_BY_MINUTES)
eventA = self.create_state_changed_event(pointA, entity_id, 10)
eventB = self.create_state_changed_event(pointB, entity_id2, 20)
config = logbook.CONFIG_SCHEMA(
{
ha.DOMAIN: {},
logbook.DOMAIN: {
logbook.CONF_INCLUDE: {logbook.CONF_ENTITIES: [entity_id2]}
},
}
)
entities_filter = logbook._generate_filter_from_config(config[logbook.DOMAIN])
events = [
e
for e in (ha.Event(EVENT_HOMEASSISTANT_STOP), eventA, eventB)
if logbook._keep_event(e, entities_filter)
]
entries = list(logbook.humanify(self.hass, events))
assert 2 == len(entries)
self.assert_entry(
entries[0], name="Home Assistant", message="stopped", domain=ha.DOMAIN
)
self.assert_entry(
entries[1], pointB, "blu", domain="sensor", entity_id=entity_id2
)
def test_include_events_domain(self):
"""Test if events are filtered if domain is included in config."""
entity_id = "switch.bla"
entity_id2 = "sensor.blu"
pointA = dt_util.utcnow()
pointB = pointA + timedelta(minutes=logbook.GROUP_BY_MINUTES)
event_alexa = ha.Event(
EVENT_ALEXA_SMART_HOME,
{"request": {"namespace": "Alexa.Discovery", "name": "Discover"}},
)
event_homekit = ha.Event(
EVENT_HOMEKIT_CHANGED,
{
ATTR_ENTITY_ID: "lock.front_door",
ATTR_DISPLAY_NAME: "Front Door",
ATTR_SERVICE: "lock",
},
)
eventA = self.create_state_changed_event(pointA, entity_id, 10)
eventB = self.create_state_changed_event(pointB, entity_id2, 20)
config = logbook.CONFIG_SCHEMA(
{
ha.DOMAIN: {},
logbook.DOMAIN: {
logbook.CONF_INCLUDE: {
logbook.CONF_DOMAINS: ["sensor", "alexa", DOMAIN_HOMEKIT]
}
},
}
)
entities_filter = logbook._generate_filter_from_config(config[logbook.DOMAIN])
events = [
e
for e in (
ha.Event(EVENT_HOMEASSISTANT_START),
event_alexa,
event_homekit,
eventA,
eventB,
)
if logbook._keep_event(e, entities_filter)
]
entries = list(logbook.humanify(self.hass, events))
assert 4 == len(entries)
self.assert_entry(
entries[0], name="Home Assistant", message="started", domain=ha.DOMAIN
)
self.assert_entry(entries[1], name="Amazon Alexa", domain="alexa")
self.assert_entry(entries[2], name="HomeKit", domain=DOMAIN_HOMEKIT)
self.assert_entry(
entries[3], pointB, "blu", domain="sensor", entity_id=entity_id2
)
def test_include_exclude_events(self):
"""Test if events are filtered if include and exclude is configured."""
entity_id = "switch.bla"
entity_id2 = "sensor.blu"
entity_id3 = "sensor.bli"
pointA = dt_util.utcnow()
pointB = pointA + timedelta(minutes=logbook.GROUP_BY_MINUTES)
eventA1 = self.create_state_changed_event(pointA, entity_id, 10)
eventA2 = self.create_state_changed_event(pointA, entity_id2, 10)
eventA3 = self.create_state_changed_event(pointA, entity_id3, 10)
eventB1 = self.create_state_changed_event(pointB, entity_id, 20)
eventB2 = self.create_state_changed_event(pointB, entity_id2, 20)
config = logbook.CONFIG_SCHEMA(
{
ha.DOMAIN: {},
logbook.DOMAIN: {
logbook.CONF_INCLUDE: {
logbook.CONF_DOMAINS: ["sensor"],
logbook.CONF_ENTITIES: ["switch.bla"],
},
logbook.CONF_EXCLUDE: {
logbook.CONF_DOMAINS: ["switch"],
logbook.CONF_ENTITIES: ["sensor.bli"],
},
},
}
)
entities_filter = logbook._generate_filter_from_config(config[logbook.DOMAIN])
events = [
e
for e in (
ha.Event(EVENT_HOMEASSISTANT_START),
eventA1,
eventA2,
eventA3,
eventB1,
eventB2,
)
if logbook._keep_event(e, entities_filter)
]
entries = list(logbook.humanify(self.hass, events))
assert 5 == len(entries)
self.assert_entry(
entries[0], name="Home Assistant", message="started", domain=ha.DOMAIN
)
self.assert_entry(
entries[1], pointA, "bla", domain="switch", entity_id=entity_id
)
self.assert_entry(
entries[2], pointA, "blu", domain="sensor", entity_id=entity_id2
)
self.assert_entry(
entries[3], pointB, "bla", domain="switch", entity_id=entity_id
)
self.assert_entry(
entries[4], pointB, "blu", domain="sensor", entity_id=entity_id2
)
def test_exclude_auto_groups(self):
"""Test if events of automatically generated groups are filtered."""
entity_id = "switch.bla"
entity_id2 = "group.switches"
pointA = dt_util.utcnow()
eventA = self.create_state_changed_event(pointA, entity_id, 10)
eventB = self.create_state_changed_event(pointA, entity_id2, 20, {"auto": True})
entities_filter = logbook._generate_filter_from_config({})
events = [
e for e in (eventA, eventB) if logbook._keep_event(e, entities_filter)
]
entries = list(logbook.humanify(self.hass, events))
assert 1 == len(entries)
self.assert_entry(
entries[0], pointA, "bla", domain="switch", entity_id=entity_id
)
def test_exclude_attribute_changes(self):
"""Test if events of attribute changes are filtered."""
entity_id = "switch.bla"
entity_id2 = "switch.blu"
pointA = dt_util.utcnow()
pointB = pointA + timedelta(minutes=1)
eventA = self.create_state_changed_event(pointA, entity_id, 10)
eventB = self.create_state_changed_event(
pointA, entity_id2, 20, last_changed=pointA, last_updated=pointB
)
entities_filter = logbook._generate_filter_from_config({})
events = [
e for e in (eventA, eventB) if logbook._keep_event(e, entities_filter)
]
entries = list(logbook.humanify(self.hass, events))
assert 1 == len(entries)
self.assert_entry(
entries[0], pointA, "bla", domain="switch", entity_id=entity_id
)
def test_home_assistant_start_stop_grouped(self):
"""Test if HA start and stop events are grouped.
Events that are occurring in the same minute.
"""
entries = list(
logbook.humanify(
self.hass,
(
ha.Event(EVENT_HOMEASSISTANT_STOP),
ha.Event(EVENT_HOMEASSISTANT_START),
),
)
)
assert 1 == len(entries)
self.assert_entry(
entries[0], name="Home Assistant", message="restarted", domain=ha.DOMAIN
)
def test_home_assistant_start(self):
"""Test if HA start is not filtered or converted into a restart."""
entity_id = "switch.bla"
pointA = dt_util.utcnow()
entries = list(
logbook.humanify(
self.hass,
(
ha.Event(EVENT_HOMEASSISTANT_START),
self.create_state_changed_event(pointA, entity_id, 10),
),
)
)
assert 2 == len(entries)
self.assert_entry(
entries[0], name="Home Assistant", message="started", domain=ha.DOMAIN
)
self.assert_entry(
entries[1], pointA, "bla", domain="switch", entity_id=entity_id
)
def test_entry_message_from_state_device(self):
"""Test if logbook message is correctly created for switches.
Especially test if the special handling for turn on/off events is done.
"""
pointA = dt_util.utcnow()
# message for a device state change
eventA = self.create_state_changed_event(pointA, "switch.bla", 10)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "changed to 10" == message
# message for a switch turned on
eventA = self.create_state_changed_event(pointA, "switch.bla", STATE_ON)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "turned on" == message
# message for a switch turned off
eventA = self.create_state_changed_event(pointA, "switch.bla", STATE_OFF)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "turned off" == message
def test_entry_message_from_state_device_tracker(self):
"""Test if logbook message is correctly created for device tracker."""
pointA = dt_util.utcnow()
# message for a device tracker "not home" state
eventA = self.create_state_changed_event(
pointA, "device_tracker.john", STATE_NOT_HOME
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is away" == message
# message for a device tracker "home" state
eventA = self.create_state_changed_event(pointA, "device_tracker.john", "work")
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is at work" == message
def test_entry_message_from_state_person(self):
"""Test if logbook message is correctly created for a person."""
pointA = dt_util.utcnow()
# message for a device tracker "not home" state
eventA = self.create_state_changed_event(pointA, "person.john", STATE_NOT_HOME)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is away" == message
# message for a device tracker "home" state
eventA = self.create_state_changed_event(pointA, "person.john", "work")
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is at work" == message
def test_entry_message_from_state_sun(self):
"""Test if logbook message is correctly created for sun."""
pointA = dt_util.utcnow()
# message for a sun rise
eventA = self.create_state_changed_event(
pointA, "sun.sun", sun.STATE_ABOVE_HORIZON
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "has risen" == message
# message for a sun set
eventA = self.create_state_changed_event(
pointA, "sun.sun", sun.STATE_BELOW_HORIZON
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "has set" == message
def test_entry_message_from_state_binary_sensor_battery(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "battery"}
# message for a binary_sensor battery "low" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.battery", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is low" == message
# message for a binary_sensor battery "normal" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.battery", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is normal" == message
def test_entry_message_from_state_binary_sensor_connectivity(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "connectivity"}
# message for a binary_sensor connectivity "connected" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.connectivity", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is connected" == message
# message for a binary_sensor connectivity "disconnected" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.connectivity", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is disconnected" == message
def test_entry_message_from_state_binary_sensor_door(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "door"}
# message for a binary_sensor door "open" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.door", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is opened" == message
# message for a binary_sensor door "closed" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.door", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is closed" == message
def test_entry_message_from_state_binary_sensor_garage_door(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "garage_door"}
# message for a binary_sensor garage_door "open" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.garage_door", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is opened" == message
# message for a binary_sensor garage_door "closed" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.garage_door", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is closed" == message
def test_entry_message_from_state_binary_sensor_opening(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "opening"}
# message for a binary_sensor opening "open" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.opening", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is opened" == message
# message for a binary_sensor opening "closed" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.opening", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is closed" == message
def test_entry_message_from_state_binary_sensor_window(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "window"}
# message for a binary_sensor window "open" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.window", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is opened" == message
# message for a binary_sensor window "closed" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.window", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is closed" == message
def test_entry_message_from_state_binary_sensor_lock(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "lock"}
# message for a binary_sensor lock "unlocked" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.lock", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is unlocked" == message
# message for a binary_sensor lock "locked" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.lock", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is locked" == message
def test_entry_message_from_state_binary_sensor_plug(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "plug"}
# message for a binary_sensor plug "unpluged" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.plug", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is plugged in" == message
# message for a binary_sensor plug "pluged" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.plug", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is unplugged" == message
def test_entry_message_from_state_binary_sensor_presence(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "presence"}
# message for a binary_sensor presence "home" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.presence", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is at home" == message
# message for a binary_sensor presence "away" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.presence", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is away" == message
def test_entry_message_from_state_binary_sensor_safety(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "safety"}
# message for a binary_sensor safety "unsafe" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.safety", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is unsafe" == message
# message for a binary_sensor safety "safe" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.safety", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is safe" == message
def test_entry_message_from_state_binary_sensor_cold(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "cold"}
# message for a binary_sensor cold "detected" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.cold", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected cold" == message
# message for a binary_sensori cold "cleared" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.cold", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no cold detected)" == message
def test_entry_message_from_state_binary_sensor_gas(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "gas"}
# message for a binary_sensor gas "detected" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.gas", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected gas" == message
# message for a binary_sensori gas "cleared" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.gas", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no gas detected)" == message
def test_entry_message_from_state_binary_sensor_heat(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "heat"}
# message for a binary_sensor heat "detected" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.heat", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected heat" == message
# message for a binary_sensori heat "cleared" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.heat", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no heat detected)" == message
def test_entry_message_from_state_binary_sensor_light(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "light"}
# message for a binary_sensor light "detected" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.light", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected light" == message
# message for a binary_sensori light "cleared" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.light", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no light detected)" == message
def test_entry_message_from_state_binary_sensor_moisture(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "moisture"}
# message for a binary_sensor moisture "detected" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.moisture", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected moisture" == message
# message for a binary_sensori moisture "cleared" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.moisture", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no moisture detected)" == message
def test_entry_message_from_state_binary_sensor_motion(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "motion"}
# message for a binary_sensor motion "detected" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.motion", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected motion" == message
# message for a binary_sensori motion "cleared" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.motion", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no motion detected)" == message
def test_entry_message_from_state_binary_sensor_occupancy(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "occupancy"}
# message for a binary_sensor occupancy "detected" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.occupancy", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected occupancy" == message
# message for a binary_sensori occupancy "cleared" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.occupancy", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no occupancy detected)" == message
def test_entry_message_from_state_binary_sensor_power(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "power"}
# message for a binary_sensor power "detected" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.power", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected power" == message
# message for a binary_sensori power "cleared" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.power", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no power detected)" == message
def test_entry_message_from_state_binary_sensor_problem(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "problem"}
# message for a binary_sensor problem "detected" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.problem", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected problem" == message
# message for a binary_sensori problem "cleared" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.problem", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no problem detected)" == message
def test_entry_message_from_state_binary_sensor_smoke(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "smoke"}
# message for a binary_sensor smoke "detected" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.smoke", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected smoke" == message
# message for a binary_sensori smoke "cleared" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.smoke", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no smoke detected)" == message
def test_entry_message_from_state_binary_sensor_sound(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "sound"}
# message for a binary_sensor sound "detected" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.sound", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected sound" == message
# message for a binary_sensori sound "cleared" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.sound", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no sound detected)" == message
def test_entry_message_from_state_binary_sensor_vibration(self):
"""Test if logbook message is correctly created for a binary_sensor."""
pointA = dt_util.utcnow()
attributes = {"device_class": "vibration"}
# message for a binary_sensor vibration "detected" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.vibration", STATE_ON, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected vibration" == message
# message for a binary_sensori vibration "cleared" state
eventA = self.create_state_changed_event(
pointA, "binary_sensor.vibration", STATE_OFF, attributes
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no vibration detected)" == message
def test_process_custom_logbook_entries(self):
"""Test if custom log book entries get added as an entry."""
name = "Nice name"
message = "has a custom entry"
entity_id = "sun.sun"
entries = list(
logbook.humanify(
self.hass,
(
ha.Event(
logbook.EVENT_LOGBOOK_ENTRY,
{
logbook.ATTR_NAME: name,
logbook.ATTR_MESSAGE: message,
logbook.ATTR_ENTITY_ID: entity_id,
},
),
),
)
)
assert 1 == len(entries)
self.assert_entry(
entries[0], name=name, message=message, domain="sun", entity_id=entity_id
)
def assert_entry(
self, entry, when=None, name=None, message=None, domain=None, entity_id=None
):
"""Assert an entry is what is expected."""
if when:
assert when == entry["when"]
if name:
assert name == entry["name"]
if message:
assert message == entry["message"]
if domain:
assert domain == entry["domain"]
if entity_id:
assert entity_id == entry["entity_id"]
def create_state_changed_event(
self,
event_time_fired,
entity_id,
state,
attributes=None,
last_changed=None,
last_updated=None,
):
"""Create state changed event."""
# Logbook only cares about state change events that
# contain an old state but will not actually act on it.
state = ha.State(
entity_id, state, attributes, last_changed, last_updated
).as_dict()
return ha.Event(
EVENT_STATE_CHANGED,
{"entity_id": entity_id, "old_state": state, "new_state": state},
time_fired=event_time_fired,
)
async def test_logbook_view(hass, hass_client):
"""Test the logbook view."""
await hass.async_add_job(init_recorder_component, hass)
await async_setup_component(hass, "logbook", {})
await hass.async_add_job(hass.data[recorder.DATA_INSTANCE].block_till_done)
client = await hass_client()
response = await client.get("/api/logbook/{}".format(dt_util.utcnow().isoformat()))
assert response.status == 200
async def test_logbook_view_period_entity(hass, hass_client):
"""Test the logbook view with period and entity."""
await hass.async_add_job(init_recorder_component, hass)
await async_setup_component(hass, "logbook", {})
await hass.async_add_job(hass.data[recorder.DATA_INSTANCE].block_till_done)
entity_id_test = "switch.test"
hass.states.async_set(entity_id_test, STATE_OFF)
hass.states.async_set(entity_id_test, STATE_ON)
entity_id_second = "switch.second"
hass.states.async_set(entity_id_second, STATE_OFF)
hass.states.async_set(entity_id_second, STATE_ON)
await hass.async_block_till_done()
await hass.async_add_job(hass.data[recorder.DATA_INSTANCE].block_till_done)
client = await hass_client()
# Today time 00:00:00
start = dt_util.utcnow().date()
start_date = datetime(start.year, start.month, start.day)
# Test today entries without filters
response = await client.get("/api/logbook/{}".format(start_date.isoformat()))
assert response.status == 200
json = await response.json()
assert len(json) == 2
assert json[0]["entity_id"] == entity_id_test
assert json[1]["entity_id"] == entity_id_second
# Test today entries with filter by period
response = await client.get(
"/api/logbook/{}?period=1".format(start_date.isoformat())
)
assert response.status == 200
json = await response.json()
assert len(json) == 2
assert json[0]["entity_id"] == entity_id_test
assert json[1]["entity_id"] == entity_id_second
# Test today entries with filter by entity_id
response = await client.get(
"/api/logbook/{}?entity=switch.test".format(start_date.isoformat())
)
assert response.status == 200
json = await response.json()
assert len(json) == 1
assert json[0]["entity_id"] == entity_id_test
# Test entries for 3 days with filter by entity_id
response = await client.get(
"/api/logbook/{}?period=3&entity=switch.test".format(start_date.isoformat())
)
assert response.status == 200
json = await response.json()
assert len(json) == 1
assert json[0]["entity_id"] == entity_id_test
# Tomorrow time 00:00:00
start = (dt_util.utcnow() + timedelta(days=1)).date()
start_date = datetime(start.year, start.month, start.day)
# Test tomorrow entries without filters
response = await client.get("/api/logbook/{}".format(start_date.isoformat()))
assert response.status == 200
json = await response.json()
assert len(json) == 0
# Test tomorrow entries with filter by entity_id
response = await client.get(
"/api/logbook/{}?entity=switch.test".format(start_date.isoformat())
)
assert response.status == 200
json = await response.json()
assert len(json) == 0
# Test entries from tomorrow to 3 days ago with filter by entity_id
response = await client.get(
"/api/logbook/{}?period=3&entity=switch.test".format(start_date.isoformat())
)
assert response.status == 200
json = await response.json()
assert len(json) == 1
assert json[0]["entity_id"] == entity_id_test
async def test_humanify_alexa_event(hass):
"""Test humanifying Alexa event."""
hass.states.async_set("light.kitchen", "on", {"friendly_name": "Kitchen Light"})
results = list(
logbook.humanify(
hass,
[
ha.Event(
EVENT_ALEXA_SMART_HOME,
{"request": {"namespace": "Alexa.Discovery", "name": "Discover"}},
),
ha.Event(
EVENT_ALEXA_SMART_HOME,
{
"request": {
"namespace": "Alexa.PowerController",
"name": "TurnOn",
"entity_id": "light.kitchen",
}
},
),
ha.Event(
EVENT_ALEXA_SMART_HOME,
{
"request": {
"namespace": "Alexa.PowerController",
"name": "TurnOn",
"entity_id": "light.non_existing",
}
},
),
],
)
)
event1, event2, event3 = results
assert event1["name"] == "Amazon Alexa"
assert event1["message"] == "send command Alexa.Discovery/Discover"
assert event1["entity_id"] is None
assert event2["name"] == "Amazon Alexa"
assert (
event2["message"]
== "send command Alexa.PowerController/TurnOn for Kitchen Light"
)
assert event2["entity_id"] == "light.kitchen"
assert event3["name"] == "Amazon Alexa"
assert (
event3["message"]
== "send command Alexa.PowerController/TurnOn for light.non_existing"
)
assert event3["entity_id"] == "light.non_existing"
async def test_humanify_homekit_changed_event(hass):
"""Test humanifying HomeKit changed event."""
event1, event2 = list(
logbook.humanify(
hass,
[
ha.Event(
EVENT_HOMEKIT_CHANGED,
{
ATTR_ENTITY_ID: "lock.front_door",
ATTR_DISPLAY_NAME: "Front Door",
ATTR_SERVICE: "lock",
},
),
ha.Event(
EVENT_HOMEKIT_CHANGED,
{
ATTR_ENTITY_ID: "cover.window",
ATTR_DISPLAY_NAME: "Window",
ATTR_SERVICE: "set_cover_position",
ATTR_VALUE: 75,
},
),
],
)
)
assert event1["name"] == "HomeKit"
assert event1["domain"] == DOMAIN_HOMEKIT
assert event1["message"] == "send command lock for Front Door"
assert event1["entity_id"] == "lock.front_door"
assert event2["name"] == "HomeKit"
assert event2["domain"] == DOMAIN_HOMEKIT
assert event2["message"] == "send command set_cover_position to 75 for Window"
assert event2["entity_id"] == "cover.window"
async def test_humanify_automation_triggered_event(hass):
"""Test humanifying Automation Trigger event."""
event1, event2 = list(
logbook.humanify(
hass,
[
ha.Event(
EVENT_AUTOMATION_TRIGGERED,
{ATTR_ENTITY_ID: "automation.hello", ATTR_NAME: "Hello Automation"},
),
ha.Event(
EVENT_AUTOMATION_TRIGGERED,
{ATTR_ENTITY_ID: "automation.bye", ATTR_NAME: "Bye Automation"},
),
],
)
)
assert event1["name"] == "Hello Automation"
assert event1["domain"] == "automation"
assert event1["message"] == "has been triggered"
assert event1["entity_id"] == "automation.hello"
assert event2["name"] == "Bye Automation"
assert event2["domain"] == "automation"
assert event2["message"] == "has been triggered"
assert event2["entity_id"] == "automation.bye"
async def test_humanify_script_started_event(hass):
"""Test humanifying Script Run event."""
event1, event2 = list(
logbook.humanify(
hass,
[
ha.Event(
EVENT_SCRIPT_STARTED,
{ATTR_ENTITY_ID: "script.hello", ATTR_NAME: "Hello Script"},
),
ha.Event(
EVENT_SCRIPT_STARTED,
{ATTR_ENTITY_ID: "script.bye", ATTR_NAME: "Bye Script"},
),
],
)
)
assert event1["name"] == "Hello Script"
assert event1["domain"] == "script"
assert event1["message"] == "started"
assert event1["entity_id"] == "script.hello"
assert event2["name"] == "Bye Script"
assert event2["domain"] == "script"
assert event2["message"] == "started"
assert event2["entity_id"] == "script.bye"
|
apache-2.0
|
[
624,
1918,
2295,
367,
314,
943,
2706,
3931,
1041,
199,
3,
4287,
26,
3507,
29,
6798,
13,
2732,
12,
3197,
13,
354,
199,
646,
2050,
199,
504,
2197,
492,
6871,
12,
2197,
199,
646,
2882,
199,
199,
646,
4613,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
4608,
492,
26668,
199,
646,
8846,
14,
1018,
465,
18251,
199,
504,
8846,
14,
1297,
492,
334,
272,
10762,
63,
13630,
63,
998,
12,
272,
10762,
63,
10486,
12,
272,
10762,
63,
2339,
12,
272,
6461,
63,
6689,
63,
21488,
12,
272,
6461,
63,
9524,
16435,
840,
1441,
63,
7363,
12,
272,
6461,
63,
9524,
16435,
840,
1441,
63,
11632,
12,
272,
6461,
63,
10774,
7474,
2594,
63,
30073,
1149,
12,
272,
6461,
63,
10484,
63,
32385,
12,
272,
10762,
63,
40,
22436,
12,
272,
11377,
63,
4609,
63,
9524,
12,
272,
11377,
63,
615,
12,
272,
11377,
63,
7517,
12,
199,
9,
199,
646,
8846,
14,
1974,
14,
3583,
465,
4487,
63,
1974,
199,
504,
8846,
14,
4608,
492,
943,
2706,
12,
295,
16940,
199,
504,
8846,
14,
4608,
14,
1895,
1800,
14,
7853,
63,
4219,
492,
6461,
63,
748,
1438,
33,
63,
4029,
2294,
63,
9524,
199,
504,
8846,
14,
4608,
14,
4219,
6065,
14,
1297,
492,
334,
272,
10762,
63,
20993,
63,
2339,
12,
272,
10762,
63,
7041,
12,
272,
15265,
465,
15265,
63,
9524,
43,
649,
12,
272,
6461,
63,
9524,
43,
649,
63,
21488,
12,
199,
9,
199,
504,
8846,
14,
2758,
492,
3272,
63,
3173,
12,
5316,
63,
2758,
63,
3173,
199,
199,
504,
2295,
14,
2330,
492,
4205,
63,
27733,
63,
3173,
12,
664,
63,
396,
63,
4219,
63,
7310,
421,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
1379,
7004,
2445,
2706,
8,
2796,
14,
1746,
304,
272,
408,
774,
314,
27829,
3931,
1041,
339,
16589,
63,
5569,
275,
943,
2706,
14,
5569,
63,
10926,
2561,
793,
2706,
14,
7378,
26,
1052,
1552,
339,
347,
3613,
8,
277,
304,
267,
408,
1084,
1536,
7645,
370,
506,
1255,
1380,
2295,
787,
8239,
1041,
267,
291,
14,
5387,
275,
664,
63,
396,
63,
4219,
63,
7310,
342,
267,
4205,
63,
27733,
63,
3173,
8,
277,
14,
5387,
9,
221,
327,
18771,
376,
315,
4402,
6249,
267,
702,
3272,
63,
3173,
8,
277,
14,
5387,
12,
943,
2706,
14,
7378,
12,
291,
14,
13993,
63,
5569,
9,
267,
291,
14,
5387,
14,
928,
342,
339,
347,
6766,
8,
277,
304,
267,
408,
6293,
8137,
626,
1990,
8239,
1041,
267,
291,
14,
5387,
14,
2379,
342,
339,
347,
511,
63,
1364,
63,
1250,
63,
981,
63,
793,
2706,
63,
2373,
8,
277,
304,
267,
408,
774,
340,
2435,
1240,
1218,
943,
6719,
2397,
1041,
267,
4882,
275,
942,
398,
768,
2411,
14,
3058,
267,
347,
1566,
63,
9799,
8,
1430,
304,
288,
408,
8310,
641,
1566,
1041,
288,
4882,
14,
740,
8,
1430,
9,
398,
291,
14,
5387,
14,
5610,
14,
5859,
8,
793,
2706,
14,
8193,
63,
4947,
21155,
63,
7285,
12,
1566,
63,
9799,
9,
267,
291,
14,
5387,
14,
5950,
14,
1250,
8,
288,
943,
2706,
14,
7378,
12,
288,
298,
793,
401,
288,
469,
355,
943,
2706,
14,
5280,
63,
2339,
26,
298,
30655,
401,
355,
943,
2706,
14,
5280,
63,
8272,
26,
298,
374,
15572,
401,
355,
943,
2706,
14,
5280,
63,
7378,
26,
298,
5656,
401,
355,
943,
2706,
14,
5280,
63,
13630,
63,
998,
26,
298,
5656,
14,
396,
63,
5656,
401,
288,
1660,
288,
715,
12,
267,
776,
398,
327,
5297,
2706,
2397,
2435,
1240,
2058,
315,
289,
16648,
376,
1566,
14,
267,
327,
25119,
2435,
1240,
911,
625,
1457,
1380,
314,
1566,
19946,
1172,
2757,
267,
327,
18416,
14,
961,
4910,
626,
2985,
1443,
440,
1172,
2757,
7686,
5966,
14,
267,
291,
14,
5387,
14,
1457,
63,
12587,
63,
4456,
342,
267,
291,
14,
5387,
14,
576,
59,
27733,
14,
3998,
63,
18235,
1055,
1457,
63,
12587,
63,
4456,
342,
398,
4474,
275,
769,
8,
288,
943,
2706,
423,
362,
63,
4368,
8,
355,
291,
14,
5387,
12,
355,
5479,
355,
4487,
63,
1974,
14,
10779,
342,
446,
6871,
8,
8419,
29,
17,
395,
355,
4487,
63,
1974,
14,
10779,
342,
435,
6871,
8,
8419,
29,
17,
395,
288,
776,
267,
776,
267,
702,
822,
8,
4368,
9,
508,
499,
398,
702,
413,
508,
822,
8,
5352,
9,
267,
2061,
63,
1250,
275,
4882,
1988,
17,
61,
398,
702,
298,
30655,
2,
508,
2061,
63,
1250,
14,
576,
14,
362,
8,
793,
2706,
14,
5280,
63,
2339,
9,
267,
702,
298,
374,
15572,
2,
508,
2061,
63,
1250,
14,
576,
14,
362,
8,
793,
2706,
14,
5280,
63,
8272,
9,
267,
702,
298,
5656,
2,
508,
2061,
63,
1250,
14,
576,
14,
362,
8,
793,
2706,
14,
5280,
63,
7378,
9,
267,
702,
298,
5656,
14,
396,
63,
5656,
2,
508,
2061,
63,
1250,
14,
576,
14,
362,
8,
793,
2706,
14,
5280,
63,
13630,
63,
998,
9,
339,
347,
511,
63,
1364,
63,
1250,
63,
981,
63,
793,
63,
2706,
63,
2373,
63,
889,
63,
1188,
8,
277,
304,
267,
408,
774,
340,
2435,
1240,
1218,
943,
6719,
2397,
1928,
1245,
1041,
267,
4882,
275,
942,
398,
768,
2411,
14,
3058,
267,
347,
1566,
63,
9799,
8,
1430,
304,
288,
408,
8310,
641,
1566,
1041,
288,
4882,
14,
740,
8,
1430,
9,
398,
291,
14,
5387,
14,
5610,
14,
5859,
8,
793,
2706,
14,
8193,
63,
4947,
21155,
63,
7285,
12,
1566,
63,
9799,
9,
398,
543,
4613,
14,
3536,
8,
5650,
14,
3364,
304,
288,
291,
14,
5387,
14,
5950,
14,
1250,
8,
793,
2706,
14,
7378,
12,
298,
793,
401,
5479,
715,
9,
398,
327,
5297,
2706,
2397,
2435,
1240,
2058,
315,
289,
16648,
376,
1566,
14,
267,
327,
25119,
2435,
1240,
911,
625,
1457,
1380,
314,
1566,
19946,
1172,
2757,
267,
327,
18416,
14,
961,
4910,
626,
2985,
1443,
440,
1172,
2757,
7686,
5966,
14,
267,
291,
14,
5387,
14,
1457,
63,
12587,
63,
4456,
342,
398,
702,
378,
508,
822,
8,
5352,
9,
339,
347,
511,
63,
14864,
2021,
63,
1541,
63,
8956,
8,
277,
304,
267,
408,
774,
11779,
2021,
2457
] |
[
1918,
2295,
367,
314,
943,
2706,
3931,
1041,
199,
3,
4287,
26,
3507,
29,
6798,
13,
2732,
12,
3197,
13,
354,
199,
646,
2050,
199,
504,
2197,
492,
6871,
12,
2197,
199,
646,
2882,
199,
199,
646,
4613,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
4608,
492,
26668,
199,
646,
8846,
14,
1018,
465,
18251,
199,
504,
8846,
14,
1297,
492,
334,
272,
10762,
63,
13630,
63,
998,
12,
272,
10762,
63,
10486,
12,
272,
10762,
63,
2339,
12,
272,
6461,
63,
6689,
63,
21488,
12,
272,
6461,
63,
9524,
16435,
840,
1441,
63,
7363,
12,
272,
6461,
63,
9524,
16435,
840,
1441,
63,
11632,
12,
272,
6461,
63,
10774,
7474,
2594,
63,
30073,
1149,
12,
272,
6461,
63,
10484,
63,
32385,
12,
272,
10762,
63,
40,
22436,
12,
272,
11377,
63,
4609,
63,
9524,
12,
272,
11377,
63,
615,
12,
272,
11377,
63,
7517,
12,
199,
9,
199,
646,
8846,
14,
1974,
14,
3583,
465,
4487,
63,
1974,
199,
504,
8846,
14,
4608,
492,
943,
2706,
12,
295,
16940,
199,
504,
8846,
14,
4608,
14,
1895,
1800,
14,
7853,
63,
4219,
492,
6461,
63,
748,
1438,
33,
63,
4029,
2294,
63,
9524,
199,
504,
8846,
14,
4608,
14,
4219,
6065,
14,
1297,
492,
334,
272,
10762,
63,
20993,
63,
2339,
12,
272,
10762,
63,
7041,
12,
272,
15265,
465,
15265,
63,
9524,
43,
649,
12,
272,
6461,
63,
9524,
43,
649,
63,
21488,
12,
199,
9,
199,
504,
8846,
14,
2758,
492,
3272,
63,
3173,
12,
5316,
63,
2758,
63,
3173,
199,
199,
504,
2295,
14,
2330,
492,
4205,
63,
27733,
63,
3173,
12,
664,
63,
396,
63,
4219,
63,
7310,
421,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
1379,
7004,
2445,
2706,
8,
2796,
14,
1746,
304,
272,
408,
774,
314,
27829,
3931,
1041,
339,
16589,
63,
5569,
275,
943,
2706,
14,
5569,
63,
10926,
2561,
793,
2706,
14,
7378,
26,
1052,
1552,
339,
347,
3613,
8,
277,
304,
267,
408,
1084,
1536,
7645,
370,
506,
1255,
1380,
2295,
787,
8239,
1041,
267,
291,
14,
5387,
275,
664,
63,
396,
63,
4219,
63,
7310,
342,
267,
4205,
63,
27733,
63,
3173,
8,
277,
14,
5387,
9,
221,
327,
18771,
376,
315,
4402,
6249,
267,
702,
3272,
63,
3173,
8,
277,
14,
5387,
12,
943,
2706,
14,
7378,
12,
291,
14,
13993,
63,
5569,
9,
267,
291,
14,
5387,
14,
928,
342,
339,
347,
6766,
8,
277,
304,
267,
408,
6293,
8137,
626,
1990,
8239,
1041,
267,
291,
14,
5387,
14,
2379,
342,
339,
347,
511,
63,
1364,
63,
1250,
63,
981,
63,
793,
2706,
63,
2373,
8,
277,
304,
267,
408,
774,
340,
2435,
1240,
1218,
943,
6719,
2397,
1041,
267,
4882,
275,
942,
398,
768,
2411,
14,
3058,
267,
347,
1566,
63,
9799,
8,
1430,
304,
288,
408,
8310,
641,
1566,
1041,
288,
4882,
14,
740,
8,
1430,
9,
398,
291,
14,
5387,
14,
5610,
14,
5859,
8,
793,
2706,
14,
8193,
63,
4947,
21155,
63,
7285,
12,
1566,
63,
9799,
9,
267,
291,
14,
5387,
14,
5950,
14,
1250,
8,
288,
943,
2706,
14,
7378,
12,
288,
298,
793,
401,
288,
469,
355,
943,
2706,
14,
5280,
63,
2339,
26,
298,
30655,
401,
355,
943,
2706,
14,
5280,
63,
8272,
26,
298,
374,
15572,
401,
355,
943,
2706,
14,
5280,
63,
7378,
26,
298,
5656,
401,
355,
943,
2706,
14,
5280,
63,
13630,
63,
998,
26,
298,
5656,
14,
396,
63,
5656,
401,
288,
1660,
288,
715,
12,
267,
776,
398,
327,
5297,
2706,
2397,
2435,
1240,
2058,
315,
289,
16648,
376,
1566,
14,
267,
327,
25119,
2435,
1240,
911,
625,
1457,
1380,
314,
1566,
19946,
1172,
2757,
267,
327,
18416,
14,
961,
4910,
626,
2985,
1443,
440,
1172,
2757,
7686,
5966,
14,
267,
291,
14,
5387,
14,
1457,
63,
12587,
63,
4456,
342,
267,
291,
14,
5387,
14,
576,
59,
27733,
14,
3998,
63,
18235,
1055,
1457,
63,
12587,
63,
4456,
342,
398,
4474,
275,
769,
8,
288,
943,
2706,
423,
362,
63,
4368,
8,
355,
291,
14,
5387,
12,
355,
5479,
355,
4487,
63,
1974,
14,
10779,
342,
446,
6871,
8,
8419,
29,
17,
395,
355,
4487,
63,
1974,
14,
10779,
342,
435,
6871,
8,
8419,
29,
17,
395,
288,
776,
267,
776,
267,
702,
822,
8,
4368,
9,
508,
499,
398,
702,
413,
508,
822,
8,
5352,
9,
267,
2061,
63,
1250,
275,
4882,
1988,
17,
61,
398,
702,
298,
30655,
2,
508,
2061,
63,
1250,
14,
576,
14,
362,
8,
793,
2706,
14,
5280,
63,
2339,
9,
267,
702,
298,
374,
15572,
2,
508,
2061,
63,
1250,
14,
576,
14,
362,
8,
793,
2706,
14,
5280,
63,
8272,
9,
267,
702,
298,
5656,
2,
508,
2061,
63,
1250,
14,
576,
14,
362,
8,
793,
2706,
14,
5280,
63,
7378,
9,
267,
702,
298,
5656,
14,
396,
63,
5656,
2,
508,
2061,
63,
1250,
14,
576,
14,
362,
8,
793,
2706,
14,
5280,
63,
13630,
63,
998,
9,
339,
347,
511,
63,
1364,
63,
1250,
63,
981,
63,
793,
63,
2706,
63,
2373,
63,
889,
63,
1188,
8,
277,
304,
267,
408,
774,
340,
2435,
1240,
1218,
943,
6719,
2397,
1928,
1245,
1041,
267,
4882,
275,
942,
398,
768,
2411,
14,
3058,
267,
347,
1566,
63,
9799,
8,
1430,
304,
288,
408,
8310,
641,
1566,
1041,
288,
4882,
14,
740,
8,
1430,
9,
398,
291,
14,
5387,
14,
5610,
14,
5859,
8,
793,
2706,
14,
8193,
63,
4947,
21155,
63,
7285,
12,
1566,
63,
9799,
9,
398,
543,
4613,
14,
3536,
8,
5650,
14,
3364,
304,
288,
291,
14,
5387,
14,
5950,
14,
1250,
8,
793,
2706,
14,
7378,
12,
298,
793,
401,
5479,
715,
9,
398,
327,
5297,
2706,
2397,
2435,
1240,
2058,
315,
289,
16648,
376,
1566,
14,
267,
327,
25119,
2435,
1240,
911,
625,
1457,
1380,
314,
1566,
19946,
1172,
2757,
267,
327,
18416,
14,
961,
4910,
626,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
MicroPyramid/forex-python
|
setup.py
|
1
|
1589
|
import io
import os
from setuptools import setup, find_packages
VERSION = '1.6'
long_description_text = """Forex Python is a Free Foreign exchange rates and currency conversion.
Features:
List all currency rates.
BitCoin price for all curuncies.
Converting amount to BitCoins.
Get historical rates for any day since 1999.
Conversion rate for one currency(ex; USD to INR).
Convert amount from one currency to other.('USD 10$' to INR).
Currency symbols.
Currency names.
Documentation: http://forex-python.readthedocs.io/en/latest/usage.html
GitHub: https://github.com/MicroPyramid/forex-python
"""
setup(
name='forex-python',
version=VERSION,
author='Micro Pyramid Informatic Pvt. Ltd.',
author_email='hello@micropyramid.com',
url='https://github.com/MicroPyramid/forex-python',
description='Foreign exchange rates and currency conversion.',
long_description=long_description_text,
packages=find_packages(exclude=['tests', 'tests.*']),
include_package_data=True,
install_requires=[
'requests',
'simplejson',
],
classifiers=[
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Topic :: Software Development :: Internationalization',
],
)
|
mit
|
[
646,
5890,
199,
646,
747,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
199,
199,
4612,
275,
283,
17,
14,
22,
7,
199,
2809,
63,
1802,
63,
505,
275,
408,
13099,
88,
2018,
365,
282,
2868,
481,
2692,
15343,
24434,
436,
9952,
8603,
14,
199,
10807,
26,
199,
1296,
1006,
9952,
24434,
14,
199,
4734,
967,
262,
8033,
367,
1006,
1094,
324,
2578,
14,
199,
7619,
1337,
5982,
370,
10199,
967,
3617,
14,
199,
1002,
32530,
24434,
367,
1263,
5382,
3967,
21300,
14,
199,
20403,
6634,
367,
1373,
9952,
8,
476,
27,
738,
3693,
370,
1621,
50,
680,
199,
7306,
5982,
687,
1373,
9952,
370,
1163,
14,
360,
1668,
36,
1616,
12913,
370,
1621,
50,
680,
199,
19567,
6698,
14,
199,
19567,
1561,
14,
199,
199,
17763,
26,
1455,
921,
1707,
88,
13,
1548,
14,
25085,
14,
2308,
15,
287,
15,
7410,
15,
3807,
14,
1360,
199,
14686,
15338,
26,
4178,
921,
5031,
14,
957,
15,
23990,
2713,
20785,
15,
1707,
88,
13,
1548,
199,
199,
624,
199,
199,
2758,
8,
272,
536,
534,
1707,
88,
13,
1548,
297,
272,
1015,
29,
4612,
12,
272,
4132,
534,
23990,
1611,
20785,
1010,
509,
3889,
29053,
14,
12126,
3130,
272,
4132,
63,
2123,
534,
5006,
32,
6453,
647,
20785,
14,
957,
297,
272,
1166,
534,
2859,
921,
5031,
14,
957,
15,
23990,
2713,
20785,
15,
1707,
88,
13,
1548,
297,
272,
1369,
534,
20931,
15343,
24434,
436,
9952,
8603,
3130,
272,
1846,
63,
1802,
29,
2809,
63,
1802,
63,
505,
12,
272,
6117,
29,
1623,
63,
5154,
8,
5473,
2968,
2219,
297,
283,
2219,
2795,
3815,
272,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
3907,
63,
6537,
1524,
267,
283,
6615,
297,
267,
283,
4129,
1001,
297,
272,
2156,
272,
19137,
1524,
267,
283,
23910,
23975,
3800,
23493,
297,
267,
283,
23699,
6187,
3800,
4403,
1010,
7106,
297,
267,
283,
3761,
3800,
25718,
26330,
3800,
10697,
844,
297,
267,
283,
11411,
8466,
3800,
2018,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
19,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
20,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
21,
297,
267,
283,
12157,
3800,
2290,
15290,
3800,
28220,
2072,
297,
272,
2156,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
5890,
199,
646,
747,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
199,
199,
4612,
275,
283,
17,
14,
22,
7,
199,
2809,
63,
1802,
63,
505,
275,
408,
13099,
88,
2018,
365,
282,
2868,
481,
2692,
15343,
24434,
436,
9952,
8603,
14,
199,
10807,
26,
199,
1296,
1006,
9952,
24434,
14,
199,
4734,
967,
262,
8033,
367,
1006,
1094,
324,
2578,
14,
199,
7619,
1337,
5982,
370,
10199,
967,
3617,
14,
199,
1002,
32530,
24434,
367,
1263,
5382,
3967,
21300,
14,
199,
20403,
6634,
367,
1373,
9952,
8,
476,
27,
738,
3693,
370,
1621,
50,
680,
199,
7306,
5982,
687,
1373,
9952,
370,
1163,
14,
360,
1668,
36,
1616,
12913,
370,
1621,
50,
680,
199,
19567,
6698,
14,
199,
19567,
1561,
14,
199,
199,
17763,
26,
1455,
921,
1707,
88,
13,
1548,
14,
25085,
14,
2308,
15,
287,
15,
7410,
15,
3807,
14,
1360,
199,
14686,
15338,
26,
4178,
921,
5031,
14,
957,
15,
23990,
2713,
20785,
15,
1707,
88,
13,
1548,
199,
199,
624,
199,
199,
2758,
8,
272,
536,
534,
1707,
88,
13,
1548,
297,
272,
1015,
29,
4612,
12,
272,
4132,
534,
23990,
1611,
20785,
1010,
509,
3889,
29053,
14,
12126,
3130,
272,
4132,
63,
2123,
534,
5006,
32,
6453,
647,
20785,
14,
957,
297,
272,
1166,
534,
2859,
921,
5031,
14,
957,
15,
23990,
2713,
20785,
15,
1707,
88,
13,
1548,
297,
272,
1369,
534,
20931,
15343,
24434,
436,
9952,
8603,
3130,
272,
1846,
63,
1802,
29,
2809,
63,
1802,
63,
505,
12,
272,
6117,
29,
1623,
63,
5154,
8,
5473,
2968,
2219,
297,
283,
2219,
2795,
3815,
272,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
3907,
63,
6537,
1524,
267,
283,
6615,
297,
267,
283,
4129,
1001,
297,
272,
2156,
272,
19137,
1524,
267,
283,
23910,
23975,
3800,
23493,
297,
267,
283,
23699,
6187,
3800,
4403,
1010,
7106,
297,
267,
283,
3761,
3800,
25718,
26330,
3800,
10697,
844,
297,
267,
283,
11411,
8466,
3800,
2018,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
19,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
20,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
21,
297,
267,
283,
12157,
3800,
2290,
15290,
3800,
28220,
2072,
297,
272,
2156,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
KaranToor/MA450
|
google-cloud-sdk/lib/surface/deployment_manager/runtime_configs/create.py
|
2
|
2929
|
# Copyright 2016 Google Inc. All Rights Reserved.
#
# 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.
"""The runtime-configs create command."""
from googlecloudsdk.api_lib.deployment_manager.runtime_configs import util
from googlecloudsdk.calliope import base
from googlecloudsdk.core import log
class Create(base.CreateCommand):
"""Create runtime-config resources.
This command creates a new runtime-config resource with the specified name
and optional description.
"""
detailed_help = {
'DESCRIPTION': '{description}',
'EXAMPLES': """\
To create a runtime-config resource named "my-config", run:
$ {command} my-config
To create a runtime-config resource named "my-config" with a
description, run:
$ {command} --description "my new configuration" my-config
""",
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Args:
parser: An argparse parser that you can use to add arguments that go
on the command line after this command. Positional arguments are
allowed.
"""
parser.add_argument(
'--description',
help='Optional description of the runtime-config resource.')
parser.add_argument('name', help='The runtime-config resource name.')
def Collection(self):
"""Returns the default collection path string.
Returns:
The default collection path string.
"""
return 'runtimeconfig.configurations'
def Run(self, args):
"""Run 'runtime-configs create'.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
Returns:
The new runtime-config resource.
Raises:
HttpException: An http error response was received while executing api
request.
"""
config_client = util.ConfigClient()
messages = util.Messages()
config_resource = util.ParseConfigName(args.name)
project = config_resource.projectsId
result = config_client.Create(
messages.RuntimeconfigProjectsConfigsCreateRequest(
parent=util.ProjectPath(project),
runtimeConfig=messages.RuntimeConfig(
name=config_resource.RelativeName(),
description=args.description,
)
)
)
log.CreatedResource(config_resource)
return util.FormatConfig(result)
|
apache-2.0
|
[
3,
1898,
7800,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
1918,
8836,
13,
7532,
1218,
1414,
1041,
199,
199,
504,
6233,
29691,
6341,
14,
1246,
63,
773,
14,
13605,
63,
2609,
14,
7726,
63,
7532,
492,
4884,
199,
504,
6233,
29691,
6341,
14,
915,
317,
13458,
492,
1300,
199,
504,
6233,
29691,
6341,
14,
1018,
492,
943,
421,
199,
533,
2790,
8,
1095,
14,
2499,
3110,
304,
523,
408,
2499,
8836,
13,
888,
5944,
14,
819,
961,
1414,
8491,
282,
892,
8836,
13,
888,
2073,
543,
314,
2013,
536,
523,
436,
2716,
1369,
14,
523,
408,
819,
16212,
63,
3437,
275,
469,
489,
283,
17705,
356,
5041,
1802,
7293,
489,
283,
8918,
356,
9638,
881,
4005,
1218,
282,
8836,
13,
888,
2073,
4310,
298,
1662,
13,
888,
401,
1255,
26,
953,
2672,
469,
1531,
93,
3002,
13,
888,
8592,
4005,
1218,
282,
8836,
13,
888,
2073,
4310,
298,
1662,
13,
888,
2,
543,
282,
881,
1369,
12,
1255,
26,
953,
2672,
469,
1531,
93,
1553,
1802,
298,
1662,
892,
2897,
2,
3002,
13,
888,
881,
10327,
523,
789,
819,
768,
4639,
523,
347,
3033,
8,
2087,
304,
272,
408,
6213,
365,
2797,
701,
3213,
317,
13458,
370,
13082,
2368,
367,
642,
1414,
14,
339,
3033,
26,
489,
1798,
26,
1626,
7534,
1798,
626,
1265,
883,
675,
370,
1050,
2368,
626,
2621,
881,
641,
314,
1414,
1004,
2410,
642,
1414,
14,
15483,
279,
2368,
787,
881,
4370,
14,
272,
408,
272,
1798,
14,
525,
63,
2094,
8,
267,
2850,
1802,
297,
267,
1720,
534,
7012,
1369,
402,
314,
8836,
13,
888,
2073,
2659,
339,
1798,
14,
525,
63,
2094,
360,
354,
297,
1720,
534,
1918,
8836,
13,
888,
2073,
536,
2659,
819,
347,
18003,
8,
277,
304,
272,
408,
3407,
314,
849,
3245,
931,
1059,
14,
339,
1803,
26,
489,
710,
849,
3245,
931,
1059,
14,
272,
408,
272,
372,
283,
7726,
888,
14,
10057,
7,
819,
347,
3378,
8,
277,
12,
1249,
304,
272,
408,
2540,
283,
7726,
13,
7532,
1218,
1370,
339,
3033,
26,
489,
1249,
26,
7534,
14,
8814,
12,
710,
2368,
626,
642,
1414,
1990,
10302,
881,
543,
14,
339,
1803,
26,
489,
710,
892,
8836,
13,
888,
2073,
14,
339,
6218,
26,
489,
4760,
1726,
26,
1626,
1455,
1125,
1177,
1990,
3086,
1830,
14043,
2986,
881,
1056,
14,
272,
408,
272,
1101,
63,
1258,
275,
4884,
14,
2028,
3041,
342,
272,
3788,
275,
4884,
14,
14508,
342,
339,
1101,
63,
1927,
275,
4884,
14,
4003,
2028,
985,
8,
589,
14,
354,
9,
272,
2199,
275,
1101,
63,
1927,
14,
6776,
1304,
339,
754,
275,
1101,
63,
1258,
14,
2499,
8,
267,
3788,
14,
14357,
888,
24286,
29123,
2499,
2017,
8,
288,
1676,
29,
1974,
14,
4761,
2042,
8,
1715,
395,
288,
8836,
2028,
29,
3431,
14,
14357,
2028,
8,
355,
536,
29,
888,
63,
1927,
14,
15277,
985,
1062,
355,
1369,
29,
589,
14,
1802,
12,
288,
776,
267,
776,
272,
776,
339,
943,
14,
10502,
4031,
8,
888,
63,
1927,
9,
272,
372,
4884,
14,
3484,
2028,
8,
1099,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
7800,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
1918,
8836,
13,
7532,
1218,
1414,
1041,
199,
199,
504,
6233,
29691,
6341,
14,
1246,
63,
773,
14,
13605,
63,
2609,
14,
7726,
63,
7532,
492,
4884,
199,
504,
6233,
29691,
6341,
14,
915,
317,
13458,
492,
1300,
199,
504,
6233,
29691,
6341,
14,
1018,
492,
943,
421,
199,
533,
2790,
8,
1095,
14,
2499,
3110,
304,
523,
408,
2499,
8836,
13,
888,
5944,
14,
819,
961,
1414,
8491,
282,
892,
8836,
13,
888,
2073,
543,
314,
2013,
536,
523,
436,
2716,
1369,
14,
523,
408,
819,
16212,
63,
3437,
275,
469,
489,
283,
17705,
356,
5041,
1802,
7293,
489,
283,
8918,
356,
9638,
881,
4005,
1218,
282,
8836,
13,
888,
2073,
4310,
298,
1662,
13,
888,
401,
1255,
26,
953,
2672,
469,
1531,
93,
3002,
13,
888,
8592,
4005,
1218,
282,
8836,
13,
888,
2073,
4310,
298,
1662,
13,
888,
2,
543,
282,
881,
1369,
12,
1255,
26,
953,
2672,
469,
1531,
93,
1553,
1802,
298,
1662,
892,
2897,
2,
3002,
13,
888,
881,
10327,
523,
789,
819,
768,
4639,
523,
347,
3033,
8,
2087,
304,
272,
408,
6213,
365,
2797,
701,
3213,
317,
13458,
370,
13082,
2368,
367,
642,
1414,
14,
339,
3033,
26,
489,
1798,
26,
1626,
7534,
1798,
626,
1265,
883,
675,
370,
1050,
2368,
626,
2621,
881,
641,
314,
1414,
1004,
2410,
642,
1414,
14,
15483,
279,
2368,
787,
881,
4370,
14,
272,
408,
272,
1798,
14,
525,
63,
2094,
8,
267,
2850,
1802,
297,
267,
1720,
534,
7012,
1369,
402,
314,
8836,
13,
888,
2073,
2659,
339,
1798,
14,
525,
63,
2094,
360,
354,
297,
1720,
534,
1918,
8836,
13,
888,
2073,
536,
2659,
819,
347,
18003,
8,
277,
304,
272,
408,
3407,
314,
849,
3245,
931,
1059,
14,
339,
1803,
26,
489,
710,
849,
3245,
931,
1059,
14,
272,
408,
272,
372,
283,
7726,
888,
14,
10057,
7,
819,
347,
3378,
8,
277,
12,
1249,
304,
272,
408,
2540,
283,
7726,
13,
7532,
1218,
1370,
339,
3033,
26,
489,
1249,
26,
7534,
14,
8814,
12,
710,
2368,
626,
642,
1414,
1990,
10302,
881,
543,
14,
339,
1803,
26,
489,
710,
892,
8836,
13,
888,
2073,
14,
339,
6218,
26,
489,
4760,
1726,
26,
1626,
1455,
1125,
1177,
1990,
3086,
1830,
14043,
2986,
881,
1056,
14,
272,
408,
272,
1101,
63,
1258,
275,
4884,
14,
2028,
3041,
342,
272,
3788,
275,
4884,
14,
14508,
342,
339,
1101,
63,
1927,
275,
4884,
14,
4003,
2028,
985,
8,
589,
14,
354,
9,
272,
2199,
275,
1101,
63,
1927,
14,
6776,
1304,
339,
754,
275,
1101,
63,
1258,
14,
2499,
8,
267,
3788,
14,
14357,
888,
24286,
29123,
2499,
2017,
8,
288,
1676,
29,
1974,
14,
4761,
2042,
8,
1715,
395,
288,
8836,
2028,
29,
3431,
14,
14357,
2028,
8,
355,
536,
29,
888,
63,
1927,
14,
15277,
985,
1062,
355,
1369,
29,
589,
14,
1802,
12,
288,
776,
267,
776,
272,
776,
339,
943,
14,
10502,
4031,
8,
888,
63,
1927,
9,
272,
372,
4884,
14,
3484,
2028,
8,
1099,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
URXtech/scrapy
|
tests/test_spidermiddleware_httperror.py
|
125
|
6935
|
from unittest import TestCase
from testfixtures import LogCapture
from twisted.trial.unittest import TestCase as TrialTestCase
from twisted.internet import defer
from scrapy.utils.test import get_crawler
from tests.mockserver import MockServer
from scrapy.http import Response, Request
from scrapy.spiders import Spider
from scrapy.spidermiddlewares.httperror import HttpErrorMiddleware, HttpError
from scrapy.settings import Settings
class _HttpErrorSpider(Spider):
name = 'httperror'
start_urls = [
"http://localhost:8998/status?n=200",
"http://localhost:8998/status?n=404",
"http://localhost:8998/status?n=402",
"http://localhost:8998/status?n=500",
]
bypass_status_codes = set()
def __init__(self, *args, **kwargs):
super(_HttpErrorSpider, self).__init__(*args, **kwargs)
self.failed = set()
self.skipped = set()
self.parsed = set()
def start_requests(self):
for url in self.start_urls:
yield Request(url, self.parse, errback=self.on_error)
def parse(self, response):
self.parsed.add(response.url[-3:])
def on_error(self, failure):
if isinstance(failure.value, HttpError):
response = failure.value.response
if response.status in self.bypass_status_codes:
self.skipped.add(response.url[-3:])
return self.parse(response)
# it assumes there is a response attached to failure
self.failed.add(failure.value.response.url[-3:])
return failure
def _responses(request, status_codes):
responses = []
for code in status_codes:
response = Response(request.url, status=code)
response.request = request
responses.append(response)
return responses
class TestHttpErrorMiddleware(TestCase):
def setUp(self):
self.spider = Spider('foo')
self.mw = HttpErrorMiddleware(Settings({}))
self.req = Request('http://scrapytest.org')
self.res200, self.res404 = _responses(self.req, [200, 404])
def test_process_spider_input(self):
self.assertEquals(None,
self.mw.process_spider_input(self.res200, self.spider))
self.assertRaises(HttpError,
self.mw.process_spider_input, self.res404, self.spider)
def test_process_spider_exception(self):
self.assertEquals([],
self.mw.process_spider_exception(self.res404, \
HttpError(self.res404), self.spider))
self.assertEquals(None,
self.mw.process_spider_exception(self.res404, \
Exception(), self.spider))
def test_handle_httpstatus_list(self):
res = self.res404.copy()
res.request = Request('http://scrapytest.org',
meta={'handle_httpstatus_list': [404]})
self.assertEquals(None,
self.mw.process_spider_input(res, self.spider))
self.spider.handle_httpstatus_list = [404]
self.assertEquals(None,
self.mw.process_spider_input(self.res404, self.spider))
class TestHttpErrorMiddlewareSettings(TestCase):
"""Similar test, but with settings"""
def setUp(self):
self.spider = Spider('foo')
self.mw = HttpErrorMiddleware(Settings({'HTTPERROR_ALLOWED_CODES': (402,)}))
self.req = Request('http://scrapytest.org')
self.res200, self.res404, self.res402 = _responses(self.req, [200, 404, 402])
def test_process_spider_input(self):
self.assertEquals(None,
self.mw.process_spider_input(self.res200, self.spider))
self.assertRaises(HttpError,
self.mw.process_spider_input, self.res404, self.spider)
self.assertEquals(None,
self.mw.process_spider_input(self.res402, self.spider))
def test_meta_overrides_settings(self):
request = Request('http://scrapytest.org',
meta={'handle_httpstatus_list': [404]})
res404 = self.res404.copy()
res404.request = request
res402 = self.res402.copy()
res402.request = request
self.assertEquals(None,
self.mw.process_spider_input(res404, self.spider))
self.assertRaises(HttpError,
self.mw.process_spider_input, res402, self.spider)
def test_spider_override_settings(self):
self.spider.handle_httpstatus_list = [404]
self.assertEquals(None,
self.mw.process_spider_input(self.res404, self.spider))
self.assertRaises(HttpError,
self.mw.process_spider_input, self.res402, self.spider)
class TestHttpErrorMiddlewareHandleAll(TestCase):
def setUp(self):
self.spider = Spider('foo')
self.mw = HttpErrorMiddleware(Settings({'HTTPERROR_ALLOW_ALL': True}))
self.req = Request('http://scrapytest.org')
self.res200, self.res404, self.res402 = _responses(self.req, [200, 404, 402])
def test_process_spider_input(self):
self.assertEquals(None,
self.mw.process_spider_input(self.res200, self.spider))
self.assertEquals(None,
self.mw.process_spider_input(self.res404, self.spider))
def test_meta_overrides_settings(self):
request = Request('http://scrapytest.org',
meta={'handle_httpstatus_list': [404]})
res404 = self.res404.copy()
res404.request = request
res402 = self.res402.copy()
res402.request = request
self.assertEquals(None,
self.mw.process_spider_input(res404, self.spider))
self.assertRaises(HttpError,
self.mw.process_spider_input, res402, self.spider)
class TestHttpErrorMiddlewareIntegrational(TrialTestCase):
def setUp(self):
self.mockserver = MockServer()
self.mockserver.__enter__()
def tearDown(self):
self.mockserver.__exit__(None, None, None)
@defer.inlineCallbacks
def test_middleware_works(self):
crawler = get_crawler(_HttpErrorSpider)
yield crawler.crawl()
assert not crawler.spider.skipped, crawler.spider.skipped
self.assertEqual(crawler.spider.parsed, {'200'})
self.assertEqual(crawler.spider.failed, {'404', '402', '500'})
@defer.inlineCallbacks
def test_logging(self):
crawler = get_crawler(_HttpErrorSpider)
with LogCapture() as log:
yield crawler.crawl(bypass_status_codes={402})
self.assertEqual(crawler.spider.parsed, {'200', '402'})
self.assertEqual(crawler.spider.skipped, {'402'})
self.assertEqual(crawler.spider.failed, {'404', '500'})
self.assertIn('Ignoring response <404', str(log))
self.assertIn('Ignoring response <500', str(log))
self.assertNotIn('Ignoring response <200', str(log))
self.assertNotIn('Ignoring response <402', str(log))
|
bsd-3-clause
|
[
504,
2882,
492,
7640,
199,
199,
504,
511,
8769,
492,
5297,
16640,
199,
504,
7390,
14,
14443,
14,
2796,
492,
7640,
465,
377,
1383,
1746,
199,
504,
7390,
14,
4901,
492,
10133,
199,
199,
504,
18918,
14,
1208,
14,
396,
492,
664,
63,
23972,
199,
504,
2295,
14,
1805,
1000,
492,
4420,
3120,
199,
504,
18918,
14,
1014,
492,
7232,
12,
4784,
199,
504,
18918,
14,
8721,
7735,
492,
428,
12508,
199,
504,
18918,
14,
12856,
14885,
758,
470,
14,
16916,
529,
451,
492,
4760,
547,
6608,
12,
4760,
547,
199,
504,
18918,
14,
1751,
492,
13303,
421,
199,
533,
485,
5779,
547,
25157,
8,
25157,
304,
272,
536,
275,
283,
16916,
529,
451,
7,
272,
1343,
63,
3603,
275,
359,
267,
298,
1014,
921,
5967,
26,
24,
13830,
15,
1205,
31,
78,
29,
1840,
401,
267,
298,
1014,
921,
5967,
26,
24,
13830,
15,
1205,
31,
78,
29,
5188,
401,
267,
298,
1014,
921,
5967,
26,
24,
13830,
15,
1205,
31,
78,
29,
13314,
401,
267,
298,
1014,
921,
5967,
26,
24,
13830,
15,
1205,
31,
78,
29,
5783,
401,
272,
1622,
272,
21115,
63,
1205,
63,
6021,
275,
663,
342,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
1547,
5779,
547,
25157,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
4892,
275,
663,
342,
267,
291,
14,
11962,
275,
663,
342,
267,
291,
14,
6751,
275,
663,
342,
339,
347,
1343,
63,
6615,
8,
277,
304,
267,
367,
1166,
315,
291,
14,
928,
63,
3603,
26,
288,
1995,
4784,
8,
633,
12,
291,
14,
1122,
12,
2329,
894,
29,
277,
14,
265,
63,
705,
9,
339,
347,
2198,
8,
277,
12,
1177,
304,
267,
291,
14,
6751,
14,
525,
8,
1310,
14,
633,
1988,
19,
5728,
339,
347,
641,
63,
705,
8,
277,
12,
5988,
304,
267,
340,
1228,
8,
5328,
14,
585,
12,
4760,
547,
304,
288,
1177,
275,
5988,
14,
585,
14,
1310,
288,
340,
1177,
14,
1205,
315,
291,
14,
20605,
63,
1205,
63,
6021,
26,
355,
291,
14,
11962,
14,
525,
8,
1310,
14,
633,
1988,
19,
5728,
355,
372,
291,
14,
1122,
8,
1310,
9,
398,
327,
652,
15194,
2337,
365,
282,
1177,
10102,
370,
5988,
267,
291,
14,
4892,
14,
525,
8,
5328,
14,
585,
14,
1310,
14,
633,
1988,
19,
5728,
267,
372,
5988,
421,
199,
318,
485,
10360,
8,
1069,
12,
2004,
63,
6021,
304,
272,
9320,
275,
942,
272,
367,
1233,
315,
2004,
63,
6021,
26,
267,
1177,
275,
7232,
8,
1069,
14,
633,
12,
2004,
29,
600,
9,
267,
1177,
14,
1069,
275,
1056,
267,
9320,
14,
740,
8,
1310,
9,
272,
372,
9320,
421,
199,
533,
1379,
5779,
547,
6608,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
12856,
275,
428,
12508,
360,
1421,
358,
267,
291,
14,
14716,
275,
4760,
547,
6608,
8,
5268,
24692,
430,
267,
291,
14,
2103,
275,
4784,
360,
1014,
921,
12865,
4462,
14,
1308,
358,
267,
291,
14,
470,
1840,
12,
291,
14,
470,
5188,
275,
485,
10360,
8,
277,
14,
2103,
12,
359,
1840,
12,
7901,
566,
339,
347,
511,
63,
1412,
63,
12856,
63,
1210,
8,
277,
304,
267,
291,
14,
2947,
8,
403,
12,
355,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1210,
8,
277,
14,
470,
1840,
12,
291,
14,
12856,
430,
267,
291,
14,
1855,
8,
5779,
547,
12,
355,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1210,
12,
291,
14,
470,
5188,
12,
291,
14,
12856,
9,
339,
347,
511,
63,
1412,
63,
12856,
63,
1971,
8,
277,
304,
267,
291,
14,
2947,
8798,
355,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1971,
8,
277,
14,
470,
5188,
12,
971,
717,
4760,
547,
8,
277,
14,
470,
5188,
395,
291,
14,
12856,
430,
267,
291,
14,
2947,
8,
403,
12,
355,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1971,
8,
277,
14,
470,
5188,
12,
971,
717,
2186,
1062,
291,
14,
12856,
430,
339,
347,
511,
63,
2479,
63,
1014,
1205,
63,
513,
8,
277,
304,
267,
522,
275,
291,
14,
470,
5188,
14,
1574,
342,
267,
522,
14,
1069,
275,
4784,
360,
1014,
921,
12865,
4462,
14,
1308,
297,
2892,
3404,
3713,
2479,
63,
1014,
1205,
63,
513,
356,
359,
5188,
13412,
267,
291,
14,
2947,
8,
403,
12,
288,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1210,
8,
470,
12,
291,
14,
12856,
430,
398,
291,
14,
12856,
14,
2479,
63,
1014,
1205,
63,
513,
275,
359,
5188,
61,
267,
291,
14,
2947,
8,
403,
12,
288,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1210,
8,
277,
14,
470,
5188,
12,
291,
14,
12856,
430,
421,
199,
533,
1379,
5779,
547,
6608,
5268,
8,
1746,
304,
272,
408,
7467,
6734,
511,
12,
1325,
543,
2202,
624,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
12856,
275,
428,
12508,
360,
1421,
358,
267,
291,
14,
14716,
275,
4760,
547,
6608,
8,
5268,
3252,
2856,
3170,
63,
17350,
63,
15639,
356,
334,
13314,
4258,
12466,
267,
291,
14,
2103,
275,
4784,
360,
1014,
921,
12865,
4462,
14,
1308,
358,
267,
291,
14,
470,
1840,
12,
291,
14,
470,
5188,
12,
291,
14,
470,
13314,
275,
485,
10360,
8,
277,
14,
2103,
12,
359,
1840,
12,
7901,
12,
841,
996,
566,
339,
347,
511,
63,
1412,
63,
12856,
63,
1210,
8,
277,
304,
267,
291,
14,
2947,
8,
403,
12,
355,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1210,
8,
277,
14,
470,
1840,
12,
291,
14,
12856,
430,
267,
291,
14,
1855,
8,
5779,
547,
12,
355,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1210,
12,
291,
14,
470,
5188,
12,
291,
14,
12856,
9,
267,
291,
14,
2947,
8,
403,
12,
355,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1210,
8,
277,
14,
470,
13314,
12,
291,
14,
12856,
430,
339,
347,
511,
63,
2024,
63,
12867,
63,
1751,
8,
277,
304,
267,
1056,
275,
4784,
360,
1014,
921,
12865,
4462,
14,
1308,
297,
2892,
3404,
3713,
2479,
63,
1014,
1205,
63,
513,
356,
359,
5188,
13412,
267,
522,
5188,
275,
291
] |
[
2882,
492,
7640,
199,
199,
504,
511,
8769,
492,
5297,
16640,
199,
504,
7390,
14,
14443,
14,
2796,
492,
7640,
465,
377,
1383,
1746,
199,
504,
7390,
14,
4901,
492,
10133,
199,
199,
504,
18918,
14,
1208,
14,
396,
492,
664,
63,
23972,
199,
504,
2295,
14,
1805,
1000,
492,
4420,
3120,
199,
504,
18918,
14,
1014,
492,
7232,
12,
4784,
199,
504,
18918,
14,
8721,
7735,
492,
428,
12508,
199,
504,
18918,
14,
12856,
14885,
758,
470,
14,
16916,
529,
451,
492,
4760,
547,
6608,
12,
4760,
547,
199,
504,
18918,
14,
1751,
492,
13303,
421,
199,
533,
485,
5779,
547,
25157,
8,
25157,
304,
272,
536,
275,
283,
16916,
529,
451,
7,
272,
1343,
63,
3603,
275,
359,
267,
298,
1014,
921,
5967,
26,
24,
13830,
15,
1205,
31,
78,
29,
1840,
401,
267,
298,
1014,
921,
5967,
26,
24,
13830,
15,
1205,
31,
78,
29,
5188,
401,
267,
298,
1014,
921,
5967,
26,
24,
13830,
15,
1205,
31,
78,
29,
13314,
401,
267,
298,
1014,
921,
5967,
26,
24,
13830,
15,
1205,
31,
78,
29,
5783,
401,
272,
1622,
272,
21115,
63,
1205,
63,
6021,
275,
663,
342,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
1547,
5779,
547,
25157,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
4892,
275,
663,
342,
267,
291,
14,
11962,
275,
663,
342,
267,
291,
14,
6751,
275,
663,
342,
339,
347,
1343,
63,
6615,
8,
277,
304,
267,
367,
1166,
315,
291,
14,
928,
63,
3603,
26,
288,
1995,
4784,
8,
633,
12,
291,
14,
1122,
12,
2329,
894,
29,
277,
14,
265,
63,
705,
9,
339,
347,
2198,
8,
277,
12,
1177,
304,
267,
291,
14,
6751,
14,
525,
8,
1310,
14,
633,
1988,
19,
5728,
339,
347,
641,
63,
705,
8,
277,
12,
5988,
304,
267,
340,
1228,
8,
5328,
14,
585,
12,
4760,
547,
304,
288,
1177,
275,
5988,
14,
585,
14,
1310,
288,
340,
1177,
14,
1205,
315,
291,
14,
20605,
63,
1205,
63,
6021,
26,
355,
291,
14,
11962,
14,
525,
8,
1310,
14,
633,
1988,
19,
5728,
355,
372,
291,
14,
1122,
8,
1310,
9,
398,
327,
652,
15194,
2337,
365,
282,
1177,
10102,
370,
5988,
267,
291,
14,
4892,
14,
525,
8,
5328,
14,
585,
14,
1310,
14,
633,
1988,
19,
5728,
267,
372,
5988,
421,
199,
318,
485,
10360,
8,
1069,
12,
2004,
63,
6021,
304,
272,
9320,
275,
942,
272,
367,
1233,
315,
2004,
63,
6021,
26,
267,
1177,
275,
7232,
8,
1069,
14,
633,
12,
2004,
29,
600,
9,
267,
1177,
14,
1069,
275,
1056,
267,
9320,
14,
740,
8,
1310,
9,
272,
372,
9320,
421,
199,
533,
1379,
5779,
547,
6608,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
12856,
275,
428,
12508,
360,
1421,
358,
267,
291,
14,
14716,
275,
4760,
547,
6608,
8,
5268,
24692,
430,
267,
291,
14,
2103,
275,
4784,
360,
1014,
921,
12865,
4462,
14,
1308,
358,
267,
291,
14,
470,
1840,
12,
291,
14,
470,
5188,
275,
485,
10360,
8,
277,
14,
2103,
12,
359,
1840,
12,
7901,
566,
339,
347,
511,
63,
1412,
63,
12856,
63,
1210,
8,
277,
304,
267,
291,
14,
2947,
8,
403,
12,
355,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1210,
8,
277,
14,
470,
1840,
12,
291,
14,
12856,
430,
267,
291,
14,
1855,
8,
5779,
547,
12,
355,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1210,
12,
291,
14,
470,
5188,
12,
291,
14,
12856,
9,
339,
347,
511,
63,
1412,
63,
12856,
63,
1971,
8,
277,
304,
267,
291,
14,
2947,
8798,
355,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1971,
8,
277,
14,
470,
5188,
12,
971,
717,
4760,
547,
8,
277,
14,
470,
5188,
395,
291,
14,
12856,
430,
267,
291,
14,
2947,
8,
403,
12,
355,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1971,
8,
277,
14,
470,
5188,
12,
971,
717,
2186,
1062,
291,
14,
12856,
430,
339,
347,
511,
63,
2479,
63,
1014,
1205,
63,
513,
8,
277,
304,
267,
522,
275,
291,
14,
470,
5188,
14,
1574,
342,
267,
522,
14,
1069,
275,
4784,
360,
1014,
921,
12865,
4462,
14,
1308,
297,
2892,
3404,
3713,
2479,
63,
1014,
1205,
63,
513,
356,
359,
5188,
13412,
267,
291,
14,
2947,
8,
403,
12,
288,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1210,
8,
470,
12,
291,
14,
12856,
430,
398,
291,
14,
12856,
14,
2479,
63,
1014,
1205,
63,
513,
275,
359,
5188,
61,
267,
291,
14,
2947,
8,
403,
12,
288,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1210,
8,
277,
14,
470,
5188,
12,
291,
14,
12856,
430,
421,
199,
533,
1379,
5779,
547,
6608,
5268,
8,
1746,
304,
272,
408,
7467,
6734,
511,
12,
1325,
543,
2202,
624,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
12856,
275,
428,
12508,
360,
1421,
358,
267,
291,
14,
14716,
275,
4760,
547,
6608,
8,
5268,
3252,
2856,
3170,
63,
17350,
63,
15639,
356,
334,
13314,
4258,
12466,
267,
291,
14,
2103,
275,
4784,
360,
1014,
921,
12865,
4462,
14,
1308,
358,
267,
291,
14,
470,
1840,
12,
291,
14,
470,
5188,
12,
291,
14,
470,
13314,
275,
485,
10360,
8,
277,
14,
2103,
12,
359,
1840,
12,
7901,
12,
841,
996,
566,
339,
347,
511,
63,
1412,
63,
12856,
63,
1210,
8,
277,
304,
267,
291,
14,
2947,
8,
403,
12,
355,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1210,
8,
277,
14,
470,
1840,
12,
291,
14,
12856,
430,
267,
291,
14,
1855,
8,
5779,
547,
12,
355,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1210,
12,
291,
14,
470,
5188,
12,
291,
14,
12856,
9,
267,
291,
14,
2947,
8,
403,
12,
355,
291,
14,
14716,
14,
1412,
63,
12856,
63,
1210,
8,
277,
14,
470,
13314,
12,
291,
14,
12856,
430,
339,
347,
511,
63,
2024,
63,
12867,
63,
1751,
8,
277,
304,
267,
1056,
275,
4784,
360,
1014,
921,
12865,
4462,
14,
1308,
297,
2892,
3404,
3713,
2479,
63,
1014,
1205,
63,
513,
356,
359,
5188,
13412,
267,
522,
5188,
275,
291,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
answer-huang/StatisticsCodeLines
|
statistics.py
|
1
|
3024
|
#coding=utf-8
__author__ = 'answer-huang'
import sys
reload(sys)
sys.setdefaultencoding('utf8')
"""
代码行统计工具
"""
import wx
from MyInfo import AboutMe
from AHDropTarget import AHDropTarget
import os
class AHFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, wx.DefaultPosition, wx.Size(500, 380),
style=wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER | wx.MAXIMIZE_BOX))
#style=wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX)
self.SetTransparent(250)
self.statusbar = self.CreateStatusBar()
self.statusbar.SetForegroundColour('red')
self.statusbar.SetFieldsCount(2)
self.statusbar.SetStatusWidths([-2, -1]) #大小比例2:1
toolbar = self.CreateToolBar()
toolbar.AddSeparator()
toolbar.AddSimpleTool(1, wx.Image('about.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap(), "关于我", "")
toolbar.AddSeparator()
toolbar.AddSimpleTool(2, wx.Image('donate.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap(), "捐助我", "")
toolbar.Realize() #准备显示工具栏
wx.EVT_TOOL(self, 1, self.OnAboutMe)
wx.EVT_TOOL(self, 2, self.OnDonate)
self.panel = wx.Panel(self)
self.panel.SetDropTarget(AHDropTarget(self))
self.font = wx.Font(18, wx.SCRIPT, wx.BOLD, wx.LIGHT)
self.selectedPath = wx.StaticText(self.panel, -1, u'将项目拖拽到这里', pos=(178, 280))
self.selectedPath.SetFont(self.font)
self.panel.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterWindow)
self.panel.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow)
self.panel.Bind(wx.EVT_MOTION, self.OnMotion)
def OnEnterWindow(self, event):
#print event.LeftIsDown()
event.Skip()
def OnLeaveWindow(self, event):
#print "leave"
event.Skip()
def OnMotion(self, event):
if event.Dragging() and event.LeftIsDown():
print '按住了鼠标移动'
event.Skip()
def UpdateStatus(self, path, codes_num):
self.statusbar.SetStatusText(path, 0)
self.statusbar.SetStatusText(codes_num, 1)
def ShowImage(self, img):
self.image = wx.Image(img, wx.BITMAP_TYPE_JPEG).Rescale(500, 350, quality=wx.IMAGE_QUALITY_HIGH)
bitmap = self.image.ConvertToBitmap()
self.logo = wx.StaticBitmap(self.panel, bitmap=bitmap, pos=(0, 0), size=(500, 350))
def ShowPathDir(self, dirList):
wx.CheckListBox(self.panel, -1, choices=dirList)
def OnAboutMe(self, event):
aboutMe = AboutMe(self)
aboutMe.ShowModal()
aboutMe.Destroy()
def OnDonate(self, event):
#wx.BeginBusyCursor()
import webbrowser
webbrowser.open('https://me.alipay.com/huangaiwu')
#wx.EndBusyCursor()
if __name__ == '__main__':
app = wx.App(redirect=False)
frame = AHFrame(None, '代码统计工具')
frame.Show(True)
app.MainLoop()
|
mit
|
[
3,
1523,
29,
1624,
13,
24,
199,
363,
2502,
363,
275,
283,
5934,
13,
10616,
621,
7,
199,
199,
646,
984,
199,
9233,
8,
1274,
9,
199,
1274,
14,
409,
27205,
28139,
360,
1624,
24,
358,
199,
199,
624,
199,
10635,
12609,
9360,
254,
14082,
95,
18189,
99,
8379,
116,
199,
624,
199,
199,
646,
4818,
199,
504,
4932,
2354,
492,
25225,
1352,
199,
504,
437,
40,
11070,
4277,
492,
437,
40,
11070,
4277,
199,
646,
747,
4388,
199,
533,
437,
40,
3160,
8,
6323,
14,
3160,
304,
272,
347,
636,
826,
721,
277,
12,
1676,
12,
2538,
304,
267,
4818,
14,
3160,
855,
826,
721,
277,
12,
1676,
12,
446,
17,
12,
2538,
12,
4818,
14,
2698,
5625,
12,
4818,
14,
2320,
8,
5783,
12,
650,
1257,
395,
2079,
3449,
29,
6323,
14,
3472,
63,
12683,
63,
18466,
7167,
334,
6323,
14,
3830,
11025,
63,
30083,
1204,
4818,
14,
4283,
1469,
11025,
63,
15694,
430,
2079,
327,
2487,
29,
6323,
14,
12711,
63,
18223,
1204,
4818,
14,
28342,
1075,
1204,
4818,
14,
18219,
63,
15694,
1204,
4818,
14,
4896,
1469,
11025,
63,
15694,
9,
267,
291,
14,
1084,
3188,
1708,
8,
7991,
9,
398,
291,
14,
1205,
1700,
275,
291,
14,
2499,
3694,
5281,
342,
267,
291,
14,
1205,
1700,
14,
1084,
29742,
15758,
360,
581,
358,
267,
291,
14,
1205,
1700,
14,
1084,
7304,
2353,
8,
18,
9,
267,
291,
14,
1205,
1700,
14,
1084,
3694,
6216,
83,
11468,
18,
12,
446,
17,
566,
327,
28232,
15348,
238,
28285,
243,
25439,
234,
18,
26,
17,
267,
22483,
275,
291,
14,
2499,
5157,
5281,
342,
267,
22483,
14,
1123,
23344,
342,
267,
22483,
14,
1123,
3184,
5157,
8,
17,
12,
4818,
14,
3491,
360,
10254,
14,
4524,
297,
4818,
14,
30189,
63,
2711,
63,
24454,
680,
7306,
1378,
16469,
1062,
298,
8379,
112,
6923,
237,
9077,
240,
401,
6899,
267,
22483,
14,
1123,
23344,
342,
267,
22483,
14,
1123,
3184,
5157,
8,
18,
12,
4818,
14,
3491,
360,
13196,
323,
14,
4524,
297,
4818,
14,
30189,
63,
2711,
63,
24454,
680,
7306,
1378,
16469,
1062,
298,
17109,
239,
12163,
103,
9077,
240,
401,
6899,
267,
22483,
14,
10099,
794,
342,
221,
327,
15977,
229,
11546,
230,
6812,
123,
29875,
119,
18189,
99,
8379,
116,
13750,
238,
267,
4818,
14,
12093,
63,
9731,
8,
277,
12,
413,
12,
291,
14,
3314,
18816,
1352,
9,
267,
4818,
14,
12093,
63,
9731,
8,
277,
12,
499,
12,
291,
14,
3314,
16932,
323,
9,
398,
291,
14,
7885,
275,
4818,
14,
10185,
8,
277,
9,
267,
291,
14,
7885,
14,
1084,
11070,
4277,
8,
20755,
11070,
4277,
8,
277,
430,
398,
291,
14,
4246,
275,
4818,
14,
6986,
8,
1085,
12,
4818,
14,
10484,
12,
4818,
14,
30144,
12,
4818,
14,
21613,
9,
267,
291,
14,
5511,
2042,
275,
4818,
14,
25289,
8,
277,
14,
7885,
12,
446,
17,
12,
399,
7,
15348,
229,
27513,
118,
31869,
163,
234,
245,
163,
234,
122,
29507,
13201,
248,
10770,
235,
297,
2086,
2687,
11175,
12,
499,
1257,
430,
267,
291,
14,
5511,
2042,
14,
1084,
6986,
8,
277,
14,
4246,
9,
398,
291,
14,
7885,
14,
8198,
8,
6323,
14,
12093,
63,
12533,
63,
15480,
12,
291,
14,
3314,
8468,
4301,
9,
267,
291,
14,
7885,
14,
8198,
8,
6323,
14,
12093,
63,
906,
26907,
63,
15480,
12,
291,
14,
3314,
23679,
4301,
9,
267,
291,
14,
7885,
14,
8198,
8,
6323,
14,
12093,
63,
27235,
1075,
12,
291,
14,
3314,
24875,
9,
339,
347,
4068,
8468,
4301,
8,
277,
12,
1566,
304,
267,
327,
1361,
1566,
14,
8185,
1831,
3514,
342,
267,
1566,
14,
7738,
342,
339,
347,
4068,
23679,
4301,
8,
277,
12,
1566,
304,
267,
327,
1361,
298,
12422,
2,
267,
1566,
14,
7738,
342,
339,
347,
4068,
24875,
8,
277,
12,
1566,
304,
267,
340,
1566,
14,
20287,
1540,
342,
436,
1566,
14,
8185,
1831,
3514,
837,
288,
870,
283,
19880,
232,
11046,
238,
30998,
166,
121,
255,
20767,
19012,
8698,
233,
102,
7,
267,
1566,
14,
7738,
342,
339,
347,
6162,
3694,
8,
277,
12,
931,
12,
9479,
63,
1507,
304,
267,
291,
14,
1205,
1700,
14,
1084,
3694,
1872,
8,
515,
12,
378,
9,
267,
291,
14,
1205,
1700,
14,
1084,
3694,
1872,
8,
6021,
63,
1507,
12,
413,
9,
2378,
347,
12968,
3491,
8,
277,
12,
6050,
304,
267,
291,
14,
1569,
275,
4818,
14,
3491,
8,
4060,
12,
4818,
14,
30189,
63,
2711,
63,
28412,
680,
1322,
2357,
8,
5783,
12,
31921,
12,
11030,
29,
6323,
14,
9438,
63,
9283,
1922,
63,
17624,
9,
267,
20810,
275,
291,
14,
1569,
14,
7306,
1378,
16469,
342,
267,
291,
14,
9733,
275,
4818,
14,
9278,
16469,
8,
277,
14,
7885,
12,
20810,
29,
20299,
12,
2086,
2687,
16,
12,
378,
395,
1568,
2687,
5783,
12,
31921,
430,
339,
347,
12968,
2042,
3567,
8,
277,
12,
2935,
1296,
304,
267,
4818,
14,
1799,
26764,
8,
277,
14,
7885,
12,
446,
17,
12,
3415,
29,
694,
1296,
9,
339,
347,
4068,
18816,
1352,
8,
277,
12,
1566,
304,
267,
3595,
1352,
275,
25225,
1352,
8,
277,
9,
267,
3595,
1352,
14,
6824,
23689,
342,
267,
3595,
1352,
14,
14704,
342,
339,
347,
4068,
16932,
323,
8,
277,
12,
1566,
304,
267,
327,
6323,
14,
5595,
28759,
8993,
342,
267,
492,
781,
29063,
267,
781,
29063,
14,
1490,
360,
2859,
921,
278,
14,
10874,
5989,
14,
957,
15,
10616,
621,
5789,
87,
85,
358,
267,
327,
6323,
14,
3005,
28759,
8993,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1145,
275,
4818,
14,
2640,
8,
4876,
29,
797,
9,
272,
2787,
275,
437,
40,
3160,
8,
403,
12,
283,
10635,
9360,
254,
14082,
95,
18189,
99,
8379,
116,
358,
272,
2787,
14,
6824,
8,
549,
9,
272,
1145,
14,
6756,
7382,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1523,
29,
1624,
13,
24,
199,
363,
2502,
363,
275,
283,
5934,
13,
10616,
621,
7,
199,
199,
646,
984,
199,
9233,
8,
1274,
9,
199,
1274,
14,
409,
27205,
28139,
360,
1624,
24,
358,
199,
199,
624,
199,
10635,
12609,
9360,
254,
14082,
95,
18189,
99,
8379,
116,
199,
624,
199,
199,
646,
4818,
199,
504,
4932,
2354,
492,
25225,
1352,
199,
504,
437,
40,
11070,
4277,
492,
437,
40,
11070,
4277,
199,
646,
747,
4388,
199,
533,
437,
40,
3160,
8,
6323,
14,
3160,
304,
272,
347,
636,
826,
721,
277,
12,
1676,
12,
2538,
304,
267,
4818,
14,
3160,
855,
826,
721,
277,
12,
1676,
12,
446,
17,
12,
2538,
12,
4818,
14,
2698,
5625,
12,
4818,
14,
2320,
8,
5783,
12,
650,
1257,
395,
2079,
3449,
29,
6323,
14,
3472,
63,
12683,
63,
18466,
7167,
334,
6323,
14,
3830,
11025,
63,
30083,
1204,
4818,
14,
4283,
1469,
11025,
63,
15694,
430,
2079,
327,
2487,
29,
6323,
14,
12711,
63,
18223,
1204,
4818,
14,
28342,
1075,
1204,
4818,
14,
18219,
63,
15694,
1204,
4818,
14,
4896,
1469,
11025,
63,
15694,
9,
267,
291,
14,
1084,
3188,
1708,
8,
7991,
9,
398,
291,
14,
1205,
1700,
275,
291,
14,
2499,
3694,
5281,
342,
267,
291,
14,
1205,
1700,
14,
1084,
29742,
15758,
360,
581,
358,
267,
291,
14,
1205,
1700,
14,
1084,
7304,
2353,
8,
18,
9,
267,
291,
14,
1205,
1700,
14,
1084,
3694,
6216,
83,
11468,
18,
12,
446,
17,
566,
327,
28232,
15348,
238,
28285,
243,
25439,
234,
18,
26,
17,
267,
22483,
275,
291,
14,
2499,
5157,
5281,
342,
267,
22483,
14,
1123,
23344,
342,
267,
22483,
14,
1123,
3184,
5157,
8,
17,
12,
4818,
14,
3491,
360,
10254,
14,
4524,
297,
4818,
14,
30189,
63,
2711,
63,
24454,
680,
7306,
1378,
16469,
1062,
298,
8379,
112,
6923,
237,
9077,
240,
401,
6899,
267,
22483,
14,
1123,
23344,
342,
267,
22483,
14,
1123,
3184,
5157,
8,
18,
12,
4818,
14,
3491,
360,
13196,
323,
14,
4524,
297,
4818,
14,
30189,
63,
2711,
63,
24454,
680,
7306,
1378,
16469,
1062,
298,
17109,
239,
12163,
103,
9077,
240,
401,
6899,
267,
22483,
14,
10099,
794,
342,
221,
327,
15977,
229,
11546,
230,
6812,
123,
29875,
119,
18189,
99,
8379,
116,
13750,
238,
267,
4818,
14,
12093,
63,
9731,
8,
277,
12,
413,
12,
291,
14,
3314,
18816,
1352,
9,
267,
4818,
14,
12093,
63,
9731,
8,
277,
12,
499,
12,
291,
14,
3314,
16932,
323,
9,
398,
291,
14,
7885,
275,
4818,
14,
10185,
8,
277,
9,
267,
291,
14,
7885,
14,
1084,
11070,
4277,
8,
20755,
11070,
4277,
8,
277,
430,
398,
291,
14,
4246,
275,
4818,
14,
6986,
8,
1085,
12,
4818,
14,
10484,
12,
4818,
14,
30144,
12,
4818,
14,
21613,
9,
267,
291,
14,
5511,
2042,
275,
4818,
14,
25289,
8,
277,
14,
7885,
12,
446,
17,
12,
399,
7,
15348,
229,
27513,
118,
31869,
163,
234,
245,
163,
234,
122,
29507,
13201,
248,
10770,
235,
297,
2086,
2687,
11175,
12,
499,
1257,
430,
267,
291,
14,
5511,
2042,
14,
1084,
6986,
8,
277,
14,
4246,
9,
398,
291,
14,
7885,
14,
8198,
8,
6323,
14,
12093,
63,
12533,
63,
15480,
12,
291,
14,
3314,
8468,
4301,
9,
267,
291,
14,
7885,
14,
8198,
8,
6323,
14,
12093,
63,
906,
26907,
63,
15480,
12,
291,
14,
3314,
23679,
4301,
9,
267,
291,
14,
7885,
14,
8198,
8,
6323,
14,
12093,
63,
27235,
1075,
12,
291,
14,
3314,
24875,
9,
339,
347,
4068,
8468,
4301,
8,
277,
12,
1566,
304,
267,
327,
1361,
1566,
14,
8185,
1831,
3514,
342,
267,
1566,
14,
7738,
342,
339,
347,
4068,
23679,
4301,
8,
277,
12,
1566,
304,
267,
327,
1361,
298,
12422,
2,
267,
1566,
14,
7738,
342,
339,
347,
4068,
24875,
8,
277,
12,
1566,
304,
267,
340,
1566,
14,
20287,
1540,
342,
436,
1566,
14,
8185,
1831,
3514,
837,
288,
870,
283,
19880,
232,
11046,
238,
30998,
166,
121,
255,
20767,
19012,
8698,
233,
102,
7,
267,
1566,
14,
7738,
342,
339,
347,
6162,
3694,
8,
277,
12,
931,
12,
9479,
63,
1507,
304,
267,
291,
14,
1205,
1700,
14,
1084,
3694,
1872,
8,
515,
12,
378,
9,
267,
291,
14,
1205,
1700,
14,
1084,
3694,
1872,
8,
6021,
63,
1507,
12,
413,
9,
2378,
347,
12968,
3491,
8,
277,
12,
6050,
304,
267,
291,
14,
1569,
275,
4818,
14,
3491,
8,
4060,
12,
4818,
14,
30189,
63,
2711,
63,
28412,
680,
1322,
2357,
8,
5783,
12,
31921,
12,
11030,
29,
6323,
14,
9438,
63,
9283,
1922,
63,
17624,
9,
267,
20810,
275,
291,
14,
1569,
14,
7306,
1378,
16469,
342,
267,
291,
14,
9733,
275,
4818,
14,
9278,
16469,
8,
277,
14,
7885,
12,
20810,
29,
20299,
12,
2086,
2687,
16,
12,
378,
395,
1568,
2687,
5783,
12,
31921,
430,
339,
347,
12968,
2042,
3567,
8,
277,
12,
2935,
1296,
304,
267,
4818,
14,
1799,
26764,
8,
277,
14,
7885,
12,
446,
17,
12,
3415,
29,
694,
1296,
9,
339,
347,
4068,
18816,
1352,
8,
277,
12,
1566,
304,
267,
3595,
1352,
275,
25225,
1352,
8,
277,
9,
267,
3595,
1352,
14,
6824,
23689,
342,
267,
3595,
1352,
14,
14704,
342,
339,
347,
4068,
16932,
323,
8,
277,
12,
1566,
304,
267,
327,
6323,
14,
5595,
28759,
8993,
342,
267,
492,
781,
29063,
267,
781,
29063,
14,
1490,
360,
2859,
921,
278,
14,
10874,
5989,
14,
957,
15,
10616,
621,
5789,
87,
85,
358,
267,
327,
6323,
14,
3005,
28759,
8993,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1145,
275,
4818,
14,
2640,
8,
4876,
29,
797,
9,
272,
2787,
275,
437,
40,
3160,
8,
403,
12,
283,
10635,
9360,
254,
14082,
95,
18189,
99,
8379,
116,
358,
272,
2787,
14,
6824,
8,
549,
9,
272,
1145,
14,
6756,
7382,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
xjljian/huawei-kernel-3.4
|
tools/perf/scripts/python/net_dropmonitor.py
|
4235
|
1554
|
# Monitor the system for dropped packets and proudce a report of drop locations and counts
import os
import sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
from Util import *
drop_log = {}
kallsyms = []
def get_kallsyms_table():
global kallsyms
try:
f = open("/proc/kallsyms", "r")
linecount = 0
for line in f:
linecount = linecount+1
f.seek(0)
except:
return
j = 0
for line in f:
loc = int(line.split()[0], 16)
name = line.split()[2]
j = j +1
if ((j % 100) == 0):
print "\r" + str(j) + "/" + str(linecount),
kallsyms.append({ 'loc': loc, 'name' : name})
print "\r" + str(j) + "/" + str(linecount)
kallsyms.sort()
return
def get_sym(sloc):
loc = int(sloc)
for i in kallsyms:
if (i['loc'] >= loc):
return (i['name'], i['loc']-loc)
return (None, 0)
def print_drop_table():
print "%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT")
for i in drop_log.keys():
(sym, off) = get_sym(i)
if sym == None:
sym = i
print "%25s %25s %25s" % (sym, off, drop_log[i])
def trace_begin():
print "Starting trace (Ctrl-C to dump results)"
def trace_end():
print "Gathering kallsyms data"
get_kallsyms_table()
print_drop_table()
# called from perf, when it finds a correspoinding event
def skb__kfree_skb(name, context, cpu, sec, nsec, pid, comm,
skbaddr, protocol, location):
slocation = str(location)
try:
drop_log[slocation] = drop_log[slocation] + 1
except:
drop_log[slocation] = 1
|
gpl-2.0
|
[
3,
26504,
314,
2656,
367,
17481,
14593,
436,
557,
1181,
301,
282,
3622,
402,
5978,
9918,
436,
8242,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
507,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
627,
199,
199,
4824,
63,
793,
275,
1052,
199,
32483,
275,
942,
199,
199,
318,
664,
63,
32483,
63,
1224,
837,
199,
198,
2966,
1022,
452,
13807,
199,
198,
893,
26,
507,
198,
70,
275,
1551,
4769,
4687,
15,
32483,
401,
298,
82,
531,
507,
198,
604,
835,
275,
378,
507,
198,
509,
1004,
315,
289,
26,
686,
198,
604,
835,
275,
1004,
835,
11,
17,
507,
198,
70,
14,
5507,
8,
16,
9,
199,
198,
2590,
26,
507,
198,
1107,
4388,
198,
74,
275,
378,
199,
198,
509,
1004,
315,
289,
26,
507,
198,
2102,
275,
1109,
8,
604,
14,
1294,
3430,
16,
467,
3193,
9,
507,
198,
354,
275,
1004,
14,
1294,
3430,
18,
61,
507,
198,
74,
275,
1335,
435,
17,
507,
198,
692,
3666,
74,
450,
2948,
9,
508,
378,
304,
686,
198,
1361,
1867,
82,
2,
435,
620,
8,
74,
9,
435,
10609,
435,
620,
8,
604,
835,
395,
507,
198,
32483,
14,
740,
2561,
283,
2102,
356,
4355,
12,
283,
354,
7,
520,
536,
1552,
421,
198,
1361,
1867,
82,
2,
435,
620,
8,
74,
9,
435,
10609,
435,
620,
8,
604,
835,
9,
199,
198,
32483,
14,
3191,
342,
199,
198,
1107,
199,
199,
318,
664,
63,
3840,
8,
83,
2102,
304,
199,
198,
2102,
275,
1109,
8,
83,
2102,
9,
199,
198,
509,
284,
315,
1022,
452,
13807,
26,
507,
198,
692,
334,
73,
459,
2102,
418,
2356,
4355,
304,
686,
198,
1107,
334,
73,
459,
354,
995,
284,
459,
2102,
418,
13,
2102,
9,
199,
198,
1107,
334,
403,
12,
378,
9,
199,
199,
318,
870,
63,
4824,
63,
1224,
837,
199,
198,
1361,
2071,
821,
83,
450,
821,
83,
450,
821,
83,
2,
450,
1689,
16575,
401,
298,
14839,
401,
298,
8760,
531,
199,
198,
509,
284,
315,
5978,
63,
793,
14,
1612,
837,
507,
198,
8,
3840,
12,
2331,
9,
275,
664,
63,
3840,
8,
73,
9,
507,
198,
692,
4678,
508,
488,
26,
686,
198,
3840,
275,
284,
507,
198,
1361,
2071,
821,
83,
450,
821,
83,
450,
821,
83,
2,
450,
334,
3840,
12,
2331,
12,
5978,
63,
793,
59,
73,
566,
421,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14139,
3307,
334,
9778,
13,
35,
370,
5461,
2058,
2924,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
298,
39,
7404,
316,
1022,
452,
13807,
666,
2,
199,
198,
362,
63,
32483,
63,
1224,
342,
199,
198,
1361,
63,
4824,
63,
1224,
342,
199,
199,
3,
2797,
687,
8582,
12,
1380,
652,
17651,
282,
1970,
470,
555,
688,
316,
1566,
199,
318,
11448,
363,
22197,
63,
6852,
8,
354,
12,
1067,
12,
5033,
12,
6513,
12,
14256,
12,
4422,
12,
1923,
12,
686,
198,
13664,
12,
4113,
12,
2909,
304,
199,
198,
83,
1985,
275,
620,
8,
1985,
9,
199,
198,
893,
26,
507,
198,
4824,
63,
793,
59,
83,
1985,
61,
275,
5978,
63,
793,
59,
83,
1985,
61,
435,
413,
199,
198,
2590,
26,
507,
198,
4824,
63,
793,
59,
83,
1985,
61,
275,
413,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
26504,
314,
2656,
367,
17481,
14593,
436,
557,
1181,
301,
282,
3622,
402,
5978,
9918,
436,
8242,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
507,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
627,
199,
199,
4824,
63,
793,
275,
1052,
199,
32483,
275,
942,
199,
199,
318,
664,
63,
32483,
63,
1224,
837,
199,
198,
2966,
1022,
452,
13807,
199,
198,
893,
26,
507,
198,
70,
275,
1551,
4769,
4687,
15,
32483,
401,
298,
82,
531,
507,
198,
604,
835,
275,
378,
507,
198,
509,
1004,
315,
289,
26,
686,
198,
604,
835,
275,
1004,
835,
11,
17,
507,
198,
70,
14,
5507,
8,
16,
9,
199,
198,
2590,
26,
507,
198,
1107,
4388,
198,
74,
275,
378,
199,
198,
509,
1004,
315,
289,
26,
507,
198,
2102,
275,
1109,
8,
604,
14,
1294,
3430,
16,
467,
3193,
9,
507,
198,
354,
275,
1004,
14,
1294,
3430,
18,
61,
507,
198,
74,
275,
1335,
435,
17,
507,
198,
692,
3666,
74,
450,
2948,
9,
508,
378,
304,
686,
198,
1361,
1867,
82,
2,
435,
620,
8,
74,
9,
435,
10609,
435,
620,
8,
604,
835,
395,
507,
198,
32483,
14,
740,
2561,
283,
2102,
356,
4355,
12,
283,
354,
7,
520,
536,
1552,
421,
198,
1361,
1867,
82,
2,
435,
620,
8,
74,
9,
435,
10609,
435,
620,
8,
604,
835,
9,
199,
198,
32483,
14,
3191,
342,
199,
198,
1107,
199,
199,
318,
664,
63,
3840,
8,
83,
2102,
304,
199,
198,
2102,
275,
1109,
8,
83,
2102,
9,
199,
198,
509,
284,
315,
1022,
452,
13807,
26,
507,
198,
692,
334,
73,
459,
2102,
418,
2356,
4355,
304,
686,
198,
1107,
334,
73,
459,
354,
995,
284,
459,
2102,
418,
13,
2102,
9,
199,
198,
1107,
334,
403,
12,
378,
9,
199,
199,
318,
870,
63,
4824,
63,
1224,
837,
199,
198,
1361,
2071,
821,
83,
450,
821,
83,
450,
821,
83,
2,
450,
1689,
16575,
401,
298,
14839,
401,
298,
8760,
531,
199,
198,
509,
284,
315,
5978,
63,
793,
14,
1612,
837,
507,
198,
8,
3840,
12,
2331,
9,
275,
664,
63,
3840,
8,
73,
9,
507,
198,
692,
4678,
508,
488,
26,
686,
198,
3840,
275,
284,
507,
198,
1361,
2071,
821,
83,
450,
821,
83,
450,
821,
83,
2,
450,
334,
3840,
12,
2331,
12,
5978,
63,
793,
59,
73,
566,
421,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14139,
3307,
334,
9778,
13,
35,
370,
5461,
2058,
2924,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
298,
39,
7404,
316,
1022,
452,
13807,
666,
2,
199,
198,
362,
63,
32483,
63,
1224,
342,
199,
198,
1361,
63,
4824,
63,
1224,
342,
199,
199,
3,
2797,
687,
8582,
12,
1380,
652,
17651,
282,
1970,
470,
555,
688,
316,
1566,
199,
318,
11448,
363,
22197,
63,
6852,
8,
354,
12,
1067,
12,
5033,
12,
6513,
12,
14256,
12,
4422,
12,
1923,
12,
686,
198,
13664,
12,
4113,
12,
2909,
304,
199,
198,
83,
1985,
275,
620,
8,
1985,
9,
199,
198,
893,
26,
507,
198,
4824,
63,
793,
59,
83,
1985,
61,
275,
5978,
63,
793,
59,
83,
1985,
61,
435,
413,
199,
198,
2590,
26,
507,
198,
4824,
63,
793,
59,
83,
1985,
61,
275,
413,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1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nova
|
nova/virt/xenapi/agent.py
|
44
|
18780
|
# Copyright (c) 2010 Citrix Systems, Inc.
# Copyright 2010-2012 OpenStack Foundation
#
# 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.
import base64
import binascii
from distutils import version
import os
import sys
import time
import uuid
from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import strutils
from nova.api.metadata import password
from nova.compute import utils as compute_utils
from nova import context
from nova import crypto
from nova import exception
from nova.i18n import _, _LE, _LI, _LW
from nova import objects
from nova import utils
USE_AGENT_KEY = "xenapi_use_agent"
USE_AGENT_SM_KEY = utils.SM_IMAGE_PROP_PREFIX + USE_AGENT_KEY
SKIP_SSH_KEY = "xenapi_skip_agent_inject_ssh"
SKIP_SSH_SM_KEY = utils.SM_IMAGE_PROP_PREFIX + SKIP_SSH_KEY
SKIP_FILES_AT_BOOT_KEY = "xenapi_skip_agent_inject_files_at_boot"
SKIP_FILES_AT_BOOT_SM_KEY = utils.SM_IMAGE_PROP_PREFIX \
+ SKIP_FILES_AT_BOOT_KEY
LOG = logging.getLogger(__name__)
xenapi_agent_opts = [
cfg.IntOpt('agent_timeout',
default=30,
help='Number of seconds to wait for agent reply'),
cfg.IntOpt('agent_version_timeout',
default=300,
help='Number of seconds to wait for agent '
'to be fully operational'),
cfg.IntOpt('agent_resetnetwork_timeout',
default=60,
help='Number of seconds to wait for agent reply '
'to resetnetwork request'),
cfg.StrOpt('agent_path',
default='usr/sbin/xe-update-networking',
help='Specifies the path in which the XenAPI guest agent '
'should be located. If the agent is present, network '
'configuration is not injected into the image. '
'Used if compute_driver=xenapi.XenAPIDriver and '
'flat_injected=True'),
cfg.BoolOpt('disable_agent',
default=False,
help='Disables the use of the XenAPI agent in any image '
'regardless of what image properties are present.'),
cfg.BoolOpt('use_agent_default',
default=False,
help='Determines if the XenAPI agent should be used when '
'the image used does not contain a hint to declare if '
'the agent is present or not. '
'The hint is a glance property "' + USE_AGENT_KEY + '" '
'that has the value "True" or "False". '
'Note that waiting for the agent when it is not present '
'will significantly increase server boot times.'),
]
CONF = cfg.CONF
CONF.register_opts(xenapi_agent_opts, 'xenserver')
def _call_agent(session, instance, vm_ref, method, addl_args=None,
timeout=None, success_codes=None):
"""Abstracts out the interaction with the agent xenapi plugin."""
if addl_args is None:
addl_args = {}
if timeout is None:
timeout = CONF.xenserver.agent_timeout
if success_codes is None:
success_codes = ['0']
# always fetch domid because VM may have rebooted
dom_id = session.VM.get_domid(vm_ref)
args = {
'id': str(uuid.uuid4()),
'dom_id': str(dom_id),
'timeout': str(timeout),
}
args.update(addl_args)
try:
ret = session.call_plugin('agent', method, args)
except session.XenAPI.Failure as e:
err_msg = e.details[-1].splitlines()[-1]
if 'TIMEOUT:' in err_msg:
LOG.error(_LE('TIMEOUT: The call to %(method)s timed out. '
'args=%(args)r'),
{'method': method, 'args': args}, instance=instance)
raise exception.AgentTimeout(method=method)
elif 'REBOOT:' in err_msg:
LOG.debug('REBOOT: The call to %(method)s detected a reboot. '
'args=%(args)r',
{'method': method, 'args': args}, instance=instance)
_wait_for_new_dom_id(session, vm_ref, dom_id, method)
return _call_agent(session, instance, vm_ref, method,
addl_args, timeout, success_codes)
elif 'NOT IMPLEMENTED:' in err_msg:
LOG.error(_LE('NOT IMPLEMENTED: The call to %(method)s is not '
'supported by the agent. args=%(args)r'),
{'method': method, 'args': args}, instance=instance)
raise exception.AgentNotImplemented(method=method)
else:
LOG.error(_LE('The call to %(method)s returned an error: %(e)s. '
'args=%(args)r'),
{'method': method, 'args': args, 'e': e},
instance=instance)
raise exception.AgentError(method=method)
if not isinstance(ret, dict):
try:
ret = jsonutils.loads(ret)
except TypeError:
LOG.error(_LE('The agent call to %(method)s returned an invalid '
'response: %(ret)r. args=%(args)r'),
{'method': method, 'ret': ret, 'args': args},
instance=instance)
raise exception.AgentError(method=method)
if ret['returncode'] not in success_codes:
LOG.error(_LE('The agent call to %(method)s returned an '
'an error: %(ret)r. args=%(args)r'),
{'method': method, 'ret': ret, 'args': args},
instance=instance)
raise exception.AgentError(method=method)
LOG.debug('The agent call to %(method)s was successful: '
'%(ret)r. args=%(args)r',
{'method': method, 'ret': ret, 'args': args},
instance=instance)
# Some old versions of the Windows agent have a trailing \\r\\n
# (ie CRLF escaped) for some reason. Strip that off.
return ret['message'].replace('\\r\\n', '')
def _wait_for_new_dom_id(session, vm_ref, old_dom_id, method):
expiration = time.time() + CONF.xenserver.agent_timeout
while True:
dom_id = session.VM.get_domid(vm_ref)
if dom_id and dom_id != -1 and dom_id != old_dom_id:
LOG.debug("Found new dom_id %s" % dom_id)
return
if time.time() > expiration:
LOG.debug("Timed out waiting for new dom_id %s" % dom_id)
raise exception.AgentTimeout(method=method)
time.sleep(1)
def is_upgrade_required(current_version, available_version):
# NOTE(johngarbutt): agent version numbers are four part,
# so we need to use the loose version to compare them
current = version.LooseVersion(current_version)
available = version.LooseVersion(available_version)
return available > current
class XenAPIBasedAgent(object):
def __init__(self, session, virtapi, instance, vm_ref):
self.session = session
self.virtapi = virtapi
self.instance = instance
self.vm_ref = vm_ref
def _add_instance_fault(self, error, exc_info):
LOG.warning(_LW("Ignoring error while configuring instance with "
"agent: %s"), error,
instance=self.instance, exc_info=True)
try:
ctxt = context.get_admin_context()
compute_utils.add_instance_fault_from_exc(
ctxt, self.instance, error, exc_info=exc_info)
except Exception:
LOG.debug("Error setting instance fault.", exc_info=True)
def _call_agent(self, method, addl_args=None, timeout=None,
success_codes=None, ignore_errors=True):
try:
return _call_agent(self.session, self.instance, self.vm_ref,
method, addl_args, timeout, success_codes)
except exception.AgentError as error:
if ignore_errors:
self._add_instance_fault(error, sys.exc_info())
else:
raise
def get_version(self):
LOG.debug('Querying agent version', instance=self.instance)
# The agent can be slow to start for a variety of reasons. On Windows,
# it will generally perform a setup process on first boot that can
# take a couple of minutes and then reboot. On Linux, the system can
# also take a while to boot.
expiration = time.time() + CONF.xenserver.agent_version_timeout
while True:
try:
# NOTE(johngarbutt): we can't use the xapi plugin
# timeout, because the domid may change when
# the server is rebooted
return self._call_agent('version', ignore_errors=False)
except exception.AgentError as error:
if time.time() > expiration:
self._add_instance_fault(error, sys.exc_info())
return
def _get_expected_build(self):
ctxt = context.get_admin_context()
agent_build = objects.Agent.get_by_triple(
ctxt, 'xen', self.instance['os_type'],
self.instance['architecture'])
if agent_build:
LOG.debug('Latest agent build for %(hypervisor)s/%(os)s'
'/%(architecture)s is %(version)s', {
'hypervisor': agent_build.hypervisor,
'os': agent_build.os,
'architecture': agent_build.architecture,
'version': agent_build.version})
else:
LOG.debug('No agent build found for %(hypervisor)s/%(os)s'
'/%(architecture)s', {
'hypervisor': 'xen',
'os': self.instance['os_type'],
'architecture': self.instance['architecture']})
return agent_build
def update_if_needed(self, version):
agent_build = self._get_expected_build()
if version and agent_build and \
is_upgrade_required(version, agent_build['version']):
LOG.debug('Updating agent to %s', agent_build['version'],
instance=self.instance)
self._perform_update(agent_build)
else:
LOG.debug('Skipping agent update.', instance=self.instance)
def _perform_update(self, agent_build):
args = {'url': agent_build['url'], 'md5sum': agent_build['md5hash']}
try:
self._call_agent('agentupdate', args)
except exception.AgentError as exc:
# Silently fail for agent upgrades
LOG.warning(_LW("Unable to update the agent due "
"to: %(exc)s"), dict(exc=exc),
instance=self.instance)
def _exchange_key_with_agent(self):
dh = SimpleDH()
args = {'pub': str(dh.get_public())}
resp = self._call_agent('key_init', args, success_codes=['D0'],
ignore_errors=False)
agent_pub = int(resp)
dh.compute_shared(agent_pub)
return dh
def _save_instance_password_if_sshkey_present(self, new_pass):
sshkey = self.instance.get('key_data')
if sshkey and sshkey.startswith("ssh-rsa"):
ctxt = context.get_admin_context()
enc = crypto.ssh_encrypt_text(sshkey, new_pass)
self.instance.system_metadata.update(
password.convert_password(ctxt, base64.b64encode(enc)))
self.instance.save()
def set_admin_password(self, new_pass):
"""Set the root/admin password on the VM instance.
This is done via an agent running on the VM. Communication between nova
and the agent is done via writing xenstore records. Since communication
is done over the XenAPI RPC calls, we need to encrypt the password.
We're using a simple Diffie-Hellman class instead of a more advanced
library (such as M2Crypto) for compatibility with the agent code.
"""
LOG.debug('Setting admin password', instance=self.instance)
try:
dh = self._exchange_key_with_agent()
except exception.AgentError as error:
self._add_instance_fault(error, sys.exc_info())
return
# Some old versions of Linux and Windows agent expect trailing \n
# on password to work correctly.
enc_pass = dh.encrypt(new_pass + '\n')
args = {'enc_pass': enc_pass}
self._call_agent('password', args)
self._save_instance_password_if_sshkey_present(new_pass)
def inject_ssh_key(self):
sshkey = self.instance.get('key_data')
if not sshkey:
return
if self.instance['os_type'] == 'windows':
LOG.debug("Skipping setting of ssh key for Windows.",
instance=self.instance)
return
if self._skip_ssh_key_inject():
LOG.debug("Skipping agent ssh key injection for this image.",
instance=self.instance)
return
sshkey = str(sshkey)
keyfile = '/root/.ssh/authorized_keys'
key_data = ''.join([
'\n',
'# The following ssh key was injected by Nova',
'\n',
sshkey.strip(),
'\n',
])
return self.inject_file(keyfile, key_data)
def inject_files(self, injected_files):
if self._skip_inject_files_at_boot():
LOG.debug("Skipping agent file injection for this image.",
instance=self.instance)
else:
for path, contents in injected_files:
self.inject_file(path, contents)
def inject_file(self, path, contents):
LOG.debug('Injecting file path: %r', path, instance=self.instance)
# Files/paths must be base64-encoded for transmission to agent
b64_path = base64.b64encode(path)
b64_contents = base64.b64encode(contents)
args = {'b64_path': b64_path, 'b64_contents': b64_contents}
return self._call_agent('inject_file', args)
def resetnetwork(self):
LOG.debug('Resetting network', instance=self.instance)
# NOTE(johngarbutt) old FreeBSD and Gentoo agents return 500 on success
return self._call_agent('resetnetwork',
timeout=CONF.xenserver.agent_resetnetwork_timeout,
success_codes=['0', '500'])
def _skip_ssh_key_inject(self):
return self._get_sys_meta_key(SKIP_SSH_SM_KEY)
def _skip_inject_files_at_boot(self):
return self._get_sys_meta_key(SKIP_FILES_AT_BOOT_SM_KEY)
def _get_sys_meta_key(self, key):
sys_meta = utils.instance_sys_meta(self.instance)
raw_value = sys_meta.get(key, 'False')
return strutils.bool_from_string(raw_value, strict=False)
def find_guest_agent(base_dir):
"""tries to locate a guest agent at the path
specified by agent_rel_path
"""
if CONF.xenserver.disable_agent:
return False
agent_rel_path = CONF.xenserver.agent_path
agent_path = os.path.join(base_dir, agent_rel_path)
if os.path.isfile(agent_path):
# The presence of the guest agent
# file indicates that this instance can
# reconfigure the network from xenstore data,
# so manipulation of files in /etc is not
# required
LOG.info(_LI('XenServer tools installed in this '
'image are capable of network injection. '
'Networking files will not be'
'manipulated'))
return True
xe_daemon_filename = os.path.join(base_dir,
'usr', 'sbin', 'xe-daemon')
if os.path.isfile(xe_daemon_filename):
LOG.info(_LI('XenServer tools are present '
'in this image but are not capable '
'of network injection'))
else:
LOG.info(_LI('XenServer tools are not '
'installed in this image'))
return False
def should_use_agent(instance):
sys_meta = utils.instance_sys_meta(instance)
if USE_AGENT_SM_KEY not in sys_meta:
return CONF.xenserver.use_agent_default
else:
use_agent_raw = sys_meta[USE_AGENT_SM_KEY]
try:
return strutils.bool_from_string(use_agent_raw, strict=True)
except ValueError:
LOG.warning(_LW("Invalid 'agent_present' value. "
"Falling back to the default."),
instance=instance)
return CONF.xenserver.use_agent_default
class SimpleDH(object):
"""This class wraps all the functionality needed to implement
basic Diffie-Hellman-Merkle key exchange in Python. It features
intelligent defaults for the prime and base numbers needed for the
calculation, while allowing you to supply your own. It requires that
the openssl binary be installed on the system on which this is run,
as it uses that to handle the encryption and decryption. If openssl
is not available, a RuntimeError will be raised.
"""
def __init__(self):
self._prime = 162259276829213363391578010288127
self._base = 5
self._public = None
self._shared = None
self.generate_private()
def generate_private(self):
self._private = int(binascii.hexlify(os.urandom(10)), 16)
return self._private
def get_public(self):
self._public = pow(self._base, self._private, self._prime)
return self._public
def compute_shared(self, other):
self._shared = pow(other, self._private, self._prime)
return self._shared
def _run_ssl(self, text, decrypt=False):
cmd = ['openssl', 'aes-128-cbc', '-A', '-a', '-pass',
'pass:%s' % self._shared, '-nosalt']
if decrypt:
cmd.append('-d')
out, err = utils.execute(*cmd, process_input=text)
if err:
raise RuntimeError(_('OpenSSL error: %s') % err)
return out
def encrypt(self, text):
return self._run_ssl(text).strip('\n')
def decrypt(self, text):
return self._run_ssl(text, decrypt=True)
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
7129,
445,
390,
1904,
15285,
12,
3277,
14,
199,
3,
1898,
7129,
13,
7409,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1300,
772,
199,
646,
14755,
199,
504,
7065,
492,
1015,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
646,
5377,
199,
199,
504,
11258,
63,
888,
492,
4810,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
504,
11258,
63,
12161,
492,
18705,
199,
504,
11258,
63,
1208,
492,
620,
1208,
199,
199,
504,
5913,
14,
1246,
14,
2343,
492,
2505,
199,
504,
5913,
14,
3357,
492,
3778,
465,
4526,
63,
1208,
199,
504,
5913,
492,
1067,
199,
504,
5913,
492,
13230,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
73,
1085,
78,
492,
5501,
485,
906,
12,
485,
2673,
12,
485,
20145,
199,
504,
5913,
492,
2251,
199,
504,
5913,
492,
3778,
421,
199,
4701,
63,
14565,
63,
3078,
275,
298,
20392,
63,
1180,
63,
4054,
2,
199,
4701,
63,
14565,
63,
4029,
63,
3078,
275,
3778,
14,
4029,
63,
9438,
63,
19926,
63,
6351,
435,
4815,
63,
14565,
63,
3078,
199,
13525,
63,
13716,
63,
3078,
275,
298,
20392,
63,
2759,
63,
4054,
63,
14815,
63,
5510,
2,
199,
13525,
63,
13716,
63,
4029,
63,
3078,
275,
3778,
14,
4029,
63,
9438,
63,
19926,
63,
6351,
435,
27885,
63,
13716,
63,
3078,
199,
13525,
63,
9472,
63,
619,
63,
22679,
63,
3078,
275,
298,
20392,
63,
2759,
63,
4054,
63,
14815,
63,
1725,
63,
292,
63,
4930,
2,
199,
13525,
63,
9472,
63,
619,
63,
22679,
63,
4029,
63,
3078,
275,
3778,
14,
4029,
63,
9438,
63,
19926,
63,
6351,
971,
3147,
435,
27885,
63,
9472,
63,
619,
63,
22679,
63,
3078,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
20392,
63,
4054,
63,
3291,
275,
359,
272,
4810,
14,
3241,
9985,
360,
4054,
63,
2593,
297,
2049,
849,
29,
1216,
12,
2049,
1720,
534,
3259,
402,
4696,
370,
3618,
367,
6631,
9351,
659,
272,
4810,
14,
3241,
9985,
360,
4054,
63,
1023,
63,
2593,
297,
2049,
849,
29,
5863,
12,
2049,
1720,
534,
3259,
402,
4696,
370,
3618,
367,
6631,
283,
490,
283,
475,
506,
9999,
3439,
279,
659,
272,
4810,
14,
3241,
9985,
360,
4054,
63,
3958,
1200,
63,
2593,
297,
2049,
849,
29,
2259,
12,
2049,
1720,
534,
3259,
402,
4696,
370,
3618,
367,
6631,
9351,
283,
490,
283,
475,
5305,
1200,
1056,
659,
272,
4810,
14,
19340,
360,
4054,
63,
515,
297,
2049,
849,
534,
2647,
15,
21457,
15,
1845,
13,
873,
13,
1200,
316,
297,
2049,
1720,
534,
6154,
5604,
314,
931,
315,
1314,
314,
30211,
3735,
13980,
6631,
283,
490,
283,
5626,
506,
16180,
14,
982,
314,
6631,
365,
3451,
12,
2784,
283,
490,
283,
4758,
365,
440,
26121,
1901,
314,
1834,
14,
283,
490,
283,
9167,
340,
4526,
63,
3090,
29,
20392,
14,
30643,
1282,
998,
2046,
436,
283,
490,
283,
7088,
63,
30785,
29,
549,
659,
272,
4810,
14,
10349,
9985,
360,
5993,
63,
4054,
297,
355,
849,
29,
797,
12,
355,
1720,
534,
2825,
5921,
314,
675,
402,
314,
30211,
3735,
6631,
315,
1263,
1834,
283,
2151,
283,
1135,
1005,
2003,
402,
4052,
1834,
4382,
787,
3451,
8038,
272,
4810,
14,
10349,
9985,
360,
1180,
63,
4054,
63,
885,
297,
355,
849,
29,
797,
12,
355,
1720,
534,
872,
18454,
340,
314,
30211,
3735,
6631,
1077,
506,
1202,
1380,
283,
2151,
283,
1589,
1834,
1202,
1630,
440,
1395,
282,
8328,
370,
20771,
340,
283,
2151,
283,
1589,
6631,
365,
3451,
503,
440,
14,
283,
2151,
283,
1918,
8328,
365,
282,
21785,
3324,
3546,
435,
4815,
63,
14565,
63,
3078,
435,
5522,
283,
2151,
283,
9099,
965,
314,
574,
298,
549,
2,
503,
298,
797,
1674,
283,
2151,
283,
7443,
626,
10923,
367,
314,
6631,
1380,
652,
365,
440,
3451,
283,
2151,
283,
14117,
16474,
590,
19781,
1654,
8498,
5431,
8038,
199,
61,
199,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
2683,
63,
3291,
8,
20392,
63,
4054,
63,
3291,
12,
283,
13615,
1000,
358,
421,
199,
318,
485,
1250,
63,
4054,
8,
1730,
12,
1256,
12,
4169,
63,
1121,
12,
1083,
12,
1050,
76,
63,
589,
29,
403,
12,
355,
2653,
29,
403,
12,
3182,
63,
6021,
29,
403,
304,
272,
408,
8458,
83,
734,
314,
18752,
543,
314,
6631,
20388,
1246,
3589,
1041,
272,
340,
1050,
76,
63,
589,
365,
488,
26,
267,
1050,
76,
63,
589,
275,
1052,
272,
340,
2653,
365,
488,
26,
267,
2653,
275,
6392,
14,
13615,
1000,
14,
4054,
63,
2593,
272,
340,
3182,
63,
6021,
365,
488,
26,
267,
3182,
63,
6021,
275,
788,
16,
418,
339,
327,
3544,
5267,
8266,
344,
2952,
7525,
1443,
1172,
295,
656,
5731,
272,
8266,
63,
344,
275,
2351,
14,
6849,
14,
362,
63,
4556,
344,
8,
2611,
63,
1121,
9,
339,
1249,
275,
469,
267,
283,
344,
356,
620,
8,
2580,
14,
2580,
20,
4000,
267,
283,
4556,
63,
344,
356,
620,
8,
4556,
63,
344,
395,
267,
283,
2593,
356,
620,
8,
2593,
395,
272,
789,
272,
1249,
14,
873,
8,
525,
76,
63,
589,
9,
339,
862,
26,
267,
2203,
275,
2351,
14,
1250,
63,
2718,
360,
4054,
297,
1083,
12,
1249,
9,
272,
871,
2351,
14,
30643,
3735,
14,
6782,
465,
325,
26,
267,
2329,
63,
1328,
275,
325,
14,
5087,
1988,
17
] |
[
1898,
334,
67,
9,
7129,
445,
390,
1904,
15285,
12,
3277,
14,
199,
3,
1898,
7129,
13,
7409,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1300,
772,
199,
646,
14755,
199,
504,
7065,
492,
1015,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
646,
5377,
199,
199,
504,
11258,
63,
888,
492,
4810,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
504,
11258,
63,
12161,
492,
18705,
199,
504,
11258,
63,
1208,
492,
620,
1208,
199,
199,
504,
5913,
14,
1246,
14,
2343,
492,
2505,
199,
504,
5913,
14,
3357,
492,
3778,
465,
4526,
63,
1208,
199,
504,
5913,
492,
1067,
199,
504,
5913,
492,
13230,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
73,
1085,
78,
492,
5501,
485,
906,
12,
485,
2673,
12,
485,
20145,
199,
504,
5913,
492,
2251,
199,
504,
5913,
492,
3778,
421,
199,
4701,
63,
14565,
63,
3078,
275,
298,
20392,
63,
1180,
63,
4054,
2,
199,
4701,
63,
14565,
63,
4029,
63,
3078,
275,
3778,
14,
4029,
63,
9438,
63,
19926,
63,
6351,
435,
4815,
63,
14565,
63,
3078,
199,
13525,
63,
13716,
63,
3078,
275,
298,
20392,
63,
2759,
63,
4054,
63,
14815,
63,
5510,
2,
199,
13525,
63,
13716,
63,
4029,
63,
3078,
275,
3778,
14,
4029,
63,
9438,
63,
19926,
63,
6351,
435,
27885,
63,
13716,
63,
3078,
199,
13525,
63,
9472,
63,
619,
63,
22679,
63,
3078,
275,
298,
20392,
63,
2759,
63,
4054,
63,
14815,
63,
1725,
63,
292,
63,
4930,
2,
199,
13525,
63,
9472,
63,
619,
63,
22679,
63,
4029,
63,
3078,
275,
3778,
14,
4029,
63,
9438,
63,
19926,
63,
6351,
971,
3147,
435,
27885,
63,
9472,
63,
619,
63,
22679,
63,
3078,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
20392,
63,
4054,
63,
3291,
275,
359,
272,
4810,
14,
3241,
9985,
360,
4054,
63,
2593,
297,
2049,
849,
29,
1216,
12,
2049,
1720,
534,
3259,
402,
4696,
370,
3618,
367,
6631,
9351,
659,
272,
4810,
14,
3241,
9985,
360,
4054,
63,
1023,
63,
2593,
297,
2049,
849,
29,
5863,
12,
2049,
1720,
534,
3259,
402,
4696,
370,
3618,
367,
6631,
283,
490,
283,
475,
506,
9999,
3439,
279,
659,
272,
4810,
14,
3241,
9985,
360,
4054,
63,
3958,
1200,
63,
2593,
297,
2049,
849,
29,
2259,
12,
2049,
1720,
534,
3259,
402,
4696,
370,
3618,
367,
6631,
9351,
283,
490,
283,
475,
5305,
1200,
1056,
659,
272,
4810,
14,
19340,
360,
4054,
63,
515,
297,
2049,
849,
534,
2647,
15,
21457,
15,
1845,
13,
873,
13,
1200,
316,
297,
2049,
1720,
534,
6154,
5604,
314,
931,
315,
1314,
314,
30211,
3735,
13980,
6631,
283,
490,
283,
5626,
506,
16180,
14,
982,
314,
6631,
365,
3451,
12,
2784,
283,
490,
283,
4758,
365,
440,
26121,
1901,
314,
1834,
14,
283,
490,
283,
9167,
340,
4526,
63,
3090,
29,
20392,
14,
30643,
1282,
998,
2046,
436,
283,
490,
283,
7088,
63,
30785,
29,
549,
659,
272,
4810,
14,
10349,
9985,
360,
5993,
63,
4054,
297,
355,
849,
29,
797,
12,
355,
1720,
534,
2825,
5921,
314,
675,
402,
314,
30211,
3735,
6631,
315,
1263,
1834,
283,
2151,
283,
1135,
1005,
2003,
402,
4052,
1834,
4382,
787,
3451,
8038,
272,
4810,
14,
10349,
9985,
360,
1180,
63,
4054,
63,
885,
297,
355,
849,
29,
797,
12,
355,
1720,
534,
872,
18454,
340,
314,
30211,
3735,
6631,
1077,
506,
1202,
1380,
283,
2151,
283,
1589,
1834,
1202,
1630,
440,
1395,
282,
8328,
370,
20771,
340,
283,
2151,
283,
1589,
6631,
365,
3451,
503,
440,
14,
283,
2151,
283,
1918,
8328,
365,
282,
21785,
3324,
3546,
435,
4815,
63,
14565,
63,
3078,
435,
5522,
283,
2151,
283,
9099,
965,
314,
574,
298,
549,
2,
503,
298,
797,
1674,
283,
2151,
283,
7443,
626,
10923,
367,
314,
6631,
1380,
652,
365,
440,
3451,
283,
2151,
283,
14117,
16474,
590,
19781,
1654,
8498,
5431,
8038,
199,
61,
199,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
2683,
63,
3291,
8,
20392,
63,
4054,
63,
3291,
12,
283,
13615,
1000,
358,
421,
199,
318,
485,
1250,
63,
4054,
8,
1730,
12,
1256,
12,
4169,
63,
1121,
12,
1083,
12,
1050,
76,
63,
589,
29,
403,
12,
355,
2653,
29,
403,
12,
3182,
63,
6021,
29,
403,
304,
272,
408,
8458,
83,
734,
314,
18752,
543,
314,
6631,
20388,
1246,
3589,
1041,
272,
340,
1050,
76,
63,
589,
365,
488,
26,
267,
1050,
76,
63,
589,
275,
1052,
272,
340,
2653,
365,
488,
26,
267,
2653,
275,
6392,
14,
13615,
1000,
14,
4054,
63,
2593,
272,
340,
3182,
63,
6021,
365,
488,
26,
267,
3182,
63,
6021,
275,
788,
16,
418,
339,
327,
3544,
5267,
8266,
344,
2952,
7525,
1443,
1172,
295,
656,
5731,
272,
8266,
63,
344,
275,
2351,
14,
6849,
14,
362,
63,
4556,
344,
8,
2611,
63,
1121,
9,
339,
1249,
275,
469,
267,
283,
344,
356,
620,
8,
2580,
14,
2580,
20,
4000,
267,
283,
4556,
63,
344,
356,
620,
8,
4556,
63,
344,
395,
267,
283,
2593,
356,
620,
8,
2593,
395,
272,
789,
272,
1249,
14,
873,
8,
525,
76,
63,
589,
9,
339,
862,
26,
267,
2203,
275,
2351,
14,
1250,
63,
2718,
360,
4054,
297,
1083,
12,
1249,
9,
272,
871,
2351,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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
nop33/indico
|
indico/modules/events/views.py
|
2
|
12813
|
# This file is part of Indico.
# Copyright (C) 2002 - 2017 European Organization for Nuclear Research (CERN).
#
# Indico is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# Indico is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Indico; if not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function, unicode_literals
import os
import posixpath
from flask import render_template, request
from sqlalchemy.orm import load_only
from indico.core.config import config
from indico.modules.admin.views import WPAdmin
from indico.modules.core.settings import core_settings, social_settings
from indico.modules.events import Event
from indico.modules.events.layout import layout_settings, theme_settings
from indico.modules.events.layout.util import (build_menu_entry_name, get_css_url, get_menu_entry_by_name,
menu_entries_for_event)
from indico.modules.events.models.events import EventType
from indico.util.date_time import format_date
from indico.util.mathjax import MathjaxMixin
from indico.util.string import strip_tags, to_unicode, truncate
from indico.web.flask.util import url_for
from indico.web.views import WPDecorated, WPJinjaMixin
def _get_print_url(event, theme=None, theme_override=False):
view = theme if theme_override else None
if event.type_ == EventType.conference:
return url_for('timetable.timetable', event, print='1', view=view)
elif event.type_ == EventType.meeting:
show_date = request.args.get('showDate')
show_session = request.args.get('showSession')
detail_level = request.args.get('detailLevel')
if show_date == 'all':
show_date = None
if show_session == 'all':
show_session = None
if detail_level in ('all', 'contrinbution'):
detail_level = None
return url_for('events.display', event, showDate=show_date, showSession=show_session, detailLevel=detail_level,
print='1', view=view)
elif event.type_ == EventType.lecture:
return url_for('events.display', event, print='1', view=view)
def render_event_header(event, conference_layout=False, theme=None, theme_override=False):
print_url = _get_print_url(event, theme, theme_override) if not conference_layout else None
show_nav_bar = event.type_ != EventType.conference or layout_settings.get(event, 'show_nav_bar')
themes = {tid: {'name': data['title'], 'user_visible': data.get('user_visible')}
for tid, data in theme_settings.get_themes_for(event.type_.name).viewitems()}
return render_template('events/header.html',
event=event, print_url=print_url, show_nav_bar=show_nav_bar, themes=themes, theme=theme)
def render_event_footer(event, dark=False):
location = event.venue_name
if event.room_name:
location = '{} ({})'.format(event.room_name, location)
description = '{}\n\n{}'.format(truncate(event.description, 1000), event.short_external_url).strip()
google_calendar_params = {
'action': 'TEMPLATE',
'text': event.title,
'dates': '{}/{}'.format(event.start_dt.strftime('%Y%m%dT%H%M%SZ'),
event.end_dt.strftime('%Y%m%dT%H%M%SZ')),
'details': description,
'location': location,
'trp': False,
'sprop': [event.external_url, 'name:indico']
}
social_settings_data = social_settings.get_all()
show_social = social_settings_data['enabled'] and layout_settings.get(event, 'show_social_badges')
return render_template('events/footer.html',
event=event,
dark=dark,
social_settings=social_settings_data,
show_social=show_social,
google_calendar_params=google_calendar_params)
class WPReferenceTypes(WPAdmin):
template_prefix = 'events/'
class WPEventBase(WPDecorated):
def __init__(self, rh, event_, **kwargs):
assert event_ == kwargs.setdefault('event', event_)
self.event = event_
WPDecorated.__init__(self, rh, **kwargs)
start_dt_local = event_.start_dt_display.astimezone(event_.display_tzinfo)
end_dt_local = event_.end_dt_display.astimezone(event_.display_tzinfo)
dates = ' ({})'.format(to_unicode(format_date(start_dt_local, format='long')))
if start_dt_local.date() != end_dt_local.date():
if start_dt_local.year == end_dt_local.year and start_dt_local.month == end_dt_local.month:
dates = ' ({}-{})'.format(start_dt_local.day, to_unicode(format_date(end_dt_local, format='long')))
else:
dates = ' ({} - {})'.format(to_unicode(format_date(start_dt_local, format='long')),
to_unicode(format_date(end_dt_local, format='long')))
self._setTitle('{} {}'.format(strip_tags(self.event.title), dates))
def _getHeader(self):
raise NotImplementedError # must be overridden by meeting/lecture and conference WPs
def getJSFiles(self):
return WPDecorated.getJSFiles(self) + self._asset_env['modules_event_display_js'].urls()
def _getHeadContent(self):
site_name = core_settings.get('site_title')
meta = render_template('events/meta.html', event=self.event, site_name=site_name)
return WPDecorated._getHeadContent(self) + meta
class WPSimpleEventDisplayBase(MathjaxMixin, WPEventBase):
"""Base class for displaying something on a lecture/meeting page"""
def __init__(self, rh, event_, **kwargs):
self.event = event_
WPEventBase.__init__(self, rh, event_, **kwargs)
def _getHeader(self):
return render_event_header(self.event).encode('utf-8')
def _getFooter(self):
return render_event_footer(self.event).encode('utf-8')
class WPSimpleEventDisplay(WPSimpleEventDisplayBase):
def __init__(self, rh, conf, theme_id, theme_override=False):
WPSimpleEventDisplayBase.__init__(self, rh, conf)
self.theme_id = theme_id
self.theme = theme_settings.themes[theme_id]
self.theme_override = theme_override
def _getHeadContent(self):
return MathjaxMixin._getHeadContent(self) + WPEventBase._getHeadContent(self)
def get_extra_css_files(self):
theme_urls = self.theme['asset_env']['display_sass'].urls() if self.theme.get('asset_env') else []
custom_url = get_css_url(self.event)
return theme_urls + ([custom_url] if custom_url else [])
def getPrintCSSFiles(self):
theme_print_sass = (self.theme['asset_env']['print_sass'].urls()
if 'print_sass' in self.theme.get('asset_env', [])
else [])
return WPEventBase.getPrintCSSFiles(self) + theme_print_sass
def getJSFiles(self):
return (WPSimpleEventDisplayBase.getJSFiles(self) +
self._asset_env['modules_event_cloning_js'].urls() +
self._asset_env['modules_vc_js'].urls())
def _applyDecoration(self, body):
if request.args.get('frame') == 'no' or request.args.get('fr') == 'no' or request.args.get('print') == '1':
return render_template('events/display/print.html', content=body)
else:
return WPEventBase._applyDecoration(self, body)
def _getHeader(self):
return render_event_header(self.event, theme=self.theme_id, theme_override=self.theme_override).encode('utf-8')
def _getFooter(self):
return render_event_footer(self.event, dark=True).encode('utf-8')
def _getBody(self, params):
attached_items = self.event.attached_items
folders = [folder for folder in attached_items.get('folders', []) if folder.title != 'Internal Page Files']
files = attached_items.get('files', [])
lectures = []
if self.event.series is not None and self.event.series.show_links:
lectures = (Event.query.with_parent(self.event.series)
.filter(Event.id != self.event.id)
.options(load_only('series_pos', 'id'))
.order_by(Event.series_pos)
.all())
plugin = self.theme.get('plugin')
tpl_name = self.theme['template']
tpl = ((plugin.name + tpl_name)
if (plugin and tpl_name[0] == ':')
else posixpath.join('events/display', tpl_name))
rv = render_template(tpl,
event=self.event,
category=self.event.category.title,
timezone=self.event.display_tzinfo,
theme_settings=self.theme.get('settings', {}),
theme_user_settings=layout_settings.get(self.event, 'timetable_theme_settings'),
files=files,
folders=folders,
lectures=lectures)
return rv.encode('utf-8')
class WPConferenceDisplayBase(WPJinjaMixin, MathjaxMixin, WPEventBase):
menu_entry_plugin = None
menu_entry_name = None
def __init__(self, rh, event_, **kwargs):
assert event_ == kwargs.setdefault('event', event_)
self.event = event_
kwargs['conf_layout_params'] = self._get_layout_params()
WPEventBase.__init__(self, rh, event_, **kwargs)
def _get_layout_params(self):
bg_color = layout_settings.get(self.event, 'header_background_color').replace('#', '').lower()
text_color = layout_settings.get(self.event, 'header_text_color').replace('#', '').lower()
announcement = ''
if layout_settings.get(self.event, 'show_announcement'):
announcement = layout_settings.get(self.event, 'announcement')
return {
'menu': menu_entries_for_event(self.event),
'active_menu_item': self.sidemenu_option,
'bg_color_css': 'background: #{0}; border-color: #{0};'.format(bg_color) if bg_color else '',
'text_color_css': 'color: #{};'.format(text_color) if text_color else '',
'announcement': announcement
}
def get_extra_css_files(self):
theme_url = self._kwargs.get('css_url_override', get_css_url(self.event))
return [theme_url] if theme_url else []
def _getHeader(self):
return render_event_header(self.event, conference_layout=True).encode('utf-8')
@property
def sidemenu_option(self):
if not self.menu_entry_name:
return None
name = build_menu_entry_name(self.menu_entry_name, self.menu_entry_plugin)
entry = get_menu_entry_by_name(name, self.event)
if entry:
return entry.id
def _getHeadContent(self):
path = config.BASE_URL
try:
timestamp = os.stat(__file__).st_mtime
except OSError:
timestamp = 0
css = '<link rel="stylesheet" type="text/css" href="{}/css/Conf_Basic.css?{}">'.format(path, timestamp)
return '\n'.join([
css,
MathjaxMixin._getHeadContent(self),
WPEventBase._getHeadContent(self)
])
def _getBody(self, params):
return WPJinjaMixin._getPageContent(self, params)
def _applyDecoration(self, body):
self.logo_url = self.event.logo_url if self.event.has_logo else None
css_override_form = self._kwargs.get('css_override_form')
if css_override_form:
override_html = render_template('events/layout/css_preview_header.html',
event=self.event, form=css_override_form,
download_url=self._kwargs['css_url_override'])
body = override_html + body
return WPEventBase._applyDecoration(self, to_unicode(body))
class WPConferenceDisplay(WPConferenceDisplayBase):
menu_entry_name = 'overview'
def _getBody(self, params):
return render_template('events/display/conference.html', **self._kwargs)
def _getFooter(self):
return render_event_footer(self.event).encode('utf-8')
class WPAccessKey(WPJinjaMixin, WPDecorated):
template_prefix = 'events/'
def _getBody(self, params):
return self._getPageContent(params)
|
gpl-3.0
|
[
3,
961,
570,
365,
1777,
402,
1010,
27347,
14,
199,
3,
1898,
334,
35,
9,
14790,
446,
9708,
31615,
290,
18863,
367,
653,
947,
4025,
26993,
334,
35,
14482,
680,
199,
3,
199,
3,
1010,
27347,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1010,
27347,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
1010,
27347,
27,
340,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
646,
747,
199,
646,
15454,
199,
199,
504,
7209,
492,
3795,
63,
1160,
12,
1056,
199,
504,
8335,
14,
1025,
492,
2248,
63,
2118,
199,
199,
504,
2539,
331,
14,
1018,
14,
888,
492,
1101,
199,
504,
2539,
331,
14,
3112,
14,
2113,
14,
4196,
492,
644,
48,
4880,
199,
504,
2539,
331,
14,
3112,
14,
1018,
14,
1751,
492,
6170,
63,
1751,
12,
20295,
63,
1751,
199,
504,
2539,
331,
14,
3112,
14,
4368,
492,
6763,
199,
504,
2539,
331,
14,
3112,
14,
4368,
14,
4209,
492,
7054,
63,
1751,
12,
8879,
63,
1751,
199,
504,
2539,
331,
14,
3112,
14,
4368,
14,
4209,
14,
1974,
492,
334,
1506,
63,
4470,
63,
2373,
63,
354,
12,
664,
63,
3919,
63,
633,
12,
664,
63,
4470,
63,
2373,
63,
991,
63,
354,
12,
6901,
6269,
63,
3189,
63,
509,
63,
1430,
9,
199,
504,
2539,
331,
14,
3112,
14,
4368,
14,
992,
14,
4368,
492,
6763,
804,
199,
504,
2539,
331,
14,
1974,
14,
602,
63,
521,
492,
1475,
63,
602,
199,
504,
2539,
331,
14,
1974,
14,
3442,
15863,
492,
21066,
15863,
4256,
199,
504,
2539,
331,
14,
1974,
14,
875,
492,
6202,
63,
2969,
12,
370,
63,
2975,
12,
14547,
199,
504,
2539,
331,
14,
2520,
14,
15720,
14,
1974,
492,
1166,
63,
509,
199,
504,
2539,
331,
14,
2520,
14,
4196,
492,
644,
48,
8584,
269,
972,
12,
644,
48,
42,
4135,
4256,
421,
199,
318,
485,
362,
63,
1361,
63,
633,
8,
1430,
12,
8879,
29,
403,
12,
8879,
63,
4415,
29,
797,
304,
272,
2455,
275,
8879,
340,
8879,
63,
4415,
587,
488,
339,
340,
1566,
14,
466,
63,
508,
6763,
804,
14,
30570,
26,
267,
372,
1166,
63,
509,
360,
521,
1224,
14,
521,
1224,
297,
1566,
12,
870,
534,
17,
297,
2455,
29,
1345,
9,
272,
916,
1566,
14,
466,
63,
508,
6763,
804,
14,
278,
13800,
26,
267,
2498,
63,
602,
275,
1056,
14,
589,
14,
362,
360,
2384,
2506,
358,
267,
2498,
63,
1730,
275,
1056,
14,
589,
14,
362,
360,
2384,
4434,
358,
267,
10093,
63,
1896,
275,
1056,
14,
589,
14,
362,
360,
5506,
4670,
358,
267,
340,
2498,
63,
602,
508,
283,
452,
356,
288,
2498,
63,
602,
275,
488,
267,
340,
2498,
63,
1730,
508,
283,
452,
356,
288,
2498,
63,
1730,
275,
488,
267,
340,
10093,
63,
1896,
315,
661,
452,
297,
283,
388,
454,
262,
464,
296,
735,
288,
10093,
63,
1896,
275,
488,
267,
372,
1166,
63,
509,
360,
4368,
14,
2918,
297,
1566,
12,
2498,
2506,
29,
2384,
63,
602,
12,
2498,
4434,
29,
2384,
63,
1730,
12,
10093,
4670,
29,
5506,
63,
1896,
12,
2432,
870,
534,
17,
297,
2455,
29,
1345,
9,
272,
916,
1566,
14,
466,
63,
508,
6763,
804,
14,
1264,
608,
26,
267,
372,
1166,
63,
509,
360,
4368,
14,
2918,
297,
1566,
12,
870,
534,
17,
297,
2455,
29,
1345,
9,
421,
199,
318,
3795,
63,
1430,
63,
1291,
8,
1430,
12,
406,
1769,
63,
4209,
29,
797,
12,
8879,
29,
403,
12,
8879,
63,
4415,
29,
797,
304,
272,
870,
63,
633,
275,
485,
362,
63,
1361,
63,
633,
8,
1430,
12,
8879,
12,
8879,
63,
4415,
9,
340,
440,
406,
1769,
63,
4209,
587,
488,
272,
2498,
63,
10927,
63,
1700,
275,
1566,
14,
466,
63,
1137,
6763,
804,
14,
30570,
503,
7054,
63,
1751,
14,
362,
8,
1430,
12,
283,
2384,
63,
10927,
63,
1700,
358,
272,
17915,
275,
469,
5700,
26,
791,
354,
356,
666,
459,
1213,
995,
283,
751,
63,
6604,
356,
666,
14,
362,
360,
751,
63,
6604,
21004,
1598,
367,
11559,
12,
666,
315,
8879,
63,
1751,
14,
362,
63,
23900,
63,
509,
8,
1430,
14,
466,
3754,
354,
680,
1345,
1744,
12737,
272,
372,
3795,
63,
1160,
360,
4368,
15,
1291,
14,
1360,
297,
2574,
1566,
29,
1430,
12,
870,
63,
633,
29,
1361,
63,
633,
12,
2498,
63,
10927,
63,
1700,
29,
2384,
63,
10927,
63,
1700,
12,
17915,
29,
23900,
12,
8879,
29,
7915,
9,
421,
199,
318,
3795,
63,
1430,
63,
12781,
8,
1430,
12,
23531,
29,
797,
304,
272,
2909,
275,
1566,
14,
24728,
63,
354,
272,
340,
1566,
14,
11245,
63,
354,
26,
267,
2909,
275,
9005,
11459,
25885,
908,
8,
1430,
14,
11245,
63,
354,
12,
2909,
9,
272,
1369,
275,
9005,
60,
78,
60,
78,
11123,
908,
8,
12517,
8,
1430,
14,
1802,
12,
5198,
395,
1566,
14,
3612,
63,
5159,
63,
633,
680,
1913,
342,
272,
6233,
63,
8183,
63,
1162,
275,
469,
267,
283,
1287,
356,
283,
7433,
297,
267,
283,
505,
356,
1566,
14,
1213,
12,
267,
283,
9356,
356,
9005,
30837,
908,
8,
1430,
14,
928,
63,
3583,
14,
6205,
3508,
57,
5,
77,
5,
19772,
5,
40,
5,
45,
5,
18101,
659,
1816,
1566,
14,
500,
63,
3583,
14,
6205,
3508,
57,
5,
77,
5,
19772,
5,
40,
5,
45,
5,
18101,
3855,
267,
283,
5087,
356,
1369,
12,
267,
283,
1985,
356,
2909,
12
] |
[
961,
570,
365,
1777,
402,
1010,
27347,
14,
199,
3,
1898,
334,
35,
9,
14790,
446,
9708,
31615,
290,
18863,
367,
653,
947,
4025,
26993,
334,
35,
14482,
680,
199,
3,
199,
3,
1010,
27347,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1010,
27347,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
1010,
27347,
27,
340,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
646,
747,
199,
646,
15454,
199,
199,
504,
7209,
492,
3795,
63,
1160,
12,
1056,
199,
504,
8335,
14,
1025,
492,
2248,
63,
2118,
199,
199,
504,
2539,
331,
14,
1018,
14,
888,
492,
1101,
199,
504,
2539,
331,
14,
3112,
14,
2113,
14,
4196,
492,
644,
48,
4880,
199,
504,
2539,
331,
14,
3112,
14,
1018,
14,
1751,
492,
6170,
63,
1751,
12,
20295,
63,
1751,
199,
504,
2539,
331,
14,
3112,
14,
4368,
492,
6763,
199,
504,
2539,
331,
14,
3112,
14,
4368,
14,
4209,
492,
7054,
63,
1751,
12,
8879,
63,
1751,
199,
504,
2539,
331,
14,
3112,
14,
4368,
14,
4209,
14,
1974,
492,
334,
1506,
63,
4470,
63,
2373,
63,
354,
12,
664,
63,
3919,
63,
633,
12,
664,
63,
4470,
63,
2373,
63,
991,
63,
354,
12,
6901,
6269,
63,
3189,
63,
509,
63,
1430,
9,
199,
504,
2539,
331,
14,
3112,
14,
4368,
14,
992,
14,
4368,
492,
6763,
804,
199,
504,
2539,
331,
14,
1974,
14,
602,
63,
521,
492,
1475,
63,
602,
199,
504,
2539,
331,
14,
1974,
14,
3442,
15863,
492,
21066,
15863,
4256,
199,
504,
2539,
331,
14,
1974,
14,
875,
492,
6202,
63,
2969,
12,
370,
63,
2975,
12,
14547,
199,
504,
2539,
331,
14,
2520,
14,
15720,
14,
1974,
492,
1166,
63,
509,
199,
504,
2539,
331,
14,
2520,
14,
4196,
492,
644,
48,
8584,
269,
972,
12,
644,
48,
42,
4135,
4256,
421,
199,
318,
485,
362,
63,
1361,
63,
633,
8,
1430,
12,
8879,
29,
403,
12,
8879,
63,
4415,
29,
797,
304,
272,
2455,
275,
8879,
340,
8879,
63,
4415,
587,
488,
339,
340,
1566,
14,
466,
63,
508,
6763,
804,
14,
30570,
26,
267,
372,
1166,
63,
509,
360,
521,
1224,
14,
521,
1224,
297,
1566,
12,
870,
534,
17,
297,
2455,
29,
1345,
9,
272,
916,
1566,
14,
466,
63,
508,
6763,
804,
14,
278,
13800,
26,
267,
2498,
63,
602,
275,
1056,
14,
589,
14,
362,
360,
2384,
2506,
358,
267,
2498,
63,
1730,
275,
1056,
14,
589,
14,
362,
360,
2384,
4434,
358,
267,
10093,
63,
1896,
275,
1056,
14,
589,
14,
362,
360,
5506,
4670,
358,
267,
340,
2498,
63,
602,
508,
283,
452,
356,
288,
2498,
63,
602,
275,
488,
267,
340,
2498,
63,
1730,
508,
283,
452,
356,
288,
2498,
63,
1730,
275,
488,
267,
340,
10093,
63,
1896,
315,
661,
452,
297,
283,
388,
454,
262,
464,
296,
735,
288,
10093,
63,
1896,
275,
488,
267,
372,
1166,
63,
509,
360,
4368,
14,
2918,
297,
1566,
12,
2498,
2506,
29,
2384,
63,
602,
12,
2498,
4434,
29,
2384,
63,
1730,
12,
10093,
4670,
29,
5506,
63,
1896,
12,
2432,
870,
534,
17,
297,
2455,
29,
1345,
9,
272,
916,
1566,
14,
466,
63,
508,
6763,
804,
14,
1264,
608,
26,
267,
372,
1166,
63,
509,
360,
4368,
14,
2918,
297,
1566,
12,
870,
534,
17,
297,
2455,
29,
1345,
9,
421,
199,
318,
3795,
63,
1430,
63,
1291,
8,
1430,
12,
406,
1769,
63,
4209,
29,
797,
12,
8879,
29,
403,
12,
8879,
63,
4415,
29,
797,
304,
272,
870,
63,
633,
275,
485,
362,
63,
1361,
63,
633,
8,
1430,
12,
8879,
12,
8879,
63,
4415,
9,
340,
440,
406,
1769,
63,
4209,
587,
488,
272,
2498,
63,
10927,
63,
1700,
275,
1566,
14,
466,
63,
1137,
6763,
804,
14,
30570,
503,
7054,
63,
1751,
14,
362,
8,
1430,
12,
283,
2384,
63,
10927,
63,
1700,
358,
272,
17915,
275,
469,
5700,
26,
791,
354,
356,
666,
459,
1213,
995,
283,
751,
63,
6604,
356,
666,
14,
362,
360,
751,
63,
6604,
21004,
1598,
367,
11559,
12,
666,
315,
8879,
63,
1751,
14,
362,
63,
23900,
63,
509,
8,
1430,
14,
466,
3754,
354,
680,
1345,
1744,
12737,
272,
372,
3795,
63,
1160,
360,
4368,
15,
1291,
14,
1360,
297,
2574,
1566,
29,
1430,
12,
870,
63,
633,
29,
1361,
63,
633,
12,
2498,
63,
10927,
63,
1700,
29,
2384,
63,
10927,
63,
1700,
12,
17915,
29,
23900,
12,
8879,
29,
7915,
9,
421,
199,
318,
3795,
63,
1430,
63,
12781,
8,
1430,
12,
23531,
29,
797,
304,
272,
2909,
275,
1566,
14,
24728,
63,
354,
272,
340,
1566,
14,
11245,
63,
354,
26,
267,
2909,
275,
9005,
11459,
25885,
908,
8,
1430,
14,
11245,
63,
354,
12,
2909,
9,
272,
1369,
275,
9005,
60,
78,
60,
78,
11123,
908,
8,
12517,
8,
1430,
14,
1802,
12,
5198,
395,
1566,
14,
3612,
63,
5159,
63,
633,
680,
1913,
342,
272,
6233,
63,
8183,
63,
1162,
275,
469,
267,
283,
1287,
356,
283,
7433,
297,
267,
283,
505,
356,
1566,
14,
1213,
12,
267,
283,
9356,
356,
9005,
30837,
908,
8,
1430,
14,
928,
63,
3583,
14,
6205,
3508,
57,
5,
77,
5,
19772,
5,
40,
5,
45,
5,
18101,
659,
1816,
1566,
14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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
JiYouMCC/python
|
renzongxian/0022/0022.py
|
40
|
1696
|
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
# Author:renzongxian
# Date:2014-12-24
# Python 3.4
"""
第 0022 题: iPhone 6、iPhone 6 Plus 早已上市开卖。请查看你写得 第 0005 题的代码是否可以复用。
"""
from PIL import Image
import os
import sys
def resize_image(image, t_weight, t_height):
im = Image.open(image)
weight, height = im.size
if weight > t_weight or height > t_height:
dw = weight / t_weight
dh = height / t_height
ds = max(dw, dh)
new_weight = int(weight / ds)
new_height = int(height / ds)
im = im.resize((new_weight, new_height))
print("Succeed to resize the image %s to %s*%s " % (image, new_weight, new_height))
im.save(image)
else:
print("The image %s doesn't need to be resized." % image)
if __name__ == "__main__":
trans_weight = 0
trans_height = 0
if len(sys.argv) <= 1:
print("Need at least 1 parameter. Try to execute 'python 0022.py $dir_path'")
else:
while True:
flag = input("请选择你要转换的分辨率: 1. iPhone 6 2. iPhone 6 Plus:")
if flag == '1':
trans_weight = 750
trans_height = 1334
break
elif flag == '2':
trans_weight = 1080
trans_height = 1920
break
else:
print("输入有误,重新选择!")
for dir_path in sys.argv[1:]:
for image_name in os.listdir(dir_path):
image_path = os.path.join(dir_path, image_name)
resize_image(image_path, trans_weight, trans_height)
|
mit
|
[
3,
5800,
26,
2859,
921,
5031,
14,
957,
15,
6824,
13,
1352,
13,
1589,
13,
3034,
15,
2384,
13,
278,
13,
1589,
13,
600,
199,
3,
6529,
26,
828,
90,
951,
88,
5653,
199,
3,
6148,
26,
7280,
13,
713,
13,
1194,
199,
3,
2018,
650,
14,
20,
199,
199,
624,
199,
199,
25238,
106,
378,
16348,
10469,
96,
247,
25742,
284,
15199,
1227,
23709,
73,
15199,
1227,
7497,
527,
8853,
246,
103,
28913,
22661,
15280,
225,
26683,
10450,
245,
20061,
25977,
21788,
164,
251,
234,
11046,
255,
17950,
248,
19073,
246,
9112,
106,
106,
378,
7972,
10469,
96,
247,
8106,
10635,
9729,
8197,
100,
25521,
23681,
11546,
236,
11428,
20061,
199,
199,
624,
199,
199,
504,
14937,
492,
6047,
199,
646,
747,
199,
646,
984,
421,
199,
318,
15210,
63,
1569,
8,
1569,
12,
307,
63,
3463,
12,
307,
63,
3333,
304,
272,
3416,
275,
6047,
14,
1490,
8,
1569,
9,
272,
5401,
12,
4569,
275,
3416,
14,
890,
272,
340,
5401,
690,
307,
63,
3463,
503,
4569,
690,
307,
63,
3333,
26,
267,
17594,
275,
5401,
1182,
307,
63,
3463,
267,
31387,
275,
4569,
1182,
307,
63,
3333,
267,
6364,
275,
1390,
8,
10772,
12,
31387,
9,
267,
892,
63,
3463,
275,
1109,
8,
3463,
1182,
6364,
9,
267,
892,
63,
3333,
275,
1109,
8,
3333,
1182,
6364,
9,
267,
3416,
275,
3416,
14,
8709,
1332,
1222,
63,
3463,
12,
892,
63,
3333,
430,
267,
870,
480,
22937,
379,
370,
15210,
314,
1834,
450,
83,
370,
450,
83,
32639,
83,
298,
450,
334,
1569,
12,
221,
892,
63,
3463,
12,
892,
63,
3333,
430,
267,
3416,
14,
2117,
8,
1569,
9,
272,
587,
26,
267,
870,
480,
1918,
1834,
450,
83,
3181,
1133,
1929,
370,
506,
295,
15308,
2122,
450,
1834,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1752,
63,
3463,
275,
378,
272,
1752,
63,
3333,
275,
378,
272,
340,
822,
8,
1274,
14,
3020,
9,
2695,
413,
26,
267,
870,
480,
17809,
737,
5210,
413,
2725,
14,
7649,
370,
5341,
283,
1548,
378,
16348,
14,
647,
2672,
694,
63,
515,
9859,
272,
587,
26,
267,
1830,
715,
26,
288,
3305,
275,
1324,
480,
25977,
14333,
232,
163,
234,
103,
11046,
255,
22274,
30229,
17109,
96,
8106,
21514,
27252,
102,
23434,
230,
26,
413,
14,
284,
15199,
1227,
221,
499,
14,
284,
15199,
1227,
7497,
527,
9107,
288,
340,
3305,
508,
283,
17,
356,
355,
1752,
63,
3463,
275,
1520,
1400,
355,
1752,
63,
3333,
275,
4944,
1082,
355,
2059,
288,
916,
3305,
508,
283,
18,
356,
355,
1752,
63,
3463,
275,
1616,
1257,
355,
1752,
63,
3333,
275,
5851,
1165,
355,
2059,
288,
587,
26,
355,
870,
480,
27252,
242,
18236,
20916,
31058,
12356,
10770,
236,
22737,
14333,
232,
163,
234,
103,
9124,
267,
367,
2935,
63,
515,
315,
984,
14,
3020,
59,
17,
10688,
288,
367,
1834,
63,
354,
315,
747,
14,
7374,
8,
694,
63,
515,
304,
355,
1834,
63,
515,
275,
747,
14,
515,
14,
904,
8,
694,
63,
515,
12,
1834,
63,
354,
9,
355,
15210,
63,
1569,
8,
1569,
63,
515,
12,
1752,
63,
3463,
12,
1752,
63,
3333,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
5800,
26,
2859,
921,
5031,
14,
957,
15,
6824,
13,
1352,
13,
1589,
13,
3034,
15,
2384,
13,
278,
13,
1589,
13,
600,
199,
3,
6529,
26,
828,
90,
951,
88,
5653,
199,
3,
6148,
26,
7280,
13,
713,
13,
1194,
199,
3,
2018,
650,
14,
20,
199,
199,
624,
199,
199,
25238,
106,
378,
16348,
10469,
96,
247,
25742,
284,
15199,
1227,
23709,
73,
15199,
1227,
7497,
527,
8853,
246,
103,
28913,
22661,
15280,
225,
26683,
10450,
245,
20061,
25977,
21788,
164,
251,
234,
11046,
255,
17950,
248,
19073,
246,
9112,
106,
106,
378,
7972,
10469,
96,
247,
8106,
10635,
9729,
8197,
100,
25521,
23681,
11546,
236,
11428,
20061,
199,
199,
624,
199,
199,
504,
14937,
492,
6047,
199,
646,
747,
199,
646,
984,
421,
199,
318,
15210,
63,
1569,
8,
1569,
12,
307,
63,
3463,
12,
307,
63,
3333,
304,
272,
3416,
275,
6047,
14,
1490,
8,
1569,
9,
272,
5401,
12,
4569,
275,
3416,
14,
890,
272,
340,
5401,
690,
307,
63,
3463,
503,
4569,
690,
307,
63,
3333,
26,
267,
17594,
275,
5401,
1182,
307,
63,
3463,
267,
31387,
275,
4569,
1182,
307,
63,
3333,
267,
6364,
275,
1390,
8,
10772,
12,
31387,
9,
267,
892,
63,
3463,
275,
1109,
8,
3463,
1182,
6364,
9,
267,
892,
63,
3333,
275,
1109,
8,
3333,
1182,
6364,
9,
267,
3416,
275,
3416,
14,
8709,
1332,
1222,
63,
3463,
12,
892,
63,
3333,
430,
267,
870,
480,
22937,
379,
370,
15210,
314,
1834,
450,
83,
370,
450,
83,
32639,
83,
298,
450,
334,
1569,
12,
221,
892,
63,
3463,
12,
892,
63,
3333,
430,
267,
3416,
14,
2117,
8,
1569,
9,
272,
587,
26,
267,
870,
480,
1918,
1834,
450,
83,
3181,
1133,
1929,
370,
506,
295,
15308,
2122,
450,
1834,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1752,
63,
3463,
275,
378,
272,
1752,
63,
3333,
275,
378,
272,
340,
822,
8,
1274,
14,
3020,
9,
2695,
413,
26,
267,
870,
480,
17809,
737,
5210,
413,
2725,
14,
7649,
370,
5341,
283,
1548,
378,
16348,
14,
647,
2672,
694,
63,
515,
9859,
272,
587,
26,
267,
1830,
715,
26,
288,
3305,
275,
1324,
480,
25977,
14333,
232,
163,
234,
103,
11046,
255,
22274,
30229,
17109,
96,
8106,
21514,
27252,
102,
23434,
230,
26,
413,
14,
284,
15199,
1227,
221,
499,
14,
284,
15199,
1227,
7497,
527,
9107,
288,
340,
3305,
508,
283,
17,
356,
355,
1752,
63,
3463,
275,
1520,
1400,
355,
1752,
63,
3333,
275,
4944,
1082,
355,
2059,
288,
916,
3305,
508,
283,
18,
356,
355,
1752,
63,
3463,
275,
1616,
1257,
355,
1752,
63,
3333,
275,
5851,
1165,
355,
2059,
288,
587,
26,
355,
870,
480,
27252,
242,
18236,
20916,
31058,
12356,
10770,
236,
22737,
14333,
232,
163,
234,
103,
9124,
267,
367,
2935,
63,
515,
315,
984,
14,
3020,
59,
17,
10688,
288,
367,
1834,
63,
354,
315,
747,
14,
7374,
8,
694,
63,
515,
304,
355,
1834,
63,
515,
275,
747,
14,
515,
14,
904,
8,
694,
63,
515,
12,
1834,
63,
354,
9,
355,
15210,
63,
1569,
8,
1569,
63,
515,
12,
1752,
63,
3463,
12,
1752,
63,
3333,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
CERNDocumentServer/cds
|
cds/modules/records/api.py
|
2
|
8723
|
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2017, 2018 CERN.
#
# Invenio is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Invenio is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.
"""Record API."""
from __future__ import absolute_import, print_function
import os
import uuid
from os.path import splitext
from flask import current_app
from invenio_files_rest.models import ObjectVersion, ObjectVersionTag
from invenio_jsonschemas import current_jsonschemas
from invenio_pidstore.models import PersistentIdentifier
from invenio_records_files.api import FileObject, FilesIterator, Record
from invenio_records_files.utils import sorted_files_from_bucket
from sqlalchemy import func
from .fetchers import recid_fetcher
from .minters import kwid_minter
def dump_object(obj):
"""Dump a object."""
tags = obj.get_tags()
# File information
content_type = splitext(obj.key)[1][1:].lower()
context_type = tags.pop('context_type', '')
media_type = tags.pop('media_type', '')
return {
'key': obj.key,
'bucket_id': str(obj.bucket_id),
'version_id': str(obj.version_id),
'checksum': obj.file.checksum if obj.file else '',
'size': obj.file.size if obj.file else 0,
'file_id': str(obj.file_id),
'completed': obj.file is not None,
'content_type': content_type,
'context_type': context_type,
'media_type': media_type,
'tags': tags,
'links': _build_file_links(obj)
}
def _build_file_links(obj):
"""Return a dict with file links."""
return dict(
self=(
u'{scheme}://{host}/{api}/{bucket}/{key}?versionId={version_id}'
.format(
# TODO: JSONSchema host is not the best solution here.
scheme=current_app.config['JSONSCHEMAS_URL_SCHEME'],
host=current_app.config['JSONSCHEMAS_HOST'],
api=current_app.config['DEPOSIT_FILES_API'].strip('/'),
bucket=obj.bucket_id,
key=obj.key,
version_id=obj.version_id,
)))
def dump_generic_object(obj, data):
"""Dump a generic object (master, subtitles, ..) avoid depending objs."""
obj_dump = dump_object(obj)
# if it's a master, get all the depending object and add them inside
# <context_type> as a list order by key.
for slave in ObjectVersion.query_heads_by_bucket(bucket=obj.bucket).join(
ObjectVersion.tags).filter(
ObjectVersion.file_id.isnot(None),
ObjectVersionTag.key == 'master',
ObjectVersionTag.value == str(obj.version_id)).order_by(
func.length(ObjectVersion.key), ObjectVersion.key):
obj_dump.setdefault(slave.get_tags()['context_type'], []).append(
dump_object(slave))
# Sort slaves by key within their lists
data.update(obj_dump)
class CDSFileObject(FileObject):
"""Wrapper for files."""
@classmethod
def _link(cls, bucket_id, key, _external=True):
return u'{scheme}://{host}/{api}/{bucket_id}/{key}'.format(
scheme=current_app.config['JSONSCHEMAS_URL_SCHEME'],
host=current_app.config['JSONSCHEMAS_HOST'],
api=current_app.config['DEPOSIT_FILES_API'].lstrip('/'),
bucket_id=bucket_id,
key=key,
)
def dumps(self):
"""Create a dump of the metadata associated to the record."""
dump_generic_object(obj=self.obj, data=self.data)
return self.data
class CDSFilesIterator(FilesIterator):
"""Iterator for files."""
def dumps(self, bucket=None):
"""Serialize files from a bucket."""
files = []
for o in sorted_files_from_bucket(bucket or self.bucket, self.keys):
if 'master' in o.get_tags():
continue
dump = self.file_cls(o, self.filesmap.get(o.key, {})).dumps()
if dump:
files.append(dump)
return files
class CDSVideosFilesIterator(CDSFilesIterator):
"""Video files iterator."""
@staticmethod
def get_master_video_file(record):
"""Get master video file from a Video record."""
try:
return next(f for f in record['_files']
if f['media_type'] == 'video'
and f['context_type'] == 'master')
except StopIteration:
return {}
@staticmethod
def get_video_subformats(master_file):
"""Get list of video subformats."""
return [
video for video in master_file.get('subformat', [])
if video['media_type'] == 'video'
and video['context_type'] == 'subformat'
]
@staticmethod
def get_video_subtitles(record):
"""Get list of video subtitles."""
return [
f for f in record['_files']
if f['context_type'] == 'subtitle' and 'language' in f['tags']
]
@staticmethod
def get_video_frames(master_file):
"""Get sorted list of video frames."""
return sorted(
master_file.get('frame', []),
key=lambda s: float(s['tags']['timestamp']))
@staticmethod
def get_video_posterframe(record):
"""Get the video poster frame."""
# First check if we have a custom thumbnail for this video
for f in record.get('_files'):
if f.get('context_type') == 'poster' and f.get(
'media_type') == 'image':
return f
# If not return the first frame from the list
master_file = CDSVideosFilesIterator.get_master_video_file(record)
return CDSVideosFilesIterator.get_video_frames(master_file)[0]
class CDSRecord(Record):
"""CDS Record."""
file_cls = CDSFileObject
files_iter_cls = CDSFilesIterator
record_fetcher = staticmethod(recid_fetcher)
@property
def pid(self):
"""Return an instance of record PID."""
pid = self.record_fetcher(self.id, self)
return PersistentIdentifier.get(pid.pid_type, pid.pid_value)
@property
def depid(self):
"""Return depid of the record."""
return PersistentIdentifier.get(
pid_type='depid', pid_value=self.get('_deposit', {}).get('id'))
class Keyword(Record):
"""Define API for a keywords."""
_schema = 'keywords/keyword-v1.0.0.json'
@classmethod
def create(cls, data, id_=None, **kwargs):
"""Create a keyword."""
data['$schema'] = current_jsonschemas.path_to_url(cls._schema)
key_id = data.get('key_id', None)
name = data.get('name', None)
data.setdefault('deleted', False)
if not id_:
id_ = uuid.uuid4()
kwid_minter(id_, data)
data['suggest_name'] = {
'input': name,
'payload': {
'key_id': key_id,
'name': name
},
}
return super(Keyword, cls).create(data=data, id_=id_, **kwargs)
@property
def ref(self):
"""Get the url."""
return Keyword.get_ref(self['key_id'])
@classmethod
def get_id(cls, ref):
"""Get the ID from the reference."""
return os.path.basename(ref)
@classmethod
def get_ref(cls, id_):
"""Get reference from an ID."""
return 'https://cds.cern.ch/api/keywords/{0}'.format(str(id_))
class Category(Record):
"""Define API for a category."""
_schema = 'categories/category-v1.0.0.json'
@classmethod
def create(cls, data, id_=None, **kwargs):
"""Create a category."""
data['$schema'] = current_jsonschemas.path_to_url(cls._schema)
data['suggest_name'] = {
'input': data.get('name', None),
'payload': {
'types': data.get('types', [])
}
}
return super(Category, cls).create(data=data, id_=id_, **kwargs)
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
9708,
12,
14894,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
199,
3,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
199,
3,
2997,
12,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
199,
3,
2868,
2290,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
199,
3,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
3,
199,
3,
1010,
18876,
642,
4190,
12,
24354,
1630,
440,
199,
3,
14442,
1912,
314,
20001,
436,
25531,
22047,
10009,
370,
652,
701,
12043,
310,
402,
2399,
2004,
199,
3,
465,
376,
6551,
71,
27639,
279,
18863,
503,
11482,
6337,
370,
1263,
1335,
17656,
26382,
14,
199,
624,
5433,
3261,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
747,
199,
646,
5377,
199,
504,
747,
14,
515,
492,
2249,
7699,
199,
199,
504,
7209,
492,
1453,
63,
571,
199,
504,
13640,
63,
1725,
63,
3911,
14,
992,
492,
6935,
3353,
12,
6935,
3353,
1931,
199,
504,
13640,
63,
1001,
9482,
492,
1453,
63,
1001,
9482,
199,
504,
13640,
63,
3150,
1617,
14,
992,
492,
3492,
6082,
7544,
199,
504,
13640,
63,
6502,
63,
1725,
14,
1246,
492,
3814,
1692,
12,
16920,
3585,
12,
12651,
199,
504,
13640,
63,
6502,
63,
1725,
14,
1208,
492,
3355,
63,
1725,
63,
504,
63,
4623,
199,
504,
8335,
492,
2562,
199,
199,
504,
1275,
3535,
1192,
492,
25305,
63,
26983,
199,
504,
1275,
827,
878,
492,
4775,
344,
63,
827,
351,
421,
199,
318,
5461,
63,
785,
8,
1113,
304,
272,
408,
11772,
282,
909,
1041,
272,
3762,
275,
1559,
14,
362,
63,
2969,
342,
272,
327,
3814,
2556,
272,
1564,
63,
466,
275,
2249,
7699,
8,
1113,
14,
498,
2788,
17,
1527,
17,
11455,
2325,
342,
272,
1067,
63,
466,
275,
3762,
14,
1935,
360,
1100,
63,
466,
297,
4074,
272,
5898,
63,
466,
275,
3762,
14,
1935,
360,
4603,
63,
466,
297,
4074,
272,
372,
469,
267,
283,
498,
356,
1559,
14,
498,
12,
267,
283,
4623,
63,
344,
356,
620,
8,
1113,
14,
4623,
63,
344,
395,
267,
283,
1023,
63,
344,
356,
620,
8,
1113,
14,
1023,
63,
344,
395,
267,
283,
8928,
356,
1559,
14,
493,
14,
8928,
340,
1559,
14,
493,
587,
3260,
267,
283,
890,
356,
1559,
14,
493,
14,
890,
340,
1559,
14,
493,
587,
378,
12,
267,
283,
493,
63,
344,
356,
620,
8,
1113,
14,
493,
63,
344,
395,
267,
283,
12634,
356,
1559,
14,
493,
365,
440,
488,
12,
267,
283,
1317,
63,
466,
356,
1564,
63,
466,
12,
267,
283,
1100,
63,
466,
356,
1067,
63,
466,
12,
267,
283,
4603,
63,
466,
356,
5898,
63,
466,
12,
267,
283,
2969,
356,
3762,
12,
267,
283,
4614,
356,
485,
1506,
63,
493,
63,
4614,
8,
1113,
9,
272,
789,
421,
199,
318,
485,
1506,
63,
493,
63,
4614,
8,
1113,
304,
272,
408,
1767,
282,
1211,
543,
570,
6220,
1041,
272,
372,
1211,
8,
267,
291,
2687,
288,
399,
16019,
5512,
93,
20193,
1102,
16152,
1246,
16152,
4623,
16152,
498,
93,
31,
1023,
1304,
3126,
1023,
63,
344,
6834,
288,
1275,
908,
8,
355,
327,
3254,
26,
4840,
6700,
1591,
365,
440,
314,
5526,
8744,
2348,
14,
355,
5687,
29,
1818,
63,
571,
14,
888,
459,
6243,
17859,
1179,
63,
2632,
63,
30430,
995,
355,
1591,
29,
1818,
63,
571,
14,
888,
459,
6243,
17859,
1179,
63,
5449,
995,
355,
2986,
29,
1818,
63,
571,
14,
888,
459,
1093,
27998,
63,
9472,
63,
3735,
2278,
1913,
2336,
659,
355,
5315,
29,
1113,
14,
4623,
63,
344,
12,
355,
790,
29,
1113,
14,
498,
12,
355,
1015,
63,
344,
29,
1113,
14,
1023,
63,
344,
12,
288,
23183,
421,
199,
318,
5461,
63,
6767,
63,
785,
8,
1113,
12,
666,
304,
272,
408,
11772,
282,
7809,
909,
334,
4133,
12,
19297,
12,
2508,
9,
5126,
10298,
13474,
1041,
272,
1559,
63,
2724,
275,
5461,
63,
785,
8,
1113,
9,
272,
327,
340,
652,
1159,
282,
5288,
12,
664,
1006,
314,
10298,
909,
436,
1050,
3062,
6272,
272,
327,
665,
1100,
63,
466,
30,
465,
282,
769,
1865,
701,
790,
14,
272,
367,
15494,
315,
6935,
3353,
14,
1131,
63,
17033,
63,
991,
63,
4623,
8,
4623,
29,
1113,
14,
4623,
680,
904,
8,
288,
6935,
3353,
14,
2969,
680,
1541,
8,
355,
6935,
3353,
14,
493,
63,
344,
14,
374,
1397,
8,
403,
395,
355,
6935,
3353,
1931,
14,
498,
508,
283,
4133,
297,
355,
6935,
3353,
1931,
14,
585,
508,
620,
8,
1113,
14,
1023,
63,
344,
4992,
1648,
63,
991,
8,
490,
2562,
14,
1267,
8,
1692,
3353,
14,
498,
395,
6935,
3353,
14,
498,
304,
267,
1559,
63,
2724,
14,
5486,
8,
12384,
14,
362,
63,
2969,
12047,
1100,
63,
466,
995,
15364,
740,
8,
288,
5461,
63,
785,
8,
12384,
430,
272,
327,
16722,
308,
21868,
701,
790,
4453,
3932,
5548,
272,
666,
14,
873,
8,
1113,
63,
2724,
9,
421,
199,
533,
445,
3177,
1173,
1692,
8,
1173,
1692,
304,
272,
408,
4590,
367,
1584,
1041,
339,
768,
3744,
272,
347,
485,
1073,
8,
1886,
12,
5315,
63,
344,
12,
790,
12,
485,
5159,
29,
549,
304,
267,
372,
399,
16019,
5512,
93,
20193,
1102,
16152,
1246,
16152,
4623,
63,
344,
16152,
498,
5285,
908,
8,
288,
5687,
29,
1818,
63,
571,
14,
888,
459,
6243
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
9708,
12,
14894,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
199,
3,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
199,
3,
2997,
12,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
199,
3,
2868,
2290,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
199,
3,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
3,
199,
3,
1010,
18876,
642,
4190,
12,
24354,
1630,
440,
199,
3,
14442,
1912,
314,
20001,
436,
25531,
22047,
10009,
370,
652,
701,
12043,
310,
402,
2399,
2004,
199,
3,
465,
376,
6551,
71,
27639,
279,
18863,
503,
11482,
6337,
370,
1263,
1335,
17656,
26382,
14,
199,
624,
5433,
3261,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
747,
199,
646,
5377,
199,
504,
747,
14,
515,
492,
2249,
7699,
199,
199,
504,
7209,
492,
1453,
63,
571,
199,
504,
13640,
63,
1725,
63,
3911,
14,
992,
492,
6935,
3353,
12,
6935,
3353,
1931,
199,
504,
13640,
63,
1001,
9482,
492,
1453,
63,
1001,
9482,
199,
504,
13640,
63,
3150,
1617,
14,
992,
492,
3492,
6082,
7544,
199,
504,
13640,
63,
6502,
63,
1725,
14,
1246,
492,
3814,
1692,
12,
16920,
3585,
12,
12651,
199,
504,
13640,
63,
6502,
63,
1725,
14,
1208,
492,
3355,
63,
1725,
63,
504,
63,
4623,
199,
504,
8335,
492,
2562,
199,
199,
504,
1275,
3535,
1192,
492,
25305,
63,
26983,
199,
504,
1275,
827,
878,
492,
4775,
344,
63,
827,
351,
421,
199,
318,
5461,
63,
785,
8,
1113,
304,
272,
408,
11772,
282,
909,
1041,
272,
3762,
275,
1559,
14,
362,
63,
2969,
342,
272,
327,
3814,
2556,
272,
1564,
63,
466,
275,
2249,
7699,
8,
1113,
14,
498,
2788,
17,
1527,
17,
11455,
2325,
342,
272,
1067,
63,
466,
275,
3762,
14,
1935,
360,
1100,
63,
466,
297,
4074,
272,
5898,
63,
466,
275,
3762,
14,
1935,
360,
4603,
63,
466,
297,
4074,
272,
372,
469,
267,
283,
498,
356,
1559,
14,
498,
12,
267,
283,
4623,
63,
344,
356,
620,
8,
1113,
14,
4623,
63,
344,
395,
267,
283,
1023,
63,
344,
356,
620,
8,
1113,
14,
1023,
63,
344,
395,
267,
283,
8928,
356,
1559,
14,
493,
14,
8928,
340,
1559,
14,
493,
587,
3260,
267,
283,
890,
356,
1559,
14,
493,
14,
890,
340,
1559,
14,
493,
587,
378,
12,
267,
283,
493,
63,
344,
356,
620,
8,
1113,
14,
493,
63,
344,
395,
267,
283,
12634,
356,
1559,
14,
493,
365,
440,
488,
12,
267,
283,
1317,
63,
466,
356,
1564,
63,
466,
12,
267,
283,
1100,
63,
466,
356,
1067,
63,
466,
12,
267,
283,
4603,
63,
466,
356,
5898,
63,
466,
12,
267,
283,
2969,
356,
3762,
12,
267,
283,
4614,
356,
485,
1506,
63,
493,
63,
4614,
8,
1113,
9,
272,
789,
421,
199,
318,
485,
1506,
63,
493,
63,
4614,
8,
1113,
304,
272,
408,
1767,
282,
1211,
543,
570,
6220,
1041,
272,
372,
1211,
8,
267,
291,
2687,
288,
399,
16019,
5512,
93,
20193,
1102,
16152,
1246,
16152,
4623,
16152,
498,
93,
31,
1023,
1304,
3126,
1023,
63,
344,
6834,
288,
1275,
908,
8,
355,
327,
3254,
26,
4840,
6700,
1591,
365,
440,
314,
5526,
8744,
2348,
14,
355,
5687,
29,
1818,
63,
571,
14,
888,
459,
6243,
17859,
1179,
63,
2632,
63,
30430,
995,
355,
1591,
29,
1818,
63,
571,
14,
888,
459,
6243,
17859,
1179,
63,
5449,
995,
355,
2986,
29,
1818,
63,
571,
14,
888,
459,
1093,
27998,
63,
9472,
63,
3735,
2278,
1913,
2336,
659,
355,
5315,
29,
1113,
14,
4623,
63,
344,
12,
355,
790,
29,
1113,
14,
498,
12,
355,
1015,
63,
344,
29,
1113,
14,
1023,
63,
344,
12,
288,
23183,
421,
199,
318,
5461,
63,
6767,
63,
785,
8,
1113,
12,
666,
304,
272,
408,
11772,
282,
7809,
909,
334,
4133,
12,
19297,
12,
2508,
9,
5126,
10298,
13474,
1041,
272,
1559,
63,
2724,
275,
5461,
63,
785,
8,
1113,
9,
272,
327,
340,
652,
1159,
282,
5288,
12,
664,
1006,
314,
10298,
909,
436,
1050,
3062,
6272,
272,
327,
665,
1100,
63,
466,
30,
465,
282,
769,
1865,
701,
790,
14,
272,
367,
15494,
315,
6935,
3353,
14,
1131,
63,
17033,
63,
991,
63,
4623,
8,
4623,
29,
1113,
14,
4623,
680,
904,
8,
288,
6935,
3353,
14,
2969,
680,
1541,
8,
355,
6935,
3353,
14,
493,
63,
344,
14,
374,
1397,
8,
403,
395,
355,
6935,
3353,
1931,
14,
498,
508,
283,
4133,
297,
355,
6935,
3353,
1931,
14,
585,
508,
620,
8,
1113,
14,
1023,
63,
344,
4992,
1648,
63,
991,
8,
490,
2562,
14,
1267,
8,
1692,
3353,
14,
498,
395,
6935,
3353,
14,
498,
304,
267,
1559,
63,
2724,
14,
5486,
8,
12384,
14,
362,
63,
2969,
12047,
1100,
63,
466,
995,
15364,
740,
8,
288,
5461,
63,
785,
8,
12384,
430,
272,
327,
16722,
308,
21868,
701,
790,
4453,
3932,
5548,
272,
666,
14,
873,
8,
1113,
63,
2724,
9,
421,
199,
533,
445,
3177,
1173,
1692,
8,
1173,
1692,
304,
272,
408,
4590,
367,
1584,
1041,
339,
768,
3744,
272,
347,
485,
1073,
8,
1886,
12,
5315,
63,
344,
12,
790,
12,
485,
5159,
29,
549,
304,
267,
372,
399,
16019,
5512,
93,
20193,
1102,
16152,
1246,
16152,
4623,
63,
344,
16152,
498,
5285,
908,
8,
288,
5687,
29,
1818,
63,
571,
14,
888,
459,
6243,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Contact: Kyle Lahnakoski (kyle@lahnakoski.com)
#
from __future__ import unicode_literals
import datetime
import types
import unittest
from mo_collections.unique_index import UniqueIndex
import mo_dots
from mo_dots import coalesce, is_container, is_list, literal_field, unwrap, to_data, is_data, is_many
from mo_future import is_text, zip_longest, first
from mo_logs import Except, Log, suppress_exception
from mo_logs.strings import expand_template, quote
import mo_math
from mo_math import is_number, log10
from mo_times import dates
class FuzzyTestCase(unittest.TestCase):
"""
COMPARE STRUCTURE AND NUMBERS!
ONLY THE ATTRIBUTES IN THE expected STRUCTURE ARE TESTED TO EXIST
EXTRA ATTRIBUTES ARE IGNORED.
NUMBERS ARE MATCHED BY ...
* places (UP TO GIVEN SIGNIFICANT DIGITS)
* digits (UP TO GIVEN DECIMAL PLACES, WITH NEGATIVE MEANING LEFT-OF-UNITS)
* delta (MAXIMUM ABSOLUTE DIFFERENCE FROM expected)
"""
def __init__(self, *args, **kwargs):
unittest.TestCase.__init__(self, *args, **kwargs)
self.default_places=15
def set_default_places(self, places):
"""
WHEN COMPARING float, HOW MANY DIGITS ARE SIGNIFICANT BY DEFAULT
"""
self.default_places=places
def assertAlmostEqual(self, test_value, expected, msg=None, digits=None, places=None, delta=None):
if delta or digits:
assertAlmostEqual(test_value, expected, msg=msg, digits=digits, places=places, delta=delta)
else:
assertAlmostEqual(test_value, expected, msg=msg, digits=digits, places=coalesce(places, self.default_places), delta=delta)
def assertEqual(self, test_value, expected, msg=None, digits=None, places=None, delta=None):
self.assertAlmostEqual(test_value, expected, msg=msg, digits=digits, places=places, delta=delta)
def assertRaises(self, problem=None, function=None, *args, **kwargs):
if function is None:
return RaiseContext(self, problem=problem or Exception)
with RaiseContext(self, problem=problem):
function(*args, **kwargs)
class RaiseContext(object):
def __init__(self, this, problem=Exception):
self.this = this
self.problem = problem
def __enter__(self):
pass
def __exit__(self, exc_type, exc_val, exc_tb):
if not exc_val:
Log.error("Expecting an error")
f = Except.wrap(exc_val)
if isinstance(self.problem, (list, tuple)):
problems = self.problem
else:
problems = [self.problem]
causes = []
for problem in problems:
if isinstance(problem, object.__class__) and issubclass(problem, BaseException) and isinstance(exc_val, problem):
return True
try:
self.this.assertIn(problem, f)
return True
except Exception as cause:
causes.append(cause)
Log.error("problem is not raised", cause=first(causes))
def assertAlmostEqual(test, expected, digits=None, places=None, msg=None, delta=None):
show_detail = True
test = unwrap(test)
expected = unwrap(expected)
try:
if test is None and (is_null_op(expected) or expected is None):
return
elif test is expected:
return
elif is_text(expected):
assertAlmostEqualValue(test, expected, msg=msg, digits=digits, places=places, delta=delta)
elif isinstance(test, UniqueIndex):
if test ^ expected:
Log.error("Sets do not match")
elif is_data(expected) and is_data(test):
for k, e in unwrap(expected).items():
t = test.get(k)
assertAlmostEqual(t, e, msg=coalesce(msg, "")+"key "+quote(k)+": ", digits=digits, places=places, delta=delta)
elif is_data(expected):
if is_many(test):
test = list(test)
if len(test) != 1:
Log.error("Expecting data, not a list")
test = test[0]
for k, e in expected.items():
try:
t = test[k]
assertAlmostEqual(t, e, msg=msg, digits=digits, places=places, delta=delta)
continue
except:
pass
t = mo_dots.get_attr(test, literal_field(k))
assertAlmostEqual(t, e, msg=msg, digits=digits, places=places, delta=delta)
elif is_container(test) and isinstance(expected, set):
test = set(to_data(t) for t in test)
if len(test) != len(expected):
Log.error(
"Sets do not match, element count different:\n{{test|json|indent}}\nexpecting{{expectedtest|json|indent}}",
test=test,
expected=expected
)
try:
return len(set(test)|expected) == len(expected)
except:
for e in expected:
for t in test:
try:
assertAlmostEqual(t, e, msg=msg, digits=digits, places=places, delta=delta)
break
except Exception as _:
pass
else:
Log.error("Sets do not match. {{value|json}} not found in {{test|json}}", value=e, test=test)
elif isinstance(expected, types.FunctionType):
return expected(test)
elif hasattr(test, "__iter__") and hasattr(expected, "__iter__"):
if test.__class__.__name__ == "ndarray": # numpy
test = test.tolist()
elif test.__class__.__name__ == "DataFrame": # pandas
test = test[test.columns[0]].values.tolist()
elif test.__class__.__name__ == "Series": # pandas
test = test.values.tolist()
if not expected and test == None:
return
if expected == None:
expected = [] # REPRESENT NOTHING
for t, e in zip_longest(test, expected):
assertAlmostEqual(t, e, msg=msg, digits=digits, places=places, delta=delta)
else:
assertAlmostEqualValue(test, expected, msg=msg, digits=digits, places=places, delta=delta)
except Exception as cause:
Log.error(
"{{test|json|limit(10000)}} does not match expected {{expected|json|limit(10000)}}",
test=test if show_detail else "[can not show]",
expected=expected if show_detail else "[can not show]",
cause=cause
)
def assertAlmostEqualValue(test, expected, digits=None, places=None, msg=None, delta=None):
"""
Snagged from unittest/case.py, then modified (Aug2014)
"""
if is_null_op(expected):
if test == None: # pandas dataframes reject any comparision with an exception!
return
else:
raise AssertionError(expand_template("{{test|json}} != NULL", locals()))
if expected == None: # None has no expectations
return
if test == expected:
# shortcut
return
if isinstance(expected, (dates.Date, datetime.datetime, datetime.date)):
return assertAlmostEqualValue(
dates.Date(test).unix,
dates.Date(expected).unix,
msg=msg,
digits=digits,
places=places,
delta=delta
)
if not is_number(expected):
# SOME SPECIAL CASES, EXPECTING EMPTY CONTAINERS IS THE SAME AS EXPECTING NULL
if is_list(expected) and len(expected) == 0 and test == None:
return
if is_data(expected) and not expected.keys() and test == None:
return
if test != expected:
raise AssertionError(expand_template("{{test|json}} != {{expected|json}}", locals()))
return
elif not is_number(test):
try:
# ASSUME IT IS A UTC DATE
test = dates.parse(test).unix
except Exception as e:
raise AssertionError(expand_template("{{test|json}} != {{expected}}", locals()))
num_param = 0
if digits != None:
num_param += 1
if places != None:
num_param += 1
if delta != None:
num_param += 1
if num_param > 1:
raise TypeError("specify only one of digits, places or delta")
if digits is not None:
with suppress_exception:
diff = log10(abs(test-expected))
if diff < digits:
return
standardMsg = expand_template("{{test|json}} != {{expected|json}} within {{digits}} decimal places", locals())
elif delta is not None:
if abs(test - expected) <= delta:
return
standardMsg = expand_template("{{test|json}} != {{expected|json}} within {{delta}} delta", locals())
else:
if places is None:
places = 15
with suppress_exception:
diff = mo_math.log10(abs(test-expected))
if diff == None:
return # Exactly the same
if diff < mo_math.ceiling(mo_math.log10(abs(test)))-places:
return
standardMsg = expand_template("{{test|json}} != {{expected|json}} within {{places}} places", locals())
raise AssertionError(coalesce(msg, "") + ": (" + standardMsg + ")")
def is_null_op(v):
return v.__class__.__name__ == "NullOp"
|
mpl-2.0
|
[
3,
2644,
26,
2774,
13,
24,
199,
3,
199,
3,
199,
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
199,
3,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
3,
199,
3,
18684,
26,
1804,
1775,
7964,
6164,
1151,
736,
8810,
334,
75,
1775,
32,
416,
6164,
1151,
736,
8810,
14,
957,
9,
199,
3,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
646,
2943,
199,
646,
2882,
199,
199,
504,
1303,
63,
7882,
14,
3235,
63,
1080,
492,
18276,
2681,
199,
646,
1303,
63,
25310,
199,
504,
1303,
63,
25310,
492,
512,
29944,
12,
365,
63,
3600,
12,
365,
63,
513,
12,
8785,
63,
698,
12,
625,
3823,
12,
370,
63,
576,
12,
365,
63,
576,
12,
365,
63,
3479,
199,
504,
1303,
63,
2443,
492,
365,
63,
505,
12,
3482,
63,
20820,
12,
1642,
199,
504,
1303,
63,
7270,
492,
1316,
716,
12,
5297,
12,
15678,
63,
1971,
199,
504,
1303,
63,
7270,
14,
5465,
492,
6544,
63,
1160,
12,
6313,
199,
646,
1303,
63,
3442,
199,
504,
1303,
63,
3442,
492,
365,
63,
1955,
12,
943,
709,
199,
504,
1303,
63,
4508,
492,
10831,
421,
199,
533,
481,
14697,
1746,
8,
2796,
14,
1746,
304,
272,
408,
272,
16503,
8693,
7553,
7996,
3942,
2401,
11576,
34,
3960,
1,
339,
5258,
6084,
2334,
10762,
16883,
1621,
2334,
1420,
7553,
7996,
3942,
9315,
7393,
1149,
2296,
22968,
272,
3651,
13954,
10762,
16883,
9315,
27499,
25517,
14,
339,
11576,
34,
3960,
9315,
603,
8078,
1149,
6515,
2263,
272,
627,
9825,
334,
2160,
2296,
598,
6882,
742,
5056,
14456,
1441,
577,
1277,
5930,
9,
272,
627,
7576,
334,
2160,
2296,
598,
6882,
742,
31371,
16980,
10092,
21287,
12,
1663,
29837,
603,
37,
879,
1206,
6578,
13,
3359,
13,
27522,
9,
272,
627,
5762,
334,
4283,
27078,
437,
11087,
2228,
4586,
5266,
1665,
540,
6013,
4442,
1420,
9,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
2882,
14,
1746,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
267,
291,
14,
885,
63,
10696,
29,
1046,
2378,
347,
663,
63,
885,
63,
10696,
8,
277,
12,
9825,
304,
267,
408,
267,
27802,
16503,
689,
1206,
2069,
12,
7781,
55,
603,
8974,
577,
1277,
5930,
9315,
5056,
14456,
1441,
6515,
6186,
267,
408,
267,
291,
14,
885,
63,
10696,
29,
10696,
339,
347,
702,
7331,
8,
277,
12,
511,
63,
585,
12,
1420,
12,
1499,
29,
403,
12,
7576,
29,
403,
12,
9825,
29,
403,
12,
5762,
29,
403,
304,
267,
340,
5762,
503,
7576,
26,
288,
702,
7331,
8,
396,
63,
585,
12,
1420,
12,
1499,
29,
1328,
12,
7576,
29,
7022,
12,
9825,
29,
10696,
12,
5762,
29,
3136,
9,
267,
587,
26,
288,
702,
7331,
8,
396,
63,
585,
12,
1420,
12,
1499,
29,
1328,
12,
7576,
29,
7022,
12,
9825,
29,
331,
29944,
8,
10696,
12,
291,
14,
885,
63,
10696,
395,
5762,
29,
3136,
9,
339,
347,
26400,
8,
277,
12,
511,
63,
585,
12,
1420,
12,
1499,
29,
403,
12,
7576,
29,
403,
12,
9825,
29,
403,
12,
5762,
29,
403,
304,
267,
291,
14,
7904,
8,
396,
63,
585,
12,
1420,
12,
1499,
29,
1328,
12,
7576,
29,
7022,
12,
9825,
29,
10696,
12,
5762,
29,
3136,
9,
339,
347,
702,
1811,
8,
277,
12,
5160,
29,
403,
12,
805,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
805,
365,
488,
26,
288,
372,
14771,
2998,
8,
277,
12,
5160,
29,
6462,
503,
2186,
9,
398,
543,
14771,
2998,
8,
277,
12,
5160,
29,
6462,
304,
288,
805,
2031,
589,
12,
1011,
958,
9,
421,
199,
533,
14771,
2998,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
642,
12,
5160,
29,
1726,
304,
267,
291,
14,
3749,
275,
642,
267,
291,
14,
6462,
275,
5160,
339,
347,
636,
4200,
721,
277,
304,
267,
986,
339,
347,
636,
2224,
721,
277,
12,
3178,
63,
466,
12,
3178,
63,
637,
12,
3178,
63,
5842,
304,
267,
340,
440,
3178,
63,
637,
26,
288,
5297,
14,
705,
480,
28864,
376,
1125,
531,
267,
289,
275,
1316,
716,
14,
3823,
8,
2804,
63,
637,
9,
398,
340,
1228,
8,
277,
14,
6462,
12,
334,
513,
12,
2008,
2298,
288,
8826,
275,
291,
14,
6462,
267,
587,
26,
288,
8826,
275,
359,
277,
14,
6462,
61,
398,
14486,
275,
942,
267,
367,
5160,
315,
8826,
26,
288,
340,
1228,
8,
6462,
12,
909,
855,
533,
3368,
436,
11602,
8,
6462,
12,
25416,
9,
436,
1228,
8,
2804,
63,
637,
12,
5160,
304,
355,
372,
715,
288,
862,
26,
355,
291,
14,
3749,
14,
4080,
8,
6462,
12,
289,
9,
355,
372,
715,
288,
871,
2186,
465,
7675,
26,
355,
14486,
14,
740,
8,
2651,
9,
267,
5297,
14,
705,
480,
6462,
365,
440,
4915,
401,
7675,
29,
2246,
8,
696,
5589,
430,
421,
199,
318,
702,
7331,
8,
396,
12,
1420,
12,
7576,
29,
403,
12,
9825,
29,
403,
12,
1499,
29,
403,
12,
5762,
29,
403,
304,
272,
2498,
63,
5506,
275,
715,
272,
511,
275,
625,
3823,
8,
396,
9,
272,
1420,
275,
625,
3823,
8,
2062,
9,
272,
862,
26,
267,
340,
511,
365,
488,
436,
334,
374,
63,
2307,
63,
411,
8,
2062,
9,
503,
1420,
365,
488,
304,
288,
372,
267,
916,
511,
365,
1420,
26,
288,
372,
267,
916,
365,
63,
505,
8,
2062,
304,
288,
702,
7331,
1110,
8,
396,
12,
1420,
12,
1499,
29,
1328,
12,
7576,
29,
7022,
12,
9825,
29,
10696,
12,
5762,
29,
3136,
9,
267,
916,
1228,
8,
396,
12,
18276,
2681,
304,
288,
340,
511,
7167,
1420,
26,
355,
5297,
14,
705,
480,
9899,
886,
440,
1336,
531,
267,
916,
365,
63,
576,
8,
2062,
9,
436,
365,
63,
576,
8,
396,
304,
288,
367,
1022,
12,
325,
315,
625,
3823,
8,
2062,
680,
1744,
837,
355,
307,
275,
511,
14,
362
] |
[
2644,
26,
2774,
13,
24,
199,
3,
199,
3,
199,
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
199,
3,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
3,
199,
3,
18684,
26,
1804,
1775,
7964,
6164,
1151,
736,
8810,
334,
75,
1775,
32,
416,
6164,
1151,
736,
8810,
14,
957,
9,
199,
3,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
646,
2943,
199,
646,
2882,
199,
199,
504,
1303,
63,
7882,
14,
3235,
63,
1080,
492,
18276,
2681,
199,
646,
1303,
63,
25310,
199,
504,
1303,
63,
25310,
492,
512,
29944,
12,
365,
63,
3600,
12,
365,
63,
513,
12,
8785,
63,
698,
12,
625,
3823,
12,
370,
63,
576,
12,
365,
63,
576,
12,
365,
63,
3479,
199,
504,
1303,
63,
2443,
492,
365,
63,
505,
12,
3482,
63,
20820,
12,
1642,
199,
504,
1303,
63,
7270,
492,
1316,
716,
12,
5297,
12,
15678,
63,
1971,
199,
504,
1303,
63,
7270,
14,
5465,
492,
6544,
63,
1160,
12,
6313,
199,
646,
1303,
63,
3442,
199,
504,
1303,
63,
3442,
492,
365,
63,
1955,
12,
943,
709,
199,
504,
1303,
63,
4508,
492,
10831,
421,
199,
533,
481,
14697,
1746,
8,
2796,
14,
1746,
304,
272,
408,
272,
16503,
8693,
7553,
7996,
3942,
2401,
11576,
34,
3960,
1,
339,
5258,
6084,
2334,
10762,
16883,
1621,
2334,
1420,
7553,
7996,
3942,
9315,
7393,
1149,
2296,
22968,
272,
3651,
13954,
10762,
16883,
9315,
27499,
25517,
14,
339,
11576,
34,
3960,
9315,
603,
8078,
1149,
6515,
2263,
272,
627,
9825,
334,
2160,
2296,
598,
6882,
742,
5056,
14456,
1441,
577,
1277,
5930,
9,
272,
627,
7576,
334,
2160,
2296,
598,
6882,
742,
31371,
16980,
10092,
21287,
12,
1663,
29837,
603,
37,
879,
1206,
6578,
13,
3359,
13,
27522,
9,
272,
627,
5762,
334,
4283,
27078,
437,
11087,
2228,
4586,
5266,
1665,
540,
6013,
4442,
1420,
9,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
2882,
14,
1746,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
267,
291,
14,
885,
63,
10696,
29,
1046,
2378,
347,
663,
63,
885,
63,
10696,
8,
277,
12,
9825,
304,
267,
408,
267,
27802,
16503,
689,
1206,
2069,
12,
7781,
55,
603,
8974,
577,
1277,
5930,
9315,
5056,
14456,
1441,
6515,
6186,
267,
408,
267,
291,
14,
885,
63,
10696,
29,
10696,
339,
347,
702,
7331,
8,
277,
12,
511,
63,
585,
12,
1420,
12,
1499,
29,
403,
12,
7576,
29,
403,
12,
9825,
29,
403,
12,
5762,
29,
403,
304,
267,
340,
5762,
503,
7576,
26,
288,
702,
7331,
8,
396,
63,
585,
12,
1420,
12,
1499,
29,
1328,
12,
7576,
29,
7022,
12,
9825,
29,
10696,
12,
5762,
29,
3136,
9,
267,
587,
26,
288,
702,
7331,
8,
396,
63,
585,
12,
1420,
12,
1499,
29,
1328,
12,
7576,
29,
7022,
12,
9825,
29,
331,
29944,
8,
10696,
12,
291,
14,
885,
63,
10696,
395,
5762,
29,
3136,
9,
339,
347,
26400,
8,
277,
12,
511,
63,
585,
12,
1420,
12,
1499,
29,
403,
12,
7576,
29,
403,
12,
9825,
29,
403,
12,
5762,
29,
403,
304,
267,
291,
14,
7904,
8,
396,
63,
585,
12,
1420,
12,
1499,
29,
1328,
12,
7576,
29,
7022,
12,
9825,
29,
10696,
12,
5762,
29,
3136,
9,
339,
347,
702,
1811,
8,
277,
12,
5160,
29,
403,
12,
805,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
805,
365,
488,
26,
288,
372,
14771,
2998,
8,
277,
12,
5160,
29,
6462,
503,
2186,
9,
398,
543,
14771,
2998,
8,
277,
12,
5160,
29,
6462,
304,
288,
805,
2031,
589,
12,
1011,
958,
9,
421,
199,
533,
14771,
2998,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
642,
12,
5160,
29,
1726,
304,
267,
291,
14,
3749,
275,
642,
267,
291,
14,
6462,
275,
5160,
339,
347,
636,
4200,
721,
277,
304,
267,
986,
339,
347,
636,
2224,
721,
277,
12,
3178,
63,
466,
12,
3178,
63,
637,
12,
3178,
63,
5842,
304,
267,
340,
440,
3178,
63,
637,
26,
288,
5297,
14,
705,
480,
28864,
376,
1125,
531,
267,
289,
275,
1316,
716,
14,
3823,
8,
2804,
63,
637,
9,
398,
340,
1228,
8,
277,
14,
6462,
12,
334,
513,
12,
2008,
2298,
288,
8826,
275,
291,
14,
6462,
267,
587,
26,
288,
8826,
275,
359,
277,
14,
6462,
61,
398,
14486,
275,
942,
267,
367,
5160,
315,
8826,
26,
288,
340,
1228,
8,
6462,
12,
909,
855,
533,
3368,
436,
11602,
8,
6462,
12,
25416,
9,
436,
1228,
8,
2804,
63,
637,
12,
5160,
304,
355,
372,
715,
288,
862,
26,
355,
291,
14,
3749,
14,
4080,
8,
6462,
12,
289,
9,
355,
372,
715,
288,
871,
2186,
465,
7675,
26,
355,
14486,
14,
740,
8,
2651,
9,
267,
5297,
14,
705,
480,
6462,
365,
440,
4915,
401,
7675,
29,
2246,
8,
696,
5589,
430,
421,
199,
318,
702,
7331,
8,
396,
12,
1420,
12,
7576,
29,
403,
12,
9825,
29,
403,
12,
1499,
29,
403,
12,
5762,
29,
403,
304,
272,
2498,
63,
5506,
275,
715,
272,
511,
275,
625,
3823,
8,
396,
9,
272,
1420,
275,
625,
3823,
8,
2062,
9,
272,
862,
26,
267,
340,
511,
365,
488,
436,
334,
374,
63,
2307,
63,
411,
8,
2062,
9,
503,
1420,
365,
488,
304,
288,
372,
267,
916,
511,
365,
1420,
26,
288,
372,
267,
916,
365,
63,
505,
8,
2062,
304,
288,
702,
7331,
1110,
8,
396,
12,
1420,
12,
1499,
29,
1328,
12,
7576,
29,
7022,
12,
9825,
29,
10696,
12,
5762,
29,
3136,
9,
267,
916,
1228,
8,
396,
12,
18276,
2681,
304,
288,
340,
511,
7167,
1420,
26,
355,
5297,
14,
705,
480,
9899,
886,
440,
1336,
531,
267,
916,
365,
63,
576,
8,
2062,
9,
436,
365,
63,
576,
8,
396,
304,
288,
367,
1022,
12,
325,
315,
625,
3823,
8,
2062,
680,
1744,
837,
355,
307,
275,
511,
14,
362,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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ensors, as applicable
#
# 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.
"""
===================
Main setup runner
===================
This module provides a wrapper around the distutils core setup.
"""
__author__ = u"Andr\xe9 Malo"
__docformat__ = "restructuredtext en"
import ConfigParser as _config_parser
from distutils import core as _core
import os as _os
import posixpath as _posixpath
import sys as _sys
from _setup import commands as _commands
from _setup import data as _data
from _setup import ext as _ext
from _setup import util as _util
from _setup import shell as _shell
def check_python_version(impl, version_min, version_max):
""" Check python version """
if impl == 'python':
version_info = _sys.version_info
elif impl == 'pypy':
version_info = getattr(_sys, 'pypy_version_info', None)
if not version_info:
return
elif impl == 'jython':
if not 'java' in _sys.platform.lower():
return
version_info = _sys.version_info
else:
raise AssertionError("impl not in ('python', 'pypy', 'jython')")
pyversion = map(int, version_info[:3])
if version_min:
min_required = \
map(int, '.'.join((version_min, '0.0.0')).split('.')[:3])
if pyversion < min_required:
raise EnvironmentError("Need at least %s %s (vs. %s)" % (
impl, version_min, '.'.join(map(str, pyversion))
))
if version_max:
max_required = map(int, version_max.split('.'))
max_required[-1] += 1
if pyversion >= max_required:
raise EnvironmentError("Need at max %s %s (vs. %s)" % (
impl,
version_max,
'.'.join(map(str, pyversion))
))
def find_description(docs):
"""
Determine the package description from DESCRIPTION
:Parameters:
`docs` : ``dict``
Docs config section
:Return: Tuple of summary, description and license
(``('summary', 'description', 'license')``)
(all may be ``None``)
:Rtype: ``tuple``
"""
summary = None
filename = docs.get('meta.summary', 'SUMMARY').strip()
if filename and _os.path.isfile(filename):
fp = open(filename)
try:
try:
summary = fp.read().strip().splitlines()[0].rstrip()
except IndexError:
summary = ''
finally:
fp.close()
description = None
filename = docs.get('meta.description', 'DESCRIPTION').strip()
if filename and _os.path.isfile(filename):
fp = open(filename)
try:
description = fp.read().rstrip()
finally:
fp.close()
if summary is None and description:
from docutils import core
summary = core.publish_parts(
source=description,
source_path=filename,
writer_name='html',
)['title'].encode('utf-8')
return summary, description
def find_classifiers(docs):
"""
Determine classifiers from CLASSIFIERS
:return: List of classifiers (``['classifier', ...]``)
:rtype: ``list``
"""
filename = docs.get('meta.classifiers', 'CLASSIFIERS').strip()
if filename and _os.path.isfile(filename):
fp = open(filename)
try:
content = fp.read()
finally:
fp.close()
content = [item.strip() for item in content.splitlines()]
return [item for item in content if item and not item.startswith('#')]
return []
def find_provides(docs):
"""
Determine provides from PROVIDES
:return: List of provides (``['provides', ...]``)
:rtype: ``list``
"""
filename = docs.get('meta.provides', 'PROVIDES').strip()
if filename and _os.path.isfile(filename):
fp = open(filename)
try:
content = fp.read()
finally:
fp.close()
content = [item.strip() for item in content.splitlines()]
return [item for item in content if item and not item.startswith('#')]
return []
def find_license(docs):
"""
Determine license from LICENSE
:return: License text
:rtype: ``str``
"""
filename = docs.get('meta.license', 'LICENSE').strip()
if filename and _os.path.isfile(filename):
fp = open(filename)
try:
return fp.read().rstrip()
finally:
fp.close()
return None
def find_packages(manifest):
""" Determine packages and subpackages """
packages = {}
collect = manifest.get('packages.collect', '').split()
lib = manifest.get('packages.lib', '.')
try:
sep = _os.path.sep
except AttributeError:
sep = _os.path.join('1', '2')[1:-1]
for root in collect:
for dirpath, _, filenames in _shell.walk(_os.path.join(lib, root)):
if dirpath.find('.svn') >= 0 or dirpath.find('.git') >= 0:
continue
if '__init__.py' in filenames:
packages[
_os.path.normpath(dirpath).replace(sep, '.')
] = None
packages = packages.keys()
packages.sort()
return packages
def find_data(name, docs):
""" Determine data files """
result = []
if docs.get('extra', '').strip():
result.append(_data.Documentation(docs['extra'].split(),
prefix='share/doc/%s' % name,
))
if docs.get('examples.dir', '').strip():
tpl = ['recursive-include %s *' % docs['examples.dir']]
if docs.get('examples.ignore', '').strip():
tpl.extend(["global-exclude %s" % item
for item in docs['examples.ignore'].split()
])
strip = int(docs.get('examples.strip', '') or 0)
result.append(_data.Documentation.from_templates(*tpl, **{
'strip': strip,
'prefix': 'share/doc/%s' % name,
'preserve': 1,
}))
if docs.get('userdoc.dir', '').strip():
tpl = ['recursive-include %s *' % docs['userdoc.dir']]
if docs.get('userdoc.ignore', '').strip():
tpl.extend(["global-exclude %s" % item
for item in docs['userdoc.ignore'].split()
])
strip = int(docs.get('userdoc.strip', '') or 0)
result.append(_data.Documentation.from_templates(*tpl, **{
'strip': strip,
'prefix': 'share/doc/%s' % name,
'preserve': 1,
}))
if docs.get('apidoc.dir', '').strip():
tpl = ['recursive-include %s *' % docs['apidoc.dir']]
if docs.get('apidoc.ignore', '').strip():
tpl.extend(["global-exclude %s" % item
for item in docs['apidoc.ignore'].split()
])
strip = int(docs.get('apidoc.strip', '') or 0)
result.append(_data.Documentation.from_templates(*tpl, **{
'strip': strip,
'prefix': 'share/doc/%s' % name,
'preserve': 1,
}))
if docs.get('man', '').strip():
result.extend(_data.Manpages.dispatch(docs['man'].split()))
return result
def make_manifest(manifest, config, docs, kwargs):
""" Create file list to pack up """
# pylint: disable = R0912
kwargs = kwargs.copy()
kwargs['script_args'] = ['install']
kwargs['packages'] = list(kwargs.get('packages') or ()) + [
'_setup', '_setup.py2', '_setup.py3',
] + list(manifest.get('packages.extra', '').split() or ())
_core._setup_stop_after = "commandline"
try:
dist = _core.setup(**kwargs)
finally:
_core._setup_stop_after = None
result = ['MANIFEST', 'PKG-INFO', 'setup.py'] + list(config)
# TODO: work with default values:
for key in ('classifiers', 'description', 'summary', 'provides',
'license'):
filename = docs.get('meta.' + key, '').strip()
if filename and _os.path.isfile(filename):
result.append(filename)
cmd = dist.get_command_obj("build_py")
cmd.ensure_finalized()
#from pprint import pprint; pprint(("build_py", cmd.get_source_files()))
for item in cmd.get_source_files():
result.append(_posixpath.sep.join(
_os.path.normpath(item).split(_os.path.sep)
))
cmd = dist.get_command_obj("build_ext")
cmd.ensure_finalized()
#from pprint import pprint; pprint(("build_ext", cmd.get_source_files()))
for item in cmd.get_source_files():
result.append(_posixpath.sep.join(
_os.path.normpath(item).split(_os.path.sep)
))
for ext in cmd.extensions:
if ext.depends:
result.extend([_posixpath.sep.join(
_os.path.normpath(item).split(_os.path.sep)
) for item in ext.depends])
cmd = dist.get_command_obj("build_clib")
cmd.ensure_finalized()
if cmd.libraries:
#import pprint; pprint.pprint(("build_clib", cmd.get_source_files()))
for item in cmd.get_source_files():
result.append(_posixpath.sep.join(
_os.path.normpath(item).split(_os.path.sep)
))
for lib in cmd.libraries:
if lib[1].get('depends'):
result.extend([_posixpath.sep.join(
_os.path.normpath(item).split(_os.path.sep)
) for item in lib[1]['depends']])
cmd = dist.get_command_obj("build_scripts")
cmd.ensure_finalized()
#import pprint; pprint.pprint(("build_scripts", cmd.get_source_files()))
if cmd.get_source_files():
for item in cmd.get_source_files():
result.append(_posixpath.sep.join(
_os.path.normpath(item).split(_os.path.sep)
))
cmd = dist.get_command_obj("install_data")
cmd.ensure_finalized()
#from pprint import pprint; pprint(("install_data", cmd.get_inputs()))
try:
strings = basestring
except NameError:
strings = (str, unicode)
for item in cmd.get_inputs():
if isinstance(item, strings):
result.append(item)
else:
result.extend(item[1])
for item in manifest.get('dist', '').split():
result.append(item)
if _os.path.isdir(item):
for filename in _shell.files(item):
result.append(filename)
result = dict([(item, None) for item in result]).keys()
result.sort()
return result
def run(config=('package.cfg',), ext=None, script_args=None, manifest_only=0):
""" Main runner """
if ext is None:
ext = []
cfg = _util.SafeConfigParser()
cfg.read(config)
pkg = dict(cfg.items('package'))
python_min = pkg.get('python.min') or None
python_max = pkg.get('python.max') or None
check_python_version('python', python_min, python_max)
pypy_min = pkg.get('pypy.min') or None
pypy_max = pkg.get('pypy.max') or None
check_python_version('pypy', pypy_min, pypy_max)
jython_min = pkg.get('jython.min') or None
jython_max = pkg.get('jython.max') or None
check_python_version('jython', jython_min, jython_max)
manifest = dict(cfg.items('manifest'))
try:
docs = dict(cfg.items('docs'))
except _config_parser.NoSectionError:
docs = {}
summary, description = find_description(docs)
scripts = manifest.get('scripts', '').strip() or None
if scripts:
scripts = scripts.split()
modules = manifest.get('modules', '').strip() or None
if modules:
modules = modules.split()
keywords = docs.get('meta.keywords', '').strip() or None
if keywords:
keywords = keywords.split()
revision = pkg.get('version.revision', '').strip()
if revision:
revision = "-r%s" % (revision,)
kwargs = {
'name': pkg['name'],
'version': "%s%s" % (
pkg['version.number'],
["", "-dev%s" % (revision,)][_util.humanbool(
'version.dev', pkg.get('version.dev', 'false')
)],
),
'provides': find_provides(docs),
'description': summary,
'long_description': description,
'classifiers': find_classifiers(docs),
'keywords': keywords,
'author': pkg['author.name'],
'author_email': pkg['author.email'],
'maintainer': pkg.get('maintainer.name'),
'maintainer_email': pkg.get('maintainer.email'),
'url': pkg.get('url.homepage'),
'download_url': pkg.get('url.download'),
'license': find_license(docs),
'package_dir': {'': manifest.get('packages.lib', '.')},
'packages': find_packages(manifest),
'py_modules': modules,
'ext_modules': ext,
'scripts': scripts,
'script_args': script_args,
'data_files': find_data(pkg['name'], docs),
'cmdclass': {
'build' : _commands.Build,
'build_ext' : _commands.BuildExt,
'install' : _commands.Install,
'install_data': _commands.InstallData,
'install_lib' : _commands.InstallLib,
}
}
for key in ('provides',):
if key not in _core.setup_keywords:
del kwargs[key]
if manifest_only:
return make_manifest(manifest, config, docs, kwargs)
# monkey-patch crappy manifest writer away.
from distutils.command import sdist
sdist.sdist.get_file_list = sdist.sdist.read_manifest
return _core.setup(**kwargs)
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
13294,
1882,
199,
3,
199,
3,
1898,
10219,
446,
6171,
199,
3,
6061,
82,
60,
1845,
25,
603,
12201,
503,
17049,
23854,
17564,
12,
465,
3964,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
624,
199,
1280,
5918,
199,
11298,
3272,
7876,
199,
1280,
5918,
199,
199,
2765,
859,
6571,
282,
4975,
6818,
314,
7065,
6170,
3272,
14,
199,
624,
199,
363,
2502,
363,
275,
399,
2,
3325,
82,
60,
1845,
25,
603,
12201,
2,
199,
363,
21841,
363,
275,
298,
26854,
655,
2,
199,
199,
646,
14196,
465,
485,
888,
63,
2087,
199,
504,
7065,
492,
6170,
465,
485,
1018,
199,
646,
747,
465,
485,
736,
199,
646,
15454,
465,
485,
23342,
199,
646,
984,
465,
485,
1274,
199,
199,
504,
485,
2758,
492,
3718,
465,
485,
4405,
199,
504,
485,
2758,
492,
666,
465,
485,
576,
199,
504,
485,
2758,
492,
1599,
465,
485,
832,
199,
504,
485,
2758,
492,
4884,
465,
485,
1974,
199,
504,
485,
2758,
492,
5218,
465,
485,
5641,
421,
199,
318,
1104,
63,
1548,
63,
1023,
8,
5472,
12,
1015,
63,
827,
12,
1015,
63,
988,
304,
272,
408,
2670,
2366,
1015,
408,
272,
340,
11512,
508,
283,
1548,
356,
267,
1015,
63,
815,
275,
485,
1274,
14,
1023,
63,
815,
272,
916,
11512,
508,
283,
20233,
356,
267,
1015,
63,
815,
275,
2519,
1547,
1274,
12,
283,
20233,
63,
1023,
63,
815,
297,
488,
9,
267,
340,
440,
1015,
63,
815,
26,
288,
372,
272,
916,
11512,
508,
283,
27179,
356,
267,
340,
440,
283,
6138,
7,
315,
485,
1274,
14,
3246,
14,
2325,
837,
288,
372,
267,
1015,
63,
815,
275,
485,
1274,
14,
1023,
63,
815,
272,
587,
26,
267,
746,
9070,
480,
5472,
440,
315,
661,
1548,
297,
283,
20233,
297,
283,
27179,
26530,
339,
1134,
1023,
275,
2341,
8,
442,
12,
1015,
63,
815,
1491,
19,
566,
272,
340,
1015,
63,
827,
26,
267,
1748,
63,
2427,
275,
971,
288,
2341,
8,
442,
12,
15671,
904,
1332,
1023,
63,
827,
12,
283,
16,
14,
16,
14,
16,
11103,
1294,
7563,
1491,
19,
566,
267,
340,
1134,
1023,
665,
1748,
63,
2427,
26,
288,
746,
25139,
480,
17809,
737,
5210,
450,
83,
450,
83,
334,
3122,
14,
450,
83,
2924,
450,
334,
355,
11512,
12,
1015,
63,
827,
12,
15671,
904,
8,
1130,
8,
495,
12,
1134,
1023,
430,
288,
5082,
272,
340,
1015,
63,
988,
26,
267,
1390,
63,
2427,
275,
2341,
8,
442,
12,
1015,
63,
988,
14,
1294,
24535,
267,
1390,
63,
2427,
1988,
17,
61,
847,
413,
267,
340,
1134,
1023,
2356,
1390,
63,
2427,
26,
288,
746,
25139,
480,
17809,
737,
1390,
450,
83,
450,
83,
334,
3122,
14,
450,
83,
2924,
450,
334,
355,
11512,
12,
355,
1015,
63,
988,
12,
355,
15671,
904,
8,
1130,
8,
495,
12,
1134,
1023,
430,
288,
5082,
421,
199,
318,
2342,
63,
1802,
8,
4757,
304,
272,
408,
272,
14703,
314,
2559,
1369,
687,
17410,
1075,
339,
520,
5976,
26,
489,
658,
4757,
64,
520,
1124,
807,
1040,
267,
5454,
83,
1101,
3420,
339,
520,
1767,
26,
11634,
402,
6212,
12,
1369,
436,
4190,
1467,
15693,
360,
4705,
297,
283,
1802,
297,
283,
1682,
358,
16580,
1467,
334,
452,
1443,
506,
1124,
403,
16580,
272,
520,
50,
466,
26,
1124,
2960,
1040,
272,
408,
272,
6212,
275,
488,
272,
1788,
275,
9149,
14,
362,
360,
2024,
14,
4705,
297,
283,
29508,
1959,
1913,
342,
272,
340,
1788,
436,
485,
736,
14,
515,
14,
6292,
8,
1501,
304,
267,
4090,
275,
1551,
8,
1501,
9,
267,
862,
26,
288,
862,
26,
355,
6212,
275,
4090,
14,
739,
1252,
1913,
1252,
7644,
3430,
16,
1055,
6735,
342,
288,
871,
7888,
26,
355,
6212,
275,
2125,
267,
3753,
26,
288,
4090,
14,
1600,
342,
339,
1369,
275,
488,
272,
1788,
275,
9149,
14,
362,
360,
2024,
14,
1802,
297,
283,
17705,
1959,
1913,
342,
272,
340,
1788,
436,
485,
736,
14,
515,
14,
6292,
8,
1501,
304,
267,
4090,
275,
1551,
8,
1501,
9,
267,
862,
26,
288,
1369,
275,
4090,
14,
739,
1252,
6735,
342,
267,
3753,
26,
288,
4090,
14,
1600,
342,
398,
340,
6212,
365,
488,
436,
1369,
26,
288,
687,
18382,
492,
6170,
288,
6212,
275,
6170,
14,
4763,
63,
4181,
8,
355,
1350,
29,
1802,
12,
355,
1350,
63,
515,
29,
1501,
12,
355,
7060,
63,
354,
534,
1360,
297,
288,
776,
459,
1213,
2278,
2143,
360,
1624,
13,
24,
358,
339,
372,
6212,
12,
1369,
421,
199,
318,
2342,
63,
27628,
8,
4757,
304,
272,
408,
272,
14703,
19137,
687,
13354,
16435,
1976,
3960,
339,
520,
1107,
26,
3820,
402,
19137,
15693,
459,
14720,
297,
21214,
16580,
272,
520,
4500,
26,
1124,
513,
1040,
272,
408,
272,
1788,
275,
9149,
14,
362,
360,
2024,
14,
27628,
297,
283,
31163,
1976,
3960,
1959,
1913,
342,
272,
340,
1788,
436,
485,
736,
14,
515,
14,
6292,
8,
1501,
304,
267,
4090,
275,
1551,
8,
1501,
9,
267,
862,
26,
288,
1564,
275,
4090,
14,
739,
342,
267,
3753,
26,
288,
4090,
14,
1600,
342,
267,
1564,
275,
359,
1053,
14,
1913,
342,
367,
1242,
315,
1564,
14,
7644,
5106,
267,
372,
359,
1053,
367,
1242,
315,
1564,
340,
1242,
436,
440,
1242,
14,
2460,
7863,
5440,
272,
372,
942,
421,
199,
318,
2342,
63,
20121,
8,
4757,
304,
272,
408,
272,
14703,
6571,
687,
6837,
654,
339,
520,
1107,
26,
3820
] |
[
1882,
2803,
26,
13294,
1882,
199,
3,
199,
3,
1898,
10219,
446,
6171,
199,
3,
6061,
82,
60,
1845,
25,
603,
12201,
503,
17049,
23854,
17564,
12,
465,
3964,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
624,
199,
1280,
5918,
199,
11298,
3272,
7876,
199,
1280,
5918,
199,
199,
2765,
859,
6571,
282,
4975,
6818,
314,
7065,
6170,
3272,
14,
199,
624,
199,
363,
2502,
363,
275,
399,
2,
3325,
82,
60,
1845,
25,
603,
12201,
2,
199,
363,
21841,
363,
275,
298,
26854,
655,
2,
199,
199,
646,
14196,
465,
485,
888,
63,
2087,
199,
504,
7065,
492,
6170,
465,
485,
1018,
199,
646,
747,
465,
485,
736,
199,
646,
15454,
465,
485,
23342,
199,
646,
984,
465,
485,
1274,
199,
199,
504,
485,
2758,
492,
3718,
465,
485,
4405,
199,
504,
485,
2758,
492,
666,
465,
485,
576,
199,
504,
485,
2758,
492,
1599,
465,
485,
832,
199,
504,
485,
2758,
492,
4884,
465,
485,
1974,
199,
504,
485,
2758,
492,
5218,
465,
485,
5641,
421,
199,
318,
1104,
63,
1548,
63,
1023,
8,
5472,
12,
1015,
63,
827,
12,
1015,
63,
988,
304,
272,
408,
2670,
2366,
1015,
408,
272,
340,
11512,
508,
283,
1548,
356,
267,
1015,
63,
815,
275,
485,
1274,
14,
1023,
63,
815,
272,
916,
11512,
508,
283,
20233,
356,
267,
1015,
63,
815,
275,
2519,
1547,
1274,
12,
283,
20233,
63,
1023,
63,
815,
297,
488,
9,
267,
340,
440,
1015,
63,
815,
26,
288,
372,
272,
916,
11512,
508,
283,
27179,
356,
267,
340,
440,
283,
6138,
7,
315,
485,
1274,
14,
3246,
14,
2325,
837,
288,
372,
267,
1015,
63,
815,
275,
485,
1274,
14,
1023,
63,
815,
272,
587,
26,
267,
746,
9070,
480,
5472,
440,
315,
661,
1548,
297,
283,
20233,
297,
283,
27179,
26530,
339,
1134,
1023,
275,
2341,
8,
442,
12,
1015,
63,
815,
1491,
19,
566,
272,
340,
1015,
63,
827,
26,
267,
1748,
63,
2427,
275,
971,
288,
2341,
8,
442,
12,
15671,
904,
1332,
1023,
63,
827,
12,
283,
16,
14,
16,
14,
16,
11103,
1294,
7563,
1491,
19,
566,
267,
340,
1134,
1023,
665,
1748,
63,
2427,
26,
288,
746,
25139,
480,
17809,
737,
5210,
450,
83,
450,
83,
334,
3122,
14,
450,
83,
2924,
450,
334,
355,
11512,
12,
1015,
63,
827,
12,
15671,
904,
8,
1130,
8,
495,
12,
1134,
1023,
430,
288,
5082,
272,
340,
1015,
63,
988,
26,
267,
1390,
63,
2427,
275,
2341,
8,
442,
12,
1015,
63,
988,
14,
1294,
24535,
267,
1390,
63,
2427,
1988,
17,
61,
847,
413,
267,
340,
1134,
1023,
2356,
1390,
63,
2427,
26,
288,
746,
25139,
480,
17809,
737,
1390,
450,
83,
450,
83,
334,
3122,
14,
450,
83,
2924,
450,
334,
355,
11512,
12,
355,
1015,
63,
988,
12,
355,
15671,
904,
8,
1130,
8,
495,
12,
1134,
1023,
430,
288,
5082,
421,
199,
318,
2342,
63,
1802,
8,
4757,
304,
272,
408,
272,
14703,
314,
2559,
1369,
687,
17410,
1075,
339,
520,
5976,
26,
489,
658,
4757,
64,
520,
1124,
807,
1040,
267,
5454,
83,
1101,
3420,
339,
520,
1767,
26,
11634,
402,
6212,
12,
1369,
436,
4190,
1467,
15693,
360,
4705,
297,
283,
1802,
297,
283,
1682,
358,
16580,
1467,
334,
452,
1443,
506,
1124,
403,
16580,
272,
520,
50,
466,
26,
1124,
2960,
1040,
272,
408,
272,
6212,
275,
488,
272,
1788,
275,
9149,
14,
362,
360,
2024,
14,
4705,
297,
283,
29508,
1959,
1913,
342,
272,
340,
1788,
436,
485,
736,
14,
515,
14,
6292,
8,
1501,
304,
267,
4090,
275,
1551,
8,
1501,
9,
267,
862,
26,
288,
862,
26,
355,
6212,
275,
4090,
14,
739,
1252,
1913,
1252,
7644,
3430,
16,
1055,
6735,
342,
288,
871,
7888,
26,
355,
6212,
275,
2125,
267,
3753,
26,
288,
4090,
14,
1600,
342,
339,
1369,
275,
488,
272,
1788,
275,
9149,
14,
362,
360,
2024,
14,
1802,
297,
283,
17705,
1959,
1913,
342,
272,
340,
1788,
436,
485,
736,
14,
515,
14,
6292,
8,
1501,
304,
267,
4090,
275,
1551,
8,
1501,
9,
267,
862,
26,
288,
1369,
275,
4090,
14,
739,
1252,
6735,
342,
267,
3753,
26,
288,
4090,
14,
1600,
342,
398,
340,
6212,
365,
488,
436,
1369,
26,
288,
687,
18382,
492,
6170,
288,
6212,
275,
6170,
14,
4763,
63,
4181,
8,
355,
1350,
29,
1802,
12,
355,
1350,
63,
515,
29,
1501,
12,
355,
7060,
63,
354,
534,
1360,
297,
288,
776,
459,
1213,
2278,
2143,
360,
1624,
13,
24,
358,
339,
372,
6212,
12,
1369,
421,
199,
318,
2342,
63,
27628,
8,
4757,
304,
272,
408,
272,
14703,
19137,
687,
13354,
16435,
1976,
3960,
339,
520,
1107,
26,
3820,
402,
19137,
15693,
459,
14720,
297,
21214,
16580,
272,
520,
4500,
26,
1124,
513,
1040,
272,
408,
272,
1788,
275,
9149,
14,
362,
360,
2024,
14,
27628,
297,
283,
31163,
1976,
3960,
1959,
1913,
342,
272,
340,
1788,
436,
485,
736,
14,
515,
14,
6292,
8,
1501,
304,
267,
4090,
275,
1551,
8,
1501,
9,
267,
862,
26,
288,
1564,
275,
4090,
14,
739,
342,
267,
3753,
26,
288,
4090,
14,
1600,
342,
267,
1564,
275,
359,
1053,
14,
1913,
342,
367,
1242,
315,
1564,
14,
7644,
5106,
267,
372,
359,
1053,
367,
1242,
315,
1564,
340,
1242,
436,
440,
1242,
14,
2460,
7863,
5440,
272,
372,
942,
421,
199,
318,
2342,
63,
20121,
8,
4757,
304,
272,
408,
272,
14703,
6571,
687,
6837,
654,
339,
520,
1107,
26,
3820,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
bearstech/ansible
|
lib/ansible/plugins/action/eos_config.py
|
126
|
4193
|
#
# Copyright 2015 Peter Sprygada <psprygada@ansible.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
import re
import time
import glob
from ansible.plugins.action.eos import ActionModule as _ActionModule
from ansible.module_utils._text import to_text
from ansible.module_utils.six.moves.urllib.parse import urlsplit
from ansible.utils.vars import merge_hash
PRIVATE_KEYS_RE = re.compile('__.+__')
class ActionModule(_ActionModule):
def run(self, tmp=None, task_vars=None):
if self._task.args.get('src'):
try:
self._handle_template()
except ValueError as exc:
return dict(failed=True, msg=exc.message)
result = super(ActionModule, self).run(tmp, task_vars)
if self._task.args.get('backup') and result.get('__backup__'):
# User requested backup and no error occurred in module.
# NOTE: If there is a parameter error, _backup key may not be in results.
filepath = self._write_backup(task_vars['inventory_hostname'],
result['__backup__'])
result['backup_path'] = filepath
# strip out any keys that have two leading and two trailing
# underscore characters
for key in result.keys():
if PRIVATE_KEYS_RE.match(key):
del result[key]
return result
def _get_working_path(self):
cwd = self._loader.get_basedir()
if self._task._role is not None:
cwd = self._task._role._role_path
return cwd
def _write_backup(self, host, contents):
backup_path = self._get_working_path() + '/backup'
if not os.path.exists(backup_path):
os.mkdir(backup_path)
for fn in glob.glob('%s/%s*' % (backup_path, host)):
os.remove(fn)
tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time()))
filename = '%s/%s_config.%s' % (backup_path, host, tstamp)
open(filename, 'w').write(contents)
return filename
def _handle_template(self):
src = self._task.args.get('src')
working_path = self._get_working_path()
if os.path.isabs(src) or urlsplit('src').scheme:
source = src
else:
source = self._loader.path_dwim_relative(working_path, 'templates', src)
if not source:
source = self._loader.path_dwim_relative(working_path, src)
if not os.path.exists(source):
raise ValueError('path specified in src not found')
try:
with open(source, 'r') as f:
template_data = to_text(f.read())
except IOError:
return dict(failed=True, msg='unable to load src file')
# Create a template search path in the following order:
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
searchpath = [working_path]
if self._task._role is not None:
searchpath.append(self._task._role._role_path)
if hasattr(self._task, "_block:"):
dep_chain = self._task._block.get_dep_chain()
if dep_chain is not None:
for role in dep_chain:
searchpath.append(role._role_path)
searchpath.append(os.path.dirname(source))
self._templar.environment.loader.searchpath = searchpath
self._task.args['src'] = self._templar.template(template_data)
|
gpl-3.0
|
[
3,
199,
3,
1898,
6900,
22912,
8360,
651,
71,
10641,
665,
80,
681,
651,
71,
10641,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
747,
199,
646,
295,
199,
646,
900,
199,
646,
5739,
199,
199,
504,
3242,
14,
5265,
14,
1287,
14,
24909,
492,
10033,
2377,
465,
485,
3310,
2377,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
29596,
199,
504,
3242,
14,
1208,
14,
2936,
492,
5389,
63,
2227,
421,
199,
18748,
63,
17434,
63,
907,
275,
295,
14,
2014,
360,
4343,
11,
13766,
421,
199,
533,
10033,
2377,
1547,
3310,
2377,
304,
339,
347,
1255,
8,
277,
12,
3529,
29,
403,
12,
2120,
63,
2936,
29,
403,
304,
398,
340,
291,
423,
1765,
14,
589,
14,
362,
360,
2164,
735,
288,
862,
26,
355,
291,
423,
2479,
63,
1160,
342,
288,
871,
1722,
465,
3178,
26,
355,
372,
1211,
8,
4892,
29,
549,
12,
1499,
29,
2804,
14,
1188,
9,
398,
754,
275,
1613,
8,
3310,
2377,
12,
291,
680,
1065,
8,
2791,
12,
2120,
63,
2936,
9,
398,
340,
291,
423,
1765,
14,
589,
14,
362,
360,
5751,
358,
436,
754,
14,
362,
10714,
5751,
12168,
288,
327,
2876,
5839,
6902,
436,
949,
1125,
8920,
315,
859,
14,
288,
327,
6944,
26,
982,
2337,
365,
282,
2725,
1125,
12,
485,
5751,
790,
1443,
440,
506,
315,
2058,
14,
288,
9911,
275,
291,
423,
952,
63,
5751,
8,
1765,
63,
2936,
459,
7212,
63,
4269,
995,
5101,
754,
13742,
5751,
363,
1105,
953,
754,
459,
5751,
63,
515,
418,
275,
9911,
398,
327,
6202,
734,
1263,
2883,
626,
1172,
2877,
9186,
436,
2877,
8520,
267,
327,
18888,
4110,
267,
367,
790,
315,
754,
14,
1612,
837,
288,
340,
28644,
1951,
63,
17434,
63,
907,
14,
1431,
8,
498,
304,
355,
2150,
754,
59,
498,
61,
398,
372,
754,
339,
347,
485,
362,
63,
9818,
63,
515,
8,
277,
304,
267,
8288,
275,
291,
423,
3422,
14,
362,
63,
12484,
342,
267,
340,
291,
423,
1765,
423,
3756,
365,
440,
488,
26,
288,
8288,
275,
291,
423,
1765,
423,
3756,
423,
3756,
63,
515,
267,
372,
8288,
339,
347,
485,
952,
63,
5751,
8,
277,
12,
1591,
12,
4072,
304,
267,
6902,
63,
515,
275,
291,
423,
362,
63,
9818,
63,
515,
342,
435,
1994,
5751,
7,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
5751,
63,
515,
304,
288,
747,
14,
8215,
8,
5751,
63,
515,
9,
267,
367,
4325,
315,
5739,
14,
6463,
3508,
83,
3149,
83,
10223,
450,
334,
5751,
63,
515,
12,
1591,
2298,
288,
747,
14,
2168,
8,
2324,
9,
267,
307,
2359,
275,
900,
14,
6205,
3647,
57,
3295,
77,
3295,
68,
19437,
40,
2689,
45,
2689,
51,
401,
900,
14,
15198,
8,
521,
14,
521,
4059,
267,
1788,
275,
1543,
83,
3149,
83,
63,
888,
4111,
83,
7,
450,
334,
5751,
63,
515,
12,
1591,
12,
307,
2359,
9,
267,
1551,
8,
1501,
12,
283,
87,
1959,
952,
8,
4407,
9,
267,
372,
1788,
339,
347,
485,
2479,
63,
1160,
8,
277,
304,
267,
2928,
275,
291,
423,
1765,
14,
589,
14,
362,
360,
2164,
358,
267,
6449,
63,
515,
275,
291,
423,
362,
63,
9818,
63,
515,
342,
398,
340,
747,
14,
515,
14,
17896,
8,
2164,
9,
503,
29596,
360,
2164,
1959,
5512,
26,
288,
1350,
275,
2928,
267,
587,
26,
288,
1350,
275,
291,
423,
3422,
14,
515,
63,
10772,
1017,
63,
6188,
8,
9818,
63,
515,
12,
283,
5876,
297,
2928,
9,
288,
340,
440,
1350,
26,
355,
1350,
275,
291,
423,
3422,
14,
515,
63,
10772,
1017,
63,
6188,
8,
9818,
63,
515,
12,
2928,
9,
398,
340,
440,
747,
14,
515,
14,
2444,
8,
1365,
304,
288,
746,
1722,
360,
515,
2013,
315,
2928,
440,
1911,
358,
398,
862,
26,
288,
543,
1551,
8,
1365,
12,
283,
82,
358,
465,
289,
26,
355,
1978,
63,
576,
275,
370,
63,
505,
8,
70,
14,
739,
1012,
267,
871,
5925,
26,
288,
372,
1211,
8,
4892,
29,
549,
12,
1499,
534,
17200,
370,
2248,
2928,
570,
358,
398,
327,
2790,
282,
1978,
2754,
931,
315,
314,
2569,
1865,
26,
267,
327,
359,
9818,
63,
515,
12,
291,
63,
3756,
63,
515,
12,
11410,
63,
3756,
63,
3771,
12,
9017,
8,
1365,
1874,
267,
2754,
515,
275,
359,
9818,
63,
515,
61,
267,
340,
291,
423,
1765,
423,
3756,
365,
440,
488,
26,
288,
2754,
515,
14,
740,
8,
277,
423,
1765,
423,
3756,
423,
3756,
63,
515,
9,
288,
340,
2688,
8,
277,
423,
1765,
12,
2668,
1457,
26,
2349,
355,
2657,
63,
4429,
275,
291,
423,
1765,
423,
1457,
14,
362,
63,
2601,
63,
4429,
342,
355,
340,
2657,
63,
4429,
365,
440,
488,
26,
490,
367,
4719,
315,
2657,
63,
4429,
26,
717,
2754,
515,
14,
740,
8,
3756,
423,
3756,
63,
515,
9,
267,
2754,
515,
14,
740,
8,
736,
14,
515,
14,
3475,
8,
1365,
430,
267,
291,
423,
26718,
14,
5418
] |
[
199,
3,
1898,
6900,
22912,
8360,
651,
71,
10641,
665,
80,
681,
651,
71,
10641,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
747,
199,
646,
295,
199,
646,
900,
199,
646,
5739,
199,
199,
504,
3242,
14,
5265,
14,
1287,
14,
24909,
492,
10033,
2377,
465,
485,
3310,
2377,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
29596,
199,
504,
3242,
14,
1208,
14,
2936,
492,
5389,
63,
2227,
421,
199,
18748,
63,
17434,
63,
907,
275,
295,
14,
2014,
360,
4343,
11,
13766,
421,
199,
533,
10033,
2377,
1547,
3310,
2377,
304,
339,
347,
1255,
8,
277,
12,
3529,
29,
403,
12,
2120,
63,
2936,
29,
403,
304,
398,
340,
291,
423,
1765,
14,
589,
14,
362,
360,
2164,
735,
288,
862,
26,
355,
291,
423,
2479,
63,
1160,
342,
288,
871,
1722,
465,
3178,
26,
355,
372,
1211,
8,
4892,
29,
549,
12,
1499,
29,
2804,
14,
1188,
9,
398,
754,
275,
1613,
8,
3310,
2377,
12,
291,
680,
1065,
8,
2791,
12,
2120,
63,
2936,
9,
398,
340,
291,
423,
1765,
14,
589,
14,
362,
360,
5751,
358,
436,
754,
14,
362,
10714,
5751,
12168,
288,
327,
2876,
5839,
6902,
436,
949,
1125,
8920,
315,
859,
14,
288,
327,
6944,
26,
982,
2337,
365,
282,
2725,
1125,
12,
485,
5751,
790,
1443,
440,
506,
315,
2058,
14,
288,
9911,
275,
291,
423,
952,
63,
5751,
8,
1765,
63,
2936,
459,
7212,
63,
4269,
995,
5101,
754,
13742,
5751,
363,
1105,
953,
754,
459,
5751,
63,
515,
418,
275,
9911,
398,
327,
6202,
734,
1263,
2883,
626,
1172,
2877,
9186,
436,
2877,
8520,
267,
327,
18888,
4110,
267,
367,
790,
315,
754,
14,
1612,
837,
288,
340,
28644,
1951,
63,
17434,
63,
907,
14,
1431,
8,
498,
304,
355,
2150,
754,
59,
498,
61,
398,
372,
754,
339,
347,
485,
362,
63,
9818,
63,
515,
8,
277,
304,
267,
8288,
275,
291,
423,
3422,
14,
362,
63,
12484,
342,
267,
340,
291,
423,
1765,
423,
3756,
365,
440,
488,
26,
288,
8288,
275,
291,
423,
1765,
423,
3756,
423,
3756,
63,
515,
267,
372,
8288,
339,
347,
485,
952,
63,
5751,
8,
277,
12,
1591,
12,
4072,
304,
267,
6902,
63,
515,
275,
291,
423,
362,
63,
9818,
63,
515,
342,
435,
1994,
5751,
7,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
5751,
63,
515,
304,
288,
747,
14,
8215,
8,
5751,
63,
515,
9,
267,
367,
4325,
315,
5739,
14,
6463,
3508,
83,
3149,
83,
10223,
450,
334,
5751,
63,
515,
12,
1591,
2298,
288,
747,
14,
2168,
8,
2324,
9,
267,
307,
2359,
275,
900,
14,
6205,
3647,
57,
3295,
77,
3295,
68,
19437,
40,
2689,
45,
2689,
51,
401,
900,
14,
15198,
8,
521,
14,
521,
4059,
267,
1788,
275,
1543,
83,
3149,
83,
63,
888,
4111,
83,
7,
450,
334,
5751,
63,
515,
12,
1591,
12,
307,
2359,
9,
267,
1551,
8,
1501,
12,
283,
87,
1959,
952,
8,
4407,
9,
267,
372,
1788,
339,
347,
485,
2479,
63,
1160,
8,
277,
304,
267,
2928,
275,
291,
423,
1765,
14,
589,
14,
362,
360,
2164,
358,
267,
6449,
63,
515,
275,
291,
423,
362,
63,
9818,
63,
515,
342,
398,
340,
747,
14,
515,
14,
17896,
8,
2164,
9,
503,
29596,
360,
2164,
1959,
5512,
26,
288,
1350,
275,
2928,
267,
587,
26,
288,
1350,
275,
291,
423,
3422,
14,
515,
63,
10772,
1017,
63,
6188,
8,
9818,
63,
515,
12,
283,
5876,
297,
2928,
9,
288,
340,
440,
1350,
26,
355,
1350,
275,
291,
423,
3422,
14,
515,
63,
10772,
1017,
63,
6188,
8,
9818,
63,
515,
12,
2928,
9,
398,
340,
440,
747,
14,
515,
14,
2444,
8,
1365,
304,
288,
746,
1722,
360,
515,
2013,
315,
2928,
440,
1911,
358,
398,
862,
26,
288,
543,
1551,
8,
1365,
12,
283,
82,
358,
465,
289,
26,
355,
1978,
63,
576,
275,
370,
63,
505,
8,
70,
14,
739,
1012,
267,
871,
5925,
26,
288,
372,
1211,
8,
4892,
29,
549,
12,
1499,
534,
17200,
370,
2248,
2928,
570,
358,
398,
327,
2790,
282,
1978,
2754,
931,
315,
314,
2569,
1865,
26,
267,
327,
359,
9818,
63,
515,
12,
291,
63,
3756,
63,
515,
12,
11410,
63,
3756,
63,
3771,
12,
9017,
8,
1365,
1874,
267,
2754,
515,
275,
359,
9818,
63,
515,
61,
267,
340,
291,
423,
1765,
423,
3756,
365,
440,
488,
26,
288,
2754,
515,
14,
740,
8,
277,
423,
1765,
423,
3756,
423,
3756,
63,
515,
9,
288,
340,
2688,
8,
277,
423,
1765,
12,
2668,
1457,
26,
2349,
355,
2657,
63,
4429,
275,
291,
423,
1765,
423,
1457,
14,
362,
63,
2601,
63,
4429,
342,
355,
340,
2657,
63,
4429,
365,
440,
488,
26,
490,
367,
4719,
315,
2657,
63,
4429,
26,
717,
2754,
515,
14,
740,
8,
3756,
423,
3756,
63,
515,
9,
267,
2754,
515,
14,
740,
8,
736,
14,
515,
14,
3475,
8,
1365,
430,
267,
291,
423,
26718,
14,
5418,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
jackkiej/SickRage
|
lib/sqlalchemy/orm/exc.py
|
79
|
5433
|
# orm/exc.py
# Copyright (C) 2005-2014 the SQLAlchemy authors and contributors <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""SQLAlchemy ORM exceptions."""
from .. import exc as sa_exc, util
NO_STATE = (AttributeError, KeyError)
"""Exception types that may be raised by instrumentation implementations."""
class StaleDataError(sa_exc.SQLAlchemyError):
"""An operation encountered database state that is unaccounted for.
Conditions which cause this to happen include:
* A flush may have attempted to update or delete rows
and an unexpected number of rows were matched during
the UPDATE or DELETE statement. Note that when
version_id_col is used, rows in UPDATE or DELETE statements
are also matched against the current known version
identifier.
* A mapped object with version_id_col was refreshed,
and the version number coming back from the database does
not match that of the object itself.
* A object is detached from its parent object, however
the object was previously attached to a different parent
identity which was garbage collected, and a decision
cannot be made if the new parent was really the most
recent "parent".
.. versionadded:: 0.7.4
"""
ConcurrentModificationError = StaleDataError
class FlushError(sa_exc.SQLAlchemyError):
"""A invalid condition was detected during flush()."""
class UnmappedError(sa_exc.InvalidRequestError):
"""Base for exceptions that involve expected mappings not present."""
class ObjectDereferencedError(sa_exc.SQLAlchemyError):
"""An operation cannot complete due to an object being garbage
collected.
"""
class DetachedInstanceError(sa_exc.SQLAlchemyError):
"""An attempt to access unloaded attributes on a
mapped instance that is detached."""
class UnmappedInstanceError(UnmappedError):
"""An mapping operation was requested for an unknown instance."""
@util.dependencies("sqlalchemy.orm.base")
def __init__(self, base, obj, msg=None):
if not msg:
try:
base.class_mapper(type(obj))
name = _safe_cls_name(type(obj))
msg = ("Class %r is mapped, but this instance lacks "
"instrumentation. This occurs when the instance"
"is created before sqlalchemy.orm.mapper(%s) "
"was called." % (name, name))
except UnmappedClassError:
msg = _default_unmapped(type(obj))
if isinstance(obj, type):
msg += (
'; was a class (%s) supplied where an instance was '
'required?' % _safe_cls_name(obj))
UnmappedError.__init__(self, msg)
def __reduce__(self):
return self.__class__, (None, self.args[0])
class UnmappedClassError(UnmappedError):
"""An mapping operation was requested for an unknown class."""
def __init__(self, cls, msg=None):
if not msg:
msg = _default_unmapped(cls)
UnmappedError.__init__(self, msg)
def __reduce__(self):
return self.__class__, (None, self.args[0])
class ObjectDeletedError(sa_exc.InvalidRequestError):
"""A refresh operation failed to retrieve the database
row corresponding to an object's known primary key identity.
A refresh operation proceeds when an expired attribute is
accessed on an object, or when :meth:`.Query.get` is
used to retrieve an object which is, upon retrieval, detected
as expired. A SELECT is emitted for the target row
based on primary key; if no row is returned, this
exception is raised.
The true meaning of this exception is simply that
no row exists for the primary key identifier associated
with a persistent object. The row may have been
deleted, or in some cases the primary key updated
to a new value, outside of the ORM's management of the target
object.
"""
@util.dependencies("sqlalchemy.orm.base")
def __init__(self, base, state, msg=None):
if not msg:
msg = "Instance '%s' has been deleted, or its "\
"row is otherwise not present." % base.state_str(state)
sa_exc.InvalidRequestError.__init__(self, msg)
def __reduce__(self):
return self.__class__, (None, self.args[0])
class UnmappedColumnError(sa_exc.InvalidRequestError):
"""Mapping operation was requested on an unknown column."""
class NoResultFound(sa_exc.InvalidRequestError):
"""A database result was required but none was found."""
class MultipleResultsFound(sa_exc.InvalidRequestError):
"""A single database result was required but more than one were found."""
def _safe_cls_name(cls):
try:
cls_name = '.'.join((cls.__module__, cls.__name__))
except AttributeError:
cls_name = getattr(cls, '__name__', None)
if cls_name is None:
cls_name = repr(cls)
return cls_name
@util.dependencies("sqlalchemy.orm.base")
def _default_unmapped(base, cls):
try:
mappers = base.manager_of_class(cls).mappers
except NO_STATE:
mappers = {}
except TypeError:
mappers = {}
name = _safe_cls_name(cls)
if not mappers:
return "Class '%s' is not mapped" % name
|
gpl-3.0
|
[
3,
9813,
15,
2804,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
7280,
314,
14303,
11462,
436,
8417,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
4657,
12800,
23383,
4967,
1041,
199,
504,
2508,
492,
3178,
465,
2937,
63,
2804,
12,
4884,
199,
199,
2826,
63,
6689,
275,
334,
10227,
12,
4067,
9,
199,
624,
1726,
2943,
626,
1443,
506,
4915,
701,
14498,
425,
12591,
1041,
421,
199,
533,
7083,
274,
1451,
547,
8,
2231,
63,
2804,
14,
4657,
12800,
547,
304,
272,
408,
2493,
3439,
14556,
3050,
1174,
626,
365,
625,
645,
3094,
471,
367,
14,
339,
1448,
3138,
1314,
7675,
642,
370,
5992,
2387,
26,
339,
627,
437,
8976,
1443,
1172,
22040,
370,
1678,
503,
3145,
4730,
489,
436,
376,
10537,
1329,
402,
4730,
4898,
7838,
5309,
489,
314,
17148,
503,
15137,
5164,
14,
257,
3390,
626,
1380,
489,
1015,
63,
344,
63,
761,
365,
1202,
12,
4730,
315,
17148,
503,
15137,
9834,
489,
787,
2597,
7838,
6169,
314,
1453,
6040,
1015,
489,
5148,
14,
339,
627,
437,
9994,
909,
543,
1015,
63,
344,
63,
761,
1990,
9236,
379,
12,
489,
436,
314,
1015,
1329,
17262,
1771,
687,
314,
3050,
1630,
489,
440,
1336,
626,
402,
314,
909,
6337,
14,
339,
627,
437,
909,
365,
32348,
687,
2399,
1676,
909,
12,
13432,
489,
314,
909,
1990,
10889,
10102,
370,
282,
3365,
1676,
489,
8503,
1314,
1990,
17516,
13736,
12,
436,
282,
14692,
489,
3913,
506,
6326,
340,
314,
892,
1676,
1990,
7710,
314,
4750,
489,
8058,
298,
1708,
1674,
2541,
2508,
7445,
447,
378,
14,
23,
14,
20,
339,
408,
199,
199,
714,
1818,
29188,
547,
275,
7083,
274,
1451,
547,
421,
199,
533,
11040,
2084,
547,
8,
2231,
63,
2804,
14,
4657,
12800,
547,
304,
272,
408,
33,
3866,
5558,
1990,
10501,
5309,
8976,
20693,
421,
199,
533,
1910,
11663,
547,
8,
2231,
63,
2804,
14,
26585,
304,
272,
408,
1563,
367,
4967,
626,
4572,
3344,
1420,
13546,
440,
3451,
1041,
421,
199,
533,
6935,
872,
22355,
547,
8,
2231,
63,
2804,
14,
4657,
12800,
547,
304,
272,
408,
2493,
3439,
3913,
4890,
7037,
370,
376,
909,
3769,
17516,
272,
13736,
14,
339,
408,
421,
199,
533,
577,
386,
4583,
3244,
547,
8,
2231,
63,
2804,
14,
4657,
12800,
547,
304,
272,
408,
2493,
7427,
370,
2879,
625,
4591,
3004,
641,
282,
272,
9994,
1256,
626,
365,
32348,
1041,
421,
199,
533,
1910,
11663,
3244,
547,
8,
1358,
11663,
547,
304,
272,
408,
2493,
4412,
3439,
1990,
5839,
367,
376,
5809,
1256,
1041,
339,
768,
1974,
14,
5714,
480,
14536,
14,
1025,
14,
1095,
531,
272,
347,
636,
826,
721,
277,
12,
1300,
12,
1559,
12,
1499,
29,
403,
304,
267,
340,
440,
1499,
26,
288,
862,
26,
355,
1300,
14,
533,
63,
7153,
8,
466,
8,
1113,
430,
355,
536,
275,
485,
3489,
63,
1886,
63,
354,
8,
466,
8,
1113,
430,
355,
1499,
275,
1689,
2543,
450,
82,
365,
9994,
12,
1325,
642,
1256,
1127,
5618,
298,
2432,
298,
13321,
425,
14,
221,
961,
11058,
1380,
314,
1256,
2,
2432,
298,
374,
2737,
2544,
8335,
14,
1025,
14,
7153,
4042,
83,
9,
298,
2432,
298,
10274,
2797,
2122,
450,
334,
354,
12,
536,
430,
288,
871,
1910,
11663,
2543,
547,
26,
355,
1499,
275,
485,
885,
63,
324,
11663,
8,
466,
8,
1113,
430,
355,
340,
1228,
8,
1113,
12,
730,
304,
490,
1499,
847,
334,
717,
14289,
1990,
282,
1021,
4366,
83,
9,
6841,
2382,
376,
1256,
1990,
283,
717,
283,
2427,
14069,
450,
485,
3489,
63,
1886,
63,
354,
8,
1113,
430,
267,
1910,
11663,
547,
855,
826,
721,
277,
12,
1499,
9,
339,
347,
636,
5270,
721,
277,
304,
267,
372,
291,
855,
533,
3108,
334,
403,
12,
291,
14,
589,
59,
16,
566,
421,
199,
533,
1910,
11663,
2543,
547,
8,
1358,
11663,
547,
304,
272,
408,
2493,
4412,
3439,
1990,
5839,
367,
376,
5809,
1021,
1041,
339,
347,
636,
826,
721,
277,
12,
843,
12,
1499,
29,
403,
304,
267,
340,
440,
1499,
26,
288,
1499,
275,
485,
885,
63,
324,
11663,
8,
1886,
9,
267,
1910,
11663,
547,
855,
826,
721,
277,
12,
1499,
9,
339,
347,
636,
5270,
721,
277,
304,
267,
372,
291,
855,
533,
3108,
334,
403,
12,
291,
14,
589,
59,
16,
566,
421,
199,
533,
6935,
17735,
547,
8,
2231,
63,
2804,
14,
26585,
304,
272,
408,
33,
9236,
3439,
3405,
370,
8044,
314,
3050,
272,
1962,
5226,
370,
376,
909,
1159,
6040,
5062,
790,
8503,
14,
339,
437,
9236,
3439,
557,
301,
5923,
1380,
376,
14721,
2225,
365,
272,
13810,
641,
376,
909,
12,
503,
1380,
520,
5247,
5026,
3227,
14,
362,
64,
365,
272,
1202,
370,
8044,
376,
909,
1314,
365,
12,
12188,
27157,
12,
10501,
272,
465,
14721,
14,
257,
437,
10468,
365,
19515,
367,
314,
1347,
1962,
272,
4079,
641,
5062,
790,
27,
340,
949,
1962,
365,
2138,
12,
642,
272,
1919,
365,
4915,
14,
339,
710,
2549,
11150,
402,
642,
1919,
365,
9329,
626,
272,
949,
1962,
3495,
367,
314,
5062,
790,
5148,
4568,
272,
543,
282,
16149,
909,
14,
257,
710,
1962,
1443,
1172,
2757,
272,
5463,
12,
503,
315,
2005,
5560,
314,
5062,
790,
4588,
272,
370,
282,
892,
574,
12,
9682,
402,
314,
23383,
1159,
10041,
402,
314,
1347,
272,
909,
14,
339,
408,
272,
768,
1974,
14,
5714,
480,
14536,
14,
1025,
14,
1095,
531,
272,
347,
636,
826,
721,
277,
12,
1300,
12,
1174,
12,
1499,
29,
403,
304,
267,
340,
440,
1499,
26,
288,
1499,
275,
298,
3244,
1543,
83,
7,
965,
2757,
5463,
12,
503,
2399,
1867,
1467,
298,
1143,
365,
4257,
440,
3451,
2122,
450,
1300,
14,
929,
63,
495,
8,
929,
9,
398,
2937,
63,
2804,
14,
26585,
855,
826,
721,
277,
12,
1499,
9,
339,
347,
636,
5270,
721,
277,
304,
267,
372,
291,
855,
533,
3108,
334,
403,
12,
291,
14,
589,
59,
16,
566,
421,
199,
533,
1910,
11663,
4547,
547,
8,
2231,
63
] |
[
9813,
15,
2804,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
7280,
314,
14303,
11462,
436,
8417,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
4657,
12800,
23383,
4967,
1041,
199,
504,
2508,
492,
3178,
465,
2937,
63,
2804,
12,
4884,
199,
199,
2826,
63,
6689,
275,
334,
10227,
12,
4067,
9,
199,
624,
1726,
2943,
626,
1443,
506,
4915,
701,
14498,
425,
12591,
1041,
421,
199,
533,
7083,
274,
1451,
547,
8,
2231,
63,
2804,
14,
4657,
12800,
547,
304,
272,
408,
2493,
3439,
14556,
3050,
1174,
626,
365,
625,
645,
3094,
471,
367,
14,
339,
1448,
3138,
1314,
7675,
642,
370,
5992,
2387,
26,
339,
627,
437,
8976,
1443,
1172,
22040,
370,
1678,
503,
3145,
4730,
489,
436,
376,
10537,
1329,
402,
4730,
4898,
7838,
5309,
489,
314,
17148,
503,
15137,
5164,
14,
257,
3390,
626,
1380,
489,
1015,
63,
344,
63,
761,
365,
1202,
12,
4730,
315,
17148,
503,
15137,
9834,
489,
787,
2597,
7838,
6169,
314,
1453,
6040,
1015,
489,
5148,
14,
339,
627,
437,
9994,
909,
543,
1015,
63,
344,
63,
761,
1990,
9236,
379,
12,
489,
436,
314,
1015,
1329,
17262,
1771,
687,
314,
3050,
1630,
489,
440,
1336,
626,
402,
314,
909,
6337,
14,
339,
627,
437,
909,
365,
32348,
687,
2399,
1676,
909,
12,
13432,
489,
314,
909,
1990,
10889,
10102,
370,
282,
3365,
1676,
489,
8503,
1314,
1990,
17516,
13736,
12,
436,
282,
14692,
489,
3913,
506,
6326,
340,
314,
892,
1676,
1990,
7710,
314,
4750,
489,
8058,
298,
1708,
1674,
2541,
2508,
7445,
447,
378,
14,
23,
14,
20,
339,
408,
199,
199,
714,
1818,
29188,
547,
275,
7083,
274,
1451,
547,
421,
199,
533,
11040,
2084,
547,
8,
2231,
63,
2804,
14,
4657,
12800,
547,
304,
272,
408,
33,
3866,
5558,
1990,
10501,
5309,
8976,
20693,
421,
199,
533,
1910,
11663,
547,
8,
2231,
63,
2804,
14,
26585,
304,
272,
408,
1563,
367,
4967,
626,
4572,
3344,
1420,
13546,
440,
3451,
1041,
421,
199,
533,
6935,
872,
22355,
547,
8,
2231,
63,
2804,
14,
4657,
12800,
547,
304,
272,
408,
2493,
3439,
3913,
4890,
7037,
370,
376,
909,
3769,
17516,
272,
13736,
14,
339,
408,
421,
199,
533,
577,
386,
4583,
3244,
547,
8,
2231,
63,
2804,
14,
4657,
12800,
547,
304,
272,
408,
2493,
7427,
370,
2879,
625,
4591,
3004,
641,
282,
272,
9994,
1256,
626,
365,
32348,
1041,
421,
199,
533,
1910,
11663,
3244,
547,
8,
1358,
11663,
547,
304,
272,
408,
2493,
4412,
3439,
1990,
5839,
367,
376,
5809,
1256,
1041,
339,
768,
1974,
14,
5714,
480,
14536,
14,
1025,
14,
1095,
531,
272,
347,
636,
826,
721,
277,
12,
1300,
12,
1559,
12,
1499,
29,
403,
304,
267,
340,
440,
1499,
26,
288,
862,
26,
355,
1300,
14,
533,
63,
7153,
8,
466,
8,
1113,
430,
355,
536,
275,
485,
3489,
63,
1886,
63,
354,
8,
466,
8,
1113,
430,
355,
1499,
275,
1689,
2543,
450,
82,
365,
9994,
12,
1325,
642,
1256,
1127,
5618,
298,
2432,
298,
13321,
425,
14,
221,
961,
11058,
1380,
314,
1256,
2,
2432,
298,
374,
2737,
2544,
8335,
14,
1025,
14,
7153,
4042,
83,
9,
298,
2432,
298,
10274,
2797,
2122,
450,
334,
354,
12,
536,
430,
288,
871,
1910,
11663,
2543,
547,
26,
355,
1499,
275,
485,
885,
63,
324,
11663,
8,
466,
8,
1113,
430,
355,
340,
1228,
8,
1113,
12,
730,
304,
490,
1499,
847,
334,
717,
14289,
1990,
282,
1021,
4366,
83,
9,
6841,
2382,
376,
1256,
1990,
283,
717,
283,
2427,
14069,
450,
485,
3489,
63,
1886,
63,
354,
8,
1113,
430,
267,
1910,
11663,
547,
855,
826,
721,
277,
12,
1499,
9,
339,
347,
636,
5270,
721,
277,
304,
267,
372,
291,
855,
533,
3108,
334,
403,
12,
291,
14,
589,
59,
16,
566,
421,
199,
533,
1910,
11663,
2543,
547,
8,
1358,
11663,
547,
304,
272,
408,
2493,
4412,
3439,
1990,
5839,
367,
376,
5809,
1021,
1041,
339,
347,
636,
826,
721,
277,
12,
843,
12,
1499,
29,
403,
304,
267,
340,
440,
1499,
26,
288,
1499,
275,
485,
885,
63,
324,
11663,
8,
1886,
9,
267,
1910,
11663,
547,
855,
826,
721,
277,
12,
1499,
9,
339,
347,
636,
5270,
721,
277,
304,
267,
372,
291,
855,
533,
3108,
334,
403,
12,
291,
14,
589,
59,
16,
566,
421,
199,
533,
6935,
17735,
547,
8,
2231,
63,
2804,
14,
26585,
304,
272,
408,
33,
9236,
3439,
3405,
370,
8044,
314,
3050,
272,
1962,
5226,
370,
376,
909,
1159,
6040,
5062,
790,
8503,
14,
339,
437,
9236,
3439,
557,
301,
5923,
1380,
376,
14721,
2225,
365,
272,
13810,
641,
376,
909,
12,
503,
1380,
520,
5247,
5026,
3227,
14,
362,
64,
365,
272,
1202,
370,
8044,
376,
909,
1314,
365,
12,
12188,
27157,
12,
10501,
272,
465,
14721,
14,
257,
437,
10468,
365,
19515,
367,
314,
1347,
1962,
272,
4079,
641,
5062,
790,
27,
340,
949,
1962,
365,
2138,
12,
642,
272,
1919,
365,
4915,
14,
339,
710,
2549,
11150,
402,
642,
1919,
365,
9329,
626,
272,
949,
1962,
3495,
367,
314,
5062,
790,
5148,
4568,
272,
543,
282,
16149,
909,
14,
257,
710,
1962,
1443,
1172,
2757,
272,
5463,
12,
503,
315,
2005,
5560,
314,
5062,
790,
4588,
272,
370,
282,
892,
574,
12,
9682,
402,
314,
23383,
1159,
10041,
402,
314,
1347,
272,
909,
14,
339,
408,
272,
768,
1974,
14,
5714,
480,
14536,
14,
1025,
14,
1095,
531,
272,
347,
636,
826,
721,
277,
12,
1300,
12,
1174,
12,
1499,
29,
403,
304,
267,
340,
440,
1499,
26,
288,
1499,
275,
298,
3244,
1543,
83,
7,
965,
2757,
5463,
12,
503,
2399,
1867,
1467,
298,
1143,
365,
4257,
440,
3451,
2122,
450,
1300,
14,
929,
63,
495,
8,
929,
9,
398,
2937,
63,
2804,
14,
26585,
855,
826,
721,
277,
12,
1499,
9,
339,
347,
636,
5270,
721,
277,
304,
267,
372,
291,
855,
533,
3108,
334,
403,
12,
291,
14,
589,
59,
16,
566,
421,
199,
533,
1910,
11663,
4547,
547,
8,
2231,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ipcamit/ipcamit.github.io
|
node_modules/pygmentize-bundled/vendor/pygments/pygments/lexers/math.py
|
291
|
93298
|
# -*- coding: utf-8 -*-
"""
pygments.lexers.math
~~~~~~~~~~~~~~~~~~~~
Lexers for math languages.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
from pygments.util import shebang_matches
from pygments.lexer import Lexer, RegexLexer, bygroups, include, \
combined, do_insertions
from pygments.token import Comment, String, Punctuation, Keyword, Name, \
Operator, Number, Text, Generic
from pygments.lexers.agile import PythonLexer
from pygments.lexers import _scilab_builtins
from pygments.lexers import _stan_builtins
__all__ = ['JuliaLexer', 'JuliaConsoleLexer', 'MuPADLexer', 'MatlabLexer',
'MatlabSessionLexer', 'OctaveLexer', 'ScilabLexer', 'NumPyLexer',
'RConsoleLexer', 'SLexer', 'JagsLexer', 'BugsLexer', 'StanLexer',
'IDLLexer', 'RdLexer', 'IgorLexer']
class JuliaLexer(RegexLexer):
"""
For `Julia <http://julialang.org/>`_ source code.
*New in Pygments 1.6.*
"""
name = 'Julia'
aliases = ['julia','jl']
filenames = ['*.jl']
mimetypes = ['text/x-julia','application/x-julia']
builtins = [
'exit','whos','edit','load','is','isa','isequal','typeof','tuple',
'ntuple','uid','hash','finalizer','convert','promote','subtype',
'typemin','typemax','realmin','realmax','sizeof','eps','promote_type',
'method_exists','applicable','invoke','dlopen','dlsym','system',
'error','throw','assert','new','Inf','Nan','pi','im',
]
tokens = {
'root': [
(r'\n', Text),
(r'[^\S\n]+', Text),
(r'#.*$', Comment),
(r'[]{}:(),;[@]', Punctuation),
(r'\\\n', Text),
(r'\\', Text),
# keywords
(r'(begin|while|for|in|return|break|continue|'
r'macro|quote|let|if|elseif|else|try|catch|end|'
r'bitstype|ccall|do|using|module|import|export|'
r'importall|baremodule|immutable)\b', Keyword),
(r'(local|global|const)\b', Keyword.Declaration),
(r'(Bool|Int|Int8|Int16|Int32|Int64|Uint|Uint8|Uint16|Uint32|Uint64'
r'|Float32|Float64|Complex64|Complex128|Any|Nothing|None)\b',
Keyword.Type),
# functions
(r'(function)((?:\s|\\\s)+)',
bygroups(Keyword,Name.Function), 'funcname'),
# types
(r'(type|typealias|abstract)((?:\s|\\\s)+)',
bygroups(Keyword,Name.Class), 'typename'),
# operators
(r'==|!=|<=|>=|->|&&|\|\||::|<:|[-~+/*%=<>&^|.?!$]', Operator),
(r'\.\*|\.\^|\.\\|\.\/|\\', Operator),
# builtins
('(' + '|'.join(builtins) + r')\b', Name.Builtin),
# backticks
(r'`(?s).*?`', String.Backtick),
# chars
(r"'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,3}|\\u[a-fA-F0-9]{1,4}|"
r"\\U[a-fA-F0-9]{1,6}|[^\\\'\n])'", String.Char),
# try to match trailing transpose
(r'(?<=[.\w\)\]])\'+', Operator),
# strings
(r'(?:[IL])"', String, 'string'),
(r'[E]?"', String, combined('stringescape', 'string')),
# names
(r'@[a-zA-Z0-9_.]+', Name.Decorator),
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
# numbers
(r'(\d+(_\d+)+\.\d*|\d*\.\d+(_\d+)+)([eEf][+-]?[0-9]+)?', Number.Float),
(r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float),
(r'\d+(_\d+)+[eEf][+-]?[0-9]+', Number.Float),
(r'\d+[eEf][+-]?[0-9]+', Number.Float),
(r'0b[01]+(_[01]+)+', Number.Binary),
(r'0b[01]+', Number.Binary),
(r'0o[0-7]+(_[0-7]+)+', Number.Oct),
(r'0o[0-7]+', Number.Oct),
(r'0x[a-fA-F0-9]+(_[a-fA-F0-9]+)+', Number.Hex),
(r'0x[a-fA-F0-9]+', Number.Hex),
(r'\d+(_\d+)+', Number.Integer),
(r'\d+', Number.Integer)
],
'funcname': [
('[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop'),
('\([^\s\w{]{1,2}\)', Operator, '#pop'),
('[^\s\w{]{1,2}', Operator, '#pop'),
],
'typename': [
('[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
],
'stringescape': [
(r'\\([\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|'
r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape)
],
'string': [
(r'"', String, '#pop'),
(r'\\\\|\\"|\\\n', String.Escape), # included here for raw strings
(r'\$(\([a-zA-Z0-9_]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?',
String.Interpol),
(r'[^\\"$]+', String),
# quotes, dollar signs, and backslashes must be parsed one at a time
(r'["\\]', String),
# unhandled string formatting sign
(r'\$', String)
],
}
def analyse_text(text):
return shebang_matches(text, r'julia')
line_re = re.compile('.*?\n')
class JuliaConsoleLexer(Lexer):
"""
For Julia console sessions. Modeled after MatlabSessionLexer.
*New in Pygments 1.6.*
"""
name = 'Julia console'
aliases = ['jlcon']
def get_tokens_unprocessed(self, text):
jllexer = JuliaLexer(**self.options)
curcode = ''
insertions = []
for match in line_re.finditer(text):
line = match.group()
if line.startswith('julia>'):
insertions.append((len(curcode),
[(0, Generic.Prompt, line[:3])]))
curcode += line[3:]
elif line.startswith(' '):
idx = len(curcode)
# without is showing error on same line as before...?
line = "\n" + line
token = (0, Generic.Traceback, line)
insertions.append((idx, [token]))
else:
if curcode:
for item in do_insertions(
insertions, jllexer.get_tokens_unprocessed(curcode)):
yield item
curcode = ''
insertions = []
yield match.start(), Generic.Output, line
if curcode: # or item:
for item in do_insertions(
insertions, jllexer.get_tokens_unprocessed(curcode)):
yield item
class MuPADLexer(RegexLexer):
"""
A `MuPAD <http://www.mupad.com>`_ lexer.
Contributed by Christopher Creutzig <christopher@creutzig.de>.
*New in Pygments 0.8.*
"""
name = 'MuPAD'
aliases = ['mupad']
filenames = ['*.mu']
tokens = {
'root' : [
(r'//.*?$', Comment.Single),
(r'/\*', Comment.Multiline, 'comment'),
(r'"(?:[^"\\]|\\.)*"', String),
(r'\(|\)|\[|\]|\{|\}', Punctuation),
(r'''(?x)\b(?:
next|break|end|
axiom|end_axiom|category|end_category|domain|end_domain|inherits|
if|%if|then|elif|else|end_if|
case|of|do|otherwise|end_case|
while|end_while|
repeat|until|end_repeat|
for|from|to|downto|step|end_for|
proc|local|option|save|begin|end_proc|
delete|frame
)\b''', Keyword),
(r'''(?x)\b(?:
DOM_ARRAY|DOM_BOOL|DOM_COMPLEX|DOM_DOMAIN|DOM_EXEC|DOM_EXPR|
DOM_FAIL|DOM_FLOAT|DOM_FRAME|DOM_FUNC_ENV|DOM_HFARRAY|DOM_IDENT|
DOM_INT|DOM_INTERVAL|DOM_LIST|DOM_NIL|DOM_NULL|DOM_POLY|DOM_PROC|
DOM_PROC_ENV|DOM_RAT|DOM_SET|DOM_STRING|DOM_TABLE|DOM_VAR
)\b''', Name.Class),
(r'''(?x)\b(?:
PI|EULER|E|CATALAN|
NIL|FAIL|undefined|infinity|
TRUE|FALSE|UNKNOWN
)\b''',
Name.Constant),
(r'\b(?:dom|procname)\b', Name.Builtin.Pseudo),
(r'\.|,|:|;|=|\+|-|\*|/|\^|@|>|<|\$|\||!|\'|%|~=', Operator),
(r'''(?x)\b(?:
and|or|not|xor|
assuming|
div|mod|
union|minus|intersect|in|subset
)\b''',
Operator.Word),
(r'\b(?:I|RDN_INF|RD_NINF|RD_NAN)\b', Number),
#(r'\b(?:adt|linalg|newDomain|hold)\b', Name.Builtin),
(r'''(?x)
((?:[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)
(?:::[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)*)(\s*)([(])''',
bygroups(Name.Function, Text, Punctuation)),
(r'''(?x)
(?:[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)
(?:::[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)*''', Name.Variable),
(r'[0-9]+(?:\.[0-9]*)?(?:e[0-9]+)?', Number),
(r'\.[0-9]+(?:e[0-9]+)?', Number),
(r'.', Text)
],
'comment' : [
(r'[^*/]', Comment.Multiline),
(r'/\*', Comment.Multiline, '#push'),
(r'\*/', Comment.Multiline, '#pop'),
(r'[*/]', Comment.Multiline)
]
}
class MatlabLexer(RegexLexer):
"""
For Matlab source code.
*New in Pygments 0.10.*
"""
name = 'Matlab'
aliases = ['matlab']
filenames = ['*.m']
mimetypes = ['text/matlab']
#
# These lists are generated automatically.
# Run the following in bash shell:
#
# for f in elfun specfun elmat; do
# echo -n "$f = "
# matlab -nojvm -r "help $f;exit;" | perl -ne \
# 'push(@c,$1) if /^ (\w+)\s+-/; END {print q{["}.join(q{","},@c).qq{"]\n};}'
# done
#
# elfun: Elementary math functions
# specfun: Special Math functions
# elmat: Elementary matrices and matrix manipulation
#
# taken from Matlab version 7.4.0.336 (R2007a)
#
elfun = ["sin","sind","sinh","asin","asind","asinh","cos","cosd","cosh",
"acos","acosd","acosh","tan","tand","tanh","atan","atand","atan2",
"atanh","sec","secd","sech","asec","asecd","asech","csc","cscd",
"csch","acsc","acscd","acsch","cot","cotd","coth","acot","acotd",
"acoth","hypot","exp","expm1","log","log1p","log10","log2","pow2",
"realpow","reallog","realsqrt","sqrt","nthroot","nextpow2","abs",
"angle","complex","conj","imag","real","unwrap","isreal","cplxpair",
"fix","floor","ceil","round","mod","rem","sign"]
specfun = ["airy","besselj","bessely","besselh","besseli","besselk","beta",
"betainc","betaln","ellipj","ellipke","erf","erfc","erfcx",
"erfinv","expint","gamma","gammainc","gammaln","psi","legendre",
"cross","dot","factor","isprime","primes","gcd","lcm","rat",
"rats","perms","nchoosek","factorial","cart2sph","cart2pol",
"pol2cart","sph2cart","hsv2rgb","rgb2hsv"]
elmat = ["zeros","ones","eye","repmat","rand","randn","linspace","logspace",
"freqspace","meshgrid","accumarray","size","length","ndims","numel",
"disp","isempty","isequal","isequalwithequalnans","cat","reshape",
"diag","blkdiag","tril","triu","fliplr","flipud","flipdim","rot90",
"find","end","sub2ind","ind2sub","bsxfun","ndgrid","permute",
"ipermute","shiftdim","circshift","squeeze","isscalar","isvector",
"ans","eps","realmax","realmin","pi","i","inf","nan","isnan",
"isinf","isfinite","j","why","compan","gallery","hadamard","hankel",
"hilb","invhilb","magic","pascal","rosser","toeplitz","vander",
"wilkinson"]
tokens = {
'root': [
# line starting with '!' is sent as a system command. not sure what
# label to use...
(r'^!.*', String.Other),
(r'%\{\s*\n', Comment.Multiline, 'blockcomment'),
(r'%.*$', Comment),
(r'^\s*function', Keyword, 'deffunc'),
# from 'iskeyword' on version 7.11 (R2010):
(r'(break|case|catch|classdef|continue|else|elseif|end|enumerated|'
r'events|for|function|global|if|methods|otherwise|parfor|'
r'persistent|properties|return|spmd|switch|try|while)\b', Keyword),
("(" + "|".join(elfun+specfun+elmat) + r')\b', Name.Builtin),
# line continuation with following comment:
(r'\.\.\..*$', Comment),
# operators:
(r'-|==|~=|<|>|<=|>=|&&|&|~|\|\|?', Operator),
# operators requiring escape for re:
(r'\.\*|\*|\+|\.\^|\.\\|\.\/|\/|\\', Operator),
# punctuation:
(r'\[|\]|\(|\)|\{|\}|:|@|\.|,', Punctuation),
(r'=|:|;', Punctuation),
# quote can be transpose, instead of string:
# (not great, but handles common cases...)
(r'(?<=[\w\)\]])\'', Operator),
(r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float),
(r'\d+[eEf][+-]?[0-9]+', Number.Float),
(r'\d+', Number.Integer),
(r'(?<![\w\)\]])\'', String, 'string'),
('[a-zA-Z_][a-zA-Z0-9_]*', Name),
(r'.', Text),
],
'string': [
(r'[^\']*\'', String, '#pop')
],
'blockcomment': [
(r'^\s*%\}', Comment.Multiline, '#pop'),
(r'^.*\n', Comment.Multiline),
(r'.', Comment.Multiline),
],
'deffunc': [
(r'(\s*)(?:(.+)(\s*)(=)(\s*))?(.+)(\()(.*)(\))(\s*)',
bygroups(Text.Whitespace, Text, Text.Whitespace, Punctuation,
Text.Whitespace, Name.Function, Punctuation, Text,
Punctuation, Text.Whitespace), '#pop'),
],
}
def analyse_text(text):
if re.match('^\s*%', text, re.M): # comment
return 0.9
elif re.match('^!\w+', text, re.M): # system cmd
return 0.9
return 0.1
line_re = re.compile('.*?\n')
class MatlabSessionLexer(Lexer):
"""
For Matlab sessions. Modeled after PythonConsoleLexer.
Contributed by Ken Schutte <kschutte@csail.mit.edu>.
*New in Pygments 0.10.*
"""
name = 'Matlab session'
aliases = ['matlabsession']
def get_tokens_unprocessed(self, text):
mlexer = MatlabLexer(**self.options)
curcode = ''
insertions = []
for match in line_re.finditer(text):
line = match.group()
if line.startswith('>>'):
insertions.append((len(curcode),
[(0, Generic.Prompt, line[:3])]))
curcode += line[3:]
elif line.startswith('???'):
idx = len(curcode)
# without is showing error on same line as before...?
line = "\n" + line
token = (0, Generic.Traceback, line)
insertions.append((idx, [token]))
else:
if curcode:
for item in do_insertions(
insertions, mlexer.get_tokens_unprocessed(curcode)):
yield item
curcode = ''
insertions = []
yield match.start(), Generic.Output, line
if curcode: # or item:
for item in do_insertions(
insertions, mlexer.get_tokens_unprocessed(curcode)):
yield item
class OctaveLexer(RegexLexer):
"""
For GNU Octave source code.
*New in Pygments 1.5.*
"""
name = 'Octave'
aliases = ['octave']
filenames = ['*.m']
mimetypes = ['text/octave']
# These lists are generated automatically.
# Run the following in bash shell:
#
# First dump all of the Octave manual into a plain text file:
#
# $ info octave --subnodes -o octave-manual
#
# Now grep through it:
# for i in \
# "Built-in Function" "Command" "Function File" \
# "Loadable Function" "Mapping Function";
# do
# perl -e '@name = qw('"$i"');
# print lc($name[0]),"_kw = [\n"';
#
# perl -n -e 'print "\"$1\",\n" if /-- '"$i"': .* (\w*) \(/;' \
# octave-manual | sort | uniq ;
# echo "]" ;
# echo;
# done
# taken from Octave Mercurial changeset 8cc154f45e37 (30-jan-2011)
builtin_kw = [ "addlistener", "addpath", "addproperty", "all",
"and", "any", "argnames", "argv", "assignin",
"atexit", "autoload",
"available_graphics_toolkits", "beep_on_error",
"bitand", "bitmax", "bitor", "bitshift", "bitxor",
"cat", "cell", "cellstr", "char", "class", "clc",
"columns", "command_line_path",
"completion_append_char", "completion_matches",
"complex", "confirm_recursive_rmdir", "cputime",
"crash_dumps_octave_core", "ctranspose", "cumprod",
"cumsum", "debug_on_error", "debug_on_interrupt",
"debug_on_warning", "default_save_options",
"dellistener", "diag", "diff", "disp",
"doc_cache_file", "do_string_escapes", "double",
"drawnow", "e", "echo_executing_commands", "eps",
"eq", "errno", "errno_list", "error", "eval",
"evalin", "exec", "exist", "exit", "eye", "false",
"fclear", "fclose", "fcntl", "fdisp", "feof",
"ferror", "feval", "fflush", "fgetl", "fgets",
"fieldnames", "file_in_loadpath", "file_in_path",
"filemarker", "filesep", "find_dir_in_path",
"fixed_point_format", "fnmatch", "fopen", "fork",
"formula", "fprintf", "fputs", "fread", "freport",
"frewind", "fscanf", "fseek", "fskipl", "ftell",
"functions", "fwrite", "ge", "genpath", "get",
"getegid", "getenv", "geteuid", "getgid",
"getpgrp", "getpid", "getppid", "getuid", "glob",
"gt", "gui_mode", "history_control",
"history_file", "history_size",
"history_timestamp_format_string", "home",
"horzcat", "hypot", "ifelse",
"ignore_function_time_stamp", "inferiorto",
"info_file", "info_program", "inline", "input",
"intmax", "intmin", "ipermute",
"is_absolute_filename", "isargout", "isbool",
"iscell", "iscellstr", "ischar", "iscomplex",
"isempty", "isfield", "isfloat", "isglobal",
"ishandle", "isieee", "isindex", "isinteger",
"islogical", "ismatrix", "ismethod", "isnull",
"isnumeric", "isobject", "isreal",
"is_rooted_relative_filename", "issorted",
"isstruct", "isvarname", "kbhit", "keyboard",
"kill", "lasterr", "lasterror", "lastwarn",
"ldivide", "le", "length", "link", "linspace",
"logical", "lstat", "lt", "make_absolute_filename",
"makeinfo_program", "max_recursion_depth", "merge",
"methods", "mfilename", "minus", "mislocked",
"mkdir", "mkfifo", "mkstemp", "mldivide", "mlock",
"mouse_wheel_zoom", "mpower", "mrdivide", "mtimes",
"munlock", "nargin", "nargout",
"native_float_format", "ndims", "ne", "nfields",
"nnz", "norm", "not", "numel", "nzmax",
"octave_config_info", "octave_core_file_limit",
"octave_core_file_name",
"octave_core_file_options", "ones", "or",
"output_max_field_width", "output_precision",
"page_output_immediately", "page_screen_output",
"path", "pathsep", "pause", "pclose", "permute",
"pi", "pipe", "plus", "popen", "power",
"print_empty_dimensions", "printf",
"print_struct_array_contents", "prod",
"program_invocation_name", "program_name",
"putenv", "puts", "pwd", "quit", "rats", "rdivide",
"readdir", "readlink", "read_readline_init_file",
"realmax", "realmin", "rehash", "rename",
"repelems", "re_read_readline_init_file", "reset",
"reshape", "resize", "restoredefaultpath",
"rethrow", "rmdir", "rmfield", "rmpath", "rows",
"save_header_format_string", "save_precision",
"saving_history", "scanf", "set", "setenv",
"shell_cmd", "sighup_dumps_octave_core",
"sigterm_dumps_octave_core", "silent_functions",
"single", "size", "size_equal", "sizemax",
"sizeof", "sleep", "source", "sparse_auto_mutate",
"split_long_rows", "sprintf", "squeeze", "sscanf",
"stat", "stderr", "stdin", "stdout", "strcmp",
"strcmpi", "string_fill_char", "strncmp",
"strncmpi", "struct", "struct_levels_to_print",
"strvcat", "subsasgn", "subsref", "sum", "sumsq",
"superiorto", "suppress_verbose_help_message",
"symlink", "system", "tic", "tilde_expand",
"times", "tmpfile", "tmpnam", "toc", "toupper",
"transpose", "true", "typeinfo", "umask", "uminus",
"uname", "undo_string_escapes", "unlink", "uplus",
"upper", "usage", "usleep", "vec", "vectorize",
"vertcat", "waitpid", "warning", "warranty",
"whos_line_format", "yes_or_no", "zeros",
"inf", "Inf", "nan", "NaN"]
command_kw = [ "close", "load", "who", "whos", ]
function_kw = [ "accumarray", "accumdim", "acosd", "acotd",
"acscd", "addtodate", "allchild", "ancestor",
"anova", "arch_fit", "arch_rnd", "arch_test",
"area", "arma_rnd", "arrayfun", "ascii", "asctime",
"asecd", "asind", "assert", "atand",
"autoreg_matrix", "autumn", "axes", "axis", "bar",
"barh", "bartlett", "bartlett_test", "beep",
"betacdf", "betainv", "betapdf", "betarnd",
"bicgstab", "bicubic", "binary", "binocdf",
"binoinv", "binopdf", "binornd", "bitcmp",
"bitget", "bitset", "blackman", "blanks",
"blkdiag", "bone", "box", "brighten", "calendar",
"cast", "cauchy_cdf", "cauchy_inv", "cauchy_pdf",
"cauchy_rnd", "caxis", "celldisp", "center", "cgs",
"chisquare_test_homogeneity",
"chisquare_test_independence", "circshift", "cla",
"clabel", "clf", "clock", "cloglog", "closereq",
"colon", "colorbar", "colormap", "colperm",
"comet", "common_size", "commutation_matrix",
"compan", "compare_versions", "compass",
"computer", "cond", "condest", "contour",
"contourc", "contourf", "contrast", "conv",
"convhull", "cool", "copper", "copyfile", "cor",
"corrcoef", "cor_test", "cosd", "cotd", "cov",
"cplxpair", "cross", "cscd", "cstrcat", "csvread",
"csvwrite", "ctime", "cumtrapz", "curl", "cut",
"cylinder", "date", "datenum", "datestr",
"datetick", "datevec", "dblquad", "deal",
"deblank", "deconv", "delaunay", "delaunayn",
"delete", "demo", "detrend", "diffpara", "diffuse",
"dir", "discrete_cdf", "discrete_inv",
"discrete_pdf", "discrete_rnd", "display",
"divergence", "dlmwrite", "dos", "dsearch",
"dsearchn", "duplication_matrix", "durbinlevinson",
"ellipsoid", "empirical_cdf", "empirical_inv",
"empirical_pdf", "empirical_rnd", "eomday",
"errorbar", "etime", "etreeplot", "example",
"expcdf", "expinv", "expm", "exppdf", "exprnd",
"ezcontour", "ezcontourf", "ezmesh", "ezmeshc",
"ezplot", "ezpolar", "ezsurf", "ezsurfc", "factor",
"factorial", "fail", "fcdf", "feather", "fftconv",
"fftfilt", "fftshift", "figure", "fileattrib",
"fileparts", "fill", "findall", "findobj",
"findstr", "finv", "flag", "flipdim", "fliplr",
"flipud", "fpdf", "fplot", "fractdiff", "freqz",
"freqz_plot", "frnd", "fsolve",
"f_test_regression", "ftp", "fullfile", "fzero",
"gamcdf", "gaminv", "gampdf", "gamrnd", "gca",
"gcbf", "gcbo", "gcf", "genvarname", "geocdf",
"geoinv", "geopdf", "geornd", "getfield", "ginput",
"glpk", "gls", "gplot", "gradient",
"graphics_toolkit", "gray", "grid", "griddata",
"griddatan", "gtext", "gunzip", "gzip", "hadamard",
"hamming", "hankel", "hanning", "hggroup",
"hidden", "hilb", "hist", "histc", "hold", "hot",
"hotelling_test", "housh", "hsv", "hurst",
"hygecdf", "hygeinv", "hygepdf", "hygernd",
"idivide", "ifftshift", "image", "imagesc",
"imfinfo", "imread", "imshow", "imwrite", "index",
"info", "inpolygon", "inputname", "interpft",
"interpn", "intersect", "invhilb", "iqr", "isa",
"isdefinite", "isdir", "is_duplicate_entry",
"isequal", "isequalwithequalnans", "isfigure",
"ishermitian", "ishghandle", "is_leap_year",
"isletter", "ismac", "ismember", "ispc", "isprime",
"isprop", "isscalar", "issquare", "isstrprop",
"issymmetric", "isunix", "is_valid_file_id",
"isvector", "jet", "kendall",
"kolmogorov_smirnov_cdf",
"kolmogorov_smirnov_test", "kruskal_wallis_test",
"krylov", "kurtosis", "laplace_cdf", "laplace_inv",
"laplace_pdf", "laplace_rnd", "legend", "legendre",
"license", "line", "linkprop", "list_primes",
"loadaudio", "loadobj", "logistic_cdf",
"logistic_inv", "logistic_pdf", "logistic_rnd",
"logit", "loglog", "loglogerr", "logm", "logncdf",
"logninv", "lognpdf", "lognrnd", "logspace",
"lookfor", "ls_command", "lsqnonneg", "magic",
"mahalanobis", "manova", "matlabroot",
"mcnemar_test", "mean", "meansq", "median", "menu",
"mesh", "meshc", "meshgrid", "meshz", "mexext",
"mget", "mkpp", "mode", "moment", "movefile",
"mpoles", "mput", "namelengthmax", "nargchk",
"nargoutchk", "nbincdf", "nbininv", "nbinpdf",
"nbinrnd", "nchoosek", "ndgrid", "newplot", "news",
"nonzeros", "normcdf", "normest", "norminv",
"normpdf", "normrnd", "now", "nthroot", "null",
"ocean", "ols", "onenormest", "optimget",
"optimset", "orderfields", "orient", "orth",
"pack", "pareto", "parseparams", "pascal", "patch",
"pathdef", "pcg", "pchip", "pcolor", "pcr",
"peaks", "periodogram", "perl", "perms", "pie",
"pink", "planerot", "playaudio", "plot",
"plotmatrix", "plotyy", "poisscdf", "poissinv",
"poisspdf", "poissrnd", "polar", "poly",
"polyaffine", "polyarea", "polyderiv", "polyfit",
"polygcd", "polyint", "polyout", "polyreduce",
"polyval", "polyvalm", "postpad", "powerset",
"ppder", "ppint", "ppjumps", "ppplot", "ppval",
"pqpnonneg", "prepad", "primes", "print",
"print_usage", "prism", "probit", "qp", "qqplot",
"quadcc", "quadgk", "quadl", "quadv", "quiver",
"qzhess", "rainbow", "randi", "range", "rank",
"ranks", "rat", "reallog", "realpow", "realsqrt",
"record", "rectangle_lw", "rectangle_sw",
"rectint", "refresh", "refreshdata",
"regexptranslate", "repmat", "residue", "ribbon",
"rindex", "roots", "rose", "rosser", "rotdim",
"rref", "run", "run_count", "rundemos", "run_test",
"runtests", "saveas", "saveaudio", "saveobj",
"savepath", "scatter", "secd", "semilogx",
"semilogxerr", "semilogy", "semilogyerr",
"setaudio", "setdiff", "setfield", "setxor",
"shading", "shift", "shiftdim", "sign_test",
"sinc", "sind", "sinetone", "sinewave", "skewness",
"slice", "sombrero", "sortrows", "spaugment",
"spconvert", "spdiags", "spearman", "spectral_adf",
"spectral_xdf", "specular", "speed", "spencer",
"speye", "spfun", "sphere", "spinmap", "spline",
"spones", "sprand", "sprandn", "sprandsym",
"spring", "spstats", "spy", "sqp", "stairs",
"statistics", "std", "stdnormal_cdf",
"stdnormal_inv", "stdnormal_pdf", "stdnormal_rnd",
"stem", "stft", "strcat", "strchr", "strjust",
"strmatch", "strread", "strsplit", "strtok",
"strtrim", "strtrunc", "structfun", "studentize",
"subplot", "subsindex", "subspace", "substr",
"substruct", "summer", "surf", "surface", "surfc",
"surfl", "surfnorm", "svds", "swapbytes",
"sylvester_matrix", "symvar", "synthesis", "table",
"tand", "tar", "tcdf", "tempdir", "tempname",
"test", "text", "textread", "textscan", "tinv",
"title", "toeplitz", "tpdf", "trace", "trapz",
"treelayout", "treeplot", "triangle_lw",
"triangle_sw", "tril", "trimesh", "triplequad",
"triplot", "trisurf", "triu", "trnd", "tsearchn",
"t_test", "t_test_regression", "type", "unidcdf",
"unidinv", "unidpdf", "unidrnd", "unifcdf",
"unifinv", "unifpdf", "unifrnd", "union", "unique",
"unix", "unmkpp", "unpack", "untabify", "untar",
"unwrap", "unzip", "u_test", "validatestring",
"vander", "var", "var_test", "vech", "ver",
"version", "view", "voronoi", "voronoin",
"waitforbuttonpress", "wavread", "wavwrite",
"wblcdf", "wblinv", "wblpdf", "wblrnd", "weekday",
"welch_test", "what", "white", "whitebg",
"wienrnd", "wilcoxon_test", "wilkinson", "winter",
"xlabel", "xlim", "ylabel", "yulewalker", "zip",
"zlabel", "z_test", ]
loadable_kw = [ "airy", "amd", "balance", "besselh", "besseli",
"besselj", "besselk", "bessely", "bitpack",
"bsxfun", "builtin", "ccolamd", "cellfun",
"cellslices", "chol", "choldelete", "cholinsert",
"cholinv", "cholshift", "cholupdate", "colamd",
"colloc", "convhulln", "convn", "csymamd",
"cummax", "cummin", "daspk", "daspk_options",
"dasrt", "dasrt_options", "dassl", "dassl_options",
"dbclear", "dbdown", "dbstack", "dbstatus",
"dbstop", "dbtype", "dbup", "dbwhere", "det",
"dlmread", "dmperm", "dot", "eig", "eigs",
"endgrent", "endpwent", "etree", "fft", "fftn",
"fftw", "filter", "find", "full", "gcd",
"getgrent", "getgrgid", "getgrnam", "getpwent",
"getpwnam", "getpwuid", "getrusage", "givens",
"gmtime", "gnuplot_binary", "hess", "ifft",
"ifftn", "inv", "isdebugmode", "issparse", "kron",
"localtime", "lookup", "lsode", "lsode_options",
"lu", "luinc", "luupdate", "matrix_type", "max",
"min", "mktime", "pinv", "qr", "qrdelete",
"qrinsert", "qrshift", "qrupdate", "quad",
"quad_options", "qz", "rand", "rande", "randg",
"randn", "randp", "randperm", "rcond", "regexp",
"regexpi", "regexprep", "schur", "setgrent",
"setpwent", "sort", "spalloc", "sparse", "spparms",
"sprank", "sqrtm", "strfind", "strftime",
"strptime", "strrep", "svd", "svd_driver", "syl",
"symamd", "symbfact", "symrcm", "time", "tsearch",
"typecast", "urlread", "urlwrite", ]
mapping_kw = [ "abs", "acos", "acosh", "acot", "acoth", "acsc",
"acsch", "angle", "arg", "asec", "asech", "asin",
"asinh", "atan", "atanh", "beta", "betainc",
"betaln", "bincoeff", "cbrt", "ceil", "conj", "cos",
"cosh", "cot", "coth", "csc", "csch", "erf", "erfc",
"erfcx", "erfinv", "exp", "finite", "fix", "floor",
"fmod", "gamma", "gammainc", "gammaln", "imag",
"isalnum", "isalpha", "isascii", "iscntrl",
"isdigit", "isfinite", "isgraph", "isinf",
"islower", "isna", "isnan", "isprint", "ispunct",
"isspace", "isupper", "isxdigit", "lcm", "lgamma",
"log", "lower", "mod", "real", "rem", "round",
"roundb", "sec", "sech", "sign", "sin", "sinh",
"sqrt", "tan", "tanh", "toascii", "tolower", "xor",
]
builtin_consts = [ "EDITOR", "EXEC_PATH", "I", "IMAGE_PATH", "NA",
"OCTAVE_HOME", "OCTAVE_VERSION", "PAGER",
"PAGER_FLAGS", "SEEK_CUR", "SEEK_END", "SEEK_SET",
"SIG", "S_ISBLK", "S_ISCHR", "S_ISDIR", "S_ISFIFO",
"S_ISLNK", "S_ISREG", "S_ISSOCK", "WCONTINUE",
"WCOREDUMP", "WEXITSTATUS", "WIFCONTINUED",
"WIFEXITED", "WIFSIGNALED", "WIFSTOPPED", "WNOHANG",
"WSTOPSIG", "WTERMSIG", "WUNTRACED", ]
tokens = {
'root': [
#We should look into multiline comments
(r'[%#].*$', Comment),
(r'^\s*function', Keyword, 'deffunc'),
# from 'iskeyword' on hg changeset 8cc154f45e37
(r'(__FILE__|__LINE__|break|case|catch|classdef|continue|do|else|'
r'elseif|end|end_try_catch|end_unwind_protect|endclassdef|'
r'endevents|endfor|endfunction|endif|endmethods|endproperties|'
r'endswitch|endwhile|events|for|function|get|global|if|methods|'
r'otherwise|persistent|properties|return|set|static|switch|try|'
r'until|unwind_protect|unwind_protect_cleanup|while)\b', Keyword),
("(" + "|".join( builtin_kw + command_kw
+ function_kw + loadable_kw
+ mapping_kw) + r')\b', Name.Builtin),
("(" + "|".join(builtin_consts) + r')\b', Name.Constant),
# operators in Octave but not Matlab:
(r'-=|!=|!|/=|--', Operator),
# operators:
(r'-|==|~=|<|>|<=|>=|&&|&|~|\|\|?', Operator),
# operators in Octave but not Matlab requiring escape for re:
(r'\*=|\+=|\^=|\/=|\\=|\*\*|\+\+|\.\*\*',Operator),
# operators requiring escape for re:
(r'\.\*|\*|\+|\.\^|\.\\|\.\/|\/|\\', Operator),
# punctuation:
(r'\[|\]|\(|\)|\{|\}|:|@|\.|,', Punctuation),
(r'=|:|;', Punctuation),
(r'"[^"]*"', String),
(r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float),
(r'\d+[eEf][+-]?[0-9]+', Number.Float),
(r'\d+', Number.Integer),
# quote can be transpose, instead of string:
# (not great, but handles common cases...)
(r'(?<=[\w\)\]])\'', Operator),
(r'(?<![\w\)\]])\'', String, 'string'),
('[a-zA-Z_][a-zA-Z0-9_]*', Name),
(r'.', Text),
],
'string': [
(r"[^']*'", String, '#pop'),
],
'deffunc': [
(r'(\s*)(?:(.+)(\s*)(=)(\s*))?(.+)(\()(.*)(\))(\s*)',
bygroups(Text.Whitespace, Text, Text.Whitespace, Punctuation,
Text.Whitespace, Name.Function, Punctuation, Text,
Punctuation, Text.Whitespace), '#pop'),
],
}
def analyse_text(text):
if re.match('^\s*[%#]', text, re.M): #Comment
return 0.1
class ScilabLexer(RegexLexer):
"""
For Scilab source code.
*New in Pygments 1.5.*
"""
name = 'Scilab'
aliases = ['scilab']
filenames = ['*.sci', '*.sce', '*.tst']
mimetypes = ['text/scilab']
tokens = {
'root': [
(r'//.*?$', Comment.Single),
(r'^\s*function', Keyword, 'deffunc'),
(r'(__FILE__|__LINE__|break|case|catch|classdef|continue|do|else|'
r'elseif|end|end_try_catch|end_unwind_protect|endclassdef|'
r'endevents|endfor|endfunction|endif|endmethods|endproperties|'
r'endswitch|endwhile|events|for|function|get|global|if|methods|'
r'otherwise|persistent|properties|return|set|static|switch|try|'
r'until|unwind_protect|unwind_protect_cleanup|while)\b', Keyword),
("(" + "|".join(_scilab_builtins.functions_kw +
_scilab_builtins.commands_kw +
_scilab_builtins.macros_kw
) + r')\b', Name.Builtin),
(r'(%s)\b' % "|".join(map(re.escape, _scilab_builtins.builtin_consts)),
Name.Constant),
# operators:
(r'-|==|~=|<|>|<=|>=|&&|&|~|\|\|?', Operator),
# operators requiring escape for re:
(r'\.\*|\*|\+|\.\^|\.\\|\.\/|\/|\\', Operator),
# punctuation:
(r'[\[\](){}@.,=:;]', Punctuation),
(r'"[^"]*"', String),
# quote can be transpose, instead of string:
# (not great, but handles common cases...)
(r'(?<=[\w\)\]])\'', Operator),
(r'(?<![\w\)\]])\'', String, 'string'),
(r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float),
(r'\d+[eEf][+-]?[0-9]+', Number.Float),
(r'\d+', Number.Integer),
('[a-zA-Z_][a-zA-Z0-9_]*', Name),
(r'.', Text),
],
'string': [
(r"[^']*'", String, '#pop'),
(r'.', String, '#pop'),
],
'deffunc': [
(r'(\s*)(?:(.+)(\s*)(=)(\s*))?(.+)(\()(.*)(\))(\s*)',
bygroups(Text.Whitespace, Text, Text.Whitespace, Punctuation,
Text.Whitespace, Name.Function, Punctuation, Text,
Punctuation, Text.Whitespace), '#pop'),
],
}
class NumPyLexer(PythonLexer):
"""
A Python lexer recognizing Numerical Python builtins.
*New in Pygments 0.10.*
"""
name = 'NumPy'
aliases = ['numpy']
# override the mimetypes to not inherit them from python
mimetypes = []
filenames = []
EXTRA_KEYWORDS = set([
'abs', 'absolute', 'accumulate', 'add', 'alen', 'all', 'allclose',
'alltrue', 'alterdot', 'amax', 'amin', 'angle', 'any', 'append',
'apply_along_axis', 'apply_over_axes', 'arange', 'arccos', 'arccosh',
'arcsin', 'arcsinh', 'arctan', 'arctan2', 'arctanh', 'argmax', 'argmin',
'argsort', 'argwhere', 'around', 'array', 'array2string', 'array_equal',
'array_equiv', 'array_repr', 'array_split', 'array_str', 'arrayrange',
'asanyarray', 'asarray', 'asarray_chkfinite', 'ascontiguousarray',
'asfarray', 'asfortranarray', 'asmatrix', 'asscalar', 'astype',
'atleast_1d', 'atleast_2d', 'atleast_3d', 'average', 'bartlett',
'base_repr', 'beta', 'binary_repr', 'bincount', 'binomial',
'bitwise_and', 'bitwise_not', 'bitwise_or', 'bitwise_xor', 'blackman',
'bmat', 'broadcast', 'byte_bounds', 'bytes', 'byteswap', 'c_',
'can_cast', 'ceil', 'choose', 'clip', 'column_stack', 'common_type',
'compare_chararrays', 'compress', 'concatenate', 'conj', 'conjugate',
'convolve', 'copy', 'corrcoef', 'correlate', 'cos', 'cosh', 'cov',
'cross', 'cumprod', 'cumproduct', 'cumsum', 'delete', 'deprecate',
'diag', 'diagflat', 'diagonal', 'diff', 'digitize', 'disp', 'divide',
'dot', 'dsplit', 'dstack', 'dtype', 'dump', 'dumps', 'ediff1d', 'empty',
'empty_like', 'equal', 'exp', 'expand_dims', 'expm1', 'extract', 'eye',
'fabs', 'fastCopyAndTranspose', 'fft', 'fftfreq', 'fftshift', 'fill',
'finfo', 'fix', 'flat', 'flatnonzero', 'flatten', 'fliplr', 'flipud',
'floor', 'floor_divide', 'fmod', 'frexp', 'fromarrays', 'frombuffer',
'fromfile', 'fromfunction', 'fromiter', 'frompyfunc', 'fromstring',
'generic', 'get_array_wrap', 'get_include', 'get_numarray_include',
'get_numpy_include', 'get_printoptions', 'getbuffer', 'getbufsize',
'geterr', 'geterrcall', 'geterrobj', 'getfield', 'gradient', 'greater',
'greater_equal', 'gumbel', 'hamming', 'hanning', 'histogram',
'histogram2d', 'histogramdd', 'hsplit', 'hstack', 'hypot', 'i0',
'identity', 'ifft', 'imag', 'index_exp', 'indices', 'inf', 'info',
'inner', 'insert', 'int_asbuffer', 'interp', 'intersect1d',
'intersect1d_nu', 'inv', 'invert', 'iscomplex', 'iscomplexobj',
'isfinite', 'isfortran', 'isinf', 'isnan', 'isneginf', 'isposinf',
'isreal', 'isrealobj', 'isscalar', 'issctype', 'issubclass_',
'issubdtype', 'issubsctype', 'item', 'itemset', 'iterable', 'ix_',
'kaiser', 'kron', 'ldexp', 'left_shift', 'less', 'less_equal', 'lexsort',
'linspace', 'load', 'loads', 'loadtxt', 'log', 'log10', 'log1p', 'log2',
'logical_and', 'logical_not', 'logical_or', 'logical_xor', 'logspace',
'lstsq', 'mat', 'matrix', 'max', 'maximum', 'maximum_sctype',
'may_share_memory', 'mean', 'median', 'meshgrid', 'mgrid', 'min',
'minimum', 'mintypecode', 'mod', 'modf', 'msort', 'multiply', 'nan',
'nan_to_num', 'nanargmax', 'nanargmin', 'nanmax', 'nanmin', 'nansum',
'ndenumerate', 'ndim', 'ndindex', 'negative', 'newaxis', 'newbuffer',
'newbyteorder', 'nonzero', 'not_equal', 'obj2sctype', 'ogrid', 'ones',
'ones_like', 'outer', 'permutation', 'piecewise', 'pinv', 'pkgload',
'place', 'poisson', 'poly', 'poly1d', 'polyadd', 'polyder', 'polydiv',
'polyfit', 'polyint', 'polymul', 'polysub', 'polyval', 'power', 'prod',
'product', 'ptp', 'put', 'putmask', 'r_', 'randint', 'random_integers',
'random_sample', 'ranf', 'rank', 'ravel', 'real', 'real_if_close',
'recarray', 'reciprocal', 'reduce', 'remainder', 'repeat', 'require',
'reshape', 'resize', 'restoredot', 'right_shift', 'rint', 'roll',
'rollaxis', 'roots', 'rot90', 'round', 'round_', 'row_stack', 's_',
'sample', 'savetxt', 'sctype2char', 'searchsorted', 'seed', 'select',
'set_numeric_ops', 'set_printoptions', 'set_string_function',
'setbufsize', 'setdiff1d', 'seterr', 'seterrcall', 'seterrobj',
'setfield', 'setflags', 'setmember1d', 'setxor1d', 'shape',
'show_config', 'shuffle', 'sign', 'signbit', 'sin', 'sinc', 'sinh',
'size', 'slice', 'solve', 'sometrue', 'sort', 'sort_complex', 'source',
'split', 'sqrt', 'square', 'squeeze', 'standard_normal', 'std',
'subtract', 'sum', 'svd', 'swapaxes', 'take', 'tan', 'tanh', 'tensordot',
'test', 'tile', 'tofile', 'tolist', 'tostring', 'trace', 'transpose',
'trapz', 'tri', 'tril', 'trim_zeros', 'triu', 'true_divide', 'typeDict',
'typename', 'uniform', 'union1d', 'unique', 'unique1d', 'unravel_index',
'unwrap', 'vander', 'var', 'vdot', 'vectorize', 'view', 'vonmises',
'vsplit', 'vstack', 'weibull', 'where', 'who', 'zeros', 'zeros_like'
])
def get_tokens_unprocessed(self, text):
for index, token, value in \
PythonLexer.get_tokens_unprocessed(self, text):
if token is Name and value in self.EXTRA_KEYWORDS:
yield index, Keyword.Pseudo, value
else:
yield index, token, value
def analyse_text(text):
return (shebang_matches(text, r'pythonw?(2(\.\d)?)?') or
'import ' in text[:1000]) \
and ('import numpy' in text or 'from numpy import' in text)
class RConsoleLexer(Lexer):
"""
For R console transcripts or R CMD BATCH output files.
"""
name = 'RConsole'
aliases = ['rconsole', 'rout']
filenames = ['*.Rout']
def get_tokens_unprocessed(self, text):
slexer = SLexer(**self.options)
current_code_block = ''
insertions = []
for match in line_re.finditer(text):
line = match.group()
if line.startswith('>') or line.startswith('+'):
# Colorize the prompt as such,
# then put rest of line into current_code_block
insertions.append((len(current_code_block),
[(0, Generic.Prompt, line[:2])]))
current_code_block += line[2:]
else:
# We have reached a non-prompt line!
# If we have stored prompt lines, need to process them first.
if current_code_block:
# Weave together the prompts and highlight code.
for item in do_insertions(insertions,
slexer.get_tokens_unprocessed(current_code_block)):
yield item
# Reset vars for next code block.
current_code_block = ''
insertions = []
# Now process the actual line itself, this is output from R.
yield match.start(), Generic.Output, line
# If we happen to end on a code block with nothing after it, need to
# process the last code block. This is neither elegant nor DRY so
# should be changed.
if current_code_block:
for item in do_insertions(insertions,
slexer.get_tokens_unprocessed(current_code_block)):
yield item
class SLexer(RegexLexer):
"""
For S, S-plus, and R source code.
*New in Pygments 0.10.*
"""
name = 'S'
aliases = ['splus', 's', 'r']
filenames = ['*.S', '*.R', '.Rhistory', '.Rprofile']
mimetypes = ['text/S-plus', 'text/S', 'text/x-r-source', 'text/x-r',
'text/x-R', 'text/x-r-history', 'text/x-r-profile']
tokens = {
'comments': [
(r'#.*$', Comment.Single),
],
'valid_name': [
(r'[a-zA-Z][0-9a-zA-Z\._]*', Text),
# can begin with ., but not if that is followed by a digit
(r'\.[a-zA-Z_][0-9a-zA-Z\._]*', Text),
],
'punctuation': [
(r'\[{1,2}|\]{1,2}|\(|\)|;|,', Punctuation),
],
'keywords': [
(r'(if|else|for|while|repeat|in|next|break|return|switch|function)'
r'(?![0-9a-zA-Z\._])',
Keyword.Reserved)
],
'operators': [
(r'<<?-|->>?|-|==|<=|>=|<|>|&&?|!=|\|\|?|\?', Operator),
(r'\*|\+|\^|/|!|%[^%]*%|=|~|\$|@|:{1,3}', Operator)
],
'builtin_symbols': [
(r'(NULL|NA(_(integer|real|complex|character)_)?|'
r'Inf|TRUE|FALSE|NaN|\.\.(\.|[0-9]+))'
r'(?![0-9a-zA-Z\._])',
Keyword.Constant),
(r'(T|F)\b', Keyword.Variable),
],
'numbers': [
# hex number
(r'0[xX][a-fA-F0-9]+([pP][0-9]+)?[Li]?', Number.Hex),
# decimal number
(r'[+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?[Li]?',
Number),
],
'statements': [
include('comments'),
# whitespaces
(r'\s+', Text),
(r'`.*?`', String.Backtick),
(r'\'', String, 'string_squote'),
(r'\"', String, 'string_dquote'),
include('builtin_symbols'),
include('numbers'),
include('keywords'),
include('punctuation'),
include('operators'),
include('valid_name'),
],
'root': [
include('statements'),
# blocks:
(r'\{|\}', Punctuation),
#(r'\{', Punctuation, 'block'),
(r'.', Text),
],
#'block': [
# include('statements'),
# ('\{', Punctuation, '#push'),
# ('\}', Punctuation, '#pop')
#],
'string_squote': [
(r'([^\'\\]|\\.)*\'', String, '#pop'),
],
'string_dquote': [
(r'([^"\\]|\\.)*"', String, '#pop'),
],
}
def analyse_text(text):
if re.search(r'[a-z0-9_\])\s]<-(?!-)', text):
return 0.11
class BugsLexer(RegexLexer):
"""
Pygments Lexer for `OpenBugs <http://www.openbugs.info/w/>`_ and WinBugs
models.
*New in Pygments 1.6.*
"""
name = 'BUGS'
aliases = ['bugs', 'winbugs', 'openbugs']
filenames = ['*.bug']
_FUNCTIONS = [
# Scalar functions
'abs', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctanh',
'cloglog', 'cos', 'cosh', 'cumulative', 'cut', 'density', 'deviance',
'equals', 'expr', 'gammap', 'ilogit', 'icloglog', 'integral', 'log',
'logfact', 'loggam', 'logit', 'max', 'min', 'phi', 'post.p.value',
'pow', 'prior.p.value', 'probit', 'replicate.post', 'replicate.prior',
'round', 'sin', 'sinh', 'solution', 'sqrt', 'step', 'tan', 'tanh',
'trunc',
# Vector functions
'inprod', 'interp.lin', 'inverse', 'logdet', 'mean', 'eigen.vals',
'ode', 'prod', 'p.valueM', 'rank', 'ranked', 'replicate.postM',
'sd', 'sort', 'sum',
## Special
'D', 'I', 'F', 'T', 'C']
""" OpenBUGS built-in functions
From http://www.openbugs.info/Manuals/ModelSpecification.html#ContentsAII
This also includes
- T, C, I : Truncation and censoring.
``T`` and ``C`` are in OpenBUGS. ``I`` in WinBUGS.
- D : ODE
- F : Functional http://www.openbugs.info/Examples/Functionals.html
"""
_DISTRIBUTIONS = ['dbern', 'dbin', 'dcat', 'dnegbin', 'dpois',
'dhyper', 'dbeta', 'dchisqr', 'ddexp', 'dexp',
'dflat', 'dgamma', 'dgev', 'df', 'dggamma', 'dgpar',
'dloglik', 'dlnorm', 'dlogis', 'dnorm', 'dpar',
'dt', 'dunif', 'dweib', 'dmulti', 'ddirch', 'dmnorm',
'dmt', 'dwish']
""" OpenBUGS built-in distributions
Functions from
http://www.openbugs.info/Manuals/ModelSpecification.html#ContentsAI
"""
tokens = {
'whitespace' : [
(r"\s+", Text),
],
'comments' : [
# Comments
(r'#.*$', Comment.Single),
],
'root': [
# Comments
include('comments'),
include('whitespace'),
# Block start
(r'(model)(\s+)({)',
bygroups(Keyword.Namespace, Text, Punctuation)),
# Reserved Words
(r'(for|in)(?![0-9a-zA-Z\._])', Keyword.Reserved),
# Built-in Functions
(r'(%s)(?=\s*\()'
% r'|'.join(_FUNCTIONS + _DISTRIBUTIONS),
Name.Builtin),
# Regular variable names
(r'[A-Za-z][A-Za-z0-9_.]*', Name),
# Number Literals
(r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?', Number),
# Punctuation
(r'\[|\]|\(|\)|:|,|;', Punctuation),
# Assignment operators
# SLexer makes these tokens Operators.
(r'<-|~', Operator),
# Infix and prefix operators
(r'\+|-|\*|/', Operator),
# Block
(r'[{}]', Punctuation),
]
}
def analyse_text(text):
if re.search(r"^\s*model\s*{", text, re.M):
return 0.7
else:
return 0.0
class JagsLexer(RegexLexer):
"""
Pygments Lexer for JAGS.
*New in Pygments 1.6.*
"""
name = 'JAGS'
aliases = ['jags']
filenames = ['*.jag', '*.bug']
## JAGS
_FUNCTIONS = [
'abs', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctanh',
'cos', 'cosh', 'cloglog',
'equals', 'exp', 'icloglog', 'ifelse', 'ilogit', 'log', 'logfact',
'loggam', 'logit', 'phi', 'pow', 'probit', 'round', 'sin', 'sinh',
'sqrt', 'step', 'tan', 'tanh', 'trunc', 'inprod', 'interp.lin',
'logdet', 'max', 'mean', 'min', 'prod', 'sum', 'sd', 'inverse',
'rank', 'sort', 't', 'acos', 'acosh', 'asin', 'asinh', 'atan',
# Truncation/Censoring (should I include)
'T', 'I']
# Distributions with density, probability and quartile functions
_DISTRIBUTIONS = ['[dpq]%s' % x for x in
['bern', 'beta', 'dchiqsqr', 'ddexp', 'dexp',
'df', 'gamma', 'gen.gamma', 'logis', 'lnorm',
'negbin', 'nchisqr', 'norm', 'par', 'pois', 'weib']]
# Other distributions without density and probability
_OTHER_DISTRIBUTIONS = [
'dt', 'dunif', 'dbetabin', 'dbern', 'dbin', 'dcat', 'dhyper',
'ddirch', 'dmnorm', 'dwish', 'dmt', 'dmulti', 'dbinom', 'dchisq',
'dnbinom', 'dweibull', 'ddirich']
tokens = {
'whitespace' : [
(r"\s+", Text),
],
'names' : [
# Regular variable names
(r'[a-zA-Z][a-zA-Z0-9_.]*\b', Name),
],
'comments' : [
# do not use stateful comments
(r'(?s)/\*.*?\*/', Comment.Multiline),
# Comments
(r'#.*$', Comment.Single),
],
'root': [
# Comments
include('comments'),
include('whitespace'),
# Block start
(r'(model|data)(\s+)({)',
bygroups(Keyword.Namespace, Text, Punctuation)),
(r'var(?![0-9a-zA-Z\._])', Keyword.Declaration),
# Reserved Words
(r'(for|in)(?![0-9a-zA-Z\._])', Keyword.Reserved),
# Builtins
# Need to use lookahead because . is a valid char
(r'(%s)(?=\s*\()' % r'|'.join(_FUNCTIONS
+ _DISTRIBUTIONS
+ _OTHER_DISTRIBUTIONS),
Name.Builtin),
# Names
include('names'),
# Number Literals
(r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?', Number),
(r'\[|\]|\(|\)|:|,|;', Punctuation),
# Assignment operators
(r'<-|~', Operator),
# # JAGS includes many more than OpenBUGS
(r'\+|-|\*|\/|\|\|[&]{2}|[<>=]=?|\^|%.*?%', Operator),
(r'[{}]', Punctuation),
]
}
def analyse_text(text):
if re.search(r'^\s*model\s*\{', text, re.M):
if re.search(r'^\s*data\s*\{', text, re.M):
return 0.9
elif re.search(r'^\s*var', text, re.M):
return 0.9
else:
return 0.3
else:
return 0
class StanLexer(RegexLexer):
"""Pygments Lexer for Stan models.
The Stan modeling language is specified in the *Stan 1.3.0
Modeling Language Manual* `pdf
<http://code.google.com/p/stan/downloads/detail?name=stan-reference-1.3.0.pdf>`_.
*New in Pygments 1.6.*
"""
name = 'Stan'
aliases = ['stan']
filenames = ['*.stan']
tokens = {
'whitespace' : [
(r"\s+", Text),
],
'comments' : [
(r'(?s)/\*.*?\*/', Comment.Multiline),
# Comments
(r'(//|#).*$', Comment.Single),
],
'root': [
# Stan is more restrictive on strings than this regex
(r'"[^"]*"', String),
# Comments
include('comments'),
# block start
include('whitespace'),
# Block start
(r'(%s)(\s*)({)' %
r'|'.join(('data', r'transformed\s+?data',
'parameters', r'transformed\s+parameters',
'model', r'generated\s+quantities')),
bygroups(Keyword.Namespace, Text, Punctuation)),
# Reserved Words
(r'(%s)\b' % r'|'.join(_stan_builtins.KEYWORDS), Keyword),
# Truncation
(r'T(?=\s*\[)', Keyword),
# Data types
(r'(%s)\b' % r'|'.join(_stan_builtins.TYPES), Keyword.Type),
# Punctuation
(r"[;:,\[\]()]", Punctuation),
# Builtin
(r'(%s)(?=\s*\()'
% r'|'.join(_stan_builtins.FUNCTIONS
+ _stan_builtins.DISTRIBUTIONS),
Name.Builtin),
# Special names ending in __, like lp__
(r'[A-Za-z][A-Za-z0-9_]*__\b', Name.Builtin.Pseudo),
(r'(%s)\b' % r'|'.join(_stan_builtins.RESERVED), Keyword.Reserved),
# Regular variable names
(r'[A-Za-z][A-Za-z0-9_]*\b', Name),
# Real Literals
(r'-?[0-9]+(\.[0-9]+)?[eE]-?[0-9]+', Number.Float),
(r'-?[0-9]*\.[0-9]*', Number.Float),
# Integer Literals
(r'-?[0-9]+', Number.Integer),
# Assignment operators
# SLexer makes these tokens Operators.
(r'<-|~', Operator),
# Infix and prefix operators (and = )
(r"\+|-|\.?\*|\.?/|\\|'|==?|!=?|<=?|>=?|\|\||&&", Operator),
# Block delimiters
(r'[{}]', Punctuation),
]
}
def analyse_text(text):
if re.search(r'^\s*parameters\s*\{', text, re.M):
return 1.0
else:
return 0.0
class IDLLexer(RegexLexer):
"""
Pygments Lexer for IDL (Interactive Data Language).
*New in Pygments 1.6.*
"""
name = 'IDL'
aliases = ['idl']
filenames = ['*.pro']
mimetypes = ['text/idl']
_RESERVED = ['and', 'begin', 'break', 'case', 'common', 'compile_opt',
'continue', 'do', 'else', 'end', 'endcase', 'elseelse',
'endfor', 'endforeach', 'endif', 'endrep', 'endswitch',
'endwhile', 'eq', 'for', 'foreach', 'forward_function',
'function', 'ge', 'goto', 'gt', 'if', 'inherits', 'le',
'lt', 'mod', 'ne', 'not', 'of', 'on_ioerror', 'or', 'pro',
'repeat', 'switch', 'then', 'until', 'while', 'xor']
"""Reserved words from: http://www.exelisvis.com/docs/reswords.html"""
_BUILTIN_LIB = ['abs', 'acos', 'adapt_hist_equal', 'alog', 'alog10',
'amoeba', 'annotate', 'app_user_dir', 'app_user_dir_query',
'arg_present', 'array_equal', 'array_indices', 'arrow',
'ascii_template', 'asin', 'assoc', 'atan', 'axis',
'a_correlate', 'bandpass_filter', 'bandreject_filter',
'barplot', 'bar_plot', 'beseli', 'beselj', 'beselk',
'besely', 'beta', 'bilinear', 'binary_template', 'bindgen',
'binomial', 'bin_date', 'bit_ffs', 'bit_population',
'blas_axpy', 'blk_con', 'box_cursor', 'breakpoint',
'broyden', 'butterworth', 'bytarr', 'byte', 'byteorder',
'bytscl', 'caldat', 'calendar', 'call_external',
'call_function', 'call_method', 'call_procedure', 'canny',
'catch', 'cd', 'cdf_[0-9a-za-z_]*', 'ceil', 'chebyshev',
'check_math',
'chisqr_cvf', 'chisqr_pdf', 'choldc', 'cholsol', 'cindgen',
'cir_3pnt', 'close', 'cluster', 'cluster_tree', 'clust_wts',
'cmyk_convert', 'colorbar', 'colorize_sample',
'colormap_applicable', 'colormap_gradient',
'colormap_rotation', 'colortable', 'color_convert',
'color_exchange', 'color_quan', 'color_range_map', 'comfit',
'command_line_args', 'complex', 'complexarr', 'complexround',
'compute_mesh_normals', 'cond', 'congrid', 'conj',
'constrained_min', 'contour', 'convert_coord', 'convol',
'convol_fft', 'coord2to3', 'copy_lun', 'correlate', 'cos',
'cosh', 'cpu', 'cramer', 'create_cursor', 'create_struct',
'create_view', 'crossp', 'crvlength', 'cti_test',
'ct_luminance', 'cursor', 'curvefit', 'cvttobm', 'cv_coord',
'cw_animate', 'cw_animate_getp', 'cw_animate_load',
'cw_animate_run', 'cw_arcball', 'cw_bgroup', 'cw_clr_index',
'cw_colorsel', 'cw_defroi', 'cw_field', 'cw_filesel',
'cw_form', 'cw_fslider', 'cw_light_editor',
'cw_light_editor_get', 'cw_light_editor_set', 'cw_orient',
'cw_palette_editor', 'cw_palette_editor_get',
'cw_palette_editor_set', 'cw_pdmenu', 'cw_rgbslider',
'cw_tmpl', 'cw_zoom', 'c_correlate', 'dblarr', 'db_exists',
'dcindgen', 'dcomplex', 'dcomplexarr', 'define_key',
'define_msgblk', 'define_msgblk_from_file', 'defroi',
'defsysv', 'delvar', 'dendrogram', 'dendro_plot', 'deriv',
'derivsig', 'determ', 'device', 'dfpmin', 'diag_matrix',
'dialog_dbconnect', 'dialog_message', 'dialog_pickfile',
'dialog_printersetup', 'dialog_printjob',
'dialog_read_image', 'dialog_write_image', 'digital_filter',
'dilate', 'dindgen', 'dissolve', 'dist', 'distance_measure',
'dlm_load', 'dlm_register', 'doc_library', 'double',
'draw_roi', 'edge_dog', 'efont', 'eigenql', 'eigenvec',
'ellipse', 'elmhes', 'emboss', 'empty', 'enable_sysrtn',
'eof', 'eos_[0-9a-za-z_]*', 'erase', 'erf', 'erfc', 'erfcx',
'erode', 'errorplot', 'errplot', 'estimator_filter',
'execute', 'exit', 'exp', 'expand', 'expand_path', 'expint',
'extrac', 'extract_slice', 'factorial', 'fft', 'filepath',
'file_basename', 'file_chmod', 'file_copy', 'file_delete',
'file_dirname', 'file_expand_path', 'file_info',
'file_lines', 'file_link', 'file_mkdir', 'file_move',
'file_poll_input', 'file_readlink', 'file_same',
'file_search', 'file_test', 'file_which', 'findgen',
'finite', 'fix', 'flick', 'float', 'floor', 'flow3',
'fltarr', 'flush', 'format_axis_values', 'free_lun',
'fstat', 'fulstr', 'funct', 'fv_test', 'fx_root',
'fz_roots', 'f_cvf', 'f_pdf', 'gamma', 'gamma_ct',
'gauss2dfit', 'gaussfit', 'gaussian_function', 'gaussint',
'gauss_cvf', 'gauss_pdf', 'gauss_smooth', 'getenv',
'getwindows', 'get_drive_list', 'get_dxf_objects',
'get_kbrd', 'get_login_info', 'get_lun', 'get_screen_size',
'greg2jul', 'grib_[0-9a-za-z_]*', 'grid3', 'griddata',
'grid_input', 'grid_tps', 'gs_iter',
'h5[adfgirst]_[0-9a-za-z_]*', 'h5_browser', 'h5_close',
'h5_create', 'h5_get_libversion', 'h5_open', 'h5_parse',
'hanning', 'hash', 'hdf_[0-9a-za-z_]*', 'heap_free',
'heap_gc', 'heap_nosave', 'heap_refcount', 'heap_save',
'help', 'hilbert', 'histogram', 'hist_2d', 'hist_equal',
'hls', 'hough', 'hqr', 'hsv', 'h_eq_ct', 'h_eq_int',
'i18n_multibytetoutf8', 'i18n_multibytetowidechar',
'i18n_utf8tomultibyte', 'i18n_widechartomultibyte',
'ibeta', 'icontour', 'iconvertcoord', 'idelete', 'identity',
'idlexbr_assistant', 'idlitsys_createtool', 'idl_base64',
'idl_validname', 'iellipse', 'igamma', 'igetcurrent',
'igetdata', 'igetid', 'igetproperty', 'iimage', 'image',
'image_cont', 'image_statistics', 'imaginary', 'imap',
'indgen', 'intarr', 'interpol', 'interpolate',
'interval_volume', 'int_2d', 'int_3d', 'int_tabulated',
'invert', 'ioctl', 'iopen', 'iplot', 'ipolygon',
'ipolyline', 'iputdata', 'iregister', 'ireset', 'iresolve',
'irotate', 'ir_filter', 'isa', 'isave', 'iscale',
'isetcurrent', 'isetproperty', 'ishft', 'isocontour',
'isosurface', 'isurface', 'itext', 'itranslate', 'ivector',
'ivolume', 'izoom', 'i_beta', 'journal', 'json_parse',
'json_serialize', 'jul2greg', 'julday', 'keyword_set',
'krig2d', 'kurtosis', 'kw_test', 'l64indgen', 'label_date',
'label_region', 'ladfit', 'laguerre', 'laplacian',
'la_choldc', 'la_cholmprove', 'la_cholsol', 'la_determ',
'la_eigenproblem', 'la_eigenql', 'la_eigenvec', 'la_elmhes',
'la_gm_linear_model', 'la_hqr', 'la_invert',
'la_least_squares', 'la_least_square_equality',
'la_linear_equation', 'la_ludc', 'la_lumprove', 'la_lusol',
'la_svd', 'la_tridc', 'la_trimprove', 'la_triql',
'la_trired', 'la_trisol', 'least_squares_filter', 'leefilt',
'legend', 'legendre', 'linbcg', 'lindgen', 'linfit',
'linkimage', 'list', 'll_arc_distance', 'lmfit', 'lmgr',
'lngamma', 'lnp_test', 'loadct', 'locale_get',
'logical_and', 'logical_or', 'logical_true', 'lon64arr',
'lonarr', 'long', 'long64', 'lsode', 'ludc', 'lumprove',
'lusol', 'lu_complex', 'machar', 'make_array', 'make_dll',
'make_rt', 'map', 'mapcontinents', 'mapgrid', 'map_2points',
'map_continents', 'map_grid', 'map_image', 'map_patch',
'map_proj_forward', 'map_proj_image', 'map_proj_info',
'map_proj_init', 'map_proj_inverse', 'map_set',
'matrix_multiply', 'matrix_power', 'max', 'md_test',
'mean', 'meanabsdev', 'mean_filter', 'median', 'memory',
'mesh_clip', 'mesh_decimate', 'mesh_issolid', 'mesh_merge',
'mesh_numtriangles', 'mesh_obj', 'mesh_smooth',
'mesh_surfacearea', 'mesh_validate', 'mesh_volume',
'message', 'min', 'min_curve_surf', 'mk_html_help',
'modifyct', 'moment', 'morph_close', 'morph_distance',
'morph_gradient', 'morph_hitormiss', 'morph_open',
'morph_thin', 'morph_tophat', 'multi', 'm_correlate',
'ncdf_[0-9a-za-z_]*', 'newton', 'noise_hurl', 'noise_pick',
'noise_scatter', 'noise_slur', 'norm', 'n_elements',
'n_params', 'n_tags', 'objarr', 'obj_class', 'obj_destroy',
'obj_hasmethod', 'obj_isa', 'obj_new', 'obj_valid',
'online_help', 'on_error', 'open', 'oplot', 'oploterr',
'parse_url', 'particle_trace', 'path_cache', 'path_sep',
'pcomp', 'plot', 'plot3d', 'ploterr', 'plots', 'plot_3dbox',
'plot_field', 'pnt_line', 'point_lun', 'polarplot',
'polar_contour', 'polar_surface', 'poly', 'polyfill',
'polyfillv', 'polygon', 'polyline', 'polyshade', 'polywarp',
'poly_2d', 'poly_area', 'poly_fit', 'popd', 'powell',
'pref_commit', 'pref_get', 'pref_set', 'prewitt', 'primes',
'print', 'printd', 'product', 'profile', 'profiler',
'profiles', 'project_vol', 'psafm', 'pseudo',
'ps_show_fonts', 'ptrarr', 'ptr_free', 'ptr_new',
'ptr_valid', 'pushd', 'p_correlate', 'qgrid3', 'qhull',
'qromb', 'qromo', 'qsimp', 'query_ascii', 'query_bmp',
'query_csv', 'query_dicom', 'query_gif', 'query_image',
'query_jpeg', 'query_jpeg2000', 'query_mrsid', 'query_pict',
'query_png', 'query_ppm', 'query_srf', 'query_tiff',
'query_wav', 'radon', 'randomn', 'randomu', 'ranks',
'rdpix', 'read', 'reads', 'readu', 'read_ascii',
'read_binary', 'read_bmp', 'read_csv', 'read_dicom',
'read_gif', 'read_image', 'read_interfile', 'read_jpeg',
'read_jpeg2000', 'read_mrsid', 'read_pict', 'read_png',
'read_ppm', 'read_spr', 'read_srf', 'read_sylk',
'read_tiff', 'read_wav', 'read_wave', 'read_x11_bitmap',
'read_xwd', 'real_part', 'rebin', 'recall_commands',
'recon3', 'reduce_colors', 'reform', 'region_grow',
'register_cursor', 'regress', 'replicate',
'replicate_inplace', 'resolve_all', 'resolve_routine',
'restore', 'retall', 'return', 'reverse', 'rk4', 'roberts',
'rot', 'rotate', 'round', 'routine_filepath',
'routine_info', 'rs_test', 'r_correlate', 'r_test',
'save', 'savgol', 'scale3', 'scale3d', 'scope_level',
'scope_traceback', 'scope_varfetch', 'scope_varname',
'search2d', 'search3d', 'sem_create', 'sem_delete',
'sem_lock', 'sem_release', 'setenv', 'set_plot',
'set_shading', 'sfit', 'shade_surf', 'shade_surf_irr',
'shade_volume', 'shift', 'shift_diff', 'shmdebug', 'shmmap',
'shmunmap', 'shmvar', 'show3', 'showfont', 'simplex', 'sin',
'sindgen', 'sinh', 'size', 'skewness', 'skip_lun',
'slicer3', 'slide_image', 'smooth', 'sobel', 'socket',
'sort', 'spawn', 'spher_harm', 'sph_4pnt', 'sph_scat',
'spline', 'spline_p', 'spl_init', 'spl_interp', 'sprsab',
'sprsax', 'sprsin', 'sprstp', 'sqrt', 'standardize',
'stddev', 'stop', 'strarr', 'strcmp', 'strcompress',
'streamline', 'stregex', 'stretch', 'string', 'strjoin',
'strlen', 'strlowcase', 'strmatch', 'strmessage', 'strmid',
'strpos', 'strput', 'strsplit', 'strtrim', 'struct_assign',
'struct_hide', 'strupcase', 'surface', 'surfr', 'svdc',
'svdfit', 'svsol', 'swap_endian', 'swap_endian_inplace',
'symbol', 'systime', 's_test', 't3d', 'tag_names', 'tan',
'tanh', 'tek_color', 'temporary', 'tetra_clip',
'tetra_surface', 'tetra_volume', 'text', 'thin', 'threed',
'timegen', 'time_test2', 'tm_test', 'total', 'trace',
'transpose', 'triangulate', 'trigrid', 'triql', 'trired',
'trisol', 'tri_surf', 'truncate_lun', 'ts_coef', 'ts_diff',
'ts_fcast', 'ts_smooth', 'tv', 'tvcrs', 'tvlct', 'tvrd',
'tvscl', 'typename', 't_cvt', 't_pdf', 'uindgen', 'uint',
'uintarr', 'ul64indgen', 'ulindgen', 'ulon64arr', 'ulonarr',
'ulong', 'ulong64', 'uniq', 'unsharp_mask', 'usersym',
'value_locate', 'variance', 'vector', 'vector_field', 'vel',
'velovect', 'vert_t3d', 'voigt', 'voronoi', 'voxel_proj',
'wait', 'warp_tri', 'watershed', 'wdelete', 'wf_draw',
'where', 'widget_base', 'widget_button', 'widget_combobox',
'widget_control', 'widget_displaycontextmen', 'widget_draw',
'widget_droplist', 'widget_event', 'widget_info',
'widget_label', 'widget_list', 'widget_propertysheet',
'widget_slider', 'widget_tab', 'widget_table',
'widget_text', 'widget_tree', 'widget_tree_move',
'widget_window', 'wiener_filter', 'window', 'writeu',
'write_bmp', 'write_csv', 'write_gif', 'write_image',
'write_jpeg', 'write_jpeg2000', 'write_nrif', 'write_pict',
'write_png', 'write_ppm', 'write_spr', 'write_srf',
'write_sylk', 'write_tiff', 'write_wav', 'write_wave',
'wset', 'wshow', 'wtn', 'wv_applet', 'wv_cwt',
'wv_cw_wavelet', 'wv_denoise', 'wv_dwt', 'wv_fn_coiflet',
'wv_fn_daubechies', 'wv_fn_gaussian', 'wv_fn_haar',
'wv_fn_morlet', 'wv_fn_paul', 'wv_fn_symlet',
'wv_import_data', 'wv_import_wavelet', 'wv_plot3d_wps',
'wv_plot_multires', 'wv_pwt', 'wv_tool_denoise',
'xbm_edit', 'xdisplayfile', 'xdxf', 'xfont',
'xinteranimate', 'xloadct', 'xmanager', 'xmng_tmpl',
'xmtool', 'xobjview', 'xobjview_rotate',
'xobjview_write_image', 'xpalette', 'xpcolor', 'xplot3d',
'xregistered', 'xroi', 'xsq_test', 'xsurface', 'xvaredit',
'xvolume', 'xvolume_rotate', 'xvolume_write_image',
'xyouts', 'zoom', 'zoom_24']
"""Functions from: http://www.exelisvis.com/docs/routines-1.html"""
tokens = {
'root': [
(r'^\s*;.*?\n', Comment.Singleline),
(r'\b(' + '|'.join(_RESERVED) + r')\b', Keyword),
(r'\b(' + '|'.join(_BUILTIN_LIB) + r')\b', Name.Builtin),
(r'\+=|-=|\^=|\*=|/=|#=|##=|<=|>=|=', Operator),
(r'\+\+|--|->|\+|-|##|#|\*|/|<|>|&&|\^|~|\|\|\?|:', Operator),
(r'\b(mod=|lt=|le=|eq=|ne=|ge=|gt=|not=|and=|or=|xor=)', Operator),
(r'\b(mod|lt|le|eq|ne|ge|gt|not|and|or|xor)\b', Operator),
(r'\b[0-9](L|B|S|UL|ULL|LL)?\b', Number),
(r'.', Text),
]
}
class RdLexer(RegexLexer):
"""
Pygments Lexer for R documentation (Rd) files
This is a very minimal implementation, highlighting little more
than the macros. A description of Rd syntax is found in `Writing R
Extensions <http://cran.r-project.org/doc/manuals/R-exts.html>`_
and `Parsing Rd files <developer.r-project.org/parseRd.pdf>`_.
*New in Pygments 1.6.*
"""
name = 'Rd'
aliases = ['rd']
filenames = ['*.Rd']
mimetypes = ['text/x-r-doc']
# To account for verbatim / LaTeX-like / and R-like areas
# would require parsing.
tokens = {
'root' : [
# catch escaped brackets and percent sign
(r'\\[\\{}%]', String.Escape),
# comments
(r'%.*$', Comment),
# special macros with no arguments
(r'\\(?:cr|l?dots|R|tab)\b', Keyword.Constant),
# macros
(r'\\[a-zA-Z]+\b', Keyword),
# special preprocessor macros
(r'^\s*#(?:ifn?def|endif).*\b', Comment.Preproc),
# non-escaped brackets
(r'[{}]', Name.Builtin),
# everything else
(r'[^\\%\n{}]+', Text),
(r'.', Text),
]
}
class IgorLexer(RegexLexer):
"""
Pygments Lexer for Igor Pro procedure files (.ipf).
See http://www.wavemetrics.com/ and http://www.igorexchange.com/.
*New in Pygments 1.7.*
"""
name = 'Igor'
aliases = ['igor', 'igorpro']
filenames = ['*.ipf']
mimetypes = ['text/ipf']
flags = re.IGNORECASE
flowControl = [
'if', 'else', 'elseif', 'endif', 'for', 'endfor', 'strswitch', 'switch',
'case', 'endswitch', 'do', 'while', 'try', 'catch', 'endtry', 'break',
'continue', 'return',
]
types = [
'variable', 'string', 'constant', 'strconstant', 'NVAR', 'SVAR', 'WAVE',
'STRUCT', 'ThreadSafe', 'function', 'end', 'static', 'macro', 'window',
'graph', 'Structure', 'EndStructure', 'EndMacro', 'FuncFit', 'Proc',
'Picture', 'Menu', 'SubMenu', 'Prompt', 'DoPrompt',
]
operations = [
'Abort', 'AddFIFOData', 'AddFIFOVectData', 'AddMovieAudio',
'AddMovieFrame', 'APMath', 'Append', 'AppendImage',
'AppendLayoutObject', 'AppendMatrixContour', 'AppendText',
'AppendToGraph', 'AppendToLayout', 'AppendToTable', 'AppendXYZContour',
'AutoPositionWindow', 'BackgroundInfo', 'Beep', 'BoundingBall',
'BrowseURL', 'BuildMenu', 'Button', 'cd', 'Chart', 'CheckBox',
'CheckDisplayed', 'ChooseColor', 'Close', 'CloseMovie', 'CloseProc',
'ColorScale', 'ColorTab2Wave', 'Concatenate', 'ControlBar',
'ControlInfo', 'ControlUpdate', 'ConvexHull', 'Convolve', 'CopyFile',
'CopyFolder', 'CopyScales', 'Correlate', 'CreateAliasShortcut', 'Cross',
'CtrlBackground', 'CtrlFIFO', 'CtrlNamedBackground', 'Cursor',
'CurveFit', 'CustomControl', 'CWT', 'Debugger', 'DebuggerOptions',
'DefaultFont', 'DefaultGuiControls', 'DefaultGuiFont', 'DefineGuide',
'DelayUpdate', 'DeleteFile', 'DeleteFolder', 'DeletePoints',
'Differentiate', 'dir', 'Display', 'DisplayHelpTopic',
'DisplayProcedure', 'DoAlert', 'DoIgorMenu', 'DoUpdate', 'DoWindow',
'DoXOPIdle', 'DrawAction', 'DrawArc', 'DrawBezier', 'DrawLine',
'DrawOval', 'DrawPICT', 'DrawPoly', 'DrawRect', 'DrawRRect', 'DrawText',
'DSPDetrend', 'DSPPeriodogram', 'Duplicate', 'DuplicateDataFolder',
'DWT', 'EdgeStats', 'Edit', 'ErrorBars', 'Execute', 'ExecuteScriptText',
'ExperimentModified', 'Extract', 'FastGaussTransform', 'FastOp',
'FBinRead', 'FBinWrite', 'FFT', 'FIFO2Wave', 'FIFOStatus', 'FilterFIR',
'FilterIIR', 'FindLevel', 'FindLevels', 'FindPeak', 'FindPointsInPoly',
'FindRoots', 'FindSequence', 'FindValue', 'FPClustering', 'fprintf',
'FReadLine', 'FSetPos', 'FStatus', 'FTPDelete', 'FTPDownload',
'FTPUpload', 'FuncFit', 'FuncFitMD', 'GetAxis', 'GetFileFolderInfo',
'GetLastUserMenuInfo', 'GetMarquee', 'GetSelection', 'GetWindow',
'GraphNormal', 'GraphWaveDraw', 'GraphWaveEdit', 'Grep', 'GroupBox',
'Hanning', 'HideIgorMenus', 'HideInfo', 'HideProcedures', 'HideTools',
'HilbertTransform', 'Histogram', 'IFFT', 'ImageAnalyzeParticles',
'ImageBlend', 'ImageBoundaryToMask', 'ImageEdgeDetection',
'ImageFileInfo', 'ImageFilter', 'ImageFocus', 'ImageGenerateROIMask',
'ImageHistModification', 'ImageHistogram', 'ImageInterpolate',
'ImageLineProfile', 'ImageLoad', 'ImageMorphology', 'ImageRegistration',
'ImageRemoveBackground', 'ImageRestore', 'ImageRotate', 'ImageSave',
'ImageSeedFill', 'ImageSnake', 'ImageStats', 'ImageThreshold',
'ImageTransform', 'ImageUnwrapPhase', 'ImageWindow', 'IndexSort',
'InsertPoints', 'Integrate', 'IntegrateODE', 'Interp3DPath',
'Interpolate3D', 'KillBackground', 'KillControl', 'KillDataFolder',
'KillFIFO', 'KillFreeAxis', 'KillPath', 'KillPICTs', 'KillStrings',
'KillVariables', 'KillWaves', 'KillWindow', 'KMeans', 'Label', 'Layout',
'Legend', 'LinearFeedbackShiftRegister', 'ListBox', 'LoadData',
'LoadPackagePreferences', 'LoadPICT', 'LoadWave', 'Loess',
'LombPeriodogram', 'Make', 'MakeIndex', 'MarkPerfTestTime',
'MatrixConvolve', 'MatrixCorr', 'MatrixEigenV', 'MatrixFilter',
'MatrixGaussJ', 'MatrixInverse', 'MatrixLinearSolve',
'MatrixLinearSolveTD', 'MatrixLLS', 'MatrixLUBkSub', 'MatrixLUD',
'MatrixMultiply', 'MatrixOP', 'MatrixSchur', 'MatrixSolve',
'MatrixSVBkSub', 'MatrixSVD', 'MatrixTranspose', 'MeasureStyledText',
'Modify', 'ModifyContour', 'ModifyControl', 'ModifyControlList',
'ModifyFreeAxis', 'ModifyGraph', 'ModifyImage', 'ModifyLayout',
'ModifyPanel', 'ModifyTable', 'ModifyWaterfall', 'MoveDataFolder',
'MoveFile', 'MoveFolder', 'MoveString', 'MoveSubwindow', 'MoveVariable',
'MoveWave', 'MoveWindow', 'NeuralNetworkRun', 'NeuralNetworkTrain',
'NewDataFolder', 'NewFIFO', 'NewFIFOChan', 'NewFreeAxis', 'NewImage',
'NewLayout', 'NewMovie', 'NewNotebook', 'NewPanel', 'NewPath',
'NewWaterfall', 'Note', 'Notebook', 'NotebookAction', 'Open',
'OpenNotebook', 'Optimize', 'ParseOperationTemplate', 'PathInfo',
'PauseForUser', 'PauseUpdate', 'PCA', 'PlayMovie', 'PlayMovieAction',
'PlaySnd', 'PlaySound', 'PopupContextualMenu', 'PopupMenu',
'Preferences', 'PrimeFactors', 'Print', 'printf', 'PrintGraphs',
'PrintLayout', 'PrintNotebook', 'PrintSettings', 'PrintTable',
'Project', 'PulseStats', 'PutScrapText', 'pwd', 'Quit',
'RatioFromNumber', 'Redimension', 'Remove', 'RemoveContour',
'RemoveFromGraph', 'RemoveFromLayout', 'RemoveFromTable', 'RemoveImage',
'RemoveLayoutObjects', 'RemovePath', 'Rename', 'RenameDataFolder',
'RenamePath', 'RenamePICT', 'RenameWindow', 'ReorderImages',
'ReorderTraces', 'ReplaceText', 'ReplaceWave', 'Resample',
'ResumeUpdate', 'Reverse', 'Rotate', 'Save', 'SaveData',
'SaveExperiment', 'SaveGraphCopy', 'SaveNotebook',
'SavePackagePreferences', 'SavePICT', 'SaveTableCopy',
'SetActiveSubwindow', 'SetAxis', 'SetBackground', 'SetDashPattern',
'SetDataFolder', 'SetDimLabel', 'SetDrawEnv', 'SetDrawLayer',
'SetFileFolderInfo', 'SetFormula', 'SetIgorHook', 'SetIgorMenuMode',
'SetIgorOption', 'SetMarquee', 'SetProcessSleep', 'SetRandomSeed',
'SetScale', 'SetVariable', 'SetWaveLock', 'SetWindow', 'ShowIgorMenus',
'ShowInfo', 'ShowTools', 'Silent', 'Sleep', 'Slider', 'Smooth',
'SmoothCustom', 'Sort', 'SoundInRecord', 'SoundInSet',
'SoundInStartChart', 'SoundInStatus', 'SoundInStopChart',
'SphericalInterpolate', 'SphericalTriangulate', 'SplitString',
'sprintf', 'sscanf', 'Stack', 'StackWindows',
'StatsAngularDistanceTest', 'StatsANOVA1Test', 'StatsANOVA2NRTest',
'StatsANOVA2RMTest', 'StatsANOVA2Test', 'StatsChiTest',
'StatsCircularCorrelationTest', 'StatsCircularMeans',
'StatsCircularMoments', 'StatsCircularTwoSampleTest',
'StatsCochranTest', 'StatsContingencyTable', 'StatsDIPTest',
'StatsDunnettTest', 'StatsFriedmanTest', 'StatsFTest',
'StatsHodgesAjneTest', 'StatsJBTest', 'StatsKendallTauTest',
'StatsKSTest', 'StatsKWTest', 'StatsLinearCorrelationTest',
'StatsLinearRegression', 'StatsMultiCorrelationTest',
'StatsNPMCTest', 'StatsNPNominalSRTest', 'StatsQuantiles',
'StatsRankCorrelationTest', 'StatsResample', 'StatsSample',
'StatsScheffeTest', 'StatsSignTest', 'StatsSRTest', 'StatsTTest',
'StatsTukeyTest', 'StatsVariancesTest', 'StatsWatsonUSquaredTest',
'StatsWatsonWilliamsTest', 'StatsWheelerWatsonTest',
'StatsWilcoxonRankTest', 'StatsWRCorrelationTest', 'String',
'StructGet', 'StructPut', 'TabControl', 'Tag', 'TextBox', 'Tile',
'TileWindows', 'TitleBox', 'ToCommandLine', 'ToolsGrid',
'Triangulate3d', 'Unwrap', 'ValDisplay', 'Variable', 'WaveMeanStdv',
'WaveStats', 'WaveTransform', 'wfprintf', 'WignerTransform',
'WindowFunction',
]
functions = [
'abs', 'acos', 'acosh', 'AiryA', 'AiryAD', 'AiryB', 'AiryBD', 'alog',
'area', 'areaXY', 'asin', 'asinh', 'atan', 'atan2', 'atanh',
'AxisValFromPixel', 'Besseli', 'Besselj', 'Besselk', 'Bessely', 'bessi',
'bessj', 'bessk', 'bessy', 'beta', 'betai', 'BinarySearch',
'BinarySearchInterp', 'binomial', 'binomialln', 'binomialNoise', 'cabs',
'CaptureHistoryStart', 'ceil', 'cequal', 'char2num', 'chebyshev',
'chebyshevU', 'CheckName', 'cmplx', 'cmpstr', 'conj', 'ContourZ', 'cos',
'cosh', 'cot', 'CountObjects', 'CountObjectsDFR', 'cpowi',
'CreationDate', 'csc', 'DataFolderExists', 'DataFolderRefsEqual',
'DataFolderRefStatus', 'date2secs', 'datetime', 'DateToJulian',
'Dawson', 'DDEExecute', 'DDEInitiate', 'DDEPokeString', 'DDEPokeWave',
'DDERequestWave', 'DDEStatus', 'DDETerminate', 'deltax', 'digamma',
'DimDelta', 'DimOffset', 'DimSize', 'ei', 'enoise', 'equalWaves', 'erf',
'erfc', 'exists', 'exp', 'expInt', 'expNoise', 'factorial', 'fakedata',
'faverage', 'faverageXY', 'FindDimLabel', 'FindListItem', 'floor',
'FontSizeHeight', 'FontSizeStringWidth', 'FresnelCos', 'FresnelSin',
'gamma', 'gammaInc', 'gammaNoise', 'gammln', 'gammp', 'gammq', 'Gauss',
'Gauss1D', 'Gauss2D', 'gcd', 'GetDefaultFontSize',
'GetDefaultFontStyle', 'GetKeyState', 'GetRTError', 'gnoise',
'GrepString', 'hcsr', 'hermite', 'hermiteGauss', 'HyperG0F1',
'HyperG1F1', 'HyperG2F1', 'HyperGNoise', 'HyperGPFQ', 'IgorVersion',
'ilim', 'imag', 'Inf', 'Integrate1D', 'interp', 'Interp2D', 'Interp3D',
'inverseERF', 'inverseERFC', 'ItemsInList', 'jlim', 'Laguerre',
'LaguerreA', 'LaguerreGauss', 'leftx', 'LegendreA', 'limit', 'ln',
'log', 'logNormalNoise', 'lorentzianNoise', 'magsqr', 'MandelbrotPoint',
'MarcumQ', 'MatrixDet', 'MatrixDot', 'MatrixRank', 'MatrixTrace', 'max',
'mean', 'min', 'mod', 'ModDate', 'NaN', 'norm', 'NumberByKey',
'numpnts', 'numtype', 'NumVarOrDefault', 'NVAR_Exists', 'p2rect',
'ParamIsDefault', 'pcsr', 'Pi', 'PixelFromAxisVal', 'pnt2x',
'poissonNoise', 'poly', 'poly2D', 'PolygonArea', 'qcsr', 'r2polar',
'real', 'rightx', 'round', 'sawtooth', 'ScreenResolution', 'sec',
'SelectNumber', 'sign', 'sin', 'sinc', 'sinh', 'SphericalBessJ',
'SphericalBessJD', 'SphericalBessY', 'SphericalBessYD',
'SphericalHarmonics', 'sqrt', 'StartMSTimer', 'StatsBetaCDF',
'StatsBetaPDF', 'StatsBinomialCDF', 'StatsBinomialPDF',
'StatsCauchyCDF', 'StatsCauchyPDF', 'StatsChiCDF', 'StatsChiPDF',
'StatsCMSSDCDF', 'StatsCorrelation', 'StatsDExpCDF', 'StatsDExpPDF',
'StatsErlangCDF', 'StatsErlangPDF', 'StatsErrorPDF', 'StatsEValueCDF',
'StatsEValuePDF', 'StatsExpCDF', 'StatsExpPDF', 'StatsFCDF',
'StatsFPDF', 'StatsFriedmanCDF', 'StatsGammaCDF', 'StatsGammaPDF',
'StatsGeometricCDF', 'StatsGeometricPDF', 'StatsHyperGCDF',
'StatsHyperGPDF', 'StatsInvBetaCDF', 'StatsInvBinomialCDF',
'StatsInvCauchyCDF', 'StatsInvChiCDF', 'StatsInvCMSSDCDF',
'StatsInvDExpCDF', 'StatsInvEValueCDF', 'StatsInvExpCDF',
'StatsInvFCDF', 'StatsInvFriedmanCDF', 'StatsInvGammaCDF',
'StatsInvGeometricCDF', 'StatsInvKuiperCDF', 'StatsInvLogisticCDF',
'StatsInvLogNormalCDF', 'StatsInvMaxwellCDF', 'StatsInvMooreCDF',
'StatsInvNBinomialCDF', 'StatsInvNCChiCDF', 'StatsInvNCFCDF',
'StatsInvNormalCDF', 'StatsInvParetoCDF', 'StatsInvPoissonCDF',
'StatsInvPowerCDF', 'StatsInvQCDF', 'StatsInvQpCDF',
'StatsInvRayleighCDF', 'StatsInvRectangularCDF', 'StatsInvSpearmanCDF',
'StatsInvStudentCDF', 'StatsInvTopDownCDF', 'StatsInvTriangularCDF',
'StatsInvUsquaredCDF', 'StatsInvVonMisesCDF', 'StatsInvWeibullCDF',
'StatsKuiperCDF', 'StatsLogisticCDF', 'StatsLogisticPDF',
'StatsLogNormalCDF', 'StatsLogNormalPDF', 'StatsMaxwellCDF',
'StatsMaxwellPDF', 'StatsMedian', 'StatsMooreCDF', 'StatsNBinomialCDF',
'StatsNBinomialPDF', 'StatsNCChiCDF', 'StatsNCChiPDF', 'StatsNCFCDF',
'StatsNCFPDF', 'StatsNCTCDF', 'StatsNCTPDF', 'StatsNormalCDF',
'StatsNormalPDF', 'StatsParetoCDF', 'StatsParetoPDF', 'StatsPermute',
'StatsPoissonCDF', 'StatsPoissonPDF', 'StatsPowerCDF',
'StatsPowerNoise', 'StatsPowerPDF', 'StatsQCDF', 'StatsQpCDF',
'StatsRayleighCDF', 'StatsRayleighPDF', 'StatsRectangularCDF',
'StatsRectangularPDF', 'StatsRunsCDF', 'StatsSpearmanRhoCDF',
'StatsStudentCDF', 'StatsStudentPDF', 'StatsTopDownCDF',
'StatsTriangularCDF', 'StatsTriangularPDF', 'StatsTrimmedMean',
'StatsUSquaredCDF', 'StatsVonMisesCDF', 'StatsVonMisesNoise',
'StatsVonMisesPDF', 'StatsWaldCDF', 'StatsWaldPDF', 'StatsWeibullCDF',
'StatsWeibullPDF', 'StopMSTimer', 'str2num', 'stringCRC', 'stringmatch',
'strlen', 'strsearch', 'StudentA', 'StudentT', 'sum', 'SVAR_Exists',
'TagVal', 'tan', 'tanh', 'ThreadGroupCreate', 'ThreadGroupRelease',
'ThreadGroupWait', 'ThreadProcessorCount', 'ThreadReturnValue', 'ticks',
'trunc', 'Variance', 'vcsr', 'WaveCRC', 'WaveDims', 'WaveExists',
'WaveMax', 'WaveMin', 'WaveRefsEqual', 'WaveType', 'WhichListItem',
'WinType', 'WNoise', 'x', 'x2pnt', 'xcsr', 'y', 'z', 'zcsr', 'ZernikeR',
]
functions += [
'AddListItem', 'AnnotationInfo', 'AnnotationList', 'AxisInfo',
'AxisList', 'CaptureHistory', 'ChildWindowList', 'CleanupName',
'ContourInfo', 'ContourNameList', 'ControlNameList', 'CsrInfo',
'CsrWave', 'CsrXWave', 'CTabList', 'DataFolderDir', 'date',
'DDERequestString', 'FontList', 'FuncRefInfo', 'FunctionInfo',
'FunctionList', 'FunctionPath', 'GetDataFolder', 'GetDefaultFont',
'GetDimLabel', 'GetErrMessage', 'GetFormula',
'GetIndependentModuleName', 'GetIndexedObjName', 'GetIndexedObjNameDFR',
'GetRTErrMessage', 'GetRTStackInfo', 'GetScrapText', 'GetUserData',
'GetWavesDataFolder', 'GrepList', 'GuideInfo', 'GuideNameList', 'Hash',
'IgorInfo', 'ImageInfo', 'ImageNameList', 'IndexedDir', 'IndexedFile',
'JulianToDate', 'LayoutInfo', 'ListMatch', 'LowerStr', 'MacroList',
'NameOfWave', 'note', 'num2char', 'num2istr', 'num2str',
'OperationList', 'PadString', 'ParseFilePath', 'PathList', 'PICTInfo',
'PICTList', 'PossiblyQuoteName', 'ProcedureText', 'RemoveByKey',
'RemoveEnding', 'RemoveFromList', 'RemoveListItem',
'ReplaceNumberByKey', 'ReplaceString', 'ReplaceStringByKey',
'Secs2Date', 'Secs2Time', 'SelectString', 'SortList',
'SpecialCharacterInfo', 'SpecialCharacterList', 'SpecialDirPath',
'StringByKey', 'StringFromList', 'StringList', 'StrVarOrDefault',
'TableInfo', 'TextFile', 'ThreadGroupGetDF', 'time', 'TraceFromPixel',
'TraceInfo', 'TraceNameList', 'UniqueName', 'UnPadString', 'UpperStr',
'VariableList', 'WaveInfo', 'WaveList', 'WaveName', 'WaveUnits',
'WinList', 'WinName', 'WinRecreation', 'XWaveName',
'ContourNameToWaveRef', 'CsrWaveRef', 'CsrXWaveRef',
'ImageNameToWaveRef', 'NewFreeWave', 'TagWaveRef', 'TraceNameToWaveRef',
'WaveRefIndexed', 'XWaveRefFromTrace', 'GetDataFolderDFR',
'GetWavesDataFolderDFR', 'NewFreeDataFolder', 'ThreadGroupGetDFR',
]
tokens = {
'root': [
(r'//.*$', Comment.Single),
(r'"([^"\\]|\\.)*"', String),
# Flow Control.
(r'\b(%s)\b' % '|'.join(flowControl), Keyword),
# Types.
(r'\b(%s)\b' % '|'.join(types), Keyword.Type),
# Built-in operations.
(r'\b(%s)\b' % '|'.join(operations), Name.Class),
# Built-in functions.
(r'\b(%s)\b' % '|'.join(functions), Name.Function),
# Compiler directives.
(r'^#(include|pragma|define|ifdef|ifndef|endif)',
Name.Decorator),
(r'[^a-zA-Z"/]+', Text),
(r'.', Text),
],
}
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
3442,
272,
18294,
2878,
339,
491,
476,
1192,
367,
3473,
10815,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
199,
504,
13277,
14,
1974,
492,
25591,
63,
6742,
199,
504,
13277,
14,
11729,
492,
21125,
12,
12939,
5838,
12,
10259,
12,
2387,
12,
971,
272,
12149,
12,
886,
63,
262,
13049,
199,
504,
13277,
14,
1418,
492,
6819,
12,
2624,
12,
10357,
12,
6431,
12,
2812,
12,
971,
272,
11013,
12,
4860,
12,
4516,
12,
8307,
199,
199,
504,
13277,
14,
12245,
14,
643,
441,
492,
2018,
5838,
199,
504,
13277,
14,
12245,
492,
485,
551,
24142,
63,
10372,
199,
504,
13277,
14,
12245,
492,
485,
9746,
63,
10372,
199,
199,
363,
452,
363,
275,
788,
42,
13987,
65,
5838,
297,
283,
42,
13987,
65,
9270,
5838,
297,
283,
16215,
32420,
5838,
297,
283,
14817,
5561,
5838,
297,
1779,
283,
14817,
5561,
4434,
5838,
297,
283,
17584,
811,
5838,
297,
283,
7181,
24142,
5838,
297,
283,
5667,
2713,
5838,
297,
1779,
283,
50,
9270,
5838,
297,
283,
4929,
5273,
297,
283,
42,
7391,
5838,
297,
283,
1713,
458,
5838,
297,
283,
933,
290,
5838,
297,
1779,
283,
998,
4464,
5273,
297,
283,
50,
68,
5838,
297,
283,
41,
2904,
5838,
418,
421,
199,
533,
1603,
13987,
65,
5838,
8,
19856,
304,
272,
408,
272,
2104,
658,
42,
13987,
65,
665,
1014,
921,
74,
13987,
279,
621,
14,
1308,
3133,
18417,
1350,
1233,
14,
339,
627,
4665,
315,
14493,
413,
14,
22,
2795,
272,
408,
272,
536,
275,
283,
42,
13987,
65,
7,
272,
5481,
275,
788,
74,
13987,
65,
1673,
74,
76,
418,
272,
6203,
275,
17855,
74,
76,
418,
272,
13290,
275,
788,
505,
15,
88,
13,
74,
13987,
65,
1673,
3578,
15,
88,
13,
74,
13987,
65,
418,
339,
12963,
275,
359,
267,
283,
2224,
1673,
11345,
83,
1673,
3773,
1673,
912,
1673,
374,
1673,
13655,
1673,
572,
537,
1673,
23426,
1673,
2960,
297,
267,
283,
343,
1363,
1673,
1535,
1673,
2227,
1673,
30092,
1673,
3916,
1673,
20422,
1673,
10512,
297,
267,
283,
466,
827,
1673,
466,
988,
1673,
3093,
827,
1673,
3093,
988,
1673,
12590,
1673,
8277,
1673,
20422,
63,
466,
297,
267,
283,
765,
63,
2444,
1673,
30002,
1673,
15195,
1673,
68,
8329,
1673,
68,
478,
12828,
1673,
2253,
297,
267,
283,
705,
1673,
11964,
1673,
479,
1673,
1222,
1673,
17354,
1673,
27531,
1673,
1038,
1673,
1017,
297,
272,
1622,
339,
4645,
275,
469,
267,
283,
1231,
356,
359,
288,
334,
82,
1154,
78,
297,
4516,
395,
288,
334,
82,
29538,
51,
60,
78,
11529,
4516,
395,
288,
334,
82,
11525,
2795,
4268,
6819,
395,
288,
334,
82,
3894,
61,
2440,
26,
1062,
27,
14251,
4300,
10357,
395,
288,
334,
82,
32190,
78,
297,
4516,
395,
288,
334,
82,
8124,
297,
4516,
395,
953,
327,
7681,
288,
334,
82,
6774,
5037,
92,
6710,
92,
509,
92,
262,
92,
1107,
92,
4785,
92,
6958,
5227,
1467,
519,
6704,
645,
293,
92,
3513,
92,
2723,
92,
692,
92,
2836,
692,
92,
2836,
92,
893,
92,
9341,
92,
500,
5227,
1467,
519,
7,
2075,
20615,
92,
67,
1250,
92,
1117,
92,
4941,
92,
578,
92,
646,
92,
3790,
5227,
1467,
519,
7,
646,
452,
92,
14890,
578,
92,
17836,
2862,
66,
297,
6431,
395,
288,
334,
82,
6774,
1832,
92,
2966,
92,
1297,
2862,
66,
297,
6431,
14,
17737,
395,
288,
334,
82,
6774,
10349,
92,
3241,
92,
3241,
24,
92,
3241,
975,
92,
3241,
708,
92,
3241,
772,
92,
23448,
92,
23448,
24,
92,
23448,
975,
92,
23448,
708,
92,
23448,
772,
7,
1467,
519,
17018,
5136,
708,
92,
5136,
772,
92,
14500,
772,
92,
14500,
3933,
92,
9874,
92,
19627,
92,
403,
2862,
66,
297,
355,
6431,
14,
804,
395,
953,
327,
3423,
288,
334,
82,
6774,
1593,
9,
17304,
3427,
83,
92,
9780,
83,
6393,
3196,
355,
10259,
8,
10650,
12,
985,
14,
3481,
395,
283,
29577,
659,
953,
327,
2943,
288,
334,
82,
6774,
466,
92,
466,
3620,
92,
6198,
9,
17304,
3427,
83,
92,
9780,
83,
6393,
3196,
355,
10259,
8,
10650,
12,
985,
14,
2543,
395,
283,
18596,
659,
953,
327,
10211,
288,
334,
82,
7,
389,
92,
1111,
92,
12932,
92,
8119,
92,
5118,
92,
12574,
6113,
6113,
10644,
447,
92,
28,
26,
92,
1988,
94,
11,
6331,
5,
29,
16137,
6,
62,
18257,
31,
1,
4,
4300,
11013,
395,
288,
334,
82,
1154,
3134,
10,
6113,
3134,
62,
92,
4537,
1103,
6113,
3134,
15,
17780,
297,
11013,
395,
953,
327,
12963,
288,
661,
360,
435,
21590,
904,
8,
10372,
9,
435,
519,
24431,
66,
297,
221,
2812,
14,
12306,
395,
953,
327,
1771,
10406,
288,
334,
82,
7,
64,
2229,
83,
680,
15279,
30880,
2624,
14,
4540,
8284,
395,
953,
327,
8365,
288,
334,
82,
4507,
8,
20942,
17780,
59,
16,
13,
23,
8194,
17,
12,
19,
93,
17780,
88,
59,
65,
13,
13753,
13,
38,
16,
13,
25,
8194,
17,
12,
19,
93,
17780,
85,
59,
65,
13,
13753,
13,
38,
16,
13,
25,
8194,
17,
12,
20,
22441,
2,
1467,
519,
22996,
53,
59,
65,
13,
13753,
13,
38,
16,
13,
25,
8194,
17,
12,
22,
22441,
4735,
9780,
1154,
78,
566,
4662,
2624,
14,
1610,
395,
953,
327,
862,
370,
1336,
8520,
16992,
288,
334,
82,
10120,
28,
1524,
3134,
87,
13670,
3934,
3985,
7386,
11013,
395,
953,
327,
3326,
288,
334,
82,
20459,
59,
1193,
566,
6949,
2624,
12,
283,
875,
659,
288,
334,
82,
3894,
37,
11843,
6949,
2624,
12,
12149,
360,
495,
17081,
3588,
297,
283,
875,
3855,
953,
327,
1561,
288,
334,
82,
20812,
59,
65,
13,
6353,
13,
58,
16,
13,
25,
3754,
11529,
2812,
14,
14946,
395,
288,
334,
82,
3894,
65,
13,
6353,
13,
58,
17900,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
297,
2812,
395,
953,
327,
5579,
288,
334,
82,
13445,
68,
11,
1547,
60,
68,
11,
6393,
60,
3134,
68,
10,
6113,
68,
7590,
3134,
68,
11,
1547
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
3442,
272,
18294,
2878,
339,
491,
476,
1192,
367,
3473,
10815,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
199,
504,
13277,
14,
1974,
492,
25591,
63,
6742,
199,
504,
13277,
14,
11729,
492,
21125,
12,
12939,
5838,
12,
10259,
12,
2387,
12,
971,
272,
12149,
12,
886,
63,
262,
13049,
199,
504,
13277,
14,
1418,
492,
6819,
12,
2624,
12,
10357,
12,
6431,
12,
2812,
12,
971,
272,
11013,
12,
4860,
12,
4516,
12,
8307,
199,
199,
504,
13277,
14,
12245,
14,
643,
441,
492,
2018,
5838,
199,
504,
13277,
14,
12245,
492,
485,
551,
24142,
63,
10372,
199,
504,
13277,
14,
12245,
492,
485,
9746,
63,
10372,
199,
199,
363,
452,
363,
275,
788,
42,
13987,
65,
5838,
297,
283,
42,
13987,
65,
9270,
5838,
297,
283,
16215,
32420,
5838,
297,
283,
14817,
5561,
5838,
297,
1779,
283,
14817,
5561,
4434,
5838,
297,
283,
17584,
811,
5838,
297,
283,
7181,
24142,
5838,
297,
283,
5667,
2713,
5838,
297,
1779,
283,
50,
9270,
5838,
297,
283,
4929,
5273,
297,
283,
42,
7391,
5838,
297,
283,
1713,
458,
5838,
297,
283,
933,
290,
5838,
297,
1779,
283,
998,
4464,
5273,
297,
283,
50,
68,
5838,
297,
283,
41,
2904,
5838,
418,
421,
199,
533,
1603,
13987,
65,
5838,
8,
19856,
304,
272,
408,
272,
2104,
658,
42,
13987,
65,
665,
1014,
921,
74,
13987,
279,
621,
14,
1308,
3133,
18417,
1350,
1233,
14,
339,
627,
4665,
315,
14493,
413,
14,
22,
2795,
272,
408,
272,
536,
275,
283,
42,
13987,
65,
7,
272,
5481,
275,
788,
74,
13987,
65,
1673,
74,
76,
418,
272,
6203,
275,
17855,
74,
76,
418,
272,
13290,
275,
788,
505,
15,
88,
13,
74,
13987,
65,
1673,
3578,
15,
88,
13,
74,
13987,
65,
418,
339,
12963,
275,
359,
267,
283,
2224,
1673,
11345,
83,
1673,
3773,
1673,
912,
1673,
374,
1673,
13655,
1673,
572,
537,
1673,
23426,
1673,
2960,
297,
267,
283,
343,
1363,
1673,
1535,
1673,
2227,
1673,
30092,
1673,
3916,
1673,
20422,
1673,
10512,
297,
267,
283,
466,
827,
1673,
466,
988,
1673,
3093,
827,
1673,
3093,
988,
1673,
12590,
1673,
8277,
1673,
20422,
63,
466,
297,
267,
283,
765,
63,
2444,
1673,
30002,
1673,
15195,
1673,
68,
8329,
1673,
68,
478,
12828,
1673,
2253,
297,
267,
283,
705,
1673,
11964,
1673,
479,
1673,
1222,
1673,
17354,
1673,
27531,
1673,
1038,
1673,
1017,
297,
272,
1622,
339,
4645,
275,
469,
267,
283,
1231,
356,
359,
288,
334,
82,
1154,
78,
297,
4516,
395,
288,
334,
82,
29538,
51,
60,
78,
11529,
4516,
395,
288,
334,
82,
11525,
2795,
4268,
6819,
395,
288,
334,
82,
3894,
61,
2440,
26,
1062,
27,
14251,
4300,
10357,
395,
288,
334,
82,
32190,
78,
297,
4516,
395,
288,
334,
82,
8124,
297,
4516,
395,
953,
327,
7681,
288,
334,
82,
6774,
5037,
92,
6710,
92,
509,
92,
262,
92,
1107,
92,
4785,
92,
6958,
5227,
1467,
519,
6704,
645,
293,
92,
3513,
92,
2723,
92,
692,
92,
2836,
692,
92,
2836,
92,
893,
92,
9341,
92,
500,
5227,
1467,
519,
7,
2075,
20615,
92,
67,
1250,
92,
1117,
92,
4941,
92,
578,
92,
646,
92,
3790,
5227,
1467,
519,
7,
646,
452,
92,
14890,
578,
92,
17836,
2862,
66,
297,
6431,
395,
288,
334,
82,
6774,
1832,
92,
2966,
92,
1297,
2862,
66,
297,
6431,
14,
17737,
395,
288,
334,
82,
6774,
10349,
92,
3241,
92,
3241,
24,
92,
3241,
975,
92,
3241,
708,
92,
3241,
772,
92,
23448,
92,
23448,
24,
92,
23448,
975,
92,
23448,
708,
92,
23448,
772,
7,
1467,
519,
17018,
5136,
708,
92,
5136,
772,
92,
14500,
772,
92,
14500,
3933,
92,
9874,
92,
19627,
92,
403,
2862,
66,
297,
355,
6431,
14,
804,
395,
953,
327,
3423,
288,
334,
82,
6774,
1593,
9,
17304,
3427,
83,
92,
9780,
83,
6393,
3196,
355,
10259,
8,
10650,
12,
985,
14,
3481,
395,
283,
29577,
659,
953,
327,
2943,
288,
334,
82,
6774,
466,
92,
466,
3620,
92,
6198,
9,
17304,
3427,
83,
92,
9780,
83,
6393,
3196,
355,
10259,
8,
10650,
12,
985,
14,
2543,
395,
283,
18596,
659,
953,
327,
10211,
288,
334,
82,
7,
389,
92,
1111,
92,
12932,
92,
8119,
92,
5118,
92,
12574,
6113,
6113,
10644,
447,
92,
28,
26,
92,
1988,
94,
11,
6331,
5,
29,
16137,
6,
62,
18257,
31,
1,
4,
4300,
11013,
395,
288,
334,
82,
1154,
3134,
10,
6113,
3134,
62,
92,
4537,
1103,
6113,
3134,
15,
17780,
297,
11013,
395,
953,
327,
12963,
288,
661,
360,
435,
21590,
904,
8,
10372,
9,
435,
519,
24431,
66,
297,
221,
2812,
14,
12306,
395,
953,
327,
1771,
10406,
288,
334,
82,
7,
64,
2229,
83,
680,
15279,
30880,
2624,
14,
4540,
8284,
395,
953,
327,
8365,
288,
334,
82,
4507,
8,
20942,
17780,
59,
16,
13,
23,
8194,
17,
12,
19,
93,
17780,
88,
59,
65,
13,
13753,
13,
38,
16,
13,
25,
8194,
17,
12,
19,
93,
17780,
85,
59,
65,
13,
13753,
13,
38,
16,
13,
25,
8194,
17,
12,
20,
22441,
2,
1467,
519,
22996,
53,
59,
65,
13,
13753,
13,
38,
16,
13,
25,
8194,
17,
12,
22,
22441,
4735,
9780,
1154,
78,
566,
4662,
2624,
14,
1610,
395,
953,
327,
862,
370,
1336,
8520,
16992,
288,
334,
82,
10120,
28,
1524,
3134,
87,
13670,
3934,
3985,
7386,
11013,
395,
953,
327,
3326,
288,
334,
82,
20459,
59,
1193,
566,
6949,
2624,
12,
283,
875,
659,
288,
334,
82,
3894,
37,
11843,
6949,
2624,
12,
12149,
360,
495,
17081,
3588,
297,
283,
875,
3855,
953,
327,
1561,
288,
334,
82,
20812,
59,
65,
13,
6353,
13,
58,
16,
13,
25,
3754,
11529,
2812,
14,
14946,
395,
288,
334,
82,
3894,
65,
13,
6353,
13,
58,
17900,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
297,
2812,
395,
953,
327,
5579,
288,
334,
82,
13445,
68,
11,
1547,
60,
68,
11,
6393,
60,
3134,
68,
10,
6113,
68,
7590,
3134,
68,
11,
1547,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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ils.py
|
1
|
32585
|
import maya.cmds as cmds
from P4 import P4,P4Exception
import os, cPickle
from functools import partial
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def p4_getLatestRevision(fileName, *args):
fileArg = fileName
#try to connect
p4 = P4()
try:
p4.connect()
except:
cmds.confirmDialog(title = "Perforce", icon = "critical", message = "Unable to connect to perforce server.")
return
#find currently opened file name
if fileName == None:
fileName = cmds.file(q = True, sceneName = True)
syncFiles = []
try:
#client info
spec = p4.run( "client", "-o" )[0]
client = spec.get("Client")
owner = spec.get("Owner")
p4.user = owner
p4.client = client
except:
cmds.confirmDialog(title = "Perforce", icon = "critical", message = "Unable to obtain client spec information.")
#try to get the current file revision on local, and compare to depot
try:
#Find out the revision of the local version of the file
myFile = p4.run_have(fileName)[0]
#This will find the revision number of your local file.
localRevision = int(myFile['haveRev'])
#find out the revision number of the depot version of the file
depotVersion = p4.run_files(myFile['depotFile'])[0]
#find the depot file path
depotFile = depotVersion['depotFile']
#find the depot revision number of the file
depotRevision = int(depotVersion['rev'])
#check for latest
if localRevision != depotRevision:
syncFiles.append(depotFile)
#Check for scene references in the file
allRefs = []
references = cmds.file(q = True, reference = True)
for reference in references:
nestedRef = cmds.file(reference, q = True, reference = True)
allRefs.append(reference)
allRefs.append(nestedRef)
#loop through all found references and check for latest
for ref in allRefs:
#get revision of local file
myFile = p4.run_have(ref)[0]
#get revision number
localRefRevision = int(myFile['haveRev'])
#grab depot file info
depotRefVersion = p4.run_files(myFile['depotFile'])[0]
#depot file path
depotFile = depotRefVersion['depotFile']
#get depot's revision #
depotRefRevision = int(depotRefVersion['rev'])
#compare
if localRefRevision != depotRefRevision:
syncFiles.append(depotFile)
#if there are files to sync, do it now
if len(syncFiles) > 0:
message = "The following files are not at latest revision:\n\n"
for file in syncFiles:
message += file + "\n"
result = cmds.confirmDialog(title = "Perforce", icon = "warning", message = message, button = ["Sync", "Cancel"])
if result == "Sync":
#sync files
for f in syncFiles:
p4.run_sync(f)
#ask if user would like to reopen
if fileArg == None:
result = cmds.confirmDialog(title = "Perforce", icon = "question", message = "Sync Complete. Reopen file to get changes?", button = ["Yes", "Cancel"])
if result == "Yes":
cmds.file(fileName, open = True, force = True)
else:
cmds.confirmDialog(title = "Perforce", icon = "information", message = "This file is already at head revision.", button = "Close")
#disconnect from server
p4.disconnect()
#Handle any p4 errors that come back from trying to run the above code
except P4Exception:
errorString = "The following errors were encountered:\n\n"
for e in p4.errors:
errorString += e + "\n"
cmds.confirmDialog(title = "Perforce", icon = "critical", message = errorString)
p4.disconnect()
return
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def p4_checkOutCurrentFile(fileName, *args):
fileArg = fileName
#try to connect
p4 = P4()
try:
p4.connect()
except:
cmds.confirmDialog(title = "Perforce", icon = "critical", message = "Unable to connect to perforce server.")
return False
#find currently opened file name
if fileName == None:
fileName = cmds.file(q = True, sceneName = True)
reopen = False
syncFiles = []
try:
#client info
spec = p4.run( "client", "-o" )[0]
client = spec.get("Client")
owner = spec.get("Owner")
p4.user = owner
p4.client = client
except:
cmds.confirmDialog(title = "Perforce", icon = "critical", message = "Unable to obtain client spec information.")
try:
#check to see if file is at head revision
myFile = p4.run_have(fileName)[0]
#This will find the revision number of your local file.
localRevision = int(myFile['haveRev'])
#find out the revision number of the depot version of the file
depotVersion = p4.run_files(myFile['depotFile'])[0]
#find the depot file path
depotFile = depotVersion['depotFile']
#find the depot revision number of the file
depotRevision = int(depotVersion['rev'])
#check for latest
if localRevision != depotRevision:
result = cmds.confirmDialog(title = "Perforce", icon = "warning", message = "This file is not at head revision. Please get latest and try again.", button = ["Get Latest", "Cancel"])
if result == "Get Latest":
p4_getLatestRevision(fileArg)
p4.disconnect()
else:
return False
else:
try:
#check to see if file is checked out
opened = p4.run_opened(depotFile)
if len(opened) > 0:
user = opened[0]['user']
cmds.confirmDialog(title = "Perforce", icon = "warning", message = "This file is already checked out by: " + user, button = "Close")
p4.disconnect()
else:
#check out the file
p4.run_edit(depotFile)
cmds.confirmDialog(title = "Perfoce", icon = "information", message = "This file is now checked out.", button = "Close")
p4.disconnect()
#tools path
toolsPath = cmds.internalVar(usd = True) + "mayaTools.txt"
if os.path.exists(toolsPath):
f = open(toolsPath, 'r')
mayaToolsDir = f.readline()
f.close()
return True
#Handle any p4 errors that come back from trying to run the above code
except P4Exception:
errorString = "The following errors were encountered:\n\n"
for e in p4.errors:
errorString += e + "\n"
cmds.confirmDialog(title = "Perforce", icon = "critical", message = errorString)
return False
#Handle any p4 errors that come back from trying to run the above code
except P4Exception:
errorString = "The following errors were encountered:\n\n"
for e in p4.errors:
errorString += e + "\n"
cmds.confirmDialog(title = "Perforce", icon = "critical", message = errorString)
p4.disconnect()
return False
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def p4_getRevisionHistory(*args):
#try to connect
p4 = P4()
try:
p4.connect()
except:
cmds.confirmDialog(title = "Perforce", icon = "critical", message = "Unable to connect to perforce server.")
return
#find currently opened file name
clientFile = cmds.file(q = True, sceneName = True)
reopen = False
syncFiles = []
try:
#client info
spec = p4.run( "client", "-o" )[0]
client = spec.get("Client")
owner = spec.get("Owner")
p4.user = owner
p4.client = client
except:
cmds.confirmDialog(title = "Perforce", icon = "critical", message = "Unable to obtain client spec information.")
#get revision history of current file
try:
#check to see if file is at head revision
myFile = p4.run_have(clientFile)[0]
depotVersion = p4.run_files(myFile['depotFile'])[0]
depotFile = depotVersion['depotFile']
history = p4.run_changes(depotFile)
info = ""
for h in history:
user = h.get("user")
change = h.get("change")
desc = h.get("desc")
if desc.find("\n") == -1:
desc = desc + "...\n"
else:
desc = desc.partition("\n")[0] + "...\n"
info += change + " by " + user + ": " + desc
#print report into a confirm dialog
cmds.confirmDialog(title = "History", icon = "information", ma = "left", message = info, button = "Close")
p4.disconnect()
except P4Exception:
errorString = "The following errors were encountered:\n\n"
for e in p4.errors:
errorString += e + "\n"
cmds.confirmDialog(title = "Perforce", icon = "critical", message = errorString)
p4.disconnect()
return
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def p4_submitCurrentFile(fileName, desc, *args):
fileArg = fileName
#try to connect
p4 = P4()
try:
p4.connect()
except:
cmds.confirmDialog(title = "Perforce", icon = "critical", message = "Unable to connect to perforce server.")
return
#find currently opened file name
if fileName == None:
fileName = cmds.file(q = True, sceneName = True)
reopen = False
syncFiles = []
try:
#client info
spec = p4.run( "client", "-o" )[0]
client = spec.get("Client")
owner = spec.get("Owner")
p4.user = owner
p4.client = client
except:
cmds.confirmDialog(title = "Perforce", icon = "critical", message = "Unable to obtain client spec information.")
#SUBMIT
try:
if desc == None:
result = cmds.promptDialog(title = "Perforce", message = "Please Enter a Description..", button = ["Accept", "Cancel"], defaultButton = "Accept", dismissString = "Cancel", cancelButton = "Cancel")
else:
result = "Accept"
#process
if result == "Accept":
#description = "test"
myFile = p4.run_have(fileName)[0]
depotVersion = p4.run_files(myFile['depotFile'])[0]
depotFile = depotVersion['depotFile']
#check to see if file is checked out
opened = p4.run_opened(depotFile)
if len(opened) > 0:
opendBy = opened[0]['user']
if opendBy.lower() != owner.lower():
cmds.confirmDialog(title = "Perforce", icon = "warning", message = "This file is already checked out by: " + opendBy, button = "Close")
p4.disconnect()
return
else:
#fetch the description
if desc == None:
desc = cmds.promptDialog(q = True, text = True)
#save the file locally (so depot and HD are in sync)
openedFile = cmds.file(q = True, sceneName = True)
saveFileName = openedFile.rpartition("/")[2]
if fileArg == None:
cmds.file(f = True, save = True, options = "v = 0", type = "mayaBinary")
#grab the name of the file
fileNameWithExt = openedFile.rpartition("/")[2]
fileName = fileNameWithExt.rpartition(".")[0]
description = (desc + "\n Affected Files: " + openedFile)
#create new changelist
newChange = p4.fetch_change()
newChange._description = description
#make sure we don't add existing default changelist files.
newChange._files = []
#determine the new number so we can refetch it.
newChangeNum = int(p4.save_change(newChange)[0].split()[1])
#change changelist number
p4.run_reopen('-c', newChangeNum, depotFile)
#submit the changelist
p4.run_submit('-c', newChangeNum)
#tell the user submit was successful
if fileArg == None:
cmds.confirmDialog(title = "Perforce", icon = "information", message = "Submit Operation was successful!", button = "Close")
else:
return True
else:
#if the file is not checked out by the user, let them know
result = cmds.confirmDialog(title = "Perforce", icon = "warning", message = "File is not checked out. Unable to continue submit operation on this file:\n\n" + fileName)
except P4Exception:
if fileArg == None:
errorString = "The following errors were encountered:\n\n"
for e in p4.errors:
errorString += e + "\n"
cmds.confirmDialog(title = "Perforce", icon = "critical", message = errorString)
p4.disconnect()
return False
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def p4_addAndSubmitCurrentFile(fileName, description, *args):
fileArg = fileName
#try to connect
p4 = P4()
try:
p4.connect()
except:
cmds.confirmDialog(title = "Perforce", icon = "critical", message = "Unable to connect to perforce server.")
return
#find currently opened file name
if fileName == None:
fileName = cmds.file(q = True, sceneName = True)
reopen = False
syncFiles = []
try:
#client info
spec = p4.run( "client", "-o" )[0]
client = spec.get("Client")
owner = spec.get("Owner")
p4.user = owner
p4.client = client
except:
cmds.confirmDialog(title = "Perforce", icon = "critical", message = "Unable to obtain client spec information.")
#find currently opened file name
proceed = False
if fileArg == None:
fileName = cmds.file(q = True, sceneName = True)
if fileName == "":
cmds.confirmDialog(title = "Perforce", icon = "warning", message = "Cannot Add file to perforce as file has no name.", button = "Close")
p4.disconnect()
return
else:
proceed = True
else:
proceed = True
#if the file has a filename,
if proceed:
try:
clientRoot = p4.fetch_client(p4.client)._Root
#check to make sure client root is in the client file path
if os.path.normpath(fileName).find(os.path.normpath(clientRoot)) == 0:
#if it was, then get a description for the changelist
if description == None:
result = cmds.promptDialog(title = "Perforce", message = "Please Enter a Description..", button = ["Accept", "Cancel"], defaultButton = "Accept", dismissString = "Cancel", cancelButton = "Cancel")
else:
result = "Accept"
if result == "Accept":
#get changelist description
if description == None:
description = cmds.promptDialog(q = True, text = True)
#create changelist
newChange = p4.fetch_change()
newChange._description = description
#make sure we don't add existing default changelist files.
newChange._files = []
#determine the new number so we can refetch it.
newChangeNum = int(p4.save_change(newChange)[0].split()[1])
#description = "test"
p4.run_add('-c', newChangeNum, fileName)
#submit the changelist
p4.run_submit('-c', newChangeNum)
#tell user operation was successful
if fileArg == None:
result = cmds.confirmDialog(title = "Perforce", icon = "information", message = "File has been successfully added to perforce and submitted!", button = ["Close", "Check Out File"])
if result == "Close":
p4.disconnect()
return
if result == "Check Out File":
p4_checkOutCurrentFile(fileName)
#return operation succuessful
return True
else:
p4.disconnect()
return
else:
cmds.confirmDialog(title = "Perforce", icon = "warning", message = "Cannot proceed. File is not under client's root, " + clientRoot, button = "Close")
p4.disconnect()
return False
except P4Exception:
errorString = "The following errors were encountered:\n\n"
for e in p4.errors:
errorString += e + "\n"
cmds.confirmDialog(title = "Perforce", icon = "critical", message = errorString)
p4.disconnect()
return False
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def p4_checkForUpdates(*args):
#try to connect
p4 = P4()
#get maya tools path
toolsPath = cmds.internalVar(usd = True) + "mayaTools.txt"
if os.path.exists(toolsPath):
f = open(toolsPath, 'r')
mayaToolsDir = f.readline()
f.close()
#connect to p4
try:
p4.connect()
except:
cmds.confirmDialog(title = "Perforce", icon = "critical", message = "Unable to connect to perforce server.")
return
#find currently opened file name
clientFile = cmds.file(q = True, sceneName = True)
reopen = False
syncFiles = []
try:
#client info
spec = p4.run( "client", "-o" )[0]
client = spec.get("Client")
owner = spec.get("Owner")
p4.user = owner
p4.client = client
except:
cmds.confirmDialog(title = "Perforce", icon = "critical", message = "Unable to obtain client spec information.")
#this will check the maya tools directory in p4 for any updates
try:
syncFiles = []
clientRoot = p4.fetch_client(p4.client)._Root
depotDirectories = []
#get current project
if os.path.exists(mayaToolsDir + "/General/Scripts/projectSettings.txt"):
#read to find current project
f = open(mayaToolsDir + "/General/Scripts/projectSettings.txt", 'r')
settings = cPickle.load(f)
f.close()
#write out new settings
project = settings.get("CurrentProject")
if os.path.exists(mayaToolsDir + "/General/Scripts/" + project + "_Project_Settings.txt"):
#read the depot paths to sync from the project settings
f = open(mayaToolsDir + "/General/Scripts/" + project + "_Project_Settings.txt", 'r')
settings = cPickle.load(f)
f.close()
depotDirectories = settings.get("depotPaths")
print depotDirectories
#look at each directory inside MayaTools
for dir in depotDirectories:
depotFiles = p4.run_files(dir + "...")
for each in depotFiles:
#try to compare depot to local. It is possible that there are local files not in depot, and vise versa
try:
fileInfo = p4.run_files(each['depotFile'])[0]
depotFilePath = fileInfo['depotFile']
fileName = depotFilePath.rpartition("/")[2]
#compare local files
localFile = p4.run_have(depotFilePath)[0]
localRevision = int(localFile['haveRev'])
depotRevision = int(fileInfo['rev'])
if localRevision < depotRevision:
syncFiles.append(depotFilePath)
except:
try:
#check to see if it errors out because we don't have a local version of the file
fileInfo = p4.run_files(each['depotFile'])[0]
depotFilePath = fileInfo['depotFile']
fileName = depotFilePath.rpartition("/")[2]
localFile = p4.run_have(depotFilePath)[0]
except:
action = each.get("action")
if action != "delete":
syncFiles.append(depotFilePath)
pass
#check size of syncFiles and ask user if they want to sync
if len(syncFiles) > 0:
result = cmds.confirmDialog(title = "MayaTools", icon = "warning", message = "There are new updates available to the depot directories specified by your project settings.", button = ["Update", "Not Now"])
if result == "Update":
for file in syncFiles:
p4.run_sync(file)
cmds.confirmDialog(title = "MayaTools", icon = "information", message = "Tools are now up to date!", button = "Close")
p4.disconnect()
else:
p4.disconnect()
return
#handle any errors
except P4Exception:
errorString = "The following errors were encountered:\n\n"
for e in p4.errors:
errorString += e + "\n"
cmds.confirmDialog(title = "Perforce", icon = "critical", message = errorString)
p4.disconnect()
return
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def createNewProject(*args):
if cmds.window("createNewARTProject_Window", exists = True):
cmds.deleteUI("createNewARTProject_Window")
#create window
window = cmds.window("createNewARTProject_Window", w = 400, h = 600, mnb = False, mxb = False, title = "Create New Project")
#frameLayouts for settings: Perforce/Auto-Sync
mainLayout = cmds.columnLayout(w = 400, h = 600)
#project name field
projectName = cmds.textFieldGrp("newARTProjectNameField", label = "Project Name: ", w = 400, h = 30, parent = mainLayout, cal = [1, "left"])
scrollLayout = cmds.scrollLayout(w = 400, h = 520, parent = mainLayout)
columnLayout = cmds.columnLayout(w = 380, parent = scrollLayout)
#perforce/auto-sync layout
p4Frame = cmds.frameLayout(parent = columnLayout, w = 370, cll = True, label='Perforce/Auto-Sync', borderStyle='in')
p4Layout = cmds.columnLayout(w = 360, parent = p4Frame, co = ["both", 5], rs = 5)
#create the scrollField with the information
cmds.scrollField(parent = p4Layout, w = 350, h = 100, editable = False, wordWrap = True, text = "Add depot paths you would like the tools to check for updates on. If updates are found, you will be notified, and asked if you would like to sync. Valid depot paths look like:\n\n//depot/usr/jeremy_ernst/MayaTools")
#crete the add button
cmds.button(w = 350, label = "Add Perforce Depot Path", parent = p4Layout, c = partial(addPerforceDepotPath, p4Layout))
#save settings button
cmds.button(parent = mainLayout, w = 400, h = 50, label = "Save Settings and Close", c = partial(saveProjectSettings, p4Layout, False))
#show window
cmds.showWindow(window)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def editProject(project, *args):
if cmds.window("createNewARTProject_Window", exists = True):
cmds.deleteUI("createNewARTProject_Window")
#create window
window = cmds.window("createNewARTProject_Window", w = 400, h = 600, mnb = False, mxb = False, title = "Edit Project")
#frameLayouts for settings: Perforce/Auto-Sync
mainLayout = cmds.columnLayout(w = 400, h = 600)
#project name field
projectName = cmds.textFieldGrp("newARTProjectNameField", label = "Project Name: ", text = project, w = 400, h = 30, parent = mainLayout, cal = [1, "left"])
scrollLayout = cmds.scrollLayout(w = 400, h = 520, parent = mainLayout)
columnLayout = cmds.columnLayout(w = 380, parent = scrollLayout)
#perforce/auto-sync layout
p4Frame = cmds.frameLayout(parent = columnLayout, w = 370, cll = True, label='Perforce/Auto-Sync', borderStyle='in')
p4Layout = cmds.columnLayout(w = 360, parent = p4Frame, co = ["both", 5], rs = 5)
#create the scrollField with the information
cmds.scrollField(parent = p4Layout, w = 350, h = 100, editable = False, wordWrap = True, text = "Add depot paths you would like the tools to check for updates on. If updates are found, you will be notified, and asked if you would like to sync. Valid depot paths look like:\n\n//depot/usr/jeremy_ernst/MayaTools")
#crete the add button
cmds.button(w = 350, label = "Add Perforce Depot Path", parent = p4Layout, c = partial(addPerforceDepotPath, p4Layout))
#get maya tools path
toolsPath = cmds.internalVar(usd = True) + "mayaTools.txt"
if os.path.exists(toolsPath):
f = open(toolsPath, 'r')
mayaToolsDir = f.readline()
f.close()
#open the project settings and auto-fill in the info
if os.path.exists(mayaToolsDir + "/General/Scripts/" + project + "_Project_Settings.txt"):
f = open(mayaToolsDir + "/General/Scripts/" + project + "_Project_Settings.txt", 'r')
settings = cPickle.load(f)
f.close()
paths = settings.get("depotPaths")
if len(paths) > 0:
for path in paths:
#add the path
field = addPerforceDepotPath(p4Layout)
cmds.textField(field, edit = True, text = path)
#save settings button
cmds.button(parent = mainLayout, w = 400, h = 50, label = "Save Settings and Close", c = partial(saveProjectSettings, p4Layout, True))
#show window
cmds.showWindow(window)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def addPerforceDepotPath(layout, *args):
field = cmds.textField(docTag = "P4DepotPath", w = 350, parent = layout)
#add a RMB menu to remove the field
menu = cmds.popupMenu(parent = field, b = 3)
cmds.menuItem(parent = menu, label = "Remove Path", c = partial(removePerforceDepotPath, field))
return field
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def removePerforceDepotPath(field, *args):
cmds.textField(field, edit = True, visible = False, h = 1)
#cmds.deleteUI(field) This crashes maya instantly. Come ON AUTODESK
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def saveProjectSettings(perforceLayout, edit, *args):
#find p4 depot path textfields
children = cmds.columnLayout(perforceLayout, q = True, childArray = True)
textFields = []
for child in children:
if child.find("textField") == 0:
data = cmds.textField(child, q = True, docTag = True)
if data == "P4DepotPath":
textFields.append(child)
#make sure paths are valid
savePaths = []
for field in textFields:
path = cmds.textField(field, q = True, text = True)
if path != "":
try:
p4 = P4()
p4.connect()
except:
cmds.confirmDialog(title = "Perforce", icon = "critical", message = "Unable to connect to perforce server.")
return
try:
#client info
spec = p4.run( "client", "-o" )[0]
client = spec.get("Client")
owner = spec.get("Owner")
p4.user = owner
p4.client = client
except:
cmds.confirmDialog(title = "Perforce", icon = "critical", message = "Unable to obtain client spec information.")
#now check
try:
depotFiles = p4.run_files(path + "...")
if len(depotFiles) > 0:
savePaths.append(path)
#handle any errors
except P4Exception:
errorString = "The following errors were encountered:\n\n"
for e in p4.errors:
errorString += e + "\n"
cmds.confirmDialog(title = "Perforce", icon = "critical", message = errorString)
p4.disconnect()
return
else:
#see if the text field is just hidden or if it is actually blank
vis = cmds.textField(field, q = True, visible = True)
if vis == True:
cmds.confirmDialog(title = "Error", icon = "critical", message = "Empty string not allowed as a path name. Either remove that field, or enter a correct depot path.")
return
#write out to disk
projectName = cmds.textFieldGrp("newARTProjectNameField", q = True, text = True)
if projectName == "":
cmds.confirmDialog(title = "Error", icon = "critical", message = "Empty string not allowed as a project name.")
return
#save the new project file under MayaTools/General/Scripts as projName + "_Project_Settings.txt"
toolsPath = cmds.internalVar(usd = True) + "mayaTools.txt"
if os.path.exists(toolsPath):
f = open(toolsPath, 'r')
mayaToolsDir = f.readline()
f.close()
if edit == False:
if os.path.exists(mayaToolsDir + "/General/Scripts/" + projectName + "_Project_Settings.txt"):
cmds.confirmDialog(title = "Error", icon = "critical", message = "Project already exists with that name")
return
#save out
f = open(mayaToolsDir + "/General/Scripts/" + projectName + "_Project_Settings.txt", 'w')
#create a dictionary with values
settings = {}
settings["depotPaths"] = savePaths
#write our dictionary to file
cPickle.dump(settings, f)
f.close()
#delete the UI
cmds.deleteUI("createNewARTProject_Window")
#add the project to the menu
create = True
items = cmds.lsUI(menuItems = True)
for i in items:
data = cmds.menuItem(i, q = True, docTag = True)
if data == "P4Proj":
label = cmds.menuItem(i, q = True, label = True)
print label
if label == projectName:
create = False
if create:
menuItem = cmds.menuItem(label = projectName, parent = "perforceProjectList", cl = "perforceProjectRadioMenuCollection", rb = True, docTag = "P4Proj", c = partial(setCurrentProject, projectName))
cmds.menuItem(parent = "perforceProjectList", optionBox = True, c = partial(editProject, projectName))
#open up the projectSettings.txt file and add an entry for current project
if os.path.exists(mayaToolsDir + "/General/Scripts/projectSettings.txt"):
f = open(mayaToolsDir + "/General/Scripts/projectSettings.txt", 'r')
oldSettings = cPickle.load(f)
useSourceControl = oldSettings.get("UseSourceControl")
f.close()
#write out new settings
settings = {}
settings["UseSourceControl"] = useSourceControl
settings["CurrentProject"] = projectName
f = open(mayaToolsDir + "/General/Scripts/projectSettings.txt", 'w')
cPickle.dump(settings, f)
f.close()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def setCurrentProject(projectName, *args):
#get access to maya tools path
toolsPath = cmds.internalVar(usd = True) + "mayaTools.txt"
if os.path.exists(toolsPath):
f = open(toolsPath, 'r')
mayaToolsDir = f.readline()
f.close()
#re-write settings
if os.path.exists(mayaToolsDir + "/General/Scripts/projectSettings.txt"):
f = open(mayaToolsDir + "/General/Scripts/projectSettings.txt", 'r')
oldSettings = cPickle.load(f)
useSourceControl = oldSettings.get("UseSourceControl")
f.close()
#write out new settings
settings = {}
settings["UseSourceControl"] = useSourceControl
settings["CurrentProject"] = projectName
f = open(mayaToolsDir + "/General/Scripts/projectSettings.txt", 'w')
cPickle.dump(settings, f)
f.close()
|
bsd-2-clause
|
[
646,
1443,
65,
14,
12975,
465,
11465,
202,
202,
199,
504,
510,
20,
492,
510,
20,
12,
48,
20,
1726,
202,
202,
199,
646,
747,
12,
17572,
202,
202,
199,
504,
9143,
492,
7417,
202,
2999,
202,
199,
3,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
20712,
202,
199,
318,
299,
20,
63,
362,
31438,
12714,
8,
15450,
12,
627,
589,
304,
202,
1128,
570,
6373,
275,
18305,
202,
1128,
327,
893,
370,
4907,
202,
1128,
299,
20,
275,
510,
20,
342,
202,
8428,
202,
1128,
862,
26,
202,
1039,
299,
20,
14,
2242,
342,
202,
8740,
202,
1128,
871,
26,
202,
1039,
11465,
14,
9548,
5619,
8,
1213,
275,
298,
2623,
3990,
401,
7016,
275,
298,
13138,
401,
1245,
275,
298,
6005,
370,
4907,
370,
1126,
3990,
1654,
2685,
202,
1039,
372,
202,
8428,
202,
1128,
327,
1623,
5544,
12123,
570,
536,
202,
1128,
340,
18305,
508,
488,
26,
202,
1223,
198,
15450,
275,
11465,
14,
493,
8,
81,
275,
715,
12,
13856,
985,
275,
715,
9,
202,
4122,
202,
1128,
7604,
5535,
275,
942,
202,
8428,
202,
8428,
202,
1128,
862,
26,
202,
1223,
198,
3,
1258,
2256,
202,
1223,
198,
1650,
275,
299,
20,
14,
1065,
8,
298,
1258,
401,
3905,
79,
2,
29688,
16,
61,
202,
1223,
198,
1258,
275,
3158,
14,
362,
480,
3041,
531,
202,
1223,
198,
4597,
275,
3158,
14,
362,
480,
14919,
531,
198,
202,
1223,
198,
80,
20,
14,
751,
275,
5771,
202,
1223,
198,
80,
20,
14,
1258,
275,
1890,
202,
8740,
202,
1128,
871,
26,
202,
1039,
11465,
14,
9548,
5619,
8,
1213,
275,
298,
2623,
3990,
401,
7016,
275,
298,
13138,
401,
1245,
275,
298,
6005,
370,
3332,
1890,
3158,
2556,
2685,
202,
8428,
202,
8428,
202,
8428,
202,
1128,
327,
893,
370,
664,
314,
1453,
570,
6974,
641,
2257,
12,
436,
6540,
370,
32544,
202,
1128,
862,
26,
202,
1039,
327,
6591,
734,
314,
6974,
402,
314,
2257,
1015,
402,
314,
570,
202,
1039,
3002,
1173,
275,
299,
20,
14,
1065,
63,
7804,
8,
15450,
2788,
16,
61,
202,
8740,
202,
1039,
327,
2765,
911,
2342,
314,
6974,
1329,
402,
2195,
2257,
570,
14,
202,
1039,
2257,
12714,
275,
1109,
8,
1662,
1173,
459,
7804,
26176,
1105,
202,
8740,
202,
1039,
327,
1623,
734,
314,
6974,
1329,
402,
314,
32544,
1015,
402,
314,
570,
202,
1039,
32544,
3353,
275,
299,
20,
14,
1065,
63,
1725,
8,
1662,
1173,
459,
27834,
1173,
25945,
16,
61,
202,
8740,
202,
1039,
327,
1623,
314,
32544,
570,
931,
202,
1039,
32544,
1173,
275,
32544,
3353,
459,
27834,
1173,
418,
202,
8740,
202,
1039,
327,
1623,
314,
32544,
6974,
1329,
402,
314,
570,
202,
1039,
32544,
12714,
275,
1109,
8,
27834,
3353,
459,
4964,
1105,
260,
202,
8428,
202,
1039,
327,
1074,
367,
8839,
202,
1039,
340,
2257,
12714,
1137,
32544,
12714,
26,
202,
1675,
7604,
5535,
14,
740,
8,
27834,
1173,
9,
202,
20085,
202,
20085,
202,
8740,
202,
1039,
327,
1799,
367,
13856,
6941,
315,
314,
570,
202,
1039,
1006,
25730,
275,
942,
202,
1039,
6941,
275,
11465,
14,
493,
8,
81,
275,
715,
12,
3659,
275,
715,
9,
202,
1039,
367,
3659,
315,
6941,
26,
202,
1675,
6032,
2891,
275,
11465,
14,
493,
8,
4443,
12,
1894,
275,
715,
12,
3659,
275,
715,
9,
202,
1675,
1006,
25730,
14,
740,
8,
4443,
9,
202,
1675,
1006,
25730,
14,
740,
8,
6376,
2891,
9,
202,
17554,
202,
1039,
327,
3813,
4012,
1006,
1911,
6941,
436,
1104,
367,
8839,
202,
1039,
367,
2984,
315,
1006,
25730,
26,
202,
1675,
327,
362,
6974,
402,
2257,
570,
202,
1675,
3002,
1173,
275,
299,
20,
14,
1065,
63,
7804,
8,
1121,
2788,
16,
61,
202,
17554,
202,
1675,
327,
362,
6974,
1329,
202,
1675,
2257,
2891,
12714,
275,
1109,
8,
1662,
1173,
459,
7804,
26176,
1105,
20712,
17554,
202,
1675,
327,
22090,
32544,
570,
2256,
202,
1675,
32544,
2891,
3353,
275,
299,
20,
14,
1065,
63,
1725,
8,
1662,
1173,
459,
27834,
1173,
25945,
16,
61,
202,
17554,
202,
1675,
327,
27834,
570,
931,
202,
1675,
32544,
1173,
275,
32544,
2891,
3353,
459,
27834,
1173,
418,
202,
17554,
202,
1675,
327,
362,
32544,
1159,
6974,
327,
202,
1675,
32544,
2891,
12714,
275,
1109,
8,
27834,
2891,
3353,
459,
4964,
1105,
202,
17554,
202,
17554,
202,
1675,
327,
5785,
202,
1675,
340,
2257,
2891,
12714,
1137,
32544,
2891,
12714,
26,
202,
2628,
7604,
5535,
14,
740,
8,
27834,
1173,
9,
202,
17554,
202,
8428,
202,
8740,
202,
8740,
202,
1039,
327,
692,
2337,
787,
1584,
370,
7604,
12,
886,
652,
3063,
202,
1039,
340,
822,
8,
5186,
5535,
9,
690,
378,
26,
202,
1675,
1245,
275,
298,
1918,
2569,
1584,
787,
440,
737,
8839,
6974,
3427,
78,
60,
78,
2,
202,
1675,
367,
570,
315,
7604,
5535,
26,
202,
2628,
1245,
847,
570,
435,
1867,
78,
2,
202,
20085,
202,
1675,
754,
275,
11465,
14,
9548,
5619,
8,
1213,
275,
298,
2623,
3990,
401,
7016,
275,
298,
3764,
401,
1245,
275,
221,
1245,
12,
5528,
275,
2097,
10878,
401,
298,
9083,
3135,
202,
17554,
202,
1675,
340,
754,
508,
298,
10878,
582,
202,
2628,
327,
5186,
1584,
202,
2628,
367,
289,
315,
7604,
5535,
26,
202,
4906,
299,
20,
14,
1065,
63,
5186,
8,
70,
9,
202,
27843,
202,
2628,
327,
813,
340,
922,
3955,
2839,
370,
295,
1490,
202,
4122,
198,
692,
570,
6373,
508,
488,
26,
202,
7903,
259,
754,
275,
11465,
14,
9548,
5619,
8,
1213,
275,
298,
2623,
3990,
401,
7016,
275,
298,
4790,
401,
1245,
275,
221,
298,
10878,
28393,
14,
799,
1490,
570,
370,
664,
4493,
15583,
5528,
275,
2097,
12555,
401,
298,
9083,
3135,
202,
7903,
258,
202,
7903,
259,
340,
754,
508,
298,
12555,
582,
202,
7903,
198,
12975,
14,
493,
8,
15450,
12,
1551,
275,
715,
12,
3542,
275,
715,
9,
202,
7903,
258,
202,
1223,
198,
2836,
26,
202,
23755,
11465,
14,
9548,
5619,
8,
1213,
275,
298,
2623,
3990,
401,
7016,
275,
298,
11697,
401,
1245,
275,
298,
2765
] |
[
1443,
65,
14,
12975,
465,
11465,
202,
202,
199,
504,
510,
20,
492,
510,
20,
12,
48,
20,
1726,
202,
202,
199,
646,
747,
12,
17572,
202,
202,
199,
504,
9143,
492,
7417,
202,
2999,
202,
199,
3,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
327,
20712,
202,
199,
318,
299,
20,
63,
362,
31438,
12714,
8,
15450,
12,
627,
589,
304,
202,
1128,
570,
6373,
275,
18305,
202,
1128,
327,
893,
370,
4907,
202,
1128,
299,
20,
275,
510,
20,
342,
202,
8428,
202,
1128,
862,
26,
202,
1039,
299,
20,
14,
2242,
342,
202,
8740,
202,
1128,
871,
26,
202,
1039,
11465,
14,
9548,
5619,
8,
1213,
275,
298,
2623,
3990,
401,
7016,
275,
298,
13138,
401,
1245,
275,
298,
6005,
370,
4907,
370,
1126,
3990,
1654,
2685,
202,
1039,
372,
202,
8428,
202,
1128,
327,
1623,
5544,
12123,
570,
536,
202,
1128,
340,
18305,
508,
488,
26,
202,
1223,
198,
15450,
275,
11465,
14,
493,
8,
81,
275,
715,
12,
13856,
985,
275,
715,
9,
202,
4122,
202,
1128,
7604,
5535,
275,
942,
202,
8428,
202,
8428,
202,
1128,
862,
26,
202,
1223,
198,
3,
1258,
2256,
202,
1223,
198,
1650,
275,
299,
20,
14,
1065,
8,
298,
1258,
401,
3905,
79,
2,
29688,
16,
61,
202,
1223,
198,
1258,
275,
3158,
14,
362,
480,
3041,
531,
202,
1223,
198,
4597,
275,
3158,
14,
362,
480,
14919,
531,
198,
202,
1223,
198,
80,
20,
14,
751,
275,
5771,
202,
1223,
198,
80,
20,
14,
1258,
275,
1890,
202,
8740,
202,
1128,
871,
26,
202,
1039,
11465,
14,
9548,
5619,
8,
1213,
275,
298,
2623,
3990,
401,
7016,
275,
298,
13138,
401,
1245,
275,
298,
6005,
370,
3332,
1890,
3158,
2556,
2685,
202,
8428,
202,
8428,
202,
8428,
202,
1128,
327,
893,
370,
664,
314,
1453,
570,
6974,
641,
2257,
12,
436,
6540,
370,
32544,
202,
1128,
862,
26,
202,
1039,
327,
6591,
734,
314,
6974,
402,
314,
2257,
1015,
402,
314,
570,
202,
1039,
3002,
1173,
275,
299,
20,
14,
1065,
63,
7804,
8,
15450,
2788,
16,
61,
202,
8740,
202,
1039,
327,
2765,
911,
2342,
314,
6974,
1329,
402,
2195,
2257,
570,
14,
202,
1039,
2257,
12714,
275,
1109,
8,
1662,
1173,
459,
7804,
26176,
1105,
202,
8740,
202,
1039,
327,
1623,
734,
314,
6974,
1329,
402,
314,
32544,
1015,
402,
314,
570,
202,
1039,
32544,
3353,
275,
299,
20,
14,
1065,
63,
1725,
8,
1662,
1173,
459,
27834,
1173,
25945,
16,
61,
202,
8740,
202,
1039,
327,
1623,
314,
32544,
570,
931,
202,
1039,
32544,
1173,
275,
32544,
3353,
459,
27834,
1173,
418,
202,
8740,
202,
1039,
327,
1623,
314,
32544,
6974,
1329,
402,
314,
570,
202,
1039,
32544,
12714,
275,
1109,
8,
27834,
3353,
459,
4964,
1105,
260,
202,
8428,
202,
1039,
327,
1074,
367,
8839,
202,
1039,
340,
2257,
12714,
1137,
32544,
12714,
26,
202,
1675,
7604,
5535,
14,
740,
8,
27834,
1173,
9,
202,
20085,
202,
20085,
202,
8740,
202,
1039,
327,
1799,
367,
13856,
6941,
315,
314,
570,
202,
1039,
1006,
25730,
275,
942,
202,
1039,
6941,
275,
11465,
14,
493,
8,
81,
275,
715,
12,
3659,
275,
715,
9,
202,
1039,
367,
3659,
315,
6941,
26,
202,
1675,
6032,
2891,
275,
11465,
14,
493,
8,
4443,
12,
1894,
275,
715,
12,
3659,
275,
715,
9,
202,
1675,
1006,
25730,
14,
740,
8,
4443,
9,
202,
1675,
1006,
25730,
14,
740,
8,
6376,
2891,
9,
202,
17554,
202,
1039,
327,
3813,
4012,
1006,
1911,
6941,
436,
1104,
367,
8839,
202,
1039,
367,
2984,
315,
1006,
25730,
26,
202,
1675,
327,
362,
6974,
402,
2257,
570,
202,
1675,
3002,
1173,
275,
299,
20,
14,
1065,
63,
7804,
8,
1121,
2788,
16,
61,
202,
17554,
202,
1675,
327,
362,
6974,
1329,
202,
1675,
2257,
2891,
12714,
275,
1109,
8,
1662,
1173,
459,
7804,
26176,
1105,
20712,
17554,
202,
1675,
327,
22090,
32544,
570,
2256,
202,
1675,
32544,
2891,
3353,
275,
299,
20,
14,
1065,
63,
1725,
8,
1662,
1173,
459,
27834,
1173,
25945,
16,
61,
202,
17554,
202,
1675,
327,
27834,
570,
931,
202,
1675,
32544,
1173,
275,
32544,
2891,
3353,
459,
27834,
1173,
418,
202,
17554,
202,
1675,
327,
362,
32544,
1159,
6974,
327,
202,
1675,
32544,
2891,
12714,
275,
1109,
8,
27834,
2891,
3353,
459,
4964,
1105,
202,
17554,
202,
17554,
202,
1675,
327,
5785,
202,
1675,
340,
2257,
2891,
12714,
1137,
32544,
2891,
12714,
26,
202,
2628,
7604,
5535,
14,
740,
8,
27834,
1173,
9,
202,
17554,
202,
8428,
202,
8740,
202,
8740,
202,
1039,
327,
692,
2337,
787,
1584,
370,
7604,
12,
886,
652,
3063,
202,
1039,
340,
822,
8,
5186,
5535,
9,
690,
378,
26,
202,
1675,
1245,
275,
298,
1918,
2569,
1584,
787,
440,
737,
8839,
6974,
3427,
78,
60,
78,
2,
202,
1675,
367,
570,
315,
7604,
5535,
26,
202,
2628,
1245,
847,
570,
435,
1867,
78,
2,
202,
20085,
202,
1675,
754,
275,
11465,
14,
9548,
5619,
8,
1213,
275,
298,
2623,
3990,
401,
7016,
275,
298,
3764,
401,
1245,
275,
221,
1245,
12,
5528,
275,
2097,
10878,
401,
298,
9083,
3135,
202,
17554,
202,
1675,
340,
754,
508,
298,
10878,
582,
202,
2628,
327,
5186,
1584,
202,
2628,
367,
289,
315,
7604,
5535,
26,
202,
4906,
299,
20,
14,
1065,
63,
5186,
8,
70,
9,
202,
27843,
202,
2628,
327,
813,
340,
922,
3955,
2839,
370,
295,
1490,
202,
4122,
198,
692,
570,
6373,
508,
488,
26,
202,
7903,
259,
754,
275,
11465,
14,
9548,
5619,
8,
1213,
275,
298,
2623,
3990,
401,
7016,
275,
298,
4790,
401,
1245,
275,
221,
298,
10878,
28393,
14,
799,
1490,
570,
370,
664,
4493,
15583,
5528,
275,
2097,
12555,
401,
298,
9083,
3135,
202,
7903,
258,
202,
7903,
259,
340,
754,
508,
298,
12555,
582,
202,
7903,
198,
12975,
14,
493,
8,
15450,
12,
1551,
275,
715,
12,
3542,
275,
715,
9,
202,
7903,
258,
202,
1223,
198,
2836,
26,
202,
23755,
11465,
14,
9548,
5619,
8,
1213,
275,
298,
2623,
3990,
401,
7016,
275,
298,
11697,
401,
1245,
275,
298,
2765,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
linegroup/topicsketch
|
twokenize.py
|
8
|
12993
|
# -*- coding: utf-8 -*-
"""
Twokenize -- a tokenizer designed for Twitter text in English and some other European languages.
This tokenizer code has gone through a long history:
(1) Brendan O'Connor wrote original version in Python, http://github.com/brendano/tweetmotif
TweetMotif: Exploratory Search and Topic Summarization for Twitter.
Brendan O'Connor, Michel Krieger, and David Ahn.
ICWSM-2010 (demo track), http://brenocon.com/oconnor_krieger_ahn.icwsm2010.tweetmotif.pdf
(2a) Kevin Gimpel and Daniel Mills modified it for POS tagging for the CMU ARK Twitter POS Tagger
(2b) Jason Baldridge and David Snyder ported it to Scala
(3) Brendan bugfixed the Scala port and merged with POS-specific changes
for the CMU ARK Twitter POS Tagger
(4) Tobi Owoputi ported it back to Java and added many improvements (2012-06)
Current home is http://github.com/brendano/ark-tweet-nlp and http://www.ark.cs.cmu.edu/TweetNLP
There have been at least 2 other Java ports, but they are not in the lineage for the code here.
Ported to Python by Myle Ott <myleott@gmail.com>.
"""
from __future__ import print_function
import operator
import re
import HTMLParser
def regex_or(*items):
return '(?:' + '|'.join(items) + ')'
Contractions = re.compile(u"(?i)(\w+)(n['’′]t|['’′]ve|['’′]ll|['’′]d|['’′]re|['’′]s|['’′]m)$", re.UNICODE)
Whitespace = re.compile(u"[\s\u0020\u00a0\u1680\u180e\u202f\u205f\u3000\u2000-\u200a]+", re.UNICODE)
punctChars = r"['\"“”‘’.?!…,:;]"
#punctSeq = punctChars+"+" #'anthem'. => ' anthem '.
punctSeq = r"['\"“”‘’]+|[.?!,…]+|[:;]+" #'anthem'. => ' anthem ' .
entity = r"&(?:amp|lt|gt|quot);"
# URLs
# BTO 2012-06: everyone thinks the daringfireball regex should be better, but they're wrong.
# If you actually empirically test it the results are bad.
# Please see https://github.com/brendano/ark-tweet-nlp/pull/9
urlStart1 = r"(?:https?://|\bwww\.)"
commonTLDs = r"(?:com|org|edu|gov|net|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|pro|tel|travel|xxx)"
ccTLDs = r"(?:ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|" + \
r"bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|" + \
r"er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|" + \
r"hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|" + \
r"lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|" + \
r"nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|" + \
r"sl|sm|sn|so|sr|ss|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|" + \
r"va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za|zm|zw)" #TODO: remove obscure country domains?
urlStart2 = r"\b(?:[A-Za-z\d-])+(?:\.[A-Za-z0-9]+){0,3}\." + regex_or(commonTLDs, ccTLDs) + r"(?:\."+ccTLDs+r")?(?=\W|$)"
urlBody = r"(?:[^\.\s<>][^\s<>]*?)?"
urlExtraCrapBeforeEnd = regex_or(punctChars, entity) + "+?"
urlEnd = r"(?:\.\.+|[<>]|\s|$)"
url = regex_or(urlStart1, urlStart2) + urlBody + "(?=(?:"+urlExtraCrapBeforeEnd+")?"+urlEnd+")"
# Numeric
timeLike = r"\d+(?::\d+){1,2}"
#numNum = r"\d+\.\d+"
numberWithCommas = r"(?:(?<!\d)\d{1,3},)+?\d{3}" + r"(?=(?:[^,\d]|$))"
numComb = u"[\u0024\u058f\u060b\u09f2\u09f3\u09fb\u0af1\u0bf9\u0e3f\u17db\ua838\ufdfc\ufe69\uff04\uffe0\uffe1\uffe5\uffe6\u00a2-\u00a5\u20a0-\u20b9]?\\d+(?:\\.\\d+)+%?".encode('utf-8')
# Abbreviations
boundaryNotDot = regex_or("$", r"\s", r"[“\"?!,:;]", entity)
aa1 = r"(?:[A-Za-z]\.){2,}(?=" + boundaryNotDot + ")"
aa2 = r"[^A-Za-z](?:[A-Za-z]\.){1,}[A-Za-z](?=" + boundaryNotDot + ")"
standardAbbreviations = r"\b(?:[Mm]r|[Mm]rs|[Mm]s|[Dd]r|[Ss]r|[Jj]r|[Rr]ep|[Ss]en|[Ss]t)\."
arbitraryAbbrev = regex_or(aa1, aa2, standardAbbreviations)
separators = "(?:--+|―|—|~|–|=)"
decorations = u"(?:[♫♪]+|[★☆]+|[♥❤♡]+|[\u2639-\u263b]+|[\ue001-\uebbb]+)".encode('utf-8')
thingsThatSplitWords = r"[^\s\.,?\"]"
embeddedApostrophe = thingsThatSplitWords+r"+['’′]" + thingsThatSplitWords + "*"
# Emoticons
# myleott: in Python the (?iu) flags affect the whole expression
#normalEyes = "(?iu)[:=]" # 8 and x are eyes but cause problems
normalEyes = "[:=]" # 8 and x are eyes but cause problems
wink = "[;]"
noseArea = "(?:|-|[^a-zA-Z0-9 ])" # doesn't get :'-(
happyMouths = r"[D\)\]\}]+"
sadMouths = r"[\(\[\{]+"
tongue = "[pPd3]+"
otherMouths = r"(?:[oO]+|[/\\]+|[vV]+|[Ss]+|[|]+)" # remove forward slash if http://'s aren't cleaned
# mouth repetition examples:
# @aliciakeys Put it in a love song :-))
# @hellocalyclops =))=))=)) Oh well
# myleott: try to be as case insensitive as possible, but still not perfect, e.g., o.O fails
#bfLeft = u"(♥|0|o|°|v|\\$|t|x|;|\u0ca0|@|ʘ|•|・|◕|\\^|¬|\\*)".encode('utf-8')
bfLeft = u"(♥|0|[oO]|°|[vV]|\\$|[tT]|[xX]|;|\u0ca0|@|ʘ|•|・|◕|\\^|¬|\\*)".encode('utf-8')
bfCenter = r"(?:[\.]|[_-]+)"
bfRight = r"\2"
s3 = r"(?:--['\"])"
s4 = r"(?:<|<|>|>)[\._-]+(?:<|<|>|>)"
s5 = "(?:[.][_]+[.])"
# myleott: in Python the (?i) flag affects the whole expression
#basicface = "(?:(?i)" +bfLeft+bfCenter+bfRight+ ")|" +s3+ "|" +s4+ "|" + s5
basicface = "(?:" +bfLeft+bfCenter+bfRight+ ")|" +s3+ "|" +s4+ "|" + s5
eeLeft = r"[\\\ƪԄ\((<>;ヽ\-=~\*]+"
eeRight= u"[\\-=\\);'\u0022<>ʃ)//ノノ丿╯σっµ~\\*]+".encode('utf-8')
eeSymbol = r"[^A-Za-z0-9\s\(\)\*:=-]"
eastEmote = eeLeft + "(?:"+basicface+"|" +eeSymbol+")+" + eeRight
oOEmote = r"(?:[oO]" + bfCenter + r"[oO])"
emoticon = regex_or(
# Standard version :) :( :] :D :P
"(?:>|>)?" + regex_or(normalEyes, wink) + regex_or(noseArea,"[Oo]") + regex_or(tongue+r"(?=\W|$|RT|rt|Rt)", otherMouths+r"(?=\W|$|RT|rt|Rt)", sadMouths, happyMouths),
# reversed version (: D: use positive lookbehind to remove "(word):"
# because eyes on the right side is more ambiguous with the standard usage of : ;
regex_or("(?<=(?: ))", "(?<=(?:^))") + regex_or(sadMouths,happyMouths,otherMouths) + noseArea + regex_or(normalEyes, wink) + "(?:<|<)?",
#inspired by http://en.wikipedia.org/wiki/User:Scapler/emoticons#East_Asian_style
eastEmote.replace("2", "1", 1), basicface,
# iOS 'emoji' characters (some smileys, some symbols) [\ue001-\uebbb]
# TODO should try a big precompiled lexicon from Wikipedia, Dan Ramage told me (BTO) he does this
# myleott: o.O and O.o are two of the biggest sources of differences
# between this and the Java version. One little hack won't hurt...
oOEmote
)
Hearts = "(?:<+/?3+)+" #the other hearts are in decorations
Arrows = regex_or(r"(?:<*[-―—=]*>+|<+[-―—=]*>*)", u"[\u2190-\u21ff]+".encode('utf-8'))
# BTO 2011-06: restored Hashtag, AtMention protection (dropped in original scala port) because it fixes
# "hello (#hashtag)" ==> "hello (#hashtag )" WRONG
# "hello (#hashtag)" ==> "hello ( #hashtag )" RIGHT
# "hello (@person)" ==> "hello (@person )" WRONG
# "hello (@person)" ==> "hello ( @person )" RIGHT
# ... Some sort of weird interaction with edgepunct I guess, because edgepunct
# has poor content-symbol detection.
# This also gets #1 #40 which probably aren't hashtags .. but good as tokens.
# If you want good hashtag identification, use a different regex.
Hashtag = "#[a-zA-Z0-9_]+" #optional: lookbehind for \b
#optional: lookbehind for \b, max length 15
AtMention = "[@@][a-zA-Z0-9_]+"
# I was worried this would conflict with at-mentions
# but seems ok in sample of 5800: 7 changes all email fixes
# http://www.regular-expressions.info/email.html
Bound = r"(?:\W|^|$)"
Email = regex_or("(?<=(?:\W))", "(?<=(?:^))") + r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}(?=" +Bound+")"
# We will be tokenizing using these regexps as delimiters
# Additionally, these things are "protected", meaning they shouldn't be further split themselves.
Protected = re.compile(
unicode(regex_or(
Hearts,
url,
Email,
timeLike,
#numNum,
numberWithCommas,
numComb,
emoticon,
Arrows,
entity,
punctSeq,
arbitraryAbbrev,
separators,
decorations,
embeddedApostrophe,
Hashtag,
AtMention
).decode('utf-8')), re.UNICODE)
# Edge punctuation
# Want: 'foo' => ' foo '
# While also: don't => don't
# the first is considered "edge punctuation".
# the second is word-internal punctuation -- don't want to mess with it.
# BTO (2011-06): the edgepunct system seems to be the #1 source of problems these days.
# I remember it causing lots of trouble in the past as well. Would be good to revisit or eliminate.
# Note the 'smart quotes' (http://en.wikipedia.org/wiki/Smart_quotes)
#edgePunctChars = r"'\"“”‘’«»{}\(\)\[\]\*&" #add \\p{So}? (symbols)
edgePunctChars = u"'\"“”‘’«»{}\\(\\)\\[\\]\\*&" #add \\p{So}? (symbols)
edgePunct = "[" + edgePunctChars + "]"
notEdgePunct = "[a-zA-Z0-9]" # content characters
offEdge = r"(^|$|:|;|\s|\.|,)" # colon here gets "(hello):" ==> "( hello ):"
EdgePunctLeft = re.compile(offEdge + "("+edgePunct+"+)("+notEdgePunct+")", re.UNICODE)
EdgePunctRight = re.compile("("+notEdgePunct+")("+edgePunct+"+)" + offEdge, re.UNICODE)
def splitEdgePunct(input):
input = EdgePunctLeft.sub(r"\1\2 \3", input)
input = EdgePunctRight.sub(r"\1 \2\3", input)
return input
# The main work of tokenizing a tweet.
def simpleTokenize(text):
# Do the no-brainers first
splitPunctText = splitEdgePunct(text)
textLength = len(splitPunctText)
# BTO: the logic here got quite convoluted via the Scala porting detour
# It would be good to switch back to a nice simple procedural style like in the Python version
# ... Scala is such a pain. Never again.
# Find the matches for subsequences that should be protected,
# e.g. URLs, 1.0, U.N.K.L.E., 12:53
bads = []
badSpans = []
for match in Protected.finditer(splitPunctText):
# The spans of the "bads" should not be split.
if (match.start() != match.end()): #unnecessary?
bads.append( [splitPunctText[match.start():match.end()]] )
badSpans.append( (match.start(), match.end()) )
# Create a list of indices to create the "goods", which can be
# split. We are taking "bad" spans like
# List((2,5), (8,10))
# to create
# List(0, 2, 5, 8, 10, 12)
# where, e.g., "12" here would be the textLength
# has an even length and no indices are the same
indices = [0]
for (first, second) in badSpans:
indices.append(first)
indices.append(second)
indices.append(textLength)
# Group the indices and map them to their respective portion of the string
splitGoods = []
for i in range(0, len(indices), 2):
goodstr = splitPunctText[indices[i]:indices[i+1]]
splitstr = goodstr.strip().split(" ")
splitGoods.append(splitstr)
# Reinterpolate the 'good' and 'bad' Lists, ensuring that
# additonal tokens from last good item get included
zippedStr = []
for i in range(len(bads)):
zippedStr = addAllnonempty(zippedStr, splitGoods[i])
zippedStr = addAllnonempty(zippedStr, bads[i])
zippedStr = addAllnonempty(zippedStr, splitGoods[len(bads)])
# BTO: our POS tagger wants "ur" and "you're" to both be one token.
# Uncomment to get "you 're"
#splitStr = []
#for tok in zippedStr:
# splitStr.extend(splitToken(tok))
#zippedStr = splitStr
return zippedStr
def addAllnonempty(master, smaller):
for s in smaller:
strim = s.strip()
if (len(strim) > 0):
master.append(strim)
return master
# "foo bar " => "foo bar"
def squeezeWhitespace(input):
return Whitespace.sub(" ", input).strip()
# Final pass tokenization based on special patterns
def splitToken(token):
m = Contractions.search(token)
if m:
return [m.group(1), m.group(2)]
return [token]
# Assume 'text' has no HTML escaping.
def tokenize(text):
return simpleTokenize(squeezeWhitespace(text))
# Twitter text comes HTML-escaped, so unescape it.
# We also first unescape &'s, in case the text has been buggily double-escaped.
def normalizeTextForTagger(text):
text = text.replace("&", "&")
text = HTMLParser.HTMLParser().unescape(text)
return text
# This is intended for raw tweet text -- we do some HTML entity unescaping before running the tagger.
#
# This function normalizes the input text BEFORE calling the tokenizer.
# So the tokens you get back may not exactly correspond to
# substrings of the original text.
def tokenizeRawTweetText(text):
tokens = tokenize(normalizeTextForTagger(text))
return tokens
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
22879,
2858,
794,
1553,
282,
14803,
19829,
367,
19259,
1318,
315,
20144,
436,
2005,
1163,
31615,
290,
10815,
14,
199,
2765,
14803,
1233,
965,
21737,
4012,
282,
1846,
7994,
26,
199,
199,
8,
17,
9,
699,
16479,
290,
593,
7,
714,
6505,
336,
22665,
3379,
1015,
315,
2018,
12,
1455,
921,
5031,
14,
957,
15,
66,
16479,
8143,
15,
23508,
573,
9142,
2126,
377,
11554,
3716,
9142,
26,
1316,
1168,
31671,
8730,
436,
32166,
12094,
4584,
2072,
367,
19259,
14,
2126,
699,
16479,
290,
593,
7,
714,
6505,
12,
603,
1158,
352,
1804,
11317,
836,
12,
436,
20232,
437,
6164,
14,
2126,
473,
27303,
4029,
13,
6542,
334,
8768,
4426,
395,
1455,
921,
66,
828,
79,
388,
14,
957,
15,
79,
1631,
269,
63,
75,
11317,
836,
63,
65,
6164,
14,
530,
87,
3300,
6542,
14,
23508,
573,
9142,
14,
5607,
199,
8,
18,
65,
9,
25645,
11908,
598,
3236,
352,
436,
24747,
14769,
603,
15350,
6042,
652,
367,
510,
3100,
1947,
1540,
367,
314,
445,
45,
53,
4160,
43,
19259,
510,
3100,
8053,
836,
199,
8,
18,
66,
9,
1603,
2660,
23928,
68,
5562,
436,
20232,
428,
9745,
424,
299,
1376,
652,
370,
17619,
65,
199,
8,
19,
9,
699,
16479,
290,
6519,
5964,
314,
17619,
65,
1844,
436,
9545,
543,
510,
3100,
13,
6100,
4493,
272,
367,
314,
445,
45,
53,
4160,
43,
19259,
510,
3100,
8053,
836,
257,
199,
8,
20,
9,
377,
2873,
73,
593,
87,
411,
935,
299,
1376,
652,
1771,
370,
9586,
436,
3483,
5002,
19053,
1470,
334,
7409,
13,
1690,
9,
199,
199,
5639,
5629,
365,
1455,
921,
5031,
14,
957,
15,
66,
16479,
8143,
15,
1096,
13,
23508,
13,
7530,
80,
436,
1455,
921,
1544,
14,
1096,
14,
1259,
14,
4400,
85,
14,
8654,
15,
52,
11554,
46,
9257,
199,
199,
10924,
1172,
2757,
737,
5210,
499,
1163,
9586,
8873,
12,
1325,
2985,
787,
440,
315,
314,
1004,
474,
367,
314,
1233,
2348,
14,
199,
199,
48,
1376,
370,
2018,
701,
603,
1775,
593,
6215,
665,
1662,
274,
357,
84,
32,
6799,
14,
957,
10827,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
4182,
199,
646,
295,
199,
646,
24581,
199,
199,
318,
5163,
63,
269,
2031,
1744,
304,
272,
372,
17644,
4881,
435,
21590,
904,
8,
1744,
9,
435,
16107,
199,
199,
714,
1239,
2452,
275,
295,
14,
2014,
8,
85,
24726,
73,
10127,
87,
29653,
78,
459,
21045,
8477,
111,
61,
84,
92,
459,
21045,
8477,
111,
61,
432,
92,
459,
21045,
8477,
111,
61,
914,
92,
459,
21045,
8477,
111,
61,
68,
92,
459,
21045,
8477,
111,
61,
264,
92,
459,
21045,
8477,
111,
61,
83,
92,
459,
21045,
8477,
111,
61,
77,
9,
11918,
295,
14,
12819,
9,
199,
16552,
275,
295,
14,
2014,
8,
85,
29354,
83,
60,
85,
20734,
60,
85,
383,
65,
16,
60,
85,
975,
1257,
60,
85,
7663,
69,
60,
85,
4999,
70,
60,
85,
10629,
70,
60,
85,
19962,
60,
85,
8269,
2696,
85,
1840,
65,
2807,
401,
295,
14,
12819,
9,
199,
199,
27003,
11229,
275,
519,
2,
459,
4451,
8477,
251,
8477,
252,
8477,
247,
21045,
14,
31,
1,
8477,
100,
12,
26,
27,
8480,
199,
3,
27003,
11205,
257,
275,
299,
4638,
11229,
5207,
5207,
198,
19367,
290,
1589,
77,
1370,
9265,
283,
376,
1589,
77,
1987,
199,
27003,
11205,
257,
275,
519,
2,
459,
4451,
8477,
251,
8477,
252,
8477,
247,
21045,
2807,
17884,
14,
31,
1,
12,
8477,
100,
2807,
92,
1491,
27,
2807,
2,
198,
19367,
290,
1589,
77,
1370,
9265,
283,
376,
1589,
77,
283,
1275,
199,
4502,
258,
275,
519,
2,
6,
5169,
5282,
92,
4116,
92,
3308,
92,
5184,
27556,
199,
3,
221,
10867,
421,
199,
3,
699,
2566,
6029,
13,
1690,
26,
4036,
368,
13516,
83,
314,
366,
9332,
8935,
8571,
5163,
1077,
506,
8034,
12,
1325,
2985,
3984,
6835,
14,
199,
3,
982,
1265,
5965,
9052,
73,
1567,
1183,
511,
652,
314,
2058,
787,
4875,
14,
199,
3,
7754,
1937,
4178,
921,
5031,
14,
957,
15,
66,
16479,
8143,
15,
1096,
13,
23508,
13,
7530,
80,
15,
9302,
15,
25,
199,
199,
633,
3162,
17,
221,
275,
519,
2,
5169,
2859,
14144,
6113,
66,
1544,
4537,
2924,
199,
2330,
52,
6533,
83,
275,
519,
2,
5169,
957,
92,
1308,
92,
8654,
92,
16294,
92,
846,
92,
77,
382,
92,
65,
3478,
92,
305,
4674,
92,
66,
565,
92,
3385,
92,
331,
411,
92,
815,
92,
442,
92,
6920,
92,
573,
4492,
92,
77,
1180,
453,
92,
354,
92,
496,
92,
14146,
92,
1239,
1090,
92,
10013,
2924,
199,
2055,
52,
6533,
83,
198,
275,
519,
2,
5169,
645,
92,
350,
92,
3624,
92,
2756,
92,
643,
92,
5789,
92,
279,
92,
455,
92,
290,
92,
8035,
92,
30030,
92,
285,
92,
305,
92,
292,
92,
3844,
92,
10084,
92,
1219,
92,
4651,
92,
2470,
92,
2501,
92,
3691,
92,
1235,
92,
4361,
92,
6856,
92,
26397,
92,
4492,
92,
468,
92,
12648,
92,
10472,
92,
656,
92,
3289,
92,
1533,
92,
13061,
25576,
435,
971,
199,
82,
2,
23064,
92,
12415,
92,
991,
92,
10582,
92,
696,
92,
2055,
92,
2866,
92,
2177,
92,
12595,
92,
335,
92,
559,
92,
346,
92,
429,
92,
4400,
92,
6413,
92,
331,
92,
1556,
92,
1259,
92,
15140,
92,
5107,
92,
11859,
92,
1480,
92,
16823,
92,
617,
92,
271,
92,
18256,
92,
6341,
92,
6428,
92,
1117,
92,
17019,
92,
825,
92,
1024,
92,
5902,
92,
24528,
25576,
435,
971,
199,
82,
2,
281,
92,
397,
92,
386,
92,
16913,
92,
329,
92,
70,
74,
92,
9010,
92,
10886,
92,
545,
92,
4391,
92,
5294,
92,
4908,
92,
7136,
92,
303,
92,
7102,
92,
2721,
92,
3561,
92,
6153,
92,
3528,
92,
13844,
92,
784,
92,
4927,
92,
71,
81,
92,
2587,
92,
458,
92,
3308,
92,
6051,
92,
8392,
92,
4312,
92,
21557,
92,
14038,
92,
6164,
92,
6271,
92,
517,
25576,
435,
971,
199,
82,
2,
10616,
92,
344,
92,
1873,
92,
382,
92,
1017,
92,
262,
92,
2308,
92,
9962,
92,
723,
92,
374,
92,
390
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
22879,
2858,
794,
1553,
282,
14803,
19829,
367,
19259,
1318,
315,
20144,
436,
2005,
1163,
31615,
290,
10815,
14,
199,
2765,
14803,
1233,
965,
21737,
4012,
282,
1846,
7994,
26,
199,
199,
8,
17,
9,
699,
16479,
290,
593,
7,
714,
6505,
336,
22665,
3379,
1015,
315,
2018,
12,
1455,
921,
5031,
14,
957,
15,
66,
16479,
8143,
15,
23508,
573,
9142,
2126,
377,
11554,
3716,
9142,
26,
1316,
1168,
31671,
8730,
436,
32166,
12094,
4584,
2072,
367,
19259,
14,
2126,
699,
16479,
290,
593,
7,
714,
6505,
12,
603,
1158,
352,
1804,
11317,
836,
12,
436,
20232,
437,
6164,
14,
2126,
473,
27303,
4029,
13,
6542,
334,
8768,
4426,
395,
1455,
921,
66,
828,
79,
388,
14,
957,
15,
79,
1631,
269,
63,
75,
11317,
836,
63,
65,
6164,
14,
530,
87,
3300,
6542,
14,
23508,
573,
9142,
14,
5607,
199,
8,
18,
65,
9,
25645,
11908,
598,
3236,
352,
436,
24747,
14769,
603,
15350,
6042,
652,
367,
510,
3100,
1947,
1540,
367,
314,
445,
45,
53,
4160,
43,
19259,
510,
3100,
8053,
836,
199,
8,
18,
66,
9,
1603,
2660,
23928,
68,
5562,
436,
20232,
428,
9745,
424,
299,
1376,
652,
370,
17619,
65,
199,
8,
19,
9,
699,
16479,
290,
6519,
5964,
314,
17619,
65,
1844,
436,
9545,
543,
510,
3100,
13,
6100,
4493,
272,
367,
314,
445,
45,
53,
4160,
43,
19259,
510,
3100,
8053,
836,
257,
199,
8,
20,
9,
377,
2873,
73,
593,
87,
411,
935,
299,
1376,
652,
1771,
370,
9586,
436,
3483,
5002,
19053,
1470,
334,
7409,
13,
1690,
9,
199,
199,
5639,
5629,
365,
1455,
921,
5031,
14,
957,
15,
66,
16479,
8143,
15,
1096,
13,
23508,
13,
7530,
80,
436,
1455,
921,
1544,
14,
1096,
14,
1259,
14,
4400,
85,
14,
8654,
15,
52,
11554,
46,
9257,
199,
199,
10924,
1172,
2757,
737,
5210,
499,
1163,
9586,
8873,
12,
1325,
2985,
787,
440,
315,
314,
1004,
474,
367,
314,
1233,
2348,
14,
199,
199,
48,
1376,
370,
2018,
701,
603,
1775,
593,
6215,
665,
1662,
274,
357,
84,
32,
6799,
14,
957,
10827,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
4182,
199,
646,
295,
199,
646,
24581,
199,
199,
318,
5163,
63,
269,
2031,
1744,
304,
272,
372,
17644,
4881,
435,
21590,
904,
8,
1744,
9,
435,
16107,
199,
199,
714,
1239,
2452,
275,
295,
14,
2014,
8,
85,
24726,
73,
10127,
87,
29653,
78,
459,
21045,
8477,
111,
61,
84,
92,
459,
21045,
8477,
111,
61,
432,
92,
459,
21045,
8477,
111,
61,
914,
92,
459,
21045,
8477,
111,
61,
68,
92,
459,
21045,
8477,
111,
61,
264,
92,
459,
21045,
8477,
111,
61,
83,
92,
459,
21045,
8477,
111,
61,
77,
9,
11918,
295,
14,
12819,
9,
199,
16552,
275,
295,
14,
2014,
8,
85,
29354,
83,
60,
85,
20734,
60,
85,
383,
65,
16,
60,
85,
975,
1257,
60,
85,
7663,
69,
60,
85,
4999,
70,
60,
85,
10629,
70,
60,
85,
19962,
60,
85,
8269,
2696,
85,
1840,
65,
2807,
401,
295,
14,
12819,
9,
199,
199,
27003,
11229,
275,
519,
2,
459,
4451,
8477,
251,
8477,
252,
8477,
247,
21045,
14,
31,
1,
8477,
100,
12,
26,
27,
8480,
199,
3,
27003,
11205,
257,
275,
299,
4638,
11229,
5207,
5207,
198,
19367,
290,
1589,
77,
1370,
9265,
283,
376,
1589,
77,
1987,
199,
27003,
11205,
257,
275,
519,
2,
459,
4451,
8477,
251,
8477,
252,
8477,
247,
21045,
2807,
17884,
14,
31,
1,
12,
8477,
100,
2807,
92,
1491,
27,
2807,
2,
198,
19367,
290,
1589,
77,
1370,
9265,
283,
376,
1589,
77,
283,
1275,
199,
4502,
258,
275,
519,
2,
6,
5169,
5282,
92,
4116,
92,
3308,
92,
5184,
27556,
199,
3,
221,
10867,
421,
199,
3,
699,
2566,
6029,
13,
1690,
26,
4036,
368,
13516,
83,
314,
366,
9332,
8935,
8571,
5163,
1077,
506,
8034,
12,
1325,
2985,
3984,
6835,
14,
199,
3,
982,
1265,
5965,
9052,
73,
1567,
1183,
511,
652,
314,
2058,
787,
4875,
14,
199,
3,
7754,
1937,
4178,
921,
5031,
14,
957,
15,
66,
16479,
8143,
15,
1096,
13,
23508,
13,
7530,
80,
15,
9302,
15,
25,
199,
199,
633,
3162,
17,
221,
275,
519,
2,
5169,
2859,
14144,
6113,
66,
1544,
4537,
2924,
199,
2330,
52,
6533,
83,
275,
519,
2,
5169,
957,
92,
1308,
92,
8654,
92,
16294,
92,
846,
92,
77,
382,
92,
65,
3478,
92,
305,
4674,
92,
66,
565,
92,
3385,
92,
331,
411,
92,
815,
92,
442,
92,
6920,
92,
573,
4492,
92,
77,
1180,
453,
92,
354,
92,
496,
92,
14146,
92,
1239,
1090,
92,
10013,
2924,
199,
2055,
52,
6533,
83,
198,
275,
519,
2,
5169,
645,
92,
350,
92,
3624,
92,
2756,
92,
643,
92,
5789,
92,
279,
92,
455,
92,
290,
92,
8035,
92,
30030,
92,
285,
92,
305,
92,
292,
92,
3844,
92,
10084,
92,
1219,
92,
4651,
92,
2470,
92,
2501,
92,
3691,
92,
1235,
92,
4361,
92,
6856,
92,
26397,
92,
4492,
92,
468,
92,
12648,
92,
10472,
92,
656,
92,
3289,
92,
1533,
92,
13061,
25576,
435,
971,
199,
82,
2,
23064,
92,
12415,
92,
991,
92,
10582,
92,
696,
92,
2055,
92,
2866,
92,
2177,
92,
12595,
92,
335,
92,
559,
92,
346,
92,
429,
92,
4400,
92,
6413,
92,
331,
92,
1556,
92,
1259,
92,
15140,
92,
5107,
92,
11859,
92,
1480,
92,
16823,
92,
617,
92,
271,
92,
18256,
92,
6341,
92,
6428,
92,
1117,
92,
17019,
92,
825,
92,
1024,
92,
5902,
92,
24528,
25576,
435,
971,
199,
82,
2,
281,
92,
397,
92,
386,
92,
16913,
92,
329,
92,
70,
74,
92,
9010,
92,
10886,
92,
545,
92,
4391,
92,
5294,
92,
4908,
92,
7136,
92,
303,
92,
7102,
92,
2721,
92,
3561,
92,
6153,
92,
3528,
92,
13844,
92,
784,
92,
4927,
92,
71,
81,
92,
2587,
92,
458,
92,
3308,
92,
6051,
92,
8392,
92,
4312,
92,
21557,
92,
14038,
92,
6164,
92,
6271,
92,
517,
25576,
435,
971,
199,
82,
2,
10616,
92,
344,
92,
1873,
92,
382,
92,
1017,
92,
262,
92,
2308,
92,
9962,
92,
723,
92,
374,
92,
390,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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el Richman, Adam Greig
#
# This file is part of strict_rfc3339.
#
# strict_rfc3339 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# strict_rfc3339 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with strict_rfc3339. If not, see <http://www.gnu.org/licenses/>.
"""
Super simple lightweight RFC3339 functions
"""
import re
import time
import calendar
__all__ = ["validate_rfc3339",
"InvalidRFC3339Error",
"rfc3339_to_timestamp",
"timestamp_to_rfc3339_utcoffset",
"timestamp_to_rfc3339_localoffset",
"now_to_rfc3339_utcoffset",
"now_to_rfc3339_localoffset"]
rfc3339_regex = re.compile(
r"^(\d\d\d\d)\-(\d\d)\-(\d\d)T"
r"(\d\d):(\d\d):(\d\d)(\.\d+)?(Z|([+\-])(\d\d):(\d\d))$")
def validate_rfc3339(datestring):
"""Check an RFC3339 string is valid via a regex and some range checks"""
m = rfc3339_regex.match(datestring)
if m is None:
return False
groups = m.groups()
year, month, day, hour, minute, second = [int(i) for i in groups[:6]]
if not 1 <= year <= 9999:
# Have to reject this, unfortunately (despite it being OK by rfc3339):
# calendar.timegm/calendar.monthrange can't cope (since datetime can't)
return False
if not 1 <= month <= 12:
return False
(_, max_day) = calendar.monthrange(year, month)
if not 1 <= day <= max_day:
return False
if not (0 <= hour <= 23 and 0 <= minute <= 59 and 0 <= second <= 59):
# forbid leap seconds :-(. See README
return False
if groups[7] != "Z":
(offset_sign, offset_hours, offset_mins) = groups[8:]
if not (0 <= int(offset_hours) <= 23 and 0 <= int(offset_mins) <= 59):
return False
# all OK
return True
class InvalidRFC3339Error(ValueError):
"""Subclass of ValueError thrown by rfc3339_to_timestamp"""
pass
def rfc3339_to_timestamp(datestring):
"""Convert an RFC3339 date-time string to a UTC UNIX timestamp"""
if not validate_rfc3339(datestring):
raise InvalidRFC3339Error
groups = rfc3339_regex.match(datestring).groups()
time_tuple = [int(p) for p in groups[:6]]
timestamp = calendar.timegm(time_tuple)
seconds_part = groups[6]
if seconds_part is not None:
timestamp += float("0" + seconds_part)
if groups[7] != "Z":
(offset_sign, offset_hours, offset_mins) = groups[8:]
offset_seconds = int(offset_hours) * 3600 + int(offset_mins) * 60
if offset_sign == '-':
offset_seconds = -offset_seconds
timestamp -= offset_seconds
return timestamp
def _seconds_and_microseconds(timestamp):
"""
Split a floating point timestamp into an integer number of seconds since
the epoch, and an integer number of microseconds (having rounded to the
nearest microsecond).
If `_seconds_and_microseconds(x) = (y, z)` then the following holds (up to
the error introduced by floating point operations):
* `x = y + z / 1_000_000.`
* `0 <= z < 1_000_000.`
"""
if isinstance(timestamp, int):
return (timestamp, 0)
else:
timestamp_us = int(round(timestamp * 1e6))
return divmod(timestamp_us, 1000000)
def _make_datestring_start(time_tuple, microseconds):
ds_format = "{0:04d}-{1:02d}-{2:02d}T{3:02d}:{4:02d}:{5:02d}"
datestring = ds_format.format(*time_tuple)
seconds_part_str = "{0:06d}".format(microseconds)
# There used to be a bug here where it could be 1000000
assert len(seconds_part_str) == 6 and seconds_part_str[0] != '-'
seconds_part_str = seconds_part_str.rstrip("0")
if seconds_part_str != "":
datestring += "." + seconds_part_str
return datestring
def timestamp_to_rfc3339_utcoffset(timestamp):
"""Convert a UTC UNIX timestamp to RFC3339, with the offset as 'Z'"""
seconds, microseconds = _seconds_and_microseconds(timestamp)
time_tuple = time.gmtime(seconds)
datestring = _make_datestring_start(time_tuple, microseconds)
datestring += "Z"
assert abs(rfc3339_to_timestamp(datestring) - timestamp) < 0.000001
return datestring
def timestamp_to_rfc3339_localoffset(timestamp):
"""
Convert a UTC UNIX timestamp to RFC3339, using the local offset.
localtime() provides the time parts. The difference between gmtime and
localtime tells us the offset.
"""
seconds, microseconds = _seconds_and_microseconds(timestamp)
time_tuple = time.localtime(seconds)
datestring = _make_datestring_start(time_tuple, microseconds)
gm_time_tuple = time.gmtime(seconds)
offset = calendar.timegm(time_tuple) - calendar.timegm(gm_time_tuple)
if abs(offset) % 60 != 0:
raise ValueError("Your local offset is not a whole minute")
offset_minutes = abs(offset) // 60
offset_hours = offset_minutes // 60
offset_minutes %= 60
offset_string = "{0:02d}:{1:02d}".format(offset_hours, offset_minutes)
if offset < 0:
datestring += "-"
else:
datestring += "+"
datestring += offset_string
assert abs(rfc3339_to_timestamp(datestring) - timestamp) < 0.000001
return datestring
def now_to_rfc3339_utcoffset(integer=True):
"""Convert the current time to RFC3339, with the offset as 'Z'"""
timestamp = time.time()
if integer:
timestamp = int(timestamp)
return timestamp_to_rfc3339_utcoffset(timestamp)
def now_to_rfc3339_localoffset(integer=True):
"""Convert the current time to RFC3339, using the local offset."""
timestamp = time.time()
if integer:
timestamp = int(timestamp)
return timestamp_to_rfc3339_localoffset(timestamp)
|
bsd-3-clause
|
[
3,
1898,
6029,
334,
35,
9,
24747,
14769,
30846,
1237,
12,
4431,
455,
598,
264,
528,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
7478,
63,
8973,
29536,
14,
199,
3,
199,
3,
7478,
63,
8973,
29536,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
7478,
63,
8973,
29536,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
7478,
63,
8973,
29536,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
199,
11823,
3486,
10540,
3463,
7329,
29536,
3423,
199,
624,
199,
199,
646,
295,
199,
646,
900,
199,
646,
11234,
199,
199,
363,
452,
363,
275,
2097,
3502,
63,
8973,
29536,
401,
1779,
298,
3364,
14468,
29536,
547,
401,
1779,
298,
8973,
29536,
63,
475,
63,
3954,
401,
1779,
298,
3954,
63,
475,
63,
8973,
29536,
63,
24036,
401,
1779,
298,
3954,
63,
475,
63,
8973,
29536,
63,
1832,
2743,
401,
1779,
298,
2131,
63,
475,
63,
8973,
29536,
63,
24036,
401,
1779,
298,
2131,
63,
475,
63,
8973,
29536,
63,
1832,
2743,
937,
199,
199,
8973,
29536,
63,
3821,
275,
295,
14,
2014,
8,
272,
519,
16136,
2961,
68,
60,
68,
60,
68,
60,
68,
2862,
13,
2961,
68,
60,
68,
2862,
13,
2961,
68,
60,
68,
9,
52,
2,
272,
519,
2,
2961,
68,
60,
68,
304,
2961,
68,
60,
68,
304,
2961,
68,
60,
68,
10127,
3134,
68,
19544,
8,
58,
92,
779,
7896,
13,
566,
2961,
68,
60,
68,
304,
2961,
68,
60,
68,
430,
22550,
421,
199,
318,
4107,
63,
8973,
29536,
8,
602,
875,
304,
272,
408,
1799,
376,
7329,
29536,
1059,
365,
1686,
4799,
282,
5163,
436,
2005,
1425,
5920,
624,
339,
333,
275,
18158,
29536,
63,
3821,
14,
1431,
8,
602,
875,
9,
272,
340,
333,
365,
488,
26,
267,
372,
756,
339,
4652,
275,
333,
14,
2634,
342,
339,
5361,
12,
5794,
12,
5382,
12,
6925,
12,
12709,
12,
3499,
275,
359,
442,
8,
73,
9,
367,
284,
315,
4652,
1491,
22,
2677,
339,
340,
440,
413,
2695,
5361,
2695,
221,
5008,
26,
267,
327,
26858,
370,
17100,
642,
12,
625,
21839,
334,
271,
681,
1175,
652,
3769,
9949,
701,
18158,
29536,
304,
267,
327,
11234,
14,
521,
13844,
15,
8183,
14,
4482,
1842,
883,
1133,
512,
321,
334,
8585,
2197,
883,
1133,
9,
267,
372,
756,
339,
340,
440,
413,
2695,
5794,
2695,
3144,
26,
267,
372,
756,
339,
27017,
1390,
63,
2977,
9,
275,
11234,
14,
4482,
1842,
8,
3403,
12,
5794,
9,
272,
340,
440,
413,
2695,
5382,
2695,
1390,
63,
2977,
26,
267,
372,
756,
339,
340,
440,
334,
16,
2695,
6925,
2695,
6546,
436,
378,
2695,
12709,
2695,
8155,
436,
378,
2695,
3499,
2695,
8155,
304,
267,
327,
367,
17949,
29487,
4696,
22901,
13417,
1666,
27781,
267,
372,
756,
339,
340,
4652,
59,
23,
61,
1137,
298,
58,
582,
267,
334,
2743,
63,
1037,
12,
3268,
63,
8419,
12,
3268,
63,
29361,
9,
275,
4652,
59,
24,
2938,
267,
340,
440,
334,
16,
2695,
1109,
8,
2743,
63,
8419,
9,
2695,
6546,
436,
378,
2695,
1109,
8,
2743,
63,
29361,
9,
2695,
8155,
304,
288,
372,
756,
339,
327,
1006,
9949,
272,
372,
715,
421,
199,
533,
6378,
14468,
29536,
547,
8,
3393,
304,
272,
408,
23636,
402,
1722,
14031,
701,
18158,
29536,
63,
475,
63,
3954,
624,
272,
986,
421,
199,
318,
18158,
29536,
63,
475,
63,
3954,
8,
602,
875,
304,
272,
408,
7306,
376,
7329,
29536,
1434,
13,
521,
1059,
370,
282,
12174,
22242,
4913,
624,
339,
340,
440,
4107,
63,
8973,
29536,
8,
602,
875,
304,
267,
746,
6378,
14468,
29536,
547,
339,
4652,
275,
18158,
29536,
63,
3821,
14,
1431,
8,
602,
875,
680,
2634,
342,
339,
900,
63,
2960,
275,
359,
442,
8,
80,
9,
367,
299,
315,
4652,
1491,
22,
2677,
272,
4913,
275,
11234,
14,
521,
13844,
8,
521,
63,
2960,
9,
339,
4696,
63,
2064,
275,
4652,
59,
22,
61,
272,
340,
4696,
63,
2064,
365,
440,
488,
26,
267,
4913,
847,
2069,
480,
16,
2,
435,
4696,
63,
2064,
9,
339,
340,
4652,
59,
23,
61,
1137,
298,
58,
582,
267,
334,
2743,
63,
1037,
12,
3268,
63,
8419,
12,
3268,
63,
29361,
9,
275,
4652,
59,
24,
2938,
267,
3268,
63,
4515,
275,
1109,
8,
2743,
63,
8419,
9,
627,
15751,
435,
1109,
8,
2743,
63,
29361,
9,
627,
5212,
267,
340,
3268,
63,
1037,
508,
20905,
288,
3268,
63,
4515,
275,
446,
2743,
63,
4515,
267,
4913,
4862,
3268,
63,
4515,
339,
372,
4913,
421,
199,
318,
485,
4515,
63,
460,
63,
18144,
8,
3954,
304,
272,
408,
272,
11740,
282,
8402,
2376,
4913,
1901,
376,
3000,
1329,
402,
4696,
3967,
272,
314,
9463,
12,
436,
376,
3000,
1329,
402,
21574,
334,
31569,
24671,
370,
314,
272,
17173,
25824,
680,
339,
982,
18494,
4515,
63,
460,
63,
18144,
8,
88,
9,
275,
334,
89,
12,
1315,
12544,
2066,
314,
2569,
15164,
334,
384,
370,
272,
314,
1125,
21399,
701,
8402,
2376,
5331,
304,
339,
627,
658,
88,
275,
612,
435,
1315,
1182,
413,
63,
1493,
63,
1493,
14,
64,
272,
627,
658,
16,
2695,
1315,
665,
413,
63,
1493,
63,
1493,
14,
64,
272,
408,
339,
340,
1228,
8,
3954,
12,
1109,
304,
267,
372,
334,
3954,
12,
378,
9,
272,
587,
26,
267,
4913,
63,
527,
275,
1109,
8,
2363,
8,
3954,
627,
413,
69,
22,
430,
267,
372,
16438,
8,
3954,
63,
527,
12,
19492,
9,
199,
199,
318,
485,
1875,
63,
602,
875,
63,
928
] |
[
1898,
6029,
334,
35,
9,
24747,
14769,
30846,
1237,
12,
4431,
455,
598,
264,
528,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
7478,
63,
8973,
29536,
14,
199,
3,
199,
3,
7478,
63,
8973,
29536,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
7478,
63,
8973,
29536,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
7478,
63,
8973,
29536,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
199,
11823,
3486,
10540,
3463,
7329,
29536,
3423,
199,
624,
199,
199,
646,
295,
199,
646,
900,
199,
646,
11234,
199,
199,
363,
452,
363,
275,
2097,
3502,
63,
8973,
29536,
401,
1779,
298,
3364,
14468,
29536,
547,
401,
1779,
298,
8973,
29536,
63,
475,
63,
3954,
401,
1779,
298,
3954,
63,
475,
63,
8973,
29536,
63,
24036,
401,
1779,
298,
3954,
63,
475,
63,
8973,
29536,
63,
1832,
2743,
401,
1779,
298,
2131,
63,
475,
63,
8973,
29536,
63,
24036,
401,
1779,
298,
2131,
63,
475,
63,
8973,
29536,
63,
1832,
2743,
937,
199,
199,
8973,
29536,
63,
3821,
275,
295,
14,
2014,
8,
272,
519,
16136,
2961,
68,
60,
68,
60,
68,
60,
68,
2862,
13,
2961,
68,
60,
68,
2862,
13,
2961,
68,
60,
68,
9,
52,
2,
272,
519,
2,
2961,
68,
60,
68,
304,
2961,
68,
60,
68,
304,
2961,
68,
60,
68,
10127,
3134,
68,
19544,
8,
58,
92,
779,
7896,
13,
566,
2961,
68,
60,
68,
304,
2961,
68,
60,
68,
430,
22550,
421,
199,
318,
4107,
63,
8973,
29536,
8,
602,
875,
304,
272,
408,
1799,
376,
7329,
29536,
1059,
365,
1686,
4799,
282,
5163,
436,
2005,
1425,
5920,
624,
339,
333,
275,
18158,
29536,
63,
3821,
14,
1431,
8,
602,
875,
9,
272,
340,
333,
365,
488,
26,
267,
372,
756,
339,
4652,
275,
333,
14,
2634,
342,
339,
5361,
12,
5794,
12,
5382,
12,
6925,
12,
12709,
12,
3499,
275,
359,
442,
8,
73,
9,
367,
284,
315,
4652,
1491,
22,
2677,
339,
340,
440,
413,
2695,
5361,
2695,
221,
5008,
26,
267,
327,
26858,
370,
17100,
642,
12,
625,
21839,
334,
271,
681,
1175,
652,
3769,
9949,
701,
18158,
29536,
304,
267,
327,
11234,
14,
521,
13844,
15,
8183,
14,
4482,
1842,
883,
1133,
512,
321,
334,
8585,
2197,
883,
1133,
9,
267,
372,
756,
339,
340,
440,
413,
2695,
5794,
2695,
3144,
26,
267,
372,
756,
339,
27017,
1390,
63,
2977,
9,
275,
11234,
14,
4482,
1842,
8,
3403,
12,
5794,
9,
272,
340,
440,
413,
2695,
5382,
2695,
1390,
63,
2977,
26,
267,
372,
756,
339,
340,
440,
334,
16,
2695,
6925,
2695,
6546,
436,
378,
2695,
12709,
2695,
8155,
436,
378,
2695,
3499,
2695,
8155,
304,
267,
327,
367,
17949,
29487,
4696,
22901,
13417,
1666,
27781,
267,
372,
756,
339,
340,
4652,
59,
23,
61,
1137,
298,
58,
582,
267,
334,
2743,
63,
1037,
12,
3268,
63,
8419,
12,
3268,
63,
29361,
9,
275,
4652,
59,
24,
2938,
267,
340,
440,
334,
16,
2695,
1109,
8,
2743,
63,
8419,
9,
2695,
6546,
436,
378,
2695,
1109,
8,
2743,
63,
29361,
9,
2695,
8155,
304,
288,
372,
756,
339,
327,
1006,
9949,
272,
372,
715,
421,
199,
533,
6378,
14468,
29536,
547,
8,
3393,
304,
272,
408,
23636,
402,
1722,
14031,
701,
18158,
29536,
63,
475,
63,
3954,
624,
272,
986,
421,
199,
318,
18158,
29536,
63,
475,
63,
3954,
8,
602,
875,
304,
272,
408,
7306,
376,
7329,
29536,
1434,
13,
521,
1059,
370,
282,
12174,
22242,
4913,
624,
339,
340,
440,
4107,
63,
8973,
29536,
8,
602,
875,
304,
267,
746,
6378,
14468,
29536,
547,
339,
4652,
275,
18158,
29536,
63,
3821,
14,
1431,
8,
602,
875,
680,
2634,
342,
339,
900,
63,
2960,
275,
359,
442,
8,
80,
9,
367,
299,
315,
4652,
1491,
22,
2677,
272,
4913,
275,
11234,
14,
521,
13844,
8,
521,
63,
2960,
9,
339,
4696,
63,
2064,
275,
4652,
59,
22,
61,
272,
340,
4696,
63,
2064,
365,
440,
488,
26,
267,
4913,
847,
2069,
480,
16,
2,
435,
4696,
63,
2064,
9,
339,
340,
4652,
59,
23,
61,
1137,
298,
58,
582,
267,
334,
2743,
63,
1037,
12,
3268,
63,
8419,
12,
3268,
63,
29361,
9,
275,
4652,
59,
24,
2938,
267,
3268,
63,
4515,
275,
1109,
8,
2743,
63,
8419,
9,
627,
15751,
435,
1109,
8,
2743,
63,
29361,
9,
627,
5212,
267,
340,
3268,
63,
1037,
508,
20905,
288,
3268,
63,
4515,
275,
446,
2743,
63,
4515,
267,
4913,
4862,
3268,
63,
4515,
339,
372,
4913,
421,
199,
318,
485,
4515,
63,
460,
63,
18144,
8,
3954,
304,
272,
408,
272,
11740,
282,
8402,
2376,
4913,
1901,
376,
3000,
1329,
402,
4696,
3967,
272,
314,
9463,
12,
436,
376,
3000,
1329,
402,
21574,
334,
31569,
24671,
370,
314,
272,
17173,
25824,
680,
339,
982,
18494,
4515,
63,
460,
63,
18144,
8,
88,
9,
275,
334,
89,
12,
1315,
12544,
2066,
314,
2569,
15164,
334,
384,
370,
272,
314,
1125,
21399,
701,
8402,
2376,
5331,
304,
339,
627,
658,
88,
275,
612,
435,
1315,
1182,
413,
63,
1493,
63,
1493,
14,
64,
272,
627,
658,
16,
2695,
1315,
665,
413,
63,
1493,
63,
1493,
14,
64,
272,
408,
339,
340,
1228,
8,
3954,
12,
1109,
304,
267,
372,
334,
3954,
12,
378,
9,
272,
587,
26,
267,
4913,
63,
527,
275,
1109,
8,
2363,
8,
3954,
627,
413,
69,
22,
430,
267,
372,
16438,
8,
3954,
63,
527,
12,
19492,
9,
199,
199,
318,
485,
1875,
63,
602,
875,
63,
928,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
yongshengwang/builthue
|
desktop/core/ext-py/Paste-1.7.2/paste/wsgiwrappers.py
|
27
|
22165
|
# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
"""WSGI Wrappers for a Request and Response
The WSGIRequest and WSGIResponse objects are light wrappers to make it easier
to deal with an incoming request and sending a response.
"""
import re
import warnings
from pprint import pformat
from Cookie import SimpleCookie
from paste.request import EnvironHeaders, get_cookie_dict, \
parse_dict_querystring, parse_formvars
from paste.util.multidict import MultiDict, UnicodeMultiDict
from paste.registry import StackedObjectProxy
from paste.response import HeaderDict
from paste.wsgilib import encode_unicode_app_iter
from paste.httpheaders import ACCEPT_LANGUAGE
from paste.util.mimeparse import desired_matches
__all__ = ['WSGIRequest', 'WSGIResponse']
_CHARSET_RE = re.compile(r';\s*charset=([^;]*)', re.I)
class DeprecatedSettings(StackedObjectProxy):
def _push_object(self, obj):
warnings.warn('paste.wsgiwrappers.settings is deprecated: Please use '
'paste.wsgiwrappers.WSGIRequest.defaults instead',
DeprecationWarning, 3)
WSGIResponse.defaults._push_object(obj)
StackedObjectProxy._push_object(self, obj)
# settings is deprecated: use WSGIResponse.defaults instead
settings = DeprecatedSettings(default=dict())
class environ_getter(object):
"""For delegating an attribute to a key in self.environ."""
# @@: Also __set__? Should setting be allowed?
def __init__(self, key, default='', default_factory=None):
self.key = key
self.default = default
self.default_factory = default_factory
def __get__(self, obj, type=None):
if type is None:
return self
if self.key not in obj.environ:
if self.default_factory:
val = obj.environ[self.key] = self.default_factory()
return val
else:
return self.default
return obj.environ[self.key]
def __repr__(self):
return '<Proxy for WSGI environ %r key>' % self.key
class WSGIRequest(object):
"""WSGI Request API Object
This object represents a WSGI request with a more friendly interface.
This does not expose every detail of the WSGI environment, and attempts
to express nothing beyond what is available in the environment
dictionary.
The only state maintained in this object is the desired ``charset``,
its associated ``errors`` handler, and the ``decode_param_names``
option.
The incoming parameter values will be automatically coerced to unicode
objects of the ``charset`` encoding when ``charset`` is set. The
incoming parameter names are not decoded to unicode unless the
``decode_param_names`` option is enabled.
When unicode is expected, ``charset`` will overridden by the the
value of the ``Content-Type`` header's charset parameter if one was
specified by the client.
The class variable ``defaults`` specifies default values for
``charset``, ``errors``, and ``langauge``. These can be overridden for the
current request via the registry.
The ``language`` default value is considered the fallback during i18n
translations to ensure in odd cases that mixed languages don't occur should
the ``language`` file contain the string but not another language in the
accepted languages list. The ``language`` value only applies when getting
a list of accepted languages from the HTTP Accept header.
This behavior is duplicated from Aquarium, and may seem strange but is
very useful. Normally, everything in the code is in "en-us". However,
the "en-us" translation catalog is usually empty. If the user requests
``["en-us", "zh-cn"]`` and a translation isn't found for a string in
"en-us", you don't want gettext to fallback to "zh-cn". You want it to
just use the string itself. Hence, if a string isn't found in the
``language`` catalog, the string in the source code will be used.
*All* other state is kept in the environment dictionary; this is
essential for interoperability.
You are free to subclass this object.
"""
defaults = StackedObjectProxy(default=dict(charset=None, errors='replace',
decode_param_names=False,
language='en-us'))
def __init__(self, environ):
self.environ = environ
# This isn't "state" really, since the object is derivative:
self.headers = EnvironHeaders(environ)
defaults = self.defaults._current_obj()
self.charset = defaults.get('charset')
if self.charset:
# There's a charset: params will be coerced to unicode. In that
# case, attempt to use the charset specified by the browser
browser_charset = self.determine_browser_charset()
if browser_charset:
self.charset = browser_charset
self.errors = defaults.get('errors', 'strict')
self.decode_param_names = defaults.get('decode_param_names', False)
self._languages = None
body = environ_getter('wsgi.input')
scheme = environ_getter('wsgi.url_scheme')
method = environ_getter('REQUEST_METHOD')
script_name = environ_getter('SCRIPT_NAME')
path_info = environ_getter('PATH_INFO')
def urlvars(self):
"""
Return any variables matched in the URL (e.g.,
``wsgiorg.routing_args``).
"""
if 'paste.urlvars' in self.environ:
return self.environ['paste.urlvars']
elif 'wsgiorg.routing_args' in self.environ:
return self.environ['wsgiorg.routing_args'][1]
else:
return {}
urlvars = property(urlvars, doc=urlvars.__doc__)
def is_xhr(self):
"""Returns a boolean if X-Requested-With is present and a XMLHttpRequest"""
return self.environ.get('HTTP_X_REQUESTED_WITH', '') == 'XMLHttpRequest'
is_xhr = property(is_xhr, doc=is_xhr.__doc__)
def host(self):
"""Host name provided in HTTP_HOST, with fall-back to SERVER_NAME"""
return self.environ.get('HTTP_HOST', self.environ.get('SERVER_NAME'))
host = property(host, doc=host.__doc__)
def languages(self):
"""Return a list of preferred languages, most preferred first.
The list may be empty.
"""
if self._languages is not None:
return self._languages
acceptLanguage = self.environ.get('HTTP_ACCEPT_LANGUAGE')
langs = ACCEPT_LANGUAGE.parse(self.environ)
fallback = self.defaults.get('language', 'en-us')
if not fallback:
return langs
if fallback not in langs:
langs.append(fallback)
index = langs.index(fallback)
langs[index+1:] = []
self._languages = langs
return self._languages
languages = property(languages, doc=languages.__doc__)
def _GET(self):
return parse_dict_querystring(self.environ)
def GET(self):
"""
Dictionary-like object representing the QUERY_STRING
parameters. Always present, if possibly empty.
If the same key is present in the query string multiple times, a
list of its values can be retrieved from the ``MultiDict`` via
the ``getall`` method.
Returns a ``MultiDict`` container or a ``UnicodeMultiDict`` when
``charset`` is set.
"""
params = self._GET()
if self.charset:
params = UnicodeMultiDict(params, encoding=self.charset,
errors=self.errors,
decode_keys=self.decode_param_names)
return params
GET = property(GET, doc=GET.__doc__)
def _POST(self):
return parse_formvars(self.environ, include_get_vars=False)
def POST(self):
"""Dictionary-like object representing the POST body.
Most values are encoded strings, or unicode strings when
``charset`` is set. There may also be FieldStorage objects
representing file uploads. If this is not a POST request, or the
body is not encoded fields (e.g., an XMLRPC request) then this
will be empty.
This will consume wsgi.input when first accessed if applicable,
but the raw version will be put in
environ['paste.parsed_formvars'].
Returns a ``MultiDict`` container or a ``UnicodeMultiDict`` when
``charset`` is set.
"""
params = self._POST()
if self.charset:
params = UnicodeMultiDict(params, encoding=self.charset,
errors=self.errors,
decode_keys=self.decode_param_names)
return params
POST = property(POST, doc=POST.__doc__)
def params(self):
"""Dictionary-like object of keys from POST, GET, URL dicts
Return a key value from the parameters, they are checked in the
following order: POST, GET, URL
Additional methods supported:
``getlist(key)``
Returns a list of all the values by that key, collected from
POST, GET, URL dicts
Returns a ``MultiDict`` container or a ``UnicodeMultiDict`` when
``charset`` is set.
"""
params = MultiDict()
params.update(self._POST())
params.update(self._GET())
if self.charset:
params = UnicodeMultiDict(params, encoding=self.charset,
errors=self.errors,
decode_keys=self.decode_param_names)
return params
params = property(params, doc=params.__doc__)
def cookies(self):
"""Dictionary of cookies keyed by cookie name.
Just a plain dictionary, may be empty but not None.
"""
return get_cookie_dict(self.environ)
cookies = property(cookies, doc=cookies.__doc__)
def determine_browser_charset(self):
"""
Determine the encoding as specified by the browser via the
Content-Type's charset parameter, if one is set
"""
charset_match = _CHARSET_RE.search(self.headers.get('Content-Type', ''))
if charset_match:
return charset_match.group(1)
def match_accept(self, mimetypes):
"""Return a list of specified mime-types that the browser's HTTP Accept
header allows in the order provided."""
return desired_matches(mimetypes,
self.environ.get('HTTP_ACCEPT', '*/*'))
def __repr__(self):
"""Show important attributes of the WSGIRequest"""
pf = pformat
msg = '<%s.%s object at 0x%x method=%s,' % \
(self.__class__.__module__, self.__class__.__name__,
id(self), pf(self.method))
msg += '\nscheme=%s, host=%s, script_name=%s, path_info=%s,' % \
(pf(self.scheme), pf(self.host), pf(self.script_name),
pf(self.path_info))
msg += '\nlanguages=%s,' % pf(self.languages)
if self.charset:
msg += ' charset=%s, errors=%s,' % (pf(self.charset),
pf(self.errors))
msg += '\nGET=%s,' % pf(self.GET)
msg += '\nPOST=%s,' % pf(self.POST)
msg += '\ncookies=%s>' % pf(self.cookies)
return msg
class WSGIResponse(object):
"""A basic HTTP response with content, headers, and out-bound cookies
The class variable ``defaults`` specifies default values for
``content_type``, ``charset`` and ``errors``. These can be overridden
for the current request via the registry.
"""
defaults = StackedObjectProxy(
default=dict(content_type='text/html', charset='utf-8',
errors='strict', headers={'Cache-Control':'no-cache'})
)
def __init__(self, content='', mimetype=None, code=200):
self._iter = None
self._is_str_iter = True
self.content = content
self.headers = HeaderDict()
self.cookies = SimpleCookie()
self.status_code = code
defaults = self.defaults._current_obj()
if not mimetype:
mimetype = defaults.get('content_type', 'text/html')
charset = defaults.get('charset')
if charset:
mimetype = '%s; charset=%s' % (mimetype, charset)
self.headers.update(defaults.get('headers', {}))
self.headers['Content-Type'] = mimetype
self.errors = defaults.get('errors', 'strict')
def __str__(self):
"""Returns a rendition of the full HTTP message, including headers.
When the content is an iterator, the actual content is replaced with the
output of str(iterator) (to avoid exhausting the iterator).
"""
if self._is_str_iter:
content = ''.join(self.get_content())
else:
content = str(self.content)
return '\n'.join(['%s: %s' % (key, value)
for key, value in self.headers.headeritems()]) \
+ '\n\n' + content
def __call__(self, environ, start_response):
"""Convenience call to return output and set status information
Conforms to the WSGI interface for calling purposes only.
Example usage:
.. code-block:: python
def wsgi_app(environ, start_response):
response = WSGIResponse()
response.write("Hello world")
response.headers['Content-Type'] = 'latin1'
return response(environ, start_response)
"""
status_text = STATUS_CODE_TEXT[self.status_code]
status = '%s %s' % (self.status_code, status_text)
response_headers = self.headers.headeritems()
for c in self.cookies.values():
response_headers.append(('Set-Cookie', c.output(header='')))
start_response(status, response_headers)
is_file = isinstance(self.content, file)
if 'wsgi.file_wrapper' in environ and is_file:
return environ['wsgi.file_wrapper'](self.content)
elif is_file:
return iter(lambda: self.content.read(), '')
return self.get_content()
def determine_charset(self):
"""
Determine the encoding as specified by the Content-Type's charset
parameter, if one is set
"""
charset_match = _CHARSET_RE.search(self.headers.get('Content-Type', ''))
if charset_match:
return charset_match.group(1)
def has_header(self, header):
"""
Case-insensitive check for a header
"""
warnings.warn('WSGIResponse.has_header is deprecated, use '
'WSGIResponse.headers.has_key instead', DeprecationWarning,
2)
return self.headers.has_key(header)
def set_cookie(self, key, value='', max_age=None, expires=None, path='/',
domain=None, secure=None, httponly=None):
"""
Define a cookie to be sent via the outgoing HTTP headers
"""
self.cookies[key] = value
for var_name, var_value in [
('max_age', max_age), ('path', path), ('domain', domain),
('secure', secure), ('expires', expires), ('httponly', httponly)]:
if var_value is not None and var_value is not False:
self.cookies[key][var_name.replace('_', '-')] = var_value
def delete_cookie(self, key, path='/', domain=None):
"""
Notify the browser the specified cookie has expired and should be
deleted (via the outgoing HTTP headers)
"""
self.cookies[key] = ''
if path is not None:
self.cookies[key]['path'] = path
if domain is not None:
self.cookies[key]['domain'] = domain
self.cookies[key]['expires'] = 0
self.cookies[key]['max-age'] = 0
def _set_content(self, content):
if hasattr(content, '__iter__'):
self._iter = content
if isinstance(content, list):
self._is_str_iter = True
else:
self._is_str_iter = False
else:
self._iter = [content]
self._is_str_iter = True
content = property(lambda self: self._iter, _set_content,
doc='Get/set the specified content, where content can '
'be: a string, a list of strings, a generator function '
'that yields strings, or an iterable object that '
'produces strings.')
def get_content(self):
"""
Returns the content as an iterable of strings, encoding each element of
the iterator from a Unicode object if necessary.
"""
charset = self.determine_charset()
if charset:
return encode_unicode_app_iter(self.content, charset, self.errors)
else:
return self.content
def wsgi_response(self):
"""
Return this WSGIResponse as a tuple of WSGI formatted data, including:
(status, headers, iterable)
"""
status_text = STATUS_CODE_TEXT[self.status_code]
status = '%s %s' % (self.status_code, status_text)
response_headers = self.headers.headeritems()
for c in self.cookies.values():
response_headers.append(('Set-Cookie', c.output(header='')))
return status, response_headers, self.get_content()
# The remaining methods partially implement the file-like object interface.
# See http://docs.python.org/lib/bltin-file-objects.html
def write(self, content):
if not self._is_str_iter:
raise IOError, "This %s instance's content is not writable: (content " \
'is an iterator)' % self.__class__.__name__
self.content.append(content)
def flush(self):
pass
def tell(self):
if not self._is_str_iter:
raise IOError, 'This %s instance cannot tell its position: (content ' \
'is an iterator)' % self.__class__.__name__
return sum([len(chunk) for chunk in self._iter])
########################################
## Content-type and charset
def charset__get(self):
"""
Get/set the charset (in the Content-Type)
"""
header = self.headers.get('content-type')
if not header:
return None
match = _CHARSET_RE.search(header)
if match:
return match.group(1)
return None
def charset__set(self, charset):
if charset is None:
del self.charset
return
try:
header = self.headers.pop('content-type')
except KeyError:
raise AttributeError(
"You cannot set the charset when no content-type is defined")
match = _CHARSET_RE.search(header)
if match:
header = header[:match.start()] + header[match.end():]
header += '; charset=%s' % charset
self.headers['content-type'] = header
def charset__del(self):
try:
header = self.headers.pop('content-type')
except KeyError:
# Don't need to remove anything
return
match = _CHARSET_RE.search(header)
if match:
header = header[:match.start()] + header[match.end():]
self.headers['content-type'] = header
charset = property(charset__get, charset__set, charset__del, doc=charset__get.__doc__)
def content_type__get(self):
"""
Get/set the Content-Type header (or None), *without* the
charset or any parameters.
If you include parameters (or ``;`` at all) when setting the
content_type, any existing parameters will be deleted;
otherwise they will be preserved.
"""
header = self.headers.get('content-type')
if not header:
return None
return header.split(';', 1)[0]
def content_type__set(self, value):
if ';' not in value:
header = self.headers.get('content-type', '')
if ';' in header:
params = header.split(';', 1)[1]
value += ';' + params
self.headers['content-type'] = value
def content_type__del(self):
try:
del self.headers['content-type']
except KeyError:
pass
content_type = property(content_type__get, content_type__set,
content_type__del, doc=content_type__get.__doc__)
## @@ I'd love to remove this, but paste.httpexceptions.get_exception
## doesn't seem to work...
# See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
STATUS_CODE_TEXT = {
100: 'CONTINUE',
101: 'SWITCHING PROTOCOLS',
200: 'OK',
201: 'CREATED',
202: 'ACCEPTED',
203: 'NON-AUTHORITATIVE INFORMATION',
204: 'NO CONTENT',
205: 'RESET CONTENT',
206: 'PARTIAL CONTENT',
226: 'IM USED',
300: 'MULTIPLE CHOICES',
301: 'MOVED PERMANENTLY',
302: 'FOUND',
303: 'SEE OTHER',
304: 'NOT MODIFIED',
305: 'USE PROXY',
306: 'RESERVED',
307: 'TEMPORARY REDIRECT',
400: 'BAD REQUEST',
401: 'UNAUTHORIZED',
402: 'PAYMENT REQUIRED',
403: 'FORBIDDEN',
404: 'NOT FOUND',
405: 'METHOD NOT ALLOWED',
406: 'NOT ACCEPTABLE',
407: 'PROXY AUTHENTICATION REQUIRED',
408: 'REQUEST TIMEOUT',
409: 'CONFLICT',
410: 'GONE',
411: 'LENGTH REQUIRED',
412: 'PRECONDITION FAILED',
413: 'REQUEST ENTITY TOO LARGE',
414: 'REQUEST-URI TOO LONG',
415: 'UNSUPPORTED MEDIA TYPE',
416: 'REQUESTED RANGE NOT SATISFIABLE',
417: 'EXPECTATION FAILED',
500: 'INTERNAL SERVER ERROR',
501: 'NOT IMPLEMENTED',
502: 'BAD GATEWAY',
503: 'SERVICE UNAVAILABLE',
504: 'GATEWAY TIMEOUT',
505: 'HTTP VERSION NOT SUPPORTED',
}
|
apache-2.0
|
[
3,
334,
67,
9,
11811,
473,
290,
699,
2000,
316,
436,
8417,
27,
5313,
367,
510,
9209,
334,
1014,
921,
1548,
16586,
14,
1308,
9,
199,
3,
3909,
1334,
314,
10697,
4190,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
624,
16828,
21947,
83,
367,
282,
4784,
436,
7232,
199,
199,
1918,
9279,
2017,
436,
9279,
2364,
2251,
787,
10540,
17995,
370,
1852,
652,
14905,
199,
475,
7962,
543,
376,
12467,
1056,
436,
10209,
282,
1177,
14,
199,
624,
199,
646,
295,
199,
646,
3598,
199,
504,
10933,
492,
30843,
199,
504,
14798,
492,
5870,
7810,
199,
504,
20901,
14,
1069,
492,
3447,
1489,
9883,
12,
664,
63,
5306,
63,
807,
12,
971,
272,
2198,
63,
807,
63,
1131,
875,
12,
2198,
63,
964,
2936,
199,
504,
20901,
14,
1974,
14,
3029,
807,
492,
29393,
12,
6140,
21365,
199,
504,
20901,
14,
5189,
492,
13894,
379,
1692,
4936,
199,
504,
20901,
14,
1310,
492,
10240,
2141,
199,
504,
20901,
14,
6508,
773,
492,
3752,
63,
2975,
63,
571,
63,
1661,
199,
504,
20901,
14,
1014,
2139,
492,
28538,
63,
13947,
199,
504,
20901,
14,
1974,
14,
7626,
1122,
492,
6387,
63,
6742,
199,
199,
363,
452,
363,
275,
788,
16828,
2017,
297,
283,
16828,
2364,
418,
199,
199,
63,
23969,
63,
907,
275,
295,
14,
2014,
8,
82,
7,
3779,
83,
10,
6043,
29,
7059,
27,
3672,
3196,
295,
14,
41,
9,
199,
199,
533,
17993,
5268,
8,
4851,
379,
1692,
4936,
304,
272,
347,
485,
5335,
63,
785,
8,
277,
12,
1559,
304,
267,
3598,
14,
4050,
360,
16586,
14,
6508,
21148,
14,
1751,
365,
5906,
26,
7754,
675,
283,
1993,
283,
16586,
14,
6508,
21148,
14,
16828,
2017,
14,
4322,
3140,
297,
1993,
13413,
12,
650,
9,
267,
9279,
2364,
14,
4322,
423,
5335,
63,
785,
8,
1113,
9,
267,
13894,
379,
1692,
4936,
423,
5335,
63,
785,
8,
277,
12,
1559,
9,
199,
199,
3,
2202,
365,
5906,
26,
675,
9279,
2364,
14,
4322,
3140,
199,
1751,
275,
17993,
5268,
8,
885,
29,
807,
1012,
199,
199,
533,
6160,
63,
7416,
8,
785,
304,
272,
408,
1858,
18703,
1958,
376,
2225,
370,
282,
790,
315,
291,
14,
2314,
1041,
272,
327,
13365,
26,
6121,
636,
409,
363,
31,
221,
7719,
4260,
506,
4370,
31,
272,
347,
636,
826,
721,
277,
12,
790,
12,
849,
4581,
849,
63,
3702,
29,
403,
304,
267,
291,
14,
498,
275,
790,
267,
291,
14,
885,
275,
849,
267,
291,
14,
885,
63,
3702,
275,
849,
63,
3702,
272,
347,
636,
362,
721,
277,
12,
1559,
12,
730,
29,
403,
304,
267,
340,
730,
365,
488,
26,
288,
372,
291,
267,
340,
291,
14,
498,
440,
315,
1559,
14,
2314,
26,
288,
340,
291,
14,
885,
63,
3702,
26,
355,
1139,
275,
1559,
14,
2314,
59,
277,
14,
498,
61,
275,
291,
14,
885,
63,
3702,
342,
355,
372,
1139,
288,
587,
26,
355,
372,
291,
14,
885,
267,
372,
1559,
14,
2314,
59,
277,
14,
498,
61,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
2650,
4936,
367,
9279,
6160,
450,
82,
790,
3524,
450,
291,
14,
498,
199,
199,
533,
9279,
2017,
8,
785,
304,
272,
408,
16828,
4784,
3261,
6935,
339,
961,
909,
8469,
282,
9279,
1056,
543,
282,
1655,
21428,
3217,
14,
272,
961,
1630,
440,
23705,
4036,
10093,
402,
314,
9279,
3734,
12,
436,
12454,
272,
370,
4056,
6548,
20561,
4052,
365,
2808,
315,
314,
3734,
272,
2600,
14,
339,
710,
1454,
1174,
26391,
315,
642,
909,
365,
314,
6387,
1124,
6043,
4542,
272,
2399,
4568,
1124,
2550,
1040,
3016,
12,
436,
314,
1124,
2708,
63,
635,
63,
1247,
1040,
272,
945,
14,
339,
710,
12467,
2725,
1338,
911,
506,
5847,
20650,
6867,
370,
2649,
272,
2251,
402,
314,
1124,
6043,
1040,
2644,
1380,
1124,
6043,
1040,
365,
663,
14,
710,
272,
12467,
2725,
1561,
787,
440,
11203,
370,
2649,
7444,
314,
272,
1124,
2708,
63,
635,
63,
1247,
1040,
945,
365,
5223,
14,
339,
3979,
2649,
365,
1420,
12,
1124,
6043,
1040,
911,
10087,
701,
314,
314,
272,
574,
402,
314,
1124,
2714,
13,
804,
1040,
1406,
1159,
5960,
2725,
340,
1373,
1990,
272,
2013,
701,
314,
1890,
14,
339,
710,
1021,
1750,
1124,
4322,
1040,
9314,
849,
1338,
367,
272,
1124,
6043,
4542,
1124,
2550,
4542,
436,
1124,
4159,
30949,
4345,
5723,
883,
506,
10087,
367,
314,
272,
1453,
1056,
4799,
314,
7086,
14,
5493,
710,
1124,
3671,
1040,
849,
574,
365,
8652,
314,
9567,
5309,
284,
1085,
78,
272,
15547,
370,
4868,
315,
16699,
5560,
626,
13492,
10815,
2793,
1133,
4781,
1077,
272,
314,
1124,
3671,
1040,
570,
1395,
314,
1059,
1325,
440,
4573,
2637,
315,
314,
272,
10226,
10815,
769,
14,
710,
1124,
3671,
1040,
574,
1454,
12966,
1380,
10232,
272,
282,
769,
402,
10226,
10815,
687,
314,
3101,
15506,
1406,
14,
2286,
961,
5953,
365,
21747,
687,
437,
392,
759,
453,
12,
436,
1443,
17021,
620,
618,
1325,
365,
272,
7437,
2997,
14,
24573,
12,
8137,
315,
314,
1233,
365,
315,
298,
287,
13,
527,
1674,
221,
9738,
12,
5591,
314,
298,
287,
13,
527,
2,
7761,
10594,
365,
9987,
2701,
14,
221,
982,
314,
922,
4145,
272,
1124,
905,
287,
13,
527,
401,
298,
3951,
13,
6413,
937,
1040,
436,
282,
7761,
5712,
1133,
1911,
367,
282,
1059,
315,
272,
298,
287,
13,
527,
401,
1265,
2793,
1133,
2934,
9796,
370,
9567,
370,
298,
3951,
13,
6413,
1674,
221,
2047,
2934,
652,
370,
5591,
2951,
675,
314,
1059,
6337,
14,
221,
869,
4894,
12,
340,
282,
1059,
5712,
1133,
1911,
315,
314,
272,
1124,
3671,
1040,
10594,
12,
314,
1059,
315,
314,
1350,
1233,
911,
506,
1202,
14,
339,
627,
2422,
10,
1163,
1174,
365,
16204,
315,
314,
3734,
2600,
27,
642,
365,
272,
22829,
1009,
367,
4661,
9198,
3616,
14,
339,
2047,
787,
2867,
370,
5516,
642,
909,
14,
339,
408,
272,
4243,
275,
13894,
379,
1692,
4936,
8,
885,
29,
807,
8,
6043,
29,
403,
12,
2552,
534,
1814,
297,
6901,
4849,
63,
635,
63,
1247,
29,
797,
12,
6901,
2637,
534,
287,
13,
527,
1333,
272,
347,
636,
826,
721,
277,
12
] |
[
334,
67,
9,
11811,
473,
290,
699,
2000,
316,
436,
8417,
27,
5313,
367,
510,
9209,
334,
1014,
921,
1548,
16586,
14,
1308,
9,
199,
3,
3909,
1334,
314,
10697,
4190,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
624,
16828,
21947,
83,
367,
282,
4784,
436,
7232,
199,
199,
1918,
9279,
2017,
436,
9279,
2364,
2251,
787,
10540,
17995,
370,
1852,
652,
14905,
199,
475,
7962,
543,
376,
12467,
1056,
436,
10209,
282,
1177,
14,
199,
624,
199,
646,
295,
199,
646,
3598,
199,
504,
10933,
492,
30843,
199,
504,
14798,
492,
5870,
7810,
199,
504,
20901,
14,
1069,
492,
3447,
1489,
9883,
12,
664,
63,
5306,
63,
807,
12,
971,
272,
2198,
63,
807,
63,
1131,
875,
12,
2198,
63,
964,
2936,
199,
504,
20901,
14,
1974,
14,
3029,
807,
492,
29393,
12,
6140,
21365,
199,
504,
20901,
14,
5189,
492,
13894,
379,
1692,
4936,
199,
504,
20901,
14,
1310,
492,
10240,
2141,
199,
504,
20901,
14,
6508,
773,
492,
3752,
63,
2975,
63,
571,
63,
1661,
199,
504,
20901,
14,
1014,
2139,
492,
28538,
63,
13947,
199,
504,
20901,
14,
1974,
14,
7626,
1122,
492,
6387,
63,
6742,
199,
199,
363,
452,
363,
275,
788,
16828,
2017,
297,
283,
16828,
2364,
418,
199,
199,
63,
23969,
63,
907,
275,
295,
14,
2014,
8,
82,
7,
3779,
83,
10,
6043,
29,
7059,
27,
3672,
3196,
295,
14,
41,
9,
199,
199,
533,
17993,
5268,
8,
4851,
379,
1692,
4936,
304,
272,
347,
485,
5335,
63,
785,
8,
277,
12,
1559,
304,
267,
3598,
14,
4050,
360,
16586,
14,
6508,
21148,
14,
1751,
365,
5906,
26,
7754,
675,
283,
1993,
283,
16586,
14,
6508,
21148,
14,
16828,
2017,
14,
4322,
3140,
297,
1993,
13413,
12,
650,
9,
267,
9279,
2364,
14,
4322,
423,
5335,
63,
785,
8,
1113,
9,
267,
13894,
379,
1692,
4936,
423,
5335,
63,
785,
8,
277,
12,
1559,
9,
199,
199,
3,
2202,
365,
5906,
26,
675,
9279,
2364,
14,
4322,
3140,
199,
1751,
275,
17993,
5268,
8,
885,
29,
807,
1012,
199,
199,
533,
6160,
63,
7416,
8,
785,
304,
272,
408,
1858,
18703,
1958,
376,
2225,
370,
282,
790,
315,
291,
14,
2314,
1041,
272,
327,
13365,
26,
6121,
636,
409,
363,
31,
221,
7719,
4260,
506,
4370,
31,
272,
347,
636,
826,
721,
277,
12,
790,
12,
849,
4581,
849,
63,
3702,
29,
403,
304,
267,
291,
14,
498,
275,
790,
267,
291,
14,
885,
275,
849,
267,
291,
14,
885,
63,
3702,
275,
849,
63,
3702,
272,
347,
636,
362,
721,
277,
12,
1559,
12,
730,
29,
403,
304,
267,
340,
730,
365,
488,
26,
288,
372,
291,
267,
340,
291,
14,
498,
440,
315,
1559,
14,
2314,
26,
288,
340,
291,
14,
885,
63,
3702,
26,
355,
1139,
275,
1559,
14,
2314,
59,
277,
14,
498,
61,
275,
291,
14,
885,
63,
3702,
342,
355,
372,
1139,
288,
587,
26,
355,
372,
291,
14,
885,
267,
372,
1559,
14,
2314,
59,
277,
14,
498,
61,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
2650,
4936,
367,
9279,
6160,
450,
82,
790,
3524,
450,
291,
14,
498,
199,
199,
533,
9279,
2017,
8,
785,
304,
272,
408,
16828,
4784,
3261,
6935,
339,
961,
909,
8469,
282,
9279,
1056,
543,
282,
1655,
21428,
3217,
14,
272,
961,
1630,
440,
23705,
4036,
10093,
402,
314,
9279,
3734,
12,
436,
12454,
272,
370,
4056,
6548,
20561,
4052,
365,
2808,
315,
314,
3734,
272,
2600,
14,
339,
710,
1454,
1174,
26391,
315,
642,
909,
365,
314,
6387,
1124,
6043,
4542,
272,
2399,
4568,
1124,
2550,
1040,
3016,
12,
436,
314,
1124,
2708,
63,
635,
63,
1247,
1040,
272,
945,
14,
339,
710,
12467,
2725,
1338,
911,
506,
5847,
20650,
6867,
370,
2649,
272,
2251,
402,
314,
1124,
6043,
1040,
2644,
1380,
1124,
6043,
1040,
365,
663,
14,
710,
272,
12467,
2725,
1561,
787,
440,
11203,
370,
2649,
7444,
314,
272,
1124,
2708,
63,
635,
63,
1247,
1040,
945,
365,
5223,
14,
339,
3979,
2649,
365,
1420,
12,
1124,
6043,
1040,
911,
10087,
701,
314,
314,
272,
574,
402,
314,
1124,
2714,
13,
804,
1040,
1406,
1159,
5960,
2725,
340,
1373,
1990,
272,
2013,
701,
314,
1890,
14,
339,
710,
1021,
1750,
1124,
4322,
1040,
9314,
849,
1338,
367,
272,
1124,
6043,
4542,
1124,
2550,
4542,
436,
1124,
4159,
30949,
4345,
5723,
883,
506,
10087,
367,
314,
272,
1453,
1056,
4799,
314,
7086,
14,
5493,
710,
1124,
3671,
1040,
849,
574,
365,
8652,
314,
9567,
5309,
284,
1085,
78,
272,
15547,
370,
4868,
315,
16699,
5560,
626,
13492,
10815,
2793,
1133,
4781,
1077,
272,
314,
1124,
3671,
1040,
570,
1395,
314,
1059,
1325,
440,
4573,
2637,
315,
314,
272,
10226,
10815,
769,
14,
710,
1124,
3671,
1040,
574,
1454,
12966,
1380,
10232,
272,
282,
769,
402,
10226,
10815,
687,
314,
3101,
15506,
1406,
14,
2286,
961,
5953,
365,
21747,
687,
437,
392,
759,
453,
12,
436,
1443,
17021,
620,
618,
1325,
365,
272,
7437,
2997,
14,
24573,
12,
8137,
315,
314,
1233,
365,
315,
298,
287,
13,
527,
1674,
221,
9738,
12,
5591,
314,
298,
287,
13,
527,
2,
7761,
10594,
365,
9987,
2701,
14,
221,
982,
314,
922,
4145,
272,
1124,
905,
287,
13,
527,
401,
298,
3951,
13,
6413,
937,
1040,
436,
282,
7761,
5712,
1133,
1911,
367,
282,
1059,
315,
272,
298,
287,
13,
527,
401,
1265,
2793,
1133,
2934,
9796,
370,
9567,
370,
298,
3951,
13,
6413,
1674,
221,
2047,
2934,
652,
370,
5591,
2951,
675,
314,
1059,
6337,
14,
221,
869,
4894,
12,
340,
282,
1059,
5712,
1133,
1911,
315,
314,
272,
1124,
3671,
1040,
10594,
12,
314,
1059,
315,
314,
1350,
1233,
911,
506,
1202,
14,
339,
627,
2422,
10,
1163,
1174,
365,
16204,
315,
314,
3734,
2600,
27,
642,
365,
272,
22829,
1009,
367,
4661,
9198,
3616,
14,
339,
2047,
787,
2867,
370,
5516,
642,
909,
14,
339,
408,
272,
4243,
275,
13894,
379,
1692,
4936,
8,
885,
29,
807,
8,
6043,
29,
403,
12,
2552,
534,
1814,
297,
6901,
4849,
63,
635,
63,
1247,
29,
797,
12,
6901,
2637,
534,
287,
13,
527,
1333,
272,
347,
636,
826,
721,
277,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
liangazhou/django-rdp
|
packages/Django-1.8.6/tests/template_backends/test_utils.py
|
351
|
1521
|
from django.core.exceptions import ImproperlyConfigured
from django.template import engines
from django.test import SimpleTestCase, override_settings
class TemplateStringsTests(SimpleTestCase):
@override_settings(TEMPLATES=[{
'BACKEND': 'raise.import.error',
}])
def test_backend_import_error(self):
"""
Failing to import a backend keeps raising the original import error.
Regression test for #24265.
"""
with self.assertRaises(ImportError):
engines.all()
with self.assertRaises(ImportError):
engines.all()
@override_settings(TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
# Incorrect: APP_DIRS and loaders are mutually incompatible.
'APP_DIRS': True,
'OPTIONS': {'loaders': []},
}])
def test_backend_improperly_configured(self):
"""
Failing to initialize a backend keeps raising the original exception.
Regression test for #24265.
"""
with self.assertRaises(ImproperlyConfigured):
engines.all()
with self.assertRaises(ImproperlyConfigured):
engines.all()
@override_settings(TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
}, {
'BACKEND': 'django.template.backends.django.DjangoTemplates',
}])
def test_backend_names_must_be_unique(self):
with self.assertRaises(ImproperlyConfigured):
engines.all()
|
apache-2.0
|
[
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1160,
492,
28156,
199,
504,
1639,
14,
396,
492,
24424,
12,
4278,
63,
1751,
421,
199,
533,
5458,
12672,
2925,
8,
17968,
304,
339,
768,
4415,
63,
1751,
8,
25437,
1524,
91,
267,
283,
18145,
356,
283,
3730,
14,
646,
14,
705,
297,
272,
789,
566,
272,
347,
511,
63,
4620,
63,
646,
63,
705,
8,
277,
304,
267,
408,
267,
12176,
316,
370,
492,
282,
4865,
18578,
17026,
314,
3379,
492,
1125,
14,
398,
13262,
511,
367,
327,
1194,
13730,
14,
267,
408,
267,
543,
291,
14,
1855,
8,
17825,
304,
288,
28156,
14,
452,
342,
267,
543,
291,
14,
1855,
8,
17825,
304,
288,
28156,
14,
452,
342,
339,
768,
4415,
63,
1751,
8,
25437,
1524,
91,
267,
283,
18145,
356,
283,
1176,
14,
1160,
14,
7765,
14,
1176,
14,
9323,
17969,
297,
267,
327,
1010,
4525,
26,
19525,
63,
14455,
436,
25520,
787,
16108,
18457,
14,
267,
283,
7121,
63,
14455,
356,
715,
12,
267,
283,
8808,
356,
791,
16370,
356,
28657,
272,
789,
566,
272,
347,
511,
63,
4620,
63,
3236,
10567,
63,
11786,
8,
277,
304,
267,
408,
267,
12176,
316,
370,
8265,
282,
4865,
18578,
17026,
314,
3379,
1919,
14,
398,
13262,
511,
367,
327,
1194,
13730,
14,
267,
408,
267,
543,
291,
14,
1855,
8,
8499,
10951,
304,
288,
28156,
14,
452,
342,
267,
543,
291,
14,
1855,
8,
8499,
10951,
304,
288,
28156,
14,
452,
342,
339,
768,
4415,
63,
1751,
8,
25437,
1524,
91,
267,
283,
18145,
356,
283,
1176,
14,
1160,
14,
7765,
14,
1176,
14,
9323,
17969,
297,
272,
1660,
469,
267,
283,
18145,
356,
283,
1176,
14,
1160,
14,
7765,
14,
1176,
14,
9323,
17969,
297,
272,
789,
566,
272,
347,
511,
63,
4620,
63,
1247,
63,
7790,
63,
1235,
63,
3235,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
8499,
10951,
304,
288,
28156,
14,
452,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1160,
492,
28156,
199,
504,
1639,
14,
396,
492,
24424,
12,
4278,
63,
1751,
421,
199,
533,
5458,
12672,
2925,
8,
17968,
304,
339,
768,
4415,
63,
1751,
8,
25437,
1524,
91,
267,
283,
18145,
356,
283,
3730,
14,
646,
14,
705,
297,
272,
789,
566,
272,
347,
511,
63,
4620,
63,
646,
63,
705,
8,
277,
304,
267,
408,
267,
12176,
316,
370,
492,
282,
4865,
18578,
17026,
314,
3379,
492,
1125,
14,
398,
13262,
511,
367,
327,
1194,
13730,
14,
267,
408,
267,
543,
291,
14,
1855,
8,
17825,
304,
288,
28156,
14,
452,
342,
267,
543,
291,
14,
1855,
8,
17825,
304,
288,
28156,
14,
452,
342,
339,
768,
4415,
63,
1751,
8,
25437,
1524,
91,
267,
283,
18145,
356,
283,
1176,
14,
1160,
14,
7765,
14,
1176,
14,
9323,
17969,
297,
267,
327,
1010,
4525,
26,
19525,
63,
14455,
436,
25520,
787,
16108,
18457,
14,
267,
283,
7121,
63,
14455,
356,
715,
12,
267,
283,
8808,
356,
791,
16370,
356,
28657,
272,
789,
566,
272,
347,
511,
63,
4620,
63,
3236,
10567,
63,
11786,
8,
277,
304,
267,
408,
267,
12176,
316,
370,
8265,
282,
4865,
18578,
17026,
314,
3379,
1919,
14,
398,
13262,
511,
367,
327,
1194,
13730,
14,
267,
408,
267,
543,
291,
14,
1855,
8,
8499,
10951,
304,
288,
28156,
14,
452,
342,
267,
543,
291,
14,
1855,
8,
8499,
10951,
304,
288,
28156,
14,
452,
342,
339,
768,
4415,
63,
1751,
8,
25437,
1524,
91,
267,
283,
18145,
356,
283,
1176,
14,
1160,
14,
7765,
14,
1176,
14,
9323,
17969,
297,
272,
1660,
469,
267,
283,
18145,
356,
283,
1176,
14,
1160,
14,
7765,
14,
1176,
14,
9323,
17969,
297,
272,
789,
566,
272,
347,
511,
63,
4620,
63,
1247,
63,
7790,
63,
1235,
63,
3235,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
8499,
10951,
304,
288,
28156,
14,
452,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
a10networks/a10sdk-python
|
a10sdk/core/sflow/sflow_polling.py
|
2
|
3657
|
from a10sdk.common.A10BaseClass import A10BaseClass
class EthList(A10BaseClass):
"""This class does not support CRUD Operations please use parent.
:param eth_end: {"type": "number", "description": "Ethernet interface to sample", "format": "interface"}
:param eth_start: {"type": "number", "description": "Ethernet interface to sample", "format": "interface"}
:param DeviceProxy: The device proxy for REST operations and session handling. Refer to `common/device_proxy.py`
"""
def __init__(self, **kwargs):
self.ERROR_MSG = ""
self.b_key = "eth-list"
self.DeviceProxy = ""
self.eth_end = ""
self.eth_start = ""
for keys, value in kwargs.items():
setattr(self,keys, value)
class VeList(A10BaseClass):
"""This class does not support CRUD Operations please use parent.
:param ve_end: {"$ref": "/axapi/v3/interface/ve", "type": "number", "description": "VE interface to sample", "format": "number"}
:param ve_start: {"$ref": "/axapi/v3/interface/ve", "type": "number", "description": "VE interface to sample", "format": "number"}
:param DeviceProxy: The device proxy for REST operations and session handling. Refer to `common/device_proxy.py`
"""
def __init__(self, **kwargs):
self.ERROR_MSG = ""
self.b_key = "ve-list"
self.DeviceProxy = ""
self.ve_end = ""
self.ve_start = ""
for keys, value in kwargs.items():
setattr(self,keys, value)
class Polling(A10BaseClass):
""" :param cpu_usage: {"default": 0, "optional": true, "type": "number", "description": "Polling CPU usage", "format": "flag"}
:param eth_list: {"minItems": 1, "items": {"type": "object"}, "uniqueItems": true, "type": "array", "array": [{"properties": {"eth-end": {"type": "number", "description": "Ethernet interface to sample", "format": "interface"}, "optional": true, "eth-start": {"type": "number", "description": "Ethernet interface to sample", "format": "interface"}}}]}
:param http_counter: {"default": 0, "optional": true, "type": "number", "description": "Polling HTTP counters", "format": "flag"}
:param uuid: {"description": "uuid of the object", "format": "string", "minLength": 1, "modify-not-allowed": 1, "optional": true, "maxLength": 64, "type": "string"}
:param ve_list: {"minItems": 1, "items": {"type": "object"}, "uniqueItems": true, "type": "array", "array": [{"properties": {"ve-end": {"$ref": "/axapi/v3/interface/ve", "type": "number", "description": "VE interface to sample", "format": "number"}, "ve-start": {"$ref": "/axapi/v3/interface/ve", "type": "number", "description": "VE interface to sample", "format": "number"}, "optional": true}}]}
:param DeviceProxy: The device proxy for REST operations and session handling. Refer to `common/device_proxy.py`
Class Description::
Configure sFlow counter polling on specified source.
Class polling supports CRUD Operations and inherits from `common/A10BaseClass`.
This class is the `"PARENT"` class for this module.`
URL for this object::
`https://<Hostname|Ip address>//axapi/v3/sflow/polling`.
"""
def __init__(self, **kwargs):
self.ERROR_MSG = ""
self.required=[]
self.b_key = "polling"
self.a10_url="/axapi/v3/sflow/polling"
self.DeviceProxy = ""
self.cpu_usage = ""
self.eth_list = []
self.http_counter = ""
self.uuid = ""
self.ve_list = []
for keys, value in kwargs.items():
setattr(self,keys, value)
|
apache-2.0
|
[
504,
282,
709,
9277,
14,
2330,
14,
33,
709,
1563,
2543,
492,
437,
709,
1563,
2543,
421,
199,
533,
662,
273,
1296,
8,
33,
709,
1563,
2543,
304,
2286,
408,
2765,
1021,
1630,
440,
2291,
17101,
3383,
29474,
8749,
675,
1676,
14,
339,
520,
635,
16227,
63,
500,
26,
2420,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
22056,
3217,
370,
2690,
401,
298,
908,
582,
298,
3266,
3570,
272,
520,
635,
16227,
63,
928,
26,
2420,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
22056,
3217,
370,
2690,
401,
298,
908,
582,
298,
3266,
3570,
272,
520,
635,
12272,
4936,
26,
710,
2243,
4566,
367,
14880,
5331,
436,
2351,
7252,
14,
21751,
370,
658,
2330,
15,
1782,
63,
3280,
14,
647,
64,
10813,
25979,
408,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
14,
3170,
63,
9740,
275,
3087,
2728,
291,
14,
66,
63,
498,
275,
298,
12391,
13,
513,
2,
267,
291,
14,
2510,
4936,
275,
3087,
267,
291,
14,
12391,
63,
500,
275,
3087,
267,
291,
14,
12391,
63,
928,
275,
3087,
398,
367,
2883,
12,
574,
315,
2074,
14,
1744,
837,
288,
5371,
8,
277,
12,
1612,
12,
574,
9,
421,
199,
533,
25777,
1296,
8,
33,
709,
1563,
2543,
304,
2286,
408,
2765,
1021,
1630,
440,
2291,
17101,
3383,
29474,
8749,
675,
1676,
14,
339,
520,
635,
11199,
63,
500,
26,
2420,
4,
1121,
582,
3286,
1219,
1246,
15,
86,
19,
15,
3266,
15,
432,
401,
298,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
2524,
3217,
370,
2690,
401,
298,
908,
582,
298,
1955,
3570,
272,
520,
635,
11199,
63,
928,
26,
2420,
4,
1121,
582,
3286,
1219,
1246,
15,
86,
19,
15,
3266,
15,
432,
401,
298,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
2524,
3217,
370,
2690,
401,
298,
908,
582,
298,
1955,
3570,
272,
520,
635,
12272,
4936,
26,
710,
2243,
4566,
367,
14880,
5331,
436,
2351,
7252,
14,
21751,
370,
658,
2330,
15,
1782,
63,
3280,
14,
647,
64,
10813,
25979,
408,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
14,
3170,
63,
9740,
275,
3087,
2728,
291,
14,
66,
63,
498,
275,
298,
432,
13,
513,
2,
267,
291,
14,
2510,
4936,
275,
3087,
267,
291,
14,
432,
63,
500,
275,
3087,
267,
291,
14,
432,
63,
928,
275,
3087,
398,
367,
2883,
12,
574,
315,
2074,
14,
1744,
837,
288,
5371,
8,
277,
12,
1612,
12,
574,
9,
421,
199,
533,
8467,
2983,
8,
33,
709,
1563,
2543,
304,
2286,
408,
259,
520,
635,
5033,
63,
3807,
26,
2420,
885,
582,
378,
12,
298,
4144,
582,
2549,
12,
298,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
28588,
11952,
4503,
401,
298,
908,
582,
298,
4173,
3570,
272,
520,
635,
16227,
63,
513,
26,
2420,
827,
7412,
582,
413,
12,
298,
1744,
582,
2420,
466,
582,
298,
785,
6018,
298,
3235,
7412,
582,
2549,
12,
298,
466,
582,
298,
1144,
401,
298,
1144,
582,
16870,
3282,
582,
2420,
12391,
13,
500,
582,
2420,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
22056,
3217,
370,
2690,
401,
298,
908,
582,
298,
3266,
6018,
298,
4144,
582,
2549,
12,
298,
12391,
13,
928,
582,
2420,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
22056,
3217,
370,
2690,
401,
298,
908,
582,
298,
3266,
3570,
4863,
9420,
272,
520,
635,
1455,
63,
5337,
26,
2420,
885,
582,
378,
12,
298,
4144,
582,
2549,
12,
298,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
28588,
3101,
21272,
401,
298,
908,
582,
298,
4173,
3570,
272,
520,
635,
5377,
26,
2420,
1802,
582,
298,
2580,
402,
314,
909,
401,
298,
908,
582,
298,
875,
401,
298,
827,
4625,
582,
413,
12,
298,
8951,
13,
1397,
13,
6541,
582,
413,
12,
298,
4144,
582,
2549,
12,
298,
988,
4625,
582,
5049,
12,
298,
466,
582,
298,
875,
3570,
272,
520,
635,
11199,
63,
513,
26,
2420,
827,
7412,
582,
413,
12,
298,
1744,
582,
2420,
466,
582,
298,
785,
6018,
298,
3235,
7412,
582,
2549,
12,
298,
466,
582,
298,
1144,
401,
298,
1144,
582,
16870,
3282,
582,
2420,
432,
13,
500,
582,
2420,
4,
1121,
582,
3286,
1219,
1246,
15,
86,
19,
15,
3266,
15,
432,
401,
298,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
2524,
3217,
370,
2690,
401,
298,
908,
582,
298,
1955,
6018,
298,
432,
13,
928,
582,
2420,
4,
1121,
582,
3286,
1219,
1246,
15,
86,
19,
15,
3266,
15,
432,
401,
298,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
2524,
3217,
370,
2690,
401,
298,
908,
582,
298,
1955,
6018,
298,
4144,
582,
2549,
4863,
9420,
272,
520,
635,
12272,
4936,
26,
710,
2243,
4566,
367,
14880,
5331,
436,
2351,
7252,
14,
21751,
370,
658,
2330,
15,
1782,
63,
3280,
14,
647,
64,
199,
199,
2543,
11994,
447,
272,
15453,
308,
5060,
7055,
12353,
641,
2013,
1350,
14,
339,
8089,
12353,
5171,
17101,
3383,
29474,
436,
21592,
687,
658,
2330,
15,
33,
709,
1563,
2543,
2313,
272,
961,
1021,
365,
314,
28531,
20562,
2,
64,
1021,
367,
642,
859,
14,
64,
10813,
339,
2851,
367,
642,
909,
447,
272,
658,
2859,
921,
28,
25680,
92,
6583,
2287,
30,
501,
1219,
1246,
15,
86,
19,
15,
83,
1659,
15,
17154,
2313,
10813,
25979,
408,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
14,
3170,
63,
9740,
275,
3087,
267,
291,
14,
2427,
9811,
267,
291,
14,
66,
63,
498,
275,
298,
17154,
2,
267,
291,
14,
65,
709,
63,
633,
9555,
1219,
1246,
15,
86,
19,
15,
83,
1659,
15,
17154,
2,
267,
291,
14,
2510,
4936,
275,
3087,
267,
291,
14,
3541,
63,
3807,
275,
3087,
267,
291,
14,
12391,
63,
513,
275,
942,
267,
291,
14,
1014,
63,
5337,
275,
3087,
267,
291,
14,
2580,
275,
3087,
267,
291,
14,
432,
63,
513,
275,
942,
398,
367,
2883,
12,
574,
315,
2074,
14,
1744,
837,
288,
5371,
8,
277,
12,
1612,
12,
574,
9,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
282,
709,
9277,
14,
2330,
14,
33,
709,
1563,
2543,
492,
437,
709,
1563,
2543,
421,
199,
533,
662,
273,
1296,
8,
33,
709,
1563,
2543,
304,
2286,
408,
2765,
1021,
1630,
440,
2291,
17101,
3383,
29474,
8749,
675,
1676,
14,
339,
520,
635,
16227,
63,
500,
26,
2420,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
22056,
3217,
370,
2690,
401,
298,
908,
582,
298,
3266,
3570,
272,
520,
635,
16227,
63,
928,
26,
2420,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
22056,
3217,
370,
2690,
401,
298,
908,
582,
298,
3266,
3570,
272,
520,
635,
12272,
4936,
26,
710,
2243,
4566,
367,
14880,
5331,
436,
2351,
7252,
14,
21751,
370,
658,
2330,
15,
1782,
63,
3280,
14,
647,
64,
10813,
25979,
408,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
14,
3170,
63,
9740,
275,
3087,
2728,
291,
14,
66,
63,
498,
275,
298,
12391,
13,
513,
2,
267,
291,
14,
2510,
4936,
275,
3087,
267,
291,
14,
12391,
63,
500,
275,
3087,
267,
291,
14,
12391,
63,
928,
275,
3087,
398,
367,
2883,
12,
574,
315,
2074,
14,
1744,
837,
288,
5371,
8,
277,
12,
1612,
12,
574,
9,
421,
199,
533,
25777,
1296,
8,
33,
709,
1563,
2543,
304,
2286,
408,
2765,
1021,
1630,
440,
2291,
17101,
3383,
29474,
8749,
675,
1676,
14,
339,
520,
635,
11199,
63,
500,
26,
2420,
4,
1121,
582,
3286,
1219,
1246,
15,
86,
19,
15,
3266,
15,
432,
401,
298,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
2524,
3217,
370,
2690,
401,
298,
908,
582,
298,
1955,
3570,
272,
520,
635,
11199,
63,
928,
26,
2420,
4,
1121,
582,
3286,
1219,
1246,
15,
86,
19,
15,
3266,
15,
432,
401,
298,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
2524,
3217,
370,
2690,
401,
298,
908,
582,
298,
1955,
3570,
272,
520,
635,
12272,
4936,
26,
710,
2243,
4566,
367,
14880,
5331,
436,
2351,
7252,
14,
21751,
370,
658,
2330,
15,
1782,
63,
3280,
14,
647,
64,
10813,
25979,
408,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
14,
3170,
63,
9740,
275,
3087,
2728,
291,
14,
66,
63,
498,
275,
298,
432,
13,
513,
2,
267,
291,
14,
2510,
4936,
275,
3087,
267,
291,
14,
432,
63,
500,
275,
3087,
267,
291,
14,
432,
63,
928,
275,
3087,
398,
367,
2883,
12,
574,
315,
2074,
14,
1744,
837,
288,
5371,
8,
277,
12,
1612,
12,
574,
9,
421,
199,
533,
8467,
2983,
8,
33,
709,
1563,
2543,
304,
2286,
408,
259,
520,
635,
5033,
63,
3807,
26,
2420,
885,
582,
378,
12,
298,
4144,
582,
2549,
12,
298,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
28588,
11952,
4503,
401,
298,
908,
582,
298,
4173,
3570,
272,
520,
635,
16227,
63,
513,
26,
2420,
827,
7412,
582,
413,
12,
298,
1744,
582,
2420,
466,
582,
298,
785,
6018,
298,
3235,
7412,
582,
2549,
12,
298,
466,
582,
298,
1144,
401,
298,
1144,
582,
16870,
3282,
582,
2420,
12391,
13,
500,
582,
2420,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
22056,
3217,
370,
2690,
401,
298,
908,
582,
298,
3266,
6018,
298,
4144,
582,
2549,
12,
298,
12391,
13,
928,
582,
2420,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
22056,
3217,
370,
2690,
401,
298,
908,
582,
298,
3266,
3570,
4863,
9420,
272,
520,
635,
1455,
63,
5337,
26,
2420,
885,
582,
378,
12,
298,
4144,
582,
2549,
12,
298,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
28588,
3101,
21272,
401,
298,
908,
582,
298,
4173,
3570,
272,
520,
635,
5377,
26,
2420,
1802,
582,
298,
2580,
402,
314,
909,
401,
298,
908,
582,
298,
875,
401,
298,
827,
4625,
582,
413,
12,
298,
8951,
13,
1397,
13,
6541,
582,
413,
12,
298,
4144,
582,
2549,
12,
298,
988,
4625,
582,
5049,
12,
298,
466,
582,
298,
875,
3570,
272,
520,
635,
11199,
63,
513,
26,
2420,
827,
7412,
582,
413,
12,
298,
1744,
582,
2420,
466,
582,
298,
785,
6018,
298,
3235,
7412,
582,
2549,
12,
298,
466,
582,
298,
1144,
401,
298,
1144,
582,
16870,
3282,
582,
2420,
432,
13,
500,
582,
2420,
4,
1121,
582,
3286,
1219,
1246,
15,
86,
19,
15,
3266,
15,
432,
401,
298,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
2524,
3217,
370,
2690,
401,
298,
908,
582,
298,
1955,
6018,
298,
432,
13,
928,
582,
2420,
4,
1121,
582,
3286,
1219,
1246,
15,
86,
19,
15,
3266,
15,
432,
401,
298,
466,
582,
298,
1955,
401,
298,
1802,
582,
298,
2524,
3217,
370,
2690,
401,
298,
908,
582,
298,
1955,
6018,
298,
4144,
582,
2549,
4863,
9420,
272,
520,
635,
12272,
4936,
26,
710,
2243,
4566,
367,
14880,
5331,
436,
2351,
7252,
14,
21751,
370,
658,
2330,
15,
1782,
63,
3280,
14,
647,
64,
199,
199,
2543,
11994,
447,
272,
15453,
308,
5060,
7055,
12353,
641,
2013,
1350,
14,
339,
8089,
12353,
5171,
17101,
3383,
29474,
436,
21592,
687,
658,
2330,
15,
33,
709,
1563,
2543,
2313,
272,
961,
1021,
365,
314,
28531,
20562,
2,
64,
1021,
367,
642,
859,
14,
64,
10813,
339,
2851,
367,
642,
909,
447,
272,
658,
2859,
921,
28,
25680,
92,
6583,
2287,
30,
501,
1219,
1246,
15,
86,
19,
15,
83,
1659,
15,
17154,
2313,
10813,
25979,
408,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
14,
3170,
63,
9740,
275,
3087,
267,
291,
14,
2427,
9811,
267,
291,
14,
66,
63,
498,
275,
298,
17154,
2,
267,
291,
14,
65,
709,
63,
633,
9555,
1219,
1246,
15,
86,
19,
15,
83,
1659,
15,
17154,
2,
267,
291,
14,
2510,
4936,
275,
3087,
267,
291,
14,
3541,
63,
3807,
275,
3087,
267,
291,
14,
12391,
63,
513,
275,
942,
267,
291,
14,
1014,
63,
5337,
275,
3087,
267,
291,
14,
2580,
275,
3087,
267,
291,
14,
432,
63,
513,
275,
942,
398,
367,
2883,
12,
574,
315,
2074,
14,
1744,
837,
288,
5371,
8,
277,
12,
1612,
12,
574,
9,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
angstwad/ansible
|
lib/ansible/module_utils/openswitch.py
|
4
|
7084
|
#
# (c) 2015 Peter Sprygada, <psprygada@ansible.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
import re
try:
import ovs.poller
import ops.dc
from ops.settings import settings
from opslib import restparser
HAS_OPS = True
except ImportError:
HAS_OPS = False
from ansible.module_utils.basic import json, json_dict_bytes_to_unicode
from ansible.module_utils.network import ModuleStub, NetCli, NetworkError
from ansible.module_utils.network import add_argument, register_transport, to_list
from ansible.module_utils.urls import fetch_url, url_argument_spec
# temporary fix until modules are update. to be removed before 2.2 final
from ansible.module_utils.network import get_module
add_argument('use_ssl', dict(default=True, type='bool'))
add_argument('validate_certs', dict(default=True, type='bool'))
def get_opsidl():
extschema = restparser.parseSchema(settings.get('ext_schema'))
ovsschema = settings.get('ovs_schema')
ovsremote = settings.get('ovs_remote')
opsidl = ops.dc.register(extschema, ovsschema, ovsremote)
init_seqno = opsidl.change_seqno
while True:
opsidl.run()
if init_seqno != opsidl.change_seqno:
break
poller = ovs.poller.Poller()
opsidl.wait(poller)
poller.block()
return (extschema, opsidl)
class Response(object):
def __init__(self, resp, hdrs):
self.body = None
self.headers = hdrs
if resp:
self.body = resp.read()
@property
def json(self):
if not self.body:
return None
try:
return json.loads(self.body)
except ValueError:
return None
class Rest(object):
def __init__(self):
self.url = None
self.url_args = ModuleStub(url_argument_spec(), self._error)
self.headers = dict({'Content-Type': 'application/json', 'Accept': 'application/json'})
self._connected = False
def _error(self, msg):
raise NetworkError(msg, url=self.url)
def connect(self, params, **kwargs):
host = params['host']
port = params['port']
# sets the module_utils/urls.py req parameters
self.url_args.params['url_username'] = params['username']
self.url_args.params['url_password'] = params['password']
self.url_args.params['validate_certs'] = params['validate_certs']
if params['use_ssl']:
proto = 'https'
if not port:
port = 443
else:
proto = 'http'
if not port:
port = 80
baseurl = '%s://%s:%s' % (proto, host, port)
headers = dict({'Content-Type': 'application/x-www-form-urlencoded'})
# Get a cookie and save it the rest of the operations.
url = '%s/%s' % (baseurl, 'login')
data = 'username=%s&password=%s' % (params['username'], params['password'])
resp, hdrs = fetch_url(self.url_args, url, data=data, headers=headers, method='POST')
# Update the base url for the rest of the operations.
self.url = '%s/rest/v1' % (baseurl)
self.headers['Cookie'] = resp.headers.get('Set-Cookie')
def disconnect(self, **kwargs):
self.url = None
self._connected = False
def authorize(self, params, **kwargs):
raise NotImplementedError
def _url_builder(self, path):
if path[0] == '/':
path = path[1:]
return '%s/%s' % (self.url, path)
def request(self, method, path, data=None, headers=None):
url = self._url_builder(path)
data = self._jsonify(data)
if headers is None:
headers = dict()
headers.update(self.headers)
resp, hdrs = fetch_url(self.url_args, url, data=data, headers=headers, method=method)
return Response(resp, hdrs)
def get(self, path, data=None, headers=None):
return self.request('GET', path, data, headers)
def put(self, path, data=None, headers=None):
return self.request('PUT', path, data, headers)
def post(self, path, data=None, headers=None):
return self.request('POST', path, data, headers)
def delete(self, path, data=None, headers=None):
return self.request('DELETE', path, data, headers)
def configure(self, commands):
path = '/system/full-configuration'
return self.put(path, data=commands)
def load_config(self, commands, **kwargs):
raise NotImplementedError
def get_config(self, **kwargs):
resp = self.get('/system/full-configuration')
return resp.json
def commit_config(self, **kwargs):
raise NotImplementedError
def abort_config(self, **kwargs):
raise NotImplementedError
def save_config(self):
raise NotImplementedError
def _jsonify(self, data):
for encoding in ("utf-8", "latin-1"):
try:
return json.dumps(data, encoding=encoding)
# Old systems using old simplejson module does not support encoding keyword.
except TypeError:
try:
new_data = json_dict_bytes_to_unicode(data, encoding=encoding)
except UnicodeDecodeError:
continue
return json.dumps(new_data)
except UnicodeDecodeError:
continue
self._error(msg='Invalid unicode encoding encountered')
Rest = register_transport('rest')(Rest)
class Cli(NetCli):
CLI_PROMPTS_RE = None
CLI_ERRORS_RE = None
NET_PASSWD_RE = re.compile(r"[\r\n]?password: $", re.I)
def configure(self, commands, **kwargs):
cmds = ['configure terminal']
cmds.extend(to_list(commands))
responses = self.execute(cmds)
return responses[1:]
def get_config(self, params, **kwargs):
return self.execute('show running-config')[0]
def load_config(self, commands, commit=False, **kwargs):
raise NotImplementedError
def replace_config(self, commands, **kwargs):
raise NotImplementedError
def commit_config(self, **kwargs):
raise NotImplementedError
def abort_config(self, **kwargs):
raise NotImplementedError
def save_config(self):
raise NotImplementedError
def run_commands(self, commands):
cmds = to_list(commands)
responses = self.execute(cmds)
return responses
Cli = register_transport('cli', default=True)(Cli)
|
gpl-3.0
|
[
3,
199,
3,
334,
67,
9,
6900,
22912,
8360,
651,
71,
10641,
12,
665,
80,
681,
651,
71,
10641,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
646,
295,
199,
199,
893,
26,
272,
492,
23671,
14,
26746,
272,
492,
4156,
14,
3833,
272,
687,
4156,
14,
1751,
492,
2202,
272,
687,
4156,
773,
492,
4618,
2087,
272,
7509,
63,
21665,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
21665,
275,
756,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
2022,
12,
2022,
63,
807,
63,
2394,
63,
475,
63,
2975,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
492,
5673,
8067,
12,
5365,
20653,
12,
7220,
547,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
492,
1050,
63,
2094,
12,
2274,
63,
5545,
12,
370,
63,
513,
199,
504,
3242,
14,
578,
63,
1208,
14,
3603,
492,
5267,
63,
633,
12,
1166,
63,
2094,
63,
1650,
199,
199,
3,
7937,
5325,
5133,
4621,
787,
1678,
14,
221,
370,
506,
4829,
2544,
499,
14,
18,
4242,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
492,
664,
63,
578,
199,
199,
525,
63,
2094,
360,
1180,
63,
4266,
297,
1211,
8,
885,
29,
549,
12,
730,
534,
2245,
1333,
199,
525,
63,
2094,
360,
3502,
63,
8356,
297,
1211,
8,
885,
29,
549,
12,
730,
534,
2245,
1333,
199,
199,
318,
664,
63,
411,
4148,
76,
837,
272,
1599,
3629,
275,
4618,
2087,
14,
1122,
6700,
8,
1751,
14,
362,
360,
832,
63,
3629,
1333,
272,
312,
86,
385,
2095,
275,
2202,
14,
362,
360,
22409,
63,
3629,
358,
272,
23671,
3846,
275,
2202,
14,
362,
360,
22409,
63,
3846,
358,
272,
1687,
4148,
76,
275,
4156,
14,
3833,
14,
2683,
8,
832,
3629,
12,
312,
86,
385,
2095,
12,
23671,
3846,
9,
339,
4205,
63,
3610,
889,
275,
1687,
4148,
76,
14,
1461,
63,
3610,
889,
272,
1830,
715,
26,
267,
1687,
4148,
76,
14,
1065,
342,
267,
340,
4205,
63,
3610,
889,
1137,
1687,
4148,
76,
14,
1461,
63,
3610,
889,
26,
288,
2059,
267,
28073,
275,
23671,
14,
26746,
14,
21160,
342,
267,
1687,
4148,
76,
14,
2573,
8,
26746,
9,
267,
28073,
14,
1457,
342,
339,
372,
334,
832,
3629,
12,
1687,
4148,
76,
9,
199,
199,
533,
7232,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
3085,
12,
18733,
2393,
304,
267,
291,
14,
2030,
275,
488,
267,
291,
14,
2139,
275,
18733,
2393,
398,
340,
3085,
26,
288,
291,
14,
2030,
275,
3085,
14,
739,
342,
339,
768,
1829,
272,
347,
2022,
8,
277,
304,
267,
340,
440,
291,
14,
2030,
26,
288,
372,
488,
267,
862,
26,
288,
372,
2022,
14,
3640,
8,
277,
14,
2030,
9,
267,
871,
1722,
26,
288,
372,
488,
199,
199,
533,
30417,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
633,
275,
488,
267,
291,
14,
633,
63,
589,
275,
5673,
8067,
8,
633,
63,
2094,
63,
1650,
1062,
291,
423,
705,
9,
267,
291,
14,
2139,
275,
1211,
3252,
2714,
13,
804,
356,
283,
3578,
15,
1001,
297,
283,
8422,
356,
283,
3578,
15,
1001,
3071,
267,
291,
423,
7113,
275,
756,
339,
347,
485,
705,
8,
277,
12,
1499,
304,
267,
746,
7220,
547,
8,
1328,
12,
1166,
29,
277,
14,
633,
9,
339,
347,
4907,
8,
277,
12,
1862,
12,
1011,
958,
304,
267,
1591,
275,
1862,
459,
1102,
418,
267,
1844,
275,
1862,
459,
719,
418,
398,
327,
5951,
314,
859,
63,
1208,
15,
3603,
14,
647,
2648,
2633,
267,
291,
14,
633,
63,
589,
14,
1162,
459,
633,
63,
2473,
418,
275,
1862,
459,
2473,
418,
267,
291,
14,
633,
63,
589,
14,
1162,
459,
633,
63,
2060,
418,
275,
1862,
459,
2060,
418,
267,
291,
14,
633,
63,
589,
14,
1162,
459,
3502,
63,
8356,
418,
275,
1862,
459,
3502,
63,
8356,
418,
398,
340,
1862,
459,
1180,
63,
4266,
2565,
288,
4104,
275,
283,
2859,
7,
288,
340,
440,
1844,
26,
355,
1844,
275,
23865,
267,
587,
26,
288,
4104,
275,
283,
1014,
7,
288,
340,
440,
1844,
26,
355,
1844,
275,
5939,
398,
1300,
633,
275,
1543,
83,
13827,
83,
2689,
83,
7,
450,
334,
2625,
12,
1591,
12,
1844,
9,
267,
2323,
275,
1211,
3252,
2714,
13,
804,
356,
283,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
3071,
267,
327,
2372,
282,
5494,
436,
3354,
652,
314,
4618,
402,
314,
5331,
14,
267,
1166,
275,
1543,
83,
3149,
83,
7,
450,
334,
28937,
12,
283,
2886,
358,
267,
666,
275,
283,
2473,
2458,
83,
6,
2060,
2458,
83,
7,
450,
334,
1162,
459,
2473,
995,
1862,
459,
2060,
1105,
267,
3085,
12,
18733,
2393,
275,
5267,
63,
633,
8,
277,
14,
633,
63,
589,
12,
1166,
12,
666,
29,
576,
12,
2323,
29,
2139,
12,
1083,
534,
4030,
358,
398,
327,
6162,
314,
1300,
1166,
367,
314,
4618,
402,
314,
5331,
14,
267,
291,
14,
633,
275,
1543,
83,
15,
3911,
15,
86,
17,
7,
450,
334,
28937,
9,
267,
291,
14,
2139,
459,
7810,
418,
275,
3085,
14,
2139,
14,
362,
360,
1084,
13,
7810,
358,
339,
347,
17639,
8,
277,
12,
1011,
958,
304,
267,
291
] |
[
199,
3,
334,
67,
9,
6900,
22912,
8360,
651,
71,
10641,
12,
665,
80,
681,
651,
71,
10641,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
646,
295,
199,
199,
893,
26,
272,
492,
23671,
14,
26746,
272,
492,
4156,
14,
3833,
272,
687,
4156,
14,
1751,
492,
2202,
272,
687,
4156,
773,
492,
4618,
2087,
272,
7509,
63,
21665,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
21665,
275,
756,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
2022,
12,
2022,
63,
807,
63,
2394,
63,
475,
63,
2975,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
492,
5673,
8067,
12,
5365,
20653,
12,
7220,
547,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
492,
1050,
63,
2094,
12,
2274,
63,
5545,
12,
370,
63,
513,
199,
504,
3242,
14,
578,
63,
1208,
14,
3603,
492,
5267,
63,
633,
12,
1166,
63,
2094,
63,
1650,
199,
199,
3,
7937,
5325,
5133,
4621,
787,
1678,
14,
221,
370,
506,
4829,
2544,
499,
14,
18,
4242,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
492,
664,
63,
578,
199,
199,
525,
63,
2094,
360,
1180,
63,
4266,
297,
1211,
8,
885,
29,
549,
12,
730,
534,
2245,
1333,
199,
525,
63,
2094,
360,
3502,
63,
8356,
297,
1211,
8,
885,
29,
549,
12,
730,
534,
2245,
1333,
199,
199,
318,
664,
63,
411,
4148,
76,
837,
272,
1599,
3629,
275,
4618,
2087,
14,
1122,
6700,
8,
1751,
14,
362,
360,
832,
63,
3629,
1333,
272,
312,
86,
385,
2095,
275,
2202,
14,
362,
360,
22409,
63,
3629,
358,
272,
23671,
3846,
275,
2202,
14,
362,
360,
22409,
63,
3846,
358,
272,
1687,
4148,
76,
275,
4156,
14,
3833,
14,
2683,
8,
832,
3629,
12,
312,
86,
385,
2095,
12,
23671,
3846,
9,
339,
4205,
63,
3610,
889,
275,
1687,
4148,
76,
14,
1461,
63,
3610,
889,
272,
1830,
715,
26,
267,
1687,
4148,
76,
14,
1065,
342,
267,
340,
4205,
63,
3610,
889,
1137,
1687,
4148,
76,
14,
1461,
63,
3610,
889,
26,
288,
2059,
267,
28073,
275,
23671,
14,
26746,
14,
21160,
342,
267,
1687,
4148,
76,
14,
2573,
8,
26746,
9,
267,
28073,
14,
1457,
342,
339,
372,
334,
832,
3629,
12,
1687,
4148,
76,
9,
199,
199,
533,
7232,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
3085,
12,
18733,
2393,
304,
267,
291,
14,
2030,
275,
488,
267,
291,
14,
2139,
275,
18733,
2393,
398,
340,
3085,
26,
288,
291,
14,
2030,
275,
3085,
14,
739,
342,
339,
768,
1829,
272,
347,
2022,
8,
277,
304,
267,
340,
440,
291,
14,
2030,
26,
288,
372,
488,
267,
862,
26,
288,
372,
2022,
14,
3640,
8,
277,
14,
2030,
9,
267,
871,
1722,
26,
288,
372,
488,
199,
199,
533,
30417,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
633,
275,
488,
267,
291,
14,
633,
63,
589,
275,
5673,
8067,
8,
633,
63,
2094,
63,
1650,
1062,
291,
423,
705,
9,
267,
291,
14,
2139,
275,
1211,
3252,
2714,
13,
804,
356,
283,
3578,
15,
1001,
297,
283,
8422,
356,
283,
3578,
15,
1001,
3071,
267,
291,
423,
7113,
275,
756,
339,
347,
485,
705,
8,
277,
12,
1499,
304,
267,
746,
7220,
547,
8,
1328,
12,
1166,
29,
277,
14,
633,
9,
339,
347,
4907,
8,
277,
12,
1862,
12,
1011,
958,
304,
267,
1591,
275,
1862,
459,
1102,
418,
267,
1844,
275,
1862,
459,
719,
418,
398,
327,
5951,
314,
859,
63,
1208,
15,
3603,
14,
647,
2648,
2633,
267,
291,
14,
633,
63,
589,
14,
1162,
459,
633,
63,
2473,
418,
275,
1862,
459,
2473,
418,
267,
291,
14,
633,
63,
589,
14,
1162,
459,
633,
63,
2060,
418,
275,
1862,
459,
2060,
418,
267,
291,
14,
633,
63,
589,
14,
1162,
459,
3502,
63,
8356,
418,
275,
1862,
459,
3502,
63,
8356,
418,
398,
340,
1862,
459,
1180,
63,
4266,
2565,
288,
4104,
275,
283,
2859,
7,
288,
340,
440,
1844,
26,
355,
1844,
275,
23865,
267,
587,
26,
288,
4104,
275,
283,
1014,
7,
288,
340,
440,
1844,
26,
355,
1844,
275,
5939,
398,
1300,
633,
275,
1543,
83,
13827,
83,
2689,
83,
7,
450,
334,
2625,
12,
1591,
12,
1844,
9,
267,
2323,
275,
1211,
3252,
2714,
13,
804,
356,
283,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
3071,
267,
327,
2372,
282,
5494,
436,
3354,
652,
314,
4618,
402,
314,
5331,
14,
267,
1166,
275,
1543,
83,
3149,
83,
7,
450,
334,
28937,
12,
283,
2886,
358,
267,
666,
275,
283,
2473,
2458,
83,
6,
2060,
2458,
83,
7,
450,
334,
1162,
459,
2473,
995,
1862,
459,
2060,
1105,
267,
3085,
12,
18733,
2393,
275,
5267,
63,
633,
8,
277,
14,
633,
63,
589,
12,
1166,
12,
666,
29,
576,
12,
2323,
29,
2139,
12,
1083,
534,
4030,
358,
398,
327,
6162,
314,
1300,
1166,
367,
314,
4618,
402,
314,
5331,
14,
267,
291,
14,
633,
275,
1543,
83,
15,
3911,
15,
86,
17,
7,
450,
334,
28937,
9,
267,
291,
14,
2139,
459,
7810,
418,
275,
3085,
14,
2139,
14,
362,
360,
1084,
13,
7810,
358,
339,
347,
17639,
8,
277,
12,
1011,
958,
304,
267,
291,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
jhd/spunout
|
flask/lib/python2.7/site-packages/werkzeug/testsuite/datastructures.py
|
145
|
28212
|
# -*- coding: utf-8 -*-
"""
werkzeug.testsuite.datastructures
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tests the functionality of the provided Werkzeug
datastructures.
TODO:
- FileMultiDict
- Immutable types undertested
- Split up dict tests
:copyright: (c) 2014 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""
from __future__ import with_statement
import unittest
import pickle
from contextlib import contextmanager
from copy import copy, deepcopy
from werkzeug import datastructures
from werkzeug._compat import iterkeys, itervalues, iteritems, iterlists, \
iterlistvalues, text_type, PY2
from werkzeug.testsuite import WerkzeugTestCase
from werkzeug.exceptions import BadRequestKeyError
class NativeItermethodsTestCase(WerkzeugTestCase):
def test_basic(self):
@datastructures.native_itermethods(['keys', 'values', 'items'])
class StupidDict(object):
def keys(self, multi=1):
return iter(['a', 'b', 'c'] * multi)
def values(self, multi=1):
return iter([1, 2, 3] * multi)
def items(self, multi=1):
return iter(zip(iterkeys(self, multi=multi),
itervalues(self, multi=multi)))
d = StupidDict()
expected_keys = ['a', 'b', 'c']
expected_values = [1, 2, 3]
expected_items = list(zip(expected_keys, expected_values))
self.assert_equal(list(iterkeys(d)), expected_keys)
self.assert_equal(list(itervalues(d)), expected_values)
self.assert_equal(list(iteritems(d)), expected_items)
self.assert_equal(list(iterkeys(d, 2)), expected_keys * 2)
self.assert_equal(list(itervalues(d, 2)), expected_values * 2)
self.assert_equal(list(iteritems(d, 2)), expected_items * 2)
class MutableMultiDictBaseTestCase(WerkzeugTestCase):
storage_class = None
def test_pickle(self):
cls = self.storage_class
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
d = cls()
d.setlist(b'foo', [1, 2, 3, 4])
d.setlist(b'bar', b'foo bar baz'.split())
s = pickle.dumps(d, protocol)
ud = pickle.loads(s)
self.assert_equal(type(ud), type(d))
self.assert_equal(ud, d)
self.assert_equal(pickle.loads(
s.replace(b'werkzeug.datastructures', b'werkzeug')), d)
ud[b'newkey'] = b'bla'
self.assert_not_equal(ud, d)
def test_basic_interface(self):
md = self.storage_class()
assert isinstance(md, dict)
mapping = [('a', 1), ('b', 2), ('a', 2), ('d', 3),
('a', 1), ('a', 3), ('d', 4), ('c', 3)]
md = self.storage_class(mapping)
# simple getitem gives the first value
self.assert_equal(md['a'], 1)
self.assert_equal(md['c'], 3)
with self.assert_raises(KeyError):
md['e']
self.assert_equal(md.get('a'), 1)
# list getitem
self.assert_equal(md.getlist('a'), [1, 2, 1, 3])
self.assert_equal(md.getlist('d'), [3, 4])
# do not raise if key not found
self.assert_equal(md.getlist('x'), [])
# simple setitem overwrites all values
md['a'] = 42
self.assert_equal(md.getlist('a'), [42])
# list setitem
md.setlist('a', [1, 2, 3])
self.assert_equal(md['a'], 1)
self.assert_equal(md.getlist('a'), [1, 2, 3])
# verify that it does not change original lists
l1 = [1, 2, 3]
md.setlist('a', l1)
del l1[:]
self.assert_equal(md['a'], 1)
# setdefault, setlistdefault
self.assert_equal(md.setdefault('u', 23), 23)
self.assert_equal(md.getlist('u'), [23])
del md['u']
md.setlist('u', [-1, -2])
# delitem
del md['u']
with self.assert_raises(KeyError):
md['u']
del md['d']
self.assert_equal(md.getlist('d'), [])
# keys, values, items, lists
self.assert_equal(list(sorted(md.keys())), ['a', 'b', 'c'])
self.assert_equal(list(sorted(iterkeys(md))), ['a', 'b', 'c'])
self.assert_equal(list(sorted(itervalues(md))), [1, 2, 3])
self.assert_equal(list(sorted(itervalues(md))), [1, 2, 3])
self.assert_equal(list(sorted(md.items())),
[('a', 1), ('b', 2), ('c', 3)])
self.assert_equal(list(sorted(md.items(multi=True))),
[('a', 1), ('a', 2), ('a', 3), ('b', 2), ('c', 3)])
self.assert_equal(list(sorted(iteritems(md))),
[('a', 1), ('b', 2), ('c', 3)])
self.assert_equal(list(sorted(iteritems(md, multi=True))),
[('a', 1), ('a', 2), ('a', 3), ('b', 2), ('c', 3)])
self.assert_equal(list(sorted(md.lists())),
[('a', [1, 2, 3]), ('b', [2]), ('c', [3])])
self.assert_equal(list(sorted(iterlists(md))),
[('a', [1, 2, 3]), ('b', [2]), ('c', [3])])
# copy method
c = md.copy()
self.assert_equal(c['a'], 1)
self.assert_equal(c.getlist('a'), [1, 2, 3])
# copy method 2
c = copy(md)
self.assert_equal(c['a'], 1)
self.assert_equal(c.getlist('a'), [1, 2, 3])
# deepcopy method
c = md.deepcopy()
self.assert_equal(c['a'], 1)
self.assert_equal(c.getlist('a'), [1, 2, 3])
# deepcopy method 2
c = deepcopy(md)
self.assert_equal(c['a'], 1)
self.assert_equal(c.getlist('a'), [1, 2, 3])
# update with a multidict
od = self.storage_class([('a', 4), ('a', 5), ('y', 0)])
md.update(od)
self.assert_equal(md.getlist('a'), [1, 2, 3, 4, 5])
self.assert_equal(md.getlist('y'), [0])
# update with a regular dict
md = c
od = {'a': 4, 'y': 0}
md.update(od)
self.assert_equal(md.getlist('a'), [1, 2, 3, 4])
self.assert_equal(md.getlist('y'), [0])
# pop, poplist, popitem, popitemlist
self.assert_equal(md.pop('y'), 0)
assert 'y' not in md
self.assert_equal(md.poplist('a'), [1, 2, 3, 4])
assert 'a' not in md
self.assert_equal(md.poplist('missing'), [])
# remaining: b=2, c=3
popped = md.popitem()
assert popped in [('b', 2), ('c', 3)]
popped = md.popitemlist()
assert popped in [('b', [2]), ('c', [3])]
# type conversion
md = self.storage_class({'a': '4', 'b': ['2', '3']})
self.assert_equal(md.get('a', type=int), 4)
self.assert_equal(md.getlist('b', type=int), [2, 3])
# repr
md = self.storage_class([('a', 1), ('a', 2), ('b', 3)])
assert "('a', 1)" in repr(md)
assert "('a', 2)" in repr(md)
assert "('b', 3)" in repr(md)
# add and getlist
md.add('c', '42')
md.add('c', '23')
self.assert_equal(md.getlist('c'), ['42', '23'])
md.add('c', 'blah')
self.assert_equal(md.getlist('c', type=int), [42, 23])
# setdefault
md = self.storage_class()
md.setdefault('x', []).append(42)
md.setdefault('x', []).append(23)
self.assert_equal(md['x'], [42, 23])
# to dict
md = self.storage_class()
md['foo'] = 42
md.add('bar', 1)
md.add('bar', 2)
self.assert_equal(md.to_dict(), {'foo': 42, 'bar': 1})
self.assert_equal(md.to_dict(flat=False), {'foo': [42], 'bar': [1, 2]})
# popitem from empty dict
with self.assert_raises(KeyError):
self.storage_class().popitem()
with self.assert_raises(KeyError):
self.storage_class().popitemlist()
# key errors are of a special type
with self.assert_raises(BadRequestKeyError):
self.storage_class()[42]
# setlist works
md = self.storage_class()
md['foo'] = 42
md.setlist('foo', [1, 2])
self.assert_equal(md.getlist('foo'), [1, 2])
class ImmutableDictBaseTestCase(WerkzeugTestCase):
storage_class = None
def test_follows_dict_interface(self):
cls = self.storage_class
data = {'foo': 1, 'bar': 2, 'baz': 3}
d = cls(data)
self.assert_equal(d['foo'], 1)
self.assert_equal(d['bar'], 2)
self.assert_equal(d['baz'], 3)
self.assert_equal(sorted(d.keys()), ['bar', 'baz', 'foo'])
self.assert_true('foo' in d)
self.assert_true('foox' not in d)
self.assert_equal(len(d), 3)
def test_copies_are_mutable(self):
cls = self.storage_class
immutable = cls({'a': 1})
with self.assert_raises(TypeError):
immutable.pop('a')
mutable = immutable.copy()
mutable.pop('a')
self.assert_true('a' in immutable)
self.assert_true(mutable is not immutable)
self.assert_true(copy(immutable) is immutable)
def test_dict_is_hashable(self):
cls = self.storage_class
immutable = cls({'a': 1, 'b': 2})
immutable2 = cls({'a': 2, 'b': 2})
x = set([immutable])
self.assert_true(immutable in x)
self.assert_true(immutable2 not in x)
x.discard(immutable)
self.assert_true(immutable not in x)
self.assert_true(immutable2 not in x)
x.add(immutable2)
self.assert_true(immutable not in x)
self.assert_true(immutable2 in x)
x.add(immutable)
self.assert_true(immutable in x)
self.assert_true(immutable2 in x)
class ImmutableTypeConversionDictTestCase(ImmutableDictBaseTestCase):
storage_class = datastructures.ImmutableTypeConversionDict
class ImmutableMultiDictTestCase(ImmutableDictBaseTestCase):
storage_class = datastructures.ImmutableMultiDict
def test_multidict_is_hashable(self):
cls = self.storage_class
immutable = cls({'a': [1, 2], 'b': 2})
immutable2 = cls({'a': [1], 'b': 2})
x = set([immutable])
self.assert_true(immutable in x)
self.assert_true(immutable2 not in x)
x.discard(immutable)
self.assert_true(immutable not in x)
self.assert_true(immutable2 not in x)
x.add(immutable2)
self.assert_true(immutable not in x)
self.assert_true(immutable2 in x)
x.add(immutable)
self.assert_true(immutable in x)
self.assert_true(immutable2 in x)
class ImmutableDictTestCase(ImmutableDictBaseTestCase):
storage_class = datastructures.ImmutableDict
class ImmutableOrderedMultiDictTestCase(ImmutableDictBaseTestCase):
storage_class = datastructures.ImmutableOrderedMultiDict
def test_ordered_multidict_is_hashable(self):
a = self.storage_class([('a', 1), ('b', 1), ('a', 2)])
b = self.storage_class([('a', 1), ('a', 2), ('b', 1)])
self.assert_not_equal(hash(a), hash(b))
class MultiDictTestCase(MutableMultiDictBaseTestCase):
storage_class = datastructures.MultiDict
def test_multidict_pop(self):
make_d = lambda: self.storage_class({'foo': [1, 2, 3, 4]})
d = make_d()
self.assert_equal(d.pop('foo'), 1)
assert not d
d = make_d()
self.assert_equal(d.pop('foo', 32), 1)
assert not d
d = make_d()
self.assert_equal(d.pop('foos', 32), 32)
assert d
with self.assert_raises(KeyError):
d.pop('foos')
def test_setlistdefault(self):
md = self.storage_class()
self.assert_equal(md.setlistdefault('u', [-1, -2]), [-1, -2])
self.assert_equal(md.getlist('u'), [-1, -2])
self.assert_equal(md['u'], -1)
def test_iter_interfaces(self):
mapping = [('a', 1), ('b', 2), ('a', 2), ('d', 3),
('a', 1), ('a', 3), ('d', 4), ('c', 3)]
md = self.storage_class(mapping)
self.assert_equal(list(zip(md.keys(), md.listvalues())),
list(md.lists()))
self.assert_equal(list(zip(md, iterlistvalues(md))),
list(iterlists(md)))
self.assert_equal(list(zip(iterkeys(md), iterlistvalues(md))),
list(iterlists(md)))
class OrderedMultiDictTestCase(MutableMultiDictBaseTestCase):
storage_class = datastructures.OrderedMultiDict
def test_ordered_interface(self):
cls = self.storage_class
d = cls()
assert not d
d.add('foo', 'bar')
self.assert_equal(len(d), 1)
d.add('foo', 'baz')
self.assert_equal(len(d), 1)
self.assert_equal(list(iteritems(d)), [('foo', 'bar')])
self.assert_equal(list(d), ['foo'])
self.assert_equal(list(iteritems(d, multi=True)),
[('foo', 'bar'), ('foo', 'baz')])
del d['foo']
assert not d
self.assert_equal(len(d), 0)
self.assert_equal(list(d), [])
d.update([('foo', 1), ('foo', 2), ('bar', 42)])
d.add('foo', 3)
self.assert_equal(d.getlist('foo'), [1, 2, 3])
self.assert_equal(d.getlist('bar'), [42])
self.assert_equal(list(iteritems(d)), [('foo', 1), ('bar', 42)])
expected = ['foo', 'bar']
self.assert_sequence_equal(list(d.keys()), expected)
self.assert_sequence_equal(list(d), expected)
self.assert_sequence_equal(list(iterkeys(d)), expected)
self.assert_equal(list(iteritems(d, multi=True)),
[('foo', 1), ('foo', 2), ('bar', 42), ('foo', 3)])
self.assert_equal(len(d), 2)
self.assert_equal(d.pop('foo'), 1)
assert d.pop('blafasel', None) is None
self.assert_equal(d.pop('blafasel', 42), 42)
self.assert_equal(len(d), 1)
self.assert_equal(d.poplist('bar'), [42])
assert not d
d.get('missingkey') is None
d.add('foo', 42)
d.add('foo', 23)
d.add('bar', 2)
d.add('foo', 42)
self.assert_equal(d, datastructures.MultiDict(d))
id = self.storage_class(d)
self.assert_equal(d, id)
d.add('foo', 2)
assert d != id
d.update({'blah': [1, 2, 3]})
self.assert_equal(d['blah'], 1)
self.assert_equal(d.getlist('blah'), [1, 2, 3])
# setlist works
d = self.storage_class()
d['foo'] = 42
d.setlist('foo', [1, 2])
self.assert_equal(d.getlist('foo'), [1, 2])
with self.assert_raises(BadRequestKeyError):
d.pop('missing')
with self.assert_raises(BadRequestKeyError):
d['missing']
# popping
d = self.storage_class()
d.add('foo', 23)
d.add('foo', 42)
d.add('foo', 1)
self.assert_equal(d.popitem(), ('foo', 23))
with self.assert_raises(BadRequestKeyError):
d.popitem()
assert not d
d.add('foo', 23)
d.add('foo', 42)
d.add('foo', 1)
self.assert_equal(d.popitemlist(), ('foo', [23, 42, 1]))
with self.assert_raises(BadRequestKeyError):
d.popitemlist()
def test_iterables(self):
a = datastructures.MultiDict((("key_a", "value_a"),))
b = datastructures.MultiDict((("key_b", "value_b"),))
ab = datastructures.CombinedMultiDict((a,b))
self.assert_equal(sorted(ab.lists()), [('key_a', ['value_a']), ('key_b', ['value_b'])])
self.assert_equal(sorted(ab.listvalues()), [['value_a'], ['value_b']])
self.assert_equal(sorted(ab.keys()), ["key_a", "key_b"])
self.assert_equal(sorted(iterlists(ab)), [('key_a', ['value_a']), ('key_b', ['value_b'])])
self.assert_equal(sorted(iterlistvalues(ab)), [['value_a'], ['value_b']])
self.assert_equal(sorted(iterkeys(ab)), ["key_a", "key_b"])
class CombinedMultiDictTestCase(WerkzeugTestCase):
storage_class = datastructures.CombinedMultiDict
def test_basic_interface(self):
d1 = datastructures.MultiDict([('foo', '1')])
d2 = datastructures.MultiDict([('bar', '2'), ('bar', '3')])
d = self.storage_class([d1, d2])
# lookup
self.assert_equal(d['foo'], '1')
self.assert_equal(d['bar'], '2')
self.assert_equal(d.getlist('bar'), ['2', '3'])
self.assert_equal(sorted(d.items()),
[('bar', '2'), ('foo', '1')])
self.assert_equal(sorted(d.items(multi=True)),
[('bar', '2'), ('bar', '3'), ('foo', '1')])
assert 'missingkey' not in d
assert 'foo' in d
# type lookup
self.assert_equal(d.get('foo', type=int), 1)
self.assert_equal(d.getlist('bar', type=int), [2, 3])
# get key errors for missing stuff
with self.assert_raises(KeyError):
d['missing']
# make sure that they are immutable
with self.assert_raises(TypeError):
d['foo'] = 'blub'
# copies are immutable
d = d.copy()
with self.assert_raises(TypeError):
d['foo'] = 'blub'
# make sure lists merges
md1 = datastructures.MultiDict((("foo", "bar"),))
md2 = datastructures.MultiDict((("foo", "blafasel"),))
x = self.storage_class((md1, md2))
self.assert_equal(list(iterlists(x)), [('foo', ['bar', 'blafasel'])])
class HeadersTestCase(WerkzeugTestCase):
storage_class = datastructures.Headers
def test_basic_interface(self):
headers = self.storage_class()
headers.add('Content-Type', 'text/plain')
headers.add('X-Foo', 'bar')
assert 'x-Foo' in headers
assert 'Content-type' in headers
headers['Content-Type'] = 'foo/bar'
self.assert_equal(headers['Content-Type'], 'foo/bar')
self.assert_equal(len(headers.getlist('Content-Type')), 1)
# list conversion
self.assert_equal(headers.to_wsgi_list(), [
('Content-Type', 'foo/bar'),
('X-Foo', 'bar')
])
self.assert_equal(str(headers), (
"Content-Type: foo/bar\r\n"
"X-Foo: bar\r\n"
"\r\n"))
self.assert_equal(str(self.storage_class()), "\r\n")
# extended add
headers.add('Content-Disposition', 'attachment', filename='foo')
self.assert_equal(headers['Content-Disposition'],
'attachment; filename=foo')
headers.add('x', 'y', z='"')
self.assert_equal(headers['x'], r'y; z="\""')
def test_defaults_and_conversion(self):
# defaults
headers = self.storage_class([
('Content-Type', 'text/plain'),
('X-Foo', 'bar'),
('X-Bar', '1'),
('X-Bar', '2')
])
self.assert_equal(headers.getlist('x-bar'), ['1', '2'])
self.assert_equal(headers.get('x-Bar'), '1')
self.assert_equal(headers.get('Content-Type'), 'text/plain')
self.assert_equal(headers.setdefault('X-Foo', 'nope'), 'bar')
self.assert_equal(headers.setdefault('X-Bar', 'nope'), '1')
self.assert_equal(headers.setdefault('X-Baz', 'quux'), 'quux')
self.assert_equal(headers.setdefault('X-Baz', 'nope'), 'quux')
headers.pop('X-Baz')
# type conversion
self.assert_equal(headers.get('x-bar', type=int), 1)
self.assert_equal(headers.getlist('x-bar', type=int), [1, 2])
# list like operations
self.assert_equal(headers[0], ('Content-Type', 'text/plain'))
self.assert_equal(headers[:1], self.storage_class([('Content-Type', 'text/plain')]))
del headers[:2]
del headers[-1]
self.assert_equal(headers, self.storage_class([('X-Bar', '1')]))
def test_copying(self):
a = self.storage_class([('foo', 'bar')])
b = a.copy()
a.add('foo', 'baz')
self.assert_equal(a.getlist('foo'), ['bar', 'baz'])
self.assert_equal(b.getlist('foo'), ['bar'])
def test_popping(self):
headers = self.storage_class([('a', 1)])
self.assert_equal(headers.pop('a'), 1)
self.assert_equal(headers.pop('b', 2), 2)
with self.assert_raises(KeyError):
headers.pop('c')
def test_set_arguments(self):
a = self.storage_class()
a.set('Content-Disposition', 'useless')
a.set('Content-Disposition', 'attachment', filename='foo')
self.assert_equal(a['Content-Disposition'], 'attachment; filename=foo')
def test_reject_newlines(self):
h = self.storage_class()
for variation in 'foo\nbar', 'foo\r\nbar', 'foo\rbar':
with self.assert_raises(ValueError):
h['foo'] = variation
with self.assert_raises(ValueError):
h.add('foo', variation)
with self.assert_raises(ValueError):
h.add('foo', 'test', option=variation)
with self.assert_raises(ValueError):
h.set('foo', variation)
with self.assert_raises(ValueError):
h.set('foo', 'test', option=variation)
def test_slicing(self):
# there's nothing wrong with these being native strings
# Headers doesn't care about the data types
h = self.storage_class()
h.set('X-Foo-Poo', 'bleh')
h.set('Content-Type', 'application/whocares')
h.set('X-Forwarded-For', '192.168.0.123')
h[:] = [(k, v) for k, v in h if k.startswith(u'X-')]
self.assert_equal(list(h), [
('X-Foo-Poo', 'bleh'),
('X-Forwarded-For', '192.168.0.123')
])
def test_bytes_operations(self):
h = self.storage_class()
h.set('X-Foo-Poo', 'bleh')
h.set('X-Whoops', b'\xff')
self.assert_equal(h.get('x-foo-poo', as_bytes=True), b'bleh')
self.assert_equal(h.get('x-whoops', as_bytes=True), b'\xff')
def test_to_wsgi_list(self):
h = self.storage_class()
h.set(u'Key', u'Value')
for key, value in h.to_wsgi_list():
if PY2:
self.assert_strict_equal(key, b'Key')
self.assert_strict_equal(value, b'Value')
else:
self.assert_strict_equal(key, u'Key')
self.assert_strict_equal(value, u'Value')
class EnvironHeadersTestCase(WerkzeugTestCase):
storage_class = datastructures.EnvironHeaders
def test_basic_interface(self):
# this happens in multiple WSGI servers because they
# use a vary naive way to convert the headers;
broken_env = {
'HTTP_CONTENT_TYPE': 'text/html',
'CONTENT_TYPE': 'text/html',
'HTTP_CONTENT_LENGTH': '0',
'CONTENT_LENGTH': '0',
'HTTP_ACCEPT': '*',
'wsgi.version': (1, 0)
}
headers = self.storage_class(broken_env)
assert headers
self.assert_equal(len(headers), 3)
self.assert_equal(sorted(headers), [
('Accept', '*'),
('Content-Length', '0'),
('Content-Type', 'text/html')
])
assert not self.storage_class({'wsgi.version': (1, 0)})
self.assert_equal(len(self.storage_class({'wsgi.version': (1, 0)})), 0)
def test_return_type_is_unicode(self):
# environ contains native strings; we return unicode
headers = self.storage_class({
'HTTP_FOO': '\xe2\x9c\x93',
'CONTENT_TYPE': 'text/plain',
})
self.assert_equal(headers['Foo'], u"\xe2\x9c\x93")
assert isinstance(headers['Foo'], text_type)
assert isinstance(headers['Content-Type'], text_type)
iter_output = dict(iter(headers))
self.assert_equal(iter_output['Foo'], u"\xe2\x9c\x93")
assert isinstance(iter_output['Foo'], text_type)
assert isinstance(iter_output['Content-Type'], text_type)
def test_bytes_operations(self):
foo_val = '\xff'
h = self.storage_class({
'HTTP_X_FOO': foo_val
})
self.assert_equal(h.get('x-foo', as_bytes=True), b'\xff')
self.assert_equal(h.get('x-foo'), u'\xff')
class HeaderSetTestCase(WerkzeugTestCase):
storage_class = datastructures.HeaderSet
def test_basic_interface(self):
hs = self.storage_class()
hs.add('foo')
hs.add('bar')
assert 'Bar' in hs
self.assert_equal(hs.find('foo'), 0)
self.assert_equal(hs.find('BAR'), 1)
assert hs.find('baz') < 0
hs.discard('missing')
hs.discard('foo')
assert hs.find('foo') < 0
self.assert_equal(hs.find('bar'), 0)
with self.assert_raises(IndexError):
hs.index('missing')
self.assert_equal(hs.index('bar'), 0)
assert hs
hs.clear()
assert not hs
class ImmutableListTestCase(WerkzeugTestCase):
storage_class = datastructures.ImmutableList
def test_list_hashable(self):
t = (1, 2, 3, 4)
l = self.storage_class(t)
self.assert_equal(hash(t), hash(l))
self.assert_not_equal(t, l)
def make_call_asserter(assert_equal_func, func=None):
"""Utility to assert a certain number of function calls.
>>> assert_calls, func = make_call_asserter(self.assert_equal)
>>> with assert_calls(2):
func()
func()
"""
calls = [0]
@contextmanager
def asserter(count, msg=None):
calls[0] = 0
yield
assert_equal_func(calls[0], count, msg)
def wrapped(*args, **kwargs):
calls[0] += 1
if func is not None:
return func(*args, **kwargs)
return asserter, wrapped
class CallbackDictTestCase(WerkzeugTestCase):
storage_class = datastructures.CallbackDict
def test_callback_dict_reads(self):
assert_calls, func = make_call_asserter(self.assert_equal)
initial = {'a': 'foo', 'b': 'bar'}
dct = self.storage_class(initial=initial, on_update=func)
with assert_calls(0, 'callback triggered by read-only method'):
# read-only methods
dct['a']
dct.get('a')
self.assert_raises(KeyError, lambda: dct['x'])
'a' in dct
list(iter(dct))
dct.copy()
with assert_calls(0, 'callback triggered without modification'):
# methods that may write but don't
dct.pop('z', None)
dct.setdefault('a')
def test_callback_dict_writes(self):
assert_calls, func = make_call_asserter(self.assert_equal)
initial = {'a': 'foo', 'b': 'bar'}
dct = self.storage_class(initial=initial, on_update=func)
with assert_calls(8, 'callback not triggered by write method'):
# always-write methods
dct['z'] = 123
dct['z'] = 123 # must trigger again
del dct['z']
dct.pop('b', None)
dct.setdefault('x')
dct.popitem()
dct.update([])
dct.clear()
with assert_calls(0, 'callback triggered by failed del'):
self.assert_raises(KeyError, lambda: dct.__delitem__('x'))
with assert_calls(0, 'callback triggered by failed pop'):
self.assert_raises(KeyError, lambda: dct.pop('x'))
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(MultiDictTestCase))
suite.addTest(unittest.makeSuite(OrderedMultiDictTestCase))
suite.addTest(unittest.makeSuite(CombinedMultiDictTestCase))
suite.addTest(unittest.makeSuite(ImmutableTypeConversionDictTestCase))
suite.addTest(unittest.makeSuite(ImmutableMultiDictTestCase))
suite.addTest(unittest.makeSuite(ImmutableDictTestCase))
suite.addTest(unittest.makeSuite(ImmutableOrderedMultiDictTestCase))
suite.addTest(unittest.makeSuite(HeadersTestCase))
suite.addTest(unittest.makeSuite(EnvironHeadersTestCase))
suite.addTest(unittest.makeSuite(HeaderSetTestCase))
suite.addTest(unittest.makeSuite(NativeItermethodsTestCase))
suite.addTest(unittest.makeSuite(CallbackDictTestCase))
return suite
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10380,
14,
14239,
14,
23004,
272,
18294,
9753,
94,
339,
6496,
314,
9330,
402,
314,
2741,
22798,
272,
666,
13547,
14,
339,
3254,
26,
339,
446,
257,
3814,
21365,
272,
446,
257,
25609,
2943,
1334,
10453,
272,
446,
257,
11740,
1536,
1211,
2295,
339,
520,
7307,
26,
334,
67,
9,
6927,
701,
1952,
827,
32472,
19728,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
2882,
199,
646,
5927,
199,
504,
15502,
492,
27608,
199,
504,
1331,
492,
1331,
12,
14800,
199,
199,
504,
10380,
492,
666,
13547,
199,
504,
10380,
423,
5819,
492,
25706,
12,
24451,
12,
10849,
12,
2740,
6717,
12,
971,
1362,
2740,
513,
1459,
12,
1318,
63,
466,
12,
7843,
18,
199,
504,
10380,
14,
14239,
492,
22798,
1746,
199,
504,
10380,
14,
3924,
492,
8857,
2017,
10230,
421,
199,
533,
653,
1905,
3315,
2474,
1746,
8,
55,
8756,
1746,
304,
272,
347,
511,
63,
4316,
8,
277,
304,
267,
768,
23004,
14,
6106,
63,
1661,
2474,
2941,
1612,
297,
283,
1459,
297,
283,
1744,
1105,
267,
1021,
1933,
31596,
2141,
8,
785,
304,
288,
347,
2883,
8,
277,
12,
3510,
29,
17,
304,
355,
372,
2740,
2941,
65,
297,
283,
66,
297,
283,
67,
418,
627,
3510,
9,
953,
347,
1338,
8,
277,
12,
3510,
29,
17,
304,
355,
372,
2740,
779,
17,
12,
499,
12,
650,
61,
627,
3510,
9,
953,
347,
2974,
8,
277,
12,
3510,
29,
17,
304,
355,
372,
2740,
8,
3065,
8,
16007,
8,
277,
12,
3510,
29,
3029,
395,
1816,
24451,
8,
277,
12,
3510,
29,
3029,
1724,
398,
366,
275,
1933,
31596,
2141,
342,
267,
1420,
63,
1612,
275,
788,
65,
297,
283,
66,
297,
283,
67,
418,
267,
1420,
63,
1459,
275,
359,
17,
12,
499,
12,
650,
61,
267,
1420,
63,
1744,
275,
769,
8,
3065,
8,
2062,
63,
1612,
12,
1420,
63,
1459,
430,
398,
291,
14,
479,
63,
1452,
8,
513,
8,
16007,
8,
68,
1826,
1420,
63,
1612,
9,
267,
291,
14,
479,
63,
1452,
8,
513,
8,
13012,
8,
68,
1826,
1420,
63,
1459,
9,
267,
291,
14,
479,
63,
1452,
8,
513,
8,
4611,
8,
68,
1826,
1420,
63,
1744,
9,
398,
291,
14,
479,
63,
1452,
8,
513,
8,
16007,
8,
68,
12,
499,
1826,
1420,
63,
1612,
627,
499,
9,
267,
291,
14,
479,
63,
1452,
8,
513,
8,
13012,
8,
68,
12,
499,
1826,
1420,
63,
1459,
627,
499,
9,
267,
291,
14,
479,
63,
1452,
8,
513,
8,
4611,
8,
68,
12,
499,
1826,
1420,
63,
1744,
627,
499,
9,
421,
199,
533,
19610,
21365,
20760,
8,
55,
8756,
1746,
304,
272,
4887,
63,
533,
275,
488,
339,
347,
511,
63,
8092,
8,
277,
304,
267,
843,
275,
291,
14,
3494,
63,
533,
398,
367,
4113,
315,
1425,
8,
8092,
14,
31977,
63,
9583,
435,
413,
304,
288,
366,
275,
843,
342,
288,
366,
14,
409,
513,
8,
66,
7,
1421,
297,
359,
17,
12,
499,
12,
650,
12,
841,
566,
288,
366,
14,
409,
513,
8,
66,
7,
1700,
297,
330,
7,
1421,
4681,
15507,
1370,
1294,
1012,
288,
308,
275,
5927,
14,
4180,
8,
68,
12,
4113,
9,
288,
26759,
275,
5927,
14,
3640,
8,
83,
9,
288,
291,
14,
479,
63,
1452,
8,
466,
8,
1181,
395,
730,
8,
68,
430,
288,
291,
14,
479,
63,
1452,
8,
1181,
12,
366,
9,
288,
291,
14,
479,
63,
1452,
8,
8092,
14,
3640,
8,
355,
308,
14,
1814,
8,
66,
7,
17719,
14,
23004,
297,
330,
7,
17719,
3855,
366,
9,
288,
26759,
59,
66,
7,
1222,
498,
418,
275,
330,
7,
21244,
7,
288,
291,
14,
479,
63,
1397,
63,
1452,
8,
1181,
12,
366,
9,
339,
347,
511,
63,
4316,
63,
3266,
8,
277,
304,
267,
6128,
275,
291,
14,
3494,
63,
533,
342,
267,
702,
1228,
8,
1064,
12,
1211,
9,
398,
4412,
275,
4274,
65,
297,
413,
395,
661,
66,
297,
499,
395,
661,
65,
297,
499,
395,
661,
68,
297,
650,
395,
673,
661,
65,
297,
413,
395,
661,
65,
297,
650,
395,
661,
68,
297,
841,
395,
661,
67,
297,
650,
1874,
267,
6128,
275,
291,
14,
3494,
63,
533,
8,
4745,
9,
398,
327,
3486,
2312,
4484,
10557,
314,
1642,
574,
267,
291,
14,
479,
63,
1452,
8,
1064,
459,
65,
995,
413,
9,
267,
291,
14,
479,
63,
1452,
8,
1064,
459,
67,
995,
650,
9,
267,
543,
291,
14,
479,
63,
3536,
8,
10230,
304,
288,
6128,
459,
69,
418,
267,
291,
14,
479,
63,
1452,
8,
1064,
14,
362,
360,
65,
659,
413,
9,
398,
327,
769,
2312,
4484,
267,
291,
14,
479,
63,
1452,
8,
1064,
14,
21343,
360,
65,
659,
359,
17,
12,
499,
12,
413,
12,
650,
566,
267,
291,
14,
479,
63,
1452,
8,
1064,
14,
21343,
360,
68,
659,
359,
19,
12,
841,
566,
267,
327,
886,
440,
746,
340,
790,
440,
1911,
267,
291,
14,
479,
63,
1452,
8,
1064,
14,
21343,
360,
88,
659,
3073,
398,
327,
3486,
542,
4484,
1806,
16334,
1006,
1338,
267,
6128,
459,
65,
418,
275,
5685,
267,
291,
14,
479,
63,
1452,
8,
1064,
14,
21343,
360,
65,
659,
359,
2260,
566,
398,
327,
769,
542,
4484,
267,
6128,
14,
409,
513,
360,
65,
297,
359,
17,
12,
499,
12,
650,
566,
267,
291,
14,
479,
63,
1452,
8,
1064,
459,
65,
995,
413,
9,
267,
291,
14,
479,
63,
1452,
8,
1064,
14,
21343,
360,
65,
659,
359,
17,
12,
499,
12,
650,
566,
398,
327,
4911,
626,
652,
1630,
440,
1570,
3379,
5548,
267,
634,
17,
275,
359,
17,
12,
499,
12,
650,
61,
267,
6128,
14,
409,
513,
360,
65,
297,
634,
17,
9,
267,
2150,
634,
17,
5873,
267,
291,
14,
479,
63,
1452,
8,
1064,
459,
65,
995,
413,
9,
398,
327,
29408,
12,
663,
513,
885,
267,
291,
14,
479,
63,
1452,
8,
1064,
14,
5486,
360,
85,
297,
6546,
395,
6546,
9,
267,
291,
14,
479,
63,
1452,
8,
1064
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10380,
14,
14239,
14,
23004,
272,
18294,
9753,
94,
339,
6496,
314,
9330,
402,
314,
2741,
22798,
272,
666,
13547,
14,
339,
3254,
26,
339,
446,
257,
3814,
21365,
272,
446,
257,
25609,
2943,
1334,
10453,
272,
446,
257,
11740,
1536,
1211,
2295,
339,
520,
7307,
26,
334,
67,
9,
6927,
701,
1952,
827,
32472,
19728,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
2882,
199,
646,
5927,
199,
504,
15502,
492,
27608,
199,
504,
1331,
492,
1331,
12,
14800,
199,
199,
504,
10380,
492,
666,
13547,
199,
504,
10380,
423,
5819,
492,
25706,
12,
24451,
12,
10849,
12,
2740,
6717,
12,
971,
1362,
2740,
513,
1459,
12,
1318,
63,
466,
12,
7843,
18,
199,
504,
10380,
14,
14239,
492,
22798,
1746,
199,
504,
10380,
14,
3924,
492,
8857,
2017,
10230,
421,
199,
533,
653,
1905,
3315,
2474,
1746,
8,
55,
8756,
1746,
304,
272,
347,
511,
63,
4316,
8,
277,
304,
267,
768,
23004,
14,
6106,
63,
1661,
2474,
2941,
1612,
297,
283,
1459,
297,
283,
1744,
1105,
267,
1021,
1933,
31596,
2141,
8,
785,
304,
288,
347,
2883,
8,
277,
12,
3510,
29,
17,
304,
355,
372,
2740,
2941,
65,
297,
283,
66,
297,
283,
67,
418,
627,
3510,
9,
953,
347,
1338,
8,
277,
12,
3510,
29,
17,
304,
355,
372,
2740,
779,
17,
12,
499,
12,
650,
61,
627,
3510,
9,
953,
347,
2974,
8,
277,
12,
3510,
29,
17,
304,
355,
372,
2740,
8,
3065,
8,
16007,
8,
277,
12,
3510,
29,
3029,
395,
1816,
24451,
8,
277,
12,
3510,
29,
3029,
1724,
398,
366,
275,
1933,
31596,
2141,
342,
267,
1420,
63,
1612,
275,
788,
65,
297,
283,
66,
297,
283,
67,
418,
267,
1420,
63,
1459,
275,
359,
17,
12,
499,
12,
650,
61,
267,
1420,
63,
1744,
275,
769,
8,
3065,
8,
2062,
63,
1612,
12,
1420,
63,
1459,
430,
398,
291,
14,
479,
63,
1452,
8,
513,
8,
16007,
8,
68,
1826,
1420,
63,
1612,
9,
267,
291,
14,
479,
63,
1452,
8,
513,
8,
13012,
8,
68,
1826,
1420,
63,
1459,
9,
267,
291,
14,
479,
63,
1452,
8,
513,
8,
4611,
8,
68,
1826,
1420,
63,
1744,
9,
398,
291,
14,
479,
63,
1452,
8,
513,
8,
16007,
8,
68,
12,
499,
1826,
1420,
63,
1612,
627,
499,
9,
267,
291,
14,
479,
63,
1452,
8,
513,
8,
13012,
8,
68,
12,
499,
1826,
1420,
63,
1459,
627,
499,
9,
267,
291,
14,
479,
63,
1452,
8,
513,
8,
4611,
8,
68,
12,
499,
1826,
1420,
63,
1744,
627,
499,
9,
421,
199,
533,
19610,
21365,
20760,
8,
55,
8756,
1746,
304,
272,
4887,
63,
533,
275,
488,
339,
347,
511,
63,
8092,
8,
277,
304,
267,
843,
275,
291,
14,
3494,
63,
533,
398,
367,
4113,
315,
1425,
8,
8092,
14,
31977,
63,
9583,
435,
413,
304,
288,
366,
275,
843,
342,
288,
366,
14,
409,
513,
8,
66,
7,
1421,
297,
359,
17,
12,
499,
12,
650,
12,
841,
566,
288,
366,
14,
409,
513,
8,
66,
7,
1700,
297,
330,
7,
1421,
4681,
15507,
1370,
1294,
1012,
288,
308,
275,
5927,
14,
4180,
8,
68,
12,
4113,
9,
288,
26759,
275,
5927,
14,
3640,
8,
83,
9,
288,
291,
14,
479,
63,
1452,
8,
466,
8,
1181,
395,
730,
8,
68,
430,
288,
291,
14,
479,
63,
1452,
8,
1181,
12,
366,
9,
288,
291,
14,
479,
63,
1452,
8,
8092,
14,
3640,
8,
355,
308,
14,
1814,
8,
66,
7,
17719,
14,
23004,
297,
330,
7,
17719,
3855,
366,
9,
288,
26759,
59,
66,
7,
1222,
498,
418,
275,
330,
7,
21244,
7,
288,
291,
14,
479,
63,
1397,
63,
1452,
8,
1181,
12,
366,
9,
339,
347,
511,
63,
4316,
63,
3266,
8,
277,
304,
267,
6128,
275,
291,
14,
3494,
63,
533,
342,
267,
702,
1228,
8,
1064,
12,
1211,
9,
398,
4412,
275,
4274,
65,
297,
413,
395,
661,
66,
297,
499,
395,
661,
65,
297,
499,
395,
661,
68,
297,
650,
395,
673,
661,
65,
297,
413,
395,
661,
65,
297,
650,
395,
661,
68,
297,
841,
395,
661,
67,
297,
650,
1874,
267,
6128,
275,
291,
14,
3494,
63,
533,
8,
4745,
9,
398,
327,
3486,
2312,
4484,
10557,
314,
1642,
574,
267,
291,
14,
479,
63,
1452,
8,
1064,
459,
65,
995,
413,
9,
267,
291,
14,
479,
63,
1452,
8,
1064,
459,
67,
995,
650,
9,
267,
543,
291,
14,
479,
63,
3536,
8,
10230,
304,
288,
6128,
459,
69,
418,
267,
291,
14,
479,
63,
1452,
8,
1064,
14,
362,
360,
65,
659,
413,
9,
398,
327,
769,
2312,
4484,
267,
291,
14,
479,
63,
1452,
8,
1064,
14,
21343,
360,
65,
659,
359,
17,
12,
499,
12,
413,
12,
650,
566,
267,
291,
14,
479,
63,
1452,
8,
1064,
14,
21343,
360,
68,
659,
359,
19,
12,
841,
566,
267,
327,
886,
440,
746,
340,
790,
440,
1911,
267,
291,
14,
479,
63,
1452,
8,
1064,
14,
21343,
360,
88,
659,
3073,
398,
327,
3486,
542,
4484,
1806,
16334,
1006,
1338,
267,
6128,
459,
65,
418,
275,
5685,
267,
291,
14,
479,
63,
1452,
8,
1064,
14,
21343,
360,
65,
659,
359,
2260,
566,
398,
327,
769,
542,
4484,
267,
6128,
14,
409,
513,
360,
65,
297,
359,
17,
12,
499,
12,
650,
566,
267,
291,
14,
479,
63,
1452,
8,
1064,
459,
65,
995,
413,
9,
267,
291,
14,
479,
63,
1452,
8,
1064,
14,
21343,
360,
65,
659,
359,
17,
12,
499,
12,
650,
566,
398,
327,
4911,
626,
652,
1630,
440,
1570,
3379,
5548,
267,
634,
17,
275,
359,
17,
12,
499,
12,
650,
61,
267,
6128,
14,
409,
513,
360,
65,
297,
634,
17,
9,
267,
2150,
634,
17,
5873,
267,
291,
14,
479,
63,
1452,
8,
1064,
459,
65,
995,
413,
9,
398,
327,
29408,
12,
663,
513,
885,
267,
291,
14,
479,
63,
1452,
8,
1064,
14,
5486,
360,
85,
297,
6546,
395,
6546,
9,
267,
291,
14,
479,
63,
1452,
8,
1064,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ShoRit/shipping-costs-sample
|
v2/lib/python2.7/site-packages/werkzeug/contrib/cache.py
|
84
|
30341
|
# -*- coding: utf-8 -*-
"""
werkzeug.contrib.cache
~~~~~~~~~~~~~~~~~~~~~~
The main problem with dynamic Web sites is, well, they're dynamic. Each
time a user requests a page, the webserver executes a lot of code, queries
the database, renders templates until the visitor gets the page he sees.
This is a lot more expensive than just loading a file from the file system
and sending it to the visitor.
For most Web applications, this overhead isn't a big deal but once it
becomes, you will be glad to have a cache system in place.
How Caching Works
=================
Caching is pretty simple. Basically you have a cache object lurking around
somewhere that is connected to a remote cache or the file system or
something else. When the request comes in you check if the current page
is already in the cache and if so, you're returning it from the cache.
Otherwise you generate the page and put it into the cache. (Or a fragment
of the page, you don't have to cache the full thing)
Here is a simple example of how to cache a sidebar for 5 minutes::
def get_sidebar(user):
identifier = 'sidebar_for/user%d' % user.id
value = cache.get(identifier)
if value is not None:
return value
value = generate_sidebar_for(user=user)
cache.set(identifier, value, timeout=60 * 5)
return value
Creating a Cache Object
=======================
To create a cache object you just import the cache system of your choice
from the cache module and instantiate it. Then you can start working
with that object:
>>> from werkzeug.contrib.cache import SimpleCache
>>> c = SimpleCache()
>>> c.set("foo", "value")
>>> c.get("foo")
'value'
>>> c.get("missing") is None
True
Please keep in mind that you have to create the cache and put it somewhere
you have access to it (either as a module global you can import or you just
put it into your WSGI application).
:copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
import os
import re
import errno
import tempfile
import platform
from hashlib import md5
from time import time
try:
import cPickle as pickle
except ImportError: # pragma: no cover
import pickle
from werkzeug._compat import iteritems, string_types, text_type, \
integer_types, to_native
from werkzeug.posixemulation import rename
def _items(mappingorseq):
"""Wrapper for efficient iteration over mappings represented by dicts
or sequences::
>>> for k, v in _items((i, i*i) for i in xrange(5)):
... assert k*k == v
>>> for k, v in _items(dict((i, i*i) for i in xrange(5))):
... assert k*k == v
"""
if hasattr(mappingorseq, 'items'):
return iteritems(mappingorseq)
return mappingorseq
class BaseCache(object):
"""Baseclass for the cache systems. All the cache systems implement this
API or a superset of it.
:param default_timeout: the default timeout (in seconds) that is used if
no timeout is specified on :meth:`set`. A timeout
of 0 indicates that the cache never expires.
"""
def __init__(self, default_timeout=300):
self.default_timeout = default_timeout
def _normalize_timeout(self, timeout):
if timeout is None:
timeout = self.default_timeout
return timeout
def get(self, key):
"""Look up key in the cache and return the value for it.
:param key: the key to be looked up.
:returns: The value if it exists and is readable, else ``None``.
"""
return None
def delete(self, key):
"""Delete `key` from the cache.
:param key: the key to delete.
:returns: Whether the key existed and has been deleted.
:rtype: boolean
"""
return True
def get_many(self, *keys):
"""Returns a list of values for the given keys.
For each key a item in the list is created::
foo, bar = cache.get_many("foo", "bar")
Has the same error handling as :meth:`get`.
:param keys: The function accepts multiple keys as positional
arguments.
"""
return map(self.get, keys)
def get_dict(self, *keys):
"""Like :meth:`get_many` but return a dict::
d = cache.get_dict("foo", "bar")
foo = d["foo"]
bar = d["bar"]
:param keys: The function accepts multiple keys as positional
arguments.
"""
return dict(zip(keys, self.get_many(*keys)))
def set(self, key, value, timeout=None):
"""Add a new key/value to the cache (overwrites value, if key already
exists in the cache).
:param key: the key to set
:param value: the value for the key
:param timeout: the cache timeout for the key in seconds (if not
specified, it uses the default timeout). A timeout of
0 idicates that the cache never expires.
:returns: ``True`` if key has been updated, ``False`` for backend
errors. Pickling errors, however, will raise a subclass of
``pickle.PickleError``.
:rtype: boolean
"""
return True
def add(self, key, value, timeout=None):
"""Works like :meth:`set` but does not overwrite the values of already
existing keys.
:param key: the key to set
:param value: the value for the key
:param timeout: the cache timeout for the key in seconds (if not
specified, it uses the default timeout). A timeout of
0 idicates that the cache never expires.
:returns: Same as :meth:`set`, but also ``False`` for already
existing keys.
:rtype: boolean
"""
return True
def set_many(self, mapping, timeout=None):
"""Sets multiple keys and values from a mapping.
:param mapping: a mapping with the keys/values to set.
:param timeout: the cache timeout for the key in seconds (if not
specified, it uses the default timeout). A timeout of
0 idicates that the cache never expires.
:returns: Whether all given keys have been set.
:rtype: boolean
"""
rv = True
for key, value in _items(mapping):
if not self.set(key, value, timeout):
rv = False
return rv
def delete_many(self, *keys):
"""Deletes multiple keys at once.
:param keys: The function accepts multiple keys as positional
arguments.
:returns: Whether all given keys have been deleted.
:rtype: boolean
"""
return all(self.delete(key) for key in keys)
def has(self, key):
"""Checks if a key exists in the cache without returning it. This is a
cheap operation that bypasses loading the actual data on the backend.
This method is optional and may not be implemented on all caches.
:param key: the key to check
"""
raise NotImplementedError(
'%s doesn\'t have an efficient implementation of `has`. That '
'means it is impossible to check whether a key exists without '
'fully loading the key\'s data. Consider using `self.get` '
'explicitly if you don\'t care about performance.'
)
def clear(self):
"""Clears the cache. Keep in mind that not all caches support
completely clearing the cache.
:returns: Whether the cache has been cleared.
:rtype: boolean
"""
return True
def inc(self, key, delta=1):
"""Increments the value of a key by `delta`. If the key does
not yet exist it is initialized with `delta`.
For supporting caches this is an atomic operation.
:param key: the key to increment.
:param delta: the delta to add.
:returns: The new value or ``None`` for backend errors.
"""
value = (self.get(key) or 0) + delta
return value if self.set(key, value) else None
def dec(self, key, delta=1):
"""Decrements the value of a key by `delta`. If the key does
not yet exist it is initialized with `-delta`.
For supporting caches this is an atomic operation.
:param key: the key to increment.
:param delta: the delta to subtract.
:returns: The new value or `None` for backend errors.
"""
value = (self.get(key) or 0) - delta
return value if self.set(key, value) else None
class NullCache(BaseCache):
"""A cache that doesn't cache. This can be useful for unit testing.
:param default_timeout: a dummy parameter that is ignored but exists
for API compatibility with other caches.
"""
class SimpleCache(BaseCache):
"""Simple memory cache for single process environments. This class exists
mainly for the development server and is not 100% thread safe. It tries
to use as many atomic operations as possible and no locks for simplicity
but it could happen under heavy load that keys are added multiple times.
:param threshold: the maximum number of items the cache stores before
it starts deleting some.
:param default_timeout: the default timeout that is used if no timeout is
specified on :meth:`~BaseCache.set`. A timeout of
0 indicates that the cache never expires.
"""
def __init__(self, threshold=500, default_timeout=300):
BaseCache.__init__(self, default_timeout)
self._cache = {}
self.clear = self._cache.clear
self._threshold = threshold
def _prune(self):
if len(self._cache) > self._threshold:
now = time()
toremove = []
for idx, (key, (expires, _)) in enumerate(self._cache.items()):
if (expires != 0 and expires <= now) or idx % 3 == 0:
toremove.append(key)
for key in toremove:
self._cache.pop(key, None)
def _normalize_timeout(self, timeout):
timeout = BaseCache._normalize_timeout(self, timeout)
if timeout > 0:
timeout = time() + timeout
return timeout
def get(self, key):
try:
expires, value = self._cache[key]
if expires == 0 or expires > time():
return pickle.loads(value)
except (KeyError, pickle.PickleError):
return None
def set(self, key, value, timeout=None):
expires = self._normalize_timeout(timeout)
self._prune()
self._cache[key] = (expires, pickle.dumps(value,
pickle.HIGHEST_PROTOCOL))
return True
def add(self, key, value, timeout=None):
expires = self._normalize_timeout(timeout)
self._prune()
item = (expires, pickle.dumps(value,
pickle.HIGHEST_PROTOCOL))
if key in self._cache:
return False
self._cache.setdefault(key, item)
return True
def delete(self, key):
return self._cache.pop(key, None) is not None
def has(self, key):
try:
expires, value = self._cache[key]
return expires == 0 or expires > time()
except KeyError:
return False
_test_memcached_key = re.compile(r'[^\x00-\x21\xff]{1,250}$').match
class MemcachedCache(BaseCache):
"""A cache that uses memcached as backend.
The first argument can either be an object that resembles the API of a
:class:`memcache.Client` or a tuple/list of server addresses. In the
event that a tuple/list is passed, Werkzeug tries to import the best
available memcache library.
This cache looks into the following packages/modules to find bindings for
memcached:
- ``pylibmc``
- ``google.appengine.api.memcached``
- ``memcached``
Implementation notes: This cache backend works around some limitations in
memcached to simplify the interface. For example unicode keys are encoded
to utf-8 on the fly. Methods such as :meth:`~BaseCache.get_dict` return
the keys in the same format as passed. Furthermore all get methods
silently ignore key errors to not cause problems when untrusted user data
is passed to the get methods which is often the case in web applications.
:param servers: a list or tuple of server addresses or alternatively
a :class:`memcache.Client` or a compatible client.
:param default_timeout: the default timeout that is used if no timeout is
specified on :meth:`~BaseCache.set`. A timeout of
0 indicates taht the cache never expires.
:param key_prefix: a prefix that is added before all keys. This makes it
possible to use the same memcached server for different
applications. Keep in mind that
:meth:`~BaseCache.clear` will also clear keys with a
different prefix.
"""
def __init__(self, servers=None, default_timeout=300, key_prefix=None):
BaseCache.__init__(self, default_timeout)
if servers is None or isinstance(servers, (list, tuple)):
if servers is None:
servers = ['127.0.0.1:11211']
self._client = self.import_preferred_memcache_lib(servers)
if self._client is None:
raise RuntimeError('no memcache module found')
else:
# NOTE: servers is actually an already initialized memcache
# client.
self._client = servers
self.key_prefix = to_native(key_prefix)
def _normalize_key(self, key):
key = to_native(key, 'utf-8')
if self.key_prefix:
key = self.key_prefix + key
return key
def _normalize_timeout(self, timeout):
timeout = BaseCache._normalize_timeout(self, timeout)
if timeout > 0:
timeout = int(time()) + timeout
return timeout
def get(self, key):
key = self._normalize_key(key)
# memcached doesn't support keys longer than that. Because often
# checks for so long keys can occur because it's tested from user
# submitted data etc we fail silently for getting.
if _test_memcached_key(key):
return self._client.get(key)
def get_dict(self, *keys):
key_mapping = {}
have_encoded_keys = False
for key in keys:
encoded_key = self._normalize_key(key)
if not isinstance(key, str):
have_encoded_keys = True
if _test_memcached_key(key):
key_mapping[encoded_key] = key
d = rv = self._client.get_multi(key_mapping.keys())
if have_encoded_keys or self.key_prefix:
rv = {}
for key, value in iteritems(d):
rv[key_mapping[key]] = value
if len(rv) < len(keys):
for key in keys:
if key not in rv:
rv[key] = None
return rv
def add(self, key, value, timeout=None):
key = self._normalize_key(key)
timeout = self._normalize_timeout(timeout)
return self._client.add(key, value, timeout)
def set(self, key, value, timeout=None):
key = self._normalize_key(key)
timeout = self._normalize_timeout(timeout)
return self._client.set(key, value, timeout)
def get_many(self, *keys):
d = self.get_dict(*keys)
return [d[key] for key in keys]
def set_many(self, mapping, timeout=None):
new_mapping = {}
for key, value in _items(mapping):
key = self._normalize_key(key)
new_mapping[key] = value
timeout = self._normalize_timeout(timeout)
failed_keys = self._client.set_multi(new_mapping, timeout)
return not failed_keys
def delete(self, key):
key = self._normalize_key(key)
if _test_memcached_key(key):
return self._client.delete(key)
def delete_many(self, *keys):
new_keys = []
for key in keys:
key = self._normalize_key(key)
if _test_memcached_key(key):
new_keys.append(key)
return self._client.delete_multi(new_keys)
def has(self, key):
key = self._normalize_key(key)
if _test_memcached_key(key):
return self._client.append(key, '')
return False
def clear(self):
return self._client.flush_all()
def inc(self, key, delta=1):
key = self._normalize_key(key)
return self._client.incr(key, delta)
def dec(self, key, delta=1):
key = self._normalize_key(key)
return self._client.decr(key, delta)
def import_preferred_memcache_lib(self, servers):
"""Returns an initialized memcache client. Used by the constructor."""
try:
import pylibmc
except ImportError:
pass
else:
return pylibmc.Client(servers)
try:
from google.appengine.api import memcache
except ImportError:
pass
else:
return memcache.Client()
try:
import memcache
except ImportError:
pass
else:
return memcache.Client(servers)
# backwards compatibility
GAEMemcachedCache = MemcachedCache
class RedisCache(BaseCache):
"""Uses the Redis key-value store as a cache backend.
The first argument can be either a string denoting address of the Redis
server or an object resembling an instance of a redis.Redis class.
Note: Python Redis API already takes care of encoding unicode strings on
the fly.
.. versionadded:: 0.7
.. versionadded:: 0.8
`key_prefix` was added.
.. versionchanged:: 0.8
This cache backend now properly serializes objects.
.. versionchanged:: 0.8.3
This cache backend now supports password authentication.
.. versionchanged:: 0.10
``**kwargs`` is now passed to the redis object.
:param host: address of the Redis server or an object which API is
compatible with the official Python Redis client (redis-py).
:param port: port number on which Redis server listens for connections.
:param password: password authentication for the Redis server.
:param db: db (zero-based numeric index) on Redis Server to connect.
:param default_timeout: the default timeout that is used if no timeout is
specified on :meth:`~BaseCache.set`. A timeout of
0 indicates that the cache never expires.
:param key_prefix: A prefix that should be added to all keys.
Any additional keyword arguments will be passed to ``redis.Redis``.
"""
def __init__(self, host='localhost', port=6379, password=None,
db=0, default_timeout=300, key_prefix=None, **kwargs):
BaseCache.__init__(self, default_timeout)
if isinstance(host, string_types):
try:
import redis
except ImportError:
raise RuntimeError('no redis module found')
if kwargs.get('decode_responses', None):
raise ValueError('decode_responses is not supported by '
'RedisCache.')
self._client = redis.Redis(host=host, port=port, password=password,
db=db, **kwargs)
else:
self._client = host
self.key_prefix = key_prefix or ''
def _normalize_timeout(self, timeout):
timeout = BaseCache._normalize_timeout(self, timeout)
if timeout == 0:
timeout = -1
return timeout
def dump_object(self, value):
"""Dumps an object into a string for redis. By default it serializes
integers as regular string and pickle dumps everything else.
"""
t = type(value)
if t in integer_types:
return str(value).encode('ascii')
return b'!' + pickle.dumps(value)
def load_object(self, value):
"""The reversal of :meth:`dump_object`. This might be called with
None.
"""
if value is None:
return None
if value.startswith(b'!'):
try:
return pickle.loads(value[1:])
except pickle.PickleError:
return None
try:
return int(value)
except ValueError:
# before 0.8 we did not have serialization. Still support that.
return value
def get(self, key):
return self.load_object(self._client.get(self.key_prefix + key))
def get_many(self, *keys):
if self.key_prefix:
keys = [self.key_prefix + key for key in keys]
return [self.load_object(x) for x in self._client.mget(keys)]
def set(self, key, value, timeout=None):
timeout = self._normalize_timeout(timeout)
dump = self.dump_object(value)
if timeout == -1:
result = self._client.set(name=self.key_prefix + key,
value=dump)
else:
result = self._client.setex(name=self.key_prefix + key,
value=dump, time=timeout)
return result
def add(self, key, value, timeout=None):
timeout = self._normalize_timeout(timeout)
dump = self.dump_object(value)
return (
self._client.setnx(name=self.key_prefix + key, value=dump) and
self._client.expire(name=self.key_prefix + key, time=timeout)
)
def set_many(self, mapping, timeout=None):
timeout = self._normalize_timeout(timeout)
# Use transaction=False to batch without calling redis MULTI
# which is not supported by twemproxy
pipe = self._client.pipeline(transaction=False)
for key, value in _items(mapping):
dump = self.dump_object(value)
if timeout == -1:
pipe.set(name=self.key_prefix + key, value=dump)
else:
pipe.setex(name=self.key_prefix + key, value=dump,
time=timeout)
return pipe.execute()
def delete(self, key):
return self._client.delete(self.key_prefix + key)
def delete_many(self, *keys):
if not keys:
return
if self.key_prefix:
keys = [self.key_prefix + key for key in keys]
return self._client.delete(*keys)
def has(self, key):
return self._client.exists(self.key_prefix + key)
def clear(self):
status = False
if self.key_prefix:
keys = self._client.keys(self.key_prefix + '*')
if keys:
status = self._client.delete(*keys)
else:
status = self._client.flushdb()
return status
def inc(self, key, delta=1):
return self._client.incr(name=self.key_prefix + key, amount=delta)
def dec(self, key, delta=1):
return self._client.decr(name=self.key_prefix + key, amount=delta)
class FileSystemCache(BaseCache):
"""A cache that stores the items on the file system. This cache depends
on being the only user of the `cache_dir`. Make absolutely sure that
nobody but this cache stores files there or otherwise the cache will
randomly delete files therein.
:param cache_dir: the directory where cache files are stored.
:param threshold: the maximum number of items the cache stores before
it starts deleting some.
:param default_timeout: the default timeout that is used if no timeout is
specified on :meth:`~BaseCache.set`. A timeout of
0 indicates that the cache never expires.
:param mode: the file mode wanted for the cache files, default 0600
"""
#: used for temporary files by the FileSystemCache
_fs_transaction_suffix = '.__wz_cache'
def __init__(self, cache_dir, threshold=500, default_timeout=300,
mode=0o600):
BaseCache.__init__(self, default_timeout)
self._path = cache_dir
self._threshold = threshold
self._mode = mode
try:
os.makedirs(self._path)
except OSError as ex:
if ex.errno != errno.EEXIST:
raise
def _normalize_timeout(self, timeout):
timeout = BaseCache._normalize_timeout(self, timeout)
if timeout != 0:
timeout = time() + timeout
return int(timeout)
def _list_dir(self):
"""return a list of (fully qualified) cache filenames
"""
return [os.path.join(self._path, fn) for fn in os.listdir(self._path)
if not fn.endswith(self._fs_transaction_suffix)]
def _prune(self):
entries = self._list_dir()
if len(entries) > self._threshold:
now = time()
for idx, fname in enumerate(entries):
try:
remove = False
with open(fname, 'rb') as f:
expires = pickle.load(f)
remove = (expires != 0 and expires <= now) or idx % 3 == 0
if remove:
os.remove(fname)
except (IOError, OSError):
pass
def clear(self):
for fname in self._list_dir():
try:
os.remove(fname)
except (IOError, OSError):
return False
return True
def _get_filename(self, key):
if isinstance(key, text_type):
key = key.encode('utf-8') # XXX unicode review
hash = md5(key).hexdigest()
return os.path.join(self._path, hash)
def get(self, key):
filename = self._get_filename(key)
try:
with open(filename, 'rb') as f:
pickle_time = pickle.load(f)
if pickle_time == 0 or pickle_time >= time():
return pickle.load(f)
else:
os.remove(filename)
return None
except (IOError, OSError, pickle.PickleError):
return None
def add(self, key, value, timeout=None):
filename = self._get_filename(key)
if not os.path.exists(filename):
return self.set(key, value, timeout)
return False
def set(self, key, value, timeout=None):
timeout = self._normalize_timeout(timeout)
filename = self._get_filename(key)
self._prune()
try:
fd, tmp = tempfile.mkstemp(suffix=self._fs_transaction_suffix,
dir=self._path)
with os.fdopen(fd, 'wb') as f:
pickle.dump(timeout, f, 1)
pickle.dump(value, f, pickle.HIGHEST_PROTOCOL)
rename(tmp, filename)
os.chmod(filename, self._mode)
except (IOError, OSError):
return False
else:
return True
def delete(self, key):
try:
os.remove(self._get_filename(key))
except (IOError, OSError):
return False
else:
return True
def has(self, key):
filename = self._get_filename(key)
try:
with open(filename, 'rb') as f:
pickle_time = pickle.load(f)
if pickle_time == 0 or pickle_time >= time():
return True
else:
os.remove(filename)
return False
except (IOError, OSError, pickle.PickleError):
return False
class UWSGICache(BaseCache):
""" Implements the cache using uWSGI's caching framework.
.. note::
This class cannot be used when running under PyPy, because the uWSGI
API implementation for PyPy is lacking the needed functionality.
:param default_timeout: The default timeout in seconds.
:param cache: The name of the caching instance to connect to, for
example: mycache@localhost:3031, defaults to an empty string, which
means uWSGI will cache in the local instance. If the cache is in the
same instance as the werkzeug app, you only have to provide the name of
the cache.
"""
def __init__(self, default_timeout=300, cache=''):
BaseCache.__init__(self, default_timeout)
if platform.python_implementation() == 'PyPy':
raise RuntimeError("uWSGI caching does not work under PyPy, see "
"the docs for more details.")
try:
import uwsgi
self._uwsgi = uwsgi
except ImportError:
raise RuntimeError("uWSGI could not be imported, are you "
"running under uWSGI?")
self.cache = cache
def get(self, key):
rv = self._uwsgi.cache_get(key, self.cache)
if rv is None:
return
return pickle.loads(rv)
def delete(self, key):
return self._uwsgi.cache_del(key, self.cache)
def set(self, key, value, timeout=None):
return self._uwsgi.cache_update(key, pickle.dumps(value),
self._normalize_timeout(timeout),
self.cache)
def add(self, key, value, timeout=None):
return self._uwsgi.cache_set(key, pickle.dumps(value),
self._normalize_timeout(timeout),
self.cache)
def clear(self):
return self._uwsgi.cache_clear(self.cache)
def has(self, key):
return self._uwsgi.cache_exists(key, self.cache) is not None
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10380,
14,
2828,
14,
1637,
272,
18294,
2878,
1714,
339,
710,
2446,
5160,
543,
8336,
6001,
15424,
365,
12,
5521,
12,
2985,
3984,
8336,
14,
221,
7048,
272,
900,
282,
922,
4145,
282,
2034,
12,
314,
3330,
1000,
24956,
282,
13918,
402,
1233,
12,
9212,
272,
314,
3050,
12,
3795,
83,
7009,
5133,
314,
18040,
7545,
314,
2034,
946,
542,
397,
14,
339,
961,
365,
282,
13918,
1655,
23133,
2419,
2951,
8697,
282,
570,
687,
314,
570,
2656,
272,
436,
10209,
652,
370,
314,
18040,
14,
339,
2104,
4750,
6001,
13103,
12,
642,
24075,
5712,
1133,
282,
7282,
7962,
1325,
5403,
652,
272,
15410,
12,
1265,
911,
506,
6482,
350,
370,
1172,
282,
2581,
2656,
315,
4192,
14,
339,
7494,
445,
23302,
28099,
272,
16248,
339,
445,
23302,
365,
7268,
3486,
14,
221,
10082,
1183,
1265,
1172,
282,
2581,
909,
634,
300,
17443,
6818,
272,
23430,
626,
365,
8539,
370,
282,
3982,
2581,
503,
314,
570,
2656,
503,
272,
6020,
587,
14,
221,
3979,
314,
1056,
12477,
315,
1265,
1104,
340,
314,
1453,
2034,
272,
365,
2575,
315,
314,
2581,
436,
340,
880,
12,
1265,
3984,
8152,
652,
687,
314,
2581,
14,
272,
6630,
1265,
3550,
314,
2034,
436,
5324,
652,
1901,
314,
2581,
14,
334,
2844,
282,
7956,
272,
402,
314,
2034,
12,
1265,
2793,
1133,
1172,
370,
2581,
314,
2615,
8377,
9,
339,
11842,
365,
282,
3486,
2893,
402,
4212,
370,
2581,
282,
18437,
367,
959,
9395,
447,
398,
347,
664,
63,
27372,
8,
751,
304,
288,
5148,
275,
283,
27372,
63,
509,
15,
751,
5,
68,
7,
450,
922,
14,
344,
288,
574,
275,
2581,
14,
362,
8,
5364,
9,
288,
340,
574,
365,
440,
488,
26,
355,
372,
574,
288,
574,
275,
3550,
63,
27372,
63,
509,
8,
751,
29,
751,
9,
288,
2581,
14,
409,
8,
5364,
12,
574,
12,
2653,
29,
2259,
627,
959,
9,
288,
372,
574,
339,
20507,
282,
11977,
6935,
272,
16248,
23476,
339,
4005,
1218,
282,
2581,
909,
1265,
2951,
492,
314,
2581,
2656,
402,
2195,
7141,
272,
687,
314,
2581,
859,
436,
17321,
652,
14,
221,
9442,
1265,
883,
1343,
6449,
272,
543,
626,
909,
26,
339,
1306,
687,
10380,
14,
2828,
14,
1637,
492,
5870,
4437,
272,
1306,
286,
275,
5870,
4437,
342,
272,
1306,
286,
14,
409,
480,
1421,
401,
298,
585,
531,
272,
1306,
286,
14,
362,
480,
1421,
531,
272,
283,
585,
7,
272,
1306,
286,
14,
362,
480,
4752,
531,
365,
488,
272,
715,
339,
7754,
4215,
315,
25169,
626,
1265,
1172,
370,
1218,
314,
2581,
436,
5324,
652,
23430,
272,
1265,
1172,
2879,
370,
652,
334,
22051,
465,
282,
859,
2288,
1265,
883,
492,
503,
1265,
2951,
272,
5324,
652,
1901,
2195,
9279,
4223,
680,
339,
520,
7307,
26,
334,
67,
9,
6927,
701,
314,
22798,
11682,
12,
1937,
10610,
367,
1655,
2436,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
747,
199,
646,
295,
199,
646,
7554,
199,
646,
5549,
199,
646,
4298,
199,
504,
8337,
492,
6128,
21,
199,
504,
900,
492,
900,
199,
893,
26,
272,
492,
17572,
465,
5927,
199,
2590,
3545,
26,
221,
327,
11942,
26,
949,
8486,
272,
492,
5927,
199,
199,
504,
10380,
423,
5819,
492,
10849,
12,
1059,
63,
1313,
12,
1318,
63,
466,
12,
971,
272,
3000,
63,
1313,
12,
370,
63,
6106,
199,
504,
10380,
14,
555,
338,
1845,
7720,
492,
11441,
421,
199,
318,
485,
1744,
8,
4745,
269,
3610,
304,
272,
408,
4590,
367,
13402,
8494,
1806,
13546,
11159,
701,
10809,
272,
503,
8013,
447,
398,
1306,
367,
1022,
12,
373,
315,
485,
1744,
1332,
73,
12,
284,
10,
73,
9,
367,
284,
315,
4945,
8,
21,
2298,
267,
2263,
259,
702,
1022,
10,
75,
508,
373,
398,
1306,
367,
1022,
12,
373,
315,
485,
1744,
8,
807,
1332,
73,
12,
284,
10,
73,
9,
367,
284,
315,
4945,
8,
21,
15206,
267,
2263,
259,
702,
1022,
10,
75,
508,
373,
339,
408,
272,
340,
2688,
8,
4745,
269,
3610,
12,
283,
1744,
735,
267,
372,
10849,
8,
4745,
269,
3610,
9,
272,
372,
4412,
269,
3610,
421,
199,
533,
3523,
4437,
8,
785,
304,
339,
408,
1563,
533,
367,
314,
2581,
10460,
14,
221,
2900,
314,
2581,
10460,
5669,
642,
272,
3261,
503,
282,
1613,
409,
402,
652,
14,
339,
520,
635,
849,
63,
2593,
26,
314,
849,
2653,
334,
262,
4696,
9,
626,
365,
1202,
340,
1169,
949,
2653,
365,
2013,
641,
520,
5247,
1705,
409,
2313,
437,
2653,
1169,
402,
378,
9126,
626,
314,
2581,
7078,
12261,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
849,
63,
2593,
29,
5863,
304,
267,
291,
14,
885,
63,
2593,
275,
849,
63,
2593,
339,
347,
485,
7721,
63,
2593,
8,
277,
12,
2653,
304,
267,
340,
2653,
365,
488,
26,
288,
2653,
275,
291,
14,
885,
63,
2593,
267,
372,
2653,
339,
347,
664,
8,
277,
12,
790,
304,
267,
408,
20926,
1536,
790,
315,
314,
2581,
436,
372,
314,
574,
367,
652,
14,
398,
520,
635,
790,
26,
314,
790,
370,
506,
21182,
1536,
14,
267,
520,
5808,
26,
710,
574,
340,
652,
3495,
436,
365,
12701,
12,
587,
1124,
403,
4345,
267,
408,
267,
372,
488,
339,
347,
3145,
8,
277,
12,
790,
304,
267,
408,
5392,
658,
498,
64,
687,
314,
2581,
14,
398,
520,
635,
790,
26,
314,
790,
370,
3145,
14,
267,
520,
5808,
26,
7480,
314,
790,
30482,
436,
965,
2757,
5463,
14,
267,
520,
4500,
26,
5046,
267,
408,
267,
372,
715,
339,
347,
664,
63,
3479,
8,
277,
12,
627,
1612,
304,
267,
408,
3407,
282,
769,
402,
1338,
367,
314,
1627,
2883,
14,
267,
2104,
1924,
790,
282,
1242,
315,
314,
769,
365,
2737,
447,
953,
3925,
12,
4681,
275,
2581,
14,
362,
63,
3479,
480,
1421,
401,
298,
1700,
531,
398,
13481,
314,
2011,
1125,
7252,
465,
520,
5247,
1705,
362,
2313,
398,
520,
635,
2883,
26,
710,
805,
11479,
3663,
2883,
465,
11333,
2151,
2368,
14,
267,
408,
267,
372,
2341,
8,
277,
14,
362,
12,
2883,
9,
339,
347,
664
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10380,
14,
2828,
14,
1637,
272,
18294,
2878,
1714,
339,
710,
2446,
5160,
543,
8336,
6001,
15424,
365,
12,
5521,
12,
2985,
3984,
8336,
14,
221,
7048,
272,
900,
282,
922,
4145,
282,
2034,
12,
314,
3330,
1000,
24956,
282,
13918,
402,
1233,
12,
9212,
272,
314,
3050,
12,
3795,
83,
7009,
5133,
314,
18040,
7545,
314,
2034,
946,
542,
397,
14,
339,
961,
365,
282,
13918,
1655,
23133,
2419,
2951,
8697,
282,
570,
687,
314,
570,
2656,
272,
436,
10209,
652,
370,
314,
18040,
14,
339,
2104,
4750,
6001,
13103,
12,
642,
24075,
5712,
1133,
282,
7282,
7962,
1325,
5403,
652,
272,
15410,
12,
1265,
911,
506,
6482,
350,
370,
1172,
282,
2581,
2656,
315,
4192,
14,
339,
7494,
445,
23302,
28099,
272,
16248,
339,
445,
23302,
365,
7268,
3486,
14,
221,
10082,
1183,
1265,
1172,
282,
2581,
909,
634,
300,
17443,
6818,
272,
23430,
626,
365,
8539,
370,
282,
3982,
2581,
503,
314,
570,
2656,
503,
272,
6020,
587,
14,
221,
3979,
314,
1056,
12477,
315,
1265,
1104,
340,
314,
1453,
2034,
272,
365,
2575,
315,
314,
2581,
436,
340,
880,
12,
1265,
3984,
8152,
652,
687,
314,
2581,
14,
272,
6630,
1265,
3550,
314,
2034,
436,
5324,
652,
1901,
314,
2581,
14,
334,
2844,
282,
7956,
272,
402,
314,
2034,
12,
1265,
2793,
1133,
1172,
370,
2581,
314,
2615,
8377,
9,
339,
11842,
365,
282,
3486,
2893,
402,
4212,
370,
2581,
282,
18437,
367,
959,
9395,
447,
398,
347,
664,
63,
27372,
8,
751,
304,
288,
5148,
275,
283,
27372,
63,
509,
15,
751,
5,
68,
7,
450,
922,
14,
344,
288,
574,
275,
2581,
14,
362,
8,
5364,
9,
288,
340,
574,
365,
440,
488,
26,
355,
372,
574,
288,
574,
275,
3550,
63,
27372,
63,
509,
8,
751,
29,
751,
9,
288,
2581,
14,
409,
8,
5364,
12,
574,
12,
2653,
29,
2259,
627,
959,
9,
288,
372,
574,
339,
20507,
282,
11977,
6935,
272,
16248,
23476,
339,
4005,
1218,
282,
2581,
909,
1265,
2951,
492,
314,
2581,
2656,
402,
2195,
7141,
272,
687,
314,
2581,
859,
436,
17321,
652,
14,
221,
9442,
1265,
883,
1343,
6449,
272,
543,
626,
909,
26,
339,
1306,
687,
10380,
14,
2828,
14,
1637,
492,
5870,
4437,
272,
1306,
286,
275,
5870,
4437,
342,
272,
1306,
286,
14,
409,
480,
1421,
401,
298,
585,
531,
272,
1306,
286,
14,
362,
480,
1421,
531,
272,
283,
585,
7,
272,
1306,
286,
14,
362,
480,
4752,
531,
365,
488,
272,
715,
339,
7754,
4215,
315,
25169,
626,
1265,
1172,
370,
1218,
314,
2581,
436,
5324,
652,
23430,
272,
1265,
1172,
2879,
370,
652,
334,
22051,
465,
282,
859,
2288,
1265,
883,
492,
503,
1265,
2951,
272,
5324,
652,
1901,
2195,
9279,
4223,
680,
339,
520,
7307,
26,
334,
67,
9,
6927,
701,
314,
22798,
11682,
12,
1937,
10610,
367,
1655,
2436,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
747,
199,
646,
295,
199,
646,
7554,
199,
646,
5549,
199,
646,
4298,
199,
504,
8337,
492,
6128,
21,
199,
504,
900,
492,
900,
199,
893,
26,
272,
492,
17572,
465,
5927,
199,
2590,
3545,
26,
221,
327,
11942,
26,
949,
8486,
272,
492,
5927,
199,
199,
504,
10380,
423,
5819,
492,
10849,
12,
1059,
63,
1313,
12,
1318,
63,
466,
12,
971,
272,
3000,
63,
1313,
12,
370,
63,
6106,
199,
504,
10380,
14,
555,
338,
1845,
7720,
492,
11441,
421,
199,
318,
485,
1744,
8,
4745,
269,
3610,
304,
272,
408,
4590,
367,
13402,
8494,
1806,
13546,
11159,
701,
10809,
272,
503,
8013,
447,
398,
1306,
367,
1022,
12,
373,
315,
485,
1744,
1332,
73,
12,
284,
10,
73,
9,
367,
284,
315,
4945,
8,
21,
2298,
267,
2263,
259,
702,
1022,
10,
75,
508,
373,
398,
1306,
367,
1022,
12,
373,
315,
485,
1744,
8,
807,
1332,
73,
12,
284,
10,
73,
9,
367,
284,
315,
4945,
8,
21,
15206,
267,
2263,
259,
702,
1022,
10,
75,
508,
373,
339,
408,
272,
340,
2688,
8,
4745,
269,
3610,
12,
283,
1744,
735,
267,
372,
10849,
8,
4745,
269,
3610,
9,
272,
372,
4412,
269,
3610,
421,
199,
533,
3523,
4437,
8,
785,
304,
339,
408,
1563,
533,
367,
314,
2581,
10460,
14,
221,
2900,
314,
2581,
10460,
5669,
642,
272,
3261,
503,
282,
1613,
409,
402,
652,
14,
339,
520,
635,
849,
63,
2593,
26,
314,
849,
2653,
334,
262,
4696,
9,
626,
365,
1202,
340,
1169,
949,
2653,
365,
2013,
641,
520,
5247,
1705,
409,
2313,
437,
2653,
1169,
402,
378,
9126,
626,
314,
2581,
7078,
12261,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
849,
63,
2593,
29,
5863,
304,
267,
291,
14,
885,
63,
2593,
275,
849,
63,
2593,
339,
347,
485,
7721,
63,
2593,
8,
277,
12,
2653,
304,
267,
340,
2653,
365,
488,
26,
288,
2653,
275,
291,
14,
885,
63,
2593,
267,
372,
2653,
339,
347,
664,
8,
277,
12,
790,
304,
267,
408,
20926,
1536,
790,
315,
314,
2581,
436,
372,
314,
574,
367,
652,
14,
398,
520,
635,
790,
26,
314,
790,
370,
506,
21182,
1536,
14,
267,
520,
5808,
26,
710,
574,
340,
652,
3495,
436,
365,
12701,
12,
587,
1124,
403,
4345,
267,
408,
267,
372,
488,
339,
347,
3145,
8,
277,
12,
790,
304,
267,
408,
5392,
658,
498,
64,
687,
314,
2581,
14,
398,
520,
635,
790,
26,
314,
790,
370,
3145,
14,
267,
520,
5808,
26,
7480,
314,
790,
30482,
436,
965,
2757,
5463,
14,
267,
520,
4500,
26,
5046,
267,
408,
267,
372,
715,
339,
347,
664,
63,
3479,
8,
277,
12,
627,
1612,
304,
267,
408,
3407,
282,
769,
402,
1338,
367,
314,
1627,
2883,
14,
267,
2104,
1924,
790,
282,
1242,
315,
314,
769,
365,
2737,
447,
953,
3925,
12,
4681,
275,
2581,
14,
362,
63,
3479,
480,
1421,
401,
298,
1700,
531,
398,
13481,
314,
2011,
1125,
7252,
465,
520,
5247,
1705,
362,
2313,
398,
520,
635,
2883,
26,
710,
805,
11479,
3663,
2883,
465,
11333,
2151,
2368,
14,
267,
408,
267,
372,
2341,
8,
277,
14,
362,
12,
2883,
9,
339,
347,
664,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
xfournet/intellij-community
|
python/testData/MockSdk2.7/Lib/re.py
|
113
|
12984
|
#
# Secret Labs' Regular Expression Engine
#
# re-compatible interface for the sre matching engine
#
# Copyright (c) 1998-2001 by Secret Labs AB. All rights reserved.
#
# This version of the SRE library can be redistributed under CNRI's
# Python 1.6 license. For any other use, please contact Secret Labs
# AB (info@pythonware.com).
#
# Portions of this engine have been developed in cooperation with
# CNRI. Hewlett-Packard provided funding for 1.6 integration and
# other compatibility work.
#
r"""Support for regular expressions (RE).
This module provides regular expression matching operations similar to
those found in Perl. It supports both 8-bit and Unicode strings; both
the pattern and the strings being processed can contain null bytes and
characters outside the US ASCII range.
Regular expressions can contain both special and ordinary characters.
Most ordinary characters, like "A", "a", or "0", are the simplest
regular expressions; they simply match themselves. You can
concatenate ordinary characters, so last matches the string 'last'.
The special characters are:
"." Matches any character except a newline.
"^" Matches the start of the string.
"$" Matches the end of the string or just before the newline at
the end of the string.
"*" Matches 0 or more (greedy) repetitions of the preceding RE.
Greedy means that it will match as many repetitions as possible.
"+" Matches 1 or more (greedy) repetitions of the preceding RE.
"?" Matches 0 or 1 (greedy) of the preceding RE.
*?,+?,?? Non-greedy versions of the previous three special characters.
{m,n} Matches from m to n repetitions of the preceding RE.
{m,n}? Non-greedy version of the above.
"\\" Either escapes special characters or signals a special sequence.
[] Indicates a set of characters.
A "^" as the first character indicates a complementing set.
"|" A|B, creates an RE that will match either A or B.
(...) Matches the RE inside the parentheses.
The contents can be retrieved or matched later in the string.
(?iLmsux) Set the I, L, M, S, U, or X flag for the RE (see below).
(?:...) Non-grouping version of regular parentheses.
(?P<name>...) The substring matched by the group is accessible by name.
(?P=name) Matches the text matched earlier by the group named name.
(?#...) A comment; ignored.
(?=...) Matches if ... matches next, but doesn't consume the string.
(?!...) Matches if ... doesn't match next.
(?<=...) Matches if preceded by ... (must be fixed length).
(?<!...) Matches if not preceded by ... (must be fixed length).
(?(id/name)yes|no) Matches yes pattern if the group with id/name matched,
the (optional) no pattern otherwise.
The special sequences consist of "\\" and a character from the list
below. If the ordinary character is not on the list, then the
resulting RE will match the second character.
\number Matches the contents of the group of the same number.
\A Matches only at the start of the string.
\Z Matches only at the end of the string.
\b Matches the empty string, but only at the start or end of a word.
\B Matches the empty string, but not at the start or end of a word.
\d Matches any decimal digit; equivalent to the set [0-9].
\D Matches any non-digit character; equivalent to the set [^0-9].
\s Matches any whitespace character; equivalent to [ \t\n\r\f\v].
\S Matches any non-whitespace character; equiv. to [^ \t\n\r\f\v].
\w Matches any alphanumeric character; equivalent to [a-zA-Z0-9_].
With LOCALE, it will match the set [0-9_] plus characters defined
as letters for the current locale.
\W Matches the complement of \w.
\\ Matches a literal backslash.
This module exports the following functions:
match Match a regular expression pattern to the beginning of a string.
search Search a string for the presence of a pattern.
sub Substitute occurrences of a pattern found in a string.
subn Same as sub, but also return the number of substitutions made.
split Split a string by the occurrences of a pattern.
findall Find all occurrences of a pattern in a string.
finditer Return an iterator yielding a match object for each match.
compile Compile a pattern into a RegexObject.
purge Clear the regular expression cache.
escape Backslash all non-alphanumerics in a string.
Some of the functions in this module takes flags as optional parameters:
I IGNORECASE Perform case-insensitive matching.
L LOCALE Make \w, \W, \b, \B, dependent on the current locale.
M MULTILINE "^" matches the beginning of lines (after a newline)
as well as the string.
"$" matches the end of lines (before a newline) as well
as the end of the string.
S DOTALL "." matches any character at all, including the newline.
X VERBOSE Ignore whitespace and comments for nicer looking RE's.
U UNICODE Make \w, \W, \b, \B, dependent on the Unicode locale.
This module also defines an exception 'error'.
"""
import sys
import sre_compile
import sre_parse
# public symbols
__all__ = [ "match", "search", "sub", "subn", "split", "findall",
"compile", "purge", "template", "escape", "I", "L", "M", "S", "X",
"U", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL", "VERBOSE",
"UNICODE", "error" ]
__version__ = "2.2.1"
# flags
I = IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE # ignore case
L = LOCALE = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale
U = UNICODE = sre_compile.SRE_FLAG_UNICODE # assume unicode locale
M = MULTILINE = sre_compile.SRE_FLAG_MULTILINE # make anchors look for newline
S = DOTALL = sre_compile.SRE_FLAG_DOTALL # make dot match newline
X = VERBOSE = sre_compile.SRE_FLAG_VERBOSE # ignore whitespace and comments
# sre extensions (experimental, don't rely on these)
T = TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE # disable backtracking
DEBUG = sre_compile.SRE_FLAG_DEBUG # dump pattern after compilation
# sre exception
error = sre_compile.error
# --------------------------------------------------------------------
# public interface
def match(pattern, string, flags=0):
"""Try to apply the pattern at the start of the string, returning
a match object, or None if no match was found."""
return _compile(pattern, flags).match(string)
def search(pattern, string, flags=0):
"""Scan through string looking for a match to the pattern, returning
a match object, or None if no match was found."""
return _compile(pattern, flags).search(string)
def sub(pattern, repl, string, count=0, flags=0):
"""Return the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in string by the
replacement repl. repl can be either a string or a callable;
if a string, backslash escapes in it are processed. If it is
a callable, it's passed the match object and must return
a replacement string to be used."""
return _compile(pattern, flags).sub(repl, string, count)
def subn(pattern, repl, string, count=0, flags=0):
"""Return a 2-tuple containing (new_string, number).
new_string is the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in the source
string by the replacement repl. number is the number of
substitutions that were made. repl can be either a string or a
callable; if a string, backslash escapes in it are processed.
If it is a callable, it's passed the match object and must
return a replacement string to be used."""
return _compile(pattern, flags).subn(repl, string, count)
def split(pattern, string, maxsplit=0, flags=0):
"""Split the source string by the occurrences of the pattern,
returning a list containing the resulting substrings."""
return _compile(pattern, flags).split(string, maxsplit)
def findall(pattern, string, flags=0):
"""Return a list of all non-overlapping matches in the string.
If one or more groups are present in the pattern, return a
list of groups; this will be a list of tuples if the pattern
has more than one group.
Empty matches are included in the result."""
return _compile(pattern, flags).findall(string)
if sys.hexversion >= 0x02020000:
__all__.append("finditer")
def finditer(pattern, string, flags=0):
"""Return an iterator over all non-overlapping matches in the
string. For each match, the iterator returns a match object.
Empty matches are included in the result."""
return _compile(pattern, flags).finditer(string)
def compile(pattern, flags=0):
"Compile a regular expression pattern, returning a pattern object."
return _compile(pattern, flags)
def purge():
"Clear the regular expression cache"
_cache.clear()
_cache_repl.clear()
def template(pattern, flags=0):
"Compile a template pattern, returning a pattern object"
return _compile(pattern, flags|T)
_alphanum = {}
for c in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890':
_alphanum[c] = 1
del c
def escape(pattern):
"Escape all non-alphanumeric characters in pattern."
s = list(pattern)
alphanum = _alphanum
for i, c in enumerate(pattern):
if c not in alphanum:
if c == "\000":
s[i] = "\\000"
else:
s[i] = "\\" + c
return pattern[:0].join(s)
# --------------------------------------------------------------------
# internals
_cache = {}
_cache_repl = {}
_pattern_type = type(sre_compile.compile("", 0))
_MAXCACHE = 100
def _compile(*key):
# internal: compile pattern
cachekey = (type(key[0]),) + key
p = _cache.get(cachekey)
if p is not None:
return p
pattern, flags = key
if isinstance(pattern, _pattern_type):
if flags:
raise ValueError('Cannot process flags argument with a compiled pattern')
return pattern
if not sre_compile.isstring(pattern):
raise TypeError, "first argument must be string or compiled pattern"
try:
p = sre_compile.compile(pattern, flags)
except error, v:
raise error, v # invalid expression
if len(_cache) >= _MAXCACHE:
_cache.clear()
_cache[cachekey] = p
return p
def _compile_repl(*key):
# internal: compile replacement pattern
p = _cache_repl.get(key)
if p is not None:
return p
repl, pattern = key
try:
p = sre_parse.parse_template(repl, pattern)
except error, v:
raise error, v # invalid expression
if len(_cache_repl) >= _MAXCACHE:
_cache_repl.clear()
_cache_repl[key] = p
return p
def _expand(pattern, match, template):
# internal: match.expand implementation hook
template = sre_parse.parse_template(template, pattern)
return sre_parse.expand_template(template, match)
def _subx(pattern, template):
# internal: pattern.sub/subn implementation helper
template = _compile_repl(template, pattern)
if not template[0] and len(template[1]) == 1:
# literal replacement
return template[1][0]
def filter(match, template=template):
return sre_parse.expand_template(template, match)
return filter
# register myself for pickling
import copy_reg
def _pickle(p):
return _compile, (p.pattern, p.flags)
copy_reg.pickle(_pattern_type, _pickle, _compile)
# --------------------------------------------------------------------
# experimental stuff (see python-dev discussions for details)
class Scanner:
def __init__(self, lexicon, flags=0):
from sre_constants import BRANCH, SUBPATTERN
self.lexicon = lexicon
# combine phrases into a compound pattern
p = []
s = sre_parse.Pattern()
s.flags = flags
for phrase, action in lexicon:
p.append(sre_parse.SubPattern(s, [
(SUBPATTERN, (len(p)+1, sre_parse.parse(phrase, flags))),
]))
s.groups = len(p)+1
p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
self.scanner = sre_compile.compile(p)
def scan(self, string):
result = []
append = result.append
match = self.scanner.scanner(string).match
i = 0
while 1:
m = match()
if not m:
break
j = m.end()
if i == j:
break
action = self.lexicon[m.lastindex-1][1]
if hasattr(action, '__call__'):
self.match = m
action = action(self, m.group())
if action is not None:
append(action)
i = j
return result, string[i:]
|
apache-2.0
|
[
3,
199,
3,
23580,
491,
2101,
7,
18528,
22013,
12580,
199,
3,
199,
3,
295,
13,
6490,
3217,
367,
314,
25877,
4877,
6869,
199,
3,
199,
3,
1898,
334,
67,
9,
19960,
13,
8339,
701,
23580,
491,
2101,
14840,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
1015,
402,
314,
26421,
3555,
883,
506,
295,
16832,
1334,
445,
46,
6129,
1159,
199,
3,
2018,
413,
14,
22,
4190,
14,
221,
2104,
1263,
1163,
675,
12,
8749,
8966,
23580,
491,
2101,
199,
3,
14840,
334,
815,
32,
1548,
1068,
14,
957,
680,
199,
3,
199,
3,
20825,
402,
642,
6869,
1172,
2757,
477,
27813,
315,
512,
5735,
543,
199,
3,
445,
46,
6129,
14,
221,
27849,
13,
29471,
2741,
27440,
316,
367,
413,
14,
22,
13150,
436,
199,
3,
1163,
7163,
1736,
14,
199,
3,
199,
199,
82,
624,
11532,
367,
5578,
8455,
334,
907,
680,
199,
199,
2765,
859,
6571,
5578,
3965,
4877,
5331,
8545,
370,
199,
273,
3362,
1911,
315,
3492,
76,
14,
221,
2779,
5171,
3865,
1695,
13,
2075,
436,
6140,
3326,
27,
3865,
199,
1589,
3851,
436,
314,
3326,
3769,
7686,
883,
1395,
2973,
2783,
436,
199,
16516,
9682,
314,
19635,
10485,
1425,
14,
199,
199,
16038,
8455,
883,
1395,
3865,
4539,
436,
24801,
4110,
14,
199,
24625,
24801,
4110,
12,
2839,
298,
33,
401,
298,
65,
401,
503,
298,
16,
401,
787,
314,
3486,
270,
199,
7898,
8455,
27,
2985,
9329,
1336,
17279,
14,
221,
2047,
883,
199,
13433,
24801,
4110,
12,
880,
2061,
4450,
314,
1059,
283,
2019,
1370,
199,
199,
1918,
4539,
4110,
787,
26,
272,
14530,
420,
21682,
1263,
4528,
871,
282,
8057,
14,
272,
18129,
2,
420,
21682,
314,
1343,
402,
314,
1059,
14,
272,
7880,
2,
420,
21682,
314,
1284,
402,
314,
1059,
503,
2951,
2544,
314,
8057,
737,
1467,
314,
1284,
402,
314,
1059,
14,
272,
22423,
420,
21682,
378,
503,
1655,
334,
71,
24737,
9,
6375,
7752,
402,
314,
22627,
5363,
14,
1467,
598,
24737,
4910,
626,
652,
911,
1336,
465,
5002,
6375,
7752,
465,
3962,
14,
272,
298,
5207,
420,
21682,
413,
503,
1655,
334,
71,
24737,
9,
6375,
7752,
402,
314,
22627,
5363,
14,
272,
29325,
420,
21682,
378,
503,
413,
334,
71,
24737,
9,
402,
314,
22627,
5363,
14,
272,
627,
22556,
11,
22556,
10674,
10172,
13,
71,
24737,
5459,
402,
314,
4136,
7795,
4539,
4110,
14,
272,
469,
77,
12,
78,
93,
259,
21682,
687,
333,
370,
302,
6375,
7752,
402,
314,
22627,
5363,
14,
272,
469,
77,
12,
78,
93,
31,
257,
10172,
13,
71,
24737,
1015,
402,
314,
3432,
14,
272,
9926,
2,
258,
13083,
24644,
4539,
4110,
503,
10166,
282,
4539,
3414,
14,
272,
942,
755,
19334,
282,
663,
402,
4110,
14,
1467,
437,
18129,
2,
465,
314,
1642,
4528,
9126,
282,
2831,
434,
316,
663,
14,
272,
15733,
2,
420,
437,
92,
34,
12,
8491,
376,
5363,
626,
911,
1336,
1902,
437,
503,
699,
14,
272,
30934,
259,
21682,
314,
5363,
6272,
314,
23592,
14,
1467,
710,
4072,
883,
506,
12396,
503,
7838,
2945,
315,
314,
1059,
14,
272,
7558,
73,
44,
706,
2521,
9,
2494,
314,
473,
12,
491,
12,
603,
12,
428,
12,
738,
12,
503,
1323,
3305,
367,
314,
5363,
334,
3239,
5084,
680,
272,
16697,
11965,
221,
10172,
13,
22390,
1015,
402,
5578,
23592,
14,
272,
7558,
48,
28,
354,
30,
11965,
710,
20597,
7838,
701,
314,
1572,
365,
17909,
701,
536,
14,
272,
7558,
48,
29,
354,
9,
258,
21682,
314,
1318,
7838,
14119,
701,
314,
1572,
4310,
536,
14,
272,
7558,
3,
11965,
221,
437,
3721,
27,
5525,
14,
272,
7558,
29,
11965,
221,
21682,
340,
2263,
4450,
2163,
12,
1325,
3181,
1133,
9451,
314,
1059,
14,
272,
7558,
1,
11965,
221,
21682,
340,
2263,
3181,
1133,
1336,
2163,
14,
272,
7558,
12932,
11965,
21682,
340,
9222,
770,
701,
2263,
334,
7790,
506,
6317,
2582,
680,
272,
7558,
11230,
11965,
21682,
340,
440,
9222,
770,
701,
2263,
334,
7790,
506,
6317,
2582,
680,
272,
7558,
8,
344,
15,
354,
9,
5066,
92,
889,
9,
21682,
9456,
3851,
340,
314,
1572,
543,
1305,
15,
354,
7838,
12,
2432,
314,
334,
4144,
9,
949,
3851,
4257,
14,
199,
199,
1918,
4539,
8013,
17568,
402,
9926,
2,
436,
282,
4528,
687,
314,
769,
199,
12843,
14,
221,
982,
314,
24801,
4528,
365,
440,
641,
314,
769,
12,
2066,
314,
199,
1099,
316,
5363,
911,
1336,
314,
3499,
4528,
14,
272,
971,
1955,
221,
21682,
314,
4072,
402,
314,
1572,
402,
314,
2011,
1329,
14,
272,
971,
33,
755,
21682,
1454,
737,
314,
1343,
402,
314,
1059,
14,
272,
971,
58,
755,
21682,
1454,
737,
314,
1284,
402,
314,
1059,
14,
272,
971,
66,
755,
21682,
314,
2701,
1059,
12,
1325,
1454,
737,
314,
1343,
503,
1284,
402,
282,
4349,
14,
272,
971,
34,
755,
21682,
314,
2701,
1059,
12,
1325,
440,
737,
314,
1343,
503,
1284,
402,
282,
4349,
14,
272,
971,
68,
755,
21682,
1263,
6107,
10964,
27,
7353,
370,
314,
663,
359,
16,
13,
25,
1055,
272,
971,
36,
755,
21682,
1263,
2222,
13,
8573,
4528,
27,
7353,
370,
314,
663,
359,
62,
16,
13,
25,
1055,
272,
971,
83,
755,
21682,
1263,
8139,
4528,
27,
7353,
370,
359,
971,
84,
60,
78,
60,
82,
60,
70,
60,
86,
1055,
272,
971,
51,
755,
21682,
1263,
2222,
13,
8506,
4528,
27,
325,
5608,
14,
370,
359,
62,
971,
84,
60,
78,
60,
82,
60,
70,
60,
86,
1055,
272,
971,
87,
755,
21682,
1263,
27964,
4528,
27,
7353,
370,
359,
65,
13,
6353,
13,
58,
16,
13,
25,
63,
1055,
1467,
8777,
20639,
37,
12,
652,
911,
1336,
314,
663,
359,
16,
13,
25,
24601,
12254,
4110,
3247,
1467,
465,
14435,
367,
314,
1453,
5867,
14,
272,
971,
55,
755,
21682,
314,
2831,
434,
402,
971,
87,
14,
272,
8522,
755,
21682,
282,
8785,
13831,
14,
199,
199,
2765,
859,
22609,
314,
2569,
3423,
26,
272,
1336,
259,
9814,
282,
5578,
3965,
3851,
370,
314,
9608,
402,
282,
1059,
14,
272,
2754,
257,
8730,
282,
1059,
367,
314,
20024,
402,
282,
3851,
14,
272,
1007,
420,
4804,
25585,
22099,
402,
282,
3851,
1911,
315,
282,
1059,
14
] |
[
199,
3,
23580,
491,
2101,
7,
18528,
22013,
12580,
199,
3,
199,
3,
295,
13,
6490,
3217,
367,
314,
25877,
4877,
6869,
199,
3,
199,
3,
1898,
334,
67,
9,
19960,
13,
8339,
701,
23580,
491,
2101,
14840,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
1015,
402,
314,
26421,
3555,
883,
506,
295,
16832,
1334,
445,
46,
6129,
1159,
199,
3,
2018,
413,
14,
22,
4190,
14,
221,
2104,
1263,
1163,
675,
12,
8749,
8966,
23580,
491,
2101,
199,
3,
14840,
334,
815,
32,
1548,
1068,
14,
957,
680,
199,
3,
199,
3,
20825,
402,
642,
6869,
1172,
2757,
477,
27813,
315,
512,
5735,
543,
199,
3,
445,
46,
6129,
14,
221,
27849,
13,
29471,
2741,
27440,
316,
367,
413,
14,
22,
13150,
436,
199,
3,
1163,
7163,
1736,
14,
199,
3,
199,
199,
82,
624,
11532,
367,
5578,
8455,
334,
907,
680,
199,
199,
2765,
859,
6571,
5578,
3965,
4877,
5331,
8545,
370,
199,
273,
3362,
1911,
315,
3492,
76,
14,
221,
2779,
5171,
3865,
1695,
13,
2075,
436,
6140,
3326,
27,
3865,
199,
1589,
3851,
436,
314,
3326,
3769,
7686,
883,
1395,
2973,
2783,
436,
199,
16516,
9682,
314,
19635,
10485,
1425,
14,
199,
199,
16038,
8455,
883,
1395,
3865,
4539,
436,
24801,
4110,
14,
199,
24625,
24801,
4110,
12,
2839,
298,
33,
401,
298,
65,
401,
503,
298,
16,
401,
787,
314,
3486,
270,
199,
7898,
8455,
27,
2985,
9329,
1336,
17279,
14,
221,
2047,
883,
199,
13433,
24801,
4110,
12,
880,
2061,
4450,
314,
1059,
283,
2019,
1370,
199,
199,
1918,
4539,
4110,
787,
26,
272,
14530,
420,
21682,
1263,
4528,
871,
282,
8057,
14,
272,
18129,
2,
420,
21682,
314,
1343,
402,
314,
1059,
14,
272,
7880,
2,
420,
21682,
314,
1284,
402,
314,
1059,
503,
2951,
2544,
314,
8057,
737,
1467,
314,
1284,
402,
314,
1059,
14,
272,
22423,
420,
21682,
378,
503,
1655,
334,
71,
24737,
9,
6375,
7752,
402,
314,
22627,
5363,
14,
1467,
598,
24737,
4910,
626,
652,
911,
1336,
465,
5002,
6375,
7752,
465,
3962,
14,
272,
298,
5207,
420,
21682,
413,
503,
1655,
334,
71,
24737,
9,
6375,
7752,
402,
314,
22627,
5363,
14,
272,
29325,
420,
21682,
378,
503,
413,
334,
71,
24737,
9,
402,
314,
22627,
5363,
14,
272,
627,
22556,
11,
22556,
10674,
10172,
13,
71,
24737,
5459,
402,
314,
4136,
7795,
4539,
4110,
14,
272,
469,
77,
12,
78,
93,
259,
21682,
687,
333,
370,
302,
6375,
7752,
402,
314,
22627,
5363,
14,
272,
469,
77,
12,
78,
93,
31,
257,
10172,
13,
71,
24737,
1015,
402,
314,
3432,
14,
272,
9926,
2,
258,
13083,
24644,
4539,
4110,
503,
10166,
282,
4539,
3414,
14,
272,
942,
755,
19334,
282,
663,
402,
4110,
14,
1467,
437,
18129,
2,
465,
314,
1642,
4528,
9126,
282,
2831,
434,
316,
663,
14,
272,
15733,
2,
420,
437,
92,
34,
12,
8491,
376,
5363,
626,
911,
1336,
1902,
437,
503,
699,
14,
272,
30934,
259,
21682,
314,
5363,
6272,
314,
23592,
14,
1467,
710,
4072,
883,
506,
12396,
503,
7838,
2945,
315,
314,
1059,
14,
272,
7558,
73,
44,
706,
2521,
9,
2494,
314,
473,
12,
491,
12,
603,
12,
428,
12,
738,
12,
503,
1323,
3305,
367,
314,
5363,
334,
3239,
5084,
680,
272,
16697,
11965,
221,
10172,
13,
22390,
1015,
402,
5578,
23592,
14,
272,
7558,
48,
28,
354,
30,
11965,
710,
20597,
7838,
701,
314,
1572,
365,
17909,
701,
536,
14,
272,
7558,
48,
29,
354,
9,
258,
21682,
314,
1318,
7838,
14119,
701,
314,
1572,
4310,
536,
14,
272,
7558,
3,
11965,
221,
437,
3721,
27,
5525,
14,
272,
7558,
29,
11965,
221,
21682,
340,
2263,
4450,
2163,
12,
1325,
3181,
1133,
9451,
314,
1059,
14,
272,
7558,
1,
11965,
221,
21682,
340,
2263,
3181,
1133,
1336,
2163,
14,
272,
7558,
12932,
11965,
21682,
340,
9222,
770,
701,
2263,
334,
7790,
506,
6317,
2582,
680,
272,
7558,
11230,
11965,
21682,
340,
440,
9222,
770,
701,
2263,
334,
7790,
506,
6317,
2582,
680,
272,
7558,
8,
344,
15,
354,
9,
5066,
92,
889,
9,
21682,
9456,
3851,
340,
314,
1572,
543,
1305,
15,
354,
7838,
12,
2432,
314,
334,
4144,
9,
949,
3851,
4257,
14,
199,
199,
1918,
4539,
8013,
17568,
402,
9926,
2,
436,
282,
4528,
687,
314,
769,
199,
12843,
14,
221,
982,
314,
24801,
4528,
365,
440,
641,
314,
769,
12,
2066,
314,
199,
1099,
316,
5363,
911,
1336,
314,
3499,
4528,
14,
272,
971,
1955,
221,
21682,
314,
4072,
402,
314,
1572,
402,
314,
2011,
1329,
14,
272,
971,
33,
755,
21682,
1454,
737,
314,
1343,
402,
314,
1059,
14,
272,
971,
58,
755,
21682,
1454,
737,
314,
1284,
402,
314,
1059,
14,
272,
971,
66,
755,
21682,
314,
2701,
1059,
12,
1325,
1454,
737,
314,
1343,
503,
1284,
402,
282,
4349,
14,
272,
971,
34,
755,
21682,
314,
2701,
1059,
12,
1325,
440,
737,
314,
1343,
503,
1284,
402,
282,
4349,
14,
272,
971,
68,
755,
21682,
1263,
6107,
10964,
27,
7353,
370,
314,
663,
359,
16,
13,
25,
1055,
272,
971,
36,
755,
21682,
1263,
2222,
13,
8573,
4528,
27,
7353,
370,
314,
663,
359,
62,
16,
13,
25,
1055,
272,
971,
83,
755,
21682,
1263,
8139,
4528,
27,
7353,
370,
359,
971,
84,
60,
78,
60,
82,
60,
70,
60,
86,
1055,
272,
971,
51,
755,
21682,
1263,
2222,
13,
8506,
4528,
27,
325,
5608,
14,
370,
359,
62,
971,
84,
60,
78,
60,
82,
60,
70,
60,
86,
1055,
272,
971,
87,
755,
21682,
1263,
27964,
4528,
27,
7353,
370,
359,
65,
13,
6353,
13,
58,
16,
13,
25,
63,
1055,
1467,
8777,
20639,
37,
12,
652,
911,
1336,
314,
663,
359,
16,
13,
25,
24601,
12254,
4110,
3247,
1467,
465,
14435,
367,
314,
1453,
5867,
14,
272,
971,
55,
755,
21682,
314,
2831,
434,
402,
971,
87,
14,
272,
8522,
755,
21682,
282,
8785,
13831,
14,
199,
199,
2765,
859,
22609,
314,
2569,
3423,
26,
272,
1336,
259,
9814,
282,
5578,
3965,
3851,
370,
314,
9608,
402,
282,
1059,
14,
272,
2754,
257,
8730,
282,
1059,
367,
314,
20024,
402,
282,
3851,
14,
272,
1007,
420,
4804,
25585,
22099,
402,
282,
3851,
1911,
315,
282,
1059,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
aarchiba/numpy
|
numpy/linalg/tests/test_regression.py
|
78
|
3097
|
""" Test functions for linalg module
"""
from __future__ import division, absolute_import, print_function
import numpy as np
from numpy import linalg, arange, float64, array, dot, transpose
from numpy.testing import (
TestCase, run_module_suite, assert_equal, assert_array_equal,
assert_array_almost_equal, assert_array_less
)
rlevel = 1
class TestRegression(TestCase):
def test_eig_build(self, level=rlevel):
# Ticket #652
rva = array([1.03221168e+02 + 0.j,
-1.91843603e+01 + 0.j,
-6.04004526e-01 + 15.84422474j,
-6.04004526e-01 - 15.84422474j,
-1.13692929e+01 + 0.j,
-6.57612485e-01 + 10.41755503j,
-6.57612485e-01 - 10.41755503j,
1.82126812e+01 + 0.j,
1.06011014e+01 + 0.j,
7.80732773e+00 + 0.j,
-7.65390898e-01 + 0.j,
1.51971555e-15 + 0.j,
-1.51308713e-15 + 0.j])
a = arange(13 * 13, dtype=float64)
a.shape = (13, 13)
a = a % 17
va, ve = linalg.eig(a)
va.sort()
rva.sort()
assert_array_almost_equal(va, rva)
def test_eigh_build(self, level=rlevel):
# Ticket 662.
rvals = [68.60568999, 89.57756725, 106.67185574]
cov = array([[77.70273908, 3.51489954, 15.64602427],
[3.51489954, 88.97013878, -1.07431931],
[15.64602427, -1.07431931, 98.18223512]])
vals, vecs = linalg.eigh(cov)
assert_array_almost_equal(vals, rvals)
def test_svd_build(self, level=rlevel):
# Ticket 627.
a = array([[0., 1.], [1., 1.], [2., 1.], [3., 1.]])
m, n = a.shape
u, s, vh = linalg.svd(a)
b = dot(transpose(u[:, n:]), a)
assert_array_almost_equal(b, np.zeros((2, 2)))
def test_norm_vector_badarg(self):
# Regression for #786: Froebenius norm for vectors raises
# TypeError.
self.assertRaises(ValueError, linalg.norm, array([1., 2., 3.]), 'fro')
def test_lapack_endian(self):
# For bug #1482
a = array([[5.7998084, -2.1825367],
[-2.1825367, 9.85910595]], dtype='>f8')
b = array(a, dtype='<f8')
ap = linalg.cholesky(a)
bp = linalg.cholesky(b)
assert_array_equal(ap, bp)
def test_large_svd_32bit(self):
# See gh-4442, 64bit would require very large/slow matrices.
x = np.eye(1000, 66)
np.linalg.svd(x)
def test_svd_no_uv(self):
# gh-4733
for shape in (3, 4), (4, 4), (4, 3):
for t in float, complex:
a = np.ones(shape, dtype=t)
w = linalg.svd(a, compute_uv=False)
c = np.count_nonzero(np.absolute(w) > 0.5)
assert_equal(c, 1)
assert_equal(np.linalg.matrix_rank(a), 1)
assert_array_less(1, np.linalg.norm(a, ord=2))
if __name__ == '__main__':
run_module_suite()
|
bsd-3-clause
|
[
624,
1379,
3423,
367,
16727,
859,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
492,
16727,
12,
20461,
12,
2069,
772,
12,
1625,
12,
6308,
12,
16992,
199,
504,
2680,
14,
4776,
492,
334,
272,
7640,
12,
1255,
63,
578,
63,
5768,
12,
702,
63,
1452,
12,
702,
63,
1144,
63,
1452,
12,
272,
702,
63,
1144,
63,
4398,
63,
1452,
12,
702,
63,
1144,
63,
2003,
199,
9,
421,
199,
82,
1896,
275,
413,
421,
199,
533,
1379,
13013,
8,
1746,
304,
339,
347,
511,
63,
22129,
63,
1506,
8,
277,
12,
2166,
29,
82,
1896,
304,
267,
327,
21932,
327,
25415,
267,
519,
3042,
275,
1625,
779,
17,
14,
21683,
12832,
2333,
69,
11,
996,
435,
378,
14,
74,
12,
2151,
446,
17,
14,
25,
10078,
1344,
1644,
69,
11,
614,
435,
378,
14,
74,
12,
2151,
446,
22,
14,
27130,
2322,
1479,
69,
13,
614,
435,
4114,
14,
16042,
8731,
1342,
74,
12,
2151,
446,
22,
14,
27130,
2322,
1479,
69,
13,
614,
446,
4114,
14,
16042,
8731,
1342,
74,
12,
2151,
446,
17,
14,
969,
1876,
1398,
1398,
69,
11,
614,
435,
378,
14,
74,
12,
2151,
446,
22,
14,
12255,
713,
21956,
69,
13,
614,
435,
1616,
14,
25292,
1229,
15773,
74,
12,
2151,
446,
22,
14,
12255,
713,
21956,
69,
13,
614,
446,
1616,
14,
25292,
1229,
15773,
74,
12,
2151,
413,
14,
2564,
713,
2333,
713,
69,
11,
614,
435,
378,
14,
74,
12,
2151,
413,
14,
1690,
614,
4893,
20,
69,
11,
614,
435,
378,
14,
74,
12,
2151,
1520,
14,
11369,
708,
18507,
69,
11,
383,
435,
378,
14,
74,
12,
2151,
446,
23,
14,
2182,
12302,
13176,
69,
13,
614,
435,
378,
14,
74,
12,
2151,
413,
14,
21,
11165,
1046,
1229,
69,
13,
1046,
435,
378,
14,
74,
12,
2151,
446,
17,
14,
21,
9056,
1555,
969,
69,
13,
1046,
435,
378,
14,
74,
566,
267,
282,
275,
20461,
8,
969,
627,
4944,
12,
2152,
29,
1609,
772,
9,
267,
282,
14,
1392,
275,
334,
969,
12,
4944,
9,
267,
282,
275,
282,
450,
5557,
267,
25819,
12,
11199,
275,
16727,
14,
22129,
8,
65,
9,
267,
25819,
14,
3191,
342,
267,
519,
3042,
14,
3191,
342,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
3042,
12,
519,
3042,
9,
339,
347,
511,
63,
69,
2056,
63,
1506,
8,
277,
12,
2166,
29,
82,
1896,
304,
267,
327,
21932,
1227,
2789,
14,
267,
519,
3643,
275,
359,
2333,
14,
2259,
15085,
5637,
12,
17838,
14,
13539,
5308,
821,
12,
23746,
14,
1822,
1085,
1229,
1342,
61,
398,
13786,
275,
1625,
4038,
1138,
14,
23,
14218,
1355,
2036,
12,
257,
650,
14,
21,
10834,
1020,
1477,
12,
221,
4114,
14,
11387,
5284,
1465,
467,
2151,
359,
19,
14,
21,
10834,
1020,
1477,
12,
221,
10523,
14,
2576,
614,
12399,
24,
12,
221,
446,
17,
14,
16,
21712,
1167,
2192,
467,
2151,
359,
1046,
14,
11387,
5284,
1465,
12,
221,
446,
17,
14,
16,
21712,
1167,
2192,
12,
221,
16096,
14,
1085,
1081,
1276,
713,
3934,
398,
5322,
12,
10782,
83,
275,
16727,
14,
69,
2056,
8,
8695,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
3643,
12,
519,
3643,
9,
339,
347,
511,
63,
18675,
63,
1506,
8,
277,
12,
2166,
29,
82,
1896,
304,
267,
327,
21932,
1227,
1465,
14,
267,
282,
275,
1625,
4038,
16,
2020,
413,
8333,
359,
17,
2020,
413,
8333,
359,
18,
2020,
413,
8333,
359,
19,
2020,
413,
19450,
267,
333,
12,
302,
275,
282,
14,
1392,
267,
399,
12,
308,
12,
373,
72,
275,
16727,
14,
18675,
8,
65,
9,
398,
330,
275,
6308,
8,
10483,
8,
85,
3981,
302,
26,
2522,
282,
9,
398,
702,
63,
1144,
63,
4398,
63,
1452,
8,
66,
12,
980,
14,
4250,
1332,
18,
12,
499,
1724,
339,
347,
511,
63,
4791,
63,
4106,
63,
4087,
1273,
8,
277,
304,
267,
327,
13262,
367,
327,
23,
1184,
26,
481,
293,
2871,
30647,
527,
6316,
367,
11102,
6534,
267,
327,
3146,
14,
267,
291,
14,
1855,
8,
3393,
12,
16727,
14,
4791,
12,
1625,
779,
17,
2020,
499,
2020,
650,
14,
2522,
283,
21775,
358,
339,
347,
511,
63,
26760,
63,
15009,
8,
277,
304,
267,
327,
2104,
6519,
327,
1079,
2564,
267,
282,
275,
1625,
4038,
21,
14,
31486,
1257,
1349,
12,
221,
446,
18,
14,
1085,
821,
12684,
467,
673,
5243,
18,
14,
1085,
821,
12684,
12,
257,
1749,
14,
24,
1427,
709,
16447,
2365,
2152,
534,
30,
70,
24,
358,
267,
330,
275,
1625,
8,
65,
12,
2152,
15829,
70,
24,
358,
398,
2771,
275,
16727,
14,
31369,
8,
65,
9,
267,
13292,
275,
16727,
14,
31369,
8,
66,
9,
267,
702,
63,
1144,
63,
1452,
8,
439,
12,
13292,
9,
339,
347,
511,
63,
9629,
63,
18675,
63,
708,
2075,
8,
277,
304,
267,
327,
1666,
23310,
13,
1602,
2260,
12,
5049,
2075,
3955,
4409,
7437,
7031,
15,
14362,
12627,
14,
267,
671,
275,
980,
14,
15240,
8,
5279,
12,
14157,
9,
267,
980,
14,
10096,
14,
18675,
8,
88,
9,
339,
347,
511,
63,
18675,
63,
889,
63,
9154,
8,
277,
304,
267,
327,
23310,
13,
2417,
1153,
267,
367,
2215,
315,
334,
19,
12,
841,
395,
334,
20,
12,
841,
395,
334,
20,
12,
650,
304,
288,
367,
307,
315,
2069,
12,
6114,
26,
355,
282,
275,
980,
14,
4548,
8,
1392,
12,
2152,
29,
84,
9,
355,
336,
275,
16727,
14,
18675,
8,
65,
12,
4526,
63,
9154,
29,
797,
9,
355,
286,
275,
980,
14,
835,
63,
10262,
8,
1590,
14,
6116,
8,
87,
9,
690,
378,
14,
21,
9,
355,
702,
63,
1452,
8,
67,
12,
413,
9,
355,
702,
63,
1452,
8,
1590,
14,
10096,
14,
3642,
63,
4648,
8,
65,
395,
413,
9,
355,
702,
63,
1144,
63,
2003,
8,
17,
12,
980,
14,
10096,
14,
4791,
8,
65,
12,
6206,
29,
18,
430,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1255,
63,
578,
63,
5768,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1379,
3423,
367,
16727,
859,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
492,
16727,
12,
20461,
12,
2069,
772,
12,
1625,
12,
6308,
12,
16992,
199,
504,
2680,
14,
4776,
492,
334,
272,
7640,
12,
1255,
63,
578,
63,
5768,
12,
702,
63,
1452,
12,
702,
63,
1144,
63,
1452,
12,
272,
702,
63,
1144,
63,
4398,
63,
1452,
12,
702,
63,
1144,
63,
2003,
199,
9,
421,
199,
82,
1896,
275,
413,
421,
199,
533,
1379,
13013,
8,
1746,
304,
339,
347,
511,
63,
22129,
63,
1506,
8,
277,
12,
2166,
29,
82,
1896,
304,
267,
327,
21932,
327,
25415,
267,
519,
3042,
275,
1625,
779,
17,
14,
21683,
12832,
2333,
69,
11,
996,
435,
378,
14,
74,
12,
2151,
446,
17,
14,
25,
10078,
1344,
1644,
69,
11,
614,
435,
378,
14,
74,
12,
2151,
446,
22,
14,
27130,
2322,
1479,
69,
13,
614,
435,
4114,
14,
16042,
8731,
1342,
74,
12,
2151,
446,
22,
14,
27130,
2322,
1479,
69,
13,
614,
446,
4114,
14,
16042,
8731,
1342,
74,
12,
2151,
446,
17,
14,
969,
1876,
1398,
1398,
69,
11,
614,
435,
378,
14,
74,
12,
2151,
446,
22,
14,
12255,
713,
21956,
69,
13,
614,
435,
1616,
14,
25292,
1229,
15773,
74,
12,
2151,
446,
22,
14,
12255,
713,
21956,
69,
13,
614,
446,
1616,
14,
25292,
1229,
15773,
74,
12,
2151,
413,
14,
2564,
713,
2333,
713,
69,
11,
614,
435,
378,
14,
74,
12,
2151,
413,
14,
1690,
614,
4893,
20,
69,
11,
614,
435,
378,
14,
74,
12,
2151,
1520,
14,
11369,
708,
18507,
69,
11,
383,
435,
378,
14,
74,
12,
2151,
446,
23,
14,
2182,
12302,
13176,
69,
13,
614,
435,
378,
14,
74,
12,
2151,
413,
14,
21,
11165,
1046,
1229,
69,
13,
1046,
435,
378,
14,
74,
12,
2151,
446,
17,
14,
21,
9056,
1555,
969,
69,
13,
1046,
435,
378,
14,
74,
566,
267,
282,
275,
20461,
8,
969,
627,
4944,
12,
2152,
29,
1609,
772,
9,
267,
282,
14,
1392,
275,
334,
969,
12,
4944,
9,
267,
282,
275,
282,
450,
5557,
267,
25819,
12,
11199,
275,
16727,
14,
22129,
8,
65,
9,
267,
25819,
14,
3191,
342,
267,
519,
3042,
14,
3191,
342,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
3042,
12,
519,
3042,
9,
339,
347,
511,
63,
69,
2056,
63,
1506,
8,
277,
12,
2166,
29,
82,
1896,
304,
267,
327,
21932,
1227,
2789,
14,
267,
519,
3643,
275,
359,
2333,
14,
2259,
15085,
5637,
12,
17838,
14,
13539,
5308,
821,
12,
23746,
14,
1822,
1085,
1229,
1342,
61,
398,
13786,
275,
1625,
4038,
1138,
14,
23,
14218,
1355,
2036,
12,
257,
650,
14,
21,
10834,
1020,
1477,
12,
221,
4114,
14,
11387,
5284,
1465,
467,
2151,
359,
19,
14,
21,
10834,
1020,
1477,
12,
221,
10523,
14,
2576,
614,
12399,
24,
12,
221,
446,
17,
14,
16,
21712,
1167,
2192,
467,
2151,
359,
1046,
14,
11387,
5284,
1465,
12,
221,
446,
17,
14,
16,
21712,
1167,
2192,
12,
221,
16096,
14,
1085,
1081,
1276,
713,
3934,
398,
5322,
12,
10782,
83,
275,
16727,
14,
69,
2056,
8,
8695,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
3643,
12,
519,
3643,
9,
339,
347,
511,
63,
18675,
63,
1506,
8,
277,
12,
2166,
29,
82,
1896,
304,
267,
327,
21932,
1227,
1465,
14,
267,
282,
275,
1625,
4038,
16,
2020,
413,
8333,
359,
17,
2020,
413,
8333,
359,
18,
2020,
413,
8333,
359,
19,
2020,
413,
19450,
267,
333,
12,
302,
275,
282,
14,
1392,
267,
399,
12,
308,
12,
373,
72,
275,
16727,
14,
18675,
8,
65,
9,
398,
330,
275,
6308,
8,
10483,
8,
85,
3981,
302,
26,
2522,
282,
9,
398,
702,
63,
1144,
63,
4398,
63,
1452,
8,
66,
12,
980,
14,
4250,
1332,
18,
12,
499,
1724,
339,
347,
511,
63,
4791,
63,
4106,
63,
4087,
1273,
8,
277,
304,
267,
327,
13262,
367,
327,
23,
1184,
26,
481,
293,
2871,
30647,
527,
6316,
367,
11102,
6534,
267,
327,
3146,
14,
267,
291,
14,
1855,
8,
3393,
12,
16727,
14,
4791,
12,
1625,
779,
17,
2020,
499,
2020,
650,
14,
2522,
283,
21775,
358,
339,
347,
511,
63,
26760,
63,
15009,
8,
277,
304,
267,
327,
2104,
6519,
327,
1079,
2564,
267,
282,
275,
1625,
4038,
21,
14,
31486,
1257,
1349,
12,
221,
446,
18,
14,
1085,
821,
12684,
467,
673,
5243,
18,
14,
1085,
821,
12684,
12,
257,
1749,
14,
24,
1427,
709,
16447,
2365,
2152,
534,
30,
70,
24,
358,
267,
330,
275,
1625,
8,
65,
12,
2152,
15829,
70,
24,
358,
398,
2771,
275,
16727,
14,
31369,
8,
65,
9,
267,
13292,
275,
16727,
14,
31369,
8,
66,
9,
267,
702,
63,
1144,
63,
1452,
8,
439,
12,
13292,
9,
339,
347,
511,
63,
9629,
63,
18675,
63,
708,
2075,
8,
277,
304,
267,
327,
1666,
23310,
13,
1602,
2260,
12,
5049,
2075,
3955,
4409,
7437,
7031,
15,
14362,
12627,
14,
267,
671,
275,
980,
14,
15240,
8,
5279,
12,
14157,
9,
267,
980,
14,
10096,
14,
18675,
8,
88,
9,
339,
347,
511,
63,
18675,
63,
889,
63,
9154,
8,
277,
304,
267,
327,
23310,
13,
2417,
1153,
267,
367,
2215,
315,
334,
19,
12,
841,
395,
334,
20,
12,
841,
395,
334,
20,
12,
650,
304,
288,
367,
307,
315,
2069,
12,
6114,
26,
355,
282,
275,
980,
14,
4548,
8,
1392,
12,
2152,
29,
84,
9,
355,
336,
275,
16727,
14,
18675,
8,
65,
12,
4526,
63,
9154,
29,
797,
9,
355,
286,
275,
980,
14,
835,
63,
10262,
8,
1590,
14,
6116,
8,
87,
9,
690,
378,
14,
21,
9,
355,
702,
63,
1452,
8,
67,
12,
413,
9,
355,
702,
63,
1452,
8,
1590,
14,
10096,
14,
3642,
63,
4648,
8,
65,
395,
413,
9,
355,
702,
63,
1144,
63,
2003,
8,
17,
12,
980,
14,
10096,
14,
4791,
8,
65,
12,
6206,
29,
18,
430,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1255,
63,
578,
63,
5768,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0
] |
toomuchcookies/pgu
|
examples/tilevid5.py
|
13
|
7123
|
"""<title>tutorial on how to add Sprite collision hit handlers, custom painting</title>"""
import pygame
from pygame.rect import Rect
from pygame.locals import *
import math
import random
# the following line is not needed if pgu is installed
import sys; sys.path.insert(0, "..")
from pgu import tilevid, timer
SW,SH = 320,240
TW,TH = 16,16
SPEED = 2
FPS = 40
def player_new(g,t,value):
g.clayer[t.ty][t.tx] = 0
s = tilevid.Sprite(g.images['player'],t.rect)
g.sprites.append(s)
s.loop = player_loop
s.groups = g.string2groups('player')
s.score = 0
g.player = s
##In player_new() I add the shoot handler.
##::
s.shoot = player_shoot
##
def player_loop(g,s):
if s.rect.right < g.view.left: g.quit = 1
s.rect.x += SPEED
keys = pygame.key.get_pressed()
dx,dy = 0,0
if keys[K_UP]: dy-=1
if keys[K_DOWN]: dy+=1
if keys[K_LEFT]: dx-=1
if keys[K_RIGHT]: dx+=1
s.rect.x += dx*5
s.rect.y += dy*5
s.rect.clamp_ip(g.view)
##In player_loop(), I check for the spacebar. The spacebar triggers a shot every 8 frames.
##::
if keys[K_SPACE] and g.frame%8==0:
shot_new(g,s,None)
##
##The player_shoot() handler, as well as the shot Sprite functions. The shot group
##has its agroup set to 'enemy' so it can hit 'enemy' Sprites.
##::
def player_shoot(g,s):
shot_new(g,s,None)
def shot_new(g,t,value):
s = tilevid.Sprite(g.images['shot'],(t.rect.right,t.rect.centery-2))
g.sprites.append(s)
s.agroups = g.string2groups('enemy')
s.hit = shot_hit
s.loop = shot_loop
def shot_loop(g,s):
s.rect.x += 8
if s.rect.left > g.view.right:
g.sprites.remove(s)
##
def shot_hit(g,s,a):
if a in g.sprites: g.sprites.remove(a)
g.player.score += 500
def enemy_new(g,t,value):
g.clayer[t.ty][t.tx] = 0
s = tilevid.Sprite(g.images['enemy'],t.rect)
g.sprites.append(s)
s.loop = enemy_loop
##In enemy_new(), I've added a lot more detail.
##- A move function to handle the type of movement the enemy will do.
##- A record of the origin and entering frame of the enemy (useful for the move functions.)
##- Set up the groups and agroups and a hit handler for the enemy.
##::
s.move = value['move']
s.origin = pygame.Rect(s.rect)
s.frame = g.frame
s.groups = g.string2groups('enemy')
s.agroups = g.string2groups('player')
s.hit = enemy_hit
##
##When an enemy is hit, the game quits.
##::
def enemy_hit(g,s,a):
g.quit = 1
##
def enemy_loop(g,s):
##In enemy_loop() we call the move handler.
##::
s.move(g,s)
##
if s.rect.right < g.view.left:
g.sprites.remove(s)
##The enemy movement handlers.
##::
def enemy_move_line(g,s):
s.rect.x -= 3
def enemy_move_sine(g,s):
s.rect.x -= 2
s.rect.y = s.origin.y + 65*math.sin((g.frame-s.frame)/10.0)
def enemy_move_circle(g,s):
s.origin.x -= 1
s.rect.y = s.origin.y + 50*math.sin((g.frame-s.frame)/10.0)
s.rect.x = s.origin.x + 50*math.cos((g.frame-s.frame)/10.0)
##
def tile_block(g,t,a):
c = t.config
if (c['top'] == 1 and a._rect.bottom <= t._rect.top and a.rect.bottom > t.rect.top):
a.rect.bottom = t.rect.top
if (c['left'] == 1 and a._rect.right <= t._rect.left and a.rect.right > t.rect.left):
a.rect.right = t.rect.left
if (c['right'] == 1 and a._rect.left >= t._rect.right and a.rect.left < t.rect.right):
a.rect.left = t.rect.right
if (c['bottom'] == 1 and a._rect.top >= t._rect.bottom and a.rect.top < t.rect.bottom):
a.rect.top = t.rect.bottom
def tile_coin(g,t,a):
a.score += 100
g.set((t.tx,t.ty),0)
def tile_fire(g,t,a):
g.quit = 1
##
idata = [
('player','player.tga',(4,4,24,24)),
('enemy','enemy.tga',(4,4,24,24)),
('shot','shot.tga',(1,2,6,4)),
]
##The codes data has been updated to include information about the appropriate
##movement handlers for enemies.
##::
cdata = {
1:(player_new,None),
2:(enemy_new,{'move':enemy_move_line}),
3:(enemy_new,{'move':enemy_move_sine}),
4:(enemy_new,{'move':enemy_move_circle}),
}
##
tdata = {
0x01:('player',tile_block,{'top':1,'bottom':1,'left':1,'right':1}),
0x02:('player',tile_block,{'top':1,'bottom':1,'left':1,'right':1}),
0x20:('player',tile_coin,None),
0x30:('player',tile_fire,None),
}
def init():
g = tilevid.Tilevid()
##In init(), set the g.view size so that all the handlers will work properly. (The player_loop one depends on view having the correct size.)
##::
g.view.w,g.view.h = SW,SH
##
g.screen = pygame.display.set_mode((SW,SH),SWSURFACE)
g.frame = 0
g.tga_load_tiles('tiles.tga',(TW,TH),tdata)
##In init() I no longer have tga_load_level load the background layer, as
##we will generate our own multi-layered starfield.
##::
g.tga_load_level('level.tga')
##
g.bounds = pygame.Rect(TW,TH,(len(g.tlayer[0])-2)*TW,(len(g.tlayer)-2)*TH)
g.load_images(idata)
g.run_codes(cdata,(0,0,25,17))
pygame.font.init()
g.font = pygame.font.SysFont('helvetica',16)
return g
def run(g):
g.quit = 0
##In run(), adding a pause variable to the game.
##::
g.pause = 0
##
t = timer.Timer(FPS)
##In run(), initializing the stars.
##::
stars = []
NS = 256
for n in range(0,NS):
stars.append([random.randrange(0,SW),random.randrange(0,SH),random.randrange(2,8)])
##
while not g.quit:
for e in pygame.event.get():
if e.type is QUIT: g.quit = 1
if e.type is KEYDOWN and e.key == K_ESCAPE: g.quit = 1
##In run(), in the event loop, checking for F10 for full screen, RETURN for pause.
##::
if e.type is KEYDOWN and e.key == K_F10:
#g.screen = pygame.display.set_mode((SW,SH),FULLSCREEN|HWSURFACE|DOUBLEBUF)
pygame.display.toggle_fullscreen()
if e.type is KEYDOWN and e.key == K_RETURN:
g.pause ^= 1
##
##In run(), handles pause, and also renders the star field before the
##foreground is painted.
##::
if not g.pause:
g.view.x += SPEED
g.run_codes(cdata,(g.view.right/TW,0,1,17))
g.loop()
g.screen.fill((0,0,0))
n = 0
for n in range(0,NS):
x,y,s = stars[n]
if ((g.frame*s)%8) < s:
x -= 1
if x < 0: x += SW
stars[n][0] = x
g.screen.set_at((x,y),(255,255,255))
g.paint(g.screen)
img = g.font.render('%05d'%g.player.score,1,(0,0,0))
g.screen.blit(img,(0+1,SH-img.get_height()+1))
img = g.font.render('%05d'%g.player.score,1,(255,255,255))
g.screen.blit(img,(0,SH-img.get_height()))
pygame.display.flip()
g.frame += 1
##
t.tick()
run(init())
|
lgpl-2.1
|
[
624,
28,
1213,
30,
23561,
641,
4212,
370,
1050,
8360,
752,
25061,
9793,
8297,
12,
3537,
32055,
316,
1108,
1213,
11193,
199,
199,
646,
9193,
199,
504,
9193,
14,
1201,
492,
21536,
199,
504,
9193,
14,
9350,
492,
627,
199,
646,
3473,
199,
646,
2196,
199,
199,
3,
314,
2569,
1004,
365,
440,
4346,
340,
299,
6051,
365,
4903,
199,
646,
984,
27,
984,
14,
515,
14,
3176,
8,
16,
12,
21777,
531,
199,
199,
504,
299,
6051,
492,
12835,
5017,
12,
9715,
199,
199,
8745,
12,
3234,
275,
25611,
12,
9873,
199,
16491,
12,
2080,
275,
3193,
12,
975,
199,
29110,
275,
499,
199,
38,
5067,
275,
6335,
199,
199,
318,
7748,
63,
1222,
8,
71,
12,
84,
12,
585,
304,
272,
486,
14,
67,
1897,
59,
84,
14,
369,
1527,
84,
14,
2347,
61,
275,
378,
272,
308,
275,
12835,
5017,
14,
30185,
8,
71,
14,
4782,
459,
6147,
995,
84,
14,
1201,
9,
272,
486,
14,
27495,
14,
740,
8,
83,
9,
272,
308,
14,
3813,
275,
7748,
63,
3813,
272,
308,
14,
2634,
275,
486,
14,
875,
18,
2634,
360,
6147,
358,
272,
308,
14,
3397,
275,
378,
272,
486,
14,
6147,
275,
308,
272,
925,
607,
7748,
63,
1222,
342,
473,
1050,
314,
930,
357,
3016,
14,
272,
925,
447,
272,
308,
14,
13927,
357,
275,
7748,
63,
13927,
357,
272,
925,
199,
199,
318,
7748,
63,
3813,
8,
71,
12,
83,
304,
272,
340,
308,
14,
1201,
14,
1019,
665,
486,
14,
1345,
14,
3039,
26,
486,
14,
10589,
275,
413,
2286,
308,
14,
1201,
14,
88,
847,
428,
1510,
1149,
2286,
2883,
275,
9193,
14,
498,
14,
362,
63,
30455,
342,
272,
11868,
12,
8161,
275,
378,
12,
16,
272,
340,
2883,
59,
43,
63,
2160,
2189,
13119,
13,
29,
17,
272,
340,
2883,
59,
43,
63,
8819,
2189,
13119,
10365,
17,
272,
340,
2883,
59,
43,
63,
9894,
2189,
11868,
13,
29,
17,
272,
340,
2883,
59,
43,
63,
12811,
2189,
11868,
10365,
17,
272,
308,
14,
1201,
14,
88,
847,
11868,
10,
21,
272,
308,
14,
1201,
14,
89,
847,
13119,
10,
21,
272,
308,
14,
1201,
14,
3995,
311,
63,
711,
8,
71,
14,
1345,
9,
2286,
925,
607,
7748,
63,
3813,
1062,
473,
1104,
367,
314,
4601,
1700,
14,
221,
710,
4601,
1700,
18899,
282,
1033,
357,
4036,
1695,
11223,
14,
272,
925,
447,
272,
340,
2883,
59,
43,
63,
11658,
61,
436,
486,
14,
1943,
5,
24,
389,
16,
26,
267,
1033,
357,
63,
1222,
8,
71,
12,
83,
12,
403,
9,
272,
925,
199,
199,
309,
1918,
7748,
63,
13927,
357,
342,
3016,
12,
465,
5521,
465,
314,
1033,
357,
8360,
752,
3423,
14,
221,
710,
1033,
357,
1572,
199,
309,
1989,
2399,
282,
923,
663,
370,
283,
6349,
1662,
7,
880,
652,
883,
9793,
283,
6349,
1662,
7,
428,
21483,
14,
199,
309,
447,
199,
318,
7748,
63,
13927,
357,
8,
71,
12,
83,
304,
272,
1033,
357,
63,
1222,
8,
71,
12,
83,
12,
403,
9,
1362,
199,
318,
1033,
357,
63,
1222,
8,
71,
12,
84,
12,
585,
304,
272,
308,
275,
12835,
5017,
14,
30185,
8,
71,
14,
4782,
459,
2782,
995,
8,
84,
14,
1201,
14,
1019,
12,
84,
14,
1201,
14,
4218,
89,
13,
18,
430,
272,
486,
14,
27495,
14,
740,
8,
83,
9,
272,
308,
14,
643,
684,
83,
275,
486,
14,
875,
18,
2634,
360,
6349,
1662,
358,
272,
308,
14,
12948,
275,
1033,
357,
63,
12948,
272,
308,
14,
3813,
275,
1033,
357,
63,
3813,
199,
199,
318,
1033,
357,
63,
3813,
8,
71,
12,
83,
304,
272,
308,
14,
1201,
14,
88,
847,
1695,
272,
340,
308,
14,
1201,
14,
3039,
690,
486,
14,
1345,
14,
1019,
26,
267,
486,
14,
27495,
14,
2168,
8,
83,
9,
199,
309,
258,
268,
199,
318,
1033,
357,
63,
12948,
8,
71,
12,
83,
12,
65,
304,
272,
340,
282,
315,
486,
14,
27495,
26,
486,
14,
27495,
14,
2168,
8,
65,
9,
272,
486,
14,
6147,
14,
3397,
847,
6891,
13359,
199,
318,
655,
69,
1662,
63,
1222,
8,
71,
12,
84,
12,
585,
304,
272,
486,
14,
67,
1897,
59,
84,
14,
369,
1527,
84,
14,
2347,
61,
275,
378,
272,
308,
275,
12835,
5017,
14,
30185,
8,
71,
14,
4782,
459,
6349,
1662,
995,
84,
14,
1201,
9,
272,
486,
14,
27495,
14,
740,
8,
83,
9,
272,
308,
14,
3813,
275,
655,
69,
1662,
63,
3813,
199,
309,
607,
655,
69,
1662,
63,
1222,
1062,
473,
9064,
3483,
282,
13918,
1655,
10093,
14,
199,
309,
13,
437,
4057,
805,
370,
2429,
314,
730,
402,
4057,
434,
314,
655,
69,
1662,
911,
886,
14,
199,
309,
13,
437,
2777,
402,
314,
6330,
436,
9509,
316,
2787,
402,
314,
655,
69,
1662,
334,
1180,
1893,
367,
314,
4057,
3423,
4959,
199,
309,
13,
2494,
1536,
314,
4652,
436,
282,
2634,
436,
282,
9793,
3016,
367,
314,
655,
69,
1662,
14,
199,
309,
447,
272,
308,
14,
1185,
275,
574,
459,
1185,
418,
272,
308,
14,
6493,
275,
9193,
14,
8252,
8,
83,
14,
1201,
9,
272,
308,
14,
1943,
275,
486,
14,
1943,
272,
308,
14,
2634,
275,
486,
14,
875,
18,
2634,
360,
6349,
1662,
358,
272,
308,
14,
643,
684,
83,
275,
486,
14,
875,
18,
2634,
360,
6147,
358,
272,
308,
14,
12948,
275,
655,
69,
1662,
63,
12948,
199,
309,
199,
199,
309,
11423,
376,
655,
69,
1662,
365,
9793,
12,
314,
9219,
2173,
1405,
14,
199,
309,
447,
199,
318,
655,
69,
1662,
63,
12948,
8,
71,
12,
83,
12,
65,
304,
272,
486,
14,
10589,
275,
413,
199,
309,
199,
199,
318,
655,
69,
1662,
63,
3813,
8,
71,
12,
83,
304,
272,
925,
607,
655,
69,
1662,
63,
3813,
342,
781,
1240,
314,
4057,
3016,
14,
272,
925,
447,
272,
308,
14,
1185,
8,
71,
12,
83,
9,
272,
925,
272,
340,
308,
14,
1201,
14,
1019,
665,
486,
14,
1345,
14,
3039,
26,
267,
486,
14,
27495,
14,
2168,
8,
83,
9,
199,
199,
309,
1918,
655,
69,
1662,
4057,
434,
8297,
14,
199,
309,
447,
199,
318,
655,
69,
1662,
63,
1185
] |
[
28,
1213,
30,
23561,
641,
4212,
370,
1050,
8360,
752,
25061,
9793,
8297,
12,
3537,
32055,
316,
1108,
1213,
11193,
199,
199,
646,
9193,
199,
504,
9193,
14,
1201,
492,
21536,
199,
504,
9193,
14,
9350,
492,
627,
199,
646,
3473,
199,
646,
2196,
199,
199,
3,
314,
2569,
1004,
365,
440,
4346,
340,
299,
6051,
365,
4903,
199,
646,
984,
27,
984,
14,
515,
14,
3176,
8,
16,
12,
21777,
531,
199,
199,
504,
299,
6051,
492,
12835,
5017,
12,
9715,
199,
199,
8745,
12,
3234,
275,
25611,
12,
9873,
199,
16491,
12,
2080,
275,
3193,
12,
975,
199,
29110,
275,
499,
199,
38,
5067,
275,
6335,
199,
199,
318,
7748,
63,
1222,
8,
71,
12,
84,
12,
585,
304,
272,
486,
14,
67,
1897,
59,
84,
14,
369,
1527,
84,
14,
2347,
61,
275,
378,
272,
308,
275,
12835,
5017,
14,
30185,
8,
71,
14,
4782,
459,
6147,
995,
84,
14,
1201,
9,
272,
486,
14,
27495,
14,
740,
8,
83,
9,
272,
308,
14,
3813,
275,
7748,
63,
3813,
272,
308,
14,
2634,
275,
486,
14,
875,
18,
2634,
360,
6147,
358,
272,
308,
14,
3397,
275,
378,
272,
486,
14,
6147,
275,
308,
272,
925,
607,
7748,
63,
1222,
342,
473,
1050,
314,
930,
357,
3016,
14,
272,
925,
447,
272,
308,
14,
13927,
357,
275,
7748,
63,
13927,
357,
272,
925,
199,
199,
318,
7748,
63,
3813,
8,
71,
12,
83,
304,
272,
340,
308,
14,
1201,
14,
1019,
665,
486,
14,
1345,
14,
3039,
26,
486,
14,
10589,
275,
413,
2286,
308,
14,
1201,
14,
88,
847,
428,
1510,
1149,
2286,
2883,
275,
9193,
14,
498,
14,
362,
63,
30455,
342,
272,
11868,
12,
8161,
275,
378,
12,
16,
272,
340,
2883,
59,
43,
63,
2160,
2189,
13119,
13,
29,
17,
272,
340,
2883,
59,
43,
63,
8819,
2189,
13119,
10365,
17,
272,
340,
2883,
59,
43,
63,
9894,
2189,
11868,
13,
29,
17,
272,
340,
2883,
59,
43,
63,
12811,
2189,
11868,
10365,
17,
272,
308,
14,
1201,
14,
88,
847,
11868,
10,
21,
272,
308,
14,
1201,
14,
89,
847,
13119,
10,
21,
272,
308,
14,
1201,
14,
3995,
311,
63,
711,
8,
71,
14,
1345,
9,
2286,
925,
607,
7748,
63,
3813,
1062,
473,
1104,
367,
314,
4601,
1700,
14,
221,
710,
4601,
1700,
18899,
282,
1033,
357,
4036,
1695,
11223,
14,
272,
925,
447,
272,
340,
2883,
59,
43,
63,
11658,
61,
436,
486,
14,
1943,
5,
24,
389,
16,
26,
267,
1033,
357,
63,
1222,
8,
71,
12,
83,
12,
403,
9,
272,
925,
199,
199,
309,
1918,
7748,
63,
13927,
357,
342,
3016,
12,
465,
5521,
465,
314,
1033,
357,
8360,
752,
3423,
14,
221,
710,
1033,
357,
1572,
199,
309,
1989,
2399,
282,
923,
663,
370,
283,
6349,
1662,
7,
880,
652,
883,
9793,
283,
6349,
1662,
7,
428,
21483,
14,
199,
309,
447,
199,
318,
7748,
63,
13927,
357,
8,
71,
12,
83,
304,
272,
1033,
357,
63,
1222,
8,
71,
12,
83,
12,
403,
9,
1362,
199,
318,
1033,
357,
63,
1222,
8,
71,
12,
84,
12,
585,
304,
272,
308,
275,
12835,
5017,
14,
30185,
8,
71,
14,
4782,
459,
2782,
995,
8,
84,
14,
1201,
14,
1019,
12,
84,
14,
1201,
14,
4218,
89,
13,
18,
430,
272,
486,
14,
27495,
14,
740,
8,
83,
9,
272,
308,
14,
643,
684,
83,
275,
486,
14,
875,
18,
2634,
360,
6349,
1662,
358,
272,
308,
14,
12948,
275,
1033,
357,
63,
12948,
272,
308,
14,
3813,
275,
1033,
357,
63,
3813,
199,
199,
318,
1033,
357,
63,
3813,
8,
71,
12,
83,
304,
272,
308,
14,
1201,
14,
88,
847,
1695,
272,
340,
308,
14,
1201,
14,
3039,
690,
486,
14,
1345,
14,
1019,
26,
267,
486,
14,
27495,
14,
2168,
8,
83,
9,
199,
309,
258,
268,
199,
318,
1033,
357,
63,
12948,
8,
71,
12,
83,
12,
65,
304,
272,
340,
282,
315,
486,
14,
27495,
26,
486,
14,
27495,
14,
2168,
8,
65,
9,
272,
486,
14,
6147,
14,
3397,
847,
6891,
13359,
199,
318,
655,
69,
1662,
63,
1222,
8,
71,
12,
84,
12,
585,
304,
272,
486,
14,
67,
1897,
59,
84,
14,
369,
1527,
84,
14,
2347,
61,
275,
378,
272,
308,
275,
12835,
5017,
14,
30185,
8,
71,
14,
4782,
459,
6349,
1662,
995,
84,
14,
1201,
9,
272,
486,
14,
27495,
14,
740,
8,
83,
9,
272,
308,
14,
3813,
275,
655,
69,
1662,
63,
3813,
199,
309,
607,
655,
69,
1662,
63,
1222,
1062,
473,
9064,
3483,
282,
13918,
1655,
10093,
14,
199,
309,
13,
437,
4057,
805,
370,
2429,
314,
730,
402,
4057,
434,
314,
655,
69,
1662,
911,
886,
14,
199,
309,
13,
437,
2777,
402,
314,
6330,
436,
9509,
316,
2787,
402,
314,
655,
69,
1662,
334,
1180,
1893,
367,
314,
4057,
3423,
4959,
199,
309,
13,
2494,
1536,
314,
4652,
436,
282,
2634,
436,
282,
9793,
3016,
367,
314,
655,
69,
1662,
14,
199,
309,
447,
272,
308,
14,
1185,
275,
574,
459,
1185,
418,
272,
308,
14,
6493,
275,
9193,
14,
8252,
8,
83,
14,
1201,
9,
272,
308,
14,
1943,
275,
486,
14,
1943,
272,
308,
14,
2634,
275,
486,
14,
875,
18,
2634,
360,
6349,
1662,
358,
272,
308,
14,
643,
684,
83,
275,
486,
14,
875,
18,
2634,
360,
6147,
358,
272,
308,
14,
12948,
275,
655,
69,
1662,
63,
12948,
199,
309,
199,
199,
309,
11423,
376,
655,
69,
1662,
365,
9793,
12,
314,
9219,
2173,
1405,
14,
199,
309,
447,
199,
318,
655,
69,
1662,
63,
12948,
8,
71,
12,
83,
12,
65,
304,
272,
486,
14,
10589,
275,
413,
199,
309,
199,
199,
318,
655,
69,
1662,
63,
3813,
8,
71,
12,
83,
304,
272,
925,
607,
655,
69,
1662,
63,
3813,
342,
781,
1240,
314,
4057,
3016,
14,
272,
925,
447,
272,
308,
14,
1185,
8,
71,
12,
83,
9,
272,
925,
272,
340,
308,
14,
1201,
14,
1019,
665,
486,
14,
1345,
14,
3039,
26,
267,
486,
14,
27495,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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
priomsrb/vimswitch
|
vimswitch/UpdateProfileAction.py
|
1
|
1247
|
from .Action import Action
from .Settings import getSettings
from .SwitchProfileAction import createSwitchProfileAction
class UpdateProfileAction(Action):
def __init__(self, settings, switchProfileAction):
Action.__init__(self)
self.settings = settings
self.switchProfileAction = switchProfileAction
self.profile = None
def execute(self):
self.profile = self._getProfile()
if self.profile == self.settings.defaultProfile:
print('Cannot update default profile')
self.exitCode = -1
return
self.switchProfileAction.update = True
self.switchProfileAction.profile = self.profile
self.switchProfileAction.execute()
def _getProfile(self):
if self.profile is None:
if self.settings.currentProfile is None:
return self.settings.defaultProfile
else:
return self.settings.currentProfile
else:
return self.profile
def createUpdateProfileAction(app):
settings = getSettings(app)
switchProfileAction = createSwitchProfileAction(app)
updateProfileAction = UpdateProfileAction(settings, switchProfileAction)
return updateProfileAction
|
gpl-2.0
|
[
504,
1275,
3310,
492,
10033,
199,
504,
1275,
5268,
492,
664,
5268,
199,
504,
1275,
10167,
5736,
3310,
492,
1218,
10167,
5736,
3310,
421,
199,
533,
6162,
5736,
3310,
8,
3310,
304,
272,
347,
636,
826,
721,
277,
12,
2202,
12,
6258,
5736,
3310,
304,
267,
10033,
855,
826,
721,
277,
9,
267,
291,
14,
1751,
275,
2202,
267,
291,
14,
5656,
5736,
3310,
275,
6258,
5736,
3310,
267,
291,
14,
2913,
275,
488,
339,
347,
5341,
8,
277,
304,
267,
291,
14,
2913,
275,
291,
423,
362,
5736,
342,
398,
340,
291,
14,
2913,
508,
291,
14,
1751,
14,
885,
5736,
26,
288,
870,
360,
6612,
1678,
849,
4690,
358,
288,
291,
14,
2224,
3034,
275,
446,
17,
288,
372,
398,
291,
14,
5656,
5736,
3310,
14,
873,
275,
715,
267,
291,
14,
5656,
5736,
3310,
14,
2913,
275,
291,
14,
2913,
267,
291,
14,
5656,
5736,
3310,
14,
2526,
342,
339,
347,
485,
362,
5736,
8,
277,
304,
267,
340,
291,
14,
2913,
365,
488,
26,
288,
340,
291,
14,
1751,
14,
1818,
5736,
365,
488,
26,
355,
372,
291,
14,
1751,
14,
885,
5736,
288,
587,
26,
355,
372,
291,
14,
1751,
14,
1818,
5736,
267,
587,
26,
288,
372,
291,
14,
2913,
421,
199,
318,
1218,
4152,
5736,
3310,
8,
571,
304,
272,
2202,
275,
664,
5268,
8,
571,
9,
272,
6258,
5736,
3310,
275,
1218,
10167,
5736,
3310,
8,
571,
9,
272,
1678,
5736,
3310,
275,
6162,
5736,
3310,
8,
1751,
12,
6258,
5736,
3310,
9,
272,
372,
1678,
5736,
3310,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1275,
3310,
492,
10033,
199,
504,
1275,
5268,
492,
664,
5268,
199,
504,
1275,
10167,
5736,
3310,
492,
1218,
10167,
5736,
3310,
421,
199,
533,
6162,
5736,
3310,
8,
3310,
304,
272,
347,
636,
826,
721,
277,
12,
2202,
12,
6258,
5736,
3310,
304,
267,
10033,
855,
826,
721,
277,
9,
267,
291,
14,
1751,
275,
2202,
267,
291,
14,
5656,
5736,
3310,
275,
6258,
5736,
3310,
267,
291,
14,
2913,
275,
488,
339,
347,
5341,
8,
277,
304,
267,
291,
14,
2913,
275,
291,
423,
362,
5736,
342,
398,
340,
291,
14,
2913,
508,
291,
14,
1751,
14,
885,
5736,
26,
288,
870,
360,
6612,
1678,
849,
4690,
358,
288,
291,
14,
2224,
3034,
275,
446,
17,
288,
372,
398,
291,
14,
5656,
5736,
3310,
14,
873,
275,
715,
267,
291,
14,
5656,
5736,
3310,
14,
2913,
275,
291,
14,
2913,
267,
291,
14,
5656,
5736,
3310,
14,
2526,
342,
339,
347,
485,
362,
5736,
8,
277,
304,
267,
340,
291,
14,
2913,
365,
488,
26,
288,
340,
291,
14,
1751,
14,
1818,
5736,
365,
488,
26,
355,
372,
291,
14,
1751,
14,
885,
5736,
288,
587,
26,
355,
372,
291,
14,
1751,
14,
1818,
5736,
267,
587,
26,
288,
372,
291,
14,
2913,
421,
199,
318,
1218,
4152,
5736,
3310,
8,
571,
304,
272,
2202,
275,
664,
5268,
8,
571,
9,
272,
6258,
5736,
3310,
275,
1218,
10167,
5736,
3310,
8,
571,
9,
272,
1678,
5736,
3310,
275,
6162,
5736,
3310,
8,
1751,
12,
6258,
5736,
3310,
9,
272,
372,
1678,
5736,
3310,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
indico/indico
|
indico/modules/events/registration/models/invitations.py
|
1
|
3543
|
# This file is part of Indico.
# Copyright (C) 2002 - 2021 CERN
#
# Indico is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see the
# LICENSE file for more details.
from uuid import uuid4
from sqlalchemy.dialects.postgresql import UUID
from indico.core.db import db
from indico.core.db.sqlalchemy import PyIntEnum
from indico.util.enum import RichIntEnum
from indico.util.i18n import L_
from indico.util.locators import locator_property
from indico.util.string import format_repr
class InvitationState(RichIntEnum):
__titles__ = [L_('Pending'), L_('Accepted'), L_('Declined')]
pending = 0
accepted = 1
declined = 2
class RegistrationInvitation(db.Model):
"""An invitation for someone to register."""
__tablename__ = 'invitations'
__table_args__ = (db.CheckConstraint('(state = {state}) OR (registration_id IS NULL)'
.format(state=InvitationState.accepted), name='registration_state'),
db.UniqueConstraint('registration_form_id', 'email'),
{'schema': 'event_registration'})
#: The ID of the invitation
id = db.Column(
db.Integer,
primary_key=True
)
#: The UUID of the invitation
uuid = db.Column(
UUID,
index=True,
unique=True,
nullable=False,
default=lambda: str(uuid4())
)
#: The ID of the registration form
registration_form_id = db.Column(
db.Integer,
db.ForeignKey('event_registration.forms.id'),
index=True,
nullable=False
)
#: The ID of the registration (if accepted)
registration_id = db.Column(
db.Integer,
db.ForeignKey('event_registration.registrations.id'),
index=True,
unique=True,
nullable=True
)
#: The state of the invitation
state = db.Column(
PyIntEnum(InvitationState),
nullable=False,
default=InvitationState.pending
)
#: Whether registration moderation should be skipped
skip_moderation = db.Column(
db.Boolean,
nullable=False,
default=False
)
#: The email of the invited person
email = db.Column(
db.String,
nullable=False
)
#: The first name of the invited person
first_name = db.Column(
db.String,
nullable=False
)
#: The last name of the invited person
last_name = db.Column(
db.String,
nullable=False
)
#: The affiliation of the invited person
affiliation = db.Column(
db.String,
nullable=False
)
#: The associated registration
registration = db.relationship(
'Registration',
lazy=True,
backref=db.backref(
'invitation',
lazy=True,
uselist=False
)
)
# relationship backrefs:
# - registration_form (RegistrationForm.invitations)
@locator_property
def locator(self):
return dict(self.registration_form.locator, invitation_id=self.id)
@locator.uuid
def locator(self):
"""A locator suitable for 'display' pages.
Instead of the numeric ID it uses the UUID.
"""
assert self.uuid is not None
return dict(self.registration_form.locator, invitation=self.uuid)
def __repr__(self):
full_name = f'{self.first_name} {self.last_name}'
return format_repr(self, 'id', 'registration_form_id', 'email', 'state', _text=full_name)
|
mit
|
[
3,
961,
570,
365,
1777,
402,
1010,
27347,
14,
199,
3,
1898,
334,
35,
9,
14790,
446,
499,
15385,
24354,
199,
3,
199,
3,
1010,
27347,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
10697,
844,
27,
1937,
314,
199,
3,
5113,
570,
367,
1655,
2436,
14,
199,
199,
504,
5377,
492,
5377,
20,
199,
199,
504,
8335,
14,
11072,
83,
14,
15437,
492,
11134,
199,
199,
504,
2539,
331,
14,
1018,
14,
697,
492,
1592,
199,
504,
2539,
331,
14,
1018,
14,
697,
14,
14536,
492,
1611,
3241,
5081,
199,
504,
2539,
331,
14,
1974,
14,
4869,
492,
30846,
3241,
5081,
199,
504,
2539,
331,
14,
1974,
14,
73,
1085,
78,
492,
491,
63,
199,
504,
2539,
331,
14,
1974,
14,
2102,
2750,
492,
14067,
63,
1829,
199,
504,
2539,
331,
14,
1974,
14,
875,
492,
1475,
63,
2722,
421,
199,
533,
30110,
5314,
2223,
8,
50,
1158,
3241,
5081,
304,
272,
636,
8916,
363,
275,
359,
44,
11252,
15960,
659,
491,
11252,
1945,
7203,
659,
491,
11252,
20856,
1942,
5440,
272,
9413,
275,
378,
272,
10226,
275,
413,
272,
15021,
1942,
275,
499,
421,
199,
533,
20764,
14883,
5314,
8,
697,
14,
1685,
304,
272,
408,
2493,
4572,
5314,
367,
17122,
370,
2274,
1041,
272,
636,
10983,
363,
275,
283,
5350,
390,
1298,
7,
272,
636,
1224,
63,
589,
363,
275,
334,
697,
14,
1799,
8463,
14097,
929,
275,
469,
929,
1552,
1549,
334,
8054,
63,
344,
2281,
5962,
3171,
1460,
1275,
908,
8,
929,
29,
14883,
5314,
2223,
14,
16121,
395,
536,
534,
8054,
63,
929,
659,
1993,
1592,
14,
11427,
8463,
360,
8054,
63,
964,
63,
344,
297,
283,
2123,
659,
1993,
791,
3629,
356,
283,
1430,
63,
8054,
3071,
339,
6079,
710,
2870,
402,
314,
4572,
5314,
272,
1305,
275,
1592,
14,
4547,
8,
267,
1592,
14,
2674,
12,
267,
5062,
63,
498,
29,
549,
272,
776,
272,
6079,
710,
11134,
402,
314,
4572,
5314,
272,
5377,
275,
1592,
14,
4547,
8,
267,
11134,
12,
267,
1478,
29,
549,
12,
267,
3747,
29,
549,
12,
267,
7854,
29,
797,
12,
267,
849,
29,
2734,
26,
620,
8,
2580,
20,
1012,
272,
776,
272,
6079,
710,
2870,
402,
314,
10991,
1824,
272,
10991,
63,
964,
63,
344,
275,
1592,
14,
4547,
8,
267,
1592,
14,
2674,
12,
267,
1592,
14,
3190,
360,
1430,
63,
8054,
14,
3351,
14,
344,
659,
267,
1478,
29,
549,
12,
267,
7854,
29,
797,
272,
776,
272,
6079,
710,
2870,
402,
314,
10991,
334,
692,
10226,
9,
272,
10991,
63,
344,
275,
1592,
14,
4547,
8,
267,
1592,
14,
2674,
12,
267,
1592,
14,
3190,
360,
1430,
63,
8054,
14,
29440,
14,
344,
659,
267,
1478,
29,
549,
12,
267,
3747,
29,
549,
12,
267,
7854,
29,
549,
272,
776,
272,
6079,
710,
1174,
402,
314,
4572,
5314,
272,
1174,
275,
1592,
14,
4547,
8,
267,
1611,
3241,
5081,
8,
14883,
5314,
2223,
395,
267,
7854,
29,
797,
12,
267,
849,
29,
14883,
5314,
2223,
14,
6455,
272,
776,
272,
6079,
7480,
10991,
818,
1754,
1077,
506,
9645,
272,
3372,
63,
632,
1754,
275,
1592,
14,
4547,
8,
267,
1592,
14,
4082,
12,
267,
7854,
29,
797,
12,
267,
849,
29,
797,
272,
776,
272,
6079,
710,
3031,
402,
314,
315,
433,
471,
4954,
272,
3031,
275,
1592,
14,
4547,
8,
267,
1592,
14,
1558,
12,
267,
7854,
29,
797,
272,
776,
272,
6079,
710,
1642,
536,
402,
314,
315,
433,
471,
4954,
272,
1642,
63,
354,
275,
1592,
14,
4547,
8,
267,
1592,
14,
1558,
12,
267,
7854,
29,
797,
272,
776,
272,
6079,
710,
2061,
536,
402,
314,
315,
433,
471,
4954,
272,
2061,
63,
354,
275,
1592,
14,
4547,
8,
267,
1592,
14,
1558,
12,
267,
7854,
29,
797,
272,
776,
272,
6079,
710,
23528,
18835,
402,
314,
315,
433,
471,
4954,
272,
23528,
18835,
275,
1592,
14,
4547,
8,
267,
1592,
14,
1558,
12,
267,
7854,
29,
797,
272,
776,
339,
6079,
710,
4568,
10991,
272,
10991,
275,
1592,
14,
11704,
8,
267,
283,
11757,
297,
267,
9617,
29,
549,
12,
267,
23412,
29,
697,
14,
894,
1121,
8,
288,
283,
5350,
5314,
297,
288,
9617,
29,
549,
12,
288,
675,
513,
29,
797,
267,
776,
272,
776,
339,
327,
8931,
1771,
7655,
26,
272,
327,
446,
10991,
63,
964,
334,
11757,
2821,
14,
5350,
390,
1298,
9,
339,
768,
6354,
63,
1829,
272,
347,
14067,
8,
277,
304,
267,
372,
1211,
8,
277,
14,
8054,
63,
964,
14,
6354,
12,
4572,
5314,
63,
344,
29,
277,
14,
344,
9,
339,
768,
6354,
14,
2580,
272,
347,
14067,
8,
277,
304,
267,
408,
33,
14067,
11233,
367,
283,
2918,
7,
6497,
14,
398,
15345,
402,
314,
8950,
2870,
652,
4440,
314,
11134,
14,
267,
408,
267,
702,
291,
14,
2580,
365,
440,
488,
267,
372,
1211,
8,
277,
14,
8054,
63,
964,
14,
6354,
12,
4572,
5314,
29,
277,
14,
2580,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
2615,
63,
354,
275,
289,
16019,
277,
14,
2246,
63,
354,
93,
469,
277,
14,
2019,
63,
354,
6834,
267,
372,
1475,
63,
2722,
8,
277,
12,
283,
344,
297,
283,
8054,
63,
964,
63,
344,
297,
283,
2123,
297,
283,
929,
297,
485,
505,
29,
2861,
63,
354,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
961,
570,
365,
1777,
402,
1010,
27347,
14,
199,
3,
1898,
334,
35,
9,
14790,
446,
499,
15385,
24354,
199,
3,
199,
3,
1010,
27347,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
10697,
844,
27,
1937,
314,
199,
3,
5113,
570,
367,
1655,
2436,
14,
199,
199,
504,
5377,
492,
5377,
20,
199,
199,
504,
8335,
14,
11072,
83,
14,
15437,
492,
11134,
199,
199,
504,
2539,
331,
14,
1018,
14,
697,
492,
1592,
199,
504,
2539,
331,
14,
1018,
14,
697,
14,
14536,
492,
1611,
3241,
5081,
199,
504,
2539,
331,
14,
1974,
14,
4869,
492,
30846,
3241,
5081,
199,
504,
2539,
331,
14,
1974,
14,
73,
1085,
78,
492,
491,
63,
199,
504,
2539,
331,
14,
1974,
14,
2102,
2750,
492,
14067,
63,
1829,
199,
504,
2539,
331,
14,
1974,
14,
875,
492,
1475,
63,
2722,
421,
199,
533,
30110,
5314,
2223,
8,
50,
1158,
3241,
5081,
304,
272,
636,
8916,
363,
275,
359,
44,
11252,
15960,
659,
491,
11252,
1945,
7203,
659,
491,
11252,
20856,
1942,
5440,
272,
9413,
275,
378,
272,
10226,
275,
413,
272,
15021,
1942,
275,
499,
421,
199,
533,
20764,
14883,
5314,
8,
697,
14,
1685,
304,
272,
408,
2493,
4572,
5314,
367,
17122,
370,
2274,
1041,
272,
636,
10983,
363,
275,
283,
5350,
390,
1298,
7,
272,
636,
1224,
63,
589,
363,
275,
334,
697,
14,
1799,
8463,
14097,
929,
275,
469,
929,
1552,
1549,
334,
8054,
63,
344,
2281,
5962,
3171,
1460,
1275,
908,
8,
929,
29,
14883,
5314,
2223,
14,
16121,
395,
536,
534,
8054,
63,
929,
659,
1993,
1592,
14,
11427,
8463,
360,
8054,
63,
964,
63,
344,
297,
283,
2123,
659,
1993,
791,
3629,
356,
283,
1430,
63,
8054,
3071,
339,
6079,
710,
2870,
402,
314,
4572,
5314,
272,
1305,
275,
1592,
14,
4547,
8,
267,
1592,
14,
2674,
12,
267,
5062,
63,
498,
29,
549,
272,
776,
272,
6079,
710,
11134,
402,
314,
4572,
5314,
272,
5377,
275,
1592,
14,
4547,
8,
267,
11134,
12,
267,
1478,
29,
549,
12,
267,
3747,
29,
549,
12,
267,
7854,
29,
797,
12,
267,
849,
29,
2734,
26,
620,
8,
2580,
20,
1012,
272,
776,
272,
6079,
710,
2870,
402,
314,
10991,
1824,
272,
10991,
63,
964,
63,
344,
275,
1592,
14,
4547,
8,
267,
1592,
14,
2674,
12,
267,
1592,
14,
3190,
360,
1430,
63,
8054,
14,
3351,
14,
344,
659,
267,
1478,
29,
549,
12,
267,
7854,
29,
797,
272,
776,
272,
6079,
710,
2870,
402,
314,
10991,
334,
692,
10226,
9,
272,
10991,
63,
344,
275,
1592,
14,
4547,
8,
267,
1592,
14,
2674,
12,
267,
1592,
14,
3190,
360,
1430,
63,
8054,
14,
29440,
14,
344,
659,
267,
1478,
29,
549,
12,
267,
3747,
29,
549,
12,
267,
7854,
29,
549,
272,
776,
272,
6079,
710,
1174,
402,
314,
4572,
5314,
272,
1174,
275,
1592,
14,
4547,
8,
267,
1611,
3241,
5081,
8,
14883,
5314,
2223,
395,
267,
7854,
29,
797,
12,
267,
849,
29,
14883,
5314,
2223,
14,
6455,
272,
776,
272,
6079,
7480,
10991,
818,
1754,
1077,
506,
9645,
272,
3372,
63,
632,
1754,
275,
1592,
14,
4547,
8,
267,
1592,
14,
4082,
12,
267,
7854,
29,
797,
12,
267,
849,
29,
797,
272,
776,
272,
6079,
710,
3031,
402,
314,
315,
433,
471,
4954,
272,
3031,
275,
1592,
14,
4547,
8,
267,
1592,
14,
1558,
12,
267,
7854,
29,
797,
272,
776,
272,
6079,
710,
1642,
536,
402,
314,
315,
433,
471,
4954,
272,
1642,
63,
354,
275,
1592,
14,
4547,
8,
267,
1592,
14,
1558,
12,
267,
7854,
29,
797,
272,
776,
272,
6079,
710,
2061,
536,
402,
314,
315,
433,
471,
4954,
272,
2061,
63,
354,
275,
1592,
14,
4547,
8,
267,
1592,
14,
1558,
12,
267,
7854,
29,
797,
272,
776,
272,
6079,
710,
23528,
18835,
402,
314,
315,
433,
471,
4954,
272,
23528,
18835,
275,
1592,
14,
4547,
8,
267,
1592,
14,
1558,
12,
267,
7854,
29,
797,
272,
776,
339,
6079,
710,
4568,
10991,
272,
10991,
275,
1592,
14,
11704,
8,
267,
283,
11757,
297,
267,
9617,
29,
549,
12,
267,
23412,
29,
697,
14,
894,
1121,
8,
288,
283,
5350,
5314,
297,
288,
9617,
29,
549,
12,
288,
675,
513,
29,
797,
267,
776,
272,
776,
339,
327,
8931,
1771,
7655,
26,
272,
327,
446,
10991,
63,
964,
334,
11757,
2821,
14,
5350,
390,
1298,
9,
339,
768,
6354,
63,
1829,
272,
347,
14067,
8,
277,
304,
267,
372,
1211,
8,
277,
14,
8054,
63,
964,
14,
6354,
12,
4572,
5314,
63,
344,
29,
277,
14,
344,
9,
339,
768,
6354,
14,
2580,
272,
347,
14067,
8,
277,
304,
267,
408,
33,
14067,
11233,
367,
283,
2918,
7,
6497,
14,
398,
15345,
402,
314,
8950,
2870,
652,
4440,
314,
11134,
14,
267,
408,
267,
702,
291,
14,
2580,
365,
440,
488,
267,
372,
1211,
8,
277,
14,
8054,
63,
964,
14,
6354,
12,
4572,
5314,
29,
277,
14,
2580,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
2615,
63,
354,
275,
289,
16019,
277,
14,
2246,
63,
354,
93,
469,
277,
14,
2019,
63,
354,
6834,
267,
372,
1475,
63,
2722,
8,
277,
12,
283,
344,
297,
283,
8054,
63,
964,
63,
344,
297,
283,
2123,
297,
283,
929,
297,
485,
505,
29,
2861,
63,
354,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
gdementen/PyTables
|
examples/array2.py
|
13
|
1029
|
from __future__ import print_function
import numpy as np
import tables
# Open a new empty HDF5 file
fileh = tables.open_file("array2.h5", mode="w")
# Shortcut to the root group
root = fileh.root
# Create an array
a = np.array([1, 2.7182818284590451, 3.141592], float)
print("About to write array:", a)
print(" with shape: ==>", a.shape)
print(" and dtype ==>", a.dtype)
# Save it on the HDF5 file
hdfarray = fileh.create_array(root, 'carray', a, "Float array")
# Get metadata on the previously saved array
print()
print("Info on the object:", repr(root.carray))
# Close the file
fileh.close()
# Open the previous HDF5 file in read-only mode
fileh = tables.open_file("array2.h5", mode="r")
# Get the root group
root = fileh.root
# Get metadata on the previously saved array
print()
print("Info on the object:", repr(root.carray))
# Get the actual array
b = root.carray.read()
print()
print("Array read from file:", b)
print(" with shape: ==>", b.shape)
print(" and dtype ==>", b.dtype)
# Close the file
fileh.close()
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
2680,
465,
980,
199,
646,
6716,
199,
199,
3,
3232,
282,
892,
2701,
24521,
21,
570,
199,
493,
72,
275,
6716,
14,
1490,
63,
493,
480,
1144,
18,
14,
72,
21,
401,
818,
628,
87,
531,
199,
3,
20124,
5919,
370,
314,
1738,
1572,
199,
1231,
275,
570,
72,
14,
1231,
199,
199,
3,
2790,
376,
1625,
199,
65,
275,
980,
14,
1144,
779,
17,
12,
499,
14,
26948,
1651,
1085,
10681,
1427,
966,
2869,
12,
650,
14,
32689,
2942,
467,
2069,
9,
199,
1361,
480,
18816,
370,
2218,
1625,
6783,
282,
9,
199,
1361,
480,
221,
543,
2215,
26,
508,
7166,
282,
14,
1392,
9,
199,
1361,
480,
221,
436,
2152,
508,
7166,
282,
14,
2271,
9,
199,
199,
3,
11063,
652,
641,
314,
24521,
21,
570,
199,
19912,
1144,
275,
570,
72,
14,
981,
63,
1144,
8,
1231,
12,
283,
67,
1144,
297,
282,
12,
298,
5136,
1625,
531,
199,
199,
3,
2372,
3341,
641,
314,
10889,
6290,
1625,
199,
1361,
342,
199,
1361,
480,
2354,
641,
314,
909,
6783,
4700,
8,
1231,
14,
67,
1144,
430,
199,
199,
3,
15524,
314,
570,
199,
493,
72,
14,
1600,
342,
199,
199,
3,
3232,
314,
4136,
24521,
21,
570,
315,
1586,
13,
2118,
818,
199,
493,
72,
275,
6716,
14,
1490,
63,
493,
480,
1144,
18,
14,
72,
21,
401,
818,
628,
82,
531,
199,
3,
2372,
314,
1738,
1572,
199,
1231,
275,
570,
72,
14,
1231,
199,
199,
3,
2372,
3341,
641,
314,
10889,
6290,
1625,
199,
1361,
342,
199,
1361,
480,
2354,
641,
314,
909,
6783,
4700,
8,
1231,
14,
67,
1144,
430,
199,
199,
3,
2372,
314,
3503,
1625,
199,
66,
275,
1738,
14,
67,
1144,
14,
739,
342,
199,
1361,
342,
199,
1361,
480,
3836,
1586,
687,
570,
6783,
330,
9,
199,
1361,
480,
221,
543,
2215,
26,
508,
7166,
330,
14,
1392,
9,
199,
1361,
480,
221,
436,
2152,
508,
7166,
330,
14,
2271,
9,
199,
199,
3,
15524,
314,
570,
199,
493,
72,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
2680,
465,
980,
199,
646,
6716,
199,
199,
3,
3232,
282,
892,
2701,
24521,
21,
570,
199,
493,
72,
275,
6716,
14,
1490,
63,
493,
480,
1144,
18,
14,
72,
21,
401,
818,
628,
87,
531,
199,
3,
20124,
5919,
370,
314,
1738,
1572,
199,
1231,
275,
570,
72,
14,
1231,
199,
199,
3,
2790,
376,
1625,
199,
65,
275,
980,
14,
1144,
779,
17,
12,
499,
14,
26948,
1651,
1085,
10681,
1427,
966,
2869,
12,
650,
14,
32689,
2942,
467,
2069,
9,
199,
1361,
480,
18816,
370,
2218,
1625,
6783,
282,
9,
199,
1361,
480,
221,
543,
2215,
26,
508,
7166,
282,
14,
1392,
9,
199,
1361,
480,
221,
436,
2152,
508,
7166,
282,
14,
2271,
9,
199,
199,
3,
11063,
652,
641,
314,
24521,
21,
570,
199,
19912,
1144,
275,
570,
72,
14,
981,
63,
1144,
8,
1231,
12,
283,
67,
1144,
297,
282,
12,
298,
5136,
1625,
531,
199,
199,
3,
2372,
3341,
641,
314,
10889,
6290,
1625,
199,
1361,
342,
199,
1361,
480,
2354,
641,
314,
909,
6783,
4700,
8,
1231,
14,
67,
1144,
430,
199,
199,
3,
15524,
314,
570,
199,
493,
72,
14,
1600,
342,
199,
199,
3,
3232,
314,
4136,
24521,
21,
570,
315,
1586,
13,
2118,
818,
199,
493,
72,
275,
6716,
14,
1490,
63,
493,
480,
1144,
18,
14,
72,
21,
401,
818,
628,
82,
531,
199,
3,
2372,
314,
1738,
1572,
199,
1231,
275,
570,
72,
14,
1231,
199,
199,
3,
2372,
3341,
641,
314,
10889,
6290,
1625,
199,
1361,
342,
199,
1361,
480,
2354,
641,
314,
909,
6783,
4700,
8,
1231,
14,
67,
1144,
430,
199,
199,
3,
2372,
314,
3503,
1625,
199,
66,
275,
1738,
14,
67,
1144,
14,
739,
342,
199,
1361,
342,
199,
1361,
480,
3836,
1586,
687,
570,
6783,
330,
9,
199,
1361,
480,
221,
543,
2215,
26,
508,
7166,
330,
14,
1392,
9,
199,
1361,
480,
221,
436,
2152,
508,
7166,
330,
14,
2271,
9,
199,
199,
3,
15524,
314,
570,
199,
493,
72,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
TeachAtTUM/edx-platform
|
cms/djangoapps/contentstore/features/pages.py
|
13
|
5052
|
# pylint: disable=missing-docstring
# pylint: disable=redefined-outer-name
# pylint: disable=unused-argument
# pylint: disable=no-member
from lettuce import step, world
from nose.tools import assert_equal, assert_in
CSS_FOR_TAB_ELEMENT = "li[data-tab-id='{0}'] input.toggle-checkbox"
@step(u'I go to the pages page$')
def go_to_static(step):
menu_css = 'li.nav-course-courseware'
static_css = 'li.nav-course-courseware-pages a'
world.css_click(menu_css)
world.css_click(static_css)
@step(u'I add a new static page$')
def add_page(step):
button_css = 'a.new-button'
world.css_click(button_css)
@step(u'I should see a static page named "([^"]*)"$')
def see_a_static_page_named_foo(step, name):
pages_css = 'div.xmodule_StaticTabModule'
page_name_html = world.css_html(pages_css)
assert_equal(page_name_html.strip(), name)
@step(u'I should not see any static pages$')
def not_see_any_static_pages(step):
pages_css = 'div.xmodule_StaticTabModule'
assert world.is_css_not_present(pages_css, wait_time=30)
@step(u'I "(edit|delete)" the static page$')
def click_edit_or_delete(step, edit_or_delete):
button_css = 'ul.component-actions .%s-button' % edit_or_delete
world.css_click(button_css)
@step(u'I change the name to "([^"]*)"$')
def change_name(step, new_name):
settings_css = '.settings-button'
world.css_click(settings_css)
input_css = 'input.setting-input'
world.css_fill(input_css, new_name)
if world.is_firefox():
world.trigger_event(input_css)
world.save_component()
@step(u'I drag the first static page to the last$')
def drag_first_static_page_to_last(step):
drag_first_to_last_with_css('.component')
@step(u'I have created a static page$')
def create_static_page(step):
step.given('I have opened the pages page in a new course')
step.given('I add a new static page')
@step(u'I have opened the pages page in a new course$')
def open_pages_page_in_new_course(step):
step.given('I have opened a new course in Studio')
step.given('I go to the pages page')
@step(u'I have created two different static pages$')
def create_two_pages(step):
step.given('I have created a static page')
step.given('I "edit" the static page')
step.given('I change the name to "First"')
step.given('I add a new static page')
# Verify order of pages
_verify_page_names('First', 'Empty')
@step(u'the static pages are switched$')
def static_pages_are_switched(step):
_verify_page_names('Empty', 'First')
def _verify_page_names(first, second):
world.wait_for(
func=lambda _: len(world.css_find('.xmodule_StaticTabModule')) == 2,
timeout=200,
timeout_msg="Timed out waiting for two pages to be present"
)
pages = world.css_find('.xmodule_StaticTabModule')
assert_equal(pages[0].text, first)
assert_equal(pages[1].text, second)
@step(u'the built-in pages are in the default order$')
def built_in_pages_in_default_order(step):
expected_pages = ['Home', 'Course', 'Wiki', 'Progress']
see_pages_in_expected_order(expected_pages)
@step(u'the built-in pages are switched$')
def built_in_pages_switched(step):
expected_pages = ['Home', 'Course', 'Progress', 'Wiki']
see_pages_in_expected_order(expected_pages)
@step(u'the pages are in the default order$')
def pages_in_default_order(step):
expected_pages = ['Home', 'Course', 'Wiki', 'Progress', 'First', 'Empty']
see_pages_in_expected_order(expected_pages)
@step(u'the pages are switched$$')
def pages_are_switched(step):
expected_pages = ['Home', 'Course', 'Progress', 'First', 'Empty', 'Wiki']
see_pages_in_expected_order(expected_pages)
@step(u'I drag the first page to the last$')
def drag_first_page_to_last(step):
drag_first_to_last_with_css('.is-movable')
@step(u'I should see the "([^"]*)" page as "(visible|hidden)"$')
def page_is_visible_or_hidden(step, page_id, visible_or_hidden):
hidden = visible_or_hidden == "hidden"
assert_equal(world.css_find(CSS_FOR_TAB_ELEMENT.format(page_id)).checked, hidden)
@step(u'I toggle the visibility of the "([^"]*)" page$')
def page_toggle_visibility(step, page_id):
world.css_find(CSS_FOR_TAB_ELEMENT.format(page_id))[0].click()
def drag_first_to_last_with_css(css_class):
# For some reason, the drag_and_drop method did not work in this case.
draggables = world.css_find(css_class + ' .drag-handle')
source = draggables.first
target = draggables.last
source.action_chains.click_and_hold(source._element).perform() # pylint: disable=protected-access
source.action_chains.move_to_element_with_offset(target._element, 0, 50).perform() # pylint: disable=protected-access
source.action_chains.release().perform()
def see_pages_in_expected_order(page_names_in_expected_order):
pages = world.css_find("li.course-tab")
assert_equal(len(page_names_in_expected_order), len(pages))
for i, page_name in enumerate(page_names_in_expected_order):
assert_in(page_name, pages[i].text)
|
agpl-3.0
|
[
3,
4287,
26,
3507,
29,
4752,
13,
12485,
199,
3,
4287,
26,
3507,
29,
27913,
13,
7837,
13,
354,
199,
3,
4287,
26,
3507,
29,
8618,
13,
2094,
199,
3,
4287,
26,
3507,
29,
889,
13,
1114,
199,
199,
504,
4691,
84,
3683,
492,
3650,
12,
6701,
199,
504,
11354,
14,
2537,
492,
702,
63,
1452,
12,
702,
63,
262,
199,
199,
14391,
63,
2707,
63,
10129,
63,
12535,
275,
298,
317,
59,
576,
13,
2902,
13,
344,
32134,
16,
93,
418,
1324,
14,
13396,
13,
13456,
2,
421,
199,
32,
2926,
8,
85,
7,
41,
2621,
370,
314,
6497,
2034,
9988,
199,
318,
2621,
63,
475,
63,
1986,
8,
2926,
304,
272,
6269,
63,
3919,
275,
283,
317,
14,
10927,
13,
1972,
13,
17744,
7,
272,
2955,
63,
3919,
275,
283,
317,
14,
10927,
13,
1972,
13,
17744,
13,
5856,
282,
7,
272,
6701,
14,
3919,
63,
4891,
8,
4470,
63,
3919,
9,
272,
6701,
14,
3919,
63,
4891,
8,
1986,
63,
3919,
9,
421,
199,
32,
2926,
8,
85,
7,
41,
1050,
282,
892,
2955,
2034,
9988,
199,
318,
1050,
63,
1606,
8,
2926,
304,
272,
5528,
63,
3919,
275,
283,
65,
14,
1222,
13,
3887,
7,
272,
6701,
14,
3919,
63,
4891,
8,
3887,
63,
3919,
9,
421,
199,
32,
2926,
8,
85,
7,
41,
1077,
1937,
282,
2955,
2034,
4310,
32397,
25952,
9988,
199,
318,
1937,
63,
65,
63,
1986,
63,
1606,
63,
4579,
63,
1421,
8,
2926,
12,
536,
304,
272,
6497,
63,
3919,
275,
283,
3015,
14,
14293,
63,
9278,
7690,
2377,
7,
272,
2034,
63,
354,
63,
1360,
275,
6701,
14,
3919,
63,
1360,
8,
5856,
63,
3919,
9,
272,
702,
63,
1452,
8,
1606,
63,
354,
63,
1360,
14,
1913,
1062,
536,
9,
421,
199,
32,
2926,
8,
85,
7,
41,
1077,
440,
1937,
1263,
2955,
6497,
9988,
199,
318,
440,
63,
3239,
63,
1629,
63,
1986,
63,
5856,
8,
2926,
304,
272,
6497,
63,
3919,
275,
283,
3015,
14,
14293,
63,
9278,
7690,
2377,
7,
272,
702,
6701,
14,
374,
63,
3919,
63,
1397,
63,
1881,
8,
5856,
63,
3919,
12,
3618,
63,
521,
29,
1216,
9,
421,
199,
32,
2926,
8,
85,
7,
41,
7340,
3773,
92,
1807,
2924,
314,
2955,
2034,
9988,
199,
318,
8968,
63,
3773,
63,
269,
63,
1807,
8,
2926,
12,
5283,
63,
269,
63,
1807,
304,
272,
5528,
63,
3919,
275,
283,
348,
14,
3173,
13,
3723,
1275,
5,
83,
13,
3887,
7,
450,
5283,
63,
269,
63,
1807,
272,
6701,
14,
3919,
63,
4891,
8,
3887,
63,
3919,
9,
421,
199,
32,
2926,
8,
85,
7,
41,
1570,
314,
536,
370,
32397,
25952,
9988,
199,
318,
1570,
63,
354,
8,
2926,
12,
892,
63,
354,
304,
272,
2202,
63,
3919,
275,
1987,
1751,
13,
3887,
7,
272,
6701,
14,
3919,
63,
4891,
8,
1751,
63,
3919,
9,
272,
1324,
63,
3919,
275,
283,
1210,
14,
6031,
13,
1210,
7,
272,
6701,
14,
3919,
63,
4498,
8,
1210,
63,
3919,
12,
892,
63,
354,
9,
272,
340,
6701,
14,
374,
63,
15394,
837,
267,
6701,
14,
7631,
63,
1430,
8,
1210,
63,
3919,
9,
272,
6701,
14,
2117,
63,
3173,
342,
421,
199,
32,
2926,
8,
85,
7,
41,
18981,
314,
1642,
2955,
2034,
370,
314,
2061,
9988,
199,
318,
18981,
63,
2246,
63,
1986,
63,
1606,
63,
475,
63,
2019,
8,
2926,
304,
272,
18981,
63,
2246,
63,
475,
63,
2019,
63,
1045,
63,
3919,
5175,
3173,
358,
421,
199,
32,
2926,
8,
85,
7,
41,
1172,
2737,
282,
2955,
2034,
9988,
199,
318,
1218,
63,
1986,
63,
1606,
8,
2926,
304,
272,
3650,
14,
11809,
360,
41,
1172,
12123,
314,
6497,
2034,
315,
282,
892,
2518,
358,
272,
3650,
14,
11809,
360,
41,
1050,
282,
892,
2955,
2034,
358,
421,
199,
32,
2926,
8,
85,
7,
41,
1172,
12123,
314,
6497,
2034,
315,
282,
892,
2518,
9988,
199,
318,
1551,
63,
5856,
63,
1606,
63,
262,
63,
1222,
63,
1972,
8,
2926,
304,
272,
3650,
14,
11809,
360,
41,
1172,
12123,
282,
892,
2518,
315,
13225,
358,
272,
3650,
14,
11809,
360,
41,
2621,
370,
314,
6497,
2034,
358,
421,
199,
32,
2926,
8,
85,
7,
41,
1172,
2737,
2877,
3365,
2955,
6497,
9988,
199,
318,
1218,
63,
5601,
63,
5856,
8,
2926,
304,
272,
3650,
14,
11809,
360,
41,
1172,
2737,
282,
2955,
2034,
358,
272,
3650,
14,
11809,
360,
41,
298,
3773,
2,
314,
2955,
2034,
358,
272,
3650,
14,
11809,
360,
41,
1570,
314,
536,
370,
298,
7147,
9008,
272,
3650,
14,
11809,
360,
41,
1050,
282,
892,
2955,
2034,
358,
272,
327,
7635,
1865,
402,
6497,
272,
485,
4712,
63,
1606,
63,
1247,
360,
7147,
297,
283,
4699,
358,
421,
199,
32,
2926,
8,
85,
1133,
426,
2955,
6497,
787,
308,
28986,
9988,
199,
318,
2955,
63,
5856,
63,
1530,
63,
83,
28986,
8,
2926,
304,
272,
485,
4712,
63,
1606,
63,
1247,
360,
4699,
297,
283,
7147,
358,
421,
199,
318,
485,
4712,
63,
1606,
63,
1247,
8,
2246,
12,
3499,
304,
272,
6701,
14,
2573,
63,
509,
8,
267,
2562,
29,
2734,
24700,
822,
8,
7617,
14,
3919,
63,
1623,
5175,
14293,
63,
9278,
7690,
2377,
1333,
508,
499,
12,
267,
2653,
29,
1840,
12,
267,
2653,
63,
1328,
628,
28682,
734,
10923,
367,
2877,
6497,
370,
506,
3451,
2,
272,
776,
272,
6497,
275,
6701,
14,
3919,
63,
1623,
5175,
14293,
63,
9278,
7690,
2377,
358,
272,
702,
63,
1452,
8,
5856,
59,
16,
1055,
505,
12,
1642,
9,
272,
702,
63,
1452,
8,
5856,
59,
17,
1055,
505,
12,
3499,
9,
421,
199,
32,
2926,
8,
85,
1133,
426,
6137,
13,
262,
6497,
787,
315,
314,
849,
1865,
9988,
199,
318,
6137,
63,
262,
63,
5856,
63,
262,
63,
885,
63,
1648,
8,
2926,
304,
272,
1420,
63,
5856,
275,
788,
12054,
297,
283,
6979,
297,
283,
26198,
297,
283,
11504,
418,
272,
1937,
63,
5856,
63,
262,
63,
2062,
63,
1648,
8,
2062,
63,
5856,
9,
421,
199,
32,
2926,
8,
85,
1133,
426,
6137,
13,
262,
6497,
787,
308,
28986,
9988,
199,
318,
6137,
63,
262,
63,
5856,
63,
83,
28986,
8,
2926,
304,
272,
1420,
63
] |
[
4287,
26,
3507,
29,
4752,
13,
12485,
199,
3,
4287,
26,
3507,
29,
27913,
13,
7837,
13,
354,
199,
3,
4287,
26,
3507,
29,
8618,
13,
2094,
199,
3,
4287,
26,
3507,
29,
889,
13,
1114,
199,
199,
504,
4691,
84,
3683,
492,
3650,
12,
6701,
199,
504,
11354,
14,
2537,
492,
702,
63,
1452,
12,
702,
63,
262,
199,
199,
14391,
63,
2707,
63,
10129,
63,
12535,
275,
298,
317,
59,
576,
13,
2902,
13,
344,
32134,
16,
93,
418,
1324,
14,
13396,
13,
13456,
2,
421,
199,
32,
2926,
8,
85,
7,
41,
2621,
370,
314,
6497,
2034,
9988,
199,
318,
2621,
63,
475,
63,
1986,
8,
2926,
304,
272,
6269,
63,
3919,
275,
283,
317,
14,
10927,
13,
1972,
13,
17744,
7,
272,
2955,
63,
3919,
275,
283,
317,
14,
10927,
13,
1972,
13,
17744,
13,
5856,
282,
7,
272,
6701,
14,
3919,
63,
4891,
8,
4470,
63,
3919,
9,
272,
6701,
14,
3919,
63,
4891,
8,
1986,
63,
3919,
9,
421,
199,
32,
2926,
8,
85,
7,
41,
1050,
282,
892,
2955,
2034,
9988,
199,
318,
1050,
63,
1606,
8,
2926,
304,
272,
5528,
63,
3919,
275,
283,
65,
14,
1222,
13,
3887,
7,
272,
6701,
14,
3919,
63,
4891,
8,
3887,
63,
3919,
9,
421,
199,
32,
2926,
8,
85,
7,
41,
1077,
1937,
282,
2955,
2034,
4310,
32397,
25952,
9988,
199,
318,
1937,
63,
65,
63,
1986,
63,
1606,
63,
4579,
63,
1421,
8,
2926,
12,
536,
304,
272,
6497,
63,
3919,
275,
283,
3015,
14,
14293,
63,
9278,
7690,
2377,
7,
272,
2034,
63,
354,
63,
1360,
275,
6701,
14,
3919,
63,
1360,
8,
5856,
63,
3919,
9,
272,
702,
63,
1452,
8,
1606,
63,
354,
63,
1360,
14,
1913,
1062,
536,
9,
421,
199,
32,
2926,
8,
85,
7,
41,
1077,
440,
1937,
1263,
2955,
6497,
9988,
199,
318,
440,
63,
3239,
63,
1629,
63,
1986,
63,
5856,
8,
2926,
304,
272,
6497,
63,
3919,
275,
283,
3015,
14,
14293,
63,
9278,
7690,
2377,
7,
272,
702,
6701,
14,
374,
63,
3919,
63,
1397,
63,
1881,
8,
5856,
63,
3919,
12,
3618,
63,
521,
29,
1216,
9,
421,
199,
32,
2926,
8,
85,
7,
41,
7340,
3773,
92,
1807,
2924,
314,
2955,
2034,
9988,
199,
318,
8968,
63,
3773,
63,
269,
63,
1807,
8,
2926,
12,
5283,
63,
269,
63,
1807,
304,
272,
5528,
63,
3919,
275,
283,
348,
14,
3173,
13,
3723,
1275,
5,
83,
13,
3887,
7,
450,
5283,
63,
269,
63,
1807,
272,
6701,
14,
3919,
63,
4891,
8,
3887,
63,
3919,
9,
421,
199,
32,
2926,
8,
85,
7,
41,
1570,
314,
536,
370,
32397,
25952,
9988,
199,
318,
1570,
63,
354,
8,
2926,
12,
892,
63,
354,
304,
272,
2202,
63,
3919,
275,
1987,
1751,
13,
3887,
7,
272,
6701,
14,
3919,
63,
4891,
8,
1751,
63,
3919,
9,
272,
1324,
63,
3919,
275,
283,
1210,
14,
6031,
13,
1210,
7,
272,
6701,
14,
3919,
63,
4498,
8,
1210,
63,
3919,
12,
892,
63,
354,
9,
272,
340,
6701,
14,
374,
63,
15394,
837,
267,
6701,
14,
7631,
63,
1430,
8,
1210,
63,
3919,
9,
272,
6701,
14,
2117,
63,
3173,
342,
421,
199,
32,
2926,
8,
85,
7,
41,
18981,
314,
1642,
2955,
2034,
370,
314,
2061,
9988,
199,
318,
18981,
63,
2246,
63,
1986,
63,
1606,
63,
475,
63,
2019,
8,
2926,
304,
272,
18981,
63,
2246,
63,
475,
63,
2019,
63,
1045,
63,
3919,
5175,
3173,
358,
421,
199,
32,
2926,
8,
85,
7,
41,
1172,
2737,
282,
2955,
2034,
9988,
199,
318,
1218,
63,
1986,
63,
1606,
8,
2926,
304,
272,
3650,
14,
11809,
360,
41,
1172,
12123,
314,
6497,
2034,
315,
282,
892,
2518,
358,
272,
3650,
14,
11809,
360,
41,
1050,
282,
892,
2955,
2034,
358,
421,
199,
32,
2926,
8,
85,
7,
41,
1172,
12123,
314,
6497,
2034,
315,
282,
892,
2518,
9988,
199,
318,
1551,
63,
5856,
63,
1606,
63,
262,
63,
1222,
63,
1972,
8,
2926,
304,
272,
3650,
14,
11809,
360,
41,
1172,
12123,
282,
892,
2518,
315,
13225,
358,
272,
3650,
14,
11809,
360,
41,
2621,
370,
314,
6497,
2034,
358,
421,
199,
32,
2926,
8,
85,
7,
41,
1172,
2737,
2877,
3365,
2955,
6497,
9988,
199,
318,
1218,
63,
5601,
63,
5856,
8,
2926,
304,
272,
3650,
14,
11809,
360,
41,
1172,
2737,
282,
2955,
2034,
358,
272,
3650,
14,
11809,
360,
41,
298,
3773,
2,
314,
2955,
2034,
358,
272,
3650,
14,
11809,
360,
41,
1570,
314,
536,
370,
298,
7147,
9008,
272,
3650,
14,
11809,
360,
41,
1050,
282,
892,
2955,
2034,
358,
272,
327,
7635,
1865,
402,
6497,
272,
485,
4712,
63,
1606,
63,
1247,
360,
7147,
297,
283,
4699,
358,
421,
199,
32,
2926,
8,
85,
1133,
426,
2955,
6497,
787,
308,
28986,
9988,
199,
318,
2955,
63,
5856,
63,
1530,
63,
83,
28986,
8,
2926,
304,
272,
485,
4712,
63,
1606,
63,
1247,
360,
4699,
297,
283,
7147,
358,
421,
199,
318,
485,
4712,
63,
1606,
63,
1247,
8,
2246,
12,
3499,
304,
272,
6701,
14,
2573,
63,
509,
8,
267,
2562,
29,
2734,
24700,
822,
8,
7617,
14,
3919,
63,
1623,
5175,
14293,
63,
9278,
7690,
2377,
1333,
508,
499,
12,
267,
2653,
29,
1840,
12,
267,
2653,
63,
1328,
628,
28682,
734,
10923,
367,
2877,
6497,
370,
506,
3451,
2,
272,
776,
272,
6497,
275,
6701,
14,
3919,
63,
1623,
5175,
14293,
63,
9278,
7690,
2377,
358,
272,
702,
63,
1452,
8,
5856,
59,
16,
1055,
505,
12,
1642,
9,
272,
702,
63,
1452,
8,
5856,
59,
17,
1055,
505,
12,
3499,
9,
421,
199,
32,
2926,
8,
85,
1133,
426,
6137,
13,
262,
6497,
787,
315,
314,
849,
1865,
9988,
199,
318,
6137,
63,
262,
63,
5856,
63,
262,
63,
885,
63,
1648,
8,
2926,
304,
272,
1420,
63,
5856,
275,
788,
12054,
297,
283,
6979,
297,
283,
26198,
297,
283,
11504,
418,
272,
1937,
63,
5856,
63,
262,
63,
2062,
63,
1648,
8,
2062,
63,
5856,
9,
421,
199,
32,
2926,
8,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
BigBrother1984/android_external_chromium_org
|
chrome_frame/combine_libs.py
|
79
|
3272
|
#!/usr/bin/env python
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# TODO(slightlyoff): move to using shared version of this script.
'''This script makes it easy to combine libs and object files to a new lib,
optionally removing some of the object files in the input libs by regular
expression matching.
For usage information, run the script with a --help argument.
'''
import optparse
import os
import re
import subprocess
import sys
def Shell(*args):
'''Runs the program and args in args, returns the output from the program.'''
process = subprocess.Popen(args,
stdin = None,
stdout = subprocess.PIPE,
stderr = subprocess.STDOUT)
output = process.stdout.readlines()
process.wait()
retcode = process.returncode
if retcode != 0:
raise RuntimeError('%s exited with status %d' % (args[0], retcode))
return output
def CollectRemovals(remove_re, inputs):
'''Returns a list of all object files in inputs that match remove_re.'''
removals = []
for input in inputs:
output = Shell('lib.exe', '/list', input)
for line in output:
line = line.rstrip()
if remove_re.search(line):
removals.append(line)
return removals
def CombineLibraries(output, remove_re, inputs):
'''Combines all the libraries and objects in inputs, while removing any
object files that match remove_re.
'''
removals = []
if remove_re:
removals = CollectRemovals(remove_re, inputs)
print removals
args = ['lib.exe', '/out:%s' % output]
args += ['/remove:%s' % obj for obj in removals]
args += inputs
Shell(*args)
USAGE = '''usage: %prog [options] <lib or obj>+
Combines input libraries or objects into an output library, while removing
any object file (in the input libraries) that matches a given regular
expression.
'''
def GetOptionParser():
parser = optparse.OptionParser(USAGE)
parser.add_option('-o', '--output', dest = 'output',
help = 'write to this output library')
parser.add_option('-r', '--remove', dest = 'remove',
help = 'object files matching this regexp will be removed '
'from the output library')
return parser
def Main():
'''Main function for this script'''
parser = GetOptionParser()
(opt, args) = parser.parse_args()
output = opt.output
remove = opt.remove
if not output:
parser.error('You must specify an output file')
if not args:
parser.error('You must specify at least one object or library')
output = output.strip()
remove = remove.strip()
if remove:
try:
remove_re = re.compile(opt.remove)
except:
parser.error('%s is not a valid regular expression' % opt.remove)
else:
remove_re = None
if sys.platform != 'win32' and sys.platform != 'cygwin':
parser.error('this script only works on Windows for now')
# If this is set, we can't capture lib.exe's output.
if 'VS_UNICODE_OUTPUT' in os.environ:
del os.environ['VS_UNICODE_OUTPUT']
CombineLibraries(output, remove_re, args)
return 0
if __name__ == '__main__':
sys.exit(Main())
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
7760,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
3,
3254,
8,
83,
4040,
590,
1997,
304,
4057,
370,
1808,
5709,
1015,
402,
642,
2884,
14,
199,
199,
2344,
2765,
2884,
7704,
652,
8837,
370,
13323,
20314,
436,
909,
1584,
370,
282,
892,
1973,
12,
199,
1422,
1183,
12881,
2005,
402,
314,
909,
1584,
315,
314,
1324,
20314,
701,
5578,
199,
5599,
4877,
14,
199,
1858,
4503,
2556,
12,
1255,
314,
2884,
543,
282,
1553,
3437,
1423,
14,
199,
2344,
199,
646,
8691,
199,
646,
747,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
421,
199,
318,
24599,
2031,
589,
304,
523,
1449,
16291,
314,
2240,
436,
1249,
315,
1249,
12,
2529,
314,
1072,
687,
314,
2240,
10595,
523,
2112,
275,
3873,
14,
7942,
8,
589,
12,
2490,
9009,
275,
488,
12,
2490,
3839,
275,
3873,
14,
6089,
12,
2490,
4635,
275,
3873,
14,
13850,
9,
523,
1072,
275,
2112,
14,
2703,
14,
9684,
342,
523,
2112,
14,
2573,
342,
523,
17375,
275,
2112,
14,
9913,
523,
340,
17375,
1137,
378,
26,
272,
746,
6064,
3508,
83,
22987,
543,
2004,
450,
68,
7,
450,
334,
589,
59,
16,
467,
17375,
430,
523,
372,
1072,
421,
199,
318,
19649,
497,
573,
3643,
8,
2168,
63,
264,
12,
4153,
304,
523,
1449,
3407,
282,
769,
402,
1006,
909,
1584,
315,
4153,
626,
1336,
2813,
63,
264,
10595,
523,
32178,
3643,
275,
942,
523,
367,
1324,
315,
4153,
26,
272,
1072,
275,
24599,
360,
773,
14,
5803,
297,
1994,
513,
297,
1324,
9,
339,
367,
1004,
315,
1072,
26,
489,
1004,
275,
1004,
14,
6735,
342,
489,
340,
2813,
63,
264,
14,
1733,
8,
604,
304,
267,
32178,
3643,
14,
740,
8,
604,
9,
819,
372,
32178,
3643,
421,
199,
318,
26353,
23624,
8,
1199,
12,
2813,
63,
264,
12,
4153,
304,
523,
1449,
17039,
397,
1006,
314,
8363,
436,
2251,
315,
4153,
12,
1830,
12881,
1263,
523,
909,
1584,
626,
1336,
2813,
63,
264,
14,
523,
1449,
523,
32178,
3643,
275,
942,
523,
340,
2813,
63,
264,
26,
272,
32178,
3643,
275,
19649,
497,
573,
3643,
8,
2168,
63,
264,
12,
4153,
9,
819,
870,
32178,
3643,
819,
1249,
275,
788,
773,
14,
5803,
297,
1994,
548,
2689,
83,
7,
450,
1072,
61,
523,
1249,
847,
18744,
2168,
2689,
83,
7,
450,
1559,
367,
1559,
315,
32178,
3643,
61,
523,
1249,
847,
4153,
523,
24599,
2031,
589,
9,
421,
199,
20274,
275,
1449,
3807,
26,
450,
6595,
359,
1419,
61,
665,
773,
503,
1559,
30,
11,
199,
199,
17039,
397,
1324,
8363,
503,
2251,
1901,
376,
1072,
3555,
12,
1830,
12881,
199,
1629,
909,
570,
334,
262,
314,
1324,
8363,
9,
626,
4450,
282,
1627,
5578,
199,
5599,
14,
199,
2344,
199,
199,
318,
2372,
14553,
837,
523,
1798,
275,
8691,
14,
14553,
8,
20274,
9,
523,
1798,
14,
525,
63,
1422,
3654,
79,
297,
2850,
1199,
297,
2053,
275,
283,
1199,
297,
490,
1720,
275,
283,
952,
370,
642,
1072,
3555,
358,
523,
1798,
14,
525,
63,
1422,
3654,
82,
297,
2850,
2168,
297,
2053,
275,
283,
2168,
297,
490,
1720,
275,
283,
785,
1584,
4877,
642,
13156,
911,
506,
4829,
283,
1169,
283,
504,
314,
1072,
3555,
358,
523,
372,
1798,
421,
199,
318,
11298,
837,
523,
1449,
6756,
805,
367,
642,
2884,
2344,
523,
1798,
275,
2372,
14553,
342,
523,
334,
2992,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
342,
523,
1072,
275,
2450,
14,
1199,
523,
2813,
275,
2450,
14,
2168,
523,
340,
440,
1072,
26,
272,
1798,
14,
705,
360,
5556,
1471,
4165,
376,
1072,
570,
358,
819,
340,
440,
1249,
26,
272,
1798,
14,
705,
360,
5556,
1471,
4165,
737,
5210,
1373,
909,
503,
3555,
358,
819,
1072,
275,
1072,
14,
1913,
342,
523,
2813,
275,
2813,
14,
1913,
342,
819,
340,
2813,
26,
272,
862,
26,
489,
2813,
63,
264,
275,
295,
14,
2014,
8,
2992,
14,
2168,
9,
272,
871,
26,
489,
1798,
14,
705,
3508,
83,
365,
440,
282,
1686,
5578,
3965,
7,
450,
2450,
14,
2168,
9,
523,
587,
26,
272,
2813,
63,
264,
275,
488,
819,
340,
984,
14,
3246,
1137,
283,
2676,
708,
7,
436,
984,
14,
3246,
1137,
283,
16680,
356,
272,
1798,
14,
705,
360,
3749,
2884,
1454,
5419,
641,
5417,
367,
3063,
358,
819,
327,
982,
642,
365,
663,
12,
781,
883,
1133,
12296,
1973,
14,
5803,
1159,
1072,
14,
523,
340,
283,
7428,
63,
12819,
63,
8414,
7,
315,
747,
14,
2314,
26,
272,
2150,
747,
14,
2314,
459,
7428,
63,
12819,
63,
8414,
418,
819,
26353,
23624,
8,
1199,
12,
2813,
63,
264,
12,
1249,
9,
523,
372,
378,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
984,
14,
2224,
8,
6756,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
7760,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
3,
3254,
8,
83,
4040,
590,
1997,
304,
4057,
370,
1808,
5709,
1015,
402,
642,
2884,
14,
199,
199,
2344,
2765,
2884,
7704,
652,
8837,
370,
13323,
20314,
436,
909,
1584,
370,
282,
892,
1973,
12,
199,
1422,
1183,
12881,
2005,
402,
314,
909,
1584,
315,
314,
1324,
20314,
701,
5578,
199,
5599,
4877,
14,
199,
1858,
4503,
2556,
12,
1255,
314,
2884,
543,
282,
1553,
3437,
1423,
14,
199,
2344,
199,
646,
8691,
199,
646,
747,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
421,
199,
318,
24599,
2031,
589,
304,
523,
1449,
16291,
314,
2240,
436,
1249,
315,
1249,
12,
2529,
314,
1072,
687,
314,
2240,
10595,
523,
2112,
275,
3873,
14,
7942,
8,
589,
12,
2490,
9009,
275,
488,
12,
2490,
3839,
275,
3873,
14,
6089,
12,
2490,
4635,
275,
3873,
14,
13850,
9,
523,
1072,
275,
2112,
14,
2703,
14,
9684,
342,
523,
2112,
14,
2573,
342,
523,
17375,
275,
2112,
14,
9913,
523,
340,
17375,
1137,
378,
26,
272,
746,
6064,
3508,
83,
22987,
543,
2004,
450,
68,
7,
450,
334,
589,
59,
16,
467,
17375,
430,
523,
372,
1072,
421,
199,
318,
19649,
497,
573,
3643,
8,
2168,
63,
264,
12,
4153,
304,
523,
1449,
3407,
282,
769,
402,
1006,
909,
1584,
315,
4153,
626,
1336,
2813,
63,
264,
10595,
523,
32178,
3643,
275,
942,
523,
367,
1324,
315,
4153,
26,
272,
1072,
275,
24599,
360,
773,
14,
5803,
297,
1994,
513,
297,
1324,
9,
339,
367,
1004,
315,
1072,
26,
489,
1004,
275,
1004,
14,
6735,
342,
489,
340,
2813,
63,
264,
14,
1733,
8,
604,
304,
267,
32178,
3643,
14,
740,
8,
604,
9,
819,
372,
32178,
3643,
421,
199,
318,
26353,
23624,
8,
1199,
12,
2813,
63,
264,
12,
4153,
304,
523,
1449,
17039,
397,
1006,
314,
8363,
436,
2251,
315,
4153,
12,
1830,
12881,
1263,
523,
909,
1584,
626,
1336,
2813,
63,
264,
14,
523,
1449,
523,
32178,
3643,
275,
942,
523,
340,
2813,
63,
264,
26,
272,
32178,
3643,
275,
19649,
497,
573,
3643,
8,
2168,
63,
264,
12,
4153,
9,
819,
870,
32178,
3643,
819,
1249,
275,
788,
773,
14,
5803,
297,
1994,
548,
2689,
83,
7,
450,
1072,
61,
523,
1249,
847,
18744,
2168,
2689,
83,
7,
450,
1559,
367,
1559,
315,
32178,
3643,
61,
523,
1249,
847,
4153,
523,
24599,
2031,
589,
9,
421,
199,
20274,
275,
1449,
3807,
26,
450,
6595,
359,
1419,
61,
665,
773,
503,
1559,
30,
11,
199,
199,
17039,
397,
1324,
8363,
503,
2251,
1901,
376,
1072,
3555,
12,
1830,
12881,
199,
1629,
909,
570,
334,
262,
314,
1324,
8363,
9,
626,
4450,
282,
1627,
5578,
199,
5599,
14,
199,
2344,
199,
199,
318,
2372,
14553,
837,
523,
1798,
275,
8691,
14,
14553,
8,
20274,
9,
523,
1798,
14,
525,
63,
1422,
3654,
79,
297,
2850,
1199,
297,
2053,
275,
283,
1199,
297,
490,
1720,
275,
283,
952,
370,
642,
1072,
3555,
358,
523,
1798,
14,
525,
63,
1422,
3654,
82,
297,
2850,
2168,
297,
2053,
275,
283,
2168,
297,
490,
1720,
275,
283,
785,
1584,
4877,
642,
13156,
911,
506,
4829,
283,
1169,
283,
504,
314,
1072,
3555,
358,
523,
372,
1798,
421,
199,
318,
11298,
837,
523,
1449,
6756,
805,
367,
642,
2884,
2344,
523,
1798,
275,
2372,
14553,
342,
523,
334,
2992,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
342,
523,
1072,
275,
2450,
14,
1199,
523,
2813,
275,
2450,
14,
2168,
523,
340,
440,
1072,
26,
272,
1798,
14,
705,
360,
5556,
1471,
4165,
376,
1072,
570,
358,
819,
340,
440,
1249,
26,
272,
1798,
14,
705,
360,
5556,
1471,
4165,
737,
5210,
1373,
909,
503,
3555,
358,
819,
1072,
275,
1072,
14,
1913,
342,
523,
2813,
275,
2813,
14,
1913,
342,
819,
340,
2813,
26,
272,
862,
26,
489,
2813,
63,
264,
275,
295,
14,
2014,
8,
2992,
14,
2168,
9,
272,
871,
26,
489,
1798,
14,
705,
3508,
83,
365,
440,
282,
1686,
5578,
3965,
7,
450,
2450,
14,
2168,
9,
523,
587,
26,
272,
2813,
63,
264,
275,
488,
819,
340,
984,
14,
3246,
1137,
283,
2676,
708,
7,
436,
984,
14,
3246,
1137,
283,
16680,
356,
272,
1798,
14,
705,
360,
3749,
2884,
1454,
5419,
641,
5417,
367,
3063,
358,
819,
327,
982,
642,
365,
663,
12,
781,
883,
1133,
12296,
1973,
14,
5803,
1159,
1072,
14,
523,
340,
283,
7428,
63,
12819,
63,
8414,
7,
315,
747,
14,
2314,
26,
272,
2150,
747,
14,
2314,
459,
7428,
63,
12819,
63,
8414,
418,
819,
26353,
23624,
8,
1199,
12,
2813,
63,
264,
12,
1249,
9,
523,
372,
378,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
984,
14,
2224,
8,
6756,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
pniedzielski/fb-hackathon-2013-11-21
|
src/repl.it/jsrepl/extern/python/reloop-closured/lib/python2.7/distutils/msvccompiler.py
|
250
|
23637
|
"""distutils.msvccompiler
Contains MSVCCompiler, an implementation of the abstract CCompiler class
for the Microsoft Visual Studio.
"""
# Written by Perry Stoll
# hacked by Robin Becker and Thomas Heller to do a better job of
# finding DevStudio (through the registry)
__revision__ = "$Id$"
import sys
import os
import string
from distutils.errors import (DistutilsExecError, DistutilsPlatformError,
CompileError, LibError, LinkError)
from distutils.ccompiler import CCompiler, gen_lib_options
from distutils import log
_can_read_reg = 0
try:
import _winreg
_can_read_reg = 1
hkey_mod = _winreg
RegOpenKeyEx = _winreg.OpenKeyEx
RegEnumKey = _winreg.EnumKey
RegEnumValue = _winreg.EnumValue
RegError = _winreg.error
except ImportError:
try:
import win32api
import win32con
_can_read_reg = 1
hkey_mod = win32con
RegOpenKeyEx = win32api.RegOpenKeyEx
RegEnumKey = win32api.RegEnumKey
RegEnumValue = win32api.RegEnumValue
RegError = win32api.error
except ImportError:
log.info("Warning: Can't read registry to find the "
"necessary compiler setting\n"
"Make sure that Python modules _winreg, "
"win32api or win32con are installed.")
pass
if _can_read_reg:
HKEYS = (hkey_mod.HKEY_USERS,
hkey_mod.HKEY_CURRENT_USER,
hkey_mod.HKEY_LOCAL_MACHINE,
hkey_mod.HKEY_CLASSES_ROOT)
def read_keys(base, key):
"""Return list of registry keys."""
try:
handle = RegOpenKeyEx(base, key)
except RegError:
return None
L = []
i = 0
while 1:
try:
k = RegEnumKey(handle, i)
except RegError:
break
L.append(k)
i = i + 1
return L
def read_values(base, key):
"""Return dict of registry keys and values.
All names are converted to lowercase.
"""
try:
handle = RegOpenKeyEx(base, key)
except RegError:
return None
d = {}
i = 0
while 1:
try:
name, value, type = RegEnumValue(handle, i)
except RegError:
break
name = name.lower()
d[convert_mbcs(name)] = convert_mbcs(value)
i = i + 1
return d
def convert_mbcs(s):
enc = getattr(s, "encode", None)
if enc is not None:
try:
s = enc("mbcs")
except UnicodeError:
pass
return s
class MacroExpander:
def __init__(self, version):
self.macros = {}
self.load_macros(version)
def set_macro(self, macro, path, key):
for base in HKEYS:
d = read_values(base, path)
if d:
self.macros["$(%s)" % macro] = d[key]
break
def load_macros(self, version):
vsbase = r"Software\Microsoft\VisualStudio\%0.1f" % version
self.set_macro("VCInstallDir", vsbase + r"\Setup\VC", "productdir")
self.set_macro("VSInstallDir", vsbase + r"\Setup\VS", "productdir")
net = r"Software\Microsoft\.NETFramework"
self.set_macro("FrameworkDir", net, "installroot")
try:
if version > 7.0:
self.set_macro("FrameworkSDKDir", net, "sdkinstallrootv1.1")
else:
self.set_macro("FrameworkSDKDir", net, "sdkinstallroot")
except KeyError:
raise DistutilsPlatformError, \
("""Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible binaries.
Visual Studio 2003 was not found on this system. If you have Cygwin installed,
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.""")
p = r"Software\Microsoft\NET Framework Setup\Product"
for base in HKEYS:
try:
h = RegOpenKeyEx(base, p)
except RegError:
continue
key = RegEnumKey(h, 0)
d = read_values(base, r"%s\%s" % (p, key))
self.macros["$(FrameworkVersion)"] = d["version"]
def sub(self, s):
for k, v in self.macros.items():
s = string.replace(s, k, v)
return s
def get_build_version():
"""Return the version of MSVC that was used to build Python.
For Python 2.3 and up, the version number is included in
sys.version. For earlier versions, assume the compiler is MSVC 6.
"""
prefix = "MSC v."
i = string.find(sys.version, prefix)
if i == -1:
return 6
i = i + len(prefix)
s, rest = sys.version[i:].split(" ", 1)
majorVersion = int(s[:-2]) - 6
minorVersion = int(s[2:3]) / 10.0
# I don't think paths are affected by minor version in version 6
if majorVersion == 6:
minorVersion = 0
if majorVersion >= 6:
return majorVersion + minorVersion
# else we don't know what version of the compiler this is
return None
def get_build_architecture():
"""Return the processor architecture.
Possible results are "Intel", "Itanium", or "AMD64".
"""
prefix = " bit ("
i = string.find(sys.version, prefix)
if i == -1:
return "Intel"
j = string.find(sys.version, ")", i)
return sys.version[i+len(prefix):j]
def normalize_and_reduce_paths(paths):
"""Return a list of normalized paths with duplicates removed.
The current order of paths is maintained.
"""
# Paths are normalized so things like: /a and /a/ aren't both preserved.
reduced_paths = []
for p in paths:
np = os.path.normpath(p)
# XXX(nnorwitz): O(n**2), if reduced_paths gets long perhaps use a set.
if np not in reduced_paths:
reduced_paths.append(np)
return reduced_paths
class MSVCCompiler (CCompiler) :
"""Concrete class that implements an interface to Microsoft Visual C++,
as defined by the CCompiler abstract class."""
compiler_type = 'msvc'
# Just set this so CCompiler's constructor doesn't barf. We currently
# don't use the 'set_executables()' bureaucracy provided by CCompiler,
# as it really isn't necessary for this sort of single-compiler class.
# Would be nice to have a consistent interface with UnixCCompiler,
# though, so it's worth thinking about.
executables = {}
# Private class data (need to distinguish C from C++ source for compiler)
_c_extensions = ['.c']
_cpp_extensions = ['.cc', '.cpp', '.cxx']
_rc_extensions = ['.rc']
_mc_extensions = ['.mc']
# Needed for the filename generation methods provided by the
# base class, CCompiler.
src_extensions = (_c_extensions + _cpp_extensions +
_rc_extensions + _mc_extensions)
res_extension = '.res'
obj_extension = '.obj'
static_lib_extension = '.lib'
shared_lib_extension = '.dll'
static_lib_format = shared_lib_format = '%s%s'
exe_extension = '.exe'
def __init__ (self, verbose=0, dry_run=0, force=0):
CCompiler.__init__ (self, verbose, dry_run, force)
self.__version = get_build_version()
self.__arch = get_build_architecture()
if self.__arch == "Intel":
# x86
if self.__version >= 7:
self.__root = r"Software\Microsoft\VisualStudio"
self.__macros = MacroExpander(self.__version)
else:
self.__root = r"Software\Microsoft\Devstudio"
self.__product = "Visual Studio version %s" % self.__version
else:
# Win64. Assume this was built with the platform SDK
self.__product = "Microsoft SDK compiler %s" % (self.__version + 6)
self.initialized = False
def initialize(self):
self.__paths = []
if "DISTUTILS_USE_SDK" in os.environ and "MSSdk" in os.environ and self.find_exe("cl.exe"):
# Assume that the SDK set up everything alright; don't try to be
# smarter
self.cc = "cl.exe"
self.linker = "link.exe"
self.lib = "lib.exe"
self.rc = "rc.exe"
self.mc = "mc.exe"
else:
self.__paths = self.get_msvc_paths("path")
if len (self.__paths) == 0:
raise DistutilsPlatformError, \
("Python was built with %s, "
"and extensions need to be built with the same "
"version of the compiler, but it isn't installed." % self.__product)
self.cc = self.find_exe("cl.exe")
self.linker = self.find_exe("link.exe")
self.lib = self.find_exe("lib.exe")
self.rc = self.find_exe("rc.exe") # resource compiler
self.mc = self.find_exe("mc.exe") # message compiler
self.set_path_env_var('lib')
self.set_path_env_var('include')
# extend the MSVC path with the current path
try:
for p in string.split(os.environ['path'], ';'):
self.__paths.append(p)
except KeyError:
pass
self.__paths = normalize_and_reduce_paths(self.__paths)
os.environ['path'] = string.join(self.__paths, ';')
self.preprocess_options = None
if self.__arch == "Intel":
self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3', '/GX' ,
'/DNDEBUG']
self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GX',
'/Z7', '/D_DEBUG']
else:
# Win64
self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3', '/GS-' ,
'/DNDEBUG']
self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GS-',
'/Z7', '/D_DEBUG']
self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO']
if self.__version >= 7:
self.ldflags_shared_debug = [
'/DLL', '/nologo', '/INCREMENTAL:no', '/DEBUG'
]
else:
self.ldflags_shared_debug = [
'/DLL', '/nologo', '/INCREMENTAL:no', '/pdb:None', '/DEBUG'
]
self.ldflags_static = [ '/nologo']
self.initialized = True
# -- Worker methods ------------------------------------------------
def object_filenames (self,
source_filenames,
strip_dir=0,
output_dir=''):
# Copied from ccompiler.py, extended to return .res as 'object'-file
# for .rc input file
if output_dir is None: output_dir = ''
obj_names = []
for src_name in source_filenames:
(base, ext) = os.path.splitext (src_name)
base = os.path.splitdrive(base)[1] # Chop off the drive
base = base[os.path.isabs(base):] # If abs, chop off leading /
if ext not in self.src_extensions:
# Better to raise an exception instead of silently continuing
# and later complain about sources and targets having
# different lengths
raise CompileError ("Don't know how to compile %s" % src_name)
if strip_dir:
base = os.path.basename (base)
if ext in self._rc_extensions:
obj_names.append (os.path.join (output_dir,
base + self.res_extension))
elif ext in self._mc_extensions:
obj_names.append (os.path.join (output_dir,
base + self.res_extension))
else:
obj_names.append (os.path.join (output_dir,
base + self.obj_extension))
return obj_names
# object_filenames ()
def compile(self, sources,
output_dir=None, macros=None, include_dirs=None, debug=0,
extra_preargs=None, extra_postargs=None, depends=None):
if not self.initialized: self.initialize()
macros, objects, extra_postargs, pp_opts, build = \
self._setup_compile(output_dir, macros, include_dirs, sources,
depends, extra_postargs)
compile_opts = extra_preargs or []
compile_opts.append ('/c')
if debug:
compile_opts.extend(self.compile_options_debug)
else:
compile_opts.extend(self.compile_options)
for obj in objects:
try:
src, ext = build[obj]
except KeyError:
continue
if debug:
# pass the full pathname to MSVC in debug mode,
# this allows the debugger to find the source file
# without asking the user to browse for it
src = os.path.abspath(src)
if ext in self._c_extensions:
input_opt = "/Tc" + src
elif ext in self._cpp_extensions:
input_opt = "/Tp" + src
elif ext in self._rc_extensions:
# compile .RC to .RES file
input_opt = src
output_opt = "/fo" + obj
try:
self.spawn ([self.rc] + pp_opts +
[output_opt] + [input_opt])
except DistutilsExecError, msg:
raise CompileError, msg
continue
elif ext in self._mc_extensions:
# Compile .MC to .RC file to .RES file.
# * '-h dir' specifies the directory for the
# generated include file
# * '-r dir' specifies the target directory of the
# generated RC file and the binary message resource
# it includes
#
# For now (since there are no options to change this),
# we use the source-directory for the include file and
# the build directory for the RC file and message
# resources. This works at least for win32all.
h_dir = os.path.dirname (src)
rc_dir = os.path.dirname (obj)
try:
# first compile .MC to .RC and .H file
self.spawn ([self.mc] +
['-h', h_dir, '-r', rc_dir] + [src])
base, _ = os.path.splitext (os.path.basename (src))
rc_file = os.path.join (rc_dir, base + '.rc')
# then compile .RC to .RES file
self.spawn ([self.rc] +
["/fo" + obj] + [rc_file])
except DistutilsExecError, msg:
raise CompileError, msg
continue
else:
# how to handle this file?
raise CompileError (
"Don't know how to compile %s to %s" % \
(src, obj))
output_opt = "/Fo" + obj
try:
self.spawn ([self.cc] + compile_opts + pp_opts +
[input_opt, output_opt] +
extra_postargs)
except DistutilsExecError, msg:
raise CompileError, msg
return objects
# compile ()
def create_static_lib (self,
objects,
output_libname,
output_dir=None,
debug=0,
target_lang=None):
if not self.initialized: self.initialize()
(objects, output_dir) = self._fix_object_args (objects, output_dir)
output_filename = \
self.library_filename (output_libname, output_dir=output_dir)
if self._need_link (objects, output_filename):
lib_args = objects + ['/OUT:' + output_filename]
if debug:
pass # XXX what goes here?
try:
self.spawn ([self.lib] + lib_args)
except DistutilsExecError, msg:
raise LibError, msg
else:
log.debug("skipping %s (up-to-date)", output_filename)
# create_static_lib ()
def link (self,
target_desc,
objects,
output_filename,
output_dir=None,
libraries=None,
library_dirs=None,
runtime_library_dirs=None,
export_symbols=None,
debug=0,
extra_preargs=None,
extra_postargs=None,
build_temp=None,
target_lang=None):
if not self.initialized: self.initialize()
(objects, output_dir) = self._fix_object_args (objects, output_dir)
(libraries, library_dirs, runtime_library_dirs) = \
self._fix_lib_args (libraries, library_dirs, runtime_library_dirs)
if runtime_library_dirs:
self.warn ("I don't know what to do with 'runtime_library_dirs': "
+ str (runtime_library_dirs))
lib_opts = gen_lib_options (self,
library_dirs, runtime_library_dirs,
libraries)
if output_dir is not None:
output_filename = os.path.join (output_dir, output_filename)
if self._need_link (objects, output_filename):
if target_desc == CCompiler.EXECUTABLE:
if debug:
ldflags = self.ldflags_shared_debug[1:]
else:
ldflags = self.ldflags_shared[1:]
else:
if debug:
ldflags = self.ldflags_shared_debug
else:
ldflags = self.ldflags_shared
export_opts = []
for sym in (export_symbols or []):
export_opts.append("/EXPORT:" + sym)
ld_args = (ldflags + lib_opts + export_opts +
objects + ['/OUT:' + output_filename])
# The MSVC linker generates .lib and .exp files, which cannot be
# suppressed by any linker switches. The .lib files may even be
# needed! Make sure they are generated in the temporary build
# directory. Since they have different names for debug and release
# builds, they can go into the same directory.
if export_symbols is not None:
(dll_name, dll_ext) = os.path.splitext(
os.path.basename(output_filename))
implib_file = os.path.join(
os.path.dirname(objects[0]),
self.library_filename(dll_name))
ld_args.append ('/IMPLIB:' + implib_file)
if extra_preargs:
ld_args[:0] = extra_preargs
if extra_postargs:
ld_args.extend(extra_postargs)
self.mkpath (os.path.dirname (output_filename))
try:
self.spawn ([self.linker] + ld_args)
except DistutilsExecError, msg:
raise LinkError, msg
else:
log.debug("skipping %s (up-to-date)", output_filename)
# link ()
# -- Miscellaneous methods -----------------------------------------
# These are all used by the 'gen_lib_options() function, in
# ccompiler.py.
def library_dir_option (self, dir):
return "/LIBPATH:" + dir
def runtime_library_dir_option (self, dir):
raise DistutilsPlatformError, \
"don't know how to set runtime library search path for MSVC++"
def library_option (self, lib):
return self.library_filename (lib)
def find_library_file (self, dirs, lib, debug=0):
# Prefer a debugging library if found (and requested), but deal
# with it if we don't have one.
if debug:
try_names = [lib + "_d", lib]
else:
try_names = [lib]
for dir in dirs:
for name in try_names:
libfile = os.path.join(dir, self.library_filename (name))
if os.path.exists(libfile):
return libfile
else:
# Oops, didn't find it in *any* of 'dirs'
return None
# find_library_file ()
# Helper methods for using the MSVC registry settings
def find_exe(self, exe):
"""Return path to an MSVC executable program.
Tries to find the program in several places: first, one of the
MSVC program search paths from the registry; next, the directories
in the PATH environment variable. If any of those work, return an
absolute path that is known to exist. If none of them work, just
return the original program name, 'exe'.
"""
for p in self.__paths:
fn = os.path.join(os.path.abspath(p), exe)
if os.path.isfile(fn):
return fn
# didn't find it; try existing path
for p in string.split(os.environ['Path'],';'):
fn = os.path.join(os.path.abspath(p),exe)
if os.path.isfile(fn):
return fn
return exe
def get_msvc_paths(self, path, platform='x86'):
"""Get a list of devstudio directories (include, lib or path).
Return a list of strings. The list will be empty if unable to
access the registry or appropriate registry keys not found.
"""
if not _can_read_reg:
return []
path = path + " dirs"
if self.__version >= 7:
key = (r"%s\%0.1f\VC\VC_OBJECTS_PLATFORM_INFO\Win32\Directories"
% (self.__root, self.__version))
else:
key = (r"%s\6.0\Build System\Components\Platforms"
r"\Win32 (%s)\Directories" % (self.__root, platform))
for base in HKEYS:
d = read_values(base, key)
if d:
if self.__version >= 7:
return string.split(self.__macros.sub(d[path]), ";")
else:
return string.split(d[path], ";")
# MSVC 6 seems to create the registry entries we need only when
# the GUI is run.
if self.__version == 6:
for base in HKEYS:
if read_values(base, r"%s\6.0" % self.__root) is not None:
self.warn("It seems you have Visual Studio 6 installed, "
"but the expected registry settings are not present.\n"
"You must at least run the Visual Studio GUI once "
"so that these entries are created.")
break
return []
def set_path_env_var(self, name):
"""Set environment variable 'name' to an MSVC path type value.
This is equivalent to a SET command prior to execution of spawned
commands.
"""
if name == "lib":
p = self.get_msvc_paths("library")
else:
p = self.get_msvc_paths(name)
if p:
os.environ[name] = string.join(p, ';')
if get_build_version() >= 8.0:
log.debug("Importing new compiler from distutils.msvc9compiler")
OldMSVCCompiler = MSVCCompiler
from distutils.msvc9compiler import MSVCCompiler
# get_build_architecture not really relevant now we support cross-compile
from distutils.msvc9compiler import MacroExpander
|
agpl-3.0
|
[
624,
13350,
14,
19875,
5772,
199,
199,
6906,
11694,
30926,
12,
376,
4514,
402,
314,
9006,
445,
9131,
1021,
199,
509,
314,
15332,
14702,
13225,
14,
199,
624,
199,
199,
3,
27694,
701,
3492,
651,
1933,
14385,
199,
3,
11176,
379,
701,
6848,
1393,
6423,
22043,
436,
27864,
869,
352,
1435,
370,
886,
282,
8034,
3906,
402,
199,
3,
257,
17196,
29314,
21025,
334,
8304,
314,
7086,
9,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
646,
984,
199,
646,
747,
199,
646,
1059,
199,
199,
504,
7065,
14,
2550,
492,
334,
12012,
1208,
4858,
547,
12,
12577,
10397,
547,
12,
2892,
24562,
547,
12,
8003,
547,
12,
10967,
547,
9,
199,
504,
7065,
14,
67,
5772,
492,
445,
9131,
12,
3805,
63,
773,
63,
1419,
199,
504,
7065,
492,
943,
199,
199,
63,
2425,
63,
739,
63,
1135,
275,
378,
199,
893,
26,
272,
492,
485,
15658,
339,
485,
2425,
63,
739,
63,
1135,
275,
413,
272,
394,
498,
63,
1494,
275,
485,
15658,
339,
5044,
28144,
920,
275,
485,
15658,
14,
28144,
920,
272,
5044,
5081,
1197,
275,
485,
15658,
14,
5081,
1197,
272,
5044,
14432,
275,
485,
15658,
14,
14432,
272,
5044,
547,
275,
485,
15658,
14,
705,
199,
199,
2590,
3545,
26,
272,
862,
26,
267,
492,
4747,
708,
1246,
267,
492,
4747,
708,
388,
267,
485,
2425,
63,
739,
63,
1135,
275,
413,
267,
394,
498,
63,
1494,
275,
4747,
708,
388,
398,
5044,
28144,
920,
275,
4747,
708,
1246,
14,
2872,
28144,
920,
267,
5044,
5081,
1197,
275,
4747,
708,
1246,
14,
2872,
5081,
1197,
267,
5044,
14432,
275,
4747,
708,
1246,
14,
2872,
14432,
267,
5044,
547,
275,
4747,
708,
1246,
14,
705,
339,
871,
3545,
26,
267,
943,
14,
815,
480,
3849,
26,
6855,
1133,
1586,
7086,
370,
2342,
314,
298,
326,
298,
17927,
6365,
4260,
60,
78,
2,
326,
298,
5483,
3238,
626,
2018,
4621,
485,
15658,
12,
298,
326,
298,
2676,
708,
1246,
503,
4747,
708,
388,
787,
4903,
2685,
267,
986,
199,
199,
692,
485,
2425,
63,
739,
63,
1135,
26,
272,
869,
17434,
275,
334,
72,
498,
63,
1494,
14,
23802,
63,
28164,
12,
1467,
394,
498,
63,
1494,
14,
23802,
63,
14211,
63,
3791,
12,
1467,
394,
498,
63,
1494,
14,
23802,
63,
7486,
63,
20890,
12,
1467,
394,
498,
63,
1494,
14,
23802,
63,
13748,
63,
5441,
9,
199,
199,
318,
1586,
63,
1612,
8,
1095,
12,
790,
304,
272,
408,
1767,
769,
402,
7086,
2883,
1041,
339,
862,
26,
267,
2429,
275,
5044,
28144,
920,
8,
1095,
12,
790,
9,
272,
871,
5044,
547,
26,
267,
372,
488,
272,
491,
275,
942,
272,
284,
275,
378,
272,
1830,
413,
26,
267,
862,
26,
288,
1022,
275,
5044,
5081,
1197,
8,
2479,
12,
284,
9,
267,
871,
5044,
547,
26,
288,
2059,
267,
491,
14,
740,
8,
75,
9,
267,
284,
275,
284,
435,
413,
272,
372,
491,
199,
199,
318,
1586,
63,
1459,
8,
1095,
12,
790,
304,
272,
408,
1767,
1211,
402,
7086,
2883,
436,
1338,
14,
339,
2900,
1561,
787,
6702,
370,
12141,
14,
272,
408,
272,
862,
26,
267,
2429,
275,
5044,
28144,
920,
8,
1095,
12,
790,
9,
272,
871,
5044,
547,
26,
267,
372,
488,
272,
366,
275,
1052,
272,
284,
275,
378,
272,
1830,
413,
26,
267,
862,
26,
288,
536,
12,
574,
12,
730,
275,
5044,
14432,
8,
2479,
12,
284,
9,
267,
871,
5044,
547,
26,
288,
2059,
267,
536,
275,
536,
14,
2325,
342,
267,
366,
59,
3916,
63,
887,
1259,
8,
354,
1874,
275,
3957,
63,
887,
1259,
8,
585,
9,
267,
284,
275,
284,
435,
413,
272,
372,
366,
199,
199,
318,
3957,
63,
887,
1259,
8,
83,
304,
272,
12011,
275,
2519,
8,
83,
12,
298,
2143,
401,
488,
9,
272,
340,
12011,
365,
440,
488,
26,
267,
862,
26,
288,
308,
275,
12011,
480,
887,
1259,
531,
267,
871,
20872,
26,
288,
986,
272,
372,
308,
199,
199,
533,
10444,
293,
4527,
11438,
26,
339,
347,
636,
826,
721,
277,
12,
1015,
304,
267,
291,
14,
16358,
275,
1052,
267,
291,
14,
912,
63,
16358,
8,
1023,
9,
339,
347,
663,
63,
11300,
8,
277,
12,
9559,
12,
931,
12,
790,
304,
267,
367,
1300,
315,
869,
17434,
26,
288,
366,
275,
1586,
63,
1459,
8,
1095,
12,
931,
9,
288,
340,
366,
26,
355,
291,
14,
16358,
905,
4,
4042,
83,
2924,
450,
9559,
61,
275,
366,
59,
498,
61,
355,
2059,
339,
347,
2248,
63,
16358,
8,
277,
12,
1015,
304,
267,
8118,
1095,
275,
519,
2,
10337,
60,
12940,
60,
15039,
21025,
60,
5,
16,
14,
17,
70,
2,
450,
1015,
267,
291,
14,
409,
63,
11300,
480,
9454,
8154,
3567,
401,
8118,
1095,
435,
519,
3212,
8555,
60,
9454,
401,
298,
2558,
694,
531,
267,
291,
14,
409,
63,
11300,
480,
7428,
8154,
3567,
401,
8118,
1095,
435,
519,
3212,
8555,
60,
7428,
401,
298,
2558,
694,
531,
267,
1851,
275,
519,
2,
10337,
60,
12940,
4537,
7278,
16442,
2,
267,
291,
14,
409,
63,
11300,
480,
16442,
3567,
401,
1851,
12,
298,
3174,
1231,
531,
267,
862,
26,
288,
340,
1015,
690,
1520,
14,
16,
26,
355,
291,
14,
409,
63,
11300,
480,
16442,
14939,
3567,
401,
1851,
12,
298,
9277,
3174,
1231,
86,
17,
14,
17,
531,
288,
587,
26,
355,
291,
14,
409,
63,
11300,
480,
16442,
14939,
3567,
401,
1851,
12,
298,
9277,
3174,
1231,
531,
267,
871,
4067,
26,
288,
746,
12577,
10397,
547,
12,
971,
2116,
334,
624,
4718,
1990,
6137,
543,
14702,
13225,
13004,
27,
199,
5359,
1471,
506,
6137,
543,
282,
6365,
2419,
883,
3550,
9025,
21984,
14,
199,
15039,
13225,
13004,
1990,
440,
1911,
641,
642,
2656,
14,
982,
1265,
1172,
445,
18313,
4903,
12,
199,
13297,
883,
862,
1013,
5662,
543,
603,
316,
55,
708,
12,
701,
9476,
3905,
67,
333,
316,
87,
708,
2,
370,
3272,
14,
647,
24887,
398,
299,
275,
519,
2,
10337,
60,
12940,
60,
7278,
22545,
12439,
60,
5884,
2,
267,
367,
1300,
315,
869,
17434,
26,
288,
862,
26,
355,
394,
275,
5044,
28144,
920,
8,
1095,
12,
299,
9,
288,
871,
5044
] |
[
13350,
14,
19875,
5772,
199,
199,
6906,
11694,
30926,
12,
376,
4514,
402,
314,
9006,
445,
9131,
1021,
199,
509,
314,
15332,
14702,
13225,
14,
199,
624,
199,
199,
3,
27694,
701,
3492,
651,
1933,
14385,
199,
3,
11176,
379,
701,
6848,
1393,
6423,
22043,
436,
27864,
869,
352,
1435,
370,
886,
282,
8034,
3906,
402,
199,
3,
257,
17196,
29314,
21025,
334,
8304,
314,
7086,
9,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
646,
984,
199,
646,
747,
199,
646,
1059,
199,
199,
504,
7065,
14,
2550,
492,
334,
12012,
1208,
4858,
547,
12,
12577,
10397,
547,
12,
2892,
24562,
547,
12,
8003,
547,
12,
10967,
547,
9,
199,
504,
7065,
14,
67,
5772,
492,
445,
9131,
12,
3805,
63,
773,
63,
1419,
199,
504,
7065,
492,
943,
199,
199,
63,
2425,
63,
739,
63,
1135,
275,
378,
199,
893,
26,
272,
492,
485,
15658,
339,
485,
2425,
63,
739,
63,
1135,
275,
413,
272,
394,
498,
63,
1494,
275,
485,
15658,
339,
5044,
28144,
920,
275,
485,
15658,
14,
28144,
920,
272,
5044,
5081,
1197,
275,
485,
15658,
14,
5081,
1197,
272,
5044,
14432,
275,
485,
15658,
14,
14432,
272,
5044,
547,
275,
485,
15658,
14,
705,
199,
199,
2590,
3545,
26,
272,
862,
26,
267,
492,
4747,
708,
1246,
267,
492,
4747,
708,
388,
267,
485,
2425,
63,
739,
63,
1135,
275,
413,
267,
394,
498,
63,
1494,
275,
4747,
708,
388,
398,
5044,
28144,
920,
275,
4747,
708,
1246,
14,
2872,
28144,
920,
267,
5044,
5081,
1197,
275,
4747,
708,
1246,
14,
2872,
5081,
1197,
267,
5044,
14432,
275,
4747,
708,
1246,
14,
2872,
14432,
267,
5044,
547,
275,
4747,
708,
1246,
14,
705,
339,
871,
3545,
26,
267,
943,
14,
815,
480,
3849,
26,
6855,
1133,
1586,
7086,
370,
2342,
314,
298,
326,
298,
17927,
6365,
4260,
60,
78,
2,
326,
298,
5483,
3238,
626,
2018,
4621,
485,
15658,
12,
298,
326,
298,
2676,
708,
1246,
503,
4747,
708,
388,
787,
4903,
2685,
267,
986,
199,
199,
692,
485,
2425,
63,
739,
63,
1135,
26,
272,
869,
17434,
275,
334,
72,
498,
63,
1494,
14,
23802,
63,
28164,
12,
1467,
394,
498,
63,
1494,
14,
23802,
63,
14211,
63,
3791,
12,
1467,
394,
498,
63,
1494,
14,
23802,
63,
7486,
63,
20890,
12,
1467,
394,
498,
63,
1494,
14,
23802,
63,
13748,
63,
5441,
9,
199,
199,
318,
1586,
63,
1612,
8,
1095,
12,
790,
304,
272,
408,
1767,
769,
402,
7086,
2883,
1041,
339,
862,
26,
267,
2429,
275,
5044,
28144,
920,
8,
1095,
12,
790,
9,
272,
871,
5044,
547,
26,
267,
372,
488,
272,
491,
275,
942,
272,
284,
275,
378,
272,
1830,
413,
26,
267,
862,
26,
288,
1022,
275,
5044,
5081,
1197,
8,
2479,
12,
284,
9,
267,
871,
5044,
547,
26,
288,
2059,
267,
491,
14,
740,
8,
75,
9,
267,
284,
275,
284,
435,
413,
272,
372,
491,
199,
199,
318,
1586,
63,
1459,
8,
1095,
12,
790,
304,
272,
408,
1767,
1211,
402,
7086,
2883,
436,
1338,
14,
339,
2900,
1561,
787,
6702,
370,
12141,
14,
272,
408,
272,
862,
26,
267,
2429,
275,
5044,
28144,
920,
8,
1095,
12,
790,
9,
272,
871,
5044,
547,
26,
267,
372,
488,
272,
366,
275,
1052,
272,
284,
275,
378,
272,
1830,
413,
26,
267,
862,
26,
288,
536,
12,
574,
12,
730,
275,
5044,
14432,
8,
2479,
12,
284,
9,
267,
871,
5044,
547,
26,
288,
2059,
267,
536,
275,
536,
14,
2325,
342,
267,
366,
59,
3916,
63,
887,
1259,
8,
354,
1874,
275,
3957,
63,
887,
1259,
8,
585,
9,
267,
284,
275,
284,
435,
413,
272,
372,
366,
199,
199,
318,
3957,
63,
887,
1259,
8,
83,
304,
272,
12011,
275,
2519,
8,
83,
12,
298,
2143,
401,
488,
9,
272,
340,
12011,
365,
440,
488,
26,
267,
862,
26,
288,
308,
275,
12011,
480,
887,
1259,
531,
267,
871,
20872,
26,
288,
986,
272,
372,
308,
199,
199,
533,
10444,
293,
4527,
11438,
26,
339,
347,
636,
826,
721,
277,
12,
1015,
304,
267,
291,
14,
16358,
275,
1052,
267,
291,
14,
912,
63,
16358,
8,
1023,
9,
339,
347,
663,
63,
11300,
8,
277,
12,
9559,
12,
931,
12,
790,
304,
267,
367,
1300,
315,
869,
17434,
26,
288,
366,
275,
1586,
63,
1459,
8,
1095,
12,
931,
9,
288,
340,
366,
26,
355,
291,
14,
16358,
905,
4,
4042,
83,
2924,
450,
9559,
61,
275,
366,
59,
498,
61,
355,
2059,
339,
347,
2248,
63,
16358,
8,
277,
12,
1015,
304,
267,
8118,
1095,
275,
519,
2,
10337,
60,
12940,
60,
15039,
21025,
60,
5,
16,
14,
17,
70,
2,
450,
1015,
267,
291,
14,
409,
63,
11300,
480,
9454,
8154,
3567,
401,
8118,
1095,
435,
519,
3212,
8555,
60,
9454,
401,
298,
2558,
694,
531,
267,
291,
14,
409,
63,
11300,
480,
7428,
8154,
3567,
401,
8118,
1095,
435,
519,
3212,
8555,
60,
7428,
401,
298,
2558,
694,
531,
267,
1851,
275,
519,
2,
10337,
60,
12940,
4537,
7278,
16442,
2,
267,
291,
14,
409,
63,
11300,
480,
16442,
3567,
401,
1851,
12,
298,
3174,
1231,
531,
267,
862,
26,
288,
340,
1015,
690,
1520,
14,
16,
26,
355,
291,
14,
409,
63,
11300,
480,
16442,
14939,
3567,
401,
1851,
12,
298,
9277,
3174,
1231,
86,
17,
14,
17,
531,
288,
587,
26,
355,
291,
14,
409,
63,
11300,
480,
16442,
14939,
3567,
401,
1851,
12,
298,
9277,
3174,
1231,
531,
267,
871,
4067,
26,
288,
746,
12577,
10397,
547,
12,
971,
2116,
334,
624,
4718,
1990,
6137,
543,
14702,
13225,
13004,
27,
199,
5359,
1471,
506,
6137,
543,
282,
6365,
2419,
883,
3550,
9025,
21984,
14,
199,
15039,
13225,
13004,
1990,
440,
1911,
641,
642,
2656,
14,
982,
1265,
1172,
445,
18313,
4903,
12,
199,
13297,
883,
862,
1013,
5662,
543,
603,
316,
55,
708,
12,
701,
9476,
3905,
67,
333,
316,
87,
708,
2,
370,
3272,
14,
647,
24887,
398,
299,
275,
519,
2,
10337,
60,
12940,
60,
7278,
22545,
12439,
60,
5884,
2,
267,
367,
1300,
315,
869,
17434,
26,
288,
862,
26,
355,
394,
275,
5044,
28144,
920,
8,
1095,
12,
299,
9,
288,
871,
5044,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ajroussel/shell-nouns-data
|
src/extractor.py
|
1
|
3851
|
#!/usr/bin/env python3
import os
import argparse
import pickle
from lxml import etree
from sys import argv
from objects import *
## returns a list of ints
def to_index(s):
outlist = list()
spl1 = s.split(',')
try:
for item in spl1:
spl2 = item.split('..')
start = int(spl2[0].split('_')[1])
end = int(spl2[1].split('_')[1]) if len(spl2) > 1 else start
outlist.extend([i - 1 for i in range(start, end + 1)])
except ValueError:
print(s)
return outlist
def get_SNs(node):
snes = list()
try:
for sn in node.find("shellnouns").iter("shellnoun"):
snes.append((sn.get("content_phrases"),
to_index(sn.get("span")),
sn.get("value")))
except AttributeError:
pass
return snes
if __name__ == '__main__':
ap = argparse.ArgumentParser()
ap.add_argument("inputfiles", type=str, nargs='+',
help="xml input files")
ap.add_argument("-o", "--outputfile", type=str, default="sn_data.pickle",
help="name of output pickle")
ap.add_argument("-a", "--annotated", action="store_true",
help="use if xml files are annotated w/SN info")
userargs = ap.parse_args()
i = 0
corpus = Corpus()
for fname in userargs.inputfiles:
docroot = etree.parse(fname).getroot()
myname, ext = os.path.splitext(fname)
print("processing", myname + "...")
session_start = i
for turn in docroot.iter("turn"):
turn_start = i
mylang = "de" if "de" in turn.get("turn_id") else "en"
for sentence in turn.iter("sent"):
sent_start = i
for tok in sentence.iter("tok"):
corpus.tokens.append(Token(tok.text, tok.attrib, i,
mylang, session_start))
i += 1
sent_end = i
corpus.sentences.append(range(sent_start, sent_end))
turn_end = i
corpus.turns.append(range(turn_start, turn_end))
session_end = i
corpus.sessions.append(range(session_start, session_end))
if userargs.annotated:
# dict: CP id -> Antecedent
cps = dict()
for cp in docroot.find("content_phrases").iter("content_phrase"):
cp_indices = to_index(cp.get("span"))
is_nom = cp.get("nominal")
new_ante = Antecedent([corpus.tokens[x + session_start]
for x in cp_indices],
is_nom)
corpus.antecedents.append(new_ante)
cps[cp.get("id")] = new_ante
# list[tuples] "proto-Anaphor"
snes = get_SNs(docroot)
for cp_key, sn_indices, val in snes:
my_anaphor = Anaphor([corpus.tokens[x + session_start]
for x in sn_indices],
val)
corpus.anaphors.append(my_anaphor)
my_antecedents = list()
for key in cp_key.split(";"):
try:
my_antecedents.append(cps[key])
except KeyError:
pass
my_instance = RefInstance(my_anaphor, *my_antecedents)
# only keep (non-empty) entries
if my_instance.antecedents:
corpus.ref_instances.append(my_instance)
with open(userargs.outputfile, 'wb') as outfile:
print("read corpus with", len(corpus.tokens), "tokens...")
pickle.dump(corpus, outfile)
print("done!")
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
646,
747,
199,
646,
7534,
199,
646,
5927,
199,
504,
14490,
492,
7559,
199,
504,
984,
492,
9238,
199,
199,
504,
2251,
492,
627,
199,
199,
309,
2529,
282,
769,
402,
14526,
221,
199,
318,
370,
63,
1080,
8,
83,
304,
272,
734,
513,
275,
769,
342,
272,
23168,
17,
275,
308,
14,
1294,
11917,
272,
862,
26,
267,
367,
1242,
315,
23168,
17,
26,
288,
23168,
18,
275,
1242,
14,
1294,
24893,
358,
288,
1343,
275,
1109,
8,
15276,
18,
59,
16,
1055,
1294,
6412,
5832,
17,
566,
288,
1284,
275,
1109,
8,
15276,
18,
59,
17,
1055,
1294,
6412,
5832,
17,
566,
340,
822,
8,
15276,
18,
9,
690,
413,
587,
1343,
288,
734,
513,
14,
2880,
779,
73,
446,
413,
367,
284,
315,
1425,
8,
928,
12,
1284,
435,
413,
3948,
272,
871,
1722,
26,
267,
870,
8,
83,
9,
272,
372,
734,
513,
421,
199,
318,
664,
63,
51,
2438,
8,
932,
304,
272,
6895,
397,
275,
769,
342,
272,
862,
26,
267,
367,
6895,
315,
1031,
14,
1623,
480,
5641,
889,
324,
83,
3471,
1661,
480,
5641,
889,
324,
2349,
288,
6895,
397,
14,
740,
1332,
5167,
14,
362,
480,
1317,
63,
838,
26201,
1288,
586,
370,
63,
1080,
8,
5167,
14,
362,
480,
3751,
8150,
586,
6895,
14,
362,
480,
585,
13324,
272,
871,
4281,
26,
267,
986,
272,
372,
6895,
397,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
339,
2771,
275,
7534,
14,
10730,
342,
272,
2771,
14,
525,
63,
2094,
480,
1210,
1725,
401,
730,
29,
495,
12,
9237,
534,
7386,
490,
1720,
628,
1652,
1324,
1584,
531,
272,
2771,
14,
525,
63,
2094,
6096,
79,
401,
4320,
1199,
493,
401,
730,
29,
495,
12,
849,
628,
5167,
63,
576,
14,
8092,
401,
490,
1720,
628,
354,
402,
1072,
5927,
531,
272,
2771,
14,
525,
63,
2094,
6096,
65,
401,
4320,
3226,
972,
401,
1595,
628,
1617,
63,
2052,
401,
490,
1720,
628,
1180,
340,
2748,
1584,
787,
27526,
336,
15,
8199,
2256,
531,
272,
922,
589,
275,
2771,
14,
1122,
63,
589,
342,
339,
284,
275,
378,
272,
16831,
275,
7499,
8843,
342,
272,
367,
6748,
315,
922,
589,
14,
1210,
1725,
26,
267,
1382,
1231,
275,
7559,
14,
1122,
8,
5252,
680,
24544,
342,
267,
3002,
354,
12,
1599,
275,
747,
14,
515,
14,
7973,
8,
5252,
9,
398,
870,
480,
6338,
401,
3002,
354,
435,
298,
12594,
267,
2351,
63,
928,
275,
284,
267,
367,
7485,
315,
1382,
1231,
14,
1661,
480,
353,
2349,
288,
7485,
63,
928,
275,
284,
288,
3002,
4159,
275,
298,
271,
2,
340,
298,
271,
2,
315,
7485,
14,
362,
480,
353,
63,
344,
531,
587,
298,
287,
2,
953,
367,
14537,
315,
7485,
14,
1661,
480,
1150,
2349,
355,
4847,
63,
928,
275,
284,
355,
367,
8431,
315,
14537,
14,
1661,
480,
9305,
2349,
490,
16831,
14,
4504,
14,
740,
8,
3264,
8,
9305,
14,
505,
12,
8431,
14,
6640,
12,
284,
12,
6901,
3002,
4159,
12,
2351,
63,
928,
430,
490,
284,
847,
413,
355,
4847,
63,
500,
275,
284,
355,
16831,
14,
25669,
14,
740,
8,
1842,
8,
1150,
63,
928,
12,
4847,
63,
500,
430,
288,
7485,
63,
500,
275,
284,
288,
16831,
14,
353,
83,
14,
740,
8,
1842,
8,
353,
63,
928,
12,
7485,
63,
500,
430,
267,
2351,
63,
500,
275,
284,
267,
16831,
14,
11676,
14,
740,
8,
1842,
8,
1730,
63,
928,
12,
2351,
63,
500,
430,
398,
340,
922,
589,
14,
3226,
972,
26,
7846,
327,
1211,
26,
19701,
1305,
1035,
1626,
266,
301,
1326,
288,
286,
1190,
275,
1211,
342,
288,
367,
7667,
315,
1382,
1231,
14,
1623,
480,
1317,
63,
838,
26201,
3471,
1661,
480,
1317,
63,
10906,
2349,
355,
7667,
63,
4108,
275,
370,
63,
1080,
8,
1850,
14,
362,
480,
3751,
2237,
355,
365,
63,
15998,
275,
7667,
14,
362,
480,
15998,
1582,
531,
355,
892,
63,
8949,
275,
1626,
266,
301,
1326,
779,
16780,
14,
4504,
59,
88,
435,
2351,
63,
928,
61,
221,
4318,
367,
671,
315,
7667,
63,
4108,
467,
4228,
365,
63,
15998,
9,
355,
16831,
14,
8949,
301,
1326,
83,
14,
740,
8,
1222,
63,
8949,
9,
355,
286,
1190,
59,
1850,
14,
362,
480,
344,
11323,
275,
892,
63,
8949,
463,
953,
327,
769,
59,
11760,
61,
3698,
298,
2625,
13,
2493,
439,
23991,
2,
288,
6895,
397,
275,
664,
63,
51,
2438,
8,
1301,
1231,
9,
953,
367,
7667,
63,
498,
12,
6895,
63,
4108,
12,
1139,
315,
6895,
397,
26,
2234,
3002,
63,
290,
439,
23991,
275,
1626,
439,
23991,
779,
16780,
14,
4504,
59,
88,
435,
2351,
63,
928,
61,
4228,
367,
671,
315,
6895,
63,
4108,
467,
3660,
1139,
9,
355,
16831,
14,
290,
439,
72,
1384,
14,
740,
8,
1662,
63,
290,
439,
23991,
9,
2234,
3002,
63,
8949,
301,
1326,
83,
275,
769,
342,
355,
367,
790,
315,
7667,
63,
498,
14,
1294,
480,
27,
2349,
490,
862,
26,
717,
3002,
63,
8949,
301,
1326,
83,
14,
740,
8,
67,
1190,
59,
498,
566,
490,
871,
4067,
26,
717,
986,
586,
355,
3002,
63,
842,
275,
15397,
3244,
8,
1662,
63,
290,
439,
23991,
12,
627,
1662,
63,
8949,
301,
1326,
83,
9,
2234,
327,
1454,
4215,
334,
2865,
13,
1667,
9,
4811,
355,
340,
3002,
63,
842,
14,
8949,
301,
1326,
83,
26,
490,
16831,
14,
1121,
63,
5990,
14,
740,
8,
1662,
63,
842,
9,
339,
543,
1551,
8,
751,
589,
14,
1199,
493,
12,
283,
6603,
358,
465,
4386,
26,
267,
870,
480,
739,
16831,
543,
401,
822,
8,
16780,
14,
4504,
395,
298,
4504,
12594,
267,
5927,
14,
2724,
8,
16780,
12,
4386,
9,
339,
870,
480,
4456,
9124,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
646,
747,
199,
646,
7534,
199,
646,
5927,
199,
504,
14490,
492,
7559,
199,
504,
984,
492,
9238,
199,
199,
504,
2251,
492,
627,
199,
199,
309,
2529,
282,
769,
402,
14526,
221,
199,
318,
370,
63,
1080,
8,
83,
304,
272,
734,
513,
275,
769,
342,
272,
23168,
17,
275,
308,
14,
1294,
11917,
272,
862,
26,
267,
367,
1242,
315,
23168,
17,
26,
288,
23168,
18,
275,
1242,
14,
1294,
24893,
358,
288,
1343,
275,
1109,
8,
15276,
18,
59,
16,
1055,
1294,
6412,
5832,
17,
566,
288,
1284,
275,
1109,
8,
15276,
18,
59,
17,
1055,
1294,
6412,
5832,
17,
566,
340,
822,
8,
15276,
18,
9,
690,
413,
587,
1343,
288,
734,
513,
14,
2880,
779,
73,
446,
413,
367,
284,
315,
1425,
8,
928,
12,
1284,
435,
413,
3948,
272,
871,
1722,
26,
267,
870,
8,
83,
9,
272,
372,
734,
513,
421,
199,
318,
664,
63,
51,
2438,
8,
932,
304,
272,
6895,
397,
275,
769,
342,
272,
862,
26,
267,
367,
6895,
315,
1031,
14,
1623,
480,
5641,
889,
324,
83,
3471,
1661,
480,
5641,
889,
324,
2349,
288,
6895,
397,
14,
740,
1332,
5167,
14,
362,
480,
1317,
63,
838,
26201,
1288,
586,
370,
63,
1080,
8,
5167,
14,
362,
480,
3751,
8150,
586,
6895,
14,
362,
480,
585,
13324,
272,
871,
4281,
26,
267,
986,
272,
372,
6895,
397,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
339,
2771,
275,
7534,
14,
10730,
342,
272,
2771,
14,
525,
63,
2094,
480,
1210,
1725,
401,
730,
29,
495,
12,
9237,
534,
7386,
490,
1720,
628,
1652,
1324,
1584,
531,
272,
2771,
14,
525,
63,
2094,
6096,
79,
401,
4320,
1199,
493,
401,
730,
29,
495,
12,
849,
628,
5167,
63,
576,
14,
8092,
401,
490,
1720,
628,
354,
402,
1072,
5927,
531,
272,
2771,
14,
525,
63,
2094,
6096,
65,
401,
4320,
3226,
972,
401,
1595,
628,
1617,
63,
2052,
401,
490,
1720,
628,
1180,
340,
2748,
1584,
787,
27526,
336,
15,
8199,
2256,
531,
272,
922,
589,
275,
2771,
14,
1122,
63,
589,
342,
339,
284,
275,
378,
272,
16831,
275,
7499,
8843,
342,
272,
367,
6748,
315,
922,
589,
14,
1210,
1725,
26,
267,
1382,
1231,
275,
7559,
14,
1122,
8,
5252,
680,
24544,
342,
267,
3002,
354,
12,
1599,
275,
747,
14,
515,
14,
7973,
8,
5252,
9,
398,
870,
480,
6338,
401,
3002,
354,
435,
298,
12594,
267,
2351,
63,
928,
275,
284,
267,
367,
7485,
315,
1382,
1231,
14,
1661,
480,
353,
2349,
288,
7485,
63,
928,
275,
284,
288,
3002,
4159,
275,
298,
271,
2,
340,
298,
271,
2,
315,
7485,
14,
362,
480,
353,
63,
344,
531,
587,
298,
287,
2,
953,
367,
14537,
315,
7485,
14,
1661,
480,
1150,
2349,
355,
4847,
63,
928,
275,
284,
355,
367,
8431,
315,
14537,
14,
1661,
480,
9305,
2349,
490,
16831,
14,
4504,
14,
740,
8,
3264,
8,
9305,
14,
505,
12,
8431,
14,
6640,
12,
284,
12,
6901,
3002,
4159,
12,
2351,
63,
928,
430,
490,
284,
847,
413,
355,
4847,
63,
500,
275,
284,
355,
16831,
14,
25669,
14,
740,
8,
1842,
8,
1150,
63,
928,
12,
4847,
63,
500,
430,
288,
7485,
63,
500,
275,
284,
288,
16831,
14,
353,
83,
14,
740,
8,
1842,
8,
353,
63,
928,
12,
7485,
63,
500,
430,
267,
2351,
63,
500,
275,
284,
267,
16831,
14,
11676,
14,
740,
8,
1842,
8,
1730,
63,
928,
12,
2351,
63,
500,
430,
398,
340,
922,
589,
14,
3226,
972,
26,
7846,
327,
1211,
26,
19701,
1305,
1035,
1626,
266,
301,
1326,
288,
286,
1190,
275,
1211,
342,
288,
367,
7667,
315,
1382,
1231,
14,
1623,
480,
1317,
63,
838,
26201,
3471,
1661,
480,
1317,
63,
10906,
2349,
355,
7667,
63,
4108,
275,
370,
63,
1080,
8,
1850,
14,
362,
480,
3751,
2237,
355,
365,
63,
15998,
275,
7667,
14,
362,
480,
15998,
1582,
531,
355,
892,
63,
8949,
275,
1626,
266,
301,
1326,
779,
16780,
14,
4504,
59,
88,
435,
2351,
63,
928,
61,
221,
4318,
367,
671,
315,
7667,
63,
4108,
467,
4228,
365,
63,
15998,
9,
355,
16831,
14,
8949,
301,
1326,
83,
14,
740,
8,
1222,
63,
8949,
9,
355,
286,
1190,
59,
1850,
14,
362,
480,
344,
11323,
275,
892,
63,
8949,
463,
953,
327,
769,
59,
11760,
61,
3698,
298,
2625,
13,
2493,
439,
23991,
2,
288,
6895,
397,
275,
664,
63,
51,
2438,
8,
1301,
1231,
9,
953,
367,
7667,
63,
498,
12,
6895,
63,
4108,
12,
1139,
315,
6895,
397,
26,
2234,
3002,
63,
290,
439,
23991,
275,
1626,
439,
23991,
779,
16780,
14,
4504,
59,
88,
435,
2351,
63,
928,
61,
4228,
367,
671,
315,
6895,
63,
4108,
467,
3660,
1139,
9,
355,
16831,
14,
290,
439,
72,
1384,
14,
740,
8,
1662,
63,
290,
439,
23991,
9,
2234,
3002,
63,
8949,
301,
1326,
83,
275,
769,
342,
355,
367,
790,
315,
7667,
63,
498,
14,
1294,
480,
27,
2349,
490,
862,
26,
717,
3002,
63,
8949,
301,
1326,
83,
14,
740,
8,
67,
1190,
59,
498,
566,
490,
871,
4067,
26,
717,
986,
586,
355,
3002,
63,
842,
275,
15397,
3244,
8,
1662,
63,
290,
439,
23991,
12,
627,
1662,
63,
8949,
301,
1326,
83,
9,
2234,
327,
1454,
4215,
334,
2865,
13,
1667,
9,
4811,
355,
340,
3002,
63,
842,
14,
8949,
301,
1326,
83,
26,
490,
16831,
14,
1121,
63,
5990,
14,
740,
8,
1662,
63,
842,
9,
339,
543,
1551,
8,
751,
589,
14,
1199,
493,
12,
283,
6603,
358,
465,
4386,
26,
267,
870,
480,
739,
16831,
543,
401,
822,
8,
16780,
14,
4504,
395,
298,
4504,
12594,
267,
5927,
14,
2724,
8,
16780,
12,
4386,
9,
339,
870,
480,
4456,
9124,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
stackforge/monasca-api
|
monasca_api/common/repositories/alarm_definitions_repository.py
|
3
|
2376
|
# Copyright 2014,2016 Hewlett Packard Enterprise Development Company, L.P.
#
# 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.
import abc
import six
@six.add_metaclass(abc.ABCMeta)
class AlarmDefinitionsRepository(object):
def __init__(self):
super(AlarmDefinitionsRepository, self).__init__()
@abc.abstractmethod
def create_alarm_definition(self, tenant_id, name, expression,
sub_expr_list, description, severity, match_by,
alarm_actions, undetermined_actions,
ok_action):
pass
@abc.abstractmethod
def get_sub_alarms(self, tenant_id, alarm_definition_id):
pass
@abc.abstractmethod
def get_alarm_metrics(self, tenant_id, alarm_definition_id):
pass
@abc.abstractmethod
def delete_alarm_definition(self, tenant_id, alarm_definition_id):
pass
@abc.abstractmethod
def get_sub_alarm_definitions(self, alarm_definition_id):
pass
@abc.abstractmethod
def get_alarm_definition(self, tenant_id, id):
pass
@abc.abstractmethod
def get_alarm_definitions(self, tenant_id, name, dimensions, severity, sort_by,
offset, limit):
pass
@abc.abstractmethod
def update_or_patch_alarm_definition(self, tenant_id, id,
name,
expression,
sub_expr_list,
actions_enabled,
description,
alarm_actions,
ok_actions,
undetermined_actions,
match_by, severity, patch):
pass
|
apache-2.0
|
[
3,
1898,
6927,
12,
9261,
27849,
9954,
1005,
29949,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
646,
13022,
199,
199,
646,
3816,
421,
199,
32,
4174,
14,
525,
63,
6577,
8,
3175,
14,
22254,
9,
199,
533,
4580,
5362,
16738,
15614,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
30655,
16738,
15614,
12,
291,
2843,
826,
4533,
339,
768,
3175,
14,
10315,
272,
347,
1218,
63,
14160,
63,
7463,
8,
277,
12,
8261,
63,
344,
12,
536,
12,
3965,
12,
1816,
1007,
63,
3684,
63,
513,
12,
1369,
12,
25574,
12,
1336,
63,
991,
12,
1816,
17987,
63,
3723,
12,
625,
27248,
63,
3723,
12,
1816,
4112,
63,
1287,
304,
267,
986,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
954,
63,
279,
25005,
8,
277,
12,
8261,
63,
344,
12,
17987,
63,
7463,
63,
344,
304,
267,
986,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
14160,
63,
6759,
8,
277,
12,
8261,
63,
344,
12,
17987,
63,
7463,
63,
344,
304,
267,
986,
339,
768,
3175,
14,
10315,
272,
347,
3145,
63,
14160,
63,
7463,
8,
277,
12,
8261,
63,
344,
12,
17987,
63,
7463,
63,
344,
304,
267,
986,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
954,
63,
14160,
63,
15388,
8,
277,
12,
17987,
63,
7463,
63,
344,
304,
267,
986,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
14160,
63,
7463,
8,
277,
12,
8261,
63,
344,
12,
1305,
304,
267,
986,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
14160,
63,
15388,
8,
277,
12,
8261,
63,
344,
12,
536,
12,
7365,
12,
25574,
12,
4069,
63,
991,
12,
2892,
3268,
12,
2304,
304,
267,
986,
339,
768,
3175,
14,
10315,
272,
347,
1678,
63,
269,
63,
2068,
63,
14160,
63,
7463,
8,
277,
12,
8261,
63,
344,
12,
1305,
12,
1460,
536,
12,
1460,
3965,
12,
1460,
1007,
63,
3684,
63,
513,
12,
1460,
5445,
63,
3827,
12,
1460,
1369,
12,
1460,
17987,
63,
3723,
12,
1460,
4112,
63,
3723,
12,
1460,
625,
27248,
63,
3723,
12,
1460,
1336,
63,
991,
12,
25574,
12,
3371,
304,
267,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6927,
12,
9261,
27849,
9954,
1005,
29949,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
646,
13022,
199,
199,
646,
3816,
421,
199,
32,
4174,
14,
525,
63,
6577,
8,
3175,
14,
22254,
9,
199,
533,
4580,
5362,
16738,
15614,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
30655,
16738,
15614,
12,
291,
2843,
826,
4533,
339,
768,
3175,
14,
10315,
272,
347,
1218,
63,
14160,
63,
7463,
8,
277,
12,
8261,
63,
344,
12,
536,
12,
3965,
12,
1816,
1007,
63,
3684,
63,
513,
12,
1369,
12,
25574,
12,
1336,
63,
991,
12,
1816,
17987,
63,
3723,
12,
625,
27248,
63,
3723,
12,
1816,
4112,
63,
1287,
304,
267,
986,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
954,
63,
279,
25005,
8,
277,
12,
8261,
63,
344,
12,
17987,
63,
7463,
63,
344,
304,
267,
986,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
14160,
63,
6759,
8,
277,
12,
8261,
63,
344,
12,
17987,
63,
7463,
63,
344,
304,
267,
986,
339,
768,
3175,
14,
10315,
272,
347,
3145,
63,
14160,
63,
7463,
8,
277,
12,
8261,
63,
344,
12,
17987,
63,
7463,
63,
344,
304,
267,
986,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
954,
63,
14160,
63,
15388,
8,
277,
12,
17987,
63,
7463,
63,
344,
304,
267,
986,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
14160,
63,
7463,
8,
277,
12,
8261,
63,
344,
12,
1305,
304,
267,
986,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
14160,
63,
15388,
8,
277,
12,
8261,
63,
344,
12,
536,
12,
7365,
12,
25574,
12,
4069,
63,
991,
12,
2892,
3268,
12,
2304,
304,
267,
986,
339,
768,
3175,
14,
10315,
272,
347,
1678,
63,
269,
63,
2068,
63,
14160,
63,
7463,
8,
277,
12,
8261,
63,
344,
12,
1305,
12,
1460,
536,
12,
1460,
3965,
12,
1460,
1007,
63,
3684,
63,
513,
12,
1460,
5445,
63,
3827,
12,
1460,
1369,
12,
1460,
17987,
63,
3723,
12,
1460,
4112,
63,
3723,
12,
1460,
625,
27248,
63,
3723,
12,
1460,
1336,
63,
991,
12,
25574,
12,
3371,
304,
267,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Thor77/youtube-dl
|
youtube_dl/extractor/slideshare.py
|
8
|
2124
|
from __future__ import unicode_literals
import re
import json
from .common import InfoExtractor
from ..compat import (
compat_urlparse,
)
from ..utils import (
ExtractorError,
get_element_by_id,
)
class SlideshareIE(InfoExtractor):
_VALID_URL = r'https?://www\.slideshare\.net/[^/]+?/(?P<title>.+?)($|\?)'
_TEST = {
'url': 'http://www.slideshare.net/Dataversity/keynote-presentation-managing-scale-and-complexity',
'info_dict': {
'id': '25665706',
'ext': 'mp4',
'title': 'Managing Scale and Complexity',
'description': 'This was a keynote presentation at the NoSQL Now! 2013 Conference & Expo (http://www.nosqlnow.com). This presentation was given by Adrian Cockcroft from Netflix.',
},
}
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
page_title = mobj.group('title')
webpage = self._download_webpage(url, page_title)
slideshare_obj = self._search_regex(
r'\$\.extend\(slideshare_object,\s*(\{.*?\})\);',
webpage, 'slideshare object')
info = json.loads(slideshare_obj)
if info['slideshow']['type'] != 'video':
raise ExtractorError('Webpage type is "%s": only video extraction is supported for Slideshare' % info['slideshow']['type'], expected=True)
doc = info['doc']
bucket = info['jsplayer']['video_bucket']
ext = info['jsplayer']['video_extension']
video_url = compat_urlparse.urljoin(bucket, doc + '-SD.' + ext)
description = get_element_by_id('slideshow-description-paragraph', webpage) or self._html_search_regex(
r'(?s)<p[^>]+itemprop="description"[^>]*>(.+?)</p>', webpage,
'description', fatal=False)
return {
'_type': 'video',
'id': info['slideshow']['id'],
'title': info['slideshow']['title'],
'ext': ext,
'url': video_url,
'thumbnail': info['slideshow']['pin_image_url'],
'description': description.strip() if description else None,
}
|
unlicense
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
646,
2022,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
10290,
12,
199,
9,
199,
504,
2508,
1208,
492,
334,
272,
19783,
12,
272,
664,
63,
2108,
63,
991,
63,
344,
12,
199,
9,
421,
199,
533,
428,
8409,
6251,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
1544,
4537,
19968,
6251,
4537,
846,
15,
26285,
31,
9448,
48,
28,
1213,
29587,
5130,
4,
6113,
31,
3171,
339,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
19968,
6251,
14,
846,
15,
1451,
422,
3677,
15,
498,
4610,
13,
31993,
13,
1237,
7407,
13,
3467,
13,
460,
13,
5254,
1209,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
28317,
1641,
1690,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
2395,
7407,
22869,
436,
19178,
1209,
297,
288,
283,
1802,
356,
283,
2765,
1990,
282,
790,
4610,
3451,
425,
737,
314,
3091,
4657,
7356,
1,
6171,
1448,
1769,
1253,
1316,
555,
334,
1014,
921,
1544,
14,
12712,
1710,
2131,
14,
957,
680,
961,
3451,
425,
1990,
1627,
701,
4431,
18429,
445,
766,
67,
293,
856,
687,
5365,
70,
20528,
3130,
267,
1660,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
2034,
63,
1213,
275,
14208,
14,
923,
360,
1213,
358,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
2034,
63,
1213,
9,
267,
27063,
6251,
63,
1113,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
1154,
4,
4537,
2880,
24805,
19968,
6251,
63,
785,
4202,
83,
22588,
91,
21040,
30446,
27853,
288,
9248,
12,
283,
19968,
6251,
909,
358,
267,
2256,
275,
2022,
14,
3640,
8,
19968,
6251,
63,
1113,
9,
267,
340,
2256,
459,
19968,
2384,
2545,
466,
418,
1137,
283,
3722,
356,
288,
746,
19783,
360,
5926,
1606,
730,
365,
2071,
83,
582,
1454,
3991,
19967,
365,
3748,
367,
428,
8409,
6251,
7,
450,
2256,
459,
19968,
2384,
2545,
466,
995,
1420,
29,
549,
9,
398,
1382,
275,
2256,
459,
1301,
418,
267,
5315,
275,
2256,
459,
74,
1836,
281,
2545,
3722,
63,
4623,
418,
267,
1599,
275,
2256,
459,
74,
1836,
281,
2545,
3722,
63,
3435,
418,
267,
3991,
63,
633,
275,
8434,
63,
10290,
14,
17755,
8,
4623,
12,
1382,
435,
2475,
3693,
3530,
435,
1599,
9,
267,
1369,
275,
664,
63,
2108,
63,
991,
63,
344,
360,
19968,
2384,
13,
1802,
13,
12400,
297,
9248,
9,
503,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
10120,
83,
21528,
80,
25524,
73,
808,
2675,
628,
1802,
2,
28959,
13661,
11198,
15939,
80,
4206,
9248,
12,
288,
283,
1802,
297,
14294,
29,
797,
9,
398,
372,
469,
288,
2513,
466,
356,
283,
3722,
297,
288,
283,
344,
356,
2256,
459,
19968,
2384,
2545,
344,
995,
288,
283,
1213,
356,
2256,
459,
19968,
2384,
2545,
1213,
995,
288,
283,
832,
356,
1599,
12,
288,
283,
633,
356,
3991,
63,
633,
12,
288,
283,
8311,
356,
2256,
459,
19968,
2384,
2545,
7751,
63,
1569,
63,
633,
995,
288,
283,
1802,
356,
1369,
14,
1913,
342,
340,
1369,
587,
488,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
646,
2022,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
10290,
12,
199,
9,
199,
504,
2508,
1208,
492,
334,
272,
19783,
12,
272,
664,
63,
2108,
63,
991,
63,
344,
12,
199,
9,
421,
199,
533,
428,
8409,
6251,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
1544,
4537,
19968,
6251,
4537,
846,
15,
26285,
31,
9448,
48,
28,
1213,
29587,
5130,
4,
6113,
31,
3171,
339,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
19968,
6251,
14,
846,
15,
1451,
422,
3677,
15,
498,
4610,
13,
31993,
13,
1237,
7407,
13,
3467,
13,
460,
13,
5254,
1209,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
28317,
1641,
1690,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
2395,
7407,
22869,
436,
19178,
1209,
297,
288,
283,
1802,
356,
283,
2765,
1990,
282,
790,
4610,
3451,
425,
737,
314,
3091,
4657,
7356,
1,
6171,
1448,
1769,
1253,
1316,
555,
334,
1014,
921,
1544,
14,
12712,
1710,
2131,
14,
957,
680,
961,
3451,
425,
1990,
1627,
701,
4431,
18429,
445,
766,
67,
293,
856,
687,
5365,
70,
20528,
3130,
267,
1660,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
2034,
63,
1213,
275,
14208,
14,
923,
360,
1213,
358,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
2034,
63,
1213,
9,
267,
27063,
6251,
63,
1113,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
1154,
4,
4537,
2880,
24805,
19968,
6251,
63,
785,
4202,
83,
22588,
91,
21040,
30446,
27853,
288,
9248,
12,
283,
19968,
6251,
909,
358,
267,
2256,
275,
2022,
14,
3640,
8,
19968,
6251,
63,
1113,
9,
267,
340,
2256,
459,
19968,
2384,
2545,
466,
418,
1137,
283,
3722,
356,
288,
746,
19783,
360,
5926,
1606,
730,
365,
2071,
83,
582,
1454,
3991,
19967,
365,
3748,
367,
428,
8409,
6251,
7,
450,
2256,
459,
19968,
2384,
2545,
466,
995,
1420,
29,
549,
9,
398,
1382,
275,
2256,
459,
1301,
418,
267,
5315,
275,
2256,
459,
74,
1836,
281,
2545,
3722,
63,
4623,
418,
267,
1599,
275,
2256,
459,
74,
1836,
281,
2545,
3722,
63,
3435,
418,
267,
3991,
63,
633,
275,
8434,
63,
10290,
14,
17755,
8,
4623,
12,
1382,
435,
2475,
3693,
3530,
435,
1599,
9,
267,
1369,
275,
664,
63,
2108,
63,
991,
63,
344,
360,
19968,
2384,
13,
1802,
13,
12400,
297,
9248,
9,
503,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
10120,
83,
21528,
80,
25524,
73,
808,
2675,
628,
1802,
2,
28959,
13661,
11198,
15939,
80,
4206,
9248,
12,
288,
283,
1802,
297,
14294,
29,
797,
9,
398,
372,
469,
288,
2513,
466,
356,
283,
3722,
297,
288,
283,
344,
356,
2256,
459,
19968,
2384,
2545,
344,
995,
288,
283,
1213,
356,
2256,
459,
19968,
2384,
2545,
1213,
995,
288,
283,
832,
356,
1599,
12,
288,
283,
633,
356,
3991,
63,
633,
12,
288,
283,
8311,
356,
2256,
459,
19968,
2384,
2545,
7751,
63,
1569,
63,
633,
995,
288,
283,
1802,
356,
1369,
14,
1913,
342,
340,
1369,
587,
488,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
kevinr/750book-web
|
750book-web-env/lib/python2.7/site-packages/pinax/apps/tagging_utils/widgets.py
|
3
|
1602
|
from django import forms
from django.conf import settings
from django.core.urlresolvers import reverse
from django.utils.safestring import mark_safe
class TagAutoCompleteInput(forms.TextInput):
class Media:
css = {
"all": (settings.STATIC_URL + "pinax/css/jquery.autocomplete.css",)
}
js = (
settings.STATIC_URL + "pinax/js/jquery-1.3.2.min.js",
settings.STATIC_URL + "pinax/js/jquery.bgiframe.min.js",
settings.STATIC_URL + "pinax/js/jquery.ajaxQueue.js",
settings.STATIC_URL + "pinax/js/jquery.autocomplete.min.js"
)
def __init__(self, app_label, model, *args, **kwargs):
self.app_label = app_label
self.model = model
super(TagAutoCompleteInput, self).__init__(*args, **kwargs)
def render(self, name, value, attrs=None):
output = super(TagAutoCompleteInput, self).render(name, value, attrs)
return output + mark_safe(u"""<script type="text/javascript">
jQuery("#id_%s").autocomplete("%s", {
max: 10,
highlight: false,
multiple: true,
multipleSeparator: " ",
scroll: true,
scrollHeight: 300,
matchContains: true,
autoFill: true
});
</script>""" % (
name,
reverse("tagging_utils_autocomplete", kwargs={
"app_label": self.app_label,
"model": self.model
})
)
)
|
mit
|
[
504,
1639,
492,
4513,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1208,
14,
28389,
492,
2216,
63,
3489,
4388,
199,
533,
8053,
3358,
14175,
3205,
8,
3351,
14,
18362,
304,
2286,
1021,
12300,
26,
267,
11431,
275,
469,
288,
298,
452,
582,
334,
1751,
14,
10449,
63,
2632,
435,
298,
7751,
1219,
15,
3919,
15,
22324,
14,
29695,
14,
3919,
26360,
267,
789,
267,
8586,
275,
334,
288,
2202,
14,
10449,
63,
2632,
435,
298,
7751,
1219,
15,
3596,
15,
22324,
13,
17,
14,
19,
14,
18,
14,
827,
14,
3596,
401,
288,
2202,
14,
10449,
63,
2632,
435,
298,
7751,
1219,
15,
3596,
15,
22324,
14,
6856,
20052,
14,
827,
14,
3596,
401,
288,
2202,
14,
10449,
63,
2632,
435,
298,
7751,
1219,
15,
3596,
15,
22324,
14,
12774,
3737,
14,
3596,
401,
288,
2202,
14,
10449,
63,
2632,
435,
298,
7751,
1219,
15,
3596,
15,
22324,
14,
29695,
14,
827,
14,
3596,
2,
267,
776,
2286,
347,
636,
826,
721,
277,
12,
1145,
63,
1302,
12,
1402,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
571,
63,
1302,
275,
1145,
63,
1302,
267,
291,
14,
1238,
275,
1402,
267,
1613,
8,
1931,
3358,
14175,
3205,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
2286,
347,
3795,
8,
277,
12,
536,
12,
574,
12,
3290,
29,
403,
304,
267,
1072,
275,
1613,
8,
1931,
3358,
14175,
3205,
12,
291,
680,
3352,
8,
354,
12,
574,
12,
3290,
9,
2728,
372,
1072,
435,
2216,
63,
3489,
8,
85,
624,
28,
1579,
730,
628,
505,
15,
9554,
1743,
288,
1335,
3227,
10064,
344,
4970,
83,
3471,
29695,
3647,
83,
401,
469,
355,
1390,
26,
1616,
12,
355,
11850,
26,
3055,
12,
355,
3663,
26,
2549,
12,
355,
3663,
23344,
26,
298,
3872,
355,
13704,
26,
2549,
12,
355,
13704,
8436,
26,
9601,
12,
355,
1336,
6906,
26,
2549,
12,
355,
2599,
12914,
26,
2549,
288,
789,
2736,
288,
3068,
1579,
11193,
450,
334,
355,
536,
12,
355,
3837,
480,
1450,
1540,
63,
1208,
63,
29695,
401,
2074,
3126,
490,
298,
571,
63,
1302,
582,
291,
14,
571,
63,
1302,
12,
490,
298,
1238,
582,
291,
14,
1238,
355,
3828,
288,
776,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
492,
4513,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1208,
14,
28389,
492,
2216,
63,
3489,
4388,
199,
533,
8053,
3358,
14175,
3205,
8,
3351,
14,
18362,
304,
2286,
1021,
12300,
26,
267,
11431,
275,
469,
288,
298,
452,
582,
334,
1751,
14,
10449,
63,
2632,
435,
298,
7751,
1219,
15,
3919,
15,
22324,
14,
29695,
14,
3919,
26360,
267,
789,
267,
8586,
275,
334,
288,
2202,
14,
10449,
63,
2632,
435,
298,
7751,
1219,
15,
3596,
15,
22324,
13,
17,
14,
19,
14,
18,
14,
827,
14,
3596,
401,
288,
2202,
14,
10449,
63,
2632,
435,
298,
7751,
1219,
15,
3596,
15,
22324,
14,
6856,
20052,
14,
827,
14,
3596,
401,
288,
2202,
14,
10449,
63,
2632,
435,
298,
7751,
1219,
15,
3596,
15,
22324,
14,
12774,
3737,
14,
3596,
401,
288,
2202,
14,
10449,
63,
2632,
435,
298,
7751,
1219,
15,
3596,
15,
22324,
14,
29695,
14,
827,
14,
3596,
2,
267,
776,
2286,
347,
636,
826,
721,
277,
12,
1145,
63,
1302,
12,
1402,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
571,
63,
1302,
275,
1145,
63,
1302,
267,
291,
14,
1238,
275,
1402,
267,
1613,
8,
1931,
3358,
14175,
3205,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
2286,
347,
3795,
8,
277,
12,
536,
12,
574,
12,
3290,
29,
403,
304,
267,
1072,
275,
1613,
8,
1931,
3358,
14175,
3205,
12,
291,
680,
3352,
8,
354,
12,
574,
12,
3290,
9,
2728,
372,
1072,
435,
2216,
63,
3489,
8,
85,
624,
28,
1579,
730,
628,
505,
15,
9554,
1743,
288,
1335,
3227,
10064,
344,
4970,
83,
3471,
29695,
3647,
83,
401,
469,
355,
1390,
26,
1616,
12,
355,
11850,
26,
3055,
12,
355,
3663,
26,
2549,
12,
355,
3663,
23344,
26,
298,
3872,
355,
13704,
26,
2549,
12,
355,
13704,
8436,
26,
9601,
12,
355,
1336,
6906,
26,
2549,
12,
355,
2599,
12914,
26,
2549,
288,
789,
2736,
288,
3068,
1579,
11193,
450,
334,
355,
536,
12,
355,
3837,
480,
1450,
1540,
63,
1208,
63,
29695,
401,
2074,
3126,
490,
298,
571,
63,
1302,
582,
291,
14,
571,
63,
1302,
12,
490,
298,
1238,
582,
291,
14,
1238,
355,
3828,
288,
776,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Lab603/PicEncyclopedias
|
jni-build/jni/include/tensorflow/python/framework/tensor_shape_test.py
|
7
|
15975
|
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# 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.
# ==============================================================================
"""Functional tests for shape inference helper classes."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.core.framework import tensor_shape_pb2
from tensorflow.python.framework import tensor_shape
from tensorflow.python.framework import test_util
from tensorflow.python.platform import googletest
class DimensionTest(test_util.TensorFlowTestCase):
def testDimension(self):
dim = tensor_shape.Dimension(12)
self.assertEqual(12, dim.value)
self.assertEqual(12, int(dim))
self.assertEqual(dim, tensor_shape.Dimension(12))
self.assertEqual(tensor_shape.Dimension(15),
dim + tensor_shape.Dimension(3))
self.assertEqual(tensor_shape.Dimension(15), dim + 3)
self.assertEqual(tensor_shape.Dimension(24),
dim * tensor_shape.Dimension(2))
self.assertEqual(tensor_shape.Dimension(24), dim * 2)
self.assertEqual(
tensor_shape.Dimension(6), dim // tensor_shape.Dimension(2))
self.assertEqual(tensor_shape.Dimension(6), dim // 2)
self.assertEqual(tensor_shape.Dimension(12),
dim.merge_with(tensor_shape.Dimension(12)))
self.assertEqual(tensor_shape.Dimension(12), dim.merge_with(12))
self.assertLess(tensor_shape.Dimension(12), tensor_shape.Dimension(13))
self.assertGreater(tensor_shape.Dimension(13), tensor_shape.Dimension(12))
self.assertLessEqual(tensor_shape.Dimension(12), tensor_shape.Dimension(12))
self.assertLessEqual(tensor_shape.Dimension(12), tensor_shape.Dimension(13))
self.assertGreater(tensor_shape.Dimension(13), tensor_shape.Dimension(12))
self.assertGreaterEqual(tensor_shape.Dimension(12),
tensor_shape.Dimension(12))
self.assertGreaterEqual(tensor_shape.Dimension(13),
tensor_shape.Dimension(12))
with self.assertRaises(ValueError):
dim.merge_with(tensor_shape.Dimension(13))
def testUnknownDimension(self):
dim = tensor_shape.Dimension(None)
self.assertIs(None, dim.value)
self.assertEqual(dim.value, tensor_shape.Dimension(None).value)
self.assertEqual(tensor_shape.Dimension(None).value,
(dim + tensor_shape.Dimension(None)).value)
self.assertEqual(tensor_shape.Dimension(None).value,
(dim * tensor_shape.Dimension(None)).value)
self.assertEqual(
tensor_shape.Dimension(None).value,
(dim // tensor_shape.Dimension(None)).value)
self.assertEqual(tensor_shape.Dimension(None).value,
dim.merge_with(tensor_shape.Dimension(None)).value)
self.assertIs(None,
tensor_shape.Dimension(None) < tensor_shape.Dimension(None))
self.assertIs(None,
tensor_shape.Dimension(None) <= tensor_shape.Dimension(None))
self.assertIs(None,
tensor_shape.Dimension(None) > tensor_shape.Dimension(None))
self.assertIs(None,
tensor_shape.Dimension(None) >= tensor_shape.Dimension(None))
def testKnownAndUnknownDimensions(self):
known = tensor_shape.Dimension(12)
unknown = tensor_shape.Dimension(None)
self.assertEqual(
tensor_shape.Dimension(None).value, (known + unknown).value)
self.assertEqual(
tensor_shape.Dimension(None).value, (unknown + known).value)
self.assertEqual(
tensor_shape.Dimension(None).value, (known * unknown).value)
self.assertEqual(
tensor_shape.Dimension(None).value, (unknown * known).value)
self.assertEqual(
tensor_shape.Dimension(None).value, (known // unknown).value)
self.assertEqual(
tensor_shape.Dimension(None).value, (unknown // known).value)
self.assertEqual(
tensor_shape.Dimension(12), known.merge_with(unknown))
self.assertEqual(
tensor_shape.Dimension(12), unknown.merge_with(known))
self.assertIs(None,
tensor_shape.Dimension(12) < tensor_shape.Dimension(None))
self.assertIs(None,
tensor_shape.Dimension(12) <= tensor_shape.Dimension(None))
self.assertIs(None,
tensor_shape.Dimension(12) > tensor_shape.Dimension(None))
self.assertIs(None,
tensor_shape.Dimension(12) >= tensor_shape.Dimension(None))
self.assertIs(None,
tensor_shape.Dimension(None) < tensor_shape.Dimension(12))
self.assertIs(None,
tensor_shape.Dimension(None) <= tensor_shape.Dimension(12))
self.assertIs(None,
tensor_shape.Dimension(None) > tensor_shape.Dimension(12))
self.assertIs(None,
tensor_shape.Dimension(None) >= tensor_shape.Dimension(12))
def testAsDimension(self):
self.assertEqual(tensor_shape.Dimension(12),
tensor_shape.as_dimension(tensor_shape.Dimension(12)))
self.assertEqual(tensor_shape.Dimension(12), tensor_shape.as_dimension(12))
self.assertEqual(
tensor_shape.Dimension(None).value,
tensor_shape.as_dimension(tensor_shape.Dimension(None)).value)
self.assertEqual(tensor_shape.Dimension(None).value,
tensor_shape.as_dimension(None).value)
def testEquality(self):
self.assertTrue(tensor_shape.Dimension(12) == tensor_shape.Dimension(12))
self.assertFalse(tensor_shape.Dimension(12) == tensor_shape.Dimension(13))
self.assertIs(None,
tensor_shape.Dimension(12) == tensor_shape.Dimension(None))
self.assertIs(None,
tensor_shape.Dimension(None) == tensor_shape.Dimension(12))
self.assertIs(None,
tensor_shape.Dimension(None) == tensor_shape.Dimension(None))
self.assertTrue(tensor_shape.Dimension(12) == "12")
self.assertTrue(tensor_shape.Dimension(12) == 24.0 / 2)
# None indicates ambiguous comparison, but comparison vs the wrong type
# is unambigously False.
self.assertIsNotNone(tensor_shape.Dimension(12) == "_")
self.assertIsNotNone(tensor_shape.Dimension(None) == 12.99)
self.assertFalse(tensor_shape.Dimension(12) == "_")
self.assertFalse(tensor_shape.Dimension(None) == 12.99)
self.assertIs(None, tensor_shape.Dimension(None) == "13")
self.assertIs(None, tensor_shape.Dimension(None) == None) # pylint: disable=g-equals-none
self.assertFalse(tensor_shape.Dimension(12) == 12.99)
def testInequality(self):
self.assertTrue(tensor_shape.Dimension(12) != tensor_shape.Dimension(13))
self.assertFalse(tensor_shape.Dimension(12) != tensor_shape.Dimension(12))
self.assertIs(None,
tensor_shape.Dimension(12) != tensor_shape.Dimension(None))
self.assertIs(None,
tensor_shape.Dimension(None) != tensor_shape.Dimension(12))
self.assertIs(None,
tensor_shape.Dimension(None) != tensor_shape.Dimension(None))
# None indicates ambiguous comparison, but comparison vs the wrong type
# is unambigously False.
self.assertIsNotNone(tensor_shape.Dimension(12) != "_")
self.assertIsNotNone(tensor_shape.Dimension(None) != 12.99)
self.assertTrue(tensor_shape.Dimension(12) != "_")
self.assertTrue(tensor_shape.Dimension(None) != 12.99)
self.assertIs(None, tensor_shape.Dimension(None) != "13")
self.assertIs(None, tensor_shape.Dimension(None) != None) # pylint: disable=g-equals-none
self.assertTrue(tensor_shape.Dimension(12) != 12.99)
def testRepr(self):
self.assertEqual(repr(tensor_shape.Dimension(7)), "Dimension(7)")
self.assertEqual(repr(tensor_shape.Dimension(None)), "Dimension(None)")
def testStr(self):
self.assertEqual(str(tensor_shape.Dimension(7)), "7")
self.assertEqual(str(tensor_shape.Dimension(None)), "?")
class ShapeTest(test_util.TensorFlowTestCase):
def testUnknownShape(self):
s = tensor_shape.TensorShape(None)
with self.assertRaises(ValueError):
s.assert_is_fully_defined()
self.assertIs(None, s.ndims)
with self.assertRaises(ValueError):
len(s)
self.assertFalse(s)
self.assertIs(None, s.dims)
def testFullyDefinedShape(self):
s = tensor_shape.TensorShape([tensor_shape.Dimension(
3), tensor_shape.Dimension(4), tensor_shape.Dimension(7)])
s.assert_is_fully_defined()
self.assertEqual(3, s.ndims)
self.assertEqual(3, len(s))
self.assertTrue(s)
s.assert_has_rank(3)
self.assertEqual([tensor_shape.Dimension(3),
tensor_shape.Dimension(4),
tensor_shape.Dimension(7)], s.dims)
self.assertEqual(tensor_shape.Dimension(3), s[0])
self.assertEqual(tensor_shape.Dimension(4), s[1])
self.assertEqual(tensor_shape.Dimension(7), s[2])
self.assertEqual([3, 4, 7], s.as_list())
s.assert_is_compatible_with([3, 4, 7])
s.assert_same_rank([6, 3, 7])
def testPartiallyDefinedShape(self):
s = tensor_shape.TensorShape([tensor_shape.Dimension(
3), tensor_shape.Dimension(None), tensor_shape.Dimension(7)])
with self.assertRaises(ValueError):
s.assert_is_fully_defined()
self.assertEqual(3, s.ndims)
self.assertEqual(3, len(s))
self.assertTrue(s)
s.assert_has_rank(3)
self.assertEqual(tensor_shape.Dimension(3), s[0])
self.assertEqual(tensor_shape.Dimension(None).value, s[1].value)
self.assertEqual(tensor_shape.Dimension(7), s[2])
s.assert_same_rank([6, 3, 7])
def testMergeFullShapes(self):
self.assertEqual([3, 4, 7],
tensor_shape.TensorShape([3, 4, 7]).merge_with(
tensor_shape.TensorShape([3, 4, 7])).as_list())
with self.assertRaises(ValueError):
tensor_shape.TensorShape([3, 4, 7]).merge_with(
tensor_shape.TensorShape([6, 3, 7]))
def testMergePartialShapes(self):
s1 = tensor_shape.TensorShape([tensor_shape.Dimension(
3), tensor_shape.Dimension(None), tensor_shape.Dimension(7)])
s2 = tensor_shape.TensorShape([tensor_shape.Dimension(
None), tensor_shape.Dimension(4), tensor_shape.Dimension(7)])
self.assertEqual([3, 4, 7], s1.merge_with(s2).as_list())
def testMergeFullAndUnknownShape(self):
self.assertEqual([3, 4, 7],
tensor_shape.TensorShape([3, 4, 7]).merge_with(
tensor_shape.TensorShape(None)).as_list())
def testSlice(self):
known = tensor_shape.TensorShape([0, 1, 2, 3, 4])
self.assertEqual(tensor_shape.Dimension(2), known[2])
tensor_shape.TensorShape([1, 2, 3]).assert_is_compatible_with(known[1:4])
unknown = tensor_shape.TensorShape(None)
self.assertEqual(tensor_shape.Dimension(None).value, unknown[2].value)
tensor_shape.TensorShape(
[None, None, None]).assert_is_compatible_with(unknown[1:4])
def testConcatenate(self):
tensor_shape.TensorShape([1, 2, 3, 4]).assert_is_compatible_with(
tensor_shape.TensorShape([1, 2]).concatenate(
tensor_shape.TensorShape([3, 4])))
tensor_shape.TensorShape([1, 2, 3, 4]).assert_is_compatible_with(
tensor_shape.TensorShape([1, 2]).concatenate(
tensor_shape.TensorShape(None)))
tensor_shape.TensorShape([1, 2, 3, 4]).assert_is_compatible_with(
tensor_shape.TensorShape(None).concatenate(
tensor_shape.TensorShape([3, 4])))
tensor_shape.TensorShape([1, 2, 3, 4]).assert_is_compatible_with(
tensor_shape.TensorShape(None).concatenate(
tensor_shape.TensorShape(None)))
tensor_shape.TensorShape([1, 2, 3]).assert_is_compatible_with(
tensor_shape.TensorShape([1, 2]).concatenate(
tensor_shape.Dimension(3)))
def testHelpers(self):
tensor_shape.TensorShape([]).assert_is_compatible_with(
tensor_shape.scalar())
tensor_shape.TensorShape([37]).assert_is_compatible_with(
tensor_shape.vector(37))
tensor_shape.TensorShape(
[94, 43]).assert_is_compatible_with(tensor_shape.matrix(94, 43))
def testTruedivFails(self):
unknown = tensor_shape.Dimension(None)
self.assertEqual((unknown // unknown).value, None)
with self.assertRaisesRegexp(TypeError, r"unsupported operand type"):
unknown / unknown # pylint: disable=pointless-statement
def testConvertFromProto(self):
def make_tensor_shape_proto(shape):
return tensor_shape_pb2.TensorShapeProto(
dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=x) for x in shape])
proto = make_tensor_shape_proto([])
self.assertEqual(tensor_shape.TensorShape([]),
tensor_shape.TensorShape(proto))
self.assertEqual(tensor_shape.TensorShape([]),
tensor_shape.as_shape(proto))
proto = make_tensor_shape_proto([1, 37, 42])
self.assertEqual(tensor_shape.TensorShape([1, 37, 42]),
tensor_shape.TensorShape(proto))
self.assertEqual(tensor_shape.TensorShape([1, 37, 42]),
tensor_shape.as_shape(proto))
partial_proto_shape = tensor_shape.as_shape(
make_tensor_shape_proto([-1, 37, 42]))
partial_shape = tensor_shape.TensorShape([None, 37, 42])
self.assertNotEqual(partial_proto_shape, partial_shape)
self.assertEqual(partial_proto_shape[0].value, None)
self.assertEqual(partial_proto_shape[1].value, 37)
self.assertEqual(partial_proto_shape[2].value, 42)
self.assertTrue(partial_shape.is_compatible_with(partial_proto_shape))
def testStr(self):
self.assertEqual("<unknown>", str(tensor_shape.unknown_shape()))
self.assertEqual("(?,)", str(tensor_shape.unknown_shape(ndims=1)))
self.assertEqual("(?, ?)", str(tensor_shape.unknown_shape(ndims=2)))
self.assertEqual("(?, ?, ?)", str(tensor_shape.unknown_shape(ndims=3)))
self.assertEqual("()", str(tensor_shape.scalar()))
self.assertEqual("(7,)", str(tensor_shape.vector(7)))
self.assertEqual("(3, 8)", str(tensor_shape.matrix(3, 8)))
self.assertEqual("(4, 5, 2)", str(tensor_shape.TensorShape([4, 5, 2])))
self.assertEqual("(32, ?, 1, 9)",
str(tensor_shape.TensorShape([32, None, 1, 9])))
def testAsProto(self):
self.assertTrue(tensor_shape.unknown_shape().as_proto().unknown_rank)
self.assertFalse(
tensor_shape.unknown_shape(ndims=3).as_proto().unknown_rank)
self.assertFalse(
tensor_shape.TensorShape([1, 2, 3]).as_proto().unknown_rank)
self.assertFalse(
tensor_shape.TensorShape([1, None, 3]).as_proto().unknown_rank)
def testEquality(self):
s1 = tensor_shape.TensorShape([tensor_shape.Dimension(
3), tensor_shape.Dimension(4), tensor_shape.Dimension(7)])
s2 = tensor_shape.TensorShape([tensor_shape.Dimension(
3), tensor_shape.Dimension(4), tensor_shape.Dimension(7)])
s3 = tensor_shape.TensorShape([tensor_shape.Dimension(3),
tensor_shape.Dimension(4), None])
self.assertTrue(s1 == s2)
self.assertFalse(s1 != s2)
self.assertFalse(s1 == "a string")
self.assertTrue(s1 != "a string")
self.assertNotEqual(s1, "347", "Should not equal an ambiguous string.")
self.assertEqual(s1, ["3", "4", "7"])
# Test with an unknown shape in s3
self.assertTrue(s1 != s3)
self.assertFalse(s3 == "a string")
self.assertTrue(s3 != "a string")
if __name__ == "__main__":
googletest.main()
|
mit
|
[
3,
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
624,
3481,
279,
2295,
367,
2215,
17353,
5922,
3992,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1018,
14,
4857,
492,
2345,
63,
1392,
63,
3317,
18,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1392,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
3246,
492,
31141,
421,
199,
533,
25291,
774,
8,
396,
63,
1974,
14,
26998,
1746,
304,
819,
347,
511,
17905,
8,
277,
304,
272,
8134,
275,
2345,
63,
1392,
14,
17905,
8,
713,
9,
272,
291,
14,
629,
8,
713,
12,
8134,
14,
585,
9,
272,
291,
14,
629,
8,
713,
12,
1109,
8,
3572,
430,
272,
291,
14,
629,
8,
3572,
12,
2345,
63,
1392,
14,
17905,
8,
713,
430,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
1046,
395,
2151,
8134,
435,
2345,
63,
1392,
14,
17905,
8,
19,
430,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
1046,
395,
8134,
435,
650,
9,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
1194,
395,
2151,
8134,
627,
2345,
63,
1392,
14,
17905,
8,
18,
430,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
1194,
395,
8134,
627,
499,
9,
272,
291,
14,
629,
8,
267,
2345,
63,
1392,
14,
17905,
8,
22,
395,
8134,
5001,
2345,
63,
1392,
14,
17905,
8,
18,
430,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
22,
395,
8134,
5001,
499,
9,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
713,
395,
2151,
8134,
14,
5628,
63,
1045,
8,
3128,
63,
1392,
14,
17905,
8,
713,
1724,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
713,
395,
8134,
14,
5628,
63,
1045,
8,
713,
430,
272,
291,
14,
15625,
8,
3128,
63,
1392,
14,
17905,
8,
713,
395,
2345,
63,
1392,
14,
17905,
8,
969,
430,
272,
291,
14,
15070,
8,
3128,
63,
1392,
14,
17905,
8,
969,
395,
2345,
63,
1392,
14,
17905,
8,
713,
430,
272,
291,
14,
15625,
591,
8,
3128,
63,
1392,
14,
17905,
8,
713,
395,
2345,
63,
1392,
14,
17905,
8,
713,
430,
272,
291,
14,
15625,
591,
8,
3128,
63,
1392,
14,
17905,
8,
713,
395,
2345,
63,
1392,
14,
17905,
8,
969,
430,
272,
291,
14,
15070,
8,
3128,
63,
1392,
14,
17905,
8,
969,
395,
2345,
63,
1392,
14,
17905,
8,
713,
430,
272,
291,
14,
26875,
8,
3128,
63,
1392,
14,
17905,
8,
713,
395,
1169,
2345,
63,
1392,
14,
17905,
8,
713,
430,
272,
291,
14,
26875,
8,
3128,
63,
1392,
14,
17905,
8,
969,
395,
1169,
2345,
63,
1392,
14,
17905,
8,
713,
430,
272,
543,
291,
14,
1855,
8,
3393,
304,
489,
8134,
14,
5628,
63,
1045,
8,
3128,
63,
1392,
14,
17905,
8,
969,
430,
819,
347,
511,
5912,
17905,
8,
277,
304,
272,
8134,
275,
2345,
63,
1392,
14,
17905,
8,
403,
9,
272,
291,
14,
3436,
8,
403,
12,
8134,
14,
585,
9,
272,
291,
14,
629,
8,
3572,
14,
585,
12,
2345,
63,
1392,
14,
17905,
8,
403,
680,
585,
9,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
403,
680,
585,
12,
2151,
334,
3572,
435,
2345,
63,
1392,
14,
17905,
8,
403,
4992,
585,
9,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
403,
680,
585,
12,
2151,
334,
3572,
627,
2345,
63,
1392,
14,
17905,
8,
403,
4992,
585,
9,
272,
291,
14,
629,
8,
267,
2345,
63,
1392,
14,
17905,
8,
403,
680,
585,
12,
267,
334,
3572,
5001,
2345,
63,
1392,
14,
17905,
8,
403,
4992,
585,
9,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
403,
680,
585,
12,
2151,
8134,
14,
5628,
63,
1045,
8,
3128,
63,
1392,
14,
17905,
8,
403,
4992,
585,
9,
272,
291,
14,
3436,
8,
403,
12,
2116,
2345,
63,
1392,
14,
17905,
8,
403,
9,
665,
2345,
63,
1392,
14,
17905,
8,
403,
430,
272,
291,
14,
3436,
8,
403,
12,
2116,
2345,
63,
1392,
14,
17905,
8,
403,
9,
2695,
2345,
63,
1392,
14,
17905,
8,
403,
430,
272,
291,
14,
3436,
8,
403,
12,
2116,
2345,
63,
1392,
14,
17905,
8,
403,
9,
690,
2345,
63,
1392,
14,
17905,
8,
403,
430,
272,
291,
14,
3436,
8,
403,
12,
2116,
2345,
63,
1392,
14,
17905,
8,
403,
9,
2356,
2345,
63,
1392,
14,
17905,
8,
403,
430,
819,
347,
511,
24574,
3325,
5912,
23370,
8,
277,
304,
272,
6040,
275,
2345,
63,
1392,
14,
17905,
8,
713,
9,
272,
5809,
275,
2345,
63,
1392,
14,
17905,
8,
403,
9,
272,
291,
14,
629,
8,
267,
2345,
63,
1392,
14,
17905,
8,
403,
680,
585,
12,
334,
3159,
435,
5809,
680,
585,
9,
272,
291,
14,
629,
8,
267,
2345,
63,
1392,
14,
17905,
8,
403,
680,
585,
12,
334,
5187,
435,
6040,
680,
585,
9,
272,
291,
14,
629,
8,
267,
2345,
63,
1392,
14,
17905,
8,
403,
680,
585,
12,
334,
3159,
627,
5809,
680,
585,
9,
272,
291,
14,
629,
8,
267,
2345,
63,
1392,
14,
17905,
8
] |
[
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
624,
3481,
279,
2295,
367,
2215,
17353,
5922,
3992,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1018,
14,
4857,
492,
2345,
63,
1392,
63,
3317,
18,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1392,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
3246,
492,
31141,
421,
199,
533,
25291,
774,
8,
396,
63,
1974,
14,
26998,
1746,
304,
819,
347,
511,
17905,
8,
277,
304,
272,
8134,
275,
2345,
63,
1392,
14,
17905,
8,
713,
9,
272,
291,
14,
629,
8,
713,
12,
8134,
14,
585,
9,
272,
291,
14,
629,
8,
713,
12,
1109,
8,
3572,
430,
272,
291,
14,
629,
8,
3572,
12,
2345,
63,
1392,
14,
17905,
8,
713,
430,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
1046,
395,
2151,
8134,
435,
2345,
63,
1392,
14,
17905,
8,
19,
430,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
1046,
395,
8134,
435,
650,
9,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
1194,
395,
2151,
8134,
627,
2345,
63,
1392,
14,
17905,
8,
18,
430,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
1194,
395,
8134,
627,
499,
9,
272,
291,
14,
629,
8,
267,
2345,
63,
1392,
14,
17905,
8,
22,
395,
8134,
5001,
2345,
63,
1392,
14,
17905,
8,
18,
430,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
22,
395,
8134,
5001,
499,
9,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
713,
395,
2151,
8134,
14,
5628,
63,
1045,
8,
3128,
63,
1392,
14,
17905,
8,
713,
1724,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
713,
395,
8134,
14,
5628,
63,
1045,
8,
713,
430,
272,
291,
14,
15625,
8,
3128,
63,
1392,
14,
17905,
8,
713,
395,
2345,
63,
1392,
14,
17905,
8,
969,
430,
272,
291,
14,
15070,
8,
3128,
63,
1392,
14,
17905,
8,
969,
395,
2345,
63,
1392,
14,
17905,
8,
713,
430,
272,
291,
14,
15625,
591,
8,
3128,
63,
1392,
14,
17905,
8,
713,
395,
2345,
63,
1392,
14,
17905,
8,
713,
430,
272,
291,
14,
15625,
591,
8,
3128,
63,
1392,
14,
17905,
8,
713,
395,
2345,
63,
1392,
14,
17905,
8,
969,
430,
272,
291,
14,
15070,
8,
3128,
63,
1392,
14,
17905,
8,
969,
395,
2345,
63,
1392,
14,
17905,
8,
713,
430,
272,
291,
14,
26875,
8,
3128,
63,
1392,
14,
17905,
8,
713,
395,
1169,
2345,
63,
1392,
14,
17905,
8,
713,
430,
272,
291,
14,
26875,
8,
3128,
63,
1392,
14,
17905,
8,
969,
395,
1169,
2345,
63,
1392,
14,
17905,
8,
713,
430,
272,
543,
291,
14,
1855,
8,
3393,
304,
489,
8134,
14,
5628,
63,
1045,
8,
3128,
63,
1392,
14,
17905,
8,
969,
430,
819,
347,
511,
5912,
17905,
8,
277,
304,
272,
8134,
275,
2345,
63,
1392,
14,
17905,
8,
403,
9,
272,
291,
14,
3436,
8,
403,
12,
8134,
14,
585,
9,
272,
291,
14,
629,
8,
3572,
14,
585,
12,
2345,
63,
1392,
14,
17905,
8,
403,
680,
585,
9,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
403,
680,
585,
12,
2151,
334,
3572,
435,
2345,
63,
1392,
14,
17905,
8,
403,
4992,
585,
9,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
403,
680,
585,
12,
2151,
334,
3572,
627,
2345,
63,
1392,
14,
17905,
8,
403,
4992,
585,
9,
272,
291,
14,
629,
8,
267,
2345,
63,
1392,
14,
17905,
8,
403,
680,
585,
12,
267,
334,
3572,
5001,
2345,
63,
1392,
14,
17905,
8,
403,
4992,
585,
9,
272,
291,
14,
629,
8,
3128,
63,
1392,
14,
17905,
8,
403,
680,
585,
12,
2151,
8134,
14,
5628,
63,
1045,
8,
3128,
63,
1392,
14,
17905,
8,
403,
4992,
585,
9,
272,
291,
14,
3436,
8,
403,
12,
2116,
2345,
63,
1392,
14,
17905,
8,
403,
9,
665,
2345,
63,
1392,
14,
17905,
8,
403,
430,
272,
291,
14,
3436,
8,
403,
12,
2116,
2345,
63,
1392,
14,
17905,
8,
403,
9,
2695,
2345,
63,
1392,
14,
17905,
8,
403,
430,
272,
291,
14,
3436,
8,
403,
12,
2116,
2345,
63,
1392,
14,
17905,
8,
403,
9,
690,
2345,
63,
1392,
14,
17905,
8,
403,
430,
272,
291,
14,
3436,
8,
403,
12,
2116,
2345,
63,
1392,
14,
17905,
8,
403,
9,
2356,
2345,
63,
1392,
14,
17905,
8,
403,
430,
819,
347,
511,
24574,
3325,
5912,
23370,
8,
277,
304,
272,
6040,
275,
2345,
63,
1392,
14,
17905,
8,
713,
9,
272,
5809,
275,
2345,
63,
1392,
14,
17905,
8,
403,
9,
272,
291,
14,
629,
8,
267,
2345,
63,
1392,
14,
17905,
8,
403,
680,
585,
12,
334,
3159,
435,
5809,
680,
585,
9,
272,
291,
14,
629,
8,
267,
2345,
63,
1392,
14,
17905,
8,
403,
680,
585,
12,
334,
5187,
435,
6040,
680,
585,
9,
272,
291,
14,
629,
8,
267,
2345,
63,
1392,
14,
17905,
8,
403,
680,
585,
12,
334,
3159,
627,
5809,
680,
585,
9,
272,
291,
14,
629,
8,
267,
2345,
63,
1392,
14,
17905,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
CybOXProject/python-cybox
|
cybox/__init__.py
|
1
|
4103
|
# Copyright (c) 2020, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.
from mixbox import entities
from mixbox.vendor import six
from .version import __version__ # noqa
#: Mapping of xsi:types to implementation/extension classes
_EXTENSION_MAP = {}
def _lookup_unprefixed(typename):
"""Attempts to resolve a class for the input XML type `typename`.
Args:
typename: The name of an CybOX XML type (e.g., UnixProcessStatusType)
without a namespace prefix.
Returns:
A stix.Entity implementation class for the `typename`.
Raises:
ValueError: If no class has been registered for the input `typename`.
"""
for xsi_type, klass in six.iteritems(_EXTENSION_MAP):
if typename in xsi_type:
return klass
error = "Unregistered extension type: %s" % typename
raise ValueError(error)
def _lookup_extension(xsi_type):
"""Returns a Python class for the `xsi_type` value.
Args:
xsi_type: An xsi:type value string.
Returns:
An Entity implementation class for the `xsi_type`.
Raises:
ValueError: If no class has been registered for the `xsi_type`.
"""
if xsi_type in _EXTENSION_MAP:
return _EXTENSION_MAP[xsi_type]
raise ValueError("Unregistered xsi:type %s" % xsi_type)
def lookup_extension(typeinfo, default=None):
"""Returns an Entity class for that has been registered for the
`typeinfo` value.
Note:
This is for internal use only.
Args:
typeinfo: An object or string containing type information. This can be
either an xsi:type attribute value or a stix.bindings object.
default: Return class if typeinfo is None or contains no xml type
information.
Returns:
An Entity implementation class for the `xsi_type`.
Raises:
ValueError: If no class has been registered for the `xsi_type`.
"""
if typeinfo is None and default:
return default
# If the `typeinfo` was a string, consider it a full xsi:type value.
if isinstance(typeinfo, six.string_types):
return _lookup_extension(typeinfo)
# Most extension bindings include this attribute.
if not hasattr(typeinfo, 'xml_type'):
if default:
return default
error = "Input %s is missing xml_type attribute. Cannot lookup class."
raise ValueError(error % type(typeinfo))
# Extension binding classes usually (always?) have an `xmlns_prefix`
# class attribute.
if hasattr(typeinfo, 'xmlns_prefix'):
xsi_type = "%s:%s" % (typeinfo.xmlns_prefix, typeinfo.xml_type)
return _lookup_extension(xsi_type)
# no xmlns_prefix found, try to resolve the class by just the `xml_type`
return _lookup_unprefixed(typeinfo.xml_type)
def add_extension(cls):
"""Registers an Entity class as an implementation of an xml type.
Classes must have an ``_XSI_TYPE`` class attributes to be registered. The
value of this attribute must be a valid xsi:type.
Note:
This was designed for internal use.
"""
_EXTENSION_MAP[cls._XSI_TYPE] = cls # noqa
def register_extension(cls):
"""Class decorator for registering a stix.Entity class as an implementation
of an xml type.
Classes must have an ``_XSI_TYPE`` class attributes to be registered.
Note:
This was designed for internal use.
"""
add_extension(cls)
return cls
# TODO: Should this get moved to mixbox or not?
class Unicode(entities.Entity):
"""Shim class to allow xs:string's in EntityList"""
def __init__(self, value):
super(Unicode, self).__init__()
self.value = value
@property
def value(self):
return self._value
@value.setter
def value(self, value):
self._value = six.text_type(value)
def to_obj(self, ns_info=None):
return self.value
def to_dict(self):
return self.value
@classmethod
def from_obj(cls, cls_obj):
return cls(cls_obj)
from_dict = from_obj
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
25455,
12,
710,
10697,
907,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
1666,
5113,
14,
2424,
367,
4890,
2895,
14,
199,
199,
504,
13667,
1977,
492,
9045,
199,
504,
13667,
1977,
14,
9884,
492,
3816,
199,
199,
504,
1275,
1023,
492,
636,
1023,
363,
221,
327,
8151,
199,
199,
12573,
12340,
402,
671,
338,
26,
1313,
370,
4514,
15,
3435,
3992,
199,
63,
15498,
63,
5443,
275,
1052,
421,
199,
318,
485,
3892,
63,
324,
27833,
8,
18596,
304,
272,
408,
15322,
1086,
370,
7512,
282,
1021,
367,
314,
1324,
4692,
730,
658,
18596,
2313,
339,
3033,
26,
267,
19151,
26,
710,
536,
402,
376,
18461,
66,
29544,
4692,
730,
334,
69,
14,
71,
2020,
13074,
3498,
3694,
804,
9,
288,
1928,
282,
3231,
2403,
14,
339,
1803,
26,
267,
437,
410,
1148,
14,
7302,
4514,
1021,
367,
314,
658,
18596,
2313,
2378,
6218,
26,
267,
1722,
26,
982,
949,
1021,
965,
2757,
7264,
367,
314,
1324,
658,
18596,
2313,
339,
408,
272,
367,
671,
338,
63,
466,
12,
8531,
315,
3816,
14,
4611,
1547,
15498,
63,
5443,
304,
267,
340,
19151,
315,
671,
338,
63,
466,
26,
288,
372,
8531,
339,
1125,
275,
298,
1358,
11616,
3329,
730,
26,
450,
83,
2,
450,
19151,
272,
746,
1722,
8,
705,
9,
421,
199,
318,
485,
3892,
63,
3435,
8,
88,
338,
63,
466,
304,
272,
408,
3407,
282,
2018,
1021,
367,
314,
658,
88,
338,
63,
466,
64,
574,
14,
339,
3033,
26,
267,
671,
338,
63,
466,
26,
1626,
671,
338,
26,
466,
574,
1059,
14,
339,
1803,
26,
267,
1626,
17680,
4514,
1021,
367,
314,
658,
88,
338,
63,
466,
2313,
339,
6218,
26,
267,
1722,
26,
982,
949,
1021,
965,
2757,
7264,
367,
314,
658,
88,
338,
63,
466,
2313,
339,
408,
272,
340,
671,
338,
63,
466,
315,
485,
15498,
63,
5443,
26,
267,
372,
485,
15498,
63,
5443,
59,
88,
338,
63,
466,
61,
339,
746,
1722,
480,
1358,
11616,
671,
338,
26,
466,
450,
83,
2,
450,
671,
338,
63,
466,
9,
421,
199,
318,
4237,
63,
3435,
8,
466,
815,
12,
849,
29,
403,
304,
272,
408,
3407,
376,
17680,
1021,
367,
626,
965,
2757,
7264,
367,
314,
272,
658,
466,
815,
64,
574,
14,
339,
3390,
26,
267,
961,
365,
367,
5007,
675,
1454,
14,
339,
3033,
26,
267,
730,
815,
26,
1626,
909,
503,
1059,
3035,
730,
2556,
14,
961,
883,
506,
288,
1902,
376,
671,
338,
26,
466,
2225,
574,
503,
282,
410,
1148,
14,
10880,
909,
14,
267,
849,
26,
1432,
1021,
340,
730,
815,
365,
488,
503,
3509,
949,
2748,
730,
288,
2556,
14,
339,
1803,
26,
267,
1626,
17680,
4514,
1021,
367,
314,
658,
88,
338,
63,
466,
2313,
339,
6218,
26,
267,
1722,
26,
982,
949,
1021,
965,
2757,
7264,
367,
314,
658,
88,
338,
63,
466,
2313,
339,
408,
272,
340,
730,
815,
365,
488,
436,
849,
26,
267,
372,
849,
339,
327,
982,
314,
658,
466,
815,
64,
1990,
282,
1059,
12,
11201,
652,
282,
221,
2615,
671,
338,
26,
466,
574,
14,
272,
340,
1228,
8,
466,
815,
12,
3816,
14,
875,
63,
1313,
304,
267,
372,
485,
3892,
63,
3435,
8,
466,
815,
9,
339,
327,
17536,
3329,
17792,
2387,
642,
2225,
14,
272,
340,
440,
2688,
8,
466,
815,
12,
283,
1652,
63,
466,
735,
267,
340,
849,
26,
288,
372,
849,
398,
1125,
275,
298,
3205,
450,
83,
365,
4124,
2748,
63,
466,
2225,
14,
18435,
4237,
1021,
2122,
267,
746,
1722,
8,
705,
450,
730,
8,
466,
815,
430,
339,
327,
13282,
11696,
3992,
9987,
334,
9223,
17076,
1172,
376,
658,
13991,
63,
1861,
64,
272,
327,
1021,
2225,
14,
272,
340,
2688,
8,
466,
815,
12,
283,
13991,
63,
1861,
735,
267,
671,
338,
63,
466,
275,
2071,
83,
2689,
83,
2,
450,
334,
466,
815,
14,
13991,
63,
1861,
12,
730,
815,
14,
1652,
63,
466,
9,
267,
372,
485,
3892,
63,
3435,
8,
88,
338,
63,
466,
9,
339,
327,
949,
9604,
63,
1861,
1911,
12,
862,
370,
7512,
314,
1021,
701,
2951,
314,
658,
1652,
63,
466,
64,
272,
372,
485,
3892,
63,
324,
27833,
8,
466,
815,
14,
1652,
63,
466,
9,
421,
199,
318,
1050,
63,
3435,
8,
1886,
304,
272,
408,
31136,
376,
17680,
1021,
465,
376,
4514,
402,
376,
2748,
730,
14,
339,
27939,
1471,
1172,
376,
24507,
56,
2684,
63,
2711,
1040,
1021,
3004,
370,
506,
7264,
14,
710,
272,
574,
402,
642,
2225,
1471,
506,
282,
1686,
671,
338,
26,
466,
14,
339,
3390,
26,
267,
961,
1990,
19829,
367,
5007,
675,
14,
339,
408,
272,
485,
15498,
63,
5443,
59,
1886,
423,
56,
2684,
63,
2711,
61,
275,
843,
221,
327,
8151,
421,
199,
318,
2274,
63,
3435,
8,
1886,
304,
272,
408,
2543,
7531,
367,
2274,
316,
282,
410,
1148,
14,
7302,
1021,
465,
376,
4514,
272,
402,
376,
2748,
730,
14,
339,
27939,
1471,
1172,
376,
24507,
56,
2684,
63,
2711,
1040,
1021,
3004,
370,
506,
7264,
14,
339,
3390,
26,
267,
961,
1990,
19829,
367,
5007,
675,
14,
339,
408,
272,
1050,
63,
3435,
8,
1886,
9,
272,
372,
843,
421,
199,
3,
3254,
26,
7719,
642,
664,
12155,
370,
13667,
1977,
503,
440,
31,
199,
533,
6140,
8,
8327,
14,
7302,
304,
272,
408,
2662,
1017,
1021,
370,
2040,
12965,
26,
875,
1159,
315,
17680,
1296,
624,
339,
347,
636,
826,
721,
277,
12,
574,
304,
267,
1613,
8,
7087,
12,
291,
2843,
826,
4533,
267,
291,
14,
585,
275,
574,
339,
768,
1829,
272,
347,
574,
8,
277,
304,
267,
372,
291,
423,
585,
339,
768,
585,
14,
8345,
272,
347,
574,
8,
277,
12,
574,
304,
267,
291,
423,
585,
275,
3816,
14,
505,
63,
466,
8,
585,
9,
339,
347,
370,
63,
1113,
8,
277,
12,
700,
63,
815,
29,
403,
304,
267,
372,
291,
14,
585,
339,
347,
370,
63,
807,
8,
277,
304,
267,
372,
291,
14,
585,
339,
768,
3744,
272,
347,
687,
63,
1113,
8,
1886,
12,
843,
63,
1113,
304,
267,
372,
843,
8,
1886,
63,
1113,
9,
339,
687,
63,
807,
275,
687
] |
[
1898,
334,
67,
9,
25455,
12,
710,
10697,
907,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
1666,
5113,
14,
2424,
367,
4890,
2895,
14,
199,
199,
504,
13667,
1977,
492,
9045,
199,
504,
13667,
1977,
14,
9884,
492,
3816,
199,
199,
504,
1275,
1023,
492,
636,
1023,
363,
221,
327,
8151,
199,
199,
12573,
12340,
402,
671,
338,
26,
1313,
370,
4514,
15,
3435,
3992,
199,
63,
15498,
63,
5443,
275,
1052,
421,
199,
318,
485,
3892,
63,
324,
27833,
8,
18596,
304,
272,
408,
15322,
1086,
370,
7512,
282,
1021,
367,
314,
1324,
4692,
730,
658,
18596,
2313,
339,
3033,
26,
267,
19151,
26,
710,
536,
402,
376,
18461,
66,
29544,
4692,
730,
334,
69,
14,
71,
2020,
13074,
3498,
3694,
804,
9,
288,
1928,
282,
3231,
2403,
14,
339,
1803,
26,
267,
437,
410,
1148,
14,
7302,
4514,
1021,
367,
314,
658,
18596,
2313,
2378,
6218,
26,
267,
1722,
26,
982,
949,
1021,
965,
2757,
7264,
367,
314,
1324,
658,
18596,
2313,
339,
408,
272,
367,
671,
338,
63,
466,
12,
8531,
315,
3816,
14,
4611,
1547,
15498,
63,
5443,
304,
267,
340,
19151,
315,
671,
338,
63,
466,
26,
288,
372,
8531,
339,
1125,
275,
298,
1358,
11616,
3329,
730,
26,
450,
83,
2,
450,
19151,
272,
746,
1722,
8,
705,
9,
421,
199,
318,
485,
3892,
63,
3435,
8,
88,
338,
63,
466,
304,
272,
408,
3407,
282,
2018,
1021,
367,
314,
658,
88,
338,
63,
466,
64,
574,
14,
339,
3033,
26,
267,
671,
338,
63,
466,
26,
1626,
671,
338,
26,
466,
574,
1059,
14,
339,
1803,
26,
267,
1626,
17680,
4514,
1021,
367,
314,
658,
88,
338,
63,
466,
2313,
339,
6218,
26,
267,
1722,
26,
982,
949,
1021,
965,
2757,
7264,
367,
314,
658,
88,
338,
63,
466,
2313,
339,
408,
272,
340,
671,
338,
63,
466,
315,
485,
15498,
63,
5443,
26,
267,
372,
485,
15498,
63,
5443,
59,
88,
338,
63,
466,
61,
339,
746,
1722,
480,
1358,
11616,
671,
338,
26,
466,
450,
83,
2,
450,
671,
338,
63,
466,
9,
421,
199,
318,
4237,
63,
3435,
8,
466,
815,
12,
849,
29,
403,
304,
272,
408,
3407,
376,
17680,
1021,
367,
626,
965,
2757,
7264,
367,
314,
272,
658,
466,
815,
64,
574,
14,
339,
3390,
26,
267,
961,
365,
367,
5007,
675,
1454,
14,
339,
3033,
26,
267,
730,
815,
26,
1626,
909,
503,
1059,
3035,
730,
2556,
14,
961,
883,
506,
288,
1902,
376,
671,
338,
26,
466,
2225,
574,
503,
282,
410,
1148,
14,
10880,
909,
14,
267,
849,
26,
1432,
1021,
340,
730,
815,
365,
488,
503,
3509,
949,
2748,
730,
288,
2556,
14,
339,
1803,
26,
267,
1626,
17680,
4514,
1021,
367,
314,
658,
88,
338,
63,
466,
2313,
339,
6218,
26,
267,
1722,
26,
982,
949,
1021,
965,
2757,
7264,
367,
314,
658,
88,
338,
63,
466,
2313,
339,
408,
272,
340,
730,
815,
365,
488,
436,
849,
26,
267,
372,
849,
339,
327,
982,
314,
658,
466,
815,
64,
1990,
282,
1059,
12,
11201,
652,
282,
221,
2615,
671,
338,
26,
466,
574,
14,
272,
340,
1228,
8,
466,
815,
12,
3816,
14,
875,
63,
1313,
304,
267,
372,
485,
3892,
63,
3435,
8,
466,
815,
9,
339,
327,
17536,
3329,
17792,
2387,
642,
2225,
14,
272,
340,
440,
2688,
8,
466,
815,
12,
283,
1652,
63,
466,
735,
267,
340,
849,
26,
288,
372,
849,
398,
1125,
275,
298,
3205,
450,
83,
365,
4124,
2748,
63,
466,
2225,
14,
18435,
4237,
1021,
2122,
267,
746,
1722,
8,
705,
450,
730,
8,
466,
815,
430,
339,
327,
13282,
11696,
3992,
9987,
334,
9223,
17076,
1172,
376,
658,
13991,
63,
1861,
64,
272,
327,
1021,
2225,
14,
272,
340,
2688,
8,
466,
815,
12,
283,
13991,
63,
1861,
735,
267,
671,
338,
63,
466,
275,
2071,
83,
2689,
83,
2,
450,
334,
466,
815,
14,
13991,
63,
1861,
12,
730,
815,
14,
1652,
63,
466,
9,
267,
372,
485,
3892,
63,
3435,
8,
88,
338,
63,
466,
9,
339,
327,
949,
9604,
63,
1861,
1911,
12,
862,
370,
7512,
314,
1021,
701,
2951,
314,
658,
1652,
63,
466,
64,
272,
372,
485,
3892,
63,
324,
27833,
8,
466,
815,
14,
1652,
63,
466,
9,
421,
199,
318,
1050,
63,
3435,
8,
1886,
304,
272,
408,
31136,
376,
17680,
1021,
465,
376,
4514,
402,
376,
2748,
730,
14,
339,
27939,
1471,
1172,
376,
24507,
56,
2684,
63,
2711,
1040,
1021,
3004,
370,
506,
7264,
14,
710,
272,
574,
402,
642,
2225,
1471,
506,
282,
1686,
671,
338,
26,
466,
14,
339,
3390,
26,
267,
961,
1990,
19829,
367,
5007,
675,
14,
339,
408,
272,
485,
15498,
63,
5443,
59,
1886,
423,
56,
2684,
63,
2711,
61,
275,
843,
221,
327,
8151,
421,
199,
318,
2274,
63,
3435,
8,
1886,
304,
272,
408,
2543,
7531,
367,
2274,
316,
282,
410,
1148,
14,
7302,
1021,
465,
376,
4514,
272,
402,
376,
2748,
730,
14,
339,
27939,
1471,
1172,
376,
24507,
56,
2684,
63,
2711,
1040,
1021,
3004,
370,
506,
7264,
14,
339,
3390,
26,
267,
961,
1990,
19829,
367,
5007,
675,
14,
339,
408,
272,
1050,
63,
3435,
8,
1886,
9,
272,
372,
843,
421,
199,
3,
3254,
26,
7719,
642,
664,
12155,
370,
13667,
1977,
503,
440,
31,
199,
533,
6140,
8,
8327,
14,
7302,
304,
272,
408,
2662,
1017,
1021,
370,
2040,
12965,
26,
875,
1159,
315,
17680,
1296,
624,
339,
347,
636,
826,
721,
277,
12,
574,
304,
267,
1613,
8,
7087,
12,
291,
2843,
826,
4533,
267,
291,
14,
585,
275,
574,
339,
768,
1829,
272,
347,
574,
8,
277,
304,
267,
372,
291,
423,
585,
339,
768,
585,
14,
8345,
272,
347,
574,
8,
277,
12,
574,
304,
267,
291,
423,
585,
275,
3816,
14,
505,
63,
466,
8,
585,
9,
339,
347,
370,
63,
1113,
8,
277,
12,
700,
63,
815,
29,
403,
304,
267,
372,
291,
14,
585,
339,
347,
370,
63,
807,
8,
277,
304,
267,
372,
291,
14,
585,
339,
768,
3744,
272,
347,
687,
63,
1113,
8,
1886,
12,
843,
63,
1113,
304,
267,
372,
843,
8,
1886,
63,
1113,
9,
339,
687,
63,
807,
275,
687,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
TwinkleChawla/nova
|
nova/tests/unit/cast_as_call.py
|
77
|
1837
|
# Copyright 2013 Red Hat, 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.
import fixtures
import oslo_messaging as messaging
class CastAsCall(fixtures.Fixture):
"""Make RPC 'cast' behave like a 'call'.
This is a little hack for tests that need to know when a cast
operation has completed. The idea is that we wait for the RPC
endpoint method to complete and return before continuing on the
caller.
See Ia7f40718533e450f00cd3e7d753ac65755c70588 for more background.
"""
def __init__(self, stubs):
super(CastAsCall, self).__init__()
self.stubs = stubs
@staticmethod
def _stub_out(stubs, obj):
orig_prepare = obj.prepare
def prepare(self, *args, **kwargs):
# Casts with fanout=True would throw errors if its monkeypatched to
# the call method, so we must override fanout to False
if 'fanout' in kwargs:
kwargs['fanout'] = False
cctxt = orig_prepare(self, *args, **kwargs)
CastAsCall._stub_out(stubs, cctxt) # woo, recurse!
return cctxt
stubs.Set(obj, 'prepare', prepare)
stubs.Set(obj, 'cast', obj.call)
def setUp(self):
super(CastAsCall, self).setUp()
self._stub_out(self.stubs, messaging.RPCClient)
|
apache-2.0
|
[
3,
1898,
6171,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
15188,
199,
646,
11258,
63,
27782,
465,
30429,
421,
199,
533,
445,
1810,
2822,
2176,
8,
8769,
14,
12812,
304,
339,
408,
5483,
11785,
283,
2931,
7,
24062,
2839,
282,
283,
1250,
1370,
339,
961,
365,
282,
12050,
11176,
367,
2295,
626,
1929,
370,
5715,
1380,
282,
9106,
272,
3439,
965,
9709,
14,
710,
16819,
365,
626,
781,
3618,
367,
314,
11785,
272,
6037,
1083,
370,
4890,
436,
372,
2544,
32620,
641,
314,
272,
8025,
14,
339,
1666,
473,
65,
23,
70,
12641,
10233,
1153,
69,
24223,
70,
383,
2866,
19,
69,
23,
68,
22566,
645,
29830,
1229,
67,
23,
24687,
367,
1655,
8020,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
22312,
304,
267,
1613,
8,
24654,
2822,
2176,
12,
291,
2843,
826,
4533,
267,
291,
14,
8957,
275,
22312,
339,
768,
4639,
272,
347,
485,
5811,
63,
548,
8,
8957,
12,
1559,
304,
267,
2306,
63,
6726,
275,
1559,
14,
6726,
398,
347,
9275,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
288,
327,
445,
1810,
83,
543,
13758,
548,
29,
549,
3955,
7978,
2552,
340,
2399,
17309,
379,
370,
288,
327,
314,
1240,
1083,
12,
880,
781,
1471,
4278,
13758,
548,
370,
756,
288,
340,
283,
12269,
548,
7,
315,
2074,
26,
355,
2074,
459,
12269,
548,
418,
275,
756,
288,
286,
6725,
275,
2306,
63,
6726,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
288,
445,
1810,
2822,
2176,
423,
5811,
63,
548,
8,
8957,
12,
286,
6725,
9,
221,
327,
336,
1534,
12,
18011,
1,
288,
372,
286,
6725,
398,
22312,
14,
1084,
8,
1113,
12,
283,
6726,
297,
9275,
9,
267,
22312,
14,
1084,
8,
1113,
12,
283,
2931,
297,
1559,
14,
1250,
9,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
24654,
2822,
2176,
12,
291,
680,
5996,
342,
267,
291,
423,
5811,
63,
548,
8,
277,
14,
8957,
12,
30429,
14,
18612,
2571,
864,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6171,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
15188,
199,
646,
11258,
63,
27782,
465,
30429,
421,
199,
533,
445,
1810,
2822,
2176,
8,
8769,
14,
12812,
304,
339,
408,
5483,
11785,
283,
2931,
7,
24062,
2839,
282,
283,
1250,
1370,
339,
961,
365,
282,
12050,
11176,
367,
2295,
626,
1929,
370,
5715,
1380,
282,
9106,
272,
3439,
965,
9709,
14,
710,
16819,
365,
626,
781,
3618,
367,
314,
11785,
272,
6037,
1083,
370,
4890,
436,
372,
2544,
32620,
641,
314,
272,
8025,
14,
339,
1666,
473,
65,
23,
70,
12641,
10233,
1153,
69,
24223,
70,
383,
2866,
19,
69,
23,
68,
22566,
645,
29830,
1229,
67,
23,
24687,
367,
1655,
8020,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
22312,
304,
267,
1613,
8,
24654,
2822,
2176,
12,
291,
2843,
826,
4533,
267,
291,
14,
8957,
275,
22312,
339,
768,
4639,
272,
347,
485,
5811,
63,
548,
8,
8957,
12,
1559,
304,
267,
2306,
63,
6726,
275,
1559,
14,
6726,
398,
347,
9275,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
288,
327,
445,
1810,
83,
543,
13758,
548,
29,
549,
3955,
7978,
2552,
340,
2399,
17309,
379,
370,
288,
327,
314,
1240,
1083,
12,
880,
781,
1471,
4278,
13758,
548,
370,
756,
288,
340,
283,
12269,
548,
7,
315,
2074,
26,
355,
2074,
459,
12269,
548,
418,
275,
756,
288,
286,
6725,
275,
2306,
63,
6726,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
288,
445,
1810,
2822,
2176,
423,
5811,
63,
548,
8,
8957,
12,
286,
6725,
9,
221,
327,
336,
1534,
12,
18011,
1,
288,
372,
286,
6725,
398,
22312,
14,
1084,
8,
1113,
12,
283,
6726,
297,
9275,
9,
267,
22312,
14,
1084,
8,
1113,
12,
283,
2931,
297,
1559,
14,
1250,
9,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
24654,
2822,
2176,
12,
291,
680,
5996,
342,
267,
291,
423,
5811,
63,
548,
8,
277,
14,
8957,
12,
30429,
14,
18612,
2571,
864,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Yukarumya/Yukarum-Redfoxes
|
python/pystache/pystache/common.py
|
48
|
2022
|
# coding: utf-8
"""
Exposes functionality needed throughout the project.
"""
from sys import version_info
def _get_string_types():
# TODO: come up with a better solution for this. One of the issues here
# is that in Python 3 there is no common base class for unicode strings
# and byte strings, and 2to3 seems to convert all of "str", "unicode",
# and "basestring" to Python 3's "str".
if version_info < (3, ):
return basestring
# The latter evaluates to "bytes" in Python 3 -- even after conversion by 2to3.
return (unicode, type(u"a".encode('utf-8')))
_STRING_TYPES = _get_string_types()
def is_string(obj):
"""
Return whether the given object is a byte string or unicode string.
This function is provided for compatibility with both Python 2 and 3
when using 2to3.
"""
return isinstance(obj, _STRING_TYPES)
# This function was designed to be portable across Python versions -- both
# with older versions and with Python 3 after applying 2to3.
def read(path):
"""
Return the contents of a text file as a byte string.
"""
# Opening in binary mode is necessary for compatibility across Python
# 2 and 3. In both Python 2 and 3, open() defaults to opening files in
# text mode. However, in Python 2, open() returns file objects whose
# read() method returns byte strings (strings of type `str` in Python 2),
# whereas in Python 3, the file object returns unicode strings (strings
# of type `str` in Python 3).
f = open(path, 'rb')
# We avoid use of the with keyword for Python 2.4 support.
try:
return f.read()
finally:
f.close()
class MissingTags(object):
"""Contains the valid values for Renderer.missing_tags."""
ignore = 'ignore'
strict = 'strict'
class PystacheError(Exception):
"""Base class for Pystache exceptions."""
pass
class TemplateNotFoundError(PystacheError):
"""An exception raised when a template is not found."""
pass
|
mpl-2.0
|
[
3,
2803,
26,
2774,
13,
24,
199,
199,
624,
199,
920,
10553,
9330,
4346,
23088,
314,
2199,
14,
199,
199,
624,
199,
199,
504,
984,
492,
1015,
63,
815,
199,
199,
318,
485,
362,
63,
875,
63,
1313,
837,
272,
327,
3254,
26,
11492,
1536,
543,
282,
8034,
8744,
367,
642,
14,
221,
7309,
402,
314,
10876,
2348,
272,
327,
257,
365,
626,
315,
2018,
650,
2337,
365,
949,
2863,
1300,
1021,
367,
2649,
3326,
272,
327,
257,
436,
3696,
3326,
12,
436,
499,
475,
19,
12237,
370,
3957,
1006,
402,
298,
495,
401,
298,
2975,
401,
272,
327,
257,
436,
298,
17628,
2,
370,
2018,
650,
1159,
298,
495,
1674,
272,
340,
1015,
63,
815,
665,
334,
19,
12,
3461,
268,
372,
7116,
272,
327,
710,
19045,
22014,
370,
298,
2394,
2,
315,
2018,
650,
1553,
2755,
2410,
8603,
701,
499,
475,
19,
14,
272,
372,
334,
2975,
12,
730,
8,
85,
2,
65,
1674,
2143,
360,
1624,
13,
24,
7058,
421,
199,
63,
5353,
63,
7893,
275,
485,
362,
63,
875,
63,
1313,
342,
421,
199,
318,
365,
63,
875,
8,
1113,
304,
272,
408,
272,
1432,
3775,
314,
1627,
909,
365,
282,
3696,
1059,
503,
2649,
1059,
14,
339,
961,
805,
365,
2741,
367,
7163,
543,
3865,
2018,
499,
436,
650,
272,
1380,
1808,
499,
475,
19,
14,
339,
408,
272,
372,
1228,
8,
1113,
12,
485,
5353,
63,
7893,
9,
421,
199,
3,
961,
805,
1990,
19829,
370,
506,
1844,
461,
9371,
2018,
5459,
1553,
3865,
199,
3,
543,
12731,
5459,
436,
543,
2018,
650,
2410,
18876,
499,
475,
19,
14,
199,
318,
1586,
8,
515,
304,
272,
408,
272,
1432,
314,
4072,
402,
282,
1318,
570,
465,
282,
3696,
1059,
14,
339,
408,
272,
327,
3232,
316,
315,
3366,
818,
365,
5784,
367,
7163,
9371,
2018,
272,
327,
499,
436,
650,
14,
221,
1010,
3865,
2018,
499,
436,
650,
12,
1551,
342,
4243,
370,
13618,
1584,
315,
272,
327,
1318,
818,
14,
221,
9738,
12,
315,
2018,
499,
12,
1551,
342,
2529,
570,
2251,
7447,
272,
327,
1586,
342,
1083,
2529,
3696,
3326,
334,
5465,
402,
730,
658,
495,
64,
315,
2018,
499,
395,
272,
327,
29781,
315,
2018,
650,
12,
314,
570,
909,
2529,
2649,
3326,
334,
5465,
272,
327,
402,
730,
658,
495,
64,
315,
2018,
650,
680,
272,
289,
275,
1551,
8,
515,
12,
283,
4848,
358,
272,
327,
2136,
5126,
675,
402,
314,
543,
4252,
367,
2018,
499,
14,
20,
2291,
14,
272,
862,
26,
267,
372,
289,
14,
739,
342,
272,
3753,
26,
267,
289,
14,
1600,
342,
421,
199,
533,
15626,
9440,
8,
785,
304,
339,
408,
6906,
314,
1686,
1338,
367,
10055,
5813,
14,
4752,
63,
2969,
1041,
339,
3686,
275,
283,
4247,
7,
272,
7478,
275,
283,
4768,
7,
421,
199,
533,
1611,
1207,
595,
547,
8,
1726,
304,
272,
408,
1563,
1021,
367,
1611,
1207,
595,
4967,
1041,
272,
986,
421,
199,
533,
5458,
10870,
8,
2713,
1207,
595,
547,
304,
272,
408,
2493,
1919,
4915,
1380,
282,
1978,
365,
440,
1911,
1041,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2803,
26,
2774,
13,
24,
199,
199,
624,
199,
920,
10553,
9330,
4346,
23088,
314,
2199,
14,
199,
199,
624,
199,
199,
504,
984,
492,
1015,
63,
815,
199,
199,
318,
485,
362,
63,
875,
63,
1313,
837,
272,
327,
3254,
26,
11492,
1536,
543,
282,
8034,
8744,
367,
642,
14,
221,
7309,
402,
314,
10876,
2348,
272,
327,
257,
365,
626,
315,
2018,
650,
2337,
365,
949,
2863,
1300,
1021,
367,
2649,
3326,
272,
327,
257,
436,
3696,
3326,
12,
436,
499,
475,
19,
12237,
370,
3957,
1006,
402,
298,
495,
401,
298,
2975,
401,
272,
327,
257,
436,
298,
17628,
2,
370,
2018,
650,
1159,
298,
495,
1674,
272,
340,
1015,
63,
815,
665,
334,
19,
12,
3461,
268,
372,
7116,
272,
327,
710,
19045,
22014,
370,
298,
2394,
2,
315,
2018,
650,
1553,
2755,
2410,
8603,
701,
499,
475,
19,
14,
272,
372,
334,
2975,
12,
730,
8,
85,
2,
65,
1674,
2143,
360,
1624,
13,
24,
7058,
421,
199,
63,
5353,
63,
7893,
275,
485,
362,
63,
875,
63,
1313,
342,
421,
199,
318,
365,
63,
875,
8,
1113,
304,
272,
408,
272,
1432,
3775,
314,
1627,
909,
365,
282,
3696,
1059,
503,
2649,
1059,
14,
339,
961,
805,
365,
2741,
367,
7163,
543,
3865,
2018,
499,
436,
650,
272,
1380,
1808,
499,
475,
19,
14,
339,
408,
272,
372,
1228,
8,
1113,
12,
485,
5353,
63,
7893,
9,
421,
199,
3,
961,
805,
1990,
19829,
370,
506,
1844,
461,
9371,
2018,
5459,
1553,
3865,
199,
3,
543,
12731,
5459,
436,
543,
2018,
650,
2410,
18876,
499,
475,
19,
14,
199,
318,
1586,
8,
515,
304,
272,
408,
272,
1432,
314,
4072,
402,
282,
1318,
570,
465,
282,
3696,
1059,
14,
339,
408,
272,
327,
3232,
316,
315,
3366,
818,
365,
5784,
367,
7163,
9371,
2018,
272,
327,
499,
436,
650,
14,
221,
1010,
3865,
2018,
499,
436,
650,
12,
1551,
342,
4243,
370,
13618,
1584,
315,
272,
327,
1318,
818,
14,
221,
9738,
12,
315,
2018,
499,
12,
1551,
342,
2529,
570,
2251,
7447,
272,
327,
1586,
342,
1083,
2529,
3696,
3326,
334,
5465,
402,
730,
658,
495,
64,
315,
2018,
499,
395,
272,
327,
29781,
315,
2018,
650,
12,
314,
570,
909,
2529,
2649,
3326,
334,
5465,
272,
327,
402,
730,
658,
495,
64,
315,
2018,
650,
680,
272,
289,
275,
1551,
8,
515,
12,
283,
4848,
358,
272,
327,
2136,
5126,
675,
402,
314,
543,
4252,
367,
2018,
499,
14,
20,
2291,
14,
272,
862,
26,
267,
372,
289,
14,
739,
342,
272,
3753,
26,
267,
289,
14,
1600,
342,
421,
199,
533,
15626,
9440,
8,
785,
304,
339,
408,
6906,
314,
1686,
1338,
367,
10055,
5813,
14,
4752,
63,
2969,
1041,
339,
3686,
275,
283,
4247,
7,
272,
7478,
275,
283,
4768,
7,
421,
199,
533,
1611,
1207,
595,
547,
8,
1726,
304,
272,
408,
1563,
1021,
367,
1611,
1207,
595,
4967,
1041,
272,
986,
421,
199,
533,
5458,
10870,
8,
2713,
1207,
595,
547,
304,
272,
408,
2493,
1919,
4915,
1380,
282,
1978,
365,
440,
1911,
1041,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
julianprabhakar/eden_car
|
tests/unit_tests/modules/s3/s3gis/OpenStreetMap.py
|
43
|
1171
|
s3gis_tests = load_module("tests.unit_tests.modules.s3.s3gis")
def test_OpenStreetMap():
s3gis_tests.layer_test(
db,
db.gis_layer_openstreetmap,
dict(
enabled = True,
name = "test OSM layer",
url1 = "http://otile1.example.com/tiles/1.0.0/osm/",
url2 = "http://otile2.example.com/tiles/1.0.0/osm/",
url3 = "http://otile3.example.com/tiles/1.0.0/osm/",
attribution = "These are just test tiles <a href='http://www.example.com/' target='_blank'>Test link</a>",
base = False,
visible = True,
zoom_levels = 18
),
"S3.gis.layers_osm[0]",
{
"name": u"test OSM layer",
"url1": u"http://otile1.example.com/tiles/1.0.0/osm/",
"url2": u"http://otile2.example.com/tiles/1.0.0/osm/",
"url3": u"http://otile3.example.com/tiles/1.0.0/osm/",
"isBaseLayer": False,
"attribution": u"These are just test tiles <a href='http://www.example.com/' target='_blank'>Test link</a>",
"zoomLevels": 18
},
session,
request,
)
|
mit
|
[
199,
83,
19,
5668,
63,
2219,
275,
2248,
63,
578,
480,
2219,
14,
3248,
63,
2219,
14,
3112,
14,
83,
19,
14,
83,
19,
5668,
531,
199,
199,
318,
511,
63,
4299,
933,
7936,
2956,
837,
272,
308,
19,
5668,
63,
2219,
14,
1897,
63,
396,
8,
267,
1592,
12,
267,
1592,
14,
5668,
63,
1897,
63,
1490,
20451,
1130,
12,
267,
1211,
8,
288,
5223,
275,
715,
12,
288,
536,
275,
298,
396,
593,
4029,
4045,
401,
288,
1166,
17,
275,
298,
1014,
921,
79,
7172,
17,
14,
2694,
14,
957,
15,
18819,
15,
17,
14,
16,
14,
16,
15,
30613,
10665,
288,
1166,
18,
275,
298,
1014,
921,
79,
7172,
18,
14,
2694,
14,
957,
15,
18819,
15,
17,
14,
16,
14,
16,
15,
30613,
10665,
288,
1166,
19,
275,
298,
1014,
921,
79,
7172,
19,
14,
2694,
14,
957,
15,
18819,
15,
17,
14,
16,
14,
16,
15,
30613,
10665,
288,
737,
15980,
275,
298,
20676,
787,
2951,
511,
30419,
665,
65,
4369,
534,
1014,
921,
1544,
14,
2694,
14,
957,
4805,
1347,
17574,
2500,
8423,
774,
2142,
1108,
65,
7166,
288,
1300,
275,
756,
12,
288,
8917,
275,
715,
12,
288,
16935,
63,
11402,
275,
6155,
267,
2318,
267,
298,
51,
19,
14,
5668,
14,
4359,
63,
30613,
59,
16,
11472,
267,
469,
288,
298,
354,
582,
399,
2,
396,
593,
4029,
4045,
401,
288,
298,
633,
17,
582,
399,
2,
1014,
921,
79,
7172,
17,
14,
2694,
14,
957,
15,
18819,
15,
17,
14,
16,
14,
16,
15,
30613,
10665,
288,
298,
633,
18,
582,
399,
2,
1014,
921,
79,
7172,
18,
14,
2694,
14,
957,
15,
18819,
15,
17,
14,
16,
14,
16,
15,
30613,
10665,
288,
298,
633,
19,
582,
399,
2,
1014,
921,
79,
7172,
19,
14,
2694,
14,
957,
15,
18819,
15,
17,
14,
16,
14,
16,
15,
30613,
10665,
288,
298,
374,
1563,
5003,
582,
756,
12,
288,
298,
292,
15980,
582,
399,
2,
20676,
787,
2951,
511,
30419,
665,
65,
4369,
534,
1014,
921,
1544,
14,
2694,
14,
957,
4805,
1347,
17574,
2500,
8423,
774,
2142,
1108,
65,
7166,
288,
298,
10598,
4670,
83,
582,
6155,
267,
1660,
267,
2351,
12,
267,
1056,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
83,
19,
5668,
63,
2219,
275,
2248,
63,
578,
480,
2219,
14,
3248,
63,
2219,
14,
3112,
14,
83,
19,
14,
83,
19,
5668,
531,
199,
199,
318,
511,
63,
4299,
933,
7936,
2956,
837,
272,
308,
19,
5668,
63,
2219,
14,
1897,
63,
396,
8,
267,
1592,
12,
267,
1592,
14,
5668,
63,
1897,
63,
1490,
20451,
1130,
12,
267,
1211,
8,
288,
5223,
275,
715,
12,
288,
536,
275,
298,
396,
593,
4029,
4045,
401,
288,
1166,
17,
275,
298,
1014,
921,
79,
7172,
17,
14,
2694,
14,
957,
15,
18819,
15,
17,
14,
16,
14,
16,
15,
30613,
10665,
288,
1166,
18,
275,
298,
1014,
921,
79,
7172,
18,
14,
2694,
14,
957,
15,
18819,
15,
17,
14,
16,
14,
16,
15,
30613,
10665,
288,
1166,
19,
275,
298,
1014,
921,
79,
7172,
19,
14,
2694,
14,
957,
15,
18819,
15,
17,
14,
16,
14,
16,
15,
30613,
10665,
288,
737,
15980,
275,
298,
20676,
787,
2951,
511,
30419,
665,
65,
4369,
534,
1014,
921,
1544,
14,
2694,
14,
957,
4805,
1347,
17574,
2500,
8423,
774,
2142,
1108,
65,
7166,
288,
1300,
275,
756,
12,
288,
8917,
275,
715,
12,
288,
16935,
63,
11402,
275,
6155,
267,
2318,
267,
298,
51,
19,
14,
5668,
14,
4359,
63,
30613,
59,
16,
11472,
267,
469,
288,
298,
354,
582,
399,
2,
396,
593,
4029,
4045,
401,
288,
298,
633,
17,
582,
399,
2,
1014,
921,
79,
7172,
17,
14,
2694,
14,
957,
15,
18819,
15,
17,
14,
16,
14,
16,
15,
30613,
10665,
288,
298,
633,
18,
582,
399,
2,
1014,
921,
79,
7172,
18,
14,
2694,
14,
957,
15,
18819,
15,
17,
14,
16,
14,
16,
15,
30613,
10665,
288,
298,
633,
19,
582,
399,
2,
1014,
921,
79,
7172,
19,
14,
2694,
14,
957,
15,
18819,
15,
17,
14,
16,
14,
16,
15,
30613,
10665,
288,
298,
374,
1563,
5003,
582,
756,
12,
288,
298,
292,
15980,
582,
399,
2,
20676,
787,
2951,
511,
30419,
665,
65,
4369,
534,
1014,
921,
1544,
14,
2694,
14,
957,
4805,
1347,
17574,
2500,
8423,
774,
2142,
1108,
65,
7166,
288,
298,
10598,
4670,
83,
582,
6155,
267,
1660,
267,
2351,
12,
267,
1056,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
hifly/OpenUpgrade
|
addons/base_report_designer/openerp_sxw2rml/__init__.py
|
423
|
1091
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp_sxw2rml import sxw2rml
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
504,
5166,
63,
20851,
18,
16300,
492,
23132,
87,
18,
16300,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
504,
5166,
63,
20851,
18,
16300,
492,
23132,
87,
18,
16300,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
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script/tskdbdiff.py
|
2
|
39751
|
# Requires python3
import re
import sqlite3
import subprocess
import shutil
import os
import codecs
import datetime
import sys
import psycopg2
import psycopg2.extras
import socket
import csv
class TskDbDiff(object):
"""Compares two TSK/Autospy SQLite databases.
Attributes:
gold_artifacts:
autopsy_artifacts:
gold_attributes:
autopsy_attributes:
gold_objects:
autopsy_objects:
artifact_comparison:
attribute_comparision:
report_errors: a listof_listof_String, the error messages that will be
printed to screen in the run_diff method
passed: a boolean, did the diff pass?
autopsy_db_file:
gold_db_file:
"""
def __init__(self, output_db, gold_db, output_dir=None, gold_bb_dump=None, gold_dump=None, verbose=False, isMultiUser=False, pgSettings=None):
"""Constructor for TskDbDiff.
Args:
output_db_path: path to output database (non-gold standard)
gold_db_path: path to gold database
output_dir: (optional) Path to folder where generated files will be put.
gold_bb_dump: (optional) path to file where the gold blackboard dump is located
gold_dump: (optional) path to file where the gold non-blackboard dump is located
verbose: (optional) a boolean, if true, diff results are sent to stdout.
"""
self.output_db_file = output_db
self.gold_db_file = gold_db
self.output_dir = output_dir
self.gold_bb_dump = gold_bb_dump
self.gold_dump = gold_dump
self._generate_gold_dump = False
self._generate_gold_bb_dump = False
self._bb_dump_diff = ""
self._dump_diff = ""
self._bb_dump = ""
self._dump = ""
self.verbose = verbose
self.isMultiUser = isMultiUser
self.pgSettings = pgSettings
if self.isMultiUser and not self.pgSettings:
print("Missing PostgreSQL database connection settings data.")
sys.exit(1)
if self.gold_bb_dump is None:
self._generate_gold_bb_dump = True
if self.gold_dump is None:
self._generate_gold_dump = True
def run_diff(self):
"""Compare the databases.
Raises:
TskDbDiffException: if an error occurs while diffing or dumping the database
"""
self._init_diff()
id_obj_path_table = -1
# generate the gold database dumps if necessary
if self._generate_gold_dump:
id_obj_path_table = TskDbDiff._dump_output_db_nonbb(self.gold_db_file, self.gold_dump, self.isMultiUser, self.pgSettings)
if self._generate_gold_bb_dump:
TskDbDiff._dump_output_db_bb(self.gold_db_file, self.gold_bb_dump, self.isMultiUser, self.pgSettings, id_obj_path_table)
# generate the output database dumps (both DB and BB)
id_obj_path_table = TskDbDiff._dump_output_db_nonbb(self.output_db_file, self._dump, self.isMultiUser, self.pgSettings)
TskDbDiff._dump_output_db_bb(self.output_db_file, self._bb_dump, self.isMultiUser, self.pgSettings, id_obj_path_table)
# Compare non-BB
dump_diff_pass = self._diff(self._dump, self.gold_dump, self._dump_diff)
# Compare BB
bb_dump_diff_pass = self._diff(self._bb_dump, self.gold_bb_dump, self._bb_dump_diff)
self._cleanup_diff()
return dump_diff_pass, bb_dump_diff_pass
def _init_diff(self):
"""Set up the necessary files based on the arguments given at construction"""
if self.output_dir is None:
# No stored files
self._bb_dump = TskDbDiff._get_tmp_file("BlackboardDump", ".txt")
self._bb_dump_diff = TskDbDiff._get_tmp_file("BlackboardDump-Diff", ".txt")
self._dump = TskDbDiff._get_tmp_file("DBDump", ".txt")
self._dump_diff = TskDbDiff._get_tmp_file("DBDump-Diff", ".txt")
else:
self._bb_dump = os.path.join(self.output_dir, "BlackboardDump.txt")
self._bb_dump_diff = os.path.join(self.output_dir, "BlackboardDump-Diff.txt")
self._dump = os.path.join(self.output_dir, "DBDump.txt")
self._dump_diff = os.path.join(self.output_dir, "DBDump-Diff.txt")
# Sorting gold before comparing (sort behaves differently in different environments)
new_bb = TskDbDiff._get_tmp_file("GoldBlackboardDump", ".txt")
new_db = TskDbDiff._get_tmp_file("GoldDBDump", ".txt")
if self.gold_bb_dump is not None:
srtcmdlst = ["sort", self.gold_bb_dump, "-o", new_bb]
subprocess.call(srtcmdlst)
srtcmdlst = ["sort", self.gold_dump, "-o", new_db]
subprocess.call(srtcmdlst)
self.gold_bb_dump = new_bb
self.gold_dump = new_db
def _cleanup_diff(self):
if self.output_dir is None:
#cleanup temp files
os.remove(self._dump)
os.remove(self._bb_dump)
if os.path.isfile(self._dump_diff):
os.remove(self._dump_diff)
if os.path.isfile(self._bb_dump_diff):
os.remove(self._bb_dump_diff)
if self.gold_bb_dump is None:
os.remove(self.gold_bb_dump)
os.remove(self.gold_dump)
def _diff(self, output_file, gold_file, diff_path):
"""Compare two text files.
Args:
output_file: a pathto_File, the latest text file
gold_file: a pathto_File, the gold text file
diff_path: The file to write the differences to
Returns False if different
"""
if (not os.path.isfile(output_file)):
return False
if (not os.path.isfile(gold_file)):
return False
# It is faster to read the contents in and directly compare
output_data = codecs.open(output_file, "r", "utf_8").read()
gold_data = codecs.open(gold_file, "r", "utf_8").read()
if (gold_data == output_data):
return True
# If they are different, invoke 'diff'
diff_file = codecs.open(diff_path, "wb", "utf_8")
# Gold needs to be passed in as 1st arg and output as 2nd
dffcmdlst = ["diff", gold_file, output_file]
subprocess.call(dffcmdlst, stdout = diff_file)
# create file path for gold files inside output folder. In case of diff, both gold and current run files
# are available in the report output folder. Prefix Gold- is added to the filename.
gold_file_in_output_dir = output_file[:output_file.rfind("/")] + "/Gold-" + output_file[output_file.rfind("/")+1:]
shutil.copy(gold_file, gold_file_in_output_dir)
return False
def _dump_output_db_bb(db_file, bb_dump_file, isMultiUser, pgSettings, id_obj_path_table):
"""Dumps sorted text results to the given output location.
Smart method that deals with a blackboard comparison to avoid issues
with different IDs based on when artifacts were created.
Args:
db_file: a pathto_File, the output database.
bb_dump_file: a pathto_File, the sorted dump file to write to
"""
unsorted_dump = TskDbDiff._get_tmp_file("dump_data", ".txt")
if isMultiUser:
conn, unused_db = db_connect(db_file, isMultiUser, pgSettings)
artifact_cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
else: # Use Sqlite
conn = sqlite3.connect(db_file)
conn.text_factory = lambda x: x.decode("utf-8", "ignore")
conn.row_factory = sqlite3.Row
artifact_cursor = conn.cursor()
# Get the list of all artifacts (along with type and associated file)
# @@@ Could add a SORT by parent_path in here since that is how we are going to later sort it.
artifact_cursor.execute("SELECT tsk_files.parent_path, tsk_files.name, blackboard_artifact_types.display_name, blackboard_artifacts.artifact_id FROM blackboard_artifact_types INNER JOIN blackboard_artifacts ON blackboard_artifact_types.artifact_type_id = blackboard_artifacts.artifact_type_id INNER JOIN tsk_files ON tsk_files.obj_id = blackboard_artifacts.obj_id")
database_log = codecs.open(unsorted_dump, "wb", "utf_8")
row = artifact_cursor.fetchone()
appnd = False
counter = 0
artifact_count = 0
artifact_fail = 0
# Cycle through artifacts
try:
while (row != None):
# File Name and artifact type
if(row["parent_path"] != None):
database_log.write(row["parent_path"] + row["name"] + ' <artifact type="' + row["display_name"] + '" > ')
else:
database_log.write(row["name"] + ' <artifact type="' + row["display_name"] + '" > ')
if isMultiUser:
attribute_cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
else:
attribute_cursor = conn.cursor()
looptry = True
artifact_count += 1
try:
art_id = ""
art_id = str(row["artifact_id"])
# Get attributes for this artifact
if isMultiUser:
attribute_cursor.execute("SELECT blackboard_attributes.source, blackboard_attributes.attribute_type_id, blackboard_attribute_types.display_name, blackboard_attributes.value_type, blackboard_attributes.value_text, blackboard_attributes.value_int32, blackboard_attributes.value_int64, blackboard_attributes.value_double FROM blackboard_attributes INNER JOIN blackboard_attribute_types ON blackboard_attributes.attribute_type_id = blackboard_attribute_types.attribute_type_id WHERE artifact_id = %s ORDER BY blackboard_attributes.source, blackboard_attribute_types.display_name, blackboard_attributes.value_type, blackboard_attributes.value_text, blackboard_attributes.value_int32, blackboard_attributes.value_int64, blackboard_attributes.value_double", [art_id])
else:
attribute_cursor.execute("SELECT blackboard_attributes.source, blackboard_attributes.attribute_type_id, blackboard_attribute_types.display_name, blackboard_attributes.value_type, blackboard_attributes.value_text, blackboard_attributes.value_int32, blackboard_attributes.value_int64, blackboard_attributes.value_double FROM blackboard_attributes INNER JOIN blackboard_attribute_types ON blackboard_attributes.attribute_type_id = blackboard_attribute_types.attribute_type_id WHERE artifact_id =? ORDER BY blackboard_attributes.source, blackboard_attribute_types.display_name, blackboard_attributes.value_type, blackboard_attributes.value_text, blackboard_attributes.value_int32, blackboard_attributes.value_int64, blackboard_attributes.value_double", [art_id])
attributes = attribute_cursor.fetchall()
# Print attributes
if (len(attributes) == 0):
# @@@@ This should be </artifact>
database_log.write(' <artifact/>\n')
row = artifact_cursor.fetchone()
continue
src = attributes[0][0]
for attr in attributes:
numvals = 0
for x in range(3, 6):
if(attr[x] != None):
numvals += 1
if(numvals > 1):
msg = "There were too many values for attribute type: " + attr["display_name"] + " for artifact with id #" + str(row["artifact_id"]) + ".\n"
if(not attr["source"] == src):
msg = "There were inconsistent sources for artifact with id #" + str(row["artifact_id"]) + ".\n"
try:
if attr["value_type"] == 0:
attr_value_as_string = str(attr["value_text"])
elif attr["value_type"] == 1:
attr_value_as_string = str(attr["value_int32"])
elif attr["value_type"] == 2:
attr_value_as_string = str(attr["value_int64"])
if attr["attribute_type_id"] == 36 and id_obj_path_table != -1 and int(attr_value_as_string) > 0: #normalize positive TSK_PATH_IDs from being object id to a path if the obj_id_path_table was generated
attr_value_as_string = id_obj_path_table[int(attr_value_as_string)]
elif attr["value_type"] == 3:
attr_value_as_string = "%20.10f" % float((attr["value_double"])) #use exact format from db schema to avoid python auto format double value to (0E-10) scientific style
elif attr["value_type"] == 4:
attr_value_as_string = "bytes"
elif attr["value_type"] == 5:
attr_value_as_string = str(attr["value_int64"])
if attr["display_name"] == "Associated Artifact":
attr_value_as_string = getAssociatedArtifactType(attribute_cursor, attr_value_as_string, isMultiUser)
patrn = re.compile("[\n\0\a\b\r\f]")
attr_value_as_string = re.sub(patrn, ' ', attr_value_as_string)
database_log.write('<attribute source="' + attr["source"] + '" type="' + attr["display_name"] + '" value="' + attr_value_as_string + '" />')
except IOError as e:
print("IO error")
raise TskDbDiffException("Unexpected IO error while writing to database log." + str(e))
except sqlite3.Error as e:
msg = "Attributes in artifact id (in output DB)# " + str(row["artifact_id"]) + " encountered an error: " + str(e) +" .\n"
print("Attributes in artifact id (in output DB)# ", str(row["artifact_id"]), " encountered an error: ", str(e))
print()
looptry = False
artifact_fail += 1
database_log.write('Error Extracting Attributes')
database_log.close()
raise TskDbDiffException(msg)
finally:
attribute_cursor.close()
# @@@@ This should be </artifact>
database_log.write(' <artifact/>\n')
row = artifact_cursor.fetchone()
if(artifact_fail > 0):
msg ="There were " + str(artifact_count) + " artifacts and " + str(artifact_fail) + " threw an exception while loading.\n"
except Exception as e:
raise TskDbDiffException("Unexpected error while dumping blackboard database: " + str(e))
finally:
database_log.close()
artifact_cursor.close()
conn.close()
# Now sort the file
srtcmdlst = ["sort", unsorted_dump, "-o", bb_dump_file]
subprocess.call(srtcmdlst)
def _dump_output_db_nonbb(db_file, dump_file, isMultiUser, pgSettings):
"""Dumps a database to a text file.
Does not dump the artifact and attributes.
Args:
db_file: a pathto_File, the database file to dump
dump_file: a pathto_File, the location to dump the non-blackboard database items
"""
conn, backup_db_file = db_connect(db_file, isMultiUser, pgSettings)
id_files_table = build_id_files_table(conn.cursor(), isMultiUser)
id_vs_parts_table = build_id_vs_parts_table(conn.cursor(), isMultiUser)
id_vs_info_table = build_id_vs_info_table(conn.cursor(), isMultiUser)
id_fs_info_table = build_id_fs_info_table(conn.cursor(), isMultiUser)
id_objects_table = build_id_objects_table(conn.cursor(), isMultiUser)
id_artifact_types_table = build_id_artifact_types_table(conn.cursor(), isMultiUser)
id_legacy_artifact_types = build_id_legacy_artifact_types_table(conn.cursor(), isMultiUser)
id_reports_table = build_id_reports_table(conn.cursor(), isMultiUser)
id_images_table = build_id_image_names_table(conn.cursor(), isMultiUser)
id_obj_path_table = build_id_obj_path_table(id_files_table, id_objects_table, id_artifact_types_table, id_reports_table, id_images_table)
if isMultiUser: # Use PostgreSQL
os.environ['PGPASSWORD']=pgSettings.password
pgDump = ["pg_dump", "--inserts", "-U", pgSettings.username, "-h", pgSettings.pgHost, "-p", pgSettings.pgPort, "-d", db_file, "-E", "utf-8", "-T", "blackboard_artifacts", "-T", "blackboard_attributes", "-f", "postgreSQLDump.sql"]
subprocess.call(pgDump)
postgreSQL_db = codecs.open("postgreSQLDump.sql", "r", "utf-8")
# Write to the database dump
with codecs.open(dump_file, "wb", "utf_8") as db_log:
dump_line = ''
for line in postgreSQL_db:
line = line.strip('\r\n ')
# Deal with pg_dump result file
if (line.startswith('--') or line.lower().startswith('alter') or "pg_catalog" in line or "idle_in_transaction_session_timeout" in line or not line): # It's comment or alter statement or catalog entry or set idle entry or empty line
continue
elif not line.endswith(';'): # Statement not finished
dump_line += line
continue
else:
dump_line += line
if 'INSERT INTO image_gallery_groups_seen' in dump_line:
dump_line = ''
continue;
dump_line = normalize_db_entry(dump_line, id_obj_path_table, id_vs_parts_table, id_vs_info_table, id_fs_info_table, id_objects_table, id_reports_table, id_images_table, id_legacy_artifact_types)
db_log.write('%s\n' % dump_line)
dump_line = ''
postgreSQL_db.close()
else: # use Sqlite
# Delete the blackboard tables
conn.text_factory = lambda x: x.decode("utf-8", "ignore")
conn.execute("DROP TABLE blackboard_artifacts")
conn.execute("DROP TABLE blackboard_attributes")
# Write to the database dump
with codecs.open(dump_file, "wb", "utf_8") as db_log:
for line in conn.iterdump():
if 'INSERT INTO "image_gallery_groups_seen"' in line:
continue
line = normalize_db_entry(line, id_obj_path_table, id_vs_parts_table, id_vs_info_table, id_fs_info_table, id_objects_table, id_reports_table, id_images_table, id_legacy_artifact_types)
db_log.write('%s\n' % line)
# Now sort the file
srtcmdlst = ["sort", dump_file, "-o", dump_file]
subprocess.call(srtcmdlst)
conn.close()
# cleanup the backup
if backup_db_file:
os.remove(backup_db_file)
return id_obj_path_table
def dump_output_db(db_file, dump_file, bb_dump_file, isMultiUser, pgSettings):
"""Dumps the given database to text files for later comparison.
Args:
db_file: a pathto_File, the database file to dump
dump_file: a pathto_File, the location to dump the non-blackboard database items
bb_dump_file: a pathto_File, the location to dump the blackboard database items
"""
id_obj_path_table = TskDbDiff._dump_output_db_nonbb(db_file, dump_file, isMultiUser, pgSettings)
TskDbDiff._dump_output_db_bb(db_file, bb_dump_file, isMultiUser, pgSettings, id_obj_path_table)
def _get_tmp_file(base, ext):
time = datetime.datetime.now().time().strftime("%H%M%f")
return os.path.join(os.environ['TMP'], base + time + ext)
class TskDbDiffException(Exception):
pass
class PGSettings(object):
def __init__(self, pgHost=None, pgPort=5432, user=None, password=None):
self.pgHost = pgHost
self.pgPort = pgPort
self.username = user
self.password = password
def get_pgHost():
return self.pgHost
def get_pgPort():
return self.pgPort
def get_username():
return self.username
def get_password():
return self.password
def normalize_db_entry(line, files_table, vs_parts_table, vs_info_table, fs_info_table, objects_table, reports_table, images_table, artifact_table):
""" Make testing more consistent and reasonable by doctoring certain db entries.
Args:
line: a String, the line to remove the object id from.
files_table: a map from object ids to file paths.
"""
# Sqlite statement use double quotes for table name, PostgreSQL doesn't. We check both databases results for normalization.
files_index = line.find('INSERT INTO "tsk_files"') > -1 or line.find('INSERT INTO tsk_files ') > -1
path_index = line.find('INSERT INTO "tsk_files_path"') > -1 or line.find('INSERT INTO tsk_files_path ') > -1
object_index = line.find('INSERT INTO "tsk_objects"') > -1 or line.find('INSERT INTO tsk_objects ') > -1
report_index = line.find('INSERT INTO "reports"') > -1 or line.find('INSERT INTO reports ') > -1
layout_index = line.find('INSERT INTO "tsk_file_layout"') > -1 or line.find('INSERT INTO tsk_file_layout ') > -1
data_source_info_index = line.find('INSERT INTO "data_source_info"') > -1 or line.find('INSERT INTO data_source_info ') > -1
event_description_index = line.find('INSERT INTO "tsk_event_descriptions"') > -1 or line.find('INSERT INTO tsk_event_descriptions ') > -1
events_index = line.find('INSERT INTO "tsk_events"') > -1 or line.find('INSERT INTO tsk_events ') > -1
ingest_job_index = line.find('INSERT INTO "ingest_jobs"') > -1 or line.find('INSERT INTO ingest_jobs ') > -1
examiners_index = line.find('INSERT INTO "tsk_examiners"') > -1 or line.find('INSERT INTO tsk_examiners ') > -1
ig_groups_index = line.find('INSERT INTO "image_gallery_groups"') > -1 or line.find('INSERT INTO image_gallery_groups ') > -1
ig_groups_seen_index = line.find('INSERT INTO "image_gallery_groups_seen"') > -1 or line.find('INSERT INTO image_gallery_groups_seen ') > -1
parens = line[line.find('(') + 1 : line.rfind(')')]
no_space_parens = parens.replace(" ", "")
fields_list = list(csv.reader([no_space_parens], quotechar="'"))[0]
#Add back in the quotechar for values that were originally wrapped (csv reader consumes this character)
fields_list_with_quotes = []
ptr = 0
for field in fields_list:
if(len(field) == 0):
field = "'" + field + "'"
else:
start = no_space_parens.find(field, ptr)
if((start - 1) >= 0 and no_space_parens[start - 1] == '\''):
if((start + len(field)) < len(no_space_parens) and no_space_parens[start + len(field)] == '\''):
field = "'" + field + "'"
fields_list_with_quotes.append(field)
if(ptr > 0):
#Add one for each comma that is used to separate values in the original string
ptr+=1
ptr += len(field)
fields_list = fields_list_with_quotes
# remove object ID
if files_index:
newLine = ('INSERT INTO "tsk_files" VALUES(' + ', '.join(fields_list[1:]) + ');')
return newLine
# remove group ID
elif ig_groups_index:
newLine = ('INSERT INTO "image_gallery_groups" VALUES(' + ', '.join(fields_list[1:]) + ');')
return newLine
#remove id field
elif ig_groups_seen_index:
# Only removing the id and group_id fields for now. May need to care about examiner_id and seen fields in future.
newLine = ('INSERT INTO "image_gallery_groups_seen" VALUES(' + ', '.join(fields_list[2:]) + ');')
return newLine
# remove object ID
elif path_index:
obj_id = int(fields_list[0])
objValue = files_table[obj_id]
# remove the obj_id from ModuleOutput/EmbeddedFileExtractor directory
idx_pre = fields_list[1].find('EmbeddedFileExtractor') + len('EmbeddedFileExtractor')
if idx_pre > -1:
idx_pos = fields_list[1].find('\\', idx_pre + 2)
dir_to_replace = fields_list[1][idx_pre + 1 : idx_pos] # +1 to skip the file seperator
dir_to_replace = dir_to_replace[0:dir_to_replace.rfind('_')]
pathValue = fields_list[1][:idx_pre+1] + dir_to_replace + fields_list[1][idx_pos:]
else:
pathValue = fields_list[1]
# remove localhost from postgres par_obj_name
multiOutput_idx = pathValue.find('ModuleOutput')
if multiOutput_idx > -1:
pathValue = "'" + pathValue[pathValue.find('ModuleOutput'):] #postgres par_obj_name include losthost
newLine = ('INSERT INTO "tsk_files_path" VALUES(' + objValue + ', ' + pathValue + ', ' + ', '.join(fields_list[2:]) + ');')
return newLine
# remove object ID
elif layout_index:
obj_id = fields_list[0]
path= files_table[int(obj_id)]
newLine = ('INSERT INTO "tsk_file_layout" VALUES(' + path + ', ' + ', '.join(fields_list[1:]) + ');')
return newLine
# remove object ID
elif object_index:
obj_id = fields_list[0]
parent_id = fields_list[1]
newLine = 'INSERT INTO "tsk_objects" VALUES('
path = None
parent_path = None
#if obj_id or parent_id is invalid literal, we simple return the values as it is
try:
obj_id = int(obj_id)
if parent_id != 'NULL':
parent_id = int(parent_id)
except Exception as e:
print(obj_id, parent_id)
return line
if obj_id in files_table.keys():
path = files_table[obj_id]
elif obj_id in vs_parts_table.keys():
path = vs_parts_table[obj_id]
elif obj_id in vs_info_table.keys():
path = vs_info_table[obj_id]
elif obj_id in fs_info_table.keys():
path = fs_info_table[obj_id]
elif obj_id in reports_table.keys():
path = reports_table[obj_id]
# remove host name (for multi-user) and dates/times from path for reports
if path is not None:
if 'ModuleOutput' in path:
# skip past the host name (if any)
path = path[path.find('ModuleOutput'):]
if 'BulkExtractor' in path or 'Smirk' in path:
# chop off the last folder (which contains a date/time)
path = path[:path.rfind('\\')]
if 'Reports\\AutopsyTestCase HTML Report' in path:
path = 'Reports\\AutopsyTestCase HTML Report'
if parent_id in files_table.keys():
parent_path = files_table[parent_id]
elif parent_id in vs_parts_table.keys():
parent_path = vs_parts_table[parent_id]
elif parent_id in vs_info_table.keys():
parent_path = vs_info_table[parent_id]
elif parent_id in fs_info_table.keys():
parent_path = fs_info_table[parent_id]
elif parent_id in images_table.keys():
parent_path = images_table[parent_id]
elif parent_id == 'NULL':
parent_path = "NULL"
# Remove host name (for multi-user) from parent_path
if parent_path is not None:
if 'ModuleOutput' in parent_path:
# skip past the host name (if any)
parent_path = parent_path[parent_path.find('ModuleOutput'):]
if path and parent_path:
return newLine + path + ', ' + parent_path + ', ' + ', '.join(fields_list[2:]) + ');'
else:
return line
# remove time-based information, ie Test_6/11/14 -> Test
elif report_index:
fields_list[1] = "AutopsyTestCase"
fields_list[2] = "0"
newLine = ('INSERT INTO "reports" VALUES(' + ','.join(fields_list[1:]) + ');') # remove report_id
return newLine
elif data_source_info_index:
fields_list[1] = "{device id}"
newLine = ('INSERT INTO "data_source_info" VALUES(' + ','.join(fields_list) + ');')
return newLine
elif ingest_job_index:
fields_list[2] = "{host_name}"
start_time = int(fields_list[3])
end_time = int(fields_list[4])
if (start_time <= end_time):
fields_list[3] = "0"
fields_list[4] = "0"
newLine = ('INSERT INTO "ingest_jobs" VALUES(' + ','.join(fields_list) + ');')
return newLine
elif examiners_index:
fields_list[1] = "{examiner_name}"
newLine = ('INSERT INTO "tsk_examiners" VALUES(' + ','.join(fields_list) + ');')
return newLine
# remove all timing dependent columns from events table
elif events_index:
newLine = ('INSERT INTO "tsk_events" VALUES(' + ','.join(fields_list[1:2]) + ');')
return newLine
# remove object ids from event description table
elif event_description_index:
# replace object ids with information that is deterministic
file_obj_id = int(fields_list[5])
object_id = int(fields_list[4])
legacy_artifact_id = 'NULL'
if (fields_list[6] != 'NULL'):
legacy_artifact_id = int(fields_list[6])
if file_obj_id != 'NULL' and file_obj_id in files_table.keys():
fields_list[5] = files_table[file_obj_id]
if object_id != 'NULL' and object_id in files_table.keys():
fields_list[4] = files_table[object_id]
if legacy_artifact_id != 'NULL' and legacy_artifact_id in artifact_table.keys():
fields_list[6] = artifact_table[legacy_artifact_id]
newLine = ('INSERT INTO "tsk_event_descriptions" VALUES(' + ','.join(fields_list[1:]) + ');') # remove report_id
return newLine
else:
return line
def getAssociatedArtifactType(cur, artifact_id, isMultiUser):
if isMultiUser:
cur.execute("SELECT tsk_files.parent_path, blackboard_artifact_types.display_name FROM blackboard_artifact_types INNER JOIN blackboard_artifacts ON blackboard_artifact_types.artifact_type_id = blackboard_artifacts.artifact_type_id INNER JOIN tsk_files ON tsk_files.obj_id = blackboard_artifacts.obj_id WHERE artifact_id=%s",[artifact_id])
else:
cur.execute("SELECT tsk_files.parent_path, blackboard_artifact_types.display_name FROM blackboard_artifact_types INNER JOIN blackboard_artifacts ON blackboard_artifact_types.artifact_type_id = blackboard_artifacts.artifact_type_id INNER JOIN tsk_files ON tsk_files.obj_id = blackboard_artifacts.obj_id WHERE artifact_id=?",[artifact_id])
info = cur.fetchone()
return "File path: " + info[0] + " Artifact Type: " + info[1]
def build_id_files_table(db_cursor, isPostgreSQL):
"""Build the map of object ids to file paths.
Args:
db_cursor: the database cursor
"""
# for each row in the db, take the object id, parent path, and name, then create a tuple in the dictionary
# with the object id as the key and the full file path (parent + name) as the value
mapping = dict([(row[0], str(row[1]) + str(row[2])) for row in sql_select_execute(db_cursor, isPostgreSQL, "SELECT obj_id, parent_path, name FROM tsk_files")])
return mapping
def build_id_vs_parts_table(db_cursor, isPostgreSQL):
"""Build the map of object ids to vs_parts.
Args:
db_cursor: the database cursor
"""
# for each row in the db, take the object id, addr, and start, then create a tuple in the dictionary
# with the object id as the key and (addr + start) as the value
mapping = dict([(row[0], str(row[1]) + '_' + str(row[2])) for row in sql_select_execute(db_cursor, isPostgreSQL, "SELECT obj_id, addr, start FROM tsk_vs_parts")])
return mapping
def build_id_vs_info_table(db_cursor, isPostgreSQL):
"""Build the map of object ids to vs_info.
Args:
db_cursor: the database cursor
"""
# for each row in the db, take the object id, vs_type, and img_offset, then create a tuple in the dictionary
# with the object id as the key and (vs_type + img_offset) as the value
mapping = dict([(row[0], str(row[1]) + '_' + str(row[2])) for row in sql_select_execute(db_cursor, isPostgreSQL, "SELECT obj_id, vs_type, img_offset FROM tsk_vs_info")])
return mapping
def build_id_fs_info_table(db_cursor, isPostgreSQL):
"""Build the map of object ids to fs_info.
Args:
db_cursor: the database cursor
"""
# for each row in the db, take the object id, img_offset, and fs_type, then create a tuple in the dictionary
# with the object id as the key and (img_offset + fs_type) as the value
mapping = dict([(row[0], str(row[1]) + '_' + str(row[2])) for row in sql_select_execute(db_cursor, isPostgreSQL, "SELECT obj_id, img_offset, fs_type FROM tsk_fs_info")])
return mapping
def build_id_objects_table(db_cursor, isPostgreSQL):
"""Build the map of object ids to par_id.
Args:
db_cursor: the database cursor
"""
# for each row in the db, take the object id, par_obj_id, then create a tuple in the dictionary
# with the object id as the key and par_obj_id, type as the value
mapping = dict([(row[0], [row[1], row[2]]) for row in sql_select_execute(db_cursor, isPostgreSQL, "SELECT * FROM tsk_objects")])
return mapping
def build_id_image_names_table(db_cursor, isPostgreSQL):
"""Build the map of object ids to name.
Args:
db_cursor: the database cursor
"""
# for each row in the db, take the object id and name then create a tuple in the dictionary
# with the object id as the key and name, type as the value
mapping = dict([(row[0], row[1]) for row in sql_select_execute(db_cursor, isPostgreSQL, "SELECT obj_id, name FROM tsk_image_names WHERE sequence=0")])
#data_sources which are logical file sets will be found in the files table
return mapping
def build_id_artifact_types_table(db_cursor, isPostgreSQL):
"""Build the map of object ids to artifact ids.
Args:
db_cursor: the database cursor
"""
# for each row in the db, take the object id, par_obj_id, then create a tuple in the dictionary
# with the object id as the key and artifact type as the value
mapping = dict([(row[0], row[1]) for row in sql_select_execute(db_cursor, isPostgreSQL, "SELECT blackboard_artifacts.artifact_obj_id, blackboard_artifact_types.type_name FROM blackboard_artifacts INNER JOIN blackboard_artifact_types ON blackboard_artifact_types.artifact_type_id = blackboard_artifacts.artifact_type_id ")])
return mapping
def build_id_legacy_artifact_types_table(db_cursor, isPostgreSQL):
"""Build the map of legacy artifact ids to artifact type.
Args:
db_cursor: the database cursor
"""
# for each row in the db, take the legacy artifact id then create a tuple in the dictionary
# with the artifact id as the key and artifact type as the value
mapping = dict([(row[0], row[1]) for row in sql_select_execute(db_cursor, isPostgreSQL, "SELECT blackboard_artifacts.artifact_id, blackboard_artifact_types.type_name FROM blackboard_artifacts INNER JOIN blackboard_artifact_types ON blackboard_artifact_types.artifact_type_id = blackboard_artifacts.artifact_type_id ")])
return mapping
def build_id_reports_table(db_cursor, isPostgreSQL):
"""Build the map of report object ids to report path.
Args:
db_cursor: the database cursor
"""
# for each row in the reports table in the db, create an obj_id -> path map
mapping = dict([(row[0], row[1]) for row in sql_select_execute(db_cursor, isPostgreSQL, "SELECT obj_id, path FROM reports")])
return mapping
def build_id_obj_path_table(files_table, objects_table, artifacts_table, reports_table, images_table):
"""Build the map of object ids to artifact ids.
Args:
files_table: obj_id, path
objects_table: obj_id, par_obj_id, type
artifacts_table: obj_id, artifact_type_name
reports_table: obj_id, path
"""
# make a copy of files_table and update it with new data from artifacts_table and reports_table
mapping = files_table.copy()
for k, v in objects_table.items():
path = ""
if k not in mapping.keys(): # If the mapping table doesn't have data for obj_id
if k in reports_table.keys(): # For a report we use the report path
par_obj_id = v[0]
if par_obj_id is not None:
mapping[k] = reports_table[k]
elif k in artifacts_table.keys(): # For an artifact we use it's par_obj_id's path+name plus it's artifact_type name
par_obj_id = v[0] # The parent of an artifact can be a file or a report
if par_obj_id in mapping.keys():
path = mapping[par_obj_id]
elif par_obj_id in reports_table.keys():
path = reports_table[par_obj_id]
elif par_obj_id in images_table.keys():
path = images_table[par_obj_id]
mapping[k] = path + "/" + artifacts_table[k]
elif v[0] not in mapping.keys():
if v[0] in artifacts_table.keys():
par_obj_id = objects_table[v[0]]
path = mapping[par_obj_id]
mapping[k] = path + "/" + artifacts_table[v[0]]
return mapping
def db_connect(db_file, isMultiUser, pgSettings=None):
if isMultiUser: # use PostgreSQL
try:
return psycopg2.connect("dbname=" + db_file + " user=" + pgSettings.username + " host=" + pgSettings.pgHost + " password=" + pgSettings.password), None
except:
print("Failed to connect to the database: " + db_file)
else: # Sqlite
# Make a copy that we can modify
backup_db_file = TskDbDiff._get_tmp_file("tsk_backup_db", ".db")
shutil.copy(db_file, backup_db_file)
# We sometimes get situations with messed up permissions
os.chmod (backup_db_file, 0o777)
return sqlite3.connect(backup_db_file), backup_db_file
def sql_select_execute(cursor, isPostgreSQL, sql_stmt):
if isPostgreSQL:
cursor.execute(sql_stmt)
return cursor.fetchall()
else:
return cursor.execute(sql_stmt)
def main():
try:
sys.argv.pop(0)
output_db = sys.argv.pop(0)
gold_db = sys.argv.pop(0)
except:
print("usage: tskdbdiff [OUTPUT DB PATH] [GOLD DB PATH]")
sys.exit(1)
db_diff = TskDbDiff(output_db, gold_db, output_dir=".")
dump_passed, bb_dump_passed = db_diff.run_diff()
if dump_passed and bb_dump_passed:
print("Database comparison passed.")
if not dump_passed:
print("Non blackboard database comparison failed.")
if not bb_dump_passed:
print("Blackboard database comparison failed.")
sys.exit(0)
if __name__ == "__main__":
if sys.hexversion < 0x03000000:
print("Python 3 required")
sys.exit(1)
main()
|
apache-2.0
|
[
3,
15127,
2366,
19,
199,
199,
646,
295,
199,
646,
11723,
19,
199,
646,
3873,
199,
646,
5145,
199,
646,
747,
199,
646,
6010,
199,
646,
2197,
199,
646,
984,
199,
646,
15492,
18,
199,
646,
15492,
18,
14,
9975,
199,
646,
2838,
199,
646,
7392,
199,
199,
533,
377,
1339,
8882,
10746,
8,
785,
304,
272,
408,
2404,
11044,
2877,
377,
8656,
15,
23570,
736,
647,
19245,
16219,
14,
339,
9382,
26,
267,
486,
1753,
63,
30129,
26,
267,
6384,
1483,
89,
63,
30129,
26,
267,
486,
1753,
63,
2987,
26,
267,
6384,
1483,
89,
63,
2987,
26,
267,
486,
1753,
63,
1462,
26,
267,
6384,
1483,
89,
63,
1462,
26,
267,
18115,
63,
8547,
26,
267,
2225,
63,
863,
759,
438,
26,
267,
3622,
63,
2550,
26,
282,
769,
1618,
63,
513,
1618,
63,
1558,
12,
314,
1125,
3788,
626,
911,
506,
267,
12487,
370,
6426,
315,
314,
1255,
63,
3028,
1083,
267,
3032,
26,
282,
5046,
12,
8103,
314,
3915,
986,
31,
267,
6384,
1483,
89,
63,
697,
63,
493,
26,
267,
486,
1753,
63,
697,
63,
493,
26,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1072,
63,
697,
12,
486,
1753,
63,
697,
12,
1072,
63,
694,
29,
403,
12,
486,
1753,
63,
2501,
63,
2724,
29,
403,
12,
486,
1753,
63,
2724,
29,
403,
12,
3376,
29,
797,
12,
365,
3947,
1899,
29,
797,
12,
10275,
5268,
29,
403,
304,
267,
408,
11447,
367,
377,
1339,
8882,
10746,
14,
398,
3033,
26,
288,
1072,
63,
697,
63,
515,
26,
931,
370,
1072,
3050,
334,
2865,
13,
23628,
4465,
9,
288,
486,
1753,
63,
697,
63,
515,
26,
931,
370,
486,
1753,
3050,
288,
1072,
63,
694,
26,
334,
4144,
9,
6912,
370,
4922,
2382,
4046,
1584,
911,
506,
5324,
14,
288,
486,
1753,
63,
2501,
63,
2724,
26,
334,
4144,
9,
931,
370,
570,
2382,
314,
486,
1753,
12136,
3576,
5461,
365,
16180,
288,
486,
1753,
63,
2724,
26,
334,
4144,
9,
931,
370,
570,
2382,
314,
486,
1753,
2222,
13,
8399,
3576,
5461,
365,
16180,
288,
3376,
26,
334,
4144,
9,
282,
5046,
12,
340,
2549,
12,
3915,
2058,
787,
4847,
370,
3839,
14,
4960,
408,
398,
291,
14,
1199,
63,
697,
63,
493,
275,
1072,
63,
697,
267,
291,
14,
23628,
63,
697,
63,
493,
275,
486,
1753,
63,
697,
267,
291,
14,
1199,
63,
694,
275,
1072,
63,
694,
267,
291,
14,
23628,
63,
2501,
63,
2724,
275,
486,
1753,
63,
2501,
63,
2724,
267,
291,
14,
23628,
63,
2724,
275,
486,
1753,
63,
2724,
267,
291,
423,
4208,
63,
23628,
63,
2724,
275,
756,
18418,
291,
423,
4208,
63,
23628,
63,
2501,
63,
2724,
275,
756,
267,
291,
423,
2501,
63,
2724,
63,
3028,
275,
3087,
267,
291,
423,
2724,
63,
3028,
275,
3087,
267,
291,
423,
2501,
63,
2724,
275,
3087,
267,
291,
423,
2724,
275,
3087,
267,
291,
14,
3832,
275,
3376,
267,
291,
14,
374,
3947,
1899,
275,
365,
3947,
1899,
267,
291,
14,
4198,
5268,
275,
10275,
5268,
398,
340,
291,
14,
374,
3947,
1899,
436,
440,
291,
14,
4198,
5268,
26,
288,
870,
480,
7718,
20175,
3050,
1950,
2202,
666,
2685,
288,
984,
14,
2224,
8,
17,
9,
398,
340,
291,
14,
23628,
63,
2501,
63,
2724,
365,
488,
26,
288,
291,
423,
4208,
63,
23628,
63,
2501,
63,
2724,
275,
715,
267,
340,
291,
14,
23628,
63,
2724,
365,
488,
26,
288,
291,
423,
4208,
63,
23628,
63,
2724,
275,
715,
339,
347,
1255,
63,
3028,
8,
277,
304,
267,
408,
16051,
314,
16219,
14,
398,
6218,
26,
288,
377,
1339,
8882,
10746,
1726,
26,
340,
376,
1125,
11058,
1830,
3915,
316,
503,
5461,
316,
314,
3050,
267,
408,
398,
291,
423,
826,
63,
3028,
342,
267,
1305,
63,
1113,
63,
515,
63,
1224,
275,
446,
17,
267,
327,
3550,
314,
486,
1753,
3050,
16864,
340,
5784,
420,
267,
340,
291,
423,
4208,
63,
23628,
63,
2724,
26,
263,
288,
1305,
63,
1113,
63,
515,
63,
1224,
275,
377,
1339,
8882,
10746,
423,
2724,
63,
1199,
63,
697,
63,
2865,
2501,
8,
277,
14,
23628,
63,
697,
63,
493,
12,
291,
14,
23628,
63,
2724,
12,
291,
14,
374,
3947,
1899,
12,
291,
14,
4198,
5268,
9,
420,
267,
340,
291,
423,
4208,
63,
23628,
63,
2501,
63,
2724,
26,
260,
288,
377,
1339,
8882,
10746,
423,
2724,
63,
1199,
63,
697,
63,
2501,
8,
277,
14,
23628,
63,
697,
63,
493,
12,
291,
14,
23628,
63,
2501,
63,
2724,
12,
291,
14,
374,
3947,
1899,
12,
291,
14,
4198,
5268,
12,
1305,
63,
1113,
63,
515,
63,
1224,
9,
398,
327,
3550,
314,
1072,
3050,
16864,
334,
10727,
6249,
436,
699,
34,
9,
267,
1305,
63,
1113,
63,
515,
63,
1224,
275,
377,
1339,
8882,
10746,
423,
2724,
63,
1199,
63,
697,
63,
2865,
2501,
8,
277,
14,
1199,
63,
697,
63,
493,
12,
291,
423,
2724,
12,
291,
14,
374,
3947,
1899,
12,
291,
14,
4198,
5268,
9,
267,
377,
1339,
8882,
10746,
423,
2724,
63,
1199,
63,
697,
63,
2501,
8,
277,
14,
1199,
63,
697,
63,
493,
12,
291,
423,
2501,
63,
2724,
12,
291,
14,
374,
3947,
1899,
12,
291,
14,
4198,
5268,
12,
1305,
63,
1113,
63,
515,
63,
1224,
9,
398,
327,
18955,
2222,
13,
5342,
267,
5461,
63,
3028,
63,
1529,
275,
291,
423,
3028,
8,
277,
423,
2724,
12,
291,
14,
23628,
63,
2724,
12,
291,
423,
2724,
63,
3028,
9,
398,
327,
18955,
699,
34,
267,
14027,
63,
2724,
63,
3028,
63,
1529,
275,
291,
423,
3028,
8,
277,
423,
2501,
63,
2724,
12,
291,
14,
23628,
63,
2501,
63,
2724,
12,
291,
423,
2501,
63,
2724,
63,
3028,
9,
398,
291,
423,
7661,
63,
3028,
342,
267,
372,
5461,
63,
3028,
63,
1529,
12,
14027,
63,
2724,
63,
3028,
63,
1529,
2378,
347,
485,
826,
63,
3028,
8,
277,
304,
267,
408,
1084,
1536,
314,
5784,
1584,
4079,
641,
314,
2368,
1627,
737,
14538,
624,
267,
340,
291,
14,
1199,
63,
694,
365,
488,
26,
288,
327,
3091,
5489,
1584,
288,
291,
423,
2501,
63,
2724,
275,
377,
1339,
8882,
10746,
423,
362,
63,
2791,
63
] |
[
15127,
2366,
19,
199,
199,
646,
295,
199,
646,
11723,
19,
199,
646,
3873,
199,
646,
5145,
199,
646,
747,
199,
646,
6010,
199,
646,
2197,
199,
646,
984,
199,
646,
15492,
18,
199,
646,
15492,
18,
14,
9975,
199,
646,
2838,
199,
646,
7392,
199,
199,
533,
377,
1339,
8882,
10746,
8,
785,
304,
272,
408,
2404,
11044,
2877,
377,
8656,
15,
23570,
736,
647,
19245,
16219,
14,
339,
9382,
26,
267,
486,
1753,
63,
30129,
26,
267,
6384,
1483,
89,
63,
30129,
26,
267,
486,
1753,
63,
2987,
26,
267,
6384,
1483,
89,
63,
2987,
26,
267,
486,
1753,
63,
1462,
26,
267,
6384,
1483,
89,
63,
1462,
26,
267,
18115,
63,
8547,
26,
267,
2225,
63,
863,
759,
438,
26,
267,
3622,
63,
2550,
26,
282,
769,
1618,
63,
513,
1618,
63,
1558,
12,
314,
1125,
3788,
626,
911,
506,
267,
12487,
370,
6426,
315,
314,
1255,
63,
3028,
1083,
267,
3032,
26,
282,
5046,
12,
8103,
314,
3915,
986,
31,
267,
6384,
1483,
89,
63,
697,
63,
493,
26,
267,
486,
1753,
63,
697,
63,
493,
26,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1072,
63,
697,
12,
486,
1753,
63,
697,
12,
1072,
63,
694,
29,
403,
12,
486,
1753,
63,
2501,
63,
2724,
29,
403,
12,
486,
1753,
63,
2724,
29,
403,
12,
3376,
29,
797,
12,
365,
3947,
1899,
29,
797,
12,
10275,
5268,
29,
403,
304,
267,
408,
11447,
367,
377,
1339,
8882,
10746,
14,
398,
3033,
26,
288,
1072,
63,
697,
63,
515,
26,
931,
370,
1072,
3050,
334,
2865,
13,
23628,
4465,
9,
288,
486,
1753,
63,
697,
63,
515,
26,
931,
370,
486,
1753,
3050,
288,
1072,
63,
694,
26,
334,
4144,
9,
6912,
370,
4922,
2382,
4046,
1584,
911,
506,
5324,
14,
288,
486,
1753,
63,
2501,
63,
2724,
26,
334,
4144,
9,
931,
370,
570,
2382,
314,
486,
1753,
12136,
3576,
5461,
365,
16180,
288,
486,
1753,
63,
2724,
26,
334,
4144,
9,
931,
370,
570,
2382,
314,
486,
1753,
2222,
13,
8399,
3576,
5461,
365,
16180,
288,
3376,
26,
334,
4144,
9,
282,
5046,
12,
340,
2549,
12,
3915,
2058,
787,
4847,
370,
3839,
14,
4960,
408,
398,
291,
14,
1199,
63,
697,
63,
493,
275,
1072,
63,
697,
267,
291,
14,
23628,
63,
697,
63,
493,
275,
486,
1753,
63,
697,
267,
291,
14,
1199,
63,
694,
275,
1072,
63,
694,
267,
291,
14,
23628,
63,
2501,
63,
2724,
275,
486,
1753,
63,
2501,
63,
2724,
267,
291,
14,
23628,
63,
2724,
275,
486,
1753,
63,
2724,
267,
291,
423,
4208,
63,
23628,
63,
2724,
275,
756,
18418,
291,
423,
4208,
63,
23628,
63,
2501,
63,
2724,
275,
756,
267,
291,
423,
2501,
63,
2724,
63,
3028,
275,
3087,
267,
291,
423,
2724,
63,
3028,
275,
3087,
267,
291,
423,
2501,
63,
2724,
275,
3087,
267,
291,
423,
2724,
275,
3087,
267,
291,
14,
3832,
275,
3376,
267,
291,
14,
374,
3947,
1899,
275,
365,
3947,
1899,
267,
291,
14,
4198,
5268,
275,
10275,
5268,
398,
340,
291,
14,
374,
3947,
1899,
436,
440,
291,
14,
4198,
5268,
26,
288,
870,
480,
7718,
20175,
3050,
1950,
2202,
666,
2685,
288,
984,
14,
2224,
8,
17,
9,
398,
340,
291,
14,
23628,
63,
2501,
63,
2724,
365,
488,
26,
288,
291,
423,
4208,
63,
23628,
63,
2501,
63,
2724,
275,
715,
267,
340,
291,
14,
23628,
63,
2724,
365,
488,
26,
288,
291,
423,
4208,
63,
23628,
63,
2724,
275,
715,
339,
347,
1255,
63,
3028,
8,
277,
304,
267,
408,
16051,
314,
16219,
14,
398,
6218,
26,
288,
377,
1339,
8882,
10746,
1726,
26,
340,
376,
1125,
11058,
1830,
3915,
316,
503,
5461,
316,
314,
3050,
267,
408,
398,
291,
423,
826,
63,
3028,
342,
267,
1305,
63,
1113,
63,
515,
63,
1224,
275,
446,
17,
267,
327,
3550,
314,
486,
1753,
3050,
16864,
340,
5784,
420,
267,
340,
291,
423,
4208,
63,
23628,
63,
2724,
26,
263,
288,
1305,
63,
1113,
63,
515,
63,
1224,
275,
377,
1339,
8882,
10746,
423,
2724,
63,
1199,
63,
697,
63,
2865,
2501,
8,
277,
14,
23628,
63,
697,
63,
493,
12,
291,
14,
23628,
63,
2724,
12,
291,
14,
374,
3947,
1899,
12,
291,
14,
4198,
5268,
9,
420,
267,
340,
291,
423,
4208,
63,
23628,
63,
2501,
63,
2724,
26,
260,
288,
377,
1339,
8882,
10746,
423,
2724,
63,
1199,
63,
697,
63,
2501,
8,
277,
14,
23628,
63,
697,
63,
493,
12,
291,
14,
23628,
63,
2501,
63,
2724,
12,
291,
14,
374,
3947,
1899,
12,
291,
14,
4198,
5268,
12,
1305,
63,
1113,
63,
515,
63,
1224,
9,
398,
327,
3550,
314,
1072,
3050,
16864,
334,
10727,
6249,
436,
699,
34,
9,
267,
1305,
63,
1113,
63,
515,
63,
1224,
275,
377,
1339,
8882,
10746,
423,
2724,
63,
1199,
63,
697,
63,
2865,
2501,
8,
277,
14,
1199,
63,
697,
63,
493,
12,
291,
423,
2724,
12,
291,
14,
374,
3947,
1899,
12,
291,
14,
4198,
5268,
9,
267,
377,
1339,
8882,
10746,
423,
2724,
63,
1199,
63,
697,
63,
2501,
8,
277,
14,
1199,
63,
697,
63,
493,
12,
291,
423,
2501,
63,
2724,
12,
291,
14,
374,
3947,
1899,
12,
291,
14,
4198,
5268,
12,
1305,
63,
1113,
63,
515,
63,
1224,
9,
398,
327,
18955,
2222,
13,
5342,
267,
5461,
63,
3028,
63,
1529,
275,
291,
423,
3028,
8,
277,
423,
2724,
12,
291,
14,
23628,
63,
2724,
12,
291,
423,
2724,
63,
3028,
9,
398,
327,
18955,
699,
34,
267,
14027,
63,
2724,
63,
3028,
63,
1529,
275,
291,
423,
3028,
8,
277,
423,
2501,
63,
2724,
12,
291,
14,
23628,
63,
2501,
63,
2724,
12,
291,
423,
2501,
63,
2724,
63,
3028,
9,
398,
291,
423,
7661,
63,
3028,
342,
267,
372,
5461,
63,
3028,
63,
1529,
12,
14027,
63,
2724,
63,
3028,
63,
1529,
2378,
347,
485,
826,
63,
3028,
8,
277,
304,
267,
408,
1084,
1536,
314,
5784,
1584,
4079,
641,
314,
2368,
1627,
737,
14538,
624,
267,
340,
291,
14,
1199,
63,
694,
365,
488,
26,
288,
327,
3091,
5489,
1584,
288,
291,
423,
2501,
63,
2724,
275,
377,
1339,
8882,
10746,
423,
362,
63,
2791,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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.
"""A command line parsing module that lets modules define their own options.
Each module defines its own options which are added to the global
option namespace, e.g.::
from tornado.options import define, options
define("mysql_host", default="127.0.0.1:3306", help="Main user DB")
define("memcache_hosts", default="127.0.0.1:11011", multiple=True,
help="Main user memcache servers")
def connect():
db = database.Connection(options.mysql_host)
...
The ``main()`` method of your application does not need to be aware of all of
the options used throughout your program; they are all automatically loaded
when the modules are loaded. However, all modules that define options
must have been imported before the command line is parsed.
Your ``main()`` method can parse the command line or parse a config file with
either::
tornado.options.parse_command_line()
# or
tornado.options.parse_config_file("/etc/server.conf")
Command line formats are what you would expect (``--myoption=myvalue``).
Config files are just Python files. Global names become options, e.g.::
myoption = "myvalue"
myotheroption = "myothervalue"
We support `datetimes <datetime.datetime>`, `timedeltas
<datetime.timedelta>`, ints, and floats (just pass a ``type`` kwarg to
`define`). We also accept multi-value options. See the documentation for
`define()` below.
`tornado.options.options` is a singleton instance of `OptionParser`, and
the top-level functions in this module (`define`, `parse_command_line`, etc)
simply call methods on it. You may create additional `OptionParser`
instances to define isolated sets of options, such as for subcommands.
.. note::
By default, several options are defined that will configure the
standard `logging` module when `parse_command_line` or `parse_config_file`
are called. If you want Tornado to leave the logging configuration
alone so you can manage it yourself, either pass ``--logging=none``
on the command line or do the following to disable it in code::
from tornado.options import options, parse_command_line
options.logging = None
parse_command_line()
"""
from __future__ import absolute_import, division, print_function, with_statement
import datetime
import numbers
import re
import sys
import os
import textwrap
from tornado.escape import _unicode, native_str
from tornado.log import define_logging_options
from tornado import stack_context
from tornado.util import basestring_type, exec_in
class Error(Exception):
"""Exception raised by errors in the options module."""
pass
class OptionParser(object):
"""A collection of options, a dictionary with object-like access.
Normally accessed via static functions in the `tornado.options` module,
which reference a global instance.
"""
def __init__(self):
# we have to use self.__dict__ because we override setattr.
self.__dict__['_options'] = {}
self.__dict__['_parse_callbacks'] = []
self.define("help", type=bool, help="show this help information",
callback=self._help_callback)
def __getattr__(self, name):
if isinstance(self._options.get(name), _Option):
return self._options[name].value()
raise AttributeError("Unrecognized option %r" % name)
def __setattr__(self, name, value):
if isinstance(self._options.get(name), _Option):
return self._options[name].set(value)
raise AttributeError("Unrecognized option %r" % name)
def __iter__(self):
return iter(self._options)
def __getitem__(self, item):
return self._options[item].value()
def items(self):
"""A sequence of (name, value) pairs.
.. versionadded:: 3.1
"""
return [(name, opt.value()) for name, opt in self._options.items()]
def groups(self):
"""The set of option-groups created by ``define``.
.. versionadded:: 3.1
"""
return set(opt.group_name for opt in self._options.values())
def group_dict(self, group):
"""The names and values of options in a group.
Useful for copying options into Application settings::
from tornado.options import define, parse_command_line, options
define('template_path', group='application')
define('static_path', group='application')
parse_command_line()
application = Application(
handlers, **options.group_dict('application'))
.. versionadded:: 3.1
"""
return dict(
(name, opt.value()) for name, opt in self._options.items()
if not group or group == opt.group_name)
def as_dict(self):
"""The names and values of all options.
.. versionadded:: 3.1
"""
return dict(
(name, opt.value()) for name, opt in self._options.items())
def define(self, name, default=None, type=None, help=None, metavar=None,
multiple=False, group=None, callback=None):
"""Defines a new command line option.
If ``type`` is given (one of str, float, int, datetime, or timedelta)
or can be inferred from the ``default``, we parse the command line
arguments based on the given type. If ``multiple`` is True, we accept
comma-separated values, and the option value is always a list.
For multi-value integers, we also accept the syntax ``x:y``, which
turns into ``range(x, y)`` - very useful for long integer ranges.
``help`` and ``metavar`` are used to construct the
automatically generated command line help string. The help
message is formatted like::
--name=METAVAR help string
``group`` is used to group the defined options in logical
groups. By default, command line options are grouped by the
file in which they are defined.
Command line option names must be unique globally. They can be parsed
from the command line with `parse_command_line` or parsed from a
config file with `parse_config_file`.
If a ``callback`` is given, it will be run with the new value whenever
the option is changed. This can be used to combine command-line
and file-based options::
define("config", type=str, help="path to config file",
callback=lambda path: parse_config_file(path, final=False))
With this definition, options in the file specified by ``--config`` will
override options set earlier on the command line, but can be overridden
by later flags.
"""
if name in self._options:
raise Error("Option %r already defined in %s" %
(name, self._options[name].file_name))
frame = sys._getframe(0)
options_file = frame.f_code.co_filename
# Can be called directly, or through top level define() fn, in which
# case, step up above that frame to look for real caller.
if (frame.f_back.f_code.co_filename == options_file and
frame.f_back.f_code.co_name == 'define'):
frame = frame.f_back
file_name = frame.f_back.f_code.co_filename
if file_name == options_file:
file_name = ""
if type is None:
if not multiple and default is not None:
type = default.__class__
else:
type = str
if group:
group_name = group
else:
group_name = file_name
self._options[name] = _Option(name, file_name=file_name,
default=default, type=type, help=help,
metavar=metavar, multiple=multiple,
group_name=group_name,
callback=callback)
def parse_command_line(self, args=None, final=True):
"""Parses all options given on the command line (defaults to
`sys.argv`).
Note that ``args[0]`` is ignored since it is the program name
in `sys.argv`.
We return a list of all arguments that are not parsed as options.
If ``final`` is ``False``, parse callbacks will not be run.
This is useful for applications that wish to combine configurations
from multiple sources.
"""
if args is None:
args = sys.argv
remaining = []
for i in range(1, len(args)):
# All things after the last option are command line arguments
if not args[i].startswith("-"):
remaining = args[i:]
break
if args[i] == "--":
remaining = args[i + 1:]
break
arg = args[i].lstrip("-")
name, equals, value = arg.partition("=")
name = name.replace('-', '_')
if not name in self._options:
self.print_help()
raise Error('Unrecognized command line option: %r' % name)
option = self._options[name]
if not equals:
if option.type == bool:
value = "true"
else:
raise Error('Option %r requires a value' % name)
option.parse(value)
if final:
self.run_parse_callbacks()
return remaining
def parse_config_file(self, path, final=True):
"""Parses and loads the Python config file at the given path.
If ``final`` is ``False``, parse callbacks will not be run.
This is useful for applications that wish to combine configurations
from multiple sources.
.. versionchanged:: 4.1
Config files are now always interpreted as utf-8 instead of
the system default encoding.
"""
config = {}
with open(path, 'rb') as f:
exec_in(native_str(f.read()), config, config)
for name in config:
if name in self._options:
self._options[name].set(config[name])
if final:
self.run_parse_callbacks()
def print_help(self, file=None):
"""Prints all the command line options to stderr (or another file)."""
if file is None:
file = sys.stderr
print("Usage: %s [OPTIONS]" % sys.argv[0], file=file)
print("\nOptions:\n", file=file)
by_group = {}
for option in self._options.values():
by_group.setdefault(option.group_name, []).append(option)
for filename, o in sorted(by_group.items()):
if filename:
print("\n%s options:\n" % os.path.normpath(filename), file=file)
o.sort(key=lambda option: option.name)
for option in o:
prefix = option.name
if option.metavar:
prefix += "=" + option.metavar
description = option.help or ""
if option.default is not None and option.default != '':
description += " (default %s)" % option.default
lines = textwrap.wrap(description, 79 - 35)
if len(prefix) > 30 or len(lines) == 0:
lines.insert(0, '')
print(" --%-30s %s" % (prefix, lines[0]), file=file)
for line in lines[1:]:
print("%-34s %s" % (' ', line), file=file)
print(file=file)
def _help_callback(self, value):
if value:
self.print_help()
sys.exit(0)
def add_parse_callback(self, callback):
"""Adds a parse callback, to be invoked when option parsing is done."""
self._parse_callbacks.append(stack_context.wrap(callback))
def run_parse_callbacks(self):
for callback in self._parse_callbacks:
callback()
def mockable(self):
"""Returns a wrapper around self that is compatible with
`mock.patch <unittest.mock.patch>`.
The `mock.patch <unittest.mock.patch>` function (included in
the standard library `unittest.mock` package since Python 3.3,
or in the third-party ``mock`` package for older versions of
Python) is incompatible with objects like ``options`` that
override ``__getattr__`` and ``__setattr__``. This function
returns an object that can be used with `mock.patch.object
<unittest.mock.patch.object>` to modify option values::
with mock.patch.object(options.mockable(), 'name', value):
assert options.name == value
"""
return _Mockable(self)
class _Mockable(object):
"""`mock.patch` compatible wrapper for `OptionParser`.
As of ``mock`` version 1.0.1, when an object uses ``__getattr__``
hooks instead of ``__dict__``, ``patch.__exit__`` tries to delete
the attribute it set instead of setting a new one (assuming that
the object does not catpure ``__setattr__``, so the patch
created a new attribute in ``__dict__``).
_Mockable's getattr and setattr pass through to the underlying
OptionParser, and delattr undoes the effect of a previous setattr.
"""
def __init__(self, options):
# Modify __dict__ directly to bypass __setattr__
self.__dict__['_options'] = options
self.__dict__['_originals'] = {}
def __getattr__(self, name):
return getattr(self._options, name)
def __setattr__(self, name, value):
assert name not in self._originals, "don't reuse mockable objects"
self._originals[name] = getattr(self._options, name)
setattr(self._options, name, value)
def __delattr__(self, name):
setattr(self._options, name, self._originals.pop(name))
class _Option(object):
UNSET = object()
def __init__(self, name, default=None, type=basestring_type, help=None,
metavar=None, multiple=False, file_name=None, group_name=None,
callback=None):
if default is None and multiple:
default = []
self.name = name
self.type = type
self.help = help
self.metavar = metavar
self.multiple = multiple
self.file_name = file_name
self.group_name = group_name
self.callback = callback
self.default = default
self._value = _Option.UNSET
def value(self):
return self.default if self._value is _Option.UNSET else self._value
def parse(self, value):
_parse = {
datetime.datetime: self._parse_datetime,
datetime.timedelta: self._parse_timedelta,
bool: self._parse_bool,
basestring_type: self._parse_string,
}.get(self.type, self.type)
if self.multiple:
self._value = []
for part in value.split(","):
if issubclass(self.type, numbers.Integral):
# allow ranges of the form X:Y (inclusive at both ends)
lo, _, hi = part.partition(":")
lo = _parse(lo)
hi = _parse(hi) if hi else lo
self._value.extend(range(lo, hi + 1))
else:
self._value.append(_parse(part))
else:
self._value = _parse(value)
if self.callback is not None:
self.callback(self._value)
return self.value()
def set(self, value):
if self.multiple:
if not isinstance(value, list):
raise Error("Option %r is required to be a list of %s" %
(self.name, self.type.__name__))
for item in value:
if item is not None and not isinstance(item, self.type):
raise Error("Option %r is required to be a list of %s" %
(self.name, self.type.__name__))
else:
if value is not None and not isinstance(value, self.type):
raise Error("Option %r is required to be a %s (%s given)" %
(self.name, self.type.__name__, type(value)))
self._value = value
if self.callback is not None:
self.callback(self._value)
# Supported date/time formats in our options
_DATETIME_FORMATS = [
"%a %b %d %H:%M:%S %Y",
"%Y-%m-%d %H:%M:%S",
"%Y-%m-%d %H:%M",
"%Y-%m-%dT%H:%M",
"%Y%m%d %H:%M:%S",
"%Y%m%d %H:%M",
"%Y-%m-%d",
"%Y%m%d",
"%H:%M:%S",
"%H:%M",
]
def _parse_datetime(self, value):
for format in self._DATETIME_FORMATS:
try:
return datetime.datetime.strptime(value, format)
except ValueError:
pass
raise Error('Unrecognized date/time format: %r' % value)
_TIMEDELTA_ABBREVS = [
('hours', ['h']),
('minutes', ['m', 'min']),
('seconds', ['s', 'sec']),
('milliseconds', ['ms']),
('microseconds', ['us']),
('days', ['d']),
('weeks', ['w']),
]
_TIMEDELTA_ABBREV_DICT = dict(
(abbrev, full) for full, abbrevs in _TIMEDELTA_ABBREVS
for abbrev in abbrevs)
_FLOAT_PATTERN = r'[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?'
_TIMEDELTA_PATTERN = re.compile(
r'\s*(%s)\s*(\w*)\s*' % _FLOAT_PATTERN, re.IGNORECASE)
def _parse_timedelta(self, value):
try:
sum = datetime.timedelta()
start = 0
while start < len(value):
m = self._TIMEDELTA_PATTERN.match(value, start)
if not m:
raise Exception()
num = float(m.group(1))
units = m.group(2) or 'seconds'
units = self._TIMEDELTA_ABBREV_DICT.get(units, units)
sum += datetime.timedelta(**{units: num})
start = m.end()
return sum
except Exception:
raise
def _parse_bool(self, value):
return value.lower() not in ("false", "0", "f")
def _parse_string(self, value):
return _unicode(value)
options = OptionParser()
"""Global options object.
All defined options are available as attributes on this object.
"""
def define(name, default=None, type=None, help=None, metavar=None,
multiple=False, group=None, callback=None):
"""Defines an option in the global namespace.
See `OptionParser.define`.
"""
return options.define(name, default=default, type=type, help=help,
metavar=metavar, multiple=multiple, group=group,
callback=callback)
def parse_command_line(args=None, final=True):
"""Parses global options from the command line.
See `OptionParser.parse_command_line`.
"""
return options.parse_command_line(args, final=final)
def parse_config_file(path, final=True):
"""Parses global options from a config file.
See `OptionParser.parse_config_file`.
"""
return options.parse_config_file(path, final=final)
def print_help(file=None):
"""Prints all the command line options to stderr (or another file).
See `OptionParser.print_help`.
"""
return options.print_help(file)
def add_parse_callback(callback):
"""Adds a parse callback, to be invoked when option parsing is done.
See `OptionParser.add_parse_callback`
"""
options.add_parse_callback(callback)
# Default options
define_logging_options(options)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8937,
27107,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
624,
33,
1414,
1004,
6057,
859,
626,
19083,
4621,
5627,
3932,
5705,
1511,
14,
199,
199,
22321,
859,
7890,
2399,
5705,
1511,
1314,
787,
3483,
370,
314,
2288,
199,
1422,
3231,
12,
325,
14,
71,
28383,
339,
687,
12148,
14,
1419,
492,
5627,
12,
1511,
339,
5627,
480,
8644,
63,
1102,
401,
849,
628,
4195,
14,
16,
14,
16,
14,
17,
26,
1153,
1690,
401,
1720,
628,
6756,
922,
6249,
531,
272,
5627,
480,
25835,
63,
5146,
401,
849,
628,
4195,
14,
16,
14,
16,
14,
17,
26,
845,
13059,
401,
3663,
29,
549,
12,
1779,
1720,
628,
6756,
922,
21598,
8037,
531,
339,
347,
4907,
837,
267,
1592,
275,
3050,
14,
3225,
8,
1419,
14,
8644,
63,
1102,
9,
267,
2263,
199,
199,
1918,
1124,
973,
8497,
1083,
402,
2195,
4223,
1630,
440,
1929,
370,
506,
20381,
402,
1006,
402,
199,
1589,
1511,
1202,
23088,
2195,
2240,
27,
2985,
787,
1006,
5847,
6511,
199,
6526,
314,
4621,
787,
6511,
14,
221,
9738,
12,
1006,
4621,
626,
5627,
1511,
199,
7790,
1172,
2757,
8439,
2544,
314,
1414,
1004,
365,
4565,
14,
199,
199,
14398,
1124,
973,
8497,
1083,
883,
2198,
314,
1414,
1004,
503,
2198,
282,
1101,
570,
543,
199,
22051,
447,
339,
12148,
14,
1419,
14,
1122,
63,
1531,
63,
604,
342,
272,
327,
503,
272,
12148,
14,
1419,
14,
1122,
63,
888,
63,
493,
4769,
6839,
15,
1000,
14,
2190,
531,
199,
199,
3110,
1004,
6752,
787,
4052,
1265,
3955,
4282,
15693,
306,
1662,
1422,
29,
1662,
585,
20008,
199,
2028,
1584,
787,
2951,
2018,
1584,
14,
13641,
1561,
8649,
1511,
12,
325,
14,
71,
28383,
339,
3002,
1422,
275,
298,
1662,
585,
2,
272,
3002,
1848,
1422,
275,
298,
1662,
1848,
585,
2,
199,
199,
6004,
2291,
658,
31601,
665,
2083,
14,
2083,
30,
3559,
658,
521,
25446,
199,
28,
2083,
14,
7473,
30,
3559,
14526,
12,
436,
15657,
334,
4764,
986,
282,
1124,
466,
1040,
17582,
370,
199,
64,
4640,
14963,
2136,
2597,
4729,
3510,
13,
585,
1511,
14,
1666,
314,
3794,
367,
199,
64,
4640,
11995,
5084,
14,
199,
199,
64,
18443,
14,
1419,
14,
1419,
64,
365,
282,
19768,
1256,
402,
658,
14553,
3559,
436,
199,
1589,
2746,
13,
1896,
3423,
315,
642,
859,
13493,
4640,
3559,
658,
1122,
63,
1531,
63,
604,
3559,
5423,
9,
199,
11184,
590,
1240,
3102,
641,
652,
14,
221,
2047,
1443,
1218,
4722,
658,
14553,
64,
199,
5990,
370,
5627,
23348,
5951,
402,
1511,
12,
4066,
465,
367,
1007,
4405,
14,
199,
199,
703,
5317,
447,
8410,
4885,
849,
12,
9978,
1511,
787,
3247,
626,
911,
7908,
314,
2043,
4465,
658,
4806,
64,
859,
1380,
658,
1122,
63,
1531,
63,
604,
64,
503,
658,
1122,
63,
888,
63,
493,
64,
2043,
787,
2797,
14,
221,
982,
1265,
2934,
377,
8622,
370,
10137,
314,
2050,
2897,
2043,
23016,
880,
1265,
883,
9635,
652,
28225,
12,
1902,
986,
1124,
306,
4806,
29,
3592,
1040,
2043,
641,
314,
1414,
1004,
503,
886,
314,
2569,
370,
3507,
652,
315,
1233,
447,
10817,
687,
12148,
14,
1419,
492,
1511,
12,
2198,
63,
1531,
63,
604,
2126,
1511,
14,
4806,
275,
488,
2126,
2198,
63,
1531,
63,
604,
342,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
543,
63,
6242,
199,
199,
646,
2197,
199,
646,
5579,
199,
646,
295,
199,
646,
984,
199,
646,
747,
199,
646,
13390,
199,
199,
504,
12148,
14,
3765,
492,
485,
2975,
12,
5438,
63,
495,
199,
504,
12148,
14,
793,
492,
5627,
63,
4806,
63,
1419,
199,
504,
12148,
492,
3464,
63,
1100,
199,
504,
12148,
14,
1974,
492,
7116,
63,
466,
12,
2146,
63,
262,
421,
199,
533,
4520,
8,
1726,
304,
272,
408,
1726,
4915,
701,
2552,
315,
314,
1511,
859,
1041,
272,
986,
421,
199,
533,
13491,
8,
785,
304,
272,
408,
33,
3245,
402,
1511,
12,
282,
2600,
543,
909,
13,
2930,
2879,
14,
339,
24573,
13810,
4799,
2955,
3423,
315,
314,
658,
18443,
14,
1419,
64,
859,
12,
272,
1314,
3659,
282,
2288,
1256,
14,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
327,
781,
1172,
370,
675,
291,
855,
807,
363,
2952,
781,
4278,
5371,
14,
267,
291,
855,
807,
363,
8680,
1419,
418,
275,
1052,
267,
291,
855,
807,
363,
8680,
1122,
63,
11948,
418,
275,
942,
267,
291,
14,
4640,
480,
3437,
401,
730,
29,
2245,
12,
1720,
628,
2384,
642,
1720,
2556,
401,
490,
3233,
29,
277,
423,
3437,
63,
3058,
9,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
340,
1228,
8,
277,
423,
1419,
14,
362,
8,
354,
395,
485,
2602,
304,
288,
372,
291,
423,
1419,
59,
354,
1055,
585,
342,
267,
746,
4281,
480,
22517,
945,
450,
82,
2,
450,
536,
9,
339,
347,
636,
10202,
721,
277,
12,
536,
12,
574,
304,
267,
340,
1228,
8,
277,
423,
1419,
14,
362,
8,
354,
395,
485,
2602,
304,
288,
372,
291,
423,
1419,
59,
354,
1055,
409,
8,
585,
9,
267,
746,
4281,
480,
22517,
945,
450,
82,
2,
450,
536,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
423,
1419,
9,
339,
347,
636,
6095,
721,
277,
12,
1242,
304,
267,
372,
291,
423,
1419,
59,
1053,
1055,
585,
342
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8937,
27107,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
624,
33,
1414,
1004,
6057,
859,
626,
19083,
4621,
5627,
3932,
5705,
1511,
14,
199,
199,
22321,
859,
7890,
2399,
5705,
1511,
1314,
787,
3483,
370,
314,
2288,
199,
1422,
3231,
12,
325,
14,
71,
28383,
339,
687,
12148,
14,
1419,
492,
5627,
12,
1511,
339,
5627,
480,
8644,
63,
1102,
401,
849,
628,
4195,
14,
16,
14,
16,
14,
17,
26,
1153,
1690,
401,
1720,
628,
6756,
922,
6249,
531,
272,
5627,
480,
25835,
63,
5146,
401,
849,
628,
4195,
14,
16,
14,
16,
14,
17,
26,
845,
13059,
401,
3663,
29,
549,
12,
1779,
1720,
628,
6756,
922,
21598,
8037,
531,
339,
347,
4907,
837,
267,
1592,
275,
3050,
14,
3225,
8,
1419,
14,
8644,
63,
1102,
9,
267,
2263,
199,
199,
1918,
1124,
973,
8497,
1083,
402,
2195,
4223,
1630,
440,
1929,
370,
506,
20381,
402,
1006,
402,
199,
1589,
1511,
1202,
23088,
2195,
2240,
27,
2985,
787,
1006,
5847,
6511,
199,
6526,
314,
4621,
787,
6511,
14,
221,
9738,
12,
1006,
4621,
626,
5627,
1511,
199,
7790,
1172,
2757,
8439,
2544,
314,
1414,
1004,
365,
4565,
14,
199,
199,
14398,
1124,
973,
8497,
1083,
883,
2198,
314,
1414,
1004,
503,
2198,
282,
1101,
570,
543,
199,
22051,
447,
339,
12148,
14,
1419,
14,
1122,
63,
1531,
63,
604,
342,
272,
327,
503,
272,
12148,
14,
1419,
14,
1122,
63,
888,
63,
493,
4769,
6839,
15,
1000,
14,
2190,
531,
199,
199,
3110,
1004,
6752,
787,
4052,
1265,
3955,
4282,
15693,
306,
1662,
1422,
29,
1662,
585,
20008,
199,
2028,
1584,
787,
2951,
2018,
1584,
14,
13641,
1561,
8649,
1511,
12,
325,
14,
71,
28383,
339,
3002,
1422,
275,
298,
1662,
585,
2,
272,
3002,
1848,
1422,
275,
298,
1662,
1848,
585,
2,
199,
199,
6004,
2291,
658,
31601,
665,
2083,
14,
2083,
30,
3559,
658,
521,
25446,
199,
28,
2083,
14,
7473,
30,
3559,
14526,
12,
436,
15657,
334,
4764,
986,
282,
1124,
466,
1040,
17582,
370,
199,
64,
4640,
14963,
2136,
2597,
4729,
3510,
13,
585,
1511,
14,
1666,
314,
3794,
367,
199,
64,
4640,
11995,
5084,
14,
199,
199,
64,
18443,
14,
1419,
14,
1419,
64,
365,
282,
19768,
1256,
402,
658,
14553,
3559,
436,
199,
1589,
2746,
13,
1896,
3423,
315,
642,
859,
13493,
4640,
3559,
658,
1122,
63,
1531,
63,
604,
3559,
5423,
9,
199,
11184,
590,
1240,
3102,
641,
652,
14,
221,
2047,
1443,
1218,
4722,
658,
14553,
64,
199,
5990,
370,
5627,
23348,
5951,
402,
1511,
12,
4066,
465,
367,
1007,
4405,
14,
199,
199,
703,
5317,
447,
8410,
4885,
849,
12,
9978,
1511,
787,
3247,
626,
911,
7908,
314,
2043,
4465,
658,
4806,
64,
859,
1380,
658,
1122,
63,
1531,
63,
604,
64,
503,
658,
1122,
63,
888,
63,
493,
64,
2043,
787,
2797,
14,
221,
982,
1265,
2934,
377,
8622,
370,
10137,
314,
2050,
2897,
2043,
23016,
880,
1265,
883,
9635,
652,
28225,
12,
1902,
986,
1124,
306,
4806,
29,
3592,
1040,
2043,
641,
314,
1414,
1004,
503,
886,
314,
2569,
370,
3507,
652,
315,
1233,
447,
10817,
687,
12148,
14,
1419,
492,
1511,
12,
2198,
63,
1531,
63,
604,
2126,
1511,
14,
4806,
275,
488,
2126,
2198,
63,
1531,
63,
604,
342,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
543,
63,
6242,
199,
199,
646,
2197,
199,
646,
5579,
199,
646,
295,
199,
646,
984,
199,
646,
747,
199,
646,
13390,
199,
199,
504,
12148,
14,
3765,
492,
485,
2975,
12,
5438,
63,
495,
199,
504,
12148,
14,
793,
492,
5627,
63,
4806,
63,
1419,
199,
504,
12148,
492,
3464,
63,
1100,
199,
504,
12148,
14,
1974,
492,
7116,
63,
466,
12,
2146,
63,
262,
421,
199,
533,
4520,
8,
1726,
304,
272,
408,
1726,
4915,
701,
2552,
315,
314,
1511,
859,
1041,
272,
986,
421,
199,
533,
13491,
8,
785,
304,
272,
408,
33,
3245,
402,
1511,
12,
282,
2600,
543,
909,
13,
2930,
2879,
14,
339,
24573,
13810,
4799,
2955,
3423,
315,
314,
658,
18443,
14,
1419,
64,
859,
12,
272,
1314,
3659,
282,
2288,
1256,
14,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
327,
781,
1172,
370,
675,
291,
855,
807,
363,
2952,
781,
4278,
5371,
14,
267,
291,
855,
807,
363,
8680,
1419,
418,
275,
1052,
267,
291,
855,
807,
363,
8680,
1122,
63,
11948,
418,
275,
942,
267,
291,
14,
4640,
480,
3437,
401,
730,
29,
2245,
12,
1720,
628,
2384,
642,
1720,
2556,
401,
490,
3233,
29,
277,
423,
3437,
63,
3058,
9,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
340,
1228,
8,
277,
423,
1419,
14,
362,
8,
354,
395,
485,
2602,
304,
288,
372,
291,
423,
1419,
59,
354,
1055,
585,
342,
267,
746,
4281,
480,
22517,
945,
450,
82,
2,
450,
536,
9,
339,
347,
636,
10202,
721,
277,
12,
536,
12,
574,
304,
267,
340,
1228,
8,
277,
423,
1419,
14,
362,
8,
354,
395,
485,
2602,
304,
288,
372,
291,
423,
1419,
59,
354,
1055,
409,
8,
585,
9,
267,
746,
4281,
480,
22517,
945,
450,
82,
2,
450,
536,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
423,
1419,
9,
339,
347,
636,
6095,
721,
277,
12,
1242,
304,
267,
372,
291,
423,
1419,
59,
1053,
1055,
585,
342,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
patricmutwiri/pombola
|
pombola/info/admin.py
|
2
|
1448
|
from django.conf import settings
from django.contrib import admin
import autocomplete_light
import models
from pombola.slug_helpers.admin import StricterSlugFieldMixin
class LabelAdmin(admin.ModelAdmin):
search_fields = [ 'name' ]
list_display = [ 'name', 'slug' ]
prepopulated_fields = {'slug': ['name']}
if settings.INFO_PAGES_ALLOW_RAW_HTML:
search_fields_to_use = ['title', 'markdown_content', 'raw_content']
fields_to_use = (
'title', 'slug', 'publication_date', 'kind', 'use_raw',
'markdown_content', 'raw_content', 'categories', 'tags'
)
else:
search_fields_to_use = ['title', 'markdown_content']
fields_to_use = (
'title', 'slug', 'publication_date', 'kind',
'markdown_content', 'categories', 'tags'
)
class InfoPageAdmin(StricterSlugFieldMixin, admin.ModelAdmin):
search_fields = search_fields_to_use
list_display = [ 'slug', 'title', 'kind', 'publication_date' ]
list_filter = [ 'kind', 'categories', 'tags' ]
date_hierarchy = 'publication_date'
ordering = ('-publication_date', 'title')
form = autocomplete_light.modelform_factory(models.InfoPage)
fields = fields_to_use
prepopulated_fields = {'slug': ['title']}
class Media:
js = ("info/js/admin.js",)
admin.site.register( models.Category, LabelAdmin )
admin.site.register( models.Tag, LabelAdmin )
admin.site.register( models.InfoPage, InfoPageAdmin )
|
agpl-3.0
|
[
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
492,
4628,
199,
199,
646,
2599,
4883,
63,
4040,
199,
199,
646,
1709,
199,
199,
504,
299,
24370,
22205,
14,
5464,
63,
7546,
14,
2113,
492,
428,
13929,
351,
17315,
4256,
199,
199,
533,
10354,
4880,
8,
2113,
14,
12976,
304,
272,
2754,
63,
955,
275,
359,
283,
354,
7,
1622,
272,
769,
63,
2918,
221,
275,
359,
283,
354,
297,
283,
5464,
7,
1622,
339,
876,
21440,
63,
955,
275,
791,
5464,
356,
788,
354,
12074,
199,
199,
692,
2202,
14,
4531,
63,
48,
5383,
63,
12231,
63,
4307,
63,
4943,
26,
272,
2754,
63,
955,
63,
475,
63,
1180,
275,
788,
1213,
297,
283,
15653,
63,
1317,
297,
283,
1773,
63,
1317,
418,
272,
1504,
63,
475,
63,
1180,
275,
334,
267,
283,
1213,
297,
283,
5464,
297,
283,
22678,
63,
602,
297,
283,
5091,
297,
283,
1180,
63,
1773,
297,
267,
283,
15653,
63,
1317,
297,
283,
1773,
63,
1317,
297,
283,
8906,
297,
283,
2969,
7,
272,
776,
199,
2836,
26,
272,
2754,
63,
955,
63,
475,
63,
1180,
275,
788,
1213,
297,
283,
15653,
63,
1317,
418,
272,
1504,
63,
475,
63,
1180,
275,
334,
267,
283,
1213,
297,
283,
5464,
297,
283,
22678,
63,
602,
297,
283,
5091,
297,
267,
283,
15653,
63,
1317,
297,
283,
8906,
297,
283,
2969,
7,
272,
776,
199,
199,
533,
10332,
3276,
4880,
8,
51,
13929,
351,
17315,
4256,
12,
4628,
14,
12976,
304,
272,
2754,
63,
955,
275,
2754,
63,
955,
63,
475,
63,
1180,
272,
769,
63,
2918,
221,
275,
359,
283,
5464,
297,
283,
1213,
297,
283,
5091,
297,
283,
22678,
63,
602,
7,
1622,
272,
769,
63,
1541,
257,
275,
359,
283,
5091,
297,
283,
8906,
297,
283,
2969,
7,
1622,
272,
1434,
63,
14861,
275,
283,
22678,
63,
602,
7,
272,
7794,
275,
12291,
22678,
63,
602,
297,
283,
1213,
358,
339,
1824,
275,
2599,
4883,
63,
4040,
14,
632,
24849,
63,
3702,
8,
992,
14,
2354,
3276,
9,
339,
1504,
275,
1504,
63,
475,
63,
1180,
272,
876,
21440,
63,
955,
275,
791,
5464,
356,
788,
1213,
12074,
339,
1021,
12300,
26,
267,
8586,
275,
1689,
815,
15,
3596,
15,
2113,
14,
3596,
26360,
421,
199,
2113,
14,
2124,
14,
2683,
8,
1709,
14,
7841,
12,
10354,
4880,
776,
199,
2113,
14,
2124,
14,
2683,
8,
1709,
14,
1931,
12,
420,
10354,
4880,
776,
199,
2113,
14,
2124,
14,
2683,
8,
1709,
14,
2354,
3276,
12,
10332,
3276,
4880,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
492,
4628,
199,
199,
646,
2599,
4883,
63,
4040,
199,
199,
646,
1709,
199,
199,
504,
299,
24370,
22205,
14,
5464,
63,
7546,
14,
2113,
492,
428,
13929,
351,
17315,
4256,
199,
199,
533,
10354,
4880,
8,
2113,
14,
12976,
304,
272,
2754,
63,
955,
275,
359,
283,
354,
7,
1622,
272,
769,
63,
2918,
221,
275,
359,
283,
354,
297,
283,
5464,
7,
1622,
339,
876,
21440,
63,
955,
275,
791,
5464,
356,
788,
354,
12074,
199,
199,
692,
2202,
14,
4531,
63,
48,
5383,
63,
12231,
63,
4307,
63,
4943,
26,
272,
2754,
63,
955,
63,
475,
63,
1180,
275,
788,
1213,
297,
283,
15653,
63,
1317,
297,
283,
1773,
63,
1317,
418,
272,
1504,
63,
475,
63,
1180,
275,
334,
267,
283,
1213,
297,
283,
5464,
297,
283,
22678,
63,
602,
297,
283,
5091,
297,
283,
1180,
63,
1773,
297,
267,
283,
15653,
63,
1317,
297,
283,
1773,
63,
1317,
297,
283,
8906,
297,
283,
2969,
7,
272,
776,
199,
2836,
26,
272,
2754,
63,
955,
63,
475,
63,
1180,
275,
788,
1213,
297,
283,
15653,
63,
1317,
418,
272,
1504,
63,
475,
63,
1180,
275,
334,
267,
283,
1213,
297,
283,
5464,
297,
283,
22678,
63,
602,
297,
283,
5091,
297,
267,
283,
15653,
63,
1317,
297,
283,
8906,
297,
283,
2969,
7,
272,
776,
199,
199,
533,
10332,
3276,
4880,
8,
51,
13929,
351,
17315,
4256,
12,
4628,
14,
12976,
304,
272,
2754,
63,
955,
275,
2754,
63,
955,
63,
475,
63,
1180,
272,
769,
63,
2918,
221,
275,
359,
283,
5464,
297,
283,
1213,
297,
283,
5091,
297,
283,
22678,
63,
602,
7,
1622,
272,
769,
63,
1541,
257,
275,
359,
283,
5091,
297,
283,
8906,
297,
283,
2969,
7,
1622,
272,
1434,
63,
14861,
275,
283,
22678,
63,
602,
7,
272,
7794,
275,
12291,
22678,
63,
602,
297,
283,
1213,
358,
339,
1824,
275,
2599,
4883,
63,
4040,
14,
632,
24849,
63,
3702,
8,
992,
14,
2354,
3276,
9,
339,
1504,
275,
1504,
63,
475,
63,
1180,
272,
876,
21440,
63,
955,
275,
791,
5464,
356,
788,
1213,
12074,
339,
1021,
12300,
26,
267,
8586,
275,
1689,
815,
15,
3596,
15,
2113,
14,
3596,
26360,
421,
199,
2113,
14,
2124,
14,
2683,
8,
1709,
14,
7841,
12,
10354,
4880,
776,
199,
2113,
14,
2124,
14,
2683,
8,
1709,
14,
1931,
12,
420,
10354,
4880,
776,
199,
2113,
14,
2124,
14,
2683,
8,
1709,
14,
2354,
3276,
12,
10332,
3276,
4880,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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loak_group.py
|
12
|
11972
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2019, Adam Goossens <adam.goossens@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {
'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'
}
DOCUMENTATION = '''
---
module: keycloak_group
short_description: Allows administration of Keycloak groups via Keycloak API
description:
- This module allows you to add, remove or modify Keycloak groups via the Keycloak REST API.
It requires access to the REST API via OpenID Connect; the user connecting and the client being
used must have the requisite access rights. In a default Keycloak installation, admin-cli
and an admin user would work, as would a separate client definition with the scope tailored
to your needs and a user having the expected roles.
- The names of module options are snake_cased versions of the camelCase ones found in the
Keycloak API and its documentation at U(http://www.keycloak.org/docs-api/3.3/rest-api/).
- Attributes are multi-valued in the Keycloak API. All attributes are lists of individual values and will
be returned that way by this module. You may pass single values for attributes when calling the module,
and this will be translated into a list suitable for the API.
- When updating a group, where possible provide the group ID to the module. This removes a lookup
to the API to translate the name into the group ID.
version_added: "2.8"
options:
state:
description:
- State of the group.
- On C(present), the group will be created if it does not yet exist, or updated with the parameters you provide.
- On C(absent), the group will be removed if it exists.
required: true
default: 'present'
type: str
choices:
- present
- absent
name:
type: str
description:
- Name of the group.
- This parameter is required only when creating or updating the group.
realm:
type: str
description:
- They Keycloak realm under which this group resides.
default: 'master'
id:
type: str
description:
- The unique identifier for this group.
- This parameter is not required for updating or deleting a group but
providing it will reduce the number of API calls required.
attributes:
type: dict
description:
- A dict of key/value pairs to set as custom attributes for the group.
- Values may be single values (e.g. a string) or a list of strings.
notes:
- Presently, the I(realmRoles), I(clientRoles) and I(access) attributes returned by the Keycloak API
are read-only for groups. This limitation will be removed in a later version of this module.
extends_documentation_fragment:
- keycloak
author:
- Adam Goossens (@adamgoossens)
'''
EXAMPLES = '''
- name: Create a Keycloak group
keycloak_group:
name: my-new-kc-group
realm: MyCustomRealm
state: present
auth_client_id: admin-cli
auth_keycloak_url: https://auth.example.com/auth
auth_realm: master
auth_username: USERNAME
auth_password: PASSWORD
delegate_to: localhost
- name: Delete a keycloak group
keycloak_group:
id: '9d59aa76-2755-48c6-b1af-beb70a82c3cd'
state: absent
realm: MyCustomRealm
auth_client_id: admin-cli
auth_keycloak_url: https://auth.example.com/auth
auth_realm: master
auth_username: USERNAME
auth_password: PASSWORD
delegate_to: localhost
- name: Delete a Keycloak group based on name
keycloak_group:
name: my-group-for-deletion
state: absent
auth_client_id: admin-cli
auth_keycloak_url: https://auth.example.com/auth
auth_realm: master
auth_username: USERNAME
auth_password: PASSWORD
delegate_to: localhost
- name: Update the name of a Keycloak group
keycloak_group:
id: '9d59aa76-2755-48c6-b1af-beb70a82c3cd'
name: an-updated-kc-group-name
state: present
auth_client_id: admin-cli
auth_keycloak_url: https://auth.example.com/auth
auth_realm: master
auth_username: USERNAME
auth_password: PASSWORD
delegate_to: localhost
- name: Create a keycloak group with some custom attributes
keycloak_group:
auth_client_id: admin-cli
auth_keycloak_url: https://auth.example.com/auth
auth_realm: master
auth_username: USERNAME
auth_password: PASSWORD
name: my-new_group
attributes:
attrib1: value1
attrib2: value2
attrib3:
- with
- numerous
- individual
- list
- items
delegate_to: localhost
'''
RETURN = '''
group:
description: Group representation of the group after module execution (sample is truncated).
returned: always
type: complex
contains:
id:
description: GUID that identifies the group
type: str
returned: always
sample: 23f38145-3195-462c-97e7-97041ccea73e
name:
description: Name of the group
type: str
returned: always
sample: grp-test-123
attributes:
description: Attributes applied to this group
type: dict
returned: always
sample:
attr1: ["val1", "val2", "val3"]
path:
description: URI path to the group
type: str
returned: always
sample: /grp-test-123
realmRoles:
description: An array of the realm-level roles granted to this group
type: list
returned: always
sample: []
subGroups:
description: A list of groups that are children of this group. These groups will have the same parameters as
documented here.
type: list
returned: always
clientRoles:
description: A list of client-level roles granted to this group
type: list
returned: always
sample: []
access:
description: A dict describing the accesses you have to this group based on the credentials used.
type: dict
returned: always
sample:
manage: true
manageMembership: true
view: true
'''
from ansible.module_utils.identity.keycloak.keycloak import KeycloakAPI, camel, \
keycloak_argument_spec, get_token, KeycloakError
from ansible.module_utils.basic import AnsibleModule
def main():
"""
Module execution
:return:
"""
argument_spec = keycloak_argument_spec()
meta_args = dict(
state=dict(default='present', choices=['present', 'absent']),
realm=dict(default='master'),
id=dict(type='str'),
name=dict(type='str'),
attributes=dict(type='dict')
)
argument_spec.update(meta_args)
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True,
required_one_of=([['id', 'name']]))
result = dict(changed=False, msg='', diff={}, group='')
# Obtain access token, initialize API
try:
connection_header = get_token(
base_url=module.params.get('auth_keycloak_url'),
validate_certs=module.params.get('validate_certs'),
auth_realm=module.params.get('auth_realm'),
client_id=module.params.get('auth_client_id'),
auth_username=module.params.get('auth_username'),
auth_password=module.params.get('auth_password'),
client_secret=module.params.get('auth_client_secret'),
)
except KeycloakError as e:
module.fail_json(msg=str(e))
kc = KeycloakAPI(module, connection_header)
realm = module.params.get('realm')
state = module.params.get('state')
gid = module.params.get('id')
name = module.params.get('name')
attributes = module.params.get('attributes')
before_group = None # current state of the group, for merging.
# does the group already exist?
if gid is None:
before_group = kc.get_group_by_name(name, realm=realm)
else:
before_group = kc.get_group_by_groupid(gid, realm=realm)
before_group = {} if before_group is None else before_group
# attributes in Keycloak have their values returned as lists
# via the API. attributes is a dict, so we'll transparently convert
# the values to lists.
if attributes is not None:
for key, val in module.params['attributes'].items():
module.params['attributes'][key] = [val] if not isinstance(val, list) else val
group_params = [x for x in module.params
if x not in list(keycloak_argument_spec().keys()) + ['state', 'realm'] and
module.params.get(x) is not None]
# build a changeset
changeset = {}
for param in group_params:
new_param_value = module.params.get(param)
old_value = before_group[param] if param in before_group else None
if new_param_value != old_value:
changeset[camel(param)] = new_param_value
# prepare the new group
updated_group = before_group.copy()
updated_group.update(changeset)
# if before_group is none, the group doesn't exist.
if before_group == {}:
if state == 'absent':
# nothing to do.
if module._diff:
result['diff'] = dict(before='', after='')
result['msg'] = 'Group does not exist; doing nothing.'
result['group'] = dict()
module.exit_json(**result)
# for 'present', create a new group.
result['changed'] = True
if name is None:
module.fail_json(msg='name must be specified when creating a new group')
if module._diff:
result['diff'] = dict(before='', after=updated_group)
if module.check_mode:
module.exit_json(**result)
# do it for real!
kc.create_group(updated_group, realm=realm)
after_group = kc.get_group_by_name(name, realm)
result['group'] = after_group
result['msg'] = 'Group {name} has been created with ID {id}'.format(name=after_group['name'],
id=after_group['id'])
else:
if state == 'present':
# no changes
if updated_group == before_group:
result['changed'] = False
result['group'] = updated_group
result['msg'] = "No changes required to group {name}.".format(name=before_group['name'])
module.exit_json(**result)
# update the existing group
result['changed'] = True
if module._diff:
result['diff'] = dict(before=before_group, after=updated_group)
if module.check_mode:
module.exit_json(**result)
# do the update
kc.update_group(updated_group, realm=realm)
after_group = kc.get_group_by_groupid(updated_group['id'], realm=realm)
result['group'] = after_group
result['msg'] = "Group {id} has been updated".format(id=after_group['id'])
module.exit_json(**result)
elif state == 'absent':
result['group'] = dict()
if module._diff:
result['diff'] = dict(before=before_group, after='')
if module.check_mode:
module.exit_json(**result)
# delete for real
gid = before_group['id']
kc.delete_group(groupid=gid, realm=realm)
result['changed'] = True
result['msg'] = "Group {name} has been deleted".format(name=before_group['name'])
module.exit_json(**result)
module.exit_json(**result)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
20312,
12,
4431,
455,
3971,
736,
22891,
665,
27679,
14,
1939,
736,
22891,
32,
6799,
14,
957,
30,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
469,
272,
283,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
272,
283,
1205,
356,
788,
7780,
995,
272,
283,
4946,
63,
991,
356,
283,
9387,
7,
199,
93,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
790,
1251,
1151,
63,
923,
199,
199,
3612,
63,
1802,
26,
22819,
4628,
4633,
402,
2606,
1251,
1151,
4652,
4799,
2606,
1251,
1151,
3261,
199,
199,
1802,
26,
272,
446,
961,
859,
6127,
1265,
370,
1050,
12,
2813,
503,
2811,
2606,
1251,
1151,
4652,
4799,
314,
2606,
1251,
1151,
14880,
3261,
14,
489,
2779,
5074,
2879,
370,
314,
14880,
3261,
4799,
25463,
15175,
27,
314,
922,
18170,
436,
314,
1890,
3769,
489,
1202,
1471,
1172,
314,
295,
783,
2124,
2879,
4481,
14,
1010,
282,
849,
2606,
1251,
1151,
12096,
12,
4628,
13,
2764,
489,
436,
376,
4628,
922,
3955,
1736,
12,
465,
3955,
282,
7396,
1890,
5492,
543,
314,
4194,
3052,
11737,
581,
489,
370,
2195,
4839,
436,
282,
922,
9445,
314,
1420,
11689,
14,
339,
446,
710,
1561,
402,
859,
1511,
787,
6895,
1728,
63,
32738,
5459,
402,
314,
31129,
1538,
7869,
1911,
315,
314,
489,
2606,
1251,
1151,
3261,
436,
2399,
3794,
737,
738,
8,
1014,
921,
1544,
14,
498,
1251,
1151,
14,
1308,
15,
4757,
13,
1246,
15,
19,
14,
19,
15,
3911,
13,
1246,
15,
680,
339,
446,
9382,
787,
3510,
13,
16611,
315,
314,
2606,
1251,
1151,
3261,
14,
2900,
3004,
787,
5548,
402,
8212,
1338,
436,
911,
489,
506,
2138,
626,
4340,
701,
642,
859,
14,
2047,
1443,
986,
2849,
1338,
367,
3004,
1380,
6358,
314,
859,
12,
489,
436,
642,
911,
506,
14598,
1901,
282,
769,
11233,
367,
314,
3261,
14,
339,
446,
3979,
12928,
282,
1572,
12,
2382,
3962,
5647,
314,
1572,
2870,
370,
314,
859,
14,
961,
14185,
282,
4237,
489,
370,
314,
3261,
370,
9028,
314,
536,
1901,
314,
1572,
2870,
14,
199,
199,
1023,
63,
3270,
26,
298,
18,
14,
24,
2,
199,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
288,
446,
8511,
402,
314,
1572,
14,
288,
446,
4068,
445,
8,
1881,
395,
314,
1572,
911,
506,
2737,
340,
652,
1630,
440,
5966,
2187,
12,
503,
4588,
543,
314,
2633,
1265,
5647,
14,
288,
446,
4068,
445,
8,
5575,
395,
314,
1572,
911,
506,
4829,
340,
652,
3495,
14,
267,
1415,
26,
2549,
267,
849,
26,
283,
1881,
7,
267,
730,
26,
620,
267,
3415,
26,
288,
446,
3451,
288,
446,
9552,
339,
536,
26,
267,
730,
26,
620,
267,
1369,
26,
288,
446,
2812,
402,
314,
1572,
14,
288,
446,
961,
2725,
365,
1415,
1454,
1380,
6425,
503,
12928,
314,
1572,
14,
339,
10482,
26,
267,
730,
26,
620,
267,
1369,
26,
288,
446,
9322,
2606,
1251,
1151,
10482,
1334,
1314,
642,
1572,
295,
19564,
14,
267,
849,
26,
283,
4133,
7,
339,
1305,
26,
267,
730,
26,
620,
267,
1369,
26,
288,
446,
710,
3747,
5148,
367,
642,
1572,
14,
288,
446,
961,
2725,
365,
440,
1415,
367,
12928,
503,
13794,
282,
1572,
1325,
1598,
13070,
652,
911,
7114,
314,
1329,
402,
3261,
4882,
1415,
14,
339,
3004,
26,
267,
730,
26,
1211,
267,
1369,
26,
288,
446,
437,
1211,
402,
790,
15,
585,
6342,
370,
663,
465,
3537,
3004,
367,
314,
1572,
14,
288,
446,
13468,
1443,
506,
2849,
1338,
334,
69,
14,
71,
14,
282,
1059,
9,
503,
282,
769,
402,
3326,
14,
199,
199,
5983,
26,
272,
446,
5543,
1150,
590,
12,
314,
473,
8,
7728,
3863,
2978,
395,
473,
8,
1258,
3863,
2978,
9,
436,
473,
8,
2732,
9,
3004,
2138,
701,
314,
2606,
1251,
1151,
3261,
489,
787,
1586,
13,
2118,
367,
4652,
14,
961,
12305,
911,
506,
4829,
315,
282,
2945,
1015,
402,
642,
859,
14,
199,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
790,
1251,
1151,
199,
199,
2502,
26,
272,
446,
4431,
455,
3971,
736,
22891,
8593,
27679,
1939,
736,
22891,
9,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
2790,
282,
2606,
1251,
1151,
1572,
523,
790,
1251,
1151,
63,
923,
26,
272,
536,
26,
3002,
13,
1222,
13,
75,
67,
13,
923,
272,
10482,
26,
4932,
7223,
27422,
272,
1174,
26,
3451,
272,
1790,
63,
1258,
63,
344,
26,
4628,
13,
2764,
272,
1790,
63,
498,
1251,
1151,
63,
633,
26,
4178,
921,
1178,
14,
2694,
14,
957,
15,
1178,
272,
1790,
63,
7728,
26,
5288,
272,
1790,
63,
2473,
26,
13044,
2339,
272,
1790,
63,
2060,
26,
21705,
5172,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
8496,
282,
790,
1251,
1151,
1572,
523,
790,
1251,
1151,
63,
923,
26,
272,
1305,
26,
283,
25,
68,
1427,
2158,
2114,
13,
1465,
1229,
13,
2006,
67,
22,
13,
66,
17,
2756,
13,
1235,
66,
2760,
65,
2564,
67,
19,
2866,
7,
272,
1174,
26,
9552,
272,
10482,
26,
4932,
7223,
27422,
272,
1790,
63,
1258,
63,
344,
26,
4628,
13,
2764,
272,
1790,
63,
498,
1251,
1151,
63,
633,
26,
4178,
921,
1178,
14,
2694,
14,
957,
15,
1178,
272,
1790,
63,
7728,
26,
5288,
272,
1790,
63,
2473,
26,
13044,
2339,
272,
1790,
63,
2060,
26,
21705,
5172,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
8496,
282,
2606,
1251,
1151,
1572,
4079,
641,
536,
523,
790,
1251,
1151,
63,
923,
26,
272,
536,
26,
3002,
13,
923,
13,
509,
13,
14281,
272,
1174,
26,
9552,
272,
1790,
63,
1258,
63,
344,
26,
4628,
13,
2764,
272,
1790,
63,
498,
1251,
1151,
63,
633,
26,
4178,
921,
1178,
14,
2694,
14,
957,
15,
1178,
272
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
20312,
12,
4431,
455,
3971,
736,
22891,
665,
27679,
14,
1939,
736,
22891,
32,
6799,
14,
957,
30,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
469,
272,
283,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
272,
283,
1205,
356,
788,
7780,
995,
272,
283,
4946,
63,
991,
356,
283,
9387,
7,
199,
93,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
790,
1251,
1151,
63,
923,
199,
199,
3612,
63,
1802,
26,
22819,
4628,
4633,
402,
2606,
1251,
1151,
4652,
4799,
2606,
1251,
1151,
3261,
199,
199,
1802,
26,
272,
446,
961,
859,
6127,
1265,
370,
1050,
12,
2813,
503,
2811,
2606,
1251,
1151,
4652,
4799,
314,
2606,
1251,
1151,
14880,
3261,
14,
489,
2779,
5074,
2879,
370,
314,
14880,
3261,
4799,
25463,
15175,
27,
314,
922,
18170,
436,
314,
1890,
3769,
489,
1202,
1471,
1172,
314,
295,
783,
2124,
2879,
4481,
14,
1010,
282,
849,
2606,
1251,
1151,
12096,
12,
4628,
13,
2764,
489,
436,
376,
4628,
922,
3955,
1736,
12,
465,
3955,
282,
7396,
1890,
5492,
543,
314,
4194,
3052,
11737,
581,
489,
370,
2195,
4839,
436,
282,
922,
9445,
314,
1420,
11689,
14,
339,
446,
710,
1561,
402,
859,
1511,
787,
6895,
1728,
63,
32738,
5459,
402,
314,
31129,
1538,
7869,
1911,
315,
314,
489,
2606,
1251,
1151,
3261,
436,
2399,
3794,
737,
738,
8,
1014,
921,
1544,
14,
498,
1251,
1151,
14,
1308,
15,
4757,
13,
1246,
15,
19,
14,
19,
15,
3911,
13,
1246,
15,
680,
339,
446,
9382,
787,
3510,
13,
16611,
315,
314,
2606,
1251,
1151,
3261,
14,
2900,
3004,
787,
5548,
402,
8212,
1338,
436,
911,
489,
506,
2138,
626,
4340,
701,
642,
859,
14,
2047,
1443,
986,
2849,
1338,
367,
3004,
1380,
6358,
314,
859,
12,
489,
436,
642,
911,
506,
14598,
1901,
282,
769,
11233,
367,
314,
3261,
14,
339,
446,
3979,
12928,
282,
1572,
12,
2382,
3962,
5647,
314,
1572,
2870,
370,
314,
859,
14,
961,
14185,
282,
4237,
489,
370,
314,
3261,
370,
9028,
314,
536,
1901,
314,
1572,
2870,
14,
199,
199,
1023,
63,
3270,
26,
298,
18,
14,
24,
2,
199,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
288,
446,
8511,
402,
314,
1572,
14,
288,
446,
4068,
445,
8,
1881,
395,
314,
1572,
911,
506,
2737,
340,
652,
1630,
440,
5966,
2187,
12,
503,
4588,
543,
314,
2633,
1265,
5647,
14,
288,
446,
4068,
445,
8,
5575,
395,
314,
1572,
911,
506,
4829,
340,
652,
3495,
14,
267,
1415,
26,
2549,
267,
849,
26,
283,
1881,
7,
267,
730,
26,
620,
267,
3415,
26,
288,
446,
3451,
288,
446,
9552,
339,
536,
26,
267,
730,
26,
620,
267,
1369,
26,
288,
446,
2812,
402,
314,
1572,
14,
288,
446,
961,
2725,
365,
1415,
1454,
1380,
6425,
503,
12928,
314,
1572,
14,
339,
10482,
26,
267,
730,
26,
620,
267,
1369,
26,
288,
446,
9322,
2606,
1251,
1151,
10482,
1334,
1314,
642,
1572,
295,
19564,
14,
267,
849,
26,
283,
4133,
7,
339,
1305,
26,
267,
730,
26,
620,
267,
1369,
26,
288,
446,
710,
3747,
5148,
367,
642,
1572,
14,
288,
446,
961,
2725,
365,
440,
1415,
367,
12928,
503,
13794,
282,
1572,
1325,
1598,
13070,
652,
911,
7114,
314,
1329,
402,
3261,
4882,
1415,
14,
339,
3004,
26,
267,
730,
26,
1211,
267,
1369,
26,
288,
446,
437,
1211,
402,
790,
15,
585,
6342,
370,
663,
465,
3537,
3004,
367,
314,
1572,
14,
288,
446,
13468,
1443,
506,
2849,
1338,
334,
69,
14,
71,
14,
282,
1059,
9,
503,
282,
769,
402,
3326,
14,
199,
199,
5983,
26,
272,
446,
5543,
1150,
590,
12,
314,
473,
8,
7728,
3863,
2978,
395,
473,
8,
1258,
3863,
2978,
9,
436,
473,
8,
2732,
9,
3004,
2138,
701,
314,
2606,
1251,
1151,
3261,
489,
787,
1586,
13,
2118,
367,
4652,
14,
961,
12305,
911,
506,
4829,
315,
282,
2945,
1015,
402,
642,
859,
14,
199,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
790,
1251,
1151,
199,
199,
2502,
26,
272,
446,
4431,
455,
3971,
736,
22891,
8593,
27679,
1939,
736,
22891,
9,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
2790,
282,
2606,
1251,
1151,
1572,
523,
790,
1251,
1151,
63,
923,
26,
272,
536,
26,
3002,
13,
1222,
13,
75,
67,
13,
923,
272,
10482,
26,
4932,
7223,
27422,
272,
1174,
26,
3451,
272,
1790,
63,
1258,
63,
344,
26,
4628,
13,
2764,
272,
1790,
63,
498,
1251,
1151,
63,
633,
26,
4178,
921,
1178,
14,
2694,
14,
957,
15,
1178,
272,
1790,
63,
7728,
26,
5288,
272,
1790,
63,
2473,
26,
13044,
2339,
272,
1790,
63,
2060,
26,
21705,
5172,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
8496,
282,
790,
1251,
1151,
1572,
523,
790,
1251,
1151,
63,
923,
26,
272,
1305,
26,
283,
25,
68,
1427,
2158,
2114,
13,
1465,
1229,
13,
2006,
67,
22,
13,
66,
17,
2756,
13,
1235,
66,
2760,
65,
2564,
67,
19,
2866,
7,
272,
1174,
26,
9552,
272,
10482,
26,
4932,
7223,
27422,
272,
1790,
63,
1258,
63,
344,
26,
4628,
13,
2764,
272,
1790,
63,
498,
1251,
1151,
63,
633,
26,
4178,
921,
1178,
14,
2694,
14,
957,
15,
1178,
272,
1790,
63,
7728,
26,
5288,
272,
1790,
63,
2473,
26,
13044,
2339,
272,
1790,
63,
2060,
26,
21705,
5172,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
8496,
282,
2606,
1251,
1151,
1572,
4079,
641,
536,
523,
790,
1251,
1151,
63,
923,
26,
272,
536,
26,
3002,
13,
923,
13,
509,
13,
14281,
272,
1174,
26,
9552,
272,
1790,
63,
1258,
63,
344,
26,
4628,
13,
2764,
272,
1790,
63,
498,
1251,
1151,
63,
633,
26,
4178,
921,
1178,
14,
2694,
14,
957,
15,
1178,
272,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
pgmillon/ansible
|
lib/ansible/modules/cloud/vmware/vmware_host_facts.py
|
1
|
11491
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: (c) 2017, Wei Gao <gaowei3@qq.com>
# Copyright: (c) 2018, Ansible Project
#
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {
'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'
}
DOCUMENTATION = r'''
---
module: vmware_host_facts
short_description: Gathers facts about remote ESXi hostsystem
description:
- This module can be used to gathers facts like CPU, memory, datastore, network and system etc. about ESXi host system.
- Please specify hostname or IP address of ESXi host system as C(hostname).
- If hostname or IP address of vCenter is provided as C(hostname) and C(esxi_hostname) is not specified, then the
module will throw an error.
- VSAN facts added in 2.7 version.
version_added: 2.5
author:
- Wei Gao (@woshihaoren)
requirements:
- python >= 2.6
- PyVmomi
options:
esxi_hostname:
description:
- ESXi hostname.
- Host facts about the specified ESXi server will be returned.
- By specifying this option, you can select which ESXi hostsystem is returned if connecting to a vCenter.
version_added: 2.8
show_tag:
description:
- Tags related to Host are shown if set to C(True).
default: False
type: bool
required: False
version_added: 2.9
extends_documentation_fragment: vmware.documentation
'''
EXAMPLES = r'''
- name: Gather vmware host facts
vmware_host_facts:
hostname: "{{ esxi_server }}"
username: "{{ esxi_username }}"
password: "{{ esxi_password }}"
register: host_facts
delegate_to: localhost
- name: Gather vmware host facts from vCenter
vmware_host_facts:
hostname: "{{ vcenter_server }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
esxi_hostname: "{{ esxi_hostname }}"
register: host_facts
delegate_to: localhost
- name: Gather vmware host facts from vCenter with tag information
vmware_host_facts:
hostname: "{{ vcenter_server }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
esxi_hostname: "{{ esxi_hostname }}"
show_tag: True
register: host_facts_tag
delegate_to: localhost
- name: Get VSAN Cluster UUID from host facts
vmware_host_facts:
hostname: "{{ esxi_server }}"
username: "{{ esxi_username }}"
password: "{{ esxi_password }}"
register: host_facts
- set_fact:
cluster_uuid: "{{ host_facts['ansible_facts']['vsan_cluster_uuid'] }}"
'''
RETURN = r'''
ansible_facts:
description: system info about the host machine
returned: always
type: dict
sample:
{
"ansible_all_ipv4_addresses": [
"10.76.33.200"
],
"ansible_bios_date": "2011-01-01T00:00:00+00:00",
"ansible_bios_version": "0.5.1",
"ansible_datastore": [
{
"free": "11.63 GB",
"name": "datastore1",
"total": "12.50 GB"
}
],
"ansible_distribution": "VMware ESXi",
"ansible_distribution_build": "4887370",
"ansible_distribution_version": "6.5.0",
"ansible_hostname": "10.76.33.100",
"ansible_interfaces": [
"vmk0"
],
"ansible_memfree_mb": 2702,
"ansible_memtotal_mb": 4095,
"ansible_os_type": "vmnix-x86",
"ansible_processor": "Intel Xeon E312xx (Sandy Bridge)",
"ansible_processor_cores": 2,
"ansible_processor_count": 2,
"ansible_processor_vcpus": 2,
"ansible_product_name": "KVM",
"ansible_product_serial": "NA",
"ansible_system_vendor": "Red Hat",
"ansible_vmk0": {
"device": "vmk0",
"ipv4": {
"address": "10.76.33.100",
"netmask": "255.255.255.0"
},
"macaddress": "52:54:00:56:7d:59",
"mtu": 1500
},
"vsan_cluster_uuid": null,
"vsan_node_uuid": null,
"vsan_health": "unknown",
"tags": [
{
"category_id": "urn:vmomi:InventoryServiceCategory:8eb81431-b20d-49f5-af7b-126853aa1189:GLOBAL",
"category_name": "host_category_0001",
"description": "",
"id": "urn:vmomi:InventoryServiceTag:e9398232-46fd-461a-bf84-06128e182a4a:GLOBAL",
"name": "host_tag_0001"
}
],
}
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.formatters import bytes_to_human
from ansible.module_utils.vmware import PyVmomi, vmware_argument_spec, find_obj
try:
from pyVmomi import vim
except ImportError:
pass
from ansible.module_utils.vmware_rest_client import VmwareRestClient
try:
from com.vmware.vapi.std_client import DynamicID
except ImportError:
pass
class VMwareHostFactManager(PyVmomi):
def __init__(self, module):
super(VMwareHostFactManager, self).__init__(module)
esxi_host_name = self.params.get('esxi_hostname', None)
if self.is_vcenter():
if esxi_host_name is None:
self.module.fail_json(msg="Connected to a vCenter system without specifying esxi_hostname")
self.host = self.get_all_host_objs(esxi_host_name=esxi_host_name)
if len(self.host) > 1:
self.module.fail_json(msg="esxi_hostname matched multiple hosts")
self.host = self.host[0]
else:
self.host = find_obj(self.content, [vim.HostSystem], None)
if self.host is None:
self.module.fail_json(msg="Failed to find host system.")
def all_facts(self):
ansible_facts = {}
ansible_facts.update(self.get_cpu_facts())
ansible_facts.update(self.get_memory_facts())
ansible_facts.update(self.get_datastore_facts())
ansible_facts.update(self.get_network_facts())
ansible_facts.update(self.get_system_facts())
ansible_facts.update(self.get_vsan_facts())
ansible_facts.update(self.get_cluster_facts())
if self.params.get('show_tag'):
ansible_facts.update(self.get_tag_facts())
self.module.exit_json(changed=False, ansible_facts=ansible_facts)
def get_cluster_facts(self):
cluster_facts = {'cluster': None}
if self.host.parent and isinstance(self.host.parent, vim.ClusterComputeResource):
cluster_facts.update(cluster=self.host.parent.name)
return cluster_facts
def get_vsan_facts(self):
config_mgr = self.host.configManager.vsanSystem
if config_mgr is None:
return {
'vsan_cluster_uuid': None,
'vsan_node_uuid': None,
'vsan_health': "unknown",
}
status = config_mgr.QueryHostStatus()
return {
'vsan_cluster_uuid': status.uuid,
'vsan_node_uuid': status.nodeUuid,
'vsan_health': status.health,
}
def get_cpu_facts(self):
return {
'ansible_processor': self.host.summary.hardware.cpuModel,
'ansible_processor_cores': self.host.summary.hardware.numCpuCores,
'ansible_processor_count': self.host.summary.hardware.numCpuPkgs,
'ansible_processor_vcpus': self.host.summary.hardware.numCpuThreads,
}
def get_memory_facts(self):
return {
'ansible_memfree_mb': self.host.hardware.memorySize // 1024 // 1024 - self.host.summary.quickStats.overallMemoryUsage,
'ansible_memtotal_mb': self.host.hardware.memorySize // 1024 // 1024,
}
def get_datastore_facts(self):
facts = dict()
facts['ansible_datastore'] = []
for store in self.host.datastore:
_tmp = {
'name': store.summary.name,
'total': bytes_to_human(store.summary.capacity),
'free': bytes_to_human(store.summary.freeSpace),
}
facts['ansible_datastore'].append(_tmp)
return facts
def get_network_facts(self):
facts = dict()
facts['ansible_interfaces'] = []
facts['ansible_all_ipv4_addresses'] = []
for nic in self.host.config.network.vnic:
device = nic.device
facts['ansible_interfaces'].append(device)
facts['ansible_all_ipv4_addresses'].append(nic.spec.ip.ipAddress)
_tmp = {
'device': device,
'ipv4': {
'address': nic.spec.ip.ipAddress,
'netmask': nic.spec.ip.subnetMask,
},
'macaddress': nic.spec.mac,
'mtu': nic.spec.mtu,
}
facts['ansible_' + device] = _tmp
return facts
def get_system_facts(self):
sn = 'NA'
for info in self.host.hardware.systemInfo.otherIdentifyingInfo:
if info.identifierType.key == 'ServiceTag':
sn = info.identifierValue
facts = {
'ansible_distribution': self.host.config.product.name,
'ansible_distribution_version': self.host.config.product.version,
'ansible_distribution_build': self.host.config.product.build,
'ansible_os_type': self.host.config.product.osType,
'ansible_system_vendor': self.host.hardware.systemInfo.vendor,
'ansible_hostname': self.host.summary.config.name,
'ansible_product_name': self.host.hardware.systemInfo.model,
'ansible_product_serial': sn,
'ansible_bios_date': self.host.hardware.biosInfo.releaseDate,
'ansible_bios_version': self.host.hardware.biosInfo.biosVersion,
}
return facts
def get_tag_facts(self):
vmware_client = VmwareRestClient(self.module)
host_dynamic_obj = DynamicID(type='HostSystem', id=self.host._moId)
self.tag_service = vmware_client.api_client.tagging.Tag
self.tag_association_svc = vmware_client.api_client.tagging.TagAssociation
self.category_service = vmware_client.api_client.tagging.Category
facts = {
'tags': self.get_tags_for_object(host_dynamic_obj)
}
return facts
def get_tags_for_object(self, dobj):
"""
Return tags associated with an object
Args:
dobj: Dynamic object
Returns: List of tags associated with the given object
"""
tag_ids = self.tag_association_svc.list_attached_tags(dobj)
tags = []
for tag_id in tag_ids:
tag_obj = self.tag_service.get(tag_id)
tags.append({
'id': tag_obj.id,
'category_name': self.category_service.get(tag_obj.category_id).name,
'name': tag_obj.name,
'description': tag_obj.description,
'category_id': tag_obj.category_id,
})
return tags
def main():
argument_spec = vmware_argument_spec()
argument_spec.update(
esxi_hostname=dict(type='str', required=False),
show_tag=dict(type='bool', default=False),
)
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
vm_host_manager = VMwareHostFactManager(module)
vm_host_manager.all_facts()
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
26,
334,
67,
9,
9708,
12,
2136,
73,
598,
8035,
665,
5294,
583,
24708,
19,
32,
16672,
14,
957,
30,
199,
3,
1898,
26,
334,
67,
9,
14894,
12,
2622,
7290,
199,
3,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
469,
272,
283,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
272,
283,
1205,
356,
788,
7780,
995,
272,
283,
4946,
63,
991,
356,
283,
9387,
7,
199,
93,
199,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
19365,
63,
1102,
63,
5047,
199,
3612,
63,
1802,
26,
19634,
83,
9036,
3595,
3982,
10427,
14828,
1591,
2253,
199,
1802,
26,
272,
446,
961,
859,
883,
506,
1202,
370,
13082,
83,
9036,
2839,
11952,
12,
4402,
12,
12007,
12,
2784,
436,
2656,
5423,
14,
3595,
10427,
14828,
1591,
2656,
14,
272,
446,
7754,
4165,
6246,
503,
3531,
2287,
402,
10427,
14828,
1591,
2656,
465,
445,
8,
4269,
680,
272,
446,
982,
6246,
503,
3531,
2287,
402,
373,
13551,
365,
2741,
465,
445,
8,
4269,
9,
436,
445,
8,
397,
6865,
63,
4269,
9,
365,
440,
2013,
12,
2066,
314,
489,
859,
911,
7978,
376,
1125,
14,
272,
446,
21685,
879,
9036,
3483,
315,
499,
14,
23,
1015,
14,
199,
1023,
63,
3270,
26,
499,
14,
21,
199,
2502,
26,
272,
446,
2136,
73,
598,
8035,
8593,
2027,
19377,
2411,
720,
78,
9,
199,
7538,
26,
272,
446,
2366,
2356,
499,
14,
22,
272,
446,
1611,
54,
28603,
199,
1419,
26,
523,
9455,
6865,
63,
4269,
26,
272,
1369,
26,
272,
446,
10427,
14828,
6246,
14,
272,
446,
10891,
9036,
3595,
314,
2013,
10427,
14828,
1654,
911,
506,
2138,
14,
272,
446,
4885,
9176,
642,
945,
12,
1265,
883,
3504,
1314,
10427,
14828,
1591,
2253,
365,
2138,
340,
18170,
370,
282,
373,
13551,
14,
272,
1015,
63,
3270,
26,
499,
14,
24,
523,
2498,
63,
1450,
26,
272,
1369,
26,
272,
446,
25204,
4048,
370,
10891,
787,
9164,
340,
663,
370,
445,
8,
549,
680,
272,
849,
26,
756,
272,
730,
26,
2155,
272,
1415,
26,
756,
272,
1015,
63,
3270,
26,
499,
14,
25,
199,
11036,
63,
9970,
63,
7677,
26,
19365,
14,
9970,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
19634,
19365,
1591,
9036,
523,
19365,
63,
1102,
63,
5047,
26,
272,
6246,
26,
7370,
9455,
6865,
63,
1000,
7820,
272,
3434,
26,
7370,
9455,
6865,
63,
2473,
7820,
272,
2505,
26,
7370,
9455,
6865,
63,
2060,
7820,
523,
2274,
26,
1591,
63,
5047,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
19634,
19365,
1591,
9036,
687,
373,
13551,
523,
19365,
63,
1102,
63,
5047,
26,
272,
6246,
26,
7370,
27127,
63,
1000,
7820,
272,
3434,
26,
7370,
27127,
63,
751,
7820,
272,
2505,
26,
7370,
27127,
63,
1529,
7820,
272,
9455,
6865,
63,
4269,
26,
7370,
9455,
6865,
63,
4269,
7820,
523,
2274,
26,
1591,
63,
5047,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
19634,
19365,
1591,
9036,
687,
373,
13551,
543,
1947,
2556,
523,
19365,
63,
1102,
63,
5047,
26,
272,
6246,
26,
7370,
27127,
63,
1000,
7820,
272,
3434,
26,
7370,
27127,
63,
751,
7820,
272,
2505,
26,
7370,
27127,
63,
1529,
7820,
272,
9455,
6865,
63,
4269,
26,
7370,
9455,
6865,
63,
4269,
7820,
272,
2498,
63,
1450,
26,
715,
523,
2274,
26,
1591,
63,
5047,
63,
1450,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
2372,
21685,
879,
16454,
11134,
687,
1591,
9036,
523,
19365,
63,
1102,
63,
5047,
26,
272,
6246,
26,
7370,
9455,
6865,
63,
1000,
7820,
272,
3434,
26,
7370,
9455,
6865,
63,
2473,
7820,
272,
2505,
26,
7370,
9455,
6865,
63,
2060,
7820,
523,
2274,
26,
1591,
63,
5047,
199,
13,
663,
63,
7783,
26,
272,
4350,
63,
2580,
26,
7370,
1591,
63,
5047,
459,
4853,
63,
5047,
2545,
3122,
290,
63,
4201,
63,
2580,
418,
7820,
199,
2344,
199,
199,
9677,
275,
519,
2344,
199,
4853,
63,
5047,
26,
523,
1369,
26,
2656,
2256,
3595,
314,
1591,
6844,
523,
2138,
26,
3544,
523,
730,
26,
1211,
523,
2690,
26,
272,
469,
267,
298,
4853,
63,
452,
63,
4774,
20,
63,
7423,
582,
359,
288,
298,
709,
14,
2114,
14,
1153,
14,
1840,
2,
267,
2156,
267,
298,
4853,
63,
29673,
63,
602,
582,
298,
8128,
13,
614,
13,
614,
52,
383,
26,
383,
26,
383,
11,
383,
26,
383,
401,
267,
298,
4853,
63,
29673,
63,
1023,
582,
298,
16,
14,
21,
14,
17,
401,
267,
298,
4853,
63,
11450,
582,
359,
288,
469,
355,
298,
4624,
582,
298,
845,
14,
2766,
18553,
401,
355,
298,
354,
582,
298,
11450,
17,
401,
355,
298,
2923,
582,
298,
713,
14,
1400,
18553,
2,
288,
789,
267,
2156,
267,
298,
4853,
63,
4972,
582,
298,
6849,
1068,
10427,
14828,
401,
267,
298,
4853,
63,
4972,
63,
1506,
582,
298,
11926,
23,
13812,
401,
267,
298,
4853,
63,
4972,
63,
1023,
582,
298,
22,
14,
21,
14,
16,
401,
267,
298,
4853,
63,
4269,
582,
298,
709,
14,
2114,
14,
1153,
14,
1960,
401,
267,
298,
4853,
63,
7436,
582,
359,
288,
298,
2611,
75,
16,
2,
267,
2156,
267,
298,
4853,
63,
5286,
4624,
63,
887,
582,
8087,
996,
12,
267,
298,
4853,
63,
278,
2037,
1735,
63,
887,
582,
841,
19113,
12,
267,
298,
4853,
63,
736,
63,
466,
582,
298,
2611,
78,
1148,
13,
88,
1184,
401,
267,
298,
4853,
63,
6459,
582,
298,
27528,
1323,
69,
265,
662,
16683,
2154,
334,
51,
460,
89,
699,
5562,
4186,
267,
298,
4853,
63,
6459,
63,
4630,
582,
499,
12,
267,
298,
4853,
63,
6459,
63,
835,
582,
499,
12,
267,
298,
4853,
63,
6459,
63,
19685,
582,
499,
12,
267,
298,
4853,
63,
2558
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
26,
334,
67,
9,
9708,
12,
2136,
73,
598,
8035,
665,
5294,
583,
24708,
19,
32,
16672,
14,
957,
30,
199,
3,
1898,
26,
334,
67,
9,
14894,
12,
2622,
7290,
199,
3,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
469,
272,
283,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
272,
283,
1205,
356,
788,
7780,
995,
272,
283,
4946,
63,
991,
356,
283,
9387,
7,
199,
93,
199,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
19365,
63,
1102,
63,
5047,
199,
3612,
63,
1802,
26,
19634,
83,
9036,
3595,
3982,
10427,
14828,
1591,
2253,
199,
1802,
26,
272,
446,
961,
859,
883,
506,
1202,
370,
13082,
83,
9036,
2839,
11952,
12,
4402,
12,
12007,
12,
2784,
436,
2656,
5423,
14,
3595,
10427,
14828,
1591,
2656,
14,
272,
446,
7754,
4165,
6246,
503,
3531,
2287,
402,
10427,
14828,
1591,
2656,
465,
445,
8,
4269,
680,
272,
446,
982,
6246,
503,
3531,
2287,
402,
373,
13551,
365,
2741,
465,
445,
8,
4269,
9,
436,
445,
8,
397,
6865,
63,
4269,
9,
365,
440,
2013,
12,
2066,
314,
489,
859,
911,
7978,
376,
1125,
14,
272,
446,
21685,
879,
9036,
3483,
315,
499,
14,
23,
1015,
14,
199,
1023,
63,
3270,
26,
499,
14,
21,
199,
2502,
26,
272,
446,
2136,
73,
598,
8035,
8593,
2027,
19377,
2411,
720,
78,
9,
199,
7538,
26,
272,
446,
2366,
2356,
499,
14,
22,
272,
446,
1611,
54,
28603,
199,
1419,
26,
523,
9455,
6865,
63,
4269,
26,
272,
1369,
26,
272,
446,
10427,
14828,
6246,
14,
272,
446,
10891,
9036,
3595,
314,
2013,
10427,
14828,
1654,
911,
506,
2138,
14,
272,
446,
4885,
9176,
642,
945,
12,
1265,
883,
3504,
1314,
10427,
14828,
1591,
2253,
365,
2138,
340,
18170,
370,
282,
373,
13551,
14,
272,
1015,
63,
3270,
26,
499,
14,
24,
523,
2498,
63,
1450,
26,
272,
1369,
26,
272,
446,
25204,
4048,
370,
10891,
787,
9164,
340,
663,
370,
445,
8,
549,
680,
272,
849,
26,
756,
272,
730,
26,
2155,
272,
1415,
26,
756,
272,
1015,
63,
3270,
26,
499,
14,
25,
199,
11036,
63,
9970,
63,
7677,
26,
19365,
14,
9970,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
19634,
19365,
1591,
9036,
523,
19365,
63,
1102,
63,
5047,
26,
272,
6246,
26,
7370,
9455,
6865,
63,
1000,
7820,
272,
3434,
26,
7370,
9455,
6865,
63,
2473,
7820,
272,
2505,
26,
7370,
9455,
6865,
63,
2060,
7820,
523,
2274,
26,
1591,
63,
5047,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
19634,
19365,
1591,
9036,
687,
373,
13551,
523,
19365,
63,
1102,
63,
5047,
26,
272,
6246,
26,
7370,
27127,
63,
1000,
7820,
272,
3434,
26,
7370,
27127,
63,
751,
7820,
272,
2505,
26,
7370,
27127,
63,
1529,
7820,
272,
9455,
6865,
63,
4269,
26,
7370,
9455,
6865,
63,
4269,
7820,
523,
2274,
26,
1591,
63,
5047,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
19634,
19365,
1591,
9036,
687,
373,
13551,
543,
1947,
2556,
523,
19365,
63,
1102,
63,
5047,
26,
272,
6246,
26,
7370,
27127,
63,
1000,
7820,
272,
3434,
26,
7370,
27127,
63,
751,
7820,
272,
2505,
26,
7370,
27127,
63,
1529,
7820,
272,
9455,
6865,
63,
4269,
26,
7370,
9455,
6865,
63,
4269,
7820,
272,
2498,
63,
1450,
26,
715,
523,
2274,
26,
1591,
63,
5047,
63,
1450,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
2372,
21685,
879,
16454,
11134,
687,
1591,
9036,
523,
19365,
63,
1102,
63,
5047,
26,
272,
6246,
26,
7370,
9455,
6865,
63,
1000,
7820,
272,
3434,
26,
7370,
9455,
6865,
63,
2473,
7820,
272,
2505,
26,
7370,
9455,
6865,
63,
2060,
7820,
523,
2274,
26,
1591,
63,
5047,
199,
13,
663,
63,
7783,
26,
272,
4350,
63,
2580,
26,
7370,
1591,
63,
5047,
459,
4853,
63,
5047,
2545,
3122,
290,
63,
4201,
63,
2580,
418,
7820,
199,
2344,
199,
199,
9677,
275,
519,
2344,
199,
4853,
63,
5047,
26,
523,
1369,
26,
2656,
2256,
3595,
314,
1591,
6844,
523,
2138,
26,
3544,
523,
730,
26,
1211,
523,
2690,
26,
272,
469,
267,
298,
4853,
63,
452,
63,
4774,
20,
63,
7423,
582,
359,
288,
298,
709,
14,
2114,
14,
1153,
14,
1840,
2,
267,
2156,
267,
298,
4853,
63,
29673,
63,
602,
582,
298,
8128,
13,
614,
13,
614,
52,
383,
26,
383,
26,
383,
11,
383,
26,
383,
401,
267,
298,
4853,
63,
29673,
63,
1023,
582,
298,
16,
14,
21,
14,
17,
401,
267,
298,
4853,
63,
11450,
582,
359,
288,
469,
355,
298,
4624,
582,
298,
845,
14,
2766,
18553,
401,
355,
298,
354,
582,
298,
11450,
17,
401,
355,
298,
2923,
582,
298,
713,
14,
1400,
18553,
2,
288,
789,
267,
2156,
267,
298,
4853,
63,
4972,
582,
298,
6849,
1068,
10427,
14828,
401,
267,
298,
4853,
63,
4972,
63,
1506,
582,
298,
11926,
23,
13812,
401,
267,
298,
4853,
63,
4972,
63,
1023,
582,
298,
22,
14,
21,
14,
16,
401,
267,
298,
4853,
63,
4269,
582,
298,
709,
14,
2114,
14,
1153,
14,
1960,
401,
267,
298,
4853,
63,
7436,
582,
359,
288,
298,
2611,
75,
16,
2,
267,
2156,
267,
298,
4853,
63,
5286,
4624,
63,
887,
582,
8087,
996,
12,
267,
298,
4853,
63,
278,
2037,
1735,
63,
887,
582,
841,
19113,
12,
267,
298,
4853,
63,
736,
63,
466,
582,
298,
2611,
78,
1148,
13,
88,
1184,
401,
267,
298,
4853,
63,
6459,
582,
298,
27528,
1323,
69,
265,
662,
16683,
2154,
334,
51,
460,
89,
699,
5562,
4186,
267,
298,
4853,
63,
6459,
63,
4630,
582,
499,
12,
267,
298,
4853,
63,
6459,
63,
835,
582,
499,
12,
267,
298,
4853,
63,
6459,
63,
19685,
582,
499,
12,
267,
298,
4853,
63,
2558,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
silkyar/570_Big_Little
|
src/arch/x86/isa/insts/simd128/integer/shift/right_logical_shift.py
|
91
|
4565
|
# Copyright (c) 2007 The Hewlett-Packard Development Company
# All rights reserved.
#
# The license below extends only to copyright in the software and shall
# not be construed as granting a license to any other intellectual
# property including but not limited to intellectual property relating
# to a hardware implementation of the functionality of the software
# licensed hereunder. You may use the software subject to the license
# terms below provided that you ensure that this notice is replicated
# unmodified and in its entirety in all distributions of the software,
# modified or unmodified, in source code or in binary form.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors: Gabe Black
microcode = '''
def macroop PSRLW_XMM_XMM {
msrl xmmh, xmmh, xmmlm, size=2, ext=0
msrl xmml, xmml, xmmlm, size=2, ext=0
};
def macroop PSRLW_XMM_M {
ldfp ufp1, seg, sib, disp, dataSize=8
msrl xmml, xmml, ufp1, size=2, ext=0
msrl xmmh, xmmh, ufp1, size=2, ext=0
};
def macroop PSRLW_XMM_P {
rdip t7
ldfp ufp1, seg, riprel, disp, dataSize=8
msrl xmml, xmml, ufp1, size=2, ext=0
msrl xmmh, xmmh, ufp1, size=2, ext=0
};
def macroop PSRLW_XMM_I {
msrli xmml, xmml, imm, size=2, ext=0
msrli xmmh, xmmh, imm, size=2, ext=0
};
def macroop PSRLD_XMM_XMM {
msrl xmmh, xmmh, xmmlm, size=4, ext=0
msrl xmml, xmml, xmmlm, size=4, ext=0
};
def macroop PSRLD_XMM_M {
ldfp ufp1, seg, sib, disp, dataSize=8
msrl xmml, xmml, ufp1, size=4, ext=0
msrl xmmh, xmmh, ufp1, size=4, ext=0
};
def macroop PSRLD_XMM_P {
rdip t7
ldfp ufp1, seg, riprel, disp, dataSize=8
msrl xmml, xmml, ufp1, size=4, ext=0
msrl xmmh, xmmh, ufp1, size=4, ext=0
};
def macroop PSRLD_XMM_I {
msrli xmml, xmml, imm, size=4, ext=0
msrli xmmh, xmmh, imm, size=4, ext=0
};
def macroop PSRLQ_XMM_XMM {
msrl xmmh, xmmh, xmmlm, size=8, ext=0
msrl xmml, xmml, xmmlm, size=8, ext=0
};
def macroop PSRLQ_XMM_M {
ldfp ufp1, seg, sib, disp, dataSize=8
msrl xmml, xmml, ufp1, size=8, ext=0
msrl xmmh, xmmh, ufp1, size=8, ext=0
};
def macroop PSRLQ_XMM_P {
rdip t7
ldfp ufp1, seg, riprel, disp, dataSize=8
msrl xmml, xmml, ufp1, size=8, ext=0
msrl xmmh, xmmh, ufp1, size=8, ext=0
};
def macroop PSRLQ_XMM_I {
msrli xmml, xmml, imm, size=8, ext=0
msrli xmmh, xmmh, imm, size=8, ext=0
};
def macroop PSRLDQ_XMM_I {
limm t2, 8
subi t1, t2, imm, flags=(ECF,), dataSize=1
br label("psrldq_less_8"), flags=(nCECF,)
# Greater than 8
limm t2, 16
subi t1, t2, imm, flags=(ECF,), dataSize=1
br label("psrldq_less_16"), flags=(nCECF,)
# Greater than 16
lfpimm xmml, 0
lfpimm xmmh, 0
br label("psrldq_end")
psrldq_less_16:
# Between 8 and 16
msrli xmml, xmmh, "(IMMEDIATE-8)<<3", size=8, ext=0
lfpimm xmmh, 0
br label("psrldq_end")
psrldq_less_8:
# Less than 8
mslli ufp1, xmmh, "(8-IMMEDIATE) << 3", size=8, ext=0
msrli xmml, xmml, "IMMEDIATE << 3", size=8, ext=0
msrli xmmh, xmmh, "IMMEDIATE << 3", size=8, ext=0
mor xmml, xmml, ufp1
psrldq_end:
fault "NoFault"
};
'''
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
10219,
710,
27849,
13,
29471,
15290,
15878,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
710,
4190,
5084,
16879,
1454,
370,
4248,
315,
314,
2032,
436,
10989,
199,
3,
440,
506,
950,
431,
68,
465,
16085,
316,
282,
4190,
370,
1263,
1163,
27925,
1264,
1061,
199,
3,
3324,
5893,
1325,
440,
13988,
370,
27925,
1264,
1061,
3324,
4668,
1958,
199,
3,
370,
282,
14991,
4514,
402,
314,
9330,
402,
314,
2032,
199,
3,
18233,
2348,
7138,
14,
221,
2047,
1443,
675,
314,
2032,
5420,
370,
314,
4190,
199,
3,
2895,
5084,
2741,
626,
1265,
4868,
626,
642,
4245,
365,
32436,
199,
3,
24214,
436,
315,
2399,
8039,
369,
315,
1006,
10208,
402,
314,
2032,
12,
199,
3,
6042,
503,
24214,
12,
315,
1350,
1233,
503,
315,
3366,
1824,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
598,
7570,
30593,
199,
199,
6453,
600,
275,
1449,
199,
318,
21308,
30382,
2431,
55,
63,
19439,
63,
19439,
469,
272,
6605,
4308,
18286,
72,
12,
18286,
72,
12,
18286,
14344,
12,
1568,
29,
18,
12,
1599,
29,
16,
272,
6605,
4308,
18286,
76,
12,
18286,
76,
12,
18286,
14344,
12,
1568,
29,
18,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
55,
63,
19439,
63,
45,
469,
272,
15930,
80,
26337,
17,
12,
8812,
12,
20417,
12,
9628,
12,
18252,
29,
24,
272,
6605,
4308,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
18,
12,
1599,
29,
16,
272,
6605,
4308,
18286,
72,
12,
18286,
72,
12,
26337,
17,
12,
1568,
29,
18,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
55,
63,
19439,
63,
48,
469,
272,
519,
21846,
307,
23,
272,
15930,
80,
26337,
17,
12,
8812,
12,
8012,
30788,
12,
9628,
12,
18252,
29,
24,
272,
6605,
4308,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
18,
12,
1599,
29,
16,
272,
6605,
4308,
18286,
72,
12,
18286,
72,
12,
26337,
17,
12,
1568,
29,
18,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
55,
63,
19439,
63,
41,
469,
272,
333,
5474,
317,
18286,
76,
12,
18286,
76,
12,
25531,
12,
1568,
29,
18,
12,
1599,
29,
16,
272,
333,
5474,
317,
18286,
72,
12,
18286,
72,
12,
25531,
12,
1568,
29,
18,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
36,
63,
19439,
63,
19439,
469,
272,
6605,
4308,
18286,
72,
12,
18286,
72,
12,
18286,
14344,
12,
1568,
29,
20,
12,
1599,
29,
16,
272,
6605,
4308,
18286,
76,
12,
18286,
76,
12,
18286,
14344,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
36,
63,
19439,
63,
45,
469,
272,
15930,
80,
26337,
17,
12,
8812,
12,
20417,
12,
9628,
12,
18252,
29,
24,
272,
6605,
4308,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
20,
12,
1599,
29,
16,
272,
6605,
4308,
18286,
72,
12,
18286,
72,
12,
26337,
17,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
36,
63,
19439,
63,
48,
469,
272,
519,
21846,
307,
23,
272,
15930,
80,
26337,
17,
12,
8812,
12,
8012,
30788,
12,
9628,
12,
18252,
29,
24,
272,
6605,
4308,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
20,
12,
1599,
29,
16,
272,
6605,
4308,
18286,
72,
12,
18286,
72,
12,
26337,
17,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
36,
63,
19439,
63,
41,
469,
272,
333,
5474,
317,
18286,
76,
12,
18286,
76,
12,
25531,
12,
1568,
29,
20,
12,
1599,
29,
16,
272,
333,
5474,
317,
18286,
72,
12,
18286,
72,
12,
25531,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
49,
63,
19439,
63,
19439,
469,
272,
6605,
4308,
18286,
72,
12,
18286,
72,
12,
18286,
14344,
12,
1568,
29,
24,
12,
1599,
29,
16,
272,
6605,
4308,
18286,
76,
12,
18286,
76,
12,
18286,
14344,
12,
1568,
29,
24,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
49,
63,
19439,
63,
45,
469,
272,
15930,
80,
26337,
17,
12,
8812,
12,
20417,
12,
9628,
12,
18252,
29,
24,
272,
6605,
4308,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12
] |
[
1898,
334,
67,
9,
10219,
710,
27849,
13,
29471,
15290,
15878,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
710,
4190,
5084,
16879,
1454,
370,
4248,
315,
314,
2032,
436,
10989,
199,
3,
440,
506,
950,
431,
68,
465,
16085,
316,
282,
4190,
370,
1263,
1163,
27925,
1264,
1061,
199,
3,
3324,
5893,
1325,
440,
13988,
370,
27925,
1264,
1061,
3324,
4668,
1958,
199,
3,
370,
282,
14991,
4514,
402,
314,
9330,
402,
314,
2032,
199,
3,
18233,
2348,
7138,
14,
221,
2047,
1443,
675,
314,
2032,
5420,
370,
314,
4190,
199,
3,
2895,
5084,
2741,
626,
1265,
4868,
626,
642,
4245,
365,
32436,
199,
3,
24214,
436,
315,
2399,
8039,
369,
315,
1006,
10208,
402,
314,
2032,
12,
199,
3,
6042,
503,
24214,
12,
315,
1350,
1233,
503,
315,
3366,
1824,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
598,
7570,
30593,
199,
199,
6453,
600,
275,
1449,
199,
318,
21308,
30382,
2431,
55,
63,
19439,
63,
19439,
469,
272,
6605,
4308,
18286,
72,
12,
18286,
72,
12,
18286,
14344,
12,
1568,
29,
18,
12,
1599,
29,
16,
272,
6605,
4308,
18286,
76,
12,
18286,
76,
12,
18286,
14344,
12,
1568,
29,
18,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
55,
63,
19439,
63,
45,
469,
272,
15930,
80,
26337,
17,
12,
8812,
12,
20417,
12,
9628,
12,
18252,
29,
24,
272,
6605,
4308,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
18,
12,
1599,
29,
16,
272,
6605,
4308,
18286,
72,
12,
18286,
72,
12,
26337,
17,
12,
1568,
29,
18,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
55,
63,
19439,
63,
48,
469,
272,
519,
21846,
307,
23,
272,
15930,
80,
26337,
17,
12,
8812,
12,
8012,
30788,
12,
9628,
12,
18252,
29,
24,
272,
6605,
4308,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
18,
12,
1599,
29,
16,
272,
6605,
4308,
18286,
72,
12,
18286,
72,
12,
26337,
17,
12,
1568,
29,
18,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
55,
63,
19439,
63,
41,
469,
272,
333,
5474,
317,
18286,
76,
12,
18286,
76,
12,
25531,
12,
1568,
29,
18,
12,
1599,
29,
16,
272,
333,
5474,
317,
18286,
72,
12,
18286,
72,
12,
25531,
12,
1568,
29,
18,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
36,
63,
19439,
63,
19439,
469,
272,
6605,
4308,
18286,
72,
12,
18286,
72,
12,
18286,
14344,
12,
1568,
29,
20,
12,
1599,
29,
16,
272,
6605,
4308,
18286,
76,
12,
18286,
76,
12,
18286,
14344,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
36,
63,
19439,
63,
45,
469,
272,
15930,
80,
26337,
17,
12,
8812,
12,
20417,
12,
9628,
12,
18252,
29,
24,
272,
6605,
4308,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
20,
12,
1599,
29,
16,
272,
6605,
4308,
18286,
72,
12,
18286,
72,
12,
26337,
17,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
36,
63,
19439,
63,
48,
469,
272,
519,
21846,
307,
23,
272,
15930,
80,
26337,
17,
12,
8812,
12,
8012,
30788,
12,
9628,
12,
18252,
29,
24,
272,
6605,
4308,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
20,
12,
1599,
29,
16,
272,
6605,
4308,
18286,
72,
12,
18286,
72,
12,
26337,
17,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
36,
63,
19439,
63,
41,
469,
272,
333,
5474,
317,
18286,
76,
12,
18286,
76,
12,
25531,
12,
1568,
29,
20,
12,
1599,
29,
16,
272,
333,
5474,
317,
18286,
72,
12,
18286,
72,
12,
25531,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
49,
63,
19439,
63,
19439,
469,
272,
6605,
4308,
18286,
72,
12,
18286,
72,
12,
18286,
14344,
12,
1568,
29,
24,
12,
1599,
29,
16,
272,
6605,
4308,
18286,
76,
12,
18286,
76,
12,
18286,
14344,
12,
1568,
29,
24,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
30382,
2431,
49,
63,
19439,
63,
45,
469,
272,
15930,
80,
26337,
17,
12,
8812,
12,
20417,
12,
9628,
12,
18252,
29,
24,
272,
6605,
4308,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
evaschalde/odoo
|
addons/stock_landed_costs/__openerp__.py
|
220
|
1914
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'WMS Landed Costs',
'version': '1.1',
'author': 'OpenERP SA',
'summary': 'Landed Costs',
'description': """
Landed Costs Management
=======================
This module allows you to easily add extra costs on pickings and decide the split of these costs among their stock moves in order to take them into account in your stock valuation.
""",
'website': 'https://www.odoo.com/page/warehouse',
'depends': ['stock_account'],
'category': 'Warehouse Management',
'sequence': 16,
'demo': [
],
'data': [
'security/ir.model.access.csv',
'stock_landed_costs_sequence.xml',
'product_view.xml',
'stock_landed_costs_view.xml',
'stock_landed_costs_data.xml',
],
'test': [
'test/stock_landed_costs.yml'
],
'installable': True,
'auto_install': False,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
91,
272,
283,
354,
356,
283,
55,
3053,
491,
7028,
24681,
83,
297,
272,
283,
1023,
356,
283,
17,
14,
17,
297,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
4705,
356,
283,
44,
7028,
24681,
83,
297,
272,
283,
1802,
356,
408,
199,
44,
7028,
24681,
83,
8259,
199,
1280,
18673,
199,
2765,
859,
6127,
1265,
370,
16174,
1050,
2402,
26819,
641,
3732,
780,
436,
19822,
314,
3715,
402,
3520,
26819,
16885,
3932,
10952,
14569,
315,
1865,
370,
5452,
3062,
1901,
2933,
315,
2195,
10952,
1139,
4086,
14,
272,
10327,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
15,
1606,
15,
12806,
297,
272,
283,
8912,
356,
788,
6088,
63,
2048,
995,
272,
283,
3710,
356,
283,
55,
11499,
8259,
297,
272,
283,
4041,
356,
3193,
12,
272,
283,
8768,
356,
359,
272,
2156,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
6088,
63,
1502,
770,
63,
25432,
63,
4041,
14,
1652,
297,
267,
283,
2558,
63,
1345,
14,
1652,
297,
267,
283,
6088,
63,
1502,
770,
63,
25432,
63,
1345,
14,
1652,
297,
267,
283,
6088,
63,
1502,
770,
63,
25432,
63,
576,
14,
1652,
297,
272,
2156,
272,
283,
396,
356,
359,
267,
283,
396,
15,
6088,
63,
1502,
770,
63,
25432,
14,
11714,
7,
272,
2156,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
91,
272,
283,
354,
356,
283,
55,
3053,
491,
7028,
24681,
83,
297,
272,
283,
1023,
356,
283,
17,
14,
17,
297,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
4705,
356,
283,
44,
7028,
24681,
83,
297,
272,
283,
1802,
356,
408,
199,
44,
7028,
24681,
83,
8259,
199,
1280,
18673,
199,
2765,
859,
6127,
1265,
370,
16174,
1050,
2402,
26819,
641,
3732,
780,
436,
19822,
314,
3715,
402,
3520,
26819,
16885,
3932,
10952,
14569,
315,
1865,
370,
5452,
3062,
1901,
2933,
315,
2195,
10952,
1139,
4086,
14,
272,
10327,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
15,
1606,
15,
12806,
297,
272,
283,
8912,
356,
788,
6088,
63,
2048,
995,
272,
283,
3710,
356,
283,
55,
11499,
8259,
297,
272,
283,
4041,
356,
3193,
12,
272,
283,
8768,
356,
359,
272,
2156,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
6088,
63,
1502,
770,
63,
25432,
63,
4041,
14,
1652,
297,
267,
283,
2558,
63,
1345,
14,
1652,
297,
267,
283,
6088,
63,
1502,
770,
63,
25432,
63,
1345,
14,
1652,
297,
267,
283,
6088,
63,
1502,
770,
63,
25432,
63,
576,
14,
1652,
297,
272,
2156,
272,
283,
396,
356,
359,
267,
283,
396,
15,
6088,
63,
1502,
770,
63,
25432,
14,
11714,
7,
272,
2156,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mlsecproject/gglsbl-rest
|
config.py
|
1
|
1443
|
from os import environ
import logging.config
from apscheduler.schedulers.background import BackgroundScheduler
from multiprocessing import cpu_count
from subprocess import Popen
logging.config.fileConfig('logging.conf')
bind = "0.0.0.0:5000"
workers = int(environ.get('WORKERS', cpu_count() * 8 + 1))
timeout = int(environ.get('TIMEOUT', 120))
access_log_format = '%(h)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" "%({X-Forwarded-For}i)s" "%({X-Forwarded-Port}i)s" "%({X-Forwarded-Proto}i)s" "%({X-Amzn-Trace-Id}i)s"'
max_requests = int(environ.get('MAX_REQUESTS', 16384))
limit_request_line = int(environ.get('LIMIT_REQUEST_LINE', 8190))
keepalive = int(environ.get('KEEPALIVE', 60))
log = logging.getLogger(__name__)
def update():
log.info("Starting update process...")
po = Popen("python3 update.py", shell=True)
log.info("Update started as PID %d", po.pid)
rc = po.wait()
log.info("Update process finished with status code %d", rc)
sched = None
def on_starting(server):
log.info("Initial database load...")
po = Popen("python3 update.py", shell=True)
log.info("Update started as PID %d", po.pid)
rc = po.wait()
log.info("Update process finished with status code %d", rc)
log.info("Starting scheduler...")
global sched
sched = BackgroundScheduler(timezone="UTC")
sched.start()
sched.add_job(update, id="update", coalesce=True, max_instances=1, trigger='interval', minutes=30)
|
apache-2.0
|
[
504,
747,
492,
6160,
199,
199,
646,
2050,
14,
888,
199,
504,
282,
1190,
5085,
14,
7211,
2393,
14,
7451,
492,
10257,
3928,
11251,
199,
504,
12866,
492,
5033,
63,
835,
199,
504,
3873,
492,
13995,
199,
199,
4806,
14,
888,
14,
493,
2028,
360,
4806,
14,
2190,
358,
199,
199,
3409,
275,
298,
16,
14,
16,
14,
16,
14,
16,
26,
13128,
2,
199,
11009,
275,
1109,
8,
2314,
14,
362,
360,
8406,
3960,
297,
5033,
63,
835,
342,
627,
1695,
435,
413,
430,
199,
2593,
275,
1109,
8,
2314,
14,
362,
360,
8899,
297,
13960,
430,
199,
2732,
63,
793,
63,
908,
275,
9487,
72,
9,
83,
11792,
82,
9,
83,
2,
2818,
83,
9,
83,
2818,
66,
9,
83,
11792,
70,
9,
83,
2,
11792,
65,
9,
83,
2,
2071,
2561,
56,
13,
1858,
15295,
13,
1858,
93,
73,
9,
83,
2,
2071,
2561,
56,
13,
1858,
15295,
13,
4313,
93,
73,
9,
83,
2,
2071,
2561,
56,
13,
1858,
15295,
13,
8548,
93,
73,
9,
83,
2,
221,
2071,
2561,
56,
13,
24566,
31591,
13,
3921,
13,
1304,
93,
73,
9,
83,
4507,
199,
988,
63,
6615,
275,
1109,
8,
2314,
14,
362,
360,
4283,
63,
6780,
51,
297,
24619,
1349,
430,
199,
3097,
63,
1069,
63,
604,
275,
1109,
8,
2314,
14,
362,
360,
13387,
63,
6780,
63,
6174,
297,
1695,
12205,
430,
199,
28227,
275,
1109,
8,
2314,
14,
362,
360,
32162,
748,
5399,
297,
5212,
430,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
1678,
837,
272,
943,
14,
815,
480,
14139,
1678,
2112,
12594,
272,
1115,
275,
13995,
480,
1548,
19,
1678,
14,
647,
401,
5218,
29,
549,
9,
272,
943,
14,
815,
480,
4152,
8239,
465,
20674,
450,
68,
401,
1115,
14,
3150,
9,
272,
4819,
275,
1115,
14,
2573,
342,
272,
943,
14,
815,
480,
4152,
2112,
9158,
543,
2004,
1233,
450,
68,
401,
4819,
9,
421,
199,
10487,
275,
488,
199,
199,
318,
641,
63,
15769,
8,
1000,
304,
272,
943,
14,
815,
480,
5733,
3050,
2248,
12594,
272,
1115,
275,
13995,
480,
1548,
19,
1678,
14,
647,
401,
5218,
29,
549,
9,
272,
943,
14,
815,
480,
4152,
8239,
465,
20674,
450,
68,
401,
1115,
14,
3150,
9,
272,
4819,
275,
1115,
14,
2573,
342,
272,
943,
14,
815,
480,
4152,
2112,
9158,
543,
2004,
1233,
450,
68,
401,
4819,
9,
339,
943,
14,
815,
480,
14139,
11899,
12594,
272,
2288,
10286,
272,
10286,
275,
10257,
3928,
11251,
8,
7145,
628,
11288,
531,
272,
10286,
14,
928,
342,
272,
10286,
14,
525,
63,
2423,
8,
873,
12,
1305,
628,
873,
401,
512,
29944,
29,
549,
12,
1390,
63,
5990,
29,
17,
12,
6804,
534,
4284,
297,
9395,
29,
1216,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
492,
6160,
199,
199,
646,
2050,
14,
888,
199,
504,
282,
1190,
5085,
14,
7211,
2393,
14,
7451,
492,
10257,
3928,
11251,
199,
504,
12866,
492,
5033,
63,
835,
199,
504,
3873,
492,
13995,
199,
199,
4806,
14,
888,
14,
493,
2028,
360,
4806,
14,
2190,
358,
199,
199,
3409,
275,
298,
16,
14,
16,
14,
16,
14,
16,
26,
13128,
2,
199,
11009,
275,
1109,
8,
2314,
14,
362,
360,
8406,
3960,
297,
5033,
63,
835,
342,
627,
1695,
435,
413,
430,
199,
2593,
275,
1109,
8,
2314,
14,
362,
360,
8899,
297,
13960,
430,
199,
2732,
63,
793,
63,
908,
275,
9487,
72,
9,
83,
11792,
82,
9,
83,
2,
2818,
83,
9,
83,
2818,
66,
9,
83,
11792,
70,
9,
83,
2,
11792,
65,
9,
83,
2,
2071,
2561,
56,
13,
1858,
15295,
13,
1858,
93,
73,
9,
83,
2,
2071,
2561,
56,
13,
1858,
15295,
13,
4313,
93,
73,
9,
83,
2,
2071,
2561,
56,
13,
1858,
15295,
13,
8548,
93,
73,
9,
83,
2,
221,
2071,
2561,
56,
13,
24566,
31591,
13,
3921,
13,
1304,
93,
73,
9,
83,
4507,
199,
988,
63,
6615,
275,
1109,
8,
2314,
14,
362,
360,
4283,
63,
6780,
51,
297,
24619,
1349,
430,
199,
3097,
63,
1069,
63,
604,
275,
1109,
8,
2314,
14,
362,
360,
13387,
63,
6780,
63,
6174,
297,
1695,
12205,
430,
199,
28227,
275,
1109,
8,
2314,
14,
362,
360,
32162,
748,
5399,
297,
5212,
430,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
1678,
837,
272,
943,
14,
815,
480,
14139,
1678,
2112,
12594,
272,
1115,
275,
13995,
480,
1548,
19,
1678,
14,
647,
401,
5218,
29,
549,
9,
272,
943,
14,
815,
480,
4152,
8239,
465,
20674,
450,
68,
401,
1115,
14,
3150,
9,
272,
4819,
275,
1115,
14,
2573,
342,
272,
943,
14,
815,
480,
4152,
2112,
9158,
543,
2004,
1233,
450,
68,
401,
4819,
9,
421,
199,
10487,
275,
488,
199,
199,
318,
641,
63,
15769,
8,
1000,
304,
272,
943,
14,
815,
480,
5733,
3050,
2248,
12594,
272,
1115,
275,
13995,
480,
1548,
19,
1678,
14,
647,
401,
5218,
29,
549,
9,
272,
943,
14,
815,
480,
4152,
8239,
465,
20674,
450,
68,
401,
1115,
14,
3150,
9,
272,
4819,
275,
1115,
14,
2573,
342,
272,
943,
14,
815,
480,
4152,
2112,
9158,
543,
2004,
1233,
450,
68,
401,
4819,
9,
339,
943,
14,
815,
480,
14139,
11899,
12594,
272,
2288,
10286,
272,
10286,
275,
10257,
3928,
11251,
8,
7145,
628,
11288,
531,
272,
10286,
14,
928,
342,
272,
10286,
14,
525,
63,
2423,
8,
873,
12,
1305,
628,
873,
401,
512,
29944,
29,
549,
12,
1390,
63,
5990,
29,
17,
12,
6804,
534,
4284,
297,
9395,
29,
1216,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
lumig242/Hue-Integration-with-CDAP
|
desktop/core/ext-py/Django-1.6.10/django/contrib/auth/tests/test_models.py
|
104
|
6290
|
import warnings
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import (Group, User, SiteProfileNotAvailable,
UserManager)
from django.contrib.auth.tests.custom_user import IsActiveTestUser1
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.db.models.signals import post_save
from django.test import TestCase
from django.test.utils import override_settings
from django.utils import six
@skipIfCustomUser
@override_settings(USE_TZ=False, AUTH_PROFILE_MODULE='')
class ProfileTestCase(TestCase):
def test_site_profile_not_available(self):
user = User.objects.create(username='testclient')
# calling get_profile without AUTH_PROFILE_MODULE set
del settings.AUTH_PROFILE_MODULE
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
with six.assertRaisesRegex(self, SiteProfileNotAvailable,
"You need to set AUTH_PROFILE_MODULE in your project"):
user.get_profile()
# Bad syntax in AUTH_PROFILE_MODULE:
settings.AUTH_PROFILE_MODULE = 'foobar'
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
with six.assertRaisesRegex(self, SiteProfileNotAvailable,
"app_label and model_name should be separated by a dot"):
user.get_profile()
# module that doesn't exist
settings.AUTH_PROFILE_MODULE = 'foo.bar'
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
with six.assertRaisesRegex(self, SiteProfileNotAvailable,
"Unable to load the profile model"):
user.get_profile()
@skipIfCustomUser
@override_settings(USE_TZ=False)
class NaturalKeysTestCase(TestCase):
fixtures = ['authtestdata.json']
def test_user_natural_key(self):
staff_user = User.objects.get(username='staff')
self.assertEqual(User.objects.get_by_natural_key('staff'), staff_user)
self.assertEqual(staff_user.natural_key(), ('staff',))
def test_group_natural_key(self):
users_group = Group.objects.create(name='users')
self.assertEqual(Group.objects.get_by_natural_key('users'), users_group)
@skipIfCustomUser
@override_settings(USE_TZ=False)
class LoadDataWithoutNaturalKeysTestCase(TestCase):
fixtures = ['regular.json']
def test_user_is_created_and_added_to_group(self):
user = User.objects.get(username='my_username')
group = Group.objects.get(name='my_group')
self.assertEqual(group, user.groups.get())
@skipIfCustomUser
@override_settings(USE_TZ=False)
class LoadDataWithNaturalKeysTestCase(TestCase):
fixtures = ['natural.json']
def test_user_is_created_and_added_to_group(self):
user = User.objects.get(username='my_username')
group = Group.objects.get(name='my_group')
self.assertEqual(group, user.groups.get())
@skipIfCustomUser
class UserManagerTestCase(TestCase):
def test_create_user(self):
email_lowercase = 'normal@normal.com'
user = User.objects.create_user('user', email_lowercase)
self.assertEqual(user.email, email_lowercase)
self.assertEqual(user.username, 'user')
self.assertFalse(user.has_usable_password())
def test_create_user_email_domain_normalize_rfc3696(self):
# According to http://tools.ietf.org/html/rfc3696#section-3
# the "@" symbol can be part of the local part of an email address
returned = UserManager.normalize_email(r'Abc\@DEF@EXAMPLE.com')
self.assertEqual(returned, r'Abc\@DEF@example.com')
def test_create_user_email_domain_normalize(self):
returned = UserManager.normalize_email('normal@DOMAIN.COM')
self.assertEqual(returned, 'normal@domain.com')
def test_create_user_email_domain_normalize_with_whitespace(self):
returned = UserManager.normalize_email('email\ with_whitespace@D.COM')
self.assertEqual(returned, 'email\ with_whitespace@d.com')
def test_empty_username(self):
self.assertRaisesMessage(ValueError,
'The given username must be set',
User.objects.create_user, username='')
class IsActiveTestCase(TestCase):
"""
Tests the behavior of the guaranteed is_active attribute
"""
@skipIfCustomUser
def test_builtin_user_isactive(self):
user = User.objects.create(username='foo', email='foo@bar.com')
# is_active is true by default
self.assertEqual(user.is_active, True)
user.is_active = False
user.save()
user_fetched = User.objects.get(pk=user.pk)
# the is_active flag is saved
self.assertFalse(user_fetched.is_active)
@override_settings(AUTH_USER_MODEL='auth.IsActiveTestUser1')
def test_is_active_field_default(self):
"""
tests that the default value for is_active is provided
"""
UserModel = get_user_model()
user = UserModel(username='foo')
self.assertEqual(user.is_active, True)
# you can set the attribute - but it will not save
user.is_active = False
# there should be no problem saving - but the attribute is not saved
user.save()
user_fetched = UserModel._default_manager.get(pk=user.pk)
# the attribute is always true for newly retrieved instance
self.assertEqual(user_fetched.is_active, True)
@skipIfCustomUser
class TestCreateSuperUserSignals(TestCase):
"""
Simple test case for ticket #20541
"""
def post_save_listener(self, *args, **kwargs):
self.signals_count += 1
def setUp(self):
self.signals_count = 0
post_save.connect(self.post_save_listener, sender=User)
def tearDown(self):
post_save.disconnect(self.post_save_listener, sender=User)
def test_create_user(self):
User.objects.create_user("JohnDoe")
self.assertEqual(self.signals_count, 1)
def test_create_superuser(self):
User.objects.create_superuser("JohnDoe", "mail@example.com", "1")
self.assertEqual(self.signals_count, 1)
|
apache-2.0
|
[
646,
3598,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
492,
664,
63,
751,
63,
1238,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
334,
2448,
12,
2876,
12,
11666,
5736,
1763,
11464,
12,
272,
2876,
2988,
9,
199,
504,
1639,
14,
2828,
14,
1178,
14,
2219,
14,
4229,
63,
751,
492,
6596,
7472,
774,
1899,
17,
199,
504,
1639,
14,
2828,
14,
1178,
14,
2219,
14,
1208,
492,
3372,
3917,
31482,
199,
504,
1639,
14,
697,
14,
992,
14,
10458,
492,
2963,
63,
2117,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
504,
1639,
14,
1208,
492,
3816,
421,
199,
32,
15118,
31482,
199,
32,
4415,
63,
1751,
8,
4701,
63,
14226,
29,
797,
12,
7560,
63,
16632,
63,
10001,
13275,
199,
533,
14386,
1746,
8,
1746,
304,
339,
347,
511,
63,
2124,
63,
2913,
63,
1397,
63,
4561,
8,
277,
304,
267,
922,
275,
2876,
14,
1462,
14,
981,
8,
2473,
534,
396,
1258,
358,
398,
327,
6358,
664,
63,
2913,
1928,
7560,
63,
16632,
63,
10001,
663,
267,
2150,
2202,
14,
5580,
63,
16632,
63,
10001,
267,
543,
3598,
14,
9341,
63,
5451,
837,
288,
3598,
14,
18815,
480,
4247,
401,
13413,
9,
288,
543,
3816,
14,
16499,
8,
277,
12,
11666,
5736,
1763,
11464,
12,
490,
298,
5556,
1929,
370,
663,
7560,
63,
16632,
63,
10001,
315,
2195,
2199,
2349,
355,
922,
14,
362,
63,
2913,
342,
398,
327,
8857,
6302,
315,
7560,
63,
16632,
63,
10001,
26,
267,
2202,
14,
5580,
63,
16632,
63,
10001,
275,
283,
9664,
7,
267,
543,
3598,
14,
9341,
63,
5451,
837,
288,
3598,
14,
18815,
480,
4247,
401,
13413,
9,
288,
543,
3816,
14,
16499,
8,
277,
12,
11666,
5736,
1763,
11464,
12,
490,
298,
571,
63,
1302,
436,
1402,
63,
354,
1077,
506,
11673,
701,
282,
6308,
2349,
355,
922,
14,
362,
63,
2913,
342,
398,
327,
859,
626,
3181,
1133,
2187,
267,
2202,
14,
5580,
63,
16632,
63,
10001,
275,
283,
1421,
14,
1700,
7,
267,
543,
3598,
14,
9341,
63,
5451,
837,
288,
3598,
14,
18815,
480,
4247,
401,
13413,
9,
288,
543,
3816,
14,
16499,
8,
277,
12,
11666,
5736,
1763,
11464,
12,
490,
298,
6005,
370,
2248,
314,
4690,
1402,
2349,
355,
922,
14,
362,
63,
2913,
342,
421,
199,
32,
15118,
31482,
199,
32,
4415,
63,
1751,
8,
4701,
63,
14226,
29,
797,
9,
199,
533,
653,
292,
4889,
6340,
1746,
8,
1746,
304,
272,
15188,
275,
788,
1178,
18481,
14,
1001,
418,
339,
347,
511,
63,
751,
63,
15759,
63,
498,
8,
277,
304,
267,
12622,
63,
751,
275,
2876,
14,
1462,
14,
362,
8,
2473,
534,
7018,
358,
267,
291,
14,
629,
8,
1899,
14,
1462,
14,
362,
63,
991,
63,
15759,
63,
498,
360,
7018,
659,
12622,
63,
751,
9,
267,
291,
14,
629,
8,
7018,
63,
751,
14,
15759,
63,
498,
1062,
661,
7018,
16829,
339,
347,
511,
63,
923,
63,
15759,
63,
498,
8,
277,
304,
267,
4390,
63,
923,
275,
5611,
14,
1462,
14,
981,
8,
354,
534,
3707,
358,
267,
291,
14,
629,
8,
2448,
14,
1462,
14,
362,
63,
991,
63,
15759,
63,
498,
360,
3707,
659,
4390,
63,
923,
9,
421,
199,
32,
15118,
31482,
199,
32,
4415,
63,
1751,
8,
4701,
63,
14226,
29,
797,
9,
199,
533,
7190,
1451,
12450,
23604,
4889,
6340,
1746,
8,
1746,
304,
272,
15188,
275,
788,
7898,
14,
1001,
418,
339,
347,
511,
63,
751,
63,
374,
63,
3966,
63,
460,
63,
3270,
63,
475,
63,
923,
8,
277,
304,
267,
922,
275,
2876,
14,
1462,
14,
362,
8,
2473,
534,
1662,
63,
2473,
358,
267,
1572,
275,
5611,
14,
1462,
14,
362,
8,
354,
534,
1662,
63,
923,
358,
267,
291,
14,
629,
8,
923,
12,
922,
14,
2634,
14,
362,
1012,
421,
199,
32,
15118,
31482,
199,
32,
4415,
63,
1751,
8,
4701,
63,
14226,
29,
797,
9,
199,
533,
7190,
1451,
3007,
23604,
4889,
6340,
1746,
8,
1746,
304,
272,
15188,
275,
788,
15759,
14,
1001,
418,
339,
347,
511,
63,
751,
63,
374,
63,
3966,
63,
460,
63,
3270,
63,
475,
63,
923,
8,
277,
304,
267,
922,
275,
2876,
14,
1462,
14,
362,
8,
2473,
534,
1662,
63,
2473,
358,
267,
1572,
275,
5611,
14,
1462,
14,
362,
8,
354,
534,
1662,
63,
923,
358,
267,
291,
14,
629,
8,
923,
12,
922,
14,
2634,
14,
362,
1012,
421,
199,
32,
15118,
31482,
199,
533,
2876,
2988,
1746,
8,
1746,
304,
339,
347,
511,
63,
981,
63,
751,
8,
277,
304,
267,
3031,
63,
21636,
275,
283,
3302,
32,
3302,
14,
957,
7,
267,
922,
275,
2876,
14,
1462,
14,
981,
63,
751,
360,
751,
297,
3031,
63,
21636,
9,
267,
291,
14,
629,
8,
751,
14,
2123,
12,
3031,
63,
21636,
9,
267,
291,
14,
629,
8,
751,
14,
2473,
12,
283,
751,
358,
267,
291,
14,
3334,
8,
751,
14,
1989,
63,
14418,
63,
2060,
1012,
339,
347,
511,
63,
981,
63,
751,
63,
2123,
63,
2261,
63,
7721,
63,
8973,
1344,
2534,
8,
277,
304,
267,
327,
31970,
370,
221,
1455,
921,
2537,
14,
15799,
14,
1308,
15,
1360,
15,
8973,
1344,
2534,
3,
2792,
13,
19,
267,
327,
314,
9244,
2,
5272,
883,
506,
1777,
402,
314,
2257,
1777,
402,
376,
3031,
2287,
267,
2138,
275,
2876,
2988,
14,
7721,
63,
2123,
8,
82,
7,
30293,
60,
32,
5638,
32,
26900,
14,
957,
358,
267,
291,
14,
629,
8,
19065,
12,
519,
7,
30293,
60,
32,
5638,
32,
2694,
14,
957,
358,
339,
347,
511,
63,
981,
63,
751,
63,
2123,
63,
2261,
63,
7721,
8,
277,
304,
267,
2138,
275,
2876,
2988,
14,
7721,
63,
2123,
360,
3302,
32,
7378,
14,
11265,
358,
267,
291,
14,
629,
8,
19065,
12,
283,
3302,
32,
2261,
14,
957,
358,
339,
347,
511,
63,
981,
63,
751,
63,
2123,
63,
2261,
63,
7721,
63,
1045,
63,
8506,
8,
277,
304,
267,
2138,
275,
2876,
2988,
14,
7721,
63,
2123,
360,
2123,
60,
543,
63,
8506,
32,
36,
14,
11265,
358,
267,
291,
14,
629
] |
[
3598,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
492,
664,
63,
751,
63,
1238,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
334,
2448,
12,
2876,
12,
11666,
5736,
1763,
11464,
12,
272,
2876,
2988,
9,
199,
504,
1639,
14,
2828,
14,
1178,
14,
2219,
14,
4229,
63,
751,
492,
6596,
7472,
774,
1899,
17,
199,
504,
1639,
14,
2828,
14,
1178,
14,
2219,
14,
1208,
492,
3372,
3917,
31482,
199,
504,
1639,
14,
697,
14,
992,
14,
10458,
492,
2963,
63,
2117,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
504,
1639,
14,
1208,
492,
3816,
421,
199,
32,
15118,
31482,
199,
32,
4415,
63,
1751,
8,
4701,
63,
14226,
29,
797,
12,
7560,
63,
16632,
63,
10001,
13275,
199,
533,
14386,
1746,
8,
1746,
304,
339,
347,
511,
63,
2124,
63,
2913,
63,
1397,
63,
4561,
8,
277,
304,
267,
922,
275,
2876,
14,
1462,
14,
981,
8,
2473,
534,
396,
1258,
358,
398,
327,
6358,
664,
63,
2913,
1928,
7560,
63,
16632,
63,
10001,
663,
267,
2150,
2202,
14,
5580,
63,
16632,
63,
10001,
267,
543,
3598,
14,
9341,
63,
5451,
837,
288,
3598,
14,
18815,
480,
4247,
401,
13413,
9,
288,
543,
3816,
14,
16499,
8,
277,
12,
11666,
5736,
1763,
11464,
12,
490,
298,
5556,
1929,
370,
663,
7560,
63,
16632,
63,
10001,
315,
2195,
2199,
2349,
355,
922,
14,
362,
63,
2913,
342,
398,
327,
8857,
6302,
315,
7560,
63,
16632,
63,
10001,
26,
267,
2202,
14,
5580,
63,
16632,
63,
10001,
275,
283,
9664,
7,
267,
543,
3598,
14,
9341,
63,
5451,
837,
288,
3598,
14,
18815,
480,
4247,
401,
13413,
9,
288,
543,
3816,
14,
16499,
8,
277,
12,
11666,
5736,
1763,
11464,
12,
490,
298,
571,
63,
1302,
436,
1402,
63,
354,
1077,
506,
11673,
701,
282,
6308,
2349,
355,
922,
14,
362,
63,
2913,
342,
398,
327,
859,
626,
3181,
1133,
2187,
267,
2202,
14,
5580,
63,
16632,
63,
10001,
275,
283,
1421,
14,
1700,
7,
267,
543,
3598,
14,
9341,
63,
5451,
837,
288,
3598,
14,
18815,
480,
4247,
401,
13413,
9,
288,
543,
3816,
14,
16499,
8,
277,
12,
11666,
5736,
1763,
11464,
12,
490,
298,
6005,
370,
2248,
314,
4690,
1402,
2349,
355,
922,
14,
362,
63,
2913,
342,
421,
199,
32,
15118,
31482,
199,
32,
4415,
63,
1751,
8,
4701,
63,
14226,
29,
797,
9,
199,
533,
653,
292,
4889,
6340,
1746,
8,
1746,
304,
272,
15188,
275,
788,
1178,
18481,
14,
1001,
418,
339,
347,
511,
63,
751,
63,
15759,
63,
498,
8,
277,
304,
267,
12622,
63,
751,
275,
2876,
14,
1462,
14,
362,
8,
2473,
534,
7018,
358,
267,
291,
14,
629,
8,
1899,
14,
1462,
14,
362,
63,
991,
63,
15759,
63,
498,
360,
7018,
659,
12622,
63,
751,
9,
267,
291,
14,
629,
8,
7018,
63,
751,
14,
15759,
63,
498,
1062,
661,
7018,
16829,
339,
347,
511,
63,
923,
63,
15759,
63,
498,
8,
277,
304,
267,
4390,
63,
923,
275,
5611,
14,
1462,
14,
981,
8,
354,
534,
3707,
358,
267,
291,
14,
629,
8,
2448,
14,
1462,
14,
362,
63,
991,
63,
15759,
63,
498,
360,
3707,
659,
4390,
63,
923,
9,
421,
199,
32,
15118,
31482,
199,
32,
4415,
63,
1751,
8,
4701,
63,
14226,
29,
797,
9,
199,
533,
7190,
1451,
12450,
23604,
4889,
6340,
1746,
8,
1746,
304,
272,
15188,
275,
788,
7898,
14,
1001,
418,
339,
347,
511,
63,
751,
63,
374,
63,
3966,
63,
460,
63,
3270,
63,
475,
63,
923,
8,
277,
304,
267,
922,
275,
2876,
14,
1462,
14,
362,
8,
2473,
534,
1662,
63,
2473,
358,
267,
1572,
275,
5611,
14,
1462,
14,
362,
8,
354,
534,
1662,
63,
923,
358,
267,
291,
14,
629,
8,
923,
12,
922,
14,
2634,
14,
362,
1012,
421,
199,
32,
15118,
31482,
199,
32,
4415,
63,
1751,
8,
4701,
63,
14226,
29,
797,
9,
199,
533,
7190,
1451,
3007,
23604,
4889,
6340,
1746,
8,
1746,
304,
272,
15188,
275,
788,
15759,
14,
1001,
418,
339,
347,
511,
63,
751,
63,
374,
63,
3966,
63,
460,
63,
3270,
63,
475,
63,
923,
8,
277,
304,
267,
922,
275,
2876,
14,
1462,
14,
362,
8,
2473,
534,
1662,
63,
2473,
358,
267,
1572,
275,
5611,
14,
1462,
14,
362,
8,
354,
534,
1662,
63,
923,
358,
267,
291,
14,
629,
8,
923,
12,
922,
14,
2634,
14,
362,
1012,
421,
199,
32,
15118,
31482,
199,
533,
2876,
2988,
1746,
8,
1746,
304,
339,
347,
511,
63,
981,
63,
751,
8,
277,
304,
267,
3031,
63,
21636,
275,
283,
3302,
32,
3302,
14,
957,
7,
267,
922,
275,
2876,
14,
1462,
14,
981,
63,
751,
360,
751,
297,
3031,
63,
21636,
9,
267,
291,
14,
629,
8,
751,
14,
2123,
12,
3031,
63,
21636,
9,
267,
291,
14,
629,
8,
751,
14,
2473,
12,
283,
751,
358,
267,
291,
14,
3334,
8,
751,
14,
1989,
63,
14418,
63,
2060,
1012,
339,
347,
511,
63,
981,
63,
751,
63,
2123,
63,
2261,
63,
7721,
63,
8973,
1344,
2534,
8,
277,
304,
267,
327,
31970,
370,
221,
1455,
921,
2537,
14,
15799,
14,
1308,
15,
1360,
15,
8973,
1344,
2534,
3,
2792,
13,
19,
267,
327,
314,
9244,
2,
5272,
883,
506,
1777,
402,
314,
2257,
1777,
402,
376,
3031,
2287,
267,
2138,
275,
2876,
2988,
14,
7721,
63,
2123,
8,
82,
7,
30293,
60,
32,
5638,
32,
26900,
14,
957,
358,
267,
291,
14,
629,
8,
19065,
12,
519,
7,
30293,
60,
32,
5638,
32,
2694,
14,
957,
358,
339,
347,
511,
63,
981,
63,
751,
63,
2123,
63,
2261,
63,
7721,
8,
277,
304,
267,
2138,
275,
2876,
2988,
14,
7721,
63,
2123,
360,
3302,
32,
7378,
14,
11265,
358,
267,
291,
14,
629,
8,
19065,
12,
283,
3302,
32,
2261,
14,
957,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
estaban/pyload
|
module/plugins/hoster/UnrestrictLi.py
|
1
|
4420
|
# -*- coding: utf-8 -*-
############################################################################
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU Affero General Public License as #
# published by the Free Software Foundation, either version 3 of the #
# License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU Affero General Public License for more details. #
# #
# You should have received a copy of the GNU Affero General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
############################################################################
import re
from datetime import datetime, timedelta
from module.plugins.Hoster import Hoster
from module.common.json_layer import json_loads
def secondsToMidnight(gmt=0):
now = datetime.utcnow() + timedelta(hours=gmt)
if now.hour is 0 and now.minute < 10:
midnight = now
else:
midnight = now + timedelta(days=1)
midnight = midnight.replace(hour=0, minute=10, second=0, microsecond=0)
return int((midnight - now).total_seconds())
class UnrestrictLi(Hoster):
__name__ = "UnrestrictLi"
__version__ = "0.12"
__type__ = "hoster"
__pattern__ = r'https?://(?:[^/]*\.)?(unrestrict|unr)\.li'
__description__ = """Unrestrict.li hoster plugin"""
__author_name__ = "stickell"
__author_mail__ = "l.stickell@yahoo.it"
def setup(self):
self.chunkLimit = 16
self.resumeDownload = True
def process(self, pyfile):
if re.match(self.__pattern__, pyfile.url):
new_url = pyfile.url
elif not self.account:
self.logError(_("Please enter your %s account or deactivate this plugin") % "Unrestrict.li")
self.fail("No Unrestrict.li account provided")
else:
self.logDebug("Old URL: %s" % pyfile.url)
for _ in xrange(5):
page = self.req.load('https://unrestrict.li/unrestrict.php',
post={'link': pyfile.url, 'domain': 'long'})
self.logDebug("JSON data: " + page)
if page != '':
break
else:
self.logInfo("Unable to get API data, waiting 1 minute and retry")
self.retry(5, 60, "Unable to get API data")
if 'Expired session' in page or ("You are not allowed to "
"download from this host" in page and self.premium):
self.account.relogin(self.user)
self.retry()
elif "File offline" in page:
self.offline()
elif "You are not allowed to download from this host" in page:
self.fail("You are not allowed to download from this host")
elif "You have reached your daily limit for this host" in page:
self.logWarning("Reached daily limit for this host")
self.retry(5, secondsToMidnight(gmt=2), "Daily limit for this host reached")
elif "ERROR_HOSTER_TEMPORARILY_UNAVAILABLE" in page:
self.logInfo("Hoster temporarily unavailable, waiting 1 minute and retry")
self.retry(5, 60, "Hoster is temporarily unavailable")
page = json_loads(page)
new_url = page.keys()[0]
self.api_data = page[new_url]
if new_url != pyfile.url:
self.logDebug("New URL: " + new_url)
if hasattr(self, 'api_data'):
self.setNameSize()
self.download(new_url, disposition=True)
if self.getConfig("history"):
self.load("https://unrestrict.li/history/&delete=all")
self.logInfo("Download history deleted")
def setNameSize(self):
if 'name' in self.api_data:
self.pyfile.name = self.api_data['name']
if 'size' in self.api_data:
self.pyfile.size = self.api_data['size']
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3949,
381,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
258,
327,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3698,
327,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
755,
327,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
14516,
327,
199,
3,
6208,
3515,
327,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
3515,
327,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3698,
327,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
3322,
327,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
10473,
327,
199,
3,
6208,
3515,
327,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
327,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
259,
327,
199,
3949,
381,
199,
199,
646,
295,
199,
504,
2197,
492,
2197,
12,
6871,
199,
199,
504,
859,
14,
5265,
14,
40,
29895,
492,
869,
29895,
199,
504,
859,
14,
2330,
14,
1001,
63,
1897,
492,
2022,
63,
3640,
421,
199,
318,
4696,
1378,
28735,
14873,
8,
22489,
29,
16,
304,
272,
3063,
275,
2197,
14,
10779,
342,
435,
6871,
8,
8419,
29,
22489,
9,
272,
340,
3063,
14,
5180,
365,
378,
436,
3063,
14,
10698,
665,
1616,
26,
267,
10887,
14873,
275,
3063,
272,
587,
26,
267,
10887,
14873,
275,
3063,
435,
6871,
8,
4899,
29,
17,
9,
272,
10887,
14873,
275,
10887,
14873,
14,
1814,
8,
5180,
29,
16,
12,
12709,
29,
709,
12,
3499,
29,
16,
12,
25824,
29,
16,
9,
272,
372,
1109,
1332,
8523,
14873,
446,
3063,
680,
2923,
63,
4515,
1012,
421,
199,
533,
1910,
22188,
13009,
8,
40,
29895,
304,
272,
636,
354,
363,
275,
298,
1358,
22188,
13009,
2,
272,
636,
1023,
363,
275,
298,
16,
14,
713,
2,
272,
636,
466,
363,
275,
298,
526,
11652,
2,
272,
636,
3401,
363,
275,
519,
7,
2859,
24524,
4735,
15,
3672,
20316,
8,
324,
22188,
92,
324,
82,
31477,
317,
7,
272,
636,
1802,
363,
275,
408,
1358,
22188,
14,
317,
394,
29895,
3589,
624,
272,
636,
2502,
63,
354,
363,
275,
298,
18043,
1697,
2,
272,
636,
2502,
63,
1198,
363,
275,
298,
76,
14,
18043,
1697,
32,
27231,
14,
390,
2,
339,
347,
3272,
8,
277,
304,
267,
291,
14,
4604,
8407,
275,
3193,
267,
291,
14,
9964,
11950,
275,
715,
339,
347,
2112,
8,
277,
12,
1134,
493,
304,
267,
340,
295,
14,
1431,
8,
277,
855,
3401,
3108,
1134,
493,
14,
633,
304,
288,
892,
63,
633,
275,
1134,
493,
14,
633,
267,
916,
440,
291,
14,
2048,
26,
288,
291,
14,
793,
547,
6115,
8254,
9509,
2195,
450,
83,
2933,
503,
25560,
642,
3589,
531,
450,
298,
1358,
22188,
14,
317,
531,
288,
291,
14,
1633,
480,
1944,
1910,
22188,
14,
317,
2933,
2741,
531,
267,
587,
26,
288,
291,
14,
793,
7084,
480,
16411,
2851,
26,
450,
83,
2,
450,
1134,
493,
14,
633,
9,
288,
367,
485,
315,
4945,
8,
21,
304,
355,
2034,
275,
291,
14,
2103,
14,
912,
360,
2859,
921,
324,
22188,
14,
317,
15,
324,
22188,
14,
8624,
297,
3660,
2963,
3713,
1073,
356,
1134,
493,
14,
633,
12,
283,
2261,
356,
283,
2809,
3071,
355,
291,
14,
793,
7084,
480,
6243,
666,
26,
298,
435,
2034,
9,
355,
340,
2034,
1137,
8061,
490,
2059,
288,
587,
26,
355,
291,
14,
793,
2354,
480,
6005,
370,
664,
3261,
666,
12,
10923,
413,
12709,
436,
7269,
531,
355,
291,
14,
7154,
8,
21,
12,
5212,
12,
298,
6005,
370,
664,
3261,
666,
531,
953,
340,
283,
20898,
2351,
7,
315,
2034,
503,
1689,
5556,
787,
440,
4370,
370,
298,
6163,
298,
4249,
687,
642,
1591,
2,
315,
2034,
436,
291,
14,
657,
23481,
304,
355,
291,
14,
2048,
14,
264,
2886,
8,
277,
14,
751,
9,
355,
291,
14,
7154,
342,
288,
916,
298,
1173,
26302,
2,
315,
2034,
26,
355,
291,
14,
18430,
342,
288,
916,
298,
5556,
787,
440,
4370,
370,
5235,
687,
642,
1591,
2,
315,
2034,
26,
355,
291,
14,
1633,
480,
5556,
787,
440,
4370,
370,
5235,
687,
642,
1591,
531,
288,
916,
298,
5556,
1172,
13075,
2195,
26122,
2304,
367,
642,
1591,
2,
315,
2034,
26,
355,
291,
14,
793,
3849,
480,
497,
4583,
26122,
2304,
367,
642,
1591,
531,
355,
291,
14,
7154,
8,
21,
12,
4696,
1378,
28735,
14873,
8,
22489,
29,
18,
395,
298,
36,
17550,
2304,
367,
642,
1591,
13075,
531,
288,
916,
298,
3170,
63,
5449,
540,
63,
12510,
726,
689,
1193,
57,
63,
1734,
17377,
2,
315,
2034,
26,
355,
291,
14,
793,
2354,
480,
40,
29895,
22256,
18735,
12,
10923,
413,
12709,
436,
7269,
531,
355,
291,
14,
7154,
8,
21,
12,
5212,
12,
298,
40,
29895,
365,
22256,
18735,
531,
288,
2034,
275,
2022,
63,
3640,
8,
1606,
9,
288,
892,
63,
633,
275,
2034,
14,
1612,
3430,
16,
61,
288,
291,
14,
1246,
63,
576,
275,
2034,
59,
1222,
63,
633,
61,
398,
340,
892,
63,
633,
1137,
1134,
493,
14,
633,
26,
288,
291,
14,
793,
7084,
480,
4665,
2851,
26,
298,
435,
892,
63,
633,
9,
398,
340,
2688,
8,
277,
12,
283,
1246,
63,
576,
735,
288,
291,
14,
18347,
2320,
342,
398,
291,
14,
4249,
8,
1222,
63,
633,
12,
2153,
3124,
29,
549,
9,
398,
340,
291,
14,
27988,
480,
5570,
2349,
288,
291,
14,
912,
480,
2859,
921,
324,
22188,
14,
317,
15,
5570,
15,
6,
1807,
29,
452,
531,
288,
291,
14,
793,
2354,
480,
11950,
7994,
5463,
531,
339,
347,
663,
985,
2320,
8,
277,
304,
267,
340,
283,
354,
7,
315,
291,
14,
1246,
63,
576,
26,
288,
291,
14,
14792,
14,
354,
275,
291,
14,
1246,
63,
576,
459,
354,
418,
267,
340,
283,
890,
7,
315,
291,
14,
1246,
63,
576,
26,
288
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3949,
381,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
258,
327,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3698,
327,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
755,
327,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
14516,
327,
199,
3,
6208,
3515,
327,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
3515,
327,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3698,
327,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
3322,
327,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
10473,
327,
199,
3,
6208,
3515,
327,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
327,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
259,
327,
199,
3949,
381,
199,
199,
646,
295,
199,
504,
2197,
492,
2197,
12,
6871,
199,
199,
504,
859,
14,
5265,
14,
40,
29895,
492,
869,
29895,
199,
504,
859,
14,
2330,
14,
1001,
63,
1897,
492,
2022,
63,
3640,
421,
199,
318,
4696,
1378,
28735,
14873,
8,
22489,
29,
16,
304,
272,
3063,
275,
2197,
14,
10779,
342,
435,
6871,
8,
8419,
29,
22489,
9,
272,
340,
3063,
14,
5180,
365,
378,
436,
3063,
14,
10698,
665,
1616,
26,
267,
10887,
14873,
275,
3063,
272,
587,
26,
267,
10887,
14873,
275,
3063,
435,
6871,
8,
4899,
29,
17,
9,
272,
10887,
14873,
275,
10887,
14873,
14,
1814,
8,
5180,
29,
16,
12,
12709,
29,
709,
12,
3499,
29,
16,
12,
25824,
29,
16,
9,
272,
372,
1109,
1332,
8523,
14873,
446,
3063,
680,
2923,
63,
4515,
1012,
421,
199,
533,
1910,
22188,
13009,
8,
40,
29895,
304,
272,
636,
354,
363,
275,
298,
1358,
22188,
13009,
2,
272,
636,
1023,
363,
275,
298,
16,
14,
713,
2,
272,
636,
466,
363,
275,
298,
526,
11652,
2,
272,
636,
3401,
363,
275,
519,
7,
2859,
24524,
4735,
15,
3672,
20316,
8,
324,
22188,
92,
324,
82,
31477,
317,
7,
272,
636,
1802,
363,
275,
408,
1358,
22188,
14,
317,
394,
29895,
3589,
624,
272,
636,
2502,
63,
354,
363,
275,
298,
18043,
1697,
2,
272,
636,
2502,
63,
1198,
363,
275,
298,
76,
14,
18043,
1697,
32,
27231,
14,
390,
2,
339,
347,
3272,
8,
277,
304,
267,
291,
14,
4604,
8407,
275,
3193,
267,
291,
14,
9964,
11950,
275,
715,
339,
347,
2112,
8,
277,
12,
1134,
493,
304,
267,
340,
295,
14,
1431,
8,
277,
855,
3401,
3108,
1134,
493,
14,
633,
304,
288,
892,
63,
633,
275,
1134,
493,
14,
633,
267,
916,
440,
291,
14,
2048,
26,
288,
291,
14,
793,
547,
6115,
8254,
9509,
2195,
450,
83,
2933,
503,
25560,
642,
3589,
531,
450,
298,
1358,
22188,
14,
317,
531,
288,
291,
14,
1633,
480,
1944,
1910,
22188,
14,
317,
2933,
2741,
531,
267,
587,
26,
288,
291,
14,
793,
7084,
480,
16411,
2851,
26,
450,
83,
2,
450,
1134,
493,
14,
633,
9,
288,
367,
485,
315,
4945,
8,
21,
304,
355,
2034,
275,
291,
14,
2103,
14,
912,
360,
2859,
921,
324,
22188,
14,
317,
15,
324,
22188,
14,
8624,
297,
3660,
2963,
3713,
1073,
356,
1134,
493,
14,
633,
12,
283,
2261,
356,
283,
2809,
3071,
355,
291,
14,
793,
7084,
480,
6243,
666,
26,
298,
435,
2034,
9,
355,
340,
2034,
1137,
8061,
490,
2059,
288,
587,
26,
355,
291,
14,
793,
2354,
480,
6005,
370,
664,
3261,
666,
12,
10923,
413,
12709,
436,
7269,
531,
355,
291,
14,
7154,
8,
21,
12,
5212,
12,
298,
6005,
370,
664,
3261,
666,
531,
953,
340,
283,
20898,
2351,
7,
315,
2034,
503,
1689,
5556,
787,
440,
4370,
370,
298,
6163,
298,
4249,
687,
642,
1591,
2,
315,
2034,
436,
291,
14,
657,
23481,
304,
355,
291,
14,
2048,
14,
264,
2886,
8,
277,
14,
751,
9,
355,
291,
14,
7154,
342,
288,
916,
298,
1173,
26302,
2,
315,
2034,
26,
355,
291,
14,
18430,
342,
288,
916,
298,
5556,
787,
440,
4370,
370,
5235,
687,
642,
1591,
2,
315,
2034,
26,
355,
291,
14,
1633,
480,
5556,
787,
440,
4370,
370,
5235,
687,
642,
1591,
531,
288,
916,
298,
5556,
1172,
13075,
2195,
26122,
2304,
367,
642,
1591,
2,
315,
2034,
26,
355,
291,
14,
793,
3849,
480,
497,
4583,
26122,
2304,
367,
642,
1591,
531,
355,
291,
14,
7154,
8,
21,
12,
4696,
1378,
28735,
14873,
8,
22489,
29,
18,
395,
298,
36,
17550,
2304,
367,
642,
1591,
13075,
531,
288,
916,
298,
3170,
63,
5449,
540,
63,
12510,
726,
689,
1193,
57,
63,
1734,
17377,
2,
315,
2034,
26,
355,
291,
14,
793,
2354,
480,
40,
29895,
22256,
18735,
12,
10923,
413,
12709,
436,
7269,
531,
355,
291,
14,
7154,
8,
21,
12,
5212,
12,
298,
40,
29895,
365,
22256,
18735,
531,
288,
2034,
275,
2022,
63,
3640,
8,
1606,
9,
288,
892,
63,
633,
275,
2034,
14,
1612,
3430,
16,
61,
288,
291,
14,
1246,
63,
576,
275,
2034,
59,
1222,
63,
633,
61,
398,
340,
892,
63,
633,
1137,
1134,
493,
14,
633,
26,
288,
291,
14,
793,
7084,
480,
4665,
2851,
26,
298,
435,
892,
63,
633,
9,
398,
340,
2688,
8,
277,
12,
283,
1246,
63,
576,
735,
288,
291,
14,
18347,
2320,
342,
398,
291,
14,
4249,
8,
1222,
63,
633,
12,
2153,
3124,
29,
549,
9,
398,
340,
291,
14,
27988,
480,
5570,
2349,
288,
291,
14,
912,
480,
2859,
921,
324,
22188,
14,
317,
15,
5570,
15,
6,
1807,
29,
452,
531,
288,
291,
14,
793,
2354,
480,
11950,
7994,
5463,
531,
339,
347,
663,
985,
2320,
8,
277,
304,
267,
340,
283,
354,
7,
315,
291,
14,
1246,
63,
576,
26,
288,
291,
14,
14792,
14,
354,
275,
291,
14,
1246,
63,
576,
459,
354,
418,
267,
340,
283,
890,
7,
315,
291,
14,
1246,
63,
576,
26,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
mrquim/mrquimrepo
|
script.module.youtube.dl/lib/youtube_dl/extractor/bbc.py
|
9
|
54001
|
# coding: utf-8
from __future__ import unicode_literals
import re
import itertools
from .common import InfoExtractor
from ..utils import (
clean_html,
dict_get,
ExtractorError,
float_or_none,
get_element_by_class,
int_or_none,
parse_duration,
parse_iso8601,
try_get,
unescapeHTML,
urlencode_postdata,
urljoin,
)
from ..compat import (
compat_etree_fromstring,
compat_HTTPError,
compat_urlparse,
)
class BBCCoUkIE(InfoExtractor):
IE_NAME = 'bbc.co.uk'
IE_DESC = 'BBC iPlayer'
_ID_REGEX = r'[pb][\da-z]{7}'
_VALID_URL = r'''(?x)
https?://
(?:www\.)?bbc\.co\.uk/
(?:
programmes/(?!articles/)|
iplayer(?:/[^/]+)?/(?:episode/|playlist/)|
music/(?:clips|audiovideo/popular)[/#]|
radio/player/
)
(?P<id>%s)(?!/(?:episodes|broadcasts|clips))
''' % _ID_REGEX
_LOGIN_URL = 'https://account.bbc.com/signin'
_NETRC_MACHINE = 'bbc'
_MEDIASELECTOR_URLS = [
# Provides HQ HLS streams with even better quality that pc mediaset but fails
# with geolocation in some cases when it's even not geo restricted at all (e.g.
# http://www.bbc.co.uk/programmes/b06bp7lf). Also may fail with selectionunavailable.
'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/iptv-all/vpid/%s',
'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/pc/vpid/%s',
]
_MEDIASELECTION_NS = 'http://bbc.co.uk/2008/mp/mediaselection'
_EMP_PLAYLIST_NS = 'http://bbc.co.uk/2008/emp/playlist'
_NAMESPACES = (
_MEDIASELECTION_NS,
_EMP_PLAYLIST_NS,
)
_TESTS = [
{
'url': 'http://www.bbc.co.uk/programmes/b039g8p7',
'info_dict': {
'id': 'b039d07m',
'ext': 'flv',
'title': 'Leonard Cohen, Kaleidoscope - BBC Radio 4',
'description': 'The Canadian poet and songwriter reflects on his musical career.',
},
'params': {
# rtmp download
'skip_download': True,
}
},
{
'url': 'http://www.bbc.co.uk/iplayer/episode/b00yng5w/The_Man_in_Black_Series_3_The_Printed_Name/',
'info_dict': {
'id': 'b00yng1d',
'ext': 'flv',
'title': 'The Man in Black: Series 3: The Printed Name',
'description': "Mark Gatiss introduces Nicholas Pierpan's chilling tale of a writer's devilish pact with a mysterious man. Stars Ewan Bailey.",
'duration': 1800,
},
'params': {
# rtmp download
'skip_download': True,
},
'skip': 'Episode is no longer available on BBC iPlayer Radio',
},
{
'url': 'http://www.bbc.co.uk/iplayer/episode/b03vhd1f/The_Voice_UK_Series_3_Blind_Auditions_5/',
'info_dict': {
'id': 'b00yng1d',
'ext': 'flv',
'title': 'The Voice UK: Series 3: Blind Auditions 5',
'description': 'Emma Willis and Marvin Humes present the fifth set of blind auditions in the singing competition, as the coaches continue to build their teams based on voice alone.',
'duration': 5100,
},
'params': {
# rtmp download
'skip_download': True,
},
'skip': 'Currently BBC iPlayer TV programmes are available to play in the UK only',
},
{
'url': 'http://www.bbc.co.uk/iplayer/episode/p026c7jt/tomorrows-worlds-the-unearthly-history-of-science-fiction-2-invasion',
'info_dict': {
'id': 'b03k3pb7',
'ext': 'flv',
'title': "Tomorrow's Worlds: The Unearthly History of Science Fiction",
'description': '2. Invasion',
'duration': 3600,
},
'params': {
# rtmp download
'skip_download': True,
},
'skip': 'Currently BBC iPlayer TV programmes are available to play in the UK only',
}, {
'url': 'http://www.bbc.co.uk/programmes/b04v20dw',
'info_dict': {
'id': 'b04v209v',
'ext': 'flv',
'title': 'Pete Tong, The Essential New Tune Special',
'description': "Pete has a very special mix - all of 2014's Essential New Tunes!",
'duration': 10800,
},
'params': {
# rtmp download
'skip_download': True,
},
'skip': 'Episode is no longer available on BBC iPlayer Radio',
}, {
'url': 'http://www.bbc.co.uk/music/clips/p022h44b',
'note': 'Audio',
'info_dict': {
'id': 'p022h44j',
'ext': 'flv',
'title': 'BBC Proms Music Guides, Rachmaninov: Symphonic Dances',
'description': "In this Proms Music Guide, Andrew McGregor looks at Rachmaninov's Symphonic Dances.",
'duration': 227,
},
'params': {
# rtmp download
'skip_download': True,
}
}, {
'url': 'http://www.bbc.co.uk/music/clips/p025c0zz',
'note': 'Video',
'info_dict': {
'id': 'p025c103',
'ext': 'flv',
'title': 'Reading and Leeds Festival, 2014, Rae Morris - Closer (Live on BBC Three)',
'description': 'Rae Morris performs Closer for BBC Three at Reading 2014',
'duration': 226,
},
'params': {
# rtmp download
'skip_download': True,
}
}, {
'url': 'http://www.bbc.co.uk/iplayer/episode/b054fn09/ad/natural-world-20152016-2-super-powered-owls',
'info_dict': {
'id': 'p02n76xf',
'ext': 'flv',
'title': 'Natural World, 2015-2016: 2. Super Powered Owls',
'description': 'md5:e4db5c937d0e95a7c6b5e654d429183d',
'duration': 3540,
},
'params': {
# rtmp download
'skip_download': True,
},
'skip': 'geolocation',
}, {
'url': 'http://www.bbc.co.uk/iplayer/episode/b05zmgwn/royal-academy-summer-exhibition',
'info_dict': {
'id': 'b05zmgw1',
'ext': 'flv',
'description': 'Kirsty Wark and Morgan Quaintance visit the Royal Academy as it prepares for its annual artistic extravaganza, meeting people who have come together to make the show unique.',
'title': 'Royal Academy Summer Exhibition',
'duration': 3540,
},
'params': {
# rtmp download
'skip_download': True,
},
'skip': 'geolocation',
}, {
# iptv-all mediaset fails with geolocation however there is no geo restriction
# for this programme at all
'url': 'http://www.bbc.co.uk/programmes/b06rkn85',
'info_dict': {
'id': 'b06rkms3',
'ext': 'flv',
'title': "Best of the Mini-Mixes 2015: Part 3, Annie Mac's Friday Night - BBC Radio 1",
'description': "Annie has part three in the Best of the Mini-Mixes 2015, plus the year's Most Played!",
},
'params': {
# rtmp download
'skip_download': True,
},
'skip': 'Now it\'s really geo-restricted',
}, {
# compact player (https://github.com/rg3/youtube-dl/issues/8147)
'url': 'http://www.bbc.co.uk/programmes/p028bfkf/player',
'info_dict': {
'id': 'p028bfkj',
'ext': 'flv',
'title': 'Extract from BBC documentary Look Stranger - Giant Leeks and Magic Brews',
'description': 'Extract from BBC documentary Look Stranger - Giant Leeks and Magic Brews',
},
'params': {
# rtmp download
'skip_download': True,
},
}, {
'url': 'http://www.bbc.co.uk/iplayer/playlist/p01dvks4',
'only_matching': True,
}, {
'url': 'http://www.bbc.co.uk/music/clips#p02frcc3',
'only_matching': True,
}, {
'url': 'http://www.bbc.co.uk/iplayer/cbeebies/episode/b0480276/bing-14-atchoo',
'only_matching': True,
}, {
'url': 'http://www.bbc.co.uk/radio/player/p03cchwf',
'only_matching': True,
}, {
'url': 'https://www.bbc.co.uk/music/audiovideo/popular#p055bc55',
'only_matching': True,
}]
_USP_RE = r'/([^/]+?)\.ism(?:\.hlsv2\.ism)?/[^/]+\.m3u8'
def _login(self):
username, password = self._get_login_info()
if username is None:
return
login_page = self._download_webpage(
self._LOGIN_URL, None, 'Downloading signin page')
login_form = self._hidden_inputs(login_page)
login_form.update({
'username': username,
'password': password,
})
post_url = urljoin(self._LOGIN_URL, self._search_regex(
r'<form[^>]+action=(["\'])(?P<url>.+?)\1', login_page,
'post url', default=self._LOGIN_URL, group='url'))
response, urlh = self._download_webpage_handle(
post_url, None, 'Logging in', data=urlencode_postdata(login_form),
headers={'Referer': self._LOGIN_URL})
if self._LOGIN_URL in urlh.geturl():
error = clean_html(get_element_by_class('form-message', response))
if error:
raise ExtractorError(
'Unable to login: %s' % error, expected=True)
raise ExtractorError('Unable to log in')
def _real_initialize(self):
self._login()
class MediaSelectionError(Exception):
def __init__(self, id):
self.id = id
def _extract_asx_playlist(self, connection, programme_id):
asx = self._download_xml(connection.get('href'), programme_id, 'Downloading ASX playlist')
return [ref.get('href') for ref in asx.findall('./Entry/ref')]
def _extract_items(self, playlist):
return playlist.findall('./{%s}item' % self._EMP_PLAYLIST_NS)
def _findall_ns(self, element, xpath):
elements = []
for ns in self._NAMESPACES:
elements.extend(element.findall(xpath % ns))
return elements
def _extract_medias(self, media_selection):
error = media_selection.find('./{%s}error' % self._MEDIASELECTION_NS)
if error is None:
media_selection.find('./{%s}error' % self._EMP_PLAYLIST_NS)
if error is not None:
raise BBCCoUkIE.MediaSelectionError(error.get('id'))
return self._findall_ns(media_selection, './{%s}media')
def _extract_connections(self, media):
return self._findall_ns(media, './{%s}connection')
def _get_subtitles(self, media, programme_id):
subtitles = {}
for connection in self._extract_connections(media):
captions = self._download_xml(connection.get('href'), programme_id, 'Downloading captions')
lang = captions.get('{http://www.w3.org/XML/1998/namespace}lang', 'en')
subtitles[lang] = [
{
'url': connection.get('href'),
'ext': 'ttml',
},
]
return subtitles
def _raise_extractor_error(self, media_selection_error):
raise ExtractorError(
'%s returned error: %s' % (self.IE_NAME, media_selection_error.id),
expected=True)
def _download_media_selector(self, programme_id):
last_exception = None
for mediaselector_url in self._MEDIASELECTOR_URLS:
try:
return self._download_media_selector_url(
mediaselector_url % programme_id, programme_id)
except BBCCoUkIE.MediaSelectionError as e:
if e.id in ('notukerror', 'geolocation', 'selectionunavailable'):
last_exception = e
continue
self._raise_extractor_error(e)
self._raise_extractor_error(last_exception)
def _download_media_selector_url(self, url, programme_id=None):
try:
media_selection = self._download_xml(
url, programme_id, 'Downloading media selection XML')
except ExtractorError as ee:
if isinstance(ee.cause, compat_HTTPError) and ee.cause.code in (403, 404):
media_selection = compat_etree_fromstring(ee.cause.read().decode('utf-8'))
else:
raise
return self._process_media_selector(media_selection, programme_id)
def _process_media_selector(self, media_selection, programme_id):
formats = []
subtitles = None
urls = []
for media in self._extract_medias(media_selection):
kind = media.get('kind')
if kind in ('video', 'audio'):
bitrate = int_or_none(media.get('bitrate'))
encoding = media.get('encoding')
service = media.get('service')
width = int_or_none(media.get('width'))
height = int_or_none(media.get('height'))
file_size = int_or_none(media.get('media_file_size'))
for connection in self._extract_connections(media):
href = connection.get('href')
if href in urls:
continue
if href:
urls.append(href)
conn_kind = connection.get('kind')
protocol = connection.get('protocol')
supplier = connection.get('supplier')
transfer_format = connection.get('transferFormat')
format_id = supplier or conn_kind or protocol
if service:
format_id = '%s_%s' % (service, format_id)
# ASX playlist
if supplier == 'asx':
for i, ref in enumerate(self._extract_asx_playlist(connection, programme_id)):
formats.append({
'url': ref,
'format_id': 'ref%s_%s' % (i, format_id),
})
elif transfer_format == 'dash':
formats.extend(self._extract_mpd_formats(
href, programme_id, mpd_id=format_id, fatal=False))
elif transfer_format == 'hls':
formats.extend(self._extract_m3u8_formats(
href, programme_id, ext='mp4', entry_protocol='m3u8_native',
m3u8_id=format_id, fatal=False))
if re.search(self._USP_RE, href):
usp_formats = self._extract_m3u8_formats(
re.sub(self._USP_RE, r'/\1.ism/\1.m3u8', href),
programme_id, ext='mp4', entry_protocol='m3u8_native',
m3u8_id=format_id, fatal=False)
for f in usp_formats:
if f.get('height') and f['height'] > 720:
continue
formats.append(f)
elif transfer_format == 'hds':
formats.extend(self._extract_f4m_formats(
href, programme_id, f4m_id=format_id, fatal=False))
else:
if not service and not supplier and bitrate:
format_id += '-%d' % bitrate
fmt = {
'format_id': format_id,
'filesize': file_size,
}
if kind == 'video':
fmt.update({
'width': width,
'height': height,
'tbr': bitrate,
'vcodec': encoding,
})
else:
fmt.update({
'abr': bitrate,
'acodec': encoding,
'vcodec': 'none',
})
if protocol in ('http', 'https'):
# Direct link
fmt.update({
'url': href,
})
elif protocol == 'rtmp':
application = connection.get('application', 'ondemand')
auth_string = connection.get('authString')
identifier = connection.get('identifier')
server = connection.get('server')
fmt.update({
'url': '%s://%s/%s?%s' % (protocol, server, application, auth_string),
'play_path': identifier,
'app': '%s?%s' % (application, auth_string),
'page_url': 'http://www.bbc.co.uk',
'player_url': 'http://www.bbc.co.uk/emp/releases/iplayer/revisions/617463_618125_4/617463_618125_4_emp.swf',
'rtmp_live': False,
'ext': 'flv',
})
else:
continue
formats.append(fmt)
elif kind == 'captions':
subtitles = self.extract_subtitles(media, programme_id)
return formats, subtitles
def _download_playlist(self, playlist_id):
try:
playlist = self._download_json(
'http://www.bbc.co.uk/programmes/%s/playlist.json' % playlist_id,
playlist_id, 'Downloading playlist JSON')
version = playlist.get('defaultAvailableVersion')
if version:
smp_config = version['smpConfig']
title = smp_config['title']
description = smp_config['summary']
for item in smp_config['items']:
kind = item['kind']
if kind not in ('programme', 'radioProgramme'):
continue
programme_id = item.get('vpid')
duration = int_or_none(item.get('duration'))
formats, subtitles = self._download_media_selector(programme_id)
return programme_id, title, description, duration, formats, subtitles
except ExtractorError as ee:
if not (isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 404):
raise
# fallback to legacy playlist
return self._process_legacy_playlist(playlist_id)
def _process_legacy_playlist_url(self, url, display_id):
playlist = self._download_legacy_playlist_url(url, display_id)
return self._extract_from_legacy_playlist(playlist, display_id)
def _process_legacy_playlist(self, playlist_id):
return self._process_legacy_playlist_url(
'http://www.bbc.co.uk/iplayer/playlist/%s' % playlist_id, playlist_id)
def _download_legacy_playlist_url(self, url, playlist_id=None):
return self._download_xml(
url, playlist_id, 'Downloading legacy playlist XML')
def _extract_from_legacy_playlist(self, playlist, playlist_id):
no_items = playlist.find('./{%s}noItems' % self._EMP_PLAYLIST_NS)
if no_items is not None:
reason = no_items.get('reason')
if reason == 'preAvailability':
msg = 'Episode %s is not yet available' % playlist_id
elif reason == 'postAvailability':
msg = 'Episode %s is no longer available' % playlist_id
elif reason == 'noMedia':
msg = 'Episode %s is not currently available' % playlist_id
else:
msg = 'Episode %s is not available: %s' % (playlist_id, reason)
raise ExtractorError(msg, expected=True)
for item in self._extract_items(playlist):
kind = item.get('kind')
if kind not in ('programme', 'radioProgramme'):
continue
title = playlist.find('./{%s}title' % self._EMP_PLAYLIST_NS).text
description_el = playlist.find('./{%s}summary' % self._EMP_PLAYLIST_NS)
description = description_el.text if description_el is not None else None
def get_programme_id(item):
def get_from_attributes(item):
for p in('identifier', 'group'):
value = item.get(p)
if value and re.match(r'^[pb][\da-z]{7}$', value):
return value
get_from_attributes(item)
mediator = item.find('./{%s}mediator' % self._EMP_PLAYLIST_NS)
if mediator is not None:
return get_from_attributes(mediator)
programme_id = get_programme_id(item)
duration = int_or_none(item.get('duration'))
if programme_id:
formats, subtitles = self._download_media_selector(programme_id)
else:
formats, subtitles = self._process_media_selector(item, playlist_id)
programme_id = playlist_id
return programme_id, title, description, duration, formats, subtitles
def _real_extract(self, url):
group_id = self._match_id(url)
webpage = self._download_webpage(url, group_id, 'Downloading video page')
error = self._search_regex(
r'<div\b[^>]+\bclass=["\']smp__message delta["\'][^>]*>([^<]+)<',
webpage, 'error', default=None)
if error:
raise ExtractorError(error, expected=True)
programme_id = None
duration = None
tviplayer = self._search_regex(
r'mediator\.bind\(({.+?})\s*,\s*document\.getElementById',
webpage, 'player', default=None)
if tviplayer:
player = self._parse_json(tviplayer, group_id).get('player', {})
duration = int_or_none(player.get('duration'))
programme_id = player.get('vpid')
if not programme_id:
programme_id = self._search_regex(
r'"vpid"\s*:\s*"(%s)"' % self._ID_REGEX, webpage, 'vpid', fatal=False, default=None)
if programme_id:
formats, subtitles = self._download_media_selector(programme_id)
title = self._og_search_title(webpage, default=None) or self._html_search_regex(
(r'<h2[^>]+id="parent-title"[^>]*>(.+?)</h2>',
r'<div[^>]+class="info"[^>]*>\s*<h1>(.+?)</h1>'), webpage, 'title')
description = self._search_regex(
(r'<p class="[^"]*medium-description[^"]*">([^<]+)</p>',
r'<div[^>]+class="info_+synopsis"[^>]*>([^<]+)</div>'),
webpage, 'description', default=None)
if not description:
description = self._html_search_meta('description', webpage)
else:
programme_id, title, description, duration, formats, subtitles = self._download_playlist(group_id)
self._sort_formats(formats)
return {
'id': programme_id,
'title': title,
'description': description,
'thumbnail': self._og_search_thumbnail(webpage, default=None),
'duration': duration,
'formats': formats,
'subtitles': subtitles,
}
class BBCIE(BBCCoUkIE):
IE_NAME = 'bbc'
IE_DESC = 'BBC'
_VALID_URL = r'https?://(?:www\.)?bbc\.(?:com|co\.uk)/(?:[^/]+/)+(?P<id>[^/#?]+)'
_MEDIASELECTOR_URLS = [
# Provides HQ HLS streams but fails with geolocation in some cases when it's
# even not geo restricted at all
'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/iptv-all/vpid/%s',
# Provides more formats, namely direct mp4 links, but fails on some videos with
# notukerror for non UK (?) users (e.g.
# http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret)
'http://open.live.bbc.co.uk/mediaselector/4/mtis/stream/%s',
# Provides fewer formats, but works everywhere for everybody (hopefully)
'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/journalism-pc/vpid/%s',
]
_TESTS = [{
# article with multiple videos embedded with data-playable containing vpids
'url': 'http://www.bbc.com/news/world-europe-32668511',
'info_dict': {
'id': 'world-europe-32668511',
'title': 'Russia stages massive WW2 parade despite Western boycott',
'description': 'md5:00ff61976f6081841f759a08bf78cc9c',
},
'playlist_count': 2,
}, {
# article with multiple videos embedded with data-playable (more videos)
'url': 'http://www.bbc.com/news/business-28299555',
'info_dict': {
'id': 'business-28299555',
'title': 'Farnborough Airshow: Video highlights',
'description': 'BBC reports and video highlights at the Farnborough Airshow.',
},
'playlist_count': 9,
'skip': 'Save time',
}, {
# article with multiple videos embedded with `new SMP()`
# broken
'url': 'http://www.bbc.co.uk/blogs/adamcurtis/entries/3662a707-0af9-3149-963f-47bea720b460',
'info_dict': {
'id': '3662a707-0af9-3149-963f-47bea720b460',
'title': 'BUGGER',
},
'playlist_count': 18,
}, {
# single video embedded with data-playable containing vpid
'url': 'http://www.bbc.com/news/world-europe-32041533',
'info_dict': {
'id': 'p02mprgb',
'ext': 'mp4',
'title': 'Aerial footage showed the site of the crash in the Alps - courtesy BFM TV',
'description': 'md5:2868290467291b37feda7863f7a83f54',
'duration': 47,
'timestamp': 1427219242,
'upload_date': '20150324',
},
'params': {
# rtmp download
'skip_download': True,
}
}, {
# article with single video embedded with data-playable containing XML playlist
# with direct video links as progressiveDownloadUrl (for now these are extracted)
# and playlist with f4m and m3u8 as streamingUrl
'url': 'http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu',
'info_dict': {
'id': '150615_telabyad_kentin_cogu',
'ext': 'mp4',
'title': "YPG: Tel Abyad'ın tamamı kontrolümüzde",
'description': 'md5:33a4805a855c9baf7115fcbde57e7025',
'timestamp': 1434397334,
'upload_date': '20150615',
},
'params': {
'skip_download': True,
}
}, {
# single video embedded with data-playable containing XML playlists (regional section)
'url': 'http://www.bbc.com/mundo/video_fotos/2015/06/150619_video_honduras_militares_hospitales_corrupcion_aw',
'info_dict': {
'id': '150619_video_honduras_militares_hospitales_corrupcion_aw',
'ext': 'mp4',
'title': 'Honduras militariza sus hospitales por nuevo escándalo de corrupción',
'description': 'md5:1525f17448c4ee262b64b8f0c9ce66c8',
'timestamp': 1434713142,
'upload_date': '20150619',
},
'params': {
'skip_download': True,
}
}, {
# single video from video playlist embedded with vxp-playlist-data JSON
'url': 'http://www.bbc.com/news/video_and_audio/must_see/33376376',
'info_dict': {
'id': 'p02w6qjc',
'ext': 'mp4',
'title': '''Judge Mindy Glazer: "I'm sorry to see you here... I always wondered what happened to you"''',
'duration': 56,
'description': '''Judge Mindy Glazer: "I'm sorry to see you here... I always wondered what happened to you"''',
},
'params': {
'skip_download': True,
}
}, {
# single video story with digitalData
'url': 'http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret',
'info_dict': {
'id': 'p02q6gc4',
'ext': 'flv',
'title': 'Sri Lanka’s spicy secret',
'description': 'As a new train line to Jaffna opens up the country’s north, travellers can experience a truly distinct slice of Tamil culture.',
'timestamp': 1437674293,
'upload_date': '20150723',
},
'params': {
# rtmp download
'skip_download': True,
}
}, {
# single video story without digitalData
'url': 'http://www.bbc.com/autos/story/20130513-hyundais-rock-star',
'info_dict': {
'id': 'p018zqqg',
'ext': 'mp4',
'title': 'Hyundai Santa Fe Sport: Rock star',
'description': 'md5:b042a26142c4154a6e472933cf20793d',
'timestamp': 1415867444,
'upload_date': '20141113',
},
'params': {
# rtmp download
'skip_download': True,
}
}, {
# single video embedded with Morph
'url': 'http://www.bbc.co.uk/sport/live/olympics/36895975',
'info_dict': {
'id': 'p041vhd0',
'ext': 'mp4',
'title': "Nigeria v Japan - Men's First Round",
'description': 'Live coverage of the first round from Group B at the Amazonia Arena.',
'duration': 7980,
'uploader': 'BBC Sport',
'uploader_id': 'bbc_sport',
},
'params': {
# m3u8 download
'skip_download': True,
},
'skip': 'Georestricted to UK',
}, {
# single video with playlist.sxml URL in playlist param
'url': 'http://www.bbc.com/sport/0/football/33653409',
'info_dict': {
'id': 'p02xycnp',
'ext': 'mp4',
'title': 'Transfers: Cristiano Ronaldo to Man Utd, Arsenal to spend?',
'description': 'BBC Sport\'s David Ornstein has the latest transfer gossip, including rumours of a Manchester United return for Cristiano Ronaldo.',
'duration': 140,
},
'params': {
# rtmp download
'skip_download': True,
}
}, {
# article with multiple videos embedded with playlist.sxml in playlist param
'url': 'http://www.bbc.com/sport/0/football/34475836',
'info_dict': {
'id': '34475836',
'title': 'Jurgen Klopp: Furious football from a witty and winning coach',
'description': 'Fast-paced football, wit, wisdom and a ready smile - why Liverpool fans should come to love new boss Jurgen Klopp.',
},
'playlist_count': 3,
}, {
# school report article with single video
'url': 'http://www.bbc.co.uk/schoolreport/35744779',
'info_dict': {
'id': '35744779',
'title': 'School which breaks down barriers in Jerusalem',
},
'playlist_count': 1,
}, {
# single video with playlist URL from weather section
'url': 'http://www.bbc.com/weather/features/33601775',
'only_matching': True,
}, {
# custom redirection to www.bbc.com
'url': 'http://www.bbc.co.uk/news/science-environment-33661876',
'only_matching': True,
}, {
# single video article embedded with data-media-vpid
'url': 'http://www.bbc.co.uk/sport/rowing/35908187',
'only_matching': True,
}]
@classmethod
def suitable(cls, url):
EXCLUDE_IE = (BBCCoUkIE, BBCCoUkArticleIE, BBCCoUkIPlayerPlaylistIE, BBCCoUkPlaylistIE)
return (False if any(ie.suitable(url) for ie in EXCLUDE_IE)
else super(BBCIE, cls).suitable(url))
def _extract_from_media_meta(self, media_meta, video_id):
# Direct links to media in media metadata (e.g.
# http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu)
# TODO: there are also f4m and m3u8 streams incorporated in playlist.sxml
source_files = media_meta.get('sourceFiles')
if source_files:
return [{
'url': f['url'],
'format_id': format_id,
'ext': f.get('encoding'),
'tbr': float_or_none(f.get('bitrate'), 1000),
'filesize': int_or_none(f.get('filesize')),
} for format_id, f in source_files.items() if f.get('url')], []
programme_id = media_meta.get('externalId')
if programme_id:
return self._download_media_selector(programme_id)
# Process playlist.sxml as legacy playlist
href = media_meta.get('href')
if href:
playlist = self._download_legacy_playlist_url(href)
_, _, _, _, formats, subtitles = self._extract_from_legacy_playlist(playlist, video_id)
return formats, subtitles
return [], []
def _extract_from_playlist_sxml(self, url, playlist_id, timestamp):
programme_id, title, description, duration, formats, subtitles = \
self._process_legacy_playlist_url(url, playlist_id)
self._sort_formats(formats)
return {
'id': programme_id,
'title': title,
'description': description,
'duration': duration,
'timestamp': timestamp,
'formats': formats,
'subtitles': subtitles,
}
def _real_extract(self, url):
playlist_id = self._match_id(url)
webpage = self._download_webpage(url, playlist_id)
json_ld_info = self._search_json_ld(webpage, playlist_id, default={})
timestamp = json_ld_info.get('timestamp')
playlist_title = json_ld_info.get('title')
if not playlist_title:
playlist_title = self._og_search_title(
webpage, default=None) or self._html_search_regex(
r'<title>(.+?)</title>', webpage, 'playlist title', default=None)
if playlist_title:
playlist_title = re.sub(r'(.+)\s*-\s*BBC.*?$', r'\1', playlist_title).strip()
playlist_description = json_ld_info.get(
'description') or self._og_search_description(webpage, default=None)
if not timestamp:
timestamp = parse_iso8601(self._search_regex(
[r'<meta[^>]+property="article:published_time"[^>]+content="([^"]+)"',
r'itemprop="datePublished"[^>]+datetime="([^"]+)"',
r'"datePublished":\s*"([^"]+)'],
webpage, 'date', default=None))
entries = []
# article with multiple videos embedded with playlist.sxml (e.g.
# http://www.bbc.com/sport/0/football/34475836)
playlists = re.findall(r'<param[^>]+name="playlist"[^>]+value="([^"]+)"', webpage)
playlists.extend(re.findall(r'data-media-id="([^"]+/playlist\.sxml)"', webpage))
if playlists:
entries = [
self._extract_from_playlist_sxml(playlist_url, playlist_id, timestamp)
for playlist_url in playlists]
# news article with multiple videos embedded with data-playable
data_playables = re.findall(r'data-playable=(["\'])({.+?})\1', webpage)
if data_playables:
for _, data_playable_json in data_playables:
data_playable = self._parse_json(
unescapeHTML(data_playable_json), playlist_id, fatal=False)
if not data_playable:
continue
settings = data_playable.get('settings', {})
if settings:
# data-playable with video vpid in settings.playlistObject.items (e.g.
# http://www.bbc.com/news/world-us-canada-34473351)
playlist_object = settings.get('playlistObject', {})
if playlist_object:
items = playlist_object.get('items')
if items and isinstance(items, list):
title = playlist_object['title']
description = playlist_object.get('summary')
duration = int_or_none(items[0].get('duration'))
programme_id = items[0].get('vpid')
formats, subtitles = self._download_media_selector(programme_id)
self._sort_formats(formats)
entries.append({
'id': programme_id,
'title': title,
'description': description,
'timestamp': timestamp,
'duration': duration,
'formats': formats,
'subtitles': subtitles,
})
else:
# data-playable without vpid but with a playlist.sxml URLs
# in otherSettings.playlist (e.g.
# http://www.bbc.com/turkce/multimedya/2015/10/151010_vid_ankara_patlama_ani)
playlist = data_playable.get('otherSettings', {}).get('playlist', {})
if playlist:
entry = None
for key in ('streaming', 'progressiveDownload'):
playlist_url = playlist.get('%sUrl' % key)
if not playlist_url:
continue
try:
info = self._extract_from_playlist_sxml(
playlist_url, playlist_id, timestamp)
if not entry:
entry = info
else:
entry['title'] = info['title']
entry['formats'].extend(info['formats'])
except Exception as e:
# Some playlist URL may fail with 500, at the same time
# the other one may work fine (e.g.
# http://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_cogu)
if isinstance(e.cause, compat_HTTPError) and e.cause.code == 500:
continue
raise
if entry:
self._sort_formats(entry['formats'])
entries.append(entry)
if entries:
return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)
# single video story (e.g. http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secret)
programme_id = self._search_regex(
[r'data-(?:video-player|media)-vpid="(%s)"' % self._ID_REGEX,
r'<param[^>]+name="externalIdentifier"[^>]+value="(%s)"' % self._ID_REGEX,
r'videoId\s*:\s*["\'](%s)["\']' % self._ID_REGEX],
webpage, 'vpid', default=None)
if programme_id:
formats, subtitles = self._download_media_selector(programme_id)
self._sort_formats(formats)
# digitalData may be missing (e.g. http://www.bbc.com/autos/story/20130513-hyundais-rock-star)
digital_data = self._parse_json(
self._search_regex(
r'var\s+digitalData\s*=\s*({.+?});?\n', webpage, 'digital data', default='{}'),
programme_id, fatal=False)
page_info = digital_data.get('page', {}).get('pageInfo', {})
title = page_info.get('pageName') or self._og_search_title(webpage)
description = page_info.get('description') or self._og_search_description(webpage)
timestamp = parse_iso8601(page_info.get('publicationDate')) or timestamp
return {
'id': programme_id,
'title': title,
'description': description,
'timestamp': timestamp,
'formats': formats,
'subtitles': subtitles,
}
# Morph based embed (e.g. http://www.bbc.co.uk/sport/live/olympics/36895975)
# There are several setPayload calls may be present but the video
# seems to be always related to the first one
morph_payload = self._parse_json(
self._search_regex(
r'Morph\.setPayload\([^,]+,\s*({.+?})\);',
webpage, 'morph payload', default='{}'),
playlist_id, fatal=False)
if morph_payload:
components = try_get(morph_payload, lambda x: x['body']['components'], list) or []
for component in components:
if not isinstance(component, dict):
continue
lead_media = try_get(component, lambda x: x['props']['leadMedia'], dict)
if not lead_media:
continue
identifiers = lead_media.get('identifiers')
if not identifiers or not isinstance(identifiers, dict):
continue
programme_id = identifiers.get('vpid') or identifiers.get('playablePid')
if not programme_id:
continue
title = lead_media.get('title') or self._og_search_title(webpage)
formats, subtitles = self._download_media_selector(programme_id)
self._sort_formats(formats)
description = lead_media.get('summary')
uploader = lead_media.get('masterBrand')
uploader_id = lead_media.get('mid')
duration = None
duration_d = lead_media.get('duration')
if isinstance(duration_d, dict):
duration = parse_duration(dict_get(
duration_d, ('rawDuration', 'formattedDuration', 'spokenDuration')))
return {
'id': programme_id,
'title': title,
'description': description,
'duration': duration,
'uploader': uploader,
'uploader_id': uploader_id,
'formats': formats,
'subtitles': subtitles,
}
def extract_all(pattern):
return list(filter(None, map(
lambda s: self._parse_json(s, playlist_id, fatal=False),
re.findall(pattern, webpage))))
# Multiple video article (e.g.
# http://www.bbc.co.uk/blogs/adamcurtis/entries/3662a707-0af9-3149-963f-47bea720b460)
EMBED_URL = r'https?://(?:www\.)?bbc\.co\.uk/(?:[^/]+/)+%s(?:\b[^"]+)?' % self._ID_REGEX
entries = []
for match in extract_all(r'new\s+SMP\(({.+?})\)'):
embed_url = match.get('playerSettings', {}).get('externalEmbedUrl')
if embed_url and re.match(EMBED_URL, embed_url):
entries.append(embed_url)
entries.extend(re.findall(
r'setPlaylist\("(%s)"\)' % EMBED_URL, webpage))
if entries:
return self.playlist_result(
[self.url_result(entry_, 'BBCCoUk') for entry_ in entries],
playlist_id, playlist_title, playlist_description)
# Multiple video article (e.g. http://www.bbc.com/news/world-europe-32668511)
medias = extract_all(r"data-media-meta='({[^']+})'")
if not medias:
# Single video article (e.g. http://www.bbc.com/news/video_and_audio/international)
media_asset = self._search_regex(
r'mediaAssetPage\.init\(\s*({.+?}), "/',
webpage, 'media asset', default=None)
if media_asset:
media_asset_page = self._parse_json(media_asset, playlist_id, fatal=False)
medias = []
for video in media_asset_page.get('videos', {}).values():
medias.extend(video.values())
if not medias:
# Multiple video playlist with single `now playing` entry (e.g.
# http://www.bbc.com/news/video_and_audio/must_see/33767813)
vxp_playlist = self._parse_json(
self._search_regex(
r'<script[^>]+class="vxp-playlist-data"[^>]+type="application/json"[^>]*>([^<]+)</script>',
webpage, 'playlist data'),
playlist_id)
playlist_medias = []
for item in vxp_playlist:
media = item.get('media')
if not media:
continue
playlist_medias.append(media)
# Download single video if found media with asset id matching the video id from URL
if item.get('advert', {}).get('assetId') == playlist_id:
medias = [media]
break
# Fallback to the whole playlist
if not medias:
medias = playlist_medias
entries = []
for num, media_meta in enumerate(medias, start=1):
formats, subtitles = self._extract_from_media_meta(media_meta, playlist_id)
if not formats:
continue
self._sort_formats(formats)
video_id = media_meta.get('externalId')
if not video_id:
video_id = playlist_id if len(medias) == 1 else '%s-%s' % (playlist_id, num)
title = media_meta.get('caption')
if not title:
title = playlist_title if len(medias) == 1 else '%s - Video %s' % (playlist_title, num)
duration = int_or_none(media_meta.get('durationInSeconds')) or parse_duration(media_meta.get('duration'))
images = []
for image in media_meta.get('images', {}).values():
images.extend(image.values())
if 'image' in media_meta:
images.append(media_meta['image'])
thumbnails = [{
'url': image.get('href'),
'width': int_or_none(image.get('width')),
'height': int_or_none(image.get('height')),
} for image in images]
entries.append({
'id': video_id,
'title': title,
'thumbnails': thumbnails,
'duration': duration,
'timestamp': timestamp,
'formats': formats,
'subtitles': subtitles,
})
return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)
class BBCCoUkArticleIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?bbc\.co\.uk/programmes/articles/(?P<id>[a-zA-Z0-9]+)'
IE_NAME = 'bbc.co.uk:article'
IE_DESC = 'BBC articles'
_TEST = {
'url': 'http://www.bbc.co.uk/programmes/articles/3jNQLTMrPlYGTBn0WV6M2MS/not-your-typical-role-model-ada-lovelace-the-19th-century-programmer',
'info_dict': {
'id': '3jNQLTMrPlYGTBn0WV6M2MS',
'title': 'Calculating Ada: The Countess of Computing - Not your typical role model: Ada Lovelace the 19th century programmer - BBC Four',
'description': 'Hannah Fry reveals some of her surprising discoveries about Ada Lovelace during filming.',
},
'playlist_count': 4,
'add_ie': ['BBCCoUk'],
}
def _real_extract(self, url):
playlist_id = self._match_id(url)
webpage = self._download_webpage(url, playlist_id)
title = self._og_search_title(webpage)
description = self._og_search_description(webpage).strip()
entries = [self.url_result(programme_url) for programme_url in re.findall(
r'<div[^>]+typeof="Clip"[^>]+resource="([^"]+)"', webpage)]
return self.playlist_result(entries, playlist_id, title, description)
class BBCCoUkPlaylistBaseIE(InfoExtractor):
def _entries(self, webpage, url, playlist_id):
single_page = 'page' in compat_urlparse.parse_qs(
compat_urlparse.urlparse(url).query)
for page_num in itertools.count(2):
for video_id in re.findall(
self._VIDEO_ID_TEMPLATE % BBCCoUkIE._ID_REGEX, webpage):
yield self.url_result(
self._URL_TEMPLATE % video_id, BBCCoUkIE.ie_key())
if single_page:
return
next_page = self._search_regex(
r'<li[^>]+class=(["\'])pagination_+next\1[^>]*><a[^>]+href=(["\'])(?P<url>(?:(?!\2).)+)\2',
webpage, 'next page url', default=None, group='url')
if not next_page:
break
webpage = self._download_webpage(
compat_urlparse.urljoin(url, next_page), playlist_id,
'Downloading page %d' % page_num, page_num)
def _real_extract(self, url):
playlist_id = self._match_id(url)
webpage = self._download_webpage(url, playlist_id)
title, description = self._extract_title_and_description(webpage)
return self.playlist_result(
self._entries(webpage, url, playlist_id),
playlist_id, title, description)
class BBCCoUkIPlayerPlaylistIE(BBCCoUkPlaylistBaseIE):
IE_NAME = 'bbc.co.uk:iplayer:playlist'
_VALID_URL = r'https?://(?:www\.)?bbc\.co\.uk/iplayer/(?:episodes|group)/(?P<id>%s)' % BBCCoUkIE._ID_REGEX
_URL_TEMPLATE = 'http://www.bbc.co.uk/iplayer/episode/%s'
_VIDEO_ID_TEMPLATE = r'data-ip-id=["\'](%s)'
_TESTS = [{
'url': 'http://www.bbc.co.uk/iplayer/episodes/b05rcz9v',
'info_dict': {
'id': 'b05rcz9v',
'title': 'The Disappearance',
'description': 'French thriller serial about a missing teenager.',
},
'playlist_mincount': 6,
'skip': 'This programme is not currently available on BBC iPlayer',
}, {
# Available for over a year unlike 30 days for most other programmes
'url': 'http://www.bbc.co.uk/iplayer/group/p02tcc32',
'info_dict': {
'id': 'p02tcc32',
'title': 'Bohemian Icons',
'description': 'md5:683e901041b2fe9ba596f2ab04c4dbe7',
},
'playlist_mincount': 10,
}]
def _extract_title_and_description(self, webpage):
title = self._search_regex(r'<h1>([^<]+)</h1>', webpage, 'title', fatal=False)
description = self._search_regex(
r'<p[^>]+class=(["\'])subtitle\1[^>]*>(?P<value>[^<]+)</p>',
webpage, 'description', fatal=False, group='value')
return title, description
class BBCCoUkPlaylistIE(BBCCoUkPlaylistBaseIE):
IE_NAME = 'bbc.co.uk:playlist'
_VALID_URL = r'https?://(?:www\.)?bbc\.co\.uk/programmes/(?P<id>%s)/(?:episodes|broadcasts|clips)' % BBCCoUkIE._ID_REGEX
_URL_TEMPLATE = 'http://www.bbc.co.uk/programmes/%s'
_VIDEO_ID_TEMPLATE = r'data-pid=["\'](%s)'
_TESTS = [{
'url': 'http://www.bbc.co.uk/programmes/b05rcz9v/clips',
'info_dict': {
'id': 'b05rcz9v',
'title': 'The Disappearance - Clips - BBC Four',
'description': 'French thriller serial about a missing teenager.',
},
'playlist_mincount': 7,
}, {
# multipage playlist, explicit page
'url': 'http://www.bbc.co.uk/programmes/b00mfl7n/clips?page=1',
'info_dict': {
'id': 'b00mfl7n',
'title': 'Frozen Planet - Clips - BBC One',
'description': 'md5:65dcbf591ae628dafe32aa6c4a4a0d8c',
},
'playlist_mincount': 24,
}, {
# multipage playlist, all pages
'url': 'http://www.bbc.co.uk/programmes/b00mfl7n/clips',
'info_dict': {
'id': 'b00mfl7n',
'title': 'Frozen Planet - Clips - BBC One',
'description': 'md5:65dcbf591ae628dafe32aa6c4a4a0d8c',
},
'playlist_mincount': 142,
}, {
'url': 'http://www.bbc.co.uk/programmes/b05rcz9v/broadcasts/2016/06',
'only_matching': True,
}, {
'url': 'http://www.bbc.co.uk/programmes/b05rcz9v/clips',
'only_matching': True,
}, {
'url': 'http://www.bbc.co.uk/programmes/b055jkys/episodes/player',
'only_matching': True,
}]
def _extract_title_and_description(self, webpage):
title = self._og_search_title(webpage, fatal=False)
description = self._og_search_description(webpage)
return title, description
|
gpl-2.0
|
[
3,
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
646,
7975,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
3633,
63,
1360,
12,
272,
1211,
63,
362,
12,
272,
19783,
12,
272,
2069,
63,
269,
63,
3592,
12,
272,
664,
63,
2108,
63,
991,
63,
533,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
2198,
63,
5553,
12,
272,
2198,
63,
4595,
15363,
12,
272,
862,
63,
362,
12,
272,
22221,
4943,
12,
272,
16511,
63,
1932,
576,
12,
272,
20818,
12,
199,
9,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
9464,
63,
13521,
12,
272,
8434,
63,
12815,
12,
272,
8434,
63,
10290,
12,
199,
9,
421,
199,
533,
699,
6265,
967,
53,
75,
4332,
8,
18283,
304,
272,
15292,
63,
2339,
275,
283,
27621,
14,
331,
14,
3210,
7,
272,
15292,
63,
15119,
275,
283,
5342,
35,
284,
10921,
7,
272,
485,
998,
63,
10710,
275,
519,
3894,
3317,
30679,
983,
13,
90,
8194,
23,
6834,
272,
485,
5600,
63,
2632,
275,
519,
2344,
2229,
88,
9,
490,
4178,
14144,
717,
16697,
1544,
20316,
27621,
4537,
331,
4537,
3210,
15,
717,
16697,
1169,
2240,
6415,
9448,
1,
19813,
15,
8636,
1169,
3384,
1897,
5169,
15,
26285,
5547,
32576,
9544,
15,
92,
10411,
15,
8636,
1169,
30891,
32576,
2764,
1190,
92,
8130,
3722,
15,
1935,
2238,
2788,
12645,
11752,
1169,
22008,
15,
6147,
15,
717,
776,
717,
7558,
48,
28,
344,
6598,
83,
18168,
1,
32576,
22027,
92,
10786,
83,
92,
2764,
1190,
430,
490,
1449,
450,
485,
998,
63,
10710,
339,
485,
17208,
63,
2632,
275,
283,
2859,
921,
2048,
14,
27621,
14,
957,
15,
1037,
262,
7,
272,
485,
7278,
8205,
63,
20890,
275,
283,
27621,
7,
339,
485,
13669,
25691,
63,
31582,
275,
359,
267,
327,
21552,
869,
49,
869,
5296,
13788,
543,
2755,
8034,
11030,
626,
13171,
5898,
409,
1325,
6918,
267,
327,
543,
8509,
1985,
315,
2005,
5560,
1380,
652,
1159,
2755,
440,
8509,
15297,
737,
1006,
334,
69,
14,
71,
14,
267,
327,
1455,
921,
1544,
14,
27621,
14,
331,
14,
3210,
15,
6815,
6415,
15,
66,
1690,
10913,
23,
276,
680,
6121,
1443,
2449,
543,
7267,
28119,
14,
267,
283,
1014,
921,
1490,
14,
6442,
14,
27621,
14,
331,
14,
3210,
15,
3700,
482,
3283,
15,
21,
15,
2416,
15,
1023,
15,
18,
14,
16,
15,
4603,
409,
15,
10432,
86,
13,
452,
15,
86,
3150,
3149,
83,
297,
267,
283,
1014,
921,
1490,
14,
6442,
14,
27621,
14,
331,
14,
3210,
15,
3700,
482,
3283,
15,
21,
15,
2416,
15,
1023,
15,
18,
14,
16,
15,
4603,
409,
15,
2352,
15,
86,
3150,
3149,
83,
297,
272,
1622,
339,
485,
13669,
4859,
1075,
63,
2709,
275,
283,
1014,
921,
27621,
14,
331,
14,
3210,
15,
9300,
15,
311,
15,
3700,
482,
1486,
7,
272,
485,
37,
1658,
63,
11625,
4924,
63,
2709,
275,
283,
1014,
921,
27621,
14,
331,
14,
3210,
15,
9300,
15,
2109,
15,
10411,
7,
339,
485,
7335,
7613,
21287,
275,
334,
267,
485,
13669,
4859,
1075,
63,
2709,
12,
267,
485,
37,
1658,
63,
11625,
4924,
63,
2709,
12,
272,
776,
339,
485,
7569,
275,
359,
267,
469,
288,
283,
633,
356,
283,
1014,
921,
1544,
14,
27621,
14,
331,
14,
3210,
15,
6815,
6415,
15,
66,
10005,
71,
24,
80,
23,
297,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
66,
10005,
68,
1780,
77,
297,
355,
283,
832,
356,
283,
22753,
297,
355,
283,
1213,
356,
283,
2553,
265,
1005,
1849,
16800,
12,
1804,
1895,
344,
736,
1859,
446,
699,
6265,
13514,
841,
297,
355,
283,
1802,
356,
283,
1918,
445,
6738,
6268,
1115,
386,
436,
20178,
5491,
16806,
83,
641,
17049,
8504,
7476,
10296,
281,
3130,
288,
1660,
288,
283,
1162,
356,
469,
355,
327,
519,
2791,
5235,
355,
283,
2759,
63,
4249,
356,
715,
12,
288,
789,
267,
1660,
267,
469,
288,
283,
633,
356,
283,
1014,
921,
1544,
14,
27621,
14,
331,
14,
3210,
15,
711,
1897,
15,
9544,
15,
66,
383,
1236,
71,
21,
87,
15,
1918,
63,
2395,
63,
262,
63,
23405,
63,
9641,
63,
19,
63,
1918,
63,
9779,
9082,
63,
985,
3678,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
66,
383,
1236,
71,
17,
68,
297,
355,
283,
832,
356,
283,
22753,
297,
355,
283,
1213,
356,
283,
1918,
4688,
315,
30593,
26,
12403,
650,
26,
710,
25716,
9082,
2812,
297,
355,
283,
1802,
356,
298,
6470,
598,
2159,
385,
13318,
10569,
653,
1158,
393,
305,
510,
4446,
10384,
1159,
682,
12687,
307,
1895,
402,
282,
7060,
1159,
29052,
1891,
691,
319,
543,
282,
333,
588,
6236,
1785,
2169,
14,
1933,
4291,
662,
20444,
699,
65,
441,
89,
4765,
355,
283,
5553,
356,
6155,
383,
12,
288,
1660,
288,
283,
1162,
356,
469,
355,
327,
519,
2791,
5235,
355,
283,
2759,
63,
4249,
356,
715,
12,
288,
1660,
288,
283,
2759,
356,
283,
22887,
365,
949,
8088,
2808,
641,
699,
6265,
284,
10921,
13514,
297,
267,
1660,
267,
469,
288,
283,
633,
356,
283,
1014,
921,
1544,
14,
27621,
14,
331,
14,
3210,
15,
711,
1897,
15,
9544,
15,
66,
1644,
20961,
17,
70,
15,
1918,
63,
23956,
1885,
63,
26667,
63,
9641,
63,
19,
63,
34,
24491,
63,
15900,
3138,
63,
21,
3678,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
66,
383,
1236,
71,
17,
68,
297,
355,
283,
832,
356,
283,
22753,
297,
355,
283,
1213,
356,
283,
1918,
32665,
1885,
738,
43,
26,
12403,
650,
26,
699,
24491,
31853,
3138,
959,
297,
355,
283,
1802,
356,
283,
37,
77,
391,
644,
8148,
83,
436,
16794,
11908,
869,
940,
83,
3451,
314,
289,
11509,
663,
402,
330,
24491,
10576,
3138,
315,
314,
308,
316,
316,
1013,
69,
3348,
12,
465,
314,
512,
1225,
397,
1980,
370,
1900,
3932,
25823,
4079,
641,
26563,
23016,
3130,
355,
283,
5553,
356,
959,
1960,
12,
288,
1660,
288,
283,
1162,
356,
469,
355,
327,
519,
2791,
5235,
355,
283,
2759,
63,
4249,
356,
715,
12,
288,
1660,
288,
283,
2759
] |
[
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
646,
7975,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
3633,
63,
1360,
12,
272,
1211,
63,
362,
12,
272,
19783,
12,
272,
2069,
63,
269,
63,
3592,
12,
272,
664,
63,
2108,
63,
991,
63,
533,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
2198,
63,
5553,
12,
272,
2198,
63,
4595,
15363,
12,
272,
862,
63,
362,
12,
272,
22221,
4943,
12,
272,
16511,
63,
1932,
576,
12,
272,
20818,
12,
199,
9,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
9464,
63,
13521,
12,
272,
8434,
63,
12815,
12,
272,
8434,
63,
10290,
12,
199,
9,
421,
199,
533,
699,
6265,
967,
53,
75,
4332,
8,
18283,
304,
272,
15292,
63,
2339,
275,
283,
27621,
14,
331,
14,
3210,
7,
272,
15292,
63,
15119,
275,
283,
5342,
35,
284,
10921,
7,
272,
485,
998,
63,
10710,
275,
519,
3894,
3317,
30679,
983,
13,
90,
8194,
23,
6834,
272,
485,
5600,
63,
2632,
275,
519,
2344,
2229,
88,
9,
490,
4178,
14144,
717,
16697,
1544,
20316,
27621,
4537,
331,
4537,
3210,
15,
717,
16697,
1169,
2240,
6415,
9448,
1,
19813,
15,
8636,
1169,
3384,
1897,
5169,
15,
26285,
5547,
32576,
9544,
15,
92,
10411,
15,
8636,
1169,
30891,
32576,
2764,
1190,
92,
8130,
3722,
15,
1935,
2238,
2788,
12645,
11752,
1169,
22008,
15,
6147,
15,
717,
776,
717,
7558,
48,
28,
344,
6598,
83,
18168,
1,
32576,
22027,
92,
10786,
83,
92,
2764,
1190,
430,
490,
1449,
450,
485,
998,
63,
10710,
339,
485,
17208,
63,
2632,
275,
283,
2859,
921,
2048,
14,
27621,
14,
957,
15,
1037,
262,
7,
272,
485,
7278,
8205,
63,
20890,
275,
283,
27621,
7,
339,
485,
13669,
25691,
63,
31582,
275,
359,
267,
327,
21552,
869,
49,
869,
5296,
13788,
543,
2755,
8034,
11030,
626,
13171,
5898,
409,
1325,
6918,
267,
327,
543,
8509,
1985,
315,
2005,
5560,
1380,
652,
1159,
2755,
440,
8509,
15297,
737,
1006,
334,
69,
14,
71,
14,
267,
327,
1455,
921,
1544,
14,
27621,
14,
331,
14,
3210,
15,
6815,
6415,
15,
66,
1690,
10913,
23,
276,
680,
6121,
1443,
2449,
543,
7267,
28119,
14,
267,
283,
1014,
921,
1490,
14,
6442,
14,
27621,
14,
331,
14,
3210,
15,
3700,
482,
3283,
15,
21,
15,
2416,
15,
1023,
15,
18,
14,
16,
15,
4603,
409,
15,
10432,
86,
13,
452,
15,
86,
3150,
3149,
83,
297,
267,
283,
1014,
921,
1490,
14,
6442,
14,
27621,
14,
331,
14,
3210,
15,
3700,
482,
3283,
15,
21,
15,
2416,
15,
1023,
15,
18,
14,
16,
15,
4603,
409,
15,
2352,
15,
86,
3150,
3149,
83,
297,
272,
1622,
339,
485,
13669,
4859,
1075,
63,
2709,
275,
283,
1014,
921,
27621,
14,
331,
14,
3210,
15,
9300,
15,
311,
15,
3700,
482,
1486,
7,
272,
485,
37,
1658,
63,
11625,
4924,
63,
2709,
275,
283,
1014,
921,
27621,
14,
331,
14,
3210,
15,
9300,
15,
2109,
15,
10411,
7,
339,
485,
7335,
7613,
21287,
275,
334,
267,
485,
13669,
4859,
1075,
63,
2709,
12,
267,
485,
37,
1658,
63,
11625,
4924,
63,
2709,
12,
272,
776,
339,
485,
7569,
275,
359,
267,
469,
288,
283,
633,
356,
283,
1014,
921,
1544,
14,
27621,
14,
331,
14,
3210,
15,
6815,
6415,
15,
66,
10005,
71,
24,
80,
23,
297,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
66,
10005,
68,
1780,
77,
297,
355,
283,
832,
356,
283,
22753,
297,
355,
283,
1213,
356,
283,
2553,
265,
1005,
1849,
16800,
12,
1804,
1895,
344,
736,
1859,
446,
699,
6265,
13514,
841,
297,
355,
283,
1802,
356,
283,
1918,
445,
6738,
6268,
1115,
386,
436,
20178,
5491,
16806,
83,
641,
17049,
8504,
7476,
10296,
281,
3130,
288,
1660,
288,
283,
1162,
356,
469,
355,
327,
519,
2791,
5235,
355,
283,
2759,
63,
4249,
356,
715,
12,
288,
789,
267,
1660,
267,
469,
288,
283,
633,
356,
283,
1014,
921,
1544,
14,
27621,
14,
331,
14,
3210,
15,
711,
1897,
15,
9544,
15,
66,
383,
1236,
71,
21,
87,
15,
1918,
63,
2395,
63,
262,
63,
23405,
63,
9641,
63,
19,
63,
1918,
63,
9779,
9082,
63,
985,
3678,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
66,
383,
1236,
71,
17,
68,
297,
355,
283,
832,
356,
283,
22753,
297,
355,
283,
1213,
356,
283,
1918,
4688,
315,
30593,
26,
12403,
650,
26,
710,
25716,
9082,
2812,
297,
355,
283,
1802,
356,
298,
6470,
598,
2159,
385,
13318,
10569,
653,
1158,
393,
305,
510,
4446,
10384,
1159,
682,
12687,
307,
1895,
402,
282,
7060,
1159,
29052,
1891,
691,
319,
543,
282,
333,
588,
6236,
1785,
2169,
14,
1933,
4291,
662,
20444,
699,
65,
441,
89,
4765,
355,
283,
5553,
356,
6155,
383,
12,
288,
1660,
288,
283,
1162,
356,
469,
355,
327,
519,
2791,
5235,
355,
283,
2759,
63,
4249,
356,
715,
12,
288,
1660,
288,
283,
2759,
356,
283,
22887,
365,
949,
8088,
2808,
641,
699,
6265,
284,
10921,
13514,
297,
267,
1660,
267,
469,
288,
283,
633,
356,
283,
1014,
921,
1544,
14,
27621,
14,
331,
14,
3210,
15,
711,
1897,
15,
9544,
15,
66,
1644,
20961,
17,
70,
15,
1918,
63,
23956,
1885,
63,
26667,
63,
9641,
63,
19,
63,
34,
24491,
63,
15900,
3138,
63,
21,
3678,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
66,
383,
1236,
71,
17,
68,
297,
355,
283,
832,
356,
283,
22753,
297,
355,
283,
1213,
356,
283,
1918,
32665,
1885,
738,
43,
26,
12403,
650,
26,
699,
24491,
31853,
3138,
959,
297,
355,
283,
1802,
356,
283,
37,
77,
391,
644,
8148,
83,
436,
16794,
11908,
869,
940,
83,
3451,
314,
289,
11509,
663,
402,
330,
24491,
10576,
3138,
315,
314,
308,
316,
316,
1013,
69,
3348,
12,
465,
314,
512,
1225,
397,
1980,
370,
1900,
3932,
25823,
4079,
641,
26563,
23016,
3130,
355,
283,
5553,
356,
959,
1960,
12,
288,
1660,
288,
283,
1162,
356,
469,
355,
327,
519,
2791,
5235,
355,
283,
2759,
63,
4249,
356,
715,
12,
288,
1660,
288,
283,
2759,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
JanSchulz/multi-package-feedstock
|
recipes/python-2.7.8/run_test.py
|
1
|
1289
|
import platform
import os
import sys
import subprocess
from pprint import pprint
print('Python version:', platform.python_version())
print('max unicode:', sys.maxunicode)
print('architecture:', platform.architecture())
print('sys.version:', sys.version)
print('platform.machine():', platform.machine())
import _bisect
import _codecs_cn
import _codecs_hk
import _codecs_iso2022
import _codecs_jp
import _codecs_kr
import _codecs_tw
import _collections
import _csv
import _ctypes
import _ctypes_test
import _elementtree
import _functools
import _hashlib
import _heapq
import _hotshot
import _io
import _json
import _locale
import _lsprof
import _multibytecodec
import _multiprocessing
import _random
import _socket
import _sqlite3
import _ssl
import _struct
import _testcapi
import array
import audioop
import binascii
import bz2
import cPickle
import cStringIO
import cmath
import datetime
import future_builtins
import itertools
import math
import mmap
import operator
import parser
import pyexpat
#import resource
import select
import strop
#import syslog
import time
import unicodedata
import zlib
import gzip
from os import urandom
if sys.platform != 'win32':
import crypt
import fcntl
import grp
import nis
import ssl
print('OPENSSL_VERSION:', ssl.OPENSSL_VERSION)
|
bsd-3-clause
|
[
646,
4298,
199,
646,
747,
199,
646,
984,
199,
646,
3873,
199,
504,
10933,
492,
10933,
199,
199,
1361,
360,
4718,
1015,
6536,
4298,
14,
1548,
63,
1023,
1012,
199,
1361,
360,
988,
2649,
6536,
984,
14,
988,
2975,
9,
199,
1361,
360,
19134,
6536,
4298,
14,
19134,
1012,
199,
1361,
360,
1274,
14,
1023,
6536,
984,
14,
1023,
9,
199,
1361,
360,
3246,
14,
6744,
837,
297,
4298,
14,
6744,
1012,
199,
199,
646,
485,
23247,
199,
646,
485,
8933,
63,
6413,
199,
646,
485,
8933,
63,
21557,
199,
646,
485,
8933,
63,
4595,
13859,
199,
646,
485,
8933,
63,
11538,
199,
646,
485,
8933,
63,
16779,
199,
646,
485,
8933,
63,
8122,
199,
646,
485,
7882,
199,
646,
485,
4737,
199,
646,
485,
9798,
199,
646,
485,
9798,
63,
396,
199,
646,
485,
2108,
2350,
199,
646,
485,
17869,
199,
646,
485,
24722,
199,
646,
485,
12492,
81,
199,
646,
485,
8885,
2782,
199,
646,
485,
2308,
199,
646,
485,
1001,
199,
646,
485,
5508,
199,
646,
485,
478,
14979,
199,
646,
485,
3029,
4414,
9276,
199,
646,
485,
25725,
199,
646,
485,
2355,
199,
646,
485,
3450,
199,
646,
485,
10659,
19,
199,
646,
485,
4266,
199,
646,
485,
1820,
199,
646,
485,
396,
14145,
199,
646,
1625,
199,
646,
10491,
411,
199,
646,
14755,
199,
646,
15055,
18,
199,
646,
17572,
199,
646,
15073,
199,
646,
286,
3442,
199,
646,
2197,
199,
646,
6466,
63,
10372,
199,
646,
7975,
199,
646,
3473,
199,
646,
21991,
199,
646,
4182,
199,
646,
1798,
199,
646,
1134,
27098,
199,
3,
646,
2073,
199,
646,
3504,
199,
646,
410,
2675,
199,
3,
646,
22112,
199,
646,
900,
199,
646,
23128,
199,
646,
12472,
199,
646,
11756,
199,
504,
747,
492,
7629,
1241,
199,
199,
692,
984,
14,
3246,
1137,
283,
2676,
708,
356,
272,
492,
21570,
272,
492,
12871,
272,
492,
18598,
272,
492,
302,
374,
199,
199,
646,
6149,
199,
1361,
360,
9935,
5413,
63,
4612,
6536,
6149,
14,
9935,
5413,
63,
4612,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4298,
199,
646,
747,
199,
646,
984,
199,
646,
3873,
199,
504,
10933,
492,
10933,
199,
199,
1361,
360,
4718,
1015,
6536,
4298,
14,
1548,
63,
1023,
1012,
199,
1361,
360,
988,
2649,
6536,
984,
14,
988,
2975,
9,
199,
1361,
360,
19134,
6536,
4298,
14,
19134,
1012,
199,
1361,
360,
1274,
14,
1023,
6536,
984,
14,
1023,
9,
199,
1361,
360,
3246,
14,
6744,
837,
297,
4298,
14,
6744,
1012,
199,
199,
646,
485,
23247,
199,
646,
485,
8933,
63,
6413,
199,
646,
485,
8933,
63,
21557,
199,
646,
485,
8933,
63,
4595,
13859,
199,
646,
485,
8933,
63,
11538,
199,
646,
485,
8933,
63,
16779,
199,
646,
485,
8933,
63,
8122,
199,
646,
485,
7882,
199,
646,
485,
4737,
199,
646,
485,
9798,
199,
646,
485,
9798,
63,
396,
199,
646,
485,
2108,
2350,
199,
646,
485,
17869,
199,
646,
485,
24722,
199,
646,
485,
12492,
81,
199,
646,
485,
8885,
2782,
199,
646,
485,
2308,
199,
646,
485,
1001,
199,
646,
485,
5508,
199,
646,
485,
478,
14979,
199,
646,
485,
3029,
4414,
9276,
199,
646,
485,
25725,
199,
646,
485,
2355,
199,
646,
485,
3450,
199,
646,
485,
10659,
19,
199,
646,
485,
4266,
199,
646,
485,
1820,
199,
646,
485,
396,
14145,
199,
646,
1625,
199,
646,
10491,
411,
199,
646,
14755,
199,
646,
15055,
18,
199,
646,
17572,
199,
646,
15073,
199,
646,
286,
3442,
199,
646,
2197,
199,
646,
6466,
63,
10372,
199,
646,
7975,
199,
646,
3473,
199,
646,
21991,
199,
646,
4182,
199,
646,
1798,
199,
646,
1134,
27098,
199,
3,
646,
2073,
199,
646,
3504,
199,
646,
410,
2675,
199,
3,
646,
22112,
199,
646,
900,
199,
646,
23128,
199,
646,
12472,
199,
646,
11756,
199,
504,
747,
492,
7629,
1241,
199,
199,
692,
984,
14,
3246,
1137,
283,
2676,
708,
356,
272,
492,
21570,
272,
492,
12871,
272,
492,
18598,
272,
492,
302,
374,
199,
199,
646,
6149,
199,
1361,
360,
9935,
5413,
63,
4612,
6536,
6149,
14,
9935,
5413,
63,
4612,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
GiovanniConserva/TestDeploy
|
venv/Lib/site-packages/django/db/backends/sqlite3/base.py
|
323
|
18115
|
"""
SQLite3 backend for django.
Works with either the pysqlite2 module or the sqlite3 module in the
standard library.
"""
from __future__ import unicode_literals
import datetime
import decimal
import re
import warnings
from django.conf import settings
from django.db import utils
from django.db.backends import utils as backend_utils
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.backends.base.validation import BaseDatabaseValidation
from django.utils import six, timezone
from django.utils.dateparse import (
parse_date, parse_datetime, parse_duration, parse_time,
)
from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.encoding import force_text
from django.utils.safestring import SafeBytes
try:
import pytz
except ImportError:
pytz = None
try:
try:
from pysqlite2 import dbapi2 as Database
except ImportError:
from sqlite3 import dbapi2 as Database
except ImportError as exc:
from django.core.exceptions import ImproperlyConfigured
raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
# Some of these import sqlite3, so import them after checking if it's installed.
from .client import DatabaseClient # isort:skip
from .creation import DatabaseCreation # isort:skip
from .features import DatabaseFeatures # isort:skip
from .introspection import DatabaseIntrospection # isort:skip
from .operations import DatabaseOperations # isort:skip
from .schema import DatabaseSchemaEditor # isort:skip
DatabaseError = Database.DatabaseError
IntegrityError = Database.IntegrityError
def adapt_datetime_warn_on_aware_datetime(value):
# Remove this function and rely on the default adapter in Django 2.0.
if settings.USE_TZ and timezone.is_aware(value):
warnings.warn(
"The SQLite database adapter received an aware datetime (%s), "
"probably from cursor.execute(). Update your code to pass a "
"naive datetime in the database connection's time zone (UTC by "
"default).", RemovedInDjango20Warning)
# This doesn't account for the database connection's timezone,
# which isn't known. (That's why this adapter is deprecated.)
value = value.astimezone(timezone.utc).replace(tzinfo=None)
return value.isoformat(str(" "))
def decoder(conv_func):
""" The Python sqlite3 interface returns always byte strings.
This function converts the received value to a regular string before
passing it to the receiver function.
"""
return lambda s: conv_func(s.decode('utf-8'))
Database.register_converter(str("bool"), decoder(lambda s: s == '1'))
Database.register_converter(str("time"), decoder(parse_time))
Database.register_converter(str("date"), decoder(parse_date))
Database.register_converter(str("datetime"), decoder(parse_datetime))
Database.register_converter(str("timestamp"), decoder(parse_datetime))
Database.register_converter(str("TIMESTAMP"), decoder(parse_datetime))
Database.register_converter(str("decimal"), decoder(backend_utils.typecast_decimal))
Database.register_adapter(datetime.datetime, adapt_datetime_warn_on_aware_datetime)
Database.register_adapter(decimal.Decimal, backend_utils.rev_typecast_decimal)
if six.PY2:
Database.register_adapter(str, lambda s: s.decode('utf-8'))
Database.register_adapter(SafeBytes, lambda s: s.decode('utf-8'))
class DatabaseWrapper(BaseDatabaseWrapper):
vendor = 'sqlite'
# SQLite doesn't actually support most of these types, but it "does the right
# thing" given more verbose field definitions, so leave them as is so that
# schema inspection is more useful.
data_types = {
'AutoField': 'integer',
'BinaryField': 'BLOB',
'BooleanField': 'bool',
'CharField': 'varchar(%(max_length)s)',
'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
'DateField': 'date',
'DateTimeField': 'datetime',
'DecimalField': 'decimal',
'DurationField': 'bigint',
'FileField': 'varchar(%(max_length)s)',
'FilePathField': 'varchar(%(max_length)s)',
'FloatField': 'real',
'IntegerField': 'integer',
'BigIntegerField': 'bigint',
'IPAddressField': 'char(15)',
'GenericIPAddressField': 'char(39)',
'NullBooleanField': 'bool',
'OneToOneField': 'integer',
'PositiveIntegerField': 'integer unsigned',
'PositiveSmallIntegerField': 'smallint unsigned',
'SlugField': 'varchar(%(max_length)s)',
'SmallIntegerField': 'smallint',
'TextField': 'text',
'TimeField': 'time',
'UUIDField': 'char(32)',
}
data_types_suffix = {
'AutoField': 'AUTOINCREMENT',
}
# SQLite requires LIKE statements to include an ESCAPE clause if the value
# being escaped has a percent or underscore in it.
# See http://www.sqlite.org/lang_expr.html for an explanation.
operators = {
'exact': '= %s',
'iexact': "LIKE %s ESCAPE '\\'",
'contains': "LIKE %s ESCAPE '\\'",
'icontains': "LIKE %s ESCAPE '\\'",
'regex': 'REGEXP %s',
'iregex': "REGEXP '(?i)' || %s",
'gt': '> %s',
'gte': '>= %s',
'lt': '< %s',
'lte': '<= %s',
'startswith': "LIKE %s ESCAPE '\\'",
'endswith': "LIKE %s ESCAPE '\\'",
'istartswith': "LIKE %s ESCAPE '\\'",
'iendswith': "LIKE %s ESCAPE '\\'",
}
# The patterns below are used to generate SQL pattern lookup clauses when
# the right-hand side of the lookup isn't a raw string (it might be an expression
# or the result of a bilateral transformation).
# In those cases, special characters for LIKE operators (e.g. \, *, _) should be
# escaped on database side.
#
# Note: we use str.format() here for readability as '%' is used as a wildcard for
# the LIKE operator.
pattern_esc = r"REPLACE(REPLACE(REPLACE({}, '\', '\\'), '%%', '\%%'), '_', '\_')"
pattern_ops = {
'contains': r"LIKE '%%' || {} || '%%' ESCAPE '\'",
'icontains': r"LIKE '%%' || UPPER({}) || '%%' ESCAPE '\'",
'startswith': r"LIKE {} || '%%' ESCAPE '\'",
'istartswith': r"LIKE UPPER({}) || '%%' ESCAPE '\'",
'endswith': r"LIKE '%%' || {} ESCAPE '\'",
'iendswith': r"LIKE '%%' || UPPER({}) ESCAPE '\'",
}
Database = Database
SchemaEditorClass = DatabaseSchemaEditor
def __init__(self, *args, **kwargs):
super(DatabaseWrapper, self).__init__(*args, **kwargs)
self.features = DatabaseFeatures(self)
self.ops = DatabaseOperations(self)
self.client = DatabaseClient(self)
self.creation = DatabaseCreation(self)
self.introspection = DatabaseIntrospection(self)
self.validation = BaseDatabaseValidation(self)
def get_connection_params(self):
settings_dict = self.settings_dict
if not settings_dict['NAME']:
from django.core.exceptions import ImproperlyConfigured
raise ImproperlyConfigured(
"settings.DATABASES is improperly configured. "
"Please supply the NAME value.")
kwargs = {
'database': settings_dict['NAME'],
'detect_types': Database.PARSE_DECLTYPES | Database.PARSE_COLNAMES,
}
kwargs.update(settings_dict['OPTIONS'])
# Always allow the underlying SQLite connection to be shareable
# between multiple threads. The safe-guarding will be handled at a
# higher level by the `BaseDatabaseWrapper.allow_thread_sharing`
# property. This is necessary as the shareability is disabled by
# default in pysqlite and it cannot be changed once a connection is
# opened.
if 'check_same_thread' in kwargs and kwargs['check_same_thread']:
warnings.warn(
'The `check_same_thread` option was provided and set to '
'True. It will be overridden with False. Use the '
'`DatabaseWrapper.allow_thread_sharing` property instead '
'for controlling thread shareability.',
RuntimeWarning
)
kwargs.update({'check_same_thread': False})
if self.features.can_share_in_memory_db:
kwargs.update({'uri': True})
return kwargs
def get_new_connection(self, conn_params):
conn = Database.connect(**conn_params)
conn.create_function("django_date_extract", 2, _sqlite_date_extract)
conn.create_function("django_date_trunc", 2, _sqlite_date_trunc)
conn.create_function("django_datetime_cast_date", 2, _sqlite_datetime_cast_date)
conn.create_function("django_datetime_extract", 3, _sqlite_datetime_extract)
conn.create_function("django_datetime_trunc", 3, _sqlite_datetime_trunc)
conn.create_function("django_time_extract", 2, _sqlite_time_extract)
conn.create_function("regexp", 2, _sqlite_regexp)
conn.create_function("django_format_dtdelta", 3, _sqlite_format_dtdelta)
conn.create_function("django_power", 2, _sqlite_power)
return conn
def init_connection_state(self):
pass
def create_cursor(self):
return self.connection.cursor(factory=SQLiteCursorWrapper)
def close(self):
self.validate_thread_sharing()
# If database is in memory, closing the connection destroys the
# database. To prevent accidental data loss, ignore close requests on
# an in-memory db.
if not self.is_in_memory_db(self.settings_dict['NAME']):
BaseDatabaseWrapper.close(self)
def _savepoint_allowed(self):
# Two conditions are required here:
# - A sufficiently recent version of SQLite to support savepoints,
# - Being in a transaction, which can only happen inside 'atomic'.
# When 'isolation_level' is not None, sqlite3 commits before each
# savepoint; it's a bug. When it is None, savepoints don't make sense
# because autocommit is enabled. The only exception is inside 'atomic'
# blocks. To work around that bug, on SQLite, 'atomic' starts a
# transaction explicitly rather than simply disable autocommit.
return self.features.uses_savepoints and self.in_atomic_block
def _set_autocommit(self, autocommit):
if autocommit:
level = None
else:
# sqlite3's internal default is ''. It's different from None.
# See Modules/_sqlite/connection.c.
level = ''
# 'isolation_level' is a misleading API.
# SQLite always runs at the SERIALIZABLE isolation level.
with self.wrap_database_errors:
self.connection.isolation_level = level
def check_constraints(self, table_names=None):
"""
Checks each table name in `table_names` for rows with invalid foreign
key references. This method is intended to be used in conjunction with
`disable_constraint_checking()` and `enable_constraint_checking()`, to
determine if rows with invalid references were entered while constraint
checks were off.
Raises an IntegrityError on the first invalid foreign key reference
encountered (if any) and provides detailed information about the
invalid reference in the error message.
Backends can override this method if they can more directly apply
constraint checking (e.g. via "SET CONSTRAINTS ALL IMMEDIATE")
"""
cursor = self.cursor()
if table_names is None:
table_names = self.introspection.table_names(cursor)
for table_name in table_names:
primary_key_column_name = self.introspection.get_primary_key_column(cursor, table_name)
if not primary_key_column_name:
continue
key_columns = self.introspection.get_key_columns(cursor, table_name)
for column_name, referenced_table_name, referenced_column_name in key_columns:
cursor.execute("""
SELECT REFERRING.`%s`, REFERRING.`%s` FROM `%s` as REFERRING
LEFT JOIN `%s` as REFERRED
ON (REFERRING.`%s` = REFERRED.`%s`)
WHERE REFERRING.`%s` IS NOT NULL AND REFERRED.`%s` IS NULL"""
% (primary_key_column_name, column_name, table_name, referenced_table_name,
column_name, referenced_column_name, column_name, referenced_column_name))
for bad_row in cursor.fetchall():
raise utils.IntegrityError("The row in table '%s' with primary key '%s' has an invalid "
"foreign key: %s.%s contains a value '%s' that does not have a corresponding value in %s.%s."
% (table_name, bad_row[0], table_name, column_name, bad_row[1],
referenced_table_name, referenced_column_name))
def is_usable(self):
return True
def _start_transaction_under_autocommit(self):
"""
Start a transaction explicitly in autocommit mode.
Staying in autocommit mode works around a bug of sqlite3 that breaks
savepoints when autocommit is disabled.
"""
self.cursor().execute("BEGIN")
def is_in_memory_db(self, name):
return name == ":memory:" or "mode=memory" in force_text(name)
FORMAT_QMARK_REGEX = re.compile(r'(?<!%)%s')
class SQLiteCursorWrapper(Database.Cursor):
"""
Django uses "format" style placeholders, but pysqlite2 uses "qmark" style.
This fixes it -- but note that if you want to use a literal "%s" in a query,
you'll need to use "%%s".
"""
def execute(self, query, params=None):
if params is None:
return Database.Cursor.execute(self, query)
query = self.convert_query(query)
return Database.Cursor.execute(self, query, params)
def executemany(self, query, param_list):
query = self.convert_query(query)
return Database.Cursor.executemany(self, query, param_list)
def convert_query(self, query):
return FORMAT_QMARK_REGEX.sub('?', query).replace('%%', '%')
def _sqlite_date_extract(lookup_type, dt):
if dt is None:
return None
try:
dt = backend_utils.typecast_timestamp(dt)
except (ValueError, TypeError):
return None
if lookup_type == 'week_day':
return (dt.isoweekday() % 7) + 1
else:
return getattr(dt, lookup_type)
def _sqlite_date_trunc(lookup_type, dt):
try:
dt = backend_utils.typecast_timestamp(dt)
except (ValueError, TypeError):
return None
if lookup_type == 'year':
return "%i-01-01" % dt.year
elif lookup_type == 'month':
return "%i-%02i-01" % (dt.year, dt.month)
elif lookup_type == 'day':
return "%i-%02i-%02i" % (dt.year, dt.month, dt.day)
def _sqlite_datetime_parse(dt, tzname):
if dt is None:
return None
try:
dt = backend_utils.typecast_timestamp(dt)
except (ValueError, TypeError):
return None
if tzname is not None:
dt = timezone.localtime(dt, pytz.timezone(tzname))
return dt
def _sqlite_datetime_cast_date(dt, tzname):
dt = _sqlite_datetime_parse(dt, tzname)
if dt is None:
return None
return dt.date().isoformat()
def _sqlite_datetime_extract(lookup_type, dt, tzname):
dt = _sqlite_datetime_parse(dt, tzname)
if dt is None:
return None
if lookup_type == 'week_day':
return (dt.isoweekday() % 7) + 1
else:
return getattr(dt, lookup_type)
def _sqlite_datetime_trunc(lookup_type, dt, tzname):
dt = _sqlite_datetime_parse(dt, tzname)
if dt is None:
return None
if lookup_type == 'year':
return "%i-01-01 00:00:00" % dt.year
elif lookup_type == 'month':
return "%i-%02i-01 00:00:00" % (dt.year, dt.month)
elif lookup_type == 'day':
return "%i-%02i-%02i 00:00:00" % (dt.year, dt.month, dt.day)
elif lookup_type == 'hour':
return "%i-%02i-%02i %02i:00:00" % (dt.year, dt.month, dt.day, dt.hour)
elif lookup_type == 'minute':
return "%i-%02i-%02i %02i:%02i:00" % (dt.year, dt.month, dt.day, dt.hour, dt.minute)
elif lookup_type == 'second':
return "%i-%02i-%02i %02i:%02i:%02i" % (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second)
def _sqlite_time_extract(lookup_type, dt):
if dt is None:
return None
try:
dt = backend_utils.typecast_time(dt)
except (ValueError, TypeError):
return None
return getattr(dt, lookup_type)
def _sqlite_format_dtdelta(conn, lhs, rhs):
"""
LHS and RHS can be either:
- An integer number of microseconds
- A string representing a timedelta object
- A string representing a datetime
"""
try:
if isinstance(lhs, six.integer_types):
lhs = str(decimal.Decimal(lhs) / decimal.Decimal(1000000))
real_lhs = parse_duration(lhs)
if real_lhs is None:
real_lhs = backend_utils.typecast_timestamp(lhs)
if isinstance(rhs, six.integer_types):
rhs = str(decimal.Decimal(rhs) / decimal.Decimal(1000000))
real_rhs = parse_duration(rhs)
if real_rhs is None:
real_rhs = backend_utils.typecast_timestamp(rhs)
if conn.strip() == '+':
out = real_lhs + real_rhs
else:
out = real_lhs - real_rhs
except (ValueError, TypeError):
return None
# typecast_timestamp returns a date or a datetime without timezone.
# It will be formatted as "%Y-%m-%d" or "%Y-%m-%d %H:%M:%S[.%f]"
return str(out)
def _sqlite_regexp(re_pattern, re_string):
return bool(re.search(re_pattern, force_text(re_string))) if re_string is not None else False
def _sqlite_power(x, y):
return x ** y
|
bsd-3-clause
|
[
624,
199,
4657,
1175,
19,
4865,
367,
1639,
14,
199,
199,
25348,
543,
1902,
314,
10382,
29498,
18,
859,
503,
314,
11723,
19,
859,
315,
314,
199,
6807,
3555,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
646,
6107,
199,
646,
295,
199,
646,
3598,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
697,
492,
3778,
199,
504,
1639,
14,
697,
14,
7765,
492,
3778,
465,
4865,
63,
1208,
199,
504,
1639,
14,
697,
14,
7765,
14,
1095,
14,
1095,
492,
29103,
4590,
199,
504,
1639,
14,
697,
14,
7765,
14,
1095,
14,
6136,
492,
29103,
13816,
199,
504,
1639,
14,
1208,
492,
3816,
12,
7137,
199,
504,
1639,
14,
1208,
14,
602,
1122,
492,
334,
272,
2198,
63,
602,
12,
2198,
63,
2083,
12,
2198,
63,
5553,
12,
2198,
63,
521,
12,
199,
9,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
1165,
3849,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
28389,
492,
14969,
5571,
199,
199,
893,
26,
272,
492,
15444,
199,
2590,
3545,
26,
272,
15444,
275,
488,
199,
199,
893,
26,
272,
862,
26,
267,
687,
10382,
29498,
18,
492,
29333,
18,
465,
8692,
272,
871,
3545,
26,
267,
687,
11723,
19,
492,
29333,
18,
465,
8692,
199,
2590,
3545,
465,
3178,
26,
272,
687,
1639,
14,
1018,
14,
3924,
492,
11897,
272,
746,
11897,
480,
547,
8697,
1902,
10382,
29498,
18,
503,
11723,
19,
4621,
334,
599,
379,
315,
626,
1865,
304,
450,
83,
2,
450,
3178,
9,
199,
199,
3,
6601,
402,
3520,
492,
11723,
19,
12,
880,
492,
3062,
2410,
7907,
340,
652,
1159,
4903,
14,
199,
504,
1275,
1258,
492,
8692,
3041,
14516,
327,
365,
361,
26,
2759,
199,
504,
1275,
8782,
492,
8692,
13921,
10473,
327,
365,
361,
26,
2759,
199,
504,
1275,
3179,
492,
8692,
10807,
10473,
327,
365,
361,
26,
2759,
199,
504,
1275,
21627,
492,
8692,
30516,
3322,
327,
365,
361,
26,
2759,
199,
504,
1275,
8170,
492,
8692,
12929,
8295,
327,
365,
361,
26,
2759,
199,
504,
1275,
3629,
492,
8692,
6700,
10423,
8540,
327,
365,
361,
26,
2759,
199,
199,
25198,
275,
8692,
14,
25198,
199,
24823,
275,
8692,
14,
24823,
421,
199,
318,
19520,
63,
2083,
63,
4050,
63,
265,
63,
14600,
63,
2083,
8,
585,
304,
272,
327,
5852,
642,
805,
436,
19687,
641,
314,
849,
12146,
315,
5634,
499,
14,
16,
14,
272,
340,
2202,
14,
4701,
63,
14226,
436,
7137,
14,
374,
63,
14600,
8,
585,
304,
267,
3598,
14,
4050,
8,
288,
298,
1918,
19245,
3050,
12146,
3086,
376,
20381,
2197,
4366,
83,
395,
298,
288,
298,
6101,
6665,
687,
3920,
14,
2526,
1252,
6162,
2195,
1233,
370,
986,
282,
298,
288,
298,
21578,
2197,
315,
314,
3050,
1950,
1159,
900,
5718,
334,
11288,
701,
298,
288,
298,
885,
680,
401,
23687,
1165,
3849,
9,
267,
327,
961,
3181,
1133,
2933,
367,
314,
3050,
1950,
1159,
7137,
12,
267,
327,
1314,
5712,
1133,
6040,
14,
334,
17231,
1159,
10842,
642,
12146,
365,
5906,
4959,
267,
574,
275,
574,
14,
29648,
8,
7145,
14,
5834,
680,
1814,
8,
9374,
29,
403,
9,
272,
372,
574,
14,
17070,
8,
495,
480,
26725,
421,
199,
318,
10334,
8,
5598,
63,
1532,
304,
272,
408,
710,
2018,
11723,
19,
3217,
2529,
3544,
3696,
3326,
14,
267,
961,
805,
15373,
314,
3086,
574,
370,
282,
5578,
1059,
2544,
267,
9476,
652,
370,
314,
13035,
805,
14,
272,
408,
272,
372,
2400,
308,
26,
8260,
63,
1532,
8,
83,
14,
2708,
360,
1624,
13,
24,
1333,
199,
199,
7243,
14,
2683,
63,
11256,
8,
495,
480,
2245,
1288,
10334,
8,
2734,
308,
26,
308,
508,
283,
17,
1333,
199,
7243,
14,
2683,
63,
11256,
8,
495,
480,
521,
1288,
10334,
8,
1122,
63,
521,
430,
199,
7243,
14,
2683,
63,
11256,
8,
495,
480,
602,
1288,
10334,
8,
1122,
63,
602,
430,
199,
7243,
14,
2683,
63,
11256,
8,
495,
480,
2083,
1288,
10334,
8,
1122,
63,
2083,
430,
199,
7243,
14,
2683,
63,
11256,
8,
495,
480,
3954,
1288,
10334,
8,
1122,
63,
2083,
430,
199,
7243,
14,
2683,
63,
11256,
8,
495,
480,
20277,
1288,
10334,
8,
1122,
63,
2083,
430,
199,
7243,
14,
2683,
63,
11256,
8,
495,
480,
6355,
1288,
10334,
8,
4620,
63,
1208,
14,
466,
2931,
63,
6355,
430,
199,
199,
7243,
14,
2683,
63,
10394,
8,
2083,
14,
2083,
12,
19520,
63,
2083,
63,
4050,
63,
265,
63,
14600,
63,
2083,
9,
199,
7243,
14,
2683,
63,
10394,
8,
6355,
14,
6745,
12,
4865,
63,
1208,
14,
4964,
63,
466,
2931,
63,
6355,
9,
199,
692,
3816,
14,
4521,
18,
26,
272,
8692,
14,
2683,
63,
10394,
8,
495,
12,
2400,
308,
26,
308,
14,
2708,
360,
1624,
13,
24,
1333,
272,
8692,
14,
2683,
63,
10394,
8,
11090,
5571,
12,
2400,
308,
26,
308,
14,
2708,
360,
1624,
13,
24,
1333,
421,
199,
533,
8692,
4590,
8,
1563,
7243,
4590,
304,
272,
20868,
275,
283,
10659,
7,
272,
327,
19245,
3181,
1133,
5965,
2291,
4750,
402,
3520,
2943,
12,
1325,
652,
298,
9105,
314,
2451,
272,
327,
8377,
2,
1627,
1655,
3376,
901,
10269,
12,
880,
10137,
3062,
465,
365,
880,
626,
272,
327,
4177,
5261,
10303,
365,
1655,
2997,
14,
272,
666,
63,
1313,
275,
469,
267,
283,
4378,
356,
283,
4115,
297,
267,
283,
6636,
792,
356,
283,
26275,
297,
267,
283,
5036,
356,
283,
2245,
297,
267,
283,
2183,
356,
283,
25545,
12473,
988,
63,
1267,
9,
83,
3196,
267,
283,
25732,
20727,
3901,
356,
283,
25545,
12473,
988,
63,
1267,
9,
83,
3196,
267,
283,
14071,
356,
283,
602,
297,
267,
283,
4626,
356,
283,
2083,
297,
267,
283,
15975,
356,
283,
6355,
297,
267,
283,
13283,
792,
356,
283,
24884,
297,
267,
283,
23252,
356,
283,
25545,
12473,
988,
63,
1267,
9,
83,
3196,
267,
283,
14225,
792,
356,
283,
25545,
12473,
988,
63,
1267,
9,
83,
3196,
267,
283,
13019,
356,
283,
3093,
297,
267,
283,
3901,
356,
283,
4115,
297,
267,
283,
25175,
356,
283,
24884,
297,
267,
283,
26969,
356,
283
] |
[
199,
4657,
1175,
19,
4865,
367,
1639,
14,
199,
199,
25348,
543,
1902,
314,
10382,
29498,
18,
859,
503,
314,
11723,
19,
859,
315,
314,
199,
6807,
3555,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
646,
6107,
199,
646,
295,
199,
646,
3598,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
697,
492,
3778,
199,
504,
1639,
14,
697,
14,
7765,
492,
3778,
465,
4865,
63,
1208,
199,
504,
1639,
14,
697,
14,
7765,
14,
1095,
14,
1095,
492,
29103,
4590,
199,
504,
1639,
14,
697,
14,
7765,
14,
1095,
14,
6136,
492,
29103,
13816,
199,
504,
1639,
14,
1208,
492,
3816,
12,
7137,
199,
504,
1639,
14,
1208,
14,
602,
1122,
492,
334,
272,
2198,
63,
602,
12,
2198,
63,
2083,
12,
2198,
63,
5553,
12,
2198,
63,
521,
12,
199,
9,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
1165,
3849,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
28389,
492,
14969,
5571,
199,
199,
893,
26,
272,
492,
15444,
199,
2590,
3545,
26,
272,
15444,
275,
488,
199,
199,
893,
26,
272,
862,
26,
267,
687,
10382,
29498,
18,
492,
29333,
18,
465,
8692,
272,
871,
3545,
26,
267,
687,
11723,
19,
492,
29333,
18,
465,
8692,
199,
2590,
3545,
465,
3178,
26,
272,
687,
1639,
14,
1018,
14,
3924,
492,
11897,
272,
746,
11897,
480,
547,
8697,
1902,
10382,
29498,
18,
503,
11723,
19,
4621,
334,
599,
379,
315,
626,
1865,
304,
450,
83,
2,
450,
3178,
9,
199,
199,
3,
6601,
402,
3520,
492,
11723,
19,
12,
880,
492,
3062,
2410,
7907,
340,
652,
1159,
4903,
14,
199,
504,
1275,
1258,
492,
8692,
3041,
14516,
327,
365,
361,
26,
2759,
199,
504,
1275,
8782,
492,
8692,
13921,
10473,
327,
365,
361,
26,
2759,
199,
504,
1275,
3179,
492,
8692,
10807,
10473,
327,
365,
361,
26,
2759,
199,
504,
1275,
21627,
492,
8692,
30516,
3322,
327,
365,
361,
26,
2759,
199,
504,
1275,
8170,
492,
8692,
12929,
8295,
327,
365,
361,
26,
2759,
199,
504,
1275,
3629,
492,
8692,
6700,
10423,
8540,
327,
365,
361,
26,
2759,
199,
199,
25198,
275,
8692,
14,
25198,
199,
24823,
275,
8692,
14,
24823,
421,
199,
318,
19520,
63,
2083,
63,
4050,
63,
265,
63,
14600,
63,
2083,
8,
585,
304,
272,
327,
5852,
642,
805,
436,
19687,
641,
314,
849,
12146,
315,
5634,
499,
14,
16,
14,
272,
340,
2202,
14,
4701,
63,
14226,
436,
7137,
14,
374,
63,
14600,
8,
585,
304,
267,
3598,
14,
4050,
8,
288,
298,
1918,
19245,
3050,
12146,
3086,
376,
20381,
2197,
4366,
83,
395,
298,
288,
298,
6101,
6665,
687,
3920,
14,
2526,
1252,
6162,
2195,
1233,
370,
986,
282,
298,
288,
298,
21578,
2197,
315,
314,
3050,
1950,
1159,
900,
5718,
334,
11288,
701,
298,
288,
298,
885,
680,
401,
23687,
1165,
3849,
9,
267,
327,
961,
3181,
1133,
2933,
367,
314,
3050,
1950,
1159,
7137,
12,
267,
327,
1314,
5712,
1133,
6040,
14,
334,
17231,
1159,
10842,
642,
12146,
365,
5906,
4959,
267,
574,
275,
574,
14,
29648,
8,
7145,
14,
5834,
680,
1814,
8,
9374,
29,
403,
9,
272,
372,
574,
14,
17070,
8,
495,
480,
26725,
421,
199,
318,
10334,
8,
5598,
63,
1532,
304,
272,
408,
710,
2018,
11723,
19,
3217,
2529,
3544,
3696,
3326,
14,
267,
961,
805,
15373,
314,
3086,
574,
370,
282,
5578,
1059,
2544,
267,
9476,
652,
370,
314,
13035,
805,
14,
272,
408,
272,
372,
2400,
308,
26,
8260,
63,
1532,
8,
83,
14,
2708,
360,
1624,
13,
24,
1333,
199,
199,
7243,
14,
2683,
63,
11256,
8,
495,
480,
2245,
1288,
10334,
8,
2734,
308,
26,
308,
508,
283,
17,
1333,
199,
7243,
14,
2683,
63,
11256,
8,
495,
480,
521,
1288,
10334,
8,
1122,
63,
521,
430,
199,
7243,
14,
2683,
63,
11256,
8,
495,
480,
602,
1288,
10334,
8,
1122,
63,
602,
430,
199,
7243,
14,
2683,
63,
11256,
8,
495,
480,
2083,
1288,
10334,
8,
1122,
63,
2083,
430,
199,
7243,
14,
2683,
63,
11256,
8,
495,
480,
3954,
1288,
10334,
8,
1122,
63,
2083,
430,
199,
7243,
14,
2683,
63,
11256,
8,
495,
480,
20277,
1288,
10334,
8,
1122,
63,
2083,
430,
199,
7243,
14,
2683,
63,
11256,
8,
495,
480,
6355,
1288,
10334,
8,
4620,
63,
1208,
14,
466,
2931,
63,
6355,
430,
199,
199,
7243,
14,
2683,
63,
10394,
8,
2083,
14,
2083,
12,
19520,
63,
2083,
63,
4050,
63,
265,
63,
14600,
63,
2083,
9,
199,
7243,
14,
2683,
63,
10394,
8,
6355,
14,
6745,
12,
4865,
63,
1208,
14,
4964,
63,
466,
2931,
63,
6355,
9,
199,
692,
3816,
14,
4521,
18,
26,
272,
8692,
14,
2683,
63,
10394,
8,
495,
12,
2400,
308,
26,
308,
14,
2708,
360,
1624,
13,
24,
1333,
272,
8692,
14,
2683,
63,
10394,
8,
11090,
5571,
12,
2400,
308,
26,
308,
14,
2708,
360,
1624,
13,
24,
1333,
421,
199,
533,
8692,
4590,
8,
1563,
7243,
4590,
304,
272,
20868,
275,
283,
10659,
7,
272,
327,
19245,
3181,
1133,
5965,
2291,
4750,
402,
3520,
2943,
12,
1325,
652,
298,
9105,
314,
2451,
272,
327,
8377,
2,
1627,
1655,
3376,
901,
10269,
12,
880,
10137,
3062,
465,
365,
880,
626,
272,
327,
4177,
5261,
10303,
365,
1655,
2997,
14,
272,
666,
63,
1313,
275,
469,
267,
283,
4378,
356,
283,
4115,
297,
267,
283,
6636,
792,
356,
283,
26275,
297,
267,
283,
5036,
356,
283,
2245,
297,
267,
283,
2183,
356,
283,
25545,
12473,
988,
63,
1267,
9,
83,
3196,
267,
283,
25732,
20727,
3901,
356,
283,
25545,
12473,
988,
63,
1267,
9,
83,
3196,
267,
283,
14071,
356,
283,
602,
297,
267,
283,
4626,
356,
283,
2083,
297,
267,
283,
15975,
356,
283,
6355,
297,
267,
283,
13283,
792,
356,
283,
24884,
297,
267,
283,
23252,
356,
283,
25545,
12473,
988,
63,
1267,
9,
83,
3196,
267,
283,
14225,
792,
356,
283,
25545,
12473,
988,
63,
1267,
9,
83,
3196,
267,
283,
13019,
356,
283,
3093,
297,
267,
283,
3901,
356,
283,
4115,
297,
267,
283,
25175,
356,
283,
24884,
297,
267,
283,
26969,
356,
283,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
aularon/meld
|
meld/vc/mercurial.py
|
6
|
5772
|
# Copyright (C) 2002-2005 Stephen Kennedy <stevek@gnome.org>
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import errno
import os
import shutil
import subprocess
import tempfile
from . import _vc
class Vc(_vc.CachedVc):
CMD = "hg"
NAME = "Mercurial"
VC_DIR = ".hg"
state_map = {
"?": _vc.STATE_NONE,
"A": _vc.STATE_NEW,
"C": _vc.STATE_NORMAL,
"!": _vc.STATE_MISSING,
"I": _vc.STATE_IGNORED,
"M": _vc.STATE_MODIFIED,
"R": _vc.STATE_REMOVED,
}
def commit_command(self, message):
return [self.CMD, "commit", "-m", message]
def update_command(self):
return [self.CMD, "update"]
def add_command(self):
return [self.CMD, "add"]
def remove_command(self, force=0):
return [self.CMD, "rm"]
def revert_command(self):
return [self.CMD, "revert"]
@classmethod
def valid_repo(cls, path):
return not _vc.call([cls.CMD, "root"], cwd=path)
def get_working_directory(self, workdir):
if workdir.startswith("/"):
return self.root
else:
return ''
def get_path_for_repo_file(self, path, commit=None):
if commit is not None:
raise NotImplementedError()
if not path.startswith(self.root + os.path.sep):
raise _vc.InvalidVCPath(self, path, "Path not in repository")
path = path[len(self.root) + 1:]
process = subprocess.Popen([self.CMD, "cat", path], cwd=self.root,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
with tempfile.NamedTemporaryFile(prefix='meld-tmp', delete=False) as f:
shutil.copyfileobj(process.stdout, f)
return f.name
def _update_tree_state_cache(self, path, tree_state):
""" Update the state of the file(s) at tree_state['path'] """
while 1:
try:
# Get the status of modified files
proc = _vc.popen([self.CMD, "status", '-A', path],
cwd=self.location)
entries = proc.read().split("\n")[:-1]
# The following command removes duplicate file entries.
# Just in case.
entries = list(set(entries))
break
except OSError as e:
if e.errno != errno.EAGAIN:
raise
if len(entries) == 0 and os.path.isfile(path):
# If we're just updating a single file there's a chance that it
# was it was previously modified, and now has been edited
# so that it is un-modified. This will result in an empty
# 'entries' list, and tree_state['path'] will still contain stale
# data. When this corner case occurs we force tree_state['path']
# to STATE_NORMAL.
tree_state[path] = _vc.STATE_NORMAL
else:
# There are 1 or more modified files, parse their state
for entry in entries:
# we might have a space in file name, it should be ignored
statekey, name = entry.split(" ", 1)
path = os.path.join(self.location, name.strip())
state = self.state_map.get(statekey.strip(), _vc.STATE_NONE)
tree_state[path] = state
def _lookup_tree_cache(self, rootdir):
# Get a list of all files in rootdir, as well as their status
tree_state = {}
self._update_tree_state_cache("./", tree_state)
return tree_state
def update_file_state(self, path):
tree_state = self._get_tree_cache(os.path.dirname(path))
self._update_tree_state_cache(path, tree_state)
def _get_dirsandfiles(self, directory, dirs, files):
tree = self._get_tree_cache(directory)
retfiles = []
retdirs = []
for name, path in files:
state = tree.get(path, _vc.STATE_NORMAL)
retfiles.append(_vc.File(path, name, state))
for name, path in dirs:
# mercurial does not operate on dirs, just files
retdirs.append(_vc.Dir(path, name, _vc.STATE_NORMAL))
for path, state in tree.items():
# removed files are not in the filesystem, so must be added here
if state in (_vc.STATE_REMOVED, _vc.STATE_MISSING):
folder, name = os.path.split(path)
if folder == directory:
retfiles.append(_vc.File(path, name, state))
return retdirs, retfiles
|
gpl-2.0
|
[
3,
1898,
334,
35,
9,
14790,
13,
9397,
17854,
17579,
1804,
287,
7439,
89,
665,
1597,
432,
75,
32,
784,
1377,
14,
1308,
30,
199,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
199,
3,
787,
7647,
26,
199,
3,
199,
3,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
259,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
17632,
1124,
1179,
2281,
891,
2401,
1821,
7168,
1549,
199,
3,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
2990,
199,
3,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
199,
3,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
199,
3,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
7554,
199,
646,
747,
199,
646,
5145,
199,
646,
3873,
199,
646,
5549,
199,
199,
504,
1275,
492,
485,
6737,
421,
199,
533,
812,
67,
1547,
6737,
14,
16138,
54,
67,
304,
339,
25548,
275,
298,
9208,
2,
272,
13637,
275,
298,
16797,
18977,
2,
272,
24955,
63,
3022,
275,
3680,
9208,
2,
339,
1174,
63,
1130,
275,
469,
267,
23665,
582,
485,
6737,
14,
6689,
63,
9185,
12,
267,
298,
33,
582,
485,
6737,
14,
6689,
63,
11365,
12,
267,
298,
35,
582,
485,
6737,
14,
6689,
63,
10765,
12,
267,
19724,
582,
485,
6737,
14,
6689,
63,
18701,
12,
267,
298,
41,
582,
485,
6737,
14,
6689,
63,
3203,
25517,
12,
267,
298,
45,
582,
485,
6737,
14,
6689,
63,
30389,
12,
267,
298,
50,
582,
485,
6737,
14,
6689,
63,
907,
2679,
14112,
12,
272,
789,
339,
347,
5532,
63,
1531,
8,
277,
12,
1245,
304,
267,
372,
359,
277,
14,
9744,
12,
298,
3543,
401,
3905,
77,
401,
1245,
61,
339,
347,
1678,
63,
1531,
8,
277,
304,
267,
372,
359,
277,
14,
9744,
12,
298,
873,
937,
339,
347,
1050,
63,
1531,
8,
277,
304,
267,
372,
359,
277,
14,
9744,
12,
298,
525,
937,
339,
347,
2813,
63,
1531,
8,
277,
12,
3542,
29,
16,
304,
267,
372,
359,
277,
14,
9744,
12,
298,
5682,
937,
339,
347,
23347,
63,
1531,
8,
277,
304,
267,
372,
359,
277,
14,
9744,
12,
298,
19092,
937,
339,
768,
3744,
272,
347,
1686,
63,
3417,
8,
1886,
12,
931,
304,
267,
372,
440,
485,
6737,
14,
1250,
779,
1886,
14,
9744,
12,
298,
1231,
2255,
8288,
29,
515,
9,
339,
347,
664,
63,
9818,
63,
3619,
8,
277,
12,
1736,
694,
304,
267,
340,
1736,
694,
14,
2460,
4769,
2349,
288,
372,
291,
14,
1231,
267,
587,
26,
288,
372,
2125,
339,
347,
664,
63,
515,
63,
509,
63,
3417,
63,
493,
8,
277,
12,
931,
12,
5532,
29,
403,
304,
267,
340,
5532,
365,
440,
488,
26,
288,
746,
4279,
342,
398,
340,
440,
931,
14,
2460,
8,
277,
14,
1231,
435,
747,
14,
515,
14,
4127,
304,
288,
746,
485,
6737,
14,
3364,
9454,
2042,
8,
277,
12,
931,
12,
298,
2042,
440,
315,
7611,
531,
267,
931,
275,
931,
59,
552,
8,
277,
14,
1231,
9,
435,
413,
2938,
398,
2112,
275,
3873,
14,
7942,
779,
277,
14,
9744,
12,
298,
3385,
401,
931,
467,
8288,
29,
277,
14,
1231,
12,
3521,
3839,
29,
5781,
14,
6089,
12,
3521,
4635,
29,
5781,
14,
6089,
9,
398,
543,
5549,
14,
19320,
8,
1861,
534,
278,
1447,
13,
2791,
297,
3145,
29,
797,
9,
465,
289,
26,
288,
5145,
14,
1574,
9234,
8,
1412,
14,
2703,
12,
289,
9,
267,
372,
289,
14,
354,
339,
347,
485,
873,
63,
2350,
63,
929,
63,
1637,
8,
277,
12,
931,
12,
3123,
63,
929,
304,
267,
408,
6162,
314,
1174,
402,
314,
570,
8,
83,
9,
737,
3123,
63,
929,
459,
515,
418,
408,
267,
1830,
413,
26,
288,
862,
26,
355,
327,
2372,
314,
2004,
402,
6042,
1584,
355,
6499,
275,
485,
6737,
14,
12207,
779,
277,
14,
9744,
12,
298,
1205,
401,
2475,
33,
297,
931,
467,
639,
8288,
29,
277,
14,
1985,
9,
355,
4811,
275,
6499,
14,
739,
1252,
1294,
4582,
78,
531,
4439,
17,
61,
2234,
327,
710,
2569,
1414,
14185,
9250,
570,
4811,
14,
355,
327,
13870,
315,
1930,
14,
355,
4811,
275,
769,
8,
409,
8,
3189,
430,
355,
2059,
288,
871,
6440,
465,
325,
26,
355,
340,
325,
14,
7931,
1137,
7554,
14,
37,
1254,
9021,
26,
490,
746,
398,
340,
822,
8,
3189,
9,
508,
378,
436,
747,
14,
515,
14,
6292,
8,
515,
304,
288,
327,
982,
781,
3984,
2951,
12928,
282,
2849,
570,
2337,
1159,
282,
22044,
626,
652,
288,
327,
1990,
652,
1990,
10889,
6042,
12,
436,
3063,
965,
2757,
21062,
288,
327,
880,
626,
652,
365,
625,
13,
5540,
14,
221,
961,
911,
754,
315,
376,
2701,
288,
327,
283,
3189,
7,
769,
12,
436,
3123,
63,
929,
459,
515,
418,
911,
5139,
1395,
20149,
288,
327,
666,
14,
221,
3979,
642,
17703,
1930,
11058,
781,
3542,
3123,
63,
929,
459,
515,
418,
288,
327,
370,
11377,
63,
10765,
14,
288,
3123,
63,
929,
59,
515,
61,
275,
485,
6737,
14,
6689,
63,
10765,
267,
587,
26,
288,
327,
6006,
787,
413,
503,
1655,
6042,
1584,
12,
2198,
3932,
1174,
288,
367,
2397
] |
[
1898,
334,
35,
9,
14790,
13,
9397,
17854,
17579,
1804,
287,
7439,
89,
665,
1597,
432,
75,
32,
784,
1377,
14,
1308,
30,
199,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
199,
3,
787,
7647,
26,
199,
3,
199,
3,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
259,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
17632,
1124,
1179,
2281,
891,
2401,
1821,
7168,
1549,
199,
3,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
2990,
199,
3,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
199,
3,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
199,
3,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
7554,
199,
646,
747,
199,
646,
5145,
199,
646,
3873,
199,
646,
5549,
199,
199,
504,
1275,
492,
485,
6737,
421,
199,
533,
812,
67,
1547,
6737,
14,
16138,
54,
67,
304,
339,
25548,
275,
298,
9208,
2,
272,
13637,
275,
298,
16797,
18977,
2,
272,
24955,
63,
3022,
275,
3680,
9208,
2,
339,
1174,
63,
1130,
275,
469,
267,
23665,
582,
485,
6737,
14,
6689,
63,
9185,
12,
267,
298,
33,
582,
485,
6737,
14,
6689,
63,
11365,
12,
267,
298,
35,
582,
485,
6737,
14,
6689,
63,
10765,
12,
267,
19724,
582,
485,
6737,
14,
6689,
63,
18701,
12,
267,
298,
41,
582,
485,
6737,
14,
6689,
63,
3203,
25517,
12,
267,
298,
45,
582,
485,
6737,
14,
6689,
63,
30389,
12,
267,
298,
50,
582,
485,
6737,
14,
6689,
63,
907,
2679,
14112,
12,
272,
789,
339,
347,
5532,
63,
1531,
8,
277,
12,
1245,
304,
267,
372,
359,
277,
14,
9744,
12,
298,
3543,
401,
3905,
77,
401,
1245,
61,
339,
347,
1678,
63,
1531,
8,
277,
304,
267,
372,
359,
277,
14,
9744,
12,
298,
873,
937,
339,
347,
1050,
63,
1531,
8,
277,
304,
267,
372,
359,
277,
14,
9744,
12,
298,
525,
937,
339,
347,
2813,
63,
1531,
8,
277,
12,
3542,
29,
16,
304,
267,
372,
359,
277,
14,
9744,
12,
298,
5682,
937,
339,
347,
23347,
63,
1531,
8,
277,
304,
267,
372,
359,
277,
14,
9744,
12,
298,
19092,
937,
339,
768,
3744,
272,
347,
1686,
63,
3417,
8,
1886,
12,
931,
304,
267,
372,
440,
485,
6737,
14,
1250,
779,
1886,
14,
9744,
12,
298,
1231,
2255,
8288,
29,
515,
9,
339,
347,
664,
63,
9818,
63,
3619,
8,
277,
12,
1736,
694,
304,
267,
340,
1736,
694,
14,
2460,
4769,
2349,
288,
372,
291,
14,
1231,
267,
587,
26,
288,
372,
2125,
339,
347,
664,
63,
515,
63,
509,
63,
3417,
63,
493,
8,
277,
12,
931,
12,
5532,
29,
403,
304,
267,
340,
5532,
365,
440,
488,
26,
288,
746,
4279,
342,
398,
340,
440,
931,
14,
2460,
8,
277,
14,
1231,
435,
747,
14,
515,
14,
4127,
304,
288,
746,
485,
6737,
14,
3364,
9454,
2042,
8,
277,
12,
931,
12,
298,
2042,
440,
315,
7611,
531,
267,
931,
275,
931,
59,
552,
8,
277,
14,
1231,
9,
435,
413,
2938,
398,
2112,
275,
3873,
14,
7942,
779,
277,
14,
9744,
12,
298,
3385,
401,
931,
467,
8288,
29,
277,
14,
1231,
12,
3521,
3839,
29,
5781,
14,
6089,
12,
3521,
4635,
29,
5781,
14,
6089,
9,
398,
543,
5549,
14,
19320,
8,
1861,
534,
278,
1447,
13,
2791,
297,
3145,
29,
797,
9,
465,
289,
26,
288,
5145,
14,
1574,
9234,
8,
1412,
14,
2703,
12,
289,
9,
267,
372,
289,
14,
354,
339,
347,
485,
873,
63,
2350,
63,
929,
63,
1637,
8,
277,
12,
931,
12,
3123,
63,
929,
304,
267,
408,
6162,
314,
1174,
402,
314,
570,
8,
83,
9,
737,
3123,
63,
929,
459,
515,
418,
408,
267,
1830,
413,
26,
288,
862,
26,
355,
327,
2372,
314,
2004,
402,
6042,
1584,
355,
6499,
275,
485,
6737,
14,
12207,
779,
277,
14,
9744,
12,
298,
1205,
401,
2475,
33,
297,
931,
467,
639,
8288,
29,
277,
14,
1985,
9,
355,
4811,
275,
6499,
14,
739,
1252,
1294,
4582,
78,
531,
4439,
17,
61,
2234,
327,
710,
2569,
1414,
14185,
9250,
570,
4811,
14,
355,
327,
13870,
315,
1930,
14,
355,
4811,
275,
769,
8,
409,
8,
3189,
430,
355,
2059,
288,
871,
6440,
465,
325,
26,
355,
340,
325,
14,
7931,
1137,
7554,
14,
37,
1254,
9021,
26,
490,
746,
398,
340,
822,
8,
3189,
9,
508,
378,
436,
747,
14,
515,
14,
6292,
8,
515,
304,
288,
327,
982,
781,
3984,
2951,
12928,
282,
2849,
570,
2337,
1159,
282,
22044,
626,
652,
288,
327,
1990,
652,
1990,
10889,
6042,
12,
436,
3063,
965,
2757,
21062,
288,
327,
880,
626,
652,
365,
625,
13,
5540,
14,
221,
961,
911,
754,
315,
376,
2701,
288,
327,
283,
3189,
7,
769,
12,
436,
3123,
63,
929,
459,
515,
418,
911,
5139,
1395,
20149,
288,
327,
666,
14,
221,
3979,
642,
17703,
1930,
11058,
781,
3542,
3123,
63,
929,
459,
515,
418,
288,
327,
370,
11377,
63,
10765,
14,
288,
3123,
63,
929,
59,
515,
61,
275,
485,
6737,
14,
6689,
63,
10765,
267,
587,
26,
288,
327,
6006,
787,
413,
503,
1655,
6042,
1584,
12,
2198,
3932,
1174,
288,
367,
2397,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
gaurav38/QosRouting
|
pox/openflow/__init__.py
|
5
|
11451
|
# Copyright 2011 James McCauley
#
# 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 is the main OpenFlow module.
Along with libopenflow, this is the major part of the OpenFlow API in POX.
There are a number of Events, which are generally raised on core.openflow
as well as on individual switch Connections. Many of these events have at
least some of the following properties:
.connection - a reference to the switch connection that caused the event
.dpid - the DPID of the switch that caused the event
.ofp - the OpenFlow message that caused the event (from libopenflow)
One of the more complicated aspects of OpenFlow is dealing with stats
replies, which may come in multiple parts (it shouldn't be that that
difficult, really, but that hasn't stopped it from beind handled wrong
wrong more than once). In POX, the raw events are available, but you will
generally just want to listen to the aggregate stats events which take
care of this for you and are only fired when all data is available.
NOTE: This module is usually automatically loaded by pox.py
"""
from pox.lib.revent import *
from pox.lib.util import dpidToStr
import libopenflow_01 as of
from pox.lib.packet.ethernet import ethernet
class ConnectionHandshakeComplete (Event):
"""
Event when a switch handshake completes
Fired immediately before ConnectionUp
"""
def __init__ (self, connection):
self.connection = connection
self.dpid = connection.dpid
class ConnectionUp (Event):
"""
Raised when a connection to a switch has been established.
"""
def __init__ (self, connection, ofp):
self.connection = connection
self.dpid = connection.dpid
self.ofp = ofp
class FeaturesReceived (Event):
"""
Raised upon receipt of an ofp_switch_features message
This generally happens as part of a connection automatically.
"""
def __init__ (self, connection, ofp):
self.connection = connection
self.dpid = connection.dpid
self.ofp = ofp
class ConnectionDown (Event):
"""
Raised when a connection to switch has been lost.
"""
def __init__ (self, connection):
self.connection = connection
self.dpid = connection.dpid
class PortStatus (Event):
"""
Fired in response to port status changes.
added (bool) - True if fired because a port was added
deleted (bool) - True if fired because a port was deleted
modified (bool) - True if fired because a port was modified
port (int) - number of port in question
"""
def __init__ (self, connection, ofp):
self.connection = connection
self.dpid = connection.dpid
self.ofp = ofp
self.modified = ofp.reason == of.OFPPR_MODIFY
self.added = ofp.reason == of.OFPPR_ADD
self.deleted = ofp.reason == of.OFPPR_DELETE
self.port = ofp.desc.port_no
class FlowRemoved (Event):
"""
Raised when a flow entry has been removed from a flow table.
This may either be because of a timeout or because it was removed
explicitly.
Properties:
idleTimeout (bool) - True if expired because of idleness
hardTimeout (bool) - True if expired because of hard timeout
timeout (bool) - True if either of the above is true
deleted (bool) - True if deleted explicitly
"""
def __init__ (self, connection, ofp):
self.connection = connection
self.dpid = connection.dpid
self.ofp = ofp
self.idleTimeout = False
self.hardTimeout = False
self.deleted = False
self.timeout = False
if ofp.reason == of.OFPRR_IDLE_TIMEOUT:
self.timeout = True
self.idleTimeout = True
elif ofp.reason == of.OFPRR_HARD_TIMEOUT:
self.timeout = True
self.hardTimeout = True
elif ofp.reason == of.OFPRR_DELETE:
self.deleted = True
class RawStatsReply (Event):
def __init__ (self, connection, ofp):
self.connection = connection
self.ofp = ofp # Raw ofp message(s)
@property
def dpid (self):
return self.connection.dpid
class StatsReply (Event):
"""
Abstract superclass for all stats replies
"""
def __init__ (self, connection, ofp, stats):
self.connection = connection
self.ofp = ofp # Raw ofp message(s)
self.stats = stats # Processed
@property
def dpid (self):
return self.connection.dpid
class SwitchDescReceived (StatsReply):
pass
class FlowStatsReceived (StatsReply):
pass
class AggregateFlowStatsReceived (StatsReply):
pass
class TableStatsReceived (StatsReply):
pass
class PortStatsReceived (StatsReply):
pass
class QueueStatsReceived (StatsReply):
pass
class PacketIn (Event):
"""
Fired in response to PacketIn events
port (int) - number of port the packet came in on
data (bytes) - raw packet data
parsed (packet subclasses) - pox.lib.packet's parsed version
"""
def __init__ (self, connection, ofp):
self.connection = connection
self.ofp = ofp
self.port = ofp.in_port
self.data = ofp.data
self._parsed = None
self.dpid = connection.dpid
def parse (self):
if self._parsed is None:
self._parsed = ethernet(self.data)
return self._parsed
@property
def parsed (self):
"""
The packet as parsed by pox.lib.packet
"""
return self.parse()
class ErrorIn (Event):
def __init__ (self, connection, ofp):
self.connection = connection
self.ofp = ofp
self.xid = ofp.xid
self.dpid = connection.dpid
self.should_log = True # If this remains True, an error will be logged
def asString (self):
return self.ofp.show()
# def lookup (m, v):
# if v in m:
# return str(m[v])
# else:
# return "Unknown/" + str(v)
#
# #TODO: The show() in ofp_error actually does some clever
# # stuff now to stringize error messages. Refactor that and the
# # (less clever) code below.
# s = 'Type: ' + lookup(of.ofp_error_type_map, self.ofp.type)
# s += ' Code: '
#
# responses = {
# of.OFPET_HELLO_FAILED : of.ofp_hello_failed_code,
# of.OFPET_BAD_REQUEST : of.ofp_bad_request_code,
# of.OFPET_BAD_ACTION : of.ofp_bad_action_code,
# of.OFPET_FLOW_MOD_FAILED : of.ofp_flow_mod_failed_code,
# of.OFPET_PORT_MOD_FAILED : of.ofp_port_mod_failed_code,
# of.OFPET_QUEUE_OP_FAILED : of.ofp_queue_op_failed_code,
# }
#
# if self.ofp.type in responses:
# s += lookup(responses[self.ofp.type],self.ofp.code)
# else:
# s += "Unknown/" + str(self.ofp.code)
# if self.ofp.type == of.OFPET_HELLO_FAILED:
# s += lookup(of.ofp_hello_failed_code, self.ofp.type)
#
# return s
class BarrierIn (Event):
"""
Fired in response to a barrier reply
xid (int) - XID of barrier request
"""
def __init__ (self, connection, ofp):
self.connection = connection
self.ofp = ofp
self.dpid = connection.dpid
self.xid = ofp.xid
class ConnectionIn (Event):
def __init__ (self, connection):
super(ConnectionIn,self).__init__()
self.connection = connection
self.dpid = connection.dpid
self.nexus = None
class ConfigurationReceived (Event):
"""
Fired in response to OFPT_GET_CONFIG_REPLY
"""
def __init__ (self, connection, ofp):
self.connection = connection
self.ofp = ofp
self.dpid = connection.dpid
self.xid = ofp.xid
@property
def flags (self):
return self.ofp.flags
@property
def miss_send_len (self):
return self.ofp.miss_send_len
@property
def drop_fragments (self):
return (self.ofp.flags & of.OFPC_FRAG_MASK) == of.OFPC_FRAG_DROP
@property
def reassemble_fragments (self):
return (self.ofp.flags & of.OFPC_FRAG_MASK) == of.OFPC_FRAG_REASM
class OpenFlowConnectionArbiter (EventMixin):
"""
Determines which OpenFlowNexus gets the switch.
Default implementation always just gives it to core.openflow
"""
_eventMixin_events = set([
ConnectionIn,
])
def __init__ (self, default = False):
""" default as False causes it to always use core.openflow """
self._default = default
self._fallback = None
def getNexus (self, connection):
e = ConnectionIn(connection)
self.raiseEventNoErrors(e)
if e.nexus is None:
e.nexus = self._default
if e.nexus is False:
if self._fallback is None:
try:
from pox.core import core
self._fallback = core.openflow
except:
raise RuntimeError("No OpenFlow nexus for new connection")
e.nexus = self._fallback
return e.nexus
class ConnectionDict (dict):
def __iter__ (self):
return self.itervalues()
def __contains__ (self, item):
v = dict.__contains__(self, item)
if v: return v
return item in self.values()
@property
def dpids (self):
return self.keys()
def iter_dpids (self):
return self.iterkeys()
class OpenFlowNexus (EventMixin):
"""
Main point of OpenFlow interaction.
There is usually just one instance of this class, registered as
core.openflow. Most OpenFlow events fire here in addition to on their
specific connections.
"""
_eventMixin_events = set([
ConnectionHandshakeComplete,
ConnectionUp,
ConnectionDown,
FeaturesReceived,
PortStatus,
PacketIn,
BarrierIn,
ErrorIn,
RawStatsReply,
SwitchDescReceived,
FlowStatsReceived,
AggregateFlowStatsReceived,
TableStatsReceived,
PortStatsReceived,
QueueStatsReceived,
FlowRemoved,
ConfigurationReceived,
])
# Bytes to send to controller when a packet misses all flows
miss_send_len = of.OFP_DEFAULT_MISS_SEND_LEN
# Enable/Disable clearing of flows on switch connect
clear_flows_on_connect = True
def __init__ (self):
self._connections = ConnectionDict() # DPID -> Connection
from pox.core import core
self.listenTo(core)
@property
def connections (self):
return self._connections
def getConnection (self, dpid):
"""
Get the Connection object associated with a DPID.
"""
return self._connections.get(dpid, None)
def sendToDPID (self, dpid, data):
"""
Send data to a specific DPID.
"""
if dpid in self._connections:
self._connections[dpid].send(data)
return True
else:
import logging
log = logging.getLogger("openflow")
log.warn("Couldn't send to %s because we're not connected to it!" %
(dpidToStr(dpid),))
return False
def _handle_DownEvent (self, event):
for c in self._connections.values():
try:
c.disconnect()
except:
pass
def _connect (self, con):
self._connections[con.dpid] = con
def _disconnect (self, dpid):
if dpid in self._connections:
del self._connections[dpid]
return True
return False
def _launch (default_arbiter=True):
from pox.core import core
if default_arbiter:
core.registerNew(OpenFlowConnectionArbiter)
core.register("openflow", OpenFlowNexus())
def launch (default_arbiter=True):
from pox.core import core
if core.hasComponent("openflow"):
return
return _launch(default_arbiter)
|
apache-2.0
|
[
3,
1898,
7760,
1603,
14015,
22895,
3630,
443,
89,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
26,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
199,
2765,
365,
314,
2446,
3232,
5060,
859,
14,
199,
199,
2439,
951,
543,
1973,
1490,
1659,
12,
642,
365,
314,
12160,
1777,
402,
314,
3232,
5060,
3261,
315,
3625,
56,
14,
199,
10924,
787,
282,
1329,
402,
27982,
12,
1314,
787,
16711,
4915,
641,
6170,
14,
1490,
1659,
199,
305,
5521,
465,
641,
8212,
6258,
8113,
83,
14,
221,
15517,
402,
3520,
4474,
1172,
737,
199,
11790,
2005,
402,
314,
2569,
4382,
26,
199,
1275,
2105,
446,
282,
3659,
370,
314,
6258,
1950,
626,
18104,
314,
1566,
199,
1275,
26050,
446,
314,
577,
16098,
402,
314,
6258,
626,
18104,
314,
1566,
199,
1275,
20943,
446,
314,
3232,
5060,
1245,
626,
18104,
314,
1566,
334,
504,
1973,
1490,
1659,
9,
199,
199,
4395,
402,
314,
1655,
23515,
17435,
83,
402,
3232,
5060,
365,
23654,
543,
5020,
199,
1155,
6528,
12,
1314,
1443,
11492,
315,
3663,
4184,
334,
390,
9296,
1133,
506,
626,
626,
199,
7330,
1792,
427,
12,
7710,
12,
1325,
626,
18699,
1133,
15248,
652,
687,
506,
688,
8860,
6835,
199,
10603,
1655,
2419,
5403,
680,
221,
1010,
3625,
56,
12,
314,
3066,
4474,
787,
2808,
12,
1325,
1265,
911,
199,
2038,
1183,
2951,
2934,
370,
6938,
370,
314,
9531,
5020,
4474,
1314,
5452,
199,
28654,
402,
642,
367,
1265,
436,
787,
1454,
31974,
1380,
1006,
666,
365,
2808,
14,
199,
199,
19855,
26,
961,
859,
365,
9987,
5847,
6511,
701,
1115,
88,
14,
647,
199,
624,
199,
199,
504,
1115,
88,
14,
773,
14,
264,
782,
492,
627,
199,
504,
1115,
88,
14,
773,
14,
1974,
492,
366,
3150,
1378,
2848,
199,
646,
1973,
1490,
1659,
63,
614,
465,
402,
199,
504,
1115,
88,
14,
773,
14,
6253,
14,
20354,
492,
21944,
421,
199,
533,
8113,
26392,
14175,
334,
2390,
304,
523,
408,
523,
6763,
1380,
282,
6258,
14305,
29672,
819,
481,
16139,
9939,
2544,
8113,
1721,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
304,
272,
291,
14,
2105,
275,
1950,
272,
291,
14,
26050,
275,
1950,
14,
26050,
199,
199,
533,
8113,
1721,
334,
2390,
304,
523,
408,
523,
24997,
1380,
282,
1950,
370,
282,
6258,
965,
2757,
23594,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
15643,
304,
272,
291,
14,
2105,
275,
1950,
272,
291,
14,
26050,
275,
1950,
14,
26050,
272,
291,
14,
20943,
275,
15643,
199,
199,
533,
7949,
2093,
9392,
334,
2390,
304,
523,
408,
523,
24997,
12188,
31594,
402,
376,
15643,
63,
5656,
63,
3179,
1245,
819,
961,
16711,
10986,
465,
1777,
402,
282,
1950,
5847,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
15643,
304,
272,
291,
14,
2105,
275,
1950,
272,
291,
14,
26050,
275,
1950,
14,
26050,
272,
291,
14,
20943,
275,
15643,
199,
199,
533,
8113,
3514,
334,
2390,
304,
523,
408,
523,
24997,
1380,
282,
1950,
370,
6258,
965,
2757,
14669,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
304,
272,
291,
14,
2105,
275,
1950,
272,
291,
14,
26050,
275,
1950,
14,
26050,
199,
199,
533,
10977,
3694,
334,
2390,
304,
523,
408,
523,
481,
16139,
315,
1177,
370,
1844,
2004,
4493,
14,
819,
3483,
334,
2245,
9,
446,
715,
340,
31974,
2952,
282,
1844,
1990,
3483,
523,
5463,
334,
2245,
9,
446,
715,
340,
31974,
2952,
282,
1844,
1990,
5463,
523,
6042,
334,
2245,
9,
446,
715,
340,
31974,
2952,
282,
1844,
1990,
6042,
523,
1844,
334,
442,
9,
446,
1329,
402,
1844,
315,
7894,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
15643,
304,
272,
291,
14,
2105,
275,
1950,
272,
291,
14,
26050,
275,
1950,
14,
26050,
272,
291,
14,
20943,
275,
15643,
272,
291,
14,
5540,
275,
15643,
14,
5764,
508,
402,
14,
6733,
3311,
63,
31225,
272,
291,
14,
3270,
275,
15643,
14,
5764,
508,
402,
14,
6733,
3311,
63,
9732,
272,
291,
14,
6062,
275,
15643,
14,
5764,
508,
402,
14,
6733,
3311,
63,
7014,
272,
291,
14,
719,
275,
15643,
14,
3257,
14,
719,
63,
889,
199,
199,
533,
20823,
23407,
334,
2390,
304,
523,
408,
523,
24997,
1380,
282,
6369,
2397,
965,
2757,
4829,
687,
282,
6369,
1817,
14,
819,
961,
1443,
1902,
506,
2952,
402,
282,
2653,
503,
2952,
652,
1990,
4829,
523,
7662,
14,
523,
19329,
26,
523,
15072,
6372,
334,
2245,
9,
446,
715,
340,
14721,
2952,
402,
1305,
552,
16709,
523,
7508,
6372,
334,
2245,
9,
446,
715,
340,
14721,
2952,
402,
7508,
2653,
523,
2653,
334,
2245,
9,
446,
715,
340,
1902,
402,
314,
3432,
365,
2549,
523,
5463,
334,
2245,
9,
446,
715,
340,
5463,
7662,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
15643,
304,
272,
291,
14,
2105,
275,
1950,
272,
291,
14,
26050,
275,
1950,
14,
26050,
272,
291,
14,
20943,
275,
15643,
272,
291,
14,
12000,
6372,
275,
756,
272,
291,
14,
8726,
6372,
275,
756,
272,
291,
14,
6062,
275,
756,
272,
291,
14,
2593,
275,
756,
272,
340,
15643,
14,
5764,
508,
402,
14,
3359,
3311,
50,
63,
23715,
63,
8899,
26,
489,
291,
14,
2593,
275,
715,
489,
291,
14,
12000,
6372,
275,
715,
272,
916,
15643,
14,
5764,
508,
402,
14,
3359,
3311,
50,
63,
30322,
63,
8899,
26,
489,
291,
14,
2593,
275,
715,
489,
291
] |
[
1898,
7760,
1603,
14015,
22895,
3630,
443,
89,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
26,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
199,
2765,
365,
314,
2446,
3232,
5060,
859,
14,
199,
199,
2439,
951,
543,
1973,
1490,
1659,
12,
642,
365,
314,
12160,
1777,
402,
314,
3232,
5060,
3261,
315,
3625,
56,
14,
199,
10924,
787,
282,
1329,
402,
27982,
12,
1314,
787,
16711,
4915,
641,
6170,
14,
1490,
1659,
199,
305,
5521,
465,
641,
8212,
6258,
8113,
83,
14,
221,
15517,
402,
3520,
4474,
1172,
737,
199,
11790,
2005,
402,
314,
2569,
4382,
26,
199,
1275,
2105,
446,
282,
3659,
370,
314,
6258,
1950,
626,
18104,
314,
1566,
199,
1275,
26050,
446,
314,
577,
16098,
402,
314,
6258,
626,
18104,
314,
1566,
199,
1275,
20943,
446,
314,
3232,
5060,
1245,
626,
18104,
314,
1566,
334,
504,
1973,
1490,
1659,
9,
199,
199,
4395,
402,
314,
1655,
23515,
17435,
83,
402,
3232,
5060,
365,
23654,
543,
5020,
199,
1155,
6528,
12,
1314,
1443,
11492,
315,
3663,
4184,
334,
390,
9296,
1133,
506,
626,
626,
199,
7330,
1792,
427,
12,
7710,
12,
1325,
626,
18699,
1133,
15248,
652,
687,
506,
688,
8860,
6835,
199,
10603,
1655,
2419,
5403,
680,
221,
1010,
3625,
56,
12,
314,
3066,
4474,
787,
2808,
12,
1325,
1265,
911,
199,
2038,
1183,
2951,
2934,
370,
6938,
370,
314,
9531,
5020,
4474,
1314,
5452,
199,
28654,
402,
642,
367,
1265,
436,
787,
1454,
31974,
1380,
1006,
666,
365,
2808,
14,
199,
199,
19855,
26,
961,
859,
365,
9987,
5847,
6511,
701,
1115,
88,
14,
647,
199,
624,
199,
199,
504,
1115,
88,
14,
773,
14,
264,
782,
492,
627,
199,
504,
1115,
88,
14,
773,
14,
1974,
492,
366,
3150,
1378,
2848,
199,
646,
1973,
1490,
1659,
63,
614,
465,
402,
199,
504,
1115,
88,
14,
773,
14,
6253,
14,
20354,
492,
21944,
421,
199,
533,
8113,
26392,
14175,
334,
2390,
304,
523,
408,
523,
6763,
1380,
282,
6258,
14305,
29672,
819,
481,
16139,
9939,
2544,
8113,
1721,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
304,
272,
291,
14,
2105,
275,
1950,
272,
291,
14,
26050,
275,
1950,
14,
26050,
199,
199,
533,
8113,
1721,
334,
2390,
304,
523,
408,
523,
24997,
1380,
282,
1950,
370,
282,
6258,
965,
2757,
23594,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
15643,
304,
272,
291,
14,
2105,
275,
1950,
272,
291,
14,
26050,
275,
1950,
14,
26050,
272,
291,
14,
20943,
275,
15643,
199,
199,
533,
7949,
2093,
9392,
334,
2390,
304,
523,
408,
523,
24997,
12188,
31594,
402,
376,
15643,
63,
5656,
63,
3179,
1245,
819,
961,
16711,
10986,
465,
1777,
402,
282,
1950,
5847,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
15643,
304,
272,
291,
14,
2105,
275,
1950,
272,
291,
14,
26050,
275,
1950,
14,
26050,
272,
291,
14,
20943,
275,
15643,
199,
199,
533,
8113,
3514,
334,
2390,
304,
523,
408,
523,
24997,
1380,
282,
1950,
370,
6258,
965,
2757,
14669,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
304,
272,
291,
14,
2105,
275,
1950,
272,
291,
14,
26050,
275,
1950,
14,
26050,
199,
199,
533,
10977,
3694,
334,
2390,
304,
523,
408,
523,
481,
16139,
315,
1177,
370,
1844,
2004,
4493,
14,
819,
3483,
334,
2245,
9,
446,
715,
340,
31974,
2952,
282,
1844,
1990,
3483,
523,
5463,
334,
2245,
9,
446,
715,
340,
31974,
2952,
282,
1844,
1990,
5463,
523,
6042,
334,
2245,
9,
446,
715,
340,
31974,
2952,
282,
1844,
1990,
6042,
523,
1844,
334,
442,
9,
446,
1329,
402,
1844,
315,
7894,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
15643,
304,
272,
291,
14,
2105,
275,
1950,
272,
291,
14,
26050,
275,
1950,
14,
26050,
272,
291,
14,
20943,
275,
15643,
272,
291,
14,
5540,
275,
15643,
14,
5764,
508,
402,
14,
6733,
3311,
63,
31225,
272,
291,
14,
3270,
275,
15643,
14,
5764,
508,
402,
14,
6733,
3311,
63,
9732,
272,
291,
14,
6062,
275,
15643,
14,
5764,
508,
402,
14,
6733,
3311,
63,
7014,
272,
291,
14,
719,
275,
15643,
14,
3257,
14,
719,
63,
889,
199,
199,
533,
20823,
23407,
334,
2390,
304,
523,
408,
523,
24997,
1380,
282,
6369,
2397,
965,
2757,
4829,
687,
282,
6369,
1817,
14,
819,
961,
1443,
1902,
506,
2952,
402,
282,
2653,
503,
2952,
652,
1990,
4829,
523,
7662,
14,
523,
19329,
26,
523,
15072,
6372,
334,
2245,
9,
446,
715,
340,
14721,
2952,
402,
1305,
552,
16709,
523,
7508,
6372,
334,
2245,
9,
446,
715,
340,
14721,
2952,
402,
7508,
2653,
523,
2653,
334,
2245,
9,
446,
715,
340,
1902,
402,
314,
3432,
365,
2549,
523,
5463,
334,
2245,
9,
446,
715,
340,
5463,
7662,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
15643,
304,
272,
291,
14,
2105,
275,
1950,
272,
291,
14,
26050,
275,
1950,
14,
26050,
272,
291,
14,
20943,
275,
15643,
272,
291,
14,
12000,
6372,
275,
756,
272,
291,
14,
8726,
6372,
275,
756,
272,
291,
14,
6062,
275,
756,
272,
291,
14,
2593,
275,
756,
272,
340,
15643,
14,
5764,
508,
402,
14,
3359,
3311,
50,
63,
23715,
63,
8899,
26,
489,
291,
14,
2593,
275,
715,
489,
291,
14,
12000,
6372,
275,
715,
272,
916,
15643,
14,
5764,
508,
402,
14,
3359,
3311,
50,
63,
30322,
63,
8899,
26,
489,
291,
14,
2593,
275,
715,
489,
291,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
kenshay/ImageScript
|
ProgramData/SystemFiles/opencv/sources/modules/ts/misc/run.py
|
5
|
41856
|
#!/usr/bin/env python
import sys, os, platform, xml, re, tempfile, glob, datetime, getpass, shutil
from optparse import OptionParser
from subprocess import Popen, PIPE
hostos = os.name # 'nt', 'posix'
hostmachine = platform.machine() # 'x86', 'AMD64', 'x86_64'
errorCode = 0
SIMD_DETECTION_PROGRAM="""
#if __SSE5__
# error SSE5
#endif
#if __AVX2__
# error AVX2
#endif
#if __AVX__
# error AVX
#endif
#if __SSE4_2__
# error SSE4.2
#endif
#if __SSE4_1__
# error SSE4.1
#endif
#if __SSSE3__
# error SSSE3
#endif
#if __SSE3__
# error SSE3
#endif
#if __AES__
# error AES
#endif
#if __SSE2__
# error SSE2
#endif
#if __SSE__
# error SSE
#endif
#if __3dNOW__
# error 3dNOW
#endif
#if __MMX__
# error MMX
#endif
#if __ARM_NEON__
# error NEON
#endif
#error NOSIMD
"""
parse_patterns = (
{'name': "has_perf_tests", 'default': "OFF", 'pattern': re.compile("^BUILD_PERF_TESTS:BOOL=(ON)$")},
{'name': "has_accuracy_tests", 'default': "OFF", 'pattern': re.compile("^BUILD_TESTS:BOOL=(ON)$")},
{'name': "cmake_home", 'default': None, 'pattern': re.compile("^CMAKE_HOME_DIRECTORY:INTERNAL=(.+)$")},
{'name': "opencv_home", 'default': None, 'pattern': re.compile("^OpenCV_SOURCE_DIR:STATIC=(.+)$")},
{'name': "tests_dir", 'default': None, 'pattern': re.compile("^EXECUTABLE_OUTPUT_PATH:PATH=(.+)$")},
{'name': "build_type", 'default': "Release", 'pattern': re.compile("^CMAKE_BUILD_TYPE:STRING=(.*)$")},
{'name': "svnversion_path", 'default': None, 'pattern': re.compile("^SVNVERSION_PATH:FILEPATH=(.*)$")},
{'name': "git_executable", 'default': None, 'pattern': re.compile("^GIT_EXECUTABLE:FILEPATH=(.*)$")},
{'name': "cxx_flags", 'default': "", 'pattern': re.compile("^CMAKE_CXX_FLAGS:STRING=(.*)$")},
{'name': "cxx_flags_debug", 'default': "", 'pattern': re.compile("^CMAKE_CXX_FLAGS_DEBUG:STRING=(.*)$")},
{'name': "cxx_flags_release", 'default': "", 'pattern': re.compile("^CMAKE_CXX_FLAGS_RELEASE:STRING=(.*)$")},
{'name': "opencv_cxx_flags", 'default': "", 'pattern': re.compile("^OPENCV_EXTRA_C_FLAGS:INTERNAL=(.*)$")},
{'name': "opencv_cxx_flags_debug", 'default': "", 'pattern': re.compile("^OPENCV_EXTRA_C_FLAGS_DEBUG:INTERNAL=(.*)$")},
{'name': "opencv_cxx_flags_release", 'default': "", 'pattern': re.compile("^OPENCV_EXTRA_C_FLAGS_RELEASE:INTERNAL=(.*)$")},
{'name': "cxx_flags_android", 'default': None, 'pattern': re.compile("^ANDROID_CXX_FLAGS:INTERNAL=(.*)$")},
{'name': "ndk_path", 'default': None, 'pattern': re.compile("^(?:ANDROID_NDK|ANDROID_STANDALONE_TOOLCHAIN)?:PATH=(.*)$")},
{'name': "android_abi", 'default': None, 'pattern': re.compile("^ANDROID_ABI:STRING=(.*)$")},
{'name': "android_executable", 'default': None, 'pattern': re.compile("^ANDROID_EXECUTABLE:FILEPATH=(.*android.*)$")},
{'name': "ant_executable", 'default': None, 'pattern': re.compile("^ANT_EXECUTABLE:FILEPATH=(.*ant.*)$")},
{'name': "java_test_binary_dir", 'default': None, 'pattern': re.compile("^opencv_test_java_BINARY_DIR:STATIC=(.*)$")},
{'name': "is_x64", 'default': "OFF", 'pattern': re.compile("^CUDA_64_BIT_DEVICE_CODE:BOOL=(ON)$")},#ugly(
{'name': "cmake_generator", 'default': None, 'pattern': re.compile("^CMAKE_GENERATOR:INTERNAL=(.+)$")},
{'name': "cxx_compiler", 'default': None, 'pattern': re.compile("^CMAKE_CXX_COMPILER:FILEPATH=(.+)$")},
{'name': "cxx_compiler_arg1", 'default': None, 'pattern': re.compile("^CMAKE_CXX_COMPILER_ARG1:[A-Z]+=(.+)$")},
{'name': "with_cuda", 'default': "OFF", 'pattern': re.compile("^WITH_CUDA:BOOL=(ON)$")},
{'name': "cuda_library", 'default': None, 'pattern': re.compile("^CUDA_CUDA_LIBRARY:FILEPATH=(.+)$")},
{'name': "core_dependencies", 'default': None, 'pattern': re.compile("^opencv_core_LIB_DEPENDS:STATIC=(.+)$")},
)
def query_yes_no(stdout, question, default="yes"):
valid = {"yes":True, "y":True, "ye":True, "no":False, "n":False}
if default == None:
prompt = " [y/n] "
elif default == "yes":
prompt = " [Y/n] "
elif default == "no":
prompt = " [y/N] "
else:
raise ValueError("invalid default answer: '%s'" % default)
while True:
stdout.write(os.linesep + question + prompt)
choice = raw_input().lower()
if default is not None and choice == '':
return valid[default]
elif choice in valid:
return valid[choice]
else:
stdout.write("Please respond with 'yes' or 'no' "\
"(or 'y' or 'n').\n")
def getRunningProcessExePathByName_win32(name):
from ctypes import windll, POINTER, pointer, Structure, sizeof
from ctypes import c_long , c_int , c_uint , c_char , c_ubyte , c_char_p , c_void_p
class PROCESSENTRY32(Structure):
_fields_ = [ ( 'dwSize' , c_uint ) ,
( 'cntUsage' , c_uint) ,
( 'th32ProcessID' , c_uint) ,
( 'th32DefaultHeapID' , c_uint) ,
( 'th32ModuleID' , c_uint) ,
( 'cntThreads' , c_uint) ,
( 'th32ParentProcessID' , c_uint) ,
( 'pcPriClassBase' , c_long) ,
( 'dwFlags' , c_uint) ,
( 'szExeFile' , c_char * 260 ) ,
( 'th32MemoryBase' , c_long) ,
( 'th32AccessKey' , c_long ) ]
class MODULEENTRY32(Structure):
_fields_ = [ ( 'dwSize' , c_long ) ,
( 'th32ModuleID' , c_long ),
( 'th32ProcessID' , c_long ),
( 'GlblcntUsage' , c_long ),
( 'ProccntUsage' , c_long ) ,
( 'modBaseAddr' , c_long ) ,
( 'modBaseSize' , c_long ) ,
( 'hModule' , c_void_p ) ,
( 'szModule' , c_char * 256 ),
( 'szExePath' , c_char * 260 ) ]
TH32CS_SNAPPROCESS = 2
TH32CS_SNAPMODULE = 0x00000008
## CreateToolhelp32Snapshot
CreateToolhelp32Snapshot= windll.kernel32.CreateToolhelp32Snapshot
CreateToolhelp32Snapshot.reltype = c_long
CreateToolhelp32Snapshot.argtypes = [ c_int , c_int ]
## Process32First
Process32First = windll.kernel32.Process32First
Process32First.argtypes = [ c_void_p , POINTER( PROCESSENTRY32 ) ]
Process32First.rettype = c_int
## Process32Next
Process32Next = windll.kernel32.Process32Next
Process32Next.argtypes = [ c_void_p , POINTER(PROCESSENTRY32) ]
Process32Next.rettype = c_int
## CloseHandle
CloseHandle = windll.kernel32.CloseHandle
CloseHandle.argtypes = [ c_void_p ]
CloseHandle.rettype = c_int
## Module32First
Module32First = windll.kernel32.Module32First
Module32First.argtypes = [ c_void_p , POINTER(MODULEENTRY32) ]
Module32First.rettype = c_int
hProcessSnap = c_void_p(0)
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS , 0 )
pe32 = PROCESSENTRY32()
pe32.dwSize = sizeof( PROCESSENTRY32 )
ret = Process32First( hProcessSnap , pointer( pe32 ) )
path = None
while ret :
if name + ".exe" == pe32.szExeFile:
hModuleSnap = c_void_p(0)
me32 = MODULEENTRY32()
me32.dwSize = sizeof( MODULEENTRY32 )
hModuleSnap = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, pe32.th32ProcessID )
ret = Module32First( hModuleSnap, pointer(me32) )
path = me32.szExePath
CloseHandle( hModuleSnap )
if path:
break
ret = Process32Next( hProcessSnap, pointer(pe32) )
CloseHandle( hProcessSnap )
return path
def getRunningProcessExePathByName_posix(name):
pids= [pid for pid in os.listdir('/proc') if pid.isdigit()]
for pid in pids:
try:
path = os.readlink(os.path.join('/proc', pid, 'exe'))
if path and path.endswith(name):
return path
except:
pass
def getRunningProcessExePathByName(name):
try:
if hostos == "nt":
return getRunningProcessExePathByName_win32(name)
elif hostos == "posix":
return getRunningProcessExePathByName_posix(name)
else:
return None
except:
return None
class TestSuite(object):
def __init__(self, options, path = None):
self.options = options
self.path = path
self.error = None
self.setUp = None
self.tearDown = None
self.adb = None
self.targetos = None
self.nameprefix = "opencv_" + self.options.mode + "_"
for p in parse_patterns:
setattr(self, p["name"], p["default"])
if self.path:
cachefile = open(os.path.join(self.path, "CMakeCache.txt"), "rt")
try:
for l in cachefile.readlines():
ll = l.strip()
if not ll or ll.startswith("#"):
continue
for p in parse_patterns:
match = p["pattern"].match(ll)
if match:
value = match.groups()[0]
if value and not value.endswith("-NOTFOUND"):
setattr(self, p["name"], value)
except:
pass
cachefile.close()
# detect target platform
if self.android_executable or self.android_abi or self.ndk_path:
self.targetos = "android"
else:
self.targetos = hostos
self.initialize()
def initialize(self):
# fix empty tests dir
if not self.tests_dir:
self.tests_dir = self.path
self.tests_dir = os.path.normpath(self.tests_dir)
# compute path to adb
if self.android_executable:
self.adb = os.path.join(os.path.dirname(os.path.dirname(self.android_executable)), ("platform-tools/adb","platform-tools/adb.exe")[hostos == 'nt'])
if not os.path.isfile(self.adb) or not os.access(self.adb, os.X_OK):
self.adb = None
else:
self.adb = None
if self.targetos == "android":
# fix adb tool location
if not self.adb:
self.adb = getRunningProcessExePathByName("adb")
if not self.adb:
self.adb = "adb"
if self.options.adb_serial:
self.adb = [self.adb, "-s", self.options.adb_serial]
else:
self.adb = [self.adb]
try:
output = Popen(self.adb + ["shell", "ls"], stdout=PIPE, stderr=PIPE).communicate()
except OSError:
self.adb = []
# remember current device serial. Needed if another device is connected while this script runs
if self.adb and not self.options.adb_serial:
adb_res = self.runAdb("devices")
if not adb_res:
self.error = "Could not run adb command: %s (for %s)" % (self.error, self.path)
self.adb = []
else:
# assume here that device name may consists of any characters except newline
connected_devices = re.findall(r"^[^\n]+[ \t]+device\r?$", adb_res, re.MULTILINE)
if not connected_devices:
self.error = "Android device not found"
self.adb = []
elif len(connected_devices) != 1:
self.error = "Too many (%s) devices are connected. Please specify single device using --serial option:\n\n" % (len(connected_devices)) + adb_res
self.adb = []
else:
self.options.adb_serial = connected_devices[0].split("\t")[0]
self.adb = self.adb + ["-s", self.options.adb_serial]
if self.adb:
# construct name for aapt tool
self.aapt = [os.path.join(os.path.dirname(self.adb[0]), ("aapt","aapt.exe")[hostos == 'nt'])]
if not os.path.isfile(self.aapt[0]):
# it's moved in SDK r22
sdk_dir = os.path.dirname( os.path.dirname(self.adb[0]) )
aapt_fn = ("aapt", "aapt.exe")[hostos == 'nt']
for r, ds, fs in os.walk( os.path.join(sdk_dir, 'build-tools') ):
if aapt_fn in fs:
self.aapt = [ os.path.join(r, aapt_fn) ]
break
else:
self.error = "Can't find '%s' tool!" % aapt_fn
# fix has_perf_tests param
self.has_perf_tests = self.has_perf_tests == "ON"
self.has_accuracy_tests = self.has_accuracy_tests == "ON"
# fix is_x64 flag
self.is_x64 = self.is_x64 == "ON"
if not self.is_x64 and ("X64" in "%s %s %s" % (self.cxx_flags, self.cxx_flags_release, self.cxx_flags_debug) or "Win64" in self.cmake_generator):
self.is_x64 = True
# fix test path
if "Visual Studio" in self.cmake_generator:
if self.options.configuration:
self.tests_dir = os.path.join(self.tests_dir, self.options.configuration)
else:
self.tests_dir = os.path.join(self.tests_dir, self.build_type)
elif not self.is_x64 and self.cxx_compiler:
#one more attempt to detect x64 compiler
try:
compiler = [self.cxx_compiler]
if self.cxx_compiler_arg1:
compiler.append(self.cxx_compiler_arg1)
output = Popen(compiler + ["-v"], stdout=PIPE, stderr=PIPE).communicate()
if not output[0] and "x86_64" in output[1]:
self.is_x64 = True
except OSError:
pass
# detect target arch
if self.targetos == "android":
if "armeabi-v7a" in self.android_abi:
self.targetarch = "armv7a"
elif "armeabi-v6" in self.android_abi:
self.targetarch = "armv6"
elif "armeabi" in self.android_abi:
self.targetarch = "armv5te"
elif "x86" in self.android_abi:
self.targetarch = "x86"
elif "mips" in self.android_abi:
self.targetarch = "mips"
else:
self.targetarch = "ARM"
elif self.is_x64 and hostmachine in ["AMD64", "x86_64"]:
self.targetarch = "x64"
elif hostmachine in ["x86", "AMD64", "x86_64"]:
self.targetarch = "x86"
else:
self.targetarch = "unknown"
# fix CUDA attributes
self.with_cuda = self.with_cuda == "ON"
if self.cuda_library and self.cuda_library.endswith("-NOTFOUND"):
self.cuda_library = None
self.has_cuda = self.with_cuda and self.cuda_library and self.targetarch in ["x86", "x64"]
self.hardware = None
self.cmake_home_vcver = self.getVCVersion(self.cmake_home)
if self.opencv_home == self.cmake_home:
self.opencv_home_vcver = self.cmake_home_vcver
else:
self.opencv_home_vcver = self.getVCVersion(self.opencv_home)
self.tests = self.getAvailableTestApps()
def getVCVersion(self, root_path):
if not root_path:
return None
if os.path.isdir(os.path.join(root_path, ".svn")):
return self.getSvnVersion(root_path)
elif os.path.isdir(os.path.join(root_path, ".git")):
return self.getGitHash(root_path)
return None
def getGitHash(self, path):
if not path or not self.git_executable:
return None
try:
output = Popen([self.git_executable, "rev-parse", "--short", "HEAD"], stdout=PIPE, stderr=PIPE, cwd = path).communicate()
if not output[1]:
return output[0].strip()
else:
return None
except OSError:
return None
def getSvnVersion(self, path):
if not path:
val = None
elif not self.svnversion_path and hostos == 'nt':
val = self.tryGetSvnVersionWithTortoise(path)
else:
svnversion = self.svnversion_path
if not svnversion:
svnversion = "svnversion"
try:
output = Popen([svnversion, "-n", path], stdout=PIPE, stderr=PIPE).communicate()
if not output[1]:
val = output[0]
else:
val = None
except OSError:
val = None
if val:
val = val.replace(" ", "_")
return val
def tryGetSvnVersionWithTortoise(self, path):
try:
wcrev = "SubWCRev.exe"
dir = tempfile.mkdtemp()
#print dir
tmpfilename = os.path.join(dir, "svn.tmp")
tmpfilename2 = os.path.join(dir, "svn_out.tmp")
tmpfile = open(tmpfilename, "w")
tmpfile.write("$WCRANGE$$WCMODS?M:$")
tmpfile.close();
output = Popen([wcrev, path, tmpfilename, tmpfilename2, "-f"], stdout=PIPE, stderr=PIPE).communicate()
if "is not a working copy" in output[0]:
version = "exported"
else:
tmpfile = open(tmpfilename2, "r")
version = tmpfile.read()
tmpfile.close()
return version
except:
return None
finally:
if dir:
shutil.rmtree(dir)
def isTest(self, fullpath):
if not os.path.isfile(fullpath):
return False
if self.targetos == "nt" and not fullpath.endswith(".exe"):
return False
if hostos == self.targetos:
return os.access(fullpath, os.X_OK)
if self.targetos == "android" and fullpath.endswith(".apk"):
return True
return True
def getAvailableTestApps(self):
if self.tests_dir and os.path.isdir(self.tests_dir):
files = glob.glob(os.path.join(self.tests_dir, self.nameprefix + "*"))
files = [f for f in files if self.isTest(f)]
if self.ant_executable and self.java_test_binary_dir:
files.append("java")
return files
return []
def getLogName(self, app, timestamp):
app = os.path.basename(app)
if app.endswith(".exe"):
if app.endswith("d.exe"):
app = app[:-5]
else:
app = app[:-4]
if app.startswith(self.nameprefix):
app = app[len(self.nameprefix):]
if self.cmake_home_vcver:
if self.cmake_home_vcver == self.opencv_home_vcver:
rev = self.cmake_home_vcver
elif self.opencv_home_vcver:
rev = self.cmake_home_vcver + "-" + self.opencv_home_vcver
else:
rev = self.cmake_home_vcver
else:
rev = None
if rev:
rev = rev.replace(":","to")
else:
rev = ""
if self.options.useLongNames:
if not rev:
rev = "unknown"
tstamp = timestamp.strftime("%Y%m%d-%H%M%S")
features = []
#OS
_os = ""
if self.targetos == "android":
_os = "Android" + self.runAdb("shell", "getprop ro.build.version.release").strip()
else:
mv = platform.mac_ver()
if mv[0]:
_os = "Darwin" + mv[0]
else:
wv = platform.win32_ver()
if wv[0]:
_os = "Windows" + wv[0]
else:
lv = platform.linux_distribution()
if lv[0]:
_os = lv[0] + lv[1]
else:
_os = self.targetos
features.append(_os)
#HW(x86, x64, ARMv7a)
if self.targetarch:
features.append(self.targetarch)
#TBB
if ";tbb;" in self.core_dependencies:
features.append("TBB")
#CUDA
if self.has_cuda:
#TODO: determine compute capability
features.append("CUDA")
#SIMD
compiler_output = ""
try:
tmpfile = tempfile.mkstemp(suffix=".cpp", text = True)
fd = os.fdopen(tmpfile[0], "w+b")
fd.write(SIMD_DETECTION_PROGRAM)
fd.close();
options = [self.cxx_compiler]
if self.cxx_compiler_arg1:
options.append(self.cxx_compiler_arg1)
cxx_flags = self.cxx_flags + " " + self.cxx_flags_release + " " + self.opencv_cxx_flags + " " + self.opencv_cxx_flags_release
if self.targetos == "android" and self.cxx_flags_android:
cxx_flags = self.cxx_flags_android + " " + cxx_flags
prev_option = None
for opt in cxx_flags.split(" "):
if opt.count('\"') % 2 == 1:
if prev_option is None:
prev_option = opt
else:
options.append(prev_option + " " + opt)
prev_option = None
elif prev_option is None:
options.append(opt)
else:
prev_option = prev_option + " " + opt
options.append(tmpfile[1])
output = Popen(options, stdout=PIPE, stderr=PIPE).communicate()
compiler_output = output[1]
os.remove(tmpfile[1])
except OSError:
pass
if compiler_output:
m = re.search("#error\W+(\w+)", compiler_output)
if m:
features.append(m.group(1))
#fin
return "%s__%s__%s__%s.xml" % (app, rev, tstamp, "_".join(features))
else:
if rev:
rev = rev + "_"
if self.hardware:
hw = str(self.hardware).replace(" ", "_") + "_"
elif self.has_cuda:
hw = "CUDA_"
else:
hw = ""
tstamp = timestamp.strftime("%Y%m%d-%H%M%S")
lname = "%s_%s_%s_%s%s%s.xml" % (app, self.targetos, self.targetarch, hw, rev, tstamp)
lname = str.replace(lname, '(', '_')
lname = str.replace(lname, ')', '_')
return lname
def getTest(self, name):
# full path
if self.isTest(name):
return name
# name only
fullname = os.path.join(self.tests_dir, name)
if self.isTest(fullname):
return fullname
# name without extension
fullname += ".exe"
if self.isTest(fullname):
return fullname
if self.targetos == "android":
fullname += ".apk"
if self.isTest(fullname):
return fullname
# short name for OpenCV tests
for t in self.tests:
if t == name:
return t
fname = os.path.basename(t)
if fname == name:
return t
if fname.endswith(".exe") or (self.targetos == "android" and fname.endswith(".apk")):
fname = fname[:-4]
if fname == name:
return t
if self.options.configuration == "Debug" and fname == name + 'd':
return t
if fname.startswith(self.nameprefix):
fname = fname[len(self.nameprefix):]
if fname == name:
return t
if self.options.configuration == "Debug" and fname == name + 'd':
return t
return None
def runAdb(self, *args):
cmd = self.adb[:]
cmd.extend(args)
try:
output = Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()
if not output[1]:
return output[0]
self.error = output[1]
except OSError:
pass
return None
def isRunnable(self):
if self.error:
return False
if self.targetarch == "x64" and hostmachine == "x86":
self.error = "Target architecture is incompatible with current platform (at %s)" % self.path
return False
if self.targetos == "android":
if not self.adb:
self.error = "Could not find adb executable (for %s)" % self.path
return False
if "armeabi-v7a" in self.android_abi:
adb_res = self.runAdb("shell", "cat /proc/cpuinfo")
if not adb_res:
self.error = "Could not get info about Android platform: %s (for %s)" % (self.error, self.path)
return False
if "ARMv7" not in adb_res:
self.error = "Android device does not support ARMv7 commands, but tests are built for armeabi-v7a (for %s)" % self.path
return False
if "NEON" in self.android_abi and "neon" not in adb_res:
self.error = "Android device has no NEON, but tests are built for %s (for %s)" % (self.android_abi, self.path)
return False
hw = re.search(r"^Hardware[ \t]*:[ \t]*(.*?)$", adb_res, re.MULTILINE)
if hw:
self.hardware = hw.groups()[0].strip()
return True
def runTest(self, path, workingDir, _stdout, _stderr, args = []):
global errorCode
if self.error:
return
args = args[:]
timestamp = datetime.datetime.now()
logfile = self.getLogName(path, timestamp)
exe = os.path.abspath(path)
userlog = [a for a in args if a.startswith("--gtest_output=")]
if len(userlog) == 0:
args.append("--gtest_output=xml:" + logfile)
else:
logfile = userlog[0][userlog[0].find(":")+1:]
if self.targetos == "android" and exe.endswith(".apk"):
print "Run java tests:", exe
try:
# get package info
output = Popen(self.aapt + ["dump", "xmltree", exe, "AndroidManifest.xml"], stdout=PIPE, stderr=_stderr).communicate()
if not output[0]:
print >> _stderr, "fail to dump manifest from", exe
return
tags = re.split(r"[ ]+E: ", output[0])
# get package name
manifest_tag = [t for t in tags if t.startswith("manifest ")]
if not manifest_tag:
print >> _stderr, "fail to read package name from", exe
return
pkg_name = re.search(r"^[ ]+A: package=\"(?P<pkg>.*?)\" \(Raw: \"(?P=pkg)\"\)\r?$", manifest_tag[0], flags=re.MULTILINE).group("pkg")
# get test instrumentation info
instrumentation_tag = [t for t in tags if t.startswith("instrumentation ")]
if not instrumentation_tag:
print >> _stderr, "can not find instrumentation detials in", exe
return
pkg_runner = re.search(r"^[ ]+A: android:name\(0x[0-9a-f]{8}\)=\"(?P<runner>.*?)\" \(Raw: \"(?P=runner)\"\)\r?$", instrumentation_tag[0], flags=re.MULTILINE).group("runner")
pkg_target = re.search(r"^[ ]+A: android:targetPackage\(0x[0-9a-f]{8}\)=\"(?P<pkg>.*?)\" \(Raw: \"(?P=pkg)\"\)\r?$", instrumentation_tag[0], flags=re.MULTILINE).group("pkg")
if not pkg_name or not pkg_runner or not pkg_target:
print >> _stderr, "can not find instrumentation detials in", exe
return
if self.options.junit_package:
if self.options.junit_package.startswith("."):
pkg_target += self.options.junit_package
else:
pkg_target = self.options.junit_package
# uninstall previously installed package
print >> _stderr, "Uninstalling old", pkg_name, "from device..."
Popen(self.adb + ["uninstall", pkg_name], stdout=PIPE, stderr=_stderr).communicate()
print >> _stderr, "Installing new", exe, "to device...",
output = Popen(self.adb + ["install", exe], stdout=PIPE, stderr=PIPE).communicate()
if output[0] and output[0].strip().endswith("Success"):
print >> _stderr, "Success"
else:
print >> _stderr, "Failure"
print >> _stderr, "Failed to install", exe, "to device"
return
print >> _stderr, "Running jUnit tests for ", pkg_target
if self.setUp:
self.setUp()
Popen(self.adb + ["shell", "am instrument -w -e package " + pkg_target + " " + pkg_name + "/" + pkg_runner], stdout=_stdout, stderr=_stderr).wait()
if self.tearDown:
self.tearDown()
except OSError:
pass
return
elif self.targetos == "android":
hostlogpath = ""
usercolor = [a for a in args if a.startswith("--gtest_color=")]
if len(usercolor) == 0 and _stdout.isatty() and hostos != "nt":
args.append("--gtest_color=yes")
try:
tempdir = "/data/local/tmp/"
andoidcwd = tempdir + getpass.getuser().replace(" ","") + "_" + self.options.mode +"/"
exename = os.path.basename(exe)
androidexe = andoidcwd + exename
# upload
_stderr.write("Uploading... ")
output = Popen(self.adb + ["push", exe, androidexe], stdout=_stdout, stderr=_stderr).wait()
if output != 0:
print >> _stderr, "adb finishes unexpectedly with error code", output
return
# chmod
output = Popen(self.adb + ["shell", "chmod 777 " + androidexe], stdout=_stdout, stderr=_stderr).wait()
if output != 0:
print >> _stderr, "adb finishes unexpectedly with error code", output
return
# run
if self.options.help:
command = exename + " --help"
else:
command = exename + " " + " ".join(args)
print >> _stderr, "Run command:", command
if self.setUp:
self.setUp()
env = self.options.android_env.copy()
env['OPENCV_TEST_DATA_PATH'] = self.options.test_data_path
if self.options.android_propagate_opencv_env:
for k, v in os.environ.items():
if k.startswith('OPENCV') and not k in env:
env[k] = v
print >> _stderr, "Android environment variables: \n", '\n'.join([' %s=%s' % (k, v) for k, v in env.items()])
commandPrefix = ''.join(['export %s=%s && ' % (k, v) for k, v in env.items()])
Popen(self.adb + ["shell", commandPrefix + "cd " + andoidcwd + "&& ./" + command], stdout=_stdout, stderr=_stderr).wait()
if self.tearDown:
self.tearDown()
# try get log
if not self.options.help:
#_stderr.write("Pull log... ")
hostlogpath = os.path.join(workingDir, logfile)
output = Popen(self.adb + ["pull", andoidcwd + logfile, hostlogpath], stdout=_stdout, stderr=PIPE).wait()
if output != 0:
print >> _stderr, "adb finishes unexpectedly with error code", output
return
#rm log
Popen(self.adb + ["shell", "rm " + andoidcwd + logfile], stdout=PIPE, stderr=PIPE).wait()
# clean temporary files
Popen(self.adb + ["shell", "rm " + tempdir + "__opencv_temp.*"], stdout=PIPE, stderr=PIPE).wait()
except OSError:
pass
if os.path.isfile(hostlogpath):
return hostlogpath
return None
elif path == "java":
cmd = [self.ant_executable,
"-Dopencv.build.type="
+ (self.options.configuration if self.options.configuration else self.build_type),
"buildAndTest"]
print >> _stderr, "Run command:", " ".join(cmd)
try:
errorCode = Popen(cmd, stdout=_stdout, stderr=_stderr, cwd = self.java_test_binary_dir + "/.build").wait()
except:
print "Unexpected error:", sys.exc_info()[0]
return None
else:
cmd = [exe]
if self.options.help:
cmd.append("--help")
else:
cmd.extend(args)
orig_temp_path = os.environ.get('OPENCV_TEMP_PATH')
temp_path = tempfile.mkdtemp(prefix="__opencv_temp.", dir=orig_temp_path or None)
os.environ['OPENCV_TEMP_PATH'] = temp_path
print >> _stderr, "Run command:", " ".join(cmd)
try:
errorCode = Popen(cmd, stdout=_stdout, stderr=_stderr, cwd = workingDir).wait()
except:
print "Unexpected error:", sys.exc_info()[0]
# clean temporary files
if orig_temp_path:
os.environ['OPENCV_TEMP_PATH'] = orig_temp_path
else:
del os.environ['OPENCV_TEMP_PATH']
try:
shutil.rmtree(temp_path)
pass
except:
pass
logpath = os.path.join(workingDir, logfile)
if os.path.isfile(logpath):
return logpath
return None
def runTests(self, tests, _stdout, _stderr, workingDir, args = []):
if not self.isRunnable():
print >> _stderr, "Error:", self.error
if self.error:
return []
if self.adb and self.targetos == "android":
print "adb command:", " ".join(self.adb)
if not tests:
tests = self.tests
logs = []
for test in tests:
t = self.getTest(test)
if t:
logfile = self.runTest(t, workingDir, _stdout, _stderr, args)
if logfile:
logs.append(os.path.relpath(logfile, "."))
else:
print >> _stderr, "Error: Test \"%s\" is not found in %s" % (test, self.tests_dir)
return logs
def getRunArgs(args):
run_args = []
for path in args:
path = os.path.abspath(path)
while (True):
if os.path.isdir(path) and os.path.isfile(os.path.join(path, "CMakeCache.txt")):
run_args.append(path)
break
npath = os.path.dirname(path)
if npath == path:
break
path = npath
return run_args
if hostos == "nt":
def moveTests(instance, destination):
src = os.path.dirname(instance.tests_dir)
# new binaries path
newBinPath = os.path.join(destination, "bin")
try:
# copy binaries and CMakeCache.txt to the specified destination
shutil.copytree(src, newBinPath)
shutil.copy(os.path.join(instance.path, "CMakeCache.txt"), os.path.join(destination, "CMakeCache.txt"))
except Exception, e:
print "Copying error occurred:", str(e)
exit(e.errno)
# pattern of CMakeCache.txt string to be replaced
replacePattern = re.compile("EXECUTABLE_OUTPUT_PATH:PATH=(.+)")
with open(os.path.join(destination, "CMakeCache.txt"), "r") as cachefile:
try:
cachedata = cachefile.read()
if hostos == 'nt':
# fix path slashes on nt systems
newBinPath = re.sub(r"\\", r"/", newBinPath)
# replace old binaries path in CMakeCache.txt
cachedata = re.sub(re.search(replacePattern, cachedata).group(1), newBinPath, cachedata)
except Exception, e:
print "Reading error occurred:", str(e)
exit(e.errno)
with open(os.path.join(destination, "CMakeCache.txt"), "w") as cachefile:
try:
cachefile.write(cachedata)
except Exception, e:
print "Writing error occurred:", str(e)
exit(e.errno)
exit()
if __name__ == "__main__":
test_args = [a for a in sys.argv if a.startswith("--perf_") or a.startswith("--gtest_")]
argv = [a for a in sys.argv if not(a.startswith("--perf_") or a.startswith("--gtest_"))]
parser = OptionParser(usage="run.py [options] [build_path]", description="Note: build_path is required if running not from CMake build directory")
parser.add_option("-t", "--tests", dest="tests", help="comma-separated list of modules to test", metavar="SUITS", default="")
if hostos == "nt":
parser.add_option("-m", "--move_tests", dest="move", help="location to move current tests build", metavar="PATH", default="")
parser.add_option("-w", "--cwd", dest="cwd", help="working directory for tests", metavar="PATH", default=".")
parser.add_option("-a", "--accuracy", dest="accuracy", help="look for accuracy tests instead of performance tests", action="store_true", default=False)
parser.add_option("-l", "--longname", dest="useLongNames", action="store_true", help="generate log files with long names", default=False)
parser.add_option("", "--android_test_data_path", dest="test_data_path", help="OPENCV_TEST_DATA_PATH for Android run", metavar="PATH", default="/sdcard/opencv_testdata/")
parser.add_option("", "--android_env", dest="android_env_array", help="Environment variable for Android run (NAME=VALUE)", action='append')
parser.add_option("", "--android_propagate_opencv_env", dest="android_propagate_opencv_env", help="Propagate OPENCV* environment variables for Android run", action="store_true", default=False)
parser.add_option("", "--configuration", dest="configuration", help="force Debug or Release configuration", metavar="CFG", default="")
parser.add_option("", "--serial", dest="adb_serial", help="Android: directs command to the USB device or emulator with the given serial number", metavar="serial number", default="")
parser.add_option("", "--package", dest="junit_package", help="Android: run jUnit tests for specified package", metavar="package", default="")
parser.add_option("", "--help-tests", dest="help", help="Show help for test executable", action="store_true", default=False)
parser.add_option("", "--check", dest="check", help="Shortcut for '--perf_min_samples=1 --perf_force_samples=1'", action="store_true", default=False)
parser.add_option("", "--list", dest="list", help="List available tests", action="store_true", default=False)
(options, args) = parser.parse_args(argv)
if options.accuracy:
options.mode = "test"
else:
options.mode = "perf"
run_args = getRunArgs(args[1:] or ['.'])
if len(run_args) == 0:
print >> sys.stderr, "Usage:", os.path.basename(sys.argv[0]), "[options] [build_path]"
print >> sys.stderr, "Please specify build_path or run script from CMake build directory"
exit(1)
options.android_env = {}
if options.android_env_array:
for entry in options.android_env_array:
k, v = entry.split("=", 1)
options.android_env[k] = v
tests = [s.strip() for s in options.tests.split(",") if s]
if len(tests) != 1 or len(run_args) != 1:
# remove --gtest_output from params
test_args = [a for a in test_args if not a.startswith("--gtest_output=")]
if options.check:
if not [a for a in test_args if a.startswith("--perf_min_samples=")] :
test_args.extend(["--perf_min_samples=1"])
if not [a for a in test_args if a.startswith("--perf_force_samples=")] :
test_args.extend(["--perf_force_samples=1"])
if not [a for a in test_args if a.startswith("--perf_verify_sanity")] :
test_args.extend(["--perf_verify_sanity"])
logs = []
test_list = []
for path in run_args:
suite = TestSuite(options, path)
if hostos == "nt":
if(options.move):
moveTests(suite, options.move)
#print vars(suite),"\n"
if options.list:
test_list.extend(suite.tests)
else:
logs.extend(suite.runTests(tests, sys.stdout, sys.stderr, options.cwd, test_args))
if options.list:
print os.linesep.join(test_list) or "No tests found"
if logs:
print >> sys.stderr, "Collected: ", " ".join(logs)
if errorCode != 0:
print "Error code: ", errorCode, (" (0x%x)" % (errorCode & 0xffffffff))
exit(errorCode)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
984,
12,
747,
12,
4298,
12,
2748,
12,
295,
12,
5549,
12,
5739,
12,
2197,
12,
18354,
12,
5145,
199,
504,
8691,
492,
13491,
199,
504,
3873,
492,
13995,
12,
22773,
199,
199,
1102,
736,
275,
747,
14,
354,
327,
283,
343,
297,
283,
9228,
7,
199,
1102,
6744,
275,
4298,
14,
6744,
342,
327,
283,
88,
1184,
297,
283,
22909,
772,
297,
283,
88,
1184,
63,
772,
7,
199,
199,
705,
3034,
275,
378,
199,
199,
25435,
63,
17442,
23658,
63,
15605,
11916,
199,
3,
692,
636,
24932,
21,
363,
199,
3,
1125,
428,
899,
21,
199,
3,
13739,
199,
3,
692,
636,
6087,
56,
18,
363,
199,
3,
1125,
437,
28493,
18,
199,
3,
13739,
199,
3,
692,
636,
6087,
56,
363,
199,
3,
1125,
437,
28493,
199,
3,
13739,
199,
3,
692,
636,
24932,
20,
63,
18,
363,
199,
3,
1125,
428,
899,
20,
14,
18,
199,
3,
13739,
199,
3,
692,
636,
24932,
20,
63,
17,
363,
199,
3,
1125,
428,
899,
20,
14,
17,
199,
3,
13739,
199,
3,
692,
636,
2300,
899,
19,
363,
199,
3,
1125,
428,
24932,
19,
199,
3,
13739,
199,
3,
692,
636,
24932,
19,
363,
199,
3,
1125,
428,
899,
19,
199,
3,
13739,
199,
3,
692,
636,
14494,
363,
199,
3,
1125,
19093,
199,
3,
13739,
199,
3,
692,
636,
24932,
18,
363,
199,
3,
1125,
428,
899,
18,
199,
3,
13739,
199,
3,
692,
636,
24932,
363,
199,
3,
1125,
428,
899,
199,
3,
13739,
199,
3,
692,
636,
19,
68,
14283,
363,
199,
3,
1125,
650,
68,
14283,
199,
3,
13739,
199,
3,
692,
636,
3218,
56,
363,
199,
3,
1125,
603,
17401,
199,
3,
13739,
199,
3,
692,
636,
12482,
63,
6388,
615,
363,
199,
3,
1125,
7110,
615,
199,
3,
13739,
199,
3,
705,
653,
3100,
1469,
36,
199,
624,
199,
199,
1122,
63,
7435,
275,
334,
523,
791,
354,
356,
298,
1989,
63,
9452,
63,
2219,
401,
3698,
283,
885,
356,
298,
7517,
401,
420,
283,
3401,
356,
295,
14,
2014,
18523,
8248,
63,
17038,
63,
7569,
26,
16026,
2687,
615,
9,
22550,
1386,
523,
791,
354,
356,
298,
1989,
63,
13374,
63,
2219,
401,
755,
283,
885,
356,
298,
7517,
401,
420,
283,
3401,
356,
295,
14,
2014,
18523,
8248,
63,
7569,
26,
16026,
2687,
615,
9,
22550,
1386,
523,
791,
354,
356,
298,
16472,
63,
4219,
401,
5185,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
30250,
63,
9524,
63,
16436,
26,
17681,
2687,
6977,
9,
22550,
1386,
523,
791,
354,
356,
298,
1490,
5107,
63,
4219,
401,
4519,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
4299,
12847,
63,
10187,
63,
3022,
26,
10449,
2687,
6977,
9,
22550,
1386,
523,
791,
354,
356,
298,
2219,
63,
694,
401,
4483,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
21623,
63,
8414,
63,
3243,
26,
3243,
2687,
6977,
9,
22550,
1386,
523,
791,
354,
356,
298,
1506,
63,
466,
401,
5185,
283,
885,
356,
298,
9625,
401,
221,
283,
3401,
356,
295,
14,
2014,
18523,
30250,
63,
8248,
63,
2711,
26,
5353,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
6836,
1023,
63,
515,
401,
3515,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
31222,
4612,
63,
3243,
26,
3817,
3243,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
3187,
63,
5904,
401,
3698,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
20072,
63,
21623,
26,
3817,
3243,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
9634,
63,
2469,
401,
4483,
283,
885,
356,
4873,
260,
283,
3401,
356,
295,
14,
2014,
18523,
30250,
63,
12206,
63,
4831,
26,
5353,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
9634,
63,
2469,
63,
1757,
401,
3515,
283,
885,
356,
4873,
260,
283,
3401,
356,
295,
14,
2014,
18523,
30250,
63,
12206,
63,
4831,
63,
5287,
26,
5353,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
9634,
63,
2469,
63,
3221,
401,
263,
283,
885,
356,
4873,
260,
283,
3401,
356,
295,
14,
2014,
18523,
30250,
63,
12206,
63,
4831,
63,
19736,
26,
5353,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
1490,
5107,
63,
9634,
63,
2469,
401,
260,
283,
885,
356,
4873,
260,
283,
3401,
356,
295,
14,
2014,
18523,
1938,
9415,
54,
63,
18555,
63,
35,
63,
4831,
26,
17681,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
1490,
5107,
63,
9634,
63,
2469,
63,
1757,
401,
257,
283,
885,
356,
4873,
260,
283,
3401,
356,
295,
14,
2014,
18523,
1938,
9415,
54,
63,
18555,
63,
35,
63,
4831,
63,
5287,
26,
17681,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
1490,
5107,
63,
9634,
63,
2469,
63,
3221,
401,
283,
885,
356,
4873,
260,
283,
3401,
356,
295,
14,
2014,
18523,
1938,
9415,
54,
63,
18555,
63,
35,
63,
4831,
63,
19736,
26,
17681,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
9634,
63,
2469,
63,
6238,
401,
263,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
25658,
63,
12206,
63,
4831,
26,
17681,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
977,
75,
63,
515,
401,
463,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
5169,
25658,
63,
8711,
43,
92,
25658,
63,
840,
3649,
748,
4817,
63,
9731,
25256,
5547,
26,
3243,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
6238,
63,
14677,
401,
4519,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
25658,
63,
1217,
41,
26,
5353,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
6238,
63,
5904,
401,
755,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
25658,
63,
21623,
26,
3817,
3243,
2687,
2795,
6238,
12432,
22550,
1386,
523,
791,
354,
356,
298,
867,
63,
5904,
401,
3698,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
1441,
63,
21623,
26,
3817,
3243,
2687,
2795,
867,
12432
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
984,
12,
747,
12,
4298,
12,
2748,
12,
295,
12,
5549,
12,
5739,
12,
2197,
12,
18354,
12,
5145,
199,
504,
8691,
492,
13491,
199,
504,
3873,
492,
13995,
12,
22773,
199,
199,
1102,
736,
275,
747,
14,
354,
327,
283,
343,
297,
283,
9228,
7,
199,
1102,
6744,
275,
4298,
14,
6744,
342,
327,
283,
88,
1184,
297,
283,
22909,
772,
297,
283,
88,
1184,
63,
772,
7,
199,
199,
705,
3034,
275,
378,
199,
199,
25435,
63,
17442,
23658,
63,
15605,
11916,
199,
3,
692,
636,
24932,
21,
363,
199,
3,
1125,
428,
899,
21,
199,
3,
13739,
199,
3,
692,
636,
6087,
56,
18,
363,
199,
3,
1125,
437,
28493,
18,
199,
3,
13739,
199,
3,
692,
636,
6087,
56,
363,
199,
3,
1125,
437,
28493,
199,
3,
13739,
199,
3,
692,
636,
24932,
20,
63,
18,
363,
199,
3,
1125,
428,
899,
20,
14,
18,
199,
3,
13739,
199,
3,
692,
636,
24932,
20,
63,
17,
363,
199,
3,
1125,
428,
899,
20,
14,
17,
199,
3,
13739,
199,
3,
692,
636,
2300,
899,
19,
363,
199,
3,
1125,
428,
24932,
19,
199,
3,
13739,
199,
3,
692,
636,
24932,
19,
363,
199,
3,
1125,
428,
899,
19,
199,
3,
13739,
199,
3,
692,
636,
14494,
363,
199,
3,
1125,
19093,
199,
3,
13739,
199,
3,
692,
636,
24932,
18,
363,
199,
3,
1125,
428,
899,
18,
199,
3,
13739,
199,
3,
692,
636,
24932,
363,
199,
3,
1125,
428,
899,
199,
3,
13739,
199,
3,
692,
636,
19,
68,
14283,
363,
199,
3,
1125,
650,
68,
14283,
199,
3,
13739,
199,
3,
692,
636,
3218,
56,
363,
199,
3,
1125,
603,
17401,
199,
3,
13739,
199,
3,
692,
636,
12482,
63,
6388,
615,
363,
199,
3,
1125,
7110,
615,
199,
3,
13739,
199,
3,
705,
653,
3100,
1469,
36,
199,
624,
199,
199,
1122,
63,
7435,
275,
334,
523,
791,
354,
356,
298,
1989,
63,
9452,
63,
2219,
401,
3698,
283,
885,
356,
298,
7517,
401,
420,
283,
3401,
356,
295,
14,
2014,
18523,
8248,
63,
17038,
63,
7569,
26,
16026,
2687,
615,
9,
22550,
1386,
523,
791,
354,
356,
298,
1989,
63,
13374,
63,
2219,
401,
755,
283,
885,
356,
298,
7517,
401,
420,
283,
3401,
356,
295,
14,
2014,
18523,
8248,
63,
7569,
26,
16026,
2687,
615,
9,
22550,
1386,
523,
791,
354,
356,
298,
16472,
63,
4219,
401,
5185,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
30250,
63,
9524,
63,
16436,
26,
17681,
2687,
6977,
9,
22550,
1386,
523,
791,
354,
356,
298,
1490,
5107,
63,
4219,
401,
4519,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
4299,
12847,
63,
10187,
63,
3022,
26,
10449,
2687,
6977,
9,
22550,
1386,
523,
791,
354,
356,
298,
2219,
63,
694,
401,
4483,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
21623,
63,
8414,
63,
3243,
26,
3243,
2687,
6977,
9,
22550,
1386,
523,
791,
354,
356,
298,
1506,
63,
466,
401,
5185,
283,
885,
356,
298,
9625,
401,
221,
283,
3401,
356,
295,
14,
2014,
18523,
30250,
63,
8248,
63,
2711,
26,
5353,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
6836,
1023,
63,
515,
401,
3515,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
31222,
4612,
63,
3243,
26,
3817,
3243,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
3187,
63,
5904,
401,
3698,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
20072,
63,
21623,
26,
3817,
3243,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
9634,
63,
2469,
401,
4483,
283,
885,
356,
4873,
260,
283,
3401,
356,
295,
14,
2014,
18523,
30250,
63,
12206,
63,
4831,
26,
5353,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
9634,
63,
2469,
63,
1757,
401,
3515,
283,
885,
356,
4873,
260,
283,
3401,
356,
295,
14,
2014,
18523,
30250,
63,
12206,
63,
4831,
63,
5287,
26,
5353,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
9634,
63,
2469,
63,
3221,
401,
263,
283,
885,
356,
4873,
260,
283,
3401,
356,
295,
14,
2014,
18523,
30250,
63,
12206,
63,
4831,
63,
19736,
26,
5353,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
1490,
5107,
63,
9634,
63,
2469,
401,
260,
283,
885,
356,
4873,
260,
283,
3401,
356,
295,
14,
2014,
18523,
1938,
9415,
54,
63,
18555,
63,
35,
63,
4831,
26,
17681,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
1490,
5107,
63,
9634,
63,
2469,
63,
1757,
401,
257,
283,
885,
356,
4873,
260,
283,
3401,
356,
295,
14,
2014,
18523,
1938,
9415,
54,
63,
18555,
63,
35,
63,
4831,
63,
5287,
26,
17681,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
1490,
5107,
63,
9634,
63,
2469,
63,
3221,
401,
283,
885,
356,
4873,
260,
283,
3401,
356,
295,
14,
2014,
18523,
1938,
9415,
54,
63,
18555,
63,
35,
63,
4831,
63,
19736,
26,
17681,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
9634,
63,
2469,
63,
6238,
401,
263,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
25658,
63,
12206,
63,
4831,
26,
17681,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
977,
75,
63,
515,
401,
463,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
5169,
25658,
63,
8711,
43,
92,
25658,
63,
840,
3649,
748,
4817,
63,
9731,
25256,
5547,
26,
3243,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
6238,
63,
14677,
401,
4519,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
25658,
63,
1217,
41,
26,
5353,
2687,
12432,
22550,
1386,
523,
791,
354,
356,
298,
6238,
63,
5904,
401,
755,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
25658,
63,
21623,
26,
3817,
3243,
2687,
2795,
6238,
12432,
22550,
1386,
523,
791,
354,
356,
298,
867,
63,
5904,
401,
3698,
283,
885,
356,
488,
12,
755,
283,
3401,
356,
295,
14,
2014,
18523,
1441,
63,
21623,
26,
3817,
3243,
2687,
2795,
867,
12432,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
kcartier/tensorflow-toe-in-the-water
|
tensorflow/python/ops/nn_grad.py
|
3
|
7922
|
"""Gradients for operators defined in nn_ops.py."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import control_flow_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import nn_ops
from tensorflow.python.ops import gen_nn_ops
@ops.RegisterGradient("Conv2DBackpropInput")
def _DeConv2DGrad(op, grad):
"""The derivatives for deconvolution.
Args:
op: the Deconvolution op.
grad: the tensor representing the gradient w.r.t. the output
Returns:
the gradients w.r.t. the input and the filter
"""
return [None,
nn_ops.conv2d_backprop_filter(grad,
array_ops.shape(op.inputs[1]),
op.inputs[2],
op.get_attr("strides"),
op.get_attr("padding")),
nn_ops.conv2d(grad,
op.inputs[1],
op.get_attr("strides"),
op.get_attr("padding"))]
@ops.RegisterGradient("Softmax")
def _SoftmaxGrad(op, grad_softmax):
"""The derivative of the softmax nonlinearity.
We assume that probs is of shape [batch_size * dim]
The formula for dsoftmax / dx = (diag(softmax) - softmax * softmax').
This matrix is diagonal minus a rank one matrix, so it is easy to implement
as follows:
grad_x = grad_softmax * softmax - sum(grad_softmax * softmax) * softmax
Args:
op: the Softmax op.
grad_softmax: the tensor representing the gradient w.r.t. the
softmax output.
Returns:
gradient w.r.t the input to the softmax
"""
# TODO(ilyasu): assert that the tensor has two dimensions at
# graph-construction time? Alternatively: do different things
# depending on the dimensionality of the input tensors.
softmax = op.outputs[0]
grad_x = ((grad_softmax -
array_ops.reshape(math_ops.reduce_sum(grad_softmax * softmax, [1]),
[-1, 1]))
* softmax)
return grad_x
@ops.RegisterGradient("BiasAdd")
def _BiasAddGrad(unused_bias_op, received_grad):
"""Return the gradients for the 2 inputs of bias_op.
The first input of unused_bias_op is the tensor t, and its gradient is
just the gradient the unused_bias_op received.
The second input of unused_bias_op is the bias vector which has one fewer
dimension than "received_grad" (the batch dimension.) Its gradient is the
received gradient Summed on the batch dimension, which is the first dimension.
Args:
unused_bias_op: The BiasOp for which we need to generate gradients.
received_grad: Tensor. The gradients passed to the BiasOp.
Returns:
Two tensors, the first one for the "tensor" input of the BiasOp,
the second one for the "bias" input of the BiasOp.
"""
reduction_dim_tensor = math_ops.range(array_ops.rank(received_grad) - 1)
return (received_grad, math_ops.reduce_sum(received_grad, reduction_dim_tensor))
def _VerifyTensor(t, name, msg):
"""Assert that the tensor does not contain any NaN's.
Args:
t: Tensor
name: name
msg: message to log
Returns:
Tensor, but verified
"""
with ops.name_scope(name):
with ops.device(t.device or ops.get_default_graph().get_default_device()):
verify_input = array_ops.check_numerics(t, message=msg)
out = control_flow_ops.with_dependencies([verify_input], t)
return out
@ops.RegisterGradient("Relu")
def _ReluGrad(op, grad):
t = _VerifyTensor(op.inputs[0], op.name, "ReluGrad input is not finite.")
return gen_nn_ops._relu_grad(grad, t)
@ops.RegisterGradient("Relu6")
def _Relu6Grad(op, grad):
return gen_nn_ops._relu6_grad(grad, op.inputs[0])
@ops.RegisterGradient("Softplus")
def _SoftplusGrad(op, grad):
return gen_nn_ops._softplus_grad(grad, op.inputs[0])
@ops.RegisterGradient("ReluGrad")
def _ReluGradGrad(op, grad):
x = op.inputs[1]
return (gen_nn_ops._relu_grad(grad, x),
array_ops.zeros(shape=array_ops.shape(x), dtype=x.dtype))
def _BroadcastMul(vec, mat):
"""Multiply after broadcasting vec to match dimensions of mat.
Args:
vec: A 1-D tensor of dimension [D0]
mat: A 2-D tensor of dimension [D0, D1]
Returns:
A tensor of dimension [D0, D1], the result of vec * mat
"""
# Reshape vec to [D0, 1]
vec = array_ops.expand_dims(vec, -1)
return vec * mat
@ops.RegisterGradient("SoftmaxCrossEntropyWithLogits")
def _SoftmaxCrossEntropyWithLogitsGrad(op, grad_0, _):
# grad_0 is the backprop for cost, and we multiply it with the gradients
# (which is output[1])
# There is no gradient for the labels
return _BroadcastMul(grad_0, op.outputs[1]), None
@ops.RegisterGradient("Conv2D")
def _Conv2DGrad(op, grad):
return [nn_ops.conv2d_backprop_input(array_ops.shape(op.inputs[0]),
op.inputs[1],
grad,
op.get_attr("strides"),
op.get_attr("padding")),
nn_ops.conv2d_backprop_filter(op.inputs[0],
array_ops.shape(op.inputs[1]),
grad,
op.get_attr("strides"),
op.get_attr("padding"))]
@ops.RegisterGradient("LRN")
def _LRNGrad(op, grad):
depth_radius = op.get_attr("depth_radius")
bias = op.get_attr("bias")
alpha = op.get_attr("alpha")
beta = op.get_attr("beta")
return [gen_nn_ops._lrn_grad(grad, op.inputs[0], op.outputs[0],
depth_radius, bias, alpha, beta)]
@ops.RegisterGradient("AvgPool")
def _AvgPoolGrad(op, grad):
return gen_nn_ops._avg_pool_grad(array_ops.shape(op.inputs[0]), grad,
op.get_attr("ksize"),
op.get_attr("strides"),
op.get_attr("padding"))
@ops.RegisterGradient("MaxPool")
def _MaxPoolGrad(op, grad):
return gen_nn_ops._max_pool_grad(op.inputs[0], op.outputs[0], grad,
op.get_attr("ksize"),
op.get_attr("strides"),
padding=op.get_attr("padding"))
@ops.RegisterGradient("BatchNormWithGlobalNormalization")
def _BatchNormWithGlobalNormalizationGrad(op, grad):
"""Return the gradients for the 5 inputs of BatchNormWithGlobalNormalization.
We do not backprop anything for the mean and var intentionally as they are
not being trained with backprop in the operation.
Args:
op: The BatchNormOp for which we need to generate gradients.
grad: Tensor. The gradients passed to the BatchNormOp.
Returns:
dx: Backprop for input, which is (grad * (g * rsqrt(v + epsilon)))
dm: Backprop for mean, which is
sum_over_rest(grad * g) * (-1 / rsqrt(v + epsilon))
dv: Backprop for variance, which is
sum_over_rest(grad * g * (x - m)) * (-1/2) * (v + epsilon) ^ (-3/2)
db: Backprop for beta, which is grad reduced in all except the
last dimension.
dg: Backprop for gamma, which is (grad * ((x - m) * rsqrt(v + epsilon)))
"""
dx, dm, dv, db, dg = gen_nn_ops._batch_norm_with_global_normalization_grad(
op.inputs[0], op.inputs[1], op.inputs[2], op.inputs[4], grad,
op.get_attr("variance_epsilon"), op.get_attr("scale_after_normalization"))
return dx, dm, dv, db, dg
@ops.RegisterGradient("L2Loss")
def _L2LossGrad(op, grad):
"""Return the gradients for L2Loss.
Args:
op: The L2LossOp for which we need to generate gradients.
grad: Tensor containing a single number.
Returns:
The gradient, which is (x * grad).
"""
return op.inputs[0] * grad
|
apache-2.0
|
[
624,
9942,
83,
367,
10211,
3247,
315,
11542,
63,
1483,
14,
647,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
11542,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3805,
63,
4411,
63,
1483,
421,
199,
32,
1483,
14,
24876,
480,
11596,
18,
2846,
564,
4469,
3205,
531,
199,
318,
485,
872,
11596,
18,
36,
14812,
8,
411,
12,
7659,
304,
523,
408,
1918,
28059,
367,
477,
27625,
14,
819,
3033,
26,
272,
1687,
26,
314,
1487,
27625,
1687,
14,
272,
7659,
26,
314,
2345,
6144,
314,
6709,
336,
14,
82,
14,
84,
14,
314,
1072,
819,
1803,
26,
272,
314,
12661,
336,
14,
82,
14,
84,
14,
314,
1324,
436,
314,
2457,
523,
408,
523,
372,
359,
403,
12,
881,
11542,
63,
1483,
14,
5598,
18,
68,
63,
31113,
63,
1541,
8,
6017,
12,
4228,
1625,
63,
1483,
14,
1392,
8,
411,
14,
3711,
59,
17,
2522,
4228,
1687,
14,
3711,
59,
18,
467,
4228,
1687,
14,
362,
63,
962,
480,
16759,
1288,
4228,
1687,
14,
362,
63,
962,
480,
8358,
8150,
881,
11542,
63,
1483,
14,
5598,
18,
68,
8,
6017,
12,
717,
1687,
14,
3711,
59,
17,
467,
717,
1687,
14,
362,
63,
962,
480,
16759,
1288,
717,
1687,
14,
362,
63,
962,
480,
8358,
2237,
61,
421,
199,
32,
1483,
14,
24876,
480,
19302,
988,
531,
199,
318,
485,
19302,
988,
14812,
8,
411,
12,
7659,
63,
16395,
304,
523,
408,
1918,
18883,
402,
314,
28344,
2222,
30440,
14,
819,
2136,
5534,
626,
24329,
365,
402,
2215,
359,
2912,
63,
890,
627,
8134,
61,
523,
710,
15723,
367,
366,
16395,
1182,
11868,
275,
334,
6706,
8,
16395,
9,
446,
28344,
627,
28344,
1959,
523,
961,
3634,
365,
16788,
21357,
282,
6915,
1373,
3634,
12,
880,
652,
365,
8837,
370,
5669,
523,
465,
11924,
26,
339,
7659,
63,
88,
275,
7659,
63,
16395,
627,
28344,
446,
3089,
8,
6017,
63,
16395,
627,
28344,
9,
627,
28344,
819,
3033,
26,
1362,
1687,
26,
314,
27238,
988,
1687,
14,
1362,
7659,
63,
16395,
26,
221,
314,
2345,
6144,
314,
6709,
336,
14,
82,
14,
84,
14,
314,
2126,
28344,
1072,
14,
819,
1803,
26,
1362,
6709,
336,
14,
82,
14,
84,
314,
1324,
370,
314,
28344,
819,
408,
523,
327,
3254,
8,
3444,
305,
85,
304,
702,
626,
314,
2345,
965,
2877,
7365,
737,
523,
327,
3343,
13,
12708,
900,
31,
221,
26776,
26,
886,
3365,
7645,
523,
327,
10298,
641,
314,
6240,
6712,
402,
314,
1324,
10519,
14,
523,
28344,
275,
1687,
14,
4467,
59,
16,
61,
523,
7659,
63,
88,
275,
3666,
6017,
63,
16395,
446,
1467,
1625,
63,
1483,
14,
5217,
8,
3442,
63,
1483,
14,
5270,
63,
1838,
8,
6017,
63,
16395,
627,
28344,
12,
359,
17,
2522,
3044,
5243,
17,
12,
413,
2459,
288,
627,
28344,
9,
523,
372,
7659,
63,
88,
421,
199,
32,
1483,
14,
24876,
480,
34,
2241,
1123,
531,
199,
318,
485,
34,
2241,
1123,
14812,
8,
8618,
63,
8160,
63,
411,
12,
3086,
63,
6017,
304,
523,
408,
1767,
314,
12661,
367,
314,
499,
4153,
402,
10671,
63,
411,
14,
819,
710,
1642,
1324,
402,
9563,
63,
8160,
63,
411,
365,
314,
2345,
307,
12,
436,
2399,
6709,
365,
523,
2951,
314,
6709,
314,
9563,
63,
8160,
63,
411,
3086,
14,
819,
710,
3499,
1324,
402,
9563,
63,
8160,
63,
411,
365,
314,
10671,
5477,
1314,
965,
1373,
27392,
523,
6240,
2419,
298,
9226,
63,
6017,
2,
334,
1589,
3522,
6240,
4959,
221,
22940,
6709,
365,
314,
523,
3086,
6709,
12094,
3594,
641,
314,
3522,
6240,
12,
1314,
365,
314,
1642,
6240,
14,
819,
3033,
26,
272,
9563,
63,
8160,
63,
411,
26,
710,
699,
2241,
4619,
367,
1314,
781,
1929,
370,
3550,
12661,
14,
272,
3086,
63,
6017,
26,
5878,
14,
221,
710,
12661,
3032,
370,
314,
699,
2241,
4619,
14,
819,
1803,
26,
272,
16853,
10519,
12,
314,
1642,
1373,
367,
314,
298,
3128,
2,
1324,
402,
314,
699,
2241,
4619,
12,
272,
314,
3499,
1373,
367,
314,
298,
8160,
2,
1324,
402,
314,
699,
2241,
4619,
14,
523,
408,
523,
16773,
63,
3572,
63,
3128,
275,
3473,
63,
1483,
14,
1842,
8,
1144,
63,
1483,
14,
4648,
8,
9226,
63,
6017,
9,
446,
413,
9,
523,
372,
334,
9226,
63,
6017,
12,
3473,
63,
1483,
14,
5270,
63,
1838,
8,
9226,
63,
6017,
12,
16773,
63,
3572,
63,
3128,
430,
421,
199,
318,
485,
7496,
3861,
8,
84,
12,
536,
12,
1499,
304,
523,
408,
9699,
626,
314,
2345,
1630,
440,
1395,
1263,
16046,
1159,
14,
819,
3033,
26,
272,
307,
26,
5878,
272,
536,
26,
536,
272,
1499,
26,
1245,
370,
943,
523,
1803,
26,
272,
5878,
12,
1325,
16317,
523,
408,
523,
543,
4156,
14,
354,
63,
2645,
8,
354,
304,
272,
543,
4156,
14,
1782,
8,
84,
14,
1782,
503,
4156,
14,
362,
63,
885,
63,
2180,
1252,
362,
63,
885,
63,
1782,
5109,
489,
4911,
63,
1210,
275,
1625,
63,
1483,
14,
1074,
63,
10563,
11818,
8,
84,
12,
1245,
29,
1328,
9,
489,
734,
275,
3304,
63,
1659,
63,
1483,
14,
1045,
63,
5714,
779,
4712,
63,
1210,
467,
307,
9,
523,
372,
734,
421,
199,
32,
1483,
14,
24876,
480,
5640,
85,
531,
199,
318,
485,
5640,
85,
14812,
8,
411,
12,
7659,
304,
523,
307,
275,
485,
7496,
3861,
8,
411,
14,
3711,
59,
16,
467,
1687,
14,
354,
12,
298,
5640,
85,
14812,
1324,
365,
440,
21837,
2685,
523,
372,
3805,
63,
4411,
63,
1483,
423,
12833,
63,
6017,
8,
6017,
12,
307,
9,
421,
199,
32,
1483,
14,
24876,
480,
5640,
85,
22,
531,
199,
318,
485,
5640,
85,
22,
14812,
8,
411,
12,
7659,
304,
523,
372,
3805,
63,
4411,
63,
1483,
423,
12833,
22,
63
] |
[
9942,
83,
367,
10211,
3247,
315,
11542,
63,
1483,
14,
647,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
11542,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3805,
63,
4411,
63,
1483,
421,
199,
32,
1483,
14,
24876,
480,
11596,
18,
2846,
564,
4469,
3205,
531,
199,
318,
485,
872,
11596,
18,
36,
14812,
8,
411,
12,
7659,
304,
523,
408,
1918,
28059,
367,
477,
27625,
14,
819,
3033,
26,
272,
1687,
26,
314,
1487,
27625,
1687,
14,
272,
7659,
26,
314,
2345,
6144,
314,
6709,
336,
14,
82,
14,
84,
14,
314,
1072,
819,
1803,
26,
272,
314,
12661,
336,
14,
82,
14,
84,
14,
314,
1324,
436,
314,
2457,
523,
408,
523,
372,
359,
403,
12,
881,
11542,
63,
1483,
14,
5598,
18,
68,
63,
31113,
63,
1541,
8,
6017,
12,
4228,
1625,
63,
1483,
14,
1392,
8,
411,
14,
3711,
59,
17,
2522,
4228,
1687,
14,
3711,
59,
18,
467,
4228,
1687,
14,
362,
63,
962,
480,
16759,
1288,
4228,
1687,
14,
362,
63,
962,
480,
8358,
8150,
881,
11542,
63,
1483,
14,
5598,
18,
68,
8,
6017,
12,
717,
1687,
14,
3711,
59,
17,
467,
717,
1687,
14,
362,
63,
962,
480,
16759,
1288,
717,
1687,
14,
362,
63,
962,
480,
8358,
2237,
61,
421,
199,
32,
1483,
14,
24876,
480,
19302,
988,
531,
199,
318,
485,
19302,
988,
14812,
8,
411,
12,
7659,
63,
16395,
304,
523,
408,
1918,
18883,
402,
314,
28344,
2222,
30440,
14,
819,
2136,
5534,
626,
24329,
365,
402,
2215,
359,
2912,
63,
890,
627,
8134,
61,
523,
710,
15723,
367,
366,
16395,
1182,
11868,
275,
334,
6706,
8,
16395,
9,
446,
28344,
627,
28344,
1959,
523,
961,
3634,
365,
16788,
21357,
282,
6915,
1373,
3634,
12,
880,
652,
365,
8837,
370,
5669,
523,
465,
11924,
26,
339,
7659,
63,
88,
275,
7659,
63,
16395,
627,
28344,
446,
3089,
8,
6017,
63,
16395,
627,
28344,
9,
627,
28344,
819,
3033,
26,
1362,
1687,
26,
314,
27238,
988,
1687,
14,
1362,
7659,
63,
16395,
26,
221,
314,
2345,
6144,
314,
6709,
336,
14,
82,
14,
84,
14,
314,
2126,
28344,
1072,
14,
819,
1803,
26,
1362,
6709,
336,
14,
82,
14,
84,
314,
1324,
370,
314,
28344,
819,
408,
523,
327,
3254,
8,
3444,
305,
85,
304,
702,
626,
314,
2345,
965,
2877,
7365,
737,
523,
327,
3343,
13,
12708,
900,
31,
221,
26776,
26,
886,
3365,
7645,
523,
327,
10298,
641,
314,
6240,
6712,
402,
314,
1324,
10519,
14,
523,
28344,
275,
1687,
14,
4467,
59,
16,
61,
523,
7659,
63,
88,
275,
3666,
6017,
63,
16395,
446,
1467,
1625,
63,
1483,
14,
5217,
8,
3442,
63,
1483,
14,
5270,
63,
1838,
8,
6017,
63,
16395,
627,
28344,
12,
359,
17,
2522,
3044,
5243,
17,
12,
413,
2459,
288,
627,
28344,
9,
523,
372,
7659,
63,
88,
421,
199,
32,
1483,
14,
24876,
480,
34,
2241,
1123,
531,
199,
318,
485,
34,
2241,
1123,
14812,
8,
8618,
63,
8160,
63,
411,
12,
3086,
63,
6017,
304,
523,
408,
1767,
314,
12661,
367,
314,
499,
4153,
402,
10671,
63,
411,
14,
819,
710,
1642,
1324,
402,
9563,
63,
8160,
63,
411,
365,
314,
2345,
307,
12,
436,
2399,
6709,
365,
523,
2951,
314,
6709,
314,
9563,
63,
8160,
63,
411,
3086,
14,
819,
710,
3499,
1324,
402,
9563,
63,
8160,
63,
411,
365,
314,
10671,
5477,
1314,
965,
1373,
27392,
523,
6240,
2419,
298,
9226,
63,
6017,
2,
334,
1589,
3522,
6240,
4959,
221,
22940,
6709,
365,
314,
523,
3086,
6709,
12094,
3594,
641,
314,
3522,
6240,
12,
1314,
365,
314,
1642,
6240,
14,
819,
3033,
26,
272,
9563,
63,
8160,
63,
411,
26,
710,
699,
2241,
4619,
367,
1314,
781,
1929,
370,
3550,
12661,
14,
272,
3086,
63,
6017,
26,
5878,
14,
221,
710,
12661,
3032,
370,
314,
699,
2241,
4619,
14,
819,
1803,
26,
272,
16853,
10519,
12,
314,
1642,
1373,
367,
314,
298,
3128,
2,
1324,
402,
314,
699,
2241,
4619,
12,
272,
314,
3499,
1373,
367,
314,
298,
8160,
2,
1324,
402,
314,
699,
2241,
4619,
14,
523,
408,
523,
16773,
63,
3572,
63,
3128,
275,
3473,
63,
1483,
14,
1842,
8,
1144,
63,
1483,
14,
4648,
8,
9226,
63,
6017,
9,
446,
413,
9,
523,
372,
334,
9226,
63,
6017,
12,
3473,
63,
1483,
14,
5270,
63,
1838,
8,
9226,
63,
6017,
12,
16773,
63,
3572,
63,
3128,
430,
421,
199,
318,
485,
7496,
3861,
8,
84,
12,
536,
12,
1499,
304,
523,
408,
9699,
626,
314,
2345,
1630,
440,
1395,
1263,
16046,
1159,
14,
819,
3033,
26,
272,
307,
26,
5878,
272,
536,
26,
536,
272,
1499,
26,
1245,
370,
943,
523,
1803,
26,
272,
5878,
12,
1325,
16317,
523,
408,
523,
543,
4156,
14,
354,
63,
2645,
8,
354,
304,
272,
543,
4156,
14,
1782,
8,
84,
14,
1782,
503,
4156,
14,
362,
63,
885,
63,
2180,
1252,
362,
63,
885,
63,
1782,
5109,
489,
4911,
63,
1210,
275,
1625,
63,
1483,
14,
1074,
63,
10563,
11818,
8,
84,
12,
1245,
29,
1328,
9,
489,
734,
275,
3304,
63,
1659,
63,
1483,
14,
1045,
63,
5714,
779,
4712,
63,
1210,
467,
307,
9,
523,
372,
734,
421,
199,
32,
1483,
14,
24876,
480,
5640,
85,
531,
199,
318,
485,
5640,
85,
14812,
8,
411,
12,
7659,
304,
523,
307,
275,
485,
7496,
3861,
8,
411,
14,
3711,
59,
16,
467,
1687,
14,
354,
12,
298,
5640,
85,
14812,
1324,
365,
440,
21837,
2685,
523,
372,
3805,
63,
4411,
63,
1483,
423,
12833,
63,
6017,
8,
6017,
12,
307,
9,
421,
199,
32,
1483,
14,
24876,
480,
5640,
85,
22,
531,
199,
318,
485,
5640,
85,
22,
14812,
8,
411,
12,
7659,
304,
523,
372,
3805,
63,
4411,
63,
1483,
423,
12833,
22,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
mikeh69/JammerDetect
|
src/audio_tones.py
|
1
|
3644
|
import math #import needed modules
import pyaudio #sudo apt-get install python-pyaudio
import struct
import pickle
from time import sleep
PyAudio = pyaudio.PyAudio #initialize pyaudio
#See http://en.wikipedia.org/wiki/Bit_rate#Audio
BITRATE = 48000 #number of frames per second - 44.1kHz does not work properly on RPi BCM2538!
LENGTH = 0.2 #seconds to play sound
CHUNKSIZE = int(BITRATE * LENGTH)
WAVEDATA_FILE = "/home/pi/wavedata.pickled"
class AudioTones:
def init(self):
self.player = PyAudio()
defaultCapability = self.player.get_default_host_api_info()
print("Player defaults:")
print(defaultCapability)
# fmt = self.player.get_format_from_width(2)
# fmt = pyaudio.paInt8 # supposedly 8-bit signed-integer
fmt = pyaudio.paInt16 # 16-bit signed-integer
print(self.player.is_format_supported(output_format = fmt, output_channels = 1,
rate = BITRATE, output_device = 3))
self.stream = self.player.open(format = fmt, channels = 1, rate = BITRATE, output = True, frames_per_buffer = CHUNKSIZE)
try:
print("Trying to load wavedata from file...")
f = open(WAVEDATA_FILE, "rb")
print(" File opened OK")
self.WAVEDATA = pickle.load(f)
print(" Wavedata read from file OK")
f.close()
return
except Exception as ex:
print(ex)
print("Failed to load wavedata from file, re-generating")
frequency = 200.0 # start frequency 200Hz
self.WAVEDATA = []
for index in range(0, 46): # valid index range 0 - 45, ~10log(32768)
num_fadein_frames = int(BITRATE * LENGTH * 0.05)
num_loud_frames = int(BITRATE * LENGTH * 0.7)
num_fadeout_frames = CHUNKSIZE - (num_loud_frames + num_fadein_frames)
self.WAVEDATA.append(struct.pack( "<H", 0 ))
for xx in range(num_fadein_frames):
x = xx
next_sample = int(math.sin(x/((BITRATE/frequency)/math.pi)) * 32000 * (xx/num_fadein_frames))
self.WAVEDATA[index] = self.WAVEDATA[index] + struct.pack( "<h", next_sample ) # little-endian int16
for xx in range(num_loud_frames):
x = xx + num_fadein_frames
next_sample = int(math.sin(x/((BITRATE/frequency)/math.pi)) * 32000)
self.WAVEDATA[index] = self.WAVEDATA[index] + struct.pack( "<h", next_sample ) # little-endian int16
for xx in range(num_fadeout_frames):
x = xx + num_loud_frames + num_fadein_frames
next_sample = int(math.sin(x/((BITRATE/frequency)/math.pi)) * 32000 * (1 - (xx/num_fadeout_frames)))
# next_sample = 0
self.WAVEDATA[index] = self.WAVEDATA[index] + struct.pack( "<h", next_sample)
frequency *= 1.0594631 # semitone ratio
# Save the newly-generated data to a file using Pickle:
print("Saving wavedata to file")
f = open(WAVEDATA_FILE, "wb")
pickle.dump(self.WAVEDATA, f)
f.close()
def test(self):
for index in range(0, 40):
self.stream.write(self.WAVEDATA[index])
index += 1
self.stream.stop_stream()
def play(self, index):
self.stream.write(self.WAVEDATA[index])
def close(self):
self.stream.stop_stream()
self.stream.close()
self.player.terminate()
if __name__ == "__main__":
tones = AudioTones()
tones.init()
for i in range(0, 40):
tones.play(i)
sleep(0.3)
|
mit
|
[
646,
3473,
258,
327,
646,
4346,
4621,
199,
646,
1134,
8130,
258,
327,
12095,
20932,
13,
362,
3907,
2366,
13,
647,
8130,
199,
646,
2702,
199,
646,
5927,
199,
504,
900,
492,
9435,
199,
199,
2713,
15484,
275,
1134,
8130,
14,
2713,
15484,
258,
327,
8489,
1134,
8130,
199,
199,
3,
9295,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
4734,
63,
1866,
3,
15484,
199,
11970,
16553,
275,
9615,
1493,
221,
327,
1955,
402,
11223,
1126,
3499,
446,
10868,
14,
17,
75,
13026,
1630,
440,
1736,
7684,
641,
820,
10542,
699,
9249,
821,
1703,
1,
199,
9127,
275,
378,
14,
18,
258,
327,
4515,
370,
5232,
20453,
199,
20512,
4305,
275,
1109,
8,
11970,
16553,
627,
491,
32106,
9,
199,
55,
6087,
1149,
2751,
63,
3817,
275,
3286,
4219,
15,
1038,
15,
758,
1354,
419,
14,
20428,
2,
199,
199,
533,
30885,
52,
4548,
26,
339,
347,
4205,
8,
277,
304,
398,
291,
14,
6147,
275,
1611,
15484,
342,
267,
849,
24512,
275,
291,
14,
6147,
14,
362,
63,
885,
63,
1102,
63,
1246,
63,
815,
342,
267,
870,
480,
10921,
4243,
9107,
267,
870,
8,
885,
24512,
9,
199,
3,
263,
7104,
275,
291,
14,
6147,
14,
362,
63,
908,
63,
504,
63,
2063,
8,
18,
9,
199,
3,
263,
7104,
275,
1134,
8130,
14,
387,
3241,
24,
221,
327,
20042,
590,
1695,
13,
2075,
10514,
13,
4115,
267,
7104,
275,
1134,
8130,
14,
387,
3241,
975,
221,
327,
3193,
13,
2075,
10514,
13,
4115,
267,
870,
8,
277,
14,
6147,
14,
374,
63,
908,
63,
4946,
8,
1199,
63,
908,
275,
7104,
12,
1072,
63,
6324,
275,
413,
12,
20866,
263,
6634,
275,
699,
649,
16553,
12,
1072,
63,
1782,
275,
650,
430,
267,
291,
14,
1745,
275,
291,
14,
6147,
14,
1490,
8,
908,
275,
7104,
12,
9245,
275,
413,
12,
6634,
275,
699,
649,
16553,
12,
1072,
275,
715,
12,
11223,
63,
529,
63,
2738,
275,
6624,
8019,
4305,
9,
398,
862,
26,
288,
870,
480,
27693,
370,
2248,
336,
4292,
419,
687,
570,
12594,
288,
289,
275,
1551,
8,
55,
6087,
1149,
2751,
63,
3817,
12,
298,
4848,
531,
288,
870,
480,
221,
3814,
12123,
9949,
531,
288,
291,
14,
55,
6087,
1149,
2751,
275,
5927,
14,
912,
8,
70,
9,
288,
870,
480,
221,
644,
4292,
419,
1586,
687,
570,
9949,
531,
288,
289,
14,
1600,
342,
288,
372,
267,
871,
2186,
465,
444,
26,
288,
870,
8,
476,
9,
288,
870,
480,
4276,
370,
2248,
336,
4292,
419,
687,
570,
12,
295,
13,
2038,
1958,
531,
398,
9857,
275,
1926,
14,
16,
221,
327,
1343,
9857,
1926,
13026,
267,
291,
14,
55,
6087,
1149,
2751,
275,
942,
2728,
367,
1478,
315,
1425,
8,
16,
12,
12426,
304,
327,
1686,
1478,
1425,
378,
446,
10416,
12,
6146,
709,
793,
8,
708,
14408,
9,
288,
1967,
63,
667,
271,
262,
63,
8444,
275,
1109,
8,
11970,
16553,
627,
491,
32106,
627,
378,
14,
1717,
9,
288,
1967,
63,
320,
1181,
63,
8444,
275,
1109,
8,
11970,
16553,
627,
491,
32106,
627,
378,
14,
23,
9,
288,
1967,
63,
667,
271,
548,
63,
8444,
275,
6624,
8019,
4305,
446,
334,
1507,
63,
320,
1181,
63,
8444,
435,
1967,
63,
667,
271,
262,
63,
8444,
9,
288,
291,
14,
55,
6087,
1149,
2751,
14,
740,
8,
1820,
14,
1389,
8,
3886,
40,
401,
378,
5082,
953,
367,
19379,
315,
1425,
8,
1507,
63,
667,
271,
262,
63,
8444,
304,
355,
671,
275,
19379,
355,
2163,
63,
3271,
275,
1109,
8,
3442,
14,
5911,
8,
88,
15,
1332,
11970,
16553,
15,
11132,
2447,
3442,
14,
1038,
430,
627,
4337,
1493,
627,
334,
2154,
15,
1507,
63,
667,
271,
262,
63,
8444,
430,
355,
291,
14,
55,
6087,
1149,
2751,
59,
1080,
61,
275,
291,
14,
55,
6087,
1149,
2751,
59,
1080,
61,
435,
2702,
14,
1389,
8,
3886,
72,
401,
2163,
63,
3271,
776,
221,
327,
12050,
13,
15009,
1109,
975,
953,
367,
19379,
315,
1425,
8,
1507,
63,
320,
1181,
63,
8444,
304,
355,
671,
275,
19379,
435,
1967,
63,
667,
271,
262,
63,
8444,
355,
2163,
63,
3271,
275,
1109,
8,
3442,
14,
5911,
8,
88,
15,
1332,
11970,
16553,
15,
11132,
2447,
3442,
14,
1038,
430,
627,
4337,
1493,
9,
355,
291,
14,
55,
6087,
1149,
2751,
59,
1080,
61,
275,
291,
14,
55,
6087,
1149,
2751,
59,
1080,
61,
435,
2702,
14,
1389,
8,
3886,
72,
401,
2163,
63,
3271,
776,
221,
327,
12050,
13,
15009,
1109,
975,
953,
367,
19379,
315,
1425,
8,
1507,
63,
667,
271,
548,
63,
8444,
304,
355,
671,
275,
19379,
435,
1967,
63,
320,
1181,
63,
8444,
435,
1967,
63,
667,
271,
262,
63,
8444,
355,
2163,
63,
3271,
275,
1109,
8,
3442,
14,
5911,
8,
88,
15,
1332,
11970,
16553,
15,
11132,
2447,
3442,
14,
1038,
430,
627,
4337,
1493,
627,
334,
17,
446,
334,
2154,
15,
1507,
63,
667,
271,
548,
63,
8444,
1724,
199,
3,
4483,
2163,
63,
3271,
275,
378,
355,
291,
14,
55,
6087,
1149,
2751,
59,
1080,
61,
275,
291,
14,
55,
6087,
1149,
2751,
59,
1080,
61,
435,
2702,
14,
1389,
8,
3886,
72,
401,
2163,
63,
3271,
9,
953,
9857,
9000,
413,
14,
27479,
2466,
2192,
221,
327,
542,
1147,
368,
10463,
398,
327,
11063,
314,
13903,
13,
10176,
666,
370,
282,
570,
1808,
31732,
26,
267,
870,
480,
30125,
336,
4292,
419,
370,
570,
531,
267,
289,
275,
1551,
8,
55,
6087,
1149,
2751,
63,
3817,
12,
298,
6603,
531,
267,
5927,
14,
2724,
8,
277,
14,
55,
6087,
1149,
2751,
12,
289,
9,
267,
289,
14,
1600,
342,
5493,
347,
511,
8,
277,
304,
267,
367,
1478,
315,
1425,
8,
16,
12,
6335,
304,
288,
291,
14,
1745,
14,
952,
8,
277,
14,
55,
6087,
1149,
2751,
59,
1080,
566,
288,
1478,
847,
413,
267,
291,
14,
1745,
14,
2379,
63,
1745,
342,
339,
347,
5232,
8,
277,
12,
1478,
304,
267,
291,
14,
1745,
14,
952,
8,
277,
14,
55,
6087,
1149,
2751,
59,
1080,
566,
339,
347,
4002,
8,
277,
304,
267,
291,
14,
1745,
14,
2379,
63,
1745,
342,
267,
291,
14,
1745,
14,
1600,
342
] |
[
3473,
258,
327,
646,
4346,
4621,
199,
646,
1134,
8130,
258,
327,
12095,
20932,
13,
362,
3907,
2366,
13,
647,
8130,
199,
646,
2702,
199,
646,
5927,
199,
504,
900,
492,
9435,
199,
199,
2713,
15484,
275,
1134,
8130,
14,
2713,
15484,
258,
327,
8489,
1134,
8130,
199,
199,
3,
9295,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
4734,
63,
1866,
3,
15484,
199,
11970,
16553,
275,
9615,
1493,
221,
327,
1955,
402,
11223,
1126,
3499,
446,
10868,
14,
17,
75,
13026,
1630,
440,
1736,
7684,
641,
820,
10542,
699,
9249,
821,
1703,
1,
199,
9127,
275,
378,
14,
18,
258,
327,
4515,
370,
5232,
20453,
199,
20512,
4305,
275,
1109,
8,
11970,
16553,
627,
491,
32106,
9,
199,
55,
6087,
1149,
2751,
63,
3817,
275,
3286,
4219,
15,
1038,
15,
758,
1354,
419,
14,
20428,
2,
199,
199,
533,
30885,
52,
4548,
26,
339,
347,
4205,
8,
277,
304,
398,
291,
14,
6147,
275,
1611,
15484,
342,
267,
849,
24512,
275,
291,
14,
6147,
14,
362,
63,
885,
63,
1102,
63,
1246,
63,
815,
342,
267,
870,
480,
10921,
4243,
9107,
267,
870,
8,
885,
24512,
9,
199,
3,
263,
7104,
275,
291,
14,
6147,
14,
362,
63,
908,
63,
504,
63,
2063,
8,
18,
9,
199,
3,
263,
7104,
275,
1134,
8130,
14,
387,
3241,
24,
221,
327,
20042,
590,
1695,
13,
2075,
10514,
13,
4115,
267,
7104,
275,
1134,
8130,
14,
387,
3241,
975,
221,
327,
3193,
13,
2075,
10514,
13,
4115,
267,
870,
8,
277,
14,
6147,
14,
374,
63,
908,
63,
4946,
8,
1199,
63,
908,
275,
7104,
12,
1072,
63,
6324,
275,
413,
12,
20866,
263,
6634,
275,
699,
649,
16553,
12,
1072,
63,
1782,
275,
650,
430,
267,
291,
14,
1745,
275,
291,
14,
6147,
14,
1490,
8,
908,
275,
7104,
12,
9245,
275,
413,
12,
6634,
275,
699,
649,
16553,
12,
1072,
275,
715,
12,
11223,
63,
529,
63,
2738,
275,
6624,
8019,
4305,
9,
398,
862,
26,
288,
870,
480,
27693,
370,
2248,
336,
4292,
419,
687,
570,
12594,
288,
289,
275,
1551,
8,
55,
6087,
1149,
2751,
63,
3817,
12,
298,
4848,
531,
288,
870,
480,
221,
3814,
12123,
9949,
531,
288,
291,
14,
55,
6087,
1149,
2751,
275,
5927,
14,
912,
8,
70,
9,
288,
870,
480,
221,
644,
4292,
419,
1586,
687,
570,
9949,
531,
288,
289,
14,
1600,
342,
288,
372,
267,
871,
2186,
465,
444,
26,
288,
870,
8,
476,
9,
288,
870,
480,
4276,
370,
2248,
336,
4292,
419,
687,
570,
12,
295,
13,
2038,
1958,
531,
398,
9857,
275,
1926,
14,
16,
221,
327,
1343,
9857,
1926,
13026,
267,
291,
14,
55,
6087,
1149,
2751,
275,
942,
2728,
367,
1478,
315,
1425,
8,
16,
12,
12426,
304,
327,
1686,
1478,
1425,
378,
446,
10416,
12,
6146,
709,
793,
8,
708,
14408,
9,
288,
1967,
63,
667,
271,
262,
63,
8444,
275,
1109,
8,
11970,
16553,
627,
491,
32106,
627,
378,
14,
1717,
9,
288,
1967,
63,
320,
1181,
63,
8444,
275,
1109,
8,
11970,
16553,
627,
491,
32106,
627,
378,
14,
23,
9,
288,
1967,
63,
667,
271,
548,
63,
8444,
275,
6624,
8019,
4305,
446,
334,
1507,
63,
320,
1181,
63,
8444,
435,
1967,
63,
667,
271,
262,
63,
8444,
9,
288,
291,
14,
55,
6087,
1149,
2751,
14,
740,
8,
1820,
14,
1389,
8,
3886,
40,
401,
378,
5082,
953,
367,
19379,
315,
1425,
8,
1507,
63,
667,
271,
262,
63,
8444,
304,
355,
671,
275,
19379,
355,
2163,
63,
3271,
275,
1109,
8,
3442,
14,
5911,
8,
88,
15,
1332,
11970,
16553,
15,
11132,
2447,
3442,
14,
1038,
430,
627,
4337,
1493,
627,
334,
2154,
15,
1507,
63,
667,
271,
262,
63,
8444,
430,
355,
291,
14,
55,
6087,
1149,
2751,
59,
1080,
61,
275,
291,
14,
55,
6087,
1149,
2751,
59,
1080,
61,
435,
2702,
14,
1389,
8,
3886,
72,
401,
2163,
63,
3271,
776,
221,
327,
12050,
13,
15009,
1109,
975,
953,
367,
19379,
315,
1425,
8,
1507,
63,
320,
1181,
63,
8444,
304,
355,
671,
275,
19379,
435,
1967,
63,
667,
271,
262,
63,
8444,
355,
2163,
63,
3271,
275,
1109,
8,
3442,
14,
5911,
8,
88,
15,
1332,
11970,
16553,
15,
11132,
2447,
3442,
14,
1038,
430,
627,
4337,
1493,
9,
355,
291,
14,
55,
6087,
1149,
2751,
59,
1080,
61,
275,
291,
14,
55,
6087,
1149,
2751,
59,
1080,
61,
435,
2702,
14,
1389,
8,
3886,
72,
401,
2163,
63,
3271,
776,
221,
327,
12050,
13,
15009,
1109,
975,
953,
367,
19379,
315,
1425,
8,
1507,
63,
667,
271,
548,
63,
8444,
304,
355,
671,
275,
19379,
435,
1967,
63,
320,
1181,
63,
8444,
435,
1967,
63,
667,
271,
262,
63,
8444,
355,
2163,
63,
3271,
275,
1109,
8,
3442,
14,
5911,
8,
88,
15,
1332,
11970,
16553,
15,
11132,
2447,
3442,
14,
1038,
430,
627,
4337,
1493,
627,
334,
17,
446,
334,
2154,
15,
1507,
63,
667,
271,
548,
63,
8444,
1724,
199,
3,
4483,
2163,
63,
3271,
275,
378,
355,
291,
14,
55,
6087,
1149,
2751,
59,
1080,
61,
275,
291,
14,
55,
6087,
1149,
2751,
59,
1080,
61,
435,
2702,
14,
1389,
8,
3886,
72,
401,
2163,
63,
3271,
9,
953,
9857,
9000,
413,
14,
27479,
2466,
2192,
221,
327,
542,
1147,
368,
10463,
398,
327,
11063,
314,
13903,
13,
10176,
666,
370,
282,
570,
1808,
31732,
26,
267,
870,
480,
30125,
336,
4292,
419,
370,
570,
531,
267,
289,
275,
1551,
8,
55,
6087,
1149,
2751,
63,
3817,
12,
298,
6603,
531,
267,
5927,
14,
2724,
8,
277,
14,
55,
6087,
1149,
2751,
12,
289,
9,
267,
289,
14,
1600,
342,
5493,
347,
511,
8,
277,
304,
267,
367,
1478,
315,
1425,
8,
16,
12,
6335,
304,
288,
291,
14,
1745,
14,
952,
8,
277,
14,
55,
6087,
1149,
2751,
59,
1080,
566,
288,
1478,
847,
413,
267,
291,
14,
1745,
14,
2379,
63,
1745,
342,
339,
347,
5232,
8,
277,
12,
1478,
304,
267,
291,
14,
1745,
14,
952,
8,
277,
14,
55,
6087,
1149,
2751,
59,
1080,
566,
339,
347,
4002,
8,
277,
304,
267,
291,
14,
1745,
14,
2379,
63,
1745,
342,
267,
291,
14,
1745,
14,
1600,
342,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,
1,
1
] |
StephaneP/volatility
|
volatility/plugins/fileparam.py
|
57
|
1840
|
# Volatility
#
# Authors:
# Mike Auty <mike.auty@gmail.com>
#
# This file is part of Volatility.
#
# Volatility is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Volatility is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Volatility. If not, see <http://www.gnu.org/licenses/>.
#
import volatility.conf as conf
import urllib
import sys
import os
## This is required to ensure that LOCATION is defined here
import volatility.debug as debug
import volatility.addrspace as addrspace #pylint: disable-msg=W0611
config = conf.ConfObject()
def set_location(_option, _opt_str, value, parser):
"""Sets the location variable in the parser to the filename in question"""
if not os.path.exists(os.path.abspath(value)):
debug.error("The requested file doesn't exist")
if parser.values.location == None:
slashes = "//"
# Windows pathname2url decides to convert C:\blah to ///C:/blah
# So to keep the URLs correct, we only add file: rather than file://
if sys.platform.startswith('win'):
slashes = ""
parser.values.location = "file:" + slashes + urllib.pathname2url(os.path.abspath(value))
config.add_option("FILENAME", default = None, action = "callback",
callback = set_location, type = 'str',
short_option = 'f', nargs = 1,
help = "Filename to use when opening an image")
|
gpl-2.0
|
[
3,
28367,
199,
3,
199,
3,
6642,
26,
199,
3,
603,
7455,
437,
19974,
665,
2664,
415,
14,
6898,
89,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28367,
14,
199,
3,
199,
3,
28367,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
28367,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
28367,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
646,
5236,
18783,
14,
2190,
465,
3743,
199,
646,
4011,
199,
646,
984,
199,
646,
747,
199,
309,
961,
365,
1415,
370,
4868,
626,
3412,
35,
2594,
365,
3247,
2348,
199,
646,
5236,
18783,
14,
1757,
465,
3105,
199,
646,
5236,
18783,
14,
18942,
1142,
465,
29259,
1142,
327,
26324,
26,
3507,
13,
1328,
29,
55,
1690,
845,
199,
199,
888,
275,
3743,
14,
8930,
1692,
342,
199,
199,
318,
663,
63,
1985,
1547,
1422,
12,
485,
2992,
63,
495,
12,
574,
12,
1798,
304,
272,
408,
9899,
314,
2909,
1750,
315,
314,
1798,
370,
314,
1788,
315,
7894,
624,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
4832,
8,
585,
2298,
267,
3105,
14,
705,
480,
1918,
5839,
570,
3181,
1133,
2187,
531,
272,
340,
1798,
14,
1459,
14,
1985,
508,
488,
26,
267,
20275,
275,
23057,
2,
267,
327,
5417,
11776,
18,
633,
12985,
3424,
370,
3957,
445,
3427,
12702,
370,
5001,
15,
35,
11254,
12702,
267,
327,
2002,
370,
4215,
314,
10867,
3211,
12,
781,
1454,
1050,
570,
26,
7830,
2419,
570,
921,
267,
340,
984,
14,
3246,
14,
2460,
360,
2676,
735,
288,
20275,
275,
3087,
267,
1798,
14,
1459,
14,
1985,
275,
298,
493,
5424,
435,
20275,
435,
4011,
14,
12445,
18,
633,
8,
736,
14,
515,
14,
4832,
8,
585,
430,
199,
199,
888,
14,
525,
63,
1422,
480,
15440,
401,
849,
275,
488,
12,
1595,
275,
298,
3058,
401,
2116,
3233,
275,
663,
63,
1985,
12,
730,
275,
283,
495,
297,
2116,
3974,
63,
1422,
275,
283,
70,
297,
9237,
275,
413,
12,
2116,
1720,
275,
298,
8117,
370,
675,
1380,
13618,
376,
1834,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
28367,
199,
3,
199,
3,
6642,
26,
199,
3,
603,
7455,
437,
19974,
665,
2664,
415,
14,
6898,
89,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28367,
14,
199,
3,
199,
3,
28367,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
28367,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
28367,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
646,
5236,
18783,
14,
2190,
465,
3743,
199,
646,
4011,
199,
646,
984,
199,
646,
747,
199,
309,
961,
365,
1415,
370,
4868,
626,
3412,
35,
2594,
365,
3247,
2348,
199,
646,
5236,
18783,
14,
1757,
465,
3105,
199,
646,
5236,
18783,
14,
18942,
1142,
465,
29259,
1142,
327,
26324,
26,
3507,
13,
1328,
29,
55,
1690,
845,
199,
199,
888,
275,
3743,
14,
8930,
1692,
342,
199,
199,
318,
663,
63,
1985,
1547,
1422,
12,
485,
2992,
63,
495,
12,
574,
12,
1798,
304,
272,
408,
9899,
314,
2909,
1750,
315,
314,
1798,
370,
314,
1788,
315,
7894,
624,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
4832,
8,
585,
2298,
267,
3105,
14,
705,
480,
1918,
5839,
570,
3181,
1133,
2187,
531,
272,
340,
1798,
14,
1459,
14,
1985,
508,
488,
26,
267,
20275,
275,
23057,
2,
267,
327,
5417,
11776,
18,
633,
12985,
3424,
370,
3957,
445,
3427,
12702,
370,
5001,
15,
35,
11254,
12702,
267,
327,
2002,
370,
4215,
314,
10867,
3211,
12,
781,
1454,
1050,
570,
26,
7830,
2419,
570,
921,
267,
340,
984,
14,
3246,
14,
2460,
360,
2676,
735,
288,
20275,
275,
3087,
267,
1798,
14,
1459,
14,
1985,
275,
298,
493,
5424,
435,
20275,
435,
4011,
14,
12445,
18,
633,
8,
736,
14,
515,
14,
4832,
8,
585,
430,
199,
199,
888,
14,
525,
63,
1422,
480,
15440,
401,
849,
275,
488,
12,
1595,
275,
298,
3058,
401,
2116,
3233,
275,
663,
63,
1985,
12,
730,
275,
283,
495,
297,
2116,
3974,
63,
1422,
275,
283,
70,
297,
9237,
275,
413,
12,
2116,
1720,
275,
298,
8117,
370,
675,
1380,
13618,
376,
1834,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
percy-g2/Novathor_xperia_u8500
|
6.1.1.B.0.253/external/webkit/Source/WebKit2/Scripts/webkit2/messages_unittest.py
|
15
|
24676
|
# Copyright (C) 2010 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import unittest
from StringIO import StringIO
import messages
_messages_file_contents = """# Copyright (C) 2010 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "config.h"
#if ENABLE(WEBKIT2)
messages -> WebPage {
LoadURL(WTF::String url)
#if ENABLE(TOUCH_EVENTS)
TouchEvent(WebKit::WebTouchEvent event)
#endif
DidReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, uint32_t policyAction)
Close()
PreferencesDidChange(WebKit::WebPreferencesStore store)
SendDoubleAndFloat(double d, float f)
SendInts(Vector<uint64_t> ints, Vector<Vector<uint64_t> > intVectors)
CreatePlugin(uint64_t pluginInstanceID, WebKit::Plugin::Parameters parameters) -> (bool result)
RunJavaScriptAlert(uint64_t frameID, WTF::String message) -> ()
GetPlugins(bool refresh) -> (Vector<WebCore::PluginInfo> plugins) DispatchOnConnectionQueue
GetPluginProcessConnection(WTF::String pluginPath) -> (CoreIPC::Connection::Handle connectionHandle) Delayed
TestMultipleAttributes() -> () DispatchOnConnectionQueue Delayed
#if PLATFORM(MAC)
DidCreateWebProcessConnection(CoreIPC::MachPort connectionIdentifier)
#endif
#if PLATFORM(MAC)
# Keyboard support
InterpretKeyEvent(uint32_t type) -> (Vector<WebCore::KeypressCommand> commandName)
#endif
}
#endif
"""
_expected_results = {
'name': 'WebPage',
'condition': 'ENABLE(WEBKIT2)',
'messages': (
{
'name': 'LoadURL',
'parameters': (
('WTF::String', 'url'),
),
'condition': None,
},
{
'name': 'TouchEvent',
'parameters': (
('WebKit::WebTouchEvent', 'event'),
),
'condition': 'ENABLE(TOUCH_EVENTS)',
},
{
'name': 'DidReceivePolicyDecision',
'parameters': (
('uint64_t', 'frameID'),
('uint64_t', 'listenerID'),
('uint32_t', 'policyAction'),
),
'condition': None,
},
{
'name': 'Close',
'parameters': (),
'condition': None,
},
{
'name': 'PreferencesDidChange',
'parameters': (
('WebKit::WebPreferencesStore', 'store'),
),
'condition': None,
},
{
'name': 'SendDoubleAndFloat',
'parameters': (
('double', 'd'),
('float', 'f'),
),
'condition': None,
},
{
'name': 'SendInts',
'parameters': (
('Vector<uint64_t>', 'ints'),
('Vector<Vector<uint64_t> >', 'intVectors')
),
'condition': None,
},
{
'name': 'CreatePlugin',
'parameters': (
('uint64_t', 'pluginInstanceID'),
('WebKit::Plugin::Parameters', 'parameters')
),
'reply_parameters': (
('bool', 'result'),
),
'condition': None,
},
{
'name': 'RunJavaScriptAlert',
'parameters': (
('uint64_t', 'frameID'),
('WTF::String', 'message')
),
'reply_parameters': (),
'condition': None,
},
{
'name': 'GetPlugins',
'parameters': (
('bool', 'refresh'),
),
'reply_parameters': (
('Vector<WebCore::PluginInfo>', 'plugins'),
),
'condition': None,
},
{
'name': 'GetPluginProcessConnection',
'parameters': (
('WTF::String', 'pluginPath'),
),
'reply_parameters': (
('CoreIPC::Connection::Handle', 'connectionHandle'),
),
'condition': None,
},
{
'name': 'TestMultipleAttributes',
'parameters': (
),
'reply_parameters': (
),
'condition': None,
},
{
'name': 'DidCreateWebProcessConnection',
'parameters': (
('CoreIPC::MachPort', 'connectionIdentifier'),
),
'condition': 'PLATFORM(MAC)',
},
{
'name': 'InterpretKeyEvent',
'parameters': (
('uint32_t', 'type'),
),
'reply_parameters': (
('Vector<WebCore::KeypressCommand>', 'commandName'),
),
'condition': 'PLATFORM(MAC)',
},
),
}
class MessagesTest(unittest.TestCase):
def setUp(self):
self.receiver = messages.MessageReceiver.parse(StringIO(_messages_file_contents))
class ParsingTest(MessagesTest):
def check_message(self, message, expected_message):
self.assertEquals(message.name, expected_message['name'])
self.assertEquals(len(message.parameters), len(expected_message['parameters']))
for index, parameter in enumerate(message.parameters):
self.assertEquals(parameter.type, expected_message['parameters'][index][0])
self.assertEquals(parameter.name, expected_message['parameters'][index][1])
if message.reply_parameters != None:
for index, parameter in enumerate(message.reply_parameters):
self.assertEquals(parameter.type, expected_message['reply_parameters'][index][0])
self.assertEquals(parameter.name, expected_message['reply_parameters'][index][1])
else:
self.assertFalse('reply_parameters' in expected_message)
self.assertEquals(message.condition, expected_message['condition'])
def test_receiver(self):
"""Receiver should be parsed as expected"""
self.assertEquals(self.receiver.name, _expected_results['name'])
self.assertEquals(self.receiver.condition, _expected_results['condition'])
self.assertEquals(len(self.receiver.messages), len(_expected_results['messages']))
for index, message in enumerate(self.receiver.messages):
self.check_message(message, _expected_results['messages'][index])
_expected_header = """/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef WebPageMessages_h
#define WebPageMessages_h
#if ENABLE(WEBKIT2)
#include "Arguments.h"
#include "Connection.h"
#include "MessageID.h"
#include "Plugin.h"
#include <WebCore/KeyboardEvent.h>
#include <WebCore/PluginData.h>
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/Vector.h>
namespace CoreIPC {
class ArgumentEncoder;
class Connection;
class MachPort;
}
namespace WTF {
class String;
}
namespace WebKit {
struct WebPreferencesStore;
class WebTouchEvent;
}
namespace Messages {
namespace WebPage {
enum Kind {
LoadURLID,
#if ENABLE(TOUCH_EVENTS)
TouchEventID,
#endif
DidReceivePolicyDecisionID,
CloseID,
PreferencesDidChangeID,
SendDoubleAndFloatID,
SendIntsID,
CreatePluginID,
RunJavaScriptAlertID,
GetPluginsID,
GetPluginProcessConnectionID,
TestMultipleAttributesID,
#if PLATFORM(MAC)
DidCreateWebProcessConnectionID,
#endif
#if PLATFORM(MAC)
InterpretKeyEventID,
#endif
};
struct LoadURL : CoreIPC::Arguments1<const WTF::String&> {
static const Kind messageID = LoadURLID;
typedef CoreIPC::Arguments1<const WTF::String&> DecodeType;
explicit LoadURL(const WTF::String& url)
: CoreIPC::Arguments1<const WTF::String&>(url)
{
}
};
#if ENABLE(TOUCH_EVENTS)
struct TouchEvent : CoreIPC::Arguments1<const WebKit::WebTouchEvent&> {
static const Kind messageID = TouchEventID;
typedef CoreIPC::Arguments1<const WebKit::WebTouchEvent&> DecodeType;
explicit TouchEvent(const WebKit::WebTouchEvent& event)
: CoreIPC::Arguments1<const WebKit::WebTouchEvent&>(event)
{
}
};
#endif
struct DidReceivePolicyDecision : CoreIPC::Arguments3<uint64_t, uint64_t, uint32_t> {
static const Kind messageID = DidReceivePolicyDecisionID;
typedef CoreIPC::Arguments3<uint64_t, uint64_t, uint32_t> DecodeType;
DidReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, uint32_t policyAction)
: CoreIPC::Arguments3<uint64_t, uint64_t, uint32_t>(frameID, listenerID, policyAction)
{
}
};
struct Close : CoreIPC::Arguments0 {
static const Kind messageID = CloseID;
typedef CoreIPC::Arguments0 DecodeType;
};
struct PreferencesDidChange : CoreIPC::Arguments1<const WebKit::WebPreferencesStore&> {
static const Kind messageID = PreferencesDidChangeID;
typedef CoreIPC::Arguments1<const WebKit::WebPreferencesStore&> DecodeType;
explicit PreferencesDidChange(const WebKit::WebPreferencesStore& store)
: CoreIPC::Arguments1<const WebKit::WebPreferencesStore&>(store)
{
}
};
struct SendDoubleAndFloat : CoreIPC::Arguments2<double, float> {
static const Kind messageID = SendDoubleAndFloatID;
typedef CoreIPC::Arguments2<double, float> DecodeType;
SendDoubleAndFloat(double d, float f)
: CoreIPC::Arguments2<double, float>(d, f)
{
}
};
struct SendInts : CoreIPC::Arguments2<const Vector<uint64_t>&, const Vector<Vector<uint64_t> >&> {
static const Kind messageID = SendIntsID;
typedef CoreIPC::Arguments2<const Vector<uint64_t>&, const Vector<Vector<uint64_t> >&> DecodeType;
SendInts(const Vector<uint64_t>& ints, const Vector<Vector<uint64_t> >& intVectors)
: CoreIPC::Arguments2<const Vector<uint64_t>&, const Vector<Vector<uint64_t> >&>(ints, intVectors)
{
}
};
struct CreatePlugin : CoreIPC::Arguments2<uint64_t, const WebKit::Plugin::Parameters&> {
static const Kind messageID = CreatePluginID;
typedef CoreIPC::Arguments1<bool&> Reply;
typedef CoreIPC::Arguments2<uint64_t, const WebKit::Plugin::Parameters&> DecodeType;
CreatePlugin(uint64_t pluginInstanceID, const WebKit::Plugin::Parameters& parameters)
: CoreIPC::Arguments2<uint64_t, const WebKit::Plugin::Parameters&>(pluginInstanceID, parameters)
{
}
};
struct RunJavaScriptAlert : CoreIPC::Arguments2<uint64_t, const WTF::String&> {
static const Kind messageID = RunJavaScriptAlertID;
typedef CoreIPC::Arguments0 Reply;
typedef CoreIPC::Arguments2<uint64_t, const WTF::String&> DecodeType;
RunJavaScriptAlert(uint64_t frameID, const WTF::String& message)
: CoreIPC::Arguments2<uint64_t, const WTF::String&>(frameID, message)
{
}
};
struct GetPlugins : CoreIPC::Arguments1<bool> {
static const Kind messageID = GetPluginsID;
typedef CoreIPC::Arguments1<Vector<WebCore::PluginInfo>&> Reply;
typedef CoreIPC::Arguments1<bool> DecodeType;
explicit GetPlugins(bool refresh)
: CoreIPC::Arguments1<bool>(refresh)
{
}
};
struct GetPluginProcessConnection : CoreIPC::Arguments1<const WTF::String&> {
static const Kind messageID = GetPluginProcessConnectionID;
struct DelayedReply : public ThreadSafeRefCounted<DelayedReply> {
DelayedReply(PassRefPtr<CoreIPC::Connection>, PassOwnPtr<CoreIPC::ArgumentEncoder>);
~DelayedReply();
bool send(const CoreIPC::Connection::Handle& connectionHandle);
private:
RefPtr<CoreIPC::Connection> m_connection;
OwnPtr<CoreIPC::ArgumentEncoder> m_arguments;
};
typedef CoreIPC::Arguments1<CoreIPC::Connection::Handle&> Reply;
typedef CoreIPC::Arguments1<const WTF::String&> DecodeType;
explicit GetPluginProcessConnection(const WTF::String& pluginPath)
: CoreIPC::Arguments1<const WTF::String&>(pluginPath)
{
}
};
struct TestMultipleAttributes : CoreIPC::Arguments0 {
static const Kind messageID = TestMultipleAttributesID;
struct DelayedReply : public ThreadSafeRefCounted<DelayedReply> {
DelayedReply(PassRefPtr<CoreIPC::Connection>, PassOwnPtr<CoreIPC::ArgumentEncoder>);
~DelayedReply();
bool send();
private:
RefPtr<CoreIPC::Connection> m_connection;
OwnPtr<CoreIPC::ArgumentEncoder> m_arguments;
};
typedef CoreIPC::Arguments0 Reply;
typedef CoreIPC::Arguments0 DecodeType;
};
#if PLATFORM(MAC)
struct DidCreateWebProcessConnection : CoreIPC::Arguments1<const CoreIPC::MachPort&> {
static const Kind messageID = DidCreateWebProcessConnectionID;
typedef CoreIPC::Arguments1<const CoreIPC::MachPort&> DecodeType;
explicit DidCreateWebProcessConnection(const CoreIPC::MachPort& connectionIdentifier)
: CoreIPC::Arguments1<const CoreIPC::MachPort&>(connectionIdentifier)
{
}
};
#endif
#if PLATFORM(MAC)
struct InterpretKeyEvent : CoreIPC::Arguments1<uint32_t> {
static const Kind messageID = InterpretKeyEventID;
typedef CoreIPC::Arguments1<Vector<WebCore::KeypressCommand>&> Reply;
typedef CoreIPC::Arguments1<uint32_t> DecodeType;
explicit InterpretKeyEvent(uint32_t type)
: CoreIPC::Arguments1<uint32_t>(type)
{
}
};
#endif
} // namespace WebPage
} // namespace Messages
namespace CoreIPC {
template<> struct MessageKindTraits<Messages::WebPage::Kind> {
static const MessageClass messageClass = MessageClassWebPage;
};
} // namespace CoreIPC
#endif // ENABLE(WEBKIT2)
#endif // WebPageMessages_h
"""
_expected_receiver_implementation = """/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#if ENABLE(WEBKIT2)
#include "WebPage.h"
#if PLATFORM(MAC)
#include "ArgumentCoders.h"
#endif
#include "ArgumentDecoder.h"
#include "Connection.h"
#include "HandleMessage.h"
#if PLATFORM(MAC)
#include "MachPort.h"
#endif
#include "Plugin.h"
#if PLATFORM(MAC)
#include "WebCoreArgumentCoders.h"
#endif
#if ENABLE(TOUCH_EVENTS)
#include "WebEvent.h"
#endif
#include "WebPageMessages.h"
#include "WebPreferencesStore.h"
namespace Messages {
namespace WebPage {
GetPluginProcessConnection::DelayedReply::DelayedReply(PassRefPtr<CoreIPC::Connection> connection, PassOwnPtr<CoreIPC::ArgumentEncoder> arguments)
: m_connection(connection)
, m_arguments(arguments)
{
}
GetPluginProcessConnection::DelayedReply::~DelayedReply()
{
ASSERT(!m_connection);
}
bool GetPluginProcessConnection::DelayedReply::send(const CoreIPC::Connection::Handle& connectionHandle)
{
ASSERT(m_arguments);
m_arguments->encode(connectionHandle);
bool result = m_connection->sendSyncReply(m_arguments.release());
m_connection = nullptr;
return result;
}
TestMultipleAttributes::DelayedReply::DelayedReply(PassRefPtr<CoreIPC::Connection> connection, PassOwnPtr<CoreIPC::ArgumentEncoder> arguments)
: m_connection(connection)
, m_arguments(arguments)
{
}
TestMultipleAttributes::DelayedReply::~DelayedReply()
{
ASSERT(!m_connection);
}
bool TestMultipleAttributes::DelayedReply::send()
{
ASSERT(m_arguments);
bool result = m_connection->sendSyncReply(m_arguments.release());
m_connection = nullptr;
return result;
}
} // namespace WebPage
} // namespace Messages
namespace WebKit {
void WebPage::didReceiveWebPageMessage(CoreIPC::Connection*, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
{
switch (messageID.get<Messages::WebPage::Kind>()) {
case Messages::WebPage::LoadURLID:
CoreIPC::handleMessage<Messages::WebPage::LoadURL>(arguments, this, &WebPage::loadURL);
return;
#if ENABLE(TOUCH_EVENTS)
case Messages::WebPage::TouchEventID:
CoreIPC::handleMessage<Messages::WebPage::TouchEvent>(arguments, this, &WebPage::touchEvent);
return;
#endif
case Messages::WebPage::DidReceivePolicyDecisionID:
CoreIPC::handleMessage<Messages::WebPage::DidReceivePolicyDecision>(arguments, this, &WebPage::didReceivePolicyDecision);
return;
case Messages::WebPage::CloseID:
CoreIPC::handleMessage<Messages::WebPage::Close>(arguments, this, &WebPage::close);
return;
case Messages::WebPage::PreferencesDidChangeID:
CoreIPC::handleMessage<Messages::WebPage::PreferencesDidChange>(arguments, this, &WebPage::preferencesDidChange);
return;
case Messages::WebPage::SendDoubleAndFloatID:
CoreIPC::handleMessage<Messages::WebPage::SendDoubleAndFloat>(arguments, this, &WebPage::sendDoubleAndFloat);
return;
case Messages::WebPage::SendIntsID:
CoreIPC::handleMessage<Messages::WebPage::SendInts>(arguments, this, &WebPage::sendInts);
return;
#if PLATFORM(MAC)
case Messages::WebPage::DidCreateWebProcessConnectionID:
CoreIPC::handleMessage<Messages::WebPage::DidCreateWebProcessConnection>(arguments, this, &WebPage::didCreateWebProcessConnection);
return;
#endif
default:
break;
}
ASSERT_NOT_REACHED();
}
CoreIPC::SyncReplyMode WebPage::didReceiveSyncWebPageMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, CoreIPC::ArgumentEncoder* reply)
{
switch (messageID.get<Messages::WebPage::Kind>()) {
case Messages::WebPage::CreatePluginID:
CoreIPC::handleMessage<Messages::WebPage::CreatePlugin>(arguments, reply, this, &WebPage::createPlugin);
return CoreIPC::AutomaticReply;
case Messages::WebPage::RunJavaScriptAlertID:
CoreIPC::handleMessage<Messages::WebPage::RunJavaScriptAlert>(arguments, reply, this, &WebPage::runJavaScriptAlert);
return CoreIPC::AutomaticReply;
case Messages::WebPage::GetPluginsID:
CoreIPC::handleMessage<Messages::WebPage::GetPlugins>(arguments, reply, this, &WebPage::getPlugins);
return CoreIPC::AutomaticReply;
case Messages::WebPage::GetPluginProcessConnectionID:
CoreIPC::handleMessageDelayed<Messages::WebPage::GetPluginProcessConnection>(connection, arguments, reply, this, &WebPage::getPluginProcessConnection);
return CoreIPC::ManualReply;
case Messages::WebPage::TestMultipleAttributesID:
CoreIPC::handleMessageDelayed<Messages::WebPage::TestMultipleAttributes>(connection, arguments, reply, this, &WebPage::testMultipleAttributes);
return CoreIPC::ManualReply;
#if PLATFORM(MAC)
case Messages::WebPage::InterpretKeyEventID:
CoreIPC::handleMessage<Messages::WebPage::InterpretKeyEvent>(arguments, reply, this, &WebPage::interpretKeyEvent);
return CoreIPC::AutomaticReply;
#endif
default:
break;
}
ASSERT_NOT_REACHED();
return CoreIPC::AutomaticReply;
}
} // namespace WebKit
#endif // ENABLE(WEBKIT2)
"""
class GeneratedFileContentsTest(unittest.TestCase):
def assertGeneratedFileContentsEqual(self, first, second):
first_list = first.split('\n')
second_list = second.split('\n')
for index, first_line in enumerate(first_list):
self.assertEquals(first_line, second_list[index])
self.assertEquals(len(first_list), len(second_list))
class HeaderTest(GeneratedFileContentsTest):
def test_header(self):
file_contents = messages.generate_messages_header(StringIO(_messages_file_contents))
self.assertGeneratedFileContentsEqual(file_contents, _expected_header)
class ReceiverImplementationTest(GeneratedFileContentsTest):
def test_receiver_implementation(self):
file_contents = messages.generate_message_handler(StringIO(_messages_file_contents))
self.assertGeneratedFileContentsEqual(file_contents, _expected_receiver_implementation)
if __name__ == '__main__':
unittest.main()
|
gpl-2.0
|
[
3,
1898,
334,
35,
9,
7129,
21257,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
199,
3,
787,
7647,
26,
199,
3,
413,
14,
221,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
499,
14,
221,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
258,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
19525,
906,
7839,
14,
2401,
473,
9730,
6483,
1124,
1179,
2281,
891,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
199,
3,
9706,
14,
1621,
4825,
6461,
7000,
19525,
906,
7839,
14,
1549,
473,
9730,
6483,
6262,
7024,
2381,
199,
3,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
199,
3,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
199,
3,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
199,
3,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
2882,
199,
504,
5228,
492,
5228,
199,
199,
646,
3788,
199,
199,
63,
3431,
63,
493,
63,
4407,
275,
408,
3,
1898,
334,
35,
9,
7129,
21257,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
199,
3,
787,
7647,
26,
199,
3,
413,
14,
221,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
499,
14,
221,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
258,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
19525,
906,
7839,
14,
2401,
473,
9730,
6483,
1124,
1179,
2281,
891,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
199,
3,
9706,
14,
1621,
4825,
6461,
7000,
19525,
906,
7839,
14,
1549,
473,
9730,
6483,
6262,
7024,
2381,
199,
3,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
199,
3,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
199,
3,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
199,
3,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
3,
2613,
298,
888,
14,
72,
2,
199,
199,
3,
692,
27926,
8,
13166,
43,
649,
18,
9,
199,
199,
3431,
1035,
6001,
3276,
469,
272,
7190,
2632,
8,
55,
6145,
447,
1558,
1166,
9,
199,
3,
692,
27926,
8,
2566,
53,
1244,
63,
8193,
51,
9,
272,
377,
13087,
2390,
8,
21666,
447,
5926,
52,
13087,
2390,
1566,
9,
199,
3,
13739,
272,
29503,
14235,
4845,
872,
3688,
8,
1635,
772,
63,
84,
2787,
998,
12,
3152,
772,
63,
84,
11647,
998,
12,
3152,
708,
63,
84,
4592,
3310,
9,
272,
15524,
342,
339,
5543,
4023,
17366,
4001,
8,
21666,
447,
5926,
30772,
5502,
3877,
9,
272,
10217,
7281,
3325,
5136,
8,
3157,
366,
12,
2069,
289,
9,
272,
10217,
3241,
83,
8,
3646,
28,
1635,
772,
63,
84,
30,
14526,
12,
11388,
28,
3646,
28,
1635,
772,
63,
84,
30,
690,
1109,
31465,
9,
339,
2790,
5061,
8,
1635,
772,
63,
84,
3589,
3244,
998,
12,
6001,
14591,
447,
5061,
447,
5976,
2633,
9,
1035,
334,
2245,
754,
9,
272,
3378,
21986,
18758,
8,
1635,
772,
63,
84,
2787,
998,
12,
644,
6145,
447,
1558,
1245,
9,
1035,
6248,
272,
2372,
19330,
8,
2245,
9236,
9,
1035,
334,
3646,
28,
5926,
5402,
447,
5061,
2354,
30,
8963,
9,
28626,
3314,
3225,
3737,
272,
2372,
5061,
3498,
3225,
8,
55,
6145,
447,
1558,
3589,
2042,
9,
1035,
334,
5402,
31472,
447,
3225,
447,
5940,
1950,
5940,
9,
18464,
1187,
379,
339,
1379,
8433,
5379,
342,
1035,
6248,
28626,
3314,
3225,
3737,
18464,
1187,
379,
199,
199,
3,
692,
21966,
8,
9410,
9,
272,
29503,
2499,
5926,
3498,
3225,
8,
5402,
31472,
447,
45,
1225,
4313,
1950,
7544,
9,
199,
3,
13739,
199,
199,
3,
692,
21966,
8,
9410,
9,
272,
327,
2606,
3576,
2291,
272,
6551,
25133,
1197,
2390,
8,
1635,
708,
63,
84,
730,
9,
1035,
334,
3646,
28,
5926,
5402,
447,
1197,
2915,
3110,
30,
1414,
985,
9,
199,
3,
13739,
199,
93,
199,
199,
3,
13739,
199,
624,
199,
199,
63,
2062,
63,
2604,
275,
469,
272,
283,
354,
356,
283,
5926,
3276,
297,
272,
283,
5394,
356,
283,
8898,
8,
13166,
43,
649,
18,
3196,
272,
283,
3431,
356,
334,
267,
469,
288,
283,
354,
356,
283,
6200,
2632,
297,
288,
283,
3214,
356,
334,
355,
661,
55,
6145,
447,
1558,
297,
283,
633,
659,
288,
2318,
288,
283,
5394,
356,
488,
12,
267,
1660,
267,
469,
288,
283,
354,
356,
283,
52,
13087,
2390,
297,
288,
283,
3214,
356,
334,
355,
661,
21666,
447,
5926,
52,
13087,
2390,
297,
283,
1430
] |
[
1898,
334,
35,
9,
7129,
21257,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
199,
3,
787,
7647,
26,
199,
3,
413,
14,
221,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
499,
14,
221,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
258,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
19525,
906,
7839,
14,
2401,
473,
9730,
6483,
1124,
1179,
2281,
891,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
199,
3,
9706,
14,
1621,
4825,
6461,
7000,
19525,
906,
7839,
14,
1549,
473,
9730,
6483,
6262,
7024,
2381,
199,
3,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
199,
3,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
199,
3,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
199,
3,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
2882,
199,
504,
5228,
492,
5228,
199,
199,
646,
3788,
199,
199,
63,
3431,
63,
493,
63,
4407,
275,
408,
3,
1898,
334,
35,
9,
7129,
21257,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
199,
3,
787,
7647,
26,
199,
3,
413,
14,
221,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
499,
14,
221,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
258,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
19525,
906,
7839,
14,
2401,
473,
9730,
6483,
1124,
1179,
2281,
891,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
199,
3,
9706,
14,
1621,
4825,
6461,
7000,
19525,
906,
7839,
14,
1549,
473,
9730,
6483,
6262,
7024,
2381,
199,
3,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
199,
3,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
199,
3,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
199,
3,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
3,
2613,
298,
888,
14,
72,
2,
199,
199,
3,
692,
27926,
8,
13166,
43,
649,
18,
9,
199,
199,
3431,
1035,
6001,
3276,
469,
272,
7190,
2632,
8,
55,
6145,
447,
1558,
1166,
9,
199,
3,
692,
27926,
8,
2566,
53,
1244,
63,
8193,
51,
9,
272,
377,
13087,
2390,
8,
21666,
447,
5926,
52,
13087,
2390,
1566,
9,
199,
3,
13739,
272,
29503,
14235,
4845,
872,
3688,
8,
1635,
772,
63,
84,
2787,
998,
12,
3152,
772,
63,
84,
11647,
998,
12,
3152,
708,
63,
84,
4592,
3310,
9,
272,
15524,
342,
339,
5543,
4023,
17366,
4001,
8,
21666,
447,
5926,
30772,
5502,
3877,
9,
272,
10217,
7281,
3325,
5136,
8,
3157,
366,
12,
2069,
289,
9,
272,
10217,
3241,
83,
8,
3646,
28,
1635,
772,
63,
84,
30,
14526,
12,
11388,
28,
3646,
28,
1635,
772,
63,
84,
30,
690,
1109,
31465,
9,
339,
2790,
5061,
8,
1635,
772,
63,
84,
3589,
3244,
998,
12,
6001,
14591,
447,
5061,
447,
5976,
2633,
9,
1035,
334,
2245,
754,
9,
272,
3378,
21986,
18758,
8,
1635,
772,
63,
84,
2787,
998,
12,
644,
6145,
447,
1558,
1245,
9,
1035,
6248,
272,
2372,
19330,
8,
2245,
9236,
9,
1035,
334,
3646,
28,
5926,
5402,
447,
5061,
2354,
30,
8963,
9,
28626,
3314,
3225,
3737,
272,
2372,
5061,
3498,
3225,
8,
55,
6145,
447,
1558,
3589,
2042,
9,
1035,
334,
5402,
31472,
447,
3225,
447,
5940,
1950,
5940,
9,
18464,
1187,
379,
339,
1379,
8433,
5379,
342,
1035,
6248,
28626,
3314,
3225,
3737,
18464,
1187,
379,
199,
199,
3,
692,
21966,
8,
9410,
9,
272,
29503,
2499,
5926,
3498,
3225,
8,
5402,
31472,
447,
45,
1225,
4313,
1950,
7544,
9,
199,
3,
13739,
199,
199,
3,
692,
21966,
8,
9410,
9,
272,
327,
2606,
3576,
2291,
272,
6551,
25133,
1197,
2390,
8,
1635,
708,
63,
84,
730,
9,
1035,
334,
3646,
28,
5926,
5402,
447,
1197,
2915,
3110,
30,
1414,
985,
9,
199,
3,
13739,
199,
93,
199,
199,
3,
13739,
199,
624,
199,
199,
63,
2062,
63,
2604,
275,
469,
272,
283,
354,
356,
283,
5926,
3276,
297,
272,
283,
5394,
356,
283,
8898,
8,
13166,
43,
649,
18,
3196,
272,
283,
3431,
356,
334,
267,
469,
288,
283,
354,
356,
283,
6200,
2632,
297,
288,
283,
3214,
356,
334,
355,
661,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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
mirkobronzi/finance-analyzer
|
lib/entries.py
|
1
|
3600
|
"""
classes Entry and Entries
"""
__author__ = 'bronzi'
from datetime import datetime
import re
#TODO: should be configurable
PUNCTUATION_REMOVER = re.compile("[0-9,\.#\-_/']")
SPACE_REMOVER = re.compile(" +")
def string_to_float(string):
"""
simply convert a string into a float
string : basestring
"""
return 0.0 if string.strip() == '' else float(string.replace(',', '.'))
class Entry:
"""
classes Entry - representing an expense/income entry
"""
def __init__(self, date, name, money_out=0.0, money_in=0.0,
comments=None):
self.date = date
self.name = name
self.money_in = money_in
self.money_out = money_out
self.comments = comments if comments else {}
self.normalized_name = Entry._normalize_entry(name)
@staticmethod
def parse(date, name, money_out='0', money_in='0', comments=None):
"""
method to parse strings and convert them into an Entry object
(all parameter are basestring)
"""
parsed_date = datetime.strptime(date, "%m/%d/%Y").date()
parsed_comments = [] if not comments else\
[x.strip().split(':') for x in comments.split(',')]
fixed_parsed_comments = map(
lambda x : x if len(x) > 1 else (x[0], ''),
parsed_comments)
return Entry(parsed_date, name, string_to_float(money_out),
string_to_float(money_in), dict(fixed_parsed_comments))
def as_tuple(self):
return (self.date, self.name, self.money_in, self.money_out,
self.comments)
@staticmethod
def _normalize_entry(name):
normalized_name = re.sub(PUNCTUATION_REMOVER, "", name)
normalized_name = re.sub(SPACE_REMOVER, " ", normalized_name)
return normalized_name.strip()
def __eq__(self, other):
return (self.date == other.date and
self.name == other.name and
self.money_in == other.money_in and
self.money_out == other.money_out and
self.comments == other.comments)
def __hash__(self):
# TODO: check a better way to implement this
# try to generate a frozen dictionary from the beginning
comments_hash = hash(frozenset(self.comments.keys())) +\
hash(frozenset(self.comments.values()))
return hash(self.date) +\
hash(self.name) +\
hash(self.money_in) +\
hash(self.money_out) +\
comments_hash
def __repr__(self):
return (str(self.date) + ' : ' + self.name + ' => (' +
str(self.money_in) + ', -' + str(self.money_out) + ') [' +
str(self.comments) + ']')
class Entries:
"""
classes Entries - representing a collection of Entry
"""
def __init__(self, *args):
self.entries = list(args)
def add(self, entry):
"""
method to add an Entry to the collection
entry : Entry
"""
self.entries.append(entry)
def extend(self, entries):
"""
method to merge the given Entries into this one
entries : Entries
"""
self.entries.extend(entries.entries)
def sorted(self):
entries_as_tuple = [entry.as_tuple() for entry in self.entries]
to_return = sorted(entries_as_tuple)
return Entries(*to_return)
def __eq__(self, other):
return self.entries == other.entries
def __repr__(self):
return str(self.entries)
def __iter__(self):
return iter(self.entries)
|
gpl-3.0
|
[
624,
199,
2888,
11855,
436,
23450,
1996,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
66,
2641,
16079,
7,
421,
199,
504,
2197,
492,
2197,
199,
646,
295,
199,
199,
3,
11768,
26,
1077,
506,
30241,
199,
48,
1734,
1028,
53,
2594,
63,
907,
2679,
2111,
275,
295,
14,
2014,
10994,
16,
13,
25,
4202,
14,
3,
16185,
63,
15,
32266,
199,
11658,
63,
907,
2679,
2111,
275,
295,
14,
2014,
480,
435,
531,
421,
199,
318,
1059,
63,
475,
63,
1609,
8,
875,
304,
272,
408,
272,
9329,
3957,
282,
1059,
1901,
282,
2069,
339,
1059,
520,
7116,
272,
408,
272,
372,
378,
14,
16,
340,
1059,
14,
1913,
342,
508,
2125,
587,
2069,
8,
875,
14,
1814,
32718,
1987,
1333,
421,
199,
533,
11855,
26,
272,
408,
272,
3992,
11855,
446,
6144,
376,
26963,
15,
23607,
2397,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1434,
12,
536,
12,
333,
13234,
63,
548,
29,
16,
14,
16,
12,
333,
13234,
63,
262,
29,
16,
14,
16,
12,
326,
6786,
29,
403,
304,
267,
291,
14,
602,
275,
1434,
267,
291,
14,
354,
275,
536,
267,
291,
14,
27468,
63,
262,
275,
333,
13234,
63,
262,
267,
291,
14,
27468,
63,
548,
275,
333,
13234,
63,
548,
267,
291,
14,
6223,
275,
6786,
340,
6786,
587,
1052,
267,
291,
14,
12916,
63,
354,
275,
11855,
423,
7721,
63,
2373,
8,
354,
9,
339,
768,
4639,
272,
347,
2198,
8,
602,
12,
536,
12,
333,
13234,
63,
548,
534,
16,
297,
333,
13234,
63,
262,
534,
16,
297,
6786,
29,
403,
304,
267,
408,
267,
1083,
370,
2198,
3326,
436,
3957,
3062,
1901,
376,
11855,
909,
267,
334,
452,
2725,
787,
7116,
9,
267,
408,
267,
4565,
63,
602,
275,
2197,
14,
9866,
8,
602,
12,
2071,
77,
3149,
68,
3149,
57,
3471,
602,
342,
267,
4565,
63,
6223,
275,
942,
340,
440,
6786,
587,
60,
288,
359,
88,
14,
1913,
1252,
1294,
11633,
367,
671,
315,
6786,
14,
1294,
29972,
267,
6317,
63,
6751,
63,
6223,
275,
2341,
8,
288,
2400,
671,
520,
671,
340,
822,
8,
88,
9,
690,
413,
587,
334,
88,
59,
16,
467,
9929,
288,
4565,
63,
6223,
9,
267,
372,
11855,
8,
6751,
63,
602,
12,
536,
12,
1059,
63,
475,
63,
1609,
8,
27468,
63,
548,
395,
2151,
1059,
63,
475,
63,
1609,
8,
27468,
63,
262,
395,
1211,
8,
5964,
63,
6751,
63,
6223,
430,
339,
347,
465,
63,
2960,
8,
277,
304,
267,
372,
334,
277,
14,
602,
12,
291,
14,
354,
12,
291,
14,
27468,
63,
262,
12,
291,
14,
27468,
63,
548,
12,
355,
291,
14,
6223,
9,
339,
768,
4639,
272,
347,
485,
7721,
63,
2373,
8,
354,
304,
267,
9657,
63,
354,
275,
295,
14,
954,
8,
48,
1734,
1028,
53,
2594,
63,
907,
2679,
2111,
12,
4873,
536,
9,
267,
9657,
63,
354,
275,
295,
14,
954,
8,
11658,
63,
907,
2679,
2111,
12,
298,
3872,
9657,
63,
354,
9,
267,
372,
9657,
63,
354,
14,
1913,
342,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
334,
277,
14,
602,
508,
1163,
14,
602,
436,
355,
291,
14,
354,
508,
1163,
14,
354,
436,
355,
291,
14,
27468,
63,
262,
508,
1163,
14,
27468,
63,
262,
436,
355,
291,
14,
27468,
63,
548,
508,
1163,
14,
27468,
63,
548,
436,
355,
291,
14,
6223,
508,
1163,
14,
6223,
9,
339,
347,
636,
2227,
721,
277,
304,
267,
327,
3254,
26,
1104,
282,
8034,
4340,
370,
5669,
642,
267,
327,
862,
370,
3550,
282,
8101,
2600,
687,
314,
9608,
267,
6786,
63,
2227,
275,
2631,
8,
21362,
8,
277,
14,
6223,
14,
1612,
4059,
17992,
288,
2631,
8,
21362,
8,
277,
14,
6223,
14,
1459,
4059,
267,
372,
2631,
8,
277,
14,
602,
9,
17992,
288,
2631,
8,
277,
14,
354,
9,
17992,
288,
2631,
8,
277,
14,
27468,
63,
262,
9,
17992,
288,
2631,
8,
277,
14,
27468,
63,
548,
9,
17992,
288,
6786,
63,
2227,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
334,
495,
8,
277,
14,
602,
9,
435,
283,
520,
283,
435,
291,
14,
354,
435,
283,
9265,
661,
435,
355,
620,
8,
277,
14,
27468,
63,
262,
9,
435,
1656,
446,
7,
435,
620,
8,
277,
14,
27468,
63,
548,
9,
435,
5320,
788,
435,
355,
620,
8,
277,
14,
6223,
9,
435,
283,
10374,
421,
199,
533,
23450,
1996,
26,
272,
408,
272,
3992,
23450,
1996,
446,
6144,
282,
3245,
402,
11855,
272,
408,
272,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
291,
14,
3189,
275,
769,
8,
589,
9,
339,
347,
1050,
8,
277,
12,
2397,
304,
267,
408,
267,
1083,
370,
1050,
376,
11855,
370,
314,
3245,
267,
2397,
520,
11855,
267,
408,
267,
291,
14,
3189,
14,
740,
8,
2373,
9,
339,
347,
12247,
8,
277,
12,
4811,
304,
267,
408,
267,
1083,
370,
5389,
314,
1627,
23450,
1996,
1901,
642,
1373,
267,
4811,
520,
23450,
1996,
267,
408,
267,
291,
14,
3189,
14,
2880,
8,
3189,
14,
3189,
9,
339,
347,
3355,
8,
277,
304,
267,
4811,
63,
305,
63,
2960,
275,
359,
2373,
14,
305,
63,
2960,
342,
367,
2397,
315,
291,
14,
3189,
61,
267,
370,
63,
1107,
275,
3355,
8,
3189,
63,
305,
63,
2960,
9,
267,
372,
23450,
1996,
2031,
475,
63,
1107,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
291,
14,
3189,
508,
1163,
14,
3189,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
620,
8,
277,
14,
3189,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
14,
3189,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
2888,
11855,
436,
23450,
1996,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
66,
2641,
16079,
7,
421,
199,
504,
2197,
492,
2197,
199,
646,
295,
199,
199,
3,
11768,
26,
1077,
506,
30241,
199,
48,
1734,
1028,
53,
2594,
63,
907,
2679,
2111,
275,
295,
14,
2014,
10994,
16,
13,
25,
4202,
14,
3,
16185,
63,
15,
32266,
199,
11658,
63,
907,
2679,
2111,
275,
295,
14,
2014,
480,
435,
531,
421,
199,
318,
1059,
63,
475,
63,
1609,
8,
875,
304,
272,
408,
272,
9329,
3957,
282,
1059,
1901,
282,
2069,
339,
1059,
520,
7116,
272,
408,
272,
372,
378,
14,
16,
340,
1059,
14,
1913,
342,
508,
2125,
587,
2069,
8,
875,
14,
1814,
32718,
1987,
1333,
421,
199,
533,
11855,
26,
272,
408,
272,
3992,
11855,
446,
6144,
376,
26963,
15,
23607,
2397,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1434,
12,
536,
12,
333,
13234,
63,
548,
29,
16,
14,
16,
12,
333,
13234,
63,
262,
29,
16,
14,
16,
12,
326,
6786,
29,
403,
304,
267,
291,
14,
602,
275,
1434,
267,
291,
14,
354,
275,
536,
267,
291,
14,
27468,
63,
262,
275,
333,
13234,
63,
262,
267,
291,
14,
27468,
63,
548,
275,
333,
13234,
63,
548,
267,
291,
14,
6223,
275,
6786,
340,
6786,
587,
1052,
267,
291,
14,
12916,
63,
354,
275,
11855,
423,
7721,
63,
2373,
8,
354,
9,
339,
768,
4639,
272,
347,
2198,
8,
602,
12,
536,
12,
333,
13234,
63,
548,
534,
16,
297,
333,
13234,
63,
262,
534,
16,
297,
6786,
29,
403,
304,
267,
408,
267,
1083,
370,
2198,
3326,
436,
3957,
3062,
1901,
376,
11855,
909,
267,
334,
452,
2725,
787,
7116,
9,
267,
408,
267,
4565,
63,
602,
275,
2197,
14,
9866,
8,
602,
12,
2071,
77,
3149,
68,
3149,
57,
3471,
602,
342,
267,
4565,
63,
6223,
275,
942,
340,
440,
6786,
587,
60,
288,
359,
88,
14,
1913,
1252,
1294,
11633,
367,
671,
315,
6786,
14,
1294,
29972,
267,
6317,
63,
6751,
63,
6223,
275,
2341,
8,
288,
2400,
671,
520,
671,
340,
822,
8,
88,
9,
690,
413,
587,
334,
88,
59,
16,
467,
9929,
288,
4565,
63,
6223,
9,
267,
372,
11855,
8,
6751,
63,
602,
12,
536,
12,
1059,
63,
475,
63,
1609,
8,
27468,
63,
548,
395,
2151,
1059,
63,
475,
63,
1609,
8,
27468,
63,
262,
395,
1211,
8,
5964,
63,
6751,
63,
6223,
430,
339,
347,
465,
63,
2960,
8,
277,
304,
267,
372,
334,
277,
14,
602,
12,
291,
14,
354,
12,
291,
14,
27468,
63,
262,
12,
291,
14,
27468,
63,
548,
12,
355,
291,
14,
6223,
9,
339,
768,
4639,
272,
347,
485,
7721,
63,
2373,
8,
354,
304,
267,
9657,
63,
354,
275,
295,
14,
954,
8,
48,
1734,
1028,
53,
2594,
63,
907,
2679,
2111,
12,
4873,
536,
9,
267,
9657,
63,
354,
275,
295,
14,
954,
8,
11658,
63,
907,
2679,
2111,
12,
298,
3872,
9657,
63,
354,
9,
267,
372,
9657,
63,
354,
14,
1913,
342,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
334,
277,
14,
602,
508,
1163,
14,
602,
436,
355,
291,
14,
354,
508,
1163,
14,
354,
436,
355,
291,
14,
27468,
63,
262,
508,
1163,
14,
27468,
63,
262,
436,
355,
291,
14,
27468,
63,
548,
508,
1163,
14,
27468,
63,
548,
436,
355,
291,
14,
6223,
508,
1163,
14,
6223,
9,
339,
347,
636,
2227,
721,
277,
304,
267,
327,
3254,
26,
1104,
282,
8034,
4340,
370,
5669,
642,
267,
327,
862,
370,
3550,
282,
8101,
2600,
687,
314,
9608,
267,
6786,
63,
2227,
275,
2631,
8,
21362,
8,
277,
14,
6223,
14,
1612,
4059,
17992,
288,
2631,
8,
21362,
8,
277,
14,
6223,
14,
1459,
4059,
267,
372,
2631,
8,
277,
14,
602,
9,
17992,
288,
2631,
8,
277,
14,
354,
9,
17992,
288,
2631,
8,
277,
14,
27468,
63,
262,
9,
17992,
288,
2631,
8,
277,
14,
27468,
63,
548,
9,
17992,
288,
6786,
63,
2227,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
334,
495,
8,
277,
14,
602,
9,
435,
283,
520,
283,
435,
291,
14,
354,
435,
283,
9265,
661,
435,
355,
620,
8,
277,
14,
27468,
63,
262,
9,
435,
1656,
446,
7,
435,
620,
8,
277,
14,
27468,
63,
548,
9,
435,
5320,
788,
435,
355,
620,
8,
277,
14,
6223,
9,
435,
283,
10374,
421,
199,
533,
23450,
1996,
26,
272,
408,
272,
3992,
23450,
1996,
446,
6144,
282,
3245,
402,
11855,
272,
408,
272,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
291,
14,
3189,
275,
769,
8,
589,
9,
339,
347,
1050,
8,
277,
12,
2397,
304,
267,
408,
267,
1083,
370,
1050,
376,
11855,
370,
314,
3245,
267,
2397,
520,
11855,
267,
408,
267,
291,
14,
3189,
14,
740,
8,
2373,
9,
339,
347,
12247,
8,
277,
12,
4811,
304,
267,
408,
267,
1083,
370,
5389,
314,
1627,
23450,
1996,
1901,
642,
1373,
267,
4811,
520,
23450,
1996,
267,
408,
267,
291,
14,
3189,
14,
2880,
8,
3189,
14,
3189,
9,
339,
347,
3355,
8,
277,
304,
267,
4811,
63,
305,
63,
2960,
275,
359,
2373,
14,
305,
63,
2960,
342,
367,
2397,
315,
291,
14,
3189,
61,
267,
370,
63,
1107,
275,
3355,
8,
3189,
63,
305,
63,
2960,
9,
267,
372,
23450,
1996,
2031,
475,
63,
1107,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
291,
14,
3189,
508,
1163,
14,
3189,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
620,
8,
277,
14,
3189,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
14,
3189,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
cousteaulecommandant/youtube-dl
|
youtube_dl/extractor/appleconnect.py
|
139
|
1848
|
# coding: utf-8
from __future__ import unicode_literals
from .common import InfoExtractor
from ..utils import (
str_to_int,
ExtractorError
)
class AppleConnectIE(InfoExtractor):
_VALID_URL = r'https?://itunes\.apple\.com/\w{0,2}/?post/idsa\.(?P<id>[\w-]+)'
_TEST = {
'url': 'https://itunes.apple.com/us/post/idsa.4ab17a39-2720-11e5-96c5-a5b38f6c42d3',
'md5': '10d0f2799111df4cb1c924520ca78f98',
'info_dict': {
'id': '4ab17a39-2720-11e5-96c5-a5b38f6c42d3',
'ext': 'm4v',
'title': 'Energy',
'uploader': 'Drake',
'thumbnail': 'http://is5.mzstatic.com/image/thumb/Video5/v4/78/61/c5/7861c5fa-ad6d-294b-1464-cf7605b911d6/source/1920x1080sr.jpg',
'upload_date': '20150710',
'timestamp': 1436545535,
},
}
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
try:
video_json = self._html_search_regex(
r'class="auc-video-data">(\{.*?\})', webpage, 'json')
except ExtractorError:
raise ExtractorError('This post doesn\'t contain a video', expected=True)
video_data = self._parse_json(video_json, video_id)
timestamp = str_to_int(self._html_search_regex(r'data-timestamp="(\d+)"', webpage, 'timestamp'))
like_count = str_to_int(self._html_search_regex(r'(\d+) Loves', webpage, 'like count'))
return {
'id': video_id,
'url': video_data['sslSrc'],
'title': video_data['title'],
'description': video_data['description'],
'uploader': video_data['artistName'],
'thumbnail': video_data['artworkUrl'],
'timestamp': timestamp,
'like_count': like_count,
}
|
unlicense
|
[
3,
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
620,
63,
475,
63,
442,
12,
272,
19783,
199,
9,
421,
199,
533,
21257,
8631,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
390,
324,
397,
4537,
12820,
4537,
957,
6307,
87,
91,
16,
12,
18,
5995,
31,
1932,
15,
1580,
65,
4537,
2229,
48,
28,
344,
24693,
87,
20253,
3171,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
2859,
921,
390,
324,
397,
14,
12820,
14,
957,
15,
527,
15,
1932,
15,
1580,
65,
14,
20,
371,
1196,
65,
1355,
13,
1465,
1165,
13,
845,
69,
21,
13,
2534,
67,
21,
13,
65,
21,
66,
1703,
70,
22,
67,
2260,
68,
19,
297,
267,
283,
1064,
21,
356,
283,
709,
68,
16,
70,
1465,
1020,
6673,
1587,
20,
2894,
17,
67,
25,
11677,
1165,
696,
2277,
70,
2905,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
20,
371,
1196,
65,
1355,
13,
1465,
1165,
13,
845,
69,
21,
13,
2534,
67,
21,
13,
65,
21,
66,
1703,
70,
22,
67,
2260,
68,
19,
297,
288,
283,
832,
356,
283,
77,
20,
86,
297,
288,
283,
1213,
356,
283,
9900,
297,
288,
283,
13671,
356,
283,
36,
345,
415,
297,
288,
283,
8311,
356,
283,
1014,
921,
374,
21,
14,
28808,
1986,
14,
957,
15,
1569,
15,
16534,
15,
9166,
21,
15,
86,
20,
15,
2277,
15,
2976,
15,
67,
21,
15,
23,
16253,
67,
21,
667,
13,
350,
22,
68,
13,
10693,
66,
13,
1079,
772,
13,
2177,
2114,
1717,
66,
25,
845,
68,
22,
15,
1365,
15,
1167,
1165,
88,
23514,
5474,
14,
8476,
297,
288,
283,
5064,
63,
602,
356,
283,
1797,
13583,
709,
297,
288,
283,
3954,
356,
4329,
1344,
1477,
1229,
1276,
12,
267,
1660,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
398,
862,
26,
288,
3991,
63,
1001,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
355,
519,
7,
533,
628,
19129,
13,
3722,
13,
576,
1743,
2961,
91,
21040,
25583,
9248,
12,
283,
1001,
358,
267,
871,
19783,
26,
288,
746,
19783,
360,
2765,
2963,
3181,
3985,
84,
1395,
282,
3991,
297,
1420,
29,
549,
9,
398,
3991,
63,
576,
275,
291,
423,
1122,
63,
1001,
8,
3722,
63,
1001,
12,
3991,
63,
344,
9,
267,
4913,
275,
620,
63,
475,
63,
442,
8,
277,
423,
1360,
63,
1733,
63,
3821,
8,
82,
5121,
419,
13,
3954,
628,
2961,
68,
20415,
297,
9248,
12,
283,
3954,
1333,
267,
2839,
63,
835,
275,
620,
63,
475,
63,
442,
8,
277,
423,
1360,
63,
1733,
63,
3821,
8,
82,
13445,
68,
8771,
3835,
2310,
297,
9248,
12,
283,
2930,
2338,
1333,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
633,
356,
3991,
63,
576,
459,
4266,
21261,
995,
288,
283,
1213,
356,
3991,
63,
576,
459,
1213,
995,
288,
283,
1802,
356,
3991,
63,
576,
459,
1802,
995,
288,
283,
13671,
356,
3991,
63,
576,
459,
11215,
985,
995,
288,
283,
8311,
356,
3991,
63,
576,
459,
580,
800,
6417,
995,
288,
283,
3954,
356,
4913,
12,
288,
283,
2930,
63,
835,
356,
2839,
63,
835,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
620,
63,
475,
63,
442,
12,
272,
19783,
199,
9,
421,
199,
533,
21257,
8631,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
390,
324,
397,
4537,
12820,
4537,
957,
6307,
87,
91,
16,
12,
18,
5995,
31,
1932,
15,
1580,
65,
4537,
2229,
48,
28,
344,
24693,
87,
20253,
3171,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
2859,
921,
390,
324,
397,
14,
12820,
14,
957,
15,
527,
15,
1932,
15,
1580,
65,
14,
20,
371,
1196,
65,
1355,
13,
1465,
1165,
13,
845,
69,
21,
13,
2534,
67,
21,
13,
65,
21,
66,
1703,
70,
22,
67,
2260,
68,
19,
297,
267,
283,
1064,
21,
356,
283,
709,
68,
16,
70,
1465,
1020,
6673,
1587,
20,
2894,
17,
67,
25,
11677,
1165,
696,
2277,
70,
2905,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
20,
371,
1196,
65,
1355,
13,
1465,
1165,
13,
845,
69,
21,
13,
2534,
67,
21,
13,
65,
21,
66,
1703,
70,
22,
67,
2260,
68,
19,
297,
288,
283,
832,
356,
283,
77,
20,
86,
297,
288,
283,
1213,
356,
283,
9900,
297,
288,
283,
13671,
356,
283,
36,
345,
415,
297,
288,
283,
8311,
356,
283,
1014,
921,
374,
21,
14,
28808,
1986,
14,
957,
15,
1569,
15,
16534,
15,
9166,
21,
15,
86,
20,
15,
2277,
15,
2976,
15,
67,
21,
15,
23,
16253,
67,
21,
667,
13,
350,
22,
68,
13,
10693,
66,
13,
1079,
772,
13,
2177,
2114,
1717,
66,
25,
845,
68,
22,
15,
1365,
15,
1167,
1165,
88,
23514,
5474,
14,
8476,
297,
288,
283,
5064,
63,
602,
356,
283,
1797,
13583,
709,
297,
288,
283,
3954,
356,
4329,
1344,
1477,
1229,
1276,
12,
267,
1660,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
398,
862,
26,
288,
3991,
63,
1001,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
355,
519,
7,
533,
628,
19129,
13,
3722,
13,
576,
1743,
2961,
91,
21040,
25583,
9248,
12,
283,
1001,
358,
267,
871,
19783,
26,
288,
746,
19783,
360,
2765,
2963,
3181,
3985,
84,
1395,
282,
3991,
297,
1420,
29,
549,
9,
398,
3991,
63,
576,
275,
291,
423,
1122,
63,
1001,
8,
3722,
63,
1001,
12,
3991,
63,
344,
9,
267,
4913,
275,
620,
63,
475,
63,
442,
8,
277,
423,
1360,
63,
1733,
63,
3821,
8,
82,
5121,
419,
13,
3954,
628,
2961,
68,
20415,
297,
9248,
12,
283,
3954,
1333,
267,
2839,
63,
835,
275,
620,
63,
475,
63,
442,
8,
277,
423,
1360,
63,
1733,
63,
3821,
8,
82,
13445,
68,
8771,
3835,
2310,
297,
9248,
12,
283,
2930,
2338,
1333,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
633,
356,
3991,
63,
576,
459,
4266,
21261,
995,
288,
283,
1213,
356,
3991,
63,
576,
459,
1213,
995,
288,
283,
1802,
356,
3991,
63,
576,
459,
1802,
995,
288,
283,
13671,
356,
3991,
63,
576,
459,
11215,
985,
995,
288,
283,
8311,
356,
3991,
63,
576,
459,
580,
800,
6417,
995,
288,
283,
3954,
356,
4913,
12,
288,
283,
2930,
63,
835,
356,
2839,
63,
835,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
reactormonk/eve-wspace
|
evewspace/Map/migrations/0005_auto__add_field_wormhole_eol_time.py
|
17
|
17431
|
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'Wormhole.eol_time'
db.add_column('Map_wormhole', 'eol_time',
self.gf('django.db.models.fields.DateTimeField')(null=True),
keep_default=False)
def backwards(self, orm):
# Deleting field 'Wormhole.eol_time'
db.delete_column('Map_wormhole', 'eol_time')
models = {
'Map.activepilot': {
'Meta': {'object_name': 'ActivePilot'},
'charactername': ('django.db.models.fields.CharField', [], {'max_length': '72'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'shipname': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
'shiptype': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
'system': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'active_pilots'", 'to': "orm['Map.System']"}),
'timestamp': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'locations'", 'to': "orm['auth.User']"})
},
'Map.destination': {
'Meta': {'object_name': 'Destination'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'system': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'destinations'", 'to': "orm['Map.KSystem']"}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'destinations'", 'null': 'True', 'to': "orm['auth.User']"})
},
'Map.ksystem': {
'Meta': {'object_name': 'KSystem', '_ormbases': ['Map.System']},
'jumps': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'sov': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'system_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['Map.System']", 'unique': 'True', 'primary_key': 'True'})
},
'Map.map': {
'Meta': {'object_name': 'Map'},
'explicitperms': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
'root': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'root'", 'to': "orm['Map.System']"})
},
'Map.maplog': {
'Meta': {'object_name': 'MapLog'},
'action': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'map': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'logentries'", 'to': "orm['Map.Map']"}),
'timestamp': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'maplogs'", 'to': "orm['auth.User']"}),
'visible': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
},
'Map.mappermission': {
'Meta': {'object_name': 'MapPermission'},
'access': ('django.db.models.fields.IntegerField', [], {}),
'group': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'mappermissions'", 'to': "orm['auth.Group']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'map': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'grouppermissions'", 'to': "orm['Map.Map']"})
},
'Map.mapsystem': {
'Meta': {'object_name': 'MapSystem'},
'friendlyname': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'interesttime': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'map': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'systems'", 'to': "orm['Map.Map']"}),
'parentsystem': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'childsystems'", 'null': 'True', 'to': "orm['Map.MapSystem']"}),
'system': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'maps'", 'to': "orm['Map.System']"})
},
'Map.signature': {
'Meta': {'ordering': "['sigid']", 'object_name': 'Signature'},
'activated': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'downtimes': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'info': ('django.db.models.fields.CharField', [], {'max_length': '65', 'null': 'True', 'blank': 'True'}),
'lastescalated': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'ratscleared': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'sigid': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
'sigtype': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'sigs'", 'null': 'True', 'to': "orm['Map.SignatureType']"}),
'system': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'signatures'", 'to': "orm['Map.System']"}),
'updated': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
},
'Map.signaturetype': {
'Meta': {'object_name': 'SignatureType'},
'escalatable': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'longname': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'shortname': ('django.db.models.fields.CharField', [], {'max_length': '6'}),
'sleeprsite': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
},
'Map.sitespawn': {
'Meta': {'object_name': 'SiteSpawn'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'sigtype': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['Map.SignatureType']"}),
'sitename': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'spawns': ('django.db.models.fields.TextField', [], {}),
'sysclass': ('django.db.models.fields.IntegerField', [], {})
},
'Map.snapshot': {
'Meta': {'object_name': 'Snapshot'},
'description': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'json': ('django.db.models.fields.TextField', [], {}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
'timestamp': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'snapshots'", 'to': "orm['auth.User']"})
},
'Map.system': {
'Meta': {'object_name': 'System', '_ormbases': ['core.SystemData']},
'first_visited': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'info': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'last_visited': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'lastscanned': ('django.db.models.fields.DateTimeField', [], {}),
'npckills': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'occupied': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'podkills': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'shipkills': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'sysclass': ('django.db.models.fields.IntegerField', [], {}),
'systemdata_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['core.SystemData']", 'unique': 'True', 'primary_key': 'True'}),
'updated': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'})
},
'Map.wormhole': {
'Meta': {'object_name': 'Wormhole'},
'bottom': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'parent_wormholes'", 'null': 'True', 'to': "orm['Map.MapSystem']"}),
'bottom_bubbled': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}),
'bottom_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'to': "orm['Map.WormholeType']"}),
'eol_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'map': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'wormholes'", 'to': "orm['Map.Map']"}),
'mass_status': ('django.db.models.fields.IntegerField', [], {}),
'time_status': ('django.db.models.fields.IntegerField', [], {}),
'top': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'child_wormholes'", 'to': "orm['Map.MapSystem']"}),
'top_bubbled': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}),
'top_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'to': "orm['Map.WormholeType']"}),
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
},
'Map.wormholetype': {
'Meta': {'object_name': 'WormholeType'},
'destination': ('django.db.models.fields.IntegerField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'jumpmass': ('django.db.models.fields.BigIntegerField', [], {}),
'lifetime': ('django.db.models.fields.IntegerField', [], {}),
'maxmass': ('django.db.models.fields.BigIntegerField', [], {}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '4'}),
'source': ('django.db.models.fields.CharField', [], {'max_length': '2'}),
'target': ('django.db.models.fields.CharField', [], {'max_length': '15'})
},
'Map.wsystem': {
'Meta': {'object_name': 'WSystem', '_ormbases': ['Map.System']},
'effect': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'}),
'static1': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'primary_statics'", 'null': 'True', 'to': "orm['Map.WormholeType']"}),
'static2': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'secondary_statics'", 'null': 'True', 'to': "orm['Map.WormholeType']"}),
'system_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['Map.System']", 'unique': 'True', 'primary_key': 'True'})
},
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'core.constellation': {
'Meta': {'object_name': 'Constellation', 'db_table': "'mapConstellations'", 'managed': 'False'},
'id': ('django.db.models.fields.IntegerField', [], {'primary_key': 'True', 'db_column': "'constellationID'"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'db_column': "'constellationName'"}),
'region': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'constellations'", 'db_column': "'regionID'", 'to': "orm['core.Region']"}),
'x': ('django.db.models.fields.FloatField', [], {}),
'y': ('django.db.models.fields.FloatField', [], {}),
'z': ('django.db.models.fields.FloatField', [], {})
},
'core.region': {
'Meta': {'object_name': 'Region', 'db_table': "'mapRegions'", 'managed': 'False'},
'id': ('django.db.models.fields.IntegerField', [], {'primary_key': 'True', 'db_column': "'regionID'"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'db_column': "'regionName'"}),
'x': ('django.db.models.fields.FloatField', [], {}),
'y': ('django.db.models.fields.FloatField', [], {}),
'z': ('django.db.models.fields.FloatField', [], {})
},
'core.systemdata': {
'Meta': {'object_name': 'SystemData', 'db_table': "'mapSolarSystems'", 'managed': 'False'},
'constellation': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'systems'", 'db_column': "'constellationID'", 'to': "orm['core.Constellation']"}),
'id': ('django.db.models.fields.IntegerField', [], {'primary_key': 'True', 'db_column': "'solarSystemID'"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'db_column': "'solarSystemName'"}),
'region': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'systems'", 'db_column': "'regionID'", 'to': "orm['core.Region']"}),
'security': ('django.db.models.fields.FloatField', [], {}),
'x': ('django.db.models.fields.FloatField', [], {}),
'y': ('django.db.models.fields.FloatField', [], {}),
'z': ('django.db.models.fields.FloatField', [], {})
}
}
complete_apps = ['Map']
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
901,
283,
55,
1025,
16668,
14,
20470,
63,
521,
7,
267,
1592,
14,
525,
63,
2301,
360,
2956,
63,
584,
77,
16668,
297,
283,
20470,
63,
521,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2307,
29,
549,
395,
1993,
4215,
63,
885,
29,
797,
9,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
15920,
901,
283,
55,
1025,
16668,
14,
20470,
63,
521,
7,
267,
1592,
14,
1807,
63,
2301,
360,
2956,
63,
584,
77,
16668,
297,
283,
20470,
63,
521,
358,
2378,
1709,
275,
469,
267,
283,
2956,
14,
2682,
1038,
1653,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
7472,
10542,
1653,
2267,
288,
283,
10856,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
2819,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
3319,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
708,
1604,
288,
283,
3319,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
708,
1604,
288,
283,
2253,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
2682,
63,
1038,
4555,
4662,
283,
475,
356,
298,
1025,
459,
2956,
14,
3989,
6097,
288,
283,
3954,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
2495,
63,
2131,
63,
525,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
751,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
8022,
4662,
283,
475,
356,
298,
1025,
459,
1178,
14,
1899,
13687,
267,
1660,
267,
283,
2956,
14,
6881,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
13151,
2267,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
2253,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
2614,
9511,
4662,
283,
475,
356,
298,
1025,
459,
2956,
14,
43,
3989,
6097,
288,
283,
751,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
2614,
9511,
4662,
283,
2307,
356,
283,
549,
297,
283,
475,
356,
298,
1025,
459,
1178,
14,
1899,
13687,
267,
1660,
267,
283,
2956,
14,
75,
2253,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
43,
3989,
297,
2513,
31525,
356,
788,
2956,
14,
3989,
14949,
288,
283,
11126,
83,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
2307,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
1152,
86,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
2253,
63,
4695,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
297,
990,
791,
475,
356,
298,
1025,
459,
2956,
14,
3989,
6256,
283,
3235,
356,
283,
549,
297,
283,
3327,
63,
498,
356,
283,
549,
3071,
267,
1660,
267,
283,
2956,
14,
1130,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2956,
2267,
288,
283,
10306,
12068,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1231,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
1231,
4662,
283,
475,
356,
298,
1025,
459,
2956,
14,
3989,
13687,
267,
1660,
267,
283,
2956,
14,
1130,
793,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2956,
2445,
2267,
288,
283,
1287,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
2299,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
1130,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
793,
3189,
4662,
283,
475,
356,
298,
1025,
459,
2956,
14,
2956,
6097,
288,
283,
3954,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
2495,
63,
2131,
63,
525,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
751,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
1130,
7270,
4662,
283,
475,
356,
298,
1025,
459,
1178,
14,
1899,
6097,
288,
283,
6604,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
3071,
267,
1660,
267,
283,
2956,
14,
1130,
5693,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2956,
7980,
2267,
288,
283,
2732,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
8613,
288,
283,
923,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
901,
283,
55,
1025,
16668,
14,
20470,
63,
521,
7,
267,
1592,
14,
525,
63,
2301,
360,
2956,
63,
584,
77,
16668,
297,
283,
20470,
63,
521,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2307,
29,
549,
395,
1993,
4215,
63,
885,
29,
797,
9,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
15920,
901,
283,
55,
1025,
16668,
14,
20470,
63,
521,
7,
267,
1592,
14,
1807,
63,
2301,
360,
2956,
63,
584,
77,
16668,
297,
283,
20470,
63,
521,
358,
2378,
1709,
275,
469,
267,
283,
2956,
14,
2682,
1038,
1653,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
7472,
10542,
1653,
2267,
288,
283,
10856,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
2819,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
3319,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
708,
1604,
288,
283,
3319,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
708,
1604,
288,
283,
2253,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
2682,
63,
1038,
4555,
4662,
283,
475,
356,
298,
1025,
459,
2956,
14,
3989,
6097,
288,
283,
3954,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
2495,
63,
2131,
63,
525,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
751,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
8022,
4662,
283,
475,
356,
298,
1025,
459,
1178,
14,
1899,
13687,
267,
1660,
267,
283,
2956,
14,
6881,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
13151,
2267,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
2253,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
2614,
9511,
4662,
283,
475,
356,
298,
1025,
459,
2956,
14,
43,
3989,
6097,
288,
283,
751,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
2614,
9511,
4662,
283,
2307,
356,
283,
549,
297,
283,
475,
356,
298,
1025,
459,
1178,
14,
1899,
13687,
267,
1660,
267,
283,
2956,
14,
75,
2253,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
43,
3989,
297,
2513,
31525,
356,
788,
2956,
14,
3989,
14949,
288,
283,
11126,
83,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
2307,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
1152,
86,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
2253,
63,
4695,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
297,
990,
791,
475,
356,
298,
1025,
459,
2956,
14,
3989,
6256,
283,
3235,
356,
283,
549,
297,
283,
3327,
63,
498,
356,
283,
549,
3071,
267,
1660,
267,
283,
2956,
14,
1130,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2956,
2267,
288,
283,
10306,
12068,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1231,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
1231,
4662,
283,
475,
356,
298,
1025,
459,
2956,
14,
3989,
13687,
267,
1660,
267,
283,
2956,
14,
1130,
793,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2956,
2445,
2267,
288,
283,
1287,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
2299,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
1130,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
793,
3189,
4662,
283,
475,
356,
298,
1025,
459,
2956,
14,
2956,
6097,
288,
283,
3954,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
2495,
63,
2131,
63,
525,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
751,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
1130,
7270,
4662,
283,
475,
356,
298,
1025,
459,
1178,
14,
1899,
6097,
288,
283,
6604,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
3071,
267,
1660,
267,
283,
2956,
14,
1130,
5693,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2956,
7980,
2267,
288,
283,
2732,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
8613,
288,
283,
923,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
CloudServer/nova
|
nova/api/openstack/compute/contrib/used_limits.py
|
62
|
3281
|
# Copyright 2012 OpenStack Foundation
#
# 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.
import six
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova import quota
QUOTAS = quota.QUOTAS
XMLNS = "http://docs.openstack.org/compute/ext/used_limits/api/v1.1"
ALIAS = "os-used-limits"
authorize = extensions.soft_extension_authorizer('compute', 'used_limits')
authorize_for_admin = extensions.extension_authorizer('compute',
'used_limits_for_admin')
class UsedLimitsController(wsgi.Controller):
def __init__(self, ext_mgr):
self.ext_mgr = ext_mgr
@staticmethod
def _reserved(req):
try:
return int(req.GET['reserved'])
except (ValueError, KeyError):
return False
@wsgi.extends
def index(self, req, resp_obj):
context = req.environ['nova.context']
project_id = self._project_id(context, req)
quotas = QUOTAS.get_project_quotas(context, project_id, usages=True)
quota_map = {
'totalRAMUsed': 'ram',
'totalCoresUsed': 'cores',
'totalInstancesUsed': 'instances',
'totalFloatingIpsUsed': 'floating_ips',
'totalSecurityGroupsUsed': 'security_groups',
}
if self.ext_mgr.is_loaded('os-server-group-quotas'):
quota_map['totalServerGroupsUsed'] = 'server_groups'
used_limits = {}
for display_name, key in six.iteritems(quota_map):
if key in quotas:
reserved = (quotas[key]['reserved']
if self._reserved(req) else 0)
used_limits[display_name] = quotas[key]['in_use'] + reserved
resp_obj.obj['limits']['absolute'].update(used_limits)
def _project_id(self, context, req):
if self.ext_mgr.is_loaded('os-used-limits-for-admin'):
if 'tenant_id' in req.GET:
tenant_id = req.GET.get('tenant_id')
target = {
'project_id': tenant_id,
'user_id': context.user_id
}
authorize_for_admin(context, target=target)
return tenant_id
return context.project_id
class Used_limits(extensions.ExtensionDescriptor):
"""Provide data on limited resources that are being used."""
name = "UsedLimits"
alias = ALIAS
namespace = XMLNS
updated = "2012-07-13T00:00:00Z"
def get_controller_extensions(self):
controller = UsedLimitsController(self.ext_mgr)
limits_ext = extensions.ControllerExtension(self, 'limits',
controller=controller)
return [limits_ext]
|
apache-2.0
|
[
3,
1898,
6029,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
3816,
199,
199,
504,
5913,
14,
1246,
14,
8512,
492,
5478,
199,
504,
5913,
14,
1246,
14,
8512,
492,
12464,
199,
504,
5913,
492,
12132,
421,
199,
18654,
1179,
275,
12132,
14,
18654,
1179,
421,
199,
4317,
2709,
275,
298,
1014,
921,
4757,
14,
8512,
14,
1308,
15,
3357,
15,
832,
15,
2972,
63,
9368,
15,
1246,
15,
86,
17,
14,
17,
2,
199,
12644,
275,
298,
736,
13,
2972,
13,
9368,
2,
199,
14204,
275,
5478,
14,
4617,
63,
3435,
63,
2502,
1793,
360,
3357,
297,
283,
2972,
63,
9368,
358,
199,
14204,
63,
509,
63,
2113,
275,
5478,
14,
3435,
63,
2502,
1793,
360,
3357,
297,
10028,
283,
2972,
63,
9368,
63,
509,
63,
2113,
358,
421,
199,
533,
8051,
24480,
7506,
8,
6508,
14,
7506,
304,
339,
347,
636,
826,
721,
277,
12,
1599,
63,
7755,
304,
267,
291,
14,
832,
63,
7755,
275,
1599,
63,
7755,
339,
768,
4639,
272,
347,
485,
10421,
8,
2103,
304,
267,
862,
26,
288,
372,
1109,
8,
2103,
14,
2970,
459,
10421,
1105,
267,
871,
334,
3393,
12,
4067,
304,
288,
372,
756,
339,
768,
6508,
14,
11036,
272,
347,
1478,
8,
277,
12,
2648,
12,
3085,
63,
1113,
304,
267,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
267,
2199,
63,
344,
275,
291,
423,
1715,
63,
344,
8,
1100,
12,
2648,
9,
267,
22874,
275,
11364,
1179,
14,
362,
63,
1715,
63,
17056,
8,
1100,
12,
2199,
63,
344,
12,
4503,
83,
29,
549,
9,
267,
12132,
63,
1130,
275,
469,
288,
283,
2923,
30839,
9167,
356,
283,
5975,
297,
288,
283,
2923,
967,
470,
9167,
356,
283,
4630,
297,
288,
283,
2923,
18194,
9167,
356,
283,
5990,
297,
288,
283,
2923,
17895,
41,
1190,
9167,
356,
283,
7774,
63,
6142,
297,
288,
283,
2923,
7676,
10177,
9167,
356,
283,
4416,
63,
2634,
297,
267,
789,
267,
340,
291,
14,
832,
63,
7755,
14,
374,
63,
4591,
360,
736,
13,
1000,
13,
923,
13,
17056,
735,
288,
12132,
63,
1130,
459,
2923,
3120,
10177,
9167,
418,
275,
283,
1000,
63,
2634,
7,
398,
1202,
63,
9368,
275,
1052,
267,
367,
2929,
63,
354,
12,
790,
315,
3816,
14,
4611,
8,
8848,
63,
1130,
304,
288,
340,
790,
315,
22874,
26,
355,
4644,
275,
334,
17056,
59,
498,
2733,
10421,
418,
1169,
340,
291,
423,
10421,
8,
2103,
9,
587,
378,
9,
355,
1202,
63,
9368,
59,
2918,
63,
354,
61,
275,
22874,
59,
498,
2733,
262,
63,
1180,
418,
435,
4644,
398,
3085,
63,
1113,
14,
1113,
459,
9368,
2545,
6116,
2278,
873,
8,
2972,
63,
9368,
9,
339,
347,
485,
1715,
63,
344,
8,
277,
12,
1067,
12,
2648,
304,
267,
340,
291,
14,
832,
63,
7755,
14,
374,
63,
4591,
360,
736,
13,
2972,
13,
9368,
13,
509,
13,
2113,
735,
288,
340,
283,
4647,
63,
344,
7,
315,
2648,
14,
2970,
26,
355,
8261,
63,
344,
275,
2648,
14,
2970,
14,
362,
360,
4647,
63,
344,
358,
355,
1347,
275,
469,
490,
283,
1715,
63,
344,
356,
8261,
63,
344,
12,
490,
283,
751,
63,
344,
356,
1067,
14,
751,
63,
344,
490,
789,
355,
20210,
63,
509,
63,
2113,
8,
1100,
12,
1347,
29,
1375,
9,
355,
372,
8261,
63,
344,
267,
372,
1067,
14,
1715,
63,
344,
421,
199,
533,
8051,
63,
9368,
8,
5359,
14,
6382,
4311,
304,
272,
408,
25107,
666,
641,
13988,
5944,
626,
787,
3769,
1202,
1041,
339,
536,
275,
298,
9167,
24480,
2,
272,
5162,
275,
437,
2673,
1179,
272,
3231,
275,
4692,
2709,
272,
4588,
275,
298,
7409,
13,
1780,
13,
969,
52,
383,
26,
383,
26,
383,
58,
2,
339,
347,
664,
63,
5538,
63,
5359,
8,
277,
304,
267,
7614,
275,
8051,
24480,
7506,
8,
277,
14,
832,
63,
7755,
9,
267,
10976,
63,
832,
275,
5478,
14,
7506,
6382,
8,
277,
12,
283,
9368,
297,
8105,
7614,
29,
5538,
9,
267,
372,
359,
9368,
63,
832,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6029,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
3816,
199,
199,
504,
5913,
14,
1246,
14,
8512,
492,
5478,
199,
504,
5913,
14,
1246,
14,
8512,
492,
12464,
199,
504,
5913,
492,
12132,
421,
199,
18654,
1179,
275,
12132,
14,
18654,
1179,
421,
199,
4317,
2709,
275,
298,
1014,
921,
4757,
14,
8512,
14,
1308,
15,
3357,
15,
832,
15,
2972,
63,
9368,
15,
1246,
15,
86,
17,
14,
17,
2,
199,
12644,
275,
298,
736,
13,
2972,
13,
9368,
2,
199,
14204,
275,
5478,
14,
4617,
63,
3435,
63,
2502,
1793,
360,
3357,
297,
283,
2972,
63,
9368,
358,
199,
14204,
63,
509,
63,
2113,
275,
5478,
14,
3435,
63,
2502,
1793,
360,
3357,
297,
10028,
283,
2972,
63,
9368,
63,
509,
63,
2113,
358,
421,
199,
533,
8051,
24480,
7506,
8,
6508,
14,
7506,
304,
339,
347,
636,
826,
721,
277,
12,
1599,
63,
7755,
304,
267,
291,
14,
832,
63,
7755,
275,
1599,
63,
7755,
339,
768,
4639,
272,
347,
485,
10421,
8,
2103,
304,
267,
862,
26,
288,
372,
1109,
8,
2103,
14,
2970,
459,
10421,
1105,
267,
871,
334,
3393,
12,
4067,
304,
288,
372,
756,
339,
768,
6508,
14,
11036,
272,
347,
1478,
8,
277,
12,
2648,
12,
3085,
63,
1113,
304,
267,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
267,
2199,
63,
344,
275,
291,
423,
1715,
63,
344,
8,
1100,
12,
2648,
9,
267,
22874,
275,
11364,
1179,
14,
362,
63,
1715,
63,
17056,
8,
1100,
12,
2199,
63,
344,
12,
4503,
83,
29,
549,
9,
267,
12132,
63,
1130,
275,
469,
288,
283,
2923,
30839,
9167,
356,
283,
5975,
297,
288,
283,
2923,
967,
470,
9167,
356,
283,
4630,
297,
288,
283,
2923,
18194,
9167,
356,
283,
5990,
297,
288,
283,
2923,
17895,
41,
1190,
9167,
356,
283,
7774,
63,
6142,
297,
288,
283,
2923,
7676,
10177,
9167,
356,
283,
4416,
63,
2634,
297,
267,
789,
267,
340,
291,
14,
832,
63,
7755,
14,
374,
63,
4591,
360,
736,
13,
1000,
13,
923,
13,
17056,
735,
288,
12132,
63,
1130,
459,
2923,
3120,
10177,
9167,
418,
275,
283,
1000,
63,
2634,
7,
398,
1202,
63,
9368,
275,
1052,
267,
367,
2929,
63,
354,
12,
790,
315,
3816,
14,
4611,
8,
8848,
63,
1130,
304,
288,
340,
790,
315,
22874,
26,
355,
4644,
275,
334,
17056,
59,
498,
2733,
10421,
418,
1169,
340,
291,
423,
10421,
8,
2103,
9,
587,
378,
9,
355,
1202,
63,
9368,
59,
2918,
63,
354,
61,
275,
22874,
59,
498,
2733,
262,
63,
1180,
418,
435,
4644,
398,
3085,
63,
1113,
14,
1113,
459,
9368,
2545,
6116,
2278,
873,
8,
2972,
63,
9368,
9,
339,
347,
485,
1715,
63,
344,
8,
277,
12,
1067,
12,
2648,
304,
267,
340,
291,
14,
832,
63,
7755,
14,
374,
63,
4591,
360,
736,
13,
2972,
13,
9368,
13,
509,
13,
2113,
735,
288,
340,
283,
4647,
63,
344,
7,
315,
2648,
14,
2970,
26,
355,
8261,
63,
344,
275,
2648,
14,
2970,
14,
362,
360,
4647,
63,
344,
358,
355,
1347,
275,
469,
490,
283,
1715,
63,
344,
356,
8261,
63,
344,
12,
490,
283,
751,
63,
344,
356,
1067,
14,
751,
63,
344,
490,
789,
355,
20210,
63,
509,
63,
2113,
8,
1100,
12,
1347,
29,
1375,
9,
355,
372,
8261,
63,
344,
267,
372,
1067,
14,
1715,
63,
344,
421,
199,
533,
8051,
63,
9368,
8,
5359,
14,
6382,
4311,
304,
272,
408,
25107,
666,
641,
13988,
5944,
626,
787,
3769,
1202,
1041,
339,
536,
275,
298,
9167,
24480,
2,
272,
5162,
275,
437,
2673,
1179,
272,
3231,
275,
4692,
2709,
272,
4588,
275,
298,
7409,
13,
1780,
13,
969,
52,
383,
26,
383,
26,
383,
58,
2,
339,
347,
664,
63,
5538,
63,
5359,
8,
277,
304,
267,
7614,
275,
8051,
24480,
7506,
8,
277,
14,
832,
63,
7755,
9,
267,
10976,
63,
832,
275,
5478,
14,
7506,
6382,
8,
277,
12,
283,
9368,
297,
8105,
7614,
29,
5538,
9,
267,
372,
359,
9368,
63,
832,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mrrrgn/olympia
|
apps/bandwagon/tests/test_models.py
|
9
|
9602
|
import datetime
import itertools
import random
import mock
from nose.tools import eq_
import amo
import amo.tests
from access.models import Group
from addons.models import Addon, AddonRecommendation
from bandwagon.models import (Collection, CollectionAddon, CollectionUser,
CollectionWatcher, RecommendedCollection,
SyncedCollection)
from devhub.models import ActivityLog
from bandwagon import tasks
from users.models import UserProfile
def get_addons(c):
q = c.addons.order_by('collectionaddon__ordering')
return list(q.values_list('id', flat=True))
def activitylog_count(type):
qs = ActivityLog.objects
if type:
qs = qs.filter(action=type.id)
return qs.count()
class TestCollections(amo.tests.TestCase):
fixtures = ('base/addon_3615', 'bandwagon/test_models',
'base/user_4043307')
def setUp(self):
super(TestCollections, self).setUp()
self.user = UserProfile.objects.create(username='uhhh', email='uh@hh')
self.other = UserProfile.objects.exclude(id=self.user.id)[0]
amo.set_user(self.user)
def test_description(self):
c = Collection.objects.create(
description='<a href="http://example.com">example.com</a> '
'http://example.com <b>foo</b> some text')
# All markup escaped, links are stripped.
eq_(unicode(c.description), '<b>foo</b> some text')
def test_icon_url(self):
# Has no icon.
c = Collection(pk=512, modified=datetime.datetime.now())
assert c.icon_url.endswith('img/icons/collection.png')
c.icontype = 'image/png'
url = c.icon_url.split('?')[0]
assert url.endswith('0/512.png')
c.id = 12341234
url = c.icon_url.split('?')[0]
assert url.endswith('12341/12341234.png')
c.icontype = None
c.type = amo.COLLECTION_FAVORITES
assert c.icon_url.endswith('img/icons/heart.png')
def test_is_subscribed(self):
c = Collection(pk=512)
c.following.create(user=self.user)
assert c.is_subscribed(self.user)
def test_translation_default(self):
"""Make sure we're getting strings from the default locale."""
c = Collection.objects.get(pk=512)
eq_(unicode(c.name), 'yay')
def test_listed(self):
"""Make sure the manager's listed() filter works."""
listed_count = Collection.objects.listed().count()
# Make a private collection.
Collection.objects.create(
name="Hello", uuid="4e2a1acc-39ae-47ec-956f-46e080ac7f69",
listed=False, author=self.user)
eq_(Collection.objects.listed().count(), listed_count)
def test_auto_uuid(self):
c = Collection.objects.create(author=self.user)
assert c.uuid != ''
assert isinstance(c.uuid, basestring)
def test_addon_index(self):
c = Collection.objects.get(pk=512)
c.author = self.user
eq_(c.addon_index, None)
ids = c.addons.values_list('id', flat=True)
c.save()
eq_(c.addon_index, Collection.make_index(ids))
def test_recommended_collection(self):
"""RecommendedCollections automatically get type=rec."""
c = RecommendedCollection.objects.create(author=self.user)
eq_(c.type, amo.COLLECTION_RECOMMENDED)
def test_set_addons(self):
addons = list(Addon.objects.values_list('id', flat=True))
c = Collection.objects.create(author=self.user)
# Check insert.
random.shuffle(addons)
c.set_addons(addons)
eq_(get_addons(c), addons)
eq_(activitylog_count(amo.LOG.ADD_TO_COLLECTION), len(addons))
# Check update.
random.shuffle(addons)
c.set_addons(addons)
eq_(get_addons(c), addons)
# Check delete.
delete_cnt = len(addons) - 1
addons = addons[:2]
c.set_addons(addons)
eq_(activitylog_count(amo.LOG.REMOVE_FROM_COLLECTION), delete_cnt)
eq_(get_addons(c), addons)
eq_(c.addons.count(), len(addons))
def test_set_addons_comment(self):
addons = list(Addon.objects.values_list('id', flat=True))
c = Collection.objects.create(author=self.user)
c.set_addons(addons, {addons[0]: 'This is a comment.'})
collection_addon = CollectionAddon.objects.get(collection=c,
addon=addons[0])
eq_(collection_addon.comments, 'This is a comment.')
def test_publishable_by(self):
c = Collection(pk=512, author=self.other)
CollectionUser(collection=c, user=self.user).save()
eq_(c.publishable_by(self.user), True)
def test_manager_publishable_by(self):
c1 = Collection.objects.create(author=self.user, name='B')
c2 = Collection.objects.create(author=self.user, name='A')
c3 = Collection.objects.create(author=self.other, name='D')
c4 = Collection.objects.create(author=self.other, name='C')
CollectionUser(collection=c1, user=self.user).save()
CollectionUser(collection=c2, user=self.other).save()
CollectionUser(collection=c3, user=self.user).save()
CollectionUser(collection=c4, user=self.other).save()
collections = Collection.objects.publishable_by(self.user)
assert list(collections) == [c2, c1, c3]
def test_collection_meta(self):
c = Collection.objects.create(author=self.user)
eq_(c.addon_count, 0)
c.add_addon(Addon.objects.all()[0])
eq_(activitylog_count(amo.LOG.ADD_TO_COLLECTION), 1)
c = Collection.objects.get(id=c.id)
assert not c.from_cache
eq_(c.addon_count, 1)
def test_favorites_slug(self):
c = Collection.objects.create(author=self.user, slug='favorites')
eq_(c.type, amo.COLLECTION_NORMAL)
eq_(c.slug, 'favorites~')
c = Collection.objects.create(author=self.user, slug='favorites')
eq_(c.type, amo.COLLECTION_NORMAL)
eq_(c.slug, 'favorites~-1')
def test_slug_dupe(self):
c = Collection.objects.create(author=self.user, slug='boom')
eq_(c.slug, 'boom')
c.save()
eq_(c.slug, 'boom')
c = Collection.objects.create(author=self.user, slug='boom')
eq_(c.slug, 'boom-1')
c = Collection.objects.create(author=self.user, slug='boom')
eq_(c.slug, 'boom-2')
def test_watchers(self):
def check(num):
eq_(Collection.objects.get(id=512).subscribers, num)
tasks.collection_watchers(512)
check(0)
CollectionWatcher.objects.create(collection_id=512, user=self.user)
check(1)
def test_can_view_stats(self):
c = Collection.objects.create(author=self.user, slug='boom')
fake_request = mock.Mock()
fake_request.groups = ()
fake_request.user.is_authenticated.return_value = True
# Owner.
fake_request.amo_user = self.user
eq_(c.can_view_stats(fake_request), True)
# Bad user.
fake_request.amo_user = UserProfile.objects.create(
username='scrub', email='ez@dee')
eq_(c.can_view_stats(fake_request), False)
# Member of group with Collections:Edit permission.
fake_request.groups = (Group(name='Collections Agency',
rules='CollectionStats:View'),)
eq_(c.can_view_stats(fake_request), True)
# Developer.
CollectionUser.objects.create(collection=c, user=self.user)
fake_request.groups = ()
fake_request.amo_user = self.user
eq_(c.can_view_stats(fake_request), True)
class TestRecommendations(amo.tests.TestCase):
fixtures = ['base/addon-recs']
ids = [5299, 1843, 2464, 7661, 5369]
@classmethod
def expected_recs(self):
scores, ranked = [], {}
# Get all the add-on => rank pairs.
for x in AddonRecommendation.scores(self.ids).values():
scores.extend(x.items())
# Sum up any dupes.
groups = itertools.groupby(sorted(scores), key=lambda x: x[0])
for addon, pairs in groups:
ranked[addon] = sum(x[1] for x in pairs)
addons = sorted(ranked.items(), key=lambda x: x[1], reverse=True)
return [x[0] for x in addons if x[0] not in self.ids]
def test_build_recs(self):
eq_(RecommendedCollection.build_recs(self.ids), self.expected_recs())
@mock.patch('bandwagon.models.AddonRecommendation.scores')
def test_no_dups(self, scores):
# The inner dict is the recommended addons for addon 7.
scores.return_value = {7: {1: 5, 2: 3, 3: 4}}
recs = RecommendedCollection.build_recs([7, 3, 8])
# 3 should not be in the list since we already have it.
eq_(recs, [1, 2])
class TestSyncedCollection(amo.tests.TestCase):
fixtures = ['base/addon-recs']
ids = (5299, 1843, 2464, 7661, 5369)
def test_set_addons(self):
synced_collection = SyncedCollection.objects.create()
synced_collection.set_addons(self.ids)
synced_collection.reload()
assert tuple(
synced_collection.addons.values_list('id', flat=True)) == self.ids
def test_set_addons_empty_list(self):
"""This is really to make sure it doesn't blow up: see bug 1197471."""
synced_collection = SyncedCollection.objects.create()
synced_collection.set_addons([])
synced_collection.reload()
assert synced_collection.addons.count() == 0
|
bsd-3-clause
|
[
646,
2197,
199,
646,
7975,
199,
646,
2196,
199,
199,
646,
1683,
199,
504,
11354,
14,
2537,
492,
3850,
63,
199,
199,
646,
30235,
199,
646,
30235,
14,
2219,
199,
504,
2879,
14,
992,
492,
5611,
199,
504,
21293,
14,
992,
492,
29366,
12,
29366,
497,
22105,
199,
504,
10981,
30412,
265,
14,
992,
492,
334,
7768,
12,
18003,
19654,
12,
18003,
1899,
12,
2892,
18003,
13978,
281,
12,
799,
11902,
7768,
12,
2892,
29988,
6867,
7768,
9,
199,
504,
4866,
16560,
14,
992,
492,
21885,
2445,
199,
504,
10981,
30412,
265,
492,
6527,
199,
504,
4390,
14,
992,
492,
19037,
421,
199,
318,
664,
63,
10788,
8,
67,
304,
272,
1894,
275,
286,
14,
10788,
14,
1648,
63,
991,
360,
3627,
9291,
363,
7128,
358,
272,
372,
769,
8,
81,
14,
1459,
63,
513,
360,
344,
297,
6829,
29,
549,
430,
421,
199,
318,
10679,
793,
63,
835,
8,
466,
304,
272,
6377,
275,
21885,
2445,
14,
1462,
272,
340,
730,
26,
267,
6377,
275,
6377,
14,
1541,
8,
1287,
29,
466,
14,
344,
9,
272,
372,
6377,
14,
835,
342,
421,
199,
533,
1379,
7768,
83,
8,
4393,
14,
2219,
14,
1746,
304,
272,
15188,
275,
661,
1095,
15,
9291,
63,
1344,
1046,
297,
283,
7877,
30412,
265,
15,
396,
63,
992,
297,
355,
283,
1095,
15,
751,
63,
5188,
1153,
1780,
358,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
7768,
83,
12,
291,
680,
5996,
342,
267,
291,
14,
751,
275,
19037,
14,
1462,
14,
981,
8,
2473,
534,
85,
12156,
72,
297,
3031,
534,
22451,
32,
12156,
358,
267,
291,
14,
1848,
275,
19037,
14,
1462,
14,
5473,
8,
344,
29,
277,
14,
751,
14,
344,
2788,
16,
61,
267,
30235,
14,
409,
63,
751,
8,
277,
14,
751,
9,
339,
347,
511,
63,
1802,
8,
277,
304,
267,
286,
275,
18003,
14,
1462,
14,
981,
8,
288,
1369,
15829,
65,
4369,
628,
1014,
921,
2694,
14,
957,
1743,
2694,
14,
957,
1108,
65,
30,
283,
717,
283,
1014,
921,
2694,
14,
957,
665,
66,
30,
1421,
1108,
66,
30,
2005,
1318,
358,
267,
327,
2900,
9189,
11077,
12,
6220,
787,
14489,
14,
267,
3850,
2531,
2975,
8,
67,
14,
1802,
395,
7673,
4116,
27,
66,
6,
3308,
27,
1421,
6,
4116,
22352,
66,
6,
3308,
27,
2005,
1318,
358,
339,
347,
511,
63,
4677,
63,
633,
8,
277,
304,
267,
327,
13481,
949,
7016,
14,
267,
286,
275,
18003,
8,
2051,
29,
7736,
12,
6042,
29,
2083,
14,
2083,
14,
2131,
1012,
267,
702,
286,
14,
4677,
63,
633,
14,
4130,
360,
4060,
15,
16471,
15,
3627,
14,
4524,
358,
398,
286,
14,
4677,
466,
275,
283,
1569,
15,
4524,
7,
267,
1166,
275,
286,
14,
4677,
63,
633,
14,
1294,
360,
31,
5832,
16,
61,
267,
702,
1166,
14,
4130,
360,
16,
15,
7736,
14,
4524,
358,
398,
286,
14,
344,
275,
14763,
4321,
267,
1166,
275,
286,
14,
4677,
63,
633,
14,
1294,
360,
31,
5832,
16,
61,
267,
702,
1166,
14,
4130,
360,
4321,
17,
15,
4321,
4321,
14,
4524,
358,
398,
286,
14,
4677,
466,
275,
488,
267,
286,
14,
466,
275,
30235,
14,
29374,
63,
2078,
54,
726,
649,
654,
267,
702,
286,
14,
4677,
63,
633,
14,
4130,
360,
4060,
15,
16471,
15,
426,
580,
14,
4524,
358,
339,
347,
511,
63,
374,
63,
23178,
8,
277,
304,
267,
286,
275,
18003,
8,
2051,
29,
7736,
9,
267,
286,
14,
21589,
14,
981,
8,
751,
29,
277,
14,
751,
9,
267,
702,
286,
14,
374,
63,
23178,
8,
277,
14,
751,
9,
339,
347,
511,
63,
6893,
63,
885,
8,
277,
304,
267,
408,
5483,
3238,
781,
3984,
10232,
3326,
687,
314,
849,
5867,
1041,
267,
286,
275,
18003,
14,
1462,
14,
362,
8,
2051,
29,
7736,
9,
267,
3850,
2531,
2975,
8,
67,
14,
354,
395,
283,
89,
1187,
358,
339,
347,
511,
63,
15023,
8,
277,
304,
267,
408,
5483,
3238,
314,
5256,
1159,
10532,
342,
2457,
5419,
1041,
267,
10532,
63,
835,
275,
18003,
14,
1462,
14,
15023,
1252,
835,
342,
267,
327,
4155,
282,
5726,
3245,
14,
267,
18003,
14,
1462,
14,
981,
8,
288,
536,
628,
6257,
401,
5377,
628,
20,
69,
18,
65,
17,
5470,
13,
1355,
3624,
13,
2417,
825,
13,
31980,
70,
13,
2466,
69,
27014,
645,
23,
70,
1876,
401,
288,
10532,
29,
797,
12,
4132,
29,
277,
14,
751,
9,
398,
3850,
2531,
7768,
14,
1462,
14,
15023,
1252,
835,
1062,
10532,
63,
835,
9,
339,
347,
511,
63,
2495,
63,
2580,
8,
277,
304,
267,
286,
275,
18003,
14,
1462,
14,
981,
8,
2502,
29,
277,
14,
751,
9,
267,
702,
286,
14,
2580,
1137,
2125,
267,
702,
1228,
8,
67,
14,
2580,
12,
7116,
9,
339,
347,
511,
63,
9291,
63,
1080,
8,
277,
304,
267,
286,
275,
18003,
14,
1462,
14,
362,
8,
2051,
29,
7736,
9,
267,
286,
14,
2502,
275,
291,
14,
751,
267,
3850,
2531,
67,
14,
9291,
63,
1080,
12,
488,
9,
267,
2762,
275,
286,
14,
10788,
14,
1459,
63,
513,
360,
344,
297,
6829,
29,
549,
9,
267,
286,
14,
2117,
342,
267,
3850,
2531,
67,
14,
9291,
63,
1080,
12,
18003,
14,
1875,
63,
1080,
8,
1580,
430,
339,
347,
511,
63,
264,
11902,
63,
3627,
8,
277,
304,
267,
408,
497,
11902,
7768,
83,
5847,
664,
730,
29,
2761,
1041,
267,
286,
275,
799,
11902,
7768,
14,
1462,
14,
981,
8,
2502,
29,
277,
14,
751,
9,
267,
3850,
2531,
67,
14,
466,
12,
30235,
14,
29374,
63,
907,
5378,
25518,
9,
339,
347,
511,
63,
409,
63,
10788,
8,
277,
304,
267,
21293,
275,
769,
8,
19654,
14,
1462,
14,
1459,
63,
513,
360,
344,
297,
6829,
29,
549,
430,
267,
286,
275,
18003,
14,
1462,
14,
981,
8,
2502,
29,
277,
14,
751,
9,
398,
327,
2670,
5518,
14,
267,
2196,
14,
11777,
8,
10788,
9,
267,
286,
14,
409,
63,
10788,
8,
10788,
9,
267,
3850,
2531,
362,
63,
10788,
8,
67,
395,
21293,
9,
267,
3850,
2531,
8240,
793,
63,
835,
8,
4393,
14,
4947,
14,
9732,
63,
2566,
63,
29374,
395,
822,
8,
10788
] |
[
2197,
199,
646,
7975,
199,
646,
2196,
199,
199,
646,
1683,
199,
504,
11354,
14,
2537,
492,
3850,
63,
199,
199,
646,
30235,
199,
646,
30235,
14,
2219,
199,
504,
2879,
14,
992,
492,
5611,
199,
504,
21293,
14,
992,
492,
29366,
12,
29366,
497,
22105,
199,
504,
10981,
30412,
265,
14,
992,
492,
334,
7768,
12,
18003,
19654,
12,
18003,
1899,
12,
2892,
18003,
13978,
281,
12,
799,
11902,
7768,
12,
2892,
29988,
6867,
7768,
9,
199,
504,
4866,
16560,
14,
992,
492,
21885,
2445,
199,
504,
10981,
30412,
265,
492,
6527,
199,
504,
4390,
14,
992,
492,
19037,
421,
199,
318,
664,
63,
10788,
8,
67,
304,
272,
1894,
275,
286,
14,
10788,
14,
1648,
63,
991,
360,
3627,
9291,
363,
7128,
358,
272,
372,
769,
8,
81,
14,
1459,
63,
513,
360,
344,
297,
6829,
29,
549,
430,
421,
199,
318,
10679,
793,
63,
835,
8,
466,
304,
272,
6377,
275,
21885,
2445,
14,
1462,
272,
340,
730,
26,
267,
6377,
275,
6377,
14,
1541,
8,
1287,
29,
466,
14,
344,
9,
272,
372,
6377,
14,
835,
342,
421,
199,
533,
1379,
7768,
83,
8,
4393,
14,
2219,
14,
1746,
304,
272,
15188,
275,
661,
1095,
15,
9291,
63,
1344,
1046,
297,
283,
7877,
30412,
265,
15,
396,
63,
992,
297,
355,
283,
1095,
15,
751,
63,
5188,
1153,
1780,
358,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
7768,
83,
12,
291,
680,
5996,
342,
267,
291,
14,
751,
275,
19037,
14,
1462,
14,
981,
8,
2473,
534,
85,
12156,
72,
297,
3031,
534,
22451,
32,
12156,
358,
267,
291,
14,
1848,
275,
19037,
14,
1462,
14,
5473,
8,
344,
29,
277,
14,
751,
14,
344,
2788,
16,
61,
267,
30235,
14,
409,
63,
751,
8,
277,
14,
751,
9,
339,
347,
511,
63,
1802,
8,
277,
304,
267,
286,
275,
18003,
14,
1462,
14,
981,
8,
288,
1369,
15829,
65,
4369,
628,
1014,
921,
2694,
14,
957,
1743,
2694,
14,
957,
1108,
65,
30,
283,
717,
283,
1014,
921,
2694,
14,
957,
665,
66,
30,
1421,
1108,
66,
30,
2005,
1318,
358,
267,
327,
2900,
9189,
11077,
12,
6220,
787,
14489,
14,
267,
3850,
2531,
2975,
8,
67,
14,
1802,
395,
7673,
4116,
27,
66,
6,
3308,
27,
1421,
6,
4116,
22352,
66,
6,
3308,
27,
2005,
1318,
358,
339,
347,
511,
63,
4677,
63,
633,
8,
277,
304,
267,
327,
13481,
949,
7016,
14,
267,
286,
275,
18003,
8,
2051,
29,
7736,
12,
6042,
29,
2083,
14,
2083,
14,
2131,
1012,
267,
702,
286,
14,
4677,
63,
633,
14,
4130,
360,
4060,
15,
16471,
15,
3627,
14,
4524,
358,
398,
286,
14,
4677,
466,
275,
283,
1569,
15,
4524,
7,
267,
1166,
275,
286,
14,
4677,
63,
633,
14,
1294,
360,
31,
5832,
16,
61,
267,
702,
1166,
14,
4130,
360,
16,
15,
7736,
14,
4524,
358,
398,
286,
14,
344,
275,
14763,
4321,
267,
1166,
275,
286,
14,
4677,
63,
633,
14,
1294,
360,
31,
5832,
16,
61,
267,
702,
1166,
14,
4130,
360,
4321,
17,
15,
4321,
4321,
14,
4524,
358,
398,
286,
14,
4677,
466,
275,
488,
267,
286,
14,
466,
275,
30235,
14,
29374,
63,
2078,
54,
726,
649,
654,
267,
702,
286,
14,
4677,
63,
633,
14,
4130,
360,
4060,
15,
16471,
15,
426,
580,
14,
4524,
358,
339,
347,
511,
63,
374,
63,
23178,
8,
277,
304,
267,
286,
275,
18003,
8,
2051,
29,
7736,
9,
267,
286,
14,
21589,
14,
981,
8,
751,
29,
277,
14,
751,
9,
267,
702,
286,
14,
374,
63,
23178,
8,
277,
14,
751,
9,
339,
347,
511,
63,
6893,
63,
885,
8,
277,
304,
267,
408,
5483,
3238,
781,
3984,
10232,
3326,
687,
314,
849,
5867,
1041,
267,
286,
275,
18003,
14,
1462,
14,
362,
8,
2051,
29,
7736,
9,
267,
3850,
2531,
2975,
8,
67,
14,
354,
395,
283,
89,
1187,
358,
339,
347,
511,
63,
15023,
8,
277,
304,
267,
408,
5483,
3238,
314,
5256,
1159,
10532,
342,
2457,
5419,
1041,
267,
10532,
63,
835,
275,
18003,
14,
1462,
14,
15023,
1252,
835,
342,
267,
327,
4155,
282,
5726,
3245,
14,
267,
18003,
14,
1462,
14,
981,
8,
288,
536,
628,
6257,
401,
5377,
628,
20,
69,
18,
65,
17,
5470,
13,
1355,
3624,
13,
2417,
825,
13,
31980,
70,
13,
2466,
69,
27014,
645,
23,
70,
1876,
401,
288,
10532,
29,
797,
12,
4132,
29,
277,
14,
751,
9,
398,
3850,
2531,
7768,
14,
1462,
14,
15023,
1252,
835,
1062,
10532,
63,
835,
9,
339,
347,
511,
63,
2495,
63,
2580,
8,
277,
304,
267,
286,
275,
18003,
14,
1462,
14,
981,
8,
2502,
29,
277,
14,
751,
9,
267,
702,
286,
14,
2580,
1137,
2125,
267,
702,
1228,
8,
67,
14,
2580,
12,
7116,
9,
339,
347,
511,
63,
9291,
63,
1080,
8,
277,
304,
267,
286,
275,
18003,
14,
1462,
14,
362,
8,
2051,
29,
7736,
9,
267,
286,
14,
2502,
275,
291,
14,
751,
267,
3850,
2531,
67,
14,
9291,
63,
1080,
12,
488,
9,
267,
2762,
275,
286,
14,
10788,
14,
1459,
63,
513,
360,
344,
297,
6829,
29,
549,
9,
267,
286,
14,
2117,
342,
267,
3850,
2531,
67,
14,
9291,
63,
1080,
12,
18003,
14,
1875,
63,
1080,
8,
1580,
430,
339,
347,
511,
63,
264,
11902,
63,
3627,
8,
277,
304,
267,
408,
497,
11902,
7768,
83,
5847,
664,
730,
29,
2761,
1041,
267,
286,
275,
799,
11902,
7768,
14,
1462,
14,
981,
8,
2502,
29,
277,
14,
751,
9,
267,
3850,
2531,
67,
14,
466,
12,
30235,
14,
29374,
63,
907,
5378,
25518,
9,
339,
347,
511,
63,
409,
63,
10788,
8,
277,
304,
267,
21293,
275,
769,
8,
19654,
14,
1462,
14,
1459,
63,
513,
360,
344,
297,
6829,
29,
549,
430,
267,
286,
275,
18003,
14,
1462,
14,
981,
8,
2502,
29,
277,
14,
751,
9,
398,
327,
2670,
5518,
14,
267,
2196,
14,
11777,
8,
10788,
9,
267,
286,
14,
409,
63,
10788,
8,
10788,
9,
267,
3850,
2531,
362,
63,
10788,
8,
67,
395,
21293,
9,
267,
3850,
2531,
8240,
793,
63,
835,
8,
4393,
14,
4947,
14,
9732,
63,
2566,
63,
29374,
395,
822,
8,
10788,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
simone-campagna/sheru
|
packages/sheru/main.py
|
1
|
5020
|
# -*- coding: utf-8 -*-
#
# Copyright 2015 Simone Campagna
#
# 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.
#
__author__ = "Simone Campagna"
__all__ = [
'main',
]
import argparse
import traceback
import sys
from . import conf
from . import log
from .stream_printer import StreamPrinter
from .sheru_config import SheruConfig
def action_init(logger, printer):
from .action.init import init
sheru_config_file = conf.get_sheru_config_file()
init(sheru_config_file=sheru_config_file, logger=logger, printer=printer)
def do_action(action, logger, printer, **args):
sheru_config_file = conf.get_sheru_config_file()
sheru_config = SheruConfig(sheru_config_file)
if not 'sheru' in sheru_config:
logger.error("config file {!r} does not contain a valid sheru configuration".format(sheru_config_file))
return 2
sheru = sheru_config['sheru']
action(sheru=sheru, logger=logger, printer=printer, **args)
def action_list(logger, printer):
from .action.list import list_sheru
return do_action(list_sheru, logger=logger, printer=printer)
def action_show(logger, printer):
from .action.show import show_sheru
return do_action(show_sheru, logger=logger, printer=printer)
def action_load(logger, printer, profile):
from .action.load import load_profile
return do_action(load_profile, logger=logger, printer=printer, profile_name=profile)
def main(printer=StreamPrinter(sys.stdout), logger=None, argv=None):
if argv is None:
argv = sys.argv[1:]
if logger is None:
logger = log.get_default_logger()
default_sheru_directory = conf.get_sheru_directory()
default_sheru_config_file = conf.get_sheru_config_file()
common_parser = argparse.ArgumentParser(
add_help=False,
)
common_parser.add_argument("--dir", "-d",
dest="sheru_directory",
default=None,
help="set sheru home directory, containing sheru config files [{!r}]".format(default_sheru_directory))
common_parser.add_argument("--config", "-c",
dest="sheru_config_file",
default=None,
help="set sheru config file [{!r}]".format(default_sheru_config_file))
common_parser.add_argument("--verbose", "-v",
dest="verbose_level",
action="count",
default=0,
help="increase verbose level")
common_parser.add_argument("--dry-run", "-D",
default=False,
action="store_true",
help="dry run mode")
common_parser.add_argument("--trace", "-t",
default=False,
action="store_true",
help="trace errors")
common_parser.add_argument('--version',
action='version',
version='%(prog)s {}'.format(conf.VERSION),
help='show version and exit')
top_level_parser = argparse.ArgumentParser(
parents=[common_parser],
description="""\
Sheru - manage remote shell profiles
""",
)
subparsers = top_level_parser.add_subparsers()
init_parser = subparsers.add_parser("init",
parents=[common_parser],
description="init sheru rc dir")
init_parser.set_defaults(
action=action_init,
action_args=[])
show_parser = subparsers.add_parser("show",
parents=[common_parser],
description="show available profiles")
show_parser.set_defaults(
action=action_show,
action_args=[])
list_parser = subparsers.add_parser("list",
parents=[common_parser],
description="list available profiles")
list_parser.set_defaults(
action=action_list,
action_args=[])
load_parser = subparsers.add_parser("load",
parents=[common_parser],
description="load available profiles")
load_parser.set_defaults(
action=action_load,
action_args=["profile"])
load_parser.add_argument("profile",
type=str,
help="profile name")
args = top_level_parser.parse_args(argv)
log.set_verbose_level(logger, args.verbose_level)
action = args.action
action_args = {arg_name: getattr(args, arg_name) for arg_name in args.action_args}
action_args['logger'] = logger
action_args['printer'] = printer
conf.setup(
sheru_directory=args.sheru_directory,
sheru_config_file=args.sheru_config_file)
try:
action(**action_args)
except Exception as err:
if args.trace:
traceback.print_exc()
logger.error("{}: {}\n".format(type(err).__name__, err))
return 3
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6900,
10751,
368,
24569,
643,
3540,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
363,
2502,
363,
275,
298,
7467,
368,
24569,
643,
3540,
2,
199,
363,
452,
363,
275,
359,
272,
283,
973,
297,
199,
61,
199,
199,
646,
7534,
199,
646,
5190,
199,
646,
984,
199,
199,
504,
1275,
492,
3743,
199,
504,
1275,
492,
943,
199,
504,
1275,
1745,
63,
11835,
492,
8271,
14131,
199,
504,
1275,
609,
281,
85,
63,
888,
492,
428,
2523,
85,
2028,
199,
199,
318,
1595,
63,
826,
8,
2921,
12,
16639,
304,
272,
687,
1275,
1287,
14,
826,
492,
4205,
272,
1033,
281,
85,
63,
888,
63,
493,
275,
3743,
14,
362,
63,
609,
281,
85,
63,
888,
63,
493,
342,
272,
4205,
8,
609,
281,
85,
63,
888,
63,
493,
29,
609,
281,
85,
63,
888,
63,
493,
12,
2512,
29,
2921,
12,
16639,
29,
11835,
9,
199,
199,
318,
886,
63,
1287,
8,
1287,
12,
2512,
12,
16639,
12,
1011,
589,
304,
272,
1033,
281,
85,
63,
888,
63,
493,
275,
3743,
14,
362,
63,
609,
281,
85,
63,
888,
63,
493,
342,
272,
1033,
281,
85,
63,
888,
275,
428,
2523,
85,
2028,
8,
609,
281,
85,
63,
888,
63,
493,
9,
272,
340,
440,
283,
609,
281,
85,
7,
315,
1033,
281,
85,
63,
888,
26,
267,
2512,
14,
705,
480,
888,
570,
18776,
82,
93,
1630,
440,
1395,
282,
1686,
1033,
281,
85,
2897,
1674,
908,
8,
609,
281,
85,
63,
888,
63,
493,
430,
267,
372,
499,
272,
1033,
281,
85,
275,
1033,
281,
85,
63,
888,
459,
609,
281,
85,
418,
272,
1595,
8,
609,
281,
85,
29,
609,
281,
85,
12,
2512,
29,
2921,
12,
16639,
29,
11835,
12,
1011,
589,
9,
1362,
199,
318,
1595,
63,
513,
8,
2921,
12,
16639,
304,
272,
687,
1275,
1287,
14,
513,
492,
769,
63,
609,
281,
85,
272,
372,
886,
63,
1287,
8,
513,
63,
609,
281,
85,
12,
2512,
29,
2921,
12,
16639,
29,
11835,
9,
199,
199,
318,
1595,
63,
2384,
8,
2921,
12,
16639,
304,
272,
687,
1275,
1287,
14,
2384,
492,
2498,
63,
609,
281,
85,
272,
372,
886,
63,
1287,
8,
2384,
63,
609,
281,
85,
12,
2512,
29,
2921,
12,
16639,
29,
11835,
9,
199,
199,
318,
1595,
63,
912,
8,
2921,
12,
16639,
12,
4690,
304,
272,
687,
1275,
1287,
14,
912,
492,
2248,
63,
2913,
272,
372,
886,
63,
1287,
8,
912,
63,
2913,
12,
2512,
29,
2921,
12,
16639,
29,
11835,
12,
4690,
63,
354,
29,
2913,
9,
199,
199,
318,
2446,
8,
11835,
29,
3296,
14131,
8,
1274,
14,
2703,
395,
2512,
29,
403,
12,
9238,
29,
403,
304,
272,
340,
9238,
365,
488,
26,
267,
9238,
275,
984,
14,
3020,
59,
17,
2938,
272,
340,
2512,
365,
488,
26,
267,
2512,
275,
943,
14,
362,
63,
885,
63,
2921,
342,
339,
849,
63,
609,
281,
85,
63,
3619,
275,
3743,
14,
362,
63,
609,
281,
85,
63,
3619,
342,
272,
849,
63,
609,
281,
85,
63,
888,
63,
493,
275,
3743,
14,
362,
63,
609,
281,
85,
63,
888,
63,
493,
342,
339,
2863,
63,
2087,
275,
7534,
14,
10730,
8,
267,
1050,
63,
3437,
29,
797,
12,
272,
776,
339,
2863,
63,
2087,
14,
525,
63,
2094,
6739,
694,
401,
3905,
68,
401,
267,
2053,
628,
609,
281,
85,
63,
3619,
401,
267,
849,
29,
403,
12,
267,
1720,
628,
409,
1033,
281,
85,
5629,
2082,
12,
3035,
1033,
281,
85,
1101,
1584,
8910,
1,
82,
11049,
1674,
908,
8,
885,
63,
609,
281,
85,
63,
3619,
430,
339,
2863,
63,
2087,
14,
525,
63,
2094,
6739,
888,
401,
3905,
67,
401,
267,
2053,
628,
609,
281,
85,
63,
888,
63,
493,
401,
267,
849,
29,
403,
12,
267,
1720,
628,
409,
1033,
281,
85,
1101,
570,
8910,
1,
82,
11049,
1674,
908,
8,
885,
63,
609,
281,
85,
63,
888,
63,
493,
430,
339,
2863,
63,
2087,
14,
525,
63,
2094,
6739,
3832,
401,
3905,
86,
401,
267,
2053,
628,
3832,
63,
1896,
401,
267,
1595,
628,
835,
401,
267,
849,
29,
16,
12,
267,
1720,
628,
31687,
3376,
2166,
531,
339,
2863,
63,
2087,
14,
525,
63,
2094,
6739,
10481,
13,
1065,
401,
3905,
36,
401,
267,
849,
29,
797,
12,
267,
1595,
628,
1617,
63,
2052,
401,
267,
1720,
628,
10481,
1255,
818,
531,
339,
2863,
63,
2087,
14,
525,
63,
2094,
6739,
3446,
401,
3905,
84,
401,
267,
849,
29,
797,
12,
267,
1595,
628,
1617,
63,
2052,
401,
267,
1720,
628,
3446,
2552,
531,
339,
2863,
63,
2087,
14,
525,
63,
2094,
4517,
1023,
297,
267,
1595,
534,
1023,
297,
267,
1015,
29342,
6595,
9,
83,
9499,
908,
8,
2190,
14,
4612,
395,
267,
1720,
534,
2384,
1015,
436,
4458,
358,
339,
2746,
63,
1896,
63,
2087,
275,
7534,
14,
10730,
8,
267,
8623,
1524,
2330,
63,
2087,
467,
267,
1369,
11916,
60,
199,
51,
2523,
85,
446,
9635,
3982,
5218,
17390,
199,
7208,
272,
776,
339,
26763,
275,
2746,
63,
1896,
63,
2087,
14,
525,
63,
954,
11531,
342,
339,
4205,
63,
2087,
275,
26763,
14,
525,
63,
2087,
480,
826,
401,
267,
8623,
1524,
2330,
63,
2087,
467,
267,
1369,
628,
826,
1033,
281,
85,
4819,
2935,
531,
272,
4205,
63,
2087,
14,
409,
63,
4322,
8,
267,
1595,
29
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6900,
10751,
368,
24569,
643,
3540,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
363,
2502,
363,
275,
298,
7467,
368,
24569,
643,
3540,
2,
199,
363,
452,
363,
275,
359,
272,
283,
973,
297,
199,
61,
199,
199,
646,
7534,
199,
646,
5190,
199,
646,
984,
199,
199,
504,
1275,
492,
3743,
199,
504,
1275,
492,
943,
199,
504,
1275,
1745,
63,
11835,
492,
8271,
14131,
199,
504,
1275,
609,
281,
85,
63,
888,
492,
428,
2523,
85,
2028,
199,
199,
318,
1595,
63,
826,
8,
2921,
12,
16639,
304,
272,
687,
1275,
1287,
14,
826,
492,
4205,
272,
1033,
281,
85,
63,
888,
63,
493,
275,
3743,
14,
362,
63,
609,
281,
85,
63,
888,
63,
493,
342,
272,
4205,
8,
609,
281,
85,
63,
888,
63,
493,
29,
609,
281,
85,
63,
888,
63,
493,
12,
2512,
29,
2921,
12,
16639,
29,
11835,
9,
199,
199,
318,
886,
63,
1287,
8,
1287,
12,
2512,
12,
16639,
12,
1011,
589,
304,
272,
1033,
281,
85,
63,
888,
63,
493,
275,
3743,
14,
362,
63,
609,
281,
85,
63,
888,
63,
493,
342,
272,
1033,
281,
85,
63,
888,
275,
428,
2523,
85,
2028,
8,
609,
281,
85,
63,
888,
63,
493,
9,
272,
340,
440,
283,
609,
281,
85,
7,
315,
1033,
281,
85,
63,
888,
26,
267,
2512,
14,
705,
480,
888,
570,
18776,
82,
93,
1630,
440,
1395,
282,
1686,
1033,
281,
85,
2897,
1674,
908,
8,
609,
281,
85,
63,
888,
63,
493,
430,
267,
372,
499,
272,
1033,
281,
85,
275,
1033,
281,
85,
63,
888,
459,
609,
281,
85,
418,
272,
1595,
8,
609,
281,
85,
29,
609,
281,
85,
12,
2512,
29,
2921,
12,
16639,
29,
11835,
12,
1011,
589,
9,
1362,
199,
318,
1595,
63,
513,
8,
2921,
12,
16639,
304,
272,
687,
1275,
1287,
14,
513,
492,
769,
63,
609,
281,
85,
272,
372,
886,
63,
1287,
8,
513,
63,
609,
281,
85,
12,
2512,
29,
2921,
12,
16639,
29,
11835,
9,
199,
199,
318,
1595,
63,
2384,
8,
2921,
12,
16639,
304,
272,
687,
1275,
1287,
14,
2384,
492,
2498,
63,
609,
281,
85,
272,
372,
886,
63,
1287,
8,
2384,
63,
609,
281,
85,
12,
2512,
29,
2921,
12,
16639,
29,
11835,
9,
199,
199,
318,
1595,
63,
912,
8,
2921,
12,
16639,
12,
4690,
304,
272,
687,
1275,
1287,
14,
912,
492,
2248,
63,
2913,
272,
372,
886,
63,
1287,
8,
912,
63,
2913,
12,
2512,
29,
2921,
12,
16639,
29,
11835,
12,
4690,
63,
354,
29,
2913,
9,
199,
199,
318,
2446,
8,
11835,
29,
3296,
14131,
8,
1274,
14,
2703,
395,
2512,
29,
403,
12,
9238,
29,
403,
304,
272,
340,
9238,
365,
488,
26,
267,
9238,
275,
984,
14,
3020,
59,
17,
2938,
272,
340,
2512,
365,
488,
26,
267,
2512,
275,
943,
14,
362,
63,
885,
63,
2921,
342,
339,
849,
63,
609,
281,
85,
63,
3619,
275,
3743,
14,
362,
63,
609,
281,
85,
63,
3619,
342,
272,
849,
63,
609,
281,
85,
63,
888,
63,
493,
275,
3743,
14,
362,
63,
609,
281,
85,
63,
888,
63,
493,
342,
339,
2863,
63,
2087,
275,
7534,
14,
10730,
8,
267,
1050,
63,
3437,
29,
797,
12,
272,
776,
339,
2863,
63,
2087,
14,
525,
63,
2094,
6739,
694,
401,
3905,
68,
401,
267,
2053,
628,
609,
281,
85,
63,
3619,
401,
267,
849,
29,
403,
12,
267,
1720,
628,
409,
1033,
281,
85,
5629,
2082,
12,
3035,
1033,
281,
85,
1101,
1584,
8910,
1,
82,
11049,
1674,
908,
8,
885,
63,
609,
281,
85,
63,
3619,
430,
339,
2863,
63,
2087,
14,
525,
63,
2094,
6739,
888,
401,
3905,
67,
401,
267,
2053,
628,
609,
281,
85,
63,
888,
63,
493,
401,
267,
849,
29,
403,
12,
267,
1720,
628,
409,
1033,
281,
85,
1101,
570,
8910,
1,
82,
11049,
1674,
908,
8,
885,
63,
609,
281,
85,
63,
888,
63,
493,
430,
339,
2863,
63,
2087,
14,
525,
63,
2094,
6739,
3832,
401,
3905,
86,
401,
267,
2053,
628,
3832,
63,
1896,
401,
267,
1595,
628,
835,
401,
267,
849,
29,
16,
12,
267,
1720,
628,
31687,
3376,
2166,
531,
339,
2863,
63,
2087,
14,
525,
63,
2094,
6739,
10481,
13,
1065,
401,
3905,
36,
401,
267,
849,
29,
797,
12,
267,
1595,
628,
1617,
63,
2052,
401,
267,
1720,
628,
10481,
1255,
818,
531,
339,
2863,
63,
2087,
14,
525,
63,
2094,
6739,
3446,
401,
3905,
84,
401,
267,
849,
29,
797,
12,
267,
1595,
628,
1617,
63,
2052,
401,
267,
1720,
628,
3446,
2552,
531,
339,
2863,
63,
2087,
14,
525,
63,
2094,
4517,
1023,
297,
267,
1595,
534,
1023,
297,
267,
1015,
29342,
6595,
9,
83,
9499,
908,
8,
2190,
14,
4612,
395,
267,
1720,
534,
2384,
1015,
436,
4458,
358,
339,
2746,
63,
1896,
63,
2087,
275,
7534,
14,
10730,
8,
267,
8623,
1524,
2330,
63,
2087,
467,
267,
1369,
11916,
60,
199,
51,
2523,
85,
446,
9635,
3982,
5218,
17390,
199,
7208,
272,
776,
339,
26763,
275,
2746,
63,
1896,
63,
2087,
14,
525,
63,
954,
11531,
342,
339,
4205,
63,
2087,
275,
26763,
14,
525,
63,
2087,
480,
826,
401,
267,
8623,
1524,
2330,
63,
2087,
467,
267,
1369,
628,
826,
1033,
281,
85,
4819,
2935,
531,
272,
4205,
63,
2087,
14,
409,
63,
4322,
8,
267,
1595,
29,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
msabramo/ansible
|
lib/ansible/modules/network/iosxr/iosxr_command.py
|
15
|
7240
|
#!/usr/bin/python
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'core'}
DOCUMENTATION = """
---
module: iosxr_command
version_added: "2.1"
author: "Ricardo Carrillo Cruz (@rcarrillocruz)"
short_description: Run commands on remote devices running Cisco iosxr
description:
- Sends arbitrary commands to an iosxr node and returns the results
read from the device. This module includes an
argument that will cause the module to wait for a specific condition
before returning or timing out if the condition is not met.
- This module does not support running commands in configuration mode.
Please use M(iosxr_config) to configure iosxr devices.
extends_documentation_fragment: iosxr
options:
commands:
description:
- List of commands to send to the remote iosxr device over the
configured provider. The resulting output from the command
is returned. If the I(wait_for) argument is provided, the
module is not returned until the condition is satisfied or
the number of retries has expired.
required: true
wait_for:
description:
- List of conditions to evaluate against the output of the
command. The task will wait for each condition to be true
before moving forward. If the conditional is not true
within the configured number of retries, the task fails.
See examples.
required: false
default: null
aliases: ['waitfor']
version_added: "2.2"
match:
description:
- The I(match) argument is used in conjunction with the
I(wait_for) argument to specify the match policy. Valid
values are C(all) or C(any). If the value is set to C(all)
then all conditionals in the wait_for must be satisfied. If
the value is set to C(any) then only one of the values must be
satisfied.
required: false
default: all
choices: ['any', 'all']
version_added: "2.2"
retries:
description:
- Specifies the number of retries a command should by tried
before it is considered failed. The command is run on the
target device every retry and evaluated against the
I(wait_for) conditions.
required: false
default: 10
interval:
description:
- Configures the interval in seconds to wait between retries
of the command. If the command does not pass the specified
conditions, the interval indicates how long to wait before
trying the command again.
required: false
default: 1
"""
EXAMPLES = """
tasks:
- name: run show version on remote devices
iosxr_command:
commands: show version
- name: run show version and check to see if output contains iosxr
iosxr_command:
commands: show version
wait_for: result[0] contains IOS-XR
- name: run multiple commands on remote nodes
iosxr_command:
commands:
- show version
- show interfaces
- name: run multiple commands and evaluate the output
iosxr_command:
commands:
- show version
- show interfaces
wait_for:
- result[0] contains IOS-XR
- result[1] contains Loopback0
"""
RETURN = """
stdout:
description: The set of responses from the commands
returned: always
type: list
sample: ['...', '...']
stdout_lines:
description: The value of stdout split into a list
returned: always
type: list
sample: [['...', '...'], ['...'], ['...']]
failed_conditions:
description: The list of conditionals that have failed
returned: failed
type: list
sample: ['...', '...']
"""
import time
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.iosxr import run_commands
from ansible.module_utils.network_common import ComplexList
from ansible.module_utils.netcli import Conditional
from ansible.module_utils.six import string_types
from ansible.module_utils.iosxr import iosxr_argument_spec, check_args
def to_lines(stdout):
for item in stdout:
if isinstance(item, string_types):
item = str(item).split('\n')
yield item
def parse_commands(module, warnings):
command = ComplexList(dict(
command=dict(key=True),
prompt=dict(),
answer=dict()
), module)
commands = command(module.params['commands'])
for index, item in enumerate(commands):
if module.check_mode and not item['command'].startswith('show'):
warnings.append(
'only show commands are supported when using check mode, not '
'executing `%s`' % item['command']
)
elif item['command'].startswith('conf'):
module.fail_json(
msg='iosxr_command does not support running config mode '
'commands. Please use iosxr_config instead'
)
commands[index] = module.jsonify(item)
return commands
def main():
spec = dict(
commands=dict(type='list', required=True),
wait_for=dict(type='list', aliases=['waitfor']),
match=dict(default='all', choices=['all', 'any']),
retries=dict(default=10, type='int'),
interval=dict(default=1, type='int')
)
spec.update(iosxr_argument_spec)
module = AnsibleModule(argument_spec=spec,
supports_check_mode=True)
warnings = list()
check_args(module, warnings)
commands = parse_commands(module, warnings)
wait_for = module.params['wait_for'] or list()
conditionals = [Conditional(c) for c in wait_for]
retries = module.params['retries']
interval = module.params['interval']
match = module.params['match']
while retries > 0:
responses = run_commands(module, commands)
for item in list(conditionals):
if item(responses):
if match == 'any':
conditionals = list()
break
conditionals.remove(item)
if not conditionals:
break
time.sleep(interval)
retries -= 1
if conditionals:
failed_conditions = [item.raw for item in conditionals]
msg = 'One or more conditional statements have not be satisfied'
module.fail_json(msg=msg, failed_conditions=failed_conditions)
result = {
'changed': False,
'stdout': responses,
'warnings': warnings,
'stdout_lines': list(to_lines(responses))
}
module.exit_json(**result)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
1018,
936,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
29516,
15775,
63,
1531,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
2502,
26,
298,
50,
530,
1005,
79,
14243,
10363,
320,
445,
6558,
90,
8593,
1195,
285,
10363,
320,
1556,
9494,
2924,
199,
3612,
63,
1802,
26,
3378,
3718,
641,
3982,
7256,
3879,
28356,
29516,
15775,
199,
1802,
26,
523,
446,
428,
3198,
9697,
3718,
370,
376,
29516,
15775,
1031,
436,
2529,
314,
2058,
272,
1586,
687,
314,
2243,
14,
961,
859,
6952,
376,
272,
1423,
626,
911,
7675,
314,
859,
370,
3618,
367,
282,
2488,
5558,
272,
2544,
8152,
503,
20542,
734,
340,
314,
5558,
365,
440,
7647,
14,
523,
446,
961,
859,
1630,
440,
2291,
3879,
3718,
315,
2897,
818,
14,
272,
7754,
675,
603,
8,
9207,
15775,
63,
888,
9,
370,
7908,
29516,
15775,
7256,
14,
199,
11036,
63,
9970,
63,
7677,
26,
29516,
15775,
199,
1419,
26,
523,
3718,
26,
272,
1369,
26,
489,
446,
3820,
402,
3718,
370,
3222,
370,
314,
3982,
29516,
15775,
2243,
1806,
314,
267,
7526,
5022,
14,
710,
9183,
1072,
687,
314,
1414,
267,
365,
2138,
14,
982,
314,
473,
8,
2573,
63,
509,
9,
1423,
365,
2741,
12,
314,
267,
859,
365,
440,
2138,
5133,
314,
5558,
365,
23233,
503,
267,
314,
1329,
402,
10086,
965,
14721,
14,
272,
1415,
26,
2549,
523,
3618,
63,
509,
26,
272,
1369,
26,
489,
446,
3820,
402,
3704,
370,
9352,
6169,
314,
1072,
402,
314,
267,
1414,
14,
710,
2120,
911,
3618,
367,
1924,
5558,
370,
506,
2549,
267,
2544,
12876,
7568,
14,
982,
314,
12303,
365,
440,
2549,
267,
4453,
314,
7526,
1329,
402,
10086,
12,
314,
2120,
6918,
14,
267,
1666,
7251,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
5481,
26,
788,
2573,
509,
418,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
523,
1336,
26,
272,
1369,
26,
489,
446,
710,
473,
8,
1431,
9,
1423,
365,
1202,
315,
22888,
543,
314,
267,
473,
8,
2573,
63,
509,
9,
1423,
370,
4165,
314,
1336,
4592,
14,
221,
4821,
267,
1338,
787,
445,
8,
452,
9,
503,
445,
8,
1629,
680,
221,
982,
314,
574,
365,
663,
370,
445,
8,
452,
9,
267,
2066,
1006,
29265,
315,
314,
3618,
63,
509,
1471,
506,
23233,
14,
221,
982,
267,
314,
574,
365,
663,
370,
445,
8,
1629,
9,
2066,
1454,
1373,
402,
314,
1338,
1471,
506,
267,
23233,
14,
272,
1415,
26,
3055,
272,
849,
26,
1006,
272,
3415,
26,
788,
1629,
297,
283,
452,
418,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
523,
10086,
26,
272,
1369,
26,
489,
446,
11015,
314,
1329,
402,
10086,
282,
1414,
1077,
701,
16416,
267,
2544,
652,
365,
8652,
3405,
14,
710,
1414,
365,
1255,
641,
314,
267,
1347,
2243,
4036,
7269,
436,
13006,
6169,
314,
267,
473,
8,
2573,
63,
509,
9,
3704,
14,
272,
1415,
26,
3055,
272,
849,
26,
1616,
523,
6252,
26,
272,
1369,
26,
489,
446,
4094,
1482,
314,
6252,
315,
4696,
370,
3618,
3382,
10086,
267,
402,
314,
1414,
14,
982,
314,
1414,
1630,
440,
986,
314,
2013,
267,
3704,
12,
314,
6252,
9126,
4212,
1846,
370,
3618,
2544,
267,
9936,
314,
1414,
4020,
14,
272,
1415,
26,
3055,
272,
849,
26,
413,
199,
624,
199,
199,
8918,
275,
408,
199,
5054,
26,
523,
446,
536,
26,
1255,
2498,
1015,
641,
3982,
7256,
272,
29516,
15775,
63,
1531,
26,
489,
3718,
26,
2498,
1015,
819,
446,
536,
26,
1255,
2498,
1015,
436,
1104,
370,
1937,
340,
1072,
3509,
29516,
15775,
272,
29516,
15775,
63,
1531,
26,
489,
3718,
26,
2498,
1015,
489,
3618,
63,
509,
26,
754,
59,
16,
61,
3509,
473,
3100,
13,
12297,
819,
446,
536,
26,
1255,
3663,
3718,
641,
3982,
3380,
272,
29516,
15775,
63,
1531,
26,
489,
3718,
26,
267,
446,
2498,
1015,
267,
446,
2498,
8386,
819,
446,
536,
26,
1255,
3663,
3718,
436,
9352,
314,
1072,
272,
29516,
15775,
63,
1531,
26,
489,
3718,
26,
267,
446,
2498,
1015,
267,
446,
2498,
8386,
489,
3618,
63,
509,
26,
267,
446,
754,
59,
16,
61,
3509,
473,
3100,
13,
12297,
267,
446,
754,
59,
17,
61,
3509,
18175,
894,
16,
199,
624,
199,
199,
9677,
275,
408,
199,
2703,
26,
523,
1369,
26,
710,
663,
402,
9320,
687,
314,
3718,
523,
2138,
26,
3544,
523,
730,
26,
769,
523,
2690,
26,
788,
20833,
24352,
418,
199,
2703,
63,
1278,
26,
523,
1369,
26,
710,
574,
402,
3839,
3715,
1901,
282,
769,
523,
2138,
26,
3544,
523,
730,
26,
769,
523,
2690,
26,
11194,
20833,
24352,
995,
788,
1396,
995,
788,
1396,
6538,
199,
4892,
63,
9855,
26,
523,
1369,
26,
710,
769,
402,
29265,
626,
1172,
3405,
523,
2138,
26,
3405,
523,
730,
26,
769,
523,
2690,
26,
788,
20833,
24352,
418,
199,
624,
199,
646,
900,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
1018,
936,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
29516,
15775,
63,
1531,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
2502,
26,
298,
50,
530,
1005,
79,
14243,
10363,
320,
445,
6558,
90,
8593,
1195,
285,
10363,
320,
1556,
9494,
2924,
199,
3612,
63,
1802,
26,
3378,
3718,
641,
3982,
7256,
3879,
28356,
29516,
15775,
199,
1802,
26,
523,
446,
428,
3198,
9697,
3718,
370,
376,
29516,
15775,
1031,
436,
2529,
314,
2058,
272,
1586,
687,
314,
2243,
14,
961,
859,
6952,
376,
272,
1423,
626,
911,
7675,
314,
859,
370,
3618,
367,
282,
2488,
5558,
272,
2544,
8152,
503,
20542,
734,
340,
314,
5558,
365,
440,
7647,
14,
523,
446,
961,
859,
1630,
440,
2291,
3879,
3718,
315,
2897,
818,
14,
272,
7754,
675,
603,
8,
9207,
15775,
63,
888,
9,
370,
7908,
29516,
15775,
7256,
14,
199,
11036,
63,
9970,
63,
7677,
26,
29516,
15775,
199,
1419,
26,
523,
3718,
26,
272,
1369,
26,
489,
446,
3820,
402,
3718,
370,
3222,
370,
314,
3982,
29516,
15775,
2243,
1806,
314,
267,
7526,
5022,
14,
710,
9183,
1072,
687,
314,
1414,
267,
365,
2138,
14,
982,
314,
473,
8,
2573,
63,
509,
9,
1423,
365,
2741,
12,
314,
267,
859,
365,
440,
2138,
5133,
314,
5558,
365,
23233,
503,
267,
314,
1329,
402,
10086,
965,
14721,
14,
272,
1415,
26,
2549,
523,
3618,
63,
509,
26,
272,
1369,
26,
489,
446,
3820,
402,
3704,
370,
9352,
6169,
314,
1072,
402,
314,
267,
1414,
14,
710,
2120,
911,
3618,
367,
1924,
5558,
370,
506,
2549,
267,
2544,
12876,
7568,
14,
982,
314,
12303,
365,
440,
2549,
267,
4453,
314,
7526,
1329,
402,
10086,
12,
314,
2120,
6918,
14,
267,
1666,
7251,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
5481,
26,
788,
2573,
509,
418,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
523,
1336,
26,
272,
1369,
26,
489,
446,
710,
473,
8,
1431,
9,
1423,
365,
1202,
315,
22888,
543,
314,
267,
473,
8,
2573,
63,
509,
9,
1423,
370,
4165,
314,
1336,
4592,
14,
221,
4821,
267,
1338,
787,
445,
8,
452,
9,
503,
445,
8,
1629,
680,
221,
982,
314,
574,
365,
663,
370,
445,
8,
452,
9,
267,
2066,
1006,
29265,
315,
314,
3618,
63,
509,
1471,
506,
23233,
14,
221,
982,
267,
314,
574,
365,
663,
370,
445,
8,
1629,
9,
2066,
1454,
1373,
402,
314,
1338,
1471,
506,
267,
23233,
14,
272,
1415,
26,
3055,
272,
849,
26,
1006,
272,
3415,
26,
788,
1629,
297,
283,
452,
418,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
523,
10086,
26,
272,
1369,
26,
489,
446,
11015,
314,
1329,
402,
10086,
282,
1414,
1077,
701,
16416,
267,
2544,
652,
365,
8652,
3405,
14,
710,
1414,
365,
1255,
641,
314,
267,
1347,
2243,
4036,
7269,
436,
13006,
6169,
314,
267,
473,
8,
2573,
63,
509,
9,
3704,
14,
272,
1415,
26,
3055,
272,
849,
26,
1616,
523,
6252,
26,
272,
1369,
26,
489,
446,
4094,
1482,
314,
6252,
315,
4696,
370,
3618,
3382,
10086,
267,
402,
314,
1414,
14,
982,
314,
1414,
1630,
440,
986,
314,
2013,
267,
3704,
12,
314,
6252,
9126,
4212,
1846,
370,
3618,
2544,
267,
9936,
314,
1414,
4020,
14,
272,
1415,
26,
3055,
272,
849,
26,
413,
199,
624,
199,
199,
8918,
275,
408,
199,
5054,
26,
523,
446,
536,
26,
1255,
2498,
1015,
641,
3982,
7256,
272,
29516,
15775,
63,
1531,
26,
489,
3718,
26,
2498,
1015,
819,
446,
536,
26,
1255,
2498,
1015,
436,
1104,
370,
1937,
340,
1072,
3509,
29516,
15775,
272,
29516,
15775,
63,
1531,
26,
489,
3718,
26,
2498,
1015,
489,
3618,
63,
509,
26,
754,
59,
16,
61,
3509,
473,
3100,
13,
12297,
819,
446,
536,
26,
1255,
3663,
3718,
641,
3982,
3380,
272,
29516,
15775,
63,
1531,
26,
489,
3718,
26,
267,
446,
2498,
1015,
267,
446,
2498,
8386,
819,
446,
536,
26,
1255,
3663,
3718,
436,
9352,
314,
1072,
272,
29516,
15775,
63,
1531,
26,
489,
3718,
26,
267,
446,
2498,
1015,
267,
446,
2498,
8386,
489,
3618,
63,
509,
26,
267,
446,
754,
59,
16,
61,
3509,
473,
3100,
13,
12297,
267,
446,
754,
59,
17,
61,
3509,
18175,
894,
16,
199,
624,
199,
199,
9677,
275,
408,
199,
2703,
26,
523,
1369,
26,
710,
663,
402,
9320,
687,
314,
3718,
523,
2138,
26,
3544,
523,
730,
26,
769,
523,
2690,
26,
788,
20833,
24352,
418,
199,
2703,
63,
1278,
26,
523,
1369,
26,
710,
574,
402,
3839,
3715,
1901,
282,
769,
523,
2138,
26,
3544,
523,
730,
26,
769,
523,
2690,
26,
11194,
20833,
24352,
995,
788,
1396,
995,
788,
1396,
6538,
199,
4892,
63,
9855,
26,
523,
1369,
26,
710,
769,
402,
29265,
626,
1172,
3405,
523,
2138,
26,
3405,
523,
730,
26,
769,
523,
2690,
26,
788,
20833,
24352,
418,
199,
624,
199,
646,
900,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
gangadhar-kadam/helpdesk-erpnext
|
erpnext/patches/v5_4/notify_system_managers_regarding_wrong_tax_calculation.py
|
45
|
1433
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.email import sendmail_to_system_managers
from frappe.utils import get_link_to_form
def execute():
wrong_records = []
for dt in ("Quotation", "Sales Order", "Delivery Note", "Sales Invoice",
"Purchase Order", "Purchase Receipt", "Purchase Invoice"):
records = frappe.db.sql_list("""select name from `tab{0}`
where apply_discount_on = 'Net Total' and ifnull(discount_amount, 0) != 0
and modified >= '2015-02-17' and docstatus=1""".format(dt))
if records:
records = [get_link_to_form(dt, d) for d in records]
wrong_records.append([dt, records])
if wrong_records:
content = """Dear System Manager,
Due to an error related to Discount Amount on Net Total, tax calculation might be wrong in the following records. We did not fix the tax amount automatically because it can corrupt the entries, so we request you to check these records and amend if you found the calculation wrong.
Please check following Entries:
%s
Regards,
Administrator""" % "\n".join([(d[0] + ": " + ", ".join(d[1])) for d in wrong_records])
try:
sendmail_to_system_managers("[Important] [ERPNext] Tax calculation might be wrong, please check.", content)
except:
pass
print "="*50
print content
print "="*50
|
agpl-3.0
|
[
3,
1898,
334,
67,
9,
6171,
12,
6001,
8144,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
504,
6950,
14,
2123,
492,
3222,
1198,
63,
475,
63,
2253,
63,
16259,
199,
504,
6950,
14,
1208,
492,
664,
63,
1073,
63,
475,
63,
964,
199,
199,
318,
5341,
837,
199,
198,
10603,
63,
6502,
275,
942,
199,
198,
509,
4487,
315,
1689,
2371,
357,
425,
401,
298,
18220,
9240,
401,
298,
24640,
3390,
401,
298,
18220,
19868,
401,
11083,
198,
2,
20486,
9240,
401,
298,
20486,
799,
13866,
401,
298,
20486,
19868,
2349,
686,
198,
6502,
275,
6950,
14,
697,
14,
3009,
63,
513,
4852,
2416,
536,
687,
658,
2902,
91,
16,
23485,
28932,
198,
4509,
4838,
63,
15446,
63,
265,
275,
283,
2480,
19271,
7,
436,
340,
2307,
8,
15446,
63,
4606,
12,
378,
9,
1137,
378,
1585,
198,
460,
6042,
2356,
283,
7806,
13,
996,
13,
1196,
7,
436,
1382,
1205,
29,
17,
23045,
908,
8,
3583,
430,
686,
686,
198,
692,
5767,
26,
1585,
198,
6502,
275,
359,
362,
63,
1073,
63,
475,
63,
964,
8,
3583,
12,
366,
9,
367,
366,
315,
5767,
61,
1585,
198,
10603,
63,
6502,
14,
740,
779,
3583,
12,
5767,
566,
1871,
199,
198,
692,
6835,
63,
6502,
26,
507,
198,
1317,
275,
408,
872,
285,
6187,
13537,
12,
199,
199,
36,
310,
370,
376,
1125,
4048,
370,
5289,
835,
26701,
641,
5365,
19271,
12,
9067,
15232,
5594,
506,
6835,
315,
314,
2569,
5767,
14,
2136,
8103,
440,
5325,
314,
9067,
5982,
5847,
2952,
652,
883,
29221,
314,
4811,
12,
880,
781,
1056,
1265,
370,
1104,
3520,
5767,
436,
282,
13419,
340,
1265,
1911,
314,
15232,
6835,
14,
199,
199,
8254,
1104,
2569,
23450,
1996,
26,
199,
199,
5,
83,
421,
199,
2872,
5596,
12,
199,
199,
31972,
624,
450,
1867,
78,
1674,
904,
7694,
68,
59,
16,
61,
435,
7244,
298,
435,
3872,
3680,
904,
8,
68,
59,
17,
2459,
367,
366,
315,
6835,
63,
6502,
566,
507,
198,
893,
26,
686,
198,
2254,
1198,
63,
475,
63,
2253,
63,
16259,
10994,
6295,
867,
61,
359,
6758,
5765,
61,
30174,
15232,
5594,
506,
6835,
12,
8749,
1104,
4765,
1564,
9,
507,
198,
2590,
26,
686,
198,
1529,
9068,
198,
1361,
22250,
10,
1400,
507,
198,
1361,
1564,
507,
198,
1361,
22250,
10,
1400,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
6171,
12,
6001,
8144,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
504,
6950,
14,
2123,
492,
3222,
1198,
63,
475,
63,
2253,
63,
16259,
199,
504,
6950,
14,
1208,
492,
664,
63,
1073,
63,
475,
63,
964,
199,
199,
318,
5341,
837,
199,
198,
10603,
63,
6502,
275,
942,
199,
198,
509,
4487,
315,
1689,
2371,
357,
425,
401,
298,
18220,
9240,
401,
298,
24640,
3390,
401,
298,
18220,
19868,
401,
11083,
198,
2,
20486,
9240,
401,
298,
20486,
799,
13866,
401,
298,
20486,
19868,
2349,
686,
198,
6502,
275,
6950,
14,
697,
14,
3009,
63,
513,
4852,
2416,
536,
687,
658,
2902,
91,
16,
23485,
28932,
198,
4509,
4838,
63,
15446,
63,
265,
275,
283,
2480,
19271,
7,
436,
340,
2307,
8,
15446,
63,
4606,
12,
378,
9,
1137,
378,
1585,
198,
460,
6042,
2356,
283,
7806,
13,
996,
13,
1196,
7,
436,
1382,
1205,
29,
17,
23045,
908,
8,
3583,
430,
686,
686,
198,
692,
5767,
26,
1585,
198,
6502,
275,
359,
362,
63,
1073,
63,
475,
63,
964,
8,
3583,
12,
366,
9,
367,
366,
315,
5767,
61,
1585,
198,
10603,
63,
6502,
14,
740,
779,
3583,
12,
5767,
566,
1871,
199,
198,
692,
6835,
63,
6502,
26,
507,
198,
1317,
275,
408,
872,
285,
6187,
13537,
12,
199,
199,
36,
310,
370,
376,
1125,
4048,
370,
5289,
835,
26701,
641,
5365,
19271,
12,
9067,
15232,
5594,
506,
6835,
315,
314,
2569,
5767,
14,
2136,
8103,
440,
5325,
314,
9067,
5982,
5847,
2952,
652,
883,
29221,
314,
4811,
12,
880,
781,
1056,
1265,
370,
1104,
3520,
5767,
436,
282,
13419,
340,
1265,
1911,
314,
15232,
6835,
14,
199,
199,
8254,
1104,
2569,
23450,
1996,
26,
199,
199,
5,
83,
421,
199,
2872,
5596,
12,
199,
199,
31972,
624,
450,
1867,
78,
1674,
904,
7694,
68,
59,
16,
61,
435,
7244,
298,
435,
3872,
3680,
904,
8,
68,
59,
17,
2459,
367,
366,
315,
6835,
63,
6502,
566,
507,
198,
893,
26,
686,
198,
2254,
1198,
63,
475,
63,
2253,
63,
16259,
10994,
6295,
867,
61,
359,
6758,
5765,
61,
30174,
15232,
5594,
506,
6835,
12,
8749,
1104,
4765,
1564,
9,
507,
198,
2590,
26,
686,
198,
1529,
9068,
198,
1361,
22250,
10,
1400,
507,
198,
1361,
1564,
507,
198,
1361,
22250,
10,
1400,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ilpianista/ansible
|
lib/ansible/module_utils/facts/namespace.py
|
172
|
2366
|
# This code is part of Ansible, but is an independent component.
# This particular file snippet, and this file snippet only, is BSD licensed.
# Modules you write using this snippet, which is embedded dynamically by Ansible
# still belong to the author of the module, and may assign their own license
# to the complete work.
#
# (c) 2017 Red Hat Inc.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
class FactNamespace:
def __init__(self, namespace_name):
self.namespace_name = namespace_name
def transform(self, name):
'''Take a text name, and transforms it as needed (add a namespace prefix, etc)'''
return name
def _underscore(self, name):
return name.replace('-', '_')
class PrefixFactNamespace(FactNamespace):
def __init__(self, namespace_name, prefix=None):
super(PrefixFactNamespace, self).__init__(namespace_name)
self.prefix = prefix
def transform(self, name):
new_name = self._underscore(name)
return '%s%s' % (self.prefix, new_name)
|
gpl-3.0
|
[
3,
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
2622,
199,
3,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
5705,
4190,
199,
3,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
334,
67,
9,
9708,
9572,
13002,
3277,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
420,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
421,
199,
533,
481,
2442,
8814,
26,
272,
347,
636,
826,
721,
277,
12,
3231,
63,
354,
304,
267,
291,
14,
3251,
63,
354,
275,
3231,
63,
354,
339,
347,
5793,
8,
277,
12,
536,
304,
267,
1449,
27200,
282,
1318,
536,
12,
436,
18501,
652,
465,
4346,
334,
525,
282,
3231,
2403,
12,
5423,
9,
2344,
267,
372,
536,
339,
347,
485,
21831,
8,
277,
12,
536,
304,
267,
372,
536,
14,
1814,
13858,
18962,
421,
199,
533,
25110,
24704,
8814,
8,
24704,
8814,
304,
272,
347,
636,
826,
721,
277,
12,
3231,
63,
354,
12,
2403,
29,
403,
304,
267,
1613,
8,
4793,
24704,
8814,
12,
291,
2843,
826,
721,
3251,
63,
354,
9,
267,
291,
14,
1861,
275,
2403,
339,
347,
5793,
8,
277,
12,
536,
304,
267,
892,
63,
354,
275,
291,
423,
21831,
8,
354,
9,
267,
372,
1543,
83,
5,
83,
7,
450,
334,
277,
14,
1861,
12,
892,
63,
354,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
2622,
199,
3,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
5705,
4190,
199,
3,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
334,
67,
9,
9708,
9572,
13002,
3277,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
420,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
421,
199,
533,
481,
2442,
8814,
26,
272,
347,
636,
826,
721,
277,
12,
3231,
63,
354,
304,
267,
291,
14,
3251,
63,
354,
275,
3231,
63,
354,
339,
347,
5793,
8,
277,
12,
536,
304,
267,
1449,
27200,
282,
1318,
536,
12,
436,
18501,
652,
465,
4346,
334,
525,
282,
3231,
2403,
12,
5423,
9,
2344,
267,
372,
536,
339,
347,
485,
21831,
8,
277,
12,
536,
304,
267,
372,
536,
14,
1814,
13858,
18962,
421,
199,
533,
25110,
24704,
8814,
8,
24704,
8814,
304,
272,
347,
636,
826,
721,
277,
12,
3231,
63,
354,
12,
2403,
29,
403,
304,
267,
1613,
8,
4793,
24704,
8814,
12,
291,
2843,
826,
721,
3251,
63,
354,
9,
267,
291,
14,
1861,
275,
2403,
339,
347,
5793,
8,
277,
12,
536,
304,
267,
892,
63,
354,
275,
291,
423,
21831,
8,
354,
9,
267,
372,
1543,
83,
5,
83,
7,
450,
334,
277,
14,
1861,
12,
892,
63,
354,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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py
|
201
|
6963
|
# -*- coding: utf-'8' "-*-"
import hashlib
import hmac
import logging
import time
import urlparse
from openerp import api, fields, models
from openerp.addons.payment.models.payment_acquirer import ValidationError
from openerp.addons.payment_authorize.controllers.main import AuthorizeController
from openerp.tools.float_utils import float_compare
_logger = logging.getLogger(__name__)
class PaymentAcquirerAuthorize(models.Model):
_inherit = 'payment.acquirer'
def _get_authorize_urls(self, environment):
""" Authorize URLs """
if environment == 'prod':
return {'authorize_form_url': 'https://secure.authorize.net/gateway/transact.dll'}
else:
return {'authorize_form_url': 'https://test.authorize.net/gateway/transact.dll'}
@api.model
def _get_providers(self):
providers = super(PaymentAcquirerAuthorize, self)._get_providers()
providers.append(['authorize', 'Authorize.Net'])
return providers
authorize_login = fields.Char(string='API Login Id', required_if_provider='authorize')
authorize_transaction_key = fields.Char(string='API Transaction Key', required_if_provider='authorize')
def _authorize_generate_hashing(self, values):
data = '^'.join([
values['x_login'],
values['x_fp_sequence'],
values['x_fp_timestamp'],
values['x_amount'],
values['x_currency_code']])
return hmac.new(str(values['x_trans_key']), data, hashlib.md5).hexdigest()
@api.multi
def authorize_form_generate_values(self, partner_values, tx_values):
self.ensure_one()
base_url = self.env['ir.config_parameter'].get_param('web.base.url')
authorize_tx_values = dict(tx_values)
temp_authorize_tx_values = {
'x_login': self.authorize_login,
'x_trans_key': self.authorize_transaction_key,
'x_amount': str(tx_values['amount']),
'x_show_form': 'PAYMENT_FORM',
'x_type': 'AUTH_CAPTURE',
'x_method': 'CC',
'x_fp_sequence': '%s%s' % (self.id, int(time.time())),
'x_version': '3.1',
'x_relay_response': 'TRUE',
'x_fp_timestamp': str(int(time.time())),
'x_relay_url': '%s' % urlparse.urljoin(base_url, AuthorizeController._return_url),
'x_cancel_url': '%s' % urlparse.urljoin(base_url, AuthorizeController._cancel_url),
'x_currency_code': tx_values['currency'] and tx_values['currency'].name or '',
'address': partner_values['address'],
'city': partner_values['city'],
'country': partner_values['country'] and partner_values['country'].name or '',
'email': partner_values['email'],
'zip': partner_values['zip'],
'first_name': partner_values['first_name'],
'last_name': partner_values['last_name'],
'phone': partner_values['phone'],
'state': partner_values.get('state') and partner_values['state'].name or '',
}
temp_authorize_tx_values['returndata'] = authorize_tx_values.pop('return_url', '')
temp_authorize_tx_values['x_fp_hash'] = self._authorize_generate_hashing(temp_authorize_tx_values)
authorize_tx_values.update(temp_authorize_tx_values)
return partner_values, authorize_tx_values
@api.multi
def authorize_get_form_action_url(self):
self.ensure_one()
return self._get_authorize_urls(self.environment)['authorize_form_url']
class TxAuthorize(models.Model):
_inherit = 'payment.transaction'
authorize_txnid = fields.Char(string='Transaction ID')
_authorize_valid_tx_status = 1
_authorize_pending_tx_status = 4
_authorize_cancel_tx_status = 2
# --------------------------------------------------
# FORM RELATED METHODS
# --------------------------------------------------
@api.model
def _authorize_form_get_tx_from_data(self, data):
""" Given a data dict coming from authorize, verify it and find the related
transaction record. """
reference, trans_id, fingerprint = data.get('x_invoice_num'), data.get('x_trans_id'), data.get('x_MD5_Hash')
if not reference or not trans_id or not fingerprint:
error_msg = 'Authorize: received data with missing reference (%s) or trans_id (%s) or fingerprint (%s)' % (reference, trans_id, fingerprint)
_logger.error(error_msg)
raise ValidationError(error_msg)
tx = self.search([('reference', '=', reference)])
if not tx or len(tx) > 1:
error_msg = 'Authorize: received data for reference %s' % (reference)
if not tx:
error_msg += '; no order found'
else:
error_msg += '; multiple order found'
_logger.error(error_msg)
raise ValidationError(error_msg)
return tx[0]
@api.model
def _authorize_form_get_invalid_parameters(self, tx, data):
invalid_parameters = []
if tx.authorize_txnid and data.get('x_trans_id') != tx.authorize_txnid:
invalid_parameters.append(('Transaction Id', data.get('x_trans_id'), tx.authorize_txnid))
# check what is buyed
if float_compare(float(data.get('x_amount', '0.0')), tx.amount, 2) != 0:
invalid_parameters.append(('Amount', data.get('x_amount'), '%.2f' % tx.amount))
return invalid_parameters
@api.model
def _authorize_form_validate(self, tx, data):
if tx.state == 'done':
_logger.warning('Authorize: trying to validate an already validated tx (ref %s)' % tx.reference)
return True
status_code = int(data.get('x_response_code', '0'))
if status_code == self._authorize_valid_tx_status:
tx.write({
'state': 'done',
'authorize_txnid': data.get('x_trans_id'),
'acquirer_reference': data['x_invoice_num'],
})
return True
elif status_code == self._authorize_pending_tx_status:
tx.write({
'state': 'pending',
'authorize_txnid': data.get('x_trans_id'),
'acquirer_reference': data['x_invoice_num'],
})
return True
elif status_code == self._authorize_cancel_tx_status:
tx.write({
'state': 'cancel',
'authorize_txnid': data.get('x_trans_id'),
'acquirer_reference': data['x_invoice_num'],
})
return True
else:
error = data.get('x_response_reason_text')
_logger.info(error)
tx.write({
'state': 'error',
'state_message': error,
'authorize_txnid': data.get('x_trans_id'),
'acquirer_reference': data['x_invoice_num'],
})
return False
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
15668,
24,
7,
3905,
1837,
2,
199,
199,
646,
8337,
199,
646,
20330,
199,
646,
2050,
199,
646,
900,
199,
646,
7097,
199,
199,
504,
5166,
492,
2986,
12,
1504,
12,
1709,
199,
504,
5166,
14,
10788,
14,
7948,
14,
992,
14,
7948,
63,
28729,
492,
8505,
199,
504,
5166,
14,
10788,
14,
7948,
63,
14204,
14,
20531,
14,
973,
492,
6529,
794,
7506,
199,
504,
5166,
14,
2537,
14,
1609,
63,
1208,
492,
2069,
63,
5785,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
25523,
1945,
2272,
82,
5949,
794,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
7948,
14,
28729,
7,
339,
347,
485,
362,
63,
14204,
63,
3603,
8,
277,
12,
3734,
304,
267,
408,
6529,
794,
10867,
408,
267,
340,
3734,
508,
283,
8788,
356,
288,
372,
791,
14204,
63,
964,
63,
633,
356,
283,
2859,
921,
7817,
14,
14204,
14,
846,
15,
7019,
15,
1515,
2442,
14,
9259,
936,
267,
587,
26,
288,
372,
791,
14204,
63,
964,
63,
633,
356,
283,
2859,
921,
396,
14,
14204,
14,
846,
15,
7019,
15,
1515,
2442,
14,
9259,
936,
339,
768,
1246,
14,
1238,
272,
347,
485,
362,
63,
9710,
8,
277,
304,
267,
18032,
275,
1613,
8,
22374,
1945,
2272,
82,
5949,
794,
12,
291,
10445,
362,
63,
9710,
342,
267,
18032,
14,
740,
2941,
14204,
297,
283,
5949,
794,
14,
2480,
1105,
267,
372,
18032,
339,
20210,
63,
2886,
275,
1504,
14,
1610,
8,
875,
534,
3735,
16430,
15418,
297,
1415,
63,
692,
63,
3780,
534,
14204,
358,
272,
20210,
63,
5945,
63,
498,
275,
1504,
14,
1610,
8,
875,
534,
3735,
18244,
2606,
297,
1415,
63,
692,
63,
3780,
534,
14204,
358,
339,
347,
485,
14204,
63,
4208,
63,
2227,
316,
8,
277,
12,
1338,
304,
267,
666,
275,
14452,
1370,
904,
779,
288,
1338,
459,
88,
63,
2886,
995,
288,
1338,
459,
88,
63,
3997,
63,
4041,
995,
288,
1338,
459,
88,
63,
3997,
63,
3954,
995,
288,
1338,
459,
88,
63,
4606,
995,
288,
1338,
459,
88,
63,
4968,
63,
600,
12121,
267,
372,
20330,
14,
1222,
8,
495,
8,
1459,
459,
88,
63,
1515,
63,
498,
3815,
666,
12,
8337,
14,
1064,
21,
680,
11453,
342,
339,
768,
1246,
14,
3029,
272,
347,
20210,
63,
964,
63,
4208,
63,
1459,
8,
277,
12,
5854,
63,
1459,
12,
4773,
63,
1459,
304,
267,
291,
14,
7505,
63,
368,
342,
267,
1300,
63,
633,
275,
291,
14,
1813,
459,
723,
14,
888,
63,
5329,
2278,
362,
63,
635,
360,
2520,
14,
1095,
14,
633,
358,
267,
20210,
63,
2347,
63,
1459,
275,
1211,
8,
2347,
63,
1459,
9,
267,
2388,
63,
14204,
63,
2347,
63,
1459,
275,
469,
288,
283,
88,
63,
2886,
356,
291,
14,
14204,
63,
2886,
12,
288,
283,
88,
63,
1515,
63,
498,
356,
291,
14,
14204,
63,
5945,
63,
498,
12,
288,
283,
88,
63,
4606,
356,
620,
8,
2347,
63,
1459,
459,
4606,
3815,
288,
283,
88,
63,
2384,
63,
964,
356,
283,
17698,
4479,
63,
3516,
297,
288,
283,
88,
63,
466,
356,
283,
5580,
63,
28342,
3942,
297,
288,
283,
88,
63,
765,
356,
283,
2571,
297,
288,
283,
88,
63,
3997,
63,
4041,
356,
1543,
83,
5,
83,
7,
450,
334,
277,
14,
344,
12,
1109,
8,
521,
14,
521,
22606,
288,
283,
88,
63,
1023,
356,
283,
19,
14,
17,
297,
288,
283,
88,
63,
21855,
63,
1310,
356,
283,
15064,
297,
288,
283,
88,
63,
3997,
63,
3954,
356,
620,
8,
442,
8,
521,
14,
521,
22606,
288,
283,
88,
63,
21855,
63,
633,
356,
1543,
83,
7,
450,
7097,
14,
17755,
8,
1095,
63,
633,
12,
6529,
794,
7506,
423,
1107,
63,
633,
395,
288,
283,
88,
63,
6406,
63,
633,
356,
1543,
83,
7,
450,
7097,
14,
17755,
8,
1095,
63,
633,
12,
6529,
794,
7506,
423,
6406,
63,
633,
395,
288,
283,
88,
63,
4968,
63,
600,
356,
4773,
63,
1459,
459,
4968,
418,
436,
4773,
63,
1459,
459,
4968,
2278,
354,
503,
3260,
288,
283,
1562,
356,
5854,
63,
1459,
459,
1562,
995,
288,
283,
3690,
356,
5854,
63,
1459,
459,
3690,
995,
288,
283,
6063,
356,
5854,
63,
1459,
459,
6063,
418,
436,
5854,
63,
1459,
459,
6063,
2278,
354,
503,
3260,
288,
283,
2123,
356,
5854,
63,
1459,
459,
2123,
995,
288,
283,
3065,
356,
5854,
63,
1459,
459,
3065,
995,
288,
283,
2246,
63,
354,
356,
5854,
63,
1459,
459,
2246,
63,
354,
995,
288,
283,
2019,
63,
354,
356,
5854,
63,
1459,
459,
2019,
63,
354,
995,
288,
283,
9339,
356,
5854,
63,
1459,
459,
9339,
995,
288,
283,
929,
356,
5854,
63,
1459,
14,
362,
360,
929,
358,
436,
5854,
63,
1459,
459,
929,
2278,
354,
503,
3260,
267,
789,
267,
2388,
63,
14204,
63,
2347,
63,
1459,
459,
1107,
576,
418,
275,
20210,
63,
2347,
63,
1459,
14,
1935,
360,
1107,
63,
633,
297,
4074,
267,
2388,
63,
14204,
63,
2347,
63,
1459,
459,
88,
63,
3997,
63,
2227,
418,
275,
291,
423,
14204,
63,
4208,
63,
2227,
316,
8,
808,
63,
14204,
63,
2347,
63,
1459,
9,
267,
20210,
63,
2347,
63,
1459,
14,
873,
8,
808,
63,
14204,
63,
2347,
63,
1459,
9,
267,
372,
5854,
63,
1459,
12,
20210,
63,
2347,
63,
1459,
339,
768,
1246,
14,
3029,
272,
347,
20210,
63,
362,
63,
964,
63,
1287,
63,
633,
8,
277,
304,
267,
291,
14,
7505,
63,
368,
342,
267,
372,
291,
423,
362,
63,
14204,
63,
3603,
8,
277,
14,
5418,
11820,
14204,
63,
964,
63,
633,
418,
421,
199,
533,
377,
88,
5949,
794,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
7948,
14,
5945,
7,
339,
20210,
63,
18174,
344,
275,
1504,
14,
1610,
8,
875,
534,
10161,
2870,
358,
339,
485,
14204,
63,
1078,
63,
2347,
63,
1205,
275,
413,
272,
485,
14204,
63,
6455,
63,
2347,
63,
1205,
275,
841,
272,
485,
14204,
63,
6406,
63,
2347,
63,
1205,
275,
499,
339,
327,
23271,
272,
327,
11295,
820,
2901,
6989,
27411,
3177,
272,
327,
23271,
339,
768,
1246,
14,
1238,
272,
347,
485
] |
[
1882,
2803,
26,
2774,
15668,
24,
7,
3905,
1837,
2,
199,
199,
646,
8337,
199,
646,
20330,
199,
646,
2050,
199,
646,
900,
199,
646,
7097,
199,
199,
504,
5166,
492,
2986,
12,
1504,
12,
1709,
199,
504,
5166,
14,
10788,
14,
7948,
14,
992,
14,
7948,
63,
28729,
492,
8505,
199,
504,
5166,
14,
10788,
14,
7948,
63,
14204,
14,
20531,
14,
973,
492,
6529,
794,
7506,
199,
504,
5166,
14,
2537,
14,
1609,
63,
1208,
492,
2069,
63,
5785,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
25523,
1945,
2272,
82,
5949,
794,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
7948,
14,
28729,
7,
339,
347,
485,
362,
63,
14204,
63,
3603,
8,
277,
12,
3734,
304,
267,
408,
6529,
794,
10867,
408,
267,
340,
3734,
508,
283,
8788,
356,
288,
372,
791,
14204,
63,
964,
63,
633,
356,
283,
2859,
921,
7817,
14,
14204,
14,
846,
15,
7019,
15,
1515,
2442,
14,
9259,
936,
267,
587,
26,
288,
372,
791,
14204,
63,
964,
63,
633,
356,
283,
2859,
921,
396,
14,
14204,
14,
846,
15,
7019,
15,
1515,
2442,
14,
9259,
936,
339,
768,
1246,
14,
1238,
272,
347,
485,
362,
63,
9710,
8,
277,
304,
267,
18032,
275,
1613,
8,
22374,
1945,
2272,
82,
5949,
794,
12,
291,
10445,
362,
63,
9710,
342,
267,
18032,
14,
740,
2941,
14204,
297,
283,
5949,
794,
14,
2480,
1105,
267,
372,
18032,
339,
20210,
63,
2886,
275,
1504,
14,
1610,
8,
875,
534,
3735,
16430,
15418,
297,
1415,
63,
692,
63,
3780,
534,
14204,
358,
272,
20210,
63,
5945,
63,
498,
275,
1504,
14,
1610,
8,
875,
534,
3735,
18244,
2606,
297,
1415,
63,
692,
63,
3780,
534,
14204,
358,
339,
347,
485,
14204,
63,
4208,
63,
2227,
316,
8,
277,
12,
1338,
304,
267,
666,
275,
14452,
1370,
904,
779,
288,
1338,
459,
88,
63,
2886,
995,
288,
1338,
459,
88,
63,
3997,
63,
4041,
995,
288,
1338,
459,
88,
63,
3997,
63,
3954,
995,
288,
1338,
459,
88,
63,
4606,
995,
288,
1338,
459,
88,
63,
4968,
63,
600,
12121,
267,
372,
20330,
14,
1222,
8,
495,
8,
1459,
459,
88,
63,
1515,
63,
498,
3815,
666,
12,
8337,
14,
1064,
21,
680,
11453,
342,
339,
768,
1246,
14,
3029,
272,
347,
20210,
63,
964,
63,
4208,
63,
1459,
8,
277,
12,
5854,
63,
1459,
12,
4773,
63,
1459,
304,
267,
291,
14,
7505,
63,
368,
342,
267,
1300,
63,
633,
275,
291,
14,
1813,
459,
723,
14,
888,
63,
5329,
2278,
362,
63,
635,
360,
2520,
14,
1095,
14,
633,
358,
267,
20210,
63,
2347,
63,
1459,
275,
1211,
8,
2347,
63,
1459,
9,
267,
2388,
63,
14204,
63,
2347,
63,
1459,
275,
469,
288,
283,
88,
63,
2886,
356,
291,
14,
14204,
63,
2886,
12,
288,
283,
88,
63,
1515,
63,
498,
356,
291,
14,
14204,
63,
5945,
63,
498,
12,
288,
283,
88,
63,
4606,
356,
620,
8,
2347,
63,
1459,
459,
4606,
3815,
288,
283,
88,
63,
2384,
63,
964,
356,
283,
17698,
4479,
63,
3516,
297,
288,
283,
88,
63,
466,
356,
283,
5580,
63,
28342,
3942,
297,
288,
283,
88,
63,
765,
356,
283,
2571,
297,
288,
283,
88,
63,
3997,
63,
4041,
356,
1543,
83,
5,
83,
7,
450,
334,
277,
14,
344,
12,
1109,
8,
521,
14,
521,
22606,
288,
283,
88,
63,
1023,
356,
283,
19,
14,
17,
297,
288,
283,
88,
63,
21855,
63,
1310,
356,
283,
15064,
297,
288,
283,
88,
63,
3997,
63,
3954,
356,
620,
8,
442,
8,
521,
14,
521,
22606,
288,
283,
88,
63,
21855,
63,
633,
356,
1543,
83,
7,
450,
7097,
14,
17755,
8,
1095,
63,
633,
12,
6529,
794,
7506,
423,
1107,
63,
633,
395,
288,
283,
88,
63,
6406,
63,
633,
356,
1543,
83,
7,
450,
7097,
14,
17755,
8,
1095,
63,
633,
12,
6529,
794,
7506,
423,
6406,
63,
633,
395,
288,
283,
88,
63,
4968,
63,
600,
356,
4773,
63,
1459,
459,
4968,
418,
436,
4773,
63,
1459,
459,
4968,
2278,
354,
503,
3260,
288,
283,
1562,
356,
5854,
63,
1459,
459,
1562,
995,
288,
283,
3690,
356,
5854,
63,
1459,
459,
3690,
995,
288,
283,
6063,
356,
5854,
63,
1459,
459,
6063,
418,
436,
5854,
63,
1459,
459,
6063,
2278,
354,
503,
3260,
288,
283,
2123,
356,
5854,
63,
1459,
459,
2123,
995,
288,
283,
3065,
356,
5854,
63,
1459,
459,
3065,
995,
288,
283,
2246,
63,
354,
356,
5854,
63,
1459,
459,
2246,
63,
354,
995,
288,
283,
2019,
63,
354,
356,
5854,
63,
1459,
459,
2019,
63,
354,
995,
288,
283,
9339,
356,
5854,
63,
1459,
459,
9339,
995,
288,
283,
929,
356,
5854,
63,
1459,
14,
362,
360,
929,
358,
436,
5854,
63,
1459,
459,
929,
2278,
354,
503,
3260,
267,
789,
267,
2388,
63,
14204,
63,
2347,
63,
1459,
459,
1107,
576,
418,
275,
20210,
63,
2347,
63,
1459,
14,
1935,
360,
1107,
63,
633,
297,
4074,
267,
2388,
63,
14204,
63,
2347,
63,
1459,
459,
88,
63,
3997,
63,
2227,
418,
275,
291,
423,
14204,
63,
4208,
63,
2227,
316,
8,
808,
63,
14204,
63,
2347,
63,
1459,
9,
267,
20210,
63,
2347,
63,
1459,
14,
873,
8,
808,
63,
14204,
63,
2347,
63,
1459,
9,
267,
372,
5854,
63,
1459,
12,
20210,
63,
2347,
63,
1459,
339,
768,
1246,
14,
3029,
272,
347,
20210,
63,
362,
63,
964,
63,
1287,
63,
633,
8,
277,
304,
267,
291,
14,
7505,
63,
368,
342,
267,
372,
291,
423,
362,
63,
14204,
63,
3603,
8,
277,
14,
5418,
11820,
14204,
63,
964,
63,
633,
418,
421,
199,
533,
377,
88,
5949,
794,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
7948,
14,
5945,
7,
339,
20210,
63,
18174,
344,
275,
1504,
14,
1610,
8,
875,
534,
10161,
2870,
358,
339,
485,
14204,
63,
1078,
63,
2347,
63,
1205,
275,
413,
272,
485,
14204,
63,
6455,
63,
2347,
63,
1205,
275,
841,
272,
485,
14204,
63,
6406,
63,
2347,
63,
1205,
275,
499,
339,
327,
23271,
272,
327,
11295,
820,
2901,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
serviceagility/boto
|
boto/pyami/installers/ubuntu/installer.py
|
153
|
3545
|
# Copyright (c) 2006,2007,2008 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
import boto.pyami.installers
import os
import os.path
import stat
import boto
import random
from pwd import getpwnam
class Installer(boto.pyami.installers.Installer):
"""
Base Installer class for Ubuntu-based AMI's
"""
def add_cron(self, name, command, minute="*", hour="*", mday="*", month="*", wday="*", who="root", env=None):
"""
Write a file to /etc/cron.d to schedule a command
env is a dict containing environment variables you want to set in the file
name will be used as the name of the file
"""
if minute == 'random':
minute = str(random.randrange(60))
if hour == 'random':
hour = str(random.randrange(24))
fp = open('/etc/cron.d/%s' % name, "w")
if env:
for key, value in env.items():
fp.write('%s=%s\n' % (key, value))
fp.write('%s %s %s %s %s %s %s\n' % (minute, hour, mday, month, wday, who, command))
fp.close()
def add_init_script(self, file, name):
"""
Add this file to the init.d directory
"""
f_path = os.path.join("/etc/init.d", name)
f = open(f_path, "w")
f.write(file)
f.close()
os.chmod(f_path, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)
self.run("/usr/sbin/update-rc.d %s defaults" % name)
def add_env(self, key, value):
"""
Add an environemnt variable
For Ubuntu, the best place is /etc/environment. Values placed here do
not need to be exported.
"""
boto.log.info('Adding env variable: %s=%s' % (key, value))
if not os.path.exists("/etc/environment.orig"):
self.run('cp /etc/environment /etc/environment.orig', notify=False, exit_on_error=False)
fp = open('/etc/environment', 'a')
fp.write('\n%s="%s"' % (key, value))
fp.close()
os.environ[key] = value
def stop(self, service_name):
self.run('/etc/init.d/%s stop' % service_name)
def start(self, service_name):
self.run('/etc/init.d/%s start' % service_name)
def create_user(self, user):
"""
Create a user on the local system
"""
self.run("useradd -m %s" % user)
usr = getpwnam(user)
return usr
def install(self):
"""
This is the only method you need to override
"""
raise NotImplementedError
|
mit
|
[
3,
1898,
334,
67,
9,
8315,
12,
9488,
12,
9300,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
221,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
3,
199,
646,
6055,
14,
647,
13496,
14,
17047,
83,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
5672,
199,
646,
6055,
199,
646,
2196,
199,
504,
14374,
492,
664,
80,
3501,
455,
199,
199,
533,
14089,
9230,
8,
10914,
14,
647,
13496,
14,
17047,
83,
14,
27598,
304,
272,
408,
272,
3523,
14089,
9230,
1021,
367,
31631,
13,
6788,
31694,
1159,
272,
408,
272,
347,
1050,
63,
14829,
8,
277,
12,
536,
12,
1414,
12,
12709,
628,
14421,
6925,
628,
14421,
333,
2977,
628,
14421,
5794,
628,
14421,
336,
2977,
628,
14421,
3963,
628,
1231,
401,
2589,
29,
403,
304,
267,
408,
267,
6990,
282,
570,
370,
1182,
6839,
15,
14829,
14,
68,
370,
8732,
282,
1414,
288,
2589,
365,
282,
1211,
3035,
3734,
2860,
1265,
2934,
370,
663,
315,
314,
570,
288,
536,
911,
506,
1202,
465,
314,
536,
402,
314,
570,
267,
408,
267,
340,
12709,
508,
283,
2355,
356,
288,
12709,
275,
620,
8,
2355,
14,
20539,
8,
2259,
430,
267,
340,
6925,
508,
283,
2355,
356,
288,
6925,
275,
620,
8,
2355,
14,
20539,
8,
1194,
430,
267,
4090,
275,
1551,
2336,
6839,
15,
14829,
14,
68,
3149,
83,
7,
450,
536,
12,
298,
87,
531,
267,
340,
2589,
26,
288,
367,
790,
12,
574,
315,
2589,
14,
1744,
837,
355,
4090,
14,
952,
3508,
83,
2458,
83,
60,
78,
7,
450,
334,
498,
12,
574,
430,
267,
4090,
14,
952,
3508,
83,
450,
83,
450,
83,
450,
83,
450,
83,
450,
83,
450,
83,
60,
78,
7,
450,
334,
10698,
12,
6925,
12,
333,
2977,
12,
5794,
12,
336,
2977,
12,
3963,
12,
1414,
430,
267,
4090,
14,
1600,
342,
339,
347,
1050,
63,
826,
63,
1579,
8,
277,
12,
570,
12,
536,
304,
267,
408,
267,
2654,
642,
570,
370,
314,
4205,
14,
68,
2082,
267,
408,
267,
289,
63,
515,
275,
747,
14,
515,
14,
904,
4769,
6839,
15,
826,
14,
68,
401,
536,
9,
267,
289,
275,
1551,
8,
70,
63,
515,
12,
298,
87,
531,
267,
289,
14,
952,
8,
493,
9,
267,
289,
14,
1600,
342,
267,
747,
14,
11693,
8,
70,
63,
515,
12,
5672,
14,
51,
63,
41,
5670,
1204,
5672,
14,
51,
63,
41,
10387,
1204,
5672,
14,
51,
63,
41,
10276,
9,
267,
291,
14,
1065,
4769,
2647,
15,
21457,
15,
873,
13,
1195,
14,
68,
450,
83,
4243,
2,
450,
536,
9,
339,
347,
1050,
63,
1813,
8,
277,
12,
790,
12,
574,
304,
267,
408,
267,
2654,
376,
655,
1042,
368,
20481,
1750,
267,
2104,
31631,
12,
314,
5526,
4192,
365,
1182,
6839,
15,
5418,
14,
221,
13468,
15090,
2348,
886,
267,
440,
1929,
370,
506,
16629,
14,
267,
408,
267,
6055,
14,
793,
14,
815,
360,
20897,
2589,
1750,
26,
450,
83,
2458,
83,
7,
450,
334,
498,
12,
574,
430,
267,
340,
440,
747,
14,
515,
14,
2444,
4769,
6839,
15,
5418,
14,
2981,
2349,
288,
291,
14,
1065,
360,
1850,
1182,
6839,
15,
5418,
1182,
6839,
15,
5418,
14,
2981,
297,
11705,
29,
797,
12,
4458,
63,
265,
63,
705,
29,
797,
9,
267,
4090,
275,
1551,
2336,
6839,
15,
5418,
297,
283,
65,
358,
267,
4090,
14,
952,
2258,
78,
5,
83,
5961,
83,
4507,
450,
334,
498,
12,
574,
430,
267,
4090,
14,
1600,
342,
267,
747,
14,
2314,
59,
498,
61,
275,
574,
339,
347,
3631,
8,
277,
12,
2435,
63,
354,
304,
267,
291,
14,
1065,
2336,
6839,
15,
826,
14,
68,
3149,
83,
3631,
7,
450,
2435,
63,
354,
9,
339,
347,
1343,
8,
277,
12,
2435,
63,
354,
304,
267,
291,
14,
1065,
2336,
6839,
15,
826,
14,
68,
3149,
83,
1343,
7,
450,
2435,
63,
354,
9,
339,
347,
1218,
63,
751,
8,
277,
12,
922,
304,
267,
408,
267,
2790,
282,
922,
641,
314,
2257,
2656,
267,
408,
267,
291,
14,
1065,
480,
751,
525,
446,
77,
450,
83,
2,
450,
922,
9,
267,
30464,
275,
664,
80,
3501,
455,
8,
751,
9,
267,
372,
30464,
339,
347,
3907,
8,
277,
304,
267,
408,
267,
961,
365,
314,
1454,
1083,
1265,
1929,
370,
4278,
267,
408,
267,
746,
4279,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
8315,
12,
9488,
12,
9300,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
221,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
3,
199,
646,
6055,
14,
647,
13496,
14,
17047,
83,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
5672,
199,
646,
6055,
199,
646,
2196,
199,
504,
14374,
492,
664,
80,
3501,
455,
199,
199,
533,
14089,
9230,
8,
10914,
14,
647,
13496,
14,
17047,
83,
14,
27598,
304,
272,
408,
272,
3523,
14089,
9230,
1021,
367,
31631,
13,
6788,
31694,
1159,
272,
408,
272,
347,
1050,
63,
14829,
8,
277,
12,
536,
12,
1414,
12,
12709,
628,
14421,
6925,
628,
14421,
333,
2977,
628,
14421,
5794,
628,
14421,
336,
2977,
628,
14421,
3963,
628,
1231,
401,
2589,
29,
403,
304,
267,
408,
267,
6990,
282,
570,
370,
1182,
6839,
15,
14829,
14,
68,
370,
8732,
282,
1414,
288,
2589,
365,
282,
1211,
3035,
3734,
2860,
1265,
2934,
370,
663,
315,
314,
570,
288,
536,
911,
506,
1202,
465,
314,
536,
402,
314,
570,
267,
408,
267,
340,
12709,
508,
283,
2355,
356,
288,
12709,
275,
620,
8,
2355,
14,
20539,
8,
2259,
430,
267,
340,
6925,
508,
283,
2355,
356,
288,
6925,
275,
620,
8,
2355,
14,
20539,
8,
1194,
430,
267,
4090,
275,
1551,
2336,
6839,
15,
14829,
14,
68,
3149,
83,
7,
450,
536,
12,
298,
87,
531,
267,
340,
2589,
26,
288,
367,
790,
12,
574,
315,
2589,
14,
1744,
837,
355,
4090,
14,
952,
3508,
83,
2458,
83,
60,
78,
7,
450,
334,
498,
12,
574,
430,
267,
4090,
14,
952,
3508,
83,
450,
83,
450,
83,
450,
83,
450,
83,
450,
83,
450,
83,
60,
78,
7,
450,
334,
10698,
12,
6925,
12,
333,
2977,
12,
5794,
12,
336,
2977,
12,
3963,
12,
1414,
430,
267,
4090,
14,
1600,
342,
339,
347,
1050,
63,
826,
63,
1579,
8,
277,
12,
570,
12,
536,
304,
267,
408,
267,
2654,
642,
570,
370,
314,
4205,
14,
68,
2082,
267,
408,
267,
289,
63,
515,
275,
747,
14,
515,
14,
904,
4769,
6839,
15,
826,
14,
68,
401,
536,
9,
267,
289,
275,
1551,
8,
70,
63,
515,
12,
298,
87,
531,
267,
289,
14,
952,
8,
493,
9,
267,
289,
14,
1600,
342,
267,
747,
14,
11693,
8,
70,
63,
515,
12,
5672,
14,
51,
63,
41,
5670,
1204,
5672,
14,
51,
63,
41,
10387,
1204,
5672,
14,
51,
63,
41,
10276,
9,
267,
291,
14,
1065,
4769,
2647,
15,
21457,
15,
873,
13,
1195,
14,
68,
450,
83,
4243,
2,
450,
536,
9,
339,
347,
1050,
63,
1813,
8,
277,
12,
790,
12,
574,
304,
267,
408,
267,
2654,
376,
655,
1042,
368,
20481,
1750,
267,
2104,
31631,
12,
314,
5526,
4192,
365,
1182,
6839,
15,
5418,
14,
221,
13468,
15090,
2348,
886,
267,
440,
1929,
370,
506,
16629,
14,
267,
408,
267,
6055,
14,
793,
14,
815,
360,
20897,
2589,
1750,
26,
450,
83,
2458,
83,
7,
450,
334,
498,
12,
574,
430,
267,
340,
440,
747,
14,
515,
14,
2444,
4769,
6839,
15,
5418,
14,
2981,
2349,
288,
291,
14,
1065,
360,
1850,
1182,
6839,
15,
5418,
1182,
6839,
15,
5418,
14,
2981,
297,
11705,
29,
797,
12,
4458,
63,
265,
63,
705,
29,
797,
9,
267,
4090,
275,
1551,
2336,
6839,
15,
5418,
297,
283,
65,
358,
267,
4090,
14,
952,
2258,
78,
5,
83,
5961,
83,
4507,
450,
334,
498,
12,
574,
430,
267,
4090,
14,
1600,
342,
267,
747,
14,
2314,
59,
498,
61,
275,
574,
339,
347,
3631,
8,
277,
12,
2435,
63,
354,
304,
267,
291,
14,
1065,
2336,
6839,
15,
826,
14,
68,
3149,
83,
3631,
7,
450,
2435,
63,
354,
9,
339,
347,
1343,
8,
277,
12,
2435,
63,
354,
304,
267,
291,
14,
1065,
2336,
6839,
15,
826,
14,
68,
3149,
83,
1343,
7,
450,
2435,
63,
354,
9,
339,
347,
1218,
63,
751,
8,
277,
12,
922,
304,
267,
408,
267,
2790,
282,
922,
641,
314,
2257,
2656,
267,
408,
267,
291,
14,
1065,
480,
751,
525,
446,
77,
450,
83,
2,
450,
922,
9,
267,
30464,
275,
664,
80,
3501,
455,
8,
751,
9,
267,
372,
30464,
339,
347,
3907,
8,
277,
304,
267,
408,
267,
961,
365,
314,
1454,
1083,
1265,
1929,
370,
4278,
267,
408,
267,
746,
4279,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Si-elegans/Web-based_GUI_Tools
|
spirit/forms/comment_like.py
|
1
|
1042
|
#-*- coding: utf-8 -*-
from django import forms
from django.utils.translation import ugettext as _
from spirit.models.comment_like import CommentLike
class LikeForm(forms.ModelForm):
class Meta:
model = CommentLike
fields = []
def __init__(self, user=None, comment=None, *args, **kwargs):
super(LikeForm, self).__init__(*args, **kwargs)
self.user = user
self.comment = comment
def clean(self):
cleaned_data = super(LikeForm, self).clean()
like = CommentLike.objects.filter(user=self.user,
comment=self.comment)
if like.exists():
# Do this since some of the unique_together fields are excluded.
raise forms.ValidationError(_("This like already exists"))
return cleaned_data
def save(self, commit=True):
if not self.instance.pk:
self.instance.user = self.user
self.instance.comment = self.comment
return super(LikeForm, self).save(commit)
|
apache-2.0
|
[
3,
13,
1837,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
199,
504,
19441,
11133,
14,
992,
14,
3349,
63,
2930,
492,
6819,
12545,
421,
199,
533,
16485,
2821,
8,
3351,
14,
15937,
304,
339,
1021,
6288,
26,
267,
1402,
275,
6819,
12545,
267,
1504,
275,
942,
339,
347,
636,
826,
721,
277,
12,
922,
29,
403,
12,
3721,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
12545,
2821,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
751,
275,
922,
267,
291,
14,
3349,
275,
3721,
339,
347,
3633,
8,
277,
304,
267,
12364,
63,
576,
275,
1613,
8,
12545,
2821,
12,
291,
680,
3118,
342,
398,
2839,
275,
6819,
12545,
14,
1462,
14,
1541,
8,
751,
29,
277,
14,
751,
12,
5101,
3721,
29,
277,
14,
3349,
9,
398,
340,
2839,
14,
2444,
837,
288,
327,
4226,
642,
3967,
2005,
402,
314,
3747,
63,
6314,
1504,
787,
8789,
14,
288,
746,
4513,
14,
8172,
6115,
2765,
2839,
2575,
3495,
2237,
398,
372,
12364,
63,
576,
339,
347,
3354,
8,
277,
12,
5532,
29,
549,
304,
267,
340,
440,
291,
14,
842,
14,
2051,
26,
288,
291,
14,
842,
14,
751,
275,
291,
14,
751,
288,
291,
14,
842,
14,
3349,
275,
291,
14,
3349,
398,
372,
1613,
8,
12545,
2821,
12,
291,
680,
2117,
8,
3543,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
13,
1837,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
199,
504,
19441,
11133,
14,
992,
14,
3349,
63,
2930,
492,
6819,
12545,
421,
199,
533,
16485,
2821,
8,
3351,
14,
15937,
304,
339,
1021,
6288,
26,
267,
1402,
275,
6819,
12545,
267,
1504,
275,
942,
339,
347,
636,
826,
721,
277,
12,
922,
29,
403,
12,
3721,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
12545,
2821,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
751,
275,
922,
267,
291,
14,
3349,
275,
3721,
339,
347,
3633,
8,
277,
304,
267,
12364,
63,
576,
275,
1613,
8,
12545,
2821,
12,
291,
680,
3118,
342,
398,
2839,
275,
6819,
12545,
14,
1462,
14,
1541,
8,
751,
29,
277,
14,
751,
12,
5101,
3721,
29,
277,
14,
3349,
9,
398,
340,
2839,
14,
2444,
837,
288,
327,
4226,
642,
3967,
2005,
402,
314,
3747,
63,
6314,
1504,
787,
8789,
14,
288,
746,
4513,
14,
8172,
6115,
2765,
2839,
2575,
3495,
2237,
398,
372,
12364,
63,
576,
339,
347,
3354,
8,
277,
12,
5532,
29,
549,
304,
267,
340,
440,
291,
14,
842,
14,
2051,
26,
288,
291,
14,
842,
14,
751,
275,
291,
14,
751,
288,
291,
14,
842,
14,
3349,
275,
291,
14,
3349,
398,
372,
1613,
8,
12545,
2821,
12,
291,
680,
2117,
8,
3543,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
NeuroDataDesign/seelviz
|
Flask/env/lib/python2.7/site-packages/pip/_vendor/packaging/_structures.py
|
1152
|
1416
|
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
class Infinity(object):
def __repr__(self):
return "Infinity"
def __hash__(self):
return hash(repr(self))
def __lt__(self, other):
return False
def __le__(self, other):
return False
def __eq__(self, other):
return isinstance(other, self.__class__)
def __ne__(self, other):
return not isinstance(other, self.__class__)
def __gt__(self, other):
return True
def __ge__(self, other):
return True
def __neg__(self):
return NegativeInfinity
Infinity = Infinity()
class NegativeInfinity(object):
def __repr__(self):
return "-Infinity"
def __hash__(self):
return hash(repr(self))
def __lt__(self, other):
return True
def __le__(self, other):
return True
def __eq__(self, other):
return isinstance(other, self.__class__)
def __ne__(self, other):
return not isinstance(other, self.__class__)
def __gt__(self, other):
return False
def __ge__(self, other):
return False
def __neg__(self):
return Infinity
NegativeInfinity = NegativeInfinity()
|
apache-2.0
|
[
3,
961,
570,
365,
21164,
18233,
1334,
314,
2895,
402,
314,
3668,
844,
12,
3394,
199,
3,
499,
14,
16,
12,
436,
314,
6289,
844,
14,
1666,
314,
5113,
570,
315,
314,
1738,
402,
642,
7611,
199,
3,
367,
4890,
2436,
14,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
421,
199,
533,
1010,
9693,
8,
785,
304,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
298,
14660,
2,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
2722,
8,
277,
430,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
8705,
721,
277,
304,
267,
372,
32548,
14660,
199,
199,
14660,
275,
1010,
9693,
342,
421,
199,
533,
32548,
14660,
8,
785,
304,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3905,
14660,
2,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
2722,
8,
277,
430,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
8705,
721,
277,
304,
267,
372,
1010,
9693,
199,
199,
15562,
14660,
275,
32548,
14660,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
961,
570,
365,
21164,
18233,
1334,
314,
2895,
402,
314,
3668,
844,
12,
3394,
199,
3,
499,
14,
16,
12,
436,
314,
6289,
844,
14,
1666,
314,
5113,
570,
315,
314,
1738,
402,
642,
7611,
199,
3,
367,
4890,
2436,
14,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
421,
199,
533,
1010,
9693,
8,
785,
304,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
298,
14660,
2,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
2722,
8,
277,
430,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
8705,
721,
277,
304,
267,
372,
32548,
14660,
199,
199,
14660,
275,
1010,
9693,
342,
421,
199,
533,
32548,
14660,
8,
785,
304,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3905,
14660,
2,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
2722,
8,
277,
430,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
8705,
721,
277,
304,
267,
372,
1010,
9693,
199,
199,
15562,
14660,
275,
32548,
14660,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
moyogo/tachyfont
|
run_time/src/gae_server/third_party/old-fonttools-master/Lib/fontTools/ttLib/tables/sbixBitmapSet.py
|
7
|
4944
|
from __future__ import print_function, division, absolute_import
from fontTools.misc.py23 import *
from fontTools.misc import sstruct
from fontTools.misc.textTools import readHex
from .sbixBitmap import *
import struct
sbixBitmapSetHeaderFormat = """
>
size: H # 00 28
resolution: H # 00 48
"""
sbixBitmapOffsetEntryFormat = """
>
ulOffset: L # 00 00 07 E0 # Offset from start of first offset entry to each bitmap
"""
sbixBitmapSetHeaderFormatSize = sstruct.calcsize(sbixBitmapSetHeaderFormat)
sbixBitmapOffsetEntryFormatSize = sstruct.calcsize(sbixBitmapOffsetEntryFormat)
class BitmapSet(object):
def __init__(self, rawdata=None, size=0, resolution=72):
self.data = rawdata
self.size = size
self.resolution = resolution
self.bitmaps = {}
def decompile(self, ttFont):
if self.data is None:
from fontTools import ttLib
raise ttLib.TTLibError
if len(self.data) < sbixBitmapSetHeaderFormatSize:
from fontTools import ttLib
raise(ttLib.TTLibError, "BitmapSet header too short: Expected %x, got %x.") \
% (sbixBitmapSetHeaderFormatSize, len(self.data))
# read BitmapSet header from raw data
sstruct.unpack(sbixBitmapSetHeaderFormat, self.data[:sbixBitmapSetHeaderFormatSize], self)
# calculate number of bitmaps
firstBitmapOffset, = struct.unpack(">L", \
self.data[sbixBitmapSetHeaderFormatSize : sbixBitmapSetHeaderFormatSize + sbixBitmapOffsetEntryFormatSize])
self.numBitmaps = (firstBitmapOffset - sbixBitmapSetHeaderFormatSize) // sbixBitmapOffsetEntryFormatSize - 1
# ^ -1 because there's one more offset than bitmaps
# build offset list for single bitmap offsets
self.bitmapOffsets = []
for i in range(self.numBitmaps + 1): # + 1 because there's one more offset than bitmaps
start = i * sbixBitmapOffsetEntryFormatSize + sbixBitmapSetHeaderFormatSize
myOffset, = struct.unpack(">L", self.data[start : start + sbixBitmapOffsetEntryFormatSize])
self.bitmapOffsets.append(myOffset)
# iterate through offset list and slice raw data into bitmaps
for i in range(self.numBitmaps):
myBitmap = Bitmap(rawdata=self.data[self.bitmapOffsets[i] : self.bitmapOffsets[i+1]], gid=i)
myBitmap.decompile(ttFont)
self.bitmaps[myBitmap.glyphName] = myBitmap
del self.bitmapOffsets
del self.data
def compile(self, ttFont):
self.bitmapOffsets = ""
self.bitmapData = ""
glyphOrder = ttFont.getGlyphOrder()
# first bitmap starts right after the header
bitmapOffset = sbixBitmapSetHeaderFormatSize + sbixBitmapOffsetEntryFormatSize * (len(glyphOrder) + 1)
for glyphName in glyphOrder:
if glyphName in self.bitmaps:
# we have a bitmap for this glyph
myBitmap = self.bitmaps[glyphName]
else:
# must add empty bitmap for this glyph
myBitmap = Bitmap(glyphName=glyphName)
myBitmap.compile(ttFont)
myBitmap.ulOffset = bitmapOffset
self.bitmapData += myBitmap.rawdata
bitmapOffset += len(myBitmap.rawdata)
self.bitmapOffsets += sstruct.pack(sbixBitmapOffsetEntryFormat, myBitmap)
# add last "offset", really the end address of the last bitmap
dummy = Bitmap()
dummy.ulOffset = bitmapOffset
self.bitmapOffsets += sstruct.pack(sbixBitmapOffsetEntryFormat, dummy)
# bitmap sets are padded to 4 byte boundaries
dataLength = len(self.bitmapOffsets) + len(self.bitmapData)
if dataLength % 4 != 0:
padding = 4 - (dataLength % 4)
else:
padding = 0
# pack header
self.data = sstruct.pack(sbixBitmapSetHeaderFormat, self)
# add offset, image data and padding after header
self.data += self.bitmapOffsets + self.bitmapData + "\0" * padding
def toXML(self, xmlWriter, ttFont):
xmlWriter.begintag("bitmapSet")
xmlWriter.newline()
xmlWriter.simpletag("size", value=self.size)
xmlWriter.newline()
xmlWriter.simpletag("resolution", value=self.resolution)
xmlWriter.newline()
glyphOrder = ttFont.getGlyphOrder()
for i in range(len(glyphOrder)):
if glyphOrder[i] in self.bitmaps:
self.bitmaps[glyphOrder[i]].toXML(xmlWriter, ttFont)
# TODO: what if there are more bitmaps than glyphs?
xmlWriter.endtag("bitmapSet")
xmlWriter.newline()
def fromXML(self, name, attrs, content, ttFont):
if name in ["size", "resolution"]:
setattr(self, name, int(attrs["value"]))
elif name == "bitmap":
if "format" in attrs:
myFormat = attrs["format"]
else:
myFormat = None
if "glyphname" in attrs:
myGlyphName = attrs["glyphname"]
else:
from fontTools import ttLib
raise ttLib.TTLibError("Bitmap must have a glyph name.")
myBitmap = Bitmap(glyphName=myGlyphName, imageFormatTag=myFormat)
for element in content:
if isinstance(element, tuple):
name, attrs, content = element
myBitmap.fromXML(name, attrs, content, ttFont)
myBitmap.compile(ttFont)
self.bitmaps[myBitmap.glyphName] = myBitmap
else:
from fontTools import ttLib
raise ttLib.TTLibError("can't handle '%s' element" % name)
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
12,
3679,
63,
646,
199,
504,
5023,
11654,
14,
9923,
14,
647,
1789,
492,
627,
199,
504,
5023,
11654,
14,
9923,
492,
308,
1820,
199,
504,
5023,
11654,
14,
9923,
14,
505,
11654,
492,
1586,
10373,
199,
504,
1275,
9264,
1148,
16469,
492,
627,
199,
646,
2702,
199,
199,
9264,
1148,
16469,
1084,
2567,
3484,
275,
408,
199,
198,
30,
199,
198,
890,
26,
3322,
869,
259,
327,
8733,
7294,
199,
198,
12588,
26,
420,
869,
259,
327,
755,
8733,
9615,
199,
624,
199,
199,
9264,
1148,
16469,
6397,
3900,
3484,
275,
408,
199,
198,
30,
199,
198,
348,
6397,
26,
263,
491,
259,
327,
8733,
8733,
24937,
662,
16,
327,
29432,
687,
1343,
402,
1642,
3268,
2397,
370,
1924,
20810,
199,
624,
199,
199,
9264,
1148,
16469,
1084,
2567,
3484,
2320,
275,
308,
1820,
14,
21691,
8,
9264,
1148,
16469,
1084,
2567,
3484,
9,
199,
9264,
1148,
16469,
6397,
3900,
3484,
2320,
275,
308,
1820,
14,
21691,
8,
9264,
1148,
16469,
6397,
3900,
3484,
9,
421,
199,
533,
10199,
1130,
1084,
8,
785,
304,
199,
198,
318,
636,
826,
721,
277,
12,
15705,
29,
403,
12,
1568,
29,
16,
12,
12401,
29,
2819,
304,
507,
198,
277,
14,
576,
275,
15705,
507,
198,
277,
14,
890,
275,
1568,
507,
198,
277,
14,
12588,
275,
12401,
507,
198,
277,
14,
2075,
8919,
275,
1052,
421,
198,
318,
477,
2014,
8,
277,
12,
13638,
6986,
304,
507,
198,
692,
291,
14,
576,
365,
488,
26,
686,
198,
504,
5023,
11654,
492,
13638,
4728,
686,
198,
3730,
13638,
4728,
14,
1481,
4728,
547,
507,
198,
692,
822,
8,
277,
14,
576,
9,
665,
20088,
1148,
16469,
1084,
2567,
3484,
2320,
26,
686,
198,
504,
5023,
11654,
492,
13638,
4728,
686,
198,
3730,
8,
6215,
4728,
14,
1481,
4728,
547,
12,
298,
16469,
1084,
1406,
4634,
3974,
26,
13796,
450,
88,
12,
4788,
450,
88,
2685,
971,
1585,
198,
5,
334,
9264,
1148,
16469,
1084,
2567,
3484,
2320,
12,
822,
8,
277,
14,
576,
430,
2742,
198,
3,
1586,
10199,
1130,
1084,
1406,
687,
3066,
666,
507,
198,
83,
1820,
14,
5301,
8,
9264,
1148,
16469,
1084,
2567,
3484,
12,
291,
14,
576,
1491,
9264,
1148,
16469,
1084,
2567,
3484,
2320,
467,
291,
9,
2742,
198,
3,
8671,
1329,
402,
4546,
8919,
507,
198,
2246,
16469,
6397,
12,
275,
2702,
14,
5301,
19651,
44,
401,
971,
686,
198,
277,
14,
576,
59,
9264,
1148,
16469,
1084,
2567,
3484,
2320,
520,
20088,
1148,
16469,
1084,
2567,
3484,
2320,
435,
20088,
1148,
16469,
6397,
3900,
3484,
2320,
566,
507,
198,
277,
14,
1507,
4734,
8919,
275,
334,
2246,
16469,
6397,
446,
20088,
1148,
16469,
1084,
2567,
3484,
2320,
9,
5001,
20088,
1148,
16469,
6397,
3900,
3484,
2320,
446,
413,
507,
198,
3,
7167,
446,
17,
2952,
2337,
1159,
1373,
1655,
3268,
2419,
4546,
8919,
2742,
198,
3,
1900,
3268,
769,
367,
2849,
20810,
15340,
507,
198,
277,
14,
20299,
5195,
2193,
275,
942,
507,
198,
509,
284,
315,
1425,
8,
277,
14,
1507,
4734,
8919,
435,
413,
304,
327,
435,
413,
2952,
2337,
1159,
1373,
1655,
3268,
2419,
4546,
8919,
686,
198,
928,
275,
284,
627,
20088,
1148,
16469,
6397,
3900,
3484,
2320,
435,
20088,
1148,
16469,
1084,
2567,
3484,
2320,
686,
198,
1662,
6397,
12,
275,
2702,
14,
5301,
19651,
44,
401,
291,
14,
576,
59,
928,
520,
1343,
435,
20088,
1148,
16469,
6397,
3900,
3484,
2320,
566,
686,
198,
277,
14,
20299,
5195,
2193,
14,
740,
8,
1662,
6397,
9,
2742,
198,
3,
13974,
4012,
3268,
769,
436,
6014,
3066,
666,
1901,
4546,
8919,
507,
198,
509,
284,
315,
1425,
8,
277,
14,
1507,
4734,
8919,
304,
686,
198,
1662,
16469,
275,
10199,
1130,
8,
14901,
29,
277,
14,
576,
59,
277,
14,
20299,
5195,
2193,
59,
73,
61,
520,
291,
14,
20299,
5195,
2193,
59,
73,
11,
17,
2365,
15122,
29,
73,
9,
686,
198,
1662,
16469,
14,
271,
2014,
8,
6215,
6986,
9,
686,
198,
277,
14,
2075,
8919,
59,
1662,
16469,
14,
26768,
61,
275,
3002,
16469,
507,
198,
2264,
291,
14,
20299,
5195,
2193,
507,
198,
2264,
291,
14,
576,
421,
198,
318,
6555,
8,
277,
12,
13638,
6986,
304,
507,
198,
277,
14,
20299,
5195,
2193,
275,
3087,
507,
198,
277,
14,
20299,
1451,
275,
3087,
2742,
198,
13723,
4738,
275,
13638,
6986,
14,
362,
15533,
4738,
342,
2742,
198,
3,
1642,
20810,
9174,
2451,
2410,
314,
1406,
507,
198,
20299,
6397,
275,
20088,
1148,
16469,
1084,
2567,
3484,
2320,
435,
20088,
1148,
16469,
6397,
3900,
3484,
2320,
627,
334,
552,
8,
13723,
4738,
9,
435,
413,
9,
507,
198,
509,
14165,
985,
315,
14165,
4738,
26,
686,
198,
692,
14165,
985,
315,
291,
14,
2075,
8919,
26,
1585,
198,
3,
781,
1172,
282,
20810,
367,
642,
14165,
1585,
198,
1662,
16469,
275,
291,
14,
2075,
8919,
59,
26768,
61,
686,
198,
2836,
26,
1585,
198,
3,
1471,
1050,
2701,
20810,
367,
642,
14165,
1585,
198,
1662,
16469,
275,
10199,
1130,
8,
26768,
29,
26768,
9,
686,
198,
1662,
16469,
14,
2014,
8,
6215,
6986,
9,
686,
198,
1662,
16469,
14,
348,
6397,
275,
20810,
6397,
686,
198,
277,
14,
20299,
1451,
847,
3002,
16469,
14,
14901,
686,
198,
20299,
6397,
847,
822,
8,
1662,
16469,
14,
14901,
9,
686,
198,
277,
14,
20299,
5195,
2193,
847,
308,
1820,
14,
1389,
8,
9264,
1148,
16469,
6397,
3900,
3484,
12,
3002,
16469,
9,
2742,
198,
3,
1050,
2061,
298,
2743,
401,
7710,
314,
1284,
2287,
402,
314,
2061,
20810,
507,
198,
5869,
275,
10199,
1130,
342,
507,
198,
5869,
14,
348,
6397,
275,
20810,
6397,
507,
198,
277,
14,
20299,
5195,
2193,
847,
308,
1820,
14,
1389,
8,
9264,
1148,
16469,
6397,
3900,
3484,
12,
7283,
9,
2742,
198,
3,
20810,
5951,
787,
21824,
370,
841,
3696,
18135,
507,
198,
576,
4625,
275,
822,
8,
277,
14,
20299,
5195,
2193,
9,
435,
822,
8,
277,
14,
20299,
1451,
9,
507,
198,
692,
666,
4625,
450,
841,
1137,
378,
26,
686,
198,
8358,
275,
841,
446,
334,
576,
4625,
450,
841,
9,
507,
198,
2836,
26,
686,
198,
8358,
275,
378,
2742,
198,
3
] |
[
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
12,
3679,
63,
646,
199,
504,
5023,
11654,
14,
9923,
14,
647,
1789,
492,
627,
199,
504,
5023,
11654,
14,
9923,
492,
308,
1820,
199,
504,
5023,
11654,
14,
9923,
14,
505,
11654,
492,
1586,
10373,
199,
504,
1275,
9264,
1148,
16469,
492,
627,
199,
646,
2702,
199,
199,
9264,
1148,
16469,
1084,
2567,
3484,
275,
408,
199,
198,
30,
199,
198,
890,
26,
3322,
869,
259,
327,
8733,
7294,
199,
198,
12588,
26,
420,
869,
259,
327,
755,
8733,
9615,
199,
624,
199,
199,
9264,
1148,
16469,
6397,
3900,
3484,
275,
408,
199,
198,
30,
199,
198,
348,
6397,
26,
263,
491,
259,
327,
8733,
8733,
24937,
662,
16,
327,
29432,
687,
1343,
402,
1642,
3268,
2397,
370,
1924,
20810,
199,
624,
199,
199,
9264,
1148,
16469,
1084,
2567,
3484,
2320,
275,
308,
1820,
14,
21691,
8,
9264,
1148,
16469,
1084,
2567,
3484,
9,
199,
9264,
1148,
16469,
6397,
3900,
3484,
2320,
275,
308,
1820,
14,
21691,
8,
9264,
1148,
16469,
6397,
3900,
3484,
9,
421,
199,
533,
10199,
1130,
1084,
8,
785,
304,
199,
198,
318,
636,
826,
721,
277,
12,
15705,
29,
403,
12,
1568,
29,
16,
12,
12401,
29,
2819,
304,
507,
198,
277,
14,
576,
275,
15705,
507,
198,
277,
14,
890,
275,
1568,
507,
198,
277,
14,
12588,
275,
12401,
507,
198,
277,
14,
2075,
8919,
275,
1052,
421,
198,
318,
477,
2014,
8,
277,
12,
13638,
6986,
304,
507,
198,
692,
291,
14,
576,
365,
488,
26,
686,
198,
504,
5023,
11654,
492,
13638,
4728,
686,
198,
3730,
13638,
4728,
14,
1481,
4728,
547,
507,
198,
692,
822,
8,
277,
14,
576,
9,
665,
20088,
1148,
16469,
1084,
2567,
3484,
2320,
26,
686,
198,
504,
5023,
11654,
492,
13638,
4728,
686,
198,
3730,
8,
6215,
4728,
14,
1481,
4728,
547,
12,
298,
16469,
1084,
1406,
4634,
3974,
26,
13796,
450,
88,
12,
4788,
450,
88,
2685,
971,
1585,
198,
5,
334,
9264,
1148,
16469,
1084,
2567,
3484,
2320,
12,
822,
8,
277,
14,
576,
430,
2742,
198,
3,
1586,
10199,
1130,
1084,
1406,
687,
3066,
666,
507,
198,
83,
1820,
14,
5301,
8,
9264,
1148,
16469,
1084,
2567,
3484,
12,
291,
14,
576,
1491,
9264,
1148,
16469,
1084,
2567,
3484,
2320,
467,
291,
9,
2742,
198,
3,
8671,
1329,
402,
4546,
8919,
507,
198,
2246,
16469,
6397,
12,
275,
2702,
14,
5301,
19651,
44,
401,
971,
686,
198,
277,
14,
576,
59,
9264,
1148,
16469,
1084,
2567,
3484,
2320,
520,
20088,
1148,
16469,
1084,
2567,
3484,
2320,
435,
20088,
1148,
16469,
6397,
3900,
3484,
2320,
566,
507,
198,
277,
14,
1507,
4734,
8919,
275,
334,
2246,
16469,
6397,
446,
20088,
1148,
16469,
1084,
2567,
3484,
2320,
9,
5001,
20088,
1148,
16469,
6397,
3900,
3484,
2320,
446,
413,
507,
198,
3,
7167,
446,
17,
2952,
2337,
1159,
1373,
1655,
3268,
2419,
4546,
8919,
2742,
198,
3,
1900,
3268,
769,
367,
2849,
20810,
15340,
507,
198,
277,
14,
20299,
5195,
2193,
275,
942,
507,
198,
509,
284,
315,
1425,
8,
277,
14,
1507,
4734,
8919,
435,
413,
304,
327,
435,
413,
2952,
2337,
1159,
1373,
1655,
3268,
2419,
4546,
8919,
686,
198,
928,
275,
284,
627,
20088,
1148,
16469,
6397,
3900,
3484,
2320,
435,
20088,
1148,
16469,
1084,
2567,
3484,
2320,
686,
198,
1662,
6397,
12,
275,
2702,
14,
5301,
19651,
44,
401,
291,
14,
576,
59,
928,
520,
1343,
435,
20088,
1148,
16469,
6397,
3900,
3484,
2320,
566,
686,
198,
277,
14,
20299,
5195,
2193,
14,
740,
8,
1662,
6397,
9,
2742,
198,
3,
13974,
4012,
3268,
769,
436,
6014,
3066,
666,
1901,
4546,
8919,
507,
198,
509,
284,
315,
1425,
8,
277,
14,
1507,
4734,
8919,
304,
686,
198,
1662,
16469,
275,
10199,
1130,
8,
14901,
29,
277,
14,
576,
59,
277,
14,
20299,
5195,
2193,
59,
73,
61,
520,
291,
14,
20299,
5195,
2193,
59,
73,
11,
17,
2365,
15122,
29,
73,
9,
686,
198,
1662,
16469,
14,
271,
2014,
8,
6215,
6986,
9,
686,
198,
277,
14,
2075,
8919,
59,
1662,
16469,
14,
26768,
61,
275,
3002,
16469,
507,
198,
2264,
291,
14,
20299,
5195,
2193,
507,
198,
2264,
291,
14,
576,
421,
198,
318,
6555,
8,
277,
12,
13638,
6986,
304,
507,
198,
277,
14,
20299,
5195,
2193,
275,
3087,
507,
198,
277,
14,
20299,
1451,
275,
3087,
2742,
198,
13723,
4738,
275,
13638,
6986,
14,
362,
15533,
4738,
342,
2742,
198,
3,
1642,
20810,
9174,
2451,
2410,
314,
1406,
507,
198,
20299,
6397,
275,
20088,
1148,
16469,
1084,
2567,
3484,
2320,
435,
20088,
1148,
16469,
6397,
3900,
3484,
2320,
627,
334,
552,
8,
13723,
4738,
9,
435,
413,
9,
507,
198,
509,
14165,
985,
315,
14165,
4738,
26,
686,
198,
692,
14165,
985,
315,
291,
14,
2075,
8919,
26,
1585,
198,
3,
781,
1172,
282,
20810,
367,
642,
14165,
1585,
198,
1662,
16469,
275,
291,
14,
2075,
8919,
59,
26768,
61,
686,
198,
2836,
26,
1585,
198,
3,
1471,
1050,
2701,
20810,
367,
642,
14165,
1585,
198,
1662,
16469,
275,
10199,
1130,
8,
26768,
29,
26768,
9,
686,
198,
1662,
16469,
14,
2014,
8,
6215,
6986,
9,
686,
198,
1662,
16469,
14,
348,
6397,
275,
20810,
6397,
686,
198,
277,
14,
20299,
1451,
847,
3002,
16469,
14,
14901,
686,
198,
20299,
6397,
847,
822,
8,
1662,
16469,
14,
14901,
9,
686,
198,
277,
14,
20299,
5195,
2193,
847,
308,
1820,
14,
1389,
8,
9264,
1148,
16469,
6397,
3900,
3484,
12,
3002,
16469,
9,
2742,
198,
3,
1050,
2061,
298,
2743,
401,
7710,
314,
1284,
2287,
402,
314,
2061,
20810,
507,
198,
5869,
275,
10199,
1130,
342,
507,
198,
5869,
14,
348,
6397,
275,
20810,
6397,
507,
198,
277,
14,
20299,
5195,
2193,
847,
308,
1820,
14,
1389,
8,
9264,
1148,
16469,
6397,
3900,
3484,
12,
7283,
9,
2742,
198,
3,
20810,
5951,
787,
21824,
370,
841,
3696,
18135,
507,
198,
576,
4625,
275,
822,
8,
277,
14,
20299,
5195,
2193,
9,
435,
822,
8,
277,
14,
20299,
1451,
9,
507,
198,
692,
666,
4625,
450,
841,
1137,
378,
26,
686,
198,
8358,
275,
841,
446,
334,
576,
4625,
450,
841,
9,
507,
198,
2836,
26,
686,
198,
8358,
275,
378,
2742,
198,
3,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
nttks/edx-platform
|
lms/djangoapps/pdfgen/tests/test_api.py
|
1
|
6717
|
"""Tests for the pdfgen API. """
from datetime import datetime
from mock import patch
from django.test import RequestFactory
from certificates import api as certs_api
from certificates.models import CertificateGenerationConfiguration, CertificateStatuses, GeneratedCertificate
from certificates.tests.factories import GeneratedCertificateFactory
from config_models.models import cache
from openedx.core.djangoapps.ga_self_paced import api as self_paced_api
from openedx.core.djangoapps.ga_task.api import AlreadyRunningError
from openedx.core.djangoapps.ga_task.tests.test_task import TaskTestMixin
from pdfgen import api as pdfgen_api
from student.tests.factories import CourseEnrollmentFactory, UserFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
class GenerateUserCertificateTest(ModuleStoreTestCase, TaskTestMixin):
def setUp(self):
super(GenerateUserCertificateTest, self).setUp()
# Enable the certificate generation feature
cache.clear()
CertificateGenerationConfiguration.objects.create(enabled=True)
self.user = UserFactory.create()
self.course = self._create_course()
self.request = RequestFactory().request()
# Setup mock
patcher_is_course_closed = patch.object(self_paced_api, 'is_course_closed')
self.mock_is_course_closed = patcher_is_course_closed.start()
self.mock_is_course_closed.return_value = False
self.addCleanup(patcher_is_course_closed.stop)
patcher_submit_task = patch('pdfgen.api.submit_task')
self.mock_submit_task = patcher_submit_task.start()
self.addCleanup(patcher_submit_task.stop)
def _create_course(self, is_self_paced=True, **options):
course = CourseFactory.create(
self_paced=is_self_paced,
start=datetime(2013, 9, 16, 7, 17, 28),
grade_cutoffs={'Pass': 0.5},
**options
)
# Enable certificate generation for this course
certs_api.set_cert_generation_enabled(course.id, is_self_paced)
CourseEnrollmentFactory(user=self.user, course_id=course.id)
return course
def _create_task(self, course, student):
task_input = {
'course_id': unicode(course.id),
'student_ids': [student.id],
}
return self._create_input_entry(task_input=task_input)
def _create_cert(self, status):
return GeneratedCertificateFactory.create(
user=self.user,
course_id=self.course.id,
status=status,
download_url='http://www.example.com/cert.pdf' if status == CertificateStatuses.downloadable else '',
mode='honor',
)
def _get_cert(self, course, student):
try:
return GeneratedCertificate.objects.get(course_id=course.id, user=student)
except GeneratedCertificate.DoesNotExist:
return None
def test_successful(self):
task = self._create_task(self.course, self.user)
self.mock_submit_task.return_value = task
self.assertEqual(
pdfgen_api.generate_user_certificate(self.request, self.user, self.course),
{
'success': True,
'message': "Certificate self-generation task(task_id={task_id}) has been started.".format(
task_id=task.id),
}
)
def test_check_error_course_is_not_self_paced(self):
not_self_paced_course = self._create_course(is_self_paced=False)
self.assertEqual(
pdfgen_api.generate_user_certificate(self.request, self.user, not_self_paced_course),
{
'success': False,
'message': "Couldn't submit a certificate self-generation task because the course is not self-paced.",
}
)
cert = self._get_cert(not_self_paced_course, self.user)
self.assertEqual(cert.course_id, not_self_paced_course.id)
self.assertEqual(cert.user, self.user)
self.assertEqual(cert.status, CertificateStatuses.error)
self.assertEqual(cert.error_reason, "This course is not self-paced.")
def test_check_error_enroll_has_expired(self):
self.mock_is_course_closed.return_value = True
self.assertEqual(
pdfgen_api.generate_user_certificate(self.request, self.user, self.course),
{
'success': False,
'message': "Couldn't submit a certificate self-generation task because student's enrollment has already expired.",
}
)
cert = self._get_cert(self.course, self.user)
self.assertEqual(cert.course_id, self.course.id)
self.assertEqual(cert.user, self.user)
self.assertEqual(cert.status, CertificateStatuses.error)
self.assertEqual(cert.error_reason, "Student's enrollment has already expired")
def test_check_error_cert_has_already_created(self):
before_cert = self._create_cert(CertificateStatuses.generating)
self.assertEqual(
pdfgen_api.generate_user_certificate(self.request, self.user, self.course),
{
'success': False,
'message': "Couldn't submit a certificate self-generation task because certificate status has already created."
}
)
cert = self._get_cert(self.course, self.user)
self.assertEqual(cert.course_id, before_cert.course_id)
self.assertEqual(cert.user, before_cert.user)
self.assertEqual(cert.status, before_cert.status)
self.assertEqual(cert.error_reason, before_cert.error_reason)
def test_already_running_error(self):
self.mock_submit_task.side_effect = AlreadyRunningError()
self.assertEqual(
pdfgen_api.generate_user_certificate(self.request, self.user, self.course),
{
'success': False,
'message': "Task is already running.",
}
)
def test_unexpected_error(self):
ex = Exception('a' * 1000)
self.mock_submit_task.side_effect = ex
self.assertEqual(
pdfgen_api.generate_user_certificate(self.request, self.user, self.course),
{
'success': False,
'message': "An unexpected error occurred.",
}
)
cert = self._get_cert(self.course, self.user)
self.assertEqual(cert.course_id, self.course.id)
self.assertEqual(cert.user, self.user)
self.assertEqual(cert.status, CertificateStatuses.error)
self.assertEqual(cert.error_reason, str(ex)[:512])
|
agpl-3.0
|
[
624,
2925,
367,
314,
11249,
2268,
3261,
14,
408,
199,
504,
2197,
492,
2197,
199,
504,
1683,
492,
3371,
199,
199,
504,
1639,
14,
396,
492,
18638,
199,
199,
504,
14512,
492,
2986,
465,
25949,
63,
1246,
199,
504,
14512,
14,
992,
492,
12904,
18514,
5688,
12,
12904,
11232,
5589,
12,
17065,
11414,
199,
504,
14512,
14,
2219,
14,
15406,
492,
17065,
11414,
2927,
199,
504,
1101,
63,
992,
14,
992,
492,
2581,
199,
504,
22709,
14,
1018,
14,
16432,
14,
5294,
63,
277,
63,
1142,
68,
492,
2986,
465,
291,
63,
1142,
68,
63,
1246,
199,
504,
22709,
14,
1018,
14,
16432,
14,
5294,
63,
1765,
14,
1246,
492,
21086,
9602,
547,
199,
504,
22709,
14,
1018,
14,
16432,
14,
5294,
63,
1765,
14,
2219,
14,
396,
63,
1765,
492,
8495,
22060,
199,
504,
11249,
2268,
492,
2986,
465,
11249,
2268,
63,
1246,
199,
504,
6474,
14,
2219,
14,
15406,
492,
18946,
2927,
12,
16047,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
17996,
1746,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
421,
199,
533,
7958,
1899,
11414,
774,
8,
27863,
12,
8495,
22060,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
6864,
1899,
11414,
774,
12,
291,
680,
5996,
342,
398,
327,
12030,
314,
5897,
10152,
3878,
267,
2581,
14,
3584,
342,
267,
12904,
18514,
5688,
14,
1462,
14,
981,
8,
3827,
29,
549,
9,
398,
291,
14,
751,
275,
16047,
14,
981,
342,
267,
291,
14,
1972,
275,
291,
423,
981,
63,
1972,
342,
267,
291,
14,
1069,
275,
18638,
1252,
1069,
342,
398,
327,
12439,
1683,
267,
21198,
63,
374,
63,
1972,
63,
5938,
275,
3371,
14,
785,
8,
277,
63,
1142,
68,
63,
1246,
12,
283,
374,
63,
1972,
63,
5938,
358,
267,
291,
14,
1805,
63,
374,
63,
1972,
63,
5938,
275,
21198,
63,
374,
63,
1972,
63,
5938,
14,
928,
342,
267,
291,
14,
1805,
63,
374,
63,
1972,
63,
5938,
14,
1107,
63,
585,
275,
756,
267,
291,
14,
12808,
8,
11238,
63,
374,
63,
1972,
63,
5938,
14,
2379,
9,
398,
21198,
63,
7275,
63,
1765,
275,
3371,
360,
5607,
2268,
14,
1246,
14,
7275,
63,
1765,
358,
267,
291,
14,
1805,
63,
7275,
63,
1765,
275,
21198,
63,
7275,
63,
1765,
14,
928,
342,
267,
291,
14,
12808,
8,
11238,
63,
7275,
63,
1765,
14,
2379,
9,
339,
347,
485,
981,
63,
1972,
8,
277,
12,
365,
63,
277,
63,
1142,
68,
29,
549,
12,
1011,
1419,
304,
267,
2518,
275,
17862,
14,
981,
8,
288,
291,
63,
1142,
68,
29,
374,
63,
277,
63,
1142,
68,
12,
288,
1343,
29,
2083,
8,
6965,
12,
1749,
12,
3193,
12,
1520,
12,
5557,
12,
7294,
395,
288,
16183,
63,
17708,
83,
3713,
4986,
356,
378,
14,
21,
1386,
288,
1011,
1419,
267,
776,
267,
327,
12030,
5897,
10152,
367,
642,
2518,
267,
25949,
63,
1246,
14,
409,
63,
4736,
63,
15043,
63,
3827,
8,
1972,
14,
344,
12,
365,
63,
277,
63,
1142,
68,
9,
398,
18946,
2927,
8,
751,
29,
277,
14,
751,
12,
2518,
63,
344,
29,
1972,
14,
344,
9,
267,
372,
2518,
339,
347,
485,
981,
63,
1765,
8,
277,
12,
2518,
12,
6474,
304,
267,
2120,
63,
1210,
275,
469,
288,
283,
1972,
63,
344,
356,
2649,
8,
1972,
14,
344,
395,
288,
283,
5500,
63,
1580,
356,
359,
5500,
14,
344,
467,
267,
789,
267,
372,
291,
423,
981,
63,
1210,
63,
2373,
8,
1765,
63,
1210,
29,
1765,
63,
1210,
9,
339,
347,
485,
981,
63,
4736,
8,
277,
12,
2004,
304,
267,
372,
17065,
11414,
2927,
14,
981,
8,
288,
922,
29,
277,
14,
751,
12,
288,
2518,
63,
344,
29,
277,
14,
1972,
14,
344,
12,
288,
2004,
29,
1205,
12,
288,
5235,
63,
633,
534,
1014,
921,
1544,
14,
2694,
14,
957,
15,
4736,
14,
5607,
7,
340,
2004,
508,
12904,
11232,
5589,
14,
4249,
461,
587,
3260,
288,
818,
534,
19923,
297,
267,
776,
339,
347,
485,
362,
63,
4736,
8,
277,
12,
2518,
12,
6474,
304,
267,
862,
26,
288,
372,
17065,
11414,
14,
1462,
14,
362,
8,
1972,
63,
344,
29,
1972,
14,
344,
12,
922,
29,
5500,
9,
267,
871,
17065,
11414,
14,
7400,
26,
288,
372,
488,
339,
347,
511,
63,
18157,
8,
277,
304,
267,
2120,
275,
291,
423,
981,
63,
1765,
8,
277,
14,
1972,
12,
291,
14,
751,
9,
267,
291,
14,
1805,
63,
7275,
63,
1765,
14,
1107,
63,
585,
275,
2120,
398,
291,
14,
629,
8,
288,
11249,
2268,
63,
1246,
14,
4208,
63,
751,
63,
6999,
8,
277,
14,
1069,
12,
291,
14,
751,
12,
291,
14,
1972,
395,
288,
469,
355,
283,
3742,
356,
715,
12,
355,
283,
1188,
356,
298,
11414,
291,
13,
15043,
2120,
8,
1765,
63,
344,
3126,
1765,
63,
344,
1552,
965,
2757,
8239,
15848,
908,
8,
490,
2120,
63,
344,
29,
1765,
14,
344,
395,
288,
789,
267,
776,
339,
347,
511,
63,
1074,
63,
705,
63,
1972,
63,
374,
63,
1397,
63,
277,
63,
1142,
68,
8,
277,
304,
267,
440,
63,
277,
63,
1142,
68,
63,
1972,
275,
291,
423,
981,
63,
1972,
8,
374,
63,
277,
63,
1142,
68,
29,
797,
9,
398,
291,
14,
629,
8,
288,
11249,
2268,
63,
1246,
14,
4208,
63,
751,
63,
6999,
8,
277,
14,
1069,
12,
291,
14,
751,
12,
440,
63,
277,
63,
1142,
68,
63,
1972,
395,
288,
469,
355,
283,
3742,
356,
756,
12,
355,
283,
1188,
356,
298,
20485,
1133,
11482,
282,
5897,
291,
13,
15043,
2120,
2952,
314,
2518,
365,
440,
291,
13,
1142,
68,
4765,
288,
789,
267,
776,
267,
6250,
275,
291,
423,
362,
63,
4736,
8,
1397,
63,
277,
63,
1142,
68,
63,
1972,
12,
291,
14,
751,
9,
267,
291,
14,
629,
8,
4736,
14,
1972,
63,
344,
12,
440,
63,
277,
63,
1142,
68,
63,
1972,
14,
344,
9,
267,
291,
14,
629,
8,
4736,
14,
751,
12,
291,
14,
751,
9,
267,
291,
14,
629,
8,
4736,
14,
1205,
12,
12904,
11232,
5589,
14,
705,
9,
267,
291,
14,
629,
8,
4736,
14,
705,
63,
5764,
12
] |
[
2925,
367,
314,
11249,
2268,
3261,
14,
408,
199,
504,
2197,
492,
2197,
199,
504,
1683,
492,
3371,
199,
199,
504,
1639,
14,
396,
492,
18638,
199,
199,
504,
14512,
492,
2986,
465,
25949,
63,
1246,
199,
504,
14512,
14,
992,
492,
12904,
18514,
5688,
12,
12904,
11232,
5589,
12,
17065,
11414,
199,
504,
14512,
14,
2219,
14,
15406,
492,
17065,
11414,
2927,
199,
504,
1101,
63,
992,
14,
992,
492,
2581,
199,
504,
22709,
14,
1018,
14,
16432,
14,
5294,
63,
277,
63,
1142,
68,
492,
2986,
465,
291,
63,
1142,
68,
63,
1246,
199,
504,
22709,
14,
1018,
14,
16432,
14,
5294,
63,
1765,
14,
1246,
492,
21086,
9602,
547,
199,
504,
22709,
14,
1018,
14,
16432,
14,
5294,
63,
1765,
14,
2219,
14,
396,
63,
1765,
492,
8495,
22060,
199,
504,
11249,
2268,
492,
2986,
465,
11249,
2268,
63,
1246,
199,
504,
6474,
14,
2219,
14,
15406,
492,
18946,
2927,
12,
16047,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
17996,
1746,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
421,
199,
533,
7958,
1899,
11414,
774,
8,
27863,
12,
8495,
22060,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
6864,
1899,
11414,
774,
12,
291,
680,
5996,
342,
398,
327,
12030,
314,
5897,
10152,
3878,
267,
2581,
14,
3584,
342,
267,
12904,
18514,
5688,
14,
1462,
14,
981,
8,
3827,
29,
549,
9,
398,
291,
14,
751,
275,
16047,
14,
981,
342,
267,
291,
14,
1972,
275,
291,
423,
981,
63,
1972,
342,
267,
291,
14,
1069,
275,
18638,
1252,
1069,
342,
398,
327,
12439,
1683,
267,
21198,
63,
374,
63,
1972,
63,
5938,
275,
3371,
14,
785,
8,
277,
63,
1142,
68,
63,
1246,
12,
283,
374,
63,
1972,
63,
5938,
358,
267,
291,
14,
1805,
63,
374,
63,
1972,
63,
5938,
275,
21198,
63,
374,
63,
1972,
63,
5938,
14,
928,
342,
267,
291,
14,
1805,
63,
374,
63,
1972,
63,
5938,
14,
1107,
63,
585,
275,
756,
267,
291,
14,
12808,
8,
11238,
63,
374,
63,
1972,
63,
5938,
14,
2379,
9,
398,
21198,
63,
7275,
63,
1765,
275,
3371,
360,
5607,
2268,
14,
1246,
14,
7275,
63,
1765,
358,
267,
291,
14,
1805,
63,
7275,
63,
1765,
275,
21198,
63,
7275,
63,
1765,
14,
928,
342,
267,
291,
14,
12808,
8,
11238,
63,
7275,
63,
1765,
14,
2379,
9,
339,
347,
485,
981,
63,
1972,
8,
277,
12,
365,
63,
277,
63,
1142,
68,
29,
549,
12,
1011,
1419,
304,
267,
2518,
275,
17862,
14,
981,
8,
288,
291,
63,
1142,
68,
29,
374,
63,
277,
63,
1142,
68,
12,
288,
1343,
29,
2083,
8,
6965,
12,
1749,
12,
3193,
12,
1520,
12,
5557,
12,
7294,
395,
288,
16183,
63,
17708,
83,
3713,
4986,
356,
378,
14,
21,
1386,
288,
1011,
1419,
267,
776,
267,
327,
12030,
5897,
10152,
367,
642,
2518,
267,
25949,
63,
1246,
14,
409,
63,
4736,
63,
15043,
63,
3827,
8,
1972,
14,
344,
12,
365,
63,
277,
63,
1142,
68,
9,
398,
18946,
2927,
8,
751,
29,
277,
14,
751,
12,
2518,
63,
344,
29,
1972,
14,
344,
9,
267,
372,
2518,
339,
347,
485,
981,
63,
1765,
8,
277,
12,
2518,
12,
6474,
304,
267,
2120,
63,
1210,
275,
469,
288,
283,
1972,
63,
344,
356,
2649,
8,
1972,
14,
344,
395,
288,
283,
5500,
63,
1580,
356,
359,
5500,
14,
344,
467,
267,
789,
267,
372,
291,
423,
981,
63,
1210,
63,
2373,
8,
1765,
63,
1210,
29,
1765,
63,
1210,
9,
339,
347,
485,
981,
63,
4736,
8,
277,
12,
2004,
304,
267,
372,
17065,
11414,
2927,
14,
981,
8,
288,
922,
29,
277,
14,
751,
12,
288,
2518,
63,
344,
29,
277,
14,
1972,
14,
344,
12,
288,
2004,
29,
1205,
12,
288,
5235,
63,
633,
534,
1014,
921,
1544,
14,
2694,
14,
957,
15,
4736,
14,
5607,
7,
340,
2004,
508,
12904,
11232,
5589,
14,
4249,
461,
587,
3260,
288,
818,
534,
19923,
297,
267,
776,
339,
347,
485,
362,
63,
4736,
8,
277,
12,
2518,
12,
6474,
304,
267,
862,
26,
288,
372,
17065,
11414,
14,
1462,
14,
362,
8,
1972,
63,
344,
29,
1972,
14,
344,
12,
922,
29,
5500,
9,
267,
871,
17065,
11414,
14,
7400,
26,
288,
372,
488,
339,
347,
511,
63,
18157,
8,
277,
304,
267,
2120,
275,
291,
423,
981,
63,
1765,
8,
277,
14,
1972,
12,
291,
14,
751,
9,
267,
291,
14,
1805,
63,
7275,
63,
1765,
14,
1107,
63,
585,
275,
2120,
398,
291,
14,
629,
8,
288,
11249,
2268,
63,
1246,
14,
4208,
63,
751,
63,
6999,
8,
277,
14,
1069,
12,
291,
14,
751,
12,
291,
14,
1972,
395,
288,
469,
355,
283,
3742,
356,
715,
12,
355,
283,
1188,
356,
298,
11414,
291,
13,
15043,
2120,
8,
1765,
63,
344,
3126,
1765,
63,
344,
1552,
965,
2757,
8239,
15848,
908,
8,
490,
2120,
63,
344,
29,
1765,
14,
344,
395,
288,
789,
267,
776,
339,
347,
511,
63,
1074,
63,
705,
63,
1972,
63,
374,
63,
1397,
63,
277,
63,
1142,
68,
8,
277,
304,
267,
440,
63,
277,
63,
1142,
68,
63,
1972,
275,
291,
423,
981,
63,
1972,
8,
374,
63,
277,
63,
1142,
68,
29,
797,
9,
398,
291,
14,
629,
8,
288,
11249,
2268,
63,
1246,
14,
4208,
63,
751,
63,
6999,
8,
277,
14,
1069,
12,
291,
14,
751,
12,
440,
63,
277,
63,
1142,
68,
63,
1972,
395,
288,
469,
355,
283,
3742,
356,
756,
12,
355,
283,
1188,
356,
298,
20485,
1133,
11482,
282,
5897,
291,
13,
15043,
2120,
2952,
314,
2518,
365,
440,
291,
13,
1142,
68,
4765,
288,
789,
267,
776,
267,
6250,
275,
291,
423,
362,
63,
4736,
8,
1397,
63,
277,
63,
1142,
68,
63,
1972,
12,
291,
14,
751,
9,
267,
291,
14,
629,
8,
4736,
14,
1972,
63,
344,
12,
440,
63,
277,
63,
1142,
68,
63,
1972,
14,
344,
9,
267,
291,
14,
629,
8,
4736,
14,
751,
12,
291,
14,
751,
9,
267,
291,
14,
629,
8,
4736,
14,
1205,
12,
12904,
11232,
5589,
14,
705,
9,
267,
291,
14,
629,
8,
4736,
14,
705,
63,
5764,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
mccheung/kbengine
|
kbe/src/lib/python/Lib/test/test_importlib/frozen/test_finder.py
|
81
|
2209
|
from .. import abc
from .. import util
machinery = util.import_importlib('importlib.machinery')
import unittest
class FindSpecTests(abc.FinderTests):
"""Test finding frozen modules."""
def find(self, name, path=None):
finder = self.machinery.FrozenImporter
return finder.find_spec(name, path)
def test_module(self):
name = '__hello__'
spec = self.find(name)
self.assertEqual(spec.origin, 'frozen')
def test_package(self):
spec = self.find('__phello__')
self.assertIsNotNone(spec)
def test_module_in_package(self):
spec = self.find('__phello__.spam', ['__phello__'])
self.assertIsNotNone(spec)
# No frozen package within another package to test with.
test_package_in_package = None
# No easy way to test.
test_package_over_module = None
def test_failure(self):
spec = self.find('<not real>')
self.assertIsNone(spec)
Frozen_FindSpecTests, Source_FindSpecTests = util.test_both(FindSpecTests,
machinery=machinery)
class FinderTests(abc.FinderTests):
"""Test finding frozen modules."""
def find(self, name, path=None):
finder = self.machinery.FrozenImporter
return finder.find_module(name, path)
def test_module(self):
name = '__hello__'
loader = self.find(name)
self.assertTrue(hasattr(loader, 'load_module'))
def test_package(self):
loader = self.find('__phello__')
self.assertTrue(hasattr(loader, 'load_module'))
def test_module_in_package(self):
loader = self.find('__phello__.spam', ['__phello__'])
self.assertTrue(hasattr(loader, 'load_module'))
# No frozen package within another package to test with.
test_package_in_package = None
# No easy way to test.
test_package_over_module = None
def test_failure(self):
loader = self.find('<not real>')
self.assertIsNone(loader)
Frozen_FinderTests, Source_FinderTests = util.test_both(FinderTests,
machinery=machinery)
if __name__ == '__main__':
unittest.main()
|
lgpl-3.0
|
[
504,
2508,
492,
13022,
199,
504,
2508,
492,
4884,
199,
199,
14121,
20067,
275,
4884,
14,
646,
63,
25893,
360,
25893,
14,
14121,
20067,
358,
199,
199,
646,
2882,
421,
199,
533,
6668,
5307,
2925,
8,
3175,
14,
11791,
2925,
304,
339,
408,
774,
17196,
8101,
4621,
1041,
339,
347,
2342,
8,
277,
12,
536,
12,
931,
29,
403,
304,
267,
11569,
275,
291,
14,
14121,
20067,
14,
29767,
18484,
267,
372,
11569,
14,
1623,
63,
1650,
8,
354,
12,
931,
9,
339,
347,
511,
63,
578,
8,
277,
304,
267,
536,
275,
2560,
5006,
12217,
267,
3158,
275,
291,
14,
1623,
8,
354,
9,
267,
291,
14,
629,
8,
1650,
14,
6493,
12,
283,
11202,
358,
339,
347,
511,
63,
2491,
8,
277,
304,
267,
3158,
275,
291,
14,
1623,
10714,
838,
3312,
13766,
267,
291,
14,
10389,
8,
1650,
9,
339,
347,
511,
63,
578,
63,
262,
63,
2491,
8,
277,
304,
267,
3158,
275,
291,
14,
1623,
10714,
838,
3312,
4343,
8283,
297,
14050,
838,
3312,
363,
1105,
267,
291,
14,
10389,
8,
1650,
9,
339,
327,
3091,
8101,
2559,
4453,
4573,
2559,
370,
511,
543,
14,
272,
511,
63,
2491,
63,
262,
63,
2491,
275,
488,
339,
327,
3091,
8837,
4340,
370,
511,
14,
272,
511,
63,
2491,
63,
1883,
63,
578,
275,
488,
339,
347,
511,
63,
5328,
8,
277,
304,
267,
3158,
275,
291,
14,
1623,
4827,
1397,
3363,
5971,
267,
291,
14,
7702,
8,
1650,
9,
199,
199,
29767,
63,
6591,
5307,
2925,
12,
5800,
63,
6591,
5307,
2925,
275,
4884,
14,
396,
63,
10727,
8,
6591,
5307,
2925,
12,
14663,
28540,
29,
14121,
20067,
9,
421,
199,
533,
481,
5755,
2925,
8,
3175,
14,
11791,
2925,
304,
339,
408,
774,
17196,
8101,
4621,
1041,
339,
347,
2342,
8,
277,
12,
536,
12,
931,
29,
403,
304,
267,
11569,
275,
291,
14,
14121,
20067,
14,
29767,
18484,
267,
372,
11569,
14,
1623,
63,
578,
8,
354,
12,
931,
9,
339,
347,
511,
63,
578,
8,
277,
304,
267,
536,
275,
2560,
5006,
12217,
267,
5077,
275,
291,
14,
1623,
8,
354,
9,
267,
291,
14,
1815,
8,
11161,
8,
3422,
12,
283,
912,
63,
578,
1333,
339,
347,
511,
63,
2491,
8,
277,
304,
267,
5077,
275,
291,
14,
1623,
10714,
838,
3312,
13766,
267,
291,
14,
1815,
8,
11161,
8,
3422,
12,
283,
912,
63,
578,
1333,
339,
347,
511,
63,
578,
63,
262,
63,
2491,
8,
277,
304,
267,
5077,
275,
291,
14,
1623,
10714,
838,
3312,
4343,
8283,
297,
14050,
838,
3312,
363,
1105,
267,
291,
14,
1815,
8,
11161,
8,
3422,
12,
283,
912,
63,
578,
1333,
339,
327,
3091,
8101,
2559,
4453,
4573,
2559,
370,
511,
543,
14,
272,
511,
63,
2491,
63,
262,
63,
2491,
275,
488,
339,
327,
3091,
8837,
4340,
370,
511,
14,
272,
511,
63,
2491,
63,
1883,
63,
578,
275,
488,
339,
347,
511,
63,
5328,
8,
277,
304,
267,
5077,
275,
291,
14,
1623,
4827,
1397,
3363,
5971,
267,
291,
14,
7702,
8,
3422,
9,
199,
199,
29767,
63,
11791,
2925,
12,
5800,
63,
11791,
2925,
275,
4884,
14,
396,
63,
10727,
8,
11791,
2925,
12,
9144,
28540,
29,
14121,
20067,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2508,
492,
13022,
199,
504,
2508,
492,
4884,
199,
199,
14121,
20067,
275,
4884,
14,
646,
63,
25893,
360,
25893,
14,
14121,
20067,
358,
199,
199,
646,
2882,
421,
199,
533,
6668,
5307,
2925,
8,
3175,
14,
11791,
2925,
304,
339,
408,
774,
17196,
8101,
4621,
1041,
339,
347,
2342,
8,
277,
12,
536,
12,
931,
29,
403,
304,
267,
11569,
275,
291,
14,
14121,
20067,
14,
29767,
18484,
267,
372,
11569,
14,
1623,
63,
1650,
8,
354,
12,
931,
9,
339,
347,
511,
63,
578,
8,
277,
304,
267,
536,
275,
2560,
5006,
12217,
267,
3158,
275,
291,
14,
1623,
8,
354,
9,
267,
291,
14,
629,
8,
1650,
14,
6493,
12,
283,
11202,
358,
339,
347,
511,
63,
2491,
8,
277,
304,
267,
3158,
275,
291,
14,
1623,
10714,
838,
3312,
13766,
267,
291,
14,
10389,
8,
1650,
9,
339,
347,
511,
63,
578,
63,
262,
63,
2491,
8,
277,
304,
267,
3158,
275,
291,
14,
1623,
10714,
838,
3312,
4343,
8283,
297,
14050,
838,
3312,
363,
1105,
267,
291,
14,
10389,
8,
1650,
9,
339,
327,
3091,
8101,
2559,
4453,
4573,
2559,
370,
511,
543,
14,
272,
511,
63,
2491,
63,
262,
63,
2491,
275,
488,
339,
327,
3091,
8837,
4340,
370,
511,
14,
272,
511,
63,
2491,
63,
1883,
63,
578,
275,
488,
339,
347,
511,
63,
5328,
8,
277,
304,
267,
3158,
275,
291,
14,
1623,
4827,
1397,
3363,
5971,
267,
291,
14,
7702,
8,
1650,
9,
199,
199,
29767,
63,
6591,
5307,
2925,
12,
5800,
63,
6591,
5307,
2925,
275,
4884,
14,
396,
63,
10727,
8,
6591,
5307,
2925,
12,
14663,
28540,
29,
14121,
20067,
9,
421,
199,
533,
481,
5755,
2925,
8,
3175,
14,
11791,
2925,
304,
339,
408,
774,
17196,
8101,
4621,
1041,
339,
347,
2342,
8,
277,
12,
536,
12,
931,
29,
403,
304,
267,
11569,
275,
291,
14,
14121,
20067,
14,
29767,
18484,
267,
372,
11569,
14,
1623,
63,
578,
8,
354,
12,
931,
9,
339,
347,
511,
63,
578,
8,
277,
304,
267,
536,
275,
2560,
5006,
12217,
267,
5077,
275,
291,
14,
1623,
8,
354,
9,
267,
291,
14,
1815,
8,
11161,
8,
3422,
12,
283,
912,
63,
578,
1333,
339,
347,
511,
63,
2491,
8,
277,
304,
267,
5077,
275,
291,
14,
1623,
10714,
838,
3312,
13766,
267,
291,
14,
1815,
8,
11161,
8,
3422,
12,
283,
912,
63,
578,
1333,
339,
347,
511,
63,
578,
63,
262,
63,
2491,
8,
277,
304,
267,
5077,
275,
291,
14,
1623,
10714,
838,
3312,
4343,
8283,
297,
14050,
838,
3312,
363,
1105,
267,
291,
14,
1815,
8,
11161,
8,
3422,
12,
283,
912,
63,
578,
1333,
339,
327,
3091,
8101,
2559,
4453,
4573,
2559,
370,
511,
543,
14,
272,
511,
63,
2491,
63,
262,
63,
2491,
275,
488,
339,
327,
3091,
8837,
4340,
370,
511,
14,
272,
511,
63,
2491,
63,
1883,
63,
578,
275,
488,
339,
347,
511,
63,
5328,
8,
277,
304,
267,
5077,
275,
291,
14,
1623,
4827,
1397,
3363,
5971,
267,
291,
14,
7702,
8,
3422,
9,
199,
199,
29767,
63,
11791,
2925,
12,
5800,
63,
11791,
2925,
275,
4884,
14,
396,
63,
10727,
8,
11791,
2925,
12,
9144,
28540,
29,
14121,
20067,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
zaccoz/odoo
|
addons/fetchmail/res_config.py
|
437
|
5234
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Business Applications
# Copyright (C) 2004-2012 OpenERP S.A. (<http://openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, osv
class fetchmail_config_settings(osv.osv_memory):
""" This wizard can be inherited in conjunction with 'res.config.settings', in order to
define fields that configure a fetchmail server.
It relies on the following convention on the object::
class my_config_settings(osv.osv_memory):
_name = 'my.settings'
_inherit = ['res.config.settings', 'fetchmail.config.settings']
_columns = {
'fetchmail_stuff': fields.boolean(...,
fetchmail_model='my.stuff', fetchmail_name='Incoming Stuff'),
}
def configure_fetchmail_stuff(self, cr, uid, ids, context=None):
return self.configure_fetchmail(cr, uid, 'fetchmail_stuff', context)
and in the form view::
<field name="fetchmail_stuff"/>
<button type="object" name="configure_fetchmail_stuff"/>
The method ``get_default_fetchmail`` determines the value of all fields that start
with 'fetchmail_'. It looks up fetchmail server configurations that match the given
model name (``fetchmail_model``) and are active.
The button action ``configure_fetchmail_stuff`` is caught by the object, and calls
automatically the method ``configure_fetchmail``; it opens the fetchmail server
configuration form for the corresponding field.
"""
_name = 'fetchmail.config.settings'
def get_default_fetchmail(self, cr, uid, fields, context=None):
""" determine the value of all fields like 'fetchmail_XXX' """
ir_model = self.pool.get('ir.model')
fetchmail_server = self.pool.get('fetchmail.server')
fetchmail_fields = [f for f in fields if f.startswith('fetchmail_')]
res = {}
for f in fetchmail_fields:
model_name = self._columns[f].fetchmail_model
model_id = ir_model.search(cr, uid, [('model', '=', model_name)])[0]
server_ids = fetchmail_server.search(cr, uid, [('object_id', '=', model_id), ('state', '=', 'done')])
res[f] = bool(server_ids)
return res
def set_fetchmail(self, cr, uid, ids, context=None):
""" deactivate fetchmail servers for all fields like 'fetchmail_XXX' that are False """
config = self.browse(cr, uid, ids[0], context)
fetchmail_fields = [f for f in self._columns if f.startswith('fetchmail_')]
# determine which models should not have active fetchmail servers, and
# deactivate all active servers for those models
models = [self._columns[f].fetchmail_model for f in fetchmail_fields if not config[f]]
if models:
fetchmail_server = self.pool.get('fetchmail.server')
server_ids = fetchmail_server.search(cr, uid, [('object_id.model', 'in', models), ('state', '=', 'done')])
fetchmail_server.set_draft(cr, uid, server_ids, context)
def configure_fetchmail(self, cr, uid, field, context=None):
""" open the form view of the fetchmail.server to configure """
action = {
'type': 'ir.actions.act_window',
'res_model': 'fetchmail.server',
'view_mode': 'form',
'target': 'current',
}
model_name = self._columns[field].fetchmail_model
model_id = self.pool.get('ir.model').search(cr, uid, [('model', '=', model_name)])[0]
server_ids = self.pool.get('fetchmail.server').search(cr, uid, [('object_id', '=', model_id)])
if server_ids:
action['res_id'] = server_ids[0]
else:
action['context'] = {
'default_name': self._columns[field].fetchmail_name,
'default_object_id': model_id,
}
return action
def __getattr__(self, name):
""" catch calls to 'configure_fetchmail_XXX' """
if name.startswith('configure_fetchmail_'):
return (lambda cr, uid, ids, context=None:
self.configure_fetchmail(cr, uid, name[10:], context))
return super(fetchmail_config_settings, self).__getattr__(name)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
23813,
24636,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
7409,
7653,
428,
14,
33,
14,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
199,
533,
5267,
1198,
63,
888,
63,
1751,
8,
4795,
14,
4795,
63,
4844,
304,
272,
408,
961,
12262,
883,
506,
12623,
315,
22888,
543,
283,
470,
14,
888,
14,
1751,
297,
315,
1865,
370,
267,
5627,
1504,
626,
7908,
282,
5267,
1198,
1654,
14,
398,
2779,
25749,
641,
314,
2569,
16129,
641,
314,
909,
447,
953,
1021,
3002,
63,
888,
63,
1751,
8,
4795,
14,
4795,
63,
4844,
304,
355,
485,
354,
275,
283,
1662,
14,
1751,
7,
355,
485,
6486,
275,
788,
470,
14,
888,
14,
1751,
297,
283,
3535,
1198,
14,
888,
14,
1751,
418,
2234,
485,
3406,
275,
469,
490,
283,
3535,
1198,
63,
14573,
356,
1504,
14,
4871,
8,
11577,
717,
5267,
1198,
63,
1238,
534,
1662,
14,
14573,
297,
5267,
1198,
63,
354,
534,
607,
7909,
1933,
3043,
659,
355,
789,
2234,
347,
7908,
63,
3535,
1198,
63,
14573,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
490,
372,
291,
14,
6472,
63,
3535,
1198,
8,
1556,
12,
1747,
12,
283,
3535,
1198,
63,
14573,
297,
1067,
9,
398,
436,
315,
314,
1824,
2455,
447,
953,
665,
698,
536,
628,
3535,
1198,
63,
14573,
7897,
288,
665,
3887,
730,
628,
785,
2,
536,
628,
6472,
63,
3535,
1198,
63,
14573,
7897,
398,
710,
1083,
1124,
362,
63,
885,
63,
3535,
1198,
1040,
16756,
314,
574,
402,
1006,
1504,
626,
1343,
267,
543,
283,
3535,
1198,
63,
1370,
221,
2779,
10734,
1536,
5267,
1198,
1654,
13422,
626,
1336,
314,
1627,
267,
1402,
536,
15693,
3535,
1198,
63,
1238,
16580,
436,
787,
4702,
14,
398,
710,
5528,
1595,
1124,
6472,
63,
3535,
1198,
63,
14573,
1040,
365,
15604,
701,
314,
909,
12,
436,
4882,
267,
5847,
314,
1083,
1124,
6472,
63,
3535,
1198,
1040,
27,
652,
30848,
314,
5267,
1198,
1654,
267,
2897,
1824,
367,
314,
5226,
901,
14,
272,
408,
272,
485,
354,
275,
283,
3535,
1198,
14,
888,
14,
1751,
7,
339,
347,
664,
63,
885,
63,
3535,
1198,
8,
277,
12,
2467,
12,
1747,
12,
1504,
12,
1067,
29,
403,
304,
267,
408,
6705,
314,
574,
402,
1006,
1504,
2839,
283,
3535,
1198,
63,
13933,
7,
408,
267,
8190,
63,
1238,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1238,
358,
267,
5267,
1198,
63,
1000,
275,
291,
14,
2293,
14,
362,
360,
3535,
1198,
14,
1000,
358,
267,
5267,
1198,
63,
955,
275,
359,
70,
367,
289,
315,
1504,
340,
289,
14,
2460,
360,
3535,
1198,
63,
5440,
267,
522,
275,
1052,
267,
367,
289,
315,
5267,
1198,
63,
955,
26,
288,
1402,
63,
354,
275,
291,
423,
3406,
59,
70,
1055,
3535,
1198,
63,
1238,
288,
1402,
63,
344,
275,
8190,
63,
1238,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
1238,
297,
6291,
1402,
63,
354,
3948,
59,
16,
61,
288,
1654,
63,
1580,
275,
5267,
1198,
63,
1000,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
785,
63,
344,
297,
6291,
1402,
63,
344,
395,
661,
929,
297,
6291,
283,
4456,
2023,
288,
522,
59,
70,
61,
275,
2155,
8,
1000,
63,
1580,
9,
267,
372,
522,
339,
347,
663,
63,
3535,
1198,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
408,
25560,
5267,
1198,
8037,
367,
1006,
1504,
2839,
283,
3535,
1198,
63,
13933,
7,
626,
787,
756,
408,
267,
1101,
275,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
59,
16,
467,
1067,
9,
267,
5267,
1198,
63,
955,
275,
359,
70,
367,
289,
315,
291,
423,
3406,
340,
289,
14,
2460,
360,
3535,
1198,
63,
5440,
267,
327,
6705,
1314,
1709,
1077,
440,
1172,
4702,
5267,
1198,
8037,
12,
436,
267,
327,
25560,
1006,
4702,
8037,
367,
5204,
1709,
267,
1709,
275,
359,
277,
423,
3406,
59,
70,
1055,
3535,
1198,
63,
1238,
367,
289,
315,
5267,
1198,
63,
955,
340,
440,
1101,
59,
70,
2677,
267,
340,
1709,
26,
288,
5267,
1198,
63,
1000,
275,
291,
14,
2293,
14,
362,
360,
3535,
1198,
14,
1000,
358,
288,
1654,
63,
1580,
275,
5267,
1198,
63,
1000,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
785,
63,
344,
14,
1238,
297,
283,
262,
297,
1709,
395,
661,
929,
297,
6291,
283,
4456,
2023,
288,
5267,
1198,
63,
1000,
14,
409,
63,
7185,
8,
1556,
12,
1747,
12,
1654,
63,
1580,
12,
1067,
9,
339,
347,
7908,
63,
3535,
1198,
8,
277,
12,
2467,
12,
1747,
12,
901,
12,
1067,
29,
403,
304,
267,
408,
1551,
314,
1824,
2455,
402,
314,
5267,
1198,
14,
1000,
370,
7908,
408,
267,
1595,
275,
469,
288,
283,
466,
356,
283,
723,
14,
3723,
14,
2442,
63,
3806,
297,
288,
283,
470,
63,
1238,
356,
283,
3535,
1198,
14,
1000,
297,
288,
283,
1345,
63,
632,
356,
283,
964,
297,
288,
283,
1375,
356,
283,
1818,
297,
267,
789,
267,
1402
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
23813,
24636,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
7409,
7653,
428,
14,
33,
14,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
199,
533,
5267,
1198,
63,
888,
63,
1751,
8,
4795,
14,
4795,
63,
4844,
304,
272,
408,
961,
12262,
883,
506,
12623,
315,
22888,
543,
283,
470,
14,
888,
14,
1751,
297,
315,
1865,
370,
267,
5627,
1504,
626,
7908,
282,
5267,
1198,
1654,
14,
398,
2779,
25749,
641,
314,
2569,
16129,
641,
314,
909,
447,
953,
1021,
3002,
63,
888,
63,
1751,
8,
4795,
14,
4795,
63,
4844,
304,
355,
485,
354,
275,
283,
1662,
14,
1751,
7,
355,
485,
6486,
275,
788,
470,
14,
888,
14,
1751,
297,
283,
3535,
1198,
14,
888,
14,
1751,
418,
2234,
485,
3406,
275,
469,
490,
283,
3535,
1198,
63,
14573,
356,
1504,
14,
4871,
8,
11577,
717,
5267,
1198,
63,
1238,
534,
1662,
14,
14573,
297,
5267,
1198,
63,
354,
534,
607,
7909,
1933,
3043,
659,
355,
789,
2234,
347,
7908,
63,
3535,
1198,
63,
14573,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
490,
372,
291,
14,
6472,
63,
3535,
1198,
8,
1556,
12,
1747,
12,
283,
3535,
1198,
63,
14573,
297,
1067,
9,
398,
436,
315,
314,
1824,
2455,
447,
953,
665,
698,
536,
628,
3535,
1198,
63,
14573,
7897,
288,
665,
3887,
730,
628,
785,
2,
536,
628,
6472,
63,
3535,
1198,
63,
14573,
7897,
398,
710,
1083,
1124,
362,
63,
885,
63,
3535,
1198,
1040,
16756,
314,
574,
402,
1006,
1504,
626,
1343,
267,
543,
283,
3535,
1198,
63,
1370,
221,
2779,
10734,
1536,
5267,
1198,
1654,
13422,
626,
1336,
314,
1627,
267,
1402,
536,
15693,
3535,
1198,
63,
1238,
16580,
436,
787,
4702,
14,
398,
710,
5528,
1595,
1124,
6472,
63,
3535,
1198,
63,
14573,
1040,
365,
15604,
701,
314,
909,
12,
436,
4882,
267,
5847,
314,
1083,
1124,
6472,
63,
3535,
1198,
1040,
27,
652,
30848,
314,
5267,
1198,
1654,
267,
2897,
1824,
367,
314,
5226,
901,
14,
272,
408,
272,
485,
354,
275,
283,
3535,
1198,
14,
888,
14,
1751,
7,
339,
347,
664,
63,
885,
63,
3535,
1198,
8,
277,
12,
2467,
12,
1747,
12,
1504,
12,
1067,
29,
403,
304,
267,
408,
6705,
314,
574,
402,
1006,
1504,
2839,
283,
3535,
1198,
63,
13933,
7,
408,
267,
8190,
63,
1238,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1238,
358,
267,
5267,
1198,
63,
1000,
275,
291,
14,
2293,
14,
362,
360,
3535,
1198,
14,
1000,
358,
267,
5267,
1198,
63,
955,
275,
359,
70,
367,
289,
315,
1504,
340,
289,
14,
2460,
360,
3535,
1198,
63,
5440,
267,
522,
275,
1052,
267,
367,
289,
315,
5267,
1198,
63,
955,
26,
288,
1402,
63,
354,
275,
291,
423,
3406,
59,
70,
1055,
3535,
1198,
63,
1238,
288,
1402,
63,
344,
275,
8190,
63,
1238,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
1238,
297,
6291,
1402,
63,
354,
3948,
59,
16,
61,
288,
1654,
63,
1580,
275,
5267,
1198,
63,
1000,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
785,
63,
344,
297,
6291,
1402,
63,
344,
395,
661,
929,
297,
6291,
283,
4456,
2023,
288,
522,
59,
70,
61,
275,
2155,
8,
1000,
63,
1580,
9,
267,
372,
522,
339,
347,
663,
63,
3535,
1198,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
408,
25560,
5267,
1198,
8037,
367,
1006,
1504,
2839,
283,
3535,
1198,
63,
13933,
7,
626,
787,
756,
408,
267,
1101,
275,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
59,
16,
467,
1067,
9,
267,
5267,
1198,
63,
955,
275,
359,
70,
367,
289,
315,
291,
423,
3406,
340,
289,
14,
2460,
360,
3535,
1198,
63,
5440,
267,
327,
6705,
1314,
1709,
1077,
440,
1172,
4702,
5267,
1198,
8037,
12,
436,
267,
327,
25560,
1006,
4702,
8037,
367,
5204,
1709,
267,
1709,
275,
359,
277,
423,
3406,
59,
70,
1055,
3535,
1198,
63,
1238,
367,
289,
315,
5267,
1198,
63,
955,
340,
440,
1101,
59,
70,
2677,
267,
340,
1709,
26,
288,
5267,
1198,
63,
1000,
275,
291,
14,
2293,
14,
362,
360,
3535,
1198,
14,
1000,
358,
288,
1654,
63,
1580,
275,
5267,
1198,
63,
1000,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
785,
63,
344,
14,
1238,
297,
283,
262,
297,
1709,
395,
661,
929,
297,
6291,
283,
4456,
2023,
288,
5267,
1198,
63,
1000,
14,
409,
63,
7185,
8,
1556,
12,
1747,
12,
1654,
63,
1580,
12,
1067,
9,
339,
347,
7908,
63,
3535,
1198,
8,
277,
12,
2467,
12,
1747,
12,
901,
12,
1067,
29,
403,
304,
267,
408,
1551,
314,
1824,
2455,
402,
314,
5267,
1198,
14,
1000,
370,
7908,
408,
267,
1595,
275,
469,
288,
283,
466,
356,
283,
723,
14,
3723,
14,
2442,
63,
3806,
297,
288,
283,
470,
63,
1238,
356,
283,
3535,
1198,
14,
1000,
297,
288,
283,
1345,
63,
632,
356,
283,
964,
297,
288,
283,
1375,
356,
283,
1818,
297,
267,
789,
267,
1402,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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